This repository has been archived by the owner on Feb 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathseparateArms.py
executable file
·65 lines (56 loc) · 1.57 KB
/
separateArms.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
58
59
60
61
62
63
64
65
#!/usr/bin/python
import sys, os, re, argparse
parser = argparse.ArgumentParser(description="Divide input copycaller file into p and q segments using an input bed file with centromere coordinates")
parser.add_argument('input', type=str,help="Tab separated copycaller file")
parser.add_argument('centro', type=str,help="Centromere bed file")
class cent(object):
"""centromere objects by chromosome"""
def __init__(self, line):
[id, start, end] = line.split("\t")
self.name = id
self.p = int(start)
self.q = int(end)
def getChrom(id, centList, cur):
if cur and id == cur.name:
return cur
for i in centList:
if id == i.name:
return i
return False
if len(sys.argv)==1:
parser.print_help()
sys.exit(1)
args = parser.parse_args()
# Main
centros=[]
f = open(args.centro,'r')
for line in f:
line = line.strip()
centobj = cent(line)
centros.append(centobj)
f.close
splitfile = os.path.join(tmpdir, 'splitchrom.cnv')
with open
curchrom = False
f = open(args.input,'r')
for line in f:
line = line.strip()
fields = line.split("\t")
if fields[0] == 'chrom':
print line
continue
id = fields[0]
start = int(fields[1])
end = int(fields[2])
curchrom = getChrom(id, centros, curchrom)
# centromere free chromosomes
if not curchrom:
print line
# print only if segment does not overlap centromere
elif end < curchrom.p:
fields[0] = ('.').join([fields[0], 'p'])
print ("\t").join(fields)
elif start > curchrom.q:
fields[0] = ('.').join([fields[0], 'q'])
print ("\t").join(fields)
f.close