Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre-filter batches in hvg overlap metric #9

Merged
merged 6 commits into from
Nov 8, 2024
Merged
Changes from 1 commit
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
Next Next commit
Pre-filter batches in hvg overlap metric
Remove those with insufficient genes before running the scoring function
  • Loading branch information
lazappi committed Nov 8, 2024
commit bcc302b517182bac98d8f936651256348a95576f
17 changes: 17 additions & 0 deletions src/metrics/hvg_overlap/script.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import sys
import anndata as ad
import numpy as np
import scanpy as sc
from scib.metrics import hvg_overlap
from scib.utils import split_batches

## VIASH START
par = {
Expand Down Expand Up @@ -36,6 +39,20 @@
print("Copy batch information", flush=True)
adata_integrated.obs['batch'] = adata_solution.obs['batch']

print("Remove batches with insufficient genes", flush=True)
adata_list = split_batches(adata_solution, "batch", hvg=adata_integrated.var_names)
skip_batches = []
for adata_batch in adata_list:
sc.pp.filter_genes(adata_batch, min_cells=1)
n_hvg_tmp = np.minimum(500, int(0.5 * adata_batch.n_vars))
if n_hvg_tmp < 500:
batch = adata_batch.obs["batch"][0]
print(f"Batch '{batch}' has insufficient genes (0.5 * {adata_batch.n_vars} < 500) and will be skipped", flush=True)
skip_batches.append(batch)

adata_solution = adata_solution[~adata_solution.obs['batch'].isin(skip_batches)]
adata_integrated = adata_integrated[~adata_integrated.obs['batch'].isin(skip_batches)]

print('Compute score', flush=True)
score = hvg_overlap(
adata_solution,
Expand Down