From 36a3562cea56970e98d892916ca137226792480d Mon Sep 17 00:00:00 2001
From: Xavier Grand <157-xgrand@users.noreply.gitbio.ens-lyon.fr>
Date: Wed, 27 Jul 2022 14:16:50 +0200
Subject: [PATCH] Modif idx genome to Channel

---
 src/RNAseq_XGR.nf                  | 40 ++++++++++++++++++------------
 src/nf_modules/star/main_2.7.8a.nf |  6 ++---
 2 files changed, 27 insertions(+), 19 deletions(-)

diff --git a/src/RNAseq_XGR.nf b/src/RNAseq_XGR.nf
index 800501f..a5f8ff5 100644
--- a/src/RNAseq_XGR.nf
+++ b/src/RNAseq_XGR.nf
@@ -20,6 +20,7 @@ Maintainer Xavier Grand <xavier.grand@ens-lyon.fr>
 def helpMessage() {
     log.info"""
     Usage:
+    Pipeline dedicated to transcriptomic analysis of short-reads paired-ends RNAseq.
     The typical command for running the pipeline is as follows:
 
       nextflow ./src/RNAseq_XGR.nf -c ./src/nextflow.config -profile singularity
@@ -63,6 +64,7 @@ params.fastq = "${project}/fastq/*_{1,2}.fq.gz"
 params.gtf = ""
 params.fasta = ""
 params.idx = ""
+params.filter_bam = "-F 268 -f 1 -q 10"
 
 params.fastp_out = "$params.project/fastp/"
 params.star_mapping_fastq_out = "$params.project/STAR/"
@@ -107,6 +109,10 @@ include { index_with_gtf } from "./nf_modules/star/main_2.7.8a.nf"
 include { mapping_fastq } from "./nf_modules/star/main_2.7.8a.nf"
 include { mapping_withindex } from "./nf_modules/star/main_2.7.8a.nf"
 include { htseq_count } from "./nf_modules/htseq/main.nf"
+include { filter_bam } from "./nf_modules/samtools/main.nf"
+include { stats_bam } from "./nf_modules/samtools/main.nf"
+include { sort_bam } from "./nf_modules/samtools/main.nf"
+include { index_bam } from "./nf_modules/samtools/main.nf"
 
 /*
  ****************************************************************
@@ -120,20 +126,6 @@ workflow {
   // fastp
   fastp(fastq_files)
 
-  //########################## QUALITY CHECKS ###################
-
-  // fastqc_rawdata
-  fastqc_raw(fastq_files)
-  // fastqc_processed
-  fastqc_preprocessed(fastp.out.fastq.map { it -> [it [0], it[1]]})
-  // multiqc
-  multiqc(
-    fastqc_raw.out.report
-    .mix(
-      fastqc_preprocessed.out.report
-      ).collect()
-  )
-
   //############ GENOME INDEXATION AND MAPPING ###################
 
   if (params.idx == "") {
@@ -145,7 +137,7 @@ workflow {
     
     index_with_gtf(genome_file, gtf_file.collect())
     mapping_fastq(index_with_gtf.out.index.collect(), fastp.out.fastq)
-    htseq_count(mapping_fastq.out.bam, gtf_file)
+    
   }
   else {
     idx_genome = "${params.idx}"
@@ -153,7 +145,23 @@ workflow {
       .of( idx_genome )
       .set { genome_indexed_input }
     genome_indexed_input.view()
-    mapping_withindex(fastp.out.fastq)
+    mapping_withindex(genome_indexed_input.collect(), fastp.out.fastq)
     htseq_count(mapping_withindex.out.bam, gtf_file)
   }
+
+  htseq_count(mapping_fastq.out.bam, gtf_file)
+
+    //########################## QUALITY CHECKS ###################
+
+  // fastqc_rawdata
+  fastqc_raw(fastq_files)
+  // fastqc_processed
+  fastqc_preprocessed(fastp.out.fastq.map { it -> [it [0], it[1]]})
+  // multiqc
+  multiqc(
+    fastqc_raw.out.report
+    .mix(
+      fastqc_preprocessed.out.report
+      ).collect()
+  )
 }
diff --git a/src/nf_modules/star/main_2.7.8a.nf b/src/nf_modules/star/main_2.7.8a.nf
index 8e25ccd..91a74dc 100644
--- a/src/nf_modules/star/main_2.7.8a.nf
+++ b/src/nf_modules/star/main_2.7.8a.nf
@@ -185,7 +185,6 @@ mv ${reads_id}.Aligned.sortedByCoord.out.bam ${reads_id}.bam
 """
 }
 
-params.idx = ""
 process mapping_withindex {
   container = "${container_url}"
   label "big_mem_multi_cpus"
@@ -194,6 +193,7 @@ process mapping_withindex {
   }
 
   input:
+    val(index)
     tuple val(reads_id), path(reads) 
 
   output:
@@ -210,7 +210,7 @@ if (reads_id instanceof List){
 if (reads.size() == 2)
 """
 STAR --runThreadN ${task.cpus} \
---genomeDir ${params.idx} \
+--genomeDir ${index} \
 --readFilesCommand zcat \
 --readFilesIn ${reads[0]} ${reads[1]} \
 --outFileNamePrefix ${reads_id}. \
@@ -223,7 +223,7 @@ mv ${reads_id}.Aligned.sortedByCoord.out.bam ${reads_id}.bam
 else
 """
 STAR --runThreadN ${task.cpus} \
---genomeDir ${params.idx} \
+--genomeDir ${index} \
 --readFilesCommand zcat \
 --readFilesIn ${reads} \
 --outFileNamePrefix ${reads_id}. \
-- 
GitLab