RNAseq_XGR.nf 5.25 KB
Newer Older
Xavier Grand's avatar
Xavier Grand committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env nextflow

nextflow.enable.dsl=2

/*
========================================================================================================================
                                                      RNAseq_XGR
========================================================================================================================

RNAseq_XGR pipeline :
 * Pipeline dedicated to transcriptomic analysis.

Maintainer Xavier Grand <xavier.grand@ens-lyon.fr>

 ****************************************************************
                      Help Message Definition
 ****************************************************************
*/

def helpMessage() {
    log.info"""
    Usage:
Xavier Grand's avatar
Xavier Grand committed
23
    Pipeline dedicated to transcriptomic analysis of short-reads paired-ends RNAseq.
Xavier Grand's avatar
Xavier Grand committed
24
25
    The typical command for running the pipeline is as follows:

26
      nextflow ./src/RNAseq_XGR.nf -c ./src/nextflow.config -profile singularity
Xavier Grand's avatar
Xavier Grand committed
27
28

    Mandatory arguments:
29
      --project [path]                Path to the fastq folder.
Xavier Grand's avatar
Xavier Grand committed
30
31
32
33
34
35
      -profile [str]                  Configuration profile to use.
                                      Available: docker, singularity, podman, psmn, ccin2p3

    References:
      --fasta [path]                  Path to genome fasta file.
      --gtf [path]                    Path to the gtf annotation file.
36
      --idx [path]                    Path to the STAR indexed genome (optional). (If allready computed)
Xavier Grand's avatar
Xavier Grand committed
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61

    Help:                             Display this help message.
      --help
      --h
    
    """.stripIndent()
}

// Show help message

params.help = ""
params.h = ""

if (params.help || params.h) {
    helpMessage()
    exit 0
}

/*
 ****************************************************************
                      Default Parameters
 ****************************************************************
*/
 
/* Arguments */
62
params.project = ""
63
params.fastq = "${params.project}/fastq/*{1,2}.fastq"
Xavier Grand's avatar
Xavier Grand committed
64
65
params.gtf = ""
params.fasta = ""
66
params.idx = ""
67
params.filter_bam_mapped = "-F 268 -f 1 -q 10"
Xavier Grand's avatar
Xavier Grand committed
68

69
70
71
params.fastp_out = "fastp/"
params.star_mapping_fastq_out = "STAR/"
params.star_index_out = "STARindex/"
Xavier Grand's avatar
Xavier Grand committed
72
73
74
75
76
77
78
79
80

/*
 ****************************************************************
                              Logs
 ****************************************************************
*/

log.info "Annotation: ${params.gtf}"
log.info "Genome fasta file: ${params.fasta}"
81
log.info "Genome index location: ${params.idx}"
Xavier Grand's avatar
Xavier Grand committed
82
83
84
85
86
87
88
89
90
91
92

/*
 ****************************************************************
                        Channel definitions
 ****************************************************************
*/

Channel
  .fromFilePairs( params.fastq, size: -1 )
  .set { fastq_files }

93
Channel
94
  .fromPath( params.gtf )
95
96
  .set { gtf_file }

Xavier Grand's avatar
Xavier Grand committed
97
98
99
100
101
102
103
/*
 ****************************************************************
                          Imports
 ****************************************************************
*/

fastqc_mod = "./nf_modules/fastqc/main.nf"
Xavier Grand's avatar
Xavier Grand committed
104
105
106
include { fastqc_fastq as fastqc_raw } from fastqc_mod addParams(fastqc_fastq_out: "01_fastqc_raw/")
include { fastqc_fastq as fastqc_preprocessed } from fastqc_mod addParams(fastqc_fastq_out: "02_fastqc_preprocessed/")
include { multiqc } from './nf_modules/multiqc/main.nf' addParams(multiqc_out: "QC/")
Xavier Grand's avatar
Xavier Grand committed
107
include { fastp } from "./nf_modules/fastp/main.nf"
108
109
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"
110
include { mapping_withindex } from "./nf_modules/star/main_2.7.8a.nf"
111
include { htseq_count } from "./nf_modules/htseq/main.nf"
112
113

include { filter_bam_mapped } from "./nf_modules/samtools/main.nf"
Xavier Grand's avatar
Xavier Grand committed
114
115
116
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"
Xavier Grand's avatar
Xavier Grand committed
117
118
119
120
121
122
123
124
125
126
127

/*
 ****************************************************************
                          Workflow
 ****************************************************************
*/

workflow {

  //########################## PREPROCESSING ####################   
  // fastp
128
  fastp(fastq_files)
Xavier Grand's avatar
Xavier Grand committed
129
130
131

  //############ GENOME INDEXATION AND MAPPING ###################

132
133
  if (params.idx == "") {
    Channel
134
      .fromPath( params.fasta )
135
      .ifEmpty { error "Cannot find any files matching: ${params.fasta}" }
136
137
138
      .map{it -> [(it.baseName =~ /([^\.]*)/)[0][1], it]}
      .set { genome_file }
    
139
    index_with_gtf(genome_file, gtf_file.collect())
140
    mapping_fastq(index_with_gtf.out.index.collect(), fastp.out.fastq)
141
    filter_bam_mapped(mapping_fastq.out.bam)
142
  }
143
  else {
144
    idx_genome = "${params.idx}"
145
    Channel
146
      .of( idx_genome )
147
      .set { genome_indexed_input }
148
    genome_indexed_input.view()
Xavier Grand's avatar
Xavier Grand committed
149
    mapping_withindex(genome_indexed_input.collect(), fastp.out.fastq)
150
151
    stats_bam(mapping_withindex.out.bam)
    filter_bam_mapped(mapping_withindex.out.bam)
152
  }
Xavier Grand's avatar
Xavier Grand committed
153

154
  sort_bam(filter_bam_mapped.out.bam)
155
156
  index_bam(sort_bam.out.bam)
  htseq_count(sort_bam.out.bam, gtf_file)
Xavier Grand's avatar
Xavier Grand committed
157
158
159
160
161
162
163
164
165
166
167
168
169
170

    //########################## 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()
  )
Xavier Grand's avatar
Xavier Grand committed
171
}