Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aggregate_across_cells functon : length of 'groups' should be equal to the number of columns in 'x' #84

Open
xjsun1221 opened this issue Jan 8, 2025 · 1 comment

Comments

@xjsun1221
Copy link

import scranpy
import numpy as np

X = np.random.randint(0, 100, size=(50, 50)).astype(np.float64)

groups = np.random.choice(['A', 'B', 'C'], size=50).astype('U10')
print(X.shape,len(groups))

single_factor_result = scranpy.aggregate_across_cells(
    x=X,          
    factors=groups,  
    num_threads=1
)
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[20], line 2
      1 # 执行聚合
----> 2 single_factor_result = scranpy.aggregate_across_cells(
      3     x=X,          
      4     factors=groups,  
      5     num_threads=1
      6 )

File [~/miniconda3/envs/sc2_clone/lib/python3.11/site-packages/scranpy/aggregate_across_cells.py:106](http://localhost:8888/lab/tree/~/miniconda3/envs/sc2_clone/lib/python3.11/site-packages/scranpy/aggregate_across_cells.py#line=105), in aggregate_across_cells(x, factors, num_threads)
    103 comblev = biocutils.NamedList(comblev, facnames)
    105 mat = mattress.initialize(x)
--> 106 outsum, outdet = lib.aggregate_across_cells(mat.ptr, combind, num_threads)
    108 counts = numpy.zeros(len(comblev[0]), dtype=numpy.uint32)
    109 for i in combind:

RuntimeError: length of 'groups' should be equal to the number of columns in 'x'

but in my data,length of 'groups' is equal to the number of columns in 'x'.

@LTLA
Copy link
Contributor

LTLA commented Jan 8, 2025

It's actually

import scranpy
import numpy as np

X = np.random.randint(0, 100, size=(50, 50)).astype(np.float64)

groups = np.random.choice(['A', 'B', 'C'], size=50).astype('U10')
print(X.shape,len(groups))

single_factor_result = scranpy.aggregate_across_cells(
    x=X,          
    factors=[groups], # could also use a tuple
    num_threads=1
)

as aggregate_across_cells() can take multiple factors. This is discussed more in help(scranpy.combine_factors).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants