-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from christopher-mohr/add_gene_heatmap_process
- Loading branch information
Showing
10 changed files
with
175 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/usr/bin/env Rscript | ||
library(tidyverse) | ||
library(ggplot2) | ||
library(fs) | ||
library(ComplexHeatmap) | ||
library(circlize) | ||
library(yaml) | ||
library(ragg) | ||
library(tidylog) | ||
|
||
###Command line argument parsing### | ||
args = commandArgs(trailingOnly=TRUE) | ||
if (length(args) < 1) { | ||
stop("Usage: compute_gene_heatmap.R <annotated_counts.tsv> or compute_gene_heatmap.R <annotated_counts.tsv> <genes.yaml>", call.=FALSE) | ||
} | ||
input_counts <- args[1] | ||
|
||
#Read annotated counts | ||
# HEADER is always RCC_FILE + GENES + SAMPLE_ID and additional metadata such as GROUP TREATMENT OTHER_METADATA | ||
counts <- read.table(input_counts, sep="\t", check.names = FALSE, header=TRUE, stringsAsFactors = FALSE) | ||
|
||
if (length(args) == 2) { | ||
input_genes <- args[2] | ||
genes <- read_yaml(input_genes) | ||
} else { | ||
gene_cols <- counts %>% dplyr::select(- any_of(c("RCC_FILE", "SAMPLE_ID", "TIME", "TREATMENT", "OTHER_METADATA"))) | ||
genes <- colnames(gene_cols) | ||
} | ||
|
||
#Select counts of interest | ||
counts_selected <- counts %>% dplyr::select(all_of(genes)) | ||
|
||
#Add proper Rownames | ||
rownames(counts_selected) <- counts$SAMPLE_ID | ||
|
||
#sort dataframe by rownames to make it easier comparable across heatmaps | ||
counts_selected[order(row.names(counts_selected)), ] | ||
|
||
#log2+1 | ||
counts_selected <- log2(counts_selected + 1) | ||
|
||
#Find max | ||
colMax <- function(data) sapply(data, max, na.rm = TRUE) | ||
#Find min | ||
colMin <- function(data) sapply(data, min, na.rm = TRUE) | ||
|
||
max_value <- max(colMax(counts_selected)) | ||
min_value <- min(colMin(counts_selected)) | ||
|
||
#Save as PDF | ||
|
||
prefix <- "" | ||
if (grepl("wo_HKnorm",input_counts)) { | ||
prefix <- "wo_HKnorm_" | ||
} | ||
|
||
agg_png(file = paste0(prefix, "gene_heatmap_mqc.png"), width = 1200, height = 2000, unit = "px") | ||
|
||
Heatmap(counts_selected, name = "Gene-Count Heatmap", column_title = "Gene (log2 +1)", | ||
row_title_rot = 90, row_title = "SampleID",row_dend_reorder = FALSE, show_row_dend = FALSE, row_names_side = "left", | ||
show_column_dend = FALSE, col = colorRamp2(c(min_value, max_value), c("#f7f7f7", "#67a9cf"))) | ||
|
||
dev.off() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
process CREATE_GENE_HEATMAP { | ||
label 'process_single' | ||
|
||
conda "r-nacho=2.0.4 r-tidyverse=2.0.0 r-ggplot2=3.4.2 r-rlang=1.1.1 r-tidylog=1.0.2 r-fs=1.6.2 bioconductor-complexheatmap=2.14.0 r-circlize=0.4.15 r-yaml=2.3.7 r-ragg=1.2.5 r-rcolorbrewer=1.1_3 r-pheatmap=1.0.12" | ||
container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ? | ||
'https://depot.galaxyproject.org/singularity/mulled-v2-68b3ca19fcb1f8b052324cb635ab60f8b17a3058:e4b1ecb1e69304213c695190148317b26caa2841-0' : | ||
'biocontainers/mulled-v2-68b3ca19fcb1f8b052324cb635ab60f8b17a3058:e4b1ecb1e69304213c695190148317b26caa2841-0' }" | ||
|
||
input: | ||
path annotated_counts | ||
|
||
output: | ||
path "*gene_heatmap_mqc.png", emit: gene_heatmap | ||
path "versions.yml" , emit: versions | ||
|
||
when: | ||
task.ext.when == null || task.ext.when | ||
|
||
script: | ||
def args = task.ext.args ?: '' | ||
|
||
def gene_filter = params.heatmap_genes_to_filter ?: "" | ||
|
||
""" | ||
compute_gene_heatmap.R $annotated_counts $gene_filter | ||
cat <<-END_VERSIONS > versions.yml | ||
"${task.process}": | ||
r-base: \$(echo \$(R --version 2>&1) | sed 's/^.*R version //; s/ .*\$//') | ||
r-nacho: \$(Rscript -e "library(NACHO); cat(as.character(packageVersion('NACHO')))") | ||
r-tidyverse: \$(Rscript -e "library(tidyverse); cat(as.character(packageVersion('tidyverse')))") | ||
r-fs: \$(Rscript -e "library(fs); cat(as.character(packageVersion('fs')))") | ||
END_VERSIONS | ||
""" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters