Thursday, 29 April 2010

== Problem: ==You have hundreds of files with a header and you want to concatenateall of them without the headers except the first one

==Solution(s)==

=== Perl one-liner ===

$ ls file.1 file.2 file.3 file.4 ...

# create a file with the header # print only the first line of one of the files and # redirect ('>') to the final file

$ head -n 1 file.1 > concatenated.file

# loop for all the files and print all lines except first one ($.==1) # if your files have numeric suffixes and are correlative use `seq` # if not use `find`, `ls | grep` etc ('find' is more secure than 'ls' [google for it]) ## (be careful with `ls` if your filenames are not non-space or non-ascii)

## better to use xargs than a loop but is more difficult to have all in a one-liner## because quotes problems when you need to do complicated things, or the redirection ## file needs also to use the loop variable.

# the tail -q prevents to output the file name # the tail -n+2 takes from second line to the end

# if the order of the numeric suffixes is important (the * expansion puts 10 before 2) # you should rename the files # and convert 1,2,...,10 to 01,02,..,10 with rename and "sprintf "%02d",$suff' # or use a loop with the correct order of suffixes [ for x in $(seq 1 22)].

Friday, 16 April 2010

The behaviour of a smart match depends on what type of thing its arguments are. The behaviour is determined by the following table: the first row that applies determines the match behaviour (which is thus mostly determined by the type of the right operand). Note that the smart match implicitly dereferences any non-blessed hash or array ref, so the "Hash" and "Array" entries apply in those cases. (For blessed references, the "Object" entries apply.)
Note that the "Matching Code" column is not always an exact rendition. For example, the smart match operator short-circuits whenever possible, but grep does not.

[copy from perlop.pod]
The yada yada operator (noted ...) is a placeholder for code. Perl parses it without error, but when you try to execute a yada yada, it throws an exception with the text Unimplemented:

The yada yada cannot stand in for an expression that is part of a larger statement since the ... is also the three-dot version of the range operator (see "Range Operators"). These examples of the yada yada are still syntax errors:

There are some cases where Perl can't immediately tell the difference between an expression and a statement. For instance, the syntax for a block and an anonymous hash reference constructor look the same unless there's something in the braces that give Perl a hint. The yada yada is a syntax error if Perl doesn't guess that the { ... } is a block. In that case, it doesn't think the ... is the yada yada because it's expecting an expression instead of a statement:

my @transformed = map { ... } @input; # syntax error

You can use a ; inside your block to denote that the { ... } is a block and not a hash reference constructor. Now the yada yada works:

Following my previous posts I am puting this here for future googling ;-).

These are the failed dependencies that I had when I tried the CPAN install Lincon Stein's Bio::Graphic (in a fresh installed linux box). I need to say that I have installed Bioperl and Bio::Graphics in all my developing machines and laptops many times and usually it works without problems at the first go, but this is because I usually had a lot of things already installed.

But now when I have run CPAN install Bio::Graphics in a clean box I have had a lot of 'expected' dependence issues:

Then I needed to install this:
* sudo aptitude install
- libgd2-xpm-dev # gd for GD. I don't know the difference between xpm and noxpm but anyway
- libexpat-dev # expat for XML::Parser
- graphviz graphviz-dev graphviz-doc libgraphviz-dev graphviz-cairo # for GraphViz
- libdb4.6-dev # for DB_File (The headers for 4.7 were also available but I had 4.6 installed)

And this CPAN modules in this order:
*CPAN
- install IPC::Run # for GraphViz and other modules
- install DB_File # used by several modules so it better to install it first
- install XML::parser
- install GraphViz
- install GD
- install CJFIELDS/BioPerl-1.6.1.tar.gz

And then I was able to install Bio::Graphics

The only caveats here are that you should know that you need the expat for XML, IPC::Run for GraphViz dependency and that DB_File uses the Berkeley db headers (that I needed to google for finding the package that contains them).

GraphViz-2.04/MANIFEST
'/home/pablo/localperl/bin/perl Makefile.PL' returned status 512, won't make
Running make test
Make had some problems, won't test
Running make install
Make had some problems, won't install

So I went to the dir where GV was unpacked and tried to Make it by hand:

pablo@pmg-linux:~/.cpan/build/GraphViz-2.04-HQxvwp$ perl Makefile.PL
Scalar value @ENV{PATH} better written as $ENV{PATH} at Makefile.PL line 37.
Scalar value @ENV{PATH} better written as $ENV{PATH} at Makefile.PL line 40.
Looking for dot... found it at /usr/bin/dot
Checking if your kit is complete...
Looks good
Warning: prerequisite IPC::Run 0.6 not found.
Writing Makefile for GraphViz

OK, this explain it all: I need IPC::Run but it was not show in CPAN

After Intalling IPC::Run, deleting the GraphViz directory in the build dir (CPAN> clean GraphViz does not work) I tried to install again from CPAN but failed again with the same error that before.

I went to the extracted GraphViz dir and intalled manually and all was OK.