Hi Karen.
One option is to use the function strsplit to split the Newick string by
character & then identify the characters between each ")" and the
following ":" and remove them. I have posted an example here on my blog:
http://blog.phytools.org/2015/08/removing-node-labels-from-newick-string.html
and it is about twice as fast as reading the tree into memory using
read.tree, setting the node labels to NULL, and then re-writing the tree
using write.tree.
All the best, Liam
Liam J. Revell, Assistant Professor of Biology
University of Massachusetts Boston
web: http://faculty.umb.edu/liam.revell/
email: liam.rev...@umb.edu
blog: http://blog.phytools.org
On 8/24/2015 2:35 PM, Karen Gordon wrote:
Hi There,
I’m currently wanting to make some changes to some phylogenies in R by reading
in the newick text as a string, rather than as a phylo object. The reason is
that the trees are large (~10,000 tips and another set with ~5000 tips) and I
must make changes to a complete set of these tree (i.e. 10,000 trees).
Currently, these trees have node labels, which I’d like to remove.
Essentially what I’d like to do is substitute “)?:” with “):” or simply delete "?",
where “?" is any and all characters that occur between the “close” parenthesis and the
colon. So far I found I could use the function ’sub’ but I’d like to make the replacements in
one fell swoop, without knowing what the node labels are in advance. Also the sub function
seems to only replace the first occurrence of the pattern rather than all matches in a string.
Any suggestions would be greatly appreciated! Thank you!
best,
Karen
_______________________________________________
R-sig-phylo mailing list - R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
Searchable archive at http://www.mail-archive.com/r-sig-phylo@r-project.org/
_______________________________________________
R-sig-phylo mailing list - R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
Searchable archive at http://www.mail-archive.com/r-sig-phylo@r-project.org/