FastaReader { @SuppressWarnings("unchecked") public LinkedHashMap<String,S> process() throws IOException { LinkedHashMap<String,S> sequences = new LinkedHashMap<String,S>(); String line = ""; String header = ""; StringBuilder sb = new StringBuilder(); int maxSequenceLength = -1; long fileIndex = 0; long sequenceIndex = 0; boolean keepGoing = true; do { line = line.trim(); if (line.length() != 0) { if (line.startsWith(">")) { if (sb.length() > 0) { S sequence = (S)sequenceCreator.getSequence(sb.toString(), sequenceIndex); headerParser.parseHeader(header, sequence); sequences.put(sequence.getAccession().getID(),sequence); if (maxSequenceLength < sb.length()) { maxSequenceLength = sb.length(); } sb = new StringBuilder(maxSequenceLength); } header = line.substring(1); } else if (line.startsWith(";")) { } else { if(sb.length() == 0){ sequenceIndex = fileIndex; } sb.append(line); } } fileIndex = br.getBytesRead(); line = br.readLine(); if (line == null) { S sequence = (S)sequenceCreator.getSequence(sb.toString(), sequenceIndex); headerParser.parseHeader(header, sequence); sequences.put(sequence.getAccession().getID(),sequence); keepGoing = false; } } while (keepGoing); br.close(); isr.close(); if (fi != null) { fi.close(); } return sequences; } FastaReader(InputStream is, FastaHeaderParserInterface<S,C> headerParser,
    		SequenceCreatorInterface<C> sequenceCreator);  FastaReader(File file, FastaHeaderParserInterface<S,C> headerParser,
    		SequenceCreatorInterface<C> sequenceCreator); @SuppressWarnings("unchecked") LinkedHashMap<String,S> process(); static void main(String[] args);  }
@Test public void testProcess() throws Exception { System.out.println("process"); InputStream inStream = this.getClass().getResourceAsStream("/PF00104_small.fasta"); assertNotNull(inStream); FastaReader<ProteinSequence,AminoAcidCompound> fastaReader = new FastaReader<ProteinSequence,AminoAcidCompound>(inStream, new GenericFastaHeaderParser<ProteinSequence,AminoAcidCompound>(), new ProteinSequenceCreator(AminoAcidCompoundSet.getAminoAcidCompoundSet())); LinkedHashMap<String,ProteinSequence> proteinSequences = fastaReader.process(); inStream.close(); assertEquals(proteinSequences.size() , 283 ); int seqNum = 0; for(String id:proteinSequences.keySet()) { ProteinSequence proteinSequence = proteinSequences.get(id); switch(seqNum) { case 0: assertEquals(proteinSequence.getAccession().getID(),"A2D504_ATEGE/1-46"); assertEquals(proteinSequence.getSequenceAsString(),"-----------------FK-N----LP-LED----------------Q----ITL--IQY-----------SWM----------------------CL-SSFA------LSWRSYK---HTNSQFLYFAPDLVF-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------"); break; case 281: assertEquals(proteinSequence.getAccession().getID(),"Q9PU76_CRONI/141-323"); assertEquals(proteinSequence.getSequenceAsString(),"VETVTELTEFAKSI-PGFS-N----LD-LND----------------Q----VTL--LKY-----------GVY----------------------EA-IFAM------LASVMNK---DGMPVAYGNGFITRE------------------------------------------------------------------------------------------------------------------------------------------------------------FLKSLRKPFCDIMEPKFDFA-MKF-NSL-E-LDDSDI--------------------SLFVA-AIIC-CGDRPG-------------------------------------------LVNV--GHIEKMQESIVHVLKL-H-----LQN---------NH---PD----------------------------DI------F--------LFP-KLLQKMAD-LRQLV-----------------TEH-AQLV--QIIKK---TESDAHLHPLL-------QEI---"); break; case 282: assertEquals(proteinSequence.getAccession().getID(),"Q98SJ1_CHICK/15-61"); assertEquals(proteinSequence.getSequenceAsString(),"---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Q-----------------NW------Q--------RFY-QLTKLLDS-MHDVV-----------------ENL-LSFC--FQTFLDKSM--SIEFPEML-------AEI---"); break; } seqNum++; } assertEquals(seqNum,283); }