Created
August 31, 2019 14:03
-
-
Save Ken-Kuroki/b28dc1fa239fa76baf5eac83ab376bd8 to your computer and use it in GitHub Desktop.
Generate distance matrix among samples by unifrac distance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from skbio import TreeNode | |
from skbio.diversity import beta_diversity | |
tree = TreeNode.read("gg_13_8_otus/trees/61_otus_unannotated.tree") | |
sample_ids = [f"sample{i}" for i in range(6)] | |
with open("gg_13_8_otus/taxonomy/61_otu_taxonomy.txt", "r") as f: | |
otu_ids = [each.strip().split("\t")[0] for each in f.readlines()] | |
data = np.random.randint(0, 100, size=(len(sample_ids), len(otu_ids))).tolist() | |
unifrac = beta_diversity("weighted_unifrac", data, ids=sample_ids, tree=tree, otu_ids=otu_ids) | |
unifrac.to_data_frame() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment