8000 Add new module: RTN/TNA by mribeirodantas · Pull Request #5687 · nf-core/modules · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add new module: RTN/TNA #5687

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

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
Draft
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
7 changes: 7 additions & 0 deletions modules/nf-core/rtn/tna/environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/modules/environment-schema.json
channels:
- conda-forge
- bioconda
dependencies:
- bioconda::bioconductor-rtn=2.30.0
50 changes: 50 additions & 0 deletions modules/nf-core/rtn/tna/main.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
process RTN_TNA {
debug true
tag "{$tni_object.name}"
label 'process_medium'

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/96/96979cd0715edeb5d68ebbd19a353760298ebf53bf729d3b68764b2bb00683f7/data':
'community.wave.seqera.io/library/bioconductor-rtn:2.30.0--71b797cd8b2d56b3' }"

input:
tuple val(meta), path(tni_object)
tuple val(meta), path(degs)
tuple val(meta), path(degs_log2)
tuple val(meta), path(degs_annotation)

output:
tuple val(meta), path("tna.rds") , emit: tna_object
tuple val(meta), path("mra.rds") , emit: mra_object
tuple val(meta), path("gsea1.rds") , emit: gsea1_object
tuple val(meta), path("gsea1_plot.pdf") , emit: gsea1_plot
tuple val(meta), path("gsea2.rds") , emit: gsea2_object
tuple val(meta), path("gsea2_plot.pdf") , emit: gsea2_plot
path "versions.yml" , emit: versions

when:
task.ext.when == null || task.ext.when

script:
def args = task.ext.args ?: ''

template 'rtn_tna.r'

stub:
def args = task.ext.args ?: ''

"""
touch tna.rds
touch mra.rds
touch gsea1.rds
touch gsea1_plot.pdf
touch gsea2.rds
touch gsea2_plot.pdf

cat <<-END_VERSIONS > versions.yml
"${task.process}":
bioconductor-rtn: \$(Rscript -e "suppressWarnings(library(RTN)); cat(as.character(packageVersion('RTN')))")
END_VERSIONS
"""
}
120 changes: 120 additions & 0 deletions modules/nf-core/rtn/tna/meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/modules/meta-schema.json
name: "rtn_tna"
description: Uses the RTN R package for transcription network analysis (TNA)
keywords:
- regulatory network
- transcriptomics
- transcription factors
tools:
- "rtn":
description: "RTN: Reconstruction of Transcriptional regulatory Networks and analysis
of regulons"
homepage: "https://www.bioconductor.org/packages/release/bioc/html/RTN.html"
documentation: "https://www.bioconductor.org/packages/release/bioc/vignettes/RTN/inst/doc/RTN.html"
tool_dev_url: "https://www.bioconductor.org/packages/release/bioc/html/RTN.html"
doi: "10.1038/ncomms3464"
licence: ["Artistic-2.0"]
identifier: biotools:rtn

input:
- - meta:
type: map
description: |
Groovy Map containing sample information
e.g. `[ id:'sample1', single_end:false ]`
- tni_object:
type: file
description: TNI object from the RTN R package
pattern: "*.rds"
- - meta:
type: map
description: |
Groovy Map containing sample information
e.g. `[ id:'sample1', single_end:false ]`
- degs:
type: file
description: TSV file with DEGs names
pattern: "*.tsv"
- - meta:
type: map
description: |
Groovy Map containing sample information
e.g. `[ id:'sample1', single_end:false ]`
- degs_log2:
type: file
description: A TSV with genes and differential expression levels (usually in
log2)
pattern: "*.tsv"
- - meta:
type: map
description: |
Groovy Map containing sample information
e.g. `[ id:'sample1', single_end:false ]`
- degs_annotation:
type: file
description: An optional TSV with gene anottation mapped to the DEGs
pattern: "*.tsv"
output:
- tna_object:
- meta:
type: file
description: RDS R Object with the TNA object
pattern: "tna.rds"
- tna.rds:
type: file
description: RDS R Object with the TNA object
pattern: "tna.rds"
- mra_object:
- meta:
type: file
description: TSV file with DEGs names
pattern: "*.tsv"
- mra.rds:
type: file
description: TSV file with DEGs names
pattern: "*.tsv"
- gsea1_object:
- meta:
type: file
description: RDS R Object with the GSEA1 object
pattern: "gsea1.rds"
- gsea1.rds:
type: file
description: RDS R Object with the GSEA1 object
pattern: "gsea1.rds"
- gsea1_plot:
- meta:
type: file
description: PDF file with the GSEA1 plot
pattern: "gsea1_plot.pdf"
- gsea1_plot.pdf:
type: file
description: PDF file with the GSEA1 plot
pattern: "gsea1_plot.pdf"
- gsea2_object:
- meta:
type: file
description: RDS R Object with the GSEA2 object
pattern: "gsea2.rds"
- gsea2.rds:
type: file
description: RDS R Object with the GSEA2 object
pattern: "gsea2.rds"
- gsea2_plot:
- meta:
type: file
description: PDF file with the GSEA2 plot
pattern: "gsea2_plot.pdf"
- gsea2_plot.pdf:
type: file
description: PDF file with the GSEA2 plot
pattern: "gsea2_plot.pdf"
- versions:
- versions.yml:
type: file
description: File containing software versions
pattern: "versions.yml"
authors:
- "@mribeirodantas"
maintainers:
- "@mribeirodantas"
113 changes: 113 additions & 0 deletions modules/nf-core/rtn/tna/templates/rtn_tna.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#!/usr/bin/env Rscript

# Ported to nf-core/modules with template by Jonathan Manning

#' Parse out options from a string without recourse to optparse
#'
#' @param x Long-form argument list like --opt1 val1 --opt2 val2
#'
#' @return named list of options and values similar to optparse

parse_args <- function(x){
args_list <- unlist(strsplit(x, ' ?--')[[1]])[-1]
args_vals <- lapply(args_list, function(x) scan(text=x, what='character', quiet = TRUE))

# Ensure the option vectors are length 2 (key/ value) to catch empty ones
args_vals <- lapply(args_vals, function(z){ length(z) <- 2; z})

parsed_args <- structure(lapply(args_vals, function(x) x[2]), names = lapply(args_vals, function(x) x[1]))
parsed_args[! is.na(parsed_args)]
}

# Load
library("RTN")
library("snow")

################################################
################################################
## Pull in module inputs ##
################################################
################################################

tni_object <- readRDS('tni.rds')
# degs_log2 <- read_tsv
# degs <- read_tsv
# degs_annotation <-

output_prefix = ifelse('$task.ext.prefix' == 'null', '$meta.id', '$task.ext.prefix')
threads <- $task.cpus
args_opt <- parse_args('$task.ext.args')

n_perm <- ifelse('n_permutations' %in% names(args_opt), strtoi(args_opt[['n_permutations']]), 10)

# Debug messages (stdout)
sink(stdout(), type = "message") # sink messages to stdout
message("Expression matrix file : ", input_expr_matrix)
message("Nb permutations : ", n_perm)
message("Nb threads : ", threads)
message("Output basename : ", output_prefix)
if ('tfs' %in% names(args_opt)) {
message("TFs : ", args_opt[['tfs']])
tfs <- strsplit(args_opt[['tfs']], ',')
} else {
# Load data
data(tfsData)
tfs <- tfsData\$Lambert2018\$SYMBOL
}
sink(NULL, type="message") # close the sink

# Input 1: 'object', a TNI object with regulons
# Input 2: 'phenotype', a named numeric vector, usually log2 differential expression levels
# Input 3: 'hits', a character vector, usually a set of differentially expressed genes
# Input 4: 'phenoIDs', an optional data frame with gene anottation mapped to the phenotype
rtna <- tni2tna.preprocess(object = tni_object, phenotype = degs_log2, hits = degs, phenoIDs = degs_annotation)

# TNA analysis here

saveRDS(rtni, file = "tni.rds")
saveRDS(rtni_permutation, file = "tni_permutated.rds")
saveRDS(rtni_bootstrapped, file = "tni_bootstrapped.rds")
saveRDS(rtni_filtered, file = "tni_filtered.rds")

# Plot
#pdf(paste0(output_prefix, "_RTN.pdf"))
#tni.graph(rtni_filtered, regulatoryElements = c("FOXM1", "E2F2"))
#title("Regulatory Transcriptional Network")
#mtext(output_prefix, side=3)
#dev.off 9E81 ()
#cat(
# paste("- Threads::", threads),
# fill=TRUE, labels=output_prefix,
# file=paste0(output_prefix, "_intercept_slope.txt"), append=FALSE
#)

################################################
################################################
## R SESSION INFO ##
################################################
################################################

sink(paste(output_prefix, "R_sessionInfo.log", sep = '.'))
print(sessionInfo())
sink()

################################################
################################################
## VERSIONS FILE ##
################################################
################################################

r.version <- strsplit(version[['version.string']], ' ')[[1]][3]
rtn.version <- as.character(packageVersion('RTN'))

writeLines(
c(
'"${task.process}":',
paste(' bioconductor-rtn:', rtn.version)
),
'versions.yml')

################################################
################################################
################################################
################################################
70 changes: 70 additions & 0 deletions modules/nf-core/rtn/tna/tests/main.nf.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
nextflow_process {

name "Test Process RTN_TNA"
script "../main.nf"
process "RTN_TNA"

tag "modules"
tag "modules_nfcore"
tag "rtn"
tag "rtn/tni"
tag "rtn/tna"

setup {
def content = "CYP24A1\nNNAT\nPHACTR3"
def DEGs = file("${workDir}/degs.tsv")
DEGs.text = content

run("RTN_TNI") {
script "../../../rtn/tni/main.nf"
process {
"""
input[0] = [
[id:'test'],
file(params.modules_testdata_base_path + 'genomics/homo_sapiens/riboseq_expression/salmon.merged.gene_counts_length_scaled.tsv', checkIfExists: true)
]
"""
}
}
}

test("musmusculus tna expression matrix - stub") {

options "-stub"

when {
process {
"""
input[0] = RTN_TNI.out.tni
input[1] = Channel.of([
[ id:'test', single_end: true ], // meta map
[ file("${workDir}/degs.tsv", checkIfExists: true) ]
])
input[2] = Channel.of([
[ id:'test', single_end: true ], // meta map
[ file(params.modules_testdata_base_path + 'genomics/mus_musculus/rnaseq_expression/treatment_mCherry_hND6_.deseq2.results_filtered.tsv', checkIfExists: true) ]
])
input[3] = Channel.of([
[ id:'test', single_end: true ], // meta map
[ ]
])
"""
}
}

then {
assertAll(
{ assert process.success },
{ assert file(process.out.tna_object[0][1]).exists() },
{ assert file(process.out.mra_object[0][1]).exists() },
{ assert file(process.out.gsea1_object[0][1]).exists() },
{ assert file(process.out.gsea1_plot[0][1]).exists() },
{ assert file(process.out.gsea2_object[0][1]).exists() },
{ assert file(process.out.gsea2_plot[0][1]).exists() },
{ assert file(process.out.versions[0]).exists() }
)
}

}

}
5 changes: 5 additions & 0 deletions modules/nf-core/rtn/tna/tests/nextflow.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
process {
withName: RTN_TNA {
ext.args = "--n_permutations 5"
}
}
5 changes: 5 additions & 0 deletions modules/nf-core/rtn/tna/tests/nextflow.config2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
process {
withName: RTN_TNA {
ext.args = '--tfs ENSG00000125798,ENSG00000125816'
}
}
5 changes: 5 additions & 0 deletions modules/nf-core/rtn/tna/tests/nextflow.config3
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
process {
withName: RTN_TNA {
ext.args = '--n_permutations 12 --tfs ENSG00000125798,ENSG00000125816'
}
}
2 changes: 2 additions & 0 deletions modules/nf-core/rtn/tna/tests/tags.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
rtn/tna:
- "modules/nf-core/rtn/tna/**"
Loading
0