-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.nf
81 lines (71 loc) · 2.35 KB
/
main.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
#!/usr/bin/env nextflow
include { alignReads; get_container; set_key_for_group_tuple } from "./aligning"
include { callHotspots } from "./hotspots_calling"
include { trimReadsFromFile; trimReads } from "./trimming"
process symlink_or_download {
publishDir "${params.outdir}/${sample_id}/stats", pattern: "${metadata}"
publishDir "${params.outdir}/${sample_id}", pattern: "${srr}/*.fastq.gz"
cpus params.threads
tag "${srr}"
maxForks 4
scratch true
errorStrategy 'ignore'
container "${params.container}"
containerOptions "--network=host"
input:
tuple val(sample_id), val(srr)
output:
tuple val(sample_id), val(srr), path("${srr}/${srr}_1.fastq.gz"), path("${srr}/${srr}_2.fastq.gz"), path("${srr}/${srr}.fastq.gz"), emit: fastq
tuple val(srr), path(metadata), emit: meta
script:
metadata = "${srr}_info.json"
"""
if prefetch -L 1 ${srr}; then
echo 'Prefetched'
ffq -o ${metadata} ${srr} 2>&1 || echo 'No metadata downloaded.' > ${metadata}
fasterq-dump -L 1 -f --threads ${task.cpus} -O ${srr} ${srr} 2>&1
find ./${srr} -name "*.fastq" -exec pigz {} \\;
else
touch ${metadata}
fi
if ! [ -d ${srr} ]; then
mkdir ${srr}
fi
touch ${srr}/${srr}_1.fastq.gz
touch ${srr}/${srr}_2.fastq.gz
touch ${srr}/${srr}.fastq.gz
"""
}
workflow downloadFiles {
main:
ids_channel = set_key_for_group_tuple(Channel.fromPath(params.samples_file)
.splitCsv(header:true, sep:'\t')
.map(row -> tuple(row.sample_id, row.align_id))).unique { it[1] }
reads = symlink_or_download(ids_channel).fastq
// Check if is_paired and convert to trimming pipeline format
output = reads.filter { file(it[2]).size() + file(it[3]).size() + file(it[4]).size() != 0 }
.map(
it -> (file(it[2]).size() == 0) ?
tuple(it[0], it[1], it[4], "${projectDir}", "", "", false) :
tuple(it[0], it[1], it[2], it[3], "", "", true)
)
emit:
output
}
workflow alignTrimmed {
take:
data
main:
out = alignReads(data) // | callHotspots
emit:
out
}
workflow alignFromSRA {
downloadFiles() | trimReads | alignTrimmed
}
workflow alignOnly {
trimReadsFromFile() | alignReads
}
workflow {
trimReadsFromFile() | alignTrimmed
}