Skip to content

Commit

Permalink
Merge pull request #27 from itrujnara/bug_fixes
Browse files Browse the repository at this point in the history
Added light mode plots
  • Loading branch information
JoseEspinosa committed May 15, 2024
2 parents 22f1f7d + 5a60c26 commit a1d3af7
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 44 deletions.
69 changes: 44 additions & 25 deletions bin/plot_orthologs.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,22 @@ if (length(args) < 2) {
}

# Styles
text_color <- "#DDDDDD"
text_color_darkmode <- "#DDDDDD"
text_color_lightmode <- "#333333"
bg_color <- "transparent"
font_size <- 16

customize_theme <- function(font_size, text_color, bg_color) {
theme(legend.position = "right",
text = element_text(size = font_size, color = text_color),
axis.text = element_text(size = font_size, color = text_color),
panel.grid = element_line(color = text_color),
plot.background = element_rect(color = bg_color, fill = bg_color),
panel.background = element_rect(color = bg_color, fill = bg_color))
}

theme_dark <- customize_theme(font_size, text_color_darkmode, bg_color)
theme_light <- customize_theme(font_size, text_color_lightmode, bg_color)
# Load the data
data <- read.csv(args[1], header = TRUE, stringsAsFactors = FALSE)

Expand All @@ -35,33 +47,39 @@ crosstable <- dcast(melted_data, method ~ score)
melted_crosstable <- melt(crosstable, id.vars = "method", variable.name = "score", value.name = "count")

# Plot the data
p <- ggplot(melted_crosstable, aes(x = method, y = count, fill = score)) +
supports <- ggplot(melted_crosstable, aes(x = method, y = count, fill = score)) +
geom_bar(stat = "identity", position = "stack") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(title = "Support for predictions", x = "Database", y = "Number of orthologs", fill = "Support") +
scale_fill_manual(values = c("#59B4C3", "#74E291", "#8F7AC2", "#EFF396", "#FF9A8D")) +
theme(legend.position = "right",
text = element_text(size = font_size, color = text_color),
axis.text.x = element_text(size = font_size, color = text_color),
axis.text.y = element_text(size = font_size, color = text_color),
plot.background = element_rect(color = bg_color, fill = bg_color),
panel.background = element_rect(color = bg_color, fill = bg_color))
scale_fill_manual(values = c("#59B4C3", "#74E291", "#8F7AC2", "#EFF396", "#FF9A8D"))

supports_dark <- supports + theme_dark

ggsave(paste0(args[2], "_supports.png"), plot = p, width = 6, height = 10, dpi = 300)
ggsave(paste0(args[2], "_supports_dark.png"), plot = supports_dark, width = 6, height = 10, dpi = 300)

supports_light <- supports + theme_light

ggsave(paste0(args[2], "_supports_light.png"), plot = supports_light, width = 6, height = 10, dpi = 300)

# Make a Venn diagram
venn.data <- list()
for (i in colnames(data)[4:ncol(data)-1]) {
hits <- (data %>% filter(data[, i] == 1) %>% select(id))$id
venn.data[[i]] <- hits
}
venn.plot <- ggVennDiagram(venn.data, set_color = text_color) +
theme(legend.position = "none",
text = element_text(size = font_size, color = text_color),
plot.background = element_rect(color = bg_color, fill = bg_color),
panel.background = element_rect(color = bg_color, fill = bg_color))
ggsave(paste0(args[2], "_venn.png"), plot = venn.plot, width = 6, height = 6, dpi = 300)

venn_plot_dark <- ggVennDiagram(venn.data, set_color = text_color_darkmode) +
theme_dark +
theme(panel.grid = element_blank(), axis.text = element_text(color = "transparent"), legend.position = "none")

ggsave(paste0(args[2], "_venn_dark.png"), plot = venn_plot_dark, width = 6, height = 6, dpi = 300)

venn_plot_light <- ggVennDiagram(venn.data, set_color = text_color_lightmode) +
theme_light +
theme(panel.grid = element_blank(), axis.text = element_text(color = "transparent"), legend.position = "none")

ggsave(paste0(args[2], "_venn_light.png"), plot = venn_plot_light, width = 6, height = 6, dpi = 300)

# Make a plot with Jaccard index for each pair of methods
jaccard <- data.frame(method1 = character(), method2 = character(), jaccard = numeric())
Expand All @@ -77,18 +95,19 @@ for (i in 4:ncol(data)-1) {
jaccard <- rbind(jaccard, data.frame(method1 = method1, method2 = method2, jaccard = length(intersect(hits1, hits2)) / length(union(hits1, hits2))))
}
}
p <- ggplot(jaccard, aes(x = method1, y = method2, fill = jaccard)) +

jaccard_plot <- ggplot(jaccard, aes(x = method1, y = method2, fill = jaccard)) +
geom_tile() +
geom_text(aes(label = round(jaccard, 2)), size=5) +
scale_fill_gradient(low = "#59B4C3", high = "#EFF396") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(title = "Jaccard Index", x = "", y = "", fill = "Jaccard Index") +
theme(legend.position = "right",
text = element_text(size = font_size, color = text_color),
axis.text.x = element_text(size = font_size, color = text_color),
axis.text.y = element_text(size = font_size, color = text_color),
plot.background = element_rect(color = bg_color, fill = bg_color),
panel.background = element_rect(color = bg_color, fill = bg_color))
labs(x = "", y = "", fill = "Jaccard Index")

jaccard_plot_dark <- jaccard_plot + theme_dark

