Compare outcomes from differential analysis based on different imputation methods#

  • load scores based on 10_1_ald_diff_analysis

Hide code cell source

import logging
from pathlib import Path

import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
from IPython.display import display

import pimmslearn
import pimmslearn.databases.diseases

logger = pimmslearn.logging.setup_nb_logger()

plt.rcParams['figure.figsize'] = (2, 2)
fontsize = 5
pimmslearn.plotting.make_large_descriptors(fontsize)
logging.getLogger('fontTools').setLevel(logging.ERROR)

# catch passed parameters
args = None
args = dict(globals()).keys()

Parameters#

Default and set parameters for the notebook.

folder_experiment = 'runs/appl_ald_data/plasma/proteinGroups'

target = 'kleiner'
model_key = 'VAE'
baseline = 'RSN'
out_folder = 'diff_analysis'
selected_statistics = ['p-unc', '-Log10 pvalue', 'qvalue', 'rejected']

disease_ontology = 5082  # code from https://disease-ontology.org/
# split diseases notebook? Query gene names for proteins in file from uniprot?
annotaitons_gene_col = 'PG.Genes'
# Parameters
disease_ontology = 10652
folder_experiment = "runs/alzheimer_study"
target = "AD"
baseline = "PI"
model_key = "TRKNN"
out_folder = "diff_analysis"
annotaitons_gene_col = "None"

Add set parameters to configuration

Hide code cell source

params = pimmslearn.nb.get_params(args, globals=globals())
args = pimmslearn.nb.Config()
args.folder_experiment = Path(params["folder_experiment"])
args = pimmslearn.nb.add_default_paths(args,
                                 out_root=(
                                     args.folder_experiment
                                     / params["out_folder"]
                                     / params["target"]
                                     / f"{params['baseline']}_vs_{params['model_key']}"))
args.update_from_dict(params)
args.scores_folder = scores_folder = (args.folder_experiment
                                      / params["out_folder"]
                                      / params["target"]
                                      / 'scores')
args.freq_features_observed = args.folder_experiment / 'freq_features_observed.csv'
args
root - INFO     Removed from global namespace: folder_experiment
root - INFO     Removed from global namespace: target
root - INFO     Removed from global namespace: model_key
root - INFO     Removed from global namespace: baseline
root - INFO     Removed from global namespace: out_folder
root - INFO     Removed from global namespace: selected_statistics
root - INFO     Removed from global namespace: disease_ontology
root - INFO     Removed from global namespace: annotaitons_gene_col
root - INFO     Already set attribute: folder_experiment has value runs/alzheimer_study
root - INFO     Already set attribute: out_folder has value diff_analysis
{'annotaitons_gene_col': 'None',
 'baseline': 'PI',
 'data': PosixPath('runs/alzheimer_study/data'),
 'disease_ontology': 10652,
 'folder_experiment': PosixPath('runs/alzheimer_study'),
 'freq_features_observed': PosixPath('runs/alzheimer_study/freq_features_observed.csv'),
 'model_key': 'TRKNN',
 'out_figures': PosixPath('runs/alzheimer_study/figures'),
 'out_folder': PosixPath('runs/alzheimer_study/diff_analysis/AD/PI_vs_TRKNN'),
 'out_metrics': PosixPath('runs/alzheimer_study'),
 'out_models': PosixPath('runs/alzheimer_study'),
 'out_preds': PosixPath('runs/alzheimer_study/preds'),
 'scores_folder': PosixPath('runs/alzheimer_study/diff_analysis/AD/scores'),
 'selected_statistics': ['p-unc', '-Log10 pvalue', 'qvalue', 'rejected'],
 'target': 'AD'}

Excel file for exports#

files_out = dict()
writer_args = dict(float_format='%.3f')

fname = args.out_folder / 'diff_analysis_compare_methods.xlsx'
files_out[fname.name] = fname
writer = pd.ExcelWriter(fname)
logger.info("Writing to excel file: %s", fname)
root - INFO     Writing to excel file: runs/alzheimer_study/diff_analysis/AD/PI_vs_TRKNN/diff_analysis_compare_methods.xlsx

Load scores#

Load baseline model scores#

Show all statistics, later use selected statistics

Hide code cell source

fname = args.scores_folder / f'diff_analysis_scores_{args.baseline}.pkl'
scores_baseline = pd.read_pickle(fname)
scores_baseline
model PI
var SS DF F p-unc np2 -Log10 pvalue qvalue rejected
protein groups Source
A0A024QZX5;A0A087X1N8;P35237 AD 0.633 1 0.931 0.336 0.005 0.474 0.502 False
age 0.035 1 0.052 0.820 0.000 0.086 0.894 False
Kiel 2.253 1 3.315 0.070 0.017 1.154 0.159 False
Magdeburg 5.871 1 8.639 0.004 0.043 2.432 0.015 True
Sweden 10.533 1 15.498 0.000 0.075 3.937 0.001 True
... ... ... ... ... ... ... ... ... ...
S4R3U6 AD 0.795 1 0.798 0.373 0.004 0.428 0.538 False
age 0.835 1 0.838 0.361 0.004 0.442 0.526 False
Kiel 0.537 1 0.538 0.464 0.003 0.333 0.619 False
Magdeburg 3.819 1 3.831 0.052 0.020 1.286 0.125 False
Sweden 4.139 1 4.153 0.043 0.021 1.367 0.108 False

7105 rows × 8 columns

Load selected comparison model scores#

Hide code cell source

fname = args.scores_folder / f'diff_analysis_scores_{args.model_key}.pkl'
scores_model = pd.read_pickle(fname)
scores_model
model TRKNN
var SS DF F p-unc np2 -Log10 pvalue qvalue rejected
protein groups Source
A0A024QZX5;A0A087X1N8;P35237 AD 0.994 1 7.134 0.008 0.036 2.085 0.023 True
age 0.004 1 0.029 0.864 0.000 0.063 0.913 False
Kiel 0.269 1 1.933 0.166 0.010 0.780 0.277 False
Magdeburg 0.519 1 3.727 0.055 0.019 1.259 0.114 False
Sweden 1.796 1 12.893 0.000 0.063 3.378 0.002 True
... ... ... ... ... ... ... ... ... ...
S4R3U6 AD 2.295 1 4.480 0.036 0.023 1.449 0.080 False
age 0.398 1 0.777 0.379 0.004 0.421 0.516 False
Kiel 2.981 1 5.819 0.017 0.030 1.775 0.043 True
Magdeburg 3.440 1 6.716 0.010 0.034 1.987 0.028 True
Sweden 27.114 1 52.939 0.000 0.217 11.062 0.000 True

7105 rows × 8 columns

Combined scores#

show only selected statistics for comparsion

Hide code cell source

scores = scores_model.join(scores_baseline, how='outer')[[args.baseline, args.model_key]]
scores = scores.loc[:, pd.IndexSlice[scores.columns.levels[0].to_list(),
                                     args.selected_statistics]]
scores
model PI TRKNN
var p-unc -Log10 pvalue qvalue rejected p-unc -Log10 pvalue qvalue rejected
protein groups Source
A0A024QZX5;A0A087X1N8;P35237 AD 0.336 0.474 0.502 False 0.008 2.085 0.023 True
Kiel 0.070 1.154 0.159 False 0.166 0.780 0.277 False
Magdeburg 0.004 2.432 0.015 True 0.055 1.259 0.114 False
Sweden 0.000 3.937 0.001 True 0.000 3.378 0.002 True
age 0.820 0.086 0.894 False 0.864 0.063 0.913 False
... ... ... ... ... ... ... ... ... ...
S4R3U6 AD 0.373 0.428 0.538 False 0.036 1.449 0.080 False
Kiel 0.464 0.333 0.619 False 0.017 1.775 0.043 True
Magdeburg 0.052 1.286 0.125 False 0.010 1.987 0.028 True
Sweden 0.043 1.367 0.108 False 0.000 11.062 0.000 True
age 0.361 0.442 0.526 False 0.379 0.421 0.516 False

7105 rows × 8 columns

Models in comparison (name mapping)

Hide code cell source

models = pimmslearn.nb.Config.from_dict(
    pimmslearn.pandas.index_to_dict(scores.columns.get_level_values(0)))
vars(models)
{'PI': 'PI', 'TRKNN': 'TRKNN'}

