forked from porchard/2020-sn-muscle
-
Notifications
You must be signed in to change notification settings - Fork 2
/
snp-roadmap-chromhmm-state.nf
96 lines (61 loc) · 1.62 KB
/
snp-roadmap-chromhmm-state.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
#!/usr/bin/env nextflow
SNP_BED_GLOB = params.snp_bed_glob
ROADMAP_BED_GLOB = params.roadmap_bed_glob
process sort_snps {
input:
file(x) from Channel.fromPath(SNP_BED_GLOB)
output:
file('snps.sorted.bed') into sort_snps_out
"""
cat $x | sort -k1,1 -k2n,2 > snps.sorted.bed
"""
}
process add_cell_type_and_state {
input:
file(x) from Channel.fromPath(ROADMAP_BED_GLOB)
output:
set val(cell_type), file('tmp.bed') into concat_by_cell_type_in
script:
cell_type = x.getName().replaceAll('.bed', '').tokenize('.')[0]
state = x.getName().replaceAll('.bed', '').tokenize('.')[1]
"""
cat $x | perl -pe 's/\$/\\t${cell_type}\\t${state}/' > tmp.bed
"""
}
process concat_by_cell_type {
input:
set val(cell_type), file("x.*.bed") from concat_by_cell_type_in.groupTuple()
output:
file("${cell_type}.bed") into intersect_in
"""
cat x.*.bed | sort -k1,1 -k2n,2 > ${cell_type}.bed
"""
}
process intersect {
input:
file(snps) from sort_snps_out
each file(bed) from intersect_in
output:
file('intersected.bed') into intersect_out
"""
bedtools intersect -sorted -a $snps -b $bed -wa -wb | cut -f1-3,7,8 > intersected.bed
"""
}
process concat {
publishDir "${params.results}/intersected"
input:
file("intersected.*.bed") from intersect_out.toSortedList()
output:
file('snp-overlap-with-roadmap-states.bed') into concat_out
"""
cat intersected.*.bed | sort -k1,1 -k2n,2 > snp-overlap-with-roadmap-states.bed
"""
}
process analyze {
publishDir "${params.results}/analyze"
input:
file(x) from concat_out
"""
check-snp-chromatin-state.R $x /lab/work/porchard/data/roadmap/roadmap_cell_types.txt
"""
}