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

Adjusted HVG with batch selection #311

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 6 additions & 2 deletions besca/st/_wrapper_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def clr_normalize(adata, results_folder):
return adata


def highly_variable_genes(adata, batch_key=None, n_shared=2):
def highly_variable_genes(adata, batch_key=None, n_shared=2, only_shared=False):
"""Calculate highly variable genes and return filtered adata containing only the HVGs.

Parameters
Expand All @@ -320,7 +320,8 @@ def highly_variable_genes(adata, batch_key=None, n_shared=2):
n_shared: `int` | default = 2
requirement for selection of HVGs - HVGs shared in nr_samples/n_shared will be included.
A higher value will result in a less stringent selection, e.g. with 2 HVGs need to be present
in at least 50% of the samples.
in at least 50% of the samples, in addition to the default scanpy behavior.
only_shared: `bool` | default = False

Returns
-------
Expand All @@ -342,6 +343,9 @@ def highly_variable_genes(adata, batch_key=None, n_shared=2):
)
if batch_key is not None:
hvglist = adata.var["highly_variable"].copy()
## Set to False so that default scanpy selection ignored
if only_shared:
hvglist[hvglist==True]=False
hvglist.loc[
adata.var["highly_variable_nbatches"]
>= len(set(adata.obs[batch_key])) / n_shared,
Expand Down
Loading