-
Notifications
You must be signed in to change notification settings - Fork 1
/
LiftOver.nf
109 lines (88 loc) · 4.59 KB
/
LiftOver.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
#! /usr/bin/env nextflow
//vim: syntax=groovy -*- mode: groovy;-*-
// Copyright (C) 2017 IARC/WHO
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
params.help = null
params.input_folder = null
params.ref = null
params.chain_folder = null
params.output_folder = "liftover_output"
params.genome_from = null
params.genome_into = null
params.picard_jar = null
log.info ""
log.info "--------------------------------------------------------"
log.info " LiftOver-nf : Nextflow pipeline for picard liftover "
log.info "--------------------------------------------------------"
log.info "Copyright (C) IARC/WHO"
log.info "This program comes with ABSOLUTELY NO WARRANTY; for details see LICENSE"
log.info "This is free software, and you are welcome to redistribute it"
log.info "under certain conditions; see LICENSE for details."
log.info "--------------------------------------------------------"
log.info ""
if (params.help) {
log.info ''
log.info '--------------------------------------------------'
log.info ' USAGE '
log.info '--------------------------------------------------'
log.info ''
log.info 'Usage: '
log.info 'nextflow run iarcbioinf/LiftOver-nf --input_folder VCF/ --ref ref.fasta --chain_folder /data/chains'
log.info ''
log.info 'Mandatory arguments:'
log.info ' --input_folder FOLDER Folder containing input files.'
log.info ' --ref FILE (with index) Reference fasta file (target genome) indexed.'
log.info ' --chain_folder FOLDER Folder containing chains files.'
log.info ' --genome_from STRING Name of genome of inputs.'
log.info ' --genome_into STRING Name of genome of outputs.'
log.info ' --picard_jar STRING Path to executable picard jar.'
log.info 'Optional arguments:'
log.info ' --output_folder FOLDER Output folder (default: liftover_output).'
log.info ''
exit 1
}
assert (params.ref != true) && (params.ref != null) : "please specify --ref option (--ref reference.fasta(.gz))"
assert (params.genome_from != true) && (params.genome_from != null) : "please specify --genome_from option"
assert (params.genome_into != true) && (params.genome_into != null) : "please specify --genome_into option"
assert (params.input_folder != true) && (params.input_folder != null) : "please specify --input_folder option"
fasta_ref = file(params.ref)
fasta_ref_fai = file( params.ref+'.fai' )
chain_file = file( params.chain_folder + "/" + params.genome_from + 'To' + params.genome_into + '.over.chain.gz' )
try { assert fasta_ref.exists() : "\n WARNING : fasta reference not located in execution directory. Make sure reference index is in the same folder as fasta reference" } catch (AssertionError e) { println e.getMessage() }
if (fasta_ref.exists()) {assert fasta_ref_fai.exists() : "input fasta reference does not seem to have a .fai index (use samtools faidx)"}
try { assert file(params.input_folder).exists() : "\n WARNING : input folder not located in execution directory" } catch (AssertionError e) { println e.getMessage() }
// recovering of input files
f = Channel.fromPath( params.input_folder+'/*' )
.ifEmpty { error "Cannot find any file in: ${params.input_folder}" }
process liftover {
tag { input_tag }
publishDir params.output_folder, mode: 'move'
input:
file f
output:
file("${input_tag}_${params.genome_into}*") into outputs1
file("${input_tag}*reject*") into outputs2
shell:
input_tag = f.baseName.replace(".gz","").replace(".vcf","").replace(".txt","").replace(".bed","")
file_type = f.extension
if(file_type == "gz") file_type = "vcf"
'''
echo !{file_type}
java -jar !{params.picard_jar} LiftoverVcf \
I=!{f} \
O=!{input_tag}_!{params.genome_into}.!{file_type} \
C=!{chain_file} \
REJECT=!{input_tag}_!{params.genome_into}_reject.!{file_type} \
R=!{params.ref} \
VERBOSITY=ERROR
'''
}