-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdebug-graham.py
executable file
·57 lines (49 loc) · 1.97 KB
/
debug-graham.py
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
#!/usr/bin/env python
#=========================================================================
# This is OPEN SOURCE SOFTWARE governed by the Gnu General Public
# License (GPL) version 3, as described at www.opensource.org.
# Copyright (C)2021 William H. Majoros <[email protected]>
#=========================================================================
from __future__ import (absolute_import, division, print_function,
unicode_literals, generators, nested_scopes, with_statement)
from builtins import (bytes, dict, int, list, object, range, str, ascii,
chr, hex, input, next, oct, open, pow, round, super, filter, map, zip)
# The above imports should allow this program to run in both Python 2 and
# Python 3. You might need to update your version of module "future".
import sys
import ProgramName
from Rex import Rex
rex=Rex()
def output(array):
array.sort(key=lambda x: x[0])
if(len(array)<2): return
(prevPos,diff,significant)=array[0]
for rec in array[1:]:
(pos,diff,significant)=rec
distance=pos-prevPos
print(distance,diff,significant,sep="\t")
prevPos=pos
#=========================================================================
# main()
#=========================================================================
if(len(sys.argv)!=2):
exit(ProgramName.get()+" <debug.txt>\n")
(infile,)=sys.argv[1:]
prevChrom=None; array=[]
with open(infile,"rt") as IN:
for line in IN:
fields=line.rstrip().split()
if(len(fields)<10): continue
(ID,v,estimate,alt1,ref1,alt2,ref2,alt3,ref3,alt4,ref4,alt5,ref5,
significant)=fields
v=float(v); estimate=float(estimate)
diff=estimate-v
if(not rex.find("(.*)@(\d+)",ID)):
raise Exception("Can't parse: "+ID)
chrom=rex[1]; pos=int(rex[2])
if(chrom!=prevChrom):
output(array)
array=[]
prevChrom=chrom
rec=[pos,diff,significant]
array.append(rec)