Skip to content
This repository has been archived by the owner on Jan 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #10 from schillerlab/release/0.2.0
Browse files Browse the repository at this point in the history
release/0.2.0
  • Loading branch information
Zethson authored Apr 30, 2021
2 parents 2143e72 + 46fcd21 commit 3caf985
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .cookietemple.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ email: [email protected]
project_name: sc-toolbox
project_short_description: A collection of project templates and useful code snippets
for single-cell data analysis with Scanpy.
version: 0.1.0
version: 0.2.0
license: MIT
4 changes: 2 additions & 2 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name-template: "0.1.0 🌈" # <<COOKIETEMPLE_FORCE_BUMP>>
tag-template: 0.1.0 # <<COOKIETEMPLE_FORCE_BUMP>>
name-template: "0.2.0 🌈" # <<COOKIETEMPLE_FORCE_BUMP>>
tag-template: 0.2.0 # <<COOKIETEMPLE_FORCE_BUMP>>
categories:
- title: "🚀 Features"
labels:
Expand Down
2 changes: 1 addition & 1 deletion cookietemple.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.1.0
current_version = 0.2.0

[bumpversion_files_whitelisted]
init_file = sc_toolbox/__init__.py
Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@
# the built documents.
#
# The short X.Y version.
version = "0.1.0"
version = "0.2.0"
# The full version, including alpha/beta/rc tags.
release = "0.1.0"
release = "0.2.0"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "sc-toolbox"
version = "0.1.0" # <<COOKIETEMPLE_FORCE_BUMP>>
version = "0.2.0" # <<COOKIETEMPLE_FORCE_BUMP>>
description = "A collection of project templates and useful code snippets for single-cell data analysis with Scanpy."
authors = ["Lukas Heumos <[email protected]>"]
license = "MIT"
Expand All @@ -9,7 +9,6 @@ homepage = "https://github.com/schillerlab/sc-toolbox"
repository = "https://github.com/schillerlab/sc-toolbox"
documentation = "https://sc-toolbox.readthedocs.io"
classifiers = [
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
Expand Down
2 changes: 1 addition & 1 deletion sc_toolbox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

__author__ = "Lukas Heumos"
__email__ = "[email protected]"
__version__ = "0.1.0"
__version__ = "0.2.0"

from sc_toolbox.api import plot
from sc_toolbox.api import calc
Expand Down
76 changes: 38 additions & 38 deletions sc_toolbox/api/calc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def generate_expression_table(
return gen_expression_table


def calc_relative_frequencies(adata, group_by: str = "cell_type", xlabel: str = "days", condition: str = "batch"):
def relative_frequencies(adata, group_by: str = "cell_type", xlabel: str = "days", condition: str = "batch"):
"""
Calculates the relative frequencies of conditions grouped by an observation.
Expand Down Expand Up @@ -98,6 +98,43 @@ def calc_relative_frequencies(adata, group_by: str = "cell_type", xlabel: str =
return relative_frequencies


def relative_frequency_per_cluster(adata, group_by: str = "cell_type", xlabel: str = "days", condition=None):
"""
Calculates relative frequencies per cluster
Args:
adata: AnnData object containing the data
group_by: The label to group by for the clusters
xlabel: x-axis label
condition: condition to combine by
Returns:
Pandas DataFrame of relative frequencies
"""
frequencies = adata.obs.groupby([group_by, xlabel]).size()
celltypes = np.unique(adata.obs[group_by])
ind = adata.obs[xlabel].cat.categories

relative_frequencies = [frequencies[ident] / sum(frequencies[ident]) for ident in celltypes]
relative_frequencies = pd.DataFrame(relative_frequencies, columns=ind, index=celltypes).fillna(0)

cell_types = {}
combinations = adata.obs.groupby([group_by, xlabel]).groups.keys()

for combination in combinations:
cell_types[combination[0]] = combination[1]
relative_frequencies[group_by] = relative_frequencies.index # type: ignore

# Todo, add for condition
if condition:
combinations = adata.obs.groupby([group_by, condition]).groups.keys()
for combination in combinations:
cell_types[combination[0]] = combination[1]
relative_frequencies[condition] = [cell_types[label] for label in relative_frequencies.index] # type: ignore

return relative_frequencies


def correlate_to_signature(
adata,
marker: pd.DataFrame,
Expand Down Expand Up @@ -178,43 +215,6 @@ def remove_outliers(cords, eps: int = 1, min_samples: int = 2):
return pd.Categorical(cluster, categories=natsorted(np.unique(cluster)))


def calc_relative_frequency_per_cluster(adata, group_by: str = "cell_type", xlabel: str = "days", condition=None):
"""
Calculates relative frequencies per cluster
Args:
adata: AnnData object containing the data
group_by: The label to group by for the clusters
xlabel: x-axis label
condition: condition to combine by
Returns:
Pandas DataFrame of relative frequencies
"""
frequencies = adata.obs.groupby([group_by, xlabel]).size()
celltypes = np.unique(adata.obs[group_by])
ind = adata.obs[xlabel].cat.categories

relative_frequencies = [frequencies[ident] / sum(frequencies[ident]) for ident in celltypes]
relative_frequencies = pd.DataFrame(relative_frequencies, columns=ind, index=celltypes).fillna(0)

cell_types = {}
combinations = adata.obs.groupby([group_by, xlabel]).groups.keys()

for combination in combinations:
cell_types[combination[0]] = combination[1]
relative_frequencies[group_by] = relative_frequencies.index # type: ignore

# Todo, add for condition
if condition:
combinations = adata.obs.groupby([group_by, condition]).groups.keys()
for combination in combinations:
cell_types[combination[0]] = combination[1]
relative_frequencies[condition] = [cell_types[label] for label in relative_frequencies.index] # type: ignore

return relative_frequencies


def add_percentages(adata, table, ids, group_by: str, threshold: int = 0, gene_label: str = "gene"):
"""
Add columns to existing diffxpy table specifying percentage of expressing cells
Expand Down
6 changes: 3 additions & 3 deletions sc_toolbox/api/plot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def average_expression_per_cluster(
)


def avg_expression_split_cluster(
def average_expression_split_cluster(
gene_expression,
genes,
order,
Expand Down Expand Up @@ -328,7 +328,7 @@ def avg_expression_split_cluster(
)


def avg_expression_per_cell(
def average_expression_per_cell(
gene_expression,
genes,
order,
Expand Down Expand Up @@ -923,7 +923,7 @@ def colors_overview(colors: Dict, ncols: int = 2, figsize: Tuple[int, int] = (8,
plt.show()


def rel_frequencies_lineplot(
def relative_frequencies_lineplot(
relative_frequencies: pd.DataFrame,
order,
cluster,
Expand Down
6 changes: 3 additions & 3 deletions sc_toolbox/api/plot/colormaps/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from matplotlib import colors

gray_red = colors.LinearSegmentedColormap.from_list("grouping", ["lightgray", "red", "darkred"], N=128)
gray_violet = colors.LinearSegmentedColormap.from_list("grouping", ["lightgray", "mediumvioletred", "indigo"], N=128)
gray_blue = colors.LinearSegmentedColormap.from_list("grouping", ["lightgray", "cornflowerblue", "darkblue"], N=128)
grey_red = colors.LinearSegmentedColormap.from_list("grouping", ["lightgray", "red", "darkred"], N=128)
grey_violet = colors.LinearSegmentedColormap.from_list("grouping", ["lightgray", "mediumvioletred", "indigo"], N=128)
grey_blue = colors.LinearSegmentedColormap.from_list("grouping", ["lightgray", "cornflowerblue", "darkblue"], N=128)

0 comments on commit 3caf985

Please sign in to comment.