-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpeaks_histonmodifications.groovy
106 lines (87 loc) · 2.5 KB
/
peaks_histonmodifications.groovy
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
def file = new File("Data/BroadHistone_K562_ControlStdAln_Rep1.sam")
String annotationFile = "./shortTssAnnotationhg19_sorted.bed"
String samFile = "short2.sam"
hits = [:]
keyList = []
tmpHits = 0
totalHits = 0
annotationMap = [:]
def samMap = [:]
cnt = 0
annotationMap = readAnnotationFiles(annotationFile)
annotationMap.keySet().each{
keyList.add(it)
annotationMap.get(it).sort()
println "${it} | Size = ${annotationMap.get(it).size()}"
}
println keyList
readSamFiles(samFile)
println hits
println "Total Hits: ${totalHits}"
def readSamFiles(String path){
def map = [:]
def list = []
def file = new File(path)
def cnt = 0
def tmp = annotationMap.get(keyList[cnt])
//println tmp
//println "tmp: ${tmp}"
def j = 0
file.eachLine{
def (value1, value2) = it.tokenize( ' ' )
//println "value1 = ${value1} | keyList[cnt] = ${keyList[cnt]}"
//println "value1 = ${value1} | ${value1.getClass()} & keyList[cnt] = ${keyList[cnt]} | ${keyList[cnt].getClass()}"
//println "value2 = ${value2.toInteger()} | ${value2.toInteger().getClass()} & tmp = ${tmp[0]} | ${tmp[0].getClass()}"
if(value1 == keyList[cnt]){
value2 = value2.toInteger()
/*while(j < tmp.size() && value2 < tmp[j]-1000){
//j = j+1
//println "Before ${value2}"
return
//println "Diag: chr = ${value1}|${keyList[cnt]} j = ${j} | tmp[{$j}] = ${tmp[j]} & ${tmp[j].getClass()} | tmp.size = ${tmp.size()}"
}*/
while(j < tmp.size() && value2 > tmp[j]+1000){
j++
}
while(j < tmp.size() && value2 > tmp[j]-1000 && value2 < tmp[j]+1000){ // && value2 < tmp[j]+1000){
//println "tmp = ${tmp}"
//println "j = ${j} | tmp[j] = ${tmp[j]}"
//println tmpHits
//println "After: ${value2}"
tmpHits = tmpHits + 1
totalHits++
//println "Hit: ${value1}"
hits.put(value1, tmpHits)
//println "Chromosom: ${keyList[cnt]} | Value2: ${value2} | tmp[${j}]: ${tmp[j]}"
j = j+1
}
} else {
//println "Before: value1 = ${value1} | keyList[${cnt}] = ${keyList[cnt]}"
if(cnt < keyList.size()){
cnt++
tmp = annotationMap.get(keyList[cnt])
//println "After: value1 = ${value1} | keyList[${cnt}] = ${keyList[cnt]}"
}
tmpHits = 0
j = 0
}
}
//println "Hits: ${hits}"
}
def readAnnotationFiles(String path){
def map = [:]
def list = []
def file = new File(path)
def tmp = "chr1"
file.each{
def (value1, value2) = it.tokenize('\t')
if(value1!=tmp){
tmp = value1
list = []
}
list.add(value2.toInteger())
map.put(tmp, list)
}
return map
}
//println annotationMap.get("chr1")