Skip to content

Commit

Permalink
Merge pull request #126 from MannLabs/multicova
Browse files Browse the repository at this point in the history
add option for compare preprocessing
  • Loading branch information
elena-krismer authored Mar 2, 2023
2 parents 17e1edb + 228f35f commit 7a1730e
Show file tree
Hide file tree
Showing 24 changed files with 143 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.4.1
current_version = 0.4.2
commit = True
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+)(?P<build>\d+))?
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
python -m pip install --upgrade pip
pip install coverage
pip install wheel
pip install dictdiffer
- name: Test installation
run: |
pip install -e.
Expand Down
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

# 0.4.2
* ADD option compare_preprocessing_modes
* update to streamlit 1.19 with new caching functions

# 0.4.1
* FIX bug when drawing FDR lines
* ADD functionionality `dataset.reset_preprocessing()` to reset all preprocessing steps
Expand Down
46 changes: 30 additions & 16 deletions alphastats/DataSet_Plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ def plot_volcano(
alpha=0.05,
draw_line=True,
perm=100,
fdr=0.05
fdr=0.05,
compare_preprocessing_modes=False
):
"""Plot Volcano Plot
Expand All @@ -136,31 +137,38 @@ def plot_volcano(
method (str): "anova", "wald", "ttest", "SAM" Defaul ttest.
labels (bool): Add text labels to significant Proteins, Default False.
alpha(float,optional): p-value cut off.
min_fc (float): Minimum fold change
min_fc (float): Minimum fold change.
draw_line(boolean): whether to draw cut off lines.
perm(float,optional): number of permutations when using SAM as method. Defaults to 100.
fdr(float,optional): FDR cut off when using SAM as method. Defaults to 0.05.
compare_preprocessing_modes(bool): Will iterate through normalization and imputation modes and return a list of VolcanoPlots in different settings, Default False.
Returns:
plotly.graph_objects._figure.Figure: Volcano Plot
"""

volcano_plot = VolcanoPlot(
dataset=self,
group1=group1,
group2=group2,
column=column,
method=method,
labels=labels,
min_fc=min_fc,
alpha=alpha,
draw_line=draw_line,
perm=perm,
fdr=fdr
)
if compare_preprocessing_modes:
params_for_func = locals()
results = self._compare_preprocessing_modes(func=VolcanoPlot,params_for_func=params_for_func)
return results

else:
volcano_plot = VolcanoPlot(
dataset=self,
group1=group1,
group2=group2,
column=column,
method=method,
labels=labels,
min_fc=min_fc,
alpha=alpha,
draw_line=draw_line,
perm=perm,
fdr=fdr
)

return volcano_plot.plot
return volcano_plot.plot

