Skip to content

Numbers of left and right parentheses in Newick string not equal #432

Closed
@alienzj

Description

@alienzj
>>> tree = open("tree/tree.nwk").read()
>>> tree.count(")")
203738
>>> tree.count("(")
203738

Method 1:

tre <- read.tree("./tree/tree.nwk")

Method 2:

tre <- read.newick("./tree/tree.nwk")

I got same error when use method 1 or method2.

Error in FUN(X[[i]], ...) : numbers of left and right parentheses in Newick string not equal

Activity

reopened this on Sep 1, 2021
reopened this on Sep 1, 2021
alienzj

alienzj commented on Sep 1, 2021

@alienzj
Author
brj1

brj1 commented on Sep 1, 2021

@brj1
Contributor

The read.tree function is exported from the ape package. You should make an issue in ape's GitHub to fix this issue. https://github.com/emmanuelparadis/ape

The read.newick function in treeio uses ape's read.tree function to read the tree, which is why you get the same error.

xiangpin

xiangpin commented on Sep 2, 2021

@xiangpin
Member

This is because the node labels contain ";" symbol, it will be confused with the end of single tree. But I also think it might be a bug of read.tree of ape. But you can also replace the "; " of node labes to "|" with some tools, such as sed shell or gsub in R.

 sed 's\; \|\g' tree.nwk.txt
alienzj

alienzj commented on Sep 2, 2021

@alienzj
Author

The read.tree function is exported from the ape package. You should make an issue in ape's GitHub to fix this issue. https://github.com/emmanuelparadis/ape

The read.newick function in treeio uses ape's read.tree function to read the tree, which is why you get the same error.

Thanks for your answers.

alienzj

alienzj commented on Sep 2, 2021

@alienzj
Author

This is because the node labels contain ";" symbol, it will be confused with the end of single tree. But I also think it might be a bug of read.tree of ape. But you can also replace the "; " of node labes to "|" with some tools, such as sed shell or gsub in R.

 sed 's\; \|\g' tree.nwk.txt

Nice! Thank you so much~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

        Participants

        @alienzj@brj1@xiangpin

        Issue actions

          Numbers of left and right parentheses in Newick string not equal · Issue #432 · YuLab-SMU/ggtree