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

TreeNode.from_taxonomy should take a pandas dataframe as input #2009

Open
mortonjt opened this issue Apr 18, 2024 · 1 comment
Open

TreeNode.from_taxonomy should take a pandas dataframe as input #2009

mortonjt opened this issue Apr 18, 2024 · 1 comment

Comments

@mortonjt
Copy link
Collaborator

mortonjt commented Apr 18, 2024

Dataframes are easier to obtain than list of tuple of lists (which is the current input of TreeNode.from_taxonomy )

The current workaround (using the metaphlan4 database as a reference) is as follows

from skbio import TreeNode
taxonomy = pd.read_table('MetaPhlAn4/mpa_vJan21_CHOCOPhlAnSGB_202103_species.txt', header=None, index_col=0)
taxonomy = pd.DataFrame(list(taxonomy[1].apply(lambda x: x.split('|')).values), index=taxonomy.index)
taxonomy.columns = ['k', 'p', 'c', 'o', 'f', 'g', 's']
lineages = [(tup.Index, [tup.k, tup.p, tup.c, tup.o, tup.f, tup.g, tup.s]) for tup in taxonomy.itertuples(index=True)]
tree = TreeNode.from_taxonomy(lineages)
@wasade
Copy link
Collaborator

wasade commented Apr 18, 2024

It would be pleasant for from_taxonomy to detect the separator used, and to split accordingly as well.

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

No branches or pull requests

2 participants