forked from bigdatagenomics/gnocchi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests for Variant Models (bigdatagenomics#26)
* Create testing stubs for variant models * finished tests for LogisiticVariantModel * Finished LinearVariantModel tests * update description of constructVariantModel fns
- Loading branch information
1 parent
76020f8
commit 3eb19c1
Showing
11 changed files
with
295 additions
and
47 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
132 changes: 132 additions & 0 deletions
132
...i-core/src/test/scala/org/bdgenomics/gnocchi/models/variant/LinearVariantModelSuite.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,132 @@ | ||
package org.bdgenomics.gnocchi.models.variant | ||
|
||
import org.bdgenomics.gnocchi.GnocchiFunSuite | ||
import org.bdgenomics.gnocchi.primitives.association.LinearAssociation | ||
import org.scalactic.Tolerance._ | ||
|
||
class LinearVariantModelSuite extends GnocchiFunSuite { | ||
|
||
sparkTest("Test constructUpdatedVariantModel works") { | ||
val assoc = LinearAssociation(ssDeviations = 0.5, | ||
ssResiduals = 0.5, | ||
geneticParameterStandardError = 0.5, | ||
tStatistic = 0.5, | ||
residualDegreesOfFreedom = 2, | ||
pValue = 0.5, | ||
weights = List(0.5, 0.5), | ||
numSamples = 10) | ||
|
||
val variantModel = LinearVariantModel("rs123456", assoc, "", 1, 1, "A", "C", "") | ||
|
||
val newVariantModel = variantModel.constructUpdatedVariantModel("rs234567", | ||
0.1, | ||
0.2, | ||
0.3, | ||
0.4, | ||
100, | ||
0.6, | ||
List(0.7, 0.8), | ||
500) | ||
|
||
// Assert that all values in the LinearVariantModel object match expected | ||
// The following values should be updated given the new parameters | ||
assert(newVariantModel.uniqueID === "rs234567") | ||
assert(newVariantModel.association.ssDeviations === 0.1) | ||
assert(newVariantModel.association.ssResiduals === 0.2) | ||
assert(newVariantModel.association.geneticParameterStandardError === 0.3) | ||
assert(newVariantModel.association.tStatistic === 0.4) | ||
assert(newVariantModel.association.residualDegreesOfFreedom === 100) | ||
assert(newVariantModel.association.pValue === 0.6) | ||
assert(newVariantModel.association.weights === List(0.7, 0.8)) | ||
assert(newVariantModel.association.numSamples === 500) | ||
|
||
// The following values should match the original ones | ||
assert(newVariantModel.phenotype === "") | ||
assert(newVariantModel.chromosome === 1) | ||
assert(newVariantModel.position === 1) | ||
assert(newVariantModel.referenceAllele === "A") | ||
assert(newVariantModel.alternateAllele === "C") | ||
assert(newVariantModel.allelicAssumption === "") | ||
} | ||
|
||
sparkTest("Test constructUpdatedVariantModel with association parameter works") { | ||
val assoc = LinearAssociation(ssDeviations = 0.5, | ||
ssResiduals = 0.5, | ||
geneticParameterStandardError = 0.5, | ||
tStatistic = 0.5, | ||
residualDegreesOfFreedom = 2, | ||
pValue = 0.5, | ||
weights = List(0.5, 0.5), | ||
numSamples = 10) | ||
|
||
val variantModel = LinearVariantModel("rs123456", assoc, "", 1, 1, "A", "C", "") | ||
|
||
val newAssoc = LinearAssociation(ssDeviations = 0.1, | ||
ssResiduals = 0.2, | ||
geneticParameterStandardError = 0.3, | ||
tStatistic = 0.4, | ||
residualDegreesOfFreedom = 100, | ||
pValue = 0.6, | ||
weights = List(0.7, 0.8), | ||
numSamples = 500) | ||
|
||
val newVariantModel = variantModel.constructUpdatedVariantModel("rs234567", newAssoc) | ||
|
||
// Assert that all values in the LinearVariantModel object match expected | ||
// The following values should be updated given the new parameters | ||
assert(newVariantModel.uniqueID === "rs234567") | ||
assert(newVariantModel.association.ssDeviations === 0.1) | ||
assert(newVariantModel.association.ssResiduals === 0.2) | ||
assert(newVariantModel.association.geneticParameterStandardError === 0.3) | ||
assert(newVariantModel.association.tStatistic === 0.4) | ||
assert(newVariantModel.association.residualDegreesOfFreedom === 100) | ||
assert(newVariantModel.association.pValue === 0.6) | ||
assert(newVariantModel.association.weights === List(0.7, 0.8)) | ||
assert(newVariantModel.association.numSamples === 500) | ||
|
||
// The following values should match the original ones | ||
assert(newVariantModel.phenotype === "") | ||
assert(newVariantModel.chromosome === 1) | ||
assert(newVariantModel.position === 1) | ||
assert(newVariantModel.referenceAllele === "A") | ||
assert(newVariantModel.alternateAllele === "C") | ||
assert(newVariantModel.allelicAssumption === "") | ||
} | ||
|
||
sparkTest("Test LinearVariantModel.mergeWith works") { | ||
val firstAssoc = LinearAssociation(ssDeviations = 0.5, | ||
ssResiduals = 0.5, | ||
geneticParameterStandardError = 0.5, | ||
tStatistic = 0.5, | ||
residualDegreesOfFreedom = 2, | ||
pValue = 0.5, | ||
weights = List(0.5, 0.5), | ||
numSamples = 10) | ||
|
||
val firstVariantModel = LinearVariantModel("rs123456", firstAssoc, "", 1, 1, "A", "C", "") | ||
|
||
val secondAssoc = LinearAssociation(ssDeviations = 0.2, | ||
ssResiduals = 0.3, | ||
geneticParameterStandardError = 0.4, | ||
tStatistic = 0.6, | ||
residualDegreesOfFreedom = 1, | ||
pValue = 0.6, | ||
weights = List(0.7, 0.8), | ||
numSamples = 10) | ||
|
||
val secondVariantModel = LinearVariantModel("rs123456", secondAssoc, "", 1, 1, "A", "C", "") | ||
|
||
// Merge firstVariantModel with secondVariantModel | ||
val mergedVariantModel = firstVariantModel.mergeWith(secondVariantModel) | ||
|
||
assert(mergedVariantModel.association.numSamples === 20) | ||
assert(mergedVariantModel.association.weights === List(0.6, 0.65)) | ||
assert(mergedVariantModel.association.ssDeviations === 0.7) | ||
assert(mergedVariantModel.association.ssResiduals === 0.8) | ||
assert(mergedVariantModel.association.geneticParameterStandardError === 0.2519 +- 0.0001) | ||
assert(mergedVariantModel.association.residualDegreesOfFreedom === 12) | ||
assert(mergedVariantModel.association.tStatistic === 2.5796 +- 0.0001) | ||
assert(mergedVariantModel.association.pValue === 0.0241 +- 0.0001) | ||
} | ||
|
||
} |
97 changes: 97 additions & 0 deletions
97
...core/src/test/scala/org/bdgenomics/gnocchi/models/variant/LogisticVariantModelSuite.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,97 @@ | ||
package org.bdgenomics.gnocchi.models.variant | ||
|
||
import org.bdgenomics.gnocchi.GnocchiFunSuite | ||
import org.bdgenomics.gnocchi.primitives.association.LogisticAssociation | ||
import org.scalactic.Tolerance._ | ||
|
||
class LogisticVariantModelSuite extends GnocchiFunSuite { | ||
|
||
sparkTest("Test constructUpdatedVariantModel works") { | ||
val assoc = LogisticAssociation(geneticParameterStandardError = 0.5, | ||
pValue = 0.5, | ||
weights = List(0.5, 0.5), | ||
numSamples = 10) | ||
|
||
val variantModel = LogisticVariantModel("rs123456", assoc, "", 1, 1, "A", "C", "") | ||
val newVariantModel = variantModel.constructUpdatedVariantModel("rs234567", 0.1, 0.2, List(0.3, 0.4), 1) | ||
|
||
// Assert that all values in the LogisticVariantModel object match expected | ||
// The following values should be updated given the new parameters | ||
assert(newVariantModel.uniqueID === "rs234567") | ||
assert(newVariantModel.association.geneticParameterStandardError === 0.1) | ||
assert(newVariantModel.association.pValue === 0.2) | ||
assert(newVariantModel.association.weights === List(0.3, 0.4)) | ||
assert(newVariantModel.association.numSamples === 1) | ||
|
||
// The following values should match the original ones | ||
assert(newVariantModel.phenotype === "") | ||
assert(newVariantModel.chromosome === 1) | ||
assert(newVariantModel.position === 1) | ||
assert(newVariantModel.referenceAllele === "A") | ||
assert(newVariantModel.alternateAllele === "C") | ||
assert(newVariantModel.allelicAssumption === "") | ||
} | ||
|
||
sparkTest("Test constructUpdatedVariantModel with association parameter works") { | ||
val assoc = LogisticAssociation(geneticParameterStandardError = 0.5, | ||
pValue = 0.5, | ||
weights = List(0.5, 0.5), | ||
numSamples = 10) | ||
|
||
val variantModel = LogisticVariantModel("rs123456", assoc, "", 1, 1, "A", "C", "") | ||
|
||
val newAssoc = LogisticAssociation(geneticParameterStandardError = 0.1, | ||
pValue = 0.2, | ||
weights = List(0.3, 0.4), | ||
numSamples = 1) | ||
|
||
val newVariantModel = variantModel.constructUpdatedVariantModel("rs234567", newAssoc) | ||
|
||
// Assert that all values in the LogisticVariantModel object match expected | ||
// The following values should be updated given the new parameters | ||
assert(newVariantModel.uniqueID === "rs234567") | ||
assert(newVariantModel.association.geneticParameterStandardError === 0.1) | ||
assert(newVariantModel.association.pValue === 0.2) | ||
assert(newVariantModel.association.weights === List(0.3, 0.4)) | ||
assert(newVariantModel.association.numSamples === 1) | ||
|
||
// The following values should match the original ones | ||
assert(newVariantModel.phenotype === "") | ||
assert(newVariantModel.chromosome === 1) | ||
assert(newVariantModel.position === 1) | ||
assert(newVariantModel.referenceAllele === "A") | ||
assert(newVariantModel.alternateAllele === "C") | ||
assert(newVariantModel.allelicAssumption === "") | ||
} | ||
|
||
sparkTest("Test LogisticVariantModel.mergeWith works") { | ||
val firstAssoc = LogisticAssociation(geneticParameterStandardError = 0.5, | ||
pValue = 0.5, | ||
weights = List(0.5, 0.5), | ||
numSamples = 10) | ||
val firstVariantModel = LogisticVariantModel("rs123456", firstAssoc, "", 1, 1, "A", "C", "") | ||
|
||
val secondAssoc = LogisticAssociation(geneticParameterStandardError = 0.2, | ||
pValue = 0.2, | ||
weights = List(0.2, 0.8), | ||
numSamples = 5) | ||
val secondVariantModel = LogisticVariantModel("rs123456", secondAssoc, "", 1, 1, "A", "C", "") | ||
|
||
// Merge firstVariantModel with secondVariantModel | ||
val mergedVariantModel = firstVariantModel.mergeWith(secondVariantModel) | ||
|
||
// Assert values in the merged model match expected | ||
assert(mergedVariantModel.association.numSamples === 15) | ||
|
||
// Assert that new geneticParameterStandardError is the weighted average of | ||
// the geneticParameterStandardErrors of the first and second model | ||
assert(mergedVariantModel.association.geneticParameterStandardError === 0.4) | ||
|
||
// Assert that the new weights are weighted averages of the weights from | ||
// the first and second model | ||
assert(mergedVariantModel.association.weights === List(0.4, 0.6)) | ||
|
||
// The new p-value should be 0.1336... | ||
assert(mergedVariantModel.association.pValue === 0.1336 +- 0.0001) | ||
} | ||
} |
5 changes: 0 additions & 5 deletions
5
.../scala/org/bdgenomics/gnocchi/models/variant/linear/AdditiveLinearVariantModelSuite.scala
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
.../scala/org/bdgenomics/gnocchi/models/variant/linear/DominantLinearVariantModelSuite.scala
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
...la/org/bdgenomics/gnocchi/models/variant/logistic/AdditiveLogisticVariantModelSuite.scala
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.