Your all-inclusive package for aggregating and visualizing metagenomic BLAST results.
Project description
metagenompy
Your all-inclusive package for aggregating and visualizing metagenomic BLAST results.
Installation
$ pip install metagenompy
Usage
NCBI taxonomy as NetworkX object
The core of metagenompy
is a taxonomy as a networkX object.
This means that all your favorite algorithms work right out of the box.
import metagenompy
import networkx as nx
# load taxonomy
graph = metagenompy.generate_taxonomy_network()
# print path from human to pineapple
for node in nx.shortest_path(graph.to_undirected(as_view=True), '9606', '4615'):
print(node, graph.nodes[node])
## 9606 {'rank': 'species', 'authority': 'Homo sapiens Linnaeus, 1758', 'scientific_name': 'Homo sapiens', 'genbank_common_name': 'human', 'common_name': 'man'}
## 9605 {'rank': 'genus', 'authority': 'Homo Linnaeus, 1758', 'scientific_name': 'Homo', 'common_name': 'humans'}
## [..]
## 4614 {'rank': 'genus', 'authority': 'Ananas Mill., 1754', 'scientific_name': 'Ananas'}
## 4615 {'rank': 'species', 'authority': ['Ananas comosus (L.) Merr., 1917', 'Ananas lucidus Mill., 1754'], 'scientific_name': 'Ananas comosus', 'synonym': ['Ananas comosus var. comosus', 'Ananas lucidus'], 'genbank_common_name': 'pineapple'}
Easy transformation and visualization of taxonomy
Extract taxonomic entities of interest and visualize their relations:
import metagenompy
import matplotlib.pyplot as plt
# load and condense taxonomy to relevant ranks
graph = metagenompy.generate_taxonomy_network()
metagenompy.condense_taxonomy(graph)
# highlight interesting nodes
graph_zoom = metagenompy.highlight_nodes(graph, [
'9606', # human
'9685', # cat
'9615', # dog
'4615', # pineapple
'3747', # strawberry
'4113', # potato
])
# visualize result
fig, ax = plt.subplots(figsize=(10, 10))
metagenompy.plot_taxonomy(graph_zoom, ax=ax, labels_kws=dict(font_size=10))
fig.tight_layout()
fig.savefig('taxonomy.pdf')
Classify taxonomic entities at different ranks:
import metagenompy
import pandas as pd
# load taxonomy
graph = metagenompy.generate_taxonomy_network()
# classification
tmp = []
for taxid in ['9606', '9685', '3747']:
for rank in ['class', 'order']:
clf_id = metagenompy.classify_taxid(graph, taxid, rank)
tmp.append({
'taxid': graph.nodes[taxid]['scientific_name'],
'rank': rank,
'clf': graph.nodes[clf_id]['scientific_name']
})
pd.DataFrame(tmp)
## taxid rank clf
## 0 Homo sapiens class Mammalia
## 1 Homo sapiens order Primates
## 2 Felis catus class Mammalia
## 3 Felis catus order Carnivora
## 4 Fragaria x ananassa class Magnoliopsida
## 5 Fragaria x ananassa order Rosales
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
metagenompy-0.2.0.tar.gz
(4.0 kB
view hashes)
Built Distribution
Close
Hashes for metagenompy-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5faeb61aae0a8cc168de654b3641f4d5bedae241c11dba033a3271dc52ba08d9 |
|
MD5 | 6c229d9b6fa62c903b6d71a03c3653e2 |
|
BLAKE2b-256 | c63d1f36aaf537684259dd7c444c2aedadea539f1eb929a7696179d00e719357 |