def tree_iterator(fname, restrict_species=None, start_line=None, end_line=None): for ln, line in enumerate(open(fname)): if start_line is not None and ln < start_line: continue elif end_line is not None and ln >= end_line: break if line.startswith("#") or not line.strip(): continue treeid, newick = line.split("\t") t = PhyloTree(newick, sp_naming_function=extract_species) if restrict_species: t.prune([n for n in t.iter_leaves() if n.species in restrict_species]) n2content = t.get_cached_content() if len(n2content[t]) < 2: continue yield treeid, t, n2content
def tree_iterator(fname, restrict_species=None, start_line=None, end_line=None): for ln, line in enumerate(open(fname)): if start_line is not None and ln < start_line: continue elif end_line is not None and ln >= end_line: break if line.startswith("#") or not line.strip(): continue treeid, newick = line.split("\t") t = PhyloTree(newick, sp_naming_function=extract_species) if restrict_species: t.prune( [n for n in t.iter_leaves() if n.species in restrict_species]) n2content = t.get_cached_content() if len(n2content[t]) < 2: continue yield treeid, t, n2content