Open ksmetz opened 1 year ago
Hi Katie!
You are correct, this kind of plot is not possible with the current plotHicTriangle
function. Intrachromosomal plots are definitely tricky, so right now it's only supported with plotHicSquare
.
In theory you could hack plotHicSquare
to rotate to fit into that crafty application, although this would prevent appropriate clipping of the viewport and so you might get some extra data. To do so, you would need to go into the plot object to the grobs, then the vp, and change the "angle"
. This will also do some funny stuff to the coordinates but if you really need this sooner than later, you can definitely go ahead and mess around with it.
In general, we definitely need more formal intrachromosomal support, but if you think these would be helpful features I'm happy to work on them!
Nicole
Hi again Nicole! :) hah
Thanks for the suggestion! I might try the angle trick to see if I can get something like that working, and I'll let you know how it goes if so!
To clarify, I was trying to make these plots more as a random thing to try/a distraction from other work I should be doing haha, it's definitely not something I really NEED probably at all. But it had come to mind because I had been to a few talks lately that showed data in this way so it had me curious if it was possible with plotgardener (and I do have some SV breakfinder results in my data so I have a set of translocation regions I could test it out with).
So I guess in general, I'm definitely not trying to convince you to launch into a whole bunch of intrachromosomal support functions (because again that seems like a whole big project potentially) with this issue. I'd more base it off of whether or not there seems to be some number of potential pg users that actually do that kind of thing regularly that would need those sorts of functions, but I've got no clue actually how desirable those sorts of functions would be. I'm also sure there's other ways to plot this sort of data that ARE already pg-compatible, so people actually in those fields might not even have this issue. So like, huge grain of salt this is not really my area of expertise and I don't know what I'm talking about lol
This is only tangentially related, but also - can plotgardener make whole-genome Hi-C plots like this? Technically another kind of intra-chromosomal plot so I figure maybe this thread isn't a bad place to ask. I feel like I vaguely remember seeing plots like this but maybe I'm just thinking of Juicebox. I guess it's also technically possible with a weird quilt of plotHicSquare
plots haha, although the chromosomes would be scaled differently. I'm actually probably more likely to use a plot like this than the one I originally posted about.
haha we definitely have talked about more intrachromosomal and genome-wide features but it could definitely turn into a whole can of worms. I'm not sure what other packages exist that handle this kind of data, but if it would get more people to use pg in their talks I would love to do it 😂
I think technically plotgardener can make whole-genome Hi-C plots, but also not in a super straightforward way using multiple plots. I think @EricSDavis made one at some point? Again, it's something we've definitely talked about but haven't prioritized implementing.
But yes, let me know how the manual rotation fares for you and if you need any more help!
Nicole
Found some old code in a slack channel that I used to make a genome-wide Hi-C plot! This code replicates the Juicebox genome-wide plots by using a super-special-secret resolution value of 6418. See example code below:
## Load required libraries
library(strawr)
library(ggplot2)
## Extract data for all chromosomes
dat <-
strawr::straw(norm = "NONE",
fname = "data/raw/hic/MEGA_K562_WT_4320_inter.hic",
chr1loc = "ALL",
chr2loc = "ALL",
unit = "BP",
binsize = 6418,
matrix = "observed") |>
`colnames<-`(c("ALL1", "ALL2", "counts"))
## Fill in lower diagonal
dat <-
rbind(dat, cbind(ALL1 = dat$ALL2,
ALL2 = dat$ALL1,
counts = dat$counts))
## Visualize
ggplot(data = dat,
aes(x = as.factor(ALL1), y = as.factor(ALL2), fill = counts)) +
scale_fill_gradientn(colors = marinerSea,
limits = c(0, 20000), #83704
oob = scales::squish,
na.value = marinerSea[1])+
geom_tile() +
theme_void() +
theme(aspect.ratio = 1)
Here's also some code for adjusting the grobs for drawing whole-chromosome interchromosomal plots with plotgardener so that they are scaled correctly when plotted beside intrachromosomal plots:
chrA <- 2
chrB <- 3
## Fractional height
chrRatio <- seqlengths(seqinfo(txdb))[chrB]/seqlengths(seqinfo(txdb))[chrA]
## Chromosomes A and B
inter <-
plotHicSquare(data = "data/raw/hic/MEGA_K562_WT_4320_inter.hic",
params = p,
chrom = as.character(chrA),
chromend = seqlengths(seqinfo(txdb))[chrA],
altchrom = as.character(chrB),
altchromstart = 1,
altchromend = seqlengths(seqinfo(txdb))[chrB],
x = p$x + p$width,
y = 0.5,
half = "bottom",
just = c("left", "top"),
draw = FALSE)
## Customize width (since chromosome B is shorter)
inter$grobs$vp$width <- unit(p$width*chrRatio, "inches")
name <- inter$grobs$childrenOrder[2]
inter$grobs$children[[name]]$y <-
inter$grobs$children[[name]]$y*chrRatio
inter$grobs$children[[name]]$x <-
inter$grobs$children[[name]]$x/chrRatio
## Draw
grid.draw(inter$grobs)
Which produces a plot like this (code for normal chromosome not included):
I'm sorry I never properly responded to this but WOW thank you so much Eric and Nicole!!! This was super helpful and also kind of blew my mind, never would have thought to try a super-special-secret resolution. I feel like I'm looking up old video game cheat codes on GameFAQs lol
I audibly said "no waaaaay" like a huge nerd when I saw this, felt terrible that I just noticed I never actually replied to tell you thank you. But thank you both! This serves my needs perfectly
Hi plotgardener team! :)
I was recently interested in surveying Hi-C regions with intrachromosomal translocations. I have often seen these represented in triangle plot form, as below (Wang et al 2021):
First, my understanding was that this kind of plot would not be possible with the current
plotHicTriangle
function; is that correct?Second, I thought maybe you could recreate a plot like this using crafty application of existing functions: I know that plotgardener can handle the 3 sections of this plot independently (
plotHicTriangle
to make the bottom 2 triangles for region 1 and region 2, andplotHicSquare
can make the intrachromosomal square part of the plot using both region 1 and region 2 with thealtchrom
parameters). However, I'm not sure if it is possible to rotate a square plot 45 degrees in order to place it between 2 triangle plots as would be necessary for that approach?In general, I'm wondering is such a plot is possible to stitch together with existing plotgardener functions, or if it's something that would require further intrachromosomal support? I do feel like it could be a huge can of worms potentially (some intrachromosomal plots I've seen get much more complex, with more than 2 regions, etc.) so I understand if it's just ultimately a limitation of the package.
Thanks for all your hard work and a beautiful package! :)
-Katie