-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmethods.html
1956 lines (1917 loc) · 278 KB
/
methods.html
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
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="" xml:lang="">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>2 Methods and Materials | Network analysis approach using morphological profiling of chemical perturbation</title>
<meta name="description" content="Exploring the intersection of graph representation learning and cell profiling" />
<meta name="generator" content="bookdown 0.33 and GitBook 2.6.7" />
<meta property="og:title" content="2 Methods and Materials | Network analysis approach using morphological profiling of chemical perturbation" />
<meta property="og:type" content="book" />
<meta property="og:description" content="Exploring the intersection of graph representation learning and cell profiling" />
<meta name="twitter:card" content="summary" />
<meta name="twitter:title" content="2 Methods and Materials | Network analysis approach using morphological profiling of chemical perturbation" />
<meta name="twitter:description" content="Exploring the intersection of graph representation learning and cell profiling" />
<meta name="author" content="Nima Chamyani" />
<meta name="date" content="2023-07-04" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<link rel="prev" href="intro.html"/>
<link rel="next" href="results.html"/>
<script src="libs/jquery-3.6.0/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/fuse.js@6.4.6/dist/fuse.min.js"></script>
<link href="libs/gitbook-2.6.7/css/style.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-table.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-bookdown.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-highlight.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-search.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-fontsettings.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-clipboard.css" rel="stylesheet" />
<link href="libs/anchor-sections-1.1.0/anchor-sections.css" rel="stylesheet" />
<link href="libs/anchor-sections-1.1.0/anchor-sections-hash.css" rel="stylesheet" />
<script src="libs/anchor-sections-1.1.0/anchor-sections.js"></script>
<style type="text/css">
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > 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 {
pre > 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 { color: #008000; } /* 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 { color: #008000; font-weight: bold; } /* 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>
<style type="text/css">
/* Used with Pandoc 2.11+ new --citeproc when CSL is used */
div.csl-bib-body { }
div.csl-entry {
clear: both;
}
.hanging div.csl-entry {
margin-left:2em;
text-indent:-2em;
}
div.csl-left-margin {
min-width:2em;
float:left;
}
div.csl-right-inline {
margin-left:2em;
padding-left:1em;
}
div.csl-indent {
margin-left: 2em;
}
</style>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div class="book without-animation with-summary font-size-2 font-family-1" data-basepath=".">
<div class="book-summary">
<nav role="navigation">
<ul class="summary">
<li class="chapter" data-level="" data-path="index.html"><a href="index.html"><i class="fa fa-check"></i>Intersecting Graph Representation Learning and Cell Profiling: A Novel Approach to Analyzing Complex Biomedical Data</a>
<ul>
<li class="chapter" data-level="" data-path="index.html"><a href="index.html#aim"><i class="fa fa-check"></i>Aim</a></li>
<li class="chapter" data-level="" data-path="index.html"><a href="index.html#what-can-be-found-in-this-document"><i class="fa fa-check"></i>What can be found in this document?</a></li>
</ul></li>
<li class="chapter" data-level="1" data-path="intro.html"><a href="intro.html"><i class="fa fa-check"></i><b>1</b> Introduction</a>
<ul>
<li class="chapter" data-level="1.1" data-path="intro.html"><a href="intro.html#graphs"><i class="fa fa-check"></i><b>1.1</b> Graphs</a></li>
<li class="chapter" data-level="1.2" data-path="intro.html"><a href="intro.html#graph-representation-learning"><i class="fa fa-check"></i><b>1.2</b> Graph representation learning</a></li>
<li class="chapter" data-level="1.3" data-path="intro.html"><a href="intro.html#cell-profiling"><i class="fa fa-check"></i><b>1.3</b> Cell profiling</a></li>
</ul></li>
<li class="chapter" data-level="2" data-path="methods.html"><a href="methods.html"><i class="fa fa-check"></i><b>2</b> Methods and Materials</a>
<ul>
<li class="chapter" data-level="2.1" data-path="methods.html"><a href="methods.html#data-preprocessing"><i class="fa fa-check"></i><b>2.1</b> Data Preprocessing</a>
<ul>
<li class="chapter" data-level="2.1.1" data-path="methods.html"><a href="methods.html#covid-19-cell-profilling-data"><i class="fa fa-check"></i><b>2.1.1</b> COVID-19 Cell profilling Data</a>
<ul>
<li class="chapter" data-level="2.1.1.1" data-path="methods.html"><a href="methods.html#normalization"><i class="fa fa-check"></i><b>2.1.1.1</b> Normalization</a></li>
<li class="chapter" data-level="2.1.1.2" data-path="methods.html"><a href="methods.html#dimensionality-reduction"><i class="fa fa-check"></i><b>2.1.1.2</b> Dimensionality Reduction</a></li>
<li class="chapter" data-level="2.1.1.3" data-path="methods.html"><a href="methods.html#development-of-a-binary-classification-of-data"><i class="fa fa-check"></i><b>2.1.1.3</b> Development of a binary classification of data</a></li>
</ul></li>
<li class="chapter" data-level="2.1.2" data-path="methods.html"><a href="methods.html#compound-protein-and-pathway-data-aggregation"><i class="fa fa-check"></i><b>2.1.2</b> Compound, Protein and Pathway Data Aggregation</a></li>
<li class="chapter" data-level="2.1.3" data-path="methods.html"><a href="methods.html#featurizing-the-biomedical-entities"><i class="fa fa-check"></i><b>2.1.3</b> Featurizing the Biomedical Entities</a>
<ul>
<li class="chapter" data-level="2.1.3.1" data-path="methods.html"><a href="methods.html#featurizing-compounds"><i class="fa fa-check"></i><b>2.1.3.1</b> Featurizing Compounds</a></li>
<li class="chapter" data-level="2.1.3.2" data-path="methods.html"><a href="methods.html#featurizing-proteins"><i class="fa fa-check"></i><b>2.1.3.2</b> Featurizing Proteins</a></li>
<li class="chapter" data-level="2.1.3.3" data-path="methods.html"><a href="methods.html#featurizing-pathways"><i class="fa fa-check"></i><b>2.1.3.3</b> Featurizing Pathways</a></li>
</ul></li>
<li class="chapter" data-level="2.1.4" data-path="methods.html"><a href="methods.html#covid-19-bio-graph"><i class="fa fa-check"></i><b>2.1.4</b> COVID-19 Bio-Graph</a></li>
<li class="chapter" data-level="2.1.5" data-path="methods.html"><a href="methods.html#representing-chemical-molecules-as-graph"><i class="fa fa-check"></i><b>2.1.5</b> Representing Chemical Molecules as Graph</a></li>
</ul></li>
<li class="chapter" data-level="2.2" data-path="methods.html"><a href="methods.html#models"><i class="fa fa-check"></i><b>2.2</b> Models</a>
<ul>
<li class="chapter" data-level="2.2.1" data-path="methods.html"><a href="methods.html#graph-level-molecular-predictor-glmp"><i class="fa fa-check"></i><b>2.2.1</b> Graph-Level Molecular Predictor (GLMP)</a></li>
<li class="chapter" data-level="2.2.2" data-path="methods.html"><a href="methods.html#bio-graph-integrative-classifierregressor-biogicbiogir"><i class="fa fa-check"></i><b>2.2.2</b> Bio-Graph Integrative Classifier/Regressor (BioGIC/BioGIR)</a>
<ul>
<li class="chapter" data-level="2.2.2.1" data-path="methods.html"><a href="methods.html#classificationregression"><i class="fa fa-check"></i><b>2.2.2.1</b> Classification/Regression</a></li>
<li class="chapter" data-level="2.2.2.2" data-path="methods.html"><a href="methods.html#predicting-joint-effect-of-nodes-chemical-combination"><i class="fa fa-check"></i><b>2.2.2.2</b> Predicting joint effect of nodes (Chemical Combination)</a></li>
</ul></li>
<li class="chapter" data-level="2.2.3" data-path="methods.html"><a href="methods.html#optimized-molecular-graph-generator-omg"><i class="fa fa-check"></i><b>2.2.3</b> Optimized Molecular Graph Generator (OMG)</a></li>
</ul></li>
<li class="chapter" data-level="2.3" data-path="methods.html"><a href="methods.html#model-validation-and-optimization"><i class="fa fa-check"></i><b>2.3</b> Model Validation and Optimization</a></li>
<li class="chapter" data-level="2.4" data-path="methods.html"><a href="methods.html#model-enhancement"><i class="fa fa-check"></i><b>2.4</b> Model Enhancement</a></li>
<li class="chapter" data-level="2.5" data-path="methods.html"><a href="methods.html#data-acquisition-software-and-libraries"><i class="fa fa-check"></i><b>2.5</b> Data acquisition, software and libraries</a></li>
</ul></li>
<li class="chapter" data-level="3" data-path="results.html"><a href="results.html"><i class="fa fa-check"></i><b>3</b> Result and Discussion</a>
<ul>
<li class="chapter" data-level="3.1" data-path="results.html"><a href="results.html#regressionclassification-performance"><i class="fa fa-check"></i><b>3.1</b> Regression/Classification Performance</a></li>
<li class="chapter" data-level="3.2" data-path="results.html"><a href="results.html#covid-19-biograph-topology"><i class="fa fa-check"></i><b>3.2</b> COVID-19 BioGraph Topology</a></li>
<li class="chapter" data-level="3.3" data-path="results.html"><a href="results.html#combination-prediction"><i class="fa fa-check"></i><b>3.3</b> Combination Prediction</a></li>
<li class="chapter" data-level="3.4" data-path="results.html"><a href="results.html#molecule-generation"><i class="fa fa-check"></i><b>3.4</b> Molecule Generation</a></li>
</ul></li>
<li class="chapter" data-level="" data-path="references.html"><a href="references.html"><i class="fa fa-check"></i>References</a></li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i><a href="./">Network analysis approach using morphological profiling of chemical perturbation</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<section class="normal" id="section-">
<div id="methods" class="section level1 hasAnchor" number="2">
<h1><span class="header-section-number">2</span> Methods and Materials<a href="methods.html#methods" class="anchor-section" aria-label="Anchor link to header"></a></h1>
<p>A diverse set of computational tools and methodologies were employed in this study to analyze and interpret complex biomedical data.</p>
<div id="data-preprocessing" class="section level2 hasAnchor" number="2.1">
<h2><span class="header-section-number">2.1</span> Data Preprocessing<a href="methods.html#data-preprocessing" class="anchor-section" aria-label="Anchor link to header"></a></h2>
<div id="covid-19-cell-profilling-data" class="section level3 hasAnchor" number="2.1.1">
<h3><span class="header-section-number">2.1.1</span> COVID-19 Cell profilling Data<a href="methods.html#covid-19-cell-profilling-data" class="anchor-section" aria-label="Anchor link to header"></a></h3>
<p>In this study, the data preprocessing stage consisted of the preparation and normalization of a COVID-19 dataset. This dataset contained phenotype features and metadata extracted from multiple images of Vero-E6 cells (African green monkey) infected with Human coronavirus SARS-CoV-2 and treated with 5300 drugs from the Specs Repurposing Library. Each compound was represented in two plate replicates within the set of 32 plates, each containing 384 wells. Fluorescent images were captured using an Image Xpress Micro XLS (Molecular Devices) microscope with a 20× objective using laser-based autofocus. Five labels were used to stain the cells, characterizing seven cellular components, including DNA, Golgi apparatus, plasma membrane, F-actin, nucleoli and cytoplasmic RNA, the endoplasmic reticulum, and the SARS-CoV-2 spike protein. The image files were then stored in grayscale TIFF format.</p>
<p>The open-source image analysis software CellProfiler version 4.0.6 was utilized to extract a total of 2009 morphological features, including size, shape, pixel intensities, and texture, from these images. The initial dataset cleaning involved the removal of features with constant values or missing data and empty features. Numeric columns in the dataset were subsequently isolated into ‘phenotype features’ and ‘metadata’. These features were then averaged on an image level. Features with extreme and outlier standard deviation values (SD < 0.001 and SD > 10000) were also eliminated.</p>
<p>This dataset represents an extensive collection of phenotype features extracted from images, along with associated metadata. Each row in the dataset corresponds to a single image, with each image associated with a specific site within a well. There are 9 sites (numbered 1-9) within each well, and approximately 350-360 wells within each plate, with a maximum of 384 wells per plate. The dataset encompasses 24 plates.</p>
<table style="width:100%;">
<colgroup>
<col width="6%" />
<col width="6%" />
<col width="6%" />
<col width="6%" />
<col width="6%" />
<col width="6%" />
<col width="6%" />
<col width="6%" />
<col width="6%" />
<col width="6%" />
<col width="6%" />
<col width="6%" />
<col width="6%" />
<col width="6%" />
<col width="6%" />
</colgroup>
<thead>
<tr class="header">
<th align="left">ImageID</th>
<th align="left">~ 2000 phenotype features</th>
<th>PlateID</th>
<th>Well</th>
<th>Site</th>
<th>Plate</th>
<th>Plate_Well</th>
<th>batch_id</th>
<th>pertType</th>
<th>cmpd_conc</th>
<th>Flag</th>
<th>Count_nuclei</th>
<th>Batch nr</th>
<th>Compound ID</th>
<th>selected_mechanism</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left">P03-L2_B03_1</td>
<td align="left">……….. values ……….</td>
<td>P03-L2</td>
<td>B03</td>
<td>1</td>
<td>03-L2</td>
<td>specs935-plate03-L2_B03</td>
<td>BJ1894547</td>
<td>trt</td>
<td>10.0</td>
<td>0</td>
<td>109.0</td>
<td>BJ1894547</td>
<td>CBK042132</td>
<td>estrogen receptor alpha modulator</td>
</tr>
<tr class="even">
<td align="left">P03-L2_B03_2</td>
<td align="left">……….. values ……….</td>
<td>P03-L2</td>
<td>B03</td>
<td>2</td>
<td>03-L2</td>
<td>specs935-plate03-L2_B03</td>
<td>BJ1894547</td>
<td>trt</td>
<td>10.0</td>
<td>0</td>
<td>121.0</td>
<td>BJ1894547</td>
<td>CBK042132</td>
<td>estrogen receptor alpha modulator</td>
</tr>
</tbody>
</table>
<p>. . . |54366 rows, 2140 columns|</p>
<p>During the preparation phase, the first step involved dropping empty features, i.e., columns with no values or with a standard deviation (SD) of 0. The dataset was then segregated into numeric columns, further filtered down to ‘phenotype features’ and ‘metadata’. The ‘phenotype features’ included numeric columns excluding those with certain strings such as ‘Metadata’, ‘Number’, ‘Outlier’, ‘ImageQuality’, ‘cmpd_conc’, ‘Total’, ‘Flag’ and ‘Site’. The difference between the number of numeric columns and the number of phenotype features gives the number of ‘metadata’.</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb1-1"><a href="methods.html#cb1-1" tabindex="-1"></a>numeric_columns <span class="op">=</span> <span class="bu">list</span>()</span>
<span id="cb1-2"><a href="methods.html#cb1-2" tabindex="-1"></a><span class="cf">for</span> a <span class="kw">in</span> df.columns:</span>
<span id="cb1-3"><a href="methods.html#cb1-3" tabindex="-1"></a> <span class="cf">if</span> (df.dtypes[a] <span class="st">'float64'</span>) <span class="op">|</span> (df.dtypes[a] <span class="st">'int64'</span>) :</span>
<span id="cb1-4"><a href="methods.html#cb1-4" tabindex="-1"></a> numeric_columns.append(a)</span>
<span id="cb1-5"><a href="methods.html#cb1-5" tabindex="-1"></a> </span>
<span id="cb1-6"><a href="methods.html#cb1-6" tabindex="-1"></a>feature_columns <span class="op">=</span> [fc <span class="cf">for</span> fc <span class="kw">in</span> numeric_columns <span class="cf">if</span> (<span class="st">'Metadata'</span> <span class="kw">not</span> <span class="kw">in</span> fc) <span class="op">&</span> (<span class="st">'Number'</span> <span class="kw">not</span> <span class="kw">in</span> fc) <span class="op">&</span></span>
<span id="cb1-7"><a href="methods.html#cb1-7" tabindex="-1"></a> (<span class="st">'Outlier'</span> <span class="kw">not</span> <span class="kw">in</span> fc) <span class="op">&</span> (<span class="st">'ImageQuality'</span> <span class="kw">not</span> <span class="kw">in</span> fc) <span class="op">&</span> (<span class="st">'cmpd_conc'</span> <span class="kw">not</span> <span class="kw">in</span> fc) <span class="op">&</span></span>
<span id="cb1-8"><a href="methods.html#cb1-8" tabindex="-1"></a> (<span class="st">'Total'</span> <span class="kw">not</span> <span class="kw">in</span> fc) <span class="op">&</span> (<span class="st">'Flag'</span> <span class="kw">not</span> <span class="kw">in</span> fc) <span class="op">&</span> (<span class="st">'Site'</span> <span class="kw">not</span> <span class="kw">in</span> fc) ]</span></code></pre></div>
<p>The preparation phase also involved removing any features with missing values and those with an SD less than 0.0001.</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb2-1"><a href="methods.html#cb2-1" tabindex="-1"></a>X <span class="op">=</span> df.loc[:, feature_columns]</span>
<span id="cb2-2"><a href="methods.html#cb2-2" tabindex="-1"></a>X.dropna(axis<span class="op">=</span><span class="dv">1</span>, inplace<span class="op">=</span><span class="va">True</span>)</span>
<span id="cb2-3"><a href="methods.html#cb2-3" tabindex="-1"></a>X <span class="op">=</span> X.loc[:, (X.std() <span class="op">></span> <span class="fl">0.0001</span>) ]</span></code></pre></div>
<div id="normalization" class="section level4 hasAnchor" number="2.1.1.1">
<h4><span class="header-section-number">2.1.1.1</span> Normalization<a href="methods.html#normalization" class="anchor-section" aria-label="Anchor link to header"></a></h4>
<p>Two methods of normalization were employed in this study: an overall approach and a plate-separated strategy. Both strategies utilized Median and Median Absolute Deviation (MMAD) normalization<span class="citation"><a href="#ref-kappal2019data">[35]</a></span>. The normalization was accomplished using the formula:</p>
<p><span class="math display">\[MMAD = \frac{X - DMSO_{median}}{|X_{dmso} - DMSO_{median}|_{median}}\]</span></p>
<p>where <span class="math inline">\(X\)</span> denotes the observed feature value, <span class="math inline">\(DMSO_{median}\)</span> signifies the median value of DMSO, and <span class="math inline">\(X_{dmso}\)</span> represents the observed feature value of DMSO. The overall strategy applied this formula to the entire dataset at once, whereas the plate-separated strategy applied it independently to each plate, using the local median values of DMSO for normalization within that plate.</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb3-1"><a href="methods.html#cb3-1" tabindex="-1"></a>dfDMSO <span class="op">=</span> df[df[<span class="st">'batch_id'</span>] <span class="op">==</span> <span class="st">'[dmso]'</span>]</span>
<span id="cb3-2"><a href="methods.html#cb3-2" tabindex="-1"></a>dfDMSO_Medians <span class="op">=</span> dfDMSO[phenotype_features].median()</span>
<span id="cb3-3"><a href="methods.html#cb3-3" tabindex="-1"></a>dfDMSO_MADs <span class="op">=</span> (dfDMSO[phenotype_features] <span class="op">-</span> dfDMSO[phenotype_features].median()).<span class="bu">abs</span>().median()</span>
<span id="cb3-4"><a href="methods.html#cb3-4" tabindex="-1"></a>df_MMAD <span class="op">=</span> df[phenotype_features].copy()</span>
<span id="cb3-5"><a href="methods.html#cb3-5" tabindex="-1"></a>df_MMAD <span class="op">=</span> (df[phenotype_features] <span class="op">-</span> dfDMSO_Medians[phenotype_features])<span class="op">/</span>dfDMSO_MADs[phenotype_features]</span>
<span id="cb3-6"><a href="methods.html#cb3-6" tabindex="-1"></a>df_MMAD.clip(lower<span class="op">=-</span><span class="dv">10</span>, upper<span class="op">=</span><span class="dv">10</span>, inplace<span class="op">=</span><span class="va">True</span>)</span></code></pre></div>
<p>In the plate separated approach, the same process was applied. However, it was done first by finding local median values for DMSO in each plate and normalizing the measurements in the same plate based on their respective DMSO medians.</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb4-1"><a href="methods.html#cb4-1" tabindex="-1"></a>df_MMAD_by_plate <span class="op">=</span> pd.DataFrame()</span>
<span id="cb4-2"><a href="methods.html#cb4-2" tabindex="-1"></a></span>
<span id="cb4-3"><a href="methods.html#cb4-3" tabindex="-1"></a><span class="cf">for</span> plate <span class="kw">in</span> plates:</span>
<span id="cb4-4"><a href="methods.html#cb4-4" tabindex="-1"></a> plate_data <span class="op">=</span> df[df[<span class="st">'Plate'</span>] <span class="op">==</span> plate]</span>
<span id="cb4-5"><a href="methods.html#cb4-5" tabindex="-1"></a> df_DMSO <span class="op">=</span> plate_data[plate_data[<span class="st">'batch_id'</span>] <span class="op">==</span> <span class="st">'[dmso]'</span>]</span>
<span id="cb4-6"><a href="methods.html#cb4-6" tabindex="-1"></a> df_DMSO_medians <span class="op">=</span> df_DMSO[phenotype_features].median()</span>
<span id="cb4-7"><a href="methods.html#cb4-7" tabindex="-1"></a> df_DMSO_MADs <span class="op">=</span> (df_DMSO[phenotype_features] <span class="op">-</span> df_DMSO[phenotype_features].median()).<span class="bu">abs</span>().median()</span>
<span id="cb4-8"><a href="methods.html#cb4-8" tabindex="-1"></a> MMAD <span class="op">=</span> (df[df[<span class="st">'Plate'</span>] <span class="op">==</span> plate][phenotype_features] <span class="op">-</span> df_DMSO_medians[phenotype_features])<span class="op">/</span>df_DMSO_MADs[phenotype_features]</span>
<span id="cb4-9"><a href="methods.html#cb4-9" tabindex="-1"></a> df_MMAD_by_plate <span class="op">=</span> pd.concat([df_MMADs_by_plate, MMAD])</span>
<span id="cb4-10"><a href="methods.html#cb4-10" tabindex="-1"></a></span>
<span id="cb4-11"><a href="methods.html#cb4-11" tabindex="-1"></a>df_MMAD_by_plate</span></code></pre></div>
<p>The site-level features were normalized at the plate level using the mean and standard deviation of the DMSO sites in the plate. MMAD normalization was chosen due to its robustness to outliers, implying that it functions well even with data containing extreme values. In contrast, other methods, such as Z-score normalization, could be significantly affected by these outliers. Furthermore, MMAD normalization does not require the data to follow a specific distribution, making it a versatile choice for various datasets. The application of two different strategies, one that treated the dataset as a whole and another that treated each plate independently, was done to account for potential variations within and between different plates.</p>
</div>
<div id="dimensionality-reduction" class="section level4 hasAnchor" number="2.1.1.2">
<h4><span class="header-section-number">2.1.1.2</span> Dimensionality Reduction<a href="methods.html#dimensionality-reduction" class="anchor-section" aria-label="Anchor link to header"></a></h4>
<p>In this part, several key steps were undertaken to reduce the dimensionality of the data, select the most informative features, and visualize the structure and variability of the data using Principal Component Analysis (PCA). PCA was applied to the dataset to identify the key direction or “a component” that describes most of the data variability. This process helps to transform the original dataset into an updated one where each data point is represented in terms of this component. The PCA algorithm also provides the loadings, or the contribution of each original feature to each principal component.</p>
<div class="sourceCode" id="cb5"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb5-1"><a href="methods.html#cb5-1" tabindex="-1"></a><span class="im">from</span> pca <span class="im">import</span> pca</span>
<span id="cb5-2"><a href="methods.html#cb5-2" tabindex="-1"></a><span class="im">import</span> matplotlib.pyplot <span class="im">as</span> plt</span>
<span id="cb5-3"><a href="methods.html#cb5-3" tabindex="-1"></a></span>
<span id="cb5-4"><a href="methods.html#cb5-4" tabindex="-1"></a>X <span class="op">=</span> covid_df.loc[(covid_df[<span class="st">'label'</span>] <span class="op">==</span> <span class="st">'DMSO'</span>) <span class="op">|</span> (covid_df[<span class="st">'label'</span>] <span class="op">==</span> <span class="st">'Uninfected'</span>) <span class="op">|</span> (covid_df[<span class="st">'label'</span>] <span class="op">==</span> <span class="st">'Remdesivir'</span>)][features].values</span>
<span id="cb5-5"><a href="methods.html#cb5-5" tabindex="-1"></a>row_label <span class="op">=</span> covid_df.loc[(covid_df[<span class="st">'label'</span>] <span class="op">==</span> <span class="st">'DMSO'</span>) <span class="op">|</span> (covid_df[<span class="st">'label'</span>] <span class="op">==</span> <span class="st">'Uninfected'</span>) <span class="op">|</span> (covid_df[<span class="st">'label'</span>] <span class="op">==</span> <span class="st">'Remdesivir'</span>)][<span class="st">'label'</span>]</span>
<span id="cb5-6"><a href="methods.html#cb5-6" tabindex="-1"></a></span>
<span id="cb5-7"><a href="methods.html#cb5-7" tabindex="-1"></a>PCA_model <span class="op">=</span> pca(n_components<span class="op">=</span><span class="dv">10</span>, detect_outliers<span class="op">=</span>[<span class="st">'ht2'</span>, <span class="st">'spe'</span>])</span>
<span id="cb5-8"><a href="methods.html#cb5-8" tabindex="-1"></a>results <span class="op">=</span> PCA_model.fit_transform(X, col_labels<span class="op">=</span>features, row_labels<span class="op">=</span>row_label)</span>
<span id="cb5-9"><a href="methods.html#cb5-9" tabindex="-1"></a>PCA_model.plot(figsize<span class="op">=</span>(<span class="dv">12</span>, <span class="dv">6</span>))</span></code></pre></div>
<div style="text-align: center;">
<figure>
<img src="assets/pca_1.png" alt="Graph basics" id="graph-basics" style="width: 90%; height: auto;"/>
</figure>
</div>
<p>Using outlier detection method like the Hotelling T2 test and the squared prediction error (SPE/DmodX) just one outlier were found in the data which was decided to remain in data.</p>
<div class="sourceCode" id="cb6"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb6-1"><a href="methods.html#cb6-1" tabindex="-1"></a>fig, axes <span class="op">=</span> plt.subplots(ncols<span class="op">=</span><span class="dv">2</span>, figsize<span class="op">=</span>(<span class="dv">17</span>,<span class="dv">8</span>))</span>
<span id="cb6-2"><a href="methods.html#cb6-2" tabindex="-1"></a>ax1 <span class="op">=</span> PCA_model.scatter(SPE<span class="op">=</span><span class="va">True</span>, hotellingt2<span class="op">=</span><span class="va">True</span>, cmap<span class="op">=</span><span class="st">'tab10'</span>, ax<span class="op">=</span>axes[<span class="dv">0</span>])</span>
<span id="cb6-3"><a href="methods.html#cb6-3" tabindex="-1"></a>ax2 <span class="op">=</span> PCA_model.biplot(SPE<span class="op">=</span><span class="va">True</span>, hotellingt2<span class="op">=</span><span class="va">True</span>, fontdict<span class="op">=</span>{<span class="st">'size'</span>: <span class="dv">8</span>}, cmap<span class="op">=</span><span class="st">'tab10'</span>, PC<span class="op">=</span>[<span class="dv">0</span>,<span class="dv">1</span>,<span class="dv">2</span>], ax<span class="op">=</span>axes[<span class="dv">1</span>])</span>
<span id="cb6-4"><a href="methods.html#cb6-4" tabindex="-1"></a>plt.show()</span></code></pre></div>
<div style="text-align: center;">
<figure>
<img src="assets/pca_biplot.png" alt="Graph basics" style="width: 90%; height: auto;"/>
</figure>
</div>
<p>The loading values obtained from PCA were subsequently utilized as input for a k-means clustering algorithm, enabling the clustering of features according to their loadings. The idea is to find the features that provide same information and cluster them together. The process begins with the execution of PCA, which is then followed by the deployment of k-means clustering on the PCA loadings. This arrangement allows features to be clustered based on their loadings. This can be construed as their significance or contribution to the data variance then a new feature is calculated for every cluster. This feature represents the average of all features contained within that specific cluster.</p>
<div class="sourceCode" id="cb7"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb7-1"><a href="methods.html#cb7-1" tabindex="-1"></a><span class="kw">def</span> feature_reducer(df, feature_list, loading_dim<span class="op">=</span><span class="dv">32</span>, feat_output_dim<span class="op">=</span><span class="dv">32</span>):</span>
<span id="cb7-2"><a href="methods.html#cb7-2" tabindex="-1"></a> <span class="im">import</span> pandas <span class="im">as</span> pd</span>
<span id="cb7-3"><a href="methods.html#cb7-3" tabindex="-1"></a> <span class="im">from</span> sklearn <span class="im">import</span> preprocessing</span>
<span id="cb7-4"><a href="methods.html#cb7-4" tabindex="-1"></a> <span class="im">from</span> sklearn.decomposition <span class="im">import</span> PCA</span>
<span id="cb7-5"><a href="methods.html#cb7-5" tabindex="-1"></a> <span class="im">from</span> sklearn.cluster <span class="im">import</span> KMeans</span>
<span id="cb7-6"><a href="methods.html#cb7-6" tabindex="-1"></a></span>
<span id="cb7-7"><a href="methods.html#cb7-7" tabindex="-1"></a> df_dsmo_uninfected_remi <span class="op">=</span> df.loc[(df[<span class="st">'label'</span>] <span class="op">==</span> <span class="st">'DMSO'</span>) <span class="op">|</span> (df[<span class="st">'label'</span>] <span class="op">==</span> <span class="st">'Uninfected'</span>) <span class="op">|</span> (df[<span class="st">'label'</span>] <span class="op">==</span> <span class="st">'Remdesivir'</span>)][feature_list]</span>
<span id="cb7-8"><a href="methods.html#cb7-8" tabindex="-1"></a> X <span class="op">=</span> df_dsmo_uninfected_remi.values</span>
<span id="cb7-9"><a href="methods.html#cb7-9" tabindex="-1"></a></span>
<span id="cb7-10"><a href="methods.html#cb7-10" tabindex="-1"></a> pca <span class="op">=</span> PCA()</span>
<span id="cb7-11"><a href="methods.html#cb7-11" tabindex="-1"></a> pca.fit(X)</span>
<span id="cb7-12"><a href="methods.html#cb7-12" tabindex="-1"></a> loadings <span class="op">=</span> pca.components_</span>
<span id="cb7-13"><a href="methods.html#cb7-13" tabindex="-1"></a> loading_data <span class="op">=</span> pd.DataFrame(loadings[:loading_dim]).T.values</span>
<span id="cb7-14"><a href="methods.html#cb7-14" tabindex="-1"></a> <span class="co"># Perform k-means clustering</span></span>
<span id="cb7-15"><a href="methods.html#cb7-15" tabindex="-1"></a> kmeans <span class="op">=</span> KMeans(n_clusters<span class="op">=</span>feat_output_dim, random_state<span class="op">=</span><span class="dv">42</span>, n_init<span class="op">=</span><span class="dv">100</span>).fit(loading_data)</span>
<span id="cb7-16"><a href="methods.html#cb7-16" tabindex="-1"></a></span>
<span id="cb7-17"><a href="methods.html#cb7-17" tabindex="-1"></a> <span class="co"># Get cluster assignments for each point</span></span>
<span id="cb7-18"><a href="methods.html#cb7-18" tabindex="-1"></a> labels <span class="op">=</span> kmeans.labels_</span>
<span id="cb7-19"><a href="methods.html#cb7-19" tabindex="-1"></a> <span class="cf">for</span> i <span class="kw">in</span> <span class="bu">range</span>(feat_output_dim):</span>
<span id="cb7-20"><a href="methods.html#cb7-20" tabindex="-1"></a> <span class="bu">exec</span>(<span class="ss">f'f_</span><span class="sc">{</span>i<span class="op">+</span><span class="dv">1</span><span class="sc">}</span><span class="ss">'</span> <span class="op">+</span> <span class="ss">f'= loading_data[labels == </span><span class="sc">{</span>i<span class="sc">}</span><span class="ss">]'</span>)</span>
<span id="cb7-21"><a href="methods.html#cb7-21" tabindex="-1"></a></span>
<span id="cb7-22"><a href="methods.html#cb7-22" tabindex="-1"></a> f <span class="op">=</span> pd.DataFrame({<span class="st">'features'</span> : df_dsmo_uninfected_remi.columns.values, <span class="st">'cluster'</span>: labels}).groupby(<span class="st">"cluster"</span>).agg(<span class="bu">list</span>)</span>
<span id="cb7-23"><a href="methods.html#cb7-23" tabindex="-1"></a> column_list <span class="op">=</span> <span class="bu">list</span>(df.columns)</span>
<span id="cb7-24"><a href="methods.html#cb7-24" tabindex="-1"></a> <span class="cf">for</span> feat <span class="kw">in</span> feature_list:</span>
<span id="cb7-25"><a href="methods.html#cb7-25" tabindex="-1"></a> column_list.remove(feat)</span>
<span id="cb7-26"><a href="methods.html#cb7-26" tabindex="-1"></a> new_df <span class="op">=</span> df.loc[:,column_list].copy()</span>
<span id="cb7-27"><a href="methods.html#cb7-27" tabindex="-1"></a> <span class="co"># new_df = df.loc[:,list(set(df.columns) - set(feature_list))].copy()</span></span>
<span id="cb7-28"><a href="methods.html#cb7-28" tabindex="-1"></a> <span class="cf">for</span> i, f_list <span class="kw">in</span> <span class="bu">enumerate</span>(f[<span class="st">'features'</span>]):</span>
<span id="cb7-29"><a href="methods.html#cb7-29" tabindex="-1"></a> new_df[<span class="ss">f'f</span><span class="sc">{</span>i<span class="op">+</span><span class="dv">1</span><span class="sc">}</span><span class="ss">'</span>] <span class="op">=</span> df[f_list].<span class="bu">apply</span>(<span class="kw">lambda</span> x: x.mean() , axis<span class="op">=</span><span class="dv">1</span>)</span>
<span id="cb7-30"><a href="methods.html#cb7-30" tabindex="-1"></a></span>
<span id="cb7-31"><a href="methods.html#cb7-31" tabindex="-1"></a> <span class="cf">return</span> new_df, f</span></code></pre></div>
<p>In another approach to reduce the dimension, each feature’s ability to differentiate between the classes was evaluated by calculating the area of the triangle formed by the centroids of the classes in the feature space when we just use that specific feature and one highly related parameter to differentiate classes (for instance feature vs. number of nuclei) to plot all the points. For this, the centroids of the three distinct categories (‘Compound’, ‘Uninfected’, ‘Remdesivir’) for each feature ~ number of nuclei plot have been calculated. The area of the triangle formed by these centroids and the distance between them has been computed. This quantifies the separation between the three categories using each feature and helps to find the most descriptive feature. Features resulting in larger triangle areas were considered more informative.</p>
<div class="sourceCode" id="cb8"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb8-1"><a href="methods.html#cb8-1" tabindex="-1"></a><span class="im">import</span> math</span>
<span id="cb8-2"><a href="methods.html#cb8-2" tabindex="-1"></a><span class="im">import</span> numpy <span class="im">as</span> np</span>
<span id="cb8-3"><a href="methods.html#cb8-3" tabindex="-1"></a></span>
<span id="cb8-4"><a href="methods.html#cb8-4" tabindex="-1"></a><span class="kw">def</span> area_of_triangle(p1, p2, p3):</span>
<span id="cb8-5"><a href="methods.html#cb8-5" tabindex="-1"></a> <span class="co"># Calculate the length of each side of the triangle</span></span>
<span id="cb8-6"><a href="methods.html#cb8-6" tabindex="-1"></a> a <span class="op">=</span> math.sqrt((p2[<span class="dv">0</span>] <span class="op">-</span> p1[<span class="dv">0</span>])<span class="op">**</span><span class="dv">2</span> <span class="op">+</span> (p2[<span class="dv">1</span>] <span class="op">-</span> p1[<span class="dv">1</span>])<span class="op">**</span><span class="dv">2</span>)</span>
<span id="cb8-7"><a href="methods.html#cb8-7" tabindex="-1"></a> b <span class="op">=</span> math.sqrt((p3[<span class="dv">0</span>] <span class="op">-</span> p2[<span class="dv">0</span>])<span class="op">**</span><span class="dv">2</span> <span class="op">+</span> (p3[<span class="dv">1</span>] <span class="op">-</span> p2[<span class="dv">1</span>])<span class="op">**</span><span class="dv">2</span>)</span>
<span id="cb8-8"><a href="methods.html#cb8-8" tabindex="-1"></a> c <span class="op">=</span> math.sqrt((p3[<span class="dv">0</span>] <span class="op">-</span> p1[<span class="dv">0</span>])<span class="op">**</span><span class="dv">2</span> <span class="op">+</span> (p3[<span class="dv">1</span>] <span class="op">-</span> p1[<span class="dv">1</span>])<span class="op">**</span><span class="dv">2</span>)</span>
<span id="cb8-9"><a href="methods.html#cb8-9" tabindex="-1"></a> </span>
<span id="cb8-10"><a href="methods.html#cb8-10" tabindex="-1"></a> <span class="co"># Calculate the semiperimeter of the triangle</span></span>
<span id="cb8-11"><a href="methods.html#cb8-11" tabindex="-1"></a> s <span class="op">=</span> (a <span class="op">+</span> b <span class="op">+</span> c) <span class="op">/</span> <span class="dv">2</span></span>
<span id="cb8-12"><a href="methods.html#cb8-12" tabindex="-1"></a> </span>
<span id="cb8-13"><a href="methods.html#cb8-13" tabindex="-1"></a> <span class="co"># Calculate the area using Heron's formula</span></span>
<span id="cb8-14"><a href="methods.html#cb8-14" tabindex="-1"></a> area <span class="op">=</span> math.sqrt(s <span class="op">*</span> (s <span class="op">-</span> a) <span class="op">*</span> (s <span class="op">-</span> b) <span class="op">*</span> (s <span class="op">-</span> c))</span>
<span id="cb8-15"><a href="methods.html#cb8-15" tabindex="-1"></a> </span>
<span id="cb8-16"><a href="methods.html#cb8-16" tabindex="-1"></a> <span class="cf">return</span> area</span>
<span id="cb8-17"><a href="methods.html#cb8-17" tabindex="-1"></a></span>
<span id="cb8-18"><a href="methods.html#cb8-18" tabindex="-1"></a><span class="kw">def</span> distance_between_centroids(centroid1, centroid2):</span>
<span id="cb8-19"><a href="methods.html#cb8-19" tabindex="-1"></a> <span class="co"># Calculate the distance using the distance formula</span></span>
<span id="cb8-20"><a href="methods.html#cb8-20" tabindex="-1"></a> distance <span class="op">=</span> np.sqrt((centroid2[<span class="dv">0</span>] <span class="op">-</span> centroid1[<span class="dv">0</span>])<span class="op">**</span><span class="dv">2</span> <span class="op">+</span> (centroid2[<span class="dv">1</span>] <span class="op">-</span> centroid1[<span class="dv">1</span>])<span class="op">**</span><span class="dv">2</span>)</span>
<span id="cb8-21"><a href="methods.html#cb8-21" tabindex="-1"></a> </span>
<span id="cb8-22"><a href="methods.html#cb8-22" tabindex="-1"></a> <span class="cf">return</span> distance</span>
<span id="cb8-23"><a href="methods.html#cb8-23" tabindex="-1"></a></span>
<span id="cb8-24"><a href="methods.html#cb8-24" tabindex="-1"></a></span>
<span id="cb8-25"><a href="methods.html#cb8-25" tabindex="-1"></a>scaler <span class="op">=</span> preprocessing.StandardScaler(with_mean<span class="op">=</span><span class="va">True</span>, with_std<span class="op">=</span><span class="va">True</span>)</span>
<span id="cb8-26"><a href="methods.html#cb8-26" tabindex="-1"></a>scaled_df <span class="op">=</span> covid_df.copy()</span>
<span id="cb8-27"><a href="methods.html#cb8-27" tabindex="-1"></a>scaled_df.loc[:, features] <span class="op">=</span> scaler.fit_transform(scaled_df.loc[:, features])</span>
<span id="cb8-28"><a href="methods.html#cb8-28" tabindex="-1"></a></span>
<span id="cb8-29"><a href="methods.html#cb8-29" tabindex="-1"></a>scores <span class="op">=</span> []</span>
<span id="cb8-30"><a href="methods.html#cb8-30" tabindex="-1"></a>comp_remi <span class="op">=</span> []</span>
<span id="cb8-31"><a href="methods.html#cb8-31" tabindex="-1"></a>comp_uni <span class="op">=</span> []</span>
<span id="cb8-32"><a href="methods.html#cb8-32" tabindex="-1"></a>remi_uni <span class="op">=</span> []</span>
<span id="cb8-33"><a href="methods.html#cb8-33" tabindex="-1"></a><span class="cf">for</span> feat <span class="kw">in</span> features[<span class="dv">1</span>:]:</span>
<span id="cb8-34"><a href="methods.html#cb8-34" tabindex="-1"></a> compound_coords <span class="op">=</span> scaled_df.loc[scaled_df[<span class="st">'label'</span>] <span class="op">==</span> <span class="st">'compound'</span>,[<span class="st">'Count_nuclei'</span>,feat]].values</span>
<span id="cb8-35"><a href="methods.html#cb8-35" tabindex="-1"></a> uninfected_coords <span class="op">=</span> scaled_df.loc[scaled_df[<span class="st">'label'</span>] <span class="op">==</span> <span class="st">'Uninfected'</span>,[<span class="st">'Count_nuclei'</span>,feat]].values</span>
<span id="cb8-36"><a href="methods.html#cb8-36" tabindex="-1"></a> remidesivir_coords <span class="op">=</span> scaled_df.loc[scaled_df[<span class="st">'label'</span>] <span class="op">==</span> <span class="st">'Remdesivir'</span>,[<span class="st">'Count_nuclei'</span>,feat]].values</span>
<span id="cb8-37"><a href="methods.html#cb8-37" tabindex="-1"></a></span>
<span id="cb8-38"><a href="methods.html#cb8-38" tabindex="-1"></a> compound_centroid <span class="op">=</span> np.mean(compound_coords, axis<span class="op">=</span><span class="dv">0</span>)</span>
<span id="cb8-39"><a href="methods.html#cb8-39" tabindex="-1"></a> uninfected_centroid <span class="op">=</span> np.mean(uninfected_coords, axis<span class="op">=</span><span class="dv">0</span>)</span>
<span id="cb8-40"><a href="methods.html#cb8-40" tabindex="-1"></a> remidesivir_centroid <span class="op">=</span> np.mean(remidesivir_coords, axis<span class="op">=</span><span class="dv">0</span>)</span>
<span id="cb8-41"><a href="methods.html#cb8-41" tabindex="-1"></a></span>
<span id="cb8-42"><a href="methods.html#cb8-42" tabindex="-1"></a> area <span class="op">=</span> area_of_triangle(compound_centroid, uninfected_centroid, remidesivir_centroid)</span>
<span id="cb8-43"><a href="methods.html#cb8-43" tabindex="-1"></a> comp_remi_dist <span class="op">=</span> distance_between_centroids(compound_centroid, remidesivir_centroid)</span>
<span id="cb8-44"><a href="methods.html#cb8-44" tabindex="-1"></a> comp_uni_dist <span class="op">=</span> distance_between_centroids(compound_centroid, uninfected_centroid)</span>
<span id="cb8-45"><a href="methods.html#cb8-45" tabindex="-1"></a> remi_uni_dist <span class="op">=</span> distance_between_centroids(remidesivir_centroid, uninfected_centroid)</span>
<span id="cb8-46"><a href="methods.html#cb8-46" tabindex="-1"></a> scores.append(area)</span>
<span id="cb8-47"><a href="methods.html#cb8-47" tabindex="-1"></a> comp_remi.append(comp_remi_dist)</span>
<span id="cb8-48"><a href="methods.html#cb8-48" tabindex="-1"></a> comp_uni.append(comp_uni_dist)</span>
<span id="cb8-49"><a href="methods.html#cb8-49" tabindex="-1"></a> remi_uni.append(remi_uni_dist)</span>
<span id="cb8-50"><a href="methods.html#cb8-50" tabindex="-1"></a></span>
<span id="cb8-51"><a href="methods.html#cb8-51" tabindex="-1"></a>feat_score <span class="op">=</span> pd.DataFrame({<span class="st">'feat'</span>: features[<span class="dv">1</span>:],</span>
<span id="cb8-52"><a href="methods.html#cb8-52" tabindex="-1"></a> <span class="st">'score'</span>: scores,</span>
<span id="cb8-53"><a href="methods.html#cb8-53" tabindex="-1"></a> <span class="st">'comp_remi'</span>:comp_remi,</span>
<span id="cb8-54"><a href="methods.html#cb8-54" tabindex="-1"></a> <span class="st">'comp_uni'</span>:comp_uni,</span>
<span id="cb8-55"><a href="methods.html#cb8-55" tabindex="-1"></a> <span class="st">'remi_uni'</span>: remi_uni})</span></code></pre></div>
<p>The features have been ranked based on the calculated area, seen as a measure of separation between the categories. The top 50 features have been selected. Between the first 50 features all annotated with MITO were removed because they bias our model. Therefore, 16 features remain as our selected features.</p>
<div class="sourceCode" id="cb9"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb9-1"><a href="methods.html#cb9-1" tabindex="-1"></a><span class="bu">list</span>(feat_score.sort_values(by<span class="op">=</span>[<span class="st">"score"</span>], ascending<span class="op">=</span><span class="va">False</span>).head(<span class="dv">50</span>)[<span class="st">'feat'</span>])</span></code></pre></div>
<p>Finally, PCA has been performed again, this time exclusively on the selected features.</p>
<div style="text-align: center;">
<figure>
<img src="assets/pca_16.png" alt="Graph basics" style="width: 100%; height: auto;"/>
</figure>
</div>
<p align="center">
<p><a href="https://pharmbio.github.io/nw-cp/assets/pca_16.html">Link to see interactive plot</a></p>
</p>
<p>The PCA results demonstrate that the 10 principal components can now explain a very high percentage (99.91%) of the variance. The first principle component improved from describing 75.1 percent of variance to 93.0 percent. This indicates that the selected features capture most of the data variability. The value of PC1 was used for regression models as the target value.</p>
<div style="text-align: center;">
<figure>
<img src="assets/pca_2.png" alt="Graph basics" style="width: 90%; height: auto;"/>
</figure>
</div>
</div>
<div id="development-of-a-binary-classification-of-data" class="section level4 hasAnchor" number="2.1.1.3">
<h4><span class="header-section-number">2.1.1.3</span> Development of a binary classification of data<a href="methods.html#development-of-a-binary-classification-of-data" class="anchor-section" aria-label="Anchor link to header"></a></h4>
<p>In this part, Kernel Density Estimation (KDE) and Empirical Confidence Regions (2d confidence intervals based on binned kernel density estimate) were utilized to inform the development of a binary classification model for identifying active and inactive compounds based on their PCA1 values.</p>
<p>Firstly, a two-dimensional KDE was performed on the compounds’ PCA1 and PCA2 values. This KDE plot provided a comprehensive understanding of the distribution of data points in the PCA space. It highlighted two distinct clusters corresponding to active and inactive compounds.</p>
<p>The KDE plot was further enhanced by overlaying empirical confidence regions on it. These regions were derived from the mean and covariance of the PCA1 and PCA2 values for each cluster. Two standard deviation ellipses were used, approximating 90% confidence regions for the location of the true mean of each cluster in the PCA space.</p>
<div class="sourceCode" id="cb10"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb10-1"><a href="methods.html#cb10-1" tabindex="-1"></a><span class="im">import</span> numpy <span class="im">as</span> np</span>
<span id="cb10-2"><a href="methods.html#cb10-2" tabindex="-1"></a><span class="im">import</span> seaborn <span class="im">as</span> sns</span>
<span id="cb10-3"><a href="methods.html#cb10-3" tabindex="-1"></a><span class="im">import</span> matplotlib.pyplot <span class="im">as</span> plt</span>
<span id="cb10-4"><a href="methods.html#cb10-4" tabindex="-1"></a><span class="im">from</span> matplotlib.patches <span class="im">import</span> Ellipse</span>
<span id="cb10-5"><a href="methods.html#cb10-5" tabindex="-1"></a></span>
<span id="cb10-6"><a href="methods.html#cb10-6" tabindex="-1"></a>mean1 <span class="op">=</span> df_cluster1[[<span class="st">'PC1'</span>, <span class="st">'PC2'</span>]].mean()</span>
<span id="cb10-7"><a href="methods.html#cb10-7" tabindex="-1"></a>cov1 <span class="op">=</span> df_cluster1[[<span class="st">'PC1'</span>, <span class="st">'PC2'</span>]].cov()</span>
<span id="cb10-8"><a href="methods.html#cb10-8" tabindex="-1"></a></span>
<span id="cb10-9"><a href="methods.html#cb10-9" tabindex="-1"></a>mean2 <span class="op">=</span> df_cluster2[[<span class="st">'PC1'</span>, <span class="st">'PC2'</span>]].mean()</span>
<span id="cb10-10"><a href="methods.html#cb10-10" tabindex="-1"></a>cov2 <span class="op">=</span> df_cluster2[[<span class="st">'PC1'</span>, <span class="st">'PC2'</span>]].cov()</span>
<span id="cb10-11"><a href="methods.html#cb10-11" tabindex="-1"></a></span>
<span id="cb10-12"><a href="methods.html#cb10-12" tabindex="-1"></a>fig, ax <span class="op">=</span> plt.subplots(figsize<span class="op">=</span>(<span class="dv">7</span>, <span class="dv">4</span>))</span>
<span id="cb10-13"><a href="methods.html#cb10-13" tabindex="-1"></a><span class="co"># Draw the KDE plot</span></span>
<span id="cb10-14"><a href="methods.html#cb10-14" tabindex="-1"></a>sns.kdeplot(data<span class="op">=</span>df_clust, x<span class="op">=</span><span class="st">'PC1'</span>, y<span class="op">=</span><span class="st">'PC2'</span>, fill<span class="op">=</span><span class="va">True</span>, ax<span class="op">=</span>ax)</span>
<span id="cb10-15"><a href="methods.html#cb10-15" tabindex="-1"></a></span>
<span id="cb10-16"><a href="methods.html#cb10-16" tabindex="-1"></a><span class="co"># Draw the confidence ellipses</span></span>
<span id="cb10-17"><a href="methods.html#cb10-17" tabindex="-1"></a><span class="cf">for</span> mean, cov <span class="kw">in</span> [(mean1, cov1), (mean2, cov2)]:</span>
<span id="cb10-18"><a href="methods.html#cb10-18" tabindex="-1"></a> eigenvalues, eigenvectors <span class="op">=</span> np.linalg.eigh(cov)</span>
<span id="cb10-19"><a href="methods.html#cb10-19" tabindex="-1"></a> order <span class="op">=</span> eigenvalues.argsort()[::<span class="op">-</span><span class="dv">1</span>]</span>
<span id="cb10-20"><a href="methods.html#cb10-20" tabindex="-1"></a> eigenvalues, eigenvectors <span class="op">=</span> eigenvalues[order], eigenvectors[:, order]</span>
<span id="cb10-21"><a href="methods.html#cb10-21" tabindex="-1"></a> vx, vy <span class="op">=</span> eigenvectors[:,<span class="dv">0</span>]</span>
<span id="cb10-22"><a href="methods.html#cb10-22" tabindex="-1"></a> theta <span class="op">=</span> np.arctan2(vy, vx)</span>
<span id="cb10-23"><a href="methods.html#cb10-23" tabindex="-1"></a></span>
<span id="cb10-24"><a href="methods.html#cb10-24" tabindex="-1"></a> <span class="co"># Draw a 2*2.146 ellipse for 90 % CI</span></span>
<span id="cb10-25"><a href="methods.html#cb10-25" tabindex="-1"></a> ellipse <span class="op">=</span> Ellipse(xy<span class="op">=</span>mean, width<span class="op">=</span><span class="dv">2</span><span class="op">*</span><span class="fl">2.146</span><span class="op">**</span>np.sqrt(eigenvalues[<span class="dv">0</span>]), </span>
<span id="cb10-26"><a href="methods.html#cb10-26" tabindex="-1"></a> height<span class="op">=</span><span class="dv">2</span><span class="op">*</span><span class="fl">2.146</span><span class="op">**</span>np.sqrt(eigenvalues[<span class="dv">1</span>]), </span>
<span id="cb10-27"><a href="methods.html#cb10-27" tabindex="-1"></a> angle<span class="op">=</span>np.degrees(theta), edgecolor<span class="op">=</span><span class="st">'red'</span>, </span>
<span id="cb10-28"><a href="methods.html#cb10-28" tabindex="-1"></a> facecolor<span class="op">=</span><span class="st">'none'</span>)</span>
<span id="cb10-29"><a href="methods.html#cb10-29" tabindex="-1"></a> ax.add_patch(ellipse)</span>
<span id="cb10-30"><a href="methods.html#cb10-30" tabindex="-1"></a></span>
<span id="cb10-31"><a href="methods.html#cb10-31" tabindex="-1"></a>plt.show()</span></code></pre></div>
<div style="text-align: center;">
<figure>
<img src="assets/KDE_ECR.png" alt="Graph basics" style="width: 70%; height: auto;"/>
</figure>
</div>
<p>The intersection of these confidence regions was then examined. The PCA1 value of 5 at this intersection was hypothesized to be an effective threshold for binary classification of compounds. Any compound with a PCA1 value greater than this threshold was classified as ‘active’, and any compound with a PCA1 value less than this threshold was classified as ‘inactive’.</p>
<p>Importantly, this approach allowed the study to estimate a suitable classification threshold but also to visualize the uncertainty around this threshold and the potential overlap between the two classes. The method provided a data-driven way to set the classification threshold and offered insights into the inherent complexity of the data.</p>
<div style="text-align: center;">
<figure>
<img src="assets/ECIRegion_R.png" alt="Graph basics" style="width: 80%; height: auto;"/>
</figure>
</div>
<p>It should be noted that the assumptions of the Gaussian distribution and independent identically distributed data inherent to this method may not hold in all cases. Therefore, the results should be interpreted with caution. Further, the use of PCA1 values alone for classification may oversimplify the problem if the active and inactive compounds differ along other principal components as well. Therefore, additional analyses are recommended to validate and refine this binary classification model.</p>
</div>
</div>
<div id="compound-protein-and-pathway-data-aggregation" class="section level3 hasAnchor" number="2.1.2">
<h3><span class="header-section-number">2.1.2</span> Compound, Protein and Pathway Data Aggregation<a href="methods.html#compound-protein-and-pathway-data-aggregation" class="anchor-section" aria-label="Anchor link to header"></a></h3>
<p>In the cell profiling data, the Simplified Molecular Input Line Entry System (SMILES) was incorporated to represent the chemical structure. The COVID-19 cell painting experiments that was carried out, was involved cell perturbations with over 5000 compounds. To uncover potential information regarding the protein binding capabilities and the pathways and assays in which these compounds are active, a highly recognized cross-reference annotation was necessitated.</p>
<p>The PubChem Chemical ID (CID) serves as an exhaustive cross-reference annotation for chemicals. The initial step involved the determination of the CIDs for all the chemical compounds. These identifiers were subsequently utilized for the aggregation of additional protein and pathway data. This approach facilitated finding the activity of the compounds within the biological systems.</p>
<div class="sourceCode" id="cb11"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb11-1"><a href="methods.html#cb11-1" tabindex="-1"></a><span class="im">import</span> pubchempy <span class="im">as</span> pcp</span>
<span id="cb11-2"><a href="methods.html#cb11-2" tabindex="-1"></a></span>
<span id="cb11-3"><a href="methods.html#cb11-3" tabindex="-1"></a>chemical_smiles <span class="op">=</span> <span class="bu">list</span>(df[<span class="st">'smiles'</span>].values)</span>
<span id="cb11-4"><a href="methods.html#cb11-4" tabindex="-1"></a></span>
<span id="cb11-5"><a href="methods.html#cb11-5" tabindex="-1"></a>cids <span class="op">=</span> []</span>
<span id="cb11-6"><a href="methods.html#cb11-6" tabindex="-1"></a><span class="cf">for</span> smiles <span class="kw">in</span> chemical_smiles:</span>
<span id="cb11-7"><a href="methods.html#cb11-7" tabindex="-1"></a> <span class="cf">try</span>:</span>
<span id="cb11-8"><a href="methods.html#cb11-8" tabindex="-1"></a> c <span class="op">=</span> pcp.get_compounds(smiles, <span class="st">'smiles'</span>)</span>
<span id="cb11-9"><a href="methods.html#cb11-9" tabindex="-1"></a> <span class="cf">if</span> c:</span>
<span id="cb11-10"><a href="methods.html#cb11-10" tabindex="-1"></a> cids.append(c[<span class="dv">0</span>].cid})</span>
<span id="cb11-11"><a href="methods.html#cb11-11" tabindex="-1"></a> <span class="cf">else</span>:</span>
<span id="cb11-12"><a href="methods.html#cb11-12" tabindex="-1"></a> <span class="bu">print</span>(<span class="ss">f'No compound found for SMILES: </span><span class="sc">{</span>smiles<span class="sc">}</span><span class="ss">'</span>)</span>
<span id="cb11-13"><a href="methods.html#cb11-13" tabindex="-1"></a> <span class="cf">except</span> <span class="pp">Exception</span> <span class="im">as</span> e:</span>
<span id="cb11-14"><a href="methods.html#cb11-14" tabindex="-1"></a> <span class="bu">print</span>(<span class="ss">f'Error occurred: </span><span class="sc">{</span>e<span class="sc">}</span><span class="ss">'</span>)</span></code></pre></div>
<p>The COVID-19 dataset consisted of compounds screened for potential activity against SARS-CoV-2. To analyze the associations between these compounds and proteins, an auxiliary dataset, sourced from the STITCH database, was utilized. The STITCH database provides information about interactions between chemicals and proteins. These connections were then indexed and collated to create a list of compounds with and their association with proteins.</p>
<p>Further, the connection between chemical compounds and their corresponding biological pathways was established through the following steps:</p>
<p>Initially, assay summaries for a selection of compounds were obtained from the PubChem database. These summaries provided information about various biological assays performed on the compounds, specifically emphasizing on the target gene IDs that interacted with the compounds during these assays. Only the assays reporting an ‘Active’ outcome and a non-empty target gene ID were retained for further analysis.</p>
<div class="sourceCode" id="cb12"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb12-1"><a href="methods.html#cb12-1" tabindex="-1"></a><span class="im">from</span> io <span class="im">import</span> StringIO</span>
<span id="cb12-2"><a href="methods.html#cb12-2" tabindex="-1"></a><span class="im">import</span> polars <span class="im">as</span> pl</span>
<span id="cb12-3"><a href="methods.html#cb12-3" tabindex="-1"></a><span class="im">import</span> pubchempy <span class="im">as</span> pcp</span>
<span id="cb12-4"><a href="methods.html#cb12-4" tabindex="-1"></a></span>
<span id="cb12-5"><a href="methods.html#cb12-5" tabindex="-1"></a>comp_gid <span class="op">=</span> pl.read_csv(<span class="st">'data/comp_gid.tsv'</span>, separator<span class="op">=</span><span class="st">'</span><span class="ch">\t</span><span class="st">'</span>)</span>
<span id="cb12-6"><a href="methods.html#cb12-6" tabindex="-1"></a>cids <span class="op">=</span> comp_gid.select([<span class="st">'pubchem_cid'</span>]).to_series().to_list()</span>
<span id="cb12-7"><a href="methods.html#cb12-7" tabindex="-1"></a></span>
<span id="cb12-8"><a href="methods.html#cb12-8" tabindex="-1"></a>cid_genid_df <span class="op">=</span> pl.DataFrame(</span>
<span id="cb12-9"><a href="methods.html#cb12-9" tabindex="-1"></a> schema<span class="op">=</span>{<span class="st">'CID'</span>: pl.Int64, <span class="st">'AID'</span>: pl.Int64, <span class="st">'Target GeneID'</span>: pl.Utf8, <span class="st">'Activity Value [uM]'</span>: pl.Float64, <span class="st">'Assay Name'</span>: pl.Utf8}</span>
<span id="cb12-10"><a href="methods.html#cb12-10" tabindex="-1"></a> )</span>
<span id="cb12-11"><a href="methods.html#cb12-11" tabindex="-1"></a> </span>
<span id="cb12-12"><a href="methods.html#cb12-12" tabindex="-1"></a><span class="cf">for</span> cid <span class="kw">in</span> cids[:<span class="dv">10</span>]:</span>
<span id="cb12-13"><a href="methods.html#cb12-13" tabindex="-1"></a> <span class="cf">try</span>:</span>
<span id="cb12-14"><a href="methods.html#cb12-14" tabindex="-1"></a> csvStringIO <span class="op">=</span> StringIO(pcp.get(cid, operation<span class="op">=</span><span class="st">'assaysummary'</span>, output<span class="op">=</span><span class="st">'CSV'</span>).decode(<span class="st">"utf-8"</span>))</span>
<span id="cb12-15"><a href="methods.html#cb12-15" tabindex="-1"></a> dictdf <span class="op">=</span> pl.read_csv(csvStringIO, dtypes<span class="op">=</span>{<span class="st">'Activity Value [uM]'</span>: pl.Float64})</span>
<span id="cb12-16"><a href="methods.html#cb12-16" tabindex="-1"></a> ciddf <span class="op">=</span> dictdf.<span class="bu">filter</span>(</span>
<span id="cb12-17"><a href="methods.html#cb12-17" tabindex="-1"></a> (pl.col(<span class="st">"Activity Outcome"</span>) <span class="op">==</span> <span class="st">"Active"</span>) <span class="op">&</span> (pl.col(<span class="st">"Target GeneID"</span>) <span class="op">!=</span> <span class="st">""</span>)</span>
<span id="cb12-18"><a href="methods.html#cb12-18" tabindex="-1"></a> ).unique(</span>
<span id="cb12-19"><a href="methods.html#cb12-19" tabindex="-1"></a> subset<span class="op">=</span><span class="st">'Target GeneID'</span></span>
<span id="cb12-20"><a href="methods.html#cb12-20" tabindex="-1"></a> ).select(</span>
<span id="cb12-21"><a href="methods.html#cb12-21" tabindex="-1"></a> [<span class="st">'CID'</span>, <span class="st">'AID'</span>, <span class="st">'Target GeneID'</span>, <span class="st">'Activity Value [uM]'</span>, <span class="st">'Assay Name'</span>]</span>
<span id="cb12-22"><a href="methods.html#cb12-22" tabindex="-1"></a> )</span>
<span id="cb12-23"><a href="methods.html#cb12-23" tabindex="-1"></a> <span class="cf">except</span>:</span>
<span id="cb12-24"><a href="methods.html#cb12-24" tabindex="-1"></a> ciddf <span class="op">=</span> pl.DataFrame(</span>
<span id="cb12-25"><a href="methods.html#cb12-25" tabindex="-1"></a> schema<span class="op">=</span>{<span class="st">'CID'</span>: pl.Int64, <span class="st">'AID'</span>: pl.Int64, <span class="st">'Target GeneID'</span>: pl.Utf8, <span class="st">'Activity Value [uM]'</span>: pl.Utf8, <span class="st">'Assay Name'</span>: pl.Utf8}</span>
<span id="cb12-26"><a href="methods.html#cb12-26" tabindex="-1"></a> )</span>
<span id="cb12-27"><a href="methods.html#cb12-27" tabindex="-1"></a> </span>
<span id="cb12-28"><a href="methods.html#cb12-28" tabindex="-1"></a> cid_genid_df <span class="op">=</span> cid_genid_df.vstack(ciddf)</span>
<span id="cb12-29"><a href="methods.html#cb12-29" tabindex="-1"></a></span>
<span id="cb12-30"><a href="methods.html#cb12-30" tabindex="-1"></a>cid_genid_df.write_csv(<span class="st">'comp_geneid.tsv'</span>, separator<span class="op">=</span><span class="st">'</span><span class="ch">\t</span><span class="st">'</span>)</span></code></pre></div>
<p>Subsequently, the list of unique target gene IDs was utilized to extract associated biological pathways from the PubChem database. These pathways, sourced from the WikiPathways database, link each gene ID to one or multiple biological pathways.</p>
<div class="sourceCode" id="cb13"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb13-1"><a href="methods.html#cb13-1" tabindex="-1"></a><span class="im">import</span> polars <span class="im">as</span> pl</span>
<span id="cb13-2"><a href="methods.html#cb13-2" tabindex="-1"></a><span class="im">import</span> pubchempy <span class="im">as</span> pcp</span>
<span id="cb13-3"><a href="methods.html#cb13-3" tabindex="-1"></a></span>
<span id="cb13-4"><a href="methods.html#cb13-4" tabindex="-1"></a>gene_id_list <span class="op">=</span> cid_genid_df.select(pl.col(<span class="st">'Target GeneID'</span>).cast(pl.Int64, strict<span class="op">=</span><span class="va">True</span>)).unique(subset<span class="op">=</span><span class="st">'Target GeneID'</span>, maintain_order<span class="op">=</span><span class="va">True</span>).to_series().to_list()</span>
<span id="cb13-5"><a href="methods.html#cb13-5" tabindex="-1"></a>genid_wpw_df <span class="op">=</span> pl.DataFrame(schema<span class="op">=</span>{<span class="st">'Target GeneID'</span>: pl.Object, <span class="st">'Wiki Pathway'</span>: pl.Utf8})</span>
<span id="cb13-6"><a href="methods.html#cb13-6" tabindex="-1"></a></span>
<span id="cb13-7"><a href="methods.html#cb13-7" tabindex="-1"></a><span class="cf">for</span> gene_id <span class="kw">in</span> gene_id_list:</span>
<span id="cb13-8"><a href="methods.html#cb13-8" tabindex="-1"></a> <span class="cf">try</span>:</span>
<span id="cb13-9"><a href="methods.html#cb13-9" tabindex="-1"></a> ptw_list <span class="op">=</span> pcp.get_json(gene_id, namespace<span class="op">=</span><span class="st">'geneid'</span>, domain<span class="op">=</span><span class="st">'gene'</span>, operation<span class="op">=</span><span class="st">'pwaccs'</span>)[<span class="st">'InformationList'</span>][<span class="st">'Information'</span>][<span class="dv">0</span>][<span class="st">'PathwayAccession'</span>]</span>
<span id="cb13-10"><a href="methods.html#cb13-10" tabindex="-1"></a> wp <span class="op">=</span> [i[<span class="dv">13</span>:] <span class="cf">for</span> i <span class="kw">in</span> <span class="bu">list</span>(<span class="bu">filter</span>(<span class="kw">lambda</span> x: <span class="st">'WikiPathways'</span> <span class="kw">in</span> x, ptw_list))]</span>
<span id="cb13-11"><a href="methods.html#cb13-11" tabindex="-1"></a> temp_df <span class="op">=</span> pl.DataFrame({<span class="st">'Target GeneID'</span>:gene_id, <span class="st">'Wiki Pathway'</span>: wp})</span>
<span id="cb13-12"><a href="methods.html#cb13-12" tabindex="-1"></a> <span class="cf">except</span>:</span>
<span id="cb13-13"><a href="methods.html#cb13-13" tabindex="-1"></a> temp_df <span class="op">=</span> pl.DataFrame({<span class="st">'Target GeneID'</span>:gene_id, <span class="st">'Wiki Pathway'</span>: <span class="st">''</span>})</span>
<span id="cb13-14"><a href="methods.html#cb13-14" tabindex="-1"></a> genid_wpw_df <span class="op">=</span> genid_wpw_df.vstack(temp_df)</span>
<span id="cb13-15"><a href="methods.html#cb13-15" tabindex="-1"></a> </span>
<span id="cb13-16"><a href="methods.html#cb13-16" tabindex="-1"></a></span>
<span id="cb13-17"><a href="methods.html#cb13-17" tabindex="-1"></a>genid_wpw_df.write_csv(<span class="st">'geneid_wpw.tsv'</span>, separator<span class="op">=</span><span class="st">'</span><span class="ch">\t</span><span class="st">'</span>)</span></code></pre></div>
<p>Gene ID fetched from these databases can be converted to STITCH database annotation by using BIIT API:</p>
<div class="sourceCode" id="cb14"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb14-1"><a href="methods.html#cb14-1" tabindex="-1"></a><span class="im">import</span> requests</span>
<span id="cb14-2"><a href="methods.html#cb14-2" tabindex="-1"></a></span>
<span id="cb14-3"><a href="methods.html#cb14-3" tabindex="-1"></a>r <span class="op">=</span> requests.post(</span>
<span id="cb14-4"><a href="methods.html#cb14-4" tabindex="-1"></a> url<span class="op">=</span><span class="st">'https://biit.cs.ut.ee/gprofiler/api/convert/convert/'</span>,</span>
<span id="cb14-5"><a href="methods.html#cb14-5" tabindex="-1"></a> json<span class="op">=</span>{</span>
<span id="cb14-6"><a href="methods.html#cb14-6" tabindex="-1"></a> <span class="st">'organism'</span>:<span class="st">'hsapiens'</span>,</span>
<span id="cb14-7"><a href="methods.html#cb14-7" tabindex="-1"></a> <span class="st">'target'</span>:<span class="st">'ENSP'</span>,</span>
<span id="cb14-8"><a href="methods.html#cb14-8" tabindex="-1"></a> <span class="st">'query'</span>:gene_id_list,</span>
<span id="cb14-9"><a href="methods.html#cb14-9" tabindex="-1"></a> <span class="st">'numeric_namespace'</span>: <span class="st">'ENTREZGENE_ACC'</span></span>
<span id="cb14-10"><a href="methods.html#cb14-10" tabindex="-1"></a> }</span>
<span id="cb14-11"><a href="methods.html#cb14-11" tabindex="-1"></a> )</span>
<span id="cb14-12"><a href="methods.html#cb14-12" tabindex="-1"></a>pl.DataFrame(r.json()[<span class="st">'result'</span>]).select([<span class="st">'incoming'</span>, <span class="st">'converted'</span>, <span class="st">'name'</span>, <span class="st">'description'</span>])</span></code></pre></div>
<p>Hence, a linkage from chemical compounds to biological pathways was constructed by associating compounds with target gene IDs from assays, and then connecting these gene IDs to biological pathways. This method of data preparation facilitated the exploration of potential mechanisms of action of compounds. It also provided an understanding of the biological processes potentially influenced by these compounds. It should be noted, however, that this is a simplified representation of the actual biological interactions, which are inherently more complex.</p>
<p>These curated lists of compounds, proteins, and pathways served as the foundation for constructing a multimodal graph. In this graph, the nodes represent compounds, proteins, and pathways while the edges depict the connections between them.</p>
</div>
<div id="featurizing-the-biomedical-entities" class="section level3 hasAnchor" number="2.1.3">
<h3><span class="header-section-number">2.1.3</span> Featurizing the Biomedical Entities<a href="methods.html#featurizing-the-biomedical-entities" class="anchor-section" aria-label="Anchor link to header"></a></h3>
<p>In machine learning, featurization converts biomedical entities, which are often three-dimensional entities like chemicals and proteins, into a format that can be understood and processed by algorithms. Essentially, it involves converting the structure and properties into numerical vectors.</p>
<p>It is necessary because machine learning algorithms work with numerical data rather than understanding biological structures and properties directly. Featurization is accomplished through the application of different algorithm and ways which will be discussed in following section.</p>
<div id="featurizing-compounds" class="section level4 hasAnchor" number="2.1.3.1">
<h4><span class="header-section-number">2.1.3.1</span> Featurizing Compounds<a href="methods.html#featurizing-compounds" class="anchor-section" aria-label="Anchor link to header"></a></h4>
<p>Starting with MACCS fingerprints, these are binary representations of a molecule based on the presence or absence of 167 predefined structural fragments. MACCS fingerprints are popular due to their simplicity, interpretability, and effectiveness at capturing structural information.</p>
<div class="sourceCode" id="cb15"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb15-1"><a href="methods.html#cb15-1" tabindex="-1"></a><span class="im">import</span> deepchem <span class="im">as</span> dc</span>
<span id="cb15-2"><a href="methods.html#cb15-2" tabindex="-1"></a></span>
<span id="cb15-3"><a href="methods.html#cb15-3" tabindex="-1"></a>feat <span class="op">=</span> dc.feat.MACCSKeysFingerprint()</span>
<span id="cb15-4"><a href="methods.html#cb15-4" tabindex="-1"></a>maccs_fp <span class="op">=</span> feat.featurize(smiles)</span></code></pre></div>
<p>Morgan fingerprints, also known as circular fingerprints, are another type of molecular descriptor. They are generated by iteratively hashing the environments of atoms in a molecule. These fingerprints are characterized by their flexibility, as their radius and length can be adjusted. This allows for various levels of specificity in the representation of molecular structures.</p>
<div class="sourceCode" id="cb16"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb16-1"><a href="methods.html#cb16-1" tabindex="-1"></a><span class="im">import</span> deepchem <span class="im">as</span> dc</span>
<span id="cb16-2"><a href="methods.html#cb16-2" tabindex="-1"></a></span>
<span id="cb16-3"><a href="methods.html#cb16-3" tabindex="-1"></a>feat <span class="op">=</span> dc.feat.CircularFingerprint(size<span class="op">=</span><span class="dv">2048</span>, radius<span class="op">=</span><span class="dv">1</span>)</span>
<span id="cb16-4"><a href="methods.html#cb16-4" tabindex="-1"></a>morgan_fp <span class="op">=</span> feat.featurize(smiles)</span></code></pre></div>
<p>PubChem fingerprints are binary fingerprints consisting of 881 bits, each representing a particular chemical substructure or pattern. They were specifically designed for use with the PubChem database and provide detailed chemical structure encoding.</p>
<div class="sourceCode" id="cb17"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb17-1"><a href="methods.html#cb17-1" tabindex="-1"></a><span class="im">import</span> pubchempy <span class="im">as</span> pcp</span>
<span id="cb17-2"><a href="methods.html#cb17-2" tabindex="-1"></a></span>
<span id="cb17-3"><a href="methods.html#cb17-3" tabindex="-1"></a>cids <span class="op">=</span> <span class="bu">list</span>(df.pubchem_cid[df[<span class="st">'label'</span>]<span class="op">==</span><span class="st">'compound'</span>])</span>
<span id="cb17-4"><a href="methods.html#cb17-4" tabindex="-1"></a></span>
<span id="cb17-5"><a href="methods.html#cb17-5" tabindex="-1"></a>bit_list <span class="op">=</span> []</span>
<span id="cb17-6"><a href="methods.html#cb17-6" tabindex="-1"></a><span class="cf">for</span> cid <span class="kw">in</span> tqdm(cids):</span>
<span id="cb17-7"><a href="methods.html#cb17-7" tabindex="-1"></a> <span class="cf">try</span>:</span>
<span id="cb17-8"><a href="methods.html#cb17-8" tabindex="-1"></a> pubchem_compound <span class="op">=</span>pcp.get_compounds(cid)[<span class="dv">0</span>]</span>
<span id="cb17-9"><a href="methods.html#cb17-9" tabindex="-1"></a> pubchem_fp <span class="op">=</span> [<span class="bu">int</span>(bit) <span class="cf">for</span> bit <span class="kw">in</span> pubchem_compound.cactvs_fingerprint]</span>
<span id="cb17-10"><a href="methods.html#cb17-10" tabindex="-1"></a> bit_list.append(pubchem_fp)</span>
<span id="cb17-11"><a href="methods.html#cb17-11" tabindex="-1"></a> <span class="cf">except</span>:</span>
<span id="cb17-12"><a href="methods.html#cb17-12" tabindex="-1"></a> <span class="bu">print</span>(<span class="ss">f'No PubChem FP found for </span><span class="sc">{</span>cid<span class="sc">}</span><span class="ss">'</span>)</span>
<span id="cb17-13"><a href="methods.html#cb17-13" tabindex="-1"></a> bit_list.append([])</span>
<span id="cb17-14"><a href="methods.html#cb17-14" tabindex="-1"></a> </span>
<span id="cb17-15"><a href="methods.html#cb17-15" tabindex="-1"></a>pc_fp <span class="op">=</span> np.asarray(bit_list)</span></code></pre></div>
<p>The Mol2Vec fingerprint is inspired by the Word2Vec algorithm in Natural Language Processing. It considers molecules as sentences and SMILES as words, thus converting molecules into continuous vectors. This technique captures not only the presence of particular substructures but also their context within the molecule, providing a more nuanced representation.</p>
<div class="sourceCode" id="cb18"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb18-1"><a href="methods.html#cb18-1" tabindex="-1"></a><span class="im">import</span> deepchem <span class="im">as</span> dc</span>
<span id="cb18-2"><a href="methods.html#cb18-2" tabindex="-1"></a></span>
<span id="cb18-3"><a href="methods.html#cb18-3" tabindex="-1"></a>feat <span class="op">=</span> dc.feat.Mol2VecFingerprint()</span>
<span id="cb18-4"><a href="methods.html#cb18-4" tabindex="-1"></a>m2v_fp <span class="op">=</span> feat.featurize(smiles)</span></code></pre></div>
<p>In computational chemistry and drug discovery, molecules’ pre-treatment plays a crucial role in preparing them for machine learning applications. Molecules undergo optimization, where their 3D structure is refined and all possible conformations are explored. This step is vital as the 3D structure heavily influences various properties, such as reactivity and binding affinity. For Mordred and RDKit to compute all descriptors, we must optimize molecules and find their most energetically favorable conformations.</p>
<div class="sourceCode" id="cb19"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb19-1"><a href="methods.html#cb19-1" tabindex="-1"></a><span class="im">from</span> rdkit <span class="im">import</span> Chem</span>
<span id="cb19-2"><a href="methods.html#cb19-2" tabindex="-1"></a><span class="im">from</span> rdkit.Chem <span class="im">import</span> AllChem</span>
<span id="cb19-3"><a href="methods.html#cb19-3" tabindex="-1"></a><span class="im">from</span> threading <span class="im">import</span> active_count</span>
<span id="cb19-4"><a href="methods.html#cb19-4" tabindex="-1"></a></span>
<span id="cb19-5"><a href="methods.html#cb19-5" tabindex="-1"></a>num_thread <span class="op">=</span> active_count()</span>
<span id="cb19-6"><a href="methods.html#cb19-6" tabindex="-1"></a><span class="kw">def</span> optimize_3d(mol, method):</span>
<span id="cb19-7"><a href="methods.html#cb19-7" tabindex="-1"></a></span>
<span id="cb19-8"><a href="methods.html#cb19-8" tabindex="-1"></a> mol <span class="op">=</span> Chem.AddHs(mol)</span>
<span id="cb19-9"><a href="methods.html#cb19-9" tabindex="-1"></a> <span class="co"># Generate initial 3D coordinates</span></span>
<span id="cb19-10"><a href="methods.html#cb19-10" tabindex="-1"></a> params <span class="op">=</span> AllChem.ETKDG()</span>
<span id="cb19-11"><a href="methods.html#cb19-11" tabindex="-1"></a> params.useRandomCoords<span class="op">=</span><span class="va">True</span></span>
<span id="cb19-12"><a href="methods.html#cb19-12" tabindex="-1"></a> params.maxAttempts<span class="op">=</span><span class="dv">5000</span></span>
<span id="cb19-13"><a href="methods.html#cb19-13" tabindex="-1"></a> AllChem.EmbedMolecule(mol, params)</span>
<span id="cb19-14"><a href="methods.html#cb19-14" tabindex="-1"></a> <span class="cf">try</span>:</span>
<span id="cb19-15"><a href="methods.html#cb19-15" tabindex="-1"></a> <span class="cf">if</span> method <span class="op">==</span> <span class="st">'MMFF'</span>:</span>
<span id="cb19-16"><a href="methods.html#cb19-16" tabindex="-1"></a> <span class="co"># optimize the 3D structure using the MMFF method (suitable for optimizing small to medium-sized molecules)</span></span>
<span id="cb19-17"><a href="methods.html#cb19-17" tabindex="-1"></a> AllChem.MMFFOptimizeMolecule(mol, maxIters<span class="op">=</span><span class="dv">200</span>, mmffVariant<span class="op">=</span><span class="st">'MMFF94s'</span>)</span>
<span id="cb19-18"><a href="methods.html#cb19-18" tabindex="-1"></a> <span class="cf">elif</span> method <span class="op">==</span> <span class="st">'LOPT'</span>:</span>
<span id="cb19-19"><a href="methods.html#cb19-19" tabindex="-1"></a> <span class="co"># optimize the 3D structure using a combination of UFF and MMFF methods (can be used for optimizing larger and more complex molecules)</span></span>
<span id="cb19-20"><a href="methods.html#cb19-20" tabindex="-1"></a> <span class="co"># create a PyForceField object and set its parameters</span></span>
<span id="cb19-21"><a href="methods.html#cb19-21" tabindex="-1"></a> ff <span class="op">=</span> AllChem.UFFGetMoleculeForceField(mol)</span>
<span id="cb19-22"><a href="methods.html#cb19-22" tabindex="-1"></a> ff.Initialize()</span>
<span id="cb19-23"><a href="methods.html#cb19-23" tabindex="-1"></a> ff.Minimize()</span>
<span id="cb19-24"><a href="methods.html#cb19-24" tabindex="-1"></a> AllChem.OptimizeMolecule(ff, maxIters<span class="op">=</span><span class="dv">500</span>)</span>
<span id="cb19-25"><a href="methods.html#cb19-25" tabindex="-1"></a> <span class="cf">elif</span> method <span class="op">==</span> <span class="st">'CONFOPT'</span>:</span>
<span id="cb19-26"><a href="methods.html#cb19-26" tabindex="-1"></a> <span class="co"># optimize each conformation using the PyForceField object (to explore the conformational space of a molecule and identify the most energetically favorable conformations)</span></span>
<span id="cb19-27"><a href="methods.html#cb19-27" tabindex="-1"></a> <span class="co"># generate 10 conformations using UFF</span></span>
<span id="cb19-28"><a href="methods.html#cb19-28" tabindex="-1"></a> <span class="co"># create a PyForceField object and set its parameters</span></span>
<span id="cb19-29"><a href="methods.html#cb19-29" tabindex="-1"></a> AllChem.EmbedMultipleConfs(mol, numConfs<span class="op">=</span><span class="dv">10</span>)</span>
<span id="cb19-30"><a href="methods.html#cb19-30" tabindex="-1"></a> ff <span class="op">=</span> AllChem.UFFGetMoleculeForceField(mol)</span>
<span id="cb19-31"><a href="methods.html#cb19-31" tabindex="-1"></a> ff.Initialize()</span>
<span id="cb19-32"><a href="methods.html#cb19-32" tabindex="-1"></a> ff.Minimize()</span>
<span id="cb19-33"><a href="methods.html#cb19-33" tabindex="-1"></a> AllChem.OptimizeMoleculeConfs(mol, ff, maxIters<span class="op">=</span><span class="dv">300</span>, numThreads<span class="op">=</span>num_thread)</span>
<span id="cb19-34"><a href="methods.html#cb19-34" tabindex="-1"></a> <span class="cf">else</span>:</span>
<span id="cb19-35"><a href="methods.html#cb19-35" tabindex="-1"></a> <span class="bu">print</span>(<span class="ss">f"method should be from </span><span class="sc">{</span>[<span class="st">'MMFF'</span>, <span class="st">'LOPT'</span>, <span class="st">'CONFOPT'</span>]<span class="sc">}</span><span class="ss">"</span>)</span>
<span id="cb19-36"><a href="methods.html#cb19-36" tabindex="-1"></a> <span class="cf">except</span>:</span>
<span id="cb19-37"><a href="methods.html#cb19-37" tabindex="-1"></a> <span class="cf">pass</span></span>
<span id="cb19-38"><a href="methods.html#cb19-38" tabindex="-1"></a> <span class="cf">return</span> mol</span></code></pre></div>
<p>RDKit descriptors include a comprehensive set of descriptors calculated directly from the molecule’s structure. These descriptors encompass a wide range of molecular properties, including size, shape, polarity, and topological characteristics. They are widely used in QSAR modeling and virtual screening applications due to their comprehensive nature.</p>
<div class="sourceCode" id="cb20"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb20-1"><a href="methods.html#cb20-1" tabindex="-1"></a><span class="im">from</span> rdkit <span class="im">import</span> Chem</span>
<span id="cb20-2"><a href="methods.html#cb20-2" tabindex="-1"></a><span class="im">from</span> rdkit.Chem <span class="im">import</span> Descriptors</span>
<span id="cb20-3"><a href="methods.html#cb20-3" tabindex="-1"></a></span>
<span id="cb20-4"><a href="methods.html#cb20-4" tabindex="-1"></a><span class="co"># Define a function to calculate all the possible descriptors</span></span>
<span id="cb20-5"><a href="methods.html#cb20-5" tabindex="-1"></a><span class="kw">def</span> calculate_descriptors(smiles, idx):</span>
<span id="cb20-6"><a href="methods.html#cb20-6" tabindex="-1"></a> mol <span class="op">=</span> Chem.MolFromSmiles(smiles)</span>
<span id="cb20-7"><a href="methods.html#cb20-7" tabindex="-1"></a> <span class="cf">try</span>:</span>
<span id="cb20-8"><a href="methods.html#cb20-8" tabindex="-1"></a> mol <span class="op">=</span> optimize_3d(mol, <span class="st">'LOPT'</span>)</span>
<span id="cb20-9"><a href="methods.html#cb20-9" tabindex="-1"></a> <span class="cf">except</span>:</span>
<span id="cb20-10"><a href="methods.html#cb20-10" tabindex="-1"></a> <span class="cf">pass</span></span>
<span id="cb20-11"><a href="methods.html#cb20-11" tabindex="-1"></a> desc_lst <span class="op">=</span> []</span>
<span id="cb20-12"><a href="methods.html#cb20-12" tabindex="-1"></a> <span class="cf">for</span> descriptor_name, descriptor_function <span class="kw">in</span> Descriptors.descList:</span>
<span id="cb20-13"><a href="methods.html#cb20-13" tabindex="-1"></a> <span class="cf">try</span>:</span>
<span id="cb20-14"><a href="methods.html#cb20-14" tabindex="-1"></a> descriptor_value <span class="op">=</span> descriptor_function(mol)</span>
<span id="cb20-15"><a href="methods.html#cb20-15" tabindex="-1"></a> <span class="cf">if</span> descriptor_value <span class="op">==</span> pd.notnull:</span>
<span id="cb20-16"><a href="methods.html#cb20-16" tabindex="-1"></a> <span class="bu">print</span>(<span class="ss">f'No value for </span><span class="sc">{</span>descriptor_name<span class="sc">}</span><span class="ss">, output: </span><span class="sc">{</span>descriptor_value<span class="sc">}</span><span class="ss"> for </span><span class="sc">{</span>idx<span class="sc">}</span><span class="ss">:</span><span class="sc">{</span>smiles<span class="sc">}</span><span class="ss">'</span>)</span>
<span id="cb20-17"><a href="methods.html#cb20-17" tabindex="-1"></a> desc_lst.append(np.nan)</span>
<span id="cb20-18"><a href="methods.html#cb20-18" tabindex="-1"></a> <span class="cf">else</span>:</span>
<span id="cb20-19"><a href="methods.html#cb20-19" tabindex="-1"></a> desc_lst.append(descriptor_value)</span>
<span id="cb20-20"><a href="methods.html#cb20-20" tabindex="-1"></a> <span class="cf">except</span>:</span>
<span id="cb20-21"><a href="methods.html#cb20-21" tabindex="-1"></a> <span class="cf">pass</span></span>
<span id="cb20-22"><a href="methods.html#cb20-22" tabindex="-1"></a> <span class="cf">return</span> desc_lst</span>
<span id="cb20-23"><a href="methods.html#cb20-23" tabindex="-1"></a></span>
<span id="cb20-24"><a href="methods.html#cb20-24" tabindex="-1"></a>descriptor_list <span class="op">=</span> []</span>
<span id="cb20-25"><a href="methods.html#cb20-25" tabindex="-1"></a><span class="cf">for</span> idx, sml <span class="kw">in</span> <span class="bu">enumerate</span>(tqdm(smiles)):</span>
<span id="cb20-26"><a href="methods.html#cb20-26" tabindex="-1"></a> compound_desc <span class="op">=</span> calculate_descriptors(sml, idx)</span>
<span id="cb20-27"><a href="methods.html#cb20-27" tabindex="-1"></a> descriptor_list.append(compound_desc)</span>
<span id="cb20-28"><a href="methods.html#cb20-28" tabindex="-1"></a> </span>
<span id="cb20-29"><a href="methods.html#cb20-29" tabindex="-1"></a>rdkit_desc_df <span class="op">=</span> pd.DataFrame(descriptor_list, columns<span class="op">=</span>[name <span class="cf">for</span> name, _ <span class="kw">in</span> Descriptors.descList]).astype(np.float64)</span>
<span id="cb20-30"><a href="methods.html#cb20-30" tabindex="-1"></a>rdkit_desc_df <span class="op">=</span> rdkit_desc_df.dropna(axis<span class="op">=</span><span class="dv">1</span>)</span>
<span id="cb20-31"><a href="methods.html#cb20-31" tabindex="-1"></a>rdkit_desc <span class="op">=</span> rdkit_desc_df.values.astype(np.float64)</span></code></pre></div>
<p>Finally, Mordred descriptors provide a vast array of over 1600 three-dimensional, two-dimensional, and one-dimensional descriptors. These descriptors represent a wide variety of chemical information, ranging from simple atom counts and molecular weight to more complex descriptors such as electrotopological state indices and autocorrelation descriptors. The rich information provided by Mordred descriptors makes them an excellent choice for modeling complex molecular behaviors.</p>
<div class="sourceCode" id="cb21"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb21-1"><a href="methods.html#cb21-1" tabindex="-1"></a><span class="im">from</span> mordred <span class="im">import</span> Calculator, descriptors</span>
<span id="cb21-2"><a href="methods.html#cb21-2" tabindex="-1"></a></span>
<span id="cb21-3"><a href="methods.html#cb21-3" tabindex="-1"></a>molecules <span class="op">=</span> [Chem.MolFromSmiles(sml) <span class="cf">for</span> sml <span class="kw">in</span> smiles]</span>
<span id="cb21-4"><a href="methods.html#cb21-4" tabindex="-1"></a></span>
<span id="cb21-5"><a href="methods.html#cb21-5" tabindex="-1"></a><span class="co"># Define a function to calculate all the possible descriptors</span></span>
<span id="cb21-6"><a href="methods.html#cb21-6" tabindex="-1"></a><span class="kw">def</span> calculate_mordred_descriptors(mol, optimization<span class="op">=</span> <span class="st">'LOPT'</span>):</span>
<span id="cb21-7"><a href="methods.html#cb21-7" tabindex="-1"></a> mol <span class="op">=</span> optimize_3d(mol, optimization)</span>
<span id="cb21-8"><a href="methods.html#cb21-8" tabindex="-1"></a> <span class="co"># Create a Mordred calculator object</span></span>
<span id="cb21-9"><a href="methods.html#cb21-9" tabindex="-1"></a> calculator <span class="op">=</span> Calculator(descriptors)</span>
<span id="cb21-10"><a href="methods.html#cb21-10" tabindex="-1"></a> <span class="cf">return</span> calculator(mol)</span>
<span id="cb21-11"><a href="methods.html#cb21-11" tabindex="-1"></a></span>
<span id="cb21-12"><a href="methods.html#cb21-12" tabindex="-1"></a>mdrd_descriptor_list <span class="op">=</span> []</span>
<span id="cb21-13"><a href="methods.html#cb21-13" tabindex="-1"></a><span class="cf">for</span> idx, mol <span class="kw">in</span> <span class="bu">enumerate</span>(tqdm(molecules)):</span>
<span id="cb21-14"><a href="methods.html#cb21-14" tabindex="-1"></a> mol_desc <span class="op">=</span> calculate_mordred_descriptors(mol)</span>
<span id="cb21-15"><a href="methods.html#cb21-15" tabindex="-1"></a> desc <span class="op">=</span> <span class="bu">list</span>(mol_desc.asdict().values())</span>
<span id="cb21-16"><a href="methods.html#cb21-16" tabindex="-1"></a> mdrd_descriptor_list.append(desc)</span>
<span id="cb21-17"><a href="methods.html#cb21-17" tabindex="-1"></a> </span>
<span id="cb21-18"><a href="methods.html#cb21-18" tabindex="-1"></a>mordred_desc_df <span class="op">=</span> pd.DataFrame(mdrd_descriptor_list, columns<span class="op">=</span><span class="bu">list</span>(mol_desc.asdict().keys())).astype(np.float64)</span>
<span id="cb21-19"><a href="methods.html#cb21-19" tabindex="-1"></a>mordred_desc_df <span class="op">=</span> mordred_desc_df.dropna(axis<span class="op">=</span><span class="dv">1</span>)</span>
<span id="cb21-20"><a href="methods.html#cb21-20" tabindex="-1"></a>mordred_desc <span class="op">=</span> mordred_desc_df.values.astype(np.float64)</span></code></pre></div>
<p>To summarize, the featureization process leverages multiple molecular descriptors to capture molecular structures’ complexity and diversity. Each descriptor contributes unique information about the molecule, resulting in a comprehensive and informative representation.</p>
<table style="width:100%;">
<colgroup>
<col width="16%" />
<col width="16%" />
<col width="16%" />
<col width="16%" />
<col width="16%" />
<col width="16%" />
</colgroup>
<thead>
<tr class="header">
<th>Featurizing Technique</th>
<th>Description</th>
<th>Size</th>
<th>Binary</th>
<th>3D Information</th>
<th>Adjustability</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>MACCS fingerprints</td>
<td>Predefined structural fragments</td>
<td>167</td>
<td>Yes</td>
<td>No</td>
<td>No</td>
</tr>
<tr class="even">
<td>Morgan fingerprints (Circular fingerprints)</td>
<td>Hashing the environments of atoms in a molecule</td>
<td>Adjustable (2048 in the example)</td>
<td>Yes</td>
<td>No</td>
<td>Yes (Radius and length can be adjusted)</td>
</tr>
<tr class="odd">
<td>PubChem fingerprints</td>
<td>Chemical substructure or pattern</td>
<td>881</td>
<td>Yes</td>
<td>No</td>
<td>No</td>
</tr>
<tr class="even">
<td>Mol2Vec fingerprint</td>
<td>SMILES as words</td>
<td>Variable</td>
<td>No</td>
<td>No</td>
<td>No</td>
</tr>
<tr class="odd">
<td>RDKit descriptors</td>
<td>Physico-chemical descriptors</td>
<td>>200</td>
<td>No</td>
<td>Yes</td>
<td>No</td>
</tr>
<tr class="even">
<td>Mordred descriptors</td>
<td>Physico-chemical descriptors</td>
<td>>1600</td>
<td>No</td>
<td>Yes</td>
<td>No</td>
</tr>
</tbody>
</table>
</div>
<div id="featurizing-proteins" class="section level4 hasAnchor" number="2.1.3.2">
<h4><span class="header-section-number">2.1.3.2</span> Featurizing Proteins<a href="methods.html#featurizing-proteins" class="anchor-section" aria-label="Anchor link to header"></a></h4>
<p>The transformation of protein sequences into embedding vectors using models pretrained on millions of proteins is highly beneficial. These models are trained to understand protein sequence patterns, structures, and dependencies. Thus, the resulting embeddings capture a wealth of information about protein sequences, including their evolutionary context, structural features, and biological functions.</p>
<p>BioTransformers is a Python package that provides a unified API to use and evaluate several pre-trained models for protein sequences. These models transform protein sequences into meaningful numerical representations, also known as embeddings. The extracted embeddings can then be used in downstream machine learning tasks such as protein classification, clustering, or prediction of protein properties.</p>
<p>The models you’ve selected, <code>protbert</code> and <code>esm1_t34_670M_UR100</code>, are two different pre-trained models available in BioTransformers.</p>
<p><code>ProtBert</code> is a transformer-based model trained on a large corpus of protein sequences using a masked language modeling objective, similar to BERT models in natural language processing. The model’s architecture enables it to capture complex patterns and dependencies in the sequence data.</p>
<p>On the other hand, <code>esm1_t34_670M_UR100</code> is part of the ESM (Evolutionary Scale Modeling) series of models, specifically trained on a large evolutionary scale of protein sequences. This model is designed to capture evolutionary patterns and sequence conservation information, which can be highly beneficial for protein-related tasks.</p>
<div class="sourceCode" id="cb22"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb22-1"><a href="methods.html#cb22-1" tabindex="-1"></a><span class="im">from</span> biotransformers <span class="im">import</span> BioTransformers</span>
<span id="cb22-2"><a href="methods.html#cb22-2" tabindex="-1"></a><span class="im">from</span> tqdm.notebook <span class="im">import</span> tqdm</span>
<span id="cb22-3"><a href="methods.html#cb22-3" tabindex="-1"></a><span class="im">import</span> torch</span>
<span id="cb22-4"><a href="methods.html#cb22-4" tabindex="-1"></a><span class="im">import</span> numpy <span class="im">as</span> np</span>
<span id="cb22-5"><a href="methods.html#cb22-5" tabindex="-1"></a><span class="im">import</span> pandas <span class="im">as</span> pd</span>
<span id="cb22-6"><a href="methods.html#cb22-6" tabindex="-1"></a><span class="im">import</span> pickle</span>
<span id="cb22-7"><a href="methods.html#cb22-7" tabindex="-1"></a></span>
<span id="cb22-8"><a href="methods.html#cb22-8" tabindex="-1"></a><span class="kw">def</span> compute_embeddings(bio_trans, sequences, batch_size<span class="op">=</span><span class="dv">10</span>):</span>
<span id="cb22-9"><a href="methods.html#cb22-9" tabindex="-1"></a> embeddings <span class="op">=</span> np.empty((<span class="dv">0</span>,<span class="dv">1024</span>), <span class="bu">float</span>)</span>
<span id="cb22-10"><a href="methods.html#cb22-10" tabindex="-1"></a> <span class="cf">for</span> idx <span class="kw">in</span> tqdm(<span class="bu">range</span>(<span class="dv">0</span>, <span class="bu">len</span>(sequences), batch_size)):</span>
<span id="cb22-11"><a href="methods.html#cb22-11" tabindex="-1"></a> batch <span class="op">=</span> sequences[idx:idx<span class="op">+</span>batch_size]</span>
<span id="cb22-12"><a href="methods.html#cb22-12" tabindex="-1"></a> embd <span class="op">=</span> bio_trans.compute_embeddings(batch, pool_mode<span class="op">=</span><span class="st">'mean'</span>, batch_size<span class="op">=</span>batch_size, silent<span class="op">=</span><span class="va">True</span>)[<span class="st">'mean'</span>]</span>
<span id="cb22-13"><a href="methods.html#cb22-13" tabindex="-1"></a> embeddings <span class="op">=</span> np.vstack((embeddings, embd))</span>
<span id="cb22-14"><a href="methods.html#cb22-14" tabindex="-1"></a> <span class="cf">return</span> embeddings</span>
<span id="cb22-15"><a href="methods.html#cb22-15" tabindex="-1"></a></span>
<span id="cb22-16"><a href="methods.html#cb22-16" tabindex="-1"></a><span class="kw">def</span> save_embeddings(embeddings, filename):</span>
<span id="cb22-17"><a href="methods.html#cb22-17" tabindex="-1"></a> <span class="cf">with</span> <span class="bu">open</span>(filename, <span class="st">"wb"</span>) <span class="im">as</span> f:</span>
<span id="cb22-18"><a href="methods.html#cb22-18" tabindex="-1"></a> pickle.dump(embeddings, f)</span>
<span id="cb22-19"><a href="methods.html#cb22-19" tabindex="-1"></a></span>
<span id="cb22-20"><a href="methods.html#cb22-20" tabindex="-1"></a><span class="co"># Load sequences</span></span>
<span id="cb22-21"><a href="methods.html#cb22-21" tabindex="-1"></a>seq_df <span class="op">=</span> pd.read_csv(<span class="st">'sequence.tsv'</span>, sep<span class="op">=</span><span class="st">'</span><span class="ch">\t</span><span class="st">'</span>)</span>
<span id="cb22-22"><a href="methods.html#cb22-22" tabindex="-1"></a>sequences <span class="op">=</span> <span class="bu">list</span>(seq_df[<span class="st">'sequence'</span>])</span>
<span id="cb22-23"><a href="methods.html#cb22-23" tabindex="-1"></a></span>
<span id="cb22-24"><a href="methods.html#cb22-24" tabindex="-1"></a><span class="co"># Backends</span></span>
<span id="cb22-25"><a href="methods.html#cb22-25" tabindex="-1"></a>backends <span class="op">=</span> [<span class="st">"protbert"</span>, <span class="st">"esm1_t34_670M_UR100"</span>]</span>
<span id="cb22-26"><a href="methods.html#cb22-26" tabindex="-1"></a></span>
<span id="cb22-27"><a href="methods.html#cb22-27" tabindex="-1"></a><span class="cf">for</span> backend <span class="kw">in</span> backends:</span>
<span id="cb22-28"><a href="methods.html#cb22-28" tabindex="-1"></a> <span class="co"># Clear GPU memory</span></span>
<span id="cb22-29"><a href="methods.html#cb22-29" tabindex="-1"></a> torch.cuda.empty_cache()</span>
<span id="cb22-30"><a href="methods.html#cb22-30" tabindex="-1"></a> <span class="bu">print</span>(<span class="ss">f"Processing with backend: </span><span class="sc">{</span>backend<span class="sc">}</span><span class="ss">"</span>)</span>
<span id="cb22-31"><a href="methods.html#cb22-31" tabindex="-1"></a> bio_trans <span class="op">=</span> BioTransformers(backend, num_gpus<span class="op">=</span><span class="dv">1</span>)</span>
<span id="cb22-32"><a href="methods.html#cb22-32" tabindex="-1"></a> embeddings <span class="op">=</span> compute_embeddings(bio_trans, sequences)</span>
<span id="cb22-33"><a href="methods.html#cb22-33" tabindex="-1"></a> save_embeddings(embeddings, <span class="ss">f"</span><span class="sc">{</span>backend<span class="sc">}</span><span class="ss">_embeddings.pkl"</span>)</span></code></pre></div>
<p>This rich representation can be leveraged in downstream tasks, improving the performance of various bioinformatics applications such as protein function prediction, protein-protein interaction prediction, and many others. By using pre-trained embeddings, one can also significantly reduce the computational cost and complexity associated with training deep learning models from scratch on large protein datasets.</p>
</div>
<div id="featurizing-pathways" class="section level4 hasAnchor" number="2.1.3.3">
<h4><span class="header-section-number">2.1.3.3</span> Featurizing Pathways<a href="methods.html#featurizing-pathways" class="anchor-section" aria-label="Anchor link to header"></a></h4>
<p>BERT tokenizer from the Hugging Face Transformers library, a pre-trained model, was chosen for its ability to perform natural language processing tasks such as tokenization to vectorize biological pathways. This process involved splitting the text into individual tokens and encoding them as numerical IDs that could be understood by the BERT model. Padding and truncation techniques were applied to ensure consistent sequence lengths during tokenization. This step was critical as pathway descriptions often varied in length. By padding shorter sequences and truncating longer ones, uniformity was achieved.</p>
<p>This would simply allow the model recognize different pathways from each other.</p>
<div class="sourceCode" id="cb23"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb23-1"><a href="methods.html#cb23-1" tabindex="-1"></a><span class="im">from</span> transformers <span class="im">import</span> BertTokenizer</span>
<span id="cb23-2"><a href="methods.html#cb23-2" tabindex="-1"></a></span>
<span id="cb23-3"><a href="methods.html#cb23-3" tabindex="-1"></a>tokenizer <span class="op">=</span> BertTokenizer.from_pretrained(<span class="st">'bert-base-uncased'</span>)</span>
<span id="cb23-4"><a href="methods.html#cb23-4" tabindex="-1"></a>string_list <span class="op">=</span> pathway_df.select(pl.col(<span class="st">'Wiki Pathway'</span>)).to_series().to_list()</span>
<span id="cb23-5"><a href="methods.html#cb23-5" tabindex="-1"></a></span>
<span id="cb23-6"><a href="methods.html#cb23-6" tabindex="-1"></a><span class="co"># Tokenize the pathway descriptions</span></span>
<span id="cb23-7"><a href="methods.html#cb23-7" tabindex="-1"></a>tokenized_strings <span class="op">=</span> tokenizer(string_list, padding<span class="op">=</span><span class="va">True</span>, truncation<span class="op">=</span><span class="va">True</span>, return_tensors<span class="op">=</span><span class="st">'pt'</span>)</span>
<span id="cb23-8"><a href="methods.html#cb23-8" tabindex="-1"></a></span>
<span id="cb23-9"><a href="methods.html#cb23-9" tabindex="-1"></a><span class="co"># Retrieve the tokenized input IDs</span></span>
<span id="cb23-10"><a href="methods.html#cb23-10" tabindex="-1"></a>pw_vector <span class="op">=</span> tokenized_strings[<span class="st">'input_ids'</span>]</span></code></pre></div>
</div>
</div>
<div id="covid-19-bio-graph" class="section level3 hasAnchor" number="2.1.4">
<h3><span class="header-section-number">2.1.4</span> COVID-19 Bio-Graph<a href="methods.html#covid-19-bio-graph" class="anchor-section" aria-label="Anchor link to header"></a></h3>
<p>Having all the data ready a multimodal graph was built that represents a complex network of interconnected biological entities - chemicals, proteins, and pathways. The graph contains 4,293 unique chemicals, each distinguished by a high-dimensional feature vector (4,272 features) that includes biochemical properties, SMILES strings, and phenotype features. The chemicals’ high-dimensional space has been condensed into a single feature PCA1 using dimensionality reduction techniques.</p>
<div class="sourceCode" id="cb24"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb24-1"><a href="methods.html#cb24-1" tabindex="-1"></a><span class="im">from</span> torch_geometric.data <span class="im">import</span> HeteroData</span>
<span id="cb24-2"><a href="methods.html#cb24-2" tabindex="-1"></a></span>
<span id="cb24-3"><a href="methods.html#cb24-3" tabindex="-1"></a>data <span class="op">=</span> HeteroData()</span>
<span id="cb24-4"><a href="methods.html#cb24-4" tabindex="-1"></a></span>
<span id="cb24-5"><a href="methods.html#cb24-5" tabindex="-1"></a>data[<span class="st">'chemical'</span>].x <span class="op">=</span> chemical_features.to(torch.<span class="bu">float</span>) <span class="co"># [num_chemicals, num_features_chemical]</span></span>
<span id="cb24-6"><a href="methods.html#cb24-6" tabindex="-1"></a>data[<span class="st">'chemical'</span>].smiles <span class="op">=</span> chemical_smiles <span class="co"># [num_chemicals]</span></span>
<span id="cb24-7"><a href="methods.html#cb24-7" tabindex="-1"></a>data[<span class="st">'chemical'</span>].y <span class="op">=</span> chemical_y.<span class="bu">long</span>() <span class="co"># [num_chemicals]</span></span>
<span id="cb24-8"><a href="methods.html#cb24-8" tabindex="-1"></a>data[<span class="st">'chemical'</span>].pca1 <span class="op">=</span> chemical_pca1.to(torch.<span class="bu">float</span>) <span class="co"># [num_chemicals]</span></span>
<span id="cb24-9"><a href="methods.html#cb24-9" tabindex="-1"></a>data[<span class="st">'chemical'</span>].phenotype_feat <span class="op">=</span> chemical_phenotype_feat.to(torch.<span class="bu">float</span>) <span class="co"># [num_chemicals, 16]</span></span>
<span id="cb24-10"><a href="methods.html#cb24-10" tabindex="-1"></a></span>
<span id="cb24-11"><a href="methods.html#cb24-11" tabindex="-1"></a><span class="cf">for</span> f, v <span class="kw">in</span> [(<span class="st">'train'</span>, <span class="st">'train'</span>), (<span class="st">'valid'</span>, <span class="st">'val'</span>), (<span class="st">'test'</span>, <span class="st">'test'</span>)]:</span>
<span id="cb24-12"><a href="methods.html#cb24-12" tabindex="-1"></a> idx <span class="op">=</span> mask_df.select(</span>
<span id="cb24-13"><a href="methods.html#cb24-13" tabindex="-1"></a> [<span class="st">'connected_compound_gid'</span>, <span class="st">'mask'</span>]</span>
<span id="cb24-14"><a href="methods.html#cb24-14" tabindex="-1"></a> ).<span class="bu">filter</span>(</span>
<span id="cb24-15"><a href="methods.html#cb24-15" tabindex="-1"></a> pl.col(<span class="st">'mask'</span>) <span class="op">==</span> f</span>
<span id="cb24-16"><a href="methods.html#cb24-16" tabindex="-1"></a> ).select(<span class="st">'connected_compound_gid'</span>).to_numpy().flatten()</span>
<span id="cb24-17"><a href="methods.html#cb24-17" tabindex="-1"></a> idx <span class="op">=</span> torch.from_numpy(idx)</span>
<span id="cb24-18"><a href="methods.html#cb24-18" tabindex="-1"></a> maskit <span class="op">=</span> torch.zeros(data[<span class="st">'chemical'</span>].num_nodes, dtype<span class="op">=</span>torch.<span class="bu">bool</span>)</span>
<span id="cb24-19"><a href="methods.html#cb24-19" tabindex="-1"></a> maskit[idx] <span class="op">=</span> <span class="va">True</span></span>
<span id="cb24-20"><a href="methods.html#cb24-20" tabindex="-1"></a> data[<span class="st">'chemical'</span>][<span class="ss">f'</span><span class="sc">{</span>v<span class="sc">}</span><span class="ss">_mask'</span>] <span class="op">=</span> maskit</span>
<span id="cb24-21"><a href="methods.html#cb24-21" tabindex="-1"></a></span>
<span id="cb24-22"><a href="methods.html#cb24-22" tabindex="-1"></a>data[<span class="st">'protein'</span>].x <span class="op">=</span> protein_esm_embeddings.to(torch.<span class="bu">float</span>) <span class="co"># [num_proteins, num_features_protein]</span></span>
<span id="cb24-23"><a href="methods.html#cb24-23" tabindex="-1"></a>data[<span class="st">'protein'</span>].name <span class="op">=</span> protein_names <span class="co"># [num_proteins]</span></span>
<span id="cb24-24"><a href="methods.html#cb24-24" tabindex="-1"></a>data[<span class="st">'protein'</span>].seq <span class="op">=</span> protein_sequences <span class="co"># [num_proteins]</span></span>
<span id="cb24-25"><a href="methods.html#cb24-25" tabindex="-1"></a></span>
<span id="cb24-26"><a href="methods.html#cb24-26" tabindex="-1"></a>data[<span class="st">'pathway'</span>].x <span class="op">=</span> pathway_features.to(torch.<span class="bu">float</span>) <span class="co"># [num_pathways, num_features_pathway]</span></span>
<span id="cb24-27"><a href="methods.html#cb24-27" tabindex="-1"></a>data[<span class="st">'pathway'</span>].name <span class="op">=</span> pathway_names <span class="co"># [num_pathways]</span></span>
<span id="cb24-28"><a href="methods.html#cb24-28" tabindex="-1"></a></span>
<span id="cb24-29"><a href="methods.html#cb24-29" tabindex="-1"></a>data[<span class="st">'chemical'</span>, <span class="st">'bind_to'</span>, <span class="st">'protein'</span>].edge_index <span class="op">=</span> torch.from_numpy(compound_protein_deges).t().contiguous() <span class="co"># [2, num_edges_bind]</span></span>
<span id="cb24-30"><a href="methods.html#cb24-30" tabindex="-1"></a>data[<span class="st">'pathway'</span>, <span class="st">'activate_by'</span>, <span class="st">'chemical'</span>].edge_index <span class="op">=</span> torch.from_numpy(pathway_compound_edges).t().contiguous() <span class="co"># [2, num_edges_activate]</span></span>
<span id="cb24-31"><a href="methods.html#cb24-31" tabindex="-1"></a>data[<span class="st">'protein'</span>, <span class="st">'governs'</span>, <span class="st">'pathway'</span>].edge_index <span class="op">=</span> torch.from_numpy(protein_pathway_edges).t().contiguous() <span class="co"># [2, num_edges_govern]</span></span></code></pre></div>
<p>The final output of this process was a <code>HeteroData</code> object from the PyTorch Geometric library, which represents a heterogeneous graph with various types of nodes and edges. This graph-based representation of the data encapsulates the interconnected nature of the compounds, proteins, and pathways, thereby providing a comprehensive overview of the interactions and associations within the COVID-19 cell profiling data.</p>
<p>Our multimodal graph, a complex mesh of interconnected biological entities, represents a wealth of relationships between chemicals, proteins, and pathways. It illustrates the intricate dynamics prevalent in molecular biology, serving as a robust framework for advanced modeling tasks.</p>
<p>Among the 4,293 chemicals, only 3,711 have known connections to at least one protein, whereas 1,376 chemicals are isolated, meaning they lack any known protein interactions. On the other hand, from the total of 16,733 proteins, 16,727 are known to interact with chemicals, leaving 2,839 proteins without any known chemical connections.</p>
<p>The graph also models 1,117 unique biological pathways. Only 282 proteins are known to govern these pathways. Interestingly, 3,220 chemicals are linked to all pathways, underscoring chemicals’ pervasive influence in biological processes. A distinct subset of 582 chemicals connect exclusively to pathways, without any protein connections, and 6 proteins have pathway connections but no compound connections.</p>
<p>Overall, the graph includes 4,293 chemicals and 16,733 proteins that have at least one known connection, either to proteins, pathways, or both. These connections, represented by the different types of edges, symbolize various biological interactions and regulatory mechanisms. The graph’s structure, supplemented by the additional attributes of each node type, provides a comprehensive data platform for downstream tasks.</p>
<p>The graph were further masked with training, validation, and testing subsets using a stratified approach to maintain a uniform distribution of classes across all subsets. This enabled the creation of robust machine learning models capable of effectively learning from training data and generalizing to unseen data.</p>
</div>
<div id="representing-chemical-molecules-as-graph" class="section level3 hasAnchor" number="2.1.5">
<h3><span class="header-section-number">2.1.5</span> Representing Chemical Molecules as Graph<a href="methods.html#representing-chemical-molecules-as-graph" class="anchor-section" aria-label="Anchor link to header"></a></h3>
<p>In conventional drug discovery processes, chemical structures are often encoded as fixed-length feature vectors, which were explained in detail in the previous section (Featurizing). These vectors, while effective for some tasks, lack the nuanced structural information and context of the atoms and bonds within the molecule.</p>
<p>Recently, graph-based representations of molecules have gained popularity in computational chemistry and cheminformatics. In this approach, each molecule is represented as a graph, where atoms are considered as nodes and bonds as edges. This representation retains the context of the molecule, allowing for more sophisticated analysis and understanding of the molecular structure. Each atom (node) and bond (edge) can be associated with features such as atom type, bond type, atom hybridization, whether the bond is in a ring, etc. Graph convolutional networks (GCNs) can then be used to learn complex patterns from these graph-structured data.</p>
<p>The graph-based representation and the conventional vector-based representation each have their unique strengths. The graph representation can capture local structural information and long-range interactions in the molecule, while the vector-based representation can efficiently capture specific substructures or holistic properties like the physico-chemical characteristics of the molecule.</p>
<p>The initial step was to convert molecular structures into graph-based representations. This conversion was achieved using the <code>MolGraphConvFeaturizer</code> from the DeepChem library. This generated node and edge features considering additional aspects such as chirality and partial charge.</p>
<p>Two dataset classes were designed for classification task: <code>CovidMolGraph_imbalance_classification</code> and <code>CovidMolGraph_balanced_classification</code>. The imbalanced dataset will be used with weight on binary classes during the training. The balanced classification approach involved resampling the minority class in the training set to balance the class distribution, improving the model’s performance.These handled the unbalanced and balanced classifications of the dataset, respectively.</p>
<div class="sourceCode" id="cb25"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb25-1"><a href="methods.html#cb25-1" tabindex="-1"></a><span class="im">import</span> os</span>
<span id="cb25-2"><a href="methods.html#cb25-2" tabindex="-1"></a><span class="im">import</span> pickle</span>
<span id="cb25-3"><a href="methods.html#cb25-3" tabindex="-1"></a><span class="im">import</span> torch</span>
<span id="cb25-4"><a href="methods.html#cb25-4" tabindex="-1"></a><span class="im">from</span> typing <span class="im">import</span> Callable, List, Optional</span>
<span id="cb25-5"><a href="methods.html#cb25-5" tabindex="-1"></a><span class="im">from</span> sklearn <span class="im">import</span> preprocessing</span>
<span id="cb25-6"><a href="methods.html#cb25-6" tabindex="-1"></a><span class="im">from</span> tqdm <span class="im">import</span> tqdm</span>
<span id="cb25-7"><a href="methods.html#cb25-7" tabindex="-1"></a><span class="im">import</span> deepchem <span class="im">as</span> dc</span>
<span id="cb25-8"><a href="methods.html#cb25-8" tabindex="-1"></a><span class="im">import</span> polars <span class="im">as</span> pl</span>
<span id="cb25-9"><a href="methods.html#cb25-9" tabindex="-1"></a><span class="im">from</span> rdkit <span class="im">import</span> Chem</span>
<span id="cb25-10"><a href="methods.html#cb25-10" tabindex="-1"></a><span class="im">import</span> numpy <span class="im">as</span> np </span>
<span id="cb25-11"><a href="methods.html#cb25-11" tabindex="-1"></a><span class="im">from</span> sklearn.model_selection <span class="im">import</span> train_test_split</span>
<span id="cb25-12"><a href="methods.html#cb25-12" tabindex="-1"></a></span>
<span id="cb25-13"><a href="methods.html#cb25-13" tabindex="-1"></a><span class="im">from</span> torch_geometric.data <span class="im">import</span> (</span>
<span id="cb25-14"><a href="methods.html#cb25-14" tabindex="-1"></a> Data,</span>
<span id="cb25-15"><a href="methods.html#cb25-15" tabindex="-1"></a> Dataset,</span>
<span id="cb25-16"><a href="methods.html#cb25-16" tabindex="-1"></a> InMemoryDataset</span>
<span id="cb25-17"><a href="methods.html#cb25-17" tabindex="-1"></a>)</span>
<span id="cb25-18"><a href="methods.html#cb25-18" tabindex="-1"></a></span>
<span id="cb25-19"><a href="methods.html#cb25-19" tabindex="-1"></a><span class="kw">class</span> CovidMolGraph_imbalance_classification(InMemoryDataset):</span>
<span id="cb25-20"><a href="methods.html#cb25-20" tabindex="-1"></a> </span>
<span id="cb25-21"><a href="methods.html#cb25-21" tabindex="-1"></a> <span class="kw">def</span> <span class="fu">__init__</span>(<span class="va">self</span>, root: <span class="bu">str</span>, transform: Optional[Callable] <span class="op">=</span> <span class="va">None</span>,</span>
<span id="cb25-22"><a href="methods.html#cb25-22" tabindex="-1"></a> pre_transform: Optional[Callable] <span class="op">=</span> <span class="va">None</span>,</span>
<span id="cb25-23"><a href="methods.html#cb25-23" tabindex="-1"></a> pre_filter: Optional[Callable] <span class="op">=</span> <span class="va">None</span>):</span>
<span id="cb25-24"><a href="methods.html#cb25-24" tabindex="-1"></a> <span class="bu">super</span>().<span class="fu">__init__</span>(root, transform, pre_transform, pre_filter)</span>
<span id="cb25-25"><a href="methods.html#cb25-25" tabindex="-1"></a> <span class="va">self</span>.data, <span class="va">self</span>.slices <span class="op">=</span> torch.load(<span class="va">self</span>.processed_paths[<span class="dv">0</span>])</span>
<span id="cb25-26"><a href="methods.html#cb25-26" tabindex="-1"></a></span>
<span id="cb25-27"><a href="methods.html#cb25-27" tabindex="-1"></a> <span class="at">@property</span></span>
<span id="cb25-28"><a href="methods.html#cb25-28" tabindex="-1"></a> <span class="kw">def</span> processed_file_names(<span class="va">self</span>) <span class="op">-></span> <span class="bu">str</span>:</span>
<span id="cb25-29"><a href="methods.html#cb25-29" tabindex="-1"></a> <span class="cf">return</span> <span class="st">'covid_data_processed.pt'</span></span>
<span id="cb25-30"><a href="methods.html#cb25-30" tabindex="-1"></a></span>
<span id="cb25-31"><a href="methods.html#cb25-31" tabindex="-1"></a> <span class="kw">def</span> process(<span class="va">self</span>):</span>
<span id="cb25-32"><a href="methods.html#cb25-32" tabindex="-1"></a> df <span class="op">=</span> pl.read_csv(<span class="st">'covid_20230504.tsv'</span>, separator<span class="op">=</span><span class="st">'</span><span class="ch">\t</span><span class="st">'</span>).<span class="bu">filter</span>(</span>
<span id="cb25-33"><a href="methods.html#cb25-33" tabindex="-1"></a> pl.col(<span class="st">'label'</span>) <span class="op">==</span> <span class="st">'compound'</span></span>
<span id="cb25-34"><a href="methods.html#cb25-34" tabindex="-1"></a> ).with_columns(</span>
<span id="cb25-35"><a href="methods.html#cb25-35" tabindex="-1"></a> pl.col(<span class="st">'pca1'</span>).<span class="bu">apply</span>(<span class="kw">lambda</span> x: <span class="dv">1</span> <span class="cf">if</span> x <span class="op">>=</span> <span class="dv">5</span> <span class="cf">else</span> <span class="dv">0</span>).alias(<span class="st">'activity'</span>)</span>
<span id="cb25-36"><a href="methods.html#cb25-36" tabindex="-1"></a> ).with_columns(</span>
<span id="cb25-37"><a href="methods.html#cb25-37" tabindex="-1"></a> pl.lit([i <span class="cf">for</span> i <span class="kw">in</span> <span class="bu">range</span>(<span class="dv">5087</span>)]).alias(<span class="st">'xid'</span>)</span>
<span id="cb25-38"><a href="methods.html#cb25-38" tabindex="-1"></a> )</span>
<span id="cb25-39"><a href="methods.html#cb25-39" tabindex="-1"></a></span>
<span id="cb25-40"><a href="methods.html#cb25-40" tabindex="-1"></a> <span class="cf">with</span> <span class="bu">open</span>(<span class="st">"all_feat.pkl"</span>, <span class="st">"rb"</span>) <span class="im">as</span> f:</span>
<span id="cb25-41"><a href="methods.html#cb25-41" tabindex="-1"></a> chemical_features <span class="op">=</span> pickle.load(f)</span>
<span id="cb25-42"><a href="methods.html#cb25-42" tabindex="-1"></a></span>
<span id="cb25-43"><a href="methods.html#cb25-43" tabindex="-1"></a> phenotype_features <span class="op">=</span> df.columns[<span class="dv">5</span>:<span class="op">-</span><span class="dv">6</span>]</span>
<span id="cb25-44"><a href="methods.html#cb25-44" tabindex="-1"></a> smiles <span class="op">=</span> df.select([<span class="st">'pubchem_smiles'</span>]).to_numpy().flatten()</span>
<span id="cb25-45"><a href="methods.html#cb25-45" tabindex="-1"></a> y <span class="op">=</span> df.select([<span class="st">'activity'</span>]).to_numpy().flatten()</span>
<span id="cb25-46"><a href="methods.html#cb25-46" tabindex="-1"></a> pca1 <span class="op">=</span> df.select([<span class="st">'pca1'</span>]).to_numpy().flatten()</span>
<span id="cb25-47"><a href="methods.html#cb25-47" tabindex="-1"></a></span>
<span id="cb25-48"><a href="methods.html#cb25-48" tabindex="-1"></a> <span class="co"># Convert the smiles into numerical features using a featurizer from deepchem</span></span>
<span id="cb25-49"><a href="methods.html#cb25-49" tabindex="-1"></a> <span class="co"># Using MolGraphConvFeaturizer</span></span>
<span id="cb25-50"><a href="methods.html#cb25-50" tabindex="-1"></a> featurizer <span class="op">=</span> dc.feat.MolGraphConvFeaturizer(use_edges<span class="op">=</span><span class="va">True</span>, use_chirality<span class="op">=</span> <span class="va">True</span>, use_partial_charge<span class="op">=</span><span class="va">True</span>)</span>
<span id="cb25-51"><a href="methods.html#cb25-51" tabindex="-1"></a> graphs <span class="op">=</span> featurizer.featurize(smiles, y<span class="op">=</span>y)</span>
<span id="cb25-52"><a href="methods.html#cb25-52" tabindex="-1"></a> </span>
<span id="cb25-53"><a href="methods.html#cb25-53" tabindex="-1"></a> data_list <span class="op">=</span> []</span>
<span id="cb25-54"><a href="methods.html#cb25-54" tabindex="-1"></a> <span class="cf">for</span> idx, graph <span class="kw">in</span> tqdm(<span class="bu">enumerate</span>(graphs)):</span>
<span id="cb25-55"><a href="methods.html#cb25-55" tabindex="-1"></a> edge_features <span class="op">=</span> torch.from_numpy(graph.edge_features).<span class="bu">float</span>()</span>
<span id="cb25-56"><a href="methods.html#cb25-56" tabindex="-1"></a> g <span class="op">=</span> Data(x<span class="op">=</span>torch.from_numpy(graph.node_features).<span class="bu">float</span>(),</span>
<span id="cb25-57"><a href="methods.html#cb25-57" tabindex="-1"></a> edge_index<span class="op">=</span>torch.from_numpy(graph.edge_index).<span class="bu">long</span>(),</span>
<span id="cb25-58"><a href="methods.html#cb25-58" tabindex="-1"></a> edge_attr<span class="op">=</span>edge_features,</span>
<span id="cb25-59"><a href="methods.html#cb25-59" tabindex="-1"></a> y<span class="op">=</span>torch.tensor(y[idx]).<span class="bu">long</span>().unsqueeze(<span class="dv">0</span>),</span>
<span id="cb25-60"><a href="methods.html#cb25-60" tabindex="-1"></a> chem_features<span class="op">=</span>torch.from_numpy(chemical_features[idx]).<span class="bu">float</span>().unsqueeze(<span class="dv">0</span>),</span>
<span id="cb25-61"><a href="methods.html#cb25-61" tabindex="-1"></a> smiles<span class="op">=</span>smiles[idx])</span>
<span id="cb25-62"><a href="methods.html#cb25-62" tabindex="-1"></a> data_list.append(g)</span>
<span id="cb25-63"><a href="methods.html#cb25-63" tabindex="-1"></a></span>
<span id="cb25-64"><a href="methods.html#cb25-64" tabindex="-1"></a> <span class="cf">if</span> <span class="va">self</span>.pre_filter <span class="kw">is</span> <span class="kw">not</span> <span class="va">None</span>:</span>
<span id="cb25-65"><a href="methods.html#cb25-65" tabindex="-1"></a> data_list <span class="op">=</span> [data <span class="cf">for</span> data <span class="kw">in</span> data_list <span class="cf">if</span> <span class="va">self</span>.pre_filter(data)]</span>
<span id="cb25-66"><a href="methods.html#cb25-66" tabindex="-1"></a></span>
<span id="cb25-67"><a href="methods.html#cb25-67" tabindex="-1"></a> <span class="cf">if</span> <span class="va">self</span>.pre_transform <span class="kw">is</span> <span class="kw">not</span> <span class="va">None</span>:</span>
<span id="cb25-68"><a href="methods.html#cb25-68" tabindex="-1"></a> data_list <span class="op">=</span> [<span class="va">self</span>.pre_transform(data) <span class="cf">for</span> data <span class="kw">in</span> data_list]</span>
<span id="cb25-69"><a href="methods.html#cb25-69" tabindex="-1"></a></span>
<span id="cb25-70"><a href="methods.html#cb25-70" tabindex="-1"></a> data, slices <span class="op">=</span> <span class="va">self</span>.collate(data_list)</span>
<span id="cb25-71"><a href="methods.html#cb25-71" tabindex="-1"></a> torch.save((data, slices), <span class="va">self</span>.processed_paths[<span class="dv">0</span>])</span>
<span id="cb25-72"><a href="methods.html#cb25-72" tabindex="-1"></a> </span>
<span id="cb25-73"><a href="methods.html#cb25-73" tabindex="-1"></a><span class="kw">class</span> CovidMolGraph_balanced_classification(InMemoryDataset):</span>
<span id="cb25-74"><a href="methods.html#cb25-74" tabindex="-1"></a> </span>