From 883425cb25ce36f83ce005f2898f1962fb02bb5f Mon Sep 17 00:00:00 2001 From: mbuttner Date: Tue, 9 Aug 2022 16:36:46 +0200 Subject: [PATCH 1/7] :fire: move plotdata function to plotting --- pytometry/preprocessing/__init__.py | 8 +-- pytometry/preprocessing/_process_data.py | 80 ------------------------ 2 files changed, 1 insertion(+), 87 deletions(-) diff --git a/pytometry/preprocessing/__init__.py b/pytometry/preprocessing/__init__.py index 47c2f29..e46b47a 100644 --- a/pytometry/preprocessing/__init__.py +++ b/pytometry/preprocessing/__init__.py @@ -1,7 +1 @@ -from ._process_data import ( - compensate, - create_comp_mat, - find_indexes, - plotdata, - split_signal, -) +from ._process_data import compensate, create_comp_mat, find_indexes, split_signal diff --git a/pytometry/preprocessing/_process_data.py b/pytometry/preprocessing/_process_data.py index df454ac..a63c155 100644 --- a/pytometry/preprocessing/_process_data.py +++ b/pytometry/preprocessing/_process_data.py @@ -3,12 +3,7 @@ import numpy as np import pandas as pd -import seaborn as sb from anndata import AnnData -from matplotlib import pyplot as plt -from matplotlib import rcParams - -from ..tools import normalize_arcsinh # import getpass # import os.path @@ -249,78 +244,3 @@ def split_signal( adata._inplace_subset_var(indx) return None if inplace else adata - - -# TODO: move function to plotting module -# Plot data. Choose between Area, Height both(default) -def plotdata( - adata: AnnData, - key="signal_type", - normalize=False, - cofactor=10, - figsize=(15, 6), - option="area", - save="", - **kwargs, -): - """Creating histogram plot from Anndata object. - - :param adata: AnnData object containing data. - :param cofactor: float value to normalize with in arcsinh-transform - :param option: Switch to choose directly between area and height data. - :param save: Filename to save the shown figure - :param kwargs: Passed to :func:`matplotlib.pyplot.savefig` - """ - option_key = option - key_in = key - adata_ = adata.copy() - - # Check if indices for area and height have been computed - if key_in not in adata_.var_keys(): - find_indexes(adata_) - - if normalize: - normalize_arcsinh(adata_, cofactor) - - if option_key not in ["area", "height", "other"]: - print(f"Option {option_key} is not a valid category. Return all.") - datax = adata_.X - var_names = adata_.var_names.values - else: - index = adata_.var[key_in] == option_key - datax = adata_.X[:, index] - var_names = adata_.var_names[index].values - - if len(var_names) == 0: - print( - f"Option {option_key} led to the selection of 0 variables. " - " Nothing to plot." - ) - return - - rcParams["figure.figsize"] = figsize - - names = var_names - number = len(names) - - columns = 3 - rows = np.ceil(number / columns) - - fig = plt.figure() - fig.subplots_adjust(hspace=0.4, wspace=0.6) - - for idx in range(number): - ax = fig.add_subplot(rows, columns, idx + 1) - sb.distplot( - datax[:, names == names[idx]], - kde=False, - norm_hist=False, - bins=400, - ax=ax, - axlabel=names[idx], - ) - if save != "": - plt.savefig(save, bbox_inches="tight", **kwargs) - plt.show() - - return From c8a552b449a02122d6494edff1ebbc9a2dddb071 Mon Sep 17 00:00:00 2001 From: mbuttner Date: Tue, 9 Aug 2022 16:39:38 +0200 Subject: [PATCH 2/7] :sparkles: add plotting module --- pytometry/plotting/__init__.py | 1 + pytometry/plotting/_histogram.py | 93 ++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 pytometry/plotting/__init__.py create mode 100644 pytometry/plotting/_histogram.py diff --git a/pytometry/plotting/__init__.py b/pytometry/plotting/__init__.py new file mode 100644 index 0000000..af1e536 --- /dev/null +++ b/pytometry/plotting/__init__.py @@ -0,0 +1 @@ +from ._histogram import plotdata diff --git a/pytometry/plotting/_histogram.py b/pytometry/plotting/_histogram.py new file mode 100644 index 0000000..483d5bf --- /dev/null +++ b/pytometry/plotting/_histogram.py @@ -0,0 +1,93 @@ +import numpy as np +import seaborn as sns +from anndata import AnnData +from matplotlib import pyplot as plt +from matplotlib import rcParams + +from ..preprocessing._process_data import find_indexes +from ..tools._normalization import normalize_arcsinh, normalize_biExp, normalize_logicle + + +# Plot data. Choose between Area, Height both(default) +def plotdata( + adata: AnnData, + key="signal_type", + normalize: str = None, + cofactor=10, + figsize=(15, 6), + option="area", + save="", + **kwargs, +): + """Creating histogram plot from Anndata object. + + :param adata: AnnData object containing data. + :param cofactor: float value to normalize with in arcsinh-transform + :param normalize: choose between "arcsinh", "biExp" and "logicle" + :param option: Switch to choose directly between area and height data. + :param save: Filename to save the shown figure + :param kwargs: Passed to :func:`matplotlib.pyplot.savefig` + """ + option_key = option + key_in = key + adata_ = adata.copy() + + # Check if indices for area and height have been computed + if key_in not in adata_.var_keys(): + find_indexes(adata_) + + if normalize is not None: + if normalize.lower().count("arcsinh") > 0: + normalize_arcsinh(adata_, cofactor) + elif normalize.lower().count("biexp") > 0: + normalize_biExp(adata_) + elif normalize.lower().count("logicle") > 0: + normalize_logicle(adata_) + else: + print( + f"{normalize} is not a valid normalization type. Continue without" + " normalization." + ) + + if option_key not in ["area", "height", "other"]: + print(f"Option {option_key} is not a valid category. Return all.") + datax = adata_.X + var_names = adata_.var_names.values + else: + index = adata_.var[key_in] == option_key + datax = adata_.X[:, index] + var_names = adata_.var_names[index].values + + if len(var_names) == 0: + print( + f"Option {option_key} led to the selection of 0 variables. " + " Nothing to plot." + ) + return + + rcParams["figure.figsize"] = figsize + + names = var_names + number = len(names) + + columns = 3 + rows = np.ceil(number / columns) + + fig = plt.figure() + fig.subplots_adjust(hspace=0.4, wspace=0.6) + + for idx in range(number): + ax = fig.add_subplot(rows, columns, idx + 1) + sns.distplot( + datax[:, names == names[idx]], + kde=False, + norm_hist=False, + bins=400, + ax=ax, + axlabel=names[idx], + ) + if save != "": + plt.savefig(save, bbox_inches="tight", **kwargs) + plt.show() + + return From 606e8f20d2dd94149fbec1cdd181ace0da1b62e0 Mon Sep 17 00:00:00 2001 From: mbuttner Date: Tue, 9 Aug 2022 16:40:37 +0200 Subject: [PATCH 3/7] :art: add plotting to init --- pytometry/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pytometry/__init__.py b/pytometry/__init__.py index 34d675f..aa957ee 100644 --- a/pytometry/__init__.py +++ b/pytometry/__init__.py @@ -20,8 +20,9 @@ """ -__version__ = "0.0.1" # denote a pre-release for 0.1.0 with 0.1a1 +__version__ = "0.1a1" # denote a pre-release for 0.1.0 with 0.1a1 +from . import plotting as pl from . import preprocessing as pp from . import read_write as io from . import tools as tl From a8e220e95792c2725574e704eea058fd66688432 Mon Sep 17 00:00:00 2001 From: mbuttner Date: Tue, 9 Aug 2022 16:52:50 +0200 Subject: [PATCH 4/7] :art: change version --- pytometry/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytometry/__init__.py b/pytometry/__init__.py index aa957ee..144601b 100644 --- a/pytometry/__init__.py +++ b/pytometry/__init__.py @@ -20,7 +20,7 @@ """ -__version__ = "0.1a1" # denote a pre-release for 0.1.0 with 0.1a1 +__version__ = "0.1.0" # denote a pre-release for 0.1.0 with 0.1a1 from . import plotting as pl from . import preprocessing as pp From 6f84c0613aa4c7035297d95b1f2cca4b04365dd8 Mon Sep 17 00:00:00 2001 From: mbuttner Date: Tue, 9 Aug 2022 16:56:21 +0200 Subject: [PATCH 5/7] :page_facing_up: adapt license --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index b09cd78..56662a7 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ Apache License same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright [yyyy] [name of copyright owner] + Copyright [2022] [Maren Buettner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. From 3ce958e302c1d95b4b4f9451c2ad113286714563 Mon Sep 17 00:00:00 2001 From: mbuttner Date: Tue, 9 Aug 2022 17:04:53 +0200 Subject: [PATCH 6/7] :lipstick: add to quickstart --- docs/tutorials/quickstart.ipynb | 56 +++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/docs/tutorials/quickstart.ipynb b/docs/tutorials/quickstart.ipynb index 4d5c6e4..f9d2a2c 100644 --- a/docs/tutorials/quickstart.ipynb +++ b/docs/tutorials/quickstart.ipynb @@ -58,6 +58,56 @@ "assert isinstance(adata, anndata._core.anndata.AnnData)" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "ef471352", + "metadata": {}, + "outputs": [], + "source": [ + "pm.pp.split_signal(adata)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5d94e857", + "metadata": {}, + "outputs": [], + "source": [ + "pm.pp.compensate(adata)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ac74dd0e", + "metadata": {}, + "outputs": [], + "source": [ + "adata_arcsinh = pm.tl.normalize_arcsinh(adata, inplace=False)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4a6efc35", + "metadata": {}, + "outputs": [], + "source": [ + "adata_biexp = pm.tl.normalize_biExp(adata, inplace=False)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "828cf9c1", + "metadata": {}, + "outputs": [], + "source": [ + "adata_logicle = pm.tl.normalize_logicle(adata, inplace=False)" + ] + }, { "cell_type": "markdown", "id": "995de332", @@ -79,7 +129,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3.9.13 64-bit", + "display_name": "Python 3.9.7 ('pyto_dev')", "language": "python", "name": "python3" }, @@ -93,11 +143,11 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.9.7" }, "vscode": { "interpreter": { - "hash": "b0fa6594d8f4cbf19f97940f81e996739fb7646882a419484c72d19e05852a7e" + "hash": "48c3c4927e81daf79217bae0bb1c93e3ab00a11990990ff2e155253980f357b0" } } }, From dd53ad788e062ded955c8a63adce140e02f4a8b2 Mon Sep 17 00:00:00 2001 From: mbuttner Date: Tue, 9 Aug 2022 17:09:28 +0200 Subject: [PATCH 7/7] :bug: fix quickstart --- docs/tutorials/quickstart.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/tutorials/quickstart.ipynb b/docs/tutorials/quickstart.ipynb index f9d2a2c..4067e8c 100644 --- a/docs/tutorials/quickstart.ipynb +++ b/docs/tutorials/quickstart.ipynb @@ -85,7 +85,7 @@ "metadata": {}, "outputs": [], "source": [ - "adata_arcsinh = pm.tl.normalize_arcsinh(adata, inplace=False)" + "adata_arcsinh = pm.tl.normalize_arcsinh(adata, cofactor=150, inplace=False)" ] }, {