Skip to content

Commit

Permalink
Logging data before finding high var genes when flavor != seurat_v3
Browse files Browse the repository at this point in the history
  • Loading branch information
euxhenh committed Apr 24, 2022
1 parent 9b34260 commit 80be4d6
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions controller/preprocessing_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,30 @@ def run_prep(
raise UserError(
"Less than 2 features remained. Try softer constraints.")

# if chvar is not None and chvar:
# if hvf != 'seurat_v3' and (clog is None or not clog):
# raise UserError(
# "For all flavors other than `seurat_v3` data must be "
# "log-transformed. Please check `Log1p`."
# )

def _normalize_and_log(adata):
nonlocal nt
if cnt is not None and cnt:
if nt == "":
nt = None
sc.pp.normalize_total(adata, target_sum=nt, max_fraction=nmax)
if clog is not None and clog:
if adata.X.min() < 0:
raise UserError(
"Data contains negative values. "
"Is the data logged already?")
sc.pp.log1p(adata)

# If not seurat_v3, log-transform the data before finding high var genes
if hvf != 'seurat_v3':
_normalize_and_log(adata)

if chvar is not None and chvar:
if hvdmax == 'inf':
hvdmax = np.Inf
Expand All @@ -182,15 +206,9 @@ def run_prep(
"Less than 2 features remained. Try softer constraints.")
adata = adata[:, adata.var.highly_variable]

if cnt is not None and cnt:
if nt == "":
nt = None
sc.pp.normalize_total(adata, target_sum=nt, max_fraction=nmax)
if clog is not None and clog:
if adata.X.min() < 0:
raise UserError(
"Data contains negative values. Is the data logged already?")
sc.pp.log1p(adata)
# If seurat_v3, log-transform the data after finding high var genes
if hvf == 'seurat_v3':
_normalize_and_log(adata)

if cscale is not None and cscale:
if smax == "":
Expand Down

0 comments on commit 80be4d6

Please sign in to comment.