comparison tools/myTools/bin/sfa/data/korkut_2015a/__init__.py @ 1:7e5c71b2e71f draft default tip

Uploaded
author laurenmarazzi
date Wed, 22 Dec 2021 16:00:34 +0000
parents
children
comparison
equal deleted inserted replaced
0:f24d4892aaed 1:7e5c71b2e71f
1 # -*- coding: utf-8 -*-
2
3 """
4 [Reference]
5 Korkut and Wang et al.
6 Perturbation biology nominates upstream-downstream drug combinations
7 in RAF inhibitor resistant melanoma cells
8 eLife (2015) 4:e04640
9 """
10
11 import os
12
13 import numpy as np
14 import pandas as pd
15
16 import sfa
17 import sfa.base
18
19 def create_data():
20 dpath = os.path.dirname(__file__)
21 fpath_network = os.path.join(dpath, "model_3250.sif")
22 return KorkutData("KORKUT_2015A", dpath, fpath_network)
23
24
25 class KorkutData(sfa.base.Data):
26
27 def __init__(self, abbr, dpath, fpath_network):
28
29 self._abbr = abbr
30 self._name = "Korkut and Wang et al. eLife 2015;4:e04640"
31
32 fpath_ptb = os.path.join(dpath, "ptb.tsv")
33
34 A, n2i, dg = sfa.read_sif(fpath_network, as_nx=True)
35 self._A = A
36 self._n2i = n2i
37 self._dg = dg
38 self._df_conds = pd.read_table(os.path.join(dpath, "conds.tsv"),
39 header=0, index_col=0)
40 self._df_exp = pd.read_table(os.path.join(dpath, "exp.tsv"),
41 header=0, index_col=0)
42
43 self._inputs = {}
44 self._df_ptb = pd.read_table(fpath_ptb, index_col=0)
45 if any(self._df_ptb.Type == 'link'):
46 self._has_link_perturb = True
47 else:
48 self._has_link_perturb = False
49
50
51 # Remove the rows and columns of a node which is not
52 # included in the given network structure.
53 not_included = set(self._df_conds.columns) - set(self._n2i.keys())
54 for target in not_included:
55 ind_removed = self._df_conds[self.df_conds[target] != 0].index
56 self._df_conds.drop(ind_removed, inplace=True)
57 self._df_conds.drop([target], axis=1, inplace=True)
58 self._df_exp.drop(ind_removed, inplace=True)
59 self._df_ptb.drop([target], inplace=True)
60
61 # Re-index according to the new size.
62 self._df_conds.index = np.arange(1, self._df_exp.shape[0]+1)
63 self._df_exp.index = self._df_conds.index
64
65
66 self._names_ptb = []
67 for i, row in enumerate(self._df_conds.iterrows()):
68 row = row[1]
69 list_name = [] # Target names
70 for target in self._df_conds.columns[row.nonzero()]:
71 list_name.append(target)
72 # end of for
73 self._names_ptb.append(list_name)
74 # end of for
75
76 s1 = set(self._df_exp.columns) # From experimental data
77 s2 = set(n2i.keys()) # From network
78 exp_only = s1 - s2
79 self._df_exp.drop(exp_only, axis=1, inplace=True)
80
81
82 # For mapping from the indices of adj. matrix to those of DataFrame
83 # (arrange the indices of adj. matrix according to df_exp.columns)
84 self._iadj_to_idf = [n2i[x] for x in self._df_exp.columns]
85 self._i2n = {idx: name for name, idx in n2i.items()}
86 # end of def __init__
87
88
89
90