Skip to content

Commit

Permalink
Changed normalization to weights (1=n)
Browse files Browse the repository at this point in the history
  • Loading branch information
szabogtamas authored and grst committed Mar 28, 2020
1 parent db501c8 commit 0875529
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion scirpy/_tools/_group_abundance.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def _group_abundance(

# normalize to fractions
scale_vector = _normalize_counts(tcr_obs, normalize=fraction, default_col=groupby)
tcr_obs = tcr_obs.assign(count=1, weight=1 / scale_vector)
tcr_obs = tcr_obs.assign(count=1, weight=scale_vector)

# Calculate distribution of lengths in each group. Use sum instead of count
# to reflect weights
Expand Down
4 changes: 2 additions & 2 deletions scirpy/_tools/_vdj_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ def vdj_usage(
"""

if fraction is None:
fraction = 1 / _normalize_counts(adata.obs, normalize=False)
fraction = _normalize_counts(adata.obs, normalize=False)
else:
if isinstance(fraction, (bool, str)):
fraction = 1 / _normalize_counts(adata.obs, normalize=fraction)
fraction = _normalize_counts(adata.obs, normalize=fraction)

observations = adata.obs.loc[:, target_cols]
observations[size_column] = fraction
Expand Down
2 changes: 1 addition & 1 deletion scirpy/_util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def _normalize_counts(
raise ValueError("No colname specified in either `normalize` or `default_col")

# https://stackoverflow.com/questions/29791785/python-pandas-add-a-column-to-my-dataframe-that-counts-a-variable
return obs.groupby(normalize_col)[normalize_col].transform("count").values
return 1 / obs.groupby(normalize_col)[normalize_col].transform("count").values


def _get_from_uns(adata: AnnData, tool: str, *, parameters: dict = None) -> Any:
Expand Down

0 comments on commit 0875529

Please sign in to comment.