-
Notifications
You must be signed in to change notification settings - Fork 1
/
decrease_size.py
executable file
·44 lines (37 loc) · 1.13 KB
/
decrease_size.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
#!/usr/bin/env python
import numpy
from utils import (
shuffle, train_val_test_split, get_gene_ontology)
import sys
import os
from collections import deque
DATA_ROOT = 'data/molecular_functions/hierarchical/level_1/paac/'
def load_data(go_id):
positives = list()
negatives = list()
with open(DATA_ROOT + go_id + '.txt', 'r') as f:
for line in f:
line = line.strip()
if line[0] == '0':
negatives.append(line)
else:
positives.append(line)
return (positives, negatives)
def main(*args, **kwargs):
try:
if len(args) != 3:
raise Exception("Please provide go_id and number of proteins")
go_id = args[1]
positives, negatives = load_data(go_id)
n = int(args[2])
shuffle(positives)
shuffle(negatives)
with open(DATA_ROOT + go_id + '.small.txt', 'w') as f:
for line in negatives[:n]:
f.write(line + '\n')
for line in positives[:n]:
f.write(line + '\n')
except Exception, e:
print e
if __name__ == '__main__':
main(*sys.argv)