<jupyter_start><jupyter_text>Correlated multi-omics features in SARS-Cov-2 infected samplesAnnotate the correlations returned by the integrative analysis.<jupyter_code>import numpy as np
import pandas as pd<jupyter_output><empty_output><jupyter_text>These results are already provided as part of the repository in `results`. Steps listed here are for reproducibility.``` feature names running these commands unites the features in each component this will work after running the pipeline with example.shdir="../results/case_study_1/EXAMPLE"export dircd ${dir}(head -n1 ${dir}proteome_1_sPLSDA_max.txt; cat ${dir}proteome_*sPLSDA*max.txt | grep -v "importance") \    > proteome_sPLSDA_keepx_max.txt(head -n1 ${dir}translatome_1_sPLSDA_max.txt; cat ${dir}translatome_*sPLSDA*max.txt | grep -v "importance") \    > translatome_sPLSDA_keepx_max.txt(head -n1 ${dir}proteome_1_DIABLO_var_keepx_max.txt; cat ${dir}proteome_*DIABLO*keepx_max*txt | grep -v "importance") \    > proteome_DIABLO_keepx_max.txt(head -n1 ${dir}translatome_1_DIABLO_var_keepx_max.txt; cat ${dir}translatome_*DIABLO*keepx_max*txt | grep -v "importance") \    > translatome_DIABLO_keepx_max.txt```<jupyter_code># change these file paths accordingly
prot_splsda_infile = ".../../results/case_study_1/proteome_sPLSDA_keepx_max.txt"
tran_splsda_infile = "../../results/case_study_1/translatome_sPLSDA_keepx_max.txt"
diablo_corr_infile = "../../results/case_study_1/DIABLO_var_keepx_correlations.txt"
panther_annotations_infile = "../../data/case_study_1/panther.txt"
mapping_annotations_infile = "../../data/case_study_1/mapping.csv"
covid_annotations_infile = "../../data/uniprot_SARS-COV2_annotations.tab"
prot_map_infile = "../../data/case_study_1/proteome_mapfile.txt"
tran_map_infile = "../../data/case_study_1/translatome_mapfile.txt"

prot_splsda_outfile = "../../results/case_study_1/proteome_splsda.tsv"
tran_splsda_outfile = "../../results/case_study_1/translatome_splsda.tsv"
corr_annotated_outfile = "../../results/case_study_1/multiblock_correlations_annotated.tsv"

prot_splsda = pd.read_csv(prot_splsda_infile, sep="\t")
tran_splsda = pd.read_csv(tran_splsda_infile, sep="\t")
diablo_corr = pd.read_csv(diablo_corr_infile, sep="\t")
panther_annotations = pd.read_csv(panther_annotations_infile, sep="\t", header=None)
covid_annotations = pd.read_csv(covid_annotations_infile, sep="\t")
mapping_annotations = pd.read_csv(mapping_annotations_infile, sep=",")
prot_map = pd.read_csv(prot_map_infile, sep="\t", usecols=["key", "val"])
tran_map = pd.read_csv(tran_map_infile, sep="\t", usecols=["key", "val"])
# flatten the correlations for a more human readable format
flat_corr = diablo_corr.stack().reset_index()

# order of cols doesnt matter here, matrix is symmetrical
prot = flat_corr.level_0.str.contains('_proteome')   
tran = flat_corr.level_1.str.contains('_translatome')
multiblock = flat_corr[prot & tran]

# below block proves the above point:
_prot = flat_corr.level_1.str.contains('_proteome')   
_tran = flat_corr.level_0.str.contains('_translatome')
_multiblock = flat_corr[_prot & _tran]

ver1 = multiblock.reset_index().drop("index", axis=1).sort_values(by=["level_0", "level_1"], ignore_index=True)
ver2 = _multiblock.reset_index().drop("index", axis=1)[["level_1", "level_0", 0]]
ver2.columns = ["level_0", "level_1", 0]
ver2 = ver2.sort_values(by=["level_0", "level_1"], ignore_index=True)

assert ver1[["level_0", "level_1"]].equals(ver2[["level_0", "level_1"]]) is True, \
    "Order of correlated features must be identical"
assert set(np.isclose(ver1[0], ver2[0])) == {True}, \
    "Order of correlated values are identical"

# we want correlations across modalities only for this step
prot_tran = flat_corr[(flat_corr.level_0.str.contains("_proteome")) & (flat_corr.level_1.str.contains("_translatome"))]
tran_prot = flat_corr[(flat_corr.level_1.str.contains("_proteome")) & (flat_corr.level_0.str.contains("_translatome"))]
prot_tran.columns = ["proteome", "translatome", "correlation"]
prot_tran = prot_tran.sort_values(by=["proteome", "translatome"], ignore_index=True)

# clean up file names
prot_tran = prot_tran.replace(regex={r'_prot_proteome$': '', r'_tran_translatome': ''})
prot_tran = prot_tran.replace(regex={r'_proteome$': '', r'_translatome': ''})

# use panther annotations
panther_annot = panther_annotations[[1,2,4]].replace(regex={r',.*$': ''})
panther_annot.columns = [1,2,3]

