-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathstats.py
executable file
·69 lines (58 loc) · 1.63 KB
/
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
69
#!/usr/bin/env python
import numpy as np
import pandas as pd
import click as ck
import gzip
from utils import (
get_gene_ontology, get_anchestors, get_go_set,
EXP_CODES,
BIOLOGICAL_PROCESS,
MOLECULAR_FUNCTION,
CELLULAR_COMPONENT)
DATA_ROOT = 'data/swissexp/'
@ck.command()
def main():
annot_stats()
def annot_stats():
c = 0
genes = set()
proteins = set()
with gzip.open('data/goa_human.gaf.gz') as f:
for line in f:
if line.startswith('!'):
continue
it = line.strip().split('\t')
if it[6] in EXP_CODES:
c += 1
genes.add(it[2])
proteins.add(it[1])
print(list(proteins)[:10])
print('Annots: ', c)
print('Genes: ', len(genes))
print('Proteins: ', len(proteins))
def filter_organisms():
df = pd.read_pickle(DATA_ROOT + 'test-bp.pkl')
orgs = set(df['orgs'])
df = pd.read_pickle(DATA_ROOT + 'test-mf.pkl')
orgs |= set(df['orgs'])
df = pd.read_pickle(DATA_ROOT + 'test-cc.pkl')
orgs |= set(df['orgs'])
pro = set()
with open('data/prokaryotes.txt') as f:
for line in f:
org = line.strip().split(':')[1]
if org in orgs:
pro.add(org)
eu = set()
with open('data/eukaryotes.txt') as f:
for line in f:
org = line.strip().split(':')[1]
if org in orgs:
eu.add(org)
df = pd.DataFrame({'orgs': list(eu)})
print(df)
df.to_pickle('eukaryotes.pkl')
df = pd.DataFrame({'orgs': list(pro)})
df.to_pickle('prokaryotes.pkl')
if __name__ == '__main__':
main()