diff --git a/adam-core/src/main/scala/org/bdgenomics/adam/converters/AlignmentRecordConverter.scala b/adam-core/src/main/scala/org/bdgenomics/adam/converters/AlignmentRecordConverter.scala index 649243824e..c5544faa1b 100644 --- a/adam-core/src/main/scala/org/bdgenomics/adam/converters/AlignmentRecordConverter.scala +++ b/adam-core/src/main/scala/org/bdgenomics/adam/converters/AlignmentRecordConverter.scala @@ -115,7 +115,8 @@ class AlignmentRecordConverter extends Serializable { // set the cigar, if provided Option(adamRecord.getCigar).map(_.toString).foreach(builder.setCigarString) - + // set the old cigar, if provided + Option(adamRecord.getOldCigar).map(_.toString).foreach(v => builder.setAttribute("OC", v)) // set mapping flags Option(adamRecord.getReadNegativeStrand) .foreach(v => builder.setReadNegativeStrandFlag(v.booleanValue)) @@ -125,6 +126,8 @@ class AlignmentRecordConverter extends Serializable { .foreach(v => builder.setSupplementaryAlignmentFlag(v.booleanValue)) Option(adamRecord.getStart) .foreach(s => builder.setAlignmentStart(s.toInt + 1)) + Option(adamRecord.getOldPosition) + .foreach(s => builder.setAttribute("OP", s.toInt + 1)) Option(adamRecord.getMapq).foreach(v => builder.setMappingQuality(v)) } else { // mapping quality must be 0 if read is unmapped diff --git a/adam-core/src/main/scala/org/bdgenomics/adam/converters/SAMRecordConverter.scala b/adam-core/src/main/scala/org/bdgenomics/adam/converters/SAMRecordConverter.scala index 9b08191cef..f2cf31b9f0 100644 --- a/adam-core/src/main/scala/org/bdgenomics/adam/converters/SAMRecordConverter.scala +++ b/adam-core/src/main/scala/org/bdgenomics/adam/converters/SAMRecordConverter.scala @@ -66,6 +66,12 @@ class SAMRecordConverter extends Serializable { assert(start != 0, "Start cannot equal 0 if contig is set.") builder.setStart((start - 1).asInstanceOf[Long]) + // set OP and OC flags, if applicable + if (samRecord.getAttribute("OP") != null) { + builder.setOldPosition(samRecord.getIntegerAttribute("OP").toLong - 1) + builder.setOldCigar(samRecord.getStringAttribute("OC")) + } + val end = samRecord.getCigar.getCigarElements .asScala .filter((p: CigarElement) => p.getOperator.consumesReferenceBases()) diff --git a/adam-core/src/main/scala/org/bdgenomics/adam/rdd/read/realignment/RealignIndels.scala b/adam-core/src/main/scala/org/bdgenomics/adam/rdd/read/realignment/RealignIndels.scala index cae6d220c0..ad82e2e600 100644 --- a/adam-core/src/main/scala/org/bdgenomics/adam/rdd/read/realignment/RealignIndels.scala +++ b/adam-core/src/main/scala/org/bdgenomics/adam/rdd/read/realignment/RealignIndels.scala @@ -357,6 +357,8 @@ private[rdd] class RealignIndels(val consensusModel: ConsensusGenerator = new Co // update mdtag and cigar builder.setMismatchingPositions(MdTag.moveAlignment(r, newCigar, reference.drop(remapping), refStart + remapping).toString()) + builder.setOldPosition(r.getStart()) + builder.setOldCigar(r.getCigar()) builder.setCigar(newCigar.toString) new RichAlignmentRecord(builder.build()) } else diff --git a/adam-core/src/test/scala/org/bdgenomics/adam/converters/AlignmentRecordConverterSuite.scala b/adam-core/src/test/scala/org/bdgenomics/adam/converters/AlignmentRecordConverterSuite.scala index 3b71b17d4a..808f080d2f 100644 --- a/adam-core/src/test/scala/org/bdgenomics/adam/converters/AlignmentRecordConverterSuite.scala +++ b/adam-core/src/test/scala/org/bdgenomics/adam/converters/AlignmentRecordConverterSuite.scala @@ -43,6 +43,8 @@ class AlignmentRecordConverterSuite extends FunSuite { .setMapq(60) .setQual(sequence) // no typo, we just don't care .setMismatchingPositions(mdtag) + .setOldPosition(12) + .setOldCigar("2^AAA3") .build() } @@ -82,6 +84,8 @@ class AlignmentRecordConverterSuite extends FunSuite { assert(toSAM.getMappingQuality === 60) assert(toSAM.getBaseQualityString === sequence) assert(toSAM.getAttribute("MD") === "2^AAA2") + assert(toSAM.getIntegerAttribute("OP") === 13) + assert(toSAM.getStringAttribute("OC") === "2^AAA3") } test("convert a read to fastq") { diff --git a/adam-core/src/test/scala/org/bdgenomics/adam/rdd/read/realignment/RealignIndelsSuite.scala b/adam-core/src/test/scala/org/bdgenomics/adam/rdd/read/realignment/RealignIndelsSuite.scala index 38bf3c4174..cd548b27d3 100644 --- a/adam-core/src/test/scala/org/bdgenomics/adam/rdd/read/realignment/RealignIndelsSuite.scala +++ b/adam-core/src/test/scala/org/bdgenomics/adam/rdd/read/realignment/RealignIndelsSuite.scala @@ -254,4 +254,18 @@ class RealignIndelsSuite extends SparkFunSuite { // this should be a NOP assert(RealignIndels(reads).count === 4) } + + sparkTest("test OP and OC tags") { + artificial_realigned_reads.collect().foreach(realn => { + val readName = realn.getReadName() + val op = realn.getOldPosition() + val oc = realn.getOldCigar() + + Option(op).filter(_ >= 0).foreach(oPos => { + val s = artificial_reads.collect().filter(x => (x.getReadName() == readName)) + assert(s.filter(x => (x.getStart() == oPos)).length > 0) + assert(s.filter(x => (x.getCigar() == oc)).length > 0) + }) + }) + } } diff --git a/pom.xml b/pom.xml index 25da293c8b..13876ea3e1 100644 --- a/pom.xml +++ b/pom.xml @@ -305,7 +305,7 @@ org.bdgenomics.bdg-formats bdg-formats - 0.3.1 + 0.3.2 commons-io