Java Code Examples for htsjdk.samtools.SAMRecord#setDuplicateReadFlag()

The following examples show how to use htsjdk.samtools.SAMRecord#setDuplicateReadFlag() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReadContextCounterTest.java    From hmftools with GNU General Public License v3.0 6 votes vote down vote up
@NotNull
public static SAMRecord buildSamRecord(final int alignmentStart, @NotNull final String cigar, @NotNull final String readString,
        @NotNull final String qualities) {
    final SAMRecord record = new SAMRecord(null);
    record.setAlignmentStart(alignmentStart);
    record.setCigarString(cigar);
    record.setReadString(readString);
    record.setReadNegativeStrandFlag(false);
    record.setBaseQualityString(qualities);
    record.setMappingQuality(20);
    record.setDuplicateReadFlag(false);
    record.setReadUnmappedFlag(false);
    record.setProperPairFlag(true);
    record.setReadPairedFlag(true);
    return record;
}
 
Example 2
Source File: SAMRecordsTest.java    From hmftools with GNU General Public License v3.0 5 votes vote down vote up
@NotNull
public static SAMRecord buildSamRecord(final int alignmentStart, @NotNull final String cigar, @NotNull final String readString,
        @NotNull final String qualities) {
    final SAMRecord record = new SAMRecord(null);
    record.setAlignmentStart(alignmentStart);
    record.setCigarString(cigar);
    record.setReadString(readString);
    record.setReadNegativeStrandFlag(false);
    record.setBaseQualityString(qualities);
    record.setMappingQuality(20);
    record.setDuplicateReadFlag(false);
    record.setReadUnmappedFlag(false);
    return record;
}
 
Example 3
Source File: RefSequenceTest.java    From hmftools with GNU General Public License v3.0 5 votes vote down vote up
@NotNull
public static SAMRecord buildSamRecord(final int alignmentStart, @NotNull final String cigar, @NotNull final String readString,
        @NotNull final String qualities) {
    final SAMRecord record = new SAMRecord(null);
    record.setAlignmentStart(alignmentStart);
    record.setCigarString(cigar);
    record.setReadString(readString);
    record.setReadNegativeStrandFlag(false);
    record.setBaseQualityString(qualities);
    record.setMappingQuality(20);
    record.setDuplicateReadFlag(false);
    record.setReadUnmappedFlag(false);
    return record;
}
 
Example 4
Source File: ReadContextFactoryTest.java    From hmftools with GNU General Public License v3.0 5 votes vote down vote up
@NotNull
static SAMRecord buildSamRecord(@NotNull final String cigar, @NotNull final String readString, @NotNull final String qualities) {
    final SAMRecord record = new SAMRecord(null);
    record.setAlignmentStart(1000);
    record.setCigarString(cigar);
    record.setReadString(readString);
    record.setReadNegativeStrandFlag(false);
    record.setBaseQualityString(qualities);
    record.setMappingQuality(20);
    record.setDuplicateReadFlag(false);
    record.setReadUnmappedFlag(false);
    return record;
}
 
Example 5
Source File: TestUtils.java    From hmftools with GNU General Public License v3.0 5 votes vote down vote up
@NotNull
public static SAMRecord buildSamRecord(final int alignmentStart, @NotNull final String cigar, @NotNull final String readString,
        @NotNull final String qualities, final boolean negativeStrand) {
    final SAMRecord record = new SAMRecord(null);
    record.setAlignmentStart(alignmentStart);
    record.setCigarString(cigar);
    record.setReadString(readString);
    record.setReadNegativeStrandFlag(negativeStrand);
    record.setBaseQualityString(qualities);
    record.setMappingQuality(20);
    record.setDuplicateReadFlag(false);
    record.setReadUnmappedFlag(false);
    return record;
}
 
