[Bioperl-l] accessing GenBank

Barry Moore barry.moore at genetics.utah.edu
Tue Jan 18 18:19:08 EST 2005


Tim,

If you just typed install bioperl at the ppm prompt you may well have 
1.2.x.  That doesn't necessarily explain why your tutorial script 
doesn't work, but it might.  You probably want to install at least 
bioperl 1.4 (1.5 is on the way soon).  Try the following script as 
another way to check if you've got bioperl working on your windows machine.

Barry

#!/usr/bin/perl

#A short script to demonstrate how to download sequences from GenBank 
and access
#the sequence and some associated annotations using Bioperl.

use strict;
use warnings;
use Bio::SeqIO;
use Bio::DB::GenBank; #use Bio::DB::GenPept or Bio::DB::RefSeq if needed

#Get some sequence IDs either like below, or read in from a file.  Note that
#this sample script works with the accession numbers below (at least at 
the time
#it was written).  If you add different accession numbers, and you get 
errors,
#you may be calling for something that the sequence doesn't have.  
You'll have
#to add your own error trapping code to handle that.
my @ids = ('K03160', 'AB039327', 'BC035972');

#Create the GenBank database object to read from the database.
my $gb = new Bio::DB::GenBank();

#Create a sequence stream to pass the sequences from the database to the 
program.
my $seqio = $gb->get_Stream_by_id(\@ids);

#Loop over all of the sequences that you requested.
while (my $seq = $seqio->next_seq) {

  #Here is how you get methods directly from the RichSeq object.  Replace
  #'display_name' with any other method in Table 2. that can be called on
  #either the RichSeq object directly, or the PrimarySeq object which it has
  #inherited.
  print "Display Name:  ", $seq->display_name,"\n";
  print "Sequence Date:  ",$seq->get_dates,"\n";

  #Here is how to access the classification data from the species object.
  my $species = $seq->species;
  print "Species  :", $species->common_name,"\n";
  my @class = $species->classification;
  print "Classification:  @class\n";

  #Here is a general way to call things that are stored as a 
Bio::SeqFeature::
  #Generic object.  Replace 'source' with any other of the "major" 
headings in
  #the feature table (e.g gene, CDS, etc.) and replace 'organism' with 
any of
  #the tag values found under that heading (mol_type, locus_tag, gene, etc.)
  my @source_feats = grep { $_->primary_tag eq 'source' } 
$seq->get_SeqFeatures();
  my $source_feat = shift @source_feats;
  my @mol_type = $source_feat->get_tag_values('mol_type');
  print "Molecule Type:  @mol_type\n";
 
  #Here is a general way to call things that are stored as some type of a
  #Bio::Annotation oject.  This includes reference information, and 
comments.
  #Replace reference with 'comment' to get the comment, and replace
  #$ref->authors with $ref->title (or location, medline, etc.) to get other
  #reference categories
  my $ann = $seq->annotation();
  my @references = ($ann->get_Annotations('reference'));
  my $ref = shift @references;
  my ($title, $authors, $location, $pubmed, $reference);
  if (defined $ref) {
    $authors = $ref->authors;
    print "Authors:  $authors\n";
  }
  print "Sequence:  \n", $seq->seq, "\n\n";
}

Tim Alcon wrote:

> I seem unable to access GenBank.  When running bptutorial.exe, it 
> seems like all the other examples run fine except that one.  Anyone 
> know why that would be?  I'm using ActivePerl on Windows XP.  I have 
> whichever version of bioperl is the current default using ppm (it's at 
> least 1.0).   When I run the exact same code from my campus Unix 
> account, it works fine.
>
> Tim
>
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at portal.open-bio.org
> http://portal.open-bio.org/mailman/listinfo/bioperl-l


-- 
Barry Moore
Dept. of Human Genetics
University of Utah
Salt Lake City, UT





More information about the Bioperl-l mailing list