Removing taxon with underscore

14 views
Skip to first unread message

Caleb Ji

unread,
Jan 15, 2018, 12:25:38 PM1/15/18
to DendroPy Users
Hi, I'm trying to remove some taxa from newick trees, but the prune function doesn't seem to work when there are underscores in the name.

import dendropy as dp
s1 = '(A, (B, C));'
tree = dp.Tree.get(data=s1, schema="newick")
tree.prune_taxa_with_labels("A")
print(tree)

s2 = '(A_, (B, C));'
tree = dp.Tree.get(data=s2, schema="newick")
tree.prune_taxa_with_labels("A_")
print(tree)

results in:

(B,C)
(A_,(B,C))

Is there a way to remove the "A_" in s2?

Thanks,
Caleb

Jeet Sukumaran

unread,
Jan 15, 2018, 12:33:20 PM1/15/18
to dendrop...@googlegroups.com, Caleb Ji
As per the Newick/NEXUS standards and as stated in multiple places in
the DendroPy documentation, unless specified otherwise, "_" in labels
are parsed as spaces. So you will either need to say:

tree.prune_taxa_with_labels("A ")

or specify ``preserve_underscores=True`` when reading in the data.
> --
> You received this message because you are subscribed to the Google
> Groups "DendroPy Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to dendropy-user...@googlegroups.com
> <mailto:dendropy-user...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.

--



--------------------------------------
Jeet Sukumaran
--------------------------------------
jeetsu...@gmail.com
--------------------------------------
Blog/Personal Pages:
http://jeetworks.org/
GitHub Repositories:
http://github.com/jeetsukumaran
Photographs (as stream):
http://www.flickr.com/photos/jeetsukumaran/
Photographs (by galleries):
http://www.flickr.com/photos/jeetsukumaran/sets/
--------------------------------------

Caleb Ji

unread,
Jan 15, 2018, 12:48:41 PM1/15/18
to DendroPy Users
I see...still, neither of them are working for me.

import dendropy as dp
s1
= "(A_, (B, C));"
tree
= dp.Tree.get(data=s1, schema="newick", preserve_underscores=False)

tree
.prune_taxa_with_labels("A ")
print(tree)


s2
= "(A_, (B, C));"

tree1
= dp.Tree.get(data=s2, schema="newick", preserve_underscores=True)
tree1
.prune_taxa_with_labels("A_")
print(tree1)

 gives

(A_,(B,C))
(A_,(B,C))


Jeet Sukumaran

unread,
Jan 15, 2018, 1:25:03 PM1/15/18
to dendrop...@googlegroups.com, Caleb Ji
The first argument should not be a single string, but a list of strings.
So, in your case, ``["A_",]`` or ``["A ",]``.
> > an email to dendropy-user...@googlegroups.com <javascript:>
> > <mailto:dendropy-user...@googlegroups.com <javascript:>>.
> > For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>.
>
> --
>
>
>
> --------------------------------------
> Jeet Sukumaran
> --------------------------------------
> jeetsu...@gmail.com <javascript:>
> --------------------------------------
> Blog/Personal Pages:
> http://jeetworks.org/
> GitHub Repositories:
> http://github.com/jeetsukumaran <http://github.com/jeetsukumaran>
> <http://www.flickr.com/photos/jeetsukumaran/sets/>
> --------------------------------------
>
> --
> You received this message because you are subscribed to the Google
> Groups "DendroPy Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to dendropy-user...@googlegroups.com
> <mailto:dendropy-user...@googlegroups.com>.

Caleb Ji

unread,
Jan 17, 2018, 9:55:53 PM1/17/18
to DendroPy Users
That works, thank you for your time!
Reply all
Reply to author
Forward
0 new messages