Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No nexus reading/writing #57

Open
hyanwong opened this issue Sep 2, 2024 · 0 comments
Open

No nexus reading/writing #57

hyanwong opened this issue Sep 2, 2024 · 0 comments

Comments

@hyanwong
Copy link
Member

hyanwong commented Sep 2, 2024

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()}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant