-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathinvariant_gene.py
252 lines (226 loc) · 9.71 KB
/
invariant_gene.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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
"""
Methods for identifying invariant genes (suitable reference/
normalization genes) from expression data
@see: Chan, OYW, Keng, BMH, Ling, MHT. 2014. Correlation and Variation
Based Method for Reference Genes Identification from Large Datasets.
Electronic Physician 6(1): 719-727.
Date created: 29th March 2012
License: GNU General Public License version 3
Bactome package is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import random
from copads.samplestatistics import SingleSample, TwoSample
def selfed_correlation(data, randomsize):
"""
The average absolute pairwise correlation between dataset X
and sample non-X data (n = randomsize) where small value
represents higher stability
Pseudocode:
1. tested_gene <-- list of expression for gene to be tested
2. dataset_X <-- list of expression for any other gene
3. q_set <-- {dataset_X(i) | 1 < i < n}
4. correlation <-- {|r(dataset_X, q_set)|}, repeat steps 2 to 4
for all genes that are not tested_gene
5. average_correlation(tested_gene) <-- average of correlation
6. repeat steps 1 to 5 to test for all genes
@param data: input data as a dictionary (processed by datafile function
in oliver.py) where key is ProbeName and value is a list of
SampleValues
@param randomsize: number of random samples to take
@return: dictionary where key is ProbeName and value is result from
current reference gene identification method
"""
results = {}
count = 0
test_list = data.keys()
if len(test_list) > randomsize:
test_list = random.sample(test_list, randomsize)
for genename in data.keys():
gene = [float(x) for x in data[genename]]
pcc = []
for tester in test_list:
tester = [float(x) for x in data[tester]]
sample = TwoSample(gene, 'genename', tester, 'tester')
try: pcc.append(abs(sample.pearson()))
except: pass
results[genename] = float(sum(pcc)) / len(pcc)
count = count + 1
if count % 500 == 0: print count, 'gene/probe processed'
return results
def selfed_ratio_correlation(data, randomsize):
"""
The average absolute pairwise correlation between dataset X
and the quotient of X and sample of non-X data (n = randomsize)
where small value represents higher stability
Pseudocode:
1. tested_gene <-- list of expression for gene to be tested
2. dataset_X <-- list of expression for any other gene
3. q_set <-- {dataset_X(i) / tested_gene(i) | 1 < i < n}
4. correlation <-- {|r(dataset_X, q_set)|}, repeat steps 2 to 4
for all genes that are not tested_gene
5. average_correlation(tested_gene) <-- average of correlation
6. repeat steps 1 to 5 to test for all genes
@param data: input data as a dictionary (processed by datafile function
in oliver.py) where key is ProbeName and value is a list of
SampleValues
@param randomsize: number of random samples to take
@return: dictionary where key is ProbeName and value is result from
current reference gene identification method
"""
results = {}
count = 0
test_list = data.keys()
if len(test_list) > randomsize:
test_list = random.sample(test_list, randomsize)
for genename in data.keys():
gene = [float(x) for x in data[genename]]
pcc = []
for tester in test_list:
tester = [float(x) for x in data[tester]]
tester = [tester[i] / gene[i]
for i in range(len(gene))]
sample = TwoSample(gene, 'genename', tester, 'tester')
try: pcc.append(abs(sample.pearson()))
except: pass
results[genename] = float(sum(pcc)) / len(pcc)
count = count + 1
if count % 500 == 0: print count, 'gene/probe processed'
return results
def selfed_product_correlation(data, randomsize):
"""
The average absolute pairwuse correlation between dataset X
and the product of X and sample of non-X data (n = randomsize)
where large value represents higher stability
Pseudocode:
1. tested_gene <-- list of expression for gene to be tested
2. dataset_X <-- list of expression for any other gene
3. q_set <-- {dataset_X(i) * tested_gene(i) | 1 < i < n}
4. correlation <-- {|r(dataset_X, q_set)|}, repeat steps 2 to 4
for all genes that are not tested_gene
5. average_correlation(tested_gene) <-- average of correlation
6. repeat steps 1 to 5 to test for all genes
@param data: input data as a dictionary (processed by datafile function
in oliver.py) where key is ProbeName and value is a list of
SampleValues
@param randomsize: number of random samples to take
@return: dictionary where key is ProbeName and value is result from
current reference gene identification method
"""
results = {}
count = 0
test_list = data.keys()
if len(test_list) > randomsize:
test_list = random.sample(test_list, randomsize)
for genename in data.keys():
gene = [float(x) for x in data[genename]]
pcc = []
for tester in test_list:
tester = [float(x) for x in data[tester]]
tester = [tester[i] * gene[i]
for i in range(len(gene))]
sample = TwoSample(gene, 'genename', tester, 'tester')
try: pcc.append(sample.pearson())
except: pass
results[genename] = float(sum(pcc)) / len(pcc)
count = count + 1
if count % 500 == 0: print count, 'gene/probe processed'
return results
def regression_ratio(data):
"""
The quotient of coefficient of determination and gradient where
large value represents higher stability.
@see Lee et al. 2007. Identification of novel universal
housekeeping genes by statistical analysis of microarray data.
Journal of Biochemistry and Molecular Biology 40(2):226-231.
@param data: input data as a dictionary (processed by datafile function
in oliver.py) where key is ProbeName and value is a list of
SampleValues
@return: dictionary where key is ProbeName and value is result from
current reference gene identification method
"""
results = {}
count = 0
for genename in data.keys():
gene = [float(x) for x in data[genename]]
tester = range(len(gene))
sample = TwoSample(gene, 'genename', tester, 'nominal')
(gradient, intercept) = sample.linear_regression()
if gradient == 0.0: gradient = 0.001
pcc = sample.pearson()
results[genename] = (pcc * pcc) / gradient
count = count + 1
if count % 500 == 0: print count, 'gene/probe processed'
return results
def average_stdev(data):
"""
The product of arithmetic mean and standard deviation where
?small? value represents higher stability.
@see Lee et al. 2007. Identification of novel universal
housekeeping genes by statistical analysis of microarray data.
Journal of Biochemistry and Molecular Biology 40(2):226-231.
@param data: input data as a dictionary (processed by datafile function
in oliver.py) where key is ProbeName and value is a list of
SampleValues
@return: dictionary where key is ProbeName and value is result from
current reference gene identification method
"""
results = {}
count = 0
for genename in data.keys():
gene = [float(x) for x in data[genename]]
gene = SingleSample(gene)
results[genename] = (gene.variance() ** 0.5) * \
gene.arithmeticMean()
count = count + 1
if count % 500 == 0: print count, 'gene/probe processed'
return results
def cv(data):
"""
The coefficient of variation where small value represents
higher stability.
@param data: input data as a dictionary (processed by datafile function
in oliver.py) where key is ProbeName and value is a list of
SampleValues
@return: dictionary where key is ProbeName and value is result from
current reference gene identification method
"""
results = {}
count = 0
for genename in data.keys():
gene = [float(x) for x in data[genename]]
gene = SingleSample(gene)
results[genename] = (gene.variance() ** 0.5) / \
gene.arithmeticMean()
count = count + 1
if count % 500 == 0: print count, 'gene/probe processed'
return results
def gradient(data):
"""
The linear regression gradient where small value represents
higher stability.
@param data: input data as a dictionary (processed by datafile function
in oliver.py) where key is ProbeName and value is a list of
SampleValues
@return: dictionary where key is ProbeName and value is result from
current reference gene identification method
"""
results = {}
count = 0
for genename in data.keys():
gene = [float(x) for x in data[genename]]
tester = range(len(gene))
sample = TwoSample(gene, 'genename', tester, 'nominal')
(gradient, intercept) = sample.linear_regression()
results[genename] = abs(gradient)
count = count + 1
if count % 500 == 0: print count, 'gene/probe processed'
return results