Skip to content

Commit 74aa8ab

Browse files
authored
Merge pull request #510 from bigbio/dev
Heatmap for FragPipe
2 parents 8e14a2c + beae1e6 commit 74aa8ab

File tree

7 files changed

+221
-38
lines changed

7 files changed

+221
-38
lines changed

pmultiqc/modules/common/dia_utils.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
from multiqc.plots import table
99

1010
from pmultiqc.modules.common.histogram import Histogram
11-
from pmultiqc.modules.common.stats import qual_uniform
11+
from pmultiqc.modules.common.stats import (
12+
qual_uniform,
13+
cal_hm_charge
14+
)
1215
from pmultiqc.modules.common.plots import dia as dia_plots
1316
from pmultiqc.modules.common.file_utils import file_prefix
1417
from pmultiqc.modules.common.common_utils import (
@@ -576,14 +579,11 @@ def heatmap_cont_pep_intensity(report_df):
576579
df["is_contaminant"] = df["Protein.Names"].str.startswith("CON", na=False)
577580

578581
# 3. "Charge"
579-
charge = dict()
580-
for raw_file, group in df[["Run", "Precursor.Charge"]].groupby("Run"):
581-
vc = group["Precursor.Charge"].value_counts(dropna=True, normalize=True)
582-
charge[raw_file] = vc.get(2, 0)
583-
charge_median = np.median(list(charge.values())) if charge else 0
584-
heatmap_charge = {
585-
k: float(max(0.0, 1.0 - abs(v - charge_median))) for k, v in charge.items()
586-
}
582+
heatmap_charge = cal_hm_charge(
583+
df=df,
584+
run_col="Run",
585+
charge_col="Precursor.Charge"
586+
)
587587

588588
heatmap_dict = {}
589589
for run, group in df.groupby("Run"):

pmultiqc/modules/common/plots/general.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def draw_heatmap(
9595
heatmap_data,
9696
heatmap_xnames,
9797
heatmap_ynames,
98-
is_maxquant
98+
report_type
9999
):
100100
pconfig = {
101101
"id": "heatmap",
@@ -112,9 +112,12 @@ def draw_heatmap(
112112
"cluster_cols": False,
113113
"save_data_file": False,
114114
}
115-
if is_maxquant:
115+
if report_type == "maxquant":
116116
hm_html = heatmap.plot(data=heatmap_data, pconfig=pconfig)
117117
description_text = "This heatmap provides an overview of the performance of MaxQuant."
118+
elif report_type == "fragpipe":
119+
hm_html = heatmap.plot(data=heatmap_data, pconfig=pconfig)
120+
description_text = "This heatmap provides an overview of the performance of FragPipe."
118121
else:
119122
hm_html = heatmap.plot(heatmap_data, heatmap_xnames, heatmap_ynames, pconfig)
120123
description_text = "This heatmap provides an overview of the performance of quantms."

pmultiqc/modules/common/stats.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import numpy as np
2+
import pandas as pd
23

34

45
def nanmedian(values: np.ndarray, all_nan_fallback: np.float64) -> np.float64:
@@ -56,4 +57,22 @@ def cal_delta_mass_dict(df, col):
5657
"frequency": frequency_bin_data,
5758
}
5859

59-
return delta_mass
60+
return delta_mass
61+
62+
63+
def cal_hm_charge(df: pd.DataFrame, run_col: str, charge_col: str):
64+
65+
if run_col not in df.columns or charge_col not in df.columns:
66+
return {}
67+
68+
charge = dict()
69+
70+
for raw_file, group in df[[run_col, charge_col]].groupby(run_col):
71+
vc = group[charge_col].value_counts(dropna=True, normalize=True)
72+
charge[raw_file] = vc.get(2, 0)
73+
charge_median = np.median(list(charge.values())) if charge else 0
74+
75+
return {
76+
k: float(max(0.0, 1.0 - abs(v - charge_median)))
77+
for k, v in charge.items()
78+
}

0 commit comments

Comments
 (0)