[Bioperl-l] Should be simple accession number script, but it's not.

Ewan Birney birney@ebi.ac.uk
Sat, 14 Dec 2002 13:05:04 +0000 (GMT)


On Fri, 13 Dec 2002, Agrin, Nathan wrote:

> I'm writing a simple script:
> 1) I want it to take a list of accession numbers in a .txt file,
> 2) pull out the entries from GenBank,
> 3) and output the names and sequences to a new .txt file.
> 
> The problem is that when I write something like;
> 
> $seq = $db->get_Seq_by_acc($accession);
> print $seq->seq();
> 
> I get an error saying cannot preform command on an undefined variable.
> Anyone had similar problems?  What's really wierd is that it seems to work some of the time.  Below is the code so far:

This is because these accessions are probably not in GenBank. You need
a loop like

while( <ACC_FILE> ) {
	($acc) = split;
	if( ($seq = $db->get_Seq_by_acc($acc)) ) {
		# do something with $seq
	} else {
		print STDERR "No accession number for $acc\n";
	}
}


> 
> #!perl
> 
> use Bio::DB::GenBank;
> 
> 
> open SEQ, "<accession.txt";
> @anum = "<SEQ>";
> 
> my $db = new Bio::DB::GenBank;
> 
> foreach my $accession ( @anum ) {
> 	# just get things by accession number
> 	my $seq = $db->get_Seq_by_acc($accession);
> 	print $seq->seq();
> }
> 
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l@bioperl.org
> http://bioperl.org/mailman/listinfo/bioperl-l
> 

-----------------------------------------------------------------
Ewan Birney. Mobile: +44 (0)7970 151230, Work: +44 1223 494420
<birney@ebi.ac.uk>. 
-----------------------------------------------------------------