Skip to content

Commit

Permalink
improve interactive plot
Browse files Browse the repository at this point in the history
  • Loading branch information
pdimens committed Jul 15, 2024
1 parent 731ed14 commit 1545b58
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/harpy/reports/Leviathan.Rmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: "Leviathan Structural Variant Calling Summary"
title: "Structural Variant Calling Summary (LEVIATHAN)"
date: "`r format(Sys.time(), '%d %b, %Y at %H:%M')`"
output:
flexdashboard::flex_dashboard:
Expand Down
2 changes: 1 addition & 1 deletion src/harpy/reports/LeviathanPop.Rmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: "Leviathan Structural Variant Calling Summary"
title: "Structural Variant Calling Summary (LEVIATHAN)"
date: "`r format(Sys.time(), '%d %b, %Y at %H:%M')`"
output:
flexdashboard::flex_dashboard:
Expand Down
54 changes: 13 additions & 41 deletions src/harpy/reports/Naibr.Rmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: "NAIBR Structural Variant Calling Summary"
title: "Structural Variant Calling Summary (NAIBR)"
date: "`r format(Sys.time(), '%d %b, %Y at %H:%M')`"
output:
flexdashboard::flex_dashboard:
Expand Down Expand Up @@ -267,12 +267,11 @@ You may click on the plot to expand it in your browser window. Clicking it again
out of the zoomed view.

```{r}
justcolors <- c("#4a9fea", "#5a8c84", "#ffd75f")
data.frame(x = 1, y = 1:3, colour = c("Inversion", "Deletion","Duplication")) %>%
color.palette <- c("deletion" = "#5a8c84", "duplication" = "#ffd75f", "inversion" = "#4a9fea")
data.frame(x = 1, y = 1:3, colour = c("inversion", "deletion","duplication")) %>%
ggplot(aes(x, y, fill = colour))+
geom_point(alpha=0, shape = 22, color = "white")+ # completely transparent rectangular point
scale_fill_manual(values=justcolors, drop=FALSE) +
scale_fill_manual(values=color.palette, drop=FALSE) +
guides(fill = guide_legend(override.aes = list(alpha=1, size = 25)))+ # showing the point in the legend
theme(axis.title = element_blank(),
axis.text = element_blank(),
Expand Down Expand Up @@ -388,36 +387,23 @@ allowing you to hover over a variant to provide additional information, includin
number of haplotag barcodes supporting the variant.

```{r colors, echo = FALSE, warning = FALSE, message = FALSE}
color.palette <- c(
"deletion" = "#5a8c84",
"duplication" = "#ffd75f",
"inversion" = "#4a9fea"
)
sv$ystart <- case_when(
sv$SV == "inversion" ~ 0.1,
sv$SV == "duplication" ~ 1.1,
sv$SV == "deletion" ~ 2.1
)
sv$ystop <- sv$ystart + 0.8
figheight <- nrow(fa.sizes) * 160
```

```{r}
l <- list()
#nplotrows <- 0
for (i in 1:nrow(fa.sizes)) {
sv.filt <- sv %>% filter(Chr1 == fa.sizes$contig[i])
sv_stats <- group_by(sv.filt, SV) %>% summarise(n = length(SV))
if (nrow(sv_stats) == 0) {
next
}
plt <- sv.filt %>%
ggplot() +
```{r interactive_plot, fig.height=figheight}
plt <- ggplot(sv) +
geom_rect(
alpha = 0.7,
aes(
xmin = Break1,
xmax = Break2,
xmin = Break1/1000000,
xmax = Break2/1000000,
ymin = ystart,
ymax = ystop,
fill = SV,
Expand All @@ -439,28 +425,14 @@ for (i in 1:nrow(fa.sizes)) {
strip.text = element_text(color = "grey20"),
legend.position = "none",
) +
coord_cartesian(xlim = c(0, NA), expand = F) +
scale_x_continuous(labels = scales::comma) +
coord_cartesian(xlim = c(0, fa.sizes$size[i] + 1), expand = F) +
scale_y_continuous(
breaks = c(0.5, 1.5, 2.5),
labels = c("INV", "DUP", "DEL"),
limits = c(0,3)
) +
xlab("Position (bp)")
annotations <- list(
x = 0.5,
y = 1.05,
text = as.character(fa.sizes$contig[i]),
xref = "paper",
yref = "paper",
xanchor = "center",
yanchor = "bottom",
showarrow = FALSE
)
l[[i]] <- subplot(ggplotly(plt, height = 800, tooltip = "text"))
}
xlab("Position (Mbp)")
# remove null
l <- Filter(Negate(is.null), l)
subplot(l, nrows = length(l) , shareX = FALSE, titleX = TRUE)
ggplotly(plt, height = figheight, tooltip = "text", margin = list(l = 50, r = 50, b = 100, t = 100, pad = 1))
```
2 changes: 1 addition & 1 deletion src/harpy/reports/NaibrPop.Rmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: "NAIBR Structural Variant Calling Summary"
title: "Structural Variant Calling Summary (NAIBR)"
date: "`r format(Sys.time(), '%d %b, %Y at %H:%M')`"
output:
flexdashboard::flex_dashboard:
Expand Down

0 comments on commit 1545b58

Please sign in to comment.