-
Notifications
You must be signed in to change notification settings - Fork 1
/
find_CpGs.py
executable file
·50 lines (26 loc) · 899 Bytes
/
find_CpGs.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
import sys
LINE_LENGTH = 0
with open(sys.argv[1]) as FILE:
for LINE in FILE:
LINE = LINE.rstrip("\n").upper()
if LINE.startswith(">"):
CHR = LINE.split(" ")[0].replace(">","")
#count for position
CHR_LINE = 1
#update the last base
LAST_BASE = "N"
continue
if LINE_LENGTH == 0:
LINE_LENGTH = len(LINE)
if (LINE.startswith("G") and LAST_BASE == "C") or (LINE.startswith("C") and LAST_BASE == "G"):
print CHR + "\t" + str( (CHR_LINE-1)*LINE_LENGTH )
print CHR + "\t" + str( ((CHR_LINE-1)*LINE_LENGTH) + 1)
CURRENT_BASE = 1
while len(LINE) > 1:
if ("".join(LINE[0:2]) == "GC") or ("".join(LINE[0:2]) == "CG"):
print CHR + "\t" + str( ((CHR_LINE-1)*LINE_LENGTH) + CURRENT_BASE )
print CHR + "\t" + str( ((CHR_LINE-1)*LINE_LENGTH) + CURRENT_BASE + 1)
LINE = LINE[1:]
CURRENT_BASE += 1
CHR_LINE += 1
LAST_BASE = LINE[-1]