Describe scores#

Hide code cell source

scores.describe()
model PI TRKNN
var p-unc -Log10 pvalue qvalue p-unc -Log10 pvalue qvalue
count 7,105.000 7,105.000 7,105.000 7,105.000 7,105.000 7,105.000
mean 0.262 2.481 0.339 0.230 3.114 0.287
std 0.304 5.331 0.332 0.296 5.792 0.323
min 0.000 0.000 0.000 0.000 0.000 0.000
25% 0.004 0.332 0.015 0.001 0.392 0.003
50% 0.119 0.923 0.239 0.066 1.182 0.131
75% 0.465 2.416 0.620 0.405 3.156 0.540
max 1.000 149.342 1.000 1.000 82.663 1.000

One to one comparison of by feature:#

Hide code cell source

scores = scores.loc[pd.IndexSlice[:, args.target], :]
scores.to_excel(writer, 'scores', **writer_args)
scores
/tmp/ipykernel_79986/3761369923.py:2: FutureWarning: Starting with pandas version 3.0 all arguments of to_excel except for the argument 'excel_writer' will be keyword-only.
  scores.to_excel(writer, 'scores', **writer_args)
model PI TRKNN
var p-unc -Log10 pvalue qvalue rejected p-unc -Log10 pvalue qvalue rejected
protein groups Source
A0A024QZX5;A0A087X1N8;P35237 AD 0.336 0.474 0.502 False 0.008 2.085 0.023 True
A0A024R0T9;K7ER74;P02655 AD 0.043 1.364 0.109 False 0.031 1.512 0.071 False
A0A024R3W6;A0A024R412;O60462;O60462-2;O60462-3;O60462-4;O60462-5;Q7LBX6;X5D2Q8 AD 0.072 1.144 0.161 False 0.264 0.578 0.394 False
A0A024R644;A0A0A0MRU5;A0A1B0GWI2;O75503 AD 0.586 0.232 0.724 False 0.266 0.575 0.396 False
A0A075B6H7 AD 0.111 0.955 0.227 False 0.020 1.707 0.048 True
... ... ... ... ... ... ... ... ... ...
Q9Y6R7 AD 0.175 0.756 0.318 False 0.175 0.756 0.289 False
Q9Y6X5 AD 0.032 1.495 0.086 False 0.113 0.946 0.205 False
Q9Y6Y8;Q9Y6Y8-2 AD 0.083 1.079 0.182 False 0.083 1.079 0.160 False
Q9Y6Y9 AD 0.409 0.388 0.572 False 0.334 0.476 0.472 False
S4R3U6 AD 0.373 0.428 0.538 False 0.036 1.449 0.080 False

1421 rows × 8 columns

And the descriptive statistics of the numeric values:

Hide code cell source

scores.describe()
model PI TRKNN
var p-unc -Log10 pvalue qvalue p-unc -Log10 pvalue qvalue
count 1,421.000 1,421.000 1,421.000 1,421.000 1,421.000 1,421.000
mean 0.255 1.414 0.336 0.239 1.579 0.301
std 0.296 1.648 0.321 0.294 1.800 0.317
min 0.000 0.001 0.000 0.000 0.002 0.000
25% 0.011 0.365 0.038 0.007 0.373 0.021
50% 0.116 0.934 0.234 0.086 1.063 0.164
75% 0.432 1.941 0.592 0.423 2.151 0.559
max 0.998 23.733 0.999 0.996 19.900 0.997

and the boolean decision values

Hide code cell source

scores.describe(include=['bool', 'O'])
model PI TRKNN
var rejected rejected
count 1421 1421
unique 2 2
top False False
freq 1025 936

Load frequencies of observed features#

Hide code cell source

freq_feat = pd.read_csv(args.freq_features_observed, index_col=0)
freq_feat.columns = pd.MultiIndex.from_tuples([('data', 'frequency'),])
freq_feat
data
frequency
protein groups
A0A024QZX5;A0A087X1N8;P35237 186
A0A024R0T9;K7ER74;P02655 195
A0A024R3W6;A0A024R412;O60462;O60462-2;O60462-3;O60462-4;O60462-5;Q7LBX6;X5D2Q8 174
A0A024R644;A0A0A0MRU5;A0A1B0GWI2;O75503 196
A0A075B6H7 91
... ...
Q9Y6R7 197
Q9Y6X5 173
Q9Y6Y8;Q9Y6Y8-2 197
Q9Y6Y9 119
S4R3U6 126

1421 rows × 1 columns

Compare shared features#

Hide code cell source

scores_common = (scores
                 .dropna()
                 .reset_index(-1, drop=True)
                 ).join(
    freq_feat, how='left'
)
scores_common
PI TRKNN data
p-unc -Log10 pvalue qvalue rejected p-unc -Log10 pvalue qvalue rejected frequency
protein groups
A0A024QZX5;A0A087X1N8;P35237 0.336 0.474 0.502 False 0.008 2.085 0.023 True 186
A0A024R0T9;K7ER74;P02655 0.043 1.364 0.109 False 0.031 1.512 0.071 False 195
A0A024R3W6;A0A024R412;O60462;O60462-2;O60462-3;O60462-4;O60462-5;Q7LBX6;X5D2Q8 0.072 1.144 0.161 False 0.264 0.578 0.394 False 174
A0A024R644;A0A0A0MRU5;A0A1B0GWI2;O75503 0.586 0.232 0.724 False 0.266 0.575 0.396 False 196
A0A075B6H7 0.111 0.955 0.227 False 0.020 1.707 0.048 True 91
... ... ... ... ... ... ... ... ... ...
Q9Y6R7 0.175 0.756 0.318 False 0.175 0.756 0.289 False 197
Q9Y6X5 0.032 1.495 0.086 False 0.113 0.946 0.205 False 173
Q9Y6Y8;Q9Y6Y8-2 0.083 1.079 0.182 False 0.083 1.079 0.160 False 197
Q9Y6Y9 0.409 0.388 0.572 False 0.334 0.476 0.472 False 119
S4R3U6 0.373 0.428 0.538 False 0.036 1.449 0.080 False 126

1421 rows × 9 columns

Annotate decisions in Confusion Table style:#

Hide code cell source

def annotate_decision(scores, model, model_column):
    return scores[(model_column, 'rejected')].replace({False: f'{model} (no) ', True: f'{model} (yes)'})


annotations = None
for model, model_column in models.items():
    if annotations is not None:
        annotations += ' - '
        annotations += annotate_decision(scores_common,
                                         model=model, model_column=model_column)
    else:
        annotations = annotate_decision(
            scores_common, model=model, model_column=model_column)
annotations.name = 'Differential Analysis Comparison'
annotations.value_counts()
Differential Analysis Comparison
PI (no)  - TRKNN (no)    877
PI (yes) - TRKNN (yes)   337
PI (no)  - TRKNN (yes)   148
PI (yes) - TRKNN (no)     59
Name: count, dtype: int64

List different decisions between models#

Hide code cell source

mask_different = (
    (scores_common.loc[:, pd.IndexSlice[:, 'rejected']].any(axis=1))
    & ~(scores_common.loc[:, pd.IndexSlice[:, 'rejected']].all(axis=1))
)
_to_write = scores_common.loc[mask_different]
_to_write.to_excel(writer, 'differences', **writer_args)
logger.info("Writen to Excel file under sheet 'differences'.")
_to_write
/tmp/ipykernel_79986/1417621106.py:6: FutureWarning: Starting with pandas version 3.0 all arguments of to_excel except for the argument 'excel_writer' will be keyword-only.
  _to_write.to_excel(writer, 'differences', **writer_args)
root - INFO     Writen to Excel file under sheet 'differences'.
PI TRKNN data
p-unc -Log10 pvalue qvalue rejected p-unc -Log10 pvalue qvalue rejected frequency
protein groups
A0A024QZX5;A0A087X1N8;P35237 0.336 0.474 0.502 False 0.008 2.085 0.023 True 186
A0A075B6H7 0.111 0.955 0.227 False 0.020 1.707 0.048 True 91
A0A075B6I0 0.027 1.575 0.074 False 0.001 3.243 0.002 True 194
A0A075B6J9 0.027 1.563 0.076 False 0.009 2.040 0.026 True 156
A0A075B6Q5 0.618 0.209 0.750 False 0.002 2.639 0.008 True 104
... ... ... ... ... ... ... ... ... ...
Q9ULP0-3;Q9ULP0-6 0.023 1.635 0.067 False 0.000 3.410 0.002 True 136
Q9UP79 0.372 0.429 0.537 False 0.000 4.258 0.000 True 135
Q9UQ52 0.073 1.134 0.164 False 0.001 3.136 0.003 True 188
Q9Y281;Q9Y281-3 0.000 3.368 0.002 True 0.395 0.403 0.531 False 51
Q9Y6C2 0.775 0.110 0.864 False 0.002 2.626 0.008 True 119

207 rows × 9 columns

Plot qvalues of both models with annotated decisions#

Prepare data for plotting (qvalues)

Hide code cell source

var = 'qvalue'
to_plot = [scores_common[v][var] for v in models.values()]
for s, k in zip(to_plot, models.keys()):
    s.name = k.replace('_', ' ')
to_plot.append(scores_common['data'])
to_plot.append(annotations)
to_plot = pd.concat(to_plot, axis=1)
to_plot
PI TRKNN frequency Differential Analysis Comparison
protein groups
A0A024QZX5;A0A087X1N8;P35237 0.502 0.023 186 PI (no) - TRKNN (yes)
A0A024R0T9;K7ER74;P02655 0.109 0.071 195 PI (no) - TRKNN (no)
A0A024R3W6;A0A024R412;O60462;O60462-2;O60462-3;O60462-4;O60462-5;Q7LBX6;X5D2Q8 0.161 0.394 174 PI (no) - TRKNN (no)
A0A024R644;A0A0A0MRU5;A0A1B0GWI2;O75503 0.724 0.396 196 PI (no) - TRKNN (no)
A0A075B6H7 0.227 0.048 91 PI (no) - TRKNN (yes)
... ... ... ... ...
Q9Y6R7 0.318 0.289 197 PI (no) - TRKNN (no)
Q9Y6X5 0.086 0.205 173 PI (no) - TRKNN (no)
Q9Y6Y8;Q9Y6Y8-2 0.182 0.160 197 PI (no) - TRKNN (no)
Q9Y6Y9 0.572 0.472 119 PI (no) - TRKNN (no)
S4R3U6 0.538 0.080 126 PI (no) - TRKNN (no)

1421 rows × 4 columns

List of features with the highest difference in qvalues

Hide code cell source

# should it be possible to run not only RSN?
to_plot['diff_qvalue'] = (to_plot[str(args.baseline)] - to_plot[str(args.model_key)]).abs()
to_plot.loc[mask_different].sort_values('diff_qvalue', ascending=False)
PI TRKNN frequency Differential Analysis Comparison diff_qvalue
protein groups
P01743 0.997 0.008 113 PI (no) - TRKNN (yes) 0.989
Q8N9I0 0.989 0.004 141 PI (no) - TRKNN (yes) 0.985
O15197;O15197-3 0.980 0.007 104 PI (no) - TRKNN (yes) 0.973
O00187;O00187-2 0.999 0.037 119 PI (no) - TRKNN (yes) 0.962
Q9NPH3;Q9NPH3-2;Q9NPH3-5 0.976 0.032 186 PI (no) - TRKNN (yes) 0.944
... ... ... ... ... ...
A0A0J9YXX1 0.058 0.048 197 PI (no) - TRKNN (yes) 0.010
F5GY80;F5H7G1;P07358 0.057 0.047 197 PI (no) - TRKNN (yes) 0.010
Q9NX62 0.055 0.046 197 PI (no) - TRKNN (yes) 0.009
P00740;P00740-2 0.053 0.044 197 PI (no) - TRKNN (yes) 0.009
K7ERG9;P00746 0.052 0.043 197 PI (no) - TRKNN (yes) 0.009

207 rows × 5 columns

Differences plotted with created annotations#

Hide code cell source

figsize = (4, 4)
size = 5
fig, ax = plt.subplots(figsize=figsize)
x_col = to_plot.columns[0]
y_col = to_plot.columns[1]
ax = sns.scatterplot(data=to_plot,
                     x=x_col,
                     y=y_col,
                     s=size,
                     hue='Differential Analysis Comparison',
                     ax=ax)
_ = ax.legend(fontsize=fontsize,
              title_fontsize=fontsize,
              markerscale=0.4,
              title='',
              )
ax.set_xlabel(f"qvalue for {x_col}")
ax.set_ylabel(f"qvalue for {y_col}")
ax.hlines(0.05, 0, 1, color='grey', linestyles='dotted')
ax.vlines(0.05, 0, 1, color='grey', linestyles='dotted')
sns.move_legend(ax, "upper right")
files_out[f'diff_analysis_comparision_1_{args.model_key}'] = (
    args.out_folder /
    f'diff_analysis_comparision_1_{args.model_key}')
fname = files_out[f'diff_analysis_comparision_1_{args.model_key}']
pimmslearn.savefig(fig, name=fname)
pimmslearn.plotting - INFO     Saved Figures to runs/alzheimer_study/diff_analysis/AD/PI_vs_TRKNN/diff_analysis_comparision_1_TRKNN
../../../_images/4eddeb090d99014591e8b3d274dea15eaec22a5973843d55c0a69ea581405abf.png
  • also showing how many features were measured (“observed”) by size of circle

Hide code cell source

fig, ax = plt.subplots(figsize=figsize)
ax = sns.scatterplot(data=to_plot,
                     x=to_plot.columns[0],
                     y=to_plot.columns[1],
                     size='frequency',
                     s=size,
                     sizes=(5, 20),
                     hue='Differential Analysis Comparison')
_ = ax.legend(fontsize=fontsize,
              title_fontsize=fontsize,
              markerscale=0.6,
              title='',
              )
ax.set_xlabel(f"qvalue for {x_col}")
ax.set_ylabel(f"qvalue for {y_col}")
ax.hlines(0.05, 0, 1, color='grey', linestyles='dotted')
ax.vlines(0.05, 0, 1, color='grey', linestyles='dotted')
sns.move_legend(ax, "upper right")
files_out[f'diff_analysis_comparision_2_{args.model_key}'] = (
    args.out_folder / f'diff_analysis_comparision_2_{args.model_key}')
pimmslearn.savefig(
    fig, name=files_out[f'diff_analysis_comparision_2_{args.model_key}'])
pimmslearn.plotting - INFO     Saved Figures to runs/alzheimer_study/diff_analysis/AD/PI_vs_TRKNN/diff_analysis_comparision_2_TRKNN
../../../_images/8a0366826b14d9a3adc9cef9aa666de3a98bc1f7c0519562949ce51ebc473d98.png

Only features contained in model#

  • this block exist due to a specific part in the ALD analysis of the paper

Hide code cell source

scores_model_only = scores.reset_index(level=-1, drop=True)
_diff = scores_model_only.index.difference(scores_common.index)
if not _diff.empty:
    scores_model_only = (scores_model_only
                         .loc[
                             _diff,
                             args.model_key]
                         .sort_values(by='qvalue', ascending=True)
                         .join(freq_feat.squeeze().rename(freq_feat.columns.droplevel()[0])
                               )
                         )
    display(scores_model_only)
else:
    scores_model_only = None
    logger.info("No features only in new comparision model.")

if not _diff.empty:
    scores_model_only.to_excel(writer, 'only_model', **writer_args)
    display(scores_model_only.rejected.value_counts())
    scores_model_only_rejected = scores_model_only.loc[scores_model_only.rejected]
    scores_model_only_rejected.to_excel(
        writer, 'only_model_rejected', **writer_args)
root - INFO     No features only in new comparision model.

DISEASES DB lookup#

Query diseases database for gene associations with specified disease ontology id.

Hide code cell source

data = pimmslearn.databases.diseases.get_disease_association(
    doid=args.disease_ontology, limit=10000)
data = pd.DataFrame.from_dict(data, orient='index').rename_axis('ENSP', axis=0)
data = data.rename(columns={'name': args.annotaitons_gene_col}).reset_index(
).set_index(args.annotaitons_gene_col)
data
pimmslearn.databases.diseases - WARNING  There are more associations available
ENSP score
None
APOE ENSP00000252486 5.000
PSEN2 ENSP00000355747 5.000
PSEN1 ENSP00000326366 5.000
APP ENSP00000284981 5.000
TREM2 ENSP00000362205 4.825
... ... ...
ERP27 ENSP00000266397 0.681
ZNF585B ENSP00000433773 0.681
KIR3DL2 ENSP00000325525 0.681
C12orf66 ENSP00000311486 0.681
ELP2 ENSP00000414851 0.681

10000 rows × 2 columns

Shared features#

ToDo: new script -> DISEASES DB lookup

Hide code cell source

feat_name = scores.index.names[0]  # first index level is feature name
if args.annotaitons_gene_col in scores.index.names:
    logger.info(f"Found gene annotation in scores index:  {scores.index.names}")
else:
    logger.info(f"No gene annotation in scores index:  {scores.index.names}"
                " Exiting.")
    import sys
    sys.exit(0)
root - INFO     No gene annotation in scores index:  ['protein groups', 'Source'] Exiting.
/home/runner/work/pimms/pimms/project/.snakemake/conda/924ec7e362d761ecf0807b9074d79999_/lib/python3.12/site-packages/IPython/core/interactiveshell.py:3707: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.
  warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1)
An exception has occurred, use %tb to see the full traceback.

SystemExit: 0

Hide code cell source

gene_to_PG = (scores.droplevel(
    list(set(scores.index.names) - {feat_name, args.annotaitons_gene_col})
)
    .index
    .to_frame()
    .reset_index(drop=True)
    .set_index(args.annotaitons_gene_col)
)
gene_to_PG.head()

Hide code cell source

disease_associations_all = data.join(
    gene_to_PG).dropna().reset_index().set_index(feat_name).join(annotations)
disease_associations_all

only by model#

Hide code cell source

idx = disease_associations_all.index.intersection(scores_model_only.index)
disease_assocications_new = disease_associations_all.loc[idx].sort_values(
    'score', ascending=False)
disease_assocications_new.head(20)

Hide code cell source

mask = disease_assocications_new.loc[idx, 'score'] >= 2.0
disease_assocications_new.loc[idx].loc[mask]

Only by model which were significant#

Hide code cell source

idx = disease_associations_all.index.intersection(
    scores_model_only_rejected.index)
disease_assocications_new_rejected = disease_associations_all.loc[idx].sort_values(
    'score', ascending=False)
disease_assocications_new_rejected.head(20)

Hide code cell source

mask = disease_assocications_new_rejected.loc[idx, 'score'] >= 2.0
disease_assocications_new_rejected.loc[idx].loc[mask]

Shared which are only significant for by model#

mask = (scores_common[(str(args.model_key), 'rejected')] & mask_different)
mask.sum()

Hide code cell source

idx = disease_associations_all.index.intersection(mask.index[mask])
disease_assocications_shared_rejected_by_model = (disease_associations_all.loc[idx].sort_values(
    'score', ascending=False))
disease_assocications_shared_rejected_by_model.head(20)

Hide code cell source

mask = disease_assocications_shared_rejected_by_model.loc[idx, 'score'] >= 2.0
disease_assocications_shared_rejected_by_model.loc[idx].loc[mask]

Only significant by RSN#

mask = (scores_common[(str(args.baseline), 'rejected')] & mask_different)
mask.sum()

Hide code cell source

idx = disease_associations_all.index.intersection(mask.index[mask])
disease_assocications_shared_rejected_by_RSN = (
    disease_associations_all
    .loc[idx]
    .sort_values('score', ascending=False))
disease_assocications_shared_rejected_by_RSN.head(20)

Hide code cell source

mask = disease_assocications_shared_rejected_by_RSN.loc[idx, 'score'] >= 2.0
disease_assocications_shared_rejected_by_RSN.loc[idx].loc[mask]

Write to excel#

Hide code cell source

disease_associations_all.to_excel(
    writer, sheet_name='disease_assoc_all', **writer_args)
disease_assocications_new.to_excel(
    writer, sheet_name='disease_assoc_new', **writer_args)
disease_assocications_new_rejected.to_excel(
    writer, sheet_name='disease_assoc_new_rejected', **writer_args)

Outputs#

Hide code cell source

writer.close()
files_out