def plot_correlation_matrix(self, method="pearson"):
"""Plot Correlation Matrix
Expand Down Expand Up @@ -224,6 +232,7 @@ def plot_intensity(
method="box",
add_significance=False,
log_scale=False,
compare_preprocessing_modes=False
):
"""Plot Intensity of individual Protein/ProteinGroup
Expand All @@ -238,6 +247,11 @@ def plot_intensity(
Returns:
plotly.graph_objects._figure.Figure: Plotly Plot
"""
if compare_preprocessing_modes:
params_for_func = locals()
results = self._compare_preprocessing_modes(func=IntensityPlot,params_for_func=params_for_func)
return results

intensity_plot = IntensityPlot(
dataset = self,
protein_id=protein_id,
Expand Down
29 changes: 29 additions & 0 deletions alphastats/DataSet_Preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import sklearn.impute
from alphastats.utils import ignore_warning
from sklearn.experimental import enable_iterative_imputer
import itertools


class Preprocess:
Expand Down Expand Up @@ -165,6 +166,34 @@ def reset_preprocessing(self):
# reset all preprocessing steps
self.create_matrix()
print("All preprocessing steps are reset.")

def _compare_preprocessing_modes(self, func, params_for_func):
dataset = self
imputation_methods = ["mean", "median", "knn"]
normalization_methods = ["zscore", "quantile", "vst"]
preprocessing_modes = list(itertools.product(normalization_methods, imputation_methods))

results_list = []

del params_for_func["compare_preprocessing_modes"]
params_for_func["dataset"] = params_for_func.pop("self")

for preprocessing_mode in preprocessing_modes:
# reset preprocessing
dataset.reset_preprocessing()
print(f"Normalization {preprocessing_mode[0]}, Imputation {str(preprocessing_mode[1])}")

dataset.preprocess(
subset=True,
normalization = preprocessing_mode[0],
imputation = preprocessing_mode[1]
)

res = func(**params_for_func)
results_list.append(res)

return results_list


@ignore_warning(RuntimeWarning)
def preprocess(
Expand Down
2 changes: 1 addition & 1 deletion alphastats/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__project__ = "alphastats"
__version__ = "0.4.1"
__version__ = "0.4.2"
__license__ = "Apache"
__description__ = "An open-source Python package for Mass Spectrometry Analysis"
__author__ = "Mann Labs"
Expand Down
9 changes: 9 additions & 0 deletions alphastats/gui/AlphaPeptStats.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@

# centering with streamlit is not really centered

from streamlit.runtime import get_instance
from streamlit.runtime.scriptrunner.script_run_context import get_script_run_ctx

runtime = get_instance()
session_id = get_script_run_ctx().session_id
session_info = runtime._session_mgr.get_session_info(session_id)

user_session_id = session_id
st.session_state["user_session_id"] = user_session_id

img_center = """
<head>
Expand Down
12 changes: 8 additions & 4 deletions alphastats/gui/pages/02_Import Data.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from alphastats import DataSet



import pandas as pd
import plotly.express as px

Expand Down Expand Up @@ -140,15 +141,14 @@ def select_sample_column_metadata(df, software):

def upload_softwarefile(software):

st.file_uploader(
softwarefile = st.file_uploader(
print_software_import_info(software=software),
key="softwarefile",
type=["csv", "tsv", "txt", "hdf"],
)

if st.session_state.softwarefile is not None:
if softwarefile is not None:

softwarefile_df = read_uploaded_file_into_df(st.session_state.softwarefile)
softwarefile_df = read_uploaded_file_into_df(softwarefile)
# display head a protein data

check_software_file(softwarefile_df, software)
Expand Down Expand Up @@ -302,6 +302,10 @@ def empty_session_state():
del st.session_state[key]
st.empty()

from streamlit.runtime import get_instance
from streamlit.runtime.scriptrunner.script_run_context import get_script_run_ctx
user_session_id = get_script_run_ctx().session_id
st.session_state["user_session_id"] = user_session_id

sidebar_info()

Expand Down
8 changes: 4 additions & 4 deletions alphastats/gui/pages/03_Data Overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import plotly.express as px


@st.cache
def convert_df(df):
@st.cache_data
def convert_df(df, user_session_id = st.session_state.user_session_id):
return df.to_csv().encode("utf-8")


@st.cache
def get_display_matrix():
@st.cache_data
def get_display_matrix(user_session_id = st.session_state.user_session_id):

processed_df = pd.DataFrame(
st.session_state.dataset.mat.values,
Expand Down
4 changes: 2 additions & 2 deletions alphastats/gui/pages/04_Analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ def download_figure(obj, format, plotting_library="plotly"):
st.download_button(label="Download as " + format, data=buffer, file_name=filename)


@st.cache
def convert_df(df):
@st.cache_data
def convert_df(df, user_session_id = st.session_state.user_session_id):
return df.to_csv().encode("utf-8")


Expand Down
4 changes: 2 additions & 2 deletions alphastats/gui/pages/06_Results.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def save_plotly(plot, format):
)


@st.cache
def convert_df(df):
@st.cache_data
def convert_df(df, user_session_id = st.session_state.user_session_id):
return df.to_csv().encode("utf-8")


Expand Down
3 changes: 0 additions & 3 deletions alphastats/gui/pages/07_ Getting Started.py

This file was deleted.

6 changes: 5 additions & 1 deletion alphastats/plots/VolcanoPlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@

class VolcanoPlot(PlotUtils):
def __init__(
self, dataset, group1, group2, column=None, method=None, labels=None, min_fc=None, alpha=None, draw_line=None, plot=True, perm=100, fdr=0.05
self, dataset, group1, group2,
column=None, method=None,
labels=None, min_fc=None,
alpha=None, draw_line=None,
plot=True, perm=100, fdr=0.05
):
self.dataset = dataset
self.group1 = group1
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
author = "Elena Krismer"

# The full version, including alpha/beta/rc tags
release = "0.4.1"
release = "0.4.2"


# -- General configuration ---------------------------------------------------
Expand Down
20 changes: 20 additions & 0 deletions package.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM python:3.9-slim-buster

# Set the working directory
WORKDIR /app

# Install any necessary system dependencies here
RUN apt-get update && apt-get install -y \
libpq-dev \
gcc \
&& rm -rf /var/lib/apt/lists/*

RUN git clone https://github.com/MannLabs/alphapeptstats.git .
# Install Python packages and any other dependencies
RUN pip3 install -e.

# Copy the Python package files into the container
COPY alphapeptstats /app/alphapeptstats

# Set the entrypoint command to the package's setup.py file
ENTRYPOINT ["python", "-m", "setup.py"]
2 changes: 1 addition & 1 deletion release/one_click_linux_gui/control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: alphastats
Version: 0.4.1
Version: 0.4.2
Architecture: all
Maintainer: MannLabs
Description: alphastats
Expand Down
2 changes: 1 addition & 1 deletion release/one_click_linux_gui/create_installer_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ python setup.py sdist bdist_wheel
# Setting up the local package
cd release/one_click_linux_gui
# Make sure you include the required extra packages and always use the stable or very-stable options!
pip install "../../dist/alphastats-0.4.1-py3-none-any.whl"
pip install "../../dist/alphastats-0.4.2-py3-none-any.whl"

# Creating the stand-alone pyinstaller folder
pip install pyinstaller==5.8
Expand Down
4 changes: 2 additions & 2 deletions release/one_click_macos_gui/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
<key>CFBundleIconFile</key>
<string>alphapeptstats_logo.icns</string>
<key>CFBundleIdentifier</key>
<string>alphastats.0.4.1</string>
<string>alphastats.0.4.2</string>
<key>CFBundleShortVersionString</key>
<string>0.4.1</string>
<string>0.4.2</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
2 changes: 1 addition & 1 deletion release/one_click_macos_gui/create_installer_macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ python setup.py sdist bdist_wheel

# Setting up the local package
cd release/one_click_macos_gui
pip install "../../dist/alphastats-0.4.1-py3-none-any.whl"
pip install "../../dist/alphastats-0.4.2-py3-none-any.whl"

# Creating the stand-alone pyinstaller folder
pip install pyinstaller==5.8
Expand Down
2 changes: 1 addition & 1 deletion release/one_click_windows_gui/alphastats_innoinstaller.iss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "AlphaPeptStats"
#define MyAppVersion "0.4.1"
#define MyAppVersion "0.4.2"
#define MyAppPublisher "MannLabs"
#define MyAppURL "https://github.com/MannLabs/alphapeptstats"
#define MyAppExeName "alphastats_gui.exe"
Expand Down
2 changes: 1 addition & 1 deletion release/one_click_windows_gui/create_installer_windows.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ python setup.py sdist bdist_wheel
# Setting up the local package
cd release/one_click_windows_gui
# Make sure you include the required extra packages and always use the stable or very-stable options!
pip install "../../dist/alphastats-0.4.1-py3-none-any.whl"
pip install "../../dist/alphastats-0.4.2-py3-none-any.whl"

# Creating the stand-alone pyinstaller folder
pip install pyinstaller==5.8
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ tqdm>=4.64.0
diffxpy==0.7.4
anndata==0.8.0
umap-learn==0.5.3
streamlit==1.17.0
streamlit==1.19.0
tables==3.7.0
numpy==1.23.5
numba==0.56.4
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def create_pip_wheel():
requirements = get_requirements()
setuptools.setup(
name="alphastats",
version="0.4.1",
version="0.4.2",
license="Apache",
description="An open-source Python package for Mass Spectrometry Analysis",
long_description=get_long_description(),
Expand Down
Loading

0 comments on commit 7a1730e

Please sign in to comment.