Ejemplo n.º 1
0
    def open_folder(folder):
        sim = Simulation(folder)

        sim.extant_genomes = file_ops.open_genome_file(
            os.path.join(folder, cfg.sim_extant_genomes()))
        sim.ancestral_genomes = file_ops.open_genome_file(
            os.path.join(folder, cfg.sim_ancestral_genomes()))
        sim.sim_tree = file_ops.open_newick_tree(
            os.path.join(folder, cfg.sim_tree()))
        sim.folder = folder

        # events:
        try:
            with open(os.path.join(sim.folder, cfg.sim_events_file())) as f:
                l = f.readline()
                header = l.strip().split()
                for l in f:
                    fields = l.strip().split()
                    node = sim.sim_tree.find_node_with_label(fields[0])
                    events = {
                        field: int(r)
                        for field, r in zip(header[1:], fields[1:])
                    }
                    node.edge.events = events
        except IOError:
            pass
        sim.sim_parameters = SimParameters()
        # Reading data back
        sim.sim_parameters.__dict__ = file_ops.read_simulation_parameters(
            folder)
        return sim
Ejemplo n.º 2
0
def main(treefile, ignore_weights, marker_file, kT=0.1, minimum=0.0, write_output=False, output_folder="."):

    # Config:
    declone = cfg.declone_path()
    # nhx output:
    nhxFile = os.path.splitext(treefile)[0] + ".nhx"
    # open tree:
    t = file_ops.open_newick_tree(treefile)
    # Newick to NHX:
    parse_NEWICK_to_nhx(t, ignore_weights, nhxFile, minimum)
    listOfInternalNodes = [node.label for node in t.internal_nodes()]
    extantAdjacencies = findAdjacencies(read_Marker_file(marker_file))
    singleLeafAdj, adjacenciesPerNode, extantWeightedAdjacencies = deCloneProbabilities(declone, extantAdjacencies, kT, listOfInternalNodes, nhxFile)
    if write_output:
        file_ops.write_declone_weights(singleLeafAdj, adjacenciesPerNode, extantWeightedAdjacencies, kT, folder=output_folder)

    return singleLeafAdj, adjacenciesPerNode, extantWeightedAdjacencies
Ejemplo n.º 3
0
    def open_folder(folder):
        sim = Simulation(folder)

        sim.extant_genomes = file_ops.open_genome_file(os.path.join(folder, cfg.sim_extant_genomes()))
        sim.ancestral_genomes = file_ops.open_genome_file(os.path.join(folder, cfg.sim_ancestral_genomes()))
        sim.sim_tree = file_ops.open_newick_tree(os.path.join(folder, cfg.sim_tree()))
        sim.folder = folder

        # events:
        try:
            with open(os.path.join(sim.folder, cfg.sim_events_file())) as f:
                l = f.readline()
                header = l.strip().split()
                for l in f:
                    fields = l.strip().split()
                    node = sim.sim_tree.find_node_with_label(fields[0])
                    events = {field: int(r) for field, r in zip(header[1:], fields[1:])}
                    node.edge.events = events
        except IOError:
            pass
        sim.sim_parameters = SimParameters()
        # Reading data back
        sim.sim_parameters.__dict__ = file_ops.read_simulation_parameters(folder)
        return sim
Ejemplo n.º 4
0
        action="store_true",
        default=False,
        help="adds adjacencies from 2-cycles that are AA- or BB-open directly."
    )

    # PARSE params:
    param = parser.parse_args()

    # test if blossom5 is needed:
    if param.perfect:
        if not file_ops.blossom5_is_available():
            print >> sys.stderr, "Blossom5 not found, it is needed for perfect matching. Either install blossom5 or do not use the '-p' perfect matching option."
            sys.exit(-1)

    extant_genomes = file_ops.open_genome_file(param.input_genomes)
    tree = file_ops.open_newick_tree(param.tree, label_internal_nodes=True)

    # estimate lenghts:
    if param.estimate_lenghts is not None:
        if param.estimate_lenghts == "lp":
            algorithms.estimate_branch_lengths_lp(tree, extant_genomes)
        elif param.estimate_lenghts == "least_squares":
            algorithms.estimate_branch_lengths_least_squares(
                tree, extant_genomes)
    else:
        # default is to run it anyway, if the tree has no branch lengths:
        if any([node.edge.length is None for node in tree.leaf_nodes()]):
            algorithms.estimate_branch_lengths_lp(tree, extant_genomes)

    # Fix multibranching trees:
    changed = resolve_tree(tree)
Ejemplo n.º 5
0
    # DEBUG:
    parser.add_argument("--add_open_2_cycles", action="store_true", default=False,
                        help="adds adjacencies from 2-cycles that are AA- or BB-open directly.")

    # PARSE params:
    param = parser.parse_args()

    # test if blossom5 is needed:
    if param.perfect:
        if not file_ops.blossom5_is_available():
            print >> sys.stderr, "Blossom5 not found, it is needed for perfect matching. Either install blossom5 or do not use the '-p' perfect matching option."
            sys.exit(-1)

    extant_genomes = file_ops.open_genome_file(param.input_genomes)
    tree = file_ops.open_newick_tree(param.tree, label_internal_nodes=True)

    # estimate lenghts:
    if param.estimate_lenghts is not None:
        if param.estimate_lenghts == "lp":
            algorithms.estimate_branch_lengths_lp(tree, extant_genomes)
        elif param.estimate_lenghts == "least_squares":
            algorithms.estimate_branch_lengths_least_squares(tree, extant_genomes)
    else:
        # default is to run it anyway, if the tree has no branch lengths:
        if any([node.edge.length is None for node in tree.leaf_nodes()]):
            algorithms.estimate_branch_lengths_lp(tree, extant_genomes)

    # Fix multibranching trees:
    changed = resolve_tree(tree)
    # if the tree changed, it might be a good idea to rerun the branch length detection?