-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnormalised-extract-exon-guides.py
134 lines (108 loc) · 4.05 KB
/
normalised-extract-exon-guides.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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
'''
A Benchmark of Computational CRISPR-Cas9 Guide Design Methods
Jacob Bradford, Dimitri Perrin. 2019.
This script reads the normalised data (generated by normalise.py) and extracts
guides that target exons.
Notes:
- Make sure you create a directory named according to "OUTPUT_DIR" in every
directory specified in "scannableDirs"
Run:
1: (normalise the raw data first, using: normalise.py)
2: normalised-extract-exon-guides.py
Output:
- Guides which target exon regions, in the normalised format
'''
import argparse, os, re
# this script requires the datasets generated by normalise.py
# it extracts all guides that are within the exon regions, as per the rules from mm10db
# ie: within the bounds of the exon region, plus-minus 17 bases
mm10dbExonListFiles = {
'500k' : r"exon_list_500k.txt",
'1m' : r"exon_list_1m.txt",
'5m' : r"exon_list_5m.txt",
#'full' : r"exon_list_full.txt",
}
humanToIntSizes = {
'500k' : 500000,
'1m' : 1000000,
'5m' : 5000000,
'full' : 61431566,
}
OUTPUT_DIR = 'exon-only'
toolsToConsider = [
'casdesigner',
'casfinder',
'cctop',
'chopchop',
'crispor',
'crisprdo',
'crisprera',
'ctfinder',
'flashfry',
'gtscan',
'guidescan',
'mm10db',
'phytocrispex',
'sgrnacas9',
'sgrnascorer',
'ssc',
'wucrispr',
'tuscan'
]
scannableDirs = {
'500k' : r'normalised/500k',
'1m' : r'normalised/1m',
'5m' : r'normalised/5m',
'full' : r'normalised/full',
}
def doesFileNameMatchToolsToConsider(fileName):
matches = False
for toolToConsider in toolsToConsider:
if toolToConsider.lower() in fileName.replace('-', '').lower():
matches = True
return matches
def createExonHashTable(size):
annotationFile = mm10dbExonListFiles[size]
hashTable = {'+' : [], '-' : []}
with open(annotationFile, 'r') as fOpen:
fLines = fOpen.read().split('\n')[:-1]
for line in fLines:
lineSplit = line.split('\t')
strand = lineSplit[2]
exonRegionStart = int(lineSplit[3])
exonRegionEnd = int(lineSplit[4])
hashTable[strand].append([exonRegionStart, exonRegionEnd])
return hashTable
def isGuideWithinExon(strStrand, guidePos, exonHashTable):
for strand in exonHashTable:
for exon in exonHashTable[strand]:
#print '%s %s %s' % (guidePos, exon[0], exon[1])
if guidePos >= (exon[0] - 17) and guidePos <= (exon[1] + 17):
return True
return False
for scannableDir in scannableDirs:
exonHashTable = createExonHashTable(scannableDir)
print '\nProcessing: %s' % scannableDir
# walk over the directory
for (dirpath, dirnames, filenames) in os.walk(scannableDirs[scannableDir]):
# for file within the directory
for currentFilename in filenames:
if doesFileNameMatchToolsToConsider(currentFilename) == False:
continue
currentFullpath = os.path.join(scannableDirs[scannableDir], currentFilename)
with open(currentFullpath, 'r') as fCurrentRead:
newFullpath = os.path.join(OUTPUT_DIR, scannableDir, currentFilename)
with open(newFullpath, 'w+') as fWrite:
for currentLineRaw in fCurrentRead:
currentLine = currentLineRaw.strip('\n').split(',')
currToolName = currentLine[0]
currSeq = currentLine[1]
currStartPos = int(currentLine[2])
currEndPos = int(currentLine[3])
currStrand = currentLine[4]
if currStrand == '+':
hashKey = currEndPos
else:
hashKey = currStartPos
if isGuideWithinExon(currStrand, hashKey, exonHashTable):
fWrite.write('%s' % (currentLineRaw))