Skip to content

mclust error: Error in dimnames(x) <- dn : length of 'dimnames' [2] not equal to array extent #56

@marcouderzo

Description

@marcouderzo

Hello,
I am running the following code on my Visium HD dataset:

# define model
model = GraphST.GraphST(adata_gd75)

# train model
adata_gd75 = model.train()

# set radius to specify the number of neighbors considered during refinement
radius = 50

tool = 'mclust' # mclust, leiden, and louvain
n_clusters = 30


# clustering
from GraphST.utils import clustering

clustering(adata_gd75, n_clusters, radius=radius, method=tool, refinement=True)

R[write to console]: Error in dimnames(x) <- dn : 
  length of 'dimnames' [2] not equal to array extent

---------------------------------------------------------------------------
RRuntimeError                             Traceback (most recent call last)
Cell In[34], line 12
      9 from GraphST.utils import clustering
     11 if tool == 'mclust':
---> 12    clustering(adata_gd75, n_clusters, radius=radius, method=tool, refinement=True) # For DLPFC dataset, we use optional refinement step.
     13 elif tool in ['leiden', 'louvain']:
     14    clustering(adata_gd75, n_clusters, radius=radius, method=tool, start=1.0, end=2.0, increment=0.1, refinement=False)

File [/opt/conda/envs/GraphST/lib/python3.8/site-packages/GraphST/utils.py:69](https://192.33.153.27/opt/conda/envs/GraphST/lib/python3.8/site-packages/GraphST/utils.py#line=68), in clustering(adata, n_clusters, radius, key, method, start, end, increment, refinement)
     66 adata.obsm['emb_pca'] = embedding
     68 if method == 'mclust':
---> 69    adata = mclust_R(adata, used_obsm='emb_pca', num_cluster=n_clusters)
     70    adata.obs['domain'] = adata.obs['mclust']
     71 elif method == 'leiden':

File [/opt/conda/envs/GraphST/lib/python3.8/site-packages/GraphST/utils.py:25](https://192.33.153.27/opt/conda/envs/GraphST/lib/python3.8/site-packages/GraphST/utils.py#line=24), in mclust_R(adata, num_cluster, modelNames, used_obsm, random_seed)
     22 r_random_seed(random_seed)
     23 rmclust = robjects.r['Mclust']
---> 25 res = rmclust(rpy2.robjects.numpy2ri.numpy2rpy(adata.obsm[used_obsm]), num_cluster, modelNames)
     26 mclust_res = np.array(res[-2])
     28 adata.obs['mclust'] = mclust_res

File [/opt/conda/envs/GraphST/lib/python3.8/site-packages/rpy2/robjects/functions.py:198](https://192.33.153.27/opt/conda/envs/GraphST/lib/python3.8/site-packages/rpy2/robjects/functions.py#line=197), in SignatureTranslatedFunction.__call__(self, *args, **kwargs)
    196         v = kwargs.pop(k)
    197         kwargs[r_k] = v
--> 198 return (super(SignatureTranslatedFunction, self)
    199         .__call__(*args, **kwargs))

File [/opt/conda/envs/GraphST/lib/python3.8/site-packages/rpy2/robjects/functions.py:125](https://192.33.153.27/opt/conda/envs/GraphST/lib/python3.8/site-packages/rpy2/robjects/functions.py#line=124), in Function.__call__(self, *args, **kwargs)
    123     else:
    124         new_kwargs[k] = conversion.py2rpy(v)
--> 125 res = super(Function, self).__call__(*new_args, **new_kwargs)
    126 res = conversion.rpy2py(res)
    127 return res

File [/opt/conda/envs/GraphST/lib/python3.8/site-packages/rpy2/rinterface_lib/conversion.py:45](https://192.33.153.27/opt/conda/envs/GraphST/lib/python3.8/site-packages/rpy2/rinterface_lib/conversion.py#line=44), in _cdata_res_to_rinterface.<locals>._(*args, **kwargs)
     44 def _(*args, **kwargs):
---> 45     cdata = function(*args, **kwargs)
     46     # TODO: test cdata is of the expected CType
     47     return _cdata_to_rinterface(cdata)

File [/opt/conda/envs/GraphST/lib/python3.8/site-packages/rpy2/rinterface.py:677](https://192.33.153.27/opt/conda/envs/GraphST/lib/python3.8/site-packages/rpy2/rinterface.py#line=676), in SexpClosure.__call__(self, *args, **kwargs)
    670     res = rmemory.protect(
    671         openrlib.rlib.R_tryEval(
    672             call_r,
    673             call_context.__sexp__._cdata,
    674             error_occured)
    675     )
    676     if error_occured[0]:
--> 677         raise embedded.RRuntimeError(_rinterface._geterrmessage())
    678 return res

RRuntimeError: Error in dimnames(x) <- dn : 
  length of 'dimnames' [2] not equal to array extent

As a sanity check:

X = adata_gd75.obsm["emb_pca"]

print(type(X))
print(X.shape)
print(X.ndim)
print(X.dtype)

<class 'numpy.ndarray'> 
(46583, 20) 
2 
float32

I don't understand what is happening. Does anyone have a clue why? @longyahui ?

Best,
Marco Uderzo
PhD Student @ Institute of Functional Genomics, Lyon

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions