Search in sources :

Example 1 with SAMRecordToGATKReadAdapter

use of org.broadinstitute.hellbender.utils.read.SAMRecordToGATKReadAdapter in project gatk by broadinstitute.

the class SAMRecordSerializerUnitTest method testChangingContigsOnHeaderlessSAMRecord.

@Test
public void testChangingContigsOnHeaderlessSAMRecord() {
    final SparkConf conf = new SparkConf().set("spark.kryo.registrator", "org.broadinstitute.hellbender.engine.spark.SAMRecordSerializerUnitTest$TestGATKRegistrator");
    final SAMRecord read = ((SAMRecordToGATKReadAdapter) ArtificialReadUtils.createHeaderlessSamBackedRead("read1", "1", 100, 50)).getEncapsulatedSamRecord();
    final SAMRecord roundTrippedRead = SparkTestUtils.roundTripInKryo(read, SAMRecord.class, conf);
    Assert.assertEquals(roundTrippedRead, read, "\nActual read: " + roundTrippedRead.getSAMString() + "\nExpected read: " + read.getSAMString());
    read.setReferenceName("2");
    read.setAlignmentStart(1);
    final SAMRecord roundTrippedRead2 = SparkTestUtils.roundTripInKryo(read, SAMRecord.class, conf);
    Assert.assertEquals(roundTrippedRead2, read, "\nActual read: " + roundTrippedRead2.getSAMString() + "\nExpected read: " + read.getSAMString());
}
Also used : SAMRecordToGATKReadAdapter(org.broadinstitute.hellbender.utils.read.SAMRecordToGATKReadAdapter) SAMRecord(htsjdk.samtools.SAMRecord) SparkConf(org.apache.spark.SparkConf) Test(org.testng.annotations.Test)

Example 2 with SAMRecordToGATKReadAdapter

use of org.broadinstitute.hellbender.utils.read.SAMRecordToGATKReadAdapter in project gatk by broadinstitute.

the class SAMRecordSerializerUnitTest method testSerializerRoundTripHeaderlessSAMRecord.

@Test
public void testSerializerRoundTripHeaderlessSAMRecord() {
    SparkConf conf = new SparkConf().set("spark.kryo.registrator", "org.broadinstitute.hellbender.engine.spark.SAMRecordSerializerUnitTest$TestGATKRegistrator");
    // check round trip with no header
    final SAMRecord read = ((SAMRecordToGATKReadAdapter) ArtificialReadUtils.createHeaderlessSamBackedRead("read1", "1", 100, 50)).getEncapsulatedSamRecord();
    final SAMRecord roundTrippedRead = SparkTestUtils.roundTripInKryo(read, SAMRecord.class, conf);
    Assert.assertEquals(roundTrippedRead, read, "\nActual read: " + roundTrippedRead.getSAMString() + "\nExpected read: " + read.getSAMString());
}
Also used : SAMRecordToGATKReadAdapter(org.broadinstitute.hellbender.utils.read.SAMRecordToGATKReadAdapter) SAMRecord(htsjdk.samtools.SAMRecord) SparkConf(org.apache.spark.SparkConf) Test(org.testng.annotations.Test)

Example 3 with SAMRecordToGATKReadAdapter

use of org.broadinstitute.hellbender.utils.read.SAMRecordToGATKReadAdapter in project gatk by broadinstitute.

the class ReadsDataSourceUnitTest method getFileWithAddedContig.

// Copy the reads in the inputFile to the output file, adding an extra contig to the sequence dictionary
// and a read referencing that contig
private File getFileWithAddedContig(final Path inputPath, final String extraContig, final String outputName, final String extension) {
    final File outputFile = BaseTest.createTempFile(outputName, extension);
    try (ReadsDataSource readsSource = new ReadsDataSource(inputPath)) {
        SAMFileHeader header = readsSource.getHeader();
        SAMSequenceRecord fakeSequenceRec = new SAMSequenceRecord(extraContig, 100);
        header.addSequence(fakeSequenceRec);
        try (final SAMFileGATKReadWriter gatkReadWriter = new SAMFileGATKReadWriter(ReadUtils.createCommonSAMWriter(outputFile, null, header, true, true, false))) {
            for (final GATKRead read : readsSource) {
                gatkReadWriter.addRead(read);
            }
            // use the contig name in the read name to make it easy to see where this read came from
            SAMRecord samRec = new SAMRecord(header);
            samRec.setReadName(extraContig + "_READ");
            samRec.setReferenceName(extraContig);
            samRec.setAlignmentStart(5);
            samRec.setReadBases(new byte[] { 'a', 'c', 'g', 't' });
            gatkReadWriter.addRead(new SAMRecordToGATKReadAdapter(samRec));
        }
    }
    return outputFile;
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) SAMRecordToGATKReadAdapter(org.broadinstitute.hellbender.utils.read.SAMRecordToGATKReadAdapter) SAMFileGATKReadWriter(org.broadinstitute.hellbender.utils.read.SAMFileGATKReadWriter) File(java.io.File)

