caravagnalab / CNAqc

CNAqc - Copy Number Alteration (CNA) Quality Check package
GNU General Public License v3.0
17 stars 8 forks source link

highlighting regions of interest #27

Closed pawanchk closed 1 year ago

pawanchk commented 1 year ago

Hi,

I obtained the copy number plot using plot_segments function, now I want to highlight certain regions of interest so I tried the geom_rect function but the highlight does not show up. Can I please know what is the best way to highlight certain regions of interest ?

This is what I have tried - base_plot + geom_rect(genes, mapping=aes(xmin=geneStart, xmax=geneEnd, ymin=-Inf, ymax=Inf, fill=geneName)

where genes is a data frame containing regions of interest to be highlighted - it has 4 columns - chr, geneStart, geneEnd, geneName

Any advice would be very helpful.

Best Regards, Pawan

Militeee commented 1 year ago

Hi @pawanchk, So I think the main problem is with the coordinates of the gene, when we plot we generally use absolute coordinates. We have this function to convert from relative to absolute, that you can call with CNAqc:::relative_to_absolute_coordinates. Anyway, it works on a CNAqc object but you can easily adapt it to your table. THa you use the transformed start and end in the geom:rect. Let me know if something else is wrong.

relative_to_absolute_coordinates = function(x, cna)
{
  reference_genome = CNAqc:::get_reference(x$reference_genome)

  vfrom = reference_genome$from
  names(vfrom) = reference_genome$chr

  cna %>%
    mutate(from = from + vfrom[chr],
           to = to + vfrom[chr])
}
caravagn commented 1 year ago

I think this should be closed and re-opened if required.