def downloadPathway(organismString: 'eco', pathwayName: '00260') -> str: """ Downloads pathway as KGML for a given organism from KEGG. Tries several times before giving up, see :attr:`FEV_KEGG.settings.retryDownloadBackoffFactor`. Parameters ---------- organismString : str Abbreviation of the organism, e.g. 'eco'. pathwayName : str Name of the pathway, e.g. '00260'. Will be automatically concatenated with `organismString` to form the pathway ID, e.g. 'eco:00260'. Returns ------- str Pathway in KGML format. Raises ------ HTTPError If pathway does not exist. URLError If connection to KEGG fails. """ return REST.kegg_get(organismString + pathwayName, 'kgml', timeout=settings.downloadTimeoutSocket).read()
def downloadPathwayList(organismString: 'eco') -> str: """ Downloads list of all pathways for a given organism from KEGG. Tries several times before giving up, see :attr:`FEV_KEGG.settings.retryDownloadBackoffFactor`. Parameters ---------- organismString : str Abbreviation of the organism, e.g. 'eco'. Returns ------- str List of pathways, delimited by '\\\\n'. Raises ------ HTTPError If pathway list does not exist. URLError If connection to KEGG fails. """ return REST.kegg_list('pathway', organismString, timeout=settings.downloadTimeoutSocket).read()
def downloadOrganismInfo(organismAbbreviation) -> str: """ Downloads the info file of an organism. Parameters ---------- organismAbbreviation : str Abbreviation of the organism to check, e.g. 'eco'. Returns ------- str Raw organism info. *None*, if download was empty (400 Bad Request), because this organism does not exist. Raises ------ URLError If connection to KEGG fails. """ try: return REST.kegg_info(organismAbbreviation, timeout=settings.downloadTimeoutSocket).read() except urllib.error.HTTPError as e: if isinstance(e, urllib.error.HTTPError) and e.code == 400: return None else: raise
def downloadGene(geneID: 'eco:b0004') -> str: """ Downloads gene description for a given gene ID (includes organism) from KEGG. Tries several times before giving up, see :attr:`FEV_KEGG.settings.retryDownloadBackoffFactor`. Parameters ---------- geneID : str ID of the gene, including organism abbreviation, e.g. 'eco:b0004'. Returns ------- str Gene in KEGG GENE format. Raises ------ HTTPError If gene does not exist. URLError If connection to KEGG fails. """ result = REST.kegg_get(geneID, timeout=settings.downloadTimeoutSocket).read() if len(result) < 3: raise urllib.error.HTTPError("Download too small:\n" + result) else: return result
def _downloadGeneBulk(query_part): if Parallelism.getShallCancelThreads() is True: raise concurrent.futures.CancelledError() else: result = REST.kegg_get(query_part, timeout=settings.downloadTimeoutSocket).read() if len(result) < 3: raise IOError("Download too small:\n" + result) else: return result
def downloadTaxonomyKEGG(): """ Download KEGG taxonomy from KEGG BRITE. Returns ------- str KEGG taxonomy in special text format. Raises ------ URLError If connection to KEGG fails. """ return REST.kegg_get('br:br08601', timeout=settings.downloadTimeoutSocket).read()
def downloadOrganismList() -> str: """ Download the list of all organisms known to KEGG. Tries several times before giving up, see :attr:`FEV_KEGG.settings.retryDownloadBackoffFactor`. Returns ------- str List of organism descriptions known to KEGG, delimited by '\\\\n'. Raises ------ URLError If connection to KEGG fails. """ return REST.kegg_list('organism', timeout=settings.downloadTimeoutSocket).read()
def downloadEcEnzyme(ecNumberID): """ Download an enzyme description file from KEGG, defined by its EC number. Parameters ---------- ecNumber : str The EC number string of the enzyme to download, e.g. '4.1.2.48'. Returns ------- str Content of the EcEnzymes's description. Raises ------ URLError If connection to KEGG fails. """ return REST.kegg_get('ec:' + ecNumberID, timeout=settings.downloadTimeoutSocket).read()
def downloadSubstance(substanceID): """ Download a substance description file from KEGG, compound or glycan. Parameters ---------- substanceID : str The ID string of the substance to download, e.g. 'C00084'. Returns ------- str Content of the substance's description. Raises ------ URLError If connection to KEGG fails. """ return REST.kegg_get(substanceID, timeout=settings.downloadTimeoutSocket).read()
def downloadEnzymeEcNumbers(enzymeAbbreviation) -> str: """ Download the list of all EC numbers for a given enzyme, identified by its abbreviation, from KEGG. Also works for everything else in the description of an enzyme, not just the abbreviation. Tries several times before giving up, see :attr:`FEV_KEGG.settings.retryDownloadBackoffFactor`. Parameters ---------- enzymeAbbreviation : str Common abbreviation of the desired enzyme, as it appears in its description, e.g. 'MiA'. Also works for everything else in the description of an enzyme, not just the abbreviation. Returns ------- str EC numbers, delimited by '\\\\n'. Raises ------ URLError If connection to KEGG fails. """ ecNumbers = [] # look up enzyme EC numbers searchResult = REST.kegg_find( 'enzyme', enzymeAbbreviation, timeout=settings.downloadTimeoutSocket).read().split('\n') for line in searchResult: if len(line) < 10: continue ecNumber = line.split('\t')[0].split(':')[1] ecNumbers.append(ecNumber) return '\n'.join(ecNumbers)