Switch to unified view

a b/doc/_build/html/utils.html
1
2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
3
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
5
<html xmlns="http://www.w3.org/1999/xhtml">
6
  <head>
7
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
8
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
9
    <title>Maui Utilities &#8212;  0.1 documentation</title>
10
    <link rel="stylesheet" href="_static/alabaster.css" type="text/css" />
11
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
12
    <script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
13
    <script type="text/javascript" src="_static/jquery.js"></script>
14
    <script type="text/javascript" src="_static/underscore.js"></script>
15
    <script type="text/javascript" src="_static/doctools.js"></script>
16
    <script async="async" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
17
    <link rel="shortcut icon" href="_static/icons8-beach-30.png"/>
18
    <link rel="index" title="Index" href="genindex.html" />
19
    <link rel="search" title="Search" href="search.html" />
20
    <link rel="prev" title="The Maui Class" href="maui.html" />
21
   
22
  <link rel="stylesheet" href="_static/custom.css" type="text/css" />
23
  
24
  
25
  <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
26
27
  </head><body>
28
  
29
30
    <div class="document">
31
      <div class="documentwrapper">
32
        <div class="bodywrapper">
33
          
34
35
          <div class="body" role="main">
36
            
37
  <div class="section" id="module-maui.utils">
38
<span id="maui-utilities"></span><h1>Maui Utilities<a class="headerlink" href="#module-maui.utils" title="Permalink to this headline">¶</a></h1>
39
<p>The maui.utils model contains utility functions for multi-omics analysis
40
using maui.</p>
41
<dl class="function">
42
<dt id="maui.utils.compute_harrells_c">
43
<code class="descclassname">maui.utils.</code><code class="descname">compute_harrells_c</code><span class="sig-paren">(</span><em>z, survival, duration_column='duration', observed_column='observed', cox_penalties=[0.1, 1, 10, 100, 1000, 10000], cv_folds=5</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/maui/utils.html#compute_harrells_c"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#maui.utils.compute_harrells_c" title="Permalink to this definition">¶</a></dt>
44
<dd><p>Compute’s Harrell’s c-Index for a Cox Proportional Hazards regression modeling
45
survival by the latent factors in z.</p>
46
<p>z:                  pd.DataFrame (n_samples, n_latent factors)
47
survival:           pd.DataFrame of survival information and relevant covariates</p>
48
<blockquote>
49
<div>(such as sex, age at diagnosis, or tumor stage)</div></blockquote>
50
<dl class="docutils">
51
<dt>duration_column:    the name of the column in <code class="docutils literal notranslate"><span class="pre">survival</span></code> containing the</dt>
52
<dd>duration (time between diagnosis and death or last followup)</dd>
53
<dt>observed_column:    the name of the column in <code class="docutils literal notranslate"><span class="pre">survival</span></code> containing</dt>
54
<dd>indicating whether time of death is known</dd>
55
<dt>cox_penalties:      penalty coefficient in Cox PH solver (see <code class="docutils literal notranslate"><span class="pre">lifelines.CoxPHFitter</span></code>)</dt>
56
<dd>to try. Returns the best c given by the different penalties
57
(by cross-validation)</dd>
58
</dl>
59
<p>cv_folds:           number of cross-validation folds to compute C</p>
60
<dl class="docutils">
61
<dt>cs: array, Harrell’s c-Index, an auc-like metric for survival prediction accuracy.</dt>
62
<dd>one value per cv_fold</dd>
63
</dl>
64
</dd></dl>
65
66
<dl class="function">
67
<dt id="maui.utils.compute_roc">
68
<code class="descclassname">maui.utils.</code><code class="descname">compute_roc</code><span class="sig-paren">(</span><em>z</em>, <em>y</em>, <em>classifier=LinearSVC(C=0.001</em>, <em>class_weight=None</em>, <em>dual=True</em>, <em>fit_intercept=True</em>, <em>intercept_scaling=1</em>, <em>loss='squared_hinge'</em>, <em>max_iter=1000</em>, <em>multi_class='ovr'</em>, <em>penalty='l2'</em>, <em>random_state=None</em>, <em>tol=0.0001</em>, <em>verbose=0)</em>, <em>cv_folds=10</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/maui/utils.html#compute_roc"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#maui.utils.compute_roc" title="Permalink to this definition">¶</a></dt>
69
<dd><p>Compute the ROC (false positive rate, true positive rate) using cross-validation.</p>
70
<p>z:          DataFrame (n_samples, n_latent_factors) of latent factor values
71
y:          Series (n_samples,) of ground-truth labels to try to predict
72
classifier: Classifier object to use, default <code class="docutils literal notranslate"><span class="pre">LinearSVC(C=.001)</span></code></p>
73
<dl class="docutils">
74
<dt>roc_curves: dict, one key per class as well as “mean”, each value is a dataframe</dt>
75
<dd>containing the tpr (true positive rate) and fpr (falce positive rate)
76
defining that class (or the mean) ROC.</dd>
77
</dl>
78
</dd></dl>
79
80
<dl class="function">
81
<dt id="maui.utils.correlate_factors_and_features">
82
<code class="descclassname">maui.utils.</code><code class="descname">correlate_factors_and_features</code><span class="sig-paren">(</span><em>z</em>, <em>concatenated_data</em>, <em>pval_threshold=0.001</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/maui/utils.html#correlate_factors_and_features"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#maui.utils.correlate_factors_and_features" title="Permalink to this definition">¶</a></dt>
83
<dd><p>Compute pearson correlation of latent factors with input features.</p>
84
<p>z:                  (n_samples, n_factors) DataFrame of latent factor values, output of maui model
85
concatenated_data:  (n_samples, n_features) DataFrame of concatenated multi-omics data</p>
86
<dl class="docutils">
87
<dt>feature_s:  DataFrame (n_features, n_latent_factors)</dt>
88
<dd>Latent factors representation of the data X.</dd>
89
</dl>
90
</dd></dl>
91
92
<dl class="function">
93
<dt id="maui.utils.estimate_kaplan_meier">
94
<code class="descclassname">maui.utils.</code><code class="descname">estimate_kaplan_meier</code><span class="sig-paren">(</span><em>y</em>, <em>survival</em>, <em>duration_column='duration'</em>, <em>observed_column='observed'</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/maui/utils.html#estimate_kaplan_meier"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#maui.utils.estimate_kaplan_meier" title="Permalink to this definition">¶</a></dt>
95
<dd><p>Estimate survival curves for groups defined in y based on survival data in <code class="docutils literal notranslate"><span class="pre">survival</span></code></p>
96
<dl class="docutils">
97
<dt>y:                  pd.Series, groups (clusters, subtypes). the index is</dt>
98
<dd>the sample names</dd>
99
<dt>survival:           pd.DataFrame with the same index as y, with columns for</dt>
100
<dd>the duration (survival time for each patient) and whether
101
or not the death was observed. If the death was not
102
observed (sensored), the duration is the time of the last
103
followup.</dd>
104
</dl>
105
<p>duration_column:        the name of the column in  <code class="docutils literal notranslate"><span class="pre">survival</span></code> with the duration
106
observed_column:    the name of the column in <code class="docutils literal notranslate"><span class="pre">survival</span></code> with True/False values</p>
107
<blockquote>
108
<div>for whether death was observed or not</div></blockquote>
109
<dl class="docutils">
110
<dt>km_estimates:       pd.DataFrame, index is the timeline, columns are survival</dt>
111
<dd>functions (estimated by Kaplan-Meier) for each class, as
112
defined in <code class="docutils literal notranslate"><span class="pre">y</span></code>.</dd>
113
</dl>
114
</dd></dl>
115
116
<dl class="function">
117
<dt id="maui.utils.filter_factors_by_r2">
118
<code class="descclassname">maui.utils.</code><code class="descname">filter_factors_by_r2</code><span class="sig-paren">(</span><em>z</em>, <em>x</em>, <em>threshold=0.02</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/maui/utils.html#filter_factors_by_r2"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#maui.utils.filter_factors_by_r2" title="Permalink to this definition">¶</a></dt>
119
<dd><p>Filter latent factors by the R^2 of a linear model predicting features x
120
from latent factors z.</p>
121
<p>z:  (n_samples, n_factors) DataFrame of latent factor values, output of a maui model
122
x:  (n_samples, n_features) DataFrame of concatenated multi-omics data</p>
123
<dl class="docutils">
124
<dt>z_filtered: (n_samples, n_factors) DataFrame of latent factor values,</dt>
125
<dd>with only those columns from the input <cite>z</cite> which have an R^2
126
above the threshold when using that column as an input
127
to a linear model predicting <cite>x</cite>.</dd>
128
</dl>
129
</dd></dl>
130
131
<dl class="function">
132
<dt id="maui.utils.map_factors_to_feaures_using_linear_models">
133
<code class="descclassname">maui.utils.</code><code class="descname">map_factors_to_feaures_using_linear_models</code><span class="sig-paren">(</span><em>z</em>, <em>x</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/maui/utils.html#map_factors_to_feaures_using_linear_models"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#maui.utils.map_factors_to_feaures_using_linear_models" title="Permalink to this definition">¶</a></dt>
134
<dd><p>Get feature &lt;-&gt; latent factors mapping from linear models.
135
Runs one univariate (multi-output) linear model per latent factor in <cite>z</cite>,
136
predicting the values of the features <cite>x</cite>, in order to get weights
137
between inputs and outputs.</p>
138
<p>z:  (n_samples, n_factors) DataFrame of latent factor values, output of a maui model
139
x:  (n_samples, n_features) DataFrame of concatenated multi-omics data</p>
140
<dl class="docutils">
141
<dt>W:  (n_features, n_latent_factors) DataFrame</dt>
142
<dd>w_{ij} is the coefficient associated with feature <cite>i</cite> in a linear model
143
predicting it from latent factor <cite>j</cite>.</dd>
144
</dl>
145
</dd></dl>
146
147
<dl class="function">
148
<dt id="maui.utils.merge_factors">
149
<code class="descclassname">maui.utils.</code><code class="descname">merge_factors</code><span class="sig-paren">(</span><em>z</em>, <em>l=None</em>, <em>threshold=0.17</em>, <em>merge_fn=&lt;function mean&gt;</em>, <em>metric='correlation'</em>, <em>linkage='single'</em>, <em>plot_dendro=True</em>, <em>plot_dendro_ax=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/maui/utils.html#merge_factors"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#maui.utils.merge_factors" title="Permalink to this definition">¶</a></dt>
150
<dd><p>Merge latent factors in <cite>z</cite> which form clusters, as defined by hierarchical
151
clustering where a cluster is formed by cutting at a pre-set threshold, i.e.
152
merge factors if their distance to one-another is below <cite>threshold</cite>.</p>
153
<p>z:              (n_samples, n_factors) DataFrame of latent factor values, output of a maui model
154
metric:         Distance metric to merge factors by, one which is supported by</p>
155
<blockquote>
156
<div><code class="xref py py-func docutils literal notranslate"><span class="pre">scipy.spatial.distance.pdist()</span></code></div></blockquote>
157
<dl class="docutils">
158
<dt>linkage:        The kind of linkage to form hierarchical clustering, one which is</dt>
159
<dd>supported by <code class="xref py py-func docutils literal notranslate"><span class="pre">scipy.cluster.hierarchy.linkage()</span></code></dd>
160
<dt>l:              As an alternative to supplying <cite>metric</cite> and <cite>linkage</cite>, supply a</dt>
161
<dd>linkage matrix of your own choice, such as one computed by
162
<code class="xref py py-func docutils literal notranslate"><span class="pre">scipy.cluster.hierarchy.linkage()</span></code></dd>
163
<dt>threshold:      The distance threshold. latent factors with similarity below the</dt>
164
<dd>threshold will be merged to form single latent facator</dd>
165
<dt>merge_fn:       A function which will be used to merge latent factors. The default</dt>
166
<dd>is <code class="xref py py-func docutils literal notranslate"><span class="pre">numpy.mean()</span></code>, i.e. the newly formed (merged) latent factor
167
will be the mean of the merged ones. Supply any function here which
168
has the same interface, i.e. takes a matrix and an axis.</dd>
169
<dt>plot_dendro:    Boolean. If True, the function will plot a dendrogram showing</dt>
170
<dd>which latent factors are merged and the threshold.</dd>
171
</dl>
172
</dd></dl>
173
174
<dl class="function">
175
<dt id="maui.utils.multivariate_logrank_test">
176
<code class="descclassname">maui.utils.</code><code class="descname">multivariate_logrank_test</code><span class="sig-paren">(</span><em>y</em>, <em>survival</em>, <em>duration_column='duration'</em>, <em>observed_column='observed'</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/maui/utils.html#multivariate_logrank_test"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#maui.utils.multivariate_logrank_test" title="Permalink to this definition">¶</a></dt>
177
<dd><p>Compute the multivariate log-rank test for differential survival
178
among the groups defined by <code class="docutils literal notranslate"><span class="pre">y</span></code> in the survival data in <code class="docutils literal notranslate"><span class="pre">survival</span></code>,
179
under the null-hypothesis that all groups have the same survival function
180
(i.e. test whether at least one group has different survival rates)</p>
181
<dl class="docutils">
182
<dt>y:                  pd.Series, groups (clusters, subtypes). the index is</dt>
183
<dd>the sample names</dd>
184
<dt>survival:           pd.DataFrame with the same index as y, with columns for</dt>
185
<dd>the duration (survival time for each patient) and whether
186
or not the death was observed. If the death was not
187
observed (sensored), the duration is the time of the last
188
followup.</dd>
189
</dl>
190
<p>duration_column:        the name of the column in  <code class="docutils literal notranslate"><span class="pre">survival</span></code> with the duration
191
observed_column:    the name of the column in <code class="docutils literal notranslate"><span class="pre">survival</span></code> with True/False values</p>
192
<blockquote>
193
<div>for whether death was observed or not</div></blockquote>
194
<p>test_statistic:     the test statistic (chi-square)
195
p_value:            the associated p_value</p>
196
</dd></dl>
197
198
<dl class="function">
199
<dt id="maui.utils.scale">
200
<code class="descclassname">maui.utils.</code><code class="descname">scale</code><span class="sig-paren">(</span><em>df</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/maui/utils.html#scale"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#maui.utils.scale" title="Permalink to this definition">¶</a></dt>
201
<dd><p>Scale and center data</p>
202
<p>df:     pd.DataFrame (n_features, n_samples) non-scaled data</p>
203
<p>scaled: pd.DataFrame (n_features, n_samples) scaled data</p>
204
</dd></dl>
205
206
<dl class="function">
207
<dt id="maui.utils.select_clinical_factors">
208
<code class="descclassname">maui.utils.</code><code class="descname">select_clinical_factors</code><span class="sig-paren">(</span><em>z</em>, <em>survival</em>, <em>duration_column='duration'</em>, <em>observed_column='observed'</em>, <em>alpha=0.05</em>, <em>cox_penalizer=0</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/maui/utils.html#select_clinical_factors"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#maui.utils.select_clinical_factors" title="Permalink to this definition">¶</a></dt>
209
<dd><p>Select latent factors which are predictive of survival. This is
210
accomplished by fitting a Cox Proportional Hazards (CPH) model to each
211
latent factor, while controlling for known covariates, and only keeping
212
those latent factors whose coefficient in the CPH is nonzero (adjusted
213
p-value &lt; alpha).</p>
214
<dl class="docutils">
215
<dt>survival:           pd.DataFrame of survival information and relevant covariates</dt>
216
<dd>(such as sex, age at diagnosis, or tumor stage)</dd>
217
<dt>duration_column:    the name of the column in <code class="docutils literal notranslate"><span class="pre">survival</span></code> containing the</dt>
218
<dd>duration (time between diagnosis and death or last followup)</dd>
219
<dt>observed_column:    the name of the column in <code class="docutils literal notranslate"><span class="pre">survival</span></code> containing</dt>
220
<dd>indicating whether time of death is known</dd>
221
<dt>alpha:              threshold for p-value of CPH coefficients to call a latent</dt>
222
<dd>factor clinically relevant (p &lt; alpha)</dd>
223
</dl>
224
<p>cox_penalizer:      penalty coefficient in Cox PH solver (see <code class="docutils literal notranslate"><span class="pre">lifelines.CoxPHFitter</span></code>)</p>
225
<dl class="docutils">
226
<dt>z_clinical: pd.DataFrame, subset of the latent factors which have been</dt>
227
<dd>determined to have clinical value (are individually predictive
228
of survival, controlling for covariates)</dd>
229
</dl>
230
</dd></dl>
231
232
</div>
233
234
235
          </div>
236
          
237
        </div>
238
      </div>
239
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
240
        <div class="sphinxsidebarwrapper">
241
            <p class="logo"><a href="index.html">
242
              <img class="logo" src="_static/hex-maui.png" alt="Logo"/>
243
            </a></p>
244
<h1 class="logo"><a href="index.html"></a></h1>
245
246
247
248
249
250
251
252
253
<h3>Navigation</h3>
254
<ul class="current">
255
<li class="toctree-l1"><a class="reference internal" href="autoencoder-integration.html">Multi-modal Autoencoders</a></li>
256
<li class="toctree-l1"><a class="reference internal" href="data-normalization.html">Data and Normalization</a></li>
257
<li class="toctree-l1"><a class="reference internal" href="filtering-and-merging-latent-factors.html">Filtering and Merging latent factors</a></li>
258
<li class="toctree-l1"><a class="reference internal" href="maui.html">The Maui Class</a></li>
259
<li class="toctree-l1 current"><a class="current reference internal" href="#">Maui Utilities</a></li>
260
</ul>
261
262
<div class="relations">
263
<h3>Related Topics</h3>
264
<ul>
265
  <li><a href="index.html">Documentation overview</a><ul>
266
      <li>Previous: <a href="maui.html" title="previous chapter">The Maui Class</a></li>
267
  </ul></li>
268
</ul>
269
</div>
270
<div id="searchbox" style="display: none" role="search">
271
  <h3>Quick search</h3>
272
    <div class="searchformwrapper">
273
    <form class="search" action="search.html" method="get">
274
      <input type="text" name="q" />
275
      <input type="submit" value="Go" />
276
      <input type="hidden" name="check_keywords" value="yes" />
277
      <input type="hidden" name="area" value="default" />
278
    </form>
279
    </div>
280
</div>
281
<script type="text/javascript">$('#searchbox').show(0);</script>
282
283
284
285
286
287
288
289
290
        </div>
291
      </div>
292
      <div class="clearer"></div>
293
    </div>
294
    <div class="footer">
295
      &copy;2018, Jonathan Ronen, Altuna Akalin.
296
      
297
      |
298
      Powered by <a href="http://sphinx-doc.org/">Sphinx 1.8.2</a>
299
      &amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.12</a>
300
      
301
      |
302
      <a href="_sources/utils.rst.txt"
303
          rel="nofollow">Page source</a>
304
    </div>
305
306
    
307
308
    
309
  </body>
310
</html>