Answers.Body: <p>If you haven't already, I recommend checking out the infercnv YouTube tutorial (<a href="https://github.com/broadinstitute/inferCNV/wiki/Running-InferCNV" rel="nofollow noreferrer">https://github.com/broadinstitute/inferCNV/wiki/Running-InferCNV</a>) for detailed instructions on running InferCNV. Additionally, you can explore Uphyloplot2 (<a href="https://github.com/harbourlab/uphyloplot2" rel="nofollow noreferrer">https://github.com/harbourlab/uphyloplot2</a>) for building a tree from the output generated by InferCNV.</p>
  <p>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 &quot;normal&quot; reference. However, considering that InferCNV assumes a normal diploid reference, I'm now uncertain if using the untreated control would be appropriate.</p>
  <p>Please let me know your thoughts, any help would be much appreciated!</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-07-04T09:54:04.310Z
Answers.LastActivityDate: 2023-07-04T09:54:04.310Z
Answers.UserDisplayName: Silvia-Bio
Answers.Body: <p>Personally I would not use <code>intercnv_obj</code> throughout, because is there was a bug in line 2, i.e. using <code>=</code> instead of <code>&lt;-</code> then the created <code>intercnv_obj</code> might be trying to be passed into <code>plot_cnv</code>.</p>
  <p>Could you try</p>
  <pre><code>data(infercnv_obj) 
  
  plot_cnv(
    infercnv_obj,
    out_dir = &quot;.&quot;,
    title = &quot;inferCNV&quot;,
    obs_title = &quot;Observations (Cells)&quot;,
    ref_title = &quot;References (Cells)&quot;,
    cluster_by_groups = TRUE,
    cluster_references = TRUE,
    plot_chr_scale = FALSE,
    chr_lengths = NULL,
    k_obs_groups = 1,
    contig_cex = 1,
    x.center = mean(infercnv_obj@expr.data),
    x.range = &quot;auto&quot;,
    hclust_method = &quot;ward.D&quot;,
    custom_color_pal = NULL,
    color_safe_pal = FALSE,
    output_filename = &quot;infercnv&quot;,
    output_format = &quot;png&quot;,
    png_res = 300,
    dynamic_resize = 0,
    ref_contig = NULL,
    write_expr_matrix = FALSE,
    write_phylo = FALSE,
    useRaster = TRUE
  )
  </code></pre>
  <hr />
  <p>If the above doesn't work ...</p>
  <p>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:</p>
  <p><a href="https://github.com/broadinstitute/infercnv/issues/415" rel="nofollow noreferrer">https://github.com/broadinstitute/infercnv/issues/415</a></p>
  <p>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.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-19T16:53:21.227Z
Answers.Text: Hi , I get an error when running that. I updated my question with the message.
Answers.UserDisplayName: mmpp
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-22T14:44:51.173Z
Answers.Text: @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 ... https://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 :-)
Answers.UserDisplayName: M__
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-22T16:46:46.530Z
Answers.Text: What did you change?
Answers.UserDisplayName: mmpp
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-22T16:47:39.923Z
Answers.Text: `data(infercnv_obj)` prior `plot_cnv`
Answers.UserDisplayName: M__
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-06-22T08:39:03.073Z
Answers.Text: 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.
Answers.UserDisplayName: user438383
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-19T02:38:49.023Z
Answers.LastActivityDate: 2023-07-04T14:57:28.973Z
Answers.LastEditDate: 2023-07-04T14:57:28.973Z
Answers.UserDisplayName: M__
Body: <p>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 <code>infercnv</code> package.</p>
  <p>I've followed the tutorial:</p>
  <pre><code># data matrix
  counts_matrix &lt;- scData@assays$RNA@counts
  meta = data.frame(labels = Idents(scData), row.names = names(Idents(scData)))
  unique(meta$labels) # check the cell labels
  </code></pre>
  <pre><code># Create the infercnv object
  infercnv_obj &lt;- CreateInfercnvObject(raw_counts_matrix = counts_matrix,
                                       annotations_file = meta,
                                       delim = &quot;\t&quot;,
                                       gene_order_file = &quot;hg38_gencode_v27.txt&quot;,
                                       ref_group_names = NULL)
  </code></pre>
  <pre><code># 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=&quot;output_dir&quot;,  # dir is auto-created for storing outputs
                               cluster_by_groups=T,   # cluster
                               denoise=T,
                               HMM=T
                               )
  </code></pre>
  <p>Now, I'm not sure how to plot the results. Any help would be appreciated.</p>
  <p>When running the below recommendation I get this:</p>
  <pre><code>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.
  &lt;sparse&gt;[ &lt;logic&gt; ]: .M.sub.i.logical() maybe inefficient
  Warning: sparse-&gt;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.
  </code></pre>
  
Tags: <r><single-cell><cnv>
Title: Plotting infercnv results
ThreadText: # Plotting infercnv results
  
  (Asked by: username_0 on 2023-05-18)
  
  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.
  
  ```
  
  **Tags:** r, single-cell, cnv
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2023-07-04. Score: 0
  
  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!
  
  
  ---
  
  ### Answer by username_2 on 2023-05-19. Score: 0
  
  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(infercnv_obj@expr.data),
    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.
  
  > **Comments:**
  > **username_0**: Hi , I get an error when running that. I updated my question with the message.  
  > **username_2**: @username_0 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 ... https://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 :-)  
  > **username_0**: What did you change?  
  > **username_2**: `data(infercnv_obj)` prior `plot_cnv`  
  > **username_3**: 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.  
  
  ---
  
  