#!/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/#importosimportcollectionsimportbs4importpypath.share.curlascurlimportpypath.resources.urlsasurlsimportpypath.utils.mappingasmapping
[docs]defcancersea_annotations():""" Retrieves genes annotated with cancer funcitonal states from the CancerSEA database. """CancerseaAnnotation=collections.namedtuple('CancerseaAnnotation',['state',],)annotations=collections.defaultdict(set)url=urls.urls['cancersea']['rescued']c=curl.Curl(url,silent=False,large=False)soup=bs4.BeautifulSoup(c.result,'html.parser')forrowinsoup.find_all('tbody')[1].find_all('tr'):state=row.find_all('td')[0].texturl_end=row.find_all('td')[-1].find('a').attrs['href']url_end=url_end.rsplit('/',maxsplit=1)[-1]data_url=urls.urls['cancersea']['rescued_data']%url_endc=curl.Curl(data_url,silent=False,large=True)_=next(c.result)forlineinc.result:line=line.strip().split('\t')uniprots=mapping.map_name(line[1],'genesymbol','uniprot')foruniprotinuniprots:annotations[uniprot].add(CancerseaAnnotation(state=state))returndict(annotations)