Skip to content

Commit

Permalink
Merge pull request bedapub#318 from bedapub/pcs_fix_hvg
Browse files Browse the repository at this point in the history
Adjusted HVG with batch selection
  • Loading branch information
swalpe authored Aug 29, 2023
2 parents dd0f732 + 3464927 commit fbe588f
Showing 1 changed file with 6 additions and 2 deletions.
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

0 comments on commit fbe588f

Please sign in to comment.