-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimpact_anlaysis.html
More file actions
582 lines (543 loc) · 33.8 KB
/
impact_anlaysis.html
File metadata and controls
582 lines (543 loc) · 33.8 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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta http-equiv="X-UA-Compatible" content="IE=EDGE" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Classifying MSK-IMPACT tumors using Projected hidden genome multinomial logistic classifier</title>
<script>// Hide empty <a> tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) -->
// v0.0.1
// Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020.
document.addEventListener('DOMContentLoaded', function() {
const codeList = document.getElementsByClassName("sourceCode");
for (var i = 0; i < codeList.length; i++) {
var linkList = codeList[i].getElementsByTagName('a');
for (var j = 0; j < linkList.length; j++) {
if (linkList[j].innerHTML === "") {
linkList[j].setAttribute('aria-hidden', 'true');
}
}
}
});
</script>
<style type="text/css">
a.anchor-section {margin-left: 10px; visibility: hidden; color: inherit;}
a.anchor-section::before {content: '#';}
.hasAnchor:hover a.anchor-section {visibility: visible;}
</style>
<script>// Anchor sections v1.0 written by Atsushi Yasumoto on Oct 3rd, 2020.
document.addEventListener('DOMContentLoaded', function() {
// Do nothing if AnchorJS is used
if (typeof window.anchors === 'object' && anchors.hasOwnProperty('hasAnchorJSLink')) {
return;
}
const h = document.querySelectorAll('h1, h2, h3, h4, h5, h6');
// Do nothing if sections are already anchored
if (Array.from(h).some(x => x.classList.contains('hasAnchor'))) {
return null;
}
// Use section id when pandoc runs with --section-divs
const section_id = function(x) {
return ((x.classList.contains('section') || (x.tagName === 'SECTION'))
? x.id : '');
};
// Add anchors
h.forEach(function(x) {
const id = x.id || section_id(x.parentElement);
if (id === '') {
return null;
}
let anchor = document.createElement('a');
anchor.href = '#' + id;
anchor.classList = ['anchor-section'];
x.classList.add('hasAnchor');
x.appendChild(anchor);
});
});
</script>
<style type="text/css">
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
</style>
<style type="text/css">code{white-space: pre;}</style>
<style type="text/css" data-origin="pandoc">
code.sourceCode > span { display: inline-block; line-height: 1.25; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode { white-space: pre; position: relative; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
code.sourceCode { white-space: pre-wrap; }
code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
</style>
<script>
// apply pandoc div.sourceCode style to pre.sourceCode instead
(function() {
var sheets = document.styleSheets;
for (var i = 0; i < sheets.length; i++) {
if (sheets[i].ownerNode.dataset["origin"] !== "pandoc") continue;
try { var rules = sheets[i].cssRules; } catch (e) { continue; }
for (var j = 0; j < rules.length; j++) {
var rule = rules[j];
// check if there is a div.sourceCode rule
if (rule.type !== rule.STYLE_RULE || rule.selectorText !== "div.sourceCode") continue;
var style = rule.style.cssText;
// check if color or background-color is set
if (rule.style.color === '' && rule.style.backgroundColor === '') continue;
// replace div.sourceCode by a pre.sourceCode rule
sheets[i].deleteRule(j);
sheets[i].insertRule('pre.sourceCode{' + style + '}', j);
}
}
})();
</script>
<style type="text/css">body {
background-color: #fff;
margin: 1em auto;
max-width: 700px;
overflow: visible;
padding-left: 2em;
padding-right: 2em;
font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
line-height: 1.35;
}
#TOC {
clear: both;
margin: 0 0 10px 10px;
padding: 4px;
width: 400px;
border: 1px solid #CCCCCC;
border-radius: 5px;
background-color: #f6f6f6;
font-size: 13px;
line-height: 1.3;
}
#TOC .toctitle {
font-weight: bold;
font-size: 15px;
margin-left: 5px;
}
#TOC ul {
padding-left: 40px;
margin-left: -1.5em;
margin-top: 5px;
margin-bottom: 5px;
}
#TOC ul ul {
margin-left: -2em;
}
#TOC li {
line-height: 16px;
}
table {
margin: 1em auto;
border-width: 1px;
border-color: #DDDDDD;
border-style: outset;
border-collapse: collapse;
}
table th {
border-width: 2px;
padding: 5px;
border-style: inset;
}
table td {
border-width: 1px;
border-style: inset;
line-height: 18px;
padding: 5px 5px;
}
table, table th, table td {
border-left-style: none;
border-right-style: none;
}
table thead, table tr.even {
background-color: #f7f7f7;
}
p {
margin: 0.5em 0;
}
blockquote {
background-color: #f6f6f6;
padding: 0.25em 0.75em;
}
hr {
border-style: solid;
border: none;
border-top: 1px solid #777;
margin: 28px 0;
}
dl {
margin-left: 0;
}
dl dd {
margin-bottom: 13px;
margin-left: 13px;
}
dl dt {
font-weight: bold;
}
ul {
margin-top: 0;
}
ul li {
list-style: circle outside;
}
ul ul {
margin-bottom: 0;
}
pre, code {
background-color: #f7f7f7;
border-radius: 3px;
color: #333;
white-space: pre-wrap;
}
pre {
border-radius: 3px;
margin: 5px 0px 10px 0px;
padding: 10px;
}
pre:not([class]) {
background-color: #f7f7f7;
}
code {
font-family: Consolas, Monaco, 'Courier New', monospace;
font-size: 85%;
}
p > code, li > code {
padding: 2px 0px;
}
div.figure {
text-align: center;
}
img {
background-color: #FFFFFF;
padding: 2px;
border: 1px solid #DDDDDD;
border-radius: 3px;
border: 1px solid #CCCCCC;
margin: 0 5px;
}
h1 {
margin-top: 0;
font-size: 35px;
line-height: 40px;
}
h2 {
border-bottom: 4px solid #f7f7f7;
padding-top: 10px;
padding-bottom: 2px;
font-size: 145%;
}
h3 {
border-bottom: 2px solid #f7f7f7;
padding-top: 10px;
font-size: 120%;
}
h4 {
border-bottom: 1px solid #f7f7f7;
margin-left: 8px;
font-size: 105%;
}
h5, h6 {
border-bottom: 1px solid #ccc;
font-size: 105%;
}
a {
color: #0033dd;
text-decoration: none;
}
a:hover {
color: #6666ff; }
a:visited {
color: #800080; }
a:visited:hover {
color: #BB00BB; }
a[href^="http:"] {
text-decoration: underline; }
a[href^="https:"] {
text-decoration: underline; }
code > span.kw { color: #555; font-weight: bold; }
code > span.dt { color: #902000; }
code > span.dv { color: #40a070; }
code > span.bn { color: #d14; }
code > span.fl { color: #d14; }
code > span.ch { color: #d14; }
code > span.st { color: #d14; }
code > span.co { color: #888888; font-style: italic; }
code > span.ot { color: #007020; }
code > span.al { color: #ff0000; font-weight: bold; }
code > span.fu { color: #900; font-weight: bold; }
code > span.er { color: #a61717; background-color: #e3d2d2; }
</style>
</head>
<body>
<h1 class="title toc-ignore">Classifying MSK-IMPACT tumors using Projected hidden genome multinomial logistic classifier</h1>
<p>In this vignette, we illustrate how to train a hidden genome (multinomial logistic) classifier on MSK-IMPACT tumors from 10 cancer sites using the R package <code>hidgenclassifier</code>.</p>
<div id="load-packages-and-import-data" class="section level2">
<h2>Load packages and import data</h2>
<p>We start by setting a seed, loading the <code>hidgenclassifier</code> and <code>magrittr</code> packages (the latter being used for its pipe <code>%>%</code> operator), and importing the <code>impact</code> data from <code>hidgenclassifier</code>.</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb1-1"><a href="#cb1-1"></a><span class="kw">set.seed</span>(<span class="dv">42</span>)</span>
<span id="cb1-2"><a href="#cb1-2"></a><span class="kw">library</span>(magrittr)</span>
<span id="cb1-3"><a href="#cb1-3"></a><span class="kw">library</span>(hidgenclassifier)</span>
<span id="cb1-4"><a href="#cb1-4"></a><span class="kw">data</span>(<span class="st">"impact"</span>)</span></code></pre></div>
<p>The impact mutation annotation dataset (stored as a <code>data.table</code> object) looks like the following:</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb2-1"><a href="#cb2-1"></a>impact</span></code></pre></div>
<pre><code>## Hugo_Symbol Chromosome Start_Position End_Position Tumor_Seq_Allele1
## 1: SPEN 1 16265908 16265908 A
## 2: ALK 2 29543736 29543736 A
## 3: PDCD1 2 242793433 242793433 G
## 4: MAP3K1 5 56177843 56177843 C
## 5: FLT4 5 180030313 180030313 C
## ---
## 33297: ERG 21 39755527 39755527 G
## 33298: EP300 22 41556670 41556670 C
## 33299: EP300 22 41574114 41574114 G
## 33300: EP300 22 41574549 41574549 G
## 33301: KDM6A X 44911027 44911027 C
## Tumor_Seq_Allele2 Reference_Allele patient_id HGVSp_Short
## 1: T A P-0000004-T01-IM3 p.I3661F
## 2: G A P-0000004-T01-IM3 p.V476A
## 3: A G P-0000004-T01-IM3 p.A215V
## 4: G C P-0000004-T01-IM3 p.S939C
## 5: A C P-0000004-T01-IM3 p.R1324L
## ---
## 33297: A G P-0002756-T03-IM5 p.S420L
## 33298: G C P-0002756-T03-IM5 p.F1205L
## 33299: A G P-0002756-T03-IM5 p.M2133I
## 33300: T G P-0002756-T03-IM5 p.M2278I
## 33301: T C P-0002756-T03-IM5 p.A243V
## Variant_Type Variant_Classification CANCER_SITE
## 1: SNP Missense_Mutation BREAST
## 2: SNP Missense_Mutation BREAST
## 3: SNP Missense_Mutation BREAST
## 4: SNP Missense_Mutation BREAST
## 5: SNP Missense_Mutation BREAST
## ---
## 33297: SNP Missense_Mutation BREAST
## 33298: SNP Missense_Mutation BREAST
## 33299: SNP Missense_Mutation BREAST
## 33300: SNP Missense_Mutation BREAST
## 33301: SNP Missense_Mutation BREAST
## CANCER_HISTOLOGY
## 1: Breast Invasive Ductal Carcinoma
## 2: Breast Invasive Ductal Carcinoma
## 3: Breast Invasive Ductal Carcinoma
## 4: Breast Invasive Ductal Carcinoma
## 5: Breast Invasive Ductal Carcinoma
## ---
## 33297: Breast Invasive Ductal Carcinoma
## 33298: Breast Invasive Ductal Carcinoma
## 33299: Breast Invasive Ductal Carcinoma
## 33300: Breast Invasive Ductal Carcinoma
## 33301: Breast Invasive Ductal Carcinoma
## Variant
## 1: Variant__SPEN__p.I3661F__1__16265908__A__T
## 2: Variant__ALK__p.V476A__2__29543736__A__G
## 3: Variant__PDCD1__p.A215V__2__242793433__G__A
## 4: Variant__MAP3K1__p.S939C__5__56177843__C__G
## 5: Variant__FLT4__p.R1324L__5__180030313__C__A
## ---
## 33297: Variant__ERG__p.S420L__21__39755527__G__A
## 33298: Variant__EP300__p.F1205L__22__41556670__C__G
## 33299: Variant__EP300__p.M2133I__22__41574114__G__A
## 33300: Variant__EP300__p.M2278I__22__41574549__G__T
## 33301: Variant__KDM6A__p.A243V__X__44911027__C__T</code></pre>
<p>The dataset consists of 33301 rows and 14 columns and catalogs somatic mutations (column “Variant”) detected at 414 targeted cancer genes across 5078 tumors from 10 cancer sites. The cancer sites are listed in the column “CANCER_SITE”:</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb4-1"><a href="#cb4-1"></a><span class="kw">unique</span>(impact<span class="op">$</span>CANCER_SITE)</span></code></pre></div>
<pre><code>## [1] "BREAST" "LIVER" "OVARIAN" "ESOPHAGEAL" "LUNG"
## [6] "COLORECTAL" "PANCREATIC" "PROSTATE" "KIDNEY" "SKIN"</code></pre>
<p>The sample/patient ids of tumors are listed in the column “patient_id”. Enter <code>?impact</code> in the R console to see more details on the dataset. We want to train a hidden genome (multinomial logistic) classifier with the above 10 cancer sites (response classes) using the variants listed in column “Variant” as predictor while simultaneously utilizing the meta-features gene (column “Hugo_Symbol”) and 96 Single Base Substitution (SBS-96) categories.</p>
</div>
<div id="training-a-hidden-genome-classifier" class="section level2">
<h2>Training a hidden genome classifier</h2>
<div id="pre-processing-and-computing-the-predictor-matrix" class="section level3">
<h3>Pre-processing and computing the predictor matrix</h3>
<p>We first extract the response cancer classes, labeled by the patient (tumor) ids in the <code>impact</code> dataset, which we store in the variable <code>pid</code>.</p>
<div class="sourceCode" id="cb6"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb6-1"><a href="#cb6-1"></a>canc_resp <-<span class="st"> </span><span class="kw">extract_cancer_response</span>(</span>
<span id="cb6-2"><a href="#cb6-2"></a> <span class="dt">maf =</span> impact,</span>
<span id="cb6-3"><a href="#cb6-3"></a> <span class="dt">cancer_col =</span> <span class="st">"CANCER_SITE"</span>,</span>
<span id="cb6-4"><a href="#cb6-4"></a> <span class="dt">sample_id_col =</span> <span class="st">"patient_id"</span></span>
<span id="cb6-5"><a href="#cb6-5"></a>)</span>
<span id="cb6-6"><a href="#cb6-6"></a>pid <-<span class="st"> </span><span class="kw">names</span>(canc_resp)</span></code></pre></div>
<p>To train the model, we first split the dataset into 5 stratified random folds, based the cancer categories. Then we define our training set by combining four out of the five folds, and use the remaining fifth fold as our test set.</p>
<div class="sourceCode" id="cb7"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb7-1"><a href="#cb7-1"></a><span class="kw">set.seed</span>(<span class="dv">42</span>)</span>
<span id="cb7-2"><a href="#cb7-2"></a>folds <-<span class="st"> </span>data.table<span class="op">::</span><span class="kw">data.table</span>(</span>
<span id="cb7-3"><a href="#cb7-3"></a> <span class="dt">resp =</span> canc_resp</span>
<span id="cb7-4"><a href="#cb7-4"></a>)[,</span>
<span id="cb7-5"><a href="#cb7-5"></a> foldid <span class="op">:</span><span class="er">=</span><span class="st"> </span><span class="kw">sample</span>(<span class="kw">rep</span>(<span class="dv">1</span><span class="op">:</span><span class="dv">5</span>, <span class="dt">length.out =</span> .N)),</span>
<span id="cb7-6"><a href="#cb7-6"></a> by =<span class="st"> </span>resp</span>
<span id="cb7-7"><a href="#cb7-7"></a>]<span class="op">$</span>foldid</span>
<span id="cb7-8"><a href="#cb7-8"></a></span>
<span id="cb7-9"><a href="#cb7-9"></a><span class="co"># 80%-20% stratified separation of training and</span></span>
<span id="cb7-10"><a href="#cb7-10"></a><span class="co"># test set tumors</span></span>
<span id="cb7-11"><a href="#cb7-11"></a>pid_train <-<span class="st"> </span>pid[folds <span class="op">!=</span><span class="st"> </span><span class="dv">5</span>]</span>
<span id="cb7-12"><a href="#cb7-12"></a>pid_test <-<span class="st"> </span>pid[folds <span class="op">==</span><span class="st"> </span><span class="dv">5</span>]</span></code></pre></div>
<p>To fit a hidden genome classifier, we need to (a) obtain the variant design matrix (X), (b) compute the meta-feature product design-meta-design matrices (XU), (c) column-bind these X and XU matrices, and (d) normalize each row of the resulting column-bound matrix by the square-root of the total mutation burden observed in that tumor (row). Note that because the XU matrix combines/condenses information from all variants (including less informative rare individual variants), given XU we can filter out the less informative/discriminative columns from X. That is, we can do a <em>feature screening</em> of the columns of X before using it as predictor in the hidden genome model, after we have computed XU.</p>
<p>A mutual information (MI) based feature screening is implemented within the function <code>screen_variant_mi</code>, which we now use to get the most discriminative variants with MI rank <span class="math inline">\(\leq\)</span> 250 (stored in the variable <code>top_v</code> in the following). Note that the screening must be done on the <em>training set</em>, which is ensured by subsetting the impact data to rows corresponding to <code>patient_id %in% pid_train</code> while the maf file <code>impact</code> passing into <code>screen_variant_mi</code>:</p>
<div class="sourceCode" id="cb8"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb8-1"><a href="#cb8-1"></a>top_v <-<span class="st"> </span><span class="kw">variant_screen_mi</span>(</span>
<span id="cb8-2"><a href="#cb8-2"></a> <span class="dt">maf =</span> impact[patient_id <span class="op">%in%</span><span class="st"> </span>pid_train],</span>
<span id="cb8-3"><a href="#cb8-3"></a> <span class="dt">variant_col =</span> <span class="st">"Variant"</span>,</span>
<span id="cb8-4"><a href="#cb8-4"></a> <span class="dt">cancer_col =</span> <span class="st">"CANCER_SITE"</span>,</span>
<span id="cb8-5"><a href="#cb8-5"></a> <span class="dt">sample_id_col =</span> <span class="st">"patient_id"</span>,</span>
<span id="cb8-6"><a href="#cb8-6"></a> <span class="dt">mi_rank_thresh =</span> <span class="dv">250</span>,</span>
<span id="cb8-7"><a href="#cb8-7"></a> <span class="dt">return_prob_mi =</span> <span class="ot">FALSE</span>,</span>
<span id="cb8-8"><a href="#cb8-8"></a> <span class="dt">do_freq_screen =</span> <span class="ot">FALSE</span></span>
<span id="cb8-9"><a href="#cb8-9"></a>)</span></code></pre></div>
<p>Note that by default <code>do_freq_screen</code> is set to <code>FALSE</code>; if <code>do_freq_screen = TRUE</code>, then an overall (relative) frequency-based screening is performed <em>prior to</em> MI based screening. This may reduce the computation load substantially for whole genome datasets where potentially tens of millions of variants, each with little individual discriminative information, are observed only once. The relative frequence threshold can be set by <code>thresh_freq_screen</code> (defaults to 1/n_sample where n_sample is the pan-cancer total number of tumors.)</p>
<p>With the most discriminative variants determined and stored in <code>top_v</code>, we now extract the variant design matrix X restricted to the variants in <code>top_v</code> and for <em>all tumors</em>. (The matrix will be row-subsetted to <code>pid_train</code> during training; the remaining rows will be used for prediction):</p>
<div class="sourceCode" id="cb9"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb9-1"><a href="#cb9-1"></a>X_variant <-<span class="st"> </span><span class="kw">extract_design</span>(</span>
<span id="cb9-2"><a href="#cb9-2"></a> <span class="dt">maf =</span> impact,</span>
<span id="cb9-3"><a href="#cb9-3"></a> <span class="dt">variant_col =</span> <span class="st">"Variant"</span>,</span>
<span id="cb9-4"><a href="#cb9-4"></a> <span class="dt">sample_id_col =</span> <span class="st">"patient_id"</span>,</span>
<span id="cb9-5"><a href="#cb9-5"></a> <span class="dt">variant_subset =</span> top_v</span>
<span id="cb9-6"><a href="#cb9-6"></a>)</span>
<span id="cb9-7"><a href="#cb9-7"></a><span class="kw">dim</span>(X_variant)</span></code></pre></div>
<pre><code>## [1] 5078 306</code></pre>
<p>Next we compute the XU matrix (for all tumors) for the meta-feature gene. This can be obtained via the function <code>extract_design_mdesign_mcat</code>, by specifying the meta-feature column to be “Hugo_Symbol”:</p>
<div class="sourceCode" id="cb11"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb11-1"><a href="#cb11-1"></a>XU_gene <-<span class="st"> </span><span class="kw">extract_design_mdesign_mcat</span>(</span>
<span id="cb11-2"><a href="#cb11-2"></a> <span class="dt">maf =</span> impact,</span>
<span id="cb11-3"><a href="#cb11-3"></a> <span class="dt">variant_col =</span> <span class="st">"Variant"</span>,</span>
<span id="cb11-4"><a href="#cb11-4"></a> <span class="dt">mfeat_col =</span> <span class="st">"Hugo_Symbol"</span>,</span>
<span id="cb11-5"><a href="#cb11-5"></a> <span class="dt">sample_id_col =</span> <span class="st">"patient_id"</span>,</span>
<span id="cb11-6"><a href="#cb11-6"></a> <span class="dt">mfeat_subset =</span> <span class="ot">NULL</span></span>
<span id="cb11-7"><a href="#cb11-7"></a>) <span class="op">%>%</span><span class="st"> </span></span>
<span id="cb11-8"><a href="#cb11-8"></a><span class="st"> </span>magrittr<span class="op">::</span><span class="kw">set_colnames</span>(</span>
<span id="cb11-9"><a href="#cb11-9"></a> <span class="kw">paste</span>(<span class="st">"Gene_"</span>, <span class="kw">colnames</span>(.))</span>
<span id="cb11-10"><a href="#cb11-10"></a> )</span>
<span id="cb11-11"><a href="#cb11-11"></a><span class="kw">dim</span>(XU_gene)</span></code></pre></div>
<pre><code>## [1] 5078 414</code></pre>
<p>(the column names are appended by the prefix “Gene_” for easier identification of predictors in the fitted models). Note that by supplying an appropriate (non-<code>NULL</code>) <code>mfeat_subset</code>, the computation in <code>extract_design_mdesign_mcat</code> can be restricted to a specific subset of genes. This is useful when analyzing whole-exome and whole-genome datasets.</p>
<p>Now we compute the XU matrix for the SBS-96 meta-feature. This is done by supplying various nucleotide change specific columns from the maf file (<code>impact</code>) to the function <code>extract_design_mdesign_sbs96</code>.</p>
<div class="sourceCode" id="cb13"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb13-1"><a href="#cb13-1"></a>XU_sbs96 <-<span class="st"> </span><span class="kw">extract_design_mdesign_sbs96</span>(</span>
<span id="cb13-2"><a href="#cb13-2"></a> <span class="dt">maf =</span> impact,</span>
<span id="cb13-3"><a href="#cb13-3"></a> <span class="dt">chromosome_col =</span> <span class="st">"Chromosome"</span>,</span>
<span id="cb13-4"><a href="#cb13-4"></a> <span class="dt">start_position_col =</span> <span class="st">"Start_Position"</span>,</span>
<span id="cb13-5"><a href="#cb13-5"></a> <span class="dt">end_position_col =</span> <span class="st">"End_Position"</span>,</span>
<span id="cb13-6"><a href="#cb13-6"></a> <span class="dt">ref_col =</span> <span class="st">"Reference_Allele"</span>,</span>
<span id="cb13-7"><a href="#cb13-7"></a> <span class="dt">alt_col =</span> <span class="st">"Tumor_Seq_Allele2"</span>,</span>
<span id="cb13-8"><a href="#cb13-8"></a> <span class="dt">sample_id_col =</span> <span class="st">"patient_id"</span></span>
<span id="cb13-9"><a href="#cb13-9"></a>) <span class="op">%>%</span><span class="st"> </span></span>
<span id="cb13-10"><a href="#cb13-10"></a><span class="st"> </span>magrittr<span class="op">::</span><span class="kw">set_colnames</span>(</span>
<span id="cb13-11"><a href="#cb13-11"></a> <span class="kw">paste</span>(<span class="st">"SBS_"</span>, <span class="kw">colnames</span>(.))</span>
<span id="cb13-12"><a href="#cb13-12"></a> )</span>
<span id="cb13-13"><a href="#cb13-13"></a><span class="kw">dim</span>(XU_sbs96)</span></code></pre></div>
<pre><code>## [1] 5078 96</code></pre>
<p>(the column names are appended by the prefix “SBS_” for easier identification of predictors in the fitted models). Note that the function <code>extract_design_mdesign_sbs96</code> calls various functions from <code>SomaticSignatures</code> and other Bioconductor packages under the hood, which uses various genomic datasets, and also overwrites a few default S3 methods. If overwriting of these functions (see above) is a concern, we recommend computing <code>XU_sbs96</code> in a non-interactive R session and saving the result as an R data object (using, say, <code>saveRDS</code>), or refreshing the R session after computing the above matrix in an interactive R session.</p>
<p>Finally, we compute the total mutation burden per tumor, labeled by tumor (patient) ids, using the function <code>extract_tmb</code>:</p>
<div class="sourceCode" id="cb15"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb15-1"><a href="#cb15-1"></a>tmb <-<span class="st"> </span><span class="kw">extract_tmb</span>(</span>
<span id="cb15-2"><a href="#cb15-2"></a> <span class="dt">maf =</span> impact,</span>
<span id="cb15-3"><a href="#cb15-3"></a> <span class="dt">variant_col =</span> <span class="st">"Variant"</span>,</span>
<span id="cb15-4"><a href="#cb15-4"></a> <span class="dt">sample_id_col =</span> <span class="st">"patient_id"</span></span>
<span id="cb15-5"><a href="#cb15-5"></a>)</span></code></pre></div>
<p>We are now in a position to create the predictor matrix for the hidden genome model, by column-binding all X and XU matrices, and subsequently normalizing the rows of the column-bound matrix by the square-root of the total mutation burdens in the tumor; the resulting entries correspond to various scalar projections as described in the manuscript. We use the convenience function <code>divide_rows</code> for this normalization inside a chained (using <code>magrittr</code> pipe) computation steps.</p>
<div class="sourceCode" id="cb16"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb16-1"><a href="#cb16-1"></a>predictor_mat <-<span class="st"> </span><span class="kw">cbind</span>(</span>
<span id="cb16-2"><a href="#cb16-2"></a> X_variant[pid, ],</span>
<span id="cb16-3"><a href="#cb16-3"></a> XU_gene[pid, ],</span>
<span id="cb16-4"><a href="#cb16-4"></a> XU_sbs96[pid, ],</span>
<span id="cb16-5"><a href="#cb16-5"></a> <span class="dt">tmb =</span> tmb[pid]</span>
<span id="cb16-6"><a href="#cb16-6"></a>) <span class="op">%>%</span><span class="st"> </span></span>
<span id="cb16-7"><a href="#cb16-7"></a><span class="st"> </span><span class="kw">divide_rows</span>(<span class="kw">sqrt</span>(tmb[pid]))</span></code></pre></div>
<p>(Note that the <code>tmb</code> corresponds to the column of <code>XU</code> associated with an “intercept” meta-feature of all 1’s.) The resulting <code>predictor_mat</code> will be used as the predictor matrix in the hidden genome model.</p>
</div>
<div id="fitting-the-mutlinomial-logistic-hidden-genome-classifier" class="section level3">
<h3>Fitting the mutlinomial logistic hidden genome classifier</h3>
<p>We use the function <code>fit_mlogit</code> to fit a hidden genome multinomial logistic classifier with <code>predictor_mat</code> as the predictor matrix, and <code>canc_resp</code> as the response cancer classes. The fitting is restricted to the training set tumors <code>pid_train</code>. The function takes a while to compute (took about ~30 minutes on a Windows 10 computer with 16GB RAM, 4 cores), so we recommend saving the result into a file once the function stops. Enter <code>?fit_mlogit</code> in the R console to see a detailed description of the arguments of <code>fit_mlogit</code>.</p>
<div class="sourceCode" id="cb17"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb17-1"><a href="#cb17-1"></a>fit_impact <-<span class="st"> </span><span class="kw">fit_mlogit</span>(</span>
<span id="cb17-2"><a href="#cb17-2"></a> <span class="dt">X =</span> predictor_mat[pid_train, ],</span>
<span id="cb17-3"><a href="#cb17-3"></a> <span class="dt">Y =</span> canc_resp[pid_train]</span>
<span id="cb17-4"><a href="#cb17-4"></a>)</span></code></pre></div>
</div>
</div>
<div id="predicting-cancer-sites-based-on-a-fitted-hidden-genome-model" class="section level2">
<h2>Predicting cancer sites based on a fitted hidden genome model</h2>
<p>To predict cancer sites of the test set tumors based on the above fitted hidden genome model, we simply use the function <code>predict_mlogit</code>:</p>
<div class="sourceCode" id="cb18"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb18-1"><a href="#cb18-1"></a>pred_impact <-<span class="st"> </span><span class="kw">predict_mlogit</span>(</span>
<span id="cb18-2"><a href="#cb18-2"></a> <span class="dt">fit =</span> fit_impact,</span>
<span id="cb18-3"><a href="#cb18-3"></a> <span class="dt">Xnew =</span> predictor_mat[pid_test, ]</span>
<span id="cb18-4"><a href="#cb18-4"></a>)</span></code></pre></div>
<p>This creates a list with entries (a) <code>probs_predicted</code>: a n_test_tumor by n_cancer matrix of multinomial probabilities, providing the predicted probability of each test set tumor being classified into each cancer site, and (b) <code>predicted</code> : a character vector listing hard classes based on the predicted multinomial probabilities (obtained by assigning tumors to the classes with the highest predicted probabilities).</p>
</div>
<div id="understanding-predictor-effects-via-one-vs-rest-odds-ratios" class="section level2">
<h2>Understanding predictor effects via one-vs-rest odds ratios</h2>
<p>Rigorous quantification of individual predictor effects can be obtained through odds-ratios from a fitted multinomial logistic regression model. We consider one-vs-rest odds ratio of a tumor being classified into a specific cancer category, relative to not being classified into that category, for one standard deviation change in each predictor from its mean, while keeping all other predictors fixed at their respective means. This can be obtained using the function <code>odds_ratio_mlogit</code>:</p>
<div class="sourceCode" id="cb19"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb19-1"><a href="#cb19-1"></a>or <-<span class="st"> </span><span class="kw">odds_ratio_mlogit</span>(</span>
<span id="cb19-2"><a href="#cb19-2"></a> <span class="dt">fit =</span> fit_impact,</span>
<span id="cb19-3"><a href="#cb19-3"></a> <span class="dt">type =</span> <span class="st">"one-vs-rest"</span>,</span>
<span id="cb19-4"><a href="#cb19-4"></a> <span class="dt">log =</span> <span class="ot">TRUE</span></span>
<span id="cb19-5"><a href="#cb19-5"></a>)</span></code></pre></div>
<p>Note that odds ratios are computed by default in a log scale.</p>
</div>
<!-- code folding -->
<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
(function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
document.getElementsByTagName("head")[0].appendChild(script);
})();
</script>
</body>
</html>