Search in sources :

Example 1 with FastqReader

use of htsjdk.samtools.fastq.FastqReader in project gatk by broadinstitute.

the class SamToFastqIntegrationTest method createFastqReadHeaderSet.

private Set<String> createFastqReadHeaderSet(final File file) {
    final Set<String> set = new HashSet<>();
    final FastqReader freader = new FastqReader(file);
    while (freader.hasNext()) {
        final FastqRecord frec = freader.next();
        set.add(frec.getReadName());
    }
    return set;
}
Also used : FastqReader(htsjdk.samtools.fastq.FastqReader) FastqRecord(htsjdk.samtools.fastq.FastqRecord)

Example 2 with FastqReader

use of htsjdk.samtools.fastq.FastqReader in project gatk by broadinstitute.

the class FastqToSam method doWork.

/* Simply invokes the right method for unpaired or paired data. */
@Override
protected Object doWork() {
    IOUtil.assertFileIsReadable(FASTQ);
    IOUtil.assertFileIsWritable(OUTPUT);
    FastqReader reader = fileToFastqReader(FASTQ);
    FastqReader reader2 = null;
    if (FASTQ2 != null) {
        IOUtil.assertFileIsReadable(FASTQ2);
        reader2 = fileToFastqReader(FASTQ2);
    }
    QUALITY_FORMAT = FastqToSam.determineQualityFormat(reader, reader2, QUALITY_FORMAT);
    final SAMFileHeader header = createSamFileHeader();
    try (final SAMFileWriter writer = createSAMWriter(OUTPUT, REFERENCE_SEQUENCE, header, false)) {
        reader = fileToFastqReader(FASTQ);
        if (FASTQ2 != null) {
            reader2 = fileToFastqReader(FASTQ2);
        }
        makeItSo(reader, reader2, writer);
        reader.close();
        if (reader2 != null) {
            reader2.close();
        }
    }
    return null;
}
Also used : FastqReader(htsjdk.samtools.fastq.FastqReader)

Example 3 with FastqReader

use of htsjdk.samtools.fastq.FastqReader in project gatk by broadinstitute.

the class RunSGAViaProcessBuilderOnSparkUnitTest method extractNamesAndSeqFromFASTQ.

// utility function: for extracting read names and sequences from a fastq/fasta file
private static void extractNamesAndSeqFromFASTQ(final File FASTAFile, final boolean fastqFilesWellFormed, List<String> readNames, List<String> sequences) throws IOException {
    if (fastqFilesWellFormed) {
        try (final FastqReader reader = new FastqReader(FASTAFile)) {
            while (reader.hasNext()) {
                final FastqRecord record = reader.next();
                readNames.add(record.getReadName());
                sequences.add(record.getReadString());
            }
        }
    } else {
        try (final BufferedReader reader = new BufferedReader(new FileReader(FASTAFile))) {
            String line = "";
            int i = 0;
            while ((line = reader.readLine()) != null) {
                final int l = i % 4;
                if (0 == l) {
                    readNames.add(line);
                    ++i;
                } else {
                    sequences.add(line);
                    reader.readLine();
                    reader.readLine();
                    i += 3;
                }
            }
        }
    }
}
Also used : FastqReader(htsjdk.samtools.fastq.FastqReader) FastqRecord(htsjdk.samtools.fastq.FastqRecord) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader)

Example 4 with FastqReader

use of htsjdk.samtools.fastq.FastqReader in project gatk by broadinstitute.

the class SamToFastqIntegrationTest method testClipping.

@Test(dataProvider = "clippingTests")
public void testClipping(final String clippingAction, final String bases1_1, final String quals1_1, final String bases1_2, final String quals1_2, final String bases2_1, final String quals2_1, final String bases2_2, final String quals2_2, final String testName) throws IOException {
    final File samFile = new File(TEST_DATA_DIR, CLIPPING_TEST_DATA);
    final File f1 = BaseTest.createTempFile("clippingtest1", "fastq");
    final File f2 = BaseTest.createTempFile("clippingtest2", "fastq");
    if (clippingAction != null) {
        convertFile(new String[] { "-input", samFile.getAbsolutePath(), "--FASTQ", f1.getAbsolutePath(), "--SECOND_END_FASTQ", f2.getAbsolutePath(), "--CLIPPING_ACTION", clippingAction, "--CLIPPING_ATTRIBUTE", "XT" });
    } else {
        convertFile(new String[] { "--input", samFile.getAbsolutePath(), "--FASTQ", f1.getAbsolutePath(), "--SECOND_END_FASTQ", f2.getAbsolutePath() });
    }
    Iterator<FastqRecord> it = new FastqReader(f1).iterator();
    FastqRecord first = it.next();
    Assert.assertEquals(first.getReadString(), bases1_1, testName);
    Assert.assertEquals(first.getBaseQualityString(), quals1_1, testName);
    FastqRecord second = it.next();
    Assert.assertEquals(second.getReadString(), bases1_2, testName);
    Assert.assertEquals(second.getBaseQualityString(), quals1_2, testName);
    it = new FastqReader(f2).iterator();
    first = it.next();
    Assert.assertEquals(first.getReadString(), bases2_1, testName);
    Assert.assertEquals(first.getBaseQualityString(), quals2_1, testName);
    second = it.next();
    Assert.assertEquals(second.getReadString(), bases2_2, testName);
    Assert.assertEquals(second.getBaseQualityString(), quals2_2, testName);
}
Also used : FastqReader(htsjdk.samtools.fastq.FastqReader) FastqRecord(htsjdk.samtools.fastq.FastqRecord) File(java.io.File) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test) CommandLineProgramTest(org.broadinstitute.hellbender.CommandLineProgramTest)

Example 5 with FastqReader

use of htsjdk.samtools.fastq.FastqReader in project gatk by broadinstitute.

the class SamToFastqIntegrationTest method testTrimming.

@Test(dataProvider = "trimmedData")
public void testTrimming(final String samFilename, final int read1Trim, final int read1MaxBases, final int expectedRead1Length, final int read2Trim, final int read2MaxBases, final int expectedRead2Length) throws IOException {
    final File samFile = new File(TEST_DATA_DIR, samFilename);
    final File pair1File = newTempFastqFile("pair1");
    final File pair2File = newTempFastqFile("pair2");
    convertFile(new String[] { "--input", samFile.getAbsolutePath(), "--FASTQ", pair1File.getAbsolutePath(), "--SECOND_END_FASTQ", pair2File.getAbsolutePath(), "--READ1_TRIM", Integer.toString(read1Trim), "--READ1_MAX_BASES_TO_WRITE", Integer.toString(read1MaxBases), "--READ2_TRIM", Integer.toString(read2Trim), "--READ2_MAX_BASES_TO_WRITE", Integer.toString(read2MaxBases) });
    for (final FastqRecord first : new FastqReader(pair1File)) {
        Assert.assertEquals(first.getReadString().length(), expectedRead1Length, "Incorrect read length");
        Assert.assertEquals(first.getBaseQualityString().length(), expectedRead1Length, "Incorrect quality string length");
    }
    for (final FastqRecord second : new FastqReader(pair2File)) {
        Assert.assertEquals(second.getReadString().length(), expectedRead2Length, "Incorrect read length");
        Assert.assertEquals(second.getBaseQualityString().length(), expectedRead2Length, "Incorrect quality string length");
    }
}
Also used : FastqReader(htsjdk.samtools.fastq.FastqReader) FastqRecord(htsjdk.samtools.fastq.FastqRecord) File(java.io.File) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test) CommandLineProgramTest(org.broadinstitute.hellbender.CommandLineProgramTest)

Aggregations

FastqReader (htsjdk.samtools.fastq.FastqReader)6 FastqRecord (htsjdk.samtools.fastq.FastqRecord)4 File (java.io.File)3 CommandLineProgramTest (org.broadinstitute.hellbender.CommandLineProgramTest)2 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)2 Test (org.testng.annotations.Test)2 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 BeforeClass (org.testng.annotations.BeforeClass)1