zhoux85 / STAligner

STAligner is a tool for alignment and integration of spatially resolved transcriptomics data.
MIT License
29 stars 5 forks source link

train_STAligner RuntimeError: Cannot return the results in a contigious 2D array. Probably ef or M is too small #29

Open t-a-m-i opened 1 day ago

t-a-m-i commented 1 day ago

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 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