From 82e6907d1add1d5fd1761e3ae16ccd7da183f822 Mon Sep 17 00:00:00 2001
From: xgrand <xavier.grand@inserm.fr>
Date: Wed, 31 May 2023 15:14:26 +0200
Subject: [PATCH] Add deseq2-wrapper

---
 .../deseq2-wrapper/1.0.0/Dockerfile           | 17 +++++++
 .../deseq2-wrapper/1.0.0/deseq2-wrapper.R     |  5 ++
 .../deseq2-wrapper/1.0.0/docker_init.sh       |  5 ++
 .../1.0.0/install_deseq2-wrapper.R            |  4 ++
 src/arriba_fusion.nf                          | 11 +++++
 src/nf_modules/concatenate/main.nf            | 48 +++++++++++++++++++
 src/nf_modules/fusion_parser/main.nf          |  1 +
 7 files changed, 91 insertions(+)
 create mode 100644 src/.docker_modules/deseq2-wrapper/1.0.0/Dockerfile
 create mode 100755 src/.docker_modules/deseq2-wrapper/1.0.0/deseq2-wrapper.R
 create mode 100755 src/.docker_modules/deseq2-wrapper/1.0.0/docker_init.sh
 create mode 100644 src/.docker_modules/deseq2-wrapper/1.0.0/install_deseq2-wrapper.R
 create mode 100755 src/nf_modules/concatenate/main.nf

diff --git a/src/.docker_modules/deseq2-wrapper/1.0.0/Dockerfile b/src/.docker_modules/deseq2-wrapper/1.0.0/Dockerfile
new file mode 100644
index 0000000..bf24a2d
--- /dev/null
+++ b/src/.docker_modules/deseq2-wrapper/1.0.0/Dockerfile
@@ -0,0 +1,17 @@
+FROM rocker/r-base:4.2.3
+
+LABEL MAINTAINER "Xavier Grand <xavier.grand@ens-lyon.fr>"
+
+RUN apt update && apt-get install -y apt-transport-https
+RUN apt install -y pandoc libfontconfig1-dev libcurl4-openssl-dev \
+                   libssl-dev libssh2-1-dev libxml2-dev zlib1g-dev \
+                   libharfbuzz-dev libfribidi-dev libfreetype6-dev \
+                   libpng-dev libtiff5-dev libjpeg-dev && \
+  R -e "install.packages(c('devtools', 'testthat', 'roxygen2', 'BiocManager', 'plotly'))" && \
+  R -e "BiocManager::install('DESeq2')"
+
+COPY *.R .
+
+RUN Rscript install_deseq2-wrapper.R
+
+CMD [ "bash" ]
\ No newline at end of file
diff --git a/src/.docker_modules/deseq2-wrapper/1.0.0/deseq2-wrapper.R b/src/.docker_modules/deseq2-wrapper/1.0.0/deseq2-wrapper.R
new file mode 100755
index 0000000..62b9783
--- /dev/null
+++ b/src/.docker_modules/deseq2-wrapper/1.0.0/deseq2-wrapper.R
@@ -0,0 +1,5 @@
+# deseq2-wrapper.R
+
+#!/bin/Rscript
+library(DESeqwrapper)
+cli_run_deseq2()
diff --git a/src/.docker_modules/deseq2-wrapper/1.0.0/docker_init.sh b/src/.docker_modules/deseq2-wrapper/1.0.0/docker_init.sh
new file mode 100755
index 0000000..d581461
--- /dev/null
+++ b/src/.docker_modules/deseq2-wrapper/1.0.0/docker_init.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+# docker pull xgrand/deseq2-wrapper:1.0.0
+docker build src/.docker_modules/deseq2-wrapper/1.0.0 -t 'xgrand/deseq2-wrapper:1.0.0'
+docker push xgrand/deseq2-wrapper:1.0.0
+# docker buildx build --platform linux/amd64,linux/arm64 -t "xgrand/deseq2-wrapper:1.0.0" --push src/.docker_modules/deseq2-wrapper/1.0.0
\ No newline at end of file
diff --git a/src/.docker_modules/deseq2-wrapper/1.0.0/install_deseq2-wrapper.R b/src/.docker_modules/deseq2-wrapper/1.0.0/install_deseq2-wrapper.R
new file mode 100644
index 0000000..9db139e
--- /dev/null
+++ b/src/.docker_modules/deseq2-wrapper/1.0.0/install_deseq2-wrapper.R
@@ -0,0 +1,4 @@
+#!/usr/bin/env Rscript
+install.packages("devtools")
+library(devtools)
+install_gitlab("LBMC/regards/deseq2-wrapper", host = "https://gitbio.ens-lyon.fr", quiet = FALSE)
diff --git a/src/arriba_fusion.nf b/src/arriba_fusion.nf
index 0d5c7db..f183a87 100644
--- a/src/arriba_fusion.nf
+++ b/src/arriba_fusion.nf
@@ -31,6 +31,7 @@ def helpMessage() {
     Input:
       --fastq [path]                  Path to fastq folder.
       --bam [path]                    Path to the bam folder (indexed and sorted).
+      --design [path]                 Path to the design file.
 
     References:                       Can be downloaded with download_references.sh (not implemented in pipeline).
       --genome [path]                 Path to genome reference fasta file.
@@ -83,6 +84,8 @@ params.star_mapping2fusion_out = "06_mapping2fusion"
 params.filter_bam_quality_out = "07_Filtered_bam"
 params.arriba_out = "10_Arriba_results"
 params.draw_fusions_out = "11_drawn_fusions"
+params.concat_fusion_out = "12_concat_fusions"
+params.fusion_out = "13_DFG"
 
 /*
  ****************************************************************
@@ -122,6 +125,10 @@ Channel
     .fromPath( params.gtf )
     .set { gtf_file }
 
+Channel
+    .fromPath( params.design )
+    .set { design }
+
 if(params.bam) {
     Channel
         .fromPath( bam_list )
@@ -162,6 +169,8 @@ include { index_bam } from './nf_modules/samtools/main.nf'
 include { htseq_count } from './nf_modules/htseq/main.nf' addParams(htseq_out: '09_htseq_count', htseq_param: "${params.htseq_param}" )
 include { arriba } from "./nf_modules/arriba/main.nf"
 include { draw_fusions } from "./nf_modules/arriba/main.nf"
+include { concat_fusion } from "./nf_modules/concatenate/main.nf"
+include { parsefusion } from "./nf_modules/fusion_parser/main.nf"
 
 /*
  ****************************************************************
@@ -232,4 +241,6 @@ workflow {
  ****************************************************************
 */
 
+  concat_fusion(arriba.out.fusions, arriba.out.discarded)
+  parsefusion(concat_fusion.out.concatenated_fusions)
 }
\ No newline at end of file
diff --git a/src/nf_modules/concatenate/main.nf b/src/nf_modules/concatenate/main.nf
new file mode 100755
index 0000000..c67cf8a
--- /dev/null
+++ b/src/nf_modules/concatenate/main.nf
@@ -0,0 +1,48 @@
+version = "3.15.4"
+container_url = "xgrand/alpine:${version}"
+
+
+params.fastq_out = ""
+process concatenate {
+    tag "fastq_folder"
+    label "big_mem_mono_cpus"
+
+    if (params.fastq_out != "") {
+        publishDir "results/${params.fastq_out}", mode: 'copy'
+    }
+
+    input:
+        path fastq
+
+    output:
+        path "merged.fastq.gz", emit: merged_fastq
+
+    script:
+"""
+zcat ${fastq}/*.fastq.gz > merged.fastq
+gzip --quiet merged.fastq
+"""
+}
+
+params.concat_fusion_out = ""
+process concat_fusion {
+    tag "concat_fusion"
+    label "big_mem_mono_cpus"
+
+    if (params.fastq_out != "") {
+        publishDir "results/${concat_fusion_out}", mode: 'copy'
+    }
+
+    input:
+        path fusions
+        path discarded_fusions
+
+    output:
+        path "*_fusions.tsv", emit: concatenated_fusions
+
+    script:
+"""
+cat ${fusions} > res_fusions.tsv
+tail +2 ${discarded_fusions} >> res_fusions.tsv
+"""
+}
\ No newline at end of file
diff --git a/src/nf_modules/fusion_parser/main.nf b/src/nf_modules/fusion_parser/main.nf
index ceac664..6023c3d 100644
--- a/src/nf_modules/fusion_parser/main.nf
+++ b/src/nf_modules/fusion_parser/main.nf
@@ -1,6 +1,7 @@
 version = "1.0"
 container_url = "xgrand/fusion_parser:${version}"
 
+params.fusion_out = ""
 process parsefusion{
   container = "${container_url}"
   label "big_mem_multi_cpus"
-- 
GitLab