-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcalculate_average_and_median.py
64 lines (51 loc) · 2.06 KB
/
calculate_average_and_median.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
#!/usr/bin/env python
# Copyright (c) 2009 GWU & NHLBI, NIH
# Authors: Chongzhi Zang, Weiqun Peng and Keji Zhao
#
# 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
import associate_binary_modification_with_expression
plus = re.compile("\+");
minus = re.compile("\-");
Dir = os.getcwd();
def get_data_list(infile, colum):
'''returns a dictionary with geneIDs as keys, expression value as values. colum is the number of colum -1 where the expression data are in the file'''
file = open(infile, 'r')
List = []
for line in file:
if not re.match("#", line):
line = line.strip()
sline = line.split()
List.append(atof(sline[colum]))
file.close()
return List
def main(argv):
parser = OptionParser()
parser.add_option("-b", "--inputfile", action="store", type="string", dest="bedfile", metavar="<file>", help="input file")
parser.add_option("-c", "--column", action="store", type="int", dest="column", help="column number, start from 0", metavar="<int>")
(opt, args) = parser.parse_args(argv)
if len(argv) < 4:
parser.print_help()
sys.exit(1)
List = get_data_list(opt.bedfile, opt.column)
print 'Number:', len(List), '; Average:', associate_binary_modification_with_expression.average(List), '; Median:',associate_binary_modification_with_expression.middle(List)
if __name__ == "__main__":
main(sys.argv)