Perl

From Christoph's Personal Wiki
Revision as of 23:47, 13 April 2007 by Christoph (Talk | contribs)

Jump to: navigation, search

Perl is a dynamic programming language.

Regex

see: Regular expression

Search and replace all "foo" with "bar" in filename:

perl -i -pe 's/foo/bar/gi' filename

Modules

Search and download: http://search.cpan.org/

Installing

perl -MCPAN -e shell
#Or,
perl -MCPAN -e "install Example::Module"

My favourites

BioPerl

See: http://www.bioperl.org/wiki/Main_Page

Perl and MySQL

This section will just list a bunch of random examples. They are useful to give you an idea of what you can do with Perl, MySQL, and the CLI.

Note: These examples were taken from my course in Comparative Microbial Genomics at CBS (in Denmark).

mysql -B -e "update cmp_genomics.features set note = '' where user = USER() and note not like 'tcs%' or note is null"
foreach accession (AE017042 AE016879 AL111168 AL645882 AP008232 AP009048 BA000021 CP000034)
   foreach type (ecf s54 s70)
     cat source/$accession.proteins.$type.sigmas.hmmsearch | \
     perl -ne 'next unless /^CDS_(\d+)\-(\d+)_DIR([\-\+]+)\s+([0-9\-\.e]+)\s+([0-9\-\.e]+)\s+/;\
               my ($start,$stop,$dir,$score,$evalue) = ($1,$2,$3,$4,$5);\
               next unless $score > 0;\
               print "update cmp_genomics.features set note = \"Sigma Factor '$type'\" \
                      where start=$start and stop = $stop and user = user() and accession = \"'$accession'\";\n";'\
     | mysql
   end
end
mysql -B -e "update cmp_genomics.features set note = '' where user = USER() and note not like 'sigma%' or note is null"
foreach accession (AE017042 AE016879 AL111168 AL645882 AP008232 AP009048 BA000021 CP000034)
   foreach type (RRreciever HisKA_1 HisKA_2 HisKA_3 HWE_HK)
     cat source/$accession.$type.TCS.hmmsearch | \
     perl -ne 'next unless /^CDS_(\d+)\-(\d+)_DIR([\-\+]+)\s+([0-9\-\.e]+)\s+([0-9\-\.e]+)\s+/;\
               my ($start,$stop,$dir,$score,$evalue) = ($1,$2,$3,$4,$5);\
               next unless $score > 0; \
               print "update cmp_genomics.features set note = \"TCS '$type'\" \
                      where start=$start and stop = $stop and user = user() and accession = \"'$accession'\";\n";'\
     | mysql -B
   end
end

External links

This article is curently a "stub". This means it is an incomplete article needing further elaboration.

I always welcome suggestions, comments, and criticism. If you have something to contribute to this site, please follow this link: Contributing Information. Thank you!