neurorestore/Libra

Error in `$<-.data.frame`(`*tmp*`, "replicate", value = integer(0))

Opened this issue · 14 comments

hi,i got an erro below,when i run function run_de

r$> DE = run_de(sce)
Error in $<-.data.frame(*tmp*, "replicate", value = integer(0)) :
replacement has 0 rows, data has 87395

sce is a seurat object,and metadata contains column cell_type and label
orig.ident nCount_RNA nFeature_RNA percent.mt percent.rb sample
AAACCCAAGGCGTTGA-1_1 K10611T_1 631 490 0.47543582 1.2678288 K10611T_1
AAACCCAGTCGCTCGA-1_1 K10611T_1 2826 1610 0.00000000 1.2738854 K10611T_1
AAACCCATCAGGAAGC-1_1 K10611T_1 867 709 0.57670127 0.8073818 K10611T_1
AAACCCATCCACAGGC-1_1 K10611T_1 1059 702 0.09442871 1.1331445 K10611T_1
AAACCCATCTCGTGGG-1_1 K10611T_1 3724 2152 0.02685285 0.6713212 K10611T_1
AAACGAAAGCGAGAAA-1_1 K10611T_1 654 510 0.76452599 1.2232416 K10611T_1
RNA_snn_res.0.8 seurat_clusters cell_type label
AAACCCAAGGCGTTGA-1_1 6 6 T cells T
AAACCCAGTCGCTCGA-1_1 4 4 PC T
AAACCCATCAGGAAGC-1_1 7 7 FIB T
AAACCCATCCACAGGC-1_1 11 11 Plasma cells T
AAACCCATCTCGTGGG-1_1 13 13 PC T
AAACGAAAGCGAGAAA-1_1 2 2 Macrophages T

couldyou please give a hand

Hi,

Can you share with me your data so I can figure out what might be the issue? Thanks.

I got the same error when inputting "pbmc" ,my own data. Relevant information is shared in the picture below. I guess the error was caused by Seurat R Package Version. The data structure was changed, comparing with the demonstration data.
But I don't know how to address it. Could you give me a hand? Thanks!
截屏2024-07-17 15 41 32
截屏2024-07-17 15 42 19

Hi Chengming,
I have successfully ran Libra on Seurat v5.0.0 (albeit with a warning sign) so I'm not sure why this doesn't work.
However, a quick fix would be to extract out the expression matrix and metadata from the Seurat object and run Libra directly on the expression matrix and metadata.

expr = LayerData(sc, assay = "RNA", layer = "counts")
meta = sc@meta.data
libra_result = run_de(expr, meta)

Thank you for your prompt response and the suggested solution. I followed your instructions to extract the expression matrix and metadata from the Seurat object and run Libra directly. However, it doesn't work.

expr = LayerData(pbmc, assay = "RNA", layer = "counts")
meta = pbmc@meta.data
libra_result = run_de(expr, meta)
Error in $<-.data.frame(*tmp*, "label", value = integer(0)) :
replacement has 0 rows, data has 98602

I wonder if the structure of data is corresponding to yours. Relevant information is showed in the pictures below.
截屏2024-07-17 19 48 58
截屏2024-07-17 19 49 56
@AlanTeoYueYang

Can i see your meta as well?
str(expr)
str(meta)

Of course

str(expr)
Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
..@ i : int [1:99273795] 0 17 28 31 34 39 43 49 71 97 ...
..@ p : int [1:98603] 0 3652 6368 9482 12074 14609 17232 20082 22758 25483 ...
..@ Dim : int [1:2] 16648 98602
..@ Dimnames:List of 2
.. ..$ : chr [1:16648] "X0610007P14Rik" "X0610009B22Rik" "X0610009L18Rik" "X0610009O20Rik" ...
.. ..$ : chr [1:98602] "E14_CAGACATGCCCTTG-1_1" "E14_AGGTTGTGTCTGGA-1_1" "E14_CTGATGGACCGAAT-1_1" "E14_CCTCGAACGCAAGG-1_1" ...
..@ x : num [1:99273795] 1 1 2 2 1 1 1 1 1 2 ...
..@ factors : list()

str(meta)
'data.frame': 98602 obs. of 5 variables:
$ orig.ident : chr "E14" "E14" "E14" "E14" ...
$ nCount_RNA : num 8015 5592 6129 5288 4681 ...
$ nFeature_RNA : int 3652 2716 3114 2592 2535 2623 2850 2676 2725 2765 ...
$ RNA_snn_res.0.5: Factor w/ 11 levels "0","1","2","3",..: 9 9 9 9 9 9 11 5 5 5 ...
$ seurat_clusters: Factor w/ 11 levels "0","1","2","3",..: 9 9 9 9 9 9 11 5 5 5 ...

Hi, to run Libra,
you need the following columns (replicate, cell_type, label, barcode) in the metadata of the Seurat object.
The error you see is because it can't find the label column.

Thanks! But it's still wrong when I run Libra,though Column cell_type clearly exists.I am unsure of the exact steps to resolve this issue. Could you please provide guidance on how to address this error?

expr = LayerData(pbmc,assay = "RNA", layer = "counts")
meta = pbmc@meta.data
libra_result = run_de(expr, meta)
[1] "6"
Error in group_by():
! Must group by variables found in .data.
✖ Column cell_type is not found.
Backtrace:

  1. ├─Libra::run_de(expr, meta)
  2. │ └─... %>% arrange(cell_type, gene)
  3. ├─dplyr::arrange(., cell_type, gene)
  4. ├─dplyr::ungroup(.)
  5. ├─dplyr::select(...)
  6. ├─dplyr::mutate(., avg_logFC = avg_logFC * -1)
  7. ├─dplyr::mutate(., gene = as.character(gene))
  8. ├─dplyr::mutate(., p_val_adj = p.adjust(p_val, method = "BH"))
  9. ├─dplyr::group_by(., cell_type)
  10. └─dplyr:::group_by.data.frame(., cell_type)
  11. └─dplyr::group_by_prepare(.data, ..., .add = .add, error_call = current_env())
  12. └─rlang::abort(bullets, call = error_call)
    

str(meta)
'data.frame': 98602 obs. of 5 variables:
$ label : chr "E14" "E14" "E14" "E14" ...
$ nCount_RNA : num 8015 5592 6129 5288 4681 ...
$ nFeature_RNA: int 3652 2716 3114 2592 2535 2623 2850 2676 2725 2765 ...
$ replicate : chr "8" "8" "8" "8" ...
$ cell_type : chr "8" "8" "8" "8" ...

Can you show me the output of this?
meta %>% dplyr::select(label, cell_type) %>% distinct()

meta %>% dplyr::select(label, cell_type) %>% distinct()
label cell_type
E14_CAGACATGCCCTTG-1_1 E14 8
E14_ATGCACGAGTCTGA-1_1 E14 10
E14_AAGTCTCTTCGACA-1_1 E14 4
E14_TGACTGGAGTTAGC-1_1 E14 7
E14_ATTCTTCTAGTCAC-1_1 E14 5
E14_TTACTCGATACGCA-1_1 E14 3
E14_TTCGAGGATCTACT-1_1 E14 2
E14_TGAACCGAGTACCA-1_1 E14 6
E14_CTAACTACCTGAGT-1_5 E14 0
E14_TTGGAGACCTCCAC-1_5 E14 9
E14_CATCCCGACCCTTG-1_5 E14 1
P4.5_ACGTGATGTTGGCA-1_9 P4.5 7
P4.5_CTCAATTGCCTTGC-1_9 P4.5 4
P4.5_TTATGAGACTCAGA-1_9 P4.5 6
P4.5_TTCCTAGATGAGGG-1_9 P4.5 10
P4.5_ACCACAGACCGCTT-1_9 P4.5 5
P4.5_ACCATTACCCATAG-1_9 P4.5 8
P4.5_TACCGGCTTCGACA-1_9 P4.5 2
P4.5_GTGTCAGAAATCGC-1_9 P4.5 3
P4.5_CGGAATTGCACTGA-1_9 P4.5 0
P4.5_AATAACACTCATTC-1_9 P4.5 1
...

Hmm can you find a way to share your data with me?

Could please tell me your e_mail address? I'll send attachments through email .

Not sure if this has already been resolved, but I ran into a similar issue.

How many unique labels do you have? The output to X above shows E14 and P4.5, but are there cells with any other labels? If so, then that is likely your problem. https://github.com/neurorestore/Libra/issues/6