#!/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/#fromfuture.utilsimportiteritemsimportsysimportreimportcollectionsimportitertoolsimportpypath.share.curlascurlimportpypath.resources.urlsasurlsimportpypath.share.commonascommonimportpypath.utils.mappingasmapping
[docs]defsignalink_interactions(organism=9606,exclude_secondary=True):""" Reads and processes SignaLink3 interactions from local file. Returns list of interactions. """SignalinkInteraction=collections.namedtuple('SignalinkInteraction',['id_a','id_b','is_direct','is_directed','effect','pathways_a','pathways_b','functions_a','functions_b','references','resources',])signalink_sources={'SLKv2.0','SLKv2.1','SLKv3.0','SignaFish','TCRcuration',}repref=re.compile(r'(?:.*:)?((?:[\w]+[^\s])?)\s?')nodes_pathways={}nodes_organism={}nodes_functions={}interactions=[]defget_value(field):returnrepref.sub('\\1',field)defget_values(field):return[get_value(f)forfinfield.split('|')]url_nodes=urls.urls['signalink']['nodes']c_nodes=curl.Curl(url_nodes,silent=False,large=True)url_edges=urls.urls['signalink']['edges']c_edges=curl.Curl(url_edges,silent=False,large=True)_=next(c_nodes.result)forlinc_nodes.result:l=l.strip('\n\r')ifl:l=l.split('\t')_id=int(l[0])uniprot=get_value(l[1])pathways=(l[4].replace('/Wingless','').split('|')ifl[4]else[])_organism=int(get_value(l[3]))nodes_pathways[uniprot]=pathwaysnodes_organism[uniprot]=_organismnodes_functions[uniprot]=l[6].split('|')ifl[6]else[]_=next(c_edges.result)forlinc_edges.result:l=l.strip().split('\t')ifexclude_secondaryandnotset(l[6].split('|'))&signalink_sources:continueid_a=get_value(l[0])id_b=get_value(l[1])if(nodes_organism[id_a]!=organismornodes_organism[id_b]!=organism):continueresources=[resforresinget_values(l[6])ifnotres.startswith('SLK')]interaction_attrs={tuple(iattr.split(':'))foriattrinl[5].split('|')}effects=[]if('MI','0624(stimulation)')ininteraction_attrs:effects.append(1)if('MI','0623(inhibition)')ininteraction_attrs:effects.append(-1)ifnoteffects:effects.append(0)foreffectineffects:interactions.append(SignalinkInteraction(id_a=id_a,id_b=id_b,is_direct=('is_direct','true')ininteraction_attrs,is_directed=('is_directed','true')ininteraction_attrs,effect=effect,pathways_a=nodes_pathways[id_a],pathways_b=nodes_pathways[id_b],functions_a=nodes_functions[id_a],functions_b=nodes_functions[id_b],references=get_values(l[4]),resources=resources,))returninteractions