[9bc947]: / doc / _build / html / utils.html

Download this file

310 lines (263 with data), 19.7 kB

  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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Maui Utilities &#8212; 0.1 documentation</title>
<link rel="stylesheet" href="_static/alabaster.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<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>
<link rel="shortcut icon" href="_static/icons8-beach-30.png"/>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="prev" title="The Maui Class" href="maui.html" />
<link rel="stylesheet" href="_static/custom.css" type="text/css" />
<meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
</head><body>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="module-maui.utils">
<span id="maui-utilities"></span><h1>Maui Utilities<a class="headerlink" href="#module-maui.utils" title="Permalink to this headline"></a></h1>
<p>The maui.utils model contains utility functions for multi-omics analysis
using maui.</p>
<dl class="function">
<dt id="maui.utils.compute_harrells_c">
<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>
<dd><p>Compute’s Harrell’s c-Index for a Cox Proportional Hazards regression modeling
survival by the latent factors in z.</p>
<p>z: pd.DataFrame (n_samples, n_latent factors)
survival: pd.DataFrame of survival information and relevant covariates</p>
<blockquote>
<div>(such as sex, age at diagnosis, or tumor stage)</div></blockquote>
<dl class="docutils">
<dt>duration_column: the name of the column in <code class="docutils literal notranslate"><span class="pre">survival</span></code> containing the</dt>
<dd>duration (time between diagnosis and death or last followup)</dd>
<dt>observed_column: the name of the column in <code class="docutils literal notranslate"><span class="pre">survival</span></code> containing</dt>
<dd>indicating whether time of death is known</dd>
<dt>cox_penalties: penalty coefficient in Cox PH solver (see <code class="docutils literal notranslate"><span class="pre">lifelines.CoxPHFitter</span></code>)</dt>
<dd>to try. Returns the best c given by the different penalties
(by cross-validation)</dd>
</dl>
<p>cv_folds: number of cross-validation folds to compute C</p>
<dl class="docutils">
<dt>cs: array, Harrell’s c-Index, an auc-like metric for survival prediction accuracy.</dt>
<dd>one value per cv_fold</dd>
</dl>
</dd></dl>
<dl class="function">
<dt id="maui.utils.compute_roc">
<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>
<dd><p>Compute the ROC (false positive rate, true positive rate) using cross-validation.</p>
<p>z: DataFrame (n_samples, n_latent_factors) of latent factor values
y: Series (n_samples,) of ground-truth labels to try to predict
classifier: Classifier object to use, default <code class="docutils literal notranslate"><span class="pre">LinearSVC(C=.001)</span></code></p>
<dl class="docutils">
<dt>roc_curves: dict, one key per class as well as “mean”, each value is a dataframe</dt>
<dd>containing the tpr (true positive rate) and fpr (falce positive rate)
defining that class (or the mean) ROC.</dd>
</dl>
</dd></dl>
<dl class="function">
<dt id="maui.utils.correlate_factors_and_features">
<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>
<dd><p>Compute pearson correlation of latent factors with input features.</p>
<p>z: (n_samples, n_factors) DataFrame of latent factor values, output of maui model
concatenated_data: (n_samples, n_features) DataFrame of concatenated multi-omics data</p>
<dl class="docutils">
<dt>feature_s: DataFrame (n_features, n_latent_factors)</dt>
<dd>Latent factors representation of the data X.</dd>
</dl>
</dd></dl>
<dl class="function">
<dt id="maui.utils.estimate_kaplan_meier">
<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>
<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>
<dl class="docutils">
<dt>y: pd.Series, groups (clusters, subtypes). the index is</dt>
<dd>the sample names</dd>
<dt>survival: pd.DataFrame with the same index as y, with columns for</dt>
<dd>the duration (survival time for each patient) and whether
or not the death was observed. If the death was not
observed (sensored), the duration is the time of the last
followup.</dd>
</dl>
<p>duration_column: the name of the column in <code class="docutils literal notranslate"><span class="pre">survival</span></code> with the duration
observed_column: the name of the column in <code class="docutils literal notranslate"><span class="pre">survival</span></code> with True/False values</p>
<blockquote>
<div>for whether death was observed or not</div></blockquote>
<dl class="docutils">
<dt>km_estimates: pd.DataFrame, index is the timeline, columns are survival</dt>
<dd>functions (estimated by Kaplan-Meier) for each class, as
defined in <code class="docutils literal notranslate"><span class="pre">y</span></code>.</dd>
</dl>
</dd></dl>
<dl class="function">
<dt id="maui.utils.filter_factors_by_r2">
<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>
<dd><p>Filter latent factors by the R^2 of a linear model predicting features x
from latent factors z.</p>
<p>z: (n_samples, n_factors) DataFrame of latent factor values, output of a maui model
x: (n_samples, n_features) DataFrame of concatenated multi-omics data</p>
<dl class="docutils">
<dt>z_filtered: (n_samples, n_factors) DataFrame of latent factor values,</dt>
<dd>with only those columns from the input <cite>z</cite> which have an R^2
above the threshold when using that column as an input
to a linear model predicting <cite>x</cite>.</dd>
</dl>
</dd></dl>
<dl class="function">
<dt id="maui.utils.map_factors_to_feaures_using_linear_models">
<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>
<dd><p>Get feature &lt;-&gt; latent factors mapping from linear models.
Runs one univariate (multi-output) linear model per latent factor in <cite>z</cite>,
predicting the values of the features <cite>x</cite>, in order to get weights
between inputs and outputs.</p>
<p>z: (n_samples, n_factors) DataFrame of latent factor values, output of a maui model
x: (n_samples, n_features) DataFrame of concatenated multi-omics data</p>
<dl class="docutils">
<dt>W: (n_features, n_latent_factors) DataFrame</dt>
<dd>w_{ij} is the coefficient associated with feature <cite>i</cite> in a linear model
predicting it from latent factor <cite>j</cite>.</dd>
</dl>
</dd></dl>
<dl class="function">
<dt id="maui.utils.merge_factors">
<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>
<dd><p>Merge latent factors in <cite>z</cite> which form clusters, as defined by hierarchical
clustering where a cluster is formed by cutting at a pre-set threshold, i.e.
merge factors if their distance to one-another is below <cite>threshold</cite>.</p>
<p>z: (n_samples, n_factors) DataFrame of latent factor values, output of a maui model
metric: Distance metric to merge factors by, one which is supported by</p>
<blockquote>
<div><code class="xref py py-func docutils literal notranslate"><span class="pre">scipy.spatial.distance.pdist()</span></code></div></blockquote>
<dl class="docutils">
<dt>linkage: The kind of linkage to form hierarchical clustering, one which is</dt>
<dd>supported by <code class="xref py py-func docutils literal notranslate"><span class="pre">scipy.cluster.hierarchy.linkage()</span></code></dd>
<dt>l: As an alternative to supplying <cite>metric</cite> and <cite>linkage</cite>, supply a</dt>
<dd>linkage matrix of your own choice, such as one computed by
<code class="xref py py-func docutils literal notranslate"><span class="pre">scipy.cluster.hierarchy.linkage()</span></code></dd>
<dt>threshold: The distance threshold. latent factors with similarity below the</dt>
<dd>threshold will be merged to form single latent facator</dd>
<dt>merge_fn: A function which will be used to merge latent factors. The default</dt>
<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
will be the mean of the merged ones. Supply any function here which
has the same interface, i.e. takes a matrix and an axis.</dd>
<dt>plot_dendro: Boolean. If True, the function will plot a dendrogram showing</dt>
<dd>which latent factors are merged and the threshold.</dd>
</dl>
</dd></dl>
<dl class="function">
<dt id="maui.utils.multivariate_logrank_test">
<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>
<dd><p>Compute the multivariate log-rank test for differential survival
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>,
under the null-hypothesis that all groups have the same survival function
(i.e. test whether at least one group has different survival rates)</p>
<dl class="docutils">
<dt>y: pd.Series, groups (clusters, subtypes). the index is</dt>
<dd>the sample names</dd>
<dt>survival: pd.DataFrame with the same index as y, with columns for</dt>
<dd>the duration (survival time for each patient) and whether
or not the death was observed. If the death was not
observed (sensored), the duration is the time of the last
followup.</dd>
</dl>
<p>duration_column: the name of the column in <code class="docutils literal notranslate"><span class="pre">survival</span></code> with the duration
observed_column: the name of the column in <code class="docutils literal notranslate"><span class="pre">survival</span></code> with True/False values</p>
<blockquote>
<div>for whether death was observed or not</div></blockquote>
<p>test_statistic: the test statistic (chi-square)
p_value: the associated p_value</p>
</dd></dl>
<dl class="function">
<dt id="maui.utils.scale">
<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>
<dd><p>Scale and center data</p>
<p>df: pd.DataFrame (n_features, n_samples) non-scaled data</p>
<p>scaled: pd.DataFrame (n_features, n_samples) scaled data</p>
</dd></dl>
<dl class="function">
<dt id="maui.utils.select_clinical_factors">
<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>
<dd><p>Select latent factors which are predictive of survival. This is
accomplished by fitting a Cox Proportional Hazards (CPH) model to each
latent factor, while controlling for known covariates, and only keeping
those latent factors whose coefficient in the CPH is nonzero (adjusted
p-value &lt; alpha).</p>
<dl class="docutils">
<dt>survival: pd.DataFrame of survival information and relevant covariates</dt>
<dd>(such as sex, age at diagnosis, or tumor stage)</dd>
<dt>duration_column: the name of the column in <code class="docutils literal notranslate"><span class="pre">survival</span></code> containing the</dt>
<dd>duration (time between diagnosis and death or last followup)</dd>
<dt>observed_column: the name of the column in <code class="docutils literal notranslate"><span class="pre">survival</span></code> containing</dt>
<dd>indicating whether time of death is known</dd>
<dt>alpha: threshold for p-value of CPH coefficients to call a latent</dt>
<dd>factor clinically relevant (p &lt; alpha)</dd>
</dl>
<p>cox_penalizer: penalty coefficient in Cox PH solver (see <code class="docutils literal notranslate"><span class="pre">lifelines.CoxPHFitter</span></code>)</p>
<dl class="docutils">
<dt>z_clinical: pd.DataFrame, subset of the latent factors which have been</dt>
<dd>determined to have clinical value (are individually predictive
of survival, controlling for covariates)</dd>
</dl>
</dd></dl>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<p class="logo"><a href="index.html">
<img class="logo" src="_static/hex-maui.png" alt="Logo"/>
</a></p>
<h1 class="logo"><a href="index.html"></a></h1>
<h3>Navigation</h3>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="autoencoder-integration.html">Multi-modal Autoencoders</a></li>
<li class="toctree-l1"><a class="reference internal" href="data-normalization.html">Data and Normalization</a></li>
<li class="toctree-l1"><a class="reference internal" href="filtering-and-merging-latent-factors.html">Filtering and Merging latent factors</a></li>
<li class="toctree-l1"><a class="reference internal" href="maui.html">The Maui Class</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Maui Utilities</a></li>
</ul>
<div class="relations">
<h3>Related Topics</h3>
<ul>
<li><a href="index.html">Documentation overview</a><ul>
<li>Previous: <a href="maui.html" title="previous chapter">The Maui Class</a></li>
</ul></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="footer">
&copy;2018, Jonathan Ronen, Altuna Akalin.
|
Powered by <a href="http://sphinx-doc.org/">Sphinx 1.8.2</a>
&amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.12</a>
|
<a href="_sources/utils.rst.txt"
rel="nofollow">Page source</a>
</div>
</body>
</html>