Skip to content

Commit

Permalink
add per-strand alignment aggregation
Browse files Browse the repository at this point in the history
  • Loading branch information
hpratt committed Nov 21, 2020
1 parent f3ac213 commit 65db8a2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

group = "com.genomealmanac"
version = "0.6.1"
version = "0.7.0"
val artifactID = "bam-aggregate-task"

repositories {
Expand Down
10 changes: 7 additions & 3 deletions src/main/kotlin/app/Matrix.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ class Matrix : CliktCommand() {
.int().default(0)
private val reverseShift by option("--reverse-shift", help = "if set, shifts reverse strand reads by the given number of basepairs")
.int().default(0)
private val strand by option("--strand", help = "if set, aggregates reads on the given strand only; may be one of 'forward' or 'reverse'")

override fun run() {
runTask(regionFiles, alignments, expansionSize, outputDir, randomAccess, batchSize, forwardShift, reverseShift)
runTask(regionFiles, alignments, expansionSize, outputDir, randomAccess, batchSize, forwardShift, reverseShift, strand)
}

}
Expand All @@ -48,7 +49,10 @@ class Matrix : CliktCommand() {
* @param expansionSize number of basepairs by which to expand each region around its center
* @param outputDir path to directory for writing output files
*/
private fun runTask(regionFiles: List<Path>, alignments: Path, expansionSize: Int, outputDir: Path, randomAccess: Boolean, batchSize: Int, forwardShift: Int, reverseShift: Int) {
private fun runTask(
regionFiles: List<Path>, alignments: Path, expansionSize: Int, outputDir: Path, randomAccess: Boolean, batchSize: Int, forwardShift: Int, reverseShift: Int,
strand: String?
) {

regionFiles.forEach {

Expand All @@ -63,7 +67,7 @@ private fun runTask(regionFiles: List<Path>, alignments: Path, expansionSize: In
)
else
writeJSONMatrix(
matrix(resizeRegions(regions, expansionSize / 2), alignments, forwardShift, reverseShift),
matrix(resizeRegions(regions, expansionSize / 2), alignments, forwardShift, reverseShift, strand),
outputDir.resolve("$combinedOutPrefix$AGGREGATE_TSV_SUFFIX")
)
}
Expand Down
20 changes: 20 additions & 0 deletions src/test/kotlin/MatrixTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,26 @@ class MatrixTests {
assertThat(values).isEqualTo(listOf(listOf(0, 1), listOf(0, 0)))
}

@Test
fun `Run aggregation on regions with reads on the forward strand only`() {
val regions = listOf(
Region("chr22", 10602488, 10602489, "", 0, '+'),
Region("chr22", 10667451, 10667452, "", 0, '-')
)
val values = matrix(regions, TEST_BAM_PATH, 0, 0, "forward")
assertThat(values).isEqualTo(listOf(listOf(1, 0), listOf(0, 0)))
}

@Test
fun `Run aggregation on regions with reads on the reverse strand only`() {
val regions = listOf(
Region("chr22", 10602488, 10602489, "", 0, '-'),
Region("chr22", 10667451, 10667452, "", 0, '+')
)
val values = matrix(regions, TEST_BAM_PATH, 0, 0, "reverse")
assertThat(values).isEqualTo(listOf(listOf(0, 1), listOf(0, 0)))
}

@Test
fun `Run aggregation and write a random access matrix`() {
val regions = listOf(
Expand Down

0 comments on commit 65db8a2

Please sign in to comment.