Search in sources :

Example 16 with FastqRecord

use of htsjdk.samtools.fastq.FastqRecord in project jvarkit by lindenb.

the class FourLinesFastqReaderTest method test1.

@Test(dataProvider = "src1")
public void test1(final String input) throws IOException {
    final FourLinesFastqReader r = new FourLinesFastqReader(new File(input));
    while (r.hasNext()) {
        FastqRecord rec = r.next();
        Assert.assertNotNull(rec);
    }
    r.close();
}
Also used : FastqRecord(htsjdk.samtools.fastq.FastqRecord) File(java.io.File) Test(org.testng.annotations.Test)

Example 17 with FastqRecord

use of htsjdk.samtools.fastq.FastqRecord in project jvarkit by lindenb.

the class FastqSplitInterleaved method doWork.

@Override
public int doWork(final List<String> args) {
    final String[] fileout = { this.fileA, this.fileB };
    FastqReader r1 = null;
    FastqWriter[] writers = { null, null };
    try {
        if (args.isEmpty()) {
            r1 = new FourLinesFastqReader(stdin());
        } else if (args.size() == 1) {
            r1 = new FourLinesFastqReader(new File(args.get(0)));
        } else {
            LOG.error("illegal.number.of.arguments");
            return -1;
        }
        if (fileout[0] == null && fileout[1] == null) {
            LOG.error("Both outputs are undefined.");
            return -1;
        }
        for (int i = 0; i < 2; ++i) {
            if (fileout[i] == null) {
                writers[i] = new BasicFastqWriter(new PrintStream(new NullOuputStream()));
            } else if (fileout[i].equals("-")) {
                if (i == 1 && "-".equals(fileout[0])) {
                    writers[i] = writers[0];
                } else {
                    writers[i] = new BasicFastqWriter(System.out);
                }
            } else {
                if (i == 1 && fileout[1].equals(fileout[0])) {
                    writers[i] = writers[0];
                } else {
                    writers[i] = new BasicFastqWriter(new File(fileout[i]));
                }
            }
        }
        FastqRecord[] records = { null, null };
        while (r1.hasNext()) {
            records[0] = r1.next();
            if (!r1.hasNext()) {
                r1.close();
                r1 = null;
                throw new IOException("fastq.paired.read.missing");
            }
            records[1] = r1.next();
            for (int i = 0; i < 2; ++i) {
                writers[i].write(records[i]);
            }
        }
        if (r1.hasNext()) {
            throw new IOException("Illegal number of reads in fastq");
        }
        return 0;
    } catch (Exception err) {
        LOG.error(err);
        return -1;
    } finally {
        CloserUtil.close(r1);
        CloserUtil.close(writers[0]);
        CloserUtil.close(writers[1]);
    }
}
Also used : PrintStream(java.io.PrintStream) FourLinesFastqReader(com.github.lindenb.jvarkit.util.picard.FourLinesFastqReader) FastqRecord(htsjdk.samtools.fastq.FastqRecord) IOException(java.io.IOException) IOException(java.io.IOException) FourLinesFastqReader(com.github.lindenb.jvarkit.util.picard.FourLinesFastqReader) FastqReader(com.github.lindenb.jvarkit.util.picard.FastqReader) BasicFastqWriter(htsjdk.samtools.fastq.BasicFastqWriter) FastqWriter(htsjdk.samtools.fastq.FastqWriter) NullOuputStream(com.github.lindenb.jvarkit.io.NullOuputStream) BasicFastqWriter(htsjdk.samtools.fastq.BasicFastqWriter) File(java.io.File)

Example 18 with FastqRecord

use of htsjdk.samtools.fastq.FastqRecord in project jvarkit by lindenb.

the class ConvertPhred64toFastq33 method convert.

private void convert(InputStream in) throws IOException {
    FastqReader r = new FourLinesFastqReader(in);
    while (r.hasNext() && !pw.checkError()) {
        final FastqRecord rec = r.next();
        byte[] quals = rec.getBaseQualityString().getBytes();
        for (int i = 0; i < quals.length; ++i) {
            quals[i] = (byte) (quals[i] - 64 + 33);
            if (quals[i] < 33 || quals[i] > 126) {
                r.close();
                throw new IOException("q=" + (int) quals[i]);
            }
        }
        String name = rec.getReadName();
        int diez = name.indexOf('#');
        if (diez != -1)
            name = name.substring(0, diez);
        pw.print(FastqConstants.SEQUENCE_HEADER);
        pw.println(name);
        pw.println(rec.getReadString());
        pw.print(FastqConstants.QUALITY_HEADER);
        pw.println(rec.getBaseQualityHeader() == null || rec.getReadName().equals(rec.getBaseQualityHeader()) ? "" : rec.getBaseQualityHeader());
        pw.println(new String(quals));
    }
    r.close();
}
Also used : FourLinesFastqReader(com.github.lindenb.jvarkit.util.picard.FourLinesFastqReader) FastqReader(com.github.lindenb.jvarkit.util.picard.FastqReader) FourLinesFastqReader(com.github.lindenb.jvarkit.util.picard.FourLinesFastqReader) FastqRecord(htsjdk.samtools.fastq.FastqRecord) IOException(java.io.IOException)

Example 19 with FastqRecord

use of htsjdk.samtools.fastq.FastqRecord in project jvarkit by lindenb.

the class FastqEntropy method convert.

private void convert(InputStream in) throws IOException {
    FastqReader r = new FourLinesFastqReader(in);
    while (r.hasNext()) {
        FastqRecord rec = r.next();
        BestCompressionOutputStream gzout = new BestCompressionOutputStream();
        gzout.write(rec.getBaseQualityString().getBytes());
        gzout.flush();
        gzout.close();
        this.length2count.incr(gzout.getByteWrittenCount());
    }
    r.close();
}
Also used : FourLinesFastqReader(com.github.lindenb.jvarkit.util.picard.FourLinesFastqReader) FastqReader(com.github.lindenb.jvarkit.util.picard.FastqReader) FourLinesFastqReader(com.github.lindenb.jvarkit.util.picard.FourLinesFastqReader) FastqRecord(htsjdk.samtools.fastq.FastqRecord)

Example 20 with FastqRecord

use of htsjdk.samtools.fastq.FastqRecord in project jvarkit by lindenb.

the class FastqRecordTreePack method scan.

private void scan(FastqReader iter) {
    while (iter.hasNext()) {
        final FastqRecord rec = iter.next();
        super.bindings.put("record", rec);
        super.nodeFactoryChain.watch(rootNode, rec);
    }
}
Also used : FastqRecord(htsjdk.samtools.fastq.FastqRecord)

Aggregations

FastqRecord (htsjdk.samtools.fastq.FastqRecord)40 SAMRecord (htsjdk.samtools.SAMRecord)16 Test (org.junit.Test)12 FastqReader (htsjdk.samtools.fastq.FastqReader)8 File (java.io.File)6 SAMFileHeader (htsjdk.samtools.SAMFileHeader)4 FastqReader (com.github.lindenb.jvarkit.util.picard.FastqReader)3 FourLinesFastqReader (com.github.lindenb.jvarkit.util.picard.FourLinesFastqReader)3 SAMFileWriter (htsjdk.samtools.SAMFileWriter)3 IOException (java.io.IOException)3 Test (org.testng.annotations.Test)3 BufferedReferenceSequenceFile (au.edu.wehi.idsv.picard.BufferedReferenceSequenceFile)2 ChimericAlignment (au.edu.wehi.idsv.sam.ChimericAlignment)2 SAMSequenceDictionaryProgress (com.github.lindenb.jvarkit.util.picard.SAMSequenceDictionaryProgress)2 Cigar (htsjdk.samtools.Cigar)2 CigarElement (htsjdk.samtools.CigarElement)2 SAMFileWriterFactory (htsjdk.samtools.SAMFileWriterFactory)2 SAMRecordIterator (htsjdk.samtools.SAMRecordIterator)2 CommandLineProgramTest (org.broadinstitute.hellbender.CommandLineProgramTest)2 ProgressLogger (org.broadinstitute.hellbender.utils.runtime.ProgressLogger)2