Beispiel #1
0
 def __init__(self, species_common=_species_common_map):
     """provides latin name:common name mappings"""
     self._species_common = {}
     self._common_species = {}
     self._species_ensembl = {}
     self._ensembl_species = {}
     for species_name, common_name in species_common:
         self.amendSpecies(CaseInsensitiveString(species_name),
                           CaseInsensitiveString(common_name))
Beispiel #2
0
 def amendSpecies(self, species_name, common_name):
     """add a new species, and common name"""
     species_name = CaseInsensitiveString(species_name)
     common_name = CaseInsensitiveString(common_name)
     assert "_" not in species_name,\
                     "'_' in species_name, not a Latin name?"
     self._purge_species(species_name)  # remove if existing
     self._species_common[species_name] = common_name
     self._common_species[common_name] = species_name
     ensembl_name = species_name.lower().replace(" ", "_")
     self._species_ensembl[species_name] = ensembl_name
     self._ensembl_species[ensembl_name] = species_name
     return
Beispiel #3
0
 def amendSpecies(self, species_name, common_name):
     """add a new species, and common name"""
     species_name = CaseInsensitiveString(species_name)
     common_name = CaseInsensitiveString(common_name)
     assert "_" not in species_name,\
                     "'_' in species_name, not a Latin name?"
     self._purge_species(species_name) # remove if existing
     self._species_common[species_name] = common_name
     self._common_species[common_name] = species_name
     ensembl_name = species_name.lower().replace(" ","_")
     self._species_ensembl[species_name] = ensembl_name
     self._ensembl_species[ensembl_name] = species_name
     return
Beispiel #4
0
 def _purge_species(self, species_name):
     """removes a species record"""
     species_name = CaseInsensitiveString(species_name)
     if not species_name in self._species_common:
         return
     common_name = self._species_common.pop(species_name)
     ensembl_name = self._species_ensembl.pop(species_name)
     self._ensembl_species.pop(ensembl_name)
     self._common_species.pop(common_name)
Beispiel #5
0
    def getEnsemblDbPrefix(self, name):
        """returns a string of the species name in the format used by
        ensembl"""
        name = CaseInsensitiveString(name)
        if name in self._common_species:
            name = self._common_species[name]
        try:
            species_name = self.getSpeciesName(name, level='raise')
        except RuntimeError:
            if name not in self._species_common:
                raise RuntimeError("Unknown name %s" % name)
            species_name = name

        return str(species_name.lower().replace(" ", "_"))
Beispiel #6
0
    def getCommonName(self, name):
        """returns the common name for the given name (which can be either a
        species name or the ensembl version)"""
        name = CaseInsensitiveString(name)
        if name in self._ensembl_species:
            name = self._ensembl_species[name]

        if name in self._species_common:
            common_name = self._species_common[name]
        elif name in self._common_species:
            common_name = name
        else:
            raise RuntimeError("Unknown species: %s" % name)
        return str(common_name)
Beispiel #7
0
 def getSpeciesName(self, name, level='ignore'):
     """returns the species name for the given common name"""
     name = CaseInsensitiveString(name)
     if name in self._species_common:
         return str(name)
     species_name = None
     level = level.lower().strip()
     name = name
     for data in [self._common_species, self._ensembl_species]:
         if name in data:
             species_name = data[name]
     if species_name is None:
         msg = "Unknown common name: %s" % name
         if level == 'raise':
             raise RuntimeError(msg)
         elif level == 'warn':
             print "WARN: %s" % msg
     return str(species_name)
Beispiel #8
0
 def getCommonName(self, name, level='raise'):
     """returns the common name for the given name (which can be either a
     species name or the ensembl version)"""
     name = CaseInsensitiveString(name)
     if name in self._ensembl_species:
         name = self._ensembl_species[name]
     
     if name in self._species_common:
         common_name = self._species_common[name]
     elif name in self._common_species:
         common_name = name
     else:
         common_name = None
     
     if common_name is None:
         msg = "Unknown species name: %s" % name
         if level == 'raise':
             raise RuntimeError(msg)
         elif level == 'warn':
             print "WARN: %s" % msg
     
     return str(common_name)