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