[Biojava-dev] SequenceIterator question

Ren, Zhen zren@amylin.com
Tue, 8 Oct 2002 08:55:24 -0700


Thanks a lot, Matthew.  If I want to go through a big set of sequences several times, what would be a more efficient approach? I certainly appreciate your help.  -Zhen

-----Original Message-----
From: Matthew Pocock [mailto:matthew_pocock@yahoo.co.uk]
Sent: Tuesday, October 08, 2002 8:25 AM
To: Ren, Zhen; biojava-dev@biojava.org
Subject: Re: [Biojava-dev] SequenceIterator question


Hi Zhen,

The correct approach is as you said - recreate the
buffered reader and start again. If you do this n
times, it will cost you n times as much as doing it
once.

There are reasons the iterators don't have reset.
There are many cases where the stream of sequences
only arrives once (e.g. data over a socket).
Sometimes, the resources needed to cache the sequences
would be prohibative (e.g. looping over all sequences
in embl). Some resources can be looped over multiple
times, but this tends to work by having an iterator
method on the collection object e.g. sequences() on
SequenceDB. This way, the collection can manage any
caching scheims and this cache can be shaired among
multiple iterators over that collection.

Is that helpfull? Best of luck with BioJava.

Matthew

 --- "Ren, Zhen" <zren@amylin.com> wrote: > Hi, there,
>  
> A newbie question.  Plesae help!  The snippet listed
> below is basically the same as the GCContent class
> in the BioJava Tutorial.  At the end of the while
> loop, stream "points" to the end of the sequence
> iterator.  If I want to traverse the sequences again
> to do something else at this point, is there a way
> to reset the "pointer" back to the beginning? 
> Otherwise, I have to close the file and create a
> second sequence iterator to do the job.  If so, how
> efficient is reading the same file twice or even
> more?  Thanks a lot.
>  
> Zhen
>  
>  
> Code snippet:
>  
> public void foo(File file) {
>     try {
>         BufferedReader fin = new BufferedReader(new
> FileReader(file));
>         SequenceIterator stream =
> SeqIOTools.readFastaProtein(fin);
>         while(stream.hasNext()) {
>             Sequence seq = stream.nextSequence();
>             System.out.println(seq.seqString());
>         }
>         fin.close();
>     } catch(BioException e) {
>         System.err.println("BioException: " +
> e.getMessage());
>     } catch(IOException e) {
>         System.err.println("IOException: " +
> e.getMessage());
>     }
> }
> 
> _______________________________________________
> biojava-dev mailing list
> biojava-dev@biojava.org
> http://biojava.org/mailman/listinfo/biojava-dev 

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com