Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stores original position and original cigar during realignment. #417

Merged
merged 1 commit into from
Nov 2, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down Expand Up @@ -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") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@
<dependency>
<groupId>org.bdgenomics.bdg-formats</groupId>
<artifactId>bdg-formats</artifactId>
<version>0.3.1</version>
<version>0.3.2</version>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the bump to bdg-formats intentional?

</dependency>
<dependency>
<groupId>commons-io</groupId>
Expand Down