本文整理汇总了Python中paleomix.common.formats.msa.MSA类的典型用法代码示例。如果您正苦于以下问题:Python MSA类的具体用法?Python MSA怎么用?Python MSA使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MSA类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _read_sequences
def _read_sequences(filenames):
results = {}
for filename in filenames:
results[filename] = MSA.from_file(filename)
MSA.validate(*results.values())
return results.iteritems()
示例2: test_msa_exclude__remove_one
def test_msa_exclude__remove_one():
fa_1 = FASTA("A", None, "ACGT")
fa_2 = FASTA("B", None, "GCTA")
initial = MSA([fa_1, fa_2])
expected = MSA([fa_1])
result = initial.exclude(["B"])
assert_equal(result, expected)
示例3: _teardown
def _teardown(self, config, temp):
# Validate output from MAFFT
output_file = reroot_path(temp, self._output_file)
try:
MSA.from_file(output_file)
except MSAError, error:
raise NodeError("Invalid MSA produced by MAFFT:\n%s" % (error,))
示例4: interleaved_phy
def interleaved_phy(msa, add_flag = False, max_name_length = _MAX_NAME_LENGTH):
MSA.validate(msa)
header = "%i %i" % (len(msa), msa.seqlen())
if add_flag:
header += " I"
result = [header, ""]
padded_len = min(max_name_length, max(len(name) for name in msa.names())) + 2
padded_len -= padded_len % -(_BLOCK_SIZE + _BLOCK_SPACING) + _BLOCK_SPACING
streams = []
spacing = " " * _BLOCK_SPACING
for record in sorted(msa):
name = record.name[:max_name_length]
padding = (padded_len - len(name)) * " "
lines = []
line = [name, padding]
for block in grouper(_BLOCK_SIZE, record.sequence, fillvalue = ""):
block = "".join(block)
if sum(len(segment) for segment in line) >= _LINE_SIZE:
lines.append("".join(line))
line = [block]
else:
line.extend((spacing, block))
lines.append("".join(line))
streams.append(lines)
for rows in zip(*streams):
result.extend(row for row in rows)
result.append("")
result.pop()
return "\n".join(result)
示例5: test_msa_split_msa__two_groups
def test_msa_split_msa__two_groups():
msa = MSA([FASTA("seq1", None, "ACGCAT"),
FASTA("seq2", None, "GAGTGA")])
expected = {"1": MSA([FASTA("seq1", None, "ACCA"),
FASTA("seq2", None, "GATG")]),
"2": MSA([FASTA("seq1", None, "GT"),
FASTA("seq2", None, "GA")])}
assert_equal(msa.split("112"), expected)
示例6: test_msa_to_file__complete_line_test
def test_msa_to_file__complete_line_test():
msa = MSA([FASTA("barfoo", None, "ACGATA" * 10 + "CGATAG" * 5),
FASTA("foobar", None, "CGAATG" * 10 + "TGTCAT" * 5)])
expected = ">barfoo\n%s\n%s\n" % ("ACGATA" * 10, "CGATAG" * 5)
expected += ">foobar\n%s\n%s\n" % ("CGAATG" * 10, "TGTCAT" * 5)
stringf = StringIO.StringIO()
MSA.to_file(msa, stringf)
assert_equal(stringf.getvalue(), expected)
示例7: test_msa_reduce__multiple_empty_column__all_empty_column_are_removed
def test_msa_reduce__multiple_empty_column__all_empty_column_are_removed():
fa_1 = FASTA("Name_A", "Meta_A", "-AnTN")
fa_2 = FASTA("Name_B", "Meta_B", "NC-NN")
initial = MSA([fa_1, fa_2])
fa_reduced_1 = FASTA("Name_A", "Meta_A", "AT")
fa_reduced_2 = FASTA("Name_B", "Meta_B", "CN")
expected = MSA([fa_reduced_1, fa_reduced_2])
assert_equal(initial.reduce(), expected)
示例8: test_msa_split__empty_group
def test_msa_split__empty_group():
msa = MSA([FASTA("seq1", None, "AC"),
FASTA("seq2", None, "GA")])
expected = {"1": MSA([FASTA("seq1", None, "A"),
FASTA("seq2", None, "G")]),
"2": MSA([FASTA("seq1", None, "C"),
FASTA("seq2", None, "A")]),
"3": MSA([FASTA("seq1", None, ""),
FASTA("seq2", None, "")])}
assert_equal(msa.split("123"), expected)
示例9: test_msa_split__partial_group
def test_msa_split__partial_group():
msa = MSA([FASTA("seq1", None, "ACGCA"),
FASTA("seq2", None, "GAGTG")])
expected = {"1": MSA([FASTA("seq1", None, "AC"),
FASTA("seq2", None, "GT")]),
"2": MSA([FASTA("seq1", None, "CA"),
FASTA("seq2", None, "AG")]),
"3": MSA([FASTA("seq1", None, "G"),
FASTA("seq2", None, "G")])}
assert_equal(msa.split("123"), expected)
示例10: _run
def _run(self, _config, temp):
# Read and check that MSAs share groups
msas = [MSA.from_file(filename) for filename in sorted(self.input_files)]
MSA.validate(*msas)
blocks = []
for msa in msas:
blocks.append(sequential_phy(msa, add_flag = self._add_flag))
with open(reroot_path(temp, self._out_phy), "w") as output:
output.write("\n\n".join(blocks))
示例11: sequential_phy
def sequential_phy(msa, add_flag = False, max_name_length = _MAX_NAME_LENGTH):
MSA.validate(msa)
header = "%i %i" % (len(msa), msa.seqlen())
if add_flag:
header += " S"
spacing = " " * _BLOCK_SPACING
result = [header, ""]
for record in sorted(msa):
result.append(record.name[:max_name_length])
blocks = grouper(_BLOCK_SIZE, record.sequence, fillvalue = "")
lines = grouper(_NUM_BLOCKS, blocks)
for line in lines:
result.append(spacing.join("".join(block) for block in line if block))
return "\n".join(result)
示例12: _run
def _run(self, _config, temp):
alignment = MSA.from_file(self._input_file)
for (to_filter, groups) in self._filter_by.iteritems():
alignment = alignment.filter_singletons(to_filter, groups)
temp_filename = fileutils.reroot_path(temp, self._output_file)
with open(temp_filename, "w") as handle:
alignment.to_file(handle)
fileutils.move_file(temp_filename, self._output_file)
示例13: _is_sufficently_covered
def _is_sufficently_covered(filepath, min_coverage):
msa = MSA.from_file(filepath)
if msa.seqlen() % 3:
return False
total_bases_not_covered = 0
for fasta_record in msa:
total_bases_not_covered += fasta_record.sequence.upper().count("N")
total_bases_not_covered += fasta_record.sequence.count("-")
total_bases = float(len(msa) * msa.seqlen())
frac_covered = 1.0 - total_bases_not_covered / total_bases
return frac_covered >= min_coverage
示例14: test_msa_from_file__compressed_bz2
def test_msa_from_file__compressed_bz2():
expected = MSA([FASTA("This_is_BZ_FASTA!", None, "CGTNA"),
FASTA("This_is_ALSO_BZ_FASTA!", None, "ACGTN")])
results = MSA.from_file(test_file("fasta_file.fasta.bz2"))
assert_equal(results, expected)
示例15: test_msa_join__single_msa
def test_msa_join__single_msa():
result = MSA.join(_JOIN_MSA_1)
assert_equal(result, _JOIN_MSA_1)