ctheodoris commited on
Commit
eb2a04b
1 Parent(s): ace12e9

add random state to umap

Browse files
Files changed (1) hide show
  1. geneformer/emb_extractor.py +3 -3
geneformer/emb_extractor.py CHANGED
@@ -272,7 +272,7 @@ def label_gene_embs(embs, downsampled_data, token_gene_dict):
272
  return embs_df
273
 
274
 
275
- def plot_umap(embs_df, emb_dims, label, output_file, kwargs_dict):
276
  only_embs_df = embs_df.iloc[:, :emb_dims]
277
  only_embs_df.index = pd.RangeIndex(0, only_embs_df.shape[0], name=None).astype(str)
278
  only_embs_df.columns = pd.RangeIndex(0, only_embs_df.shape[1], name=None).astype(
@@ -282,8 +282,8 @@ def plot_umap(embs_df, emb_dims, label, output_file, kwargs_dict):
282
  obs_dict = {"cell_id": list(only_embs_df.index), f"{label}": list(embs_df[label])}
283
  adata = anndata.AnnData(X=only_embs_df, obs=obs_dict, var=vars_dict)
284
  sc.tl.pca(adata, svd_solver="arpack")
285
- sc.pp.neighbors(adata)
286
- sc.tl.umap(adata)
287
  sns.set(rc={"figure.figsize": (10, 10)}, font_scale=2.3)
288
  sns.set_style("white")
289
  default_kwargs_dict = {"palette": "Set2", "size": 200}
 
272
  return embs_df
273
 
274
 
275
+ def plot_umap(embs_df, emb_dims, label, output_file, kwargs_dict, seed=0):
276
  only_embs_df = embs_df.iloc[:, :emb_dims]
277
  only_embs_df.index = pd.RangeIndex(0, only_embs_df.shape[0], name=None).astype(str)
278
  only_embs_df.columns = pd.RangeIndex(0, only_embs_df.shape[1], name=None).astype(
 
282
  obs_dict = {"cell_id": list(only_embs_df.index), f"{label}": list(embs_df[label])}
283
  adata = anndata.AnnData(X=only_embs_df, obs=obs_dict, var=vars_dict)
284
  sc.tl.pca(adata, svd_solver="arpack")
285
+ sc.pp.neighbors(adata, random_state=seed)
286
+ sc.tl.umap(adata, random_state=seed)
287
  sns.set(rc={"figure.figsize": (10, 10)}, font_scale=2.3)
288
  sns.set_style("white")
289
  default_kwargs_dict = {"palette": "Set2", "size": 200}