manipulate_seq.pl

#!/usr/local/bin/perl -w

# Use BioPerl to convert between sequence formats
# and do some basic sequence manipulation
# WI Bioinformatics course - Feb 2002 - Lecture 6

use Bio::SeqIO;
use Bio::Tools::SeqStats;   # used to calculate MW

$inFile = "BMP7.tfa";

$in  = Bio::SeqIO->new('-file' => "$inFile" ,
                           '-format' => 'Fasta');
$out = Bio::SeqIO->new('-format' => 'Genbank');

while ($seqobj = $in->next_seq()) 
{
   # Print sequence in output format
   $out->write_seq($seqobj);

   print "\nRaw sequence:\n", $seqobj->seq(), "\n";      
   print "\nSequence ID is ", $seqobj->display_id(), "\n";
   print "Sequence from 1 to 100:\n", $seqobj->subseq(1,100), "\n";

   # Check if there's an accession number
   print "Acc num is ", $seqobj->accession_number(), "\n";
   
   print "Type of sequence: ", $type = $seqobj->moltype(), "\n";
   if ($type eq "dna")
   {
      $rev_comp = $seqobj->revcom->seq();
      print "\nReverse complemented sequence:\n$rev_comp\n";
      
      print "\nReverse complemented sequence from 1 to 100:\n",
          $seqobj->revcom->subseq(1, 100), "\n";
   }
   $seq_stats  =  Bio::Tools::SeqStats->new($seqobj);
   $weight = $seq_stats->get_mol_wt();
   
   print "Molecular weight: $$weight[0]\n";
   # Need $$weight[0] because $weight is an array reference
}