[Bioperl-l] Bio::Index::Fasta foreach loop

Jason Stajich jason at cgt.mc.duke.edu
Thu Apr 10 10:04:36 EDT 2003


On Thu, 10 Apr 2003, Ann Hedley wrote:

> Hi
>
> I've used Bio::Index::Fasta to make the index $inxdc from a fasta file.
>  I now want a  loop to to examine each sequence in turn.


If you want to look at each sequence in turn, just use Bio::SeqIO, no need
to index, indexing is just for random access lookup (when you don't want
to look at everything in order)

my $in = new Bio::SeqIO(-file => $filedc, -format => 'fasta');
while( my $seq = $in->next_seq ) {
  print $seq->display_id, " ", $seq->seq(),"\n";
}

Alternatively I think you can do this from a Bio::Index:: object

my $stream = $inxdc->get_PrimarySeq_stream;
while( my $seq = $stream->next_seq ) {
   print $seq->display_id, " ", $seq->seq(),"\n";
}

>
> This script prints the correct sequence...
>
>   my $seqdc = $inxdc->fetch("CEC00023");
>   print $seqdc->seq;
>
> ... so the index file is OK, but how do I put that in a loop for each
> sequence $id?
>
> Any ideas much appreciated
>
> Many Thanks
> Ann
>
>
> #!/usr/bin/perl -w
>
> use strict;
> use Bio::Index::Fasta; # using fasta file format
>
> ##########get decoder seqs into $idxdc
> #########################################
>
>   my $Index_File_name = shift;
>   my $filedc = "/home/user1/alldc5.fsa";
>   my $inxdc = Bio::Index::Fasta->new( -filename   => $filedc . ".idx",
>                                     -write_flag => 1 );
>   # pass a reference to the critical function to the Bio::Index object
>   $inxdc->id_parser(\&get_id);
>   # make the index
>   $inxdc->make_index($filedc);
>
> ###########print sequence and length for all
> seqs###############################
>
> foreach $inxdc($id)        #????????????
> {
>   my $seqdc = $inxdc->fetch("$id");
>   print $seqdc->seq;
>   print " length is ",$seqdc->length(), ", decoder\n";
> }
>
>
> #########################################################################
>
> # here is where the retrieval key is specified
>   sub get_id
>   {
>      my $header = shift;
>      $header =~ /^>(CEC\d{5})/;
>      $1;
>   }
>
>
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at bioperl.org
> http://bioperl.org/mailman/listinfo/bioperl-l
>

--
Jason Stajich
Duke University
jason at cgt.mc.duke.edu


More information about the Bioperl-l mailing list