[Bioperl-l] Trouble with fetching a sequence from indexed fasta file

Andrew Walsh walsh at cenix-bioscience.com
Thu Apr 28 01:38:48 EDT 2005

Hello Oliver,

The error message "Can't call method seq on an undefined value" means 
that the return value of $inx->fetch($id) is undefined.  You are then 
trying to call the method 'seq' on this undefined value, which is a 
run-time error.

This likely means that one of the ids that you are trying to find is not 
in your proteins.idx file.  You could print the accession at the top of 
the for loop to find out which one it is.  Or you could use this:

my $seq_obj = $inx->fetch($id);
if (! $seq_obj) {
     print "$id was not retrievable\n";
     # put in code to handle this case
else {
     # now you can go ahead and print the sequence
     my $sequence = $seq_obj->seq;



Oliver Homann wrote:
> Hello everyone,
> First off, thanks to those of you that advised my about bioperl 
> installation.  I was eventually able to install using the Fedora core 2 
> version at biolinux.com (it seems to work so far).
> I'm writing now in the hopes that someone can help resolve a bit of 
> beginner's confusion that is currently plaguing me.  Specifically, I'm 
> trying to fetch sequences from a large indexed fasta file using the code 
> posted below.  I;'ve left out everything but the relevant section.  The 
> part that has me puzzled is that my string of IDs that I'm using to 
> fetch the sequences only works when entered manually into the fetch() 
> method.  In other words, the block below doesn't work, nor does the 
> version without the extra $id = 'orf...' line.  These approaches yield 
> the error message "Can't call method seq on an undefined value".  
> However, it DOES work if I relpace fetch($id) with fetch 
> ('orf19.1168.prot_[A.aaa]').  Could someone please explain to me why 
> this is the case?  I suspect I'm missing something fundamental here...
> Many thanks!
> Oliver
> my $inx = Bio::Index::Fasta->new('/home/oliver/Sequences/proteins.idx');
> foreach my $id(@idlist) {
> print "$id \n";
> $id = 'orf19.1168.prot_[A_aaa]';
> my $seq_obj = $inx->fetch($id);
> my $sequence = $seq_obj->seq;
> print "$sequence \n";
> }
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at portal.open-bio.org
> http://portal.open-bio.org/mailman/listinfo/bioperl-l

Andrew Walsh, M.Sc.
Bioinformatics Software Engineer
IT Unit
Cenix BioScience GmbH
Tatzberg 47
01307 Dresden
Tel. +49-351-4173 137
Fax  +49-351-4173 109

public key: http://www.cenix-bioscience.com/public_keys/walsh.gpg

More information about the Bioperl-l mailing list