ggsave(paste0(args[2], "_jaccard_dark.png"), plot = jaccard_plot_dark, width = 6, height = 6, dpi = 300)

jaccard_plot_light <- jaccard_plot + theme_light

ggsave(paste0(args[2], "_jaccard.png"), plot = p, width = 6, height = 6, dpi = 300)
ggsave(paste0(args[2], "_jaccard_light.png"), plot = jaccard_plot_light, width = 6, height = 6, dpi = 300)
18 changes: 14 additions & 4 deletions bin/plot_tree.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ library(treeio)
library(ggtree)
library(ggplot2)

fgcolor <- "#eeeeee"
fgcolor_dark <- "#dddddd"
fgcolor_light <- "#333333"
bgcolor <- "transparent"

args <- commandArgs(trailingOnly = TRUE)
Expand All @@ -17,8 +18,17 @@ if (length(args) < 3) {
}

tree <- read.tree(args[1])
p <- ggtree(tree, color = fgcolor) +
geom_tiplab(color = fgcolor) +

p_dark <- ggtree(tree, color = fgcolor_dark) +
geom_tiplab(color = fgcolor_dark) +
theme_tree() +
theme(panel.background = element_rect(color = bgcolor, fill = bgcolor), plot.background = element_rect(color = bgcolor, fill = bgcolor))

ggsave(paste0(args[2], "_", args[3], "_tree_dark.png"), dpi = 300, height = 16, width = 8)

p_light <- ggtree(tree, color = fgcolor_light) +
geom_tiplab(color = fgcolor_light) +
theme_tree() +
theme(panel.background = element_rect(color = bgcolor, fill = bgcolor), plot.background = element_rect(color = bgcolor, fill = bgcolor))
ggsave(paste0(args[2], "_", args[3], "_tree.png"), dpi = 300, height = 16, width = 8)

ggsave(paste0(args[2], "_", args[3], "_tree_light.png"), dpi = 300, height = 16, width = 8)
17 changes: 10 additions & 7 deletions modules/local/plot_orthologs.nf
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ process PLOT_ORTHOLOGS {
tuple val(meta), path(score_table)

output:
tuple val(meta), path("*_supports.png") , emit: supports
tuple val(meta), path("*_venn.png") , emit: venn
tuple val(meta), path("*_jaccard.png") , emit: jaccard
path "versions.yml" , emit: versions
tuple val(meta), path("*_supports_light.png"), path("*_supports_dark.png"), emit: supports
tuple val(meta), path("*_venn_light.png"), path("*_venn_dark.png") , emit: venn
tuple val(meta), path("*_jaccard_light.png"), path("*_jaccard_dark.png") , emit: jaccard
path "versions.yml" , emit: versions

when:
task.ext.when == null || task.ext.when
Expand All @@ -32,9 +32,12 @@ process PLOT_ORTHOLOGS {
stub:
def prefix = task.ext.prefix ?: "${meta.id}"
"""
touch ${prefix}_supports.png
touch ${prefix}_venn.png
touch ${prefix}_jaccard.png
touch ${prefix}_supports_dark.png
touch ${prefix}_supports_light.png
touch ${prefix}_venn_dark.png
touch ${prefix}_venn_light.png
touch ${prefix}_jaccard_dark.png
touch ${prefix}_jaccard_light.png
cat <<- END_VERSIONS > versions.yml
"${task.process}":
Expand Down
7 changes: 4 additions & 3 deletions modules/local/plot_tree.nf
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ process PLOT_TREE {
val method

output:
tuple val(meta), path("*.png"), emit: plot
path "versions.yml" , emit: versions
tuple val(meta), path("*_light.png"), path("*_dark.png") , emit: plot
path "versions.yml" , emit: versions

when:
task.ext.when == null || task.ext.when
Expand All @@ -31,7 +31,8 @@ process PLOT_TREE {
stub:
prefix = task.ext.prefix ?: meta.id
"""
touch ${prefix}_${method}_tree.png
touch ${prefix}_${method}_tree_dark.png
touch ${prefix}_${method}_tree_light.png
cat <<- END_VERSIONS > versions.yml
"${task.process}":
Expand Down
10 changes: 5 additions & 5 deletions workflows/reportho.nf
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ workflow REPORTHO {
ALIGN.out.alignment
)

ch_iqtree = MAKE_TREES.out.mlplot
ch_fastme = MAKE_TREES.out.meplot
ch_iqtree = MAKE_TREES.out.mlplot.map { [it[0], it[1]] }
ch_fastme = MAKE_TREES.out.meplot.map { [it[0], it[1]] }

ch_versions = ch_versions.mix(MAKE_TREES.out.versions)
}
Expand All @@ -111,9 +111,9 @@ workflow REPORTHO {
GET_ORTHOLOGS.out.seqinfo,
GET_ORTHOLOGS.out.score_table,
GET_ORTHOLOGS.out.orthologs,
GET_ORTHOLOGS.out.supports_plot,
GET_ORTHOLOGS.out.venn_plot,
GET_ORTHOLOGS.out.jaccard_plot,
GET_ORTHOLOGS.out.supports_plot.map { [it[0], it[1]]},
GET_ORTHOLOGS.out.venn_plot.map { [it[0], it[1]]},
GET_ORTHOLOGS.out.jaccard_plot.map { [it[0], it[1]]},
GET_ORTHOLOGS.out.stats,
ch_seqhits,
ch_seqmisses,
Expand Down

0 comments on commit a1d3af7

Please sign in to comment.