#!/usr/bin/env python# -*- coding: utf-8 -*-## This file is part of the `pypath` python module## Copyright 2014-2023# EMBL, EMBL-EBI, Uniklinik RWTH Aachen, Heidelberg University## Authors: see the file `README.rst`# Contact: Dénes Türei (turei.denes@gmail.com)## Distributed under the GPLv3 License.# See accompanying file LICENSE.txt or copy at# https://www.gnu.org/licenses/gpl-3.0.html## Website: https://pypath.omnipathdb.org/#importcollectionsimportwarningsimportbs4importpypath.resources.urlsasurlsimportpypath.share.curlascurlimportpypath.share.settingsassettings"""Note: find other Ensembl related functions in ``inputs.biomart``."""
[docs]defensembl_organisms():""" List of organisms in Ensembl with various taxon IDs and metadata about related Ensembl database contents. Returns List of named tuples. """record=Noneresult=[]url=urls.urls['ensembl']['species']c=curl.Curl(url,req_headers=[settings.get('user_agent')])withwarnings.catch_warnings():warnings.simplefilter('ignore',bs4.XMLParsedAsHTMLWarning)soup=bs4.BeautifulSoup(c.result,'html.parser')forrinsoup.find('table').find_all('tr'):ifnotrecord:record=collections.namedtuple('EnsemblOrganism',[c.text.lower().replace(' ','_')forcinr]+['ensembl_name'])continuer=list(r)result.append(record(*(int(c.text)ifi==2elsec.textfori,cinenumerate(r)),(# Mus musculus -> mmusculuslambdax:''.join([xx[0]forxxinx[:-1]]+[x[-1]]))(r[1].text.lower().split())))returnresult