-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap_reads.nf
137 lines (112 loc) · 2.92 KB
/
map_reads.nf
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
28
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
process star_index {
tag "STAR: indexing ${ref.getName()}"
container 'https://depot.galaxyproject.org/singularity/star:2.7.9a--h9ee0642_0'
cpus params.max_cpus
memory params.max_memory
input:
path ref
val refsize
output:
path index_dir
script:
log2refsize = 31 - Integer.numberOfLeadingZeros( refsize as Integer )
genomeSAindexNbases = Math.min(14.0, log2refsize/2.0 - 1.0) as Integer
index_dir = 'STAR_index'
"""
mkdir $index_dir && \
STAR --runMode genomeGenerate \
--runThreadN $task.cpus \
--limitGenomeGenerateRAM ${task.memory.toBytes()} \
--genomeSAindexNbases $genomeSAindexNbases \
--genomeFastaFiles $ref \
--genomeDir $index_dir
"""
}
process star_align {
tag "Mapping $readfq"
container 'https://depot.galaxyproject.org/singularity/star:2.7.9a--h9ee0642_0'
cpus params.max_cpus
memory params.max_memory
// Override with extra time for STAR alignment
time '6h'
input:
path readfq
path index
output:
path "${outprefix}.bam"
script:
outprefix = readfq.getSimpleName()
// 80% of available mem for bam sorting (bytes)
bam_mem_limit = task.memory.toBytes() *0.8 as Integer
"""
STAR --runMode alignReads \
--runThreadN $task.cpus \
--readFilesCommand zcat \
--alignEndsType EndToEnd \
--twopassMode None \
--alignIntronMax 1 \
--outFilterScoreMin $params.sam_qual \
--outFilterMismatchNmax $params.alignment_mismatch \
--outSAMtype BAM SortedByCoordinate \
--outStd BAM_SortedByCoordinate \
--limitBAMsortRAM ${bam_mem_limit} \
--genomeDir $index \
--readFilesIn $readfq \
--outFileNamePrefix $outprefix \
> ${outprefix}.bam
"""
}
process ref_size {
tag "Getting size of reference ${ref.getName()}"
input:
path ref
output:
env REFSIZE
"""
REFSIZE=\$( \
gzip -dc < $ref | \
awk 'BEGIN{ ORS=""} /^[^>]/ {print \$0}' | \
wc -c \
)
"""
}
process decompress {
tag "Decompressing $gzfile"
input:
path gzfile
output:
path "${gzfile.getBaseName()}"
"""
gzip -dc < $gzfile > ${gzfile.getBaseName()}
"""
}
process samtools_index {
tag "Indexing bam: $bam"
container 'https://depot.galaxyproject.org/singularity/samtools:1.12--hd5e65b6_0'
cpus params.max_cpus
// publishDir "${params.outdir}/alignments"
input:
path bam
output:
tuple(path(bam), path(bai))
script:
bai = "${bam}.bai"
"""
samtools index -@ $task.cpus $bam $bai
"""
}
workflow map_reads {
take:
reads
reference
main:
ref_size(reference)
star_index(decompress(reference), ref_size.out)
star_align(reads, star_index.out)
samtools_index(star_align.out)
// alignments = star_align.out
// .join(samtools_index.out.map{[ it.getBaseName(), it]})
// alignments.view()
emit:
indexed_bam = samtools_index.out
}