<jupyter_start><jupyter_text>Load BIOM table and sample metadata<jupyter_code># with biom_open("finrisk-MG-BL_AGE-filtered_rarefied_table.biom") as f:
with biom_open(table_MG_path) as f:
    table = Table.from_hdf5(f)
table.pa()
pd_table = (table.to_dataframe(dense=True))
tip_names = set(pd_table.index.to_list())

# metadata = pd.read_csv("gotu.shared.metadata.txt", sep="\t", index_col=0)
metadata = pd.read_csv(finrisk_metadata_path, sep="\t", index_col=0)<jupyter_output><empty_output><jupyter_text>Filter/split sample metadata into group >= 60 and <= 35<jupyter_code>old = metadata.loc[metadata["BL_AGE"] >= 60]
young = metadata.loc[metadata["BL_AGE"] <= 35]

old_samples = [s for s in old.index.tolist() if table.exists(s)]
young_sample = [s for s in young.index.tolist() if table.exists(s)]

old_table = (pd_table[old_samples]).T
young_table = (pd_table[young_sample]).T<jupyter_output><empty_output><jupyter_text>Load tree and assign log ratios<jupyter_code>tree = TreeNode.read(wol_tree_path,format="newick")
assign_name(tree)
tree = tree.shear(tip_names)
assign_counts(tree, old_table, young_table, tip_names)
young_min = calc_old_young_log(tree, len(old_samples), len(young_sample))
young_min = abs(young_min)
assign_old_young_status(tree, young_min)<jupyter_output><empty_output><jupyter_text>Format taxonomy<jupyter_code>tax = pd.read_csv("lineages.txt", sep="\t", index_col=0)
tax = tax.loc[tip_names]
tax[["Level 1", "Level 2","Level 3", "Level 4", "Level 5", "Level 6", "Level 7"]] = \
    tax.Taxonmy.str.split(";", expand=True)
tax.loc[["G001765415",
"G001899365",
"G001899425",
"G001917115",
"G001917235",
"G001917285",
"G000980455",
"G000431115",
"G000431315",
"G000431555",
"G000433095",
"G000433235",
"G000437435",
"G000437655",
"G000980375"], "Level 2"] = "p__Melainabacteria"
tax.loc[[
"G000432575",
"G000433255",
"G000433455",
"G000433475",
"G000433875",
"G000434835",
"G000436255",
"G000437335",
"G000438295",
"G000438415"
], "Level 2"] = "p__Firmicutes"
tax = tax.applymap(lambda x: x.split("__")[1].split("_")[0])
tax = tax.to_dict()<jupyter_output><empty_output><jupyter_text>Create feature metadata and sample metadata<jupyter_code>with open("old_young_log.tsv", 'w') as f:
    f.write("feature id\told_young_log_ratio\tage\tLevel 1\tLevel 2\tLevel 3\tLevel 4\tLevel 5\tLevel 6\tLevel 7\n")
    for node in tree.postorder(include_self=False):
        if node.is_tip():
            f.write("" + node.name + \
                    "\t" + str(node.old_young_log) + \
                    "\t" + node.age  +
                    "\t" + tax["Level 1"][node.name] +
                    "\t" + tax["Level 2"][node.name] +
                    "\t" + tax["Level 3"][node.name] +
                    "\t" + tax["Level 4"][node.name] +
                    "\t" + tax["Level 5"][node.name] +
                    "\t" + tax["Level 6"][node.name] +
                    "\t" + tax["Level 7"][node.name] +
                    "\n")
        else:
            if type(node.name) == type("str"):
                f.write("" + node.name + \
                    "\t" + str(node.old_young_log) + \
                    "\t" + node.age  + \
                    "\t" + "" + \
                    "\t" + "" +
                    "\t" + "" +
                    "\t" + "" +
                    "\t" + "" +
                    "\t" + "" +
                    "\t" + "" +
                    "\n")
        
metadata.loc[young_sample, "age_status"] = "young"
metadata.loc[old_samples, "age_status"] = "old"
metadata = metadata.loc[old_samples + young_sample]
metadata.to_csv("s-meta.tsv", sep="\t", na_rep="NA")<jupyter_output><empty_output><jupyter_text>Create qiime2 Artifacts<jupyter_code>table = table.filter(old_samples + young_sample, axis="sample", inplace=False)
Artifact.import_data("FeatureTable[Frequency]", table).save("table.qza")
Artifact.import_data("Phylogeny[Rooted]", tree).save("dec_shear_tree.qza")<jupyter_output><empty_output><jupyter_text>Create EMPress plot<jupyter_code>!qiime empress community-plot \
    --i-tree dec_shear_tree.qza \
    --i-feature-table table.qza \
    --m-sample-metadata-file s-meta.tsv \
    --m-feature-metadata-file old_young_log.tsv \
    --o-visualization fig2c.qzv<jupyter_output><empty_output><jupyter_text>Load EMPress visualization<jupyter_code>Visualization.load("fig2c.qzv")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16995412844036697, 'fraction_numerical': 0.06077981651376147, 'mean_word_length': 3.3785140562248994, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '119577', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1858, 'n_tokens_neox': 1622, 'n_words': 249, 'path': '03.02-metagenomic-age-phylo-analysis.ipynb', 'repo_name': 'gwarmstrong/faiths-pd-benchmarking', 'size': '4360'}