Advertisement
Guest User

Untitled

a guest
May 11th, 2011
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.32 KB | None | 0 0
  1. use Bio::DB::GenBank;
  2. use Bio::SeqIO;
  3. use Error qw(:try);  ##for the try catch
  4.  
  5. ##@lines comes from a file with the accesion numbers
  6.  
  7. for($i=0; $i<$nlines; $i++){
  8.     chomp(@lines[$i]);
  9.     print @lines[$i], " ->";    #this is the accesion number or gen_id
  10.     $acc_num = @lines[$i];     
  11.     #so we create a genbank object first
  12.     #and we get the report by the accesion number or gen_id
  13.     #if we get an error, like connection error we try again
  14.     $ok = 0;
  15.     ##the try catch is because my connection sometimes is sucky
  16.     do{
  17.         try{
  18.             $gb = new Bio::DB::GenBank();
  19.             $seq = $gb->get_Seq_by_version($acc_num);
  20.             $ok=0;
  21.         }
  22.         catch Bio::Root::Exception with{
  23.             my $err = shift;
  24.             print "Connection error again, argh, try once more with $acc_num\n";
  25.             $ok=1;
  26.         };
  27.     }while($ok==1);
  28.     for my $result($seq->get_SeqFeatures){
  29.     ##here we get te taxon of each seq
  30.     push @ids, $result->get_tag_values("db_xref") if ($result->has_tag("db_xref"));
  31.     }
  32.     #print it to a file
  33.     for $taxon(@ids){
  34.         ##but first there is to check if we have a taxon or an ATCC
  35.         @aux = split(":",$taxon);
  36.         if(@aux[0] eq "taxon"){
  37.             print {$out} $taxon, "\n";
  38.             last;
  39.         }
  40.     }
  41.     @ids = ();
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement