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)
def test_reader_from_blocks(): n = NexusReader(custom=['begin custom;', '[comment]', 'end;']) assert hasattr(n, 'custom')
def test_error_on_missing_file(examples): with pytest.raises(IOError): NexusReader(examples / 'sausage.nex')
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)))
def test_error_on_missing_file(self): with self.assertRaises(IOError): NexusReader(os.path.join(EXAMPLE_DIR, 'sausage.nex'))
def test_regression(self): nex = NexusReader(os.path.join(REGRESSION_DIR, 'ape_random.trees')) assert nex.trees.ntrees == 2
def setUp(self): self.nex = NexusReader( os.path.join(REGRESSION_DIR, 'detranslate-with-dash.trees') )
def glottolog(regression): """ Regression: Test that we can read glottolog tree format. """ return NexusReader(regression / 'glottolog.trees')
def mesquite_branches(regression): return NexusReader(regression / 'mesquite_formatted_branches.trees')
def taxlabels(regression): """ Regression: Test that we can read taxalabels delimited by spaces not new lines. """ return NexusReader(regression / 'taxlabels.nex')
def mesquite(regression): return NexusReader(regression / 'mesquite_taxa_block.nex')
def int_length(regression): return NexusReader(regression / 'branchlengths-in-integers.trees')
def with_dash(regression): return NexusReader(regression / 'detranslate-with-dash.trees')
def bad_chars(regression): return NexusReader(regression / 'bad_chars_in_taxaname.trees')
def setUp(self): self.nex = NexusReader( os.path.join(REGRESSION_DIR, 'taxlabels.nex') )
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
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]
def setUp(self): self.nex = NexusReader( os.path.join(REGRESSION_DIR, 'bad_chars_in_taxaname.trees') )
def setUp(self): self.nex = NexusReader( os.path.join(EXAMPLE_DIR, 'example-beast.trees') )
def setUp(self): self.nex = NexusReader( os.path.join(REGRESSION_DIR, 'branchlengths-in-integers.trees') )
def setUp(self): self.nex = NexusReader( os.path.join(EXAMPLE_DIR, 'example-translated.trees') )
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'))
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()
def setUp(self): self.nex = NexusReader( os.path.join(REGRESSION_DIR, 'mesquite_taxa_block.nex') )
def test_roundtrip(examples): nex = NexusReader(examples.joinpath('example2.nex')) _ = NexusReader.from_string(nex.write())
def setUp(self): self.nex = NexusReader( os.path.join(REGRESSION_DIR, 'mesquite_formatted_branches.trees') )
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()
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