mapping_single.nf 1.17 KB
Newer Older
Laurent Modolo's avatar
Laurent Modolo committed
1
2
3
4
/*
* mapping single end fastq
*/

Laurent Modolo's avatar
Laurent Modolo committed
5
6
7
8
9
10
11
12
params.fastq = "$baseDir/data/fastq/*.fastq"

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

Channel
  .fromPath( params.fastq )
  .ifEmpty { error "Cannot find any fastq files matching: ${params.fastq}" }
13
  .map { it -> [(it.baseName =~ /([^\.]*)/)[0][1], it]}
Laurent Modolo's avatar
Laurent Modolo committed
14
15
16
17
18
19
20
  .set { fastq_files }
Channel
  .fromPath( params.index )
  .ifEmpty { error "Cannot find any index files matching: ${params.index}" }
  .set { index_files }

process mapping_fastq {
21
  tag "$file_id"
Laurent Modolo's avatar
Laurent Modolo committed
22
23
24
25
  cpus 4
  publishDir "results/mapping/bams/", mode: 'copy'

  input:
26
  set file_id, file(reads) from fastq_files
27
  file index from index_files.collect()
Laurent Modolo's avatar
Laurent Modolo committed
28
29

  output:
30
  set file_id, "*.bam" into bam_files
31
  file "*_report.txt" into mapping_report
Laurent Modolo's avatar
Laurent Modolo committed
32
33
34
35

  script:
index_id = index[0]
for (index_file in index) {
36
  if (index_file =~ /.*\.1\.ebwt/ && !(index_file =~ /.*\.rev\.1\.ebwt/)) {
Laurent Modolo's avatar
Laurent Modolo committed
37
38
39
40
41
      index_id = ( index_file =~ /(.*)\.1\.ebwt/)[0][1]
  }
}
"""
bowtie --best -v 3 -k 1 --sam -p ${task.cpus} ${index_id} \
42
-q ${reads} 2> \
43
44
${file_id}_bowtie_report.txt | \
samtools view -Sb - > ${file_id}.bam
Laurent Modolo's avatar
Laurent Modolo committed
45

46
if grep -q "Error" ${file_id}_bowtie_report.txt; then
Laurent Modolo's avatar
Laurent Modolo committed
47
48
49
50
  exit 1
fi
"""
}