Example #1
0
    def testChangeTranslate(self):
        f = """#NEXUS
Begin taxa ;
    dimensions ntax = 4;
    taxlabels a b c d ;
end;
begin trees;
    translate 
        1 a,
        2 b,
        3 c,
        4 d;
    tree t = (1,2,(3,4));
end;
begin trees;
    translate 
        1 d,
        2 b,
        3 c,
        4 a;
    tree t = (4,2,(3,1));
end;
"""
        d = Dataset()
        d.read(StringIO(f), format="NEXUS")
        t = d.trees_blocks[0][0]
        s = d.trees_blocks[1][0]
        self.assertEqual(t.taxa_block, s.taxa_block)
        encode_splits(s)
        encode_splits(t)
        self.assertEqual(treedists.symmetric_difference(t, s), 0)
Example #2
0
 def testTaxaWithUnderscoreRead(self):
     rd = dendropy.tests.data_source_path("rana.nex")
     rt = dendropy.tests.data_source_path("rana.tre")
     d = Dataset()
     d.read(open(rd, "rU"), format="NEXUS")
     self.assertEqual(len(d.taxa_blocks[0]), 64)
     d.read_trees(open(rt, "rU"), format="NEXUS")
     self.assertEqual(len(d.taxa_blocks[0]), 64)
Example #3
0
    if conf_file is None:
        sys.exit("Expecting a conf file template for GARLI")
    data_file = opts.data_filepath
    intree_file = opts.intree_filepath
    if data_file is None:
        sys.exit("Data file must be specified")
    if intree_file is None:
        sys.exit("Input tree file must be specified")
    for f in [data_file, intree_file, conf_file]:
        if not os.path.exists(f):
            sys.exit("%s does not exist" % f)

    conf = read_garli_conf(open(conf_file, "rU"))
    write_garli_conf(sys.stdout, conf)
    d = Dataset()
    d.read(open(data_file, "rU"), format="NEXUS")
    taxa = d.taxa_blocks[0]
    full_taxa_mask = taxa.all_taxa_bitmask()
    for n, taxon in enumerate(taxa):
        TAXON_TO_TRANSLATE[taxon] = str(n + 1)
    _LOG.debug("%s = full_taxa_mask" % bin(full_taxa_mask))
    assert (len(d.taxa_blocks) == 1)
    characters = d.char_blocks[0]
    assert (len(d.char_blocks) == 1)
    assert (len(characters) == len(taxa))
    inp_trees = d.read_trees(open(intree_file, "rU"), format="NEXUS")
    assert (inp_trees)
    current_taxon_mask = None
    for tree in inp_trees:
        assert tree.taxa_block is taxa
        encode_splits(tree)
        _LOG.setLevel(logging.DEBUG)
    data_file = opts.data_filepath
    intree_file = opts.intree_filepath
    if data_file is None:
        sys.exit("Data file must be specified")
    if intree_file is None:
        sys.exit("Input tree file must be specified")
    for f in [data_file, intree_file, conf_file]:
        if not os.path.exists(f):
            sys.exit("%s does not exist" % f)

    garli = GarliConf()
    garli.read_garli_conf(open(conf_file, "rU"))

    full_dataset = Dataset()
    full_dataset.read(open(data_file, "rU"), format="NEXUS")
    assert(len(full_dataset.taxa_blocks) == 1)
    taxa = full_dataset.taxa_blocks[0]
    full_taxa_mask = taxa.all_taxa_bitmask()
    for n, taxon in enumerate(taxa):
        TAXON_TO_TRANSLATE[taxon] = str(n + 1)
    _LOG.debug("%s = full_taxa_mask" % bin(full_taxa_mask))


    garli.datafname = os.path.join("data.nex")

    raw_trees = full_dataset.read_trees(open(intree_file, "rU"), format="NEXUS")
    assert(raw_trees)
    current_taxon_mask = None

    # read initial trees and verify that they have the correct set of taxa
Example #5
0
        _LOG.setLevel(logging.DEBUG)
    data_file = opts.data_filepath
    intree_file = opts.intree_filepath
    if data_file is None:
        sys.exit("Data file must be specified")
    if intree_file is None:
        sys.exit("Input tree file must be specified")
    for f in [data_file, intree_file, conf_file]:
        if not os.path.exists(f):
            sys.exit("%s does not exist" % f)

    garli = GarliConf()
    garli.read_garli_conf(open(conf_file, "rU"))

    full_dataset = Dataset()
    full_dataset.read(open(data_file, "rU"), format="NEXUS")
    assert (len(full_dataset.taxa_blocks) == 1)
    taxa = full_dataset.taxa_blocks[0]
    full_taxa_mask = taxa.all_taxa_bitmask()
    for n, taxon in enumerate(taxa):
        TAXON_TO_TRANSLATE[taxon] = str(n + 1)
    _LOG.debug("%s = full_taxa_mask" % bin(full_taxa_mask))

    garli.datafname = os.path.join("data.nex")

    raw_trees = full_dataset.read_trees(open(intree_file, "rU"),
                                        format="NEXUS")
    assert (raw_trees)
    current_taxon_mask = None

    # read initial trees and verify that they have the correct set of taxa