broadinstitute / infercnv

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

Plot cnv references #267

Closed jingyu9603 closed 2 years ago

jingyu9603 commented 4 years ago

Hi! I'd like to use infercnv to distinguish between malignant and nonmalignant cells.Code I used in docker mirror are as follows :

options(error = function() traceback(2))

library("infercnv")

infercnv_obj = CreateInfercnvObject(raw_counts_matrix="Pt1_Epithelial_T_exprMatrix_RNA.txt",
                                    annotations_file="Pt1_Epithelial_T_cellAnnota.txt",
                                    delim="\t",
                                    gene_order_file="gene_pos.txt",
                                    ref_group_names=c("T cell"))

out_dir="Pt1_inferCNV_outdir_Epithelial_T"

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, 
                             cluster_by_groups=FALSE, 
                             k_obs_groups=2,
                 plot_steps=FALSE,
                             denoise=TRUE,
                             HMM=TRUE,
                 analysis_mode="subclusters",
                 tumor_subcluster_pval=0.05,
                 num_threads=8
                             )

All the previous steps are working properly, but by the time the plot_cnv_references went wrong. The info like the follows:

INFO [2020-10-21 11:44:36] plot_cnv_observations:Writing observation data to Pt1_in  

ferCNV_outdir_Epithelial_T/infercnv.preliminary.observations.txt  

INFO [2020-10-21 11:44:46] plot_cnv_references:Start  

INFO [2020-10-21 11:44:46] Reference data size: Cells= 11431 Genes= 5511  

ERROR [2020-10-21 11:44:46] Unexpected error, should not happen.  

