def test_taxa_score(self): """score taxa strings in the face of replicates""" master = {'a':['k__k1','p__p1','c__c1','o__o1','f__f1','g__g1','s__s1'], 'b':['k__k1','p__p1','c__c2',None,'f__f2','g__g1','s__s2'], 'c':[None,None,None,None,None,None,None], 'd':['k__k2','p__x','c__c1','o__o10','f__f2','g__g2','s__s3']} rep1 = {'a':['k__k1','p__p1','c__c1','o__o1','f__f1','g__g1','s__s1'], 'c':[None,None,None,None,None,None,None], 'd':['k__k2','','c__c1','f__f2','f__f2','g__g2','s__s3']} rep2 = {'a':['k__k1','p__p1','c__c1','o__o1','f__f1','g__g1','s__s1'], 'b':['k__k1','p__p1','c__c2',None,'f__f2','g__g1','s__s9'], 'c':[None,None,None,None,None,None,None]} rep3 = {'a':['k__k1','p__p1','c__c1','o__o1','f__f1','g__g1','s__s1'], 'b':['k__k1','p__p1','c__c2',None,'f__f2','g__g1','s__s2'], 'd':['k__k2','','c__c1','f__f2','f__f2','g__g2','s__s3']} rep4 = {'a':['k__k1','p__p1','c__c1','o__o1','f__f1','g__g1','s__s1'], 'b':['k__k1','p__p1','c__c10',None,'f__f2','g__g1','s__s2'], 'c':[None,None,None,None,None,None,None], 'd':['k__k1','','c__c1','f__f2','f__f2','g__g2','s__s3']} # if malformed, as in rep3 rep4 for d, count as contridiction exp = {'a':[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0], 'b':[1.0, 1.0, 0.75, 1.0, 1.0, 1.0, 0.75], 'c':[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0], 'd':[0.75, 0.25, 1.0, 0.25, 1.0, 1.0, 1.0]} obs = taxa_score(master, [rep1,rep2,rep3,rep4]) self.assertEqual(obs, exp)
def test_merge_taxa_strings_and_scores(self): """merge taxa scores and the strings""" master = {'a':['k__k1','p__p1','c__c1','o__o1','f__f1','g__g1','s__s1'], 'b':['k__k1','p__p1','c__c2',None,'f__f2','g__g1','s__s2'], 'c':[None,None,None,None,None,None,None], 'd':['k__k2','p__x','c__c1','o__o10','f__f2','g__g2','s__s3']} rep1 = {'a':['k__k1','p__p1','c__c1','o__o1','f__f1','g__g1','s__s1'], 'c':[None,None,None,None,None,None,None], 'd':['k__k2','','c__c1','f__f2','f__f2','g__g2','s__s3']} rep2 = {'a':['k__k1','p__p1','c__c1','o__o1','f__f1','g__g1','s__s1'], 'b':['k__k1','p__p1','c__c2',None,'f__f2','g__g1','s__s9'], 'c':[None,None,None,None,None,None,None]} rep3 = {'a':['k__k1','p__p1','c__c1','o__o1','f__f1','g__g1','s__s1'], 'b':['k__k1','p__p1','c__c2',None,'f__f2','g__g1','s__s2'], 'd':['k__k2','','c__c1','f__f2','f__f2','g__g2','s__s3']} rep4 = {'a':['k__k1','p__p1','c__c1','o__o1','f__f1','g__g1','s__s1'], 'b':['k__k1','p__p1','c__c10',None,'f__f2','g__g1','s__s2'], 'c':[None,None,None,None,None,None,None], 'd':['k__k1','','c__c1','f__f2','f__f2','g__g2','s__s3']} scores = taxa_score(master, [rep1, rep2, rep3, rep4]) exp = {'a':[('k__k1',1.0), ('p__p1',1.0), ('c__c1',1.0), ('o__o1',1.0), ('f__f1',1.0), ('g__g1',1.0), ('s__s1',1.0)], 'b':[('k__k1',1.0), ('p__p1',1.0), ('c__c2',0.75), (None,1.0), ('f__f2',1.0), ('g__g1',1.0), ('s__s2',0.75)], 'c':[(None,1.0), (None,1.0), (None,1.0), (None,1.0), (None,1.0), (None,1.0), (None,1.0)], 'd':[('k__k2',0.75), ('p__x',0.25), ('c__c1',1.0), ('o__o10',0.25), ('f__f2',1.0), ('g__g2',1.0), ('s__s3',1.0)]} obs = merge_taxa_strings_and_scores(master, scores) self.assertEqual(obs,exp)
def test_merge_taxa_strings_and_scores(self): """merge taxa scores and the strings""" master = { 'a': ['k__k1', 'p__p1', 'c__c1', 'o__o1', 'f__f1', 'g__g1', 's__s1'], 'b': ['k__k1', 'p__p1', 'c__c2', None, 'f__f2', 'g__g1', 's__s2'], 'c': [None, None, None, None, None, None, None], 'd': ['k__k2', 'p__x', 'c__c1', 'o__o10', 'f__f2', 'g__g2', 's__s3'] } rep1 = { 'a': ['k__k1', 'p__p1', 'c__c1', 'o__o1', 'f__f1', 'g__g1', 's__s1'], 'c': [None, None, None, None, None, None, None], 'd': ['k__k2', '', 'c__c1', 'f__f2', 'f__f2', 'g__g2', 's__s3'] } rep2 = { 'a': ['k__k1', 'p__p1', 'c__c1', 'o__o1', 'f__f1', 'g__g1', 's__s1'], 'b': ['k__k1', 'p__p1', 'c__c2', None, 'f__f2', 'g__g1', 's__s9'], 'c': [None, None, None, None, None, None, None] } rep3 = { 'a': ['k__k1', 'p__p1', 'c__c1', 'o__o1', 'f__f1', 'g__g1', 's__s1'], 'b': ['k__k1', 'p__p1', 'c__c2', None, 'f__f2', 'g__g1', 's__s2'], 'd': ['k__k2', '', 'c__c1', 'f__f2', 'f__f2', 'g__g2', 's__s3'] } rep4 = { 'a': ['k__k1', 'p__p1', 'c__c1', 'o__o1', 'f__f1', 'g__g1', 's__s1'], 'b': ['k__k1', 'p__p1', 'c__c10', None, 'f__f2', 'g__g1', 's__s2'], 'c': [None, None, None, None, None, None, None], 'd': ['k__k1', '', 'c__c1', 'f__f2', 'f__f2', 'g__g2', 's__s3'] } scores = taxa_score(master, [rep1, rep2, rep3, rep4]) exp = { 'a': [('k__k1', 1.0), ('p__p1', 1.0), ('c__c1', 1.0), ('o__o1', 1.0), ('f__f1', 1.0), ('g__g1', 1.0), ('s__s1', 1.0)], 'b': [('k__k1', 1.0), ('p__p1', 1.0), ('c__c2', 0.75), (None, 1.0), ('f__f2', 1.0), ('g__g1', 1.0), ('s__s2', 0.75)], 'c': [(None, 1.0), (None, 1.0), (None, 1.0), (None, 1.0), (None, 1.0), (None, 1.0), (None, 1.0)], 'd': [('k__k2', 0.75), ('p__x', 0.25), ('c__c1', 1.0), ('o__o10', 0.25), ('f__f2', 1.0), ('g__g2', 1.0), ('s__s3', 1.0)] } obs = merge_taxa_strings_and_scores(master, scores) self.assertEqual(obs, exp)
def test_taxa_score(self): """score taxa strings in the face of replicates""" master = { 'a': ['k__k1', 'p__p1', 'c__c1', 'o__o1', 'f__f1', 'g__g1', 's__s1'], 'b': ['k__k1', 'p__p1', 'c__c2', None, 'f__f2', 'g__g1', 's__s2'], 'c': [None, None, None, None, None, None, None], 'd': ['k__k2', 'p__x', 'c__c1', 'o__o10', 'f__f2', 'g__g2', 's__s3'] } rep1 = { 'a': ['k__k1', 'p__p1', 'c__c1', 'o__o1', 'f__f1', 'g__g1', 's__s1'], 'c': [None, None, None, None, None, None, None], 'd': ['k__k2', '', 'c__c1', 'f__f2', 'f__f2', 'g__g2', 's__s3'] } rep2 = { 'a': ['k__k1', 'p__p1', 'c__c1', 'o__o1', 'f__f1', 'g__g1', 's__s1'], 'b': ['k__k1', 'p__p1', 'c__c2', None, 'f__f2', 'g__g1', 's__s9'], 'c': [None, None, None, None, None, None, None] } rep3 = { 'a': ['k__k1', 'p__p1', 'c__c1', 'o__o1', 'f__f1', 'g__g1', 's__s1'], 'b': ['k__k1', 'p__p1', 'c__c2', None, 'f__f2', 'g__g1', 's__s2'], 'd': ['k__k2', '', 'c__c1', 'f__f2', 'f__f2', 'g__g2', 's__s3'] } rep4 = { 'a': ['k__k1', 'p__p1', 'c__c1', 'o__o1', 'f__f1', 'g__g1', 's__s1'], 'b': ['k__k1', 'p__p1', 'c__c10', None, 'f__f2', 'g__g1', 's__s2'], 'c': [None, None, None, None, None, None, None], 'd': ['k__k1', '', 'c__c1', 'f__f2', 'f__f2', 'g__g2', 's__s3'] } # if malformed, as in rep3 rep4 for d, count as contridiction exp = { 'a': array([1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]), 'b': array([1.0, 1.0, 0.75, 1.0, 1.0, 1.0, 0.75]), 'c': array([1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]), 'd': array([0.75, 0.25, 1.0, 0.25, 1.0, 1.0, 1.0]) } obs = taxa_score(master, [rep1, rep2, rep3, rep4]) self.assertEqual(obs.keys(), exp.keys()) for k in exp: self.assertTrue(array_equal(obs[k], exp[k]))