Commit e0d8e2fe by Frédéric Boyer

Bug à l'affichage au chargement de la taxonomie

parent ab0b0aa3
......@@ -83,6 +83,7 @@ def loadTaxonomyDatabase(options):
if isinstance(options.taxonomy, Taxonomy):
taxonomy = options.taxonomy
if taxonomy is None and isinstance(options.taxonomy, str):
import sys
taxonomy = EcoTaxonomyDB(options.taxonomy)
options.ecodb=options.taxonomy
options.taxonomy=taxonomy
......
......@@ -28,7 +28,14 @@ class Taxonomy(object):
self._genusidx = self._ranks.index('genus')
self._familyidx = self._ranks.index('family')
self._orderidx = self._ranks.index('order')
self._nameidx=dict((x[0],x[2]) for x in self._name)
self._nameidx = {}
for x in self._name :
if x[0] not in self._nameidx :
self._nameidx[x[0]] = [x[2]]
else :
self._nameidx[x[0]].append(x[2])
self._nameidx.update(dict((x[0],x[2]) for x in self._preferedName))
self._preferedidx=dict((x[2],x[1]) for x in self._preferedName)
......@@ -49,8 +56,11 @@ class Taxonomy(object):
return self.findTaxonByIdx(self.findIndex(taxid))
def findTaxonByName(self,name):
return self._taxonomy[self._nameidx[name]]
taxa = []
for i in self._nameidx[name] :
taxa.append(self._taxonomy[i])
return taxa
def findRankByName(self,rank):
try:
return self._ranks.index(rank)
......@@ -219,6 +229,7 @@ class Taxonomy(object):
self._taxonomy.append((newtaxid,rankid,a.pop(),groupname))
for x in t:
x[2]=newidx
def addLocalTaxon(self,name,rank,parent,minimaltaxid=10000000):
newtaxid = minimaltaxid if (self._bigestTaxid < minimaltaxid) else self._bigestTaxid+1
......@@ -229,13 +240,19 @@ class Taxonomy(object):
self._taxonomy.append(tx)
newidx=len(self._taxonomy)-1
self._name.append((name,'scientific name',newidx))
self._nameidx[name]=newidx
if name not in self._nameidx :
self._nameidx[name]=[newidx]
else :
self._nameidx[name].append(newidx)
self._index[newtaxid]=newidx
self._bigestTaxid=newtaxid
return newtaxid
def removeLocalTaxon(self,taxid):
raise NotImplemented
txidx = self.findIndex(taxid)
......@@ -246,18 +263,17 @@ class Taxonomy(object):
for t in self._taxonomy:
if t[2] == txidx:
self.removeLocalTaxon(t[0])
return taxon
def addPreferedName(self,taxid,name):
idx = self.findIndex(taxid)
self._preferedName.append(name,'obi',idx)
self._preferedidx[idx]=name
return taxid
class EcoTaxonomyDB(Taxonomy,EcoPCRDBFile):
'''
A taxonomy database class
......@@ -279,7 +295,7 @@ class EcoTaxonomyDB(Taxonomy,EcoPCRDBFile):
self._preferedNamesFile = "%s.pdx" % self._path
self._aliasFile = "%s.adx" % self._path
print >> sys.stderr,"Reading binary taxonomy database...",
print >> sys.stderr,"Reading binary taxonomy database..."
self.__readNodeTable()
......@@ -356,7 +372,6 @@ class EcoTaxonomyDB(Taxonomy,EcoPCRDBFile):
except:
print >> sys.stderr, " [INFO : Taxon alias file not found] "
index={}
i = 0;
buildIndex=True
localtaxon=0
......@@ -371,8 +386,8 @@ class EcoTaxonomyDB(Taxonomy,EcoPCRDBFile):
i+=1
print >> sys.stderr,"Taxonomical tree read",
return taxonomy, index,localtaxon
print >> sys.stderr,"Taxonomical tree read"
return taxonomy, index, localtaxon
def __readNodeTable(self):
self._taxonomy, self._index, self._localtaxon= self.__ecoTaxonomyIndex()
......@@ -388,9 +403,9 @@ class EcoTaxonomyDB(Taxonomy,EcoPCRDBFile):
try :
self._preferedName = [(x[0],'obi',x[2])
for x in self.__ecoNameIterator(self._preferedNamesFile)]
print >> sys.stderr, " [INFO : Prefered taxon name file found] : %d added taxa" % len(self._preferedName)
print >> sys.stderr, " [INFO : Preferred taxon name file found] : %d added taxa" % len(self._preferedName)
except:
print >> sys.stderr, " [INFO : Prefered taxon name file not found]"
print >> sys.stderr, " [INFO : Preferred taxon name file not found]"
self._preferedName = []
......@@ -418,8 +433,13 @@ class TaxonomyDump(Taxonomy):
print >>sys.stderr,"Adding deleted taxid..."
for taxid in self._deletedNodeIterator('%s/delnodes.dmp' % taxdir):
self._index[taxid]=None
self._nameidx=dict((x[0],x[2]) for x in self._name)
self._nameidx = {}
for x in self._name :
if x[0] not in self._nameidx :
self._nameidx[x[0]] = [x[2]]
else :
self._nameidx[x[0]].append(x[2])
def _taxonCmp(t1,t2):
......
......@@ -60,7 +60,7 @@ def universalOpen(file,*options):
name = data[0].filename
rep = zip.open(name)
except Exception as e:
print 'Unexpected error: ', e
print>>sys.stderr, e
sys.exit();
else:
rep = file
......
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