[Biojava-dev] SequenceIterator question

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


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());
    }
}