IanevskiAleksandr / sc-type

GNU General Public License v3.0
227 stars 44 forks source link

sc-Type: Error in Z[cell_markers_genes_score[jj, "gene_"], ] : subscript out of bounds." #9

Open PilanEli opened 2 years ago

PilanEli commented 2 years ago

Hi

Dear Aleksandr

Thanks for the useful software. May I ask how to solve the " Error in Z[cell_markers_genesscore[jj, "gene"], ] : subscript out of bounds." After running the commands to get cell-type by cell matrix this error is displayed.

I'm using a file normalized by sctransform.

Thank you very much, Yours sincerely,

Eli

Error sctype

Close-your-eyes commented 2 years ago

Do you have mouse data? If so, then there may be no marker genes. cell_markers_genes_score generated in line 40 of the function (original R script file downloaded manually) may be empty.

PilanEli commented 2 years ago

Hi

I have the data; however i think i have identified the problem. I didn't rescue all the genes after applying the integration.

Thank you!

dmclean22 commented 2 years ago

Hi

I have the data; however i think i have identified the problem. I didn't rescue all the genes after applying the integration.

Thank you!

Hello,

I am having the same problem, how did you fix this?

Thanks

ahdee commented 1 year ago

I am having the same problem, how did you fix this?

@dmclean22 I'm not OP or developer but for me I accidently set it to a different layer, so make sure that you select the correct assay, either setting it indectory DefaultAssay(sc) <- "SCT" or set it in the function call. Else you need to look in the @assay$SCT$scale.data and see what in particular is going on with the genes (rows )

DrGin-hub commented 1 year ago

Hi I face the same error due to my Seurat object being made with "use.names = F", which gives you ENSEMBL ID instead of gene ID change to "use.names = T" and works again

chenli-bioinfo commented 9 months ago

I have a similar problem running the example on the readme page. I am using Seurat 5.0 and it seems problematic:

es.max = sctype_score(scRNAseqData = pbmc[["RNA"]]@scale.data, scaled = TRUE, gs = gs_list$gs_positive, gs2 = gs_list$gs_negative)

WeChatbc78487d951d05ac6a6ff459a4a42c09

I changed to: es.max = sctype_score(scRNAseqData = pbmc@assays$RNA@layers$scale.data, scaled = TRUE, gs = gs_list$gs_positive, gs2 = gs_list$gs_negative)

and then got the same error: WeChat07fc0dc2ceea2072448960b0a007a8ac

Could anyone help? Thanks

blain1995 commented 9 months ago

Hi, just to confirm I am experiencing the same error as @chenli-bioinfo mentioned above with a Seurat v5 object, no solution as of yet - would appreciate any advice!

blain1995 commented 9 months ago

@chenli-bioinfo found a workaround for using Seurat v5, it isn't ideal.

If you create a new assay by casting your RNA assay5 to a v3 assay with as() like below: pbmc3k[["RNA3"]] <- as(object = pbmc3k[["RNA"]], Class = "Assay") you can then alter the sctype function to use the new assay instead of the original RNA assay. I have used this with my data and it has worked as expected.

jgarces02 commented 9 months ago

Please, take a look to this other issue and to the tutorial note:

# NOTE: scRNAseqData parameter should correspond to your input scRNA-seq matrix. 
# In case Seurat is used, it is either pbmc[["RNA"]]@scale.data (default), pbmc[["SCT"]]@scale.data, in case sctransform is used for normalization,
# or pbmc[["integrated"]]@scale.data, in case a joint analysis of multiple single-cell datasets is performed.
jordan841220 commented 9 months ago

For me, the error occurs after I modified the gene_sets_prepare function to silent the checkgenessymbol and toupper function (which I have no idea why they were necessary). Therefore, gene names with special symbols would not be discarded. And gene names would not be converted to uppercase. Under this circumstance, I would have to modify the sctype_score function to silent the toupper function again, and everything works fine.

DC-Jade commented 9 months ago

hello, I ran into the same issue. And I check the source code. I found the issue in step '# subselect genes only found in data". GeneIndToKeep = rownames(scRNAseqData) %in% as.character(gs[[d_]]) rownames(scRNAseqData) is upper case, but my input mouse gs is lower case,

So I change gs_list$gs_positive into upper case and solved it. gs = lapply(gs_list$gs_positive, toupper)

swainasish commented 7 months ago

The problem arise, as there is no gene names in the scale.data layer, can be solve by

pbmc_mat = as.matrix(pbmc[["RNA"]]@layers$scale.data)
rownames(pbmc_mat) = rownames(pbmc)
colnames(pbmc_mat) = colnames(pbmc)
es.max = sctype_score(scRNAseqData = pbmc_mat, scaled = TRUE, 
                      gs = gs, gs2 = gs_list$gs_negative)

Here, I created a matrix (pbmc_mat), then set the rownames and colnames from the seurat object (pbmc).

sfplab commented 2 months ago

I see this issue with Seurat 5.1.0 objects as well, irrespective whether scaled = T or F, or whether object is pre- or post-integration. Would greatly appreciate @IanevskiAleksandr to weigh in. Thanks!

PS. Traced this back to how data_type is handled in line 25 of auto_detect_tissue_type.R, replaced with: as.matrix(LayerData(object = seuratObject,layer = data_type))