/** * Returns true if the read does not belong to a contig, i.e. it's location is GenomeLoc.UNMAPPED. * NOTE: A read can have a mapped GenomeLoc and still have an unmapped flag! * * @param r record * @return true if read is unmapped to a genome loc */ public static boolean isReadGenomeLocUnmapped(final SAMRecord r) { return SAMRecord.NO_ALIGNMENT_REFERENCE_NAME.equals(r.getReferenceName()); }
/** * @return reference name, null if this is unmapped */ @Override public String getContig() { if (getReadUnmappedFlag()) { return null; } else { return getReferenceName(); } }
/** * @return reference name, null if this is unmapped */ @Override public String getContig() { if (getReadUnmappedFlag()) { return null; } else { return getReferenceName(); } }
public boolean hasNext() { if (chr == null && currentRecord != null) { return true; } if (currentRecord == null || (chr != null && !chr.equals(currentRecord.getReferenceName()))) { return false; } else { return contained ? currentRecord.getAlignmentEnd() <= end : currentRecord.getAlignmentStart() <= end; } }
public UnsupportedCigarOperatorException(final CigarOperator co, final SAMRecord read, final String message) { super(String.format( "Unsupported CIGAR operator %s in read %s at %s:%d. %s", co, read.getReadName(), read.getReferenceName(), read.getAlignmentStart(), message)); } }
@Override public String getReferenceName() { if (!initializedFields.contains(LazyField.REFERENCE_NAME)) { setReferenceName(getReferenceNameImpl()); } return super.getReferenceName(); }
@Override public String getReferenceName() { if (!initializedFields.contains(LazyField.REFERENCE_NAME)) { setReferenceName(getReferenceNameImpl()); } return super.getReferenceName(); }
public static String getMrnm(SAMRecord record) { if (record.getMateReferenceName() == null) { return "*"; } if (record.getReferenceName().equals(record.getMateReferenceName())) { return "="; } return record.getMateReferenceName(); }
private void advanceToFirstRecord() { while (wrappedIterator.hasNext()) { currentRecord = wrappedIterator.next(); if (!currentRecord.getReferenceName().equals(chr)) { break; //currentRecord is 1-based, end-inclusive. //start/end are 0-based, end-exclusive } else if ((contained && currentRecord.getAlignmentStart()-1 >= start) || (!contained && currentRecord.getAlignmentEnd()-1 >= start)) { break; } } }
/** * Records that a given record has been processed and triggers logging if necessary. * @return boolean true if logging was triggered, false otherwise */ public synchronized boolean record(final SAMRecord rec) { if (rec.getReferenceIndex() == SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX) { return record(null, 0); } else { return record(rec.getReferenceName(), rec.getAlignmentStart()); } }
private void warnIfReferenceIsTooLargeForBinField(final SAMRecord rec) { final SAMSequenceRecord sequence = rec.getHeader() != null ? rec.getHeader().getSequence(rec.getReferenceName()) : null; if (!isReferenceSizeWarningShowed && sequence != null && SAMUtils.isReferenceSequenceCompatibleWithBAI(sequence) && rec.getValidationStringency() != ValidationStringency.SILENT) { LOG.warn("Reference length is too large for BAM bin field. Values in the bin field could be incorrect."); isReferenceSizeWarningShowed = true; } }
private void warnIfReferenceIsTooLargeForBinField(final SAMRecord rec) { final SAMSequenceRecord sequence = rec.getHeader() != null ? rec.getHeader().getSequence(rec.getReferenceName()) : null; if (!isReferenceSizeWarningShowed && sequence != null && SAMUtils.isReferenceSequenceCompatibleWithBAI(sequence) && rec.getValidationStringency() != ValidationStringency.SILENT) { LOG.warn("Reference length is too large for BAM bin field. Values in the bin field could be incorrect."); isReferenceSizeWarningShowed = true; } }
public ChimericAlignment(SAMRecord r) { this.rname = r.getReferenceName(); this.pos = r.getAlignmentStart(); this.isNegativeStrand = r.getReadNegativeStrandFlag(); this.cigar = r.getCigar(); this.mapq = r.getMappingQuality(); this.nm = r.getIntegerAttribute(SAMTag.NM.name()); } public ChimericAlignment(String str) {
@Test public void test_chrM_1500_location() throws IOException { CRAMFileReader reader = new CRAMFileReader(cramFile, indexFile, source); reader.setValidationStringency(ValidationStringency.SILENT); CloseableIterator<SAMRecord> iterator = reader.queryAlignmentStart("chrM", 1500); Assert.assertTrue(iterator.hasNext()); SAMRecord record = iterator.next(); Assert.assertEquals(record.getReferenceName(), "chrM"); Assert.assertTrue(record.getAlignmentStart() >= 1500); }
@Test(dataProvider = "samFilesWithSpaceInSequenceName") public void testSamSequenceTruncation(final String filename) { final SamReader reader = SamReaderFactory.makeDefault().open(new File(TEST_DATA_DIR, filename)); for (final SAMSequenceRecord sequence : reader.getFileHeader().getSequenceDictionary().getSequences()) { Assert.assertFalse(sequence.getSequenceName().contains(" "), sequence.getSequenceName()); } for (final SAMRecord rec : reader) { Assert.assertFalse(rec.getReferenceName().contains(" ")); } CloserUtil.close(reader); }
@Test public void test() throws IOException { CRAMFileReader reader = new CRAMFileReader(new ByteArraySeekableStream(cramBytes), new ByteArraySeekableStream(indexBytes), source, ValidationStringency.SILENT); for (SAMSequenceRecord sequenceRecord : reader.getFileHeader().getSequenceDictionary().getSequences()) { final CloseableIterator<SAMRecord> iterator = reader.queryAlignmentStart(sequenceRecord.getSequenceName(), 1); Assert.assertNotNull(iterator); Assert.assertTrue(iterator.hasNext()); SAMRecord record = iterator.next(); Assert.assertEquals(record.getReferenceName(), sequenceRecord.getSequenceName()); Assert.assertEquals(record.getAlignmentStart(), 1); } }
private byte[] compressScores (SAMRecord record, byte[] ref, QualityScorePreservation p) { ReferenceTracks tracks = new ReferenceTracks(0, record.getReferenceName(), ref); Sam2CramRecordFactory f = new Sam2CramRecordFactory(ref, record.getHeader(), CramVersions.CRAM_v3); CramCompressionRecord cramRecord = f.createCramRecord(record); p.addQualityScores(record, cramRecord, tracks); if (!cramRecord.isForcePreserveQualityScores()) { CramNormalizer.restoreQualityScores((byte) 30, Collections.singletonList(cramRecord)); } return cramRecord.qualityScores; } }
/** * Strip mapping information from a SAMRecord, but preserve it in the 'O' tags if it isn't already set. */ public static void makeReadUnmappedWithOriginalTags(final SAMRecord rec) { if (!hasOriginalMappingInformation(rec)) { rec.setAttribute(SAMTag.OP.name(), rec.getAlignmentStart()); rec.setAttribute(SAMTag.OC.name(), rec.getCigarString()); rec.setAttribute(SAMTag.OF.name(), rec.getFlags()); rec.setAttribute(SAMTag.OR.name(), rec.getReferenceName()); } makeReadUnmapped(rec); }
/** * Strip mapping information from a SAMRecord, but preserve it in the 'O' tags if it isn't already set. */ public static void makeReadUnmappedWithOriginalTags(final SAMRecord rec) { if (!hasOriginalMappingInformation(rec)) { rec.setAttribute(SAMTag.OP.name(), rec.getAlignmentStart()); rec.setAttribute(SAMTag.OC.name(), rec.getCigarString()); rec.setAttribute(SAMTag.OF.name(), rec.getFlags()); rec.setAttribute(SAMTag.OR.name(), rec.getReferenceName()); } makeReadUnmapped(rec); }
/** * Strip mapping information from a SAMRecord, but preserve it in the 'O' tags if it isn't already set. */ public static void makeReadUnmappedWithOriginalTags(final SAMRecord rec) { if (!hasOriginalMappingInformation(rec)) { rec.setAttribute(SAMTag.OP.name(), rec.getAlignmentStart()); rec.setAttribute(SAMTag.OC.name(), rec.getCigarString()); rec.setAttribute(SAMTag.OF.name(), rec.getFlags()); rec.setAttribute(SAMTag.OR.name(), rec.getReferenceName()); } makeReadUnmapped(rec); }