-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.nf
139 lines (110 loc) · 3.95 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
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
#!/usr/bin/env nextflow
/*
Simply run nextflow pipeline as:
// Better to use imputed dataset for snpmatch cross
nextflow run submit.snpmatch.nf --input "*vcf" --db hdf5_file --outdir output_folder
*/
/*
* SET UP CONFIGURATION VARIABLES
*/
params.input = false
// change input_column when providing bed file as input to read nth column
params.input_column = false
params.project = "the1001genomes"
params.outdir = 'snpmatch_1135g'
params.func = 'inbred'
params.genome = "athaliana_tair10"
params.skip_db_hets = false
// databases
params.db = "/groups/nordborg/projects/the1001genomes/scratch/rahul/101.VCF_1001G_1135/1135g_SNP_BIALLELIC.hetfiltered.snpmat.6oct2015.hdf5"
//input files
input_files = Channel
.fromPath ( params.input )
.map { [ "$it.baseName", "${it.getParent()}", file("$it") ] }
.ifEmpty { exit 1, "Cannot find any input files matching: ${params.input}\nNB: Path needs to be enclosed in quotes!\n" }
Channel
.fromPath ( params.db )
.map{ [ file("${it}"), file("${it.parent}/${it.baseName}.acc.hdf5") ] }
.ifEmpty { exit 1, "please provide hdf5 files as a database" }
.into{ db_file; db_file_for_csv}
process parse_inputfiles {
tag { "${prefix}" }
publishDir "${input_folder}", mode: 'copy'
// storeDir "${input_folder}"
input:
set val(prefix), val(input_folder), file(input_file) from input_files
output:
set val(prefix), file("${input_file}.snpmatch.npz") into input_gzips
file "${input_file}.snpmatch.stats.json" into input_stats
script:
if (params.input_column){
"""
awk '{print \$1 "\t" \$2 "\t" \$${params.input_column}}' $input_file > ${input_file}.col.bed
snpmatch parser -v -i ${input_file}.col.bed -o ${input_file}.snpmatch
"""
} else{
"""
snpmatch parser -v -i $input_file -o ${input_file}.snpmatch
"""
}
}
input_files_dbs = input_gzips.combine(db_file)
if (params.func == 'inbred'){
process identify_libraries {
tag { "${prefix}" }
publishDir "$params.outdir", mode: 'copy'
errorStrategy { task.exitStatus in [143,137] ? 'retry' : 'ignore' }
input:
set val(prefix), file(input_npz), file(f_db), file(f_db_acc) from input_files_dbs
output:
file "snpmatch_${prefix}" into snpmatch_output
script:
skip_db_hets = params.skip_db_hets != false ? "--skip_db_hets" : ''
"""
mkdir -p snpmatch_${prefix}
snpmatch inbred -v $skip_db_hets -d $f_db -e $f_db_acc -i $input_npz -o snpmatch_${prefix}/${prefix} --refine
"""
}
input_csv = snpmatch_output.collect()
process make_csv_inbred {
publishDir "$params.outdir", mode: 'copy'
input:
file "*" from input_csv
output:
file "intermediate_modified.csv" into output_csv
"""
python $workflow.projectDir/bin/01_makeCSVTable_inbred.py --dirs -i ./ -o intermediate_modified.csv -f $params.outdir
"""
}
}
if (params.func == 'cross'){
process cross_libraries {
tag { "${prefix}" }
publishDir "$params.outdir", mode: 'copy'
// storeDir "$params.outdir"
errorStrategy { task.exitStatus in [143,137] ? 'retry' : 'ignore' }
// cross generally puts out many errors based on the number of SNPs in a window and chromosome
input:
set val(prefix), file(input_npz), file(f_db), file(f_db_acc) from input_files_dbs
output:
file "csmatch_${prefix}" into snpmatch_output
script:
skip_db_hets = params.skip_db_hets != false ? "--skip_db_hets" : ''
"""
mkdir -p csmatch_${prefix}
snpmatch cross -v $skip_db_hets -d $f_db -e $f_db_acc -i $input_npz -o csmatch_${prefix}/${prefix}.csmatch --genome $params.genome
"""
}
input_csv = snpmatch_output.collect()
process make_csv_cross {
publishDir "$params.outdir", mode: 'copy'
input:
file "*" from input_csv
set file(f_db), file(f_db_acc) from db_file_for_csv
output:
file "intermediate_modified*" into output_csv
"""
python $workflow.projectDir/bin/02_makeCSVTable_csmatch.py -d $f_db --dirs -i ./ -o intermediate_modified -f $params.outdir
"""
}
}