-
Notifications
You must be signed in to change notification settings - Fork 308
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
Small bugfixes and cleanups to BQSR #38
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7a2d4dc
disambiguate isMismatchBase(), other small cleanups
jey b12fa58
Factor out SnpTable, fix crash in SNP handling
jey 2735cd1
Print a log message on startup to more easily tell runs apart
jey 4b135f6
Improve BQSR performance by reducing GC pressure
jey 24bcce2
Rename 'offset' to 'readOffset' and 'position' to 'referencePosition'
jey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
63 changes: 63 additions & 0 deletions
63
adam-core/src/main/scala/edu/berkeley/cs/amplab/adam/models/SnpTable.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,63 @@ | ||
package edu.berkeley.cs.amplab.adam.models | ||
|
||
import edu.berkeley.cs.amplab.adam.rdd.AdamContext._ | ||
import edu.berkeley.cs.amplab.adam.avro.ADAMRecord | ||
import org.apache.spark.Logging | ||
import org.apache.spark.rdd.RDD | ||
import org.apache.spark.SparkContext._ | ||
import scala.collection.immutable._ | ||
import scala.collection.mutable | ||
import java.io.File | ||
|
||
class SnpTable(private val table: Map[String, Set[Long]]) extends Serializable with Logging { | ||
log.info("SNP table has %s contigs and %s entries".format(table.size, table.values.map(_.size).sum)) | ||
|
||
def isMaskedAtReadOffset(read: ADAMRecord, offset: Int): Boolean = { | ||
val position = read.readOffsetToReferencePosition(offset) | ||
try { | ||
position.isEmpty || table(read.getReferenceName.toString).contains(position.get) | ||
} catch { | ||
case e: java.util.NoSuchElementException => | ||
false | ||
} | ||
} | ||
} | ||
|
||
object SnpTable { | ||
def apply(): SnpTable = { | ||
new SnpTable(Map[String, Set[Long]]()) | ||
} | ||
|
||
// `dbSNP` is expected to be a sites-only VCF | ||
def apply(dbSNP: File): SnpTable = { | ||
// parse into tuples of (contig, position) | ||
val lines = scala.io.Source.fromFile(dbSNP).getLines() | ||
val tuples = lines.filter(line => !line.startsWith("#")).map(line => { | ||
val split = line.split("\t") | ||
val contig = split(0) | ||
val pos = split(1).toLong | ||
(contig, pos) | ||
}) | ||
// construct map from contig to set of positions | ||
// this is done in-place to reduce overhead | ||
val table = new mutable.HashMap[String, mutable.HashSet[Long]] | ||
tuples.foreach(tup => table.getOrElseUpdate(tup._1, { new mutable.HashSet[Long] }) += tup._2) | ||
// construct SnpTable from immutable copy of `table` | ||
new SnpTable(table.mapValues(_.toSet).toMap) | ||
} | ||
|
||
/* | ||
def apply(lines: RDD[String]): SnpTable = { | ||
// parse into tuples of (contig, position) | ||
val tuples = lines.filter(line => !line.startsWith("#")).map(line => { | ||
val split = line.split("\t") | ||
val contig = split(0) | ||
val pos = split(1).toLong | ||
(contig, pos) | ||
}) | ||
// construct map from contig to set of positions | ||
val table = tuples.groupByKey.collect.toMap.mapValues(_.toSet) | ||
new SnpTable(table) | ||
} | ||
*/ | ||
} |
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed the text to be clearer that this is logging each invocation, and have included the arguments in a format suitable for copy-and-paste (e.g. to reproduce a run or re-run with slight changes to arguments).
However, I haven't moved it to the
else
branch to have more complete logs -- is this OK?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me. I like that you added the argsToString feature to copy-paste an ADAM command-line.