broadinstitute / infercnv

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

Question about reload infercnv_obj #405

Closed Fish-on-plate closed 2 years ago

Fish-on-plate commented 2 years ago

Hello, It's quite an excellent tool. I wonder whether there is any way to reload infercnv_obj from former outputs ? It'll takes a long time to rerun for a further plotting adjustment. Thanks in advance.

GeorgescuC commented 2 years ago

Hi @Fish-on-plate ,

If you are trying to run infercnv with the same options, it should automatically try to reload the last backup object. In the case you have changed some of the options, it will check at what step the difference in arguments become relevant and reload the object from the previous step. The goal was to have this reload be fully automated, but there could always be cases where it doesn't behave as expected.

If you already have a final infercnv object and want to directly experiment with the plotting functionnality, you can use: infercnv_obj = readRDS("output_folder/run.final.infercnv_obj")

Then run the plotting calls you want.

Regards, Christophe.

Van1yu3 commented 2 years ago

Hi @GeorgescuC ,

May I ask if I already have a final infercnv object infercnv_obj = readRDS("output_folder/run.final.infercnv_obj"), and I would like to change the annotations_file in the CreateInfercnvObject function to produce a different CNV plot, what should I do with minimal rerun of the whole program?

For example, if previously I run with the argument annotations_file=fileA:

infercnv_obj = CreateInfercnvObject(raw_counts_matrix=raw_counts_matrix,
                                    annotations_file=fileA,
                                    delim="\t",
                                    gene_order_file=gene_order_file,
                                    ref_group_names=c("groupA"))
infercnv_obj = infercnv::run(infercnv_obj,
                             cutoff=0.1,  
                             out_dir=".", 
                             cluster_by_groups=T,
                             denoise=T,
                             HMM=T,
                             output_format="pdf"
                             )

and then I would like to get another CNV plot with annotations_file=fileB, theoretically I don't need to run the same code again, because the only difference is the annotation file. I have tried changing only the observation_grouped_cell_indices slot with the following code:

infercnv_obj = readRDS("output_folder/run.final.infercnv_obj")
infercnv_obj2 = CreateInfercnvObject(raw_counts_matrix=raw_counts_matrix,
                                    annotations_file=fileB,
                                    delim="\t",
                                    gene_order_file=gene_order_file,
                                    ref_group_names=c("groupA"))
infercnv_obj@observation_grouped_cell_indices <- infercnv_obj2@observation_grouped_cell_indices
plot_cnv(infercnv_obj, ,out_dir=".",output_format="pdf")

But error occurs:

ERROR [2022-04-23 22:50:49] Unexpected error, should not happen.
Error in .plot_cnv_observations(infercnv_obj = infercnv_obj, obs_data = obs_data,  :
  Error
GeorgescuC commented 2 years ago

Hi @Van1yu3 ,

Your attempt to replace the data in the infercnv_obj@observation_grouped_cell_indices slot using a new object is the good start to do this, but you will also need to clear out the clustering information stored in the infercnv_obj@tumor_subclusters slot by setting it to NULL as there is conflicting data stored there.

Are the reference cells the same for your second set of annotations? If not you will also need to transfer the data from the infercnv_obj2@reference_grouped_cell_indices to the processed one.

Regards, Christophe.