Example #1
0
def split_msa(msa, split_by = "123"):
    """Splits a MSA and returns a dictionary of keys to MSAs,
    using the keys in the 'split_by' parameter at the top
    level. See also pypeline.common.sequences.split."""
    validate_msa(msa)
    if not split_by:
        raise TypeError("No partitions to split by specified")

    results = {}
    for key in split_by:
        results[key] = dict((name, {}) for name in msa)

    for (name, sequence) in msa.iteritems():
        for (key, partition) in split(sequence, split_by).iteritems():
            results[key][name] = partition

    return results
Example #2
0
    def split(self, split_by = "123"):
        """Splits a MSA and returns a dictionary of keys to MSAs,
        using the keys in the 'split_by' parameter at the top
        level. See also pypeline.common.sequences.split."""
        self.validate(self)
        if not split_by:
            raise TypeError("No partitions to split by specified")

        results = dict((key, set()) for key in split_by)
        for record in self:
            for (key, partition) in split(record.sequence, split_by).iteritems():
                results[key].add(FASTA(record.name, None, partition))

        for (key, value) in results.items():
            results[key] = MSA(value)

        return results
Example #3
0
def split_msa(msa, split_by="123"):
    """Splits a MSA and returns a dictionary of keys to MSAs,
    using the keys in the 'split_by' parameter at the top
    level. See also pypeline.common.sequences.split."""
    validate_msa(msa)
    if not split_by:
        raise TypeError("No partitions to split by specified")

    results = {}
    for key in split_by:
        results[key] = dict((name, {}) for name in msa)

    for (name, sequence) in msa.iteritems():
        for (key, partition) in split(sequence, split_by).iteritems():
            results[key][name] = partition

    return results
Example #4
0
def test_split__three_groups():
    expected = {"1": "AC", "2": "CA", "3": "GT"}
    assert_equal(split("ACGCAT", "123"), expected)
    assert_equal(split("ACGCAT"), expected)
Example #5
0
def test_split__two_groups():
    assert_equal(split("ACGCAT", "112"), {"1": "ACCA", "2": "GT"})
Example #6
0
def test_split__single_group():
    assert_equal(split("ACGCAT", "111"), {'1': 'ACGCAT'})
Example #7
0
def test_split__no_split_by():
    split("", split_by="")
Example #8
0
def test_split__empty_sequence():
    assert_equal(split(""), {"1": "", "2": "", "3": ""})
Example #9
0
def test_split__partial_group():
    expected = {"1" : "AA", "2" : "CA", "3" : "G"}
    assert_equal(split("ACGAA"), expected)
Example #10
0
def test_split__three_groups():
    expected = {"1" : "AC", "2" : "CA", "3" : "GT"}
    assert_equal(split("ACGCAT", "123"), expected)
    assert_equal(split("ACGCAT"), expected)
Example #11
0
def test_split__two_groups():
    assert_equal(split("ACGCAT", "112"), {"1" : "ACCA", "2" : "GT"})
Example #12
0
def test_split__single_group():
    assert_equal(split("ACGCAT", "111"), {'1' : 'ACGCAT'})
Example #13
0
def test_split__no_split_by():
    split("", split_by = "")
Example #14
0
def test_split__empty_sequence():
    assert_equal(split(""), {"1" : "", "2" : "", "3" : ""})
Example #15
0
def test_split__empty_group():
    expected = {"1": "A", "2": "C", "3": ""}
    assert_equal(split("AC"), expected)
Example #16
0
def test_split__partial_group():
    expected = {"1": "AA", "2": "CA", "3": "G"}
    assert_equal(split("ACGAA"), expected)
Example #17
0
def test_split__empty_group():
    expected = {"1" : "A", "2" : "C", "3" : ""}
    assert_equal(split("AC"), expected)