SpaGCN: Integrating gene expression, spatial location and histology to identify spatial domains and spatially variable genes by graph convolutional network
MIT License
191
stars
59
forks
source link
BaseException: Could not construct partition: vector too long #78
#For this toy data, we set the number of clusters=7
# since this tissue has 15 layers
n_clusters=15
#Set seed
r_seed=t_seed=n_seed=100
#Search for suitable resolution
res=spg.search_res(adata,
adj,
l,
n_clusters,
start=0.3,
step=0.1,
tol=5e-3,
lr=0.05,
max_epochs=20,
r_seed=r_seed,
t_seed=t_seed,
n_seed=n_seed
)
when I run the code above, something wrong.
the wrong message like below
BaseException Traceback (most recent call last)
Cell In[49], line 9
6 r_seed=t_seed=n_seed=100
8 #Search for suitable resolution
----> 9 res=spg.search_res(adata,
10 adj,
11 l,
12 n_clusters,
13 start=0.3,
14 step=0.1,
15 tol=5e-3,
16 lr=0.05,
17 max_epochs=20,
18 r_seed=r_seed,
19 t_seed=t_seed,
20 n_seed=n_seed
21 )
File d:\software\python38\lib\site-packages\SpaGCN\util.py:353, in search_res(adata, adj, l, target_num, start, step, tol, lr, max_epochs, r_seed, t_seed, n_seed, max_run)
351 clf=SpaGCN()
352 clf.set_l(l)
--> 353 clf.train(adata,adj,init_spa=True,init="louvain",res=res, tol=tol, lr=lr, max_epochs=max_epochs)
354 y_pred, _=clf.predict()
355 old_num=len(set(y_pred))
File d:\software\python38\lib\site-packages\SpaGCN\SpaGCN.py:62, in SpaGCN.train(self, adata, adj, num_pcs, lr, max_epochs, weight_decay, opt, init_spa, init, n_neighbors, n_clusters, res, tol)
60 #----------Train model----------
61 self.model=simple_GC_DEC(embed.shape[1],embed.shape[1])
---> 62 self.model.fit(embed,adj_exp,lr=self.lr,max_epochs=self.max_epochs,weight_decay=self.weight_decay,opt=self.opt,init_spa=self.init_spa,init=self.init,n_neighbors=self.n_neighbors,n_clusters=self.n_clusters,res=self.res, tol=self.tol)
63 self.embed=embed
64 self.adj_exp=adj_exp
File d:\software\python38\lib\site-packages\SpaGCN\models.py:69, in simple_GC_DEC.fit(self, X, adj, lr, max_epochs, update_interval, trajectory_interval, weight_decay, opt, init, n_neighbors, res, n_clusters, init_spa, tol)
67 adata=sc.AnnData(X)
68 sc.pp.neighbors(adata, n_neighbors=n_neighbors)
---> 69 sc.tl.louvain(adata,resolution=res)
70 y_pred=adata.obs['louvain'].astype(int).to_numpy()
71 self.n_clusters=len(np.unique(y_pred))
File d:\software\python38\lib\site-packages\scanpy\tools\_louvain.py:151, in louvain(adata, resolution, random_state, restrict_to, key_added, adjacency, flavor, directed, use_weights, partition_type, partition_kwargs, neighbors_key, obsp, copy)
149 partition_kwargs["seed"] = random_state
150 logg.info(' using the "louvain" package of Traag (2017)')
--> 151 part = louvain.find_partition(
152 g,
153 partition_type,
154 **partition_kwargs,
155 )
156 # adata.uns['louvain_quality'] = part.quality()
157 else:
158 part = g.community_multilevel(weights=weights)
File d:\software\python38\lib\site-packages\louvain\functions.py:68, in find_partition(graph, partition_type, initial_membership, weights, seed, **kwargs)
66 if not weights is None:
67 kwargs['weights'] = weights
---> 68 partition = partition_type(graph,
69 initial_membership=initial_membership,
70 **kwargs)
71 optimiser = Optimiser()
73 if (not seed is None):
File d:\software\python38\lib\site-packages\louvain\VertexPartition.py:769, in RBConfigurationVertexPartition.__init__(self, graph, initial_membership, weights, resolution_parameter)
765 else:
766 # Make sure it is a list
767 weights = list(weights)
--> 769 self._partition = _c_louvain._new_RBConfigurationVertexPartition(pygraph_t,
770 initial_membership, weights, resolution_parameter)
771 self._update_internal_membership()
BaseException: Could not construct partition: vector too long
hi, I use my data to test the SpaGCN.
sample type: mouse brain. 10X
when I run the code above, something wrong.
the wrong message like below
need your help as soon as possible.
best wishes~