-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[avocado-122] Tested and reintegrated EM algorithm.
- Loading branch information
Showing
9 changed files
with
300 additions
and
100 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
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
77 changes: 77 additions & 0 deletions
77
avocado-core/src/test/scala/org/bdgenomics/avocado/algorithms/em/EMforAllelesSuite.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,77 @@ | ||
/** | ||
* 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.algorithms.em | ||
|
||
import org.scalatest.FunSuite | ||
import scala.math.abs | ||
|
||
class EMForAllelesSuite extends FunSuite { | ||
|
||
def fpEquals(a: Double, b: Double, eps: Double = 1e-3): Boolean = { | ||
abs(a - b) < eps | ||
} | ||
|
||
test("cannot run EM without specifying an iteration limit or target tolerance") { | ||
intercept[AssertionError] { | ||
EMForAlleles.emForMAF(Array(Array[Double]()), | ||
1.0 - 1e-3) | ||
} | ||
} | ||
|
||
test("run EM on single sample, definite ref") { | ||
val psi = EMForAlleles.emForMAF(Array(Array(0.0, 0.0, 1.0)), | ||
1.0 - 1e-3, | ||
maxIterations = Some(10)) | ||
|
||
assert(fpEquals(psi, 1.0)) | ||
} | ||
|
||
test("run EM on three samples, mix of hom ref, het, hom alt") { | ||
val psi = EMForAlleles.emForMAF(Array(Array(0.0000001, 0.0001, 0.1), | ||
Array(0.0001, 0.1, 0.0001), | ||
Array(0.1, 0.0001, 0.0000001)), | ||
1.0 - 1e-3, | ||
maxIterations = Some(10)) | ||
|
||
assert(fpEquals(psi, 0.5)) | ||
} | ||
|
||
test("run EM on five samples, one hom alt, all others hom ref") { | ||
val psi = EMForAlleles.emForMAF(Array(Array(0.0000001, 0.0001, 0.1), | ||
Array(0.0000001, 0.0001, 0.1), | ||
Array(0.0000001, 0.0001, 0.1), | ||
Array(0.0000001, 0.0001, 0.1), | ||
Array(0.1, 0.0001, 0.0000001)), | ||
1.0 - 1e-3, | ||
maxIterations = Some(10)) | ||
|
||
assert(fpEquals(psi, 0.8)) | ||
} | ||
|
||
test("run EM on five samples, with varying ploidy, M = 10, G = 7") { | ||
val psi = EMForAlleles.emForMAF(Array(Array(0.0000001, 0.0001, 0.1), | ||
Array(0.0000001, 0.0001, 0.1), | ||
Array(0.0000001, 0.0001, 0.1), | ||
Array(0.1, 0.0001), | ||
Array(0.0001, 0.1, 0.0001, 0.0000001)), | ||
1.0 - 1e-3, | ||
maxIterations = Some(10)) | ||
|
||
assert(fpEquals(psi, 0.7)) | ||
} | ||
} |
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
{ | ||
} | ||
biallelicGenotyper = { | ||
tolerance = 0.001; | ||
} | ||
defPart = | ||
{ | ||
|
Oops, something went wrong.