-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathisoforms_fpkm.py
executable file
·67 lines (53 loc) · 1.97 KB
/
isoforms_fpkm.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
#!/usr/bin/env python
from optparse import OptionParser
################################################################################
# isoforms_fpkm.py
#
# Print the FPKM values for all isoforms of the given gene.
################################################################################
################################################################################
# main
################################################################################
def main():
usage = 'usage: %prog [options] <gene_id> <iso_ft>'
parser = OptionParser(usage)
#parser.add_option()
(options,args) = parser.parse_args()
if len(args) != 2:
parser.error('Must provide a gene_id and isoforms.fpkm_tracking file')
else:
gene_id = args[0]
iso_ft = args[1]
# get headers
fpkm_in = open(iso_ft)
headers = fpkm_in.readline().split()
# determine sample table length
sample_len = 0
for i in range(len(headers)):
if headers[i][-5:] == '_FPKM':
sample = headers[i][:-5]
if len(sample) > sample_len:
sample_len = len(sample)
for line in fpkm_in:
a = line.split('\t')
a[-1] = a[-1].rstrip()
tracking_id = a[0]
line_gene_id = a[3]
if line_gene_id == gene_id:
i = 9
while i < len(a):
sample = headers[i][:-5]
if a[i+3] in ['FAIL','HIDATA']:
cols = (tracking_id, sample_len, sample, a[i+3])
print '%-18s %*s %11s' % cols
else:
fpkm = float(a[i])
cols = (tracking_id, sample_len, sample, fpkm)
print '%-18s %*s %11.3f' % cols
i += 4
fpkm_in.close()
################################################################################
# __main__
################################################################################
if __name__ == '__main__':
main()