Skip to content

Commit

Permalink
add log info
Browse files Browse the repository at this point in the history
  • Loading branch information
SarahOuologuem committed Apr 9, 2024
1 parent 138853e commit 5a09f00
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
11 changes: 5 additions & 6 deletions panpipes/python_scripts/rerun_find_neighbors_for_clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,19 @@
neighbor_dict = read_yaml(args.neighbor_dict)

sc.settings.n_jobs = int(args.n_threads)
L.info("Running with options: %s", args)

# read data
L.info("reading mudata")
L.info("Reading in MuData from '%s'" % args.infile)
mdata = read(args.infile)



for mod in neighbor_dict.keys():
if neighbor_dict[mod]['use_existing']:
L.info('using existing neighbors graph for %s' % mod)
L.info('Using existing neighbors graph for %s' % mod)
pass
else:
L.info("computing new neighbors for %s" % mod)
L.info("Computing new neighbors for %s" % mod)
if type(mdata) is MuData:
adata=mdata[mod]
if (neighbor_dict[mod]['dim_red'] == "X_pca") and ("X_pca" not in adata.obsm.keys()):
Expand Down Expand Up @@ -82,6 +81,6 @@



L.info("saving data")
L.info("Saving updated MuData to '%s'" % args.outfile)
mdata.write(args.outfile)
L.info("done")
L.info("Done")
10 changes: 9 additions & 1 deletion panpipes/python_scripts/run_clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
L.info(args)

# read data
L.info("Reading in data from '%s'" % args.infile)
mdata = mu.read(args.infile)
if type(mdata) is AnnData:
adata = mdata
Expand All @@ -45,23 +46,30 @@
# check sc.pp.neihgbours has been run
if uns_key not in adata.uns.keys():
# sys.exit("Error: sc.pp.neighbours has not been run on this object")
L.warning("Running neighbors with default parameters since no neighbors graph found in this data object")
sc.pp.neighbors(adata)
uns_key="neighbors"


# run command
if args.algorithm == "louvain":
L.info("Running Louvain clustering")
sc.tl.louvain(adata, resolution=float(args.resolution), key_added='clusters', neighbors_key=uns_key)
elif args.algorithm == "leiden":
L.info("Running Leiden clustering")
sc.tl.leiden(adata, resolution=float(args.resolution), key_added='clusters', neighbors_key=uns_key)
else:
sys.exit("algorithm not found: please specify 'louvain' or 'leiden'")
L.error("Could not find clustering algorithm '%s'. Please specify 'louvain' or 'leiden'" % args.algorithm)
sys.exit("Could not find clustering algorithm '%s'. Please specify 'louvain' or 'leiden'" % args.algorithm)

#mdata.update()
## write out clusters as text file
L.info("Saving cluster column to csv file '%s'" % args.outfile)
clusters = pd.DataFrame(adata.obs['clusters'])
clusters.to_csv(args.outfile, sep='\t')

L.info("Saving cell numbers per cluster to csv file")

tmp = clusters['clusters'].value_counts().to_frame("cell_num").reset_index().rename(columns={"index":"cluster"})
tmp.to_csv(os.path.dirname(args.outfile) + "/cellnum_per_cluster.csv")

Expand Down
5 changes: 4 additions & 1 deletion panpipes/python_scripts/run_umap.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
L.info(args)

# read data
L.info("Reading in data from '%s'" % args.infile)
mdata = mu.read(args.infile)
if type(mdata) is AnnData:
adata = mdata
Expand All @@ -55,7 +56,7 @@
# check sc.pp.neihgbours has been run
if uns_key not in adata.uns.keys():
# sys.exit("Error: sc.pp.neighbours has not been run on this object")
L.warning("running neighbors with default parameters since no neighbors graph found in this data object")
L.warning("Running neighbors with default parameters since no neighbors graph found in this data object")
sc.pp.neighbors(adata)
uns_key="neighbors"

Expand All @@ -68,6 +69,7 @@


# what parameters?
L.info("Running UMAP on neighbors_key %s" % uns_key)
if uns_key =="wnn":
mu.tl.umap(adata, min_dist=float(args.min_dist), neighbors_key=uns_key)
else:
Expand All @@ -81,4 +83,5 @@

# save coordinates to file
# (note this saves values values up to 6 significant figures, because why save 20 for a plot
L.info("Saving UMAP coordinates to csv file '%s'" % args.outfile)
umap_coords.to_csv(args.outfile, sep = '\t')

0 comments on commit 5a09f00

Please sign in to comment.