1: #!/usr/bin/perl -w
   2: 
   3: use strict;
   4: use Bio::DB::GenBank;
   5: use Bio::SeqIO;
   6: use File::Basename;
   7: 
   8: # configuration information
   9: my $outfile  = 'outfile';
  10: my $progname = basename $0;
  11: 
  12: # usage information
  13: my $usage = "usage:  $0 accession1 [accession2 ...]\n";
  14: die $usage unless @ARGV;
  15: 
  16: # start program flow
  17: my $gb = new Bio::DB::GenBank( 
  18:    -retrievaltype => 'tempfile', 
  19:    -format => 'Fasta'
  20: );
  21: 
  22: my $seqout = Bio::SeqIO->new( -file => ">$outfile", -format => 'FASTA' );
  23: 
  24: my $seqio = $gb->get_Stream_by_acc( @ARGV );
  25: while( my $sequence =  $seqio->next_seq ) {
  26:    $seqout->write_seq($sequence);
  27: }

Replies are listed 'Best First'.
Re: Fetching Biological Sequences from the NCBI
by Sameet (Beadle) on Apr 23, 2004 at 18:25 UTC
    Is it possible to download a part of the sequence using this code, with some modifications. I mean I have 3 nested loops. One selects a chromosome randomly, one selects a contig randomly and third selects a number from 2000 to the length of the contig. Can anybody tell me a way to do it. All help is highly solicitated and will be highly appreciated. regards sameet