Skip to content

Commit

Permalink
Update preprocess.py
Browse files Browse the repository at this point in the history
  • Loading branch information
YazdanZ authored Jan 22, 2024
1 parent 6a8592a commit 8fee09a
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/preprocessing/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,21 @@ def preprocess(cfg: ConfigParser) -> None:
anndata.obs["barcodes"] = anndata.obs.index
anndata.obs["celltype"] = anndata.obs["barcodes"].map(annotation_dict)

canndata = anndata.copy()

# identify highly variable genes
sc.pp.log1p(anndata) # logarithmize the data
sc.pp.log1p(canndata) # logarithmize the data
sc.pp.highly_variable_genes(
anndata, n_top_genes=int(cfg.get("Preprocessing", "highly variable number"))
canndata, n_top_genes=int(cfg.get("Preprocessing", "highly variable number"))
)

if issparse(anndata.X):
anndata.X = np.exp(anndata.X.toarray()) - 1 # get back original data
if issparse(canndata.X):
canndata.X = np.exp(canndata.X.toarray()) - 1 # get back original data
else:
anndata.X = np.exp(anndata.X) - 1 # get back original data
canndata.X = np.exp(canndata.X) - 1 # get back original data

anndata = anndata[
:, anndata.var["highly_variable"]
:, canndata.var["highly_variable"]
] # only keep highly variable genes

# sort genes by name (not needed)
Expand Down

0 comments on commit 8fee09a

Please sign in to comment.