Example 4 with SAMRecordToGATKReadAdapter

use of org.broadinstitute.hellbender.utils.read.SAMRecordToGATKReadAdapter in project gatk by broadinstitute.

the class SATagBuilder method getArtificialReadsBasedOnSATag.

/**
     * Returns a list of artificial GATKReads corresponding to the reads described by the SA tag in read.
     * Fills as much information as can be inferred from the original read onto the artificial read copies
     * This function is only used for testing (e.g. testGetArtificialReadsBasedOnSATag, testEmptyNMTagSupport)
     *
     * @param header the header to be used in constructing artificial reads
     */
public List<GATKRead> getArtificialReadsBasedOnSATag(SAMFileHeader header) {
    List<GATKRead> output = new ArrayList<>(supplementaryReads.size());
    GATKRead readCopy = read.copy();
    readCopy.setAttribute("SA", getTag());
    SAMRecord record = readCopy.convertToSAMRecord(header);
    List<SAMRecord> readRecords = SAMUtils.getOtherCanonicalAlignments(record);
    for (SAMRecord artificialRead : readRecords) {
        output.add(new SAMRecordToGATKReadAdapter(artificialRead));
    }
    return output;
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) SAMRecordToGATKReadAdapter(org.broadinstitute.hellbender.utils.read.SAMRecordToGATKReadAdapter) SAMRecord(htsjdk.samtools.SAMRecord) ArrayList(java.util.ArrayList)

Example 5 with SAMRecordToGATKReadAdapter

use of org.broadinstitute.hellbender.utils.read.SAMRecordToGATKReadAdapter in project gatk by broadinstitute.

the class CollectQualityYieldMetrics method doWork.

/**
     * Main method for the program.  Checks that all input files are present and
     * readable and that the output file can be written to.  Then iterates through
     * all the records accumulating metrics.  Finally writes metrics file
     */
@Override
protected Object doWork() {
    final ProgressLogger progress = new ProgressLogger(logger);
    File output = new File(qualityYieldMetricsArgs.output);
    // Some quick parameter checking
    IOUtil.assertFileIsReadable(INPUT);
    IOUtil.assertFileIsWritable(output);
    logger.info("Reading input file and calculating metrics.");
    final SamReader sam = SamReaderFactory.makeDefault().referenceSequence(REFERENCE_SEQUENCE).open(INPUT);
    final MetricsFile<QualityYieldMetrics, Integer> metricsFile = getMetricsFile();
    final QualityYieldMetrics metrics = new QualityYieldMetrics();
    metrics.setUseOriginalQualities(qualityYieldMetricsArgs.useOriginalQualities);
    for (final SAMRecord rec : sam) {
        metrics.addRead(new SAMRecordToGATKReadAdapter(rec));
        progress.record(rec);
    }
    metrics.finish();
    metricsFile.addMetric(metrics);
    metricsFile.write(output);
    return null;
}
Also used : SamReader(htsjdk.samtools.SamReader) QualityYieldMetrics(org.broadinstitute.hellbender.metrics.QualityYieldMetrics) SAMRecordToGATKReadAdapter(org.broadinstitute.hellbender.utils.read.SAMRecordToGATKReadAdapter) SAMRecord(htsjdk.samtools.SAMRecord) ProgressLogger(org.broadinstitute.hellbender.utils.runtime.ProgressLogger) MetricsFile(htsjdk.samtools.metrics.MetricsFile) File(java.io.File)

Aggregations

SAMRecordToGATKReadAdapter (org.broadinstitute.hellbender.utils.read.SAMRecordToGATKReadAdapter)8 GATKRead (org.broadinstitute.hellbender.utils.read.GATKRead)5 Test (org.testng.annotations.Test)5 SAMRecord (htsjdk.samtools.SAMRecord)4 File (java.io.File)2 SparkConf (org.apache.spark.SparkConf)2 SamReader (htsjdk.samtools.SamReader)1 MetricsFile (htsjdk.samtools.metrics.MetricsFile)1 ArrayList (java.util.ArrayList)1 JavaSparkContext (org.apache.spark.api.java.JavaSparkContext)1 QualityYieldMetrics (org.broadinstitute.hellbender.metrics.QualityYieldMetrics)1 SAMFileGATKReadWriter (org.broadinstitute.hellbender.utils.read.SAMFileGATKReadWriter)1 ProgressLogger (org.broadinstitute.hellbender.utils.runtime.ProgressLogger)1 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)1