#!/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/#importcsvimportcollectionsimportpypath.share.curlascurlimportpypath.share.commonascommonimportpypath.resources.urlsasurlsimportpypath.utils.mappingasmapping
[docs]defcpad_annotations(include_unknown_type=False):CpadAnnotation=collections.namedtuple('CpadAnnotation',['regulator_type','effect_on_pathway','pathway','effect_on_cancer','effect_on_cancer_outcome','cancer','pathway_category',])cpad=get_cpad()result=collections.defaultdict(set)forrecincpad:ifrec['Regulator']=='NULL':continueforregulatorinrec['Regulator'].split(' and '):uniprot=mapping.map_name0(regulator,'genesymbol','uniprot')ifuniprot:regulator_name=uniprotregulator_type='protein'else:mirbase=mapping.map_name('hsa-%s'%regulator,'mir-mat-name','mirbase',)ifnotmirbase:mirbase=mapping.map_name('hsa-%s'%regulator,'mir-name','mirbase',)ifmirbase:regulator_name=mirbaseregulator_type='mirna'else:ifinclude_unknown_type:regulator_name=regulatorregulator_type='unknown'else:continueifisinstance(regulator_name,str):regulator_name=(regulator_name,)forregulator_name_0inregulator_name:record=CpadAnnotation(regulator_type=regulator_type,effect_on_pathway=rec['Regulator_Type'],effect_on_cancer=rec['Regulation_Type'],effect_on_cancer_outcome=rec['Outcome_Description'],pathway=rec['Pathway'],pathway_category=rec['Pathway_Category'],cancer=rec['Cancer'],)result[regulator_name_0].add(record)returndict(result)
[docs]defcpad_pathway_cancer():""" Collects only the pathway-cancer relationships. Returns sets of records grouped in dicts by cancer and by pathway. """CpadPathwayCancer=collections.namedtuple('CpadPathwayCancer',['pathway','cancer','pathway_category','effect_on_cancer','effect_on_cancer_outcome',])cpad=get_cpad()by_cancer=collections.defaultdict(set)by_pathway=collections.defaultdict(set)forrecincpad:record=CpadPathwayCancer(pathway=rec['Pathway'],cancer=rec['Cancer'],pathway_category=rec['Pathway_Category'],effect_on_cancer=rec['Regulation_Type'],effect_on_cancer_outcome=rec['Outcome_Description'],)by_cancer[rec['Cancer']].add(record)by_pathway[rec['Pathway']].add(record)returndict(by_cancer),dict(by_pathway)