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

Svplots #110

Merged
merged 4 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
93 changes: 2 additions & 91 deletions 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 Expand Up @@ -71,9 +71,7 @@ knitr::kable(
)
)
```
This tab (`General Stats`) shows overview information. Clicking `Per-Contig Plots`
in the navigation bar at the top of this page will show you interactive
plots detailing all variants identified.
This report shows overview information.

In the colorful summary boxes are the per-population average number of
variants detected by type.
Expand Down Expand Up @@ -320,91 +318,4 @@ popheight <- 5 / length(populations) / 10
for (SV in c("INV", "DEL", "DUP", "BND")){
circosplot(sv, fa.sizes, SV, popheight, populations, col.ramp)
}
```

# Per-Contig Plots
## Per-contig
### plots per contig {.no-title data-height=10000}
<h1> Structural Variants Per Contig Per Population </h1>
Below is a plot to help you assess what structural variants were
detected by LEVIATHAN. These plots are interactive, allowing you
to hover over a variant to provide additional information, including
the genomic interval in which it occurs and the number of haplotag
barcodes supporting the variant. Populations are stacked vertically
for each contig, denoted by the grey strip on the right side of each row.

```{r echo = FALSE, message = FALSE, warning = FALSE}
sv$ystart <- case_when(
sv$type == "INV" ~ 0.1,
sv$type == "DUP" ~ 1.1,
sv$type == "DEL" ~ 2.1,
sv$type == "BND" ~ 3.1,
)
sv$ystop <- sv$ystart + 0.8
```

```{r percontig plotly, echo = FALSE, out.width = '100%', warning=FALSE}
color.palette <- c("DEL"="#5a8c84", "DUP"="#ffd75f", "INV"="#4a9fea","BND"="#df487f")
l <- list()
nplotrows <- 0

for (i in 1:nrow(fa.sizes)) {
sv.filt <- sv %>% filter(contig == fa.sizes$contig[i])
sv_stats <- group_by(sv.filt, type) %>% summarise(n = length(type))
if (nrow(sv_stats) == 0) {
next
}
nplotrows <- nplotrows + 1
plt <- sv.filt %>%
ggplot() +
geom_rect(
alpha = 0.7,
aes(
ymin = ystart,
ymax = ystop,
xmin = position_start,
xmax = position_end,
fill = type,
color = type,
text = sprintf("Population: %s<br>Type: %s<br>Position: %s-%s<br>barcodes: %s", population, type, position_start, position_end, n_barcodes)
)
) +
geom_hline(yintercept = 1:3, color = "grey96") +
scale_color_manual(values = color.palette) +
scale_fill_manual(values = color.palette) +
facet_grid(rows = vars(population)) +
theme_light() +
theme(
axis.line.y = element_blank(),
axis.ticks.y = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
strip.background = element_rect(fill = "grey80"),
strip.text = element_text(color = "grey20"),
legend.position = "none",
) +
scale_x_continuous(labels = scales::comma) +
scale_y_continuous(
breaks = c(0.5, 1.5, 2.5, 3.5),
labels = c("INV", "DUP", "DEL", "BND"),
limits = c(0,4)
) +
coord_cartesian(xlim = c(0, fa.sizes$size[i] + 1), expand = F) +
xlab("Position (bp)") +
labs(fill = "SV type", color = "SV type")
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
)
pp <- subplot(ggplotly(plt, height = 850 * length(populations), tooltip = "text")) %>%
layout(annotations = annotations)
l[[i]] <- pp
}
subplot(l, nrows = nplotrows, shareX = FALSE, titleX = TRUE)
```
56 changes: 14 additions & 42 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 @@ -383,41 +382,28 @@ circosplot(sv, fa.sizes, samplename)
## per contig
### Per-contig {.no-title data-height=7000}
<h1> Structural Variants Per Contig </h1>
Below is a plot to help you assess what structural variants were detected by LEVIATHAN. These plots are interactive,
Below is a plot to help you assess what structural variants were detected by NAIBR. These plots are interactive,
allowing you to hover over a variant to provide additional information, including the genomic interval in which it occurs and the
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))
```
111 changes: 5 additions & 106 deletions 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 Expand Up @@ -47,9 +47,8 @@ script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"
```{r echo = FALSE, warnings = FALSE, message = FALSE}
infiles <- snakemake@input[["bedpe"]]
fai <- snakemake@input[["fai"]]
#infiles <- paste0("/home/pdimens/", c(1,2,3), ".bedpe")
#infiles <- list.files("~/downsampled/", full.names = T)
#fai <- "/home/pdimens/test.fai"
#infiles <- list.files(path = "~", pattern = "*bedpe", full.names = T)
#fai <- "~/test.fai"
```

# General Stats
Expand All @@ -72,9 +71,7 @@ knitr::kable(
)
)
```
This tab (`General Stats`) shows overview information. Clicking `Per-Contig Plots`
in the navigation bar at the top of this page will show you interactive
plots detailing all variants identified.
This report shows overview information.

