-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathteloclip.nf
More file actions
197 lines (161 loc) · 4.02 KB
/
Copy pathteloclip.nf
File metadata and controls
197 lines (161 loc) · 4.02 KB
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/usr/bin/env nextflow
/*
* Teloclip Example Workflow
*
* This workflow demonstrates how to use teloclip in a Nextflow pipeline
* with proper containerization (each tool in its own container).
*
* Example usage:
* nextflow run teloclip.nf --bam input.bam --ref ref.fa
*/
nextflow.enable.dsl=2
// Parameters
params.bam = null
params.ref = null
params.outdir = "results"
params.motifs = "TTAGGG"
params.min_repeats = 1
// Check required parameters
if (!params.bam) error "Please provide --bam parameter"
if (!params.ref) error "Please provide --ref parameter"
/*
* Process: Index reference FASTA
*/
process INDEX_FASTA {
container 'quay.io/biocontainers/samtools:latest'
publishDir "${params.outdir}/ref", mode: 'copy'
input:
path ref
output:
path "${ref}.fai"
script:
"""
samtools faidx ${ref}
"""
}
/*
* Process: Convert BAM to SAM
*/
process BAM_TO_SAM {
container 'quay.io/biocontainers/samtools:latest'
input:
path bam
output:
path "input.sam"
script:
"""
samtools view -h ${bam} > input.sam
"""
}
/*
* Process: Filter alignments with teloclip
*/
process TELOCLIP_FILTER {
container 'adamtaranto/teloclip:latest'
publishDir "${params.outdir}/filtered", mode: 'copy'
input:
path sam
path fai
output:
path "overhangs.sam"
script:
def motif_arg = params.motifs ? "--motifs ${params.motifs}" : ""
def repeats_arg = params.min_repeats > 1 ? "--min-repeats ${params.min_repeats}" : ""
"""
teloclip filter \
--ref-idx ${fai} \
${motif_arg} \
${repeats_arg} \
${sam} > overhangs.sam
"""
}
/*
* Process: Convert SAM to sorted BAM
*/
process SAM_TO_BAM {
container 'quay.io/biocontainers/samtools:latest'
publishDir "${params.outdir}/filtered", mode: 'copy'
input:
path sam
output:
tuple path("overhangs.bam"), path("overhangs.bam.bai")
path sam
script:
"""
samtools sort ${sam} > overhangs.bam
samtools index overhangs.bam
"""
}
/*
* Process: Extract overhang sequences (optional)
*/
process TELOCLIP_EXTRACT {
container 'adamtaranto/teloclip:latest'
publishDir "${params.outdir}/extracted", mode: 'copy'
input:
path sam
path fai
output:
path "overhangs/*.fasta"
script:
"""
mkdir -p overhangs
teloclip extract \
--ref-idx ${fai} \
--extract-dir overhangs \
${sam}
"""
}
/*
* Process: Extend telomeric sequences
*/
process TELOCLIP_EXTEND {
container 'adamtaranto/teloclip:latest'
publishDir "${params.outdir}/extended", mode: 'copy'
input:
tuple path(bam), path(bai)
path ref
path fai
output:
path "*_extended.fasta"
path "*_extension_report.txt"
script:
"""
teloclip extend \\
${bam} \\
${ref} \\
--output-fasta teloclip_extended.fasta \\
--stats-report teloclip_extension_report.txt \\
--count-motifs ${params.motifs} \\
--screen-terminal-bases 1000
"""
}
/*
* Main workflow
*/
workflow {
// Create channels
bam_ch = Channel.fromPath(params.bam)
ref_ch = Channel.fromPath(params.ref)
// Index reference
fai_ch = INDEX_FASTA(ref_ch)
// Convert BAM to SAM
sam_ch = BAM_TO_SAM(bam_ch)
// Filter with teloclip
filtered_sam = TELOCLIP_FILTER(sam_ch, fai_ch)
// Convert to sorted and indexed BAM
sam_bam_outputs = SAM_TO_BAM(filtered_sam)
bam_indexed = sam_bam_outputs[0]
filtered_sam_copy = sam_bam_outputs[1]
// Extract sequences (optional - runs in parallel with extend)
TELOCLIP_EXTRACT(filtered_sam_copy, fai_ch)
// Extend reference genome with telomeric sequences
TELOCLIP_EXTEND(bam_indexed, ref_ch, fai_ch)
}
workflow.onComplete {
println "Pipeline completed!"
println "Results saved to: ${params.outdir}"
println " - Filtered BAM: ${params.outdir}/filtered/"
println " - Extracted sequences: ${params.outdir}/extracted/"
println " - Extended genome: ${params.outdir}/extended/"
}