|
| 1 | +package org.biojava.nbio.core.fasta; |
| 2 | + |
| 3 | +import java.io.InputStream; |
| 4 | +import java.util.LinkedHashMap; |
| 5 | + |
| 6 | +import static org.junit.Assert.* ; |
| 7 | +import static org.hamcrest.CoreMatchers.* ; |
| 8 | + |
| 9 | +import org.biojava.nbio.core.sequence.ProteinSequence; |
| 10 | +import org.biojava.nbio.core.sequence.compound.AminoAcidCompound; |
| 11 | +import org.biojava.nbio.core.sequence.compound.AminoAcidCompoundSet; |
| 12 | +import org.biojava.nbio.core.sequence.io.FastaReader; |
| 13 | +import org.biojava.nbio.core.sequence.io.GenericFastaHeaderParser; |
| 14 | +import org.biojava.nbio.core.sequence.io.ProteinSequenceCreator; |
| 15 | +import org.biojava.nbio.core.sequence.io.util.ClasspathResource; |
| 16 | +import org.junit.Test; |
| 17 | + |
| 18 | + |
| 19 | +public class TestFASTAReader { |
| 20 | + |
| 21 | + @Test |
| 22 | + public void testProcessAll() throws Exception { |
| 23 | + ClasspathResource r = new ClasspathResource("org/biojava/nbio/core/fasta/P02768.fasta"); |
| 24 | + FastaReader<ProteinSequence, AminoAcidCompound> fastaReader = null ; |
| 25 | + try( InputStream inStream = r.getInputStream() ) { |
| 26 | + fastaReader = new FastaReader<ProteinSequence, AminoAcidCompound>( |
| 27 | + inStream, |
| 28 | + new GenericFastaHeaderParser<ProteinSequence, AminoAcidCompound>(), |
| 29 | + new ProteinSequenceCreator(AminoAcidCompoundSet.getAminoAcidCompoundSet())); |
| 30 | + LinkedHashMap<String, ProteinSequence> sequences = fastaReader.process(); |
| 31 | + assertThat(sequences,is(notNullValue())); |
| 32 | + assertThat(sequences.size(),is(1)); |
| 33 | + } finally { |
| 34 | + if(fastaReader != null) fastaReader.close(); |
| 35 | + } |
| 36 | + } |
| 37 | + @Test |
| 38 | + public void testProcess1() throws Exception { |
| 39 | + ClasspathResource r = new ClasspathResource("org/biojava/nbio/core/fasta/P02768.fasta"); |
| 40 | + FastaReader<ProteinSequence, AminoAcidCompound> fastaReader = null ; |
| 41 | + try( InputStream inStream = r.getInputStream() ) { |
| 42 | + fastaReader = new FastaReader<ProteinSequence, AminoAcidCompound>( |
| 43 | + inStream, |
| 44 | + new GenericFastaHeaderParser<ProteinSequence, AminoAcidCompound>(), |
| 45 | + new ProteinSequenceCreator(AminoAcidCompoundSet.getAminoAcidCompoundSet())); |
| 46 | + assertThat(fastaReader.process(1),is(notNullValue())); |
| 47 | + assertThat(fastaReader.process(1),is(nullValue())); |
| 48 | + } finally { |
| 49 | + if(fastaReader != null) fastaReader.close(); |
| 50 | + } |
| 51 | + } |
| 52 | + @Test |
| 53 | + public void testProcess1v2() throws Exception { |
| 54 | + ClasspathResource r = new ClasspathResource("org/biojava/nbio/core/fasta/TwoSequences.fasta"); |
| 55 | + FastaReader<ProteinSequence, AminoAcidCompound> fastaReader = null ; |
| 56 | + try( InputStream inStream = r.getInputStream() ) { |
| 57 | + fastaReader = new FastaReader<ProteinSequence, AminoAcidCompound>( |
| 58 | + inStream, |
| 59 | + new GenericFastaHeaderParser<ProteinSequence, AminoAcidCompound>(), |
| 60 | + new ProteinSequenceCreator(AminoAcidCompoundSet.getAminoAcidCompoundSet())); |
| 61 | + assertThat(fastaReader.process(1),is(notNullValue())); |
| 62 | + assertThat(fastaReader.process(1),is(notNullValue())); |
| 63 | + assertThat(fastaReader.process(1),is(nullValue())); |
| 64 | + } finally { |
| 65 | + if(fastaReader != null) fastaReader.close(); |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | +} |
0 commit comments