In the colorful summary boxes are the per-population average number of
variants detected by type.
Expand Down Expand Up @@ -110,7 +107,7 @@ chimeric <- function(x){

```{r echo = FALSE}
emptyfiles <- character()
sv <- data.frame(matrix(ncol=12,nrow=0, dimnames=list(NULL, c("Population", "Chr1", "Break1", "Chr2", "Break2", "SplitMolecules", "DiscordantReads", "Orientation", "Haplotype", "Score", "PassFilter", "SV" ))))
sv <- data.frame(matrix(ncol=12,nrow=0, dimnames=list(NULL, c("Population", "Chr1", "Break1", "Chr2", "Break2", "SplitMolecules", "DiscordantReads", "Orientation", "Haplotype", "Score", "PassFilter", "SV"))))
for(i in infiles){
.df <- tryCatch(readvariants(i), error = function(e){return(0)})
if(length(.df)==1){
Expand Down Expand Up @@ -202,7 +199,6 @@ DT::datatable(
filter = "top",
extensions = 'Buttons',
options = list(dom = 'Brtip', buttons = c('csv'), scrollX = TRUE),
autoHideNavigation = T,
fillContainer = T
)
```
Expand All @@ -220,7 +216,6 @@ DT::datatable(
filter = "top",
extensions = 'Buttons',
options = list(dom = 'Brtip', buttons = c('csv'), scrollX = TRUE),
autoHideNavigation = T,
fillContainer = T
)
```
Expand Down Expand Up @@ -271,7 +266,6 @@ DT::datatable(
filter = "top",
extensions = 'Buttons',
options = list(dom = 'Brtip', buttons = 'csv', scrollX = TRUE),
autoHideNavigation = T,
fillContainer = T
)
```
Expand Down Expand Up @@ -403,104 +397,9 @@ circosplot(sv_clean, fa.sizes, "inversion", popheight, populations, col.ramp)
### Deletions
```{r echo = FALSE, message = FALSE, warning = FALSE, dev = "jpeg", fig.align='center'}
circosplot(sv_clean, fa.sizes, "deletion", popheight, populations, col.ramp)

```

### Duplications
```{r echo = FALSE, message = FALSE, warning = FALSE, dev = "jpeg", fig.align='center'}
circosplot(sv_clean, fa.sizes, "duplication", popheight, populations, col.ramp)
```

# Per-Contig Plots
## percontig desc
### desc {.no-title}
<h1> Structural Variants Per Contig Per Population </h1>
Below is a plot to help you assess what structural variants were
detected by NAIBR These plots are interactive, allowing you
to hover over a variant to provide additional information, including
the genomic interval in which it occurs and the number of haplotag
barcodes supporting the variant. Populations are stacked vertically
for each contig, denoted by the grey strip on the right side of each row.

## per contig
### plots per contig {.no-title data-height=10000}
```{r echo = FALSE, message = FALSE, warning = FALSE}
color.palette <- c(
"deletion" = "#5a8c84",
"duplication" = "#ffd75f",
"inversion" = "#4a9fea"
)

sv_clean$ystart <- case_when(
sv_clean$SV == "inversion" ~ 0.1,
sv_clean$SV == "duplication" ~ 1.1,
sv_clean$SV == "deletion" ~ 2.1
)
sv_clean$ystop <- sv_clean$ystart + 0.8

```


```{r echo = FALSE, out.width = '100%', warning=FALSE}
l <- list()
nplotrows <- 0

for (i in 1:nrow(fa.sizes)) {
sv.filt <- sv_clean %>% 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() +
geom_rect(
alpha = 0.7,
aes(
xmin = Break1,
xmax = Break2,
ymin = ystart,
ymax = ystop,
fill = SV,
color = SV,
text = sprintf("Type: %s<br>Position: %s-%s<br>barcodes: %s", SV, Break1, Break2, SplitMolecules) )
) +
geom_hline(yintercept = 1:3, color = "grey96") +
scale_color_manual(values = color.palette) +
scale_fill_manual(values = color.palette) +
facet_grid(rows = vars(Population)) +
theme_light() +
theme(
axis.line.y = element_blank(),
axis.ticks.y = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
strip.background = element_rect(fill = "grey80"),
strip.text = element_text(color = "grey20"),
legend.position = "none",
) +
scale_x_continuous(labels = scales::comma) +
scale_y_continuous(
breaks = c(0.5, 1.5, 2.5),
labels = c("INV", "DUP", "DEL"),
limits = c(0,3)
) +
coord_cartesian(xlim = c(0, fa.sizes$size[i] + 1), expand = F) +
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
)
pp <- subplot(ggplotly(plt, height = 800 * length(populations), tooltip = "text")) %>%
layout(annotations = annotations)
l[[i]] <- pp
}
# remove null
l <- Filter(Negate(is.null), l)
subplot(l, nrows = length(l) , shareX = FALSE, titleX = TRUE)
```
Loading
Loading