# use covid annotations
covid_annot = covid_annotations.copy()
covid_annot.replace(regex={r'_HUMAN$': ''}, inplace=True)
covid_annot.drop(["Status", "Gene names", "Entry name", "Length"], axis=1, inplace=True)
covid_annot.columns = [1, 2, 3]
covid_annot

# merge annotations
annot = pd.concat([panther_annot, covid_annot], ignore_index=True)
annot

prot_tran_annot = pd.merge(annot, prot_tran, how="right", left_on=1, right_on="proteome")
prot_tran_annot.columns = [
    "tmp2", "prot_annotation", "prot_category", "proteome", 
    "translatome", "correlation"
]
prot_tran_annot = pd.merge(annot, prot_tran_annot, how="right", left_on=1, right_on="translatome")
prot_tran_annot.columns = [
    "tmp1", "tran_annotation", "tran_category", "tmp2", 
    "prot_annotation", "prot_category", "proteome", 
    "translatome", "correlation"
]
prot_tran_annot.drop(["tmp1", "tmp2"], axis=1, inplace=True)
prot_tran_annot
cols = [
    "translatome", "tran_annotation", "tran_category", 
    "proteome", "prot_annotation", "prot_category", "correlation"
]
prot_tran_annot = prot_tran_annot[cols]
prot_tran_annot.sort_values(by="correlation", ascending=False, ignore_index=True, inplace=True)
prot_tran_annot.to_csv(corr_annotated_outfile, sep="\t")
prot_tran_annot

id_to_feature = mapping_annotations.iloc[:,0:2]
id_to_feature.columns = ["name", "id"]
id_to_feature
prot_tran_annot = pd.merge(id_to_feature, prot_tran_annot, how="right", left_on="id", right_on="proteome")
prot_tran_annot.columns = [
    "prot_name", "tmp1", "translatome", "tran_annotation", "tran_category", 
    "proteome", "prot_annotation", "prot_category", "correlation"
]
prot_tran_annot = pd.merge(id_to_feature, prot_tran_annot, how="right", left_on="id", right_on="translatome")
prot_tran_annot.columns = [
    "tran_name", "tmp2", "prot_name", "tmp1", "translatome", "tran_annotation", 
    "tran_category", "proteome", "prot_annotation", "prot_category", "correlation"
]
cols = ["translatome", "tran_name", "tran_annotation", "tran_category", "proteome", "prot_name", "prot_annotation", "prot_category", "correlation"]
prot_tran_annot = prot_tran_annot[cols]
prot_tran_annot.sort_values(by="correlation", ascending=False, ignore_index=True, inplace=True)
prot_tran_annot.to_csv(corr_annotated_outfile, sep="\t")
prot_tran_annot
# export single omics proteomics with annotations
prot_splsda = pd.read_csv(prot_splsda_infile, sep="\t")
prot_splsda.reset_index(inplace=True)
prot_splsda.replace(regex={r'_prot$': ''}, inplace=True)
prot_splsda.replace(regex={r'_tran$': ''}, inplace=True)
prot_splsda.replace(regex={r'__FEATUREID$': ''}, inplace=True)
prot_splsda.set_index("index", inplace=True)
prot_splsda

prot_splsda_annot = pd.merge(annot, prot_splsda, how="right", left_on=1, right_on="index")
prot_splsda_annot.columns = ["index", "name", "annotation"] + prot_splsda_annot.columns.to_list()[3:]
prot_splsda_annot.sort_values(by="importance", ascending=False, ignore_index=True, inplace=True)
prot_splsda_annot.set_index("index", inplace=True)
prot_splsda_annot.to_csv(prot_splsda_outfile, sep="\t")
prot_splsda_annot
# export single omics proteomics with annotations
tran_splsda = pd.read_csv(tran_splsda_infile, sep="\t")
tran_splsda.reset_index(inplace=True)
tran_splsda.replace(regex={r'_prot$': ''}, inplace=True)
tran_splsda.replace(regex={r'_tran$': ''}, inplace=True)
tran_splsda.replace(regex={r'__FEATUREID$': ''}, inplace=True)
tran_splsda.set_index("index", inplace=True)
tran_splsda

tran_splsda_annot = pd.merge(annot, tran_splsda, how="right", left_on=1, right_on="index")
tran_splsda_annot.columns = ["index", "name", "annotation"] + tran_splsda_annot.columns.to_list()[3:]
tran_splsda_annot.sort_values(by="importance", ascending=False, ignore_index=True, inplace=True)
tran_splsda_annot.set_index("index", inplace=True)
tran_splsda_annot.to_csv(tran_splsda_outfile, sep="\t")
tran_splsda_annot<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1529114533205005, 'fraction_numerical': 0.009985563041385948, 'mean_word_length': 7.900428265524625, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '221240', 'license': 'MIT', 'n_tokens_mistral': 3204, 'n_tokens_neox': 3118, 'n_words': 484, 'path': 'src/case_study_1/annotate_multiomics_correlations.ipynb', 'repo_name': 'aljabadi/SARS-CoV-2', 'size': '8312'}