Source:
private void transferAlignmentInfoToFragment(final SAMRecord unaligned, final SAMRecord aligned, final boolean isContaminant, final boolean needsSafeReverseComplement) { setValuesFromAlignment(unaligned, aligned, needsSafeReverseComplement); updateCigarForTrimmedOrClippedBases(unaligned, aligned); if (SAMUtils.cigarMapsNoBasesToRef(unaligned.getCigar())) { log.warn("Record contains no unclipped bases; making unmapped: " + aligned); SAMUtils.makeReadUnmapped(unaligned); } else if (SAMUtils.recordMapsEntirelyBeyondEndOfReference(aligned)) { log.warn("Record mapped off end of reference; making unmapped: " + aligned); SAMUtils.makeReadUnmapped(unaligned); } else if (isContaminant) { if (numForeignContaminantWarnings < MAX_FOREIGN_CONTAM_WARN) { log.warn("Record looks like foreign contamination ; making unmapped: " + aligned); numForeignContaminantWarnings++; } if (numForeignContaminantWarnings == MAX_FOREIGN_CONTAM_WARN) { log.warn("No more warnings regarding foreign contamination; limit reached."); } unaligned.setAttribute("PA", String.join(",", aligned.getContig(), ((Integer) aligned.getAlignmentStart()).toString(), aligned.getCigarString(), ((Integer) aligned.getMappingQuality()).toString(), aligned.getStringAttribute(SAMTag.NM.name()))+";"); unaligned.setReadUnmappedFlag(true); unaligned.setMappingQuality(SAMRecord.NO_MAPPING_QUALITY); unaligned.setReferenceIndex(SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX); unaligned.setAlignmentStart(0); unaligned.setCigar(null); unaligned.setCigarString(SAMRecord.NO_ALIGNMENT_CIGAR); Optional<String> optionalComment = Optional.ofNullable(unaligned.getStringAttribute(SAMTag.CO.name())); unaligned.setAttribute(optionalComment.map(s -> s + " | ").orElse("") + SAMTag.CO.name(), "Cross-species contamination"); } }

Target:
private void transferAlignmentInfoToFragment(final SAMRecord unaligned, final SAMRecord aligned, final boolean isContaminant, final boolean needsSafeReverseComplement) { setValuesFromAlignment(unaligned, aligned, needsSafeReverseComplement); updateCigarForTrimmedOrClippedBases(unaligned, aligned); if (SAMUtils.cigarMapsNoBasesToRef(unaligned.getCigar())) { log.warn("Record contains no unclipped bases; making unmapped: " + aligned); SAMUtils.makeReadUnmapped(unaligned); } else if (SAMUtils.recordMapsEntirelyBeyondEndOfReference(aligned)) { log.warn("Record mapped off end of reference; making unmapped: " + aligned); SAMUtils.makeReadUnmapped(unaligned); } else if (isContaminant) { crossSpeciesReads++; if (unmappingReadsStrategy.isPopulatePaTag()) { unaligned.setAttribute("PA", encodeMappingInformation(aligned)); } if (unmappingReadsStrategy.isResetMappingInformation()) { unaligned.setReferenceIndex(SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX); unaligned.setAlignmentStart(SAMRecord.NO_ALIGNMENT_START); unaligned.setCigar(null); unaligned.setCigarString(SAMRecord.NO_ALIGNMENT_CIGAR); } unaligned.setReadUnmappedFlag(true); unaligned.setMappingQuality(SAMRecord.NO_MAPPING_QUALITY); Optional<String> optionalComment = Optional.ofNullable(unaligned.getStringAttribute(SAMTag.CO.name())); unaligned.setAttribute(optionalComment.map(s -> s + " | ").orElse("") + SAMTag.CO.name(), "Cross-species contamination"); } }