public static String getMrnm(SAMRecord record) { if (record.getMateReferenceName() == null) { return "*"; } if (record.getReferenceName().equals(record.getMateReferenceName())) { return "="; } return record.getMateReferenceName(); }
@Override public String getMateReferenceName() { if (!initializedFields.contains(LazyField.MATE_REFERENCE_NAME)) { setMateReferenceName(getMateReferenceNameImpl()); } return super.getMateReferenceName(); }
@Override public String getMateReferenceName() { if (!initializedFields.contains(LazyField.MATE_REFERENCE_NAME)) { setMateReferenceName(getMateReferenceNameImpl()); } return super.getMateReferenceName(); }
public static boolean iSizeTooBigToMove(SAMRecord read, int maxInsertSizeForMovingReadPairs) { return ( read.getReadPairedFlag() && ! read.getMateUnmappedFlag() && !read.getReferenceName().equals(read.getMateReferenceName()) ) // maps to different chromosomes || Math.abs(read.getInferredInsertSize()) > maxInsertSizeForMovingReadPairs; // we won't try to move such a read }
@Test public void testNullHeaderMateReferenceName() { final SAMRecord sam = createTestRecordHelper(); final SAMFileHeader samHeader = sam.getHeader(); Assert.assertTrue(null != samHeader); final String originalMateRefName = sam.getMateReferenceName(); // setting header to null retains the previously assigned mate ref name sam.setHeader(null); Assert.assertTrue(originalMateRefName.equals(sam.getMateReferenceName())); // null header allows mate reference name to be set to NO_ALIGNMENT_REFERENCE_NAME sam.setMateReferenceName(SAMRecord.NO_ALIGNMENT_REFERENCE_NAME); Assert.assertTrue(sam.getMateReferenceName().equals(SAMRecord.NO_ALIGNMENT_REFERENCE_NAME)); Assert.assertTrue(sam.getMateReferenceIndex().equals(SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX)); // null header allows reference name to be reset to a valid namw sam.setMateReferenceName(originalMateRefName); Assert.assertTrue(sam.getMateReferenceName().equals(originalMateRefName)); }
@Test public void testMateReferenceIndex() { // NO_ALIGNMENT_REFERENCE SAMRecord sam = createTestRecordHelper(); sam.setMateReferenceIndex(SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX); Assert.assertTrue(sam.getMateReferenceIndex().equals(SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX)); Assert.assertTrue(sam.getMateReferenceName().equals(SAMRecord.NO_ALIGNMENT_REFERENCE_NAME)); // valid reference sam = createTestRecordHelper(); sam.setMateReferenceIndex(3); Assert.assertTrue(sam.getMateReferenceIndex().equals(3)); Assert.assertTrue(sam.getMateReferenceName().equals("chr4")); }
@Test public void testMateReferenceName() { // NO_ALIGNMENT_NAME SAMRecord sam = createTestRecordHelper(); sam.setMateReferenceName(SAMRecord.NO_ALIGNMENT_REFERENCE_NAME); Assert.assertTrue(sam.getMateReferenceName().equals(SAMRecord.NO_ALIGNMENT_REFERENCE_NAME)); Assert.assertTrue(sam.getMateReferenceIndex().equals(SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX)); // valid reference sam = createTestRecordHelper(); sam.setMateReferenceName("chr4"); Assert.assertTrue(sam.getMateReferenceName().equals("chr4")); Assert.assertTrue(sam.getMateReferenceIndex().equals(3)); // unresolvable reference sam = createTestRecordHelper(); sam.setMateReferenceName("unresolvableName"); Assert.assertTrue(sam.getMateReferenceName().equals("unresolvableName")); Assert.assertTrue(sam.getMateReferenceIndex().equals(SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX)); }
return record.getCigarString(); case RNEXT: return record.getMateReferenceName(); case PNEXT: return Integer.toString(record.getMateAlignmentStart());
if (read.getMateReferenceName().equals(SAMRecord.NO_ALIGNMENT_REFERENCE_NAME)) { Assert.assertEquals(read.getMateAlignmentStart(), SAMRecord.NO_ALIGNMENT_START); Assert.assertTrue(read.getMateUnmappedFlag()); !read.getReferenceName().equals(read.getMateReferenceName())) { Assert.assertEquals(read.getInferredInsertSize(), 0); } else {
@Test public void testNullHeaderMateReferenceIndex() { SAMRecord sam = createTestRecordHelper(); final SAMFileHeader samHeader = sam.getHeader(); sam.setMateReferenceName("chr1"); int originalMateRefIndex = sam.getMateReferenceIndex(); Assert.assertTrue(SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX != originalMateRefIndex); // setting header to null resets the mate reference index to null sam.setHeader(null); Assert.assertTrue(null == sam.mMateReferenceIndex); // restoring the header to restores the reference index back to the original sam.setHeader(samHeader); Assert.assertTrue(sam.getMateReferenceIndex().equals(originalMateRefIndex)); // setting the header to null allows setting the mate reference index to NO_ALIGNMENT_REFERENCE_INDEX sam.setHeader(null); sam.setMateReferenceIndex(SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX); Assert.assertTrue(sam.getMateReferenceIndex().equals(SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX)); Assert.assertTrue(sam.getMateReferenceName().equals(SAMRecord.NO_ALIGNMENT_REFERENCE_NAME)); // force the internal SAMRecord mate reference index value to (null) initial state sam = new SAMRecord(null); Assert.assertTrue(null == sam.mMateReferenceIndex); Assert.assertTrue(sam.getMateReferenceIndex() == SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX); // an unresolvable mate reference name doesn't throw final String unresolvableRefName = "unresolvable"; sam.setMateReferenceName(unresolvableRefName); // now force the SAMRecord to try to resolve the unresolvable mate reference name sam.setHeader(samHeader); Assert.assertTrue(null == sam.mMateReferenceIndex); Assert.assertTrue(sam.getMateReferenceIndex() == SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX); }
private void validateRecords(final List<SAMRecord> expectedRecords, ByteArrayInputStream is, ReferenceSource referenceSource) { CRAMFileReader cReader = new CRAMFileReader(null, is, referenceSource); SAMRecordIterator iterator2 = cReader.getIterator(); int index = 0; while (iterator2.hasNext()) { SAMRecord actualRecord = iterator2.next(); SAMRecord expectedRecord = expectedRecords.get(index++); Assert.assertEquals(actualRecord.getReadName(), expectedRecord.getReadName()); Assert.assertEquals(actualRecord.getFlags(), expectedRecord.getFlags()); Assert.assertEquals(actualRecord.getAlignmentStart(), expectedRecord.getAlignmentStart()); Assert.assertEquals(actualRecord.getAlignmentEnd(), expectedRecord.getAlignmentEnd()); Assert.assertEquals(actualRecord.getReferenceName(), expectedRecord.getReferenceName()); Assert.assertEquals(actualRecord.getMateAlignmentStart(), expectedRecord.getMateAlignmentStart()); Assert.assertEquals(actualRecord.getMateReferenceName(), expectedRecord.getMateReferenceName()); Assert.assertEquals(actualRecord.getReadBases(), expectedRecord.getReadBases()); Assert.assertEquals(actualRecord.getBaseQualities(), expectedRecord.getBaseQualities()); } cReader.close(); }
/** * Determines whether a SAMRecord matches this filter. Takes record, finds * the location of its mate using the MC tag. Checks if either record * overlaps the current interval using overlap detector. If yes, return * false -> don't filter it out. * * If a read is secondary, supplementary, or single ended, filter read out. * Use {@link IntervalFilter} if you want to keep these reads, but NOTE: the * resulting bam may not be valid. * * @param record the SAMRecord to evaluate * @return true if the SAMRecord matches the filter, otherwise false */ @Override public boolean filterOut(final SAMRecord record) { if (record.isSecondaryOrSupplementary() || !record.getReadPairedFlag()) { return true; } if (!record.getReadUnmappedFlag() && hasOverlaps(record.getReferenceName(), record.getStart(), record.getEnd())) { return false; } return record.getMateUnmappedFlag() || !hasOverlaps(record.getMateReferenceName(), record.getMateAlignmentStart(), SAMUtils.getMateAlignmentEnd(record)); }
public static Alignment buildAlignment(SAMRecord record, Map<String, Object> attributes, String referenceSequence) { List<Alignment.AlignmentDifference> differences; differences = AlignmentUtils.getDifferencesFromCigar(record, referenceSequence, Integer.MAX_VALUE); Alignment alignment = new Alignment(record.getReadName(), record.getReferenceName(), record.getAlignmentStart(), record.getAlignmentEnd(), record.getUnclippedStart(), record.getUnclippedEnd(), record.getReadLength(), record.getMappingQuality(), record.getBaseQualityString(),//.replace("\\", "\\\\").replace("\"", "\\\""), record.getMateReferenceName(), record.getMateAlignmentStart(), record.getInferredInsertSize(), record.getFlags(), differences, attributes); return alignment; } public static Alignment buildAlignment(SAMRecord record, String referenceSequence) {
/** * Determines whether a SAMRecord matches this filter. Takes record, finds * the location of its mate using the MC tag. Checks if either record * overlaps the current interval using overlap detector. If yes, return * false -> don't filter it out. * * If a read is secondary, supplementary, or single ended, filter read out. * Use {@link IntervalFilter} if you want to keep these reads, but NOTE: the * resulting bam may not be valid. * * @param record the SAMRecord to evaluate * @return true if the SAMRecord matches the filter, otherwise false */ @Override public boolean filterOut(final SAMRecord record) { if (record.isSecondaryOrSupplementary() || !record.getReadPairedFlag()) { return true; } if (!record.getReadUnmappedFlag() && hasOverlaps(record.getReferenceName(), record.getStart(), record.getEnd())) { return false; } return record.getMateUnmappedFlag() || !hasOverlaps(record.getMateReferenceName(), record.getMateAlignmentStart(), SAMUtils.getMateAlignmentEnd(record)); }
/** * * @return String representation of this. * @deprecated This method is not guaranteed to return a valid SAM text representation of the SAMRecord. * To get standard SAM text representation, {@link SAMRecord#getSAMString}. */ @Deprecated public String format() { final StringBuilder buffer = new StringBuilder(); addField(buffer, getReadName(), null, null); addField(buffer, getFlags(), null, null); addField(buffer, getReferenceName(), null, "*"); addField(buffer, getAlignmentStart(), 0, "*"); addField(buffer, getMappingQuality(), 0, "0"); addField(buffer, getCigarString(), null, "*"); addField(buffer, getMateReferenceName(), null, "*"); addField(buffer, getMateAlignmentStart(), 0, "*"); addField(buffer, getInferredInsertSize(), 0, "*"); addField(buffer, getReadString(), null, "*"); addField(buffer, getBaseQualityString(), null, "*"); if (mAttributes != null) { SAMBinaryTagAndValue entry = getBinaryAttributes(); while (entry != null) { addField(buffer, formatTagValue(entry.tag, entry.value)); entry = entry.getNext(); } } return buffer.toString(); }
/** * * @return String representation of this. * @deprecated This method is not guaranteed to return a valid SAM text representation of the SAMRecord. * To get standard SAM text representation, {@link SAMRecord#getSAMString}. */ @Deprecated public String format() { final StringBuilder buffer = new StringBuilder(); addField(buffer, getReadName(), null, null); addField(buffer, getFlags(), null, null); addField(buffer, getReferenceName(), null, "*"); addField(buffer, getAlignmentStart(), 0, "*"); addField(buffer, getMappingQuality(), 0, "0"); addField(buffer, getCigarString(), null, "*"); addField(buffer, getMateReferenceName(), null, "*"); addField(buffer, getMateAlignmentStart(), 0, "*"); addField(buffer, getInferredInsertSize(), 0, "*"); addField(buffer, getReadString(), null, "*"); addField(buffer, getBaseQualityString(), null, "*"); if (mAttributes != null) { SAMBinaryTagAndValue entry = getBinaryAttributes(); while (entry != null) { addField(buffer, formatTagValue(entry.tag, entry.value)); entry = entry.getNext(); } } return buffer.toString(); }
/** * * @return String representation of this. * @deprecated This method is not guaranteed to return a valid SAM text representation of the SAMRecord. * To get standard SAM text representation, use htsjdk.samtools.SAMRecord#getSAMString(). */ public String format() { final StringBuilder buffer = new StringBuilder(); addField(buffer, getReadName(), null, null); addField(buffer, getFlags(), null, null); addField(buffer, getReferenceName(), null, "*"); addField(buffer, getAlignmentStart(), 0, "*"); addField(buffer, getMappingQuality(), 0, "0"); addField(buffer, getCigarString(), null, "*"); addField(buffer, getMateReferenceName(), null, "*"); addField(buffer, getMateAlignmentStart(), 0, "*"); addField(buffer, getInferredInsertSize(), 0, "*"); addField(buffer, getReadString(), null, "*"); addField(buffer, getBaseQualityString(), null, "*"); if (mAttributes != null) { SAMBinaryTagAndValue entry = getBinaryAttributes(); while (entry != null) { addField(buffer, formatTagValue(entry.tag, entry.value)); entry = entry.getNext(); } } return buffer.toString(); }
private void advance() { int candidateIndex = getIndexOfMinAlignment(); if (candidateIndex < 0) { next = null; } else { next = records[candidateIndex]; SAMSequenceRecord sequence = header.getSequence(next.getReferenceName()); next.setHeader(header); next.setReferenceIndex(sequence.getSequenceIndex()); next.setReadName(sources[candidateIndex].id + delim + next.getReadName()); if (next.getMateReferenceIndex() == SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX) { next.setMateAlignmentStart(SAMRecord.NO_ALIGNMENT_START); } else { SAMSequenceRecord mateSequence = header.getSequence(next.getMateReferenceName()); next.setMateReferenceIndex(mateSequence.getSequenceIndex()); } if (sources[candidateIndex].it.hasNext()) records[candidateIndex] = sources[candidateIndex].it.next(); else records[candidateIndex] = null; } }
newSAM.setMateReferenceName(getMateReferenceName()); newSAM.setMateAlignmentStart(getMateAlignmentStart()); newSAM.setInferredInsertSize(getInferredInsertSize());
newSAM.setMateReferenceName(getMateReferenceName()); newSAM.setMateAlignmentStart(getMateAlignmentStart()); newSAM.setInferredInsertSize(getInferredInsertSize());