Source code for pypath.inputs.stitch

#!/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/
#

from typing import List, Literal, Union
from numbers import Number

import re
import collections

import pypath.resources.urls as urls
import pypath.share.curl as curl


[docs] def stitch_actions_interactions(threshold: Number = None) -> List[tuple]: StitchActionsInteraction = collections.namedtuple( 'StitchActionsInteraction', ( 'partner_a', 'partner_b', 'mechanism', 'action', 'score', ), ) url = urls.urls['stitch']['actions'] c = curl.Curl(url, silent = False, large = True, slow = True) _ = next(c.result) sep = re.compile(r'[sm\.]') for l in c.result: if hasattr(l, 'decode'): l = l.decode('utf-8') l = l.strip().split('\t') score = int(l[5]) if threshold is not None and score < threshold: continue a = sep.split(l[0])[1] b = sep.split(l[1])[1] if l[4] == 'f': a, b = b, a yield StitchActionsInteraction( partner_a = a, partner_b = b, mechanism = l[2], action = l[3] or None, score = int(l[5]), )