Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to generate a figure like the Supplementary figure 4C in your paper? #272

Closed
YiweiNiu opened this issue Jul 8, 2021 · 4 comments
Closed

Comments

@YiweiNiu
Copy link

YiweiNiu commented Jul 8, 2021

Hi,

I would like to plot a figure like the Supplementary figure 4C in your bioRxiv paper? Could you please give me some guides to do that?

Thanks,
Yiwei

@teunbrand
Copy link
Collaborator

teunbrand commented Jul 8, 2021

Hello,

That figure is the result of an ATA from a series of KO vs WT comparisons. Here is an example for the test data. We make a copy of the test data to show how to do it for multiple samples, and because it is a copy, the log2 fold change will show as 0.

library(GENOVA)

exp <- get_test_data("40k")
explist <- list(dat1 = exp, dat2 = exp)

# Call TADs with insulation score
ins <- insulation_score(explist)
tads <- call_TAD_insulation(ins, min_strength = 0)[[1]]

# Feed TADs to ATA
ata <- ATA(explist, tads)
visualise(ata, colour_lim = c(0, 600))

Created on 2021-07-08 by the reprex package (v1.0.0)

@YiweiNiu
Copy link
Author

YiweiNiu commented Jul 8, 2021

Thank you for your quick reply!

I could run the ATA analysis successfully on my data. Thanks to the clear documentation of GENOVA!

But I do not know how to plot a figure like this, which is from the Supplementary figure 4C of your paper.

图片

@teunbrand
Copy link
Collaborator

teunbrand commented Jul 8, 2021

I think @robinweide might now the exact details, but I presume it would have been something like the following. Example assumes you've run the previous chunk posted above.

library(data.table)
library(ggplot2)

# Melt array
df <- data.table(
  x = as.vector(slice.index(ata$signal, 1)),
  y = as.vector(slice.index(ata$signal, 2)),
  sample = as.vector(slice.index(ata$signal, 3)),
  value = as.vector(ata$signal)
)
# Calculate distance (unit is arbitrary due to ATA)
df[, dist := x - y]
# Take averages per off-diagonal band
df <- df[, list(value = mean(value)), by = c("dist", "sample")]
# Split by sample
df <- split(df, df$sample)

# Adjust sample 2 a bit so that a difference will show
# Don't do this with real data!
df[[2]][, value := sqrt(value)]
# Recombine the two samples, if you have more, this needs to be repeated for all samples
df <- df[[1]][df[[2]], on = c("dist")]
# Convert distance to TAD units
df[, dist := scales::rescale(dist, to = c(-2, 2))]

# Plot stuff
ggplot(df, aes(dist, value / i.value)) +
  geom_line(aes(colour = sample))

@YiweiNiu
Copy link
Author

YiweiNiu commented Jul 8, 2021

Bravo! Thank you very much. Now I understand the structure of ATA$signal.

@YiweiNiu YiweiNiu closed this as completed Jul 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants