fusor.find_initial_pivots AttributeError: 'AnnData' object has no attribute 'mean'
Closed this issue · 3 comments
Hi,
Thank you for the great package and documentation. I am really looking forward to applying this to my own data and testing different data modalities. I have completed the install and CODEX vignette successfully, however, I am running into the error below on my own data. Everything completes successfully up until this point.
I will say that I am converting a Seurat .Rds into AnnData and running the python code. This has worked well for me in the past. I am wondering if you think the issue lies within the arrays being converted or if it is something else I am missing.
sc <- import('scanpy', convert = FALSE)
py$adata <- sc$AnnData(
X = t(as.matrix(GetAssayData(seurat_object, assay = assay, slot='counts'))),
obs = seurat_object[[]],
var = GetAssay(seurat_object)[[]]
)
...process as in maxfuse vingette...
The error:
>>> fusor.find_initial_pivots(
... wt1=0.3, wt2=0.3,
... svd_components1=25, svd_components2=20
... )
Now at batch 0<->0...
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/ldata_fast/python_envs/maxfuse/lib/python3.8/site-packages/maxfuse/model.py", line 619, in find_initial_pivots
arr1 = utils.get_centroids(
File "/ldata_fast/python_envs/maxfuse/lib/python3.8/site-packages/maxfuse/utils.py", line 271, in get_centroids
centroids[curr_label, :] = arr[indices, :].mean(axis=1)
AttributeError: 'AnnData' object has no attribute 'mean'
Additionally, the step prior to investigate the elbow plot this error, if it helps.
>>> fusor.plot_singular_values(
target='shared_arr1',
n_components=None,
)
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/ldata_fast/python_envs/maxfuse/lib/python3.8/site-packages/maxfuse/model.py", line 346, in plot_singular_values
_, s, _ = utils.robust_svd(arr=target, n_components=n_components, randomized=randomized_svd, n_runs=svd_runs)
File "/ldata_fast/python_envs/maxfuse/lib/python3.8/site-packages/maxfuse/utils.py", line 308, in robust_svd
u, s, vh = svds(arr*1.0, k=n_components) # svds can not handle integer values
TypeError: unsupported operand type(s) for *: 'AnnData' and 'float'
update. my first error was not suppling an array to the fusor.plot_singular_values()
function. when I convert to array using
rna_shared = rna_shared.X.copy()
protien_shared = protien_shared.X.copy()
I now get this error:
>>> fusor.find_initial_pivots(
... wt1=0.3, wt2=0.3,
... svd_components1=25, svd_components2=20
... )
Now at batch 0<->0...
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/ldata_fast/python_envs/maxfuse/lib/python3.8/site-packages/maxfuse/model.py", line 639, in find_initial_pivots
match_utils.get_initial_matching(
File "/ldata_fast/python_envs/maxfuse/lib/python3.8/site-packages/maxfuse/match_utils.py", line 179, in get_initial_matching
arr1 = utils.svd_denoise(
File "/ldata_fast/python_envs/maxfuse/lib/python3.8/site-packages/maxfuse/utils.py", line 334, in svd_denoise
u, s, vh = robust_svd(arr, n_components=n_components, randomized=randomized, n_runs=n_runs)
File "/ldata_fast/python_envs/maxfuse/lib/python3.8/site-packages/maxfuse/utils.py", line 308, in robust_svd
u, s, vh = svds(arr*1.0, k=n_components) # svds can not handle integer values
File "/ldata_fast/python_envs/maxfuse/lib/python3.8/site-packages/scipy/sparse/linalg/_eigen/_svds.py", line 447, in svds
args = _iv(A, k, ncv, tol, which, v0, maxiter, return_singular_vectors,
File "/ldata_fast/python_envs/maxfuse/lib/python3.8/site-packages/scipy/sparse/linalg/_eigen/_svds.py", line 49, in _iv
raise ValueError(message)
ValueError: `k` must be an integer satisfying `0 < k < min(A.shape)`.
further update: this was due to my shared array dimensions being less than the input for svd components. This solved my error with this function. I will close. Also, the above conversion from seurat seems to work here, for those interested.
Thanks a lot for your input and interest in our work! We will be happy to answer any further questions.