def test_overlapping_names(self): # here the 3rd level is different, but the 4th level is the same # across the three assignments. this can happen in practice if # three different genera are assigned, and under each there is # an unnamed species # (e.g., f__x;g__A;s__, f__x;g__B;s__, f__x;g__B;s__) # in this case, the assignment should be f__x. in_ = [['Ab', 'Bc', 'De', 'Jk'], ['Ab', 'Bc', 'Fg', 'Jk'], ['Ab', 'Bc', 'Hi', 'Jk']] actual = _compute_consensus_annotation(in_, 0.51, "Unassigned") expected = (['Ab', 'Bc'], 1.) self.assertEqual(actual, expected) # here the third level is the same in 4/5 of the # assignments, but one of them (z, y, c) refers to a # different taxa since the higher levels are different. # the consensus value should be 3/5, not 4/5, to # reflect that. in_ = [['a', 'b', 'c'], ['a', 'd', 'e'], ['a', 'b', 'c'], ['a', 'b', 'c'], ['z', 'y', 'c']] actual = _compute_consensus_annotation(in_, 0.51, "Unassigned") expected = (['a', 'b', 'c'], 0.6) self.assertEqual(actual, expected)
def test_single_annotation(self): in_ = [['Ab', 'Bc', 'De']] actual = _compute_consensus_annotation(in_, 1.0, "Unassigned") expected = (['Ab', 'Bc', 'De'], 1.0) self.assertEqual(actual, expected) actual = _compute_consensus_annotation(in_, 0.501, "Unassigned") expected = (['Ab', 'Bc', 'De'], 1.0) self.assertEqual(actual, expected)
def test_single_annotation(self): in_ = [['Ab', 'Bc', 'De']] actual = _compute_consensus_annotation(in_, 1.0, "Unassigned") expected = (['Ab', 'Bc', 'De'], 1.0) self.assertEqual(actual, expected) actual = _compute_consensus_annotation(in_, 0.501, "Unassigned") expected = (['Ab', 'Bc', 'De'], 1.0) self.assertEqual(actual, expected)
def test_no_consensus(self): in_ = [['Ab', 'Bc', 'De'], ['Cd', 'Bc', 'Fg', 'Hi'], ['Ef', 'Bc', 'Fg', 'Jk']] actual = _compute_consensus_annotation(in_, 0.51, "Unassigned") expected = (['Unassigned'], 1.) self.assertEqual(actual, expected) actual = _compute_consensus_annotation( in_, 0.51, unassignable_label="Hello world!") expected = (['Hello world!'], 1.) self.assertEqual(actual, expected)
def test_no_consensus(self): in_ = [['Ab', 'Bc', 'De'], ['Cd', 'Bc', 'Fg', 'Hi'], ['Ef', 'Bc', 'Fg', 'Jk']] actual = _compute_consensus_annotation(in_, 0.51, "Unassigned") expected = (['Unassigned'], 1.) self.assertEqual(actual, expected) actual = _compute_consensus_annotation( in_, 0.51, unassignable_label="Hello world!") expected = (['Hello world!'], 1.) self.assertEqual(actual, expected)
def test_varied_min_fraction(self): in_ = [['Ab', 'Bc', 'De'], ['Ab', 'Bc', 'Fg', 'Hi'], ['Ab', 'Bc', 'Fg', 'Jk']] actual = _compute_consensus_annotation(in_, 0.51, "Unassigned") expected = (['Ab', 'Bc', 'Fg'], 2. / 3.) self.assertEqual(actual, expected) # increased min_consensus_fraction yields decreased specificity in_ = [['Ab', 'Bc', 'De'], ['Ab', 'Bc', 'Fg', 'Hi'], ['Ab', 'Bc', 'Fg', 'Jk']] actual = _compute_consensus_annotation(in_, 0.99, "Unassigned") expected = (['Ab', 'Bc'], 1.0) self.assertEqual(actual, expected)
def test_adjusts_resolution(self): # max result depth is that of shallowest assignment in_ = [['Ab', 'Bc', 'Fg'], ['Ab', 'Bc', 'Fg', 'Hi'], ['Ab', 'Bc', 'Fg', 'Hi'], ['Ab', 'Bc', 'Fg', 'Hi'], ['Ab', 'Bc', 'Fg', 'Hi', 'Jk']] actual = _compute_consensus_annotation(in_, 0.51, "Unassigned") expected = (['Ab', 'Bc', 'Fg'], 1.0) self.assertEqual(actual, expected) in_ = [['Ab', 'Bc', 'Fg'], ['Ab', 'Bc', 'Fg', 'Hi', 'Jk'], ['Ab', 'Bc', 'Fg', 'Hi', 'Jk'], ['Ab', 'Bc', 'Fg', 'Hi', 'Jk'], ['Ab', 'Bc', 'Fg', 'Hi', 'Jk']] actual = _compute_consensus_annotation(in_, 0.51, "Unassigned") expected = (['Ab', 'Bc', 'Fg'], 1.0) self.assertEqual(actual, expected)
def test_varied_min_fraction(self): in_ = [['Ab', 'Bc', 'De'], ['Ab', 'Bc', 'Fg', 'Hi'], ['Ab', 'Bc', 'Fg', 'Jk']] actual = _compute_consensus_annotation(in_, 0.51, "Unassigned") expected = (['Ab', 'Bc', 'Fg'], 2. / 3.) self.assertEqual(actual, expected) # increased min_consensus_fraction yields decreased specificity in_ = [['Ab', 'Bc', 'De'], ['Ab', 'Bc', 'Fg', 'Hi'], ['Ab', 'Bc', 'Fg', 'Jk']] actual = _compute_consensus_annotation(in_, 0.99, "Unassigned") expected = (['Ab', 'Bc'], 1.0) self.assertEqual(actual, expected)
def test_adjusts_resolution(self): # max result depth is that of shallowest assignment in_ = [['Ab', 'Bc', 'Fg'], ['Ab', 'Bc', 'Fg', 'Hi'], ['Ab', 'Bc', 'Fg', 'Hi'], ['Ab', 'Bc', 'Fg', 'Hi'], ['Ab', 'Bc', 'Fg', 'Hi', 'Jk']] actual = _compute_consensus_annotation(in_, 0.51, "Unassigned") expected = (['Ab', 'Bc', 'Fg'], 1.0) self.assertEqual(actual, expected) in_ = [['Ab', 'Bc', 'Fg'], ['Ab', 'Bc', 'Fg', 'Hi', 'Jk'], ['Ab', 'Bc', 'Fg', 'Hi', 'Jk'], ['Ab', 'Bc', 'Fg', 'Hi', 'Jk'], ['Ab', 'Bc', 'Fg', 'Hi', 'Jk']] actual = _compute_consensus_annotation(in_, 0.51, "Unassigned") expected = (['Ab', 'Bc', 'Fg'], 1.0) self.assertEqual(actual, expected)
def test_overlapping_names(self): # here the 3rd level is different, but the 4th level is the same # across the three assignments. this can happen in practice if # three different genera are assigned, and under each there is # an unnamed species # (e.g., f__x;g__A;s__, f__x;g__B;s__, f__x;g__B;s__) # in this case, the assignment should be f__x. in_ = [['Ab', 'Bc', 'De', 'Jk'], ['Ab', 'Bc', 'Fg', 'Jk'], ['Ab', 'Bc', 'Hi', 'Jk']] actual = _compute_consensus_annotation(in_, 0.51, "Unassigned") expected = (['Ab', 'Bc'], 1.) self.assertEqual(actual, expected) # here the third level is the same in 4/5 of the # assignments, but one of them (z, y, c) refers to a # different taxa since the higher levels are different. # the consensus value should be 3/5, not 4/5, to # reflect that. in_ = [['a', 'b', 'c'], ['a', 'd', 'e'], ['a', 'b', 'c'], ['a', 'b', 'c'], ['z', 'y', 'c']] actual = _compute_consensus_annotation(in_, 0.51, "Unassigned") expected = (['a', 'b', 'c'], 0.6) self.assertEqual(actual, expected)