def test_sameMajorBothHaveMinorsOnSameBranches_returnsSecondMinor(self): lineage = Lineage(major="4", minor="8.7.8") other = Lineage(major="4", minor="8.7.6") actual = lineage.mrca(other) expected = Lineage(major="4", minor="8.7") assert actual == expected
def test_sameMajorOneHasMinors_returnsMajor(self): lineage = Lineage(major="4", minor="8.9") other = Lineage(major="4") actual = lineage.mrca(other) expected = other assert actual == expected
def test_twoLineagesSameMajorOneWithMinor_returnsOneWithMinor(self): l1 = Lineage(major="foo", minor="bar") l2 = Lineage(major="foo") actual = Lineage.call([l1, l2]) expected = l1 assert actual == expected
def test_sameMajorBothHaveMinorsOnDifferentBranches_returnsMajor(self): lineage = Lineage(major="4", minor="8.9") other = Lineage(major="4", minor="4.7.6") actual = lineage.mrca(other) expected = Lineage(major="4") assert actual == expected
def test_sameMajorAndMinors_returnsSame(self): lineage = Lineage(major="4", minor="3.4.5.8") other = Lineage(major="4", minor="3.4.5.8") actual = lineage.mrca(other) expected = lineage assert actual == expected
def test_sameMajorNoMinors_returnsMajor(self): lineage = Lineage(major="4") other = Lineage(major="4") actual = lineage.mrca(other) expected = lineage assert actual == expected
def test_threeLineagesSameMajorSameDepthMinor_returnsMRCA(self): l1 = Lineage(major="4", minor="1.3.4.5") l2 = Lineage(major="4", minor="1.3.6.6") l3 = Lineage(major="4", minor="1.3.6.8") actual = Lineage.call([l1, l2, l3]) expected = Lineage(major="4", minor="1.3") assert actual == expected
def test_threeLineagesWithMinorsDiffLen_returnsLongest(self): l1 = Lineage(major="4", minor="1.3.4.5.9") l2 = Lineage(major="4", minor="1.3.6") l3 = Lineage(major="4", minor="1.3.6.8") actual = Lineage.call([l1, l2, l3]) expected = Lineage(major="4", minor="1.3.4.5.9") assert actual == expected
def test_threeLineagesWithDiffMinorsSameLen_returnsMajor(self): l1 = Lineage(major="4", minor="1.3.4") l2 = Lineage(major="4", minor="2.3.6") l3 = Lineage(major="4", minor="3.3.6") actual = Lineage.call([l1, l2, l3]) expected = Lineage(major="4") assert actual == expected
def test_twoLineagesSameMajor_returnsLowestOnTree(self): l1 = Lineage(major="4", minor="1.3.4") l2 = Lineage(major="4", minor="8.3") classifier = Classifier() sample_idx = 0 actual = classifier.call_sample_lineage([l1, l2], sample_idx) expected = str(l1) assert actual == expected
def test_twoLineagesDiffMajor_returnsMixedDisregardMaxAlt(self): l1 = Lineage(major="4", minor="1.3.4") l2 = Lineage(major="5", minor="8.3") classifier = Classifier(max_alt_lineages=5) sample_idx = 0 actual = classifier.call_sample_lineage([l1, l2], sample_idx) expected = "mixed" assert actual == expected
def test_mixedLineagesBelowThreshold_returnsMostCommon(self): l1 = Lineage(major="4", minor="1.3.4") l2 = Lineage(major="4", minor="1.3") l3 = Lineage(major="5", minor="8.3") classifier = Classifier(max_alt_lineages=1) sample_idx = 0 actual = classifier.call_sample_lineage([l1, l2, l3], sample_idx) expected = str(l1) assert actual == expected
def test_withPrefixLineage_ignoresPrefix(self): s = "lineageBovis" actual = Lineage.from_str(s) expected = Lineage(major="Bovis") assert actual == expected
def test_oneLineage_returnsSameLineage(self): lineage = Lineage(major="foo", minor="bar") actual = Lineage.call([lineage]) expected = lineage assert actual == expected
def test_majorAndMinor_allMinorsLumpedInTogether(self): s = "lineage4.1.2.3.4.5" actual = Lineage.from_str(s) expected = Lineage(major="4", minor="1.2.3.4.5") assert actual == expected
def test_noHeader_allPanelVariantsInPanel(self): stream = StringIO( "lineage1,615938,1104,G/A,368,GAG/GAA,E/E,Rv0524,hemL\n" "lineage1.1,4404247,1056,G/A,352,CTG/CTA,L/L,Rv3915,-" ) actual = load_panel(stream) expected = { 615938: PanelVariant( Lineage("1"), 615938, "G", "A", "Rv0524", "hemL", 1104 ), 4404247: PanelVariant( Lineage("1", "1"), 4404247, "G", "A", "Rv3915", "-", 1056 ), } assert actual == expected
def test_fileWithNoIssues_loadsOk(self): stream = StringIO( "lineage,position,gene_coord,allele_change,codon_number,codon_change,amino_acid_change,locus_id,gene_name\n" "lineage1,615938,1104,G/A,368,GAG/GAA,E/E,Rv0524,hemL\n" "lineage1.1,4404247,1056,G/A,352,CTG/CTA,L/L,Rv3915,-" ) actual = load_panel(stream, no_header=False) expected = { 615938: PanelVariant( Lineage("1"), 615938, "G", "A", "Rv0524", "hemL", 1104 ), 4404247: PanelVariant( Lineage("1", "1"), 4404247, "G", "A", "Rv3915", "-", 1056 ), } assert actual == expected
def test_nonDefaultDelim_loadsOk(self): stream = StringIO( "lineage1|615938|1104|G/A|368|GAG/GAA|E/E|Rv0524|hemL\n" "lineage1.1|4404247|1056|G/A|352|CTG/CTA|L/L|Rv3915|-" ) delim = "|" actual = load_panel(stream, delim=delim) expected = { 615938: PanelVariant( Lineage("1"), 615938, "G", "A", "Rv0524", "hemL", 1104 ), 4404247: PanelVariant( Lineage("1", "1"), 4404247, "G", "A", "Rv3915", "-", 1056 ), } assert actual == expected
def test_oneLineage_returnsOnlyElement(self): l1 = Lineage(major="4", minor="1.3.4") classifier = Classifier() sample_idx = 0 actual = classifier.call_sample_lineage([l1], sample_idx) expected = str(l1) assert actual == expected
def test_geneNameIsEmpty_returnsNone(self): row = ",".join( ["lineage1", "615938", "1104", "G/A", "368", "GAG/GAA", "E/E", "foo", "",] ) actual = PanelVariant.from_row(row) expected = PanelVariant(Lineage("1"), 615938, "G", "A", "foo", None, 1104) assert actual == expected
def test_tabAsDelim_returnsExpected(self): delim = "\t" row = delim.join( ["lineage1", "615938", "1104", "G/A", "368", "GAG/GAA", "E/E", "foo", "",] ) actual = PanelVariant.from_row(row, delim=delim) expected = PanelVariant(Lineage("1"), 615938, "G", "A", "foo", None, 1104) assert actual == expected
def test_posNotInPanel_returnsFalse(self, mock_variant): index = { 1: PanelVariant(Lineage("1"), 1, "G", "A"), } classifier = Classifier(index) mock_variant.POS = 4 mock_variant.REF = "G" mock_variant.FILTER = None assert not classifier.is_variant_valid(mock_variant)
def test_variantRefDoesntMatchPanel_returnsFalse(self, mock_variant): index = { 1: PanelVariant(Lineage("1"), 1, "G", "A"), } classifier = Classifier(index) mock_variant.POS = 1 mock_variant.REF = "d" mock_variant.FILTER = None assert not classifier.is_variant_valid(mock_variant)
def test_oneLineageTooManyHets_returnsTooManyHets(self): l1 = Lineage(major="4", minor="1.3.4") classifier = Classifier(max_het=1) sample_idx = 0 classifier.het_counts[sample_idx] = 5 actual = classifier.call_sample_lineage([l1], sample_idx) expected = "too_many_hets" assert actual == expected
def test_panelVariantFailsFilter_returnsFalse(self, mock_variant): index = { 1: PanelVariant(Lineage("1"), 1, "G", "A"), } classifier = Classifier(index) mock_variant.POS = 1 mock_variant.REF = "G" mock_variant.ALT = ["T", "A"] mock_variant.FILTER = "FAIL" assert not classifier.is_variant_valid(mock_variant)
def test_refLineagePosPanelRefInAlt_returnsTrue(self, mock_variant): index = { 1: PanelVariant(Lineage("1"), 1, "G", "A"), } classifier = Classifier(index) mock_variant.POS = 1 mock_variant.REF = "G" mock_variant.ALT = ["T", "C"] mock_variant.FILTER = None assert not classifier.is_variant_valid(mock_variant)
def test_panelVariantAltNotInVariantAlts_returnsFalse(self, mock_variant): index = { 1: PanelVariant(Lineage("1"), 1, "G", "A"), } classifier = Classifier(index) mock_variant.POS = 1 mock_variant.REF = "G" mock_variant.ALT = ["T", "C"] mock_variant.FILTER = None assert not classifier.is_variant_valid(mock_variant)
def test_posNotInPanel_returnsEmpty(self, mocked_variant): index = { 4: PanelVariant(Lineage("1"), 1, "G", "A"), } classifier = Classifier(index) mocked_variant.POS = 1 mocked_variant.REF = "G" mocked_variant.ALT = ["T", "A"] mocked_variant.genotypes = [[2, -1, False], [2, 2, False]] mocked_variant.format.side_effect = KeyError actual = classifier.samples_with_lineage_variant(mocked_variant) expected = [] assert actual == expected
def test_sampleHasLineageVariantAndPassesFilter_returnsIndex(self, mocked_variant): index = { 1: PanelVariant(Lineage("1"), 1, "G", "A"), } classifier = Classifier(index) mocked_variant.POS = 1 mocked_variant.REF = "G" mocked_variant.ALT = ["T", "A", "N"] mocked_variant.genotypes = [[-1, -1, False], [2, 2, False]] mocked_variant.format.return_value = ["PASS", "PASS"] actual = classifier.samples_with_lineage_variant(mocked_variant) expected = [1] assert actual == expected
def test_hetSampleDoesntHaveLineageVariant_returnsEmpty(self, mocked_variant): index = { 1: PanelVariant(Lineage("1"), 1, "G", "A"), } classifier = Classifier(index) mocked_variant.POS = 1 mocked_variant.REF = "G" mocked_variant.ALT = ["T", "A", "N"] mocked_variant.genotypes = [[-1, -1, False], [1, 3, False]] mocked_variant.format.side_effect = KeyError actual = classifier.samples_with_lineage_variant(mocked_variant) expected = [] assert actual == expected