Пример #1
0
 def test_run_randomise_sample_toobig(self):
     # raises ValueError, sample size too big (only 3 trees in this file)
     nex = NexusReader(self.filename)
     with self.assertRaises(ValueError):
         run_random(10, nex)
Пример #2
0
def test_reader_from_blocks():
    n = NexusReader(custom=['begin custom;', '[comment]', 'end;'])
    assert hasattr(n, 'custom')
Пример #3
0
def test_error_on_missing_file(examples):
    with pytest.raises(IOError):
        NexusReader(examples / 'sausage.nex')
Пример #4
0
def hash(salt, value):
    return hashlib.md5(("%s-%s" % (salt, value)).encode('ascii')).hexdigest()


if __name__ == '__main__':  # pragma: no cover
    from optparse import OptionParser
    parser = OptionParser(usage="usage: %prog fudge.nex output.nex")
    options, args = parser.parse_args()

    try:
        nexusname = args[0]
    except IndexError:
        print(__doc__)
        print("Author: %s\n" % __author__)
        parser.print_help()
        sys.exit()

    try:
        newnexus = args[1]
    except IndexError:
        newnexus = None

    nexus = NexusReader(nexusname)
    nexus = anonymise(nexus)

    if newnexus is not None:
        nexus.write_to_file(newnexus)
        print("New nexus written to %s" % newnexus)
    else:
        print(nexus.write_to_file(hash('filename', nexusname)))
Пример #5
0
 def test_error_on_missing_file(self):
     with self.assertRaises(IOError):
         NexusReader(os.path.join(EXAMPLE_DIR, 'sausage.nex'))
Пример #6
0
 def test_regression(self):
     nex = NexusReader(os.path.join(REGRESSION_DIR, 'ape_random.trees'))
     assert nex.trees.ntrees == 2
Пример #7
0
 def setUp(self):
     self.nex = NexusReader(
         os.path.join(REGRESSION_DIR, 'detranslate-with-dash.trees')
     )
Пример #8
0
def glottolog(regression):
    """
    Regression: Test that we can read glottolog tree format.
    """
    return NexusReader(regression / 'glottolog.trees')
Пример #9
0
def mesquite_branches(regression):
    return NexusReader(regression / 'mesquite_formatted_branches.trees')
Пример #10
0
def taxlabels(regression):
    """
    Regression: Test that we can read taxalabels delimited by spaces not new
    lines.
    """
    return NexusReader(regression / 'taxlabels.nex')
Пример #11
0
def mesquite(regression):
    return NexusReader(regression / 'mesquite_taxa_block.nex')
Пример #12
0
def int_length(regression):
    return NexusReader(regression / 'branchlengths-in-integers.trees')
Пример #13
0
def with_dash(regression):
    return NexusReader(regression / 'detranslate-with-dash.trees')
Пример #14
0
def bad_chars(regression):
    return NexusReader(regression / 'bad_chars_in_taxaname.trees')
Пример #15
0
 def setUp(self):
     self.nex = NexusReader(
         os.path.join(REGRESSION_DIR, 'taxlabels.nex')
     )
Пример #16
0
def test_TreeHandler_Regression_RandomAPETrees_regression(regression):
    """Regression: Test that we can parse randomly generated APE/R trees"""
    nex = NexusReader(regression / 'ape_random.trees')
    assert nex.trees.ntrees == 2
Пример #17
0
 def setUp(self):
     self.nex = NexusReader(
         os.path.join(REGRESSION_DIR, 'glottolog.trees')
     )
def test_detranslate(trees_translated, examples):
    assert not trees_translated.trees._been_detranslated
    trees_translated.trees.detranslate()
    # should NOW be the same as tree 0 in example.trees
    other_tree_file = NexusReader(str(examples / 'example.trees'))
    assert other_tree_file.trees[0] == trees_translated.trees[0]
Пример #19
0
 def setUp(self):
     self.nex = NexusReader(
         os.path.join(REGRESSION_DIR, 'bad_chars_in_taxaname.trees')
     )
Пример #20
0
 def setUp(self):
     self.nex = NexusReader(
         os.path.join(EXAMPLE_DIR, 'example-beast.trees')
     )
Пример #21
0
 def setUp(self):
     self.nex = NexusReader(
         os.path.join(REGRESSION_DIR, 'branchlengths-in-integers.trees')
     )
Пример #22
0
 def setUp(self):
     self.nex = NexusReader(
         os.path.join(EXAMPLE_DIR, 'example-translated.trees')
     )
Пример #23
0
 def test_read_file(self):
     nex = NexusReader(os.path.join(EXAMPLE_DIR, 'example.nex'))
     assert 'data' in nex.blocks
     assert 'Simon' in nex.blocks['data'].matrix
 def setUp(self):
     self.nex = NexusReader(os.path.join(EXAMPLE_DIR, 'example2.nex'))
Пример #25
0
 def test_write(self):
     nex = NexusReader(os.path.join(EXAMPLE_DIR, 'example.trees'))
     with open(os.path.join(EXAMPLE_DIR, 'example.trees')) as handle:
         text = handle.read()
     assert text == nex.write()
Пример #26
0
 def setUp(self):
     self.nex = NexusReader(
         os.path.join(REGRESSION_DIR, 'mesquite_taxa_block.nex')
     )
Пример #27
0
def test_roundtrip(examples):
    nex = NexusReader(examples.joinpath('example2.nex'))
    _ = NexusReader.from_string(nex.write())
Пример #28
0
 def setUp(self):
     self.nex = NexusReader(
         os.path.join(REGRESSION_DIR, 'mesquite_formatted_branches.trees')
     )
Пример #29
0
def test_write(examples):
    nex = NexusReader(examples / 'example.trees')
    assert nex.write().startswith('#NEXUS')
    assert examples.joinpath('example.trees').read_text(
        encoding='utf8') == nex.write()
Пример #30
0
 def test_run_randomise_sample2(self):
     nex = NexusReader(self.filename)
     new_nex = run_random(2, nex)
     assert new_nex.trees.ntrees == len(new_nex.trees.trees) == 2