-
Notifications
You must be signed in to change notification settings - Fork 751
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into seqkit-2.9.0-part-2
- Loading branch information
Showing
8 changed files
with
406 additions
and
3 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::r-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,67 @@ | ||
name: immunedeconv | ||
description: Perform immune cell deconvolution using RNA-seq data and various computational methods. | ||
keywords: | ||
- Immune Deconvolution | ||
- RNA-seq | ||
- Bioinformatics Tools | ||
- Computational Immunology | ||
tools: | ||
- immunedeconv: | ||
description: | | ||
The immunedeconv R package provides functions for immune cell deconvolution | ||
from RNA-seq data. It supports multiple deconvolution methods and generates | ||
results as well as visualizations. | ||
homepage: https://github.com/icbi-lab/immunedeconv | ||
documentation: https://icbi-lab.github.io/immunedeconv/ | ||
licence: ["GPL-2"] | ||
input: | ||
- - meta: | ||
type: map | ||
description: | | ||
Groovy Map containing sample information | ||
e.g. `[ id:'sample1', single_end:false ]` | ||
- input_file: | ||
type: file | ||
description: Input matrix with genes in rows and samples in columns. | ||
pattern: "*.tsv" | ||
- method: | ||
type: string | ||
description: The deconvolution method to use (e.g., 'CIBERSORT', 'EPIC', 'xCell'). | ||
- function: | ||
type: string | ||
description: The specific function from immunedeconv to execute for analysis. | ||
- - gene_symbol_col: | ||
type: string | ||
description: Column name for gene symbols in the matrix input file. | ||
output: | ||
- deconv_table: | ||
- meta: | ||
type: map | ||
description: | | ||
Groovy Map containing sample information | ||
e.g. `[ id:'sample1', single_end:false ]` | ||
- "*.deconvolution_results.tsv": | ||
type: file | ||
description: Results table containing deconvolution data. | ||
pattern: "*.deconvolution_results.tsv" | ||
- deconv_plots: | ||
- meta: | ||
type: map | ||
description: | | ||
Groovy Map containing sample information | ||
e.g. `[ id:'sample1', single_end:false ]` | ||
- "*.png": | ||
type: file | ||
description: Visualization plots generated during deconvolution. | ||
pattern: "*.png" | ||
- versions: | ||
- versions.yml: | ||
type: file | ||
description: File containing software versions | ||
pattern: "versions.yml" | ||
authors: | ||
- "@grst" | ||
- "@nschcolnicov" | ||
maintainers: | ||
- "@grst" | ||
- "@nschcolnicov" |
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,107 @@ | ||
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(params.modules_testdata_base_path + 'genomics/mus_musculus/rnaseq_expression/bulk_mat.tsv', checkIfExists: true), "quantiseq", "deconvolute" ] | ||
input[1] = "gene_symbol" | ||
""" | ||
} | ||
} | ||
|
||
then { | ||
assertAll ( | ||
{ assert process.success }, | ||
{ assert snapshot( | ||
process.out.deconv_table, | ||
process.out.deconv_plots[0][1].collect{ file(it).name }, //assert unstable file | ||
process.out.versions | ||
).match() | ||
} | ||
) | ||
} | ||
} | ||
|
||
test("test_immunedeconv_custom_data_mouse") { | ||
|
||
when { | ||
process { | ||
""" | ||
input[0] = [ [id:"immunedeconv"], file(params.modules_testdata_base_path + 'genomics/mus_musculus/rnaseq_expression/bulk_mat_mouse.tsv', checkIfExists: true), "mmcp_counter", "deconvolute_mouse" ] | ||
input[1] = "gene_symbol" | ||
""" | ||
} | ||
} | ||
|
||
then { | ||
assertAll ( | ||
{ assert process.success }, | ||
{ assert snapshot( | ||
process.out.deconv_table, | ||
process.out.deconv_plots[0][1].collect{ file(it).name }, //assert unstable file | ||
process.out.versions | ||
).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.deconv_table, | ||
process.out.deconv_plots[0][1].collect{ file(it).name }, //assert unstable file | ||
process.out.versions | ||
).match() | ||
} | ||
) | ||
} | ||
} | ||
|
||
test("test_immunedeconv - stub") { | ||
|
||
options "-stub" | ||
|
||
when { | ||
process { | ||
""" | ||
input[0] = [ [id:"immunedeconv"], file(params.modules_testdata_base_path + 'genomics/mus_musculus/rnaseq_expression/bulk_mat.tsv', checkIfExists: true), "quantiseq", "deconvolute" ] | ||
input[1] = "gene_symbol" | ||
""" | ||
} | ||
} | ||
|
||
then { | ||
assertAll ( | ||
{ assert process.success }, | ||
{ assert snapshot( | ||
process.out.deconv_table, | ||
process.out.deconv_plots[0][1].collect{ file(it).name }, //assert unstable file | ||
process.out.versions | ||
).match() | ||
} | ||
) | ||
} | ||
} | ||
} |
Oops, something went wrong.