Hi,
Great package! I tried using it on my data, but I´m running into a RuntimeError when calling train_STAligner.
Unfortunately, I don´t have much knowledge in this area, do you have any ideas where this could stem from?
How would I adjust the parameters ef or M?
after running this line
adata_concat = STAligner.train_STAligner(adata_concat, verbose=True, knn_neigh = 100, margin=1, device=used_device)
Here the full output:
STAligner(
(conv1): GATConv(189, 512, heads=1)
(conv2): GATConv(512, 30, heads=1)
(conv3): GATConv(30, 512, heads=1)
(conv4): GATConv(512, 189, heads=1)
)
Pretrain with STAGATE...
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 500/500 [00:57<00:00, 8.72it/s]
Train with STAligner...
0%| | 0/500 [00:00, ?it/s]
Update spot triplets at epoch 500
20%|██████████████████████▊ | 100/500 [02:44<00:48, 8.28it/s]
Update spot triplets at epoch 600
20%|██████████████████████▊ | 100/500 [04:31<18:05, 2.71s/it]
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
Cell In[17], line 6
1 # Important parameter:
2 # "iter_comb" is used to specify the order of integration
3 # "margin" is used to control the intensity/weight of batch correction
4 #iter_comb = [(0, 3), (1, 3), (2, 3)] ## Fix slice 3 as reference to align
----> 6 adata_concat = STAligner.train_STAligner(adata_concat, verbose=True, knn_neigh = 100,
7 margin=1, device=used_device)
File ~/anaconda3/envs/env_STAligner/lib/python3.8/site-packages/STAligner-1.0.0-py3.8.egg/STAligner/train_STAligner.py:188, in train_STAligner(adata, hidden_dims, n_epochs, lr, key_added, gradient_clipping, weight_decay, margin, verbose, random_seed, iter_comb, knn_neigh, device)
184 adata.obsm['STAGATE'] = z.cpu().detach().numpy()
186 # If knn_neigh>1, points in one slice may have multiple MNN points in another slice.
187 # not all points have MNN achors
--> 188 mnn_dict = create_dictionary_mnn(adata, use_rep='STAGATE', batch_name='batch_name', k=knn_neigh,
189 iter_comb=iter_comb, verbose=0)
191 anchor_ind = []
192 positive_ind = []
File ~/anaconda3/envs/env_STAligner/lib/python3.8/site-packages/STAligner-1.0.0-py3.8.egg/STAligner/mnn_utils.py:45, in create_dictionary_mnn(adata, use_rep, batch_name, k, save_on_disk, approx, verbose, iter_comb)
43 names2 = ref
44 # if k>1,one point in ds1 may have multiple MNN points in ds2.
---> 45 match = mnn(ds1, ds2, names1, names2, knn=k, save_on_disk = save_on_disk, approx = approx)
47 G = nx.Graph()
48 G.add_edges_from(match)
File ~/anaconda3/envs/env_STAligner/lib/python3.8/site-packages/STAligner-1.0.0-py3.8.egg/STAligner/mnn_utils.py:140, in mnn(ds1, ds2, names1, names2, knn, save_on_disk, approx)
136 def mnn(ds1, ds2, names1, names2, knn = 20, save_on_disk = True, approx = True):
137 if approx:
138 # Find nearest neighbors in first direction.
139 # output KNN point for each point in ds1. match1 is a set(): (points in names1, points in names2), the size of the set is ds1.shape[0]*knn
--> 140 match1 = nn_approx(ds1, ds2, names1, names2, knn=knn)#, save_on_disk = save_on_disk)
141 # Find nearest neighbors in second direction.
142 match2 = nn_approx(ds2, ds1, names2, names1, knn=knn)#, save_on_disk = save_on_disk)
File ~/anaconda3/envs/env_STAligner/lib/python3.8/site-packages/STAligner-1.0.0-py3.8.egg/STAligner/mnn_utils.py:89, in nn_approx(ds1, ds2, names1, names2, knn)
87 p.set_ef(10)
88 p.add_items(ds2)
---> 89 ind, distances = p.knn_query(ds1, k=knn)
90 match = set()
91 for a, b in zip(range(ds1.shape[0]), ind):
RuntimeError: Cannot return the results in a contigious 2D array. Probably ef or M is too small
Hi, Great package! I tried using it on my data, but I´m running into a RuntimeError when calling train_STAligner. Unfortunately, I don´t have much knowledge in this area, do you have any ideas where this could stem from? How would I adjust the parameters ef or M?
after running this line
adata_concat = STAligner.train_STAligner(adata_concat, verbose=True, knn_neigh = 100, margin=1, device=used_device)
Here the full output:
STAligner( (conv1): GATConv(189, 512, heads=1) (conv2): GATConv(512, 30, heads=1) (conv3): GATConv(30, 512, heads=1) (conv4): GATConv(512, 189, heads=1) ) Pretrain with STAGATE... 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 500/500 [00:57<00:00, 8.72it/s] Train with STAligner... 0%| | 0/500 [00:00, ?it/s] Update spot triplets at epoch 500 20%|██████████████████████▊ | 100/500 [02:44<00:48, 8.28it/s] Update spot triplets at epoch 600 20%|██████████████████████▊ | 100/500 [04:31<18:05, 2.71s/it] --------------------------------------------------------------------------- RuntimeError Traceback (most recent call last) Cell In[17], line 6 1 # Important parameter: 2 # "iter_comb" is used to specify the order of integration 3 # "margin" is used to control the intensity/weight of batch correction 4 #iter_comb = [(0, 3), (1, 3), (2, 3)] ## Fix slice 3 as reference to align ----> 6 adata_concat = STAligner.train_STAligner(adata_concat, verbose=True, knn_neigh = 100, 7 margin=1, device=used_device) File ~/anaconda3/envs/env_STAligner/lib/python3.8/site-packages/STAligner-1.0.0-py3.8.egg/STAligner/train_STAligner.py:188, in train_STAligner(adata, hidden_dims, n_epochs, lr, key_added, gradient_clipping, weight_decay, margin, verbose, random_seed, iter_comb, knn_neigh, device) 184 adata.obsm['STAGATE'] = z.cpu().detach().numpy() 186 # If knn_neigh>1, points in one slice may have multiple MNN points in another slice. 187 # not all points have MNN achors --> 188 mnn_dict = create_dictionary_mnn(adata, use_rep='STAGATE', batch_name='batch_name', k=knn_neigh, 189 iter_comb=iter_comb, verbose=0) 191 anchor_ind = [] 192 positive_ind = [] File ~/anaconda3/envs/env_STAligner/lib/python3.8/site-packages/STAligner-1.0.0-py3.8.egg/STAligner/mnn_utils.py:45, in create_dictionary_mnn(adata, use_rep, batch_name, k, save_on_disk, approx, verbose, iter_comb) 43 names2 = ref 44 # if k>1,one point in ds1 may have multiple MNN points in ds2. ---> 45 match = mnn(ds1, ds2, names1, names2, knn=k, save_on_disk = save_on_disk, approx = approx) 47 G = nx.Graph() 48 G.add_edges_from(match) File ~/anaconda3/envs/env_STAligner/lib/python3.8/site-packages/STAligner-1.0.0-py3.8.egg/STAligner/mnn_utils.py:140, in mnn(ds1, ds2, names1, names2, knn, save_on_disk, approx) 136 def mnn(ds1, ds2, names1, names2, knn = 20, save_on_disk = True, approx = True): 137 if approx: 138 # Find nearest neighbors in first direction. 139 # output KNN point for each point in ds1. match1 is a set(): (points in names1, points in names2), the size of the set is ds1.shape[0]*knn --> 140 match1 = nn_approx(ds1, ds2, names1, names2, knn=knn)#, save_on_disk = save_on_disk) 141 # Find nearest neighbors in second direction. 142 match2 = nn_approx(ds2, ds1, names2, names1, knn=knn)#, save_on_disk = save_on_disk) File ~/anaconda3/envs/env_STAligner/lib/python3.8/site-packages/STAligner-1.0.0-py3.8.egg/STAligner/mnn_utils.py:89, in nn_approx(ds1, ds2, names1, names2, knn) 87 p.set_ef(10) 88 p.add_items(ds2) ---> 89 ind, distances = p.knn_query(ds1, k=knn) 90 match = set() 91 for a, b in zip(range(ds1.shape[0]), ind): RuntimeError: Cannot return the results in a contigious 2D array. Probably ef or M is too small