Example 6
Source File: DefaultSamFilterTest.java    From rtg-tools with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void testFilterRecordByFlags() {
  final SamFilterParams.SamFilterParamsBuilder builder = SamFilterParams.builder();
  final SAMRecord rec = new SAMRecord(new SAMFileHeader()); // Not unmapped but alignment position == 0
  rec.setReadUnmappedFlag(true);      // Unmapped with alignment position == 0
  assertTrue(new DefaultSamFilter(builder.create()).acceptRecord(rec));
  builder.excludeUnmapped(true);
  assertFalse(new DefaultSamFilter(builder.create()).acceptRecord(rec));

  rec.setReadUnmappedFlag(false);      // Mapped with alignment position == 10
  rec.setAlignmentStart(10);
  assertTrue(new DefaultSamFilter(builder.create()).acceptRecord(rec));

  rec.setDuplicateReadFlag(true);      // Now a duplicate
  assertTrue(new DefaultSamFilter(builder.create()).acceptRecord(rec));
  builder.excludeDuplicates(true);
  assertFalse(new DefaultSamFilter(builder.create()).acceptRecord(rec));
  builder.excludeDuplicates(false);

  rec.setReadPairedFlag(true); // Now paired-end

  builder.excludeUnmated(true);
  assertFalse(new DefaultSamFilter(builder.create()).acceptRecord(rec));
  rec.setProperPairFlag(true); // Now properly paired (i.e. no longer unmated)
  assertTrue(new DefaultSamFilter(builder.create()).acceptRecord(rec));

  builder.excludeMated(true);
  assertFalse(new DefaultSamFilter(builder.create()).acceptRecord(rec));
}
 
Example 7
Source File: RevertSam.java    From picard with MIT License 4 votes vote down vote up
/**
 * Takes an individual SAMRecord and applies the set of changes/reversions to it that
 * have been requested by program level options.
 */
public void revertSamRecord(final SAMRecord rec) {
    if (RESTORE_ORIGINAL_QUALITIES) {
        final byte[] oq = rec.getOriginalBaseQualities();
        if (oq != null) {
            rec.setBaseQualities(oq);
            rec.setOriginalBaseQualities(null);
        }
    }

    if (REMOVE_DUPLICATE_INFORMATION) {
        rec.setDuplicateReadFlag(false);
    }

    if (REMOVE_ALIGNMENT_INFORMATION) {
        if (rec.getReadNegativeStrandFlag()) {
            rec.reverseComplement(true);
            rec.setReadNegativeStrandFlag(false);
        }

        // Remove all alignment based information about the read itself
        rec.setReferenceIndex(SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX);
        rec.setAlignmentStart(SAMRecord.NO_ALIGNMENT_START);
        rec.setCigarString(SAMRecord.NO_ALIGNMENT_CIGAR);
        rec.setMappingQuality(SAMRecord.NO_MAPPING_QUALITY);

        rec.setInferredInsertSize(0);
        rec.setNotPrimaryAlignmentFlag(false);
        rec.setProperPairFlag(false);
        rec.setReadUnmappedFlag(true);

        // Then remove any mate flags and info related to alignment
        rec.setMateAlignmentStart(SAMRecord.NO_ALIGNMENT_START);
        rec.setMateNegativeStrandFlag(false);
        rec.setMateReferenceIndex(SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX);
        rec.setMateUnmappedFlag(rec.getReadPairedFlag());

        if (RESTORE_HARDCLIPS) {
            String hardClippedBases = rec.getStringAttribute(AbstractAlignmentMerger.HARD_CLIPPED_BASES_TAG);
            String hardClippedQualities = rec.getStringAttribute(AbstractAlignmentMerger.HARD_CLIPPED_BASE_QUALITIES_TAG);
            if (hardClippedBases != null && hardClippedQualities != null) {
                // Record has already been reverse complemented if this was on the negative strand
                rec.setReadString(rec.getReadString() + hardClippedBases);
                rec.setBaseQualities(SAMUtils.fastqToPhred(SAMUtils.phredToFastq(rec.getBaseQualities()) + hardClippedQualities));

                // Remove hard clipping storage tags
                rec.setAttribute(AbstractAlignmentMerger.HARD_CLIPPED_BASES_TAG, null);
                rec.setAttribute(AbstractAlignmentMerger.HARD_CLIPPED_BASE_QUALITIES_TAG, null);
            }
        }

        // And then remove any tags that are calculated from the alignment
        ATTRIBUTE_TO_CLEAR.forEach(tag -> rec.setAttribute(tag, null));
    }
}