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 paleomix.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).items(): results[key].add(FASTA(record.name, None, partition)) for (key, value) in results.items(): results[key] = MSA(value) return results
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 paleomix.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
def test_split__empty_sequence(): assert_equal(split(""), {"1": "", "2": "", "3": ""})
def test_split__partial_group(): expected = {"1": "AA", "2": "CA", "3": "G"} assert split("ACGAA") == expected
def test_split__empty_group(): expected = {"1": "A", "2": "C", "3": ""} assert split("AC") == expected
def test_split__no_split_by(): split("", split_by="")
def test_split__empty_group(): expected = {"1": "A", "2": "C", "3": ""} assert_equal(split("AC"), expected)
def test_split__two_groups(): assert_equal(split("ACGCAT", "112"), {"1": "ACCA", "2": "GT"})
def test_split__empty_sequence(): assert split("") == {"1": "", "2": "", "3": ""}
def test_split__partial_group(): expected = {"1": "AA", "2": "CA", "3": "G"} assert_equal(split("ACGAA"), expected)
def test_split__three_groups(): expected = {"1": "AC", "2": "CA", "3": "GT"} assert_equal(split("ACGCAT", "123"), expected) assert_equal(split("ACGCAT"), expected)
def test_split__single_group(): assert_equal(split("ACGCAT", "111"), {'1': 'ACGCAT'})
def test_split__no_split_by(): with pytest.raises(ValueError, match="No split_by specified"): split("", split_by="")
def test_split__single_group(): assert split("ACGCAT", "111") == {"1": "ACGCAT"}
def test_split__two_groups(): assert split("ACGCAT", "112") == {"1": "ACCA", "2": "GT"}
def test_split__three_groups(): expected = {"1": "AC", "2": "CA", "3": "GT"} assert split("ACGCAT", "123") == expected assert split("ACGCAT") == expected