-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcalculate_diff-over-sum.py
60 lines (49 loc) · 1.66 KB
/
calculate_diff-over-sum.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
#!/usr/bin/env python
# Copyright (c) 2010 DFCI/HSPH
# Author: Chongzhi Zang
#
# This software is distributable under the terms of the GNU General
# Public License (GPL) v2, the text of which can be found at
# http://www.gnu.org/copyleft/gpl.html. Installing, importing or
# otherwise using this module constitutes acceptance of the terms of
# this License.
#
# Disclaimer
#
# This software 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.
#
# Comments and/or additions are welcome (send e-mail to:
import re, os, sys, shutil
from math import *
from string import *
from optparse import OptionParser
import operator
## from a input data list of id, drug name; output id "\t" drug_name.
def main(argv):
parser = OptionParser()
parser.add_option("-i", "--input_file", action="store", type="string",
dest="in_file", help="input file", metavar="<file>")
parser.add_option("-o", "--output_file_name", action="store", type="string",
dest="out_file", help="output file name", metavar="<file>")
(opt, args) = parser.parse_args(argv)
if len(argv) < 4:
parser.print_help()
sys.exit(1)
f = open(opt.in_file,'r')
o = open(opt.out_file, 'w')
for line in f:
if not re.match("#", line):
line = line.strip()
sline = line.split()
a = atof(sline[1])
b = atof(sline[2])
d = abs(a - b) / (a + b + 2.0)
o.write(sline[0] + '\t' + str(d) + '\n')
f.close()
o.close()
if __name__ == "__main__":
main(sys.argv)