<s> import mock <EOL> import nose <EOL> import unittest <EOL> import nose . tools as asserts <EOL> import json <EOL> from cycledash import db <EOL> from cycledash . api import genotypes <EOL> from common . helpers import tables <EOL> from workers . genotype_extractor import _extract <EOL> from test_projects_api import create_project_with_name <EOL> from test_runs_api import create_run_with_uri <EOL> import helpers <EOL> class TestGenotypesAPI ( object ) : <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> cls . project = create_project_with_name ( '<STR_LIT>' ) <EOL> cls . run = create_run_with_uri ( cls . project [ '<STR_LIT:id>' ] , '<STR_LIT>' ) <EOL> _extract ( cls . run [ '<STR_LIT:id>' ] ) <EOL> cls . truth_run = create_run_with_uri ( cls . project [ '<STR_LIT:id>' ] , '<STR_LIT>' ) <EOL> _extract ( cls . truth_run [ '<STR_LIT:id>' ] ) <EOL> @ classmethod <EOL> def tearDownClass ( cls ) : <EOL> helpers . delete_all_records ( db ) <EOL> def test_stats_with_entire_truth_vcf ( self ) : <EOL> query = { <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : self . truth_run [ '<STR_LIT:id>' ] <EOL> } <EOL> stats = genotypes . get ( self . run [ '<STR_LIT:id>' ] , query , with_stats = True ) [ '<STR_LIT>' ] <EOL> total_truth_records_expected = <NUM_LIT:12> <EOL> true_positives_expected = <NUM_LIT:8> <EOL> false_positives_expected = <NUM_LIT:12> <EOL> false_negatives_expected = <NUM_LIT:4> <EOL> precision_expected = true_positives_expected * <NUM_LIT:1.0> / ( true_positives_expected + false_positives_expected ) <EOL> recall_expected = true_positives_expected * <NUM_LIT:1.0> / ( true_positives_expected + false_negatives_expected ) <EOL> f1score_expected = <NUM_LIT> * ( precision_expected * recall_expected ) / ( precision_expected + recall_expected ) <EOL> asserts . eq_ ( stats [ '<STR_LIT>' ] , total_truth_records_expected ) <EOL> asserts . eq_ ( stats [ '<STR_LIT>' ] , true_positives_expected ) <EOL> asserts . eq_ ( stats [ '<STR_LIT>' ] , false_positives_expected ) <EOL> asserts . eq_ ( stats [ '<STR_LIT>' ] , false_negatives_expected ) <EOL> asserts . assert_almost_equals ( stats [ '<STR_LIT>' ] , recall_expected ) <EOL> asserts . assert_almost_equals ( stats [ '<STR_LIT>' ] , precision_expected ) <EOL> asserts . assert_almost_equals ( stats [ '<STR_LIT>' ] , f1score_expected ) <EOL> def test_stats_with_self ( self ) : <EOL> query = { <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : self . run [ '<STR_LIT:id>' ] <EOL> } <EOL> stats = genotypes . get ( self . run [ '<STR_LIT:id>' ] , query , with_stats = True ) [ '<STR_LIT>' ] <EOL> total_truth_records_expected = <NUM_LIT:20> <EOL> true_positives_expected = <NUM_LIT:20> <EOL> false_positives_expected = <NUM_LIT:0> <EOL> false_negatives_expected = <NUM_LIT:0> <EOL> precision_expected = true_positives_expected * <NUM_LIT:1.0> / ( true_positives_expected + false_positives_expected ) <EOL> recall_expected = true_positives_expected * <NUM_LIT:1.0> / ( true_positives_expected + false_negatives_expected ) <EOL> f1score_expected = <NUM_LIT> * ( precision_expected * recall_expected ) / ( precision_expected + recall_expected ) <EOL> asserts . eq_ ( stats [ '<STR_LIT>' ] , total_truth_records_expected ) <EOL> asserts . eq_ ( stats [ '<STR_LIT>' ] , true_positives_expected ) <EOL> asserts . eq_ ( stats [ '<STR_LIT>' ] , false_positives_expected ) <EOL> asserts . eq_ ( stats [ '<STR_LIT>' ] , false_negatives_expected ) <EOL> asserts . assert_almost_equals ( stats [ '<STR_LIT>' ] , recall_expected ) <EOL> asserts . assert_almost_equals ( stats [ '<STR_LIT>' ] , precision_expected ) <EOL> asserts . assert_almost_equals ( stats [ '<STR_LIT>' ] , f1score_expected ) <EOL> def test_stats_with_truth_and_range ( self ) : <EOL> query = { <EOL> '<STR_LIT>' : { '<STR_LIT:start>' : <NUM_LIT:0> , '<STR_LIT:end>' : <NUM_LIT> , '<STR_LIT>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : self . truth_run [ '<STR_LIT:id>' ] <EOL> } <EOL> stats = genotypes . get ( self . run [ '<STR_LIT:id>' ] , query , with_stats = True ) [ '<STR_LIT>' ] <EOL> total_truth_records_expected = <NUM_LIT:8> <EOL> true_positives_expected = <NUM_LIT:6> <EOL> false_positives_expected = <NUM_LIT:4> <EOL> false_negatives_expected = <NUM_LIT:2> <EOL> precision_expected = true_positives_expected * <NUM_LIT:1.0> / ( true_positives_expected + false_positives_expected ) <EOL> recall_expected = true_positives_expected * <NUM_LIT:1.0> / ( true_positives_expected + false_negatives_expected ) <EOL> f1score_expected = <NUM_LIT> * ( precision_expected * recall_expected ) / ( precision_expected + recall_expected ) <EOL> asserts . eq_ ( stats [ '<STR_LIT>' ] , total_truth_records_expected ) <EOL> asserts . eq_ ( stats [ '<STR_LIT>' ] , true_positives_expected ) <EOL> asserts . eq_ ( stats [ '<STR_LIT>' ] , false_positives_expected ) <EOL> asserts . eq_ ( stats [ '<STR_LIT>' ] , false_negatives_expected ) <EOL> asserts . assert_almost_equals ( stats [ '<STR_LIT>' ] , recall_expected ) <EOL> asserts . assert_almost_equals ( stats [ '<STR_LIT>' ] , precision_expected ) <EOL> asserts . assert_almost_equals ( stats [ '<STR_LIT>' ] , f1score_expected ) <EOL> def test_stats_with_truth_and_filters ( self ) : <EOL> query = { <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT>' : [ { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:type>' : '<STR_LIT:=>' } ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : self . truth_run [ '<STR_LIT:id>' ] <EOL> } <EOL> stats = genotypes . get ( self . run [ '<STR_LIT:id>' ] , query , with_stats = True ) [ '<STR_LIT>' ] <EOL> total_truth_records_expected = <NUM_LIT:6> <EOL> true_positives_expected = <NUM_LIT:4> <EOL> false_positives_expected = <NUM_LIT:6> <EOL> false_negatives_expected = <NUM_LIT:2> <EOL> precision_expected = true_positives_expected * <NUM_LIT:1.0> / ( true_positives_expected + false_positives_expected ) <EOL> recall_expected = true_positives_expected * <NUM_LIT:1.0> / ( true_positives_expected + false_negatives_expected ) <EOL> f1score_expected = <NUM_LIT> * ( precision_expected * recall_expected ) / ( precision_expected + recall_expected ) <EOL> asserts . eq_ ( stats [ '<STR_LIT>' ] , total_truth_records_expected ) <EOL> asserts . eq_ ( stats [ '<STR_LIT>' ] , true_positives_expected ) <EOL> asserts . eq_ ( stats [ '<STR_LIT>' ] , false_positives_expected ) <EOL> asserts . eq_ ( stats [ '<STR_LIT>' ] , false_negatives_expected ) <EOL> asserts . assert_almost_equals ( stats [ '<STR_LIT>' ] , recall_expected ) <EOL> asserts . assert_almost_equals ( stats [ '<STR_LIT>' ] , precision_expected ) <EOL> asserts . assert_almost_equals ( stats [ '<STR_LIT>' ] , f1score_expected ) </s>
