broadinstitute / infercnv

Inferring CNV from Single-Cell RNA-Seq
Other
556 stars 164 forks source link

Error in running inferCNV : assignment of an object of class "logical" is not valid for @'cnv_regions' in an object of class "MCMC_inferCNV"; is(value, "factor") is not TRUE Calls: <Anonymous> ... initializeObject -> initializeObject -> <Anonymous> Execution halted #360

Closed tinakeshav closed 2 years ago

tinakeshav commented 3 years ago

Hi, I have an RNA count matrix for a few samples generated by cell ranger, turned into a Seurat object. I'm running inferCNV on each sample separately. For a very small bad QC test sample with about ~1000 cells, inferCNV ran fine. But for the rest of the samples it keeps throwing this error.

error message:

Error in (function (cl, name, valueClass)  :   assignment of an object of class "logical" is not valid for @'cnv_regions' in an object of class "MCMC_inferCNV"; is(value, "factor") is not TRUE Calls: <Anonymous> ... initializeObject -> initializeObject -> <Anonymous> Execution halted 

FULL ERROR / COMMANDS:

DefaultAssay(sample) = 'RNA'
counts_matrix = GetAssayData(sample, slot="counts")
sample_annotation = sample@meta.data[,"clust", drop=FALSE] 
path_to_order = '/cluster/projects/tk/gencde.v22.annotation_gen_pos.txt'
# create the infercnv object
infercnv_obj = CreateInfercnvObject(raw_counts_matrix=counts_matrix,
                                    annotations_file=sample_annotation,
                                    delim="\t",
                                    gene_order_file=path_to_order,
                                    ref_group_names=NULL)
infercnv_obj = infercnv::run(infercnv_obj
                             ,cutoff=0.1 # cutoff=1 works well for Smart-seq2, and cutoff=0.1 works well for 10x Genomics
                             ,out_dir=out_dir_name
                             ,denoise=TRUE
                             ,HMM=TRUE
                        )

INFO [2021-09-03 14:09:36] Parsing gene order file: /cluster/projects/lupiengroup/People/tina/gencode.v22.annotation_gen_pos.txt
INFO [2021-09-03 14:09:37] ::order_reduce:Start.
INFO [2021-09-03 14:09:39] .order_reduce(): expr and order match.
INFO [2021-09-03 14:09:42] ::process_data:order_reduce:Reduction from positional data, new dimensions (r,c) = 36601,4784 Total=49670543 Min=0 Max=10658.
INFO [2021-09-03 14:09:42] num genes removed taking into account provided gene ordering list: 14814 = 40.4743039807656% removed.
INFO [2021-09-03 14:09:42] -filtering out cells < 100 or > Inf, removing 0 % of cells
INFO [2021-09-03 14:09:45] validating infercnv_obj
INFO [2021-09-03 14:09:45] ::process_data:Start
INFO [2021-09-03 14:09:45] Checking for saved results.
INFO [2021-09-03 14:09:45]

        STEP 1: incoming data

INFO [2021-09-03 14:10:03]

        STEP 02: Removing lowly expressed genes

INFO [2021-09-03 14:10:03] ::above_min_mean_expr_cutoff:Start
INFO [2021-09-03 14:10:04] Removing 13174 genes from matrix as below mean expr threshold: 0.1
INFO [2021-09-03 14:10:05] validating infercnv_obj
INFO [2021-09-03 14:10:05] There are 8613 genes and 4784 cells remaining in the expr matrix.
INFO [2021-09-03 14:10:14] no genes removed due to min cells/gene filter
INFO [2021-09-03 14:10:31]

        STEP 03: normalization by sequencing depth

INFO [2021-09-03 14:10:31] normalizing counts matrix by depth
INFO [2021-09-03 14:10:39] Computed total sum normalization factor as median libsize: 4759.000000
INFO [2021-09-03 14:10:39] Adding h-spike
INFO [2021-09-03 14:10:39] -no normals defined, using all observation cells as proxy
INFO [2021-09-03 14:10:39] -hspike modeling of normalsToUse
INFO [2021-09-03 14:13:49] validating infercnv_obj
INFO [2021-09-03 14:13:49] normalizing counts matrix by depth
INFO [2021-09-03 14:13:50] Using specified normalization factor: 4759.000000
INFO [2021-09-03 14:14:07]

        STEP 04: log transformation of data

INFO [2021-09-03 14:14:07] transforming log2xplus1()
INFO [2021-09-03 14:14:10] -mirroring for hspike
INFO [2021-09-03 14:14:10] transforming log2xplus1()
INFO [2021-09-03 14:14:29]

        STEP 08: removing average of reference data (before smoothing)

INFO [2021-09-03 14:14:29] ::subtract_ref_expr_from_obs:Start inv_log=FALSE, use_bounds=TRUE
INFO [2021-09-03 14:14:29] -no reference cells specified... using mean of all cells as proxy
INFO [2021-09-03 14:14:37] -subtracting expr per gene, use_bounds=TRUE
INFO [2021-09-03 15:01:51] -mirroring for hspike
INFO [2021-09-03 15:01:51] ::subtract_ref_expr_from_obs:Start inv_log=FALSE, use_bounds=TRUE
INFO [2021-09-03 15:01:51] subtracting mean(normal) per gene per cell across all data
INFO [2021-09-03 15:01:57] -subtracting expr per gene, use_bounds=TRUE
INFO [2021-09-03 15:02:28]

        STEP 09: apply max centered expression threshold: 3

INFO [2021-09-03 15:02:28] ::process_data:setting max centered expr, threshold set to: +/-:  3
INFO [2021-09-03 15:02:30] -mirroring for hspike
INFO [2021-09-03 15:02:30] ::process_data:setting max centered expr, threshold set to: +/-:  3
INFO [2021-09-03 15:03:00]

        STEP 10: Smoothing data per cell by chromosome

INFO [2021-09-03 15:03:00] smooth_by_chromosome: chr: chr1
INFO [2021-09-03 15:03:10] smooth_by_chromosome: chr: chr2
INFO [2021-09-03 15:03:20] smooth_by_chromosome: chr: chr3
INFO [2021-09-03 15:03:29] smooth_by_chromosome: chr: chr4
INFO [2021-09-03 15:03:37] smooth_by_chromosome: chr: chr5
INFO [2021-09-03 15:03:48] smooth_by_chromosome: chr: chr6
INFO [2021-09-03 15:03:57] smooth_by_chromosome: chr: chr7
INFO [2021-09-03 15:04:05] smooth_by_chromosome: chr: chr8
INFO [2021-09-03 15:04:14] smooth_by_chromosome: chr: chr9
INFO [2021-09-03 15:04:22] smooth_by_chromosome: chr: chr10
INFO [2021-09-03 15:04:31] smooth_by_chromosome: chr: chr11
INFO [2021-09-03 15:04:42] smooth_by_chromosome: chr: chr12
INFO [2021-09-03 15:04:51] smooth_by_chromosome: chr: chr13
INFO [2021-09-03 15:04:59] smooth_by_chromosome: chr: chr14
INFO [2021-09-03 15:05:07] smooth_by_chromosome: chr: chr15
INFO [2021-09-03 15:05:17] smooth_by_chromosome: chr: chr16
INFO [2021-09-03 15:05:25] smooth_by_chromosome: chr: chr17
INFO [2021-09-03 15:05:34] smooth_by_chromosome: chr: chr18
INFO [2021-09-03 15:05:42] smooth_by_chromosome: chr: chr19
INFO [2021-09-03 15:05:51] smooth_by_chromosome: chr: chr20
INFO [2021-09-03 15:05:59] smooth_by_chromosome: chr: chr21
INFO [2021-09-03 15:06:06] smooth_by_chromosome: chr: chr22
INFO [2021-09-03 15:06:15] -mirroring for hspike
INFO [2021-09-03 15:06:15] smooth_by_chromosome: chr: chrA
INFO [2021-09-03 15:06:15] smooth_by_chromosome: chr: chr_0
INFO [2021-09-03 15:06:15] smooth_by_chromosome: chr: chr_B
INFO [2021-09-03 15:06:16] smooth_by_chromosome: chr: chr_0pt5
INFO [2021-09-03 15:06:16] smooth_by_chromosome: chr: chr_C
INFO [2021-09-03 15:06:16] smooth_by_chromosome: chr: chr_1pt5
INFO [2021-09-03 15:06:17] smooth_by_chromosome: chr: chr_D
INFO [2021-09-03 15:06:17] smooth_by_chromosome: chr: chr_2pt0
INFO [2021-09-03 15:06:18] smooth_by_chromosome: chr: chr_E
INFO [2021-09-03 15:06:18] smooth_by_chromosome: chr: chr_3pt0
INFO [2021-09-03 15:06:18] smooth_by_chromosome: chr: chr_F
INFO [2021-09-03 15:06:50]

        STEP 11: re-centering data across chromosome after smoothing

INFO [2021-09-03 15:06:50] ::center_smooth across chromosomes per cell
INFO [2021-09-03 15:07:03] -mirroring for hspike
INFO [2021-09-03 15:07:03] ::center_smooth across chromosomes per cell
INFO [2021-09-03 15:07:34]

        STEP 12: removing average of reference data (after smoothing)

INFO [2021-09-03 15:07:34] ::subtract_ref_expr_from_obs:Start inv_log=FALSE, use_bounds=TRUE
INFO [2021-09-03 15:07:34] -no reference cells specified... using mean of all cells as proxy
INFO [2021-09-03 15:07:43] -subtracting expr per gene, use_bounds=TRUE
INFO [2021-09-03 15:07:50] -mirroring for hspike
INFO [2021-09-03 15:07:50] ::subtract_ref_expr_from_obs:Start inv_log=FALSE, use_bounds=TRUE
INFO [2021-09-03 15:07:50] subtracting mean(normal) per gene per cell across all data
INFO [2021-09-03 15:07:55] -subtracting expr per gene, use_bounds=TRUE
INFO [2021-09-03 15:08:26]

        STEP 14: invert log2(FC) to FC

INFO [2021-09-03 15:08:26] invert_log2(), computing 2^x
INFO [2021-09-03 15:08:28] -mirroring for hspike
INFO [2021-09-03 15:08:28] invert_log2(), computing 2^x
INFO [2021-09-03 15:09:08]

        STEP 15: Clustering samples (not defining tumor subclusters)

INFO [2021-09-03 15:09:08] define_signif_tumor_subclusters(p_val=0.1
INFO [2021-09-03 15:09:08] define_signif_tumor_subclusters(), tumor: all_observations
INFO [2021-09-03 16:59:48] cut tree into: 1 groups
INFO [2021-09-03 16:59:48] -processing all_observations,all_observations_s1
INFO [2021-09-03 16:59:48] -mirroring for hspike
INFO [2021-09-03 16:59:48] define_signif_tumor_subclusters(p_val=0.1
INFO [2021-09-03 16:59:48] define_signif_tumor_subclusters(), tumor: all_observations
INFO [2021-09-03 16:59:48] cut tree into: 1 groups
INFO [2021-09-03 16:59:48] -processing all_observations,all_observations_s1
INFO [2021-09-03 16:59:48] define_signif_tumor_subclusters(), tumor: simnorm_cell_normalsToUse
INFO [2021-09-03 16:59:49] cut tree into: 1 groups
INFO [2021-09-03 16:59:49] -processing simnorm_cell_normalsToUse,simnorm_cell_normalsToUse_s1
INFO [2021-09-03 17:01:08] ::plot_cnv:Start
INFO [2021-09-03 17:01:08] ::plot_cnv:Current data dimensions (r,c)=8613,4784 Total=41251073.8987977 Min=0.725712079309498 Max=1.60416437608817.
INFO [2021-09-03 17:01:08] ::plot_cnv:Depending on the size of the matrix this may take a moment.
INFO [2021-09-03 17:02:08] plot_cnv(): auto thresholding at: (0.867390 , 1.134867)
INFO [2021-09-03 17:02:12] plot_cnv_observation:Start
INFO [2021-09-03 17:02:12] Observation data size: Cells= 4784 Genes= 8613
INFO [2021-09-03 17:02:12] plot_cnv_observation:Writing observations by grouping.
INFO [2021-09-03 17:03:11] plot_cnv_observation:Writing observation groupings/color.
INFO [2021-09-03 17:03:11] plot_cnv_observation:Done writing observation groupings/color.
INFO [2021-09-03 17:03:12] plot_cnv_observation:Writing observation heatmap thresholds.
INFO [2021-09-03 17:03:12] plot_cnv_observation:Done writing observation heatmap thresholds.
INFO [2021-09-03 17:03:30] Colors for breaks:  #00008B,#24249B,#4848AB,#6D6DBC,#9191CC,#B6B6DD,#DADAEE,#FFFFFF,#EEDADA,#DDB6B6,#CC9191,#BC6D6D,#AB4848,#9B2424,#8B0000
INFO [2021-09-03 17:03:30] Quantiles of plotted data range: 0.867389611252118,0.971010805114303,0.998481825308773,1.02800376812288,1.13486654013983
INFO [2021-09-03 17:03:44] plot_cnv_observations:Writing observation data to inferCNVPat2_LN5/infercnv.preliminary.observations.txt
INFO [2021-09-03 17:04:45]

        STEP 17: HMM-based CNV prediction

INFO [2021-09-03 17:04:45] predict_CNV_via_HMM_on_whole_tumor_samples
INFO [2021-09-03 17:05:00] -done predicting CNV based on initial tumor subclusters
INFO [2021-09-03 17:05:00] get_predicted_CNV_regions(subcluster)
INFO [2021-09-03 17:05:00] -processing cell_group_name: all_observations.all_observations_s1, size: 4784
INFO [2021-09-03 17:05:55] -writing cell clusters file: inferCNVPat2_LN5/17_HMM_predHMMi6.hmm_mode-samples.cell_groupings
INFO [2021-09-03 17:05:55] -writing cnv regions file: inferCNVPat2_LN5/17_HMM_predHMMi6.hmm_mode-samples.pred_cnv_regions.dat
INFO [2021-09-03 17:05:55] -writing per-gene cnv report: inferCNVPat2_LN5/17_HMM_predHMMi6.hmm_mode-samples.pred_cnv_genes.dat
INFO [2021-09-03 17:05:55] -writing gene ordering info: inferCNVPat2_LN5/17_HMM_predHMMi6.hmm_mode-samples.genes_used.dat
INFO [2021-09-03 17:06:10] ::plot_cnv:Start
INFO [2021-09-03 17:06:10] ::plot_cnv:Current data dimensions (r,c)=8613,4784 Total=123831562 Min=2 Max=4.
INFO [2021-09-03 17:06:11] ::plot_cnv:Depending on the size of the matrix this may take a moment.
INFO [2021-09-03 17:07:03] plot_cnv_observation:Start
INFO [2021-09-03 17:07:03] Observation data size: Cells= 4784 Genes= 8613
INFO [2021-09-03 17:07:04] plot_cnv_observation:Writing observations by grouping.
INFO [2021-09-03 17:07:54] plot_cnv_observation:Writing observation groupings/color.
INFO [2021-09-03 17:07:54] plot_cnv_observation:Done writing observation groupings/color.
INFO [2021-09-03 17:07:55] plot_cnv_observation:Writing observation heatmap thresholds.
INFO [2021-09-03 17:07:55] plot_cnv_observation:Done writing observation heatmap thresholds.
INFO [2021-09-03 17:08:12] Colors for breaks:  #00008B,#24249B,#4848AB,#6D6DBC,#9191CC,#B6B6DD,#DADAEE,#FFFFFF,#EEDADA,#DDB6B6,#CC9191,#BC6D6D,#AB4848,#9B2424,#8B0000
INFO [2021-09-03 17:08:12] Quantiles of plotted data range: 2,3,3,3,4
INFO [2021-09-03 17:08:22] plot_cnv_observations:Writing observation data to inferCNVPat2_LN5/infercnv.17_HMM_predHMMi6.hmm_mode-samples.observations.txt
INFO [2021-09-03 17:09:16]

        STEP 18: Run Bayesian Network Model on HMM predicted CNVs

INFO [2021-09-03 17:09:16] Creating the following Directory:  inferCNVPat2_LN5/BayesNetOutput.HMMi6.hmm_mode-samples
INFO [2021-09-03 17:09:16] Initializing new MCM InferCNV Object.
INFO [2021-09-03 17:09:16] validating infercnv_obj

Error in (function (cl, name, valueClass)  :
  assignment of an object of class "logical" is not valid for @'cnv_regions' in an object of class "MCMC_inferCNV"; is(value, "factor") is not TRUE
Calls: <Anonymous> ... initializeObject -> initializeObject -> <Anonymous>
Execution halted

SessionInfo:

R version 4.0.0 (2020-04-24)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

locale:
 [1] LC_CTYPE=en_CA.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_CA.UTF-8        LC_COLLATE=en_CA.UTF-8
 [5] LC_MONETARY=en_CA.UTF-8    LC_MESSAGES=en_CA.UTF-8
 [7] LC_PAPER=en_CA.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] parallel  stats4    stats     graphics  grDevices utils     datasets
[8] methods   base

other attached packages:
 [1] infercnv_1.9.1       future_1.21.0        GenomicRanges_1.40.0
 [4] GenomeInfoDb_1.24.2  IRanges_2.22.2       S4Vectors_0.26.1
 [7] BiocGenerics_0.34.0  SeuratObject_4.0.2   Seurat_4.0.3
[10] Signac_1.3.0         data.table_1.13.0    forcats_0.5.0
[13] stringr_1.4.0        dplyr_1.0.0          purrr_0.3.4
[16] readr_1.3.1          tidyr_1.1.0          tibble_3.0.3
[19] ggplot2_3.3.2        tidyverse_1.3.0

loaded via a namespace (and not attached):
  [1] reticulate_1.16             tidyselect_1.1.0
  [3] htmlwidgets_1.5.1           grid_4.0.0
  [5] docopt_0.7.1                BiocParallel_1.22.0
  [7] Rtsne_0.15                  munsell_0.5.0
  [9] codetools_0.2-16            ica_1.0-2
 [11] miniUI_0.1.1.1              withr_2.2.0
 [13] argparse_2.0.3              colorspace_1.4-1
 [15] Biobase_2.48.0              rstudioapi_0.11
 [17] SingleCellExperiment_1.10.1 ROCR_1.0-11
 [19] tensor_1.5                  listenv_0.8.0
 [21] slam_0.1-48                 GenomeInfoDbData_1.2.3
 [23] polyclip_1.10-0             farver_2.0.3
 [25] TH.data_1.0-10              coda_0.19-3
 [27] parallelly_1.27.0           vctrs_0.3.8
 [29] generics_0.0.2              lambda.r_1.2.4
 [31] fastcluster_1.1.25          lsa_0.73.2
 [33] ggseqlogo_0.1               R6_2.4.1
 [35] doParallel_1.0.15           locfit_1.5-9.4
 [37] reshape_0.8.8               bitops_1.0-6
 [39] spatstat.utils_2.1-0        DelayedArray_0.14.1
 [41] assertthat_0.2.1            promises_1.1.1
 [43] scales_1.1.1                multcomp_1.4-16
 [45] gtable_0.3.0                globals_0.14.0
 [47] goftest_1.2-2               sandwich_3.0-0
 [49] rlang_0.4.11                RcppRoll_0.3.0
 [51] splines_4.0.0               lazyeval_0.2.2
 [53] rjags_4-10                  spatstat.geom_2.1-0
 [55] broom_0.7.0                 reshape2_1.4.4
 [57] abind_1.4-5                 modelr_0.1.8
 [59] backports_1.1.8             httpuv_1.5.4
 [61] tools_4.0.0                 gplots_3.0.4
 [63] ellipsis_0.3.1              spatstat.core_2.1-2
 [65] RColorBrewer_1.1-2          phyclust_0.1-30
 [67] ggridges_0.5.2              Rcpp_1.0.5
 [69] plyr_1.8.6                  zlibbioc_1.34.0
 [71] RCurl_1.98-1.3              rpart_4.1-15
 [73] deldir_0.1-28               pbapply_1.4-2
 [75] cowplot_1.0.0               zoo_1.8-8
 [77] SummarizedExperiment_1.18.2 haven_2.3.1
 [79] ggrepel_0.8.2               cluster_2.1.0
 [81] fs_1.5.0                    magrittr_1.5
 [83] futile.options_1.0.1        scattermore_0.7
 [85] lmtest_0.9-37               reprex_0.3.0
 [87] RANN_2.6.1                  mvtnorm_1.1-1
 [89] SnowballC_0.7.0             fitdistrplus_1.1-1
 [91] matrixStats_0.58.0          hms_0.5.3
 [93] patchwork_1.0.1             mime_0.9
 [95] xtable_1.8-4                sparsesvd_0.2
 [97] readxl_1.3.1                gridExtra_2.3
 [99] compiler_4.0.0              KernSmooth_2.23-17
[101] crayon_1.3.4                htmltools_0.5.1.1
[103] mgcv_1.8-31                 later_1.1.0.1
[105] libcoin_1.0-8               lubridate_1.7.9
[107] DBI_1.1.0                   tweenr_1.0.1
[109] formatR_1.7                 dbplyr_1.4.4
[111] MASS_7.3-51.6               rappdirs_0.3.1
[113] Matrix_1.3-4                cli_2.0.2
[115] gdata_2.18.0                igraph_1.2.5
[117] pkgconfig_2.0.3             coin_1.4-1
[119] plotly_4.9.2.1              spatstat.sparse_2.0-0
[121] xml2_1.3.2                  foreach_1.5.0
[123] XVector_0.28.0              rvest_0.3.6
[125] digest_0.6.25               sctransform_0.3.2
[127] RcppAnnoy_0.0.18            spatstat.data_2.1-0
[129] Biostrings_2.56.0           cellranger_1.1.0
[131] leiden_0.3.3                fastmatch_1.1-0
[133] edgeR_3.30.3                uwot_0.1.10
[135] gtools_3.8.2                modeltools_0.2-23
[137] shiny_1.5.0                 Rsamtools_2.4.0
[139] lifecycle_1.0.0             nlme_3.1-147
[141] jsonlite_1.7.0              futile.logger_1.4.3
[143] limma_3.44.3                viridisLite_0.3.0
[145] fansi_0.4.1                 pillar_1.4.6
[147] lattice_0.20-41             fastmap_1.0.1
[149] httr_1.4.2                  survival_3.1-12
[151] glue_1.4.1                  qlcMatrix_0.9.7
[153] png_0.1-7                   iterators_1.0.12
[155] ggforce_0.3.2               stringi_1.4.6
[157] blob_1.2.1                  caTools_1.18.0
[159] irlba_2.3.3                 future.apply_1.6.0
[161] ape_5.4
GeorgescuC commented 3 years ago

Hi @tinakeshav ,

If you take a look at the plots generated by steps 15 (residual expression) and 17 (HMM predictions), do they look like the process up to those steps ran fine? And more specifically, do you have any CNVs predicted by the HMM? This error might occur if no CNVs are detected by the HMM (although I think we should have fixed that, something may have been missed). If that is the case, do the predictions seem to match the residual expression? You have run infercnv with no subclutering and without clustering by groups, so if there are subclones or different samples/cell population altogether, prediction cannot be accurate as a single set of prediction is given for all cells and so only the most common signal (or lack of) will be represented.

Regards, Christophe.