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

ValueError: Reference must match the number of genes in AnnData. #134

Closed
HZT55 opened this issue Jun 19, 2024 · 3 comments · Fixed by #135
Closed

ValueError: Reference must match the number of genes in AnnData. #134

HZT55 opened this issue Jun 19, 2024 · 3 comments · Fixed by #135
Labels
bug Something isn't working

Comments

@HZT55
Copy link

HZT55 commented Jun 19, 2024

Report

Hi,

I am trying to use infercnvpy directly supply an array of average normal gene expression, but when I run:

cnv.tl.infercnv(
    adata,
    reference = normal_expr,
    window_size=250,
)

I get the error message: Reference must match the number of genes in AnnData.

The normal_expr is generated by the following code:

normal_raw_matrix_sort = normal_raw_matrix.loc[adata.var.index.intersection(normal_raw_matrix.index)]
normal_raw_matrix_sort = normal_raw_matrix_sort.loc[adata.var.index]
normal_expr = normal_raw_matrix_sort.mean(axis=1).values

So the number and order of genes in normal_expr does match the adata.

assert len(normal_expr) == adata.shape[1]
try:
    cnv.tl.infercnv(
        GSE131907_adata,
        reference=normal_expr,
        window_size=250,
    )
except ValueError as e:
    print("Error: ", e)
    print("Shape of normal_expr: ", normal_expr.shape)
    print("Shape of GSE131907_adata: ", GSE131907_adata.shape)`
Error:  Reference must match the number of genes in AnnData. 
Shape of normal_expr:  (18383,)
Shape of GSE131907_adata:  (55320, 18383)

How do I deal with this?

Many thanks!

Version information

anndata 0.10.7
infercnvpy 0.4.5
matplotlib 3.8.4
numpy 1.26.4
pandas 2.2.1
scanpy 1.10.1

@grst
Copy link
Member

grst commented Jun 20, 2024

Hi @HZT55,

thanks for reporting the issue! I think I found the problem. The issue was that the the X and Y chromosomes are by default removed from the anndata, and therefore the reference didn't match anymore.

The problem should be solved in #135. Would be great if you could test it by installing this version via

pip install git+https://github.com/icbi-lab/infercnvpy.git@fix-134

Cheers,
Gregor

@HZT55
Copy link
Author

HZT55 commented Jun 24, 2024

Hi Gregor,

Thank you for the quick fix! I can confirm that the issue has been resolved. Everything is working smoothly now.

@grst
Copy link
Member

grst commented Jun 24, 2024

Great, I'll include it in the next release then.

@grst grst closed this as completed in #135 Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants