From 7efa8d83bcb0febf9265b6e2d4d470477273a794 Mon Sep 17 00:00:00 2001 From: TuomasBorman Date: Fri, 22 Nov 2024 20:24:13 +0200 Subject: [PATCH 1/3] Add main nf file for TreeSE --- modules/local/treesummarizedexperiment.nf | 72 +++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 modules/local/treesummarizedexperiment.nf diff --git a/modules/local/treesummarizedexperiment.nf b/modules/local/treesummarizedexperiment.nf new file mode 100644 index 00000000..512426db --- /dev/null +++ b/modules/local/treesummarizedexperiment.nf @@ -0,0 +1,72 @@ +process TREESUMMARIZEDEXPERIMENT { + tag "$prefix" + label 'process_low' + + conda "bioconda::bioconductor-treesummarizedexperiment=2.10.0" + container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ? + 'https://depot.galaxyproject.org/singularity/bioconductor-treesummarizedexperiment%3A2.8.0--r43hdfd78af_0' : + 'bioconductor-treesummarizedexperiment%3A2.8.0--r43hdfd78af_0' }" + + input: + tuple val(prefix), path(tax_tsv), path(otu_tsv) + path sam_tsv + path tree + + output: + tuple val(prefix), path("*TreeSummarizedExperiment.rds"), emit: rds + path "versions.yml" , emit: versions + + when: + task.ext.when == null || task.ext.when + + script: + def sam_tsv = "\"${sam_tsv}\"" + def otu_tsv = "\"${otu_tsv}\"" + def tax_tsv = "\"${tax_tsv}\"" + def tree = "\"${tree}\"" + def prefix = "\"${prefix}\"" + """ + #!/usr/bin/env Rscript + + suppressPackageStartupMessages(library(TreeSummarizedExperiment)) + + # Read otu table. It must be in a list as a matrix. + otu_mat <- read.table($otu_tsv, sep="\\t", header=TRUE, row.names=1) + otu_mat <- as.matrix(otu_mat) + assays <- SimpleList(counts = otu_mat) + # Read taxonomy table. Correct format for it is DataFrame. + taxonomy_table <- read.table($tax_tsv, sep="\\t", header=TRUE, row.names=1) + taxonomy_table <- DataFrame(taxonomy_table) + + # Create TreeSE object. We assume that rownames between taxonomy table + # and abundance matrix match. + tse <- TreeSummarizedExperiment( + assays = assays, + rowData = taxonomy_table + ) + + # If provided, we add sample metadata as DataFrame object. rownames of + # sample metadata must match with colnames of abundance matrix. + if (file.exists($sam_tsv)) { + sample_meta <- read.table($sam_tsv, sep="\\t", header=TRUE, row.names=1) + sample_meta <- DataFrame(sample_meta) + colData(tse) <- sample_meta + } + + # If provided, we add phylogeny. The rownames in abundance matrix must match + # with node labels in phylogeny. + if (file.exists($tree)) { + phylogeny <- read_tree($tree) + rowTree(tse) <- phylogeny + } + + saveRDS(tse, file = paste0($prefix, "_TreeSummarizedExperiment.rds")) + + # Version information + writeLines(c("\\"${task.process}\\":", + paste0(" R: ", paste0(R.Version()[c("major","minor")], collapse = ".")), + paste0(" TreeSummarizedExperiment: ", packageVersion("TreeSummarizedExperiment"))), + "versions.yml" + ) + """ +} From fbd3bfab876d4f62c801561fce4a203d4712a206 Mon Sep 17 00:00:00 2001 From: TuomasBorman Date: Fri, 22 Nov 2024 20:31:47 +0200 Subject: [PATCH 2/3] up --- modules/local/treesummarizedexperiment.nf | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/local/treesummarizedexperiment.nf b/modules/local/treesummarizedexperiment.nf index 512426db..7a3ec269 100644 --- a/modules/local/treesummarizedexperiment.nf +++ b/modules/local/treesummarizedexperiment.nf @@ -30,7 +30,8 @@ process TREESUMMARIZEDEXPERIMENT { suppressPackageStartupMessages(library(TreeSummarizedExperiment)) - # Read otu table. It must be in a list as a matrix. + # Read otu table. It must be in a SimpleList as a matrix where rows + # represent taxa and columns samples. otu_mat <- read.table($otu_tsv, sep="\\t", header=TRUE, row.names=1) otu_mat <- as.matrix(otu_mat) assays <- SimpleList(counts = otu_mat) From bddb10434297f8ef3cd85bdd73321c404a9d8ae4 Mon Sep 17 00:00:00 2001 From: TuomasBorman Date: Fri, 22 Nov 2024 20:46:47 +0200 Subject: [PATCH 3/3] Fix TreeSE version --- modules/local/treesummarizedexperiment.nf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/local/treesummarizedexperiment.nf b/modules/local/treesummarizedexperiment.nf index 7a3ec269..d72b05fa 100644 --- a/modules/local/treesummarizedexperiment.nf +++ b/modules/local/treesummarizedexperiment.nf @@ -4,8 +4,8 @@ process TREESUMMARIZEDEXPERIMENT { conda "bioconda::bioconductor-treesummarizedexperiment=2.10.0" container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ? - 'https://depot.galaxyproject.org/singularity/bioconductor-treesummarizedexperiment%3A2.8.0--r43hdfd78af_0' : - 'bioconductor-treesummarizedexperiment%3A2.8.0--r43hdfd78af_0' }" + 'https://depot.galaxyproject.org/singularity/bioconductor-treesummarizedexperiment%3A2.10.0--r43hdfd78af_0' : + 'bioconductor-treesummarizedexperiment%3A2.10.0--r43hdfd78af_0' }" input: tuple val(prefix), path(tax_tsv), path(otu_tsv)