-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathdata_stats.py
executable file
·68 lines (61 loc) · 1.97 KB
/
data_stats.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
#!/usr/bin/env python
import click as ck
import numpy as np
import pandas as pd
from collections import Counter
from utils import Ontology, FUNC_DICT, NAMESPACES
import logging
logging.basicConfig(level=logging.INFO)
@ck.command()
@ck.option(
'--go-file', '-gf', default='data/go.obo',
help='Gene Ontology file in OBO Format')
@ck.option(
'--terms-file', '-tf', default='data/terms.pkl',
help='Result file with a list of terms for prediction task')
@ck.option(
'--train-data-file', '-trdf', default='data/train_data.pkl',
help='Result file with a list of terms for prediction task')
@ck.option(
'--test-data-file', '-tsdf', default='data/test_data.pkl',
help='Result file with a list of terms for prediction task')
@ck.option(
'--ont', '-o', default='bp',
help='Minimum number of annotated proteins')
def main(go_file, terms_file, train_data_file, test_data_file, ont):
go = Ontology(go_file, with_rels=True)
logging.info('GO loaded')
go_set = go.get_namespace_terms(NAMESPACES[ont])
terms_df = pd.read_pickle(terms_file)
tcnt = 0
print('Total terms', len(terms_df))
for go_id in terms_df['terms']:
if go_id in go_set:
tcnt += 1
trdf = pd.read_pickle(train_data_file)
print('Total train', len(trdf))
cnt = 0
for i, row in trdf.iterrows():
ok = False
for go_id in row['annotations']:
if go_id in go_set:
ok = True
break
if ok:
cnt += 1
print('Number of training proteins', cnt)
tsdf = pd.read_pickle(test_data_file)
print('Total test', len(tsdf))
cnt = 0
for i, row in tsdf.iterrows():
ok = False
for go_id in row['annotations']:
if go_id in go_set:
ok = True
break
if ok:
cnt += 1
print('Number of testing proteins', cnt)
print('Number of terms', tcnt)
if __name__ == '__main__':
main()