Stockholm Perl Module Examples

From Biowiki
(Redirected from StockholmPerlModuleExamples)
Jump to: navigation, search

Here is an example of how to use the module in dart (see Stockholm tools for more info on this and other tools):

The following one-liner uses the Stockholm::Database module to read in a file called first10-pandit.stock, extract a random 0.3 (30%) of the alignments therein (using a Knuth/Fisher-Yates shuffle with a Schwartzian transform), and write those alignments to a file random3-of-first10.stock.

perl -I/mnt/clusternfs/dart/perl -e 'use Stockholm::Database;
  $db = Stockholm::Database->from_file(shift);	# load
  $dbSize=@$db; $p=shift; $n=int($p*$dbSize);  # get no. of alignments to sample
  @index=(0..$dbSize-1);  # prepare index array
  for $i (0..$n) { $j=int(rand($dbSize-$i))+$i; @index[$i,$j]=@index[$j,$i] };	# Fisher-Yates shuffle
  @{$db}=@{$db}[@index[0..$n-1]];  # Schwartzian transform
  $db->to_file(shift);'  # save
  first10-pandit.stock .3 random3-of-first10.stock

NB to actually get this to work you'll need to strip out the comments...