broadinstitute / infercnv

Inferring CNV from Single-Cell RNA-Seq
Other
558 stars 166 forks source link

Error validating infercnv_obj "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" #277

Closed kevin198930 closed 2 years ago

kevin198930 commented 3 years ago

Hello,

I have been trying to get inferCNV to run on my downsampled Seurat object, but I have been running into the following error that I presented in the title of this issue post. I am running infercnv version 1.6.0. My original Seurat object had over 22k cells, so in my script I downsampled to 5k cells. After downsampling and running the script again I ran into an error during the "-hspike modeling of normalsToUse" step. I discovered after researching the issue on this GitHub that this error occurs when you have less than 10 cells assigned to a particular annotation cell type. Here is the table of the cell types from my annotation file:

Astrocyte 3869 Chondrocytes 4 DC 1 Endothelial_cells 120 Fibroblasts 12 Macrophage 21 MSC 4 Neurons 98 Osteoblasts 1 Smooth_muscle_cells 64
T_cells 1 Tissue_stem_cells 769 Unclassified 36

I removed all the cells from these cell type groups from my cell_annotations.txt file that were < 10 cells, but I did not remove the cells from the downsampled R object. I don't know if this is necessary. My cell_annotations file contains only the cell barcode in the first column (eg ATGAGGGTCGTCAACA_15) and the second column contains the cell types that remained after my removal (eg. Astrocyte, Tissue_stem_cells, Endothelial_cells, Smooth_muscle_cells, Neurons, Unclassified, Fibroblasts, Macrophage). I have no reference group names so I set this parameter to NULL as recommended in the CreateInfercnvObject() function.

From there I ran my script again and generated the Error:

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: ... initializeObject -> initializeObject -> Execution halted

The beginning of my script is as follows:

object_downsample <- subset(tumor_subset, cells = sample(Cells(tumor_subset), 5000))

counts_matrix <- GetAssayData(object_downsample, slot="counts")

infercnv_obj <- CreateInfercnvObject(raw_counts_matrix= counts_matrix, annotations_file="downsampled_tumor_cell_annotations_for_inferCNV.txt", delim="\t", gene_order_file= "gene_pos_update_2.txt", ref_group_names= NULL)

print(lengths(infercnv_obj@reference_grouped_cell_indices))

perform infercnv operations to reveal cnv signal

infercnv_obj = infercnv::run(infercnv_obj, cutoff=0.1, # use 1 for smart-seq, 0.1 for 10x-genomics out_dir="output_dir", # dir is auto-created for storing outputs cluster_by_groups=F, # cluster denoise=T, HMM=T )

I noticed as the script was running the output for print(lengths(infercnv_obj@reference_grouped_cell_indices)) was integer(0). Also, the first messages that appeared when I started the run were:

Warning messages: 1: undefined slot classes in definition of "XRaw": elementMetadata(class "DataTable_OR_NULL") 2: undefined slot classes in definition of "XInteger": elementMetadata(class "DataTable_OR_NULL") 3: undefined slot classes in definition of "XDouble": elementMetadata(class "DataTable_OR_NULL") 4: multiple methods tables found for 'rowRanges'

Finally the execution halted with the error:

STEP 18: Run Bayesian Network Model on HMM predicted CNV's

INFO [2020-12-14 18:30:18] Creating the following Directory: output_dir/BayesNetOutput.HMMi6.hmm_mode-samples INFO [2020-12-14 18:30:18] Initializing new MCM InferCNV Object. INFO [2020-12-14 18:30:18] 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: ... initializeObject -> initializeObject -> Execution halted

From researching this github I found a related error post: "problem in STEP 13: Run Bayesian Network Model on HMM predicted CNV's #187". It seems the user fixed the issue by replacing the dot operator in the group name. However, none of my cell type annotations have a dot operator and my ref_group_names is set to NULL. I am not sure how to fix this issue and any help would be greatly appreciated! Thanks

lybird300 commented 3 years ago

Hi Kevin, have you figured it out? I believe I encountered the same thing with infercnv_1.2.2. For me, everything worked fine until STEP 18. My run log is attached. Any advice would be appreciated. Thank you! my_infercnv_run_log.txt

GeorgescuC commented 3 years ago

Hi @kevin198930 ,

You should remove from the matrix/object you provide as input the cells that you removed from the annotation file. inferCNV checks that all the cells in the annotation file are in the matrix, but not the other way around so it could lead to unexpected issues. As a note, inferCNV also provided an option "max_cells_per_group" when you create the object to sample at most the given number of cells from each annotation.

The result of print(lengths(infercnv_obj@reference_grouped_cell_indices)) being integer(0) is expected since you have not provided any annotation as a reference. I have however never seen the warning messages you are getting.

Can you please try to rerun inferCNV from the start after having made sure the cells you provide in the matrix are also in the annotations?

Regards, Christophe.