Search in sources :

Example 1 with FastaSequenceReader

use of com.github.lindenb.jvarkit.util.bio.fasta.FastaSequenceReader in project jvarkit by lindenb.

the class TestNg01 method testRefGenomeFactoryForFile.

@Test
public void testRefGenomeFactoryForFile() throws IOException {
    final ReferenceGenomeFactory rgf = new ReferenceGenomeFactory();
    rgf.setBufferSize(2);
    final ReferenceGenome ref = rgf.open(TOY_FA);
    final FastaSequenceReader fsr = new FastaSequenceReader();
    final List<FastaSequence> seqs = fsr.readAll(new File(TOY_FA));
    Assert.assertEquals(seqs.size(), ref.size());
    for (int i = 0; i < seqs.size(); i++) {
        Assert.assertEquals(ref.getContig(i).length(), seqs.get(i).length());
        Assert.assertEquals(ref.getContig(i).getContig(), seqs.get(i).getName());
        for (int x = 0; x < ref.getContig(i).length(); ++x) {
            Assert.assertEquals(ref.getContig(i).charAt(x), seqs.get(i).charAt(x));
        }
    }
    ref.close();
}
Also used : ReferenceGenome(com.github.lindenb.jvarkit.util.bio.fasta.ReferenceGenome) ReferenceGenomeFactory(com.github.lindenb.jvarkit.util.bio.fasta.ReferenceGenomeFactory) FastaSequence(com.github.lindenb.jvarkit.util.bio.fasta.FastaSequence) File(java.io.File) FastaSequenceReader(com.github.lindenb.jvarkit.util.bio.fasta.FastaSequenceReader) Test(org.testng.annotations.Test)

Example 2 with FastaSequenceReader

use of com.github.lindenb.jvarkit.util.bio.fasta.FastaSequenceReader in project jvarkit by lindenb.

the class FastaBatchReader method doOpen.

@Override
protected void doOpen() throws Exception {
    Objects.requireNonNull(getResource(), "Input resource must be set");
    if (LOG.isInfoEnabled())
        LOG.info("opening " + getResource());
    if (!this.getResource().isReadable())
        throw new IllegalStateException("Resource is not readable.");
    final FastaSequenceReader fastaReader = new FastaSequenceReader();
    fastaReader.setSequenceCapacity(getSequenceCapacity());
    this.fastaIterator = fastaReader.iterator(new InputStreamReader(this.getResource().getInputStream()));
}
Also used : InputStreamReader(java.io.InputStreamReader) FastaSequenceReader(com.github.lindenb.jvarkit.util.bio.fasta.FastaSequenceReader)

Aggregations

FastaSequenceReader (com.github.lindenb.jvarkit.util.bio.fasta.FastaSequenceReader)2 FastaSequence (com.github.lindenb.jvarkit.util.bio.fasta.FastaSequence)1 ReferenceGenome (com.github.lindenb.jvarkit.util.bio.fasta.ReferenceGenome)1 ReferenceGenomeFactory (com.github.lindenb.jvarkit.util.bio.fasta.ReferenceGenomeFactory)1 File (java.io.File)1 InputStreamReader (java.io.InputStreamReader)1 Test (org.testng.annotations.Test)1