Skip to content

No nexus reading/writing #57

@hyanwong

Description

@hyanwong

The README mentions NEXUS, but there are no functions that help to read or write this format in this repo.

However, you can grab the newick(s) from within the nexus and convert them using

with open("myfile.nexus") as nex:
    tags = "begin trees;", "end;"
    newicks = None
    for line in nex:
        line = line.strip()
        if newicks is not None:
            if line[:len(tags[1])].lower().startswith(tags[1]):
                break
            p = line.find("=")
            if p >= 0:
                newicks[line[:p].strip()] = line[p+1:] if line.endswith(";") else f"{line[p+1:]};"
        elif line[:len(tags[0])].lower().startswith(tags[0]):
            newicks = {}

tree_seqs = {k: tsconvert.from_newick(line, min_edge_length=1e-10) for k, line in newicks.items()}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions