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
12 changes: 7 additions & 5 deletions pytometry/plotting/_histogram.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Tuple

import numpy as np
import seaborn as sns
from anndata import AnnData
Expand All @@ -11,12 +13,12 @@
# Plot data. Choose between Area, Height both(default)
def plotdata(
adata: AnnData,
key="signal_type",
key: str = "signal_type",
normalize: str = None,
cofactor=10,
figsize=(15, 6),
option="area",
save="",
cofactor: float = 10,
figsize: Tuple[float, float] = (15, 6),
option: str = "area",
save: str = "",
**kwargs,
):
"""Creating histogram plot from Anndata object.
Expand Down
28 changes: 16 additions & 12 deletions pytometry/plotting/_scatter_density.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
from typing import List, Optional, Union

import datashader as ds
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import scanpy as sc
from anndata import AnnData
from datashader.mpl_ext import dsshow
from matplotlib.axes import Axes
from matplotlib.colors import Colormap


def scatter_density(
adata: AnnData,
x="FSC-A",
y="SSC-A",
x_label="FSC-A",
y_label="SSC-A",
x_scale="linear",
y_scale="linear",
x_lim=[-2 * 1e4, 3 * 1e5],
y_lim=[-2 * 1e4, 3 * 1e5],
ax=None,
cmap="jet",
vmin=None,
vmax=None,
x: str = "FSC-A",
y: str = "SSC-A",
x_label: str = "FSC-A",
y_label: str = "SSC-A",
x_scale: str = "linear",
y_scale: str = "linear",
x_lim: List[float] = [-2 * 1e4, 3 * 1e5],
y_lim: List[float] = [-2 * 1e4, 3 * 1e5],
ax: Optional[Axes] = None,
cmap: Union[str, List, Colormap] = "jet",
vmin: Optional[float] = None,
vmax: Optional[float] = None,
):
"""Plots the cell density across two adata.obs.

Expand Down
12 changes: 6 additions & 6 deletions pytometry/preprocessing/_process_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def create_comp_mat(spillmat: pd.DataFrame, relevant_data: str = "") -> pd.DataF
def find_indexes(
adata: AnnData,
var_key: str = None,
key_added="signal_type",
data_type="facs",
key_added: str = "signal_type",
data_type: str = "facs",
inplace: bool = True,
) -> Optional[AnnData]:
"""Find channels of interest for computing compensation.
Expand Down Expand Up @@ -186,10 +186,10 @@ def compensate(

def split_signal(
adata: AnnData,
var_key=None,
key="signal_type",
option="area",
data_type="facs",
var_key: Optional[str] = None,
key: str = "signal_type",
option: str = "area",
data_type: str = "facs",
inplace: bool = True,
) -> Optional[AnnData]:
"""Method to filter out height or area data.
Expand Down
27 changes: 9 additions & 18 deletions pytometry/tools/_normalization.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# from typing import Optional

import numpy as np
from anndata import AnnData
from scipy import interpolate
Expand All @@ -26,14 +24,7 @@ def normalize_arcsinh(adata: AnnData, cofactor: float, inplace: bool = True):
return None if inplace else adata


def normalize_logicle(
adata,
t=262144,
m=4.5,
w=0.5,
a=0,
inplace: bool = True,
):
def normalize_logicle(adata, t=262144, m=4.5, w=0.5, a=0, inplace=True):
"""Logicle transformation.

Args:
Expand Down Expand Up @@ -126,7 +117,7 @@ def normalize_logicle(
return None if inplace else adata


def _scale(value, p) -> float:
def _scale(value: float, p: dict) -> float:
"""Scale helper function.

Args:
Expand Down Expand Up @@ -194,7 +185,7 @@ def _scale(value, p) -> float:
return -1


def _solve(b, w) -> float:
def _solve(b: float, w: float) -> float:
"""Helper function for biexponential transformation.

Args:
Expand All @@ -214,7 +205,7 @@ def _solve(b, w) -> float:

# based on RTSAFE from Numerical Recipes 1st Edition
# bracket the root
d_lo = 0
d_lo = 0.0
d_hi = b

# bisection first step
Expand Down Expand Up @@ -269,7 +260,7 @@ def _solve(b, w) -> float:
return -1


def _seriesBiexponential(p, value) -> float:
def _seriesBiexponential(p: dict, value: float) -> float:
"""Helper function to compute biex trafo.

Args:
Expand All @@ -295,7 +286,7 @@ def normalize_biExp(
width=-10.0,
positive=4.418540,
max_value=262144.000029,
inplace: bool = True,
inplace=True,
):
"""Biexponential transformation.

Expand Down Expand Up @@ -491,7 +482,7 @@ def _generate_biex_lut(
return positive, values


def _log_root(b, w) -> float:
def _log_root(b: float, w: float) -> float:
"""Helper function.

Args:
Expand All @@ -502,10 +493,10 @@ def _log_root(b, w) -> float:
float: Solution to interpolation
"""
# Code adopted from FlowKit Python package
x_lo = 0
x_lo = 0.0
x_hi = b
d = (x_lo + x_hi) / 2
dx = abs(int(x_lo - x_hi))
dx = abs(int(x_lo - x_hi)) # type: float
dx_last = dx
fb = -2 * np.log(b) + w * b
f = 2.0 * np.log(d) + w * b + fb
Expand Down