-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix impossible stats & regression test
- Loading branch information
Showing
3 changed files
with
136 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
##fileformat=VCFv4.1 | ||
##source=BespokeByIsaac | ||
##FORMAT=<ID=GT,Number=1,Type=String,Description="Genotype"> | ||
##FORMAT=<ID=GQ,Number=1,Type=Integer,Description="Genotype Quality"> | ||
##FORMAT=<ID=DP,Number=1,Type=Integer,Description="Read Depth"> | ||
##FORMAT=<ID=RD,Number=1,Type=Integer,Description="Depth of reference-supporting bases (reads1)"> | ||
##FORMAT=<ID=AD,Number=1,Type=Integer,Description="Depth of variant-supporting bases (reads2)"> | ||
##FORMAT=<ID=FREQ,Number=1,Type=String,Description="Variant allele frequency"> | ||
##FORMAT=<ID=DP4,Number=4,Type=Integer,Description="Strand read counts: ref/fwd, ref/rev, var/fwd, var/rev"> | ||
#CHROM POS ID REF ALT QUAL FILTER INFO FORMAT NORMAL TUMOR | ||
20 61795 . G T . FOUND . GT:GQ:DP:RD:AD:FREQ:DP4 0/1:.:44:22:22:50%:16,6,9,13 0/1:.:37:18:19:51.35%:10,8,10,9 | ||
20 52731 . C A . NOTFOUND . GT:GQ:DP:RD:AD:FREQ:DP4 0/1:.:32:17:15:46.88%:9,8,9,6 0/1:.:36:21:15:41.67%:8,13,8,7 | ||
20 65288 . G T . FOUND . GT:GQ:DP:RD:AD:FREQ:DP4 0/1:.:21:13:8:38.1%:4,9,0,8 0/1:.:14:10:4:28.57%:2,8,0,4 | ||
20 65900 . G A . FOUND . GT:GQ:DP:RD:AD:FREQ:DP4 1/1:.:26:0:26:100%:0,0,12,14 1/1:.:27:0:27:100%:0,0,15,12 | ||
20 68090 . G C . NOTFOUND . GT:GQ:DP:RD:AD:FREQ:DP4 1/1:.:23:0:23:100%:0,0,7,16 1/1:.:41:0:41:100%:0,0,21,20 | ||
20 75254 . C A . FOUND . GT:GQ:DP:RD:AD:FREQ:DP4 0/1:.:34:22:11:33.33%:13,9,5,6 0/1:.:40:20:20:50%:5,15,14,6 |
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,107 @@ | ||
import mock | ||
import nose | ||
import unittest | ||
import nose.tools as asserts | ||
import json | ||
|
||
from cycledash import db | ||
from cycledash.genotypes import get | ||
from common.helpers import tables, pick | ||
from workers.genotype_extractor import _extract | ||
|
||
from test_projects_api import create_project_with_name | ||
from test_runs_api import create_run_with_uri | ||
from helpers import delete_tables | ||
|
||
|
||
class TestGenotypesAPI(object): | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
cls.project = create_project_with_name('my project') | ||
cls.run = create_run_with_uri(cls.project['id'], '/tests/data/snv.vcf') | ||
_extract(cls.run['id']) | ||
cls.truth_run = create_run_with_uri(cls.project['id'], '/tests/data/snv.truth.vcf') | ||
_extract(cls.truth_run['id']) | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
delete_tables(db.engine, 'genotypes', 'vcfs', 'bams', 'projects') | ||
|
||
def test_stats_with_entire_truth_vcf(self): | ||
query = { | ||
'range': {}, | ||
'filters': [], | ||
'sortBy': [], | ||
'compareToVcfId': self.truth_run['id'] | ||
} | ||
stats = get(self.run['id'], query, with_stats=True)['stats'] | ||
|
||
asserts.eq_(stats['totalTruthRecords'], 12) | ||
|
||
asserts.eq_(stats['truePositives'], 8) | ||
asserts.eq_(stats['falsePositives'], 12) | ||
asserts.eq_(stats['falseNegatives'], 4) | ||
|
||
asserts.assert_almost_equals(stats['recall'], 2/3.0) | ||
asserts.assert_almost_equals(stats['precision'], 1/2.5) | ||
asserts.assert_almost_equals(stats['f1score'], 1/2.0) | ||
|
||
def test_stats_with_self(self): | ||
query = { | ||
'range': {}, | ||
'filters': [], | ||
'sortBy': [], | ||
'compareToVcfId': self.run['id'] | ||
} | ||
stats = get(self.run['id'], query, with_stats=True)['stats'] | ||
|
||
asserts.eq_(stats['totalTruthRecords'], 20) | ||
|
||
asserts.eq_(stats['truePositives'], 20) | ||
asserts.eq_(stats['falsePositives'], 0) | ||
asserts.eq_(stats['falseNegatives'], 0) | ||
|
||
asserts.assert_almost_equals(stats['recall'], 1.0) | ||
asserts.assert_almost_equals(stats['precision'], 1.0) | ||
asserts.assert_almost_equals(stats['f1score'], 1.0) | ||
|
||
def test_stats_with_truth_and_range(self): | ||
query = { | ||
'range': {'start': 0, 'end': 66000, 'contig': '20'}, | ||
'filters': [], | ||
'sortBy': [], | ||
'compareToVcfId': self.truth_run['id'] | ||
} | ||
stats = get(self.run['id'], query, with_stats=True)['stats'] | ||
|
||
asserts.eq_(stats['totalTruthRecords'], 8) | ||
|
||
asserts.eq_(stats['truePositives'], 6) | ||
asserts.eq_(stats['falsePositives'], 4) | ||
asserts.eq_(stats['falseNegatives'], 2) | ||
|
||
asserts.assert_almost_equals(stats['recall'], 3/4.0) | ||
asserts.assert_almost_equals(stats['precision'], 3/5.0) | ||
asserts.assert_almost_equals(stats['f1score'], 2/3.0) | ||
|
||
def test_stats_with_truth_and_filters(self): | ||
query = { | ||
'range': {}, | ||
'filters': [{'columnName': 'sample_name', | ||
'filterValue': 'TUMOR', | ||
'type': '='}], | ||
'sortBy': [], | ||
'compareToVcfId': self.truth_run['id'] | ||
} | ||
stats = get(self.run['id'], query, with_stats=True)['stats'] | ||
|
||
asserts.eq_(stats['totalTruthRecords'], 6) | ||
|
||
asserts.eq_(stats['truePositives'], 4) | ||
asserts.eq_(stats['falsePositives'], 6) | ||
asserts.eq_(stats['falseNegatives'], 2) | ||
|
||
asserts.assert_almost_equals(stats['recall'], 2/3.0) | ||
asserts.assert_almost_equals(stats['precision'], 1/2.5) | ||
asserts.assert_almost_equals(stats['f1score'], 1/2.0) |