-
Notifications
You must be signed in to change notification settings - Fork 736
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
51c2192
commit 976a4fd
Showing
6 changed files
with
489 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
channels: | ||
- conda-forge | ||
- bioconda | ||
dependencies: | ||
- bioconda::immunedeconv=2.1.2 |
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,37 @@ | ||
process IMMUNEDECONV { | ||
tag "$meta.id" | ||
label 'process_single' | ||
|
||
conda "${moduleDir}/environment.yml" | ||
container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ? | ||
'https://community-cr-prod.seqera.io/docker/registry/v2/blobs/sha256/22/22cb85f1b69ceff45b83e0fdb7b96d9ae29c8aafeaa0707d64cc4628982977ab/data' : | ||
'community.wave.seqera.io/library/r-immunedeconv:2.1.2--e1bb1ea1cf505cb3' }" | ||
|
||
input: | ||
tuple val(meta), path(input_file), val(method), val(function) | ||
val gene_symbol_col | ||
|
||
output: | ||
tuple val(meta), path("*.deconvolution_results.tsv"), emit: deconv_table | ||
tuple val(meta), path("*.png"), emit: deconv_plots, optional: true | ||
path "versions.yml", emit: versions | ||
|
||
when: | ||
task.ext.when == null || task.ext.when | ||
|
||
script: | ||
template 'immunedeconv.R' | ||
|
||
stub: | ||
prefix = task.ext.prefix ?: "${meta.id}" | ||
""" | ||
touch ${prefix}.deconvolution_results.tsv | ||
touch ${prefix}.plot1_stacked_bar_chart.png | ||
touch ${prefix}.plot2_points_with_facets.png | ||
cat <<-END_VERSIONS > versions.yml | ||
"${task.process}": | ||
r-immunedeconv: \$(Rscript -e "cat(as.character(packageVersion('immunedeconv')))") | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
name: untar #TODO update for module | ||
description: Extract files. | ||
keywords: | ||
- untar | ||
- uncompress | ||
- extract | ||
tools: | ||
- untar: | ||
description: | | ||
Extract tar.gz files. | ||
documentation: https://www.gnu.org/software/tar/manual/ | ||
licence: ["GPL-3.0-or-later"] | ||
identifier: "" | ||
input: | ||
- - meta: | ||
type: map | ||
description: | | ||
Groovy Map containing sample information | ||
e.g. [ id:'test', single_end:false ] | ||
- archive: | ||
type: file | ||
description: File to be untar | ||
pattern: "*.{tar}.{gz}" | ||
output: | ||
- untar: | ||
- meta: | ||
type: map | ||
description: | | ||
Groovy Map containing sample information | ||
e.g. [ id:'test', single_end:false ] | ||
- $prefix: | ||
type: directory | ||
description: Directory containing contents of archive | ||
pattern: "*/" | ||
- versions: | ||
- versions.yml: | ||
type: file | ||
description: File containing software versions | ||
pattern: "versions.yml" | ||
authors: | ||
- "@joseespinosa" | ||
- "@drpatelh" | ||
- "@matthdsm" | ||
- "@jfy133" | ||
maintainers: | ||
- "@joseespinosa" | ||
- "@drpatelh" | ||
- "@matthdsm" | ||
- "@jfy133" |
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,89 @@ | ||
#!/usr/bin/env Rscript | ||
|
||
library(dplyr) | ||
library(ggplot2) | ||
library(tidyr) | ||
library(immunedeconv) | ||
library(tibble) | ||
library(readr) | ||
|
||
#Load prefix | ||
prefix = ifelse('$task.ext.prefix' == 'null', '$meta.id', '$task.ext.prefix') | ||
|
||
# Load the TSV file and keep only $gene_symbol_col column + counts | ||
gene_expression_matrix <- readr::read_tsv('$input_file') %>% | ||
as.data.frame() %>% | ||
dplyr::select( | ||
dplyr::all_of('$gene_symbol_col'), # Keep the '$gene_symbol_col' column | ||
where(~ !is.character(.)) # Include all non-string columns | ||
) %>% | ||
tibble::column_to_rownames('$gene_symbol_col') | ||
|
||
# Check if the data is log-transformed or TPM-transformed | ||
# Check range of values | ||
min_value <- min(gene_expression_matrix, na.rm = TRUE) | ||
max_value <- max(gene_expression_matrix, na.rm = TRUE) | ||
|
||
# Detect log-transformed data (values typically within a compressed range) | ||
if (max_value < 100 && min_value >= 0) { | ||
warning("The data appears to be log-transformed. Please provide TPM-transformed data.") | ||
} | ||
|
||
# Detect TPM-transformed data (column sums should be close to 1,000,000) | ||
column_sums <- colSums(gene_expression_matrix, na.rm = TRUE) | ||
if (!all(abs(column_sums - 1e6) < 1e4)) { | ||
warning("The data does not appear to be properly TPM-transformed. Ensure the data is normalized.") | ||
} | ||
|
||
# Generate results | ||
result <- immunedeconv::${function}(gene_expression_matrix, method = '$method') | ||
|
||
# Save the result to a CSV file | ||
readr::write_tsv(result, paste0(prefix,'.deconvolution_results.tsv')) | ||
|
||
# Plot and save results | ||
# Plot 1: Stacked bar chart | ||
plot1 <- result %>% | ||
gather(sample, fraction, -cell_type) %>% | ||
ggplot(aes(x = sample, y = fraction, fill = cell_type)) + | ||
geom_bar(stat = 'identity') + | ||
coord_flip() + | ||
scale_fill_brewer(palette = 'Paired') + | ||
scale_x_discrete(limits = rev(levels(result))) | ||
|
||
# Save Plot 1 | ||
ggsave(paste0(prefix,'.plot1_stacked_bar_chart.png'), plot = plot1, dpi = 300, width = 10, height = 8) | ||
|
||
# Plot 2: Points with facets | ||
plot2 <- result %>% | ||
gather(sample, score, -cell_type) %>% | ||
ggplot(aes(x = sample, y = score, color = cell_type)) + | ||
geom_point(size = 4) + | ||
facet_wrap(~cell_type, scales = 'free_x', ncol = 3) + | ||
scale_color_brewer(palette = 'Paired', guide = FALSE) + | ||
coord_flip() + | ||
theme_bw() + | ||
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1)) | ||
|
||
# Save Plot 2 | ||
ggsave(paste0(prefix,'.plot2_points_with_facets.png'), plot = plot2, dpi = 300, width = 12, height = 10) | ||
|
||
################################################ | ||
################################################ | ||
## VERSIONS FILE ## | ||
################################################ | ||
################################################ | ||
|
||
immunedeconv_version <- as.character(packageVersion('immunedeconv')) | ||
|
||
writeLines( | ||
c( | ||
'"${task.process}":', | ||
paste(' r-immunedeconv:', immunedeconv_version) | ||
), | ||
'versions.yml') | ||
|
||
################################################ | ||
################################################ | ||
################################################ | ||
################################################ |
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,87 @@ | ||
nextflow_process { | ||
|
||
name "Test Process IMMUNEDECONV" | ||
script "../main.nf" | ||
process "IMMUNEDECONV" | ||
tag "modules" | ||
tag "modules_nfcore" | ||
tag "immunedeconv" | ||
|
||
test("test_immunedeconv_bulkmat") { | ||
|
||
when { | ||
process { | ||
""" | ||
input[0] = [ [id:"immunedeconv"], file('https://raw.githubusercontent.com/omnideconv/immunedeconv/refs/heads/master/tests/testthat/bulk_mat.tsv', checkIfExists: true), "quantiseq", "deconvolute" ] | ||
input[1] = "gene_symbol" | ||
""" | ||
} | ||
} | ||
|
||
then { | ||
assertAll ( | ||
{ assert process.success }, | ||
{ assert snapshot(process.out).match() }, | ||
) | ||
} | ||
} | ||
|
||
test("test_immunedeconv_custom_data_mouse") { | ||
|
||
when { | ||
process { | ||
""" | ||
input[0] = [ [id:"immunedeconv"], file('https://github.com/omnideconv/immunedeconv/raw/refs/heads/master/tests/testthat/bulk_mat_mouse.tsv', checkIfExists: true), "mmcp_counter", "deconvolute_mouse" ] | ||
input[1] = "gene_symbol" | ||
""" | ||
} | ||
} | ||
|
||
then { | ||
assertAll ( | ||
{ assert process.success }, | ||
{ assert snapshot(process.out).match() }, | ||
) | ||
} | ||
} | ||
|
||
test("test_immunedeconv_bulkmat_mouse") { | ||
|
||
when { | ||
process { | ||
""" | ||
input[0] = [ [id:"immunedeconv"], file('https://raw.githubusercontent.com/nf-core/test-datasets/modules/data/genomics/mus_musculus/rnaseq_expression/SRP254919.salmon.merged.gene_counts.top1000cov.tsv', checkIfExists: true), "mmcp_counter", "deconvolute_mouse" ] | ||
input[1] = "gene_name" | ||
""" | ||
} | ||
} | ||
|
||
then { | ||
assertAll ( | ||
{ assert process.success }, | ||
{ assert snapshot(process.out).match() }, | ||
) | ||
} | ||
} | ||
|
||
test("test_immunedeconv - stub") { | ||
|
||
options "-stub" | ||
|
||
when { | ||
process { | ||
""" | ||
input[0] = [ [id:"immunedeconv"], file('https://raw.githubusercontent.com/omnideconv/immunedeconv/refs/heads/master/tests/testthat/bulk_mat.tsv', checkIfExists: true), "quantiseq", "deconvolute" ] | ||
input[1] = "gene_symbol" | ||
""" | ||
} | ||
} | ||
|
||
then { | ||
assertAll ( | ||
{ assert process.success }, | ||
{ assert snapshot(process.out).match() }, | ||
) | ||
} | ||
} | ||
} |
Oops, something went wrong.