Skip to content

Commit

Permalink
Merge pull request #204 from MannLabs/release_0.6.2
Browse files Browse the repository at this point in the history
Release 0.6.2
  • Loading branch information
elena-krismer authored Jun 18, 2023
2 parents b7674c4 + 311d5f4 commit be87721
Show file tree
Hide file tree
Showing 22 changed files with 138 additions and 40 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.6.1
current_version = 0.6.2
commit = True
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+)(?P<build>\d+))?
Expand Down
6 changes: 6 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Changelog

# 0.6.2
* FIX preprocessing with VST floats and inf
* FIX plotly display

# 0.6.1
* FIX data loading

# 0.6.0
* ADD mzTAB support
* ENH color Volcano Plot data points using list of protein names `color_list=your_protein_list`
Expand Down
3 changes: 2 additions & 1 deletion alphastats/DataSet.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def create_matrix(self):
df.columns = df.columns.str.replace(substring_to_remove, "")
# transpose dataframe
mat = df.transpose()
mat.replace([np.inf, -np.inf], np.nan, inplace=True)
# remove proteins with only zero
self.mat = mat.loc[:, (mat != 0).any(axis=0)]
self.mat = self.mat.astype(float)
Expand Down Expand Up @@ -206,7 +207,7 @@ def overview(self):
dataset_overview = (
"Attributes of the DataSet can be accessed using: \n"
+ "DataSet.rawinput:\t Raw Protein data.\n"
+ "DataSet.mat:\tProcessed data matrix with ProteinIDs/ProteinGroups as columns and samples as rows. All computations are performed on this matrix.\n"
+ "DataSet.mat:\t\tProcessed data matrix with ProteinIDs/ProteinGroups as columns and samples as rows. All computations are performed on this matrix.\n"
+ "DataSet.metadata:\tMetadata for the samples in the matrix. Metadata will be matched with DataSet.mat when needed (for instance Volcano Plot)."
)
print(dataset_overview)
2 changes: 2 additions & 0 deletions alphastats/DataSet_Plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ def plot_umap(self, group=None, circle=False):
)
return dimensionality_reduction.plot


@ignore_warning(RuntimeWarning)
def plot_volcano(
self,
group1,
Expand Down
25 changes: 18 additions & 7 deletions alphastats/DataSet_Preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ def _imputation(self, method):
logging.info("Imputing data...")

if method == "mean":
imp = sklearn.impute.SimpleImputer(missing_values=np.nan, strategy="mean")
imp = sklearn.impute.SimpleImputer(missing_values=np.nan, strategy="mean", keep_empty_features=True)
imputation_array = imp.fit_transform(self.mat.values)

elif method == "median":
imp = sklearn.impute.SimpleImputer(missing_values=np.nan, strategy="median")
imp = sklearn.impute.SimpleImputer(missing_values=np.nan, strategy="median", keep_empty_features=True)
imputation_array = imp.fit_transform(self.mat.values)

elif method == "knn":
Expand Down Expand Up @@ -145,7 +145,7 @@ def _normalization(self, method):
)

elif method == "vst":
scaler = sklearn.preprocessing.PowerTransformer()
scaler = sklearn.preprocessing.PowerTransformer(standardize=False)
normalized_array = scaler.fit_transform(self.mat.values)

else:
Expand All @@ -167,10 +167,17 @@ def reset_preprocessing(self):
self.create_matrix()
print("All preprocessing steps are reset.")

@ignore_warning(RuntimeWarning)
def _compare_preprocessing_modes(self, func, params_for_func) -> list:
dataset = self
imputation_methods = ["mean", "median", "knn"]
normalization_methods = ["zscore", "quantile", "vst"]

# normalization_methods = methods["normalization"]
# if isinstance(methods, dict):
# imputation_methods = methods["imputation"]

imputation_methods = ["mean", "median", "knn", "randomforest"]
normalization_methods = ["vst","zscore", "quantile" ]

preprocessing_modes = list(itertools.product(normalization_methods, imputation_methods))

results_list = []
Expand All @@ -182,7 +189,7 @@ def _compare_preprocessing_modes(self, func, params_for_func) -> list:
# reset preprocessing
dataset.reset_preprocessing()
print(f"Normalization {preprocessing_mode[0]}, Imputation {str(preprocessing_mode[1])}")

dataset.mat.replace([np.inf, -np.inf], np.nan, inplace=True)
dataset.preprocess(
subset=True,
normalization = preprocessing_mode[0],
Expand All @@ -192,6 +199,8 @@ def _compare_preprocessing_modes(self, func, params_for_func) -> list:
res = func(**params_for_func)
results_list.append(res)

print("\t")

return results_list

def _log2_transform(self):
Expand Down Expand Up @@ -272,11 +281,13 @@ def preprocess(
if subset:
self.mat = self._subset()

if log2_transform:
if log2_transform and self.preprocessing_info.get("Log2-transformed") is False:
self._log2_transform()

if normalization is not None:
self._normalization(method=normalization)
self.mat = self.mat.replace([np.inf, -np.inf], np.nan)
#self.mat[:] = np.nan_to_num(self.mat)

if imputation is not None:
self._imputation(method=imputation)
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.6.1"
__version__ = "0.6.2"
__license__ = "Apache"
__description__ = "An open-source Python package for Mass Spectrometry Analysis"
__author__ = "Mann Labs"
Expand Down
1 change: 1 addition & 0 deletions alphastats/plots/DimensionalityReduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ def _plot(self, sample_names, group_color):
labels=self.labels,
color=group_color,
hover_data=[components[self.dataset.sample]],
template="simple_white+alphastats_colors"
)

# rename hover_data_0 to sample
Expand Down
32 changes: 28 additions & 4 deletions alphastats/plots/IntensityPlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,30 @@
import numpy as np
import plotly.graph_objects as go
import plotly.express as px
import plotly

from alphastats.plots.PlotUtils import plotly_object, PlotUtils

plotly.io.templates["alphastats_colors"] = plotly.graph_objects.layout.Template(
layout=plotly.graph_objects.Layout(
paper_bgcolor="rgba(0,0,0,0)",
plot_bgcolor="rgba(0,0,0,0)",
colorway=[
"#009599",
"#005358",
"#772173",
"#B65EAF", # pink
"#A73A00",
"#6490C1",
"#FF894F",
"#2B5E8B",
"#A87F32",
],
)
)

plotly.io.templates.default = "simple_white+alphastats_colors"


class IntensityPlot(PlotUtils):
def __init__(self,
Expand Down Expand Up @@ -115,23 +136,26 @@ def _prepare_data(self):
def _plot(self):
if self.method == "violin":
fig = px.violin(
self.prepared_df, y=self.protein_id, x=self.group, color=self.group, labels={self.protein_id: self.y_label}
self.prepared_df, y=self.protein_id, x=self.group, color=self.group, labels={self.protein_id: self.y_label},
template="simple_white+alphastats_colors"
)

elif self.method == "box":
fig = px.box(
self.prepared_df, y=self.protein_id, x=self.group, color=self.group, labels={self.protein_id: self.y_label}
self.prepared_df, y=self.protein_id, x=self.group, color=self.group, labels={self.protein_id: self.y_label},
template="simple_white+alphastats_colors"
)

elif self.method == "scatter":
fig = px.scatter(
self.prepared_df, y=self.protein_id, x=self.group, color=self.group, labels={self.protein_id: self.y_label}
self.prepared_df, y=self.protein_id, x=self.group, color=self.group, labels={self.protein_id: self.y_label},
template="simple_white+alphastats_colors"
)

elif self.method == "all":
fig = px.violin(
self.prepared_df, y=self.protein_id, x=self.group, color=self.group, labels={self.protein_id: self.y_label},
box=True, points="all"
box=True, points="all", template= "simple_white+alphastats_colors"
)

else:
Expand Down
20 changes: 20 additions & 0 deletions alphastats/plots/PlotUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@
import seaborn as sns
import plotly.graph_objects as go

plotly.io.templates["alphastats_colors"] = plotly.graph_objects.layout.Template(
layout=plotly.graph_objects.Layout(
paper_bgcolor="rgba(0,0,0,0)",
plot_bgcolor="rgba(0,0,0,0)",
colorway=[
"#009599",
"#005358",
"#772173",
"#B65EAF", # pink
"#A73A00",
"#6490C1",
"#FF894F",
"#2B5E8B",
"#A87F32",
],
)
)

plotly.io.templates.default = "simple_white+alphastats_colors"

class PlotUtils:
def __init__(self) -> None:
pass
Expand Down
24 changes: 22 additions & 2 deletions alphastats/plots/VolcanoPlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,28 @@
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go

import plotly
from functools import lru_cache

plotly.io.templates["alphastats_colors"] = plotly.graph_objects.layout.Template(
layout=plotly.graph_objects.Layout(
paper_bgcolor="rgba(0,0,0,0)",
plot_bgcolor="rgba(0,0,0,0)",
colorway=[
"#009599",
"#005358",
"#772173",
"#B65EAF", # pink
"#A73A00",
"#6490C1",
"#FF894F",
"#2B5E8B",
"#A87F32",
],
)
)

plotly.io.templates.default = "simple_white+alphastats_colors"

class VolcanoPlot(PlotUtils):
def __init__(
Expand Down Expand Up @@ -245,7 +264,7 @@ def _annotate_result_df(self):
convert pvalue to log10
add color labels for up and down regulates
"""
self.res = self.res[(self.res["log2fc"] < 10) & (self.res["log2fc"] > -10)]
self.res = self.res[(self.res["log2fc"] < 20) & (self.res["log2fc"] > -20)]
self.res["-log10(p-value)"] = -np.log10(self.res[self.pvalue_column])

self.alpha = -np.log10(self.alpha)
Expand Down Expand Up @@ -353,6 +372,7 @@ def _plot(self):
y="-log10(p-value)",
color="color",
hover_data=self.hover_data,
template= "simple_white+alphastats_colors"
)

# update coloring
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.6.1"
release = "0.6.2"


# -- General configuration ---------------------------------------------------
Expand Down
15 changes: 14 additions & 1 deletion nbs/getting_started.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "63ea0375-2937-4689-b1c9-f2186776b329",
"metadata": {},
Expand Down Expand Up @@ -329,6 +330,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "ebcf20a2-458d-480b-8a76-4d38c98aa1a2",
"metadata": {},
Expand Down Expand Up @@ -618,6 +620,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "1b2da0df-dd79-429f-815e-cea5228790dd",
"metadata": {},
Expand Down Expand Up @@ -648,6 +651,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "71235990-e4bc-491f-8828-8f9445dcac3b",
"metadata": {},
Expand Down Expand Up @@ -681,6 +685,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "aefc5fe7-0f97-42d5-acb6-d9a151320627",
"metadata": {},
Expand Down Expand Up @@ -716,6 +721,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "e0efd5a2-22cf-4504-9ce8-0490a7967e92",
"metadata": {},
Expand All @@ -725,6 +731,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "b8244053-e920-447d-a405-7049507733a9",
"metadata": {},
Expand All @@ -751,6 +758,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "1cd24307-cd84-411b-8c3c-dccc3be08dbc",
"metadata": {},
Expand Down Expand Up @@ -787,6 +795,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "bc027a63-318a-475d-a04e-7e27002e2ee2",
"metadata": {},
Expand All @@ -813,6 +822,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "51c7655f-9bb7-4473-be47-563e8ced0e98",
"metadata": {},
Expand Down Expand Up @@ -848,6 +858,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "d4d74bd7-3937-4155-965c-302c7a7795c4",
"metadata": {},
Expand All @@ -874,6 +885,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "4357b5ee-e208-4992-9f52-60ec5eb73758",
"metadata": {},
Expand Down Expand Up @@ -914,6 +926,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "7bdf8679-0451-4f2f-b041-637d134c7ea2",
"metadata": {},
Expand Down Expand Up @@ -958,7 +971,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
"version": "3.9.13"
},
"vscode": {
"interpreter": {
Expand Down
Loading

0 comments on commit be87721

Please sign in to comment.