Skip to content

Commit

Permalink
Merge baba084 into b29d204
Browse files Browse the repository at this point in the history
  • Loading branch information
noamBarkai committed Mar 2, 2016
2 parents b29d204 + baba084 commit 8cc5c6d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,41 +47,26 @@ abstract class SmithWaterman(xSequence: String, ySequence: String) extends Seria
* @param matrix Matrix to score.
* @return Tuple of (i, j) coordinates.
*/
private[smithwaterman] final def maxCoordinates(matrix: Array[Array[Double]]): (Int, Int) = {
def maxInCol(col: Array[Double]): (Double, Int) = {
def takeMax(a: (Double, Int), b: (Double, Int)): (Double, Int) = {
if (a._1 > b._1) {
a
} else {
b
private[smithwaterman] final def maxCoordinates(matrix: Array[Array[Double]]): (Int, Int) = {
var xMax = 0
var yMax = 0
var max = Double.MinValue
var x = 0
while (x < matrix.length) {
var y = 0
while (y < matrix(x).length) {
if (matrix(x)(y) >= max) {
max = matrix(x)(y)
xMax = x
yMax = y
}
y += 1
}
x += 1
}

val c: Array[(Double, Int)] = col.zipWithIndex

c.reduce(takeMax)
(yMax, xMax)
}

def maxCol(cols: Array[(Double, Int)]): (Int, Int) = {
def takeMax(a: (Double, Int, Int), b: (Double, Int, Int)): (Double, Int, Int) = {
if (a._1 > b._1) {
a
} else {
b
}
}

val c: Array[((Double, Int), Int)] = cols.zipWithIndex

val m: (Double, Int, Int) = c.map(kv => (kv._1._1, kv._1._2, kv._2))
.reduce(takeMax)

(m._2, m._3)
}

maxCol(matrix.map(maxInCol))
}

/**
* Converts a reversed non-numeric CIGAR into a normal CIGAR.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ abstract class SmithWatermanGapScoringFromFn(
}

// score matrix
for (i <- 1 to x) {
for (j <- 1 to y) {
var i = 1
while (i <= x) {
var j = 1
while (j <= y) {
val m = scoreMatrix(i - 1)(j - 1) + scoreFn(i, j, xSequence(i - 1), ySequence(j - 1))
val d = scoreMatrix(i - 1)(j) + scoreFn(i, j, xSequence(i - 1), '_')
val in = scoreMatrix(i)(j - 1) + scoreFn(i, j, '_', ySequence(j - 1))
Expand All @@ -64,7 +66,9 @@ abstract class SmithWatermanGapScoringFromFn(

scoreMatrix(i)(j) = scoreUpdate
moveMatrix(i)(j) = moveUpdate
j += 1
}
i += 1
}

(scoreMatrix, moveMatrix)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package org.bdgenomics.adam.algorithms.smithwaterman

import org.scalatest.FunSuite
import scala.math.abs
import scala.util.Random

class SmithWatermanSuite extends FunSuite {

Expand Down Expand Up @@ -237,4 +238,13 @@ class SmithWatermanSuite extends FunSuite {
assert(sw.xStart === 8)
}

test("smithWaterman - simple alignment") {
val sw = new SmithWatermanConstantGapScoring("AAA",
"AAT",
1.0, 0.0, -0.333, -0.333)
assert(sw.cigarX.toString === "3M")
assert(sw.cigarY.toString === "3M")
assert(sw.xStart === 0)
}

}

0 comments on commit 8cc5c6d

Please sign in to comment.