This is a test version of Biostars. For the public version, visit https://www.biostars.org.
get species names from newick phylogenetic tree file

Hi I have a newick phylogeny file has more than 1000 species. I want to extract just species name in different file. I appreciate your help

next-gen alignment sequencing genome r

1 answer

What have you tried?

Look at the ape package for instance. It'd be as simple as:

> library(ape)
> tree <- read.tree(text = "(((A,B),(C,D)),E);")  # or read.tree(file='path/to/file.tree') if using a file
> tree$tip.label
[1] "A" "B" "C" "D" "E"

A similar approach in python:

python -c 'import sys; from ete3 import Tree; t = Tree(sys.argv[1]);print(t.get_leaf_names());' treefile.nwk

I tried ape But the problem was importing the phylogenetic file it is too big for copy and paste and made error And I couldn't use it as import data

For python I got this error ete3 command not found

Then don't import it with copy and paste, read the file in directly. What I showed above was just an example of the functionality, you need to adapt it to what you are trying to do.

As for python, yes of course, ETE3 isn't a standard module - you need to install it.

Log in to answer this question.