-
Notifications
You must be signed in to change notification settings - Fork 17
/
cnMOPS.py
57 lines (46 loc) · 1.14 KB
/
cnMOPS.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
56
57
import SV
import os
import re
class cnMOPS:
seqnames=0
start=1
end=2
width=3
strand=4
sampleName=5
median=6
mean=7
CN=8
@staticmethod
def parse_CN (CN):
i=re.sub ('CN', '', CN)
if int(i) > 2: return 'DUP'
else:
return 'DEL'
@staticmethod
def doparse ( input_line ):
E=input_line.rstrip('\n').split('\t')
chrom=E[cnMOPS.seqnames]
start=E[cnMOPS.start]
end=E[cnMOPS.end]
calltype=cnMOPS.parse_CN( E[cnMOPS.CN] )
filter=E[cnMOPS.mean]
program='cn.MOPS'
other=':'.join(E)
length=int(E[cnMOPS.width])
return SV.SV.format_line (chrom, start, end, calltype, filter, program, other, str(length))
# ------------------------------------------------------------
def __init__ (self, fname):
self.fname=fname
if not os.path.exists (self.fname):
raise Exception ("NO such file: " + self.fname)
# -------------------------------------------------------------
def run ( self ):
f = open (self.fname)
for line in f:
# ignore the header line
if re.search ('seqnames', line): continue
sv_line=cnMOPS.doparse ( line )
print(sv_line)
f.close()
# -------------------------------------------------------------