#!/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/#importreimportitertoolsimportcollectionsimportpypath.share.curlascurlimportpypath.resources.urlsasurlsimportpypath.inputs.commonasinputs_commonimportpypath.utils.mappingasmapping
[docs]deframilowski_interactions(putative=False):""" Downloads and processes ligand-receptor interactions from Supplementary Table 2 of Ramilowski 2015. Returns list of lists with ligand and receptor gene symbols, reference and resources as elements. """c=curl.Curl(urls.urls['rami']['url'],silent=False,large=True)xlsname=c.fnamedel(c)raw=inputs_common.read_xls(xlsname,'All.Pairs')[1:]Ramilowski2015Interaction=collections.namedtuple('Ramilowski2015Interaction',('ligand','receptor','references','resources',),)return[Ramilowski2015Interaction(ligand=r[1],receptor=r[3],references=r[13].replace(' ',''),# referencesresources=';'.join(filter(len,itertools.chain(r[5:11],[r[15]]))),)forrinrawifnotr[15].startswith('EXCLUDED')and(putativeorr[15]!='putative')]returnraw
[docs]deframilowski_locations(long_notes=False):""" Subcellular location annotations from Ramilowski 2015. """reloc=re.compile(r'([^\(]+[^\s^\(])'r'\s?\('r'?(?:(.*[^\)])?)'r'\)?')resep=re.compile(r'[\.;,]')renote=re.compile(r'Note=([- \w\(\),\s\+\./%\'":;]*)')sources=((4,'UniProt'),(5,'HPRD'),(7,'LocTree3'),(10,'Consensus'),(11,'Consensus6'),)RamilowskiLocation=collections.namedtuple('RamilowskiLocation',['location','source','tmh','note','long_note',],)url=urls.urls['rami']['loc']c=curl.Curl(url,silent=False,large=True)_=next(c.result)result=collections.defaultdict(set)forlinc.result:l=l.strip('\n\r').split('\t')foridx,sourceinsources:locs=l[idx]long_note=Nonemnote=renote.search(locs)ifmnote:long_note=mnote.groups()[0]locs=renote.sub('',locs)forlocinresep.split(locs):if':'inlocand'GO:'notinloc:loc=loc.split(':')[-1]loc=loc.strip().replace('- ','-').lower()if(notlocorlen(loc.split())>3orre.search(r'\d',loc)orloc=='n/a'orany(winlocforwin('tumor',))):continuem=reloc.match(loc)ifnotm:continuelocation,note=m.groups()tmh=l[9].strip()uniprots=mapping.map_name(l[3],'uniprot','uniprot')foruniprotinuniprots:result[uniprot].add(RamilowskiLocation(location=(location.lower().replace('=','').strip()),source=source,tmh=int(tmh)iftmh.isdigit()elseNone,note=note,long_note=long_noteiflong_noteselseNone,))returndict(result)