def tree_twoway_counts(tree, alphabet=DnaPairs, average=True, attr='Sequence'):
    """From tree, return dict of Count objects.

    Note: if average is True, only has counts in m[i,j] or m[j,i], not both.
    """
    leaves = list(tree.traverse())
    result = {}
    if average:
        #return symmetric matrix
        for first, second in two_item_combos(leaves):
            seq_1 = getattr(first, attr)
            seq_2 = getattr(second, attr)
            result[(first.Id, second.Id)] = \
                Counts.fromPair(seq_1, seq_2, alphabet)
    else:
        for first, second in two_item_combos(leaves):
            seq_1 = getattr(first, attr)
            seq_2 = getattr(second, attr)
            result[(first.Id, second.Id)] = \
                Counts.fromPair(seq_1, seq_2, alphabet,False)
            result[(second.Id, first.Id)] = \
                Counts.fromPair(seq_2, seq_1, alphabet,False)
    return result
Exemple #2
0
def tree_twoway_counts(tree, alphabet=DnaPairs, average=True, attr='Sequence'):
    """From tree, return dict of Count objects.

    Note: if average is True, only has counts in m[i,j] or m[j,i], not both.
    """
    leaves = list(tree.traverse())
    result = {}
    if average:
        #return symmetric matrix
        for first, second in two_item_combos(leaves):
            seq_1 = getattr(first, attr)
            seq_2 = getattr(second, attr)
            result[(first.Id, second.Id)] = \
                Counts.fromPair(seq_1, seq_2, alphabet)
    else:
        for first, second in two_item_combos(leaves):
            seq_1 = getattr(first, attr)
            seq_2 = getattr(second, attr)
            result[(first.Id, second.Id)] = \
                Counts.fromPair(seq_1, seq_2, alphabet,False)
            result[(second.Id, first.Id)] = \
                Counts.fromPair(seq_2, seq_1, alphabet,False)
    return result
Exemple #3
0
 def test_two_item_combos(self):
     """two_item_combos should return items in correct order"""
     items = list(two_item_combos("abcd"))
     self.assertEqual(items, map(tuple, ["ab", "ac", "ad", "bc", "bd", "cd"]))
Exemple #4
0
 def test_two_item_combos(self):
     """two_item_combos should return items in correct order"""
     items = list(two_item_combos('abcd'))
     self.assertEqual(items, map(tuple,
                                 ['ab', 'ac', 'ad', 'bc', 'bd', 'cd']))
Exemple #5
0
 def test_two_item_combos(self):
     """two_item_combos should return items in correct order"""
     items = list(two_item_combos('abcd'))
     self.assertEqual(items, map(tuple, ['ab','ac','ad','bc','bd','cd']))