Skip to content

Commit

Permalink
Rebase work onto master
Browse files Browse the repository at this point in the history
  • Loading branch information
massie committed May 13, 2014
1 parent b16d180 commit 1bf03f6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class GenotypePredicatesSuite extends SparkFunSuite {
ParquetLogger.hadoopLoggerLevel(Level.SEVERE)

val v0 = ADAMVariant.newBuilder
.setContig(ADAMContig.newBuilder.setContigName("11").build)
.setContig("11")
.setPosition(17409571)
.setReferenceAllele("T")
.setVariantAllele("C")
Expand All @@ -86,8 +86,10 @@ class GenotypePredicatesSuite extends SparkFunSuite {

val genotypes = sc.parallelize(List(
ADAMGenotype.newBuilder().setVariant(v0)
.setSampleId("ignored")
.setVariantCallingAnnotations(passFilterAnnotation).build(),
ADAMGenotype.newBuilder()
.setSampleId("ignored")
.setVariant(v0)
.setVariantCallingAnnotations(failFilterAnnotation).build()))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,30 @@ class RecordConditionSuite extends FunSuite {

test("create record condition from simple field condition") {
val mappedReadCondition = RecordCondition[ADAMRecord](
FieldCondition(ADAMRecordField.readMapped.toString, (x: Boolean) => x == true))
FieldCondition(ADAMRecordField.readMapped.toString(), (x: Boolean) => x))

val mappedRead = ADAMRecord.newBuilder
.setReadMapped(true)
.build
assert(mappedReadCondition(mappedRead) == true)
assert(mappedReadCondition(mappedRead))

val unmappedRead = ADAMRecord.newBuilder
.setReadMapped(false)
.build

assert(mappedReadCondition(unmappedRead) == false)
assert(!mappedReadCondition(unmappedRead))

val underspecifiedRead = ADAMRecord.newBuilder
.setMapq(30)
.build

assert(mappedReadCondition(underspecifiedRead) == false)
assert(!mappedReadCondition(underspecifiedRead))

}

test("create record condition from nested field condition") {
val v0 = ADAMVariant.newBuilder
.setContig(ADAMContig.newBuilder.setContigName("11").build)
.setContig("11")
.setPosition(17409571)
.setReferenceAllele("T")
.setVariantAllele("C")
Expand All @@ -44,26 +44,28 @@ class RecordConditionSuite extends FunSuite {

val passGenotype =
ADAMGenotype.newBuilder().setVariant(v0)
.setSampleId("ignored")
.setVariantCallingAnnotations(passFilterAnnotation)
.build
val failGenotype = ADAMGenotype.newBuilder()
.setSampleId("ignored")
.setVariant(v0)
.setVariantCallingAnnotations(failFilterAnnotation)
.build

val isPassing = RecordCondition[ADAMGenotype](FieldCondition("variantCallingAnnotations.variantIsPassing", PredicateUtils.isTrue))

assert(isPassing(passGenotype) == true)
assert(isPassing(failGenotype) == false)
assert(isPassing(passGenotype))
assert(!isPassing(failGenotype))

}

test("create record condition from multiple field conditions") {
val mappedReadCondition = RecordCondition[ADAMRecord](
FieldCondition(ADAMRecordField.readMapped.toString, (x: Boolean) => x == true),
FieldCondition(ADAMRecordField.primaryAlignment.toString, (x: Boolean) => x == true),
FieldCondition(ADAMRecordField.failedVendorQualityChecks.toString, (x: Boolean) => x == false),
FieldCondition(ADAMRecordField.duplicateRead.toString, (x: Boolean) => x == false))
FieldCondition(ADAMRecordField.readMapped.toString(), (x: Boolean) => x),
FieldCondition(ADAMRecordField.primaryAlignment.toString(), (x: Boolean) => x),
FieldCondition(ADAMRecordField.failedVendorQualityChecks.toString(), (x: Boolean) => !x),
FieldCondition(ADAMRecordField.duplicateRead.toString(), (x: Boolean) => !x))

val mappedRead = ADAMRecord.newBuilder
.setReadMapped(true)
Expand All @@ -72,7 +74,7 @@ class RecordConditionSuite extends FunSuite {
.setDuplicateRead(false)
.build

assert(mappedReadCondition(mappedRead) == true)
assert(mappedReadCondition(mappedRead))

val mappedDuplicateRead = ADAMRecord.newBuilder
.setReadMapped(true)
Expand All @@ -81,7 +83,7 @@ class RecordConditionSuite extends FunSuite {
.setDuplicateRead(true)
.build

assert(mappedReadCondition(mappedDuplicateRead) == false)
assert(!mappedReadCondition(mappedDuplicateRead))

val mappedSecondaryAlignmentRead = ADAMRecord.newBuilder
.setReadMapped(true)
Expand All @@ -90,42 +92,42 @@ class RecordConditionSuite extends FunSuite {
.setDuplicateRead(false)
.build

assert(mappedReadCondition(mappedSecondaryAlignmentRead) == false)
assert(!mappedReadCondition(mappedSecondaryAlignmentRead))

val unmappedRead = ADAMRecord.newBuilder
.setReadMapped(false)
.build

assert(mappedReadCondition(unmappedRead) == false)
assert(!mappedReadCondition(unmappedRead))
}

test("create record condition from non-equality field conditions") {
val highQualityReadCondition = RecordCondition[ADAMRecord](
FieldCondition(ADAMRecordField.readMapped.toString, PredicateUtils.isTrue),
FieldCondition(ADAMRecordField.mapq.toString, (x: Int) => x > 10))
FieldCondition(ADAMRecordField.readMapped.toString(), PredicateUtils.isTrue),
FieldCondition(ADAMRecordField.mapq.toString(), (x: Int) => x > 10))

val highQualityRead = ADAMRecord.newBuilder
.setReadMapped(true)
.setMapq(30)
.build

assert(highQualityReadCondition(highQualityRead) == true)
assert(highQualityReadCondition(highQualityRead))

val lowQualityRead = ADAMRecord.newBuilder
.setReadMapped(true)
.setMapq(5)
.build

assert(highQualityReadCondition(lowQualityRead) == false)
assert(!highQualityReadCondition(lowQualityRead))
}

test("create record condition OR of record conditions") {

val sample1Conditon = RecordCondition[ADAMRecord](
FieldCondition(ADAMRecordField.recordGroupSample.toString, (x: String) => x == "sample1"))
FieldCondition(ADAMRecordField.recordGroupSample.toString(), (x: String) => x == "sample1"))

val sample2Conditon = RecordCondition[ADAMRecord](
FieldCondition(ADAMRecordField.recordGroupSample.toString, (x: String) => x == "sample2"))
FieldCondition(ADAMRecordField.recordGroupSample.toString(), (x: String) => x == "sample2"))

val sample1ORsample2 = sample1Conditon || sample2Conditon

Expand All @@ -141,9 +143,9 @@ class RecordConditionSuite extends FunSuite {
.setRecordGroupSample("sample3")
.build

assert(sample1ORsample2(sample1Read) == true)
assert(sample1ORsample2(sample2Read) == true)
assert(sample1ORsample2(sample3Read) == false)
assert(sample1ORsample2(sample1Read))
assert(sample1ORsample2(sample2Read))
assert(!sample1ORsample2(sample3Read))
}

test("high quality adam read condition") {
Expand All @@ -154,19 +156,19 @@ class RecordConditionSuite extends FunSuite {
.setMapq(30)
.build

assert(highQualityReadCondition(highQualityRead) == true)
assert(highQualityReadCondition(highQualityRead))

val lowQualityRead = ADAMRecord.newBuilder
.setReadMapped(true)
.setMapq(5)
.build

assert(highQualityReadCondition(lowQualityRead) == false)
assert(!highQualityReadCondition(lowQualityRead))
}

test("passing genotype record condition") {
val v0 = ADAMVariant.newBuilder
.setContig(ADAMContig.newBuilder.setContigName("11").build)
.setContig("11")
.setPosition(17409571)
.setReferenceAllele("T")
.setVariantAllele("C")
Expand All @@ -179,8 +181,10 @@ class RecordConditionSuite extends FunSuite {

val genotypes = Seq[ADAMGenotype](
ADAMGenotype.newBuilder().setVariant(v0)
.setSampleId("ignored")
.setVariantCallingAnnotations(passFilterAnnotation).build(),
ADAMGenotype.newBuilder()
.setSampleId("ignored")
.setVariant(v0)
.setVariantCallingAnnotations(failFilterAnnotation).build())

Expand Down

0 comments on commit 1bf03f6

Please sign in to comment.