[Bio] / FigMetagenomeTools / getgenbank.pl Repository:
ViewVC logotype

View of /FigMetagenomeTools/getgenbank.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (download) (as text) (annotate)
Fri Mar 16 20:51:25 2007 UTC (12 years, 8 months ago) by olson
Branch: MAIN
CVS Tags: mgrast_dev_08112011, mgrast_dev_08022011, mgrast_dev_05262011, mgrast_dev_04082011, mgrast_version_3_2, mgrast_dev_12152011, mgrast_dev_06072011, mgrast_rel_2008_0806, mgrast_dev_10262011, mgrast_dev_02212011, mgrast_rel_2008_0923, mgrast_release_3_0, mgrast_dev_03252011, mgrast_rel_2008_0924, mgrast_rel_2008_1110_v2, mgrast_rel_2008_0625, mgrast_release_3_0_4, mgrast_release_3_0_2, mgrast_release_3_0_3, mgrast_release_3_0_1, mgrast_dev_03312011, mgrast_release_3_1_2, mgrast_release_3_1_1, mgrast_release_3_1_0, mgrast_dev_04132011, mgrast_dev_04012011, mgrast_rel_2008_0919, mgrast_rel_2008_1110, myrast_33, mgrast_rel_2008_0917, mgrast_dev_04052011, mgrast_dev_02222011, HEAD
Changes since 1.1: +0 -1 lines
initial tweaks

#!/usr/bin/env perl

# get genomes.
# first get accession numbers

use strict;
use Bio::DB::GenBank;
use Bio::SeqIO;
my $gb = new Bio::DB::GenBank;
my $do = shift || die "$0 <-s -b> <file>\n\t-s for single, -b for batch\n";
my $file=shift || die "$0 <-s -b> <file>\n\t-s for single, -b for batch\n";

my @accs;
open (IN, $file) || die "$file";
while (<IN>) {
 chomp;
 next unless ($_);
 push (@accs, $_);
 }
close IN;

print STDERR $#accs+1, " sequences to get\n";


if ($do eq "-s") {singleget(\@accs)}
else {batchget(\@accs)}
exit(0);


sub singleget {
 my $accs = shift;
# my $seqout = new Bio::SeqIO(-fh => \*STDOUT, -format => 'genbank');
 foreach my $acc (@$accs) {
  print STDERR "Trying $acc\n";
  my $seqout = new Bio::SeqIO(-file => ">$acc", -format => 'genbank');
  my $seq = $gb->get_Seq_by_acc($acc);
  if ($seq) {$seqout->write_seq($seq)}
  else {print STDERR "ERROR with $acc\n"}
 }
}

sub batchget {
 my $accs=shift;
 my $seqout = new Bio::SeqIO(-fh => \*STDOUT, -format => 'genbank');
 my $seqio = $gb->get_Stream_by_batch($accs);

 my $seq;
 while( defined ($seq = $seqio->next_seq )) {
  if ($seq) {$seqout->write_seq($seq)}
  else {print STDERR "ERROR with a sequence?\n"}
 }
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3