Commit 9bafa0ed by Eric Coissac

compute sum of count per category and print them as a new column named total

parent 4133a16a
......@@ -8,6 +8,7 @@ Created on 2 fevr. 2010
from obitools.options import getOptionManager
from obitools.format.options import addInputFormatOption
import sys
from obitools.ecopcr.options import addTaxonomyDBOptions, loadTaxonomyDatabase
def addStatOptions(optionManager):
optionManager.add_option('-c','--category-attribute',
......@@ -69,31 +70,40 @@ def mean(values,options):
if __name__ == "__main__":
optionParser = getOptionManager([addStatOptions,addInputFormatOption])
optionParser = getOptionManager([addStatOptions,addInputFormatOption,addTaxonomyDBOptions])
(options, entries) = optionParser()
loadTaxonomyDatabase(options)
options.statistics = set(options.minimum) | set(options.maximum) | set(options.mean)
total = 0
catcount={}
totcount={}
values={}
lcat=0
for s in entries:
category = []
for c in options.categories:
if c in s:
v = s[c]
try:
if hasattr(options, 'taxonomy') and options.taxonomy is not None:
environ = {'taxonomy' : options.taxonomy,'sequence':s}
else:
environ = {'sequence':s}
v = eval(c,environ,s)
lv=len(str(v))
if lv > lcat:
lcat=lv
category.append(v)
else:
except:
category.append(None)
if 4 > lcat:
lcat=4
category=tuple(category)
catcount[category]=catcount.get(category,0)+1
totcount[category]=totcount.get(category,0)+s['count']
for var in options.statistics:
if var in s:
v = s[var]
......@@ -129,7 +139,8 @@ if __name__ == "__main__":
"\t".join([minvar % x for x in options.minimum]) + "\t" +\
"\t".join([maxvar % x for x in options.maximum]) + "\t" +\
"\t".join([meanvar % x for x in options.mean]) + \
"\t count"
"\t count" + \
"\t total"
print hcat
for c in catcount:
for v in c:
......@@ -140,6 +151,7 @@ if __name__ == "__main__":
print (("%%%dd" % lmaxi[m]) % maxi[m][c])+"\t",
for m in options.mean:
print (("%%%df" % lavg[m]) % avg[m][c])+"\t",
print "%7d" %catcount[c]
print "%7d" %catcount[c],
print "%9d" %totcount[c]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment