3333 help = "list of modalities to search for UMAPs in" )
3434args , opt = parser .parse_known_args ()
3535
36- L .info ("running with:" )
3736L .info (args )
3837# args = argparse.Namespace(infile='mdata_clustered.h5mu', figdir=None)
3938# ---------
@@ -42,11 +41,11 @@ def main(adata,figdir):
4241 # get all possible umap coords
4342 pattern = "X_umap(.*)"
4443 obsm_keys = [x for x in adata .obsm .keys () if re .search (pattern , x )]
45- L .info ("Umap keys founds %s" % obsm_keys )
46- # get all possible clustersclusters
44+ L .info ("UMAP keys found: %s" % obsm_keys )
45+ # get all possible clusters
4746 pattern = re .compile (r'^leiden|^louvain' )
4847 cluster_keys = [x for x in adata .obs .columns if re .search (pattern , x )]
49- L .info ("Cluster keys founds %s" % cluster_keys )
48+ L .info ("Cluster keys found: %s" % cluster_keys )
5049 if len (obsm_keys ) == 0 or len (cluster_keys ) == 0 :
5150 return
5251
@@ -55,22 +54,24 @@ def main(adata,figdir):
5554 adata .obs [ck ] = adata .obs [ck ].astype ('category' )
5655 # plot all the umaps
5756 for ok in obsm_keys :
57+ L .info ("Plotting UMAP on %s coloured by %s" % (ok , cluster_keys ))
5858 fig = sc .pl .embedding (adata , basis = ok ,color = cluster_keys ,
5959 show = False , return_fig = True , legend_loc = 'on data' )
6060 for ax in fig .axes :
6161 ax .set (xlabel = "UMAP_1" , ylabel = "UMAP_2" )
6262 fig .suptitle (ok , y = 1.0 )
63+ L .info ("Saving figure to '%s'" % os .path .join (figdir , ok + "_clusters.png" ))
6364 fig .savefig (os .path .join (figdir , ok + "_clusters.png" ))
6465
6566def plot_spatial (adata ,figdir ):
6667 # get all possible umap coords
6768 pattern = "spatial(.*)"
6869 obsm_keys = [x for x in adata .obsm .keys () if re .search (pattern , x )]
69- L .info ("Umap keys founds %s" % obsm_keys )
70+ L .info ("UMAP keys found: %s" % obsm_keys )
7071 # get all possible clustersclusters
7172 pattern = re .compile (r'^leiden|^louvain' )
7273 cluster_keys = [x for x in adata .obs .columns if re .search (pattern , x )]
73- L .info ("Cluster keys founds %s" % cluster_keys )
74+ L .info ("Cluster keys found: %s" % cluster_keys )
7475 if len (obsm_keys ) == 0 or len (cluster_keys ) == 0 :
7576 return
7677
@@ -79,15 +80,18 @@ def plot_spatial(adata,figdir):
7980 adata .obs [ck ] = adata .obs [ck ].astype ('category' )
8081 # plot all the umaps
8182 for ok in obsm_keys :
83+ L .info ("Plotting UMAP on %s coloured by %s" % (ok , cluster_keys ))
8284 fig = sc .pl .embedding (adata , basis = ok ,color = cluster_keys ,
8385 show = False , return_fig = True , legend_loc = 'on data' )
8486 for ax in fig .axes :
8587 ax .set (xlabel = "spatial1" , ylabel = "spatial2" )
8688 fig .suptitle (ok , y = 1.0 )
89+ L .info ("Saving figure to '%s'" % os .path .join (figdir , ok + "_clusters.png" ))
8790 fig .savefig (os .path .join (figdir , ok + "_clusters.png" ))
8891
8992
90- L .debug ("load data" )
93+
94+ L .info ("Reading in MuData from '%s'" % args .infile )
9195mdata = read (args .infile )
9296
9397mods = args .modalities .split (',' )
@@ -97,14 +101,15 @@ def plot_spatial(adata,figdir):
97101if 'multimodal' in mods :
98102 if os .path .exists ("multimodal/figures" ) is False :
99103 os .makedirs ("multimodal/figures" )
104+ L .info ("Plotting multimodal figures" )
100105 main (mdata , figdir = "multimodal/figures" )
101106
102107
103108# we also need to plot per modality
104109if type (mdata ) is MuData :
105110 for mod in mdata .mod .keys ():
106111 if mod in mods :
107- L .info ("plotting for modality: %s" % mod )
112+ L .info ("Plotting for modality: %s" % mod )
108113 figdir = os .path .join (mod , "figures" )
109114 if os .path .exists (figdir ) is False :
110115 os .makedirs (figdir )
@@ -115,6 +120,4 @@ def plot_spatial(adata,figdir):
115120
116121
117122
118-
119-
120- L .info ('done' )
123+ L .info ('Done' )
0 commit comments