From 54248eb51283118e223f7b414a30799ee0293444 Mon Sep 17 00:00:00 2001 From: Adrian Date: Mon, 21 Aug 2023 14:41:44 +0200 Subject: [PATCH] final tested commit stage one (#14) --- bin/index-downstream.R | 75 ++++++++++++++++++++++++++ conf/environments.config | 5 ++ modules/local/downstream_processing.nf | 6 +++ modules/local/subread.nf | 2 +- 4 files changed, 87 insertions(+), 1 deletion(-) create mode 100755 bin/index-downstream.R diff --git a/bin/index-downstream.R b/bin/index-downstream.R new file mode 100755 index 0000000..e60e257 --- /dev/null +++ b/bin/index-downstream.R @@ -0,0 +1,75 @@ +#!/usr/bin/env Rscript + +# Setup ------------------------------------------------------------------- +args <- commandArgs(trailingOnly = TRUE) + +downstream_ch_file <- args[1] +organism_in <- args[2] +user_file <- args[3] + +if (organism_in == 'mouse') { + organism <- 'mus_musculus' +} else if (organism_in == 'human') { + organism <- 'homo_sapiens' +} else { + stop('Provided organism not supported...') +} + +#downstream_ch_file <- "/futuriandgeDownstream/used-locally-for-testing/counts/extended_source-pipeline-out_meta_file-dockerfile.txt" +#organism <- 'mus_musculus' +#user_file <- "/futuriandgeDownstream/used-locally-for-testing/template-user-request.xlsx" + +sample_metadata <- readxl::read_excel(user_file, sheet = 'metadata') +contrasts <- readxl::read_excel(user_file, sheet = 'comparisons') + +# Load -------------------------------------------------------------------- +library(futuriandgeDownstream) + +# F1 +print('Running futuriandgeDownstream::return_count_matrix') +counts <- futuriandgeDownstream::return_count_matrix(downstream_ch_file) + +# F2 +print('Running futuriandgeDownstream::remove_mirna') +counts_no_mirnas <- futuriandgeDownstream::remove_mirna(counts, organism) + +# F3 +print('Running futuriandgeDownstream::run_dge') +dge_results <- futuriandgeDownstream::run_dge(count_matrix_raw = counts_no_mirnas, + metadata_raw = sample_metadata, + comparisons = contrasts) + +# save dge results +print('Running save') +save(dge_results, file = 'dge_results.RData') + +# F4 +print('Running splot_diagnostic_plotsave') +futuriandgeDownstream::plot_diagnostic_plots(count_matrix_raw = counts_no_mirnas, + metadata_raw = sample_metadata) + +# F5 +print('futuriandgeDownstream::render_dge_html_report') +contrasts_for_report <- dplyr::mutate(contrasts, compared_gorups = paste0( + studied_effect, + '_vs_', + baseline + )) + +for (groups in contrasts_for_report$compared_gorups) { + + sample_metadata$sample <- gsub("_T1", + "", + sample_metadata$sample_id) + + futuriandgeDownstream::render_dge_html_report( + comparison_name = groups, + dge_results_in = data.frame(dge_results$dge_results[[groups]]), + metadata = sample_metadata, + norm_counts = dge_results$normalised_counts, + raw_counts = dge_results$raw_counts_no_gtf_miRNA, + organism = organism, + output_name = paste0(groups, ".html") + ) +} + diff --git a/conf/environments.config b/conf/environments.config index f40001e..cb1f642 100644 --- a/conf/environments.config +++ b/conf/environments.config @@ -61,4 +61,9 @@ container = 'https://depot.galaxyproject.org/singularity/multiqc:1.14--pyhdfd78af_0' } + withName: DESEQ2 { + container = 'sodzier/r-pkg-futuriandge-downstream:0.1.0' + containerOptions = "-B ${baseDir}/.nextflow:/futuriandgeDownstream" +} + } diff --git a/modules/local/downstream_processing.nf b/modules/local/downstream_processing.nf index c832266..d9403ca 100644 --- a/modules/local/downstream_processing.nf +++ b/modules/local/downstream_processing.nf @@ -11,11 +11,17 @@ process DESEQ2 { output: path("*"), emit: DESeq2_DOWNSTREAM_out + script: + def org = params.organism + def user_file = params.contrasts """ # Merge all downstream info files cat *_downstream_info.txt > all_downstream_info.txt # Remove lines containing the header except for the first occurrence in the first line sed -i '1!{/sample_id,is_single_end,strandedness,count_matrix_path/d}' all_downstream_info.txt + + index-downstream.R all_downstream_info.txt ${org} ${user_file} + """ } diff --git a/modules/local/subread.nf b/modules/local/subread.nf index b07f116..f7269d4 100644 --- a/modules/local/subread.nf +++ b/modules/local/subread.nf @@ -42,6 +42,6 @@ process FEATURECOUNTS { echo "sample_id,is_single_end,strandedness,count_matrix_path" > ${meta.id}_downstream_info.txt # Write sample info to file - echo "${meta.id},${meta.single_end},${meta.strandedness},${PWD}/${meta.id}_featureCounts_matrix.txt" >> ${meta.id}_downstream_info.txt + echo "${meta.id},${meta.single_end},${meta.strandedness},\$PWD/${meta.id}_featureCounts_matrix.txt" >> ${meta.id}_downstream_info.txt """ }