Commit 9df2c5c6 by Eric Coissac

Patch bug in merging already merged attribute

parent a9317d19
......@@ -15,7 +15,9 @@ from obitools.format.options import addInOutputOption, sequenceWriterGenerator,\
from obitools.options import getOptionManager
from obitools.ecopcr.options import addTaxonomyDBOptions, loadTaxonomyDatabase
from random import random
from obitools.utils import progressBar
import math
import sys
def minimum(seqs):
return min(s['select'] for s in seqs)
......@@ -126,6 +128,8 @@ if __name__ == '__main__':
classes = {}
print >>sys.stderr,"\nLoading sequences...\n"
for s in entries:
category = []
for c in options.categories:
......@@ -168,7 +172,14 @@ if __name__ == '__main__':
mergedKey.add('taxid')
print >>sys.stderr,"\nSelecting sequences...\n"
lclasses=len(classes)
progressBar(1,lclasses,True,'Selecting')
i=0
for c in classes:
i+=1
progressBar(i,lclasses,False,"%15s" % c)
seqs = classes[c]
sortclass(seqs, options)
if len(c)==1:
......@@ -185,10 +196,10 @@ if __name__ == '__main__':
s["taxid_dist"][s.id]=s['taxid']
mkey = "merged_%s" % key
if mkey not in s:
s[mkey]={}
if key in s:
s[mkey][s[key]]=s[mkey].get(s[key],0)+1
#del(s[key])
if key in s:
s[mkey]={s[key]:1}
else:
s[mkey]={}
if 'count' not in s:
s['count']=1
......@@ -207,14 +218,21 @@ if __name__ == '__main__':
s["taxid_dist"][seq.id]=seq['taxid']
mkey = "merged_%s" % key
if key in seq:
s[mkey][seq[key]]=s[mkey].get(seq[key],0)+1
if mkey in seq:
for skey in seq[mkey]:
if skey in s:
s[mkey][skey]=s[mkey].get(seq[skey],0)+seq[mkey][skey]
else:
s[mkey][skey]=seq[mkey][skey]
m = seq[mkey]
else:
if key in seq:
m={seq[key]:1}
allmkey = set(m.keys()) | set(s[mkey].keys())
s[mkey] = dict((k,m.get(k,0)+s[mkey].get(k,0)) for k in allmkey)
# if mkey in seq:
# for skey in seq[mkey]:
# if skey in s:
# s[mkey][skey]=s[mkey].get(seq[skey],0)+seq[mkey][skey]
# else:
# s[mkey][skey]=seq[mkey][skey]
#for key in seq.iterkeys():
# # Merger proprement l'attribut merged s'il exist
......@@ -232,4 +250,6 @@ if __name__ == '__main__':
for s in seqs[0:options.number]:
s['class']=c
del s['select']
writer(s)
\ No newline at end of file
writer(s)
print >>sys.stderr
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