Open Tang-YH opened 1 year ago
Please try providing the array as [n_obs, 1] rather than [n_obs].
Thanks! Though I just encountered another error after I expanded the dimensions:
File "./python3.10/site-packages/torch/distributions/gamma.py", line 57, in expand
new.concentration = self.concentration.expand(batch_shape)
RuntimeError: The expanded size of the tensor (1) must match the existing size (11712) at non-singleton dimension 0. Target sizes: [1, 1]. Tensor sizes: [11712, 1]
Trace Shapes:
Param Sites:
Sample Sites:
m_g_mean dist | 1 1
value | 1 1
m_g_alpha_e_inv dist | 1 1
value | 1 1
m_g dist | 1 13597
value | 1 13597
n_s_cells_per_location dist 11712 1 |
value 11712 1 |
b_s_groups_per_location dist 11712 1 |
value 11712 1 |
z_sr_groups_factors dist 11712 50 |
value 11712 50 |
k_r_factors_per_groups dist | 50 1
value | 50 1
x_fr_group2fact dist | 50 9
value | 50 9
w_sf dist 11712 9 |
value 11712 9 |
Ok, this is unexpected. Let me check what's going on next week.
In general, providing this information has only a limited effect in our experience. It's useful for interpreting the cell abundance results though.
Dear Vitalii, dear Tang-YH, I have encountered exactly the same error and as my cell density varies on my samples I would like to try out to input the number of cell per spot recovered by segmentation.
Here is how I prepare my model, by following #103 issue for data format of segmentation prior :
# prepare anndata for cell2location model
cell2location.models.Cell2location.setup_anndata(adata=spatial)
# segmentation prior
seg_prior= np.array(spatial.obs["Nuclei_count"])+0.1 #add pseudocount
seg_prior=seg_prior.reshape(seg_prior.shape[0],1)
seg_prior = seg_prior.astype('float32')
print(seg_prior.shape)
print(seg_prior.dtype)
# create and train the model
mod = cell2location.models.Cell2location(
spatial, cell_state_df=inf_aver,
# the expected average cell abundance: tissue-dependent
# hyper-prior which can be estimated from paired histology:
N_cells_per_location=seg_prior,
# hyperparameter controlling normalisation of
# within-experiment variation in RNA detection:
detection_alpha=20
)
And here is the same error :
RuntimeError: The expanded size of the tensor (1) must match the existing size (2129) at non-singleton dimension 0. Target sizes: [1, 1]. Tensor sizes: [2129, 1]
Trace Shapes:
Param Sites:
Sample Sites:
m_g_mean dist | 1 1
value | 1 1
m_g_alpha_e_inv dist | 1 1
value | 1 1
m_g dist | 1 17817
value | 1 17817
n_s_cells_per_location dist 2129 1 |
value 2129 1 |
b_s_groups_per_location dist 2129 1 |
value 2129 1 |
z_sr_groups_factors dist 2129 50 |
value 2129 50 |
k_r_factors_per_groups dist | 50 1
value | 50 1
x_fr_group2fact dist | 50 18
value | 50 18
w_sf dist 2129 18 |
value 2129 18 |
Have you been able to investigate on the issue or troubleshoot it already ?
Thanks a lot for your help and the great tool !
Best
Hi Vitalii,
I met an error after I specified an array as the prior estimate of cell abundances per spot. The model seems to try to match the number of spots with 50 (what if I understood correctly is the default number of groups of cell types), and returns an error when they don't match.
I specified the parameter
N_cells_per_location
as the array of cell segmentation label counts, which is a numpy array of length 11712, the same as the total number of spots. The code works if I replace the cell abundance estimate with a single number.Is there a different way of providing the by spot cell abundance estimates?
Thank you! Yiheng