Snippets
Created by
Dénes Türei
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2017 - EMBL-EBI
#
# File author(s): Dénes Türei (denes@ebi.ac.uk)
#
# Website: http://www.ebi.ac.uk/~denes
#
import pypath
import re
int1 = \
'''MEK1_pS217_S221->MAPK_pT202_Y204
GSK3A_pS21_S9->GSK3A_pS9
GSK3B_pS21_S9->GSK3B_pS9
RPS6KB1_pT389->RPS6_pS235_S236
EGFR_pY1068->Src_pY416
HER2_pY1248->EGFR_pY1068
Src_pY416->EGFR_pY1068
RPS6_pS240_S244->RPS6_pS235_S236
AKT_pS473->GSK3A_pS21_S9
AKT_pS473->GSK3B_pS21_S9
MEK1_pS217_S221->BAD_pS112
EGFR_pY1068->HER2_pY1248
NRG1->HER3_pY1298
HGF->MET_pY1235
AKT_pS473->AKT_pT308
AKT_pT308->AKT_pS473
MAPK_pT202_Y204->MEK1_pS217_S221
GSK3A_pS9->GSK3A_pS21_S9
GSK3B_pS9->GSK3B_pS21_S9
RPS6_pS235_S236->RPS6KB1_pT389
GSK3A_pS21_S9->PRAS40_pT246
GSK3B_pS21_S9->PRAS40_pT246
RPS6KB1_pT389->BAD_pS112
RPS6KB1_pT389->RPS6_pS240_S244'''
int2 = \
'''Serum->MAPK14_pT180_Y182
HGF->RAF1_pS338
EGF->Src_pY416
EGF->EGFR_pY1068
Rictor_pT1135->mTOR_pS2448
EGF->EGFR_pY1173
EGF->EIF4EBP1_pS65
EGF->GSK3A_pS21_S9
EGF->GSK3B_pS21_S9
PBS1->RPS6_pS240_S244
BAD_pS112->JUN_pS73
GSK3A_pS9->RPS6KB1_pT389
GSK3B_pS9->RPS6KB1_pT389
Src_pY416->EGFR_pY1068
RPS6KB1_pT389->NDRG1_pT346
NDRG1_pT346->GSK3A_pS9
NDRG1_pT346->GSK3B_pS9
AKT_pS473->AKT_pT308
AKT_pT308->AKT_pS473
GSK3A_pS9->GSK3A_pS21_S9
GSK3A_pS9->GSK3A_pS21_S9
NRG1->HER3_pY1298
HGF->MET_pY1235
RPS6KA1_pT359_S363->BAD_pS112'''
def map_int(interactions):
return \
list(
map(
lambda i:
list(
map(
lambda p:
p.split('_'),
i
)
),
map(
lambda i:
i.split('->'),
interactions.split('\n')
)
)
)
def map_mods(mods):
return \
list(
map(
lambda m:
(m[0], int(m[1:])),
map(
lambda m:
m.replace('p', ''),
filter(
lambda m:
m != 'alpha' and m != 'beta',
mods
)
)
)
)
def to_uniprot(interactions):
result = []
unmapped = set([])
m = pypath.mapping.Mapper()
for i in interactions:
u0 = m.map_name(i[0][0], 'genesymbol', 'uniprot')
u1 = m.map_name(i[1][0], 'genesymbol', 'uniprot')
if not len(u0):
unmapped.add(i[0][0])
if not len(u1):
unmapped.add(i[1][0])
if len(u0) and len(u1):
mods0 = map_mods(i[0][1:])
mods1 = map_mods(i[1][1:])
result.append([[u0[0], i[0][0]] + mods0,
[u1[0], i[1][0]] + mods1])
return result, unmapped
def lookup_interactions(uint, pa):
result = []
for i in uint:
e = pa.edge_exists(i[0][0], i[1][0])
res = [i[0][0], i[0][1], i[1][0], i[1][1]]
if type(e) is not int:
res.extend(['', '', ''])
result.append(res)
print('Could not find edge between %s and %s' % (i[0][1], i[1][1]))
continue
e = pa.graph.es[e]
dirr = (i[0][0], i[1][0])
d = e['dirs']
ptms = set(i[1][2:])
if d.get_dir(dirr):
res.append('directed')
if dirr in e['refs_by_dir']:
refs = list(map(lambda r: r.pmid, e['refs_by_dir'][dirr]))
res.append(';'.join(refs))
else:
refs = list(map(lambda r: r.pmid, e['refs_by_dir']['undirected']))
res.append(';'.join(refs))
elif d.get_dir('undirected'):
undir_refs = list(map(lambda r: r.pmid, e['refs_by_dir']['undirected']))
res.append('undirected')
res.append(';'.join(undir_refs))
ptms_in_dbs = set([])
for ptm in e['ptm']:
if ptm.ptm.protein == i[1][0]:
this_ptm = (ptm.ptm.residue.name, ptm.ptm.residue.number)
if this_ptm in ptms:
ptms_in_dbs.add(this_ptm)
res.append(';'.join(list(map(lambda p: '%s%u' % p, ptms_in_dbs))))
result.append(res)
return result
def table(fname, ll):
with open(fname, 'w') as fp:
fp.write('\n'.join(map(lambda l: '\t'.join(l), ll)))
uint1, unmapped1 = to_uniprot(map_int(int1))
uint2, unmapped2 = to_uniprot(map_int(int2))
pa = pypath.PyPath(ncbi_tax_id = 9606, loops = True)
pa.load_omnipath()
pa.load_ptms()
res1 = lookup_interactions(uint1, pa)
res2 = lookup_interactions(uint2, pa)
table('mean.tab', res1)
table('var.tab', res2)
|
Comments (0)
You can clone a snippet to your computer for local editing. Learn more.