Error in .plot_cnv_references(infercnv_obj = infercnv_obj, ref_data = ref_data_t,:  

  Error  

Calls: <Anonymous> -> plot_cnv -> .plot_cnv_references  

5: (function ()  

   traceback(2))()  

4: stop("Error")  

3: .plot_cnv_references(infercnv_obj = infercnv_obj, ref_data = ref_data_t,  

       ref_groups = ref_groups, name_ref_groups = name_ref_groups,  

       cluster_references = cluster_references, hclust_method = hclust_method,  

       grouping_key_coln = grouping_key_coln[2], col_pal = custom_pal,  

       contig_seps = col_sep, file_base_name = out_dir, do_plot = !is.na(output_format),  

       output_filename_prefix = output_filename, cnv_ref_title = ref_title,  

       breaksList = breaksList_t, gene_position_breaks = gene_position_breaks,  

       x.center = x.center, layout_add = TRUE, useRaster = useRaster)  

2: plot_cnv(infercnv_obj, k_obs_groups = k_obs_groups, cluster_by_groups = cluster_by_groups,  

       cluster_references = cluster_references, out_dir = out_dir,  

       title = "Preliminary infercnv (pre-noise filtering)", output_filename = "infercnv.preliminary",  

       output_format = output_format, write_expr_matrix = TRUE,  

       png_res = png_res, useRaster = useRaster)  

1: infercnv::run(infercnv_obj, cutoff = 0.1, out_dir = out_dir,  

       cluster_by_groups = FALSE, k_obs_groups = 2, plot_steps = FALSE,  

       denoise = TRUE, HMM = TRUE, analysis_mode = "subclusters",  

       tumor_subcluster_pval = 0.05, num_threads = 8)  

Documents in the out_dir are as follows : image infercnv.preliminary.png below : image I don't know what went wrong in the middle, can you help me ?

kabanowa47 commented 3 years ago

Hi! Would you like to show how is the structure of your annotation file Pt1_Epithelial_T_cellAnnota.txt please? It will be very helpful for me to help you somehow or find the solution of my problem. I have got some other issue that is related to the lack of the sample labels on the plot. May be there is something wrong there in your file or may be in mine. Here is the link to my thread: [https://github.com/broadinstitute/infercnv/issues/265]

Hi! I'd like to use infercnv to distinguish between malignant and nonmalignant cells.Code I used in docker mirror are as follows :

options(error = function() traceback(2))

library("infercnv")

infercnv_obj = CreateInfercnvObject(raw_counts_matrix="Pt1_Epithelial_T_exprMatrix_RNA.txt",
                                    annotations_file="Pt1_Epithelial_T_cellAnnota.txt",
                                    delim="\t",
                                    gene_order_file="gene_pos.txt",
                                    ref_group_names=c("T cell"))

out_dir="Pt1_inferCNV_outdir_Epithelial_T"

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, 
                             cluster_by_groups=FALSE, 
                             k_obs_groups=2,
               plot_steps=FALSE,
                             denoise=TRUE,
                             HMM=TRUE,
               analysis_mode="subclusters",
               tumor_subcluster_pval=0.05,
               num_threads=8
                             )

All the previous steps are working properly, but by the time the plot_cnv_references went wrong. The info like the follows:

INFO [2020-10-21 11:44:36] plot_cnv_observations:Writing observation data to Pt1_in  

ferCNV_outdir_Epithelial_T/infercnv.preliminary.observations.txt  

INFO [2020-10-21 11:44:46] plot_cnv_references:Start  

INFO [2020-10-21 11:44:46] Reference data size: Cells= 11431 Genes= 5511  

ERROR [2020-10-21 11:44:46] Unexpected error, should not happen.  

Error in .plot_cnv_references(infercnv_obj = infercnv_obj, ref_data = ref_data_t,:  

  Error  

Calls: <Anonymous> -> plot_cnv -> .plot_cnv_references  

5: (function ()  

   traceback(2))()  

4: stop("Error")  

3: .plot_cnv_references(infercnv_obj = infercnv_obj, ref_data = ref_data_t,  

       ref_groups = ref_groups, name_ref_groups = name_ref_groups,  

       cluster_references = cluster_references, hclust_method = hclust_method,  

       grouping_key_coln = grouping_key_coln[2], col_pal = custom_pal,  

       contig_seps = col_sep, file_base_name = out_dir, do_plot = !is.na(output_format),  

       output_filename_prefix = output_filename, cnv_ref_title = ref_title,  

       breaksList = breaksList_t, gene_position_breaks = gene_position_breaks,  

       x.center = x.center, layout_add = TRUE, useRaster = useRaster)  

2: plot_cnv(infercnv_obj, k_obs_groups = k_obs_groups, cluster_by_groups = cluster_by_groups,  

       cluster_references = cluster_references, out_dir = out_dir,  

       title = "Preliminary infercnv (pre-noise filtering)", output_filename = "infercnv.preliminary",  

       output_format = output_format, write_expr_matrix = TRUE,  

       png_res = png_res, useRaster = useRaster)  

1: infercnv::run(infercnv_obj, cutoff = 0.1, out_dir = out_dir,  

       cluster_by_groups = FALSE, k_obs_groups = 2, plot_steps = FALSE,  

       denoise = TRUE, HMM = TRUE, analysis_mode = "subclusters",  

       tumor_subcluster_pval = 0.05, num_threads = 8)  

Documents in the out_dir are as follows : image infercnv.preliminary.png below : image I don't know what went wrong in the middle, can you help me ?

jingyu9603 commented 3 years ago

Hi,@kabanowa47 The structure of your annotation file Pt1_Epithelial_T_cellAnnota.txt is as follows: ![Uploading image.png…]()

GeorgescuC commented 3 years ago

Hi @jingyu9603 ,

The annotation file does not seem to have completed uploading before you posted your last message.

Which version of infercnv are you using?

Regards, Christophe.

jingyu9603 commented 3 years ago

Hi @GeorgescuC , Think you for your reply! The structure of my annotation file Pt1_Epithelial_T_cellAnnota.txt is as follows: image

The version of infercnv is '1.5.0'

kabanowa47 commented 3 years ago

Hi, please be sure that you use sep="\t" between these two columns. Best!

newbieMars commented 3 years ago

Hi @jingyu9603 ,

Did you resolve your problem? Because since, I've upgraded to infercnv ( I've tested versions from 1.5.0 to 1.7.1 from github master branch) and R (4.0.3, from rocker-versioned2 tidyverse::latest docker image) and I'm experiencing the same issue. While with infercnv 1.2.2 and R 3.6.3 (rocker-versioned tidyverse::3.6.3), everything works fine, and I've all the output generated. I've also tried to rename my infercnv object between creating the object (infercnv_obj) and running the object (infer_cnv_run_obj), as suggested when doing multiple runs #206 (even if it's not my case), but it still not resolve the problem. My annotation file is well written (with tabulation), and as it works with infercnv 1.2.2, it's a kind of positive control.

Thanks

jingyu9603 commented 3 years ago

Hi @newbieMars , I haven't solved the problem for the moment.

newbieMars commented 3 years ago

Hi @jingyu9603 ,

You should try to run infercnv with cluster_by_groups=TRUE parameter. I can't explain why, but I've tryed to turn on/off several parameter when running infercnv. And cluster_by_groups=FALSE leads to this error message (I've tested with the latest version of the tool). I've opened a new issue to that. If you remove the cluster ID of your cells, It should be considered as one group (thus no difference between cluster_by_groups=TRUE or cluster_by_groups=FALSE). And you will be able to cross the information of gene_expression_clusters and cnv_significant_subclusters through cell_ID.

Best

GeorgescuC commented 3 years ago

Hi,

Using the information about how to reproduce the issue in https://github.com/broadinstitute/infercnv/issues/273 , I have made changes to the code that are available on the master branch here. Could you try the changes and see if all the issues are solved? It should both fix what groups of references the subclustering is run on and allow results generated using older versions that have the issue to be plotted without changing settings/data.

You can follow the install instructions from a github branch on the wiki .

Regards, Christophe.