Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
56 changes: 53 additions & 3 deletions docs/tutorials/quickstart.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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, cofactor=150, 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",
Expand All @@ -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"
},
Expand All @@ -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"
}
}
},
Expand Down
3 changes: 2 additions & 1 deletion pytometry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@

"""

__version__ = "0.0.1" # 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 . import read_write as io
from . import tools as tl
Expand Down
1 change: 1 addition & 0 deletions pytometry/plotting/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from ._histogram import plotdata
93 changes: 93 additions & 0 deletions pytometry/plotting/_histogram.py
Original file line number Diff line number Diff line change
@@ -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
8 changes: 1 addition & 7 deletions pytometry/preprocessing/__init__.py
Original file line number Diff line number Diff line change
@@ -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
80 changes: 0 additions & 80 deletions pytometry/preprocessing/_process_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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