Skip to content

Commit

Permalink
Removed spaces in empty lines in inputs module
Browse files Browse the repository at this point in the history
  • Loading branch information
npalacioescat committed Feb 27, 2020
1 parent f6e364c commit e758523
Show file tree
Hide file tree
Showing 13 changed files with 297 additions and 299 deletions.
25 changes: 12 additions & 13 deletions src/pypath/inputs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
# Website: http://pypath.omnipathdb.org/
#


import importlib


Expand All @@ -31,35 +30,35 @@ def get_method(module_name, method_name = None):
name. E.g. for ``'uniprot.all_uniprots'`` it returns the ``all_uniprots``
method from the ``pypath.inputs.uniprot`` module.
"""

if not method_name:

module_method = module_name.rsplit('.', maxsplit = 1)
method_name = module_method[-1]
module_name = module_method[-2] if len(module_method) > 1 else 'main'

module_name = module_name.rsplit('.', maxsplit = 1)[-1]
module_name = 'pypath.inputs.%s' % module_name

try:

mod = importlib.import_module(module_name)

except:

session.get_log().msg(
msg = 'Could not import module `%s`.' % module_name,
label = 'inputs',
)

try:

method = getattr(mod, method_name)

return method

except:

session.get_log().msg(
msg = 'Could not find method `%s` in module `%s`.' % (
method_name,
Expand Down
6 changes: 3 additions & 3 deletions src/pypath/inputs/deathdomain.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ def deathdomain_interactions_rescued():
"""

url = urls.urls['death']['url_alive']

c = curl.Curl(url, silent = False, large = True)

_ = next(c.result)

return [
[i.strip() for i in line.split('\t')]
for line in c.result
Expand Down
36 changes: 18 additions & 18 deletions src/pypath/inputs/depod.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ def depod_interactions(organism = 9606):
l = l.split('\t')
specA = int(l[9].split(':')[1].split('(')[0])
specB = int(l[10].split(':')[1].split('(')[0])

if organism is None or (specA == organism and specB == organism):

pm = l[8].replace('pubmed:', '')
sc = l[14].replace('curator score:', '')
ty = l[11].split('(')[1].replace(')', '')
l = [l[0], l[1]]
interaction = ()

for ll in l:

ll = ll.split('|')
uniprot = ''
for lll in ll:
Expand All @@ -66,38 +66,38 @@ def depod_interactions(organism = 9606):
if nm[0] == 'uniprotkb' and len(u) == 6:
uniprot = u
interaction += (uniprot, )

interaction += (pm, sc, ty)
if len(interaction[0]) > 1 and len(interaction[1]) > 1:
i.append(interaction)

lnum += 1

return i


def depod_enzyme_substrate(organism = 9606):

result = []

reunip = re.compile(r'uniprotkb:([A-Z0-9]+)')
reptm = re.compile(r'([A-Z][a-z]{2})-([0-9]+)')
repmidsep = re.compile(r'[,|]\s?')

url = urls.urls['depod']['urls'][0]
c = curl.Curl(url, silent = False, encoding = 'ascii')
data = c.result
data = [x.split('\t') for x in data.split('\n')]
del data[0]

url_mitab = urls.urls['depod']['urls'][1]
c_mitab = curl.Curl(url_mitab, silent = False, encoding = 'iso-8859-1')
data_mitab = c_mitab.result
data_mitab = [x.split('\t') for x in data_mitab.split('\n')]
del data_mitab[0]

for i, l in enumerate(data):

if (
len(l) > 6 and
l[2] == 'protein substrate' and
Expand All @@ -106,10 +106,10 @@ def depod_enzyme_substrate(organism = 9606):
) == organism and
l[4].strip() != 'N/A'
):

enzyme_uniprot = reunip.search(data_mitab[i][0]).groups()[0]
substrate_uniprot = reunip.search(data_mitab[i][1]).groups()[0]

for enzyme_up, substrate_up in itertools.product(
mapping.map_name(
enzyme_uniprot,
Expand All @@ -122,16 +122,16 @@ def depod_enzyme_substrate(organism = 9606):
'uniprot'
),
):

for resaa, resnum in reptm.findall(l[4]):

resnum = int(resnum)
resaa = (
common.aminoa_3_to_1_letter[resaa]
if resaa in common.aminoa_3_to_1_letter else
resaa
)

result.append({
'instance': None,
'kinase': enzyme_up,
Expand All @@ -143,5 +143,5 @@ def depod_enzyme_substrate(organism = 9606):
'end': None,
'typ': 'dephosphorylation',
})

return result
46 changes: 23 additions & 23 deletions src/pypath/inputs/huri.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,23 +93,23 @@ def hi_iii():
'form[request_file_format]': 'psi',
}
c = curl.Curl(url, silent = False, large = True, post = post_data)

for row in c.result:

if not row.strip():

continue

id_a, id_b, rest = row.split(' ', maxsplit = 2)
id_a, isoform_a = id_a.split('-') if '-' in id_a else (id_a, 1)
id_b, isoform_b = id_b.split('-') if '-' in id_b else (id_b, 1)

sc = rescore.search(rest)
score = float(sc.groups()[0]) if sc else None
screens = tuple(
int(i) for i in rescreens.search(rest).groups()[0].split(',')
)

yield HiiiiInteraction(
id_a = id_a[10:],
id_b = id_b[10:],
Expand All @@ -122,11 +122,11 @@ def hi_iii():

def lit_bm_13_interactions():
"""
Downloads and processes Lit-BM-13 dataset, the 2013 version of the
Downloads and processes Lit-BM-13 dataset, the 2013 version of the
high confidence literature curated interactions from CCSB.
Returns list of interactions.
"""

LitBm13Interaction = collections.namedtuple(
'LitBm13Interaction',
[
Expand All @@ -136,16 +136,16 @@ def lit_bm_13_interactions():
'genesymbol_b',
]
)

url = urls.urls['hid']['lit-bm-13']
c = curl.Curl(url, silent = False, large = True)

_ = next(c.result)

for row in c.result:

row = row.strip().split('\t')

yield LitBm13Interaction(
entrez_a = row[0],
entrez_b = row[2],
Expand All @@ -156,11 +156,11 @@ def lit_bm_13_interactions():

def lit_bm_17_interactions():
"""
Downloads and processes Lit-BM-13 dataset, the 2017 version of the
Downloads and processes Lit-BM-13 dataset, the 2017 version of the
high confidence literature curated interactions from CCSB.
Returns list of interactions.
"""

LitBm17Interaction = collections.namedtuple(
'LitBm17Interaction',
[
Expand All @@ -170,25 +170,25 @@ def lit_bm_17_interactions():
'score',
]
)

url = urls.urls['hid']['lit-bm-17']
c = curl.Curl(url, silent = False)
data = c.result

c = curl.Curl(url, silent = False, large = True)

_ = next(c.result)

for row in c.result:

row = row.strip().split('\t')

id_a = row[0][10:]
id_b = row[1][10:]

pubmed = row[8][7:]
score = float(row[14][13:])

yield LitBm17Interaction(
id_a = id_a,
id_b = id_b,
Expand Down
4 changes: 2 additions & 2 deletions src/pypath/inputs/intact.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ def get_id(field):
uniprot, isoform = _try_isoform(
field.split(':')[1].replace('"', '')
)

uniprot = uniprot.split('-')[0]

return uniprot, isoform


Expand Down
35 changes: 17 additions & 18 deletions src/pypath/inputs/kea.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
# Website: http://pypath.omnipathdb.org/
#


import re
import collections
import itertools
Expand All @@ -40,8 +39,8 @@


def kea_interactions():


KeaRecord = collections.namedtuple(
'KeaRecord',
[
Expand All @@ -53,32 +52,32 @@ def kea_interactions():
'resource',
]
)

resub = re.compile(r'(\w+)_([A-Z])([0-9]+)')

url = urls.urls['kea']['kinase_substrate']

c = curl.Curl(url, silent = False, large = True)

result = []

for rec in c.result:

rec = rec.strip().split('\t')

site = resub.match(rec[1].strip())

if not site:

continue

target, resaa, resnum = site.groups()

e_uniprots = mapping.map_name(rec[0], 'genesymbol', 'uniprot')
s_uniprots = mapping.map_name(target, 'genesymbol', 'uniprot')

for enz, sub in itertools.product(e_uniprots, s_uniprots):

result.append(
KeaRecord(
enzyme = enz,
Expand All @@ -89,12 +88,12 @@ def kea_interactions():
resource = _resources[rec[3].strip()]
)
)

return result


def kea_enzyme_substrate():

return [
{
'start': None,
Expand Down
Loading

0 comments on commit e758523

Please sign in to comment.