-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencoding.py
183 lines (145 loc) · 12.4 KB
/
encoding.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
from load_data import normaliseCF, seqToOneHot, turnToOneHot, seqToDinucleotides
from picrispr import FeatureEncoding, splitBpwise
def noSequence(experiment, augmented, cutoff, CFtoScore=normaliseCF, seqToOneHot=seqToOneHot, count=None, i=0, featurenames=None, numBpWise=0, *args, **kwargs):
encoding = FeatureEncoding(epiDim=len(experiment[0])-1, epiStart=0, seqDim=0, featurenames=featurenames, encodingFunction="noSequence")
if (count == 1): print("no sequence encoding")
cleavage_freq = [experiment[datapoint][-1] for datapoint in range(len(experiment))] # extract cleavage_freq
cleavage_freq_transformed, pt = CFtoScore(cleavage_freq, cutoff)
for line in range(len(experiment)):
experiment[line] = [item for item in experiment[line]] # fetchall gives a list of tuples, need to convert into list of lists
experiment[line][-1] = cleavage_freq_transformed[line] # write cleavage frequency back to experiment array
for key in range(len(experiment)):
bpwiseFeatures = experiment[key][:numBpWise]
bpwiseList = []
for bpwise in bpwiseFeatures:
if bpwise is not None:
bpwise = splitBpwise(bpwise)
if len(bpwise) == 23: bpwiseList.append(bpwise)
else: bpwiseList.append([0] * 23) # in case nucleosome data is not available
else: bpwiseList.append([0] * 23)
bpwiseList = [item for sublist in bpwiseList for item in sublist]
experiment[key] = bpwiseList + [float(i) if i is not None else 0 for i in experiment[key][numBpWise:]]
for key in range(len(augmented)):
bpwiseFeatures = augmented[key][:numBpWise]
bpwiseList = []
for bpwise in bpwiseFeatures:
if bpwise is not None:
bpwise = splitBpwise(bpwise)
if len(bpwise) == 23: bpwiseList.append(bpwise)
else: bpwiseList.append([0] * 23) # in case nucleosome data is not available
else: bpwiseList.append([0] * 23)
bpwiseList = [item for sublist in bpwiseList for item in sublist]
augmented[key] = bpwiseList + [float(i) if i is not None else 0 for i in augmented[key][numBpWise:]]
return experiment, augmented, encoding, pt
def noEncoding(experiment, augmented, cutoff, CFtoScore=normaliseCF, seqToOneHot=seqToOneHot, count=None, i=0, featurenames=None, numBpWise=0, *args, **kwargs):
encoding = FeatureEncoding(epiDim=len(experiment[0])-2, epiStart=0, seqDim=0, featurenames=featurenames, encodingFunction="noEncoding")
cleavage_freq = [experiment[datapoint][-1] for datapoint in range(len(experiment))] # extract cleavage_freq
cleavage_freq_transformed, pt = CFtoScore(cleavage_freq, cutoff)
for line in range(len(experiment)):
experiment[line] = [item for item in experiment[line]] # fetchall gives a list of tuples, need to convert into list of lists
experiment[line][-1] = cleavage_freq_transformed[line] # write cleavage frequency back to experiment array
for key in range(len(experiment)):
bpwiseFeatures = experiment[key][:numBpWise]
bpwiseList = []
for bpwise in bpwiseFeatures:
if bpwise is not None:
bpwise = splitBpwise(bpwise)
if len(bpwise) == 23: bpwiseList.append(bpwise)
else: bpwiseList.append([0] * 23) # in case nucleosome data is not available
else: bpwiseList.append([0] * 23)
bpwiseList = [item for sublist in bpwiseList for item in sublist]
experiment[key] = bpwiseList + [i if i is not None else 0 for i in experiment[key][numBpWise:]]
for key in range(len(augmented)):
bpwiseFeatures = augmented[key][:numBpWise]
bpwiseList = []
for bpwise in bpwiseFeatures:
if bpwise is not None:
bpwise = splitBpwise(bpwise)
if len(bpwise) == 23: bpwiseList.append(bpwise)
else: bpwiseList.append([0] * 23) # in case nucleosome data is not available
else: bpwiseList.append([0] * 23)
bpwiseList = [item for sublist in bpwiseList for item in sublist]
augmented[key] = bpwiseList + [i if i is not None else 0 for i in augmented[key][numBpWise:]]
return experiment, augmented, encoding, pt
def oneHotSingleNuclTargetMismatchType(experiment, augmented, cutoff, CFtoScore=normaliseCF, seqToOneHot=seqToOneHot, count=None, i=0, featurenames=None, numBpWise=0, *args, **kwargs):
if featurenames is None: featurenames=['A_match', 'T_match', 'C_match', 'G_match',
'A_mismT', 'T_mismC', 'C_mismG', 'G_mismA',
'A_mismC', 'T_mismG', 'C_mismA', 'G_mismT',
'A_mismG', 'T_mismA', 'C_mismT', 'G_mismC',
'CTCF', 'DNase', 'RRBS', 'H3K4me3', 'DRIP', 'energy1', 'energy2', 'energy3', 'energy4', 'energy5']
epiStart, seqDim = 16, 16
# 2 for sequences, 1 for cleavage_freq
encoding = FeatureEncoding(epiDim=len(experiment[0])-2-1, epiStart=epiStart, seqDim=seqDim, featurenames=featurenames, encodingFunction="oneHotSingleNuclTargetMismatchType")
cleavage_freq = [experiment[datapoint][-1] for datapoint in range(len(experiment))] # extract cleavage_freq
cleavage_freq_transformed, pt = CFtoScore(cleavage_freq, cutoff)
for line in range(len(experiment)):
experiment[line] = [item for item in experiment[line]] # fetchall gives a list of tuples, need to convert into list of lists
experiment[line][-1] = cleavage_freq_transformed[line] # write cleavage frequency back to experiment array
# turn both grna and target sequence into 23*4 long one-hot vectors
experiment = turnToOneHot(experiment, seqToOneHot=seqToOneHot, encodingFunction="oneHotSingleNuclTargetMismatchType", numBpWise=numBpWise)
augmented = turnToOneHot(augmented, seqToOneHot=seqToOneHot, encodingFunction="oneHotSingleNuclTargetMismatchType", numBpWise=numBpWise)
return experiment, augmented, encoding, pt
def oneHotSingleNuclTargetMismatch(experiment, augmented, cutoff, CFtoScore=normaliseCF, seqToOneHot=seqToOneHot, count=None, i=0, featurenames=None, numBpWise=0, *args, **kwargs):
if featurenames is None: featurenames=['A', 'A_mism', 'T', 'T_mism', 'C', 'C_mism', 'G', 'G_mism', 'CTCF', 'DNase', 'RRBS', 'H3K4me3', 'DRIP', 'energy1', 'energy2', 'energy3', 'energy4', 'energy5']
epiStart, seqDim = 8, 8
# 2 for sequences, 1 for cleavage_freq
encoding = FeatureEncoding(epiDim=len(experiment[0])-2-1, epiStart=epiStart, seqDim=seqDim, featurenames=featurenames, encodingFunction="oneHotSingleNuclTargetMismatch")
cleavage_freq = [experiment[datapoint][-1] for datapoint in range(len(experiment))] # extract cleavage_freq
cleavage_freq_transformed, pt = CFtoScore(cleavage_freq, cutoff)
for line in range(len(experiment)):
experiment[line] = [item for item in experiment[line]] # fetchall gives a list of tuples, need to convert into list of lists
experiment[line][-1] = cleavage_freq_transformed[line] # write cleavage frequency back to experiment array
# turn both grna and target sequence into 23*4 long one-hot vectors
experiment = turnToOneHot(experiment, seqToOneHot=seqToOneHot, encodingFunction="oneHotSingleNuclTargetMismatch", numBpWise=numBpWise)
augmented = turnToOneHot(augmented, seqToOneHot=seqToOneHot, encodingFunction="oneHotSingleNuclTargetMismatch", numBpWise=numBpWise)
return experiment, augmented, encoding, pt
def oneHotSingleNucl(experiment, augmented, cutoff, CFtoScore=normaliseCF, seqToOneHot=seqToOneHot, count=None, i=0, featurenames=None, numBpWise=0, CRISPRNetStyle=False, *args, **kwargs):
if featurenames is None: featurenames=['A', 'T', 'C', 'G', 'CTCF', 'DNase', 'RRBS', 'H3K4me3', 'DRIP', 'energy1', 'energy2', 'energy3', 'energy4', 'energy5']
epiStart, seqDim = 4, 4
if CRISPRNetStyle:
epiStart, seqDim = 6, 6
featurenames = featurenames[:4] + ['base order desc', 'base order asc'] + featurenames[4:]
# 2 for sequences, 1 for cleavage_freq
encoding = FeatureEncoding(epiDim=len(experiment[0])-2-1, epiStart=epiStart, seqDim=seqDim, featurenames=featurenames, encodingFunction="oneHotSingleNucl")
cleavage_freq = [experiment[datapoint][-1] for datapoint in range(len(experiment))] # extract cleavage_freq
cleavage_freq_transformed, pt = CFtoScore(cleavage_freq, cutoff)
for line in range(len(experiment)):
experiment[line] = [item for item in experiment[line]] # fetchall gives a list of tuples, need to convert into list of lists
experiment[line][-1] = cleavage_freq_transformed[line] # write cleavage frequency back to experiment array
# turn both grna and target sequence into 23*4 long one-hot vectors
experiment = turnToOneHot(experiment, seqToOneHot=seqToOneHot, encodingFunction="oneHotSingleNucl", numBpWise=numBpWise, CRISPRNetStyle=CRISPRNetStyle)
augmented = turnToOneHot(augmented, seqToOneHot=seqToOneHot, encodingFunction="oneHotSingleNucl", numBpWise=numBpWise, CRISPRNetStyle=CRISPRNetStyle)
return experiment, augmented, encoding, pt
def oneHotDinuclTargetMismatch(experiment, augmented, cutoff, CFtoScore=normaliseCF, seqToOneHot=seqToDinucleotides, count=None, i=0, featurenames=None, numBpWise=0, *args, **kwargs):
featurenames = ['AA', 'AA_mism', 'AT', 'AT_mism', 'AC', 'AC_mism', 'AG', 'AG_mism',
'TA', 'TA_mism', 'TT', 'TT_mism', 'TC', 'TC_mism', 'TG', 'TG_mism',
'CA', 'CA_mism', 'CT', 'CT_mism', 'CC', 'CC_mism', 'CG', 'CG_mism',
'GA', 'GA_mism', 'GT', 'GT_mism', 'GC', 'GC_mism', 'GG', 'GG_mism', 'CTCF', 'DNase', 'RRBS', 'DRIP', 'energy_2', 'energy_3', 'energy_5']
epiStart, seqDim = 32, 32
# 2 for sequences, 1 for cleavage_freq
encoding = FeatureEncoding(epiDim=len(experiment[0])-2-1, epiStart=epiStart, seqDim=seqDim, featurenames=featurenames, encodingFunction="oneHotDinuclTargetMismatch")
if (count == 1): print("one-hot dinucleotide encoding in interface mode")
cleavage_freq = [experiment[datapoint][-1] for datapoint in range(len(experiment))] # extract cleavage_freq
cleavage_freq_transformed, pt = CFtoScore(cleavage_freq, cutoff)
for line in range(len(experiment)):
experiment[line] = [item for item in experiment[line]] # fetchall gives a list of tuples, need to convert into list of lists
experiment[line][-1] = cleavage_freq_transformed[line] # write cleavage frequency back to experiment array
# turn both grna and target sequence into 23*4 long one-hot vectors
experiment = turnToOneHot(experiment, seqToOneHot=seqToOneHot, numBpWise=numBpWise)
augmented = turnToOneHot(augmented, seqToOneHot=seqToOneHot, numBpWise=numBpWise)
return experiment, augmented, encoding, pt
def oneHotDinucl(experiment, augmented, cutoff, CFtoScore=normaliseCF, seqToOneHot=seqToDinucleotides, count=None, i=0, featurenames=None, numBpWise=0, *args, **kwargs):
featurenames = ['AA', 'AT', 'AC', 'AG', 'TA', 'TT', 'TC', 'TG', 'CA', 'CT', 'CC', 'CG', 'GA', 'GT', 'GC', 'GG', 'CTCF', 'DNase', 'RRBS', 'DRIP', 'energy_2', 'energy_3', 'energy_5']
epiStart, seqDim = 16, 16
# 2 for sequences, 1 for cleavage_freq
encoding = FeatureEncoding(epiDim=len(experiment[0])-2-1, epiStart=epiStart, seqDim=seqDim, featurenames=featurenames, encodingFunction="oneHotDinucl")
if (count == 1): print("one-hot dinucleotide encoding")
cleavage_freq = [experiment[datapoint][-1] for datapoint in range(len(experiment))] # extract cleavage_freq
cleavage_freq_transformed, pt = CFtoScore(cleavage_freq, cutoff)
for line in range(len(experiment)):
experiment[line] = [item for item in experiment[line]] # fetchall gives a list of tuples, need to convert into list of lists
experiment[line][-1] = cleavage_freq_transformed[line] # write cleavage frequency back to experiment array
# turn both grna and target sequence into 23*4 long one-hot vectors
experiment = turnToOneHot(experiment, seqToOneHot=seqToOneHot, numBpWise=numBpWise)
augmented = turnToOneHot(augmented, seqToOneHot=seqToOneHot, numBpWise=numBpWise)
return experiment, augmented, encoding, pt