Biotech > FAQ > BioPerl FAQ (Frequently Asked Questions)

How do I use Bio::Index::Fasta and index on diff...

To see other biotech frequently asked questions, please visit

(Continued from previous question...)

How do I use Bio::Index::Fasta and index on different ids?

I'm using Bio::Index::Fasta in order to retrieve sequences from my indexed fasta file but I keep seeing MSG: Did not provide a valid Bio::PrimarySeqI object when I call fetch followed by write_seq() on a Bio::SeqIO handle. Why?

It's likely that fetch didn't retrieve a Bio::Seq object. There are few possible explanations but the most common cause is that the id you're passing to fetch is not the key to that sequence in the index. For example, if the FASTA header is >gi|12366 and your id is 12366 then fetch won't find the sequence, it expects to see gi|12366. You need to use the get_id method to specify the key used in indexing, like this:

$inx = Bio::Index::Fasta->new(-filename =>$indexname);
$inx = id_parser(\&get_id);

sub get_id {
  my $header = shift;
  $header =~ /^>gi\|(+)/;

The same issue arises when you use Bio::DB::Fasta, but in that case the code might look like this:

$inx = Bio::DB::Fasta->new($fastaname, -makeid => \&get_id);

(Continued on next question...)

Other Frequently Asked Questions