1
$\begingroup$

I'm working with matched single cell data, where we have treated and untreated samples for the same patient. I ran CNV analysis using the infercnv package.

I've followed the tutorial:

# data matrix
counts_matrix <- scData@assays$RNA@counts
meta = data.frame(labels = Idents(scData), row.names = names(Idents(scData)))
unique(meta$labels) # check the cell labels
# Create the infercnv object
infercnv_obj <- CreateInfercnvObject(raw_counts_matrix = counts_matrix,
                                     annotations_file = meta,
                                     delim = "\t",
                                     gene_order_file = "hg38_gencode_v27.txt",
                                     ref_group_names = NULL)
# perform infercnv operations to reveal cnv signal
infercnv_obj = infercnv::run(infercnv_obj,
                             cutoff=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=T,   # cluster
                             denoise=T,
                             HMM=T
                             )

Now, I'm not sure how to plot the results. Any help would be appreciated.

When running the below recommendation I get this:

INFO [2023-05-19 12:49:22] ::plot_cnv:Start
INFO [2023-05-19 12:49:22] ::plot_cnv:Current data dimensions (r,c)=34108,17624 Total=82463956 Min=0 Max=55099.
INFO [2023-05-19 12:49:22] ::plot_cnv:Depending on the size of the matrix this may take a moment.
<sparse>[ <logic> ]: .M.sub.i.logical() maybe inefficient
Warning: sparse->dense coercion: allocating vector of size 4.5 GiBINFO [2023-05-19 12:50:12] plot_cnv(): auto thresholding at: (-2.725632 , 3.000000)
INFO [2023-05-19 12:50:35] plot_cnv_observation:Start
INFO [2023-05-19 12:50:35] Observation data size: Cells= 17624 Genes= 34108
INFO [2023-05-19 12:50:35] clustering observations via method: ward.D
INFO [2023-05-19 12:50:35] Number of cells in group(1) is 331
INFO [2023-05-19 12:50:36] group size being clustered:  331,34108
Error in parallelDist(data_to_cluster, threads = infercnv.env$GLOBAL_NUM_THREADS) : 
  x must be a matrix or a list of matrices.
$\endgroup$

2 Answers 2

0
$\begingroup$

If you haven't already, I recommend checking out the infercnv YouTube tutorial (https://github.com/broadinstitute/inferCNV/wiki/Running-InferCNV) for detailed instructions on running InferCNV. Additionally, you can explore Uphyloplot2 (https://github.com/harbourlab/uphyloplot2) for building a tree from the output generated by InferCNV.

I noticed that you didn't use the untreated sample as the normal reference for your CNV analysis. I'm curious to understand your reasoning behind this. In my case, I also have an untreated sample that isn't diploid, along with two treated samples. Initially, I planned to use the untreated sample as the "normal" reference. However, considering that InferCNV assumes a normal diploid reference, I'm now uncertain if using the untreated control would be appropriate.

Please let me know your thoughts, any help would be much appreciated!

$\endgroup$
0
$\begingroup$

Personally I would not use intercnv_obj throughout, because is there was a bug in line 2, i.e. using = instead of <- then the created intercnv_obj might be trying to be passed into plot_cnv.

Could you try

data(infercnv_obj) 

plot_cnv(
  infercnv_obj,
  out_dir = ".",
  title = "inferCNV",
  obs_title = "Observations (Cells)",
  ref_title = "References (Cells)",
  cluster_by_groups = TRUE,
  cluster_references = TRUE,
  plot_chr_scale = FALSE,
  chr_lengths = NULL,
  k_obs_groups = 1,
  contig_cex = 1,
  x.center = mean([email protected]),
  x.range = "auto",
  hclust_method = "ward.D",
  custom_color_pal = NULL,
  color_safe_pal = FALSE,
  output_filename = "infercnv",
  output_format = "png",
  png_res = 300,
  dynamic_resize = 0,
  ref_contig = NULL,
  write_expr_matrix = FALSE,
  write_phylo = FALSE,
  useRaster = TRUE
)

If the above doesn't work ...

What I think is happening is the input data is the problem. This precise error is already known and was reported on Broad's GitHub here:

https://github.com/broadinstitute/infercnv/issues/415

The responder (Broad Institute) believed it was the version problem, i.e. the version was outdated. However a separate respondee believed it was the input data format and suggested shifting away from a sparse matrix. That would make sense in context to the error being thrown.

$\endgroup$
5
  • 1
    $\begingroup$ Hi , I get an error when running that. I updated my question with the message. $\endgroup$
    – mmpp
    Commented May 19, 2023 at 16:53
  • $\begingroup$ @mmpp I have modified the code and I've included an error log on GitHub. Apologies for the delay. If problem continued I'd recommend referring to this GitHub error log ... github.com/broadinstitute/infercnv/issues/415 or else filing a separate error and referring to this error log. It is not clear whether Broad has fully resolved this - but they already know about it. Good luck :-) $\endgroup$
    – M__
    Commented May 22, 2023 at 14:44
  • $\begingroup$ What did you change? $\endgroup$
    – mmpp
    Commented May 22, 2023 at 16:46
  • $\begingroup$ data(infercnv_obj) prior plot_cnv $\endgroup$
    – M__
    Commented May 22, 2023 at 16:47
  • $\begingroup$ It’s absolutely fine to use = as an assignment operator in R, it’s largely a myth that <- is ‘better’ in some way. It’s certainly not a ‘bug’ by any means. $\endgroup$
    – user438383
    Commented Jun 22, 2023 at 8:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.