我有一个看起来像这样的R代码:
r <- rowData(sce_list[[1]])
c <- colData(sce_list[[1]])
t <- sce_list[[1]][r$use,c$use]
到这里一切运行顺利。但是,当我尝试将t的值分配给另一个对象,如下所示时,我会遇到错误。
sce_list[[1]]$qc = t
Error in `[[<-`(`*tmp*`, name, value = <S4 object of class "SingleCellExperiment">) :
1842 elements in value to replace 5586 elements
其中sce_list是sce的列表。
编辑:
str(t)的输出
Formal class 'SingleCellExperiment' [package "SingleCellExperiment"] with 10 slots
..@ int_elementMetadata:Formal class 'DataFrame' [package "S4Vectors"] with 6 slots
.. .. ..@ rownames : NULL
.. .. ..@ nrows : int 1842
.. .. ..@ listData :List of 2
.. .. .. ..$ is_spike_MT: logi [1:1842] FALSE FALSE FALSE FALSE FALSE FALSE ...
.. .. .. ..$ is_spike : logi [1:1842] FALSE FALSE FALSE FALSE FALSE FALSE ...
.. .. ..@ elementType : chr "ANY"
.. .. ..@ elementMetadata: NULL
.. .. ..@ metadata : list()
..@ int_colData :Formal class 'DataFrame' [package "S4Vectors"] with 6 slots
.. .. ..@ rownames : NULL
.. .. ..@ nrows : int 3973
.. .. ..@ listData : Named list()
.. .. ..@ elementType : chr "ANY"
.. .. ..@ elementMetadata: NULL
.. .. ..@ metadata : list()
..@ int_metadata :List of 2
.. ..$ version :Classes 'package_version', 'numeric_version' hidden list of 1
.. .. ..$ : int [1:3] 1 0 0
.. ..$ spike_names: chr "MT"
..@ reducedDims :Formal class 'SimpleList' [package "S4Vectors"] with 4 slots
.. .. ..@ listData : Named list()
.. .. ..@ elementType : chr "ANY"
.. .. ..@ elementMetadata: NULL
.. .. ..@ metadata : list()
..@ rowRanges :Formal class 'GRangesList' [package "GenomicRanges"] with 5 slots
.. .. ..@ unlistData :Formal class 'GRanges' [package "GenomicRanges"] with 6 slots
.. .. .. .. ..@ seqnames :Formal class 'Rle' [package "S4Vectors"] with 4 slots
.. .. .. .. .. .. ..@ values : Factor w/ 0 levels:
.. .. .. .. .. .. ..@ lengths : int(0)
.. .. .. .. .. .. ..@ elementMetadata: NULL
.. .. .. .. .. .. ..@ metadata : list()
.. .. .. .. ..@ ranges :Formal class 'IRanges' [package "IRanges"] with 6 slots
.. .. .. .. .. .. ..@ start : int(0)
.. .. .. .. .. .. ..@ width : int(0)
.. .. .. .. .. .. ..@ NAMES : NULL
.. .. .. .. .. .. ..@ elementType : chr "integer"
.. .. .. .. .. .. ..@ elementMetadata: NULL
.. .. .. .. .. .. ..@ metadata : list()
.. .. .. .. ..@ strand :Formal class 'Rle' [package "S4Vectors"] with 4 slots
.. .. .. .. .. .. ..@ values : Factor w/ 3 levels "+","-","*":
.. .. .. .. .. .. ..@ lengths : int(0)
.. .. .. .. .. .. ..@ elementMetadata: NULL
.. .. .. .. .. .. ..@ metadata : list()
.. .. .. .. ..@ elementMetadata:Formal class 'DataFrame' [package "S4Vectors"] with 6 slots
.. .. .. .. .. .. ..@ rownames : NULL
.. .. .. .. .. .. ..@ nrows : int 0
.. .. .. .. .. .. ..@ listData : Named list()
.. .. .. .. .. .. ..@ elementType : chr "ANY"
.. .. .. .. .. .. ..@ elementMetadata: NULL
.. .. .. .. .. .. ..@ metadata : list()
.. .. .. .. ..@ seqinfo :Formal class 'Seqinfo' [package "GenomeInfoDb"] with 4 slots
.. .. .. .. .. .. ..@ seqnames : chr(0)
.. .. .. .. .. .. ..@ seqlengths : int(0)
.. .. .. .. .. .. ..@ is_circular: logi(0)
.. .. .. .. .. .. ..@ genome : chr(0)
.. .. .. .. ..@ metadata : list()
.. .. ..@ elementMetadata:Formal class 'DataFrame' [package "S4Vectors"] with 6 slots
.. .. .. .. ..@ rownames : NULL
.. .. .. .. ..@ nrows : int 1842
.. .. .. .. ..@ listData :List of 12
.. .. .. .. .. ..$ id : chr [1:1842] "ENSG00000187608" "ENSG00000186891" "ENSG00000186827" "ENSG00000175756" ...
.. .. .. .. .. ..$ symbol : chr [1:1842] "ISG15" "TNFRSF18" "TNFRSF4" "AURKAIP1" ...
.. .. .. .. .. ..$ is_feature_control : logi [1:1842] FALSE FALSE FALSE FALSE FALSE FALSE ...
.. .. .. .. .. ..$ is_feature_control_MT: logi [1:1842] FALSE FALSE FALSE FALSE FALSE FALSE ...
.. .. .. .. .. ..$ mean_counts : num [1:1842] 5.067 0.166 0.162 0.639 0.719 ...
.. .. .. .. .. ..$ log10_mean_counts : num [1:1842] 0.783 0.0669 0.0651 0.2146 0.2353 ...
.. .. .. .. .. ..$ rank_counts : num [1:1842] 33536 30766 30710 32857 32945 ...
.. .. .. .. .. ..$ n_cells_counts : int [1:1842] 4580 516 458 2376 2578 2153 2277 5388 3604 4131 ...
.. .. .. .. .. ..$ pct_dropout_counts : num [1:1842] 18 90.8 91.8 57.5 53.8 ...
.. .. .. .. .. ..$ total_counts : num [1:1842] 28305 930 904 3569 4017 ...
.. .. .. .. .. ..$ log10_total_counts : num [1:1842] 4.45 2.97 2.96 3.55 3.6 ...
.. .. .. .. .. ..$ use : Named logi [1:1842] TRUE TRUE TRUE TRUE TRUE TRUE ...
.. .. .. .. .. .. ..- attr(*, "names")= chr [1:1842] "ENSG00000187608" "ENSG00000186891" "ENSG00000186827" "ENSG00000175756" ...
.. .. .. .. ..@ elementType : chr "ANY"
.. .. .. .. ..@ elementMetadata: NULL
.. .. .. .. ..@ metadata : list()
.. .. ..@ partitioning :Formal class 'PartitioningByEnd' [package "IRanges"] with 5 slots
.. .. .. .. ..@ end : int [1:1842] 0 0 0 0 0 0 0 0 0 0 ...
.. .. .. .. ..@ NAMES : chr [1:1842] "ENSG00000187608" "ENSG00000186891" "ENSG00000186827" "ENSG00000175756" ...
.. .. .. .. ..@ elementType : chr "integer"
.. .. .. .. ..@ elementMetadata: NULL
.. .. .. .. ..@ metadata : list()
.. .. ..@ elementType : chr "GRanges"
.. .. ..@ metadata : list()
..@ colData :Formal class 'DataFrame' [package "S4Vectors"] with 6 slots
.. .. ..@ rownames : chr [1:3973] "AAACCTGAGAAGGTTT-1" "AAACCTGAGCGTTCCG-1" "AAACCTGAGTACGTAA-1" "AAACCTGGTCCATGAT-1" ...
.. .. ..@ nrows : int 3973
.. .. ..@ listData :List of 32
.. .. .. ..$ dataset : int [1:3973] 1 1 1 1 1 1 1 1 1 1 ...
.. .. .. ..$ barcode : chr [1:3973] "AAACCTGAGAAGGTTT-1" "AAACCTGAGCGTTCCG-1" "AAACCTGAGTACGTAA-1" "AAACCTGGTCCATGAT-1" ...
.. .. .. ..$ total_features : int [1:3973] 1373 1837 2259 2601 1967 1236 1642 1153 1078 2682 ...
.. .. .. ..$ log10_total_features : num [1:3973] 3.14 3.26 3.35 3.42 3.29 ...
.. .. .. ..$ total_counts : num [1:3973] 3380 7332 10099 12184 7352 ...
.. .. .. ..$ log10_total_counts : num [1:3973] 3.53 3.87 4 4.09 3.87 ...
.. .. .. ..$ pct_counts_top_50_features : num [1:3973] 33.1 38.9 42.5 42.2 42.8 ...
.. .. .. ..$ pct_counts_top_100_features : num [1:3973] 45 54.8 59.2 53.5 52.4 ...
.. .. .. ..$ pct_counts_top_200_features : num [1:3973] 57.5 66.9 69 64.7 63.5 ...
.. .. .. ..$ pct_counts_top_500_features : num [1:3973] 74.2 79.2 79.4 76.8 76.6 ...
.. .. .. ..$ total_features_endogenous : int [1:3973] 1373 1837 2259 2601 1967 1236 1642 1153 1078 2682 ...
.. .. .. ..$ log10_total_features_endogenous : num [1:3973] 3.14 3.26 3.35 3.42 3.29 ...
.. .. .. ..$ total_counts_endogenous : num [1:3973] 3380 7332 10099 12184 7352 ...
.. .. .. ..$ log10_total_counts_endogenous : num [1:3973] 3.53 3.87 4 4.09 3.87 ...
.. .. .. ..$ pct_counts_endogenous : num [1:3973] 100 100 100 100 100 100 100 100 100 100 ...
.. .. .. ..$ pct_counts_top_50_features_endogenous : num [1:3973] 33.1 38.9 42.5 42.2 42.8 ...
.. .. .. ..$ pct_counts_top_100_features_endogenous: num [1:3973] 45 54.8 59.2 53.5 52.4 ...
.. .. .. ..$ pct_counts_top_200_features_endogenous: num [1:3973] 57.5 66.9 69 64.7 63.5 ...
.. .. .. ..$ pct_counts_top_500_features_endogenous: num [1:3973] 74.2 79.2 79.4 76.8 76.6 ...
.. .. .. ..$ total_features_feature_control : int [1:3973] 0 0 0 0 0 0 0 0 0 0 ...
.. .. .. ..$ log10_total_features_feature_control : num [1:3973] 0 0 0 0 0 0 0 0 0 0 ...
.. .. .. ..$ total_counts_feature_control : num [1:3973] 0 0 0 0 0 0 0 0 0 0 ...
.. .. .. ..$ log10_total_counts_feature_control : num [1:3973] 0 0 0 0 0 0 0 0 0 0 ...
.. .. .. ..$ pct_counts_feature_control : num [1:3973] 0 0 0 0 0 0 0 0 0 0 ...
.. .. .. ..$ total_features_MT : int [1:3973] 0 0 0 0 0 0 0 0 0 0 ...
.. .. .. ..$ log10_total_features_MT : num [1:3973] 0 0 0 0 0 0 0 0 0 0 ...
.. .. .. ..$ total_counts_MT : num [1:3973] 0 0 0 0 0 0 0 0 0 0 ...
.. .. .. ..$ log10_total_counts_MT : num [1:3973] 0 0 0 0 0 0 0 0 0 0 ...
.. .. .. ..$ pct_counts_MT : num [1:3973] 0 0 0 0 0 0 0 0 0 0 ...
.. .. .. ..$ is_cell_control : logi [1:3973] FALSE FALSE FALSE FALSE FALSE FALSE ...
.. .. .. ..$ use : logi [1:3973] TRUE TRUE TRUE TRUE TRUE TRUE ...
.. .. .. ..$ outlier : logi [1:3973] FALSE FALSE FALSE FALSE FALSE FALSE ...
.. .. ..@ elementType : chr "ANY"
.. .. ..@ elementMetadata: NULL
.. .. ..@ metadata : list()
..@ assays :Reference class 'ShallowSimpleListAssays' [package "SummarizedExperiment"] with 1 field
.. ..$ data: NULL
.. ..and 14 methods.
..@ NAMES : NULL
..@ elementMetadata :Formal class 'DataFrame' [package "S4Vectors"] with 6 slots
.. .. ..@ rownames : NULL
.. .. ..@ nrows : int 1842
.. .. ..@ listData : Named list()
.. .. ..@ elementType : chr "ANY"
.. .. ..@ elementMetadata: NULL
.. .. ..@ metadata : list()
..@ metadata :List of 1
.. ..$ name: chr "iMates-1"
和
class(sce_list[[1]])
[1] "SingleCellExperiment"
attr(,"package")
[1] "SingleCellExperiment"
R大师的任何人都可以帮助我解决这个问题。
答案 0 :(得分:0)
我想出了一种解决此问题的方法。这不是最优雅的答案,但确实可以解决问题。因此,这里是:
for (i in seq_along(sce_list))
{
r <- rowData(sce_list[[i]])$use
c <- colData(sce_list[[i]])$use
tt=(sce_list[[i]])[r,c]
assign(paste0("sce_",i,".qc"),tt)
}
是的,我把它放在一个循环中,因为我希望它可以循环运行。 :)
如果某人有这样做的优雅方法,请发布它,我会尝试的。