Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion alphaquant/diffquant/condpair_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def analyze_condpair(*,runconfig, condpair):
return

df_c1_normed, df_c2_normed = aqnorm.normalize_if_specified(df_c1 = df_c1, df_c2 = df_c2, c1_samples = c1_samples, c2_samples = c2_samples, normalize_within_conds = runconfig.normalize, normalize_between_conds = runconfig.normalize,
runtime_plots = runconfig.runtime_plots, protein_subset_for_normalization_file=runconfig.protein_subset_for_normalization_file, pep2prot = pep2prot)#, "./test_data/normed_intensities.tsv")
runtime_plots = runconfig.runtime_plots, protein_subset_for_normalization_file=runconfig.protein_subset_for_normalization_file, pep2prot = pep2prot,
median_normalization = getattr(runconfig, 'median_normalization', False))#, "./test_data/normed_intensities.tsv")
Comment on lines 69 to +71

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please simplify this by splitting into several statements?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nevermind, now I got it..
ping me once it is a good time to format the codebase ;-)


summarization_nodes = getattr(runconfig, 'summarization_nodes', [])
if summarization_nodes:
Expand Down
18 changes: 9 additions & 9 deletions alphaquant/norm/normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def mode_normalization(x):
import numpy as np
from scipy import stats

def get_betweencond_shift(df_c1_normed, df_c2_normed, enfore_median = False):
def get_betweencond_shift(df_c1_normed, df_c2_normed, median_normalization = False):

both_idx = df_c1_normed.index.intersection(df_c2_normed.index)
df1 = df_c1_normed.loc[both_idx]
Expand All @@ -269,7 +269,7 @@ def get_betweencond_shift(df_c1_normed, df_c2_normed, enfore_median = False):

diff_fcs = df1[col1].to_numpy() - df2[col2].to_numpy()
median = np.nanmedian(diff_fcs)
if enfore_median:
if median_normalization:
return -median

if len(diff_fcs)<100:
Expand All @@ -288,7 +288,7 @@ def get_betweencond_shift(df_c1_normed, df_c2_normed, enfore_median = False):
# Cell
import pandas as pd

def normalize_if_specified(df_c1, df_c2, c1_samples, c2_samples, normalize_within_conds = True, normalize_between_conds = True, runtime_plots = True, protein_subset_for_normalization_file = None, pep2prot =None):
def normalize_if_specified(df_c1, df_c2, c1_samples, c2_samples, normalize_within_conds = True, normalize_between_conds = True, runtime_plots = True, protein_subset_for_normalization_file = None, pep2prot =None, median_normalization = False):

if normalize_within_conds:
df_c1 = normalize_within_cond(df_c=df_c1, samples_c= c1_samples)
Expand All @@ -299,15 +299,15 @@ def normalize_if_specified(df_c1, df_c2, c1_samples, c2_samples, normalize_withi
aq_plot_pairwise.plot_withincond_normalization(df_c1, df_c2)

if normalize_between_conds:
df_c1, df_c2 = get_normalized_dfs_between_conditions(df_c1, df_c2, protein_subset_for_normalization_file, pep2prot,runtime_plots = runtime_plots)
df_c1, df_c2 = get_normalized_dfs_between_conditions(df_c1, df_c2, protein_subset_for_normalization_file, pep2prot,runtime_plots = runtime_plots, median_normalization = median_normalization)
LOGGER.info("normalized between conditions")

return df_c1, df_c2



def get_normalized_dfs_between_conditions(df_c1, df_c2, protein_subset_for_normalization_file, pep2prot,runtime_plots):
shift_between_cond = prepare_tables_and_get_betweencond_shift(df_c1, df_c2, protein_subset_for_normalization_file, pep2prot)
def get_normalized_dfs_between_conditions(df_c1, df_c2, protein_subset_for_normalization_file, pep2prot,runtime_plots, median_normalization = False):
shift_between_cond = prepare_tables_and_get_betweencond_shift(df_c1, df_c2, protein_subset_for_normalization_file, pep2prot, median_normalization = median_normalization)

LOGGER.info(f"shift comparison by {shift_between_cond}")
df_c2 = df_c2-shift_between_cond
Expand All @@ -322,12 +322,12 @@ def normalize_within_cond(df_c, samples_c):
df_c_normed = pd.DataFrame(apply_sampleshifts(df_c.to_numpy().T, sample2shift).T, index = df_c.index, columns = samples_c)
return df_c_normed

def prepare_tables_and_get_betweencond_shift(df_c1, df_c2, protein_subset_for_normalization_file, pep2prot):
def prepare_tables_and_get_betweencond_shift(df_c1, df_c2, protein_subset_for_normalization_file, pep2prot, median_normalization = False):
specified_protein_subset = read_specified_protein_subset_if_given(protein_subset_for_normalization_file)
prepared1 = prepare_table_for_betweencond_shift(df_c1, specified_protein_subset, pep2prot)
prepared2 = prepare_table_for_betweencond_shift(df_c2, specified_protein_subset, pep2prot)
enforce_median = protein_subset_for_normalization_file is not None
return get_betweencond_shift(prepared1, prepared2, enforce_median)
median_normalization = median_normalization or (protein_subset_for_normalization_file is not None)
return get_betweencond_shift(prepared1, prepared2, median_normalization)

def read_specified_protein_subset_if_given(specified_protein_subset_file):
if specified_protein_subset_file is not None:
Expand Down
2 changes: 2 additions & 0 deletions alphaquant/run_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def run_pipeline(input_file: str,
volcano_fcthresh: float = 0.5,
annotation_columns: Optional[List[str]] = None,
protein_subset_for_normalization_file: Optional[str] = None,
median_normalization: bool = False,
protnorm_peptides: bool = True,
peptides_to_exclude_file: Optional[str] = None,
reset_progress_folder: bool = False,
Expand Down Expand Up @@ -154,6 +155,7 @@ def run_pipeline(input_file: str,
volcano_fcthresh (float): Fold change threshold for volcano plot significance. Defaults to 0.5.
annotation_columns (list): Additional columns to include in output tables.
protein_subset_for_normalization_file (str): File specifying proteins to use for normalization.
median_normalization (bool): Take the median of the between-condition fold-change distribution as the shift, instead of choosing between its median and its mode. Passing protein_subset_for_normalization_file also implies this. Defaults to False.
protnorm_peptides (bool): Enable protein-level peptide normalization. Defaults to True.
peptides_to_exclude_file (str): File listing peptides to exclude (e.g., shared between species).
reset_progress_folder (bool): Clear and recreate the progress folder. Defaults to False.
Expand Down