forked from bigdatagenomics/avocado
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AVOCADO-200] Feed assembled variants to INDEL realigner.
Resolves bigdatagenomics#200. Depends on bigdatagenomics/adam#1363. * Adds a ConsensusRealigner that uses the main Realigner to realign reads, which are then fed into the variant discovery engine with loose filters. Any INDEL variants that are discovered are then fed in to ADAM's INDEL realignment engine as known INDELs. * Uses this realignment mode in the BiallelicGenotyperSuite to clean up a previously failing test. * Adds this to the Reassemble CLI as a `-use_consensus_realigner` switch.
- Loading branch information
Showing
7 changed files
with
215 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
avocado-core/src/main/scala/org/bdgenomics/avocado/realigner/ConsensusRealigner.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* Licensed to Big Data Genomics (BDG) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The BDG licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.bdgenomics.avocado.realigner | ||
|
||
import org.bdgenomics.adam.algorithms.consensus.ConsensusGenerator | ||
import org.bdgenomics.adam.rdd.read.AlignmentRecordRDD | ||
import org.bdgenomics.adam.rdd.variant.VariantRDD | ||
import org.bdgenomics.avocado.genotyping.DiscoverVariants | ||
import org.bdgenomics.formats.avro.Variant | ||
|
||
object ConsensusRealigner { | ||
|
||
/** | ||
* Realigns a set of reads against the reference genome. | ||
* | ||
* @param reads Reads to realign. | ||
* @param kmerLength The length k of the k-mers. | ||
* @return Returns the realigned reads. | ||
*/ | ||
def realign(reads: AlignmentRecordRDD, | ||
kmerLength: Int): AlignmentRecordRDD = { | ||
|
||
// use the realigner to make a first pass over the reads | ||
val realignedReads = Realigner.realign(reads, kmerLength) | ||
|
||
// from here, we'll discover any potential variants | ||
val variants = filterIndels(DiscoverVariants(realignedReads)) | ||
|
||
// we'll pass these discovered variants to ADAM's indel realigner | ||
reads.realignIndels(ConsensusGenerator.fromKnownIndels(variants)) | ||
} | ||
|
||
/** | ||
* @param v The variant to filter. | ||
* @return Returns false if the variant is a SNV/MNV. | ||
*/ | ||
private[realigner] def discardSnvs(v: Variant): Boolean = { | ||
v.getReferenceAllele.length != v.getAlternateAllele.length | ||
} | ||
|
||
/** | ||
* @param rdd The RDD of variants to filter. | ||
* @return Returns a new RDD of variants where the SNVs & MNVs have been | ||
* removed and only INDEL variants remain. | ||
*/ | ||
private[realigner] def filterIndels(rdd: VariantRDD): VariantRDD = { | ||
rdd.transform(r => r.filter(discardSnvs)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
avocado-core/src/test/scala/org/bdgenomics/avocado/realigner/ConsensusRealignerSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/** | ||
* Licensed to Big Data Genomics (BDG) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The BDG licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.bdgenomics.avocado.realigner | ||
|
||
import org.bdgenomics.adam.models.SequenceDictionary | ||
import org.bdgenomics.adam.rdd.read.AlignmentRecordRDD | ||
import org.bdgenomics.adam.rdd.variant.VariantRDD | ||
import org.bdgenomics.formats.avro.Variant | ||
|
||
class ConsensusRealignerSuite extends SparkRealignerSuite { | ||
|
||
val allowLegacyCigars = true | ||
|
||
def realign(rdd: AlignmentRecordRDD, | ||
kmerLength: Int): AlignmentRecordRDD = { | ||
ConsensusRealigner.realign(rdd, kmerLength) | ||
} | ||
|
||
val snv = Variant.newBuilder | ||
.setStart(0L) | ||
.setReferenceAllele("A") | ||
.setAlternateAllele("G") | ||
.build | ||
val mnv = Variant.newBuilder | ||
.setStart(1L) | ||
.setReferenceAllele("AC") | ||
.setAlternateAllele("GT") | ||
.build | ||
val ins = Variant.newBuilder | ||
.setStart(2L) | ||
.setReferenceAllele("A") | ||
.setAlternateAllele("ACC") | ||
.build | ||
val del = Variant.newBuilder | ||
.setStart(3L) | ||
.setReferenceAllele("GCT") | ||
.setAlternateAllele("G") | ||
.build | ||
|
||
test("filter out a snv") { | ||
assert(!ConsensusRealigner.discardSnvs(snv)) | ||
} | ||
|
||
test("filter out a mnv") { | ||
assert(!ConsensusRealigner.discardSnvs(mnv)) | ||
} | ||
|
||
test("keep an insert") { | ||
assert(ConsensusRealigner.discardSnvs(ins)) | ||
} | ||
|
||
test("keep a deletion") { | ||
assert(ConsensusRealigner.discardSnvs(del)) | ||
} | ||
|
||
sparkTest("filter snv/mnv variants out") { | ||
val vRdd = VariantRDD(sc.parallelize(Seq(snv, mnv, ins, del)), | ||
SequenceDictionary.empty) | ||
val filteredVariants = ConsensusRealigner.filterIndels(vRdd) | ||
.rdd | ||
.collect | ||
|
||
val variantIds = filteredVariants.map(_.getStart) | ||
.toSet | ||
|
||
assert(variantIds.size === 2) | ||
assert(variantIds(2L)) | ||
assert(variantIds(3L)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters