bowtie.nf 3.08 KB
Newer Older
Laurent Modolo's avatar
Laurent Modolo committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*
* Bowtie :
* Imputs : fastq files
* Imputs : fasta files
* Output : bam files
*/

/*                      fasta indexing                                     */
params.fasta = "$baseDir/data/bam/*.fasta"

log.info "fasta files : ${params.fasta}"

Channel
  .fromPath( params.fasta )
  .ifEmpty { error "Cannot find any bam files matching: ${params.fasta}" }
  .set { fasta_file }

process index_fasta {
  tag "$fasta.baseName"
  cpus 4
  publishDir "results/mapping/index/", mode: 'copy'

  input:
    file fasta from fasta_file

  output:
    file "*.index*" into index_files
28
    file "*_report.txt" into indexing_report
Laurent Modolo's avatar
Laurent Modolo committed
29
30
31
32
33
34
35
36
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
62
63
64
65
66
67

  script:
"""
bowtie-build --threads ${task.cpus} -f ${fasta} ${fasta.baseName}.index &> ${fasta.baseName}_bowtie_report.txt

if grep -q "Error" ${fasta.baseName}_bowtie_report.txt; then
  exit 1
fi
"""
}



/*
* for paired-end data
*/

params.fastq = "$baseDir/data/fastq/*_{1,2}.fastq"
params.index = "$baseDir/data/index/*.index.*"

log.info "fastq files : ${params.fastq}"
log.info "index files : ${params.index}"

Channel
  .fromFilePairs( params.fastq )
  .ifEmpty { error "Cannot find any fastq files matching: ${params.fastq}" }
  .set { fastq_files }
Channel
  .fromPath( params.index )
  .ifEmpty { error "Cannot find any index files matching: ${params.index}" }
  .set { index_files }

process mapping_fastq {
  tag "$pair_id"
  cpus 4
  publishDir "results/mapping/bams/", mode: 'copy'

  input:
  set pair_id, file(reads) from fastq_files
68
  file index from index_files.collect()
Laurent Modolo's avatar
Laurent Modolo committed
69
70
71

  output:
  file "*.bam" into bam_files
72
  file "*_report.txt" into mapping_report
Laurent Modolo's avatar
Laurent Modolo committed
73
74
75
76

  script:
  index_id = index[0]
  for (index_file in index) {
77
  if (index_file =~ /.*\.1\.ebwt/ && !(index_file =~ /.*\.rev\.1\.ebwt/)) {
Laurent Modolo's avatar
Laurent Modolo committed
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
        index_id = ( index_file =~ /(.*)\.1\.ebwt/)[0][1]
    }
  }
"""
# -v specify the max number of missmatch, -k the number of match reported per
# reads
bowtie --best -v 3 -k 1 --sam -p ${task.cpus} ${index_id} \
-1 ${reads[0]} -2 ${reads[1]} 2> \
${pair_id}_bowtie_report.txt | \
samtools view -Sb - > ${pair_id}.bam

if grep -q "Error" ${pair_id}_bowtie_report.txt; then
  exit 1
fi
"""
}


/*
* for single-end data
*/
99
100
params.mean = 200
params.sd = 100
Laurent Modolo's avatar
Laurent Modolo committed
101
102
103

log.info "fastq files : ${params.fastq}"
log.info "index files : ${params.index}"
104
105
log.info "mean read size: ${params.mean}"
log.info "sd read size: ${params.sd}"
Laurent Modolo's avatar
Laurent Modolo committed
106
107
108
109

Channel
  .fromPath( params.fastq )
  .ifEmpty { error "Cannot find any fastq files matching: ${params.fastq}" }
110
  .map { it -> [(it.baseName =~ /([^\.]*)/)[0][1], it]}
Laurent Modolo's avatar
Laurent Modolo committed
111
112
113
114
115
116
117
  .set { fastq_files }
Channel
  .fromPath( params.index )
  .ifEmpty { error "Cannot find any index files matching: ${params.index}" }
  .set { index_files }

process mapping_fastq {
118
  tag "$file_id"
Laurent Modolo's avatar
Laurent Modolo committed
119
  cpus 4
120
  publishDir "results/mapping/quantification/", mode: 'copy'
Laurent Modolo's avatar
Laurent Modolo committed
121
122

  input:
123
  set file_id, file(reads) from fastq_files
124
  file index from index_files.collect()
Laurent Modolo's avatar
Laurent Modolo committed
125
126

  output:
127
  file "*" into count_files
Laurent Modolo's avatar
Laurent Modolo committed
128
129
130

  script:
"""
131
132
133
134
135
mkdir ${file_id}
kallisto quant -i ${index} -t ${task.cpus} --single \
--bias --bootstrap-samples 100 -o ${file_id} \
-l ${params.mean} -s ${params.sd} \
${reads} > ${file_id}_kallisto_report.txt
Laurent Modolo's avatar
Laurent Modolo committed
136
137
"""
}
138