diff options
author | zsloan | 2016-06-20 11:03:20 -0500 |
---|---|---|
committer | GitHub | 2016-06-20 11:03:20 -0500 |
commit | 8222ef16d443dc41db9d7e09b1af400d8d866854 (patch) | |
tree | e4f5b49aa21c32aa2b770b1a65c8fef7782b625f /wqflask/basicStatistics | |
parent | d90dc3748557d1d6fbaa59f71fe676b8a7c393ca (diff) | |
parent | 10df36b60273d81678f6630c07a2d8e5a6409282 (diff) | |
download | genenetwork2-8222ef16d443dc41db9d7e09b1af400d8d866854.tar.gz |
Merge pull request #168 from genenetwork/staging
Staging
Diffstat (limited to 'wqflask/basicStatistics')
-rwxr-xr-x | wqflask/basicStatistics/corestats.py | 64 |
1 files changed, 32 insertions, 32 deletions
diff --git a/wqflask/basicStatistics/corestats.py b/wqflask/basicStatistics/corestats.py index 4f2d122f..eba84c52 100755 --- a/wqflask/basicStatistics/corestats.py +++ b/wqflask/basicStatistics/corestats.py @@ -1,8 +1,8 @@ #!/usr/bin/env python -# corestats.py (COREy STATS) +# corestats.py (COREy STATS) # Copyright (c) 2006-2007, Corey Goldberg (corey@goldb.org) -# +# # statistical calculation class # for processing numeric sequences # @@ -19,65 +19,65 @@ import sys class Stats: - + def __init__(self, sequence): # sequence of numbers we will process - # convert all items to floats for numerical processing + # convert all items to floats for numerical processing self.sequence = [float(item) for item in sequence] - + def sum(self): - if len(self.sequence) < 1: + if len(self.sequence) < 1: return None else: return sum(self.sequence) - - + + def count(self): return len(self.sequence) - + def min(self): - if len(self.sequence) < 1: + if len(self.sequence) < 1: return None else: return min(self.sequence) - - + + def max(self): - if len(self.sequence) < 1: + if len(self.sequence) < 1: return None else: return max(self.sequence) - + def avg(self): - if len(self.sequence) < 1: + if len(self.sequence) < 1: return None - else: - return sum(self.sequence) / len(self.sequence) - - + else: + return sum(self.sequence) / len(self.sequence) + + def median(self): - if len(self.sequence) < 1: + if len(self.sequence) < 1: return None else: self.sequence.sort() return self.sequence[len(self.sequence) // 2] - - + + def stdev(self): - if len(self.sequence) < 1: + if len(self.sequence) < 1: return None else: avg = self.avg() sdsq = sum([(i - avg) ** 2 for i in self.sequence]) stdev = (sdsq / (len(self.sequence) - 1)) ** .5 return stdev - - + + def percentile(self, percentile): - if len(self.sequence) < 1: + if len(self.sequence) < 1: value = None elif (percentile >= 100): sys.stderr.write('ERROR: percentile must be < 100. you supplied: %s\n'% percentile) @@ -87,17 +87,17 @@ class Stats: self.sequence.sort() value = self.sequence[element_idx] return value - - - + + + # Sample script using this class: -# ------------------------------------------- +# ------------------------------------------- # #!/usr/bin/env python # import corestats -# +# # sequence = [1, 2.5, 7, 13.4, 8.0] # stats = corestats.Stats(sequence) # print stats.avg() # print stats.percentile(90) -# ------------------------------------------- +# ------------------------------------------- |