File size: 48,210 Bytes
1699569
 
6ce67d2
1699569
 
 
6ce67d2
e5a12b8
 
 
62faff0
 
2267bcd
66e83e0
1699569
c6e3011
6ce67d2
c6e3011
ff86fbf
62faff0
c6e3011
6ce67d2
 
c6e3011
 
 
1699569
62faff0
 
 
 
 
 
 
f21967a
a6d026f
f192d73
62faff0
3559da9
f2f40f0
f192d73
afb8bf9
62faff0
3559da9
f2f40f0
afb8bf9
a6d026f
f21967a
2bba935
6ce67d2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c6e3011
e48b5b5
6ce67d2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105ed33
62faff0
2bba935
b2912c4
6ce67d2
 
 
 
 
 
1699569
e48b5b5
2267bcd
105ed33
62faff0
e48b5b5
 
 
f21967a
e32c352
6ce67d2
e32c352
 
6ce67d2
e32c352
6ce67d2
e32c352
 
6ce67d2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e32c352
 
 
105ed33
f67304b
1699569
 
 
 
c5c0a51
1699569
c5c0a51
8eb1090
6ce67d2
 
 
 
 
 
 
 
f67304b
 
6ce67d2
 
 
 
f67304b
6ce67d2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f67304b
 
6ce67d2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f67304b
6ce67d2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f67304b
6ce67d2
 
f67304b
6ce67d2
 
 
 
 
f67304b
6ce67d2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c5c0a51
1699569
6ce67d2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4b2cc15
6ce67d2
c5c0a51
 
6337933
6ce67d2
 
 
 
 
 
 
c5c0a51
e32c352
f658f80
e5a12b8
d4a2975
8eb1090
6ce67d2
 
e32c352
6ce67d2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e32c352
 
 
6337933
6ce67d2
 
e32c352
6ce67d2
e32c352
6ce67d2
e32c352
 
 
 
 
 
6ce67d2
 
 
 
 
 
 
 
 
e32c352
6ce67d2
 
 
 
e32c352
6ce67d2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e32c352
6ce67d2
e32c352
6ce67d2
 
e32c352
 
6ce67d2
 
 
e32c352
6ce67d2
 
e32c352
6ce67d2
e32c352
6ce67d2
 
 
e32c352
6ce67d2
 
 
 
e32c352
 
 
6ce67d2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8eb1090
62faff0
6ce67d2
62faff0
fb7bdf2
 
 
 
 
62faff0
fb7bdf2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2267bcd
 
8eb1090
2267bcd
6ce67d2
2267bcd
6ce67d2
2267bcd
6ce67d2
8eb1090
66e83e0
6ce67d2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f2f40f0
 
ff86fbf
 
66e83e0
 
 
 
 
 
 
 
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
import streamlit as st
import time
import concurrent.futures
import json
from gensim.models import Word2Vec
import pandas as pd
import threading
import matplotlib.pyplot as plt
import squarify
import numpy as np
import re
import urllib.request
import random
import plotly.express as px

st.set_page_config(
    page_title="Abstractalytics",
                page_icon=":microscope:",
                layout="wide", #centered
                initial_sidebar_state="auto",
                menu_items={
                    'About': "Abstractalytics is a Natural Language Processing (NLP) that harnesses Word2Vec to mine"
                             " insight from pubmed abstracts. Created by Jimmie E. Fata, PhD"
                }
                )

# Define the HTML and CSS styles
st.markdown("""
<style>
    [data-testid=stSidebar] {
        background-color: #99CCFF;
    }
</style>
""", unsafe_allow_html=True)
st.markdown("""
    <style>
    body {
        background-color: #CCFFFF;
        # color: #ffffff;
        # font-size: 1px
    }
    .stApp {
        background-color: #CCFFFF;
        # color: #ffffff;
        # font-size: 1px
    }
    </style>
    """, unsafe_allow_html=True)

st.header(":red[*Abstractalytics*]")

st.subheader("*A web app designed to explore :red[*PubMed abstracts*] for deeper understanding and fresh insights, driven "
             "by Natural Language Processing (NLP) techniques.*")

def custom_subheader(text, identifier, font_size):
    st.markdown(f"<h3 id='{identifier}' style='font-size: {font_size}px;'>{text}</h3>", unsafe_allow_html=True)

custom_subheader("Welcome to our innovative web2vec app designed to unlock the wealth of knowledge and insights hidden "
             "within PubMed abstracts! To begin, simply select a corpus that interests you. Next, enter a single keyword "
             "you wish to explore within the corpus. Abstractalytics powerful Natural Language "
             "Processing (NLP) algorithms will analyze the chosen corpus and present you with a list of top words, "
             "genes, drugs, phytochemicals, and compounds that are contextually and semantically related "
             "to your input. This advanced text-mining technique enables you to explore and understand complex "
             "relationships, uncovering new discoveries and connections in your field of research across a massive "
             "amount of abstracts. Dive in and enjoy the exploration! More oncology-related corpora comming soon.", "unique-id", 18)

st.markdown("---")

#Define the correct password
# CORRECT_PASSWORD = "123"

# Define a function to check if the password is correct
# def authenticate(password):
#     if password == CORRECT_PASSWORD:
#         return True
#     else:
#         return False
#
# # Create a Streamlit input field for the password
# password = st.text_input("Enter password:", type="password")
#
# # If the password is correct, show the app content
# if authenticate(password):
opt = st.sidebar.radio("Select a PubMed Corpus",
                           options=(
                                    'Breast Cancer corpus', 'Lung Cancer corpus'))
# if opt == "Clotting corpus":
#     model_used = ("pubmed_model_clotting")
#     num_abstracts = 45493
#     database_name = "Clotting"
# if opt == "Neuroblastoma corpus":
#     model_used = ("pubmed_model_neuroblastoma")
#     num_abstracts = 29032
#     database_name = "Neuroblastoma"
if opt == "Breast Cancer corpus":
    model_used = ("pubmed_model_breast_cancer2")
    num_abstracts = 290320
    database_name = "Breast_cancer"
if opt == "Lung Cancer corpus":
    model_used = ("lung_cancer_pubmed_model")
    num_abstracts = 210320
    database_name = "Lung_cancer"

st.header(f":blue[{database_name} Pubmed corpus.]")
text_input_value = st.text_input(f"Enter one term to search within the {database_name} corpus")
query = text_input_value
query = query.lower()
query = re.sub("[,.?!&*;:]", "", query)
query = re.sub(" ", "-", query)
# matches = [" "]
# if any([x in query for x in matches]):
#     st.write("Please only enter one term or a term without spaces")
# # query = input ("Enter your keyword(s):")
if query:
    bar = st.progress(0)
    time.sleep(.05)
    st.caption(f"Searching {num_abstracts} {database_name} PubMed abstracts covering 1990-2022")

    for i in range(10):
        bar.progress((i + 1) * 10)
        time.sleep(.1)

    # try:
    model = Word2Vec.load(f"{model_used}")  # you can continue training with the loaded model!
    words = list(model.wv.key_to_index)
    X = model.wv[model.wv.key_to_index]
    # print(model.wv['bfgf'])
    model2 = model.wv[query]
    # print(model.wv.similar_by_word('bfgf', topn=50, restrict_vocab=None))
    df = pd.DataFrame(X)

    def get_compound_ids(compound_names):
        with concurrent.futures.ThreadPoolExecutor() as executor:
            compound_ids = list(executor.map(get_compound_id, compound_names))
        return compound_ids


    import requests


    def get_compound_id(compound_name):
        url = f"http://rest.kegg.jp/find/compound/{compound_name}"
        response = requests.get(url)
        if response.status_code == 200:
            result = response.text.split('\n')
            if result[0]:
                compound_id = result[0].split('\t')[0]
                return compound_id
        return None

    # except:
    #     st.error("Term occurrence is too low - please try another term")
    #     st.stop()
    st.markdown("---")

    table = model.wv.most_similar_cosmul(query, topn=10000)
    table = (pd.DataFrame(table))
    table.index.name = 'Rank'
    table.columns = ['Word', 'SIMILARITY']

    pd.set_option('display.max_rows', None)
    table2 = table.copy()

    # st.markdown(f"<b><p style='font-family: Arial; font-size: 20px;'>Populate a treemap to visualize "
    #             f"<span style='color:red; font-style: italic;'>words</span> contextually "
    #             f"and semantically similar to <span style='color:red; font-style: italic;'>{query}</span> "
    #             f"within the <span style='color:red; font-style: italic;'>{database_name}</span> corpus.</p></b>",
    #     unsafe_allow_html=True)

    # Set the max number of words to display
    value_word = min(100, len(table2))

    st.markdown(
        f"<b><p style='font-family: Arial; font-size: 20px; font-style: Bold;'>Top <span style='color:red; font-style: italic;'>{value_word} "
        f"</span>words contextually and semantically similar to "
        f"<span style='color:red; font-style: italic;'>{query} </span>within the <span style='color:red; font-style: italic;'>{database_name}</span> corpus. "
        f"Click on the squares to expand and also the PubMed and Wikipedia links for more word information</span></p></b>",
        unsafe_allow_html=True)

    short_table = table2.head(value_word).round(2)
    short_table.index += 1
    short_table.index = (1 / short_table.index) * 10
    sizes = short_table.index.tolist()

    short_table.set_index('Word', inplace=True)
    table2["SIMILARITY"] = 'Similarity Score ' + table2.head(value_word)["SIMILARITY"].round(2).astype(str)
    rank_num = list(short_table.index.tolist())

    df = short_table
    try:
        df['text'] = short_table.index
        df['href'] = [f'https://pubmed.ncbi.nlm.nih.gov/?term={database_name}%5Bmh%5D+NOT+review%5Bpt%5D' \
                      '+AND+english%5Bla%5D+AND+hasabstract+AND+1990:2022%5Bdp%5D+AND+' + c for c in short_table.index]
        df['href2'] = [f'https://en.wikipedia.org/wiki/' + c for c in short_table.index]

        df.loc[:, 'database'] = database_name

        fig = px.treemap(df, path=[short_table.index], values=sizes, custom_data=['href', 'text', 'database', 'href2'],
                         hover_name=(table2.head(value_word)['SIMILARITY']))

        fig.update(layout_coloraxis_showscale=False)
        fig.update_layout(autosize=True, paper_bgcolor="#CCFFFF", margin=dict(t=0, b=0, l=0, r=0))
        fig.update_annotations(visible=False)
        fig.update_traces(marker=dict(cornerradius=5), root_color="#CCFFFF", hovertemplate=None,
                              hoverlabel_bgcolor="lightblue", hoverlabel_bordercolor="#000000",
                              texttemplate="<br><span "
                                           "style='font-family: Arial; font-size: 20px;'>%{customdata[1]}<br><br>"
                                           "<a href='%{customdata[0]}'>PubMed"
                                           "</a><br><br><a href='%{customdata[3]}'>Wikipedia"
                                           "</span></a>")
        fig.update_layout(uniformtext=dict(minsize=15), treemapcolorway=["lightgreen"])

        # st.pyplot(fig2)
        st.plotly_chart(fig, use_container_width=True)

        # st.caption(
        #     "Gene designation and database provided by HUGO Gene Nomenclature Committee (HGNC): https://www.genenames.org/")
        # st.caption("Gene designation add in exceptions [p21, p53, her2, her3]")

        csv = table2.head(value_word).to_csv().encode('utf-8')
        st.download_button(label=f"download top {value_word} words (csv)", data=csv,
                               file_name=f'{database_name}_words.csv', mime='text/csv')
    except:
        st.warning(
                f"This selection exceeds the number of similar words related to {query} within the {database_name} corpus, please choose a lower number")

    # st.markdown("---")
    # # st.write(short_table)
    # #
    #
    # # print()
    # # print("Human genes similar to " + str(query))
    # df1 = table.copy()
    # df2 = pd.read_csv('Human Genes.csv')
    # m = df1.Word.isin(df2.symbol)
    # df1 = df1[m]
    # df1.rename(columns={'Word': 'Human Gene'}, inplace=True)
    # df1["Human Gene"] = df1["Human Gene"].str.upper()
    # # print(df1.head(50))
    # # print()
    # # df1.head(50).to_csv("clotting_sim2.csv", index=True, header=False)
    # # time.sleep(2)
    # # Create the slider with increments of 5 up to 100
    #
    # # Set the maximum number of genes to display up to 100
    # value_gene = min(len(df1), 100)
    #
    # if value_gene > 0:
    #     # st.markdown(f"<b><p style='font-family: Arial; font-size: 20px;'>Treemap visualization of "
    #     #             f"<span style='color:red; font-style: italic;'>genes</span> contextually "
    #     #             f"and semantically similar to <span style='color:red; font-style: italic;'>{query}</span> "
    #     #             f"within the <span style='color:red; font-style: italic;'>{database_name}</span> corpus.</p></b>",
    #     #     unsafe_allow_html=True)
    #
    #     st.markdown(
    #         f"<b><p style='font-family: Arial; font-size: 20px; font-style: Bold;'>Top <span style='color:red; font-style: italic;'>{value_gene} "
    #         f"</span>genes contextually and semantically similar to "
    #         f"<span style='color:red; font-style: italic;'>{query}</span> within the <span style='color:red; font-style: italic;'>{database_name}</span> database. "
    #         f"Click on the squares to expand and also the Pubmed and GeneCard links for more gene information</span></p></b>",
    #         unsafe_allow_html=True)
    #
    #     df10 = df1.head(value_gene).copy()
    #     df10.index = (1 / df10.index) * 100000
    #     sizes = df10.index.tolist()
    #     df10.set_index('Human Gene', inplace=True)
    #
    #     df3 = df1.copy()
    #     df3["SIMILARITY"] = 'Similarity Score ' + df3.head(value_gene)["SIMILARITY"].round(2).astype(str)
    #     df3.reset_index(inplace=True)
    #     df3 = df3.rename(columns={'Human Gene': 'symbol2'})
    #     # Use df.query to get a subset of df1 based on ids in df2
    #     subset = df3.head(value_gene).query('symbol2 in @df2.symbol2')
    #     # Use merge to join the two DataFrames on id
    #     result = pd.merge(subset, df2, on='symbol2')
    #     # Show the result
    #     # print(result)
    #     # label = df10.index.tolist()
    #     # df2 = df10
    #     # print(df2)
    #     try:
    #         # Define the `text` column for labels and `href` column for links
    #         df10['text'] = df10.index
    #         df10['href'] = [f'https://pubmed.ncbi.nlm.nih.gov/?term={database_name}%5Bmh%5D+NOT+review%5Bpt%5D' \
    #                         '+AND+english%5Bla%5D+AND+hasabstract+AND+1990:2022%5Bdp%5D+AND+' + c for c in df10['text']]
    #         df10['href2'] = [f'https://www.genecards.org/cgi-bin/carddisp.pl?gene=' + c for c in df10['text']]
    #
    #         df10['name'] = [c for c in result['Approved name']]
    #         assert isinstance(df10, object)
    #         df10.loc[:, 'database'] = database_name
    #
    #         # print(df['name'])
    #
    #         # Create the treemap using `px.treemap`
    #         fig = px.treemap(df10, path=[df10['text']], values=sizes,
    #                          custom_data=['href', 'name', 'database', 'href2', 'text'],
    #                          hover_name=(df3.head(value_gene)['SIMILARITY']))
    #
    #         fig.update(layout_coloraxis_showscale=False)
    #         fig.update_layout(autosize=True, paper_bgcolor="#CCFFFF", margin=dict(t=0, b=0, l=0, r=0))
    #         fig.update_annotations(visible=False)
    #         fig.update_traces(marker=dict(cornerradius=5), root_color="#CCFFFF", hovertemplate=None,
    #                           hoverlabel_bgcolor="lightblue", hoverlabel_bordercolor="#000000",
    #                           texttemplate="<br><span style='font-family: Arial; font-size: 20px;'>%{customdata[4]}<br><br>"
    #                                        "%{customdata[1]}<br><br>"
    #                                        "<a href='%{customdata[0]}'>PubMed"
    #                                        "</a><br><br><a href='%{customdata[3]}'>GeneCard"
    #                                        "</span></a>")
    #         fig.update_layout(uniformtext=dict(minsize=15), treemapcolorway=["lightblue"])
    #         # # display the treemap in Streamlit
    #         # with treemap2:
    #
    #         # st.pyplot(fig2)
    #         st.plotly_chart(fig, use_container_width=True)
    #
    #         st.caption(
    #             "Gene designation and database provided by HUGO Gene Nomenclature Committee (HGNC): https://www.genenames.org/")
    #         st.caption("Gene designation add in exceptions [p21, p53, her2, her3]")
    #         st.caption("Gene information provided by GeneCards: https://www.genecards.org//")
    #
    #         csv = df1.head(value_gene).to_csv().encode('utf-8')
    #         st.download_button(label=f"download top {value_gene} genes (csv)", data=csv,
    #                            file_name=f'{database_name}_genes.csv', mime='text/csv')
    #
    #
    #     except:
    #         st.warning(f"No similar genes related to {query} within the {database_name} corpus were found.")

    st.markdown("---")

    df1 = table.copy()
    df2 = pd.read_csv('Human Genes.csv')
    m = df1.Word.isin(df2.symbol)
    df1 = df1[m]
    df1.rename(columns={'Word': 'Genes'}, inplace=True)
    df_len = len(df1)
    print(len(df1))

    # st.markdown(f"<b><p style='font-family: Arial; font-size: 20px;'>Populate a treemap to visualize "
    #             f"<span style='color:red; font-style: italic;'>proteins</span> contextually "
    #             f"and semantically similar to <span style='color:red; font-style: italic;'>{query}</span> "
    #             f"within the <span style='color:red; font-style: italic;'>{database_name}</span> corpus.</p></b>",
    #     unsafe_allow_html=True)

    # Set the number of proteins to display
    value_gene = min(df_len, 100)

    st.markdown(
        f"<b><p style='font-family: Arial; font-size: 20px; font-style: Bold;'>Top <span style='color:red; font-style: italic;'>{value_gene} "
        f"</span>human genes contextually and semantically similar to "
        f"<span style='color:red; font-style: italic;'>{query}  </span>within the <span style='color:red; font-style: italic;'>{database_name} </span>corpus. Click on the squares to expand and also the Pubmed and GeneCard links for more gene information</span></p></b>",
        unsafe_allow_html=True)

    df11 = df1.head(value_gene).copy()

    df11.index = (1 / df11.index) * 10000
    sizes = df11.index.tolist()

    df11.set_index('Genes', inplace=True)

    df4 = df1.copy()
    # print(df4.head(10))
    df4["SIMILARITY"] = 'Similarity Score ' + df4.head(value_gene)["SIMILARITY"].round(2).astype(str)
    df4.reset_index(inplace=True)
    # df4 = df4.rename(columns={'Protein': 'symbol2'})
    # print(df4)
    # # Use df.query to get a subset of df1 based on ids in df2
    # subset = df4.head(value_gene).query('symbol2 in @df2b.symbol2')
    # # Use merge to join the two DataFrames on id
    # result = pd.merge(subset, df2b, on='symbol2')
    # print(result)
    if value_gene <= df_len:
        # Define the `text` column for labels and `href` column for links
        df11['text'] = df11.index
        df11['href'] = [f'https://pubmed.ncbi.nlm.nih.gov/?term={database_name}%5Bmh%5D+NOT+review%5Bpt%5D' \
                            '+AND+english%5Bla%5D+AND+hasabstract+AND+1990:2022%5Bdp%5D+AND+' + c for c in df11['text']]
        df11['href2'] = [f'https://www.genecards.org/cgi-bin/carddisp.pl?gene=' + c for c in df11['text']]
        assert isinstance(df11, object)
        df11['database'] = database_name

        # df11['name'] = [c for c in result['Approved name']]

        # Create the treemap using `px.treemap`
        fig = px.treemap(df11, path=[df11['text']], values=sizes, custom_data=['href', 'database', 'href2', 'text'],
                             hover_name=(df4.head(value_gene)['SIMILARITY']))

        fig.update(layout_coloraxis_showscale=False)
        fig.update_layout(autosize=True, paper_bgcolor="#CCFFFF", margin=dict(t=0, b=0, l=0, r=0))
        fig.update_annotations(visible=False)
        fig.update_traces(marker=dict(cornerradius=5), root_color="#CCFFFF", hovertemplate=None,
                              hoverlabel_bgcolor="lightblue", hoverlabel_bordercolor="#000000",
                              texttemplate="<span style='font-family: Arial; font-size: 20px;'>%{customdata[3]}<br><br>"
                                           "<a href='%{customdata[0]}'>PubMed"
                                           "</a><br><br><a href='%{customdata[2]}'>GeneCard"
                                           "</span></a>")
        fig.update_layout(uniformtext=dict(minsize=15), treemapcolorway=["LightPink"])
        # # display the treemap in Streamlit
        # with treemap2:

        # st.pyplot(fig2)
        st.plotly_chart(fig, use_container_width=True)

        # st.caption(
        #         "Gene designation and database provided by KEGG homo sapien gene list: https://rest.kegg.jp/list/hsa")
        # st.caption("Gene information provided by GeneCards: https://www.genecards.org//")
        st.caption("Human gene designation and database provided by HUGO Gene Nomenclature Committee (HGNC): https://www.genenames.org/")
        st.caption("Gene designation add in exceptions [p21, p53, her2, her3]")
        st.caption("Gene information provided by GeneCards: https://www.genecards.org//")

        csv = df1.head(value_gene).to_csv().encode('utf-8')
        st.download_button(label=f"download top {value_gene} genes (csv)", data=csv,
                               file_name=f'{database_name}_genes.csv', mime='text/csv')


    else:
        st.warning(
                f"This selection exceeds the number of similar proteins related to {query} within the {database_name} corpus, please choose a lower number")
    st.markdown("---")
    # print()
    # print("Human genes similar to " + str(query))
    df1 = table.copy()
    df2 = pd.read_csv('kegg_drug_list_lowercase.csv')
    m = df1.Word.isin(df2.drugs)
    df1 = df1[m]
    df1.rename(columns={'Word': 'Drugs'}, inplace=True)
    df_len = len(df1)
    # print(len(df1))
    # df1["Human Gene"] = df1["Human Gene"].str.upper()
    # print(df1.head(50))
    # print()
    # df1.head(50).to_csv("clotting_sim2.csv", index=True, header=False)
    # time.sleep(2)
    # Create the slider with increments of 5 up to 100

    # Remove the slider and set the value_compound to the minimum of the number of rows in the dataframe and 100
    value_drug = min(df1.shape[0], 100)

    # st.markdown(f"<b><p style='font-family: Arial; font-size: 20px;'>Visualize "
    #             f"<span style='color:red; font-style: italic;'>KEGG compounds</span> contextually "
    #             f"and semantically similar to <span style='color:red; font-style: italic;'>{query}</span> "
    #             f"within the <span style='color:red; font-style: italic;'>{database_name}</span> corpus.</p></b>",
    #     unsafe_allow_html=True)

    st.markdown(
        f"<b><p style='font-family: Arial; font-size: 20px; font-style: Bold;'>Top <span style='color:red; font-style: italic;'>{value_drug} "
        f"</span>Drugs contextually and semantically similar to "
        f"<span style='color:red; font-style: italic;'>{query}</span> within the <span style='color:red; font-style: italic;'>{database_name}</span> corpus. Click on the squares to expand and the Pubmed and Wikipedia links for more compound information</span></p></b>",
        unsafe_allow_html=True)

    df13 = df1.head(value_drug).copy()

    df13.index = (1 / df13.index) * 10000
    sizes = df13.index.tolist()

    df13.set_index('Drugs', inplace=True)

    df6 = df1.copy()
    # print(df4.head(10))
    df6["SIMILARITY"] = 'Similarity Score ' + df6.head(value_drug)["SIMILARITY"].round(2).astype(str)
    df6.reset_index(inplace=True)
    # df4 = df4.rename(columns={'Protein': 'symbol2'})
    # print(df4)
    # # Use df.query to get a subset of df1 based on ids in df2
    # subset = df4.head(value_gene).query('symbol2 in @df2b.symbol2')
    # # Use merge to join the two DataFrames on id
    # result = pd.merge(subset, df2b, on='symbol2')
    # print(result)
    if value_drug <= df_len:
        # Define the `text` column for labels and `href` column for links
        # Reset the index
        df13.reset_index(inplace=True)

        # Replace hyphens with spaces in the 'text' column
        df13['Drugs'] = df13['Drugs'].str.replace('-', ' ')

        # Set the 'text' column back as the index
        df13.set_index('Drugs', inplace=True)
        df13['text'] = df13.index
        df13['href'] = [f'https://pubmed.ncbi.nlm.nih.gov/?term={database_name}%5Bmh%5D+NOT+review%5Bpt%5D' \
                            '+AND+english%5Bla%5D+AND+hasabstract+AND+1990:2022%5Bdp%5D+AND+' + c for c in df13['text']]
        df13['href2'] = [f'https://en.wikipedia.org/wiki/' + c for c in df13['text']]
        assert isinstance(df13, object)
        df13['database'] = database_name

        # df11['name'] = [c for c in result['Approved name']]

        # Create the treemap using `px.treemap`
        fig = px.treemap(df13, path=[df13['text']], values=sizes, custom_data=['href', 'database', 'href2', 'text'],
                             hover_name=(df6.head(value_drug)['SIMILARITY']))

        fig.update(layout_coloraxis_showscale=False)
        fig.update_layout(autosize=True, paper_bgcolor="#CCFFFF", margin=dict(t=0, b=0, l=0, r=0))
        fig.update_annotations(visible=False)
        fig.update_traces(marker=dict(cornerradius=5), root_color="#CCFFFF", hovertemplate=None,
                              hoverlabel_bgcolor="lightblue", hoverlabel_bordercolor="#000000",
                              texttemplate="<span style='font-family: Arial; font-size: 20px;'>%{customdata[3]}<br><br>"
                                           "<a href='%{customdata[0]}'>PubMed"
                                           "</a><br><br><a href='%{customdata[2]}'>Wikipedia"
                                           "</span></a>")
        fig.update_layout(uniformtext=dict(minsize=15), treemapcolorway=["Thistle"])
        # # display the treemap in Streamlit
        # with treemap2:

        # st.pyplot(fig2)
        st.plotly_chart(fig, use_container_width=True)

        st.caption(
                "Drug designation and database provided by KEGG: https://www.kegg.jp/kegg/drug/")

        csv = df1.head(value_drug).to_csv().encode('utf-8')
        st.download_button(label=f"download top {value_drug} drugs (csv)", data=csv,
                               file_name=f'{database_name}_drugs.csv', mime='text/csv')


    else:
        st.warning(
                f"This selection exceeds the number of similar drugs related to {query} within the {database_name} corpus, please choose a lower number")
    st.markdown("---")
    #
    # st.markdown("---")
    # # print()
    # # print("Human genes similar to " + str(query))
    # df1 = table.copy()
    # df2 = pd.read_csv('diseasesKegg.csv')
    # m = df1.Word.isin(df2.disease)
    # df1 = df1[m]
    # df1.rename(columns={'Word': 'Disease'}, inplace=True)
    # df_len = len(df1)
    # # print(len(df1))
    # # df1["Human Gene"] = df1["Human Gene"].str.upper()
    # # print(df1.head(50))
    # # print()
    # # df1.head(50).to_csv("clotting_sim2.csv", index=True, header=False)
    # # time.sleep(2)
    # # Create the slider with increments of 5 up to 100
    #
    # # Remove the slider and set the value_compound to the minimum of the number of rows in the dataframe and 100
    # value_disease = min(df1.shape[0], 100)
    #
    # # st.markdown(f"<b><p style='font-family: Arial; font-size: 20px;'>Visualize "
    # #             f"<span style='color:red; font-style: italic;'>KEGG compounds</span> contextually "
    # #             f"and semantically similar to <span style='color:red; font-style: italic;'>{query}</span> "
    # #             f"within the <span style='color:red; font-style: italic;'>{database_name}</span> corpus.</p></b>",
    # #     unsafe_allow_html=True)
    #
    # st.markdown(
    #     f"<b><p style='font-family: Arial; font-size: 20px; font-style: Bold;'>Top <span style='color:red; font-style: italic;'>{value_disease} "
    #     f"</span>Diseases contextually and semantically similar to "
    #     f"<span style='color:red; font-style: italic;'>{query}:</span> within the <span style='color:red; font-style: italic;'>{database_name}</span> database. Click on the squares to expand and the Pubmed and Wikipedia links for more compound information</span></p></b>",
    #     unsafe_allow_html=True)
    #
    # df14 = df1.head(value_disease).copy()
    #
    # df14.index = (1 / df14.index) * 10000
    # sizes = df14.index.tolist()
    #
    # df14.set_index('Disease', inplace=True)
    #
    # df7 = df1.copy()
    # # print(df4.head(10))
    # df7["SIMILARITY"] = 'Similarity Score ' + df7.head(value_disease)["SIMILARITY"].round(2).astype(str)
    # df7.reset_index(inplace=True)
    # # df4 = df4.rename(columns={'Protein': 'symbol2'})
    # # print(df4)
    # # # Use df.query to get a subset of df1 based on ids in df2
    # # subset = df4.head(value_gene).query('symbol2 in @df2b.symbol2')
    # # # Use merge to join the two DataFrames on id
    # # result = pd.merge(subset, df2b, on='symbol2')
    # # print(result)
    # if value_disease <= df_len:
    #     # Define the `text` column for labels and `href` column for links
    #     # Reset the index
    #     df14.reset_index(inplace=True)
    #
    #     # Replace hyphens with spaces in the 'text' column
    #     df14['Disease'] = df14['Disease'].str.replace('-', ' ')
    #
    #     # Set the 'text' column back as the index
    #     df14.set_index('Disease', inplace=True)
    #     df14['text'] = df14.index
    #     df14['href'] = [f'https://pubmed.ncbi.nlm.nih.gov/?term={database_name}%5Bmh%5D+NOT+review%5Bpt%5D' \
    #                     '+AND+english%5Bla%5D+AND+hasabstract+AND+1990:2022%5Bdp%5D+AND+' + c for c in df14['text']]
    #     df14['href2'] = [f'https://en.wikipedia.org/wiki/' + c for c in df14['text']]
    #     assert isinstance(df14, object)
    #     df14['database'] = database_name
    #
    #     # df11['name'] = [c for c in result['Approved name']]
    #
    #     # Create the treemap using `px.treemap`
    #     fig = px.treemap(df14, path=[df14['text']], values=sizes, custom_data=['href', 'database', 'href2', 'text'],
    #                      hover_name=(df7.head(value_disease)['SIMILARITY']))
    #
    #     fig.update(layout_coloraxis_showscale=False)
    #     fig.update_layout(autosize=True, paper_bgcolor="#CCFFFF", margin=dict(t=0, b=0, l=0, r=0))
    #     fig.update_annotations(visible=False)
    #     fig.update_traces(marker=dict(cornerradius=5), root_color="#CCFFFF", hovertemplate=None,
    #                       hoverlabel_bgcolor="lightblue", hoverlabel_bordercolor="#000000",
    #                       texttemplate="<span style='font-family: Arial; font-size: 20px;'>%{customdata[3]}<br><br>"
    #                                    "<a href='%{customdata[0]}'>PubMed"
    #                                    "</a><br><br><a href='%{customdata[2]}'>Wikipedia"
    #                                    "</span></a>")
    #     fig.update_layout(uniformtext=dict(minsize=15), treemapcolorway=["PaleGoldenRod"])
    #     # # display the treemap in Streamlit
    #     # with treemap2:
    #
    #     # st.pyplot(fig2)
    #     st.plotly_chart(fig, use_container_width=True)
    #
    #     st.caption("Disease designation and database provided by KEGG: https://www.genome.jp/kegg/disease/")
    #
    #     csv = df1.head(value_disease).to_csv().encode('utf-8')
    #     st.download_button(label=f"download top {value_disease} diseases (csv)", data=csv,
    #                        file_name=f'{database_name}_disease.csv', mime='text/csv')
    #
    #
    # else:
    #     st.warning(
    #         f"This selection exceeds the number of similar diseases related to {query} within the {database_name} corpus, please choose a lower number")
    # st.markdown("---")

    # st.markdown("---")
    # # print()
    # # print("Human genes similar to " + str(query))
    # df1 = table.copy()
    # df2 = pd.read_csv('pathwaysKegg.csv')
    # m = df1.Word.isin(df2.pathway)
    # df1 = df1[m]
    # df1.rename(columns={'Word': 'Pathway'}, inplace=True)
    # df_len = len(df1)
    # # print(len(df1))
    # # df1["Human Gene"] = df1["Human Gene"].str.upper()
    # # print(df1.head(50))
    # # print()
    # # df1.head(50).to_csv("clotting_sim2.csv", index=True, header=False)
    # # time.sleep(2)
    # # Create the slider with increments of 5 up to 100
    #
    # # Remove the slider and set the value_compound to the minimum of the number of rows in the dataframe and 100
    # value_pathway = min(df1.shape[0], 100)
    #
    # # st.markdown(f"<b><p style='font-family: Arial; font-size: 20px;'>Visualize "
    # #             f"<span style='color:red; font-style: italic;'>KEGG compounds</span> contextually "
    # #             f"and semantically similar to <span style='color:red; font-style: italic;'>{query}</span> "
    # #             f"within the <span style='color:red; font-style: italic;'>{database_name}</span> corpus.</p></b>",
    # #     unsafe_allow_html=True)
    #
    # st.markdown(
    #     f"<b><p style='font-family: Arial; font-size: 20px; font-style: Bold;'>Top <span style='color:red; font-style: italic;'>{value_pathway} "
    #     f"</span>Pathways contextually and semantically similar to "
    #     f"<span style='color:red; font-style: italic;'>{query}:</span> within the <span style='color:red; font-style: italic;'>{database_name}</span> database. Click on the squares to expand and the Pubmed and Wikipedia links for more compound information</span></p></b>",
    #     unsafe_allow_html=True)
    #
    # df16 = df1.head(value_pathway).copy()
    #
    # df16.index = (1 / df16.index) * 10000
    # sizes = df16.index.tolist()
    #
    # df16.set_index('Pathway', inplace=True)
    #
    # df9 = df1.copy()
    # # print(df4.head(10))
    # df9["SIMILARITY"] = 'Similarity Score ' + df9.head(value_pathway)["SIMILARITY"].round(2).astype(str)
    # df9.reset_index(inplace=True)
    # # df4 = df4.rename(columns={'Protein': 'symbol2'})
    # # print(df4)
    # # # Use df.query to get a subset of df1 based on ids in df2
    # # subset = df4.head(value_gene).query('symbol2 in @df2b.symbol2')
    # # # Use merge to join the two DataFrames on id
    # # result = pd.merge(subset, df2b, on='symbol2')
    # # print(result)
    # if value_pathway <= df_len:
    #     # Define the `text` column for labels and `href` column for links
    #     # Reset the index
    #     df16.reset_index(inplace=True)
    #
    #     # Replace hyphens with spaces in the 'text' column
    #     df16['Pathway'] = df16['Pathway'].str.replace('-', ' ')
    #
    #     # Set the 'text' column back as the index
    #     df16.set_index('Pathway', inplace=True)
    #     df16['text'] = df16.index
    #     df16['href'] = [f'https://pubmed.ncbi.nlm.nih.gov/?term={database_name}%5Bmh%5D+NOT+review%5Bpt%5D' \
    #                     '+AND+english%5Bla%5D+AND+hasabstract+AND+1990:2022%5Bdp%5D+AND+' + c for c in df16['text']]
    #     df16['href2'] = [f'https://en.wikipedia.org/wiki/' + c for c in df16['text']]
    #     assert isinstance(df16, object)
    #     df16['database'] = database_name
    #
    #     # df11['name'] = [c for c in result['Approved name']]
    #
    #     # Create the treemap using `px.treemap`
    #     fig = px.treemap(df16, path=[df16['text']], values=sizes, custom_data=['href', 'database', 'href2', 'text'],
    #                      hover_name=(df9.head(value_pathway)['SIMILARITY']))
    #
    #     fig.update(layout_coloraxis_showscale=False)
    #     fig.update_layout(autosize=True, paper_bgcolor="#CCFFFF", margin=dict(t=0, b=0, l=0, r=0))
    #     fig.update_annotations(visible=False)
    #     fig.update_traces(marker=dict(cornerradius=5), root_color="#CCFFFF", hovertemplate=None,
    #                       hoverlabel_bgcolor="lightblue", hoverlabel_bordercolor="#000000",
    #                       texttemplate="<span style='font-family: Arial; font-size: 20px;'>%{customdata[3]}<br><br>"
    #                                    "<a href='%{customdata[0]}'>PubMed"
    #                                    "</a><br><br><a href='%{customdata[2]}'>Wikipedia"
    #                                    "</span></a>")
    #     fig.update_layout(uniformtext=dict(minsize=15), treemapcolorway=["FloralWhite"])
    #     # # display the treemap in Streamlit
    #     # with treemap2:
    #
    #     # st.pyplot(fig2)
    #     st.plotly_chart(fig, use_container_width=True)
    #
    #     st.caption("Pathway designation and database provided by KEGG: https://www.genome.jp/kegg/pathway.html")
    #
    #     csv = df1.head(value_pathway).to_csv().encode('utf-8')
    #     st.download_button(label=f"download top {value_pathway} pathways (csv)", data=csv,
    #                        file_name=f'{database_name}_pathways.csv', mime='text/csv')
    #
    #
    # else:
    #     st.warning(
    #         f"This selection exceeds the number of similar pathways related to {query} within the {database_name} corpus, please choose a lower number")
    # st.markdown("---")

    st.markdown("---")
    # print()
    # print("Human genes similar to " + str(query))
    df1 = table.copy()
    df2 = pd.read_csv('phytochemicals.csv')
    m = df1.Word.isin(df2.phyto)
    df1 = df1[m]
    df1.rename(columns={'Word': 'Phytochemical'}, inplace=True)
    df_len = len(df1)
    # print(len(df1))
    # df1["Human Gene"] = df1["Human Gene"].str.upper()
    # print(df1.head(50))
    # print()
    # df1.head(50).to_csv("clotting_sim2.csv", index=True, header=False)
    # time.sleep(2)
    # Create the slider with increments of 5 up to 100

    # Remove the slider and set the value_compound to the minimum of the number of rows in the dataframe and 100
    value_phyto = min(df1.shape[0], 100)

    # st.markdown(f"<b><p style='font-family: Arial; font-size: 20px;'>Visualize "
    #             f"<span style='color:red; font-style: italic;'>KEGG compounds</span> contextually "
    #             f"and semantically similar to <span style='color:red; font-style: italic;'>{query}</span> "
    #             f"within the <span style='color:red; font-style: italic;'>{database_name}</span> corpus.</p></b>",
    #     unsafe_allow_html=True)

    st.markdown(
        f"<b><p style='font-family: Arial; font-size: 20px; font-style: Bold;'>Top <span style='color:red; font-style: italic;'>{value_phyto} "
        f"</span>Phytochemicals contextually and semantically similar to "
        f"<span style='color:red; font-style: italic;'>{query}</span> within the <span style='color:red; font-style: italic;'>{database_name}</span> corpus. "
        f"Click on the squares to expand and also the Pubmed and Wikipedia links for more compound information</span></p></b>",
        unsafe_allow_html=True)

    df15 = df1.head(value_phyto).copy()

    df15.index = (1 / df15.index) * 10000
    sizes = df15.index.tolist()

    df15.set_index('Phytochemical', inplace=True)

    df8 = df1.copy()
    # print(df4.head(10))
    df8["SIMILARITY"] = 'Similarity Score ' + df8.head(value_phyto)["SIMILARITY"].round(2).astype(str)
    df8.reset_index(inplace=True)
    # df4 = df4.rename(columns={'Protein': 'symbol2'})
    # print(df4)
    # # Use df.query to get a subset of df1 based on ids in df2
    # subset = df4.head(value_gene).query('symbol2 in @df2b.symbol2')
    # # Use merge to join the two DataFrames on id
    # result = pd.merge(subset, df2b, on='symbol2')
    # print(result)
    if value_phyto <= df_len:
        # Define the `text` column for labels and `href` column for links
        # Reset the index
        df15.reset_index(inplace=True)

        # Replace hyphens with spaces in the 'text' column
        df15['Phytochemical'] = df15['Phytochemical'].str.replace('-', ' ')

        # Set the 'text' column back as the index
        df15.set_index('Phytochemical', inplace=True)
        df15['text'] = df15.index
        df15['href'] = [f'https://pubmed.ncbi.nlm.nih.gov/?term={database_name}%5Bmh%5D+NOT+review%5Bpt%5D' \
                        '+AND+english%5Bla%5D+AND+hasabstract+AND+1990:2022%5Bdp%5D+AND+' + c for c in df15['text']]
        df15['href2'] = [f'https://en.wikipedia.org/wiki/' + c for c in df15['text']]
        assert isinstance(df15, object)
        df15['database'] = database_name

        # df11['name'] = [c for c in result['Approved name']]

        # Create the treemap using `px.treemap`
        fig = px.treemap(df15, path=[df15['text']], values=sizes, custom_data=['href', 'database', 'href2', 'text'],
                         hover_name=(df8.head(value_phyto)['SIMILARITY']))

        fig.update(layout_coloraxis_showscale=False)
        fig.update_layout(autosize=True, paper_bgcolor="#CCFFFF", margin=dict(t=0, b=0, l=0, r=0))
        fig.update_annotations(visible=False)
        fig.update_traces(marker=dict(cornerradius=5), root_color="#CCFFFF", hovertemplate=None,
                          hoverlabel_bgcolor="lightblue", hoverlabel_bordercolor="#000000",
                          texttemplate="<span style='font-family: Arial; font-size: 20px;'>%{customdata[3]}<br><br>"
                                       "<a href='%{customdata[0]}'>PubMed"
                                       "</a><br><br><a href='%{customdata[2]}'>Wikipedia"
                                       "</span></a>")
        fig.update_layout(uniformtext=dict(minsize=15), treemapcolorway=["LightSeaGreen"])
        # # display the treemap in Streamlit
        # with treemap2:

        # st.pyplot(fig2)
        st.plotly_chart(fig, use_container_width=True)

        st.caption("Phytochemical designation and database provided by PhytoHub: https://phytohub.eu/")

        csv = df1.head(value_phyto).to_csv().encode('utf-8')
        st.download_button(label=f"download top {value_phyto} phytochemicals (csv)", data=csv,
                           file_name=f'{database_name}_phytochemicals.csv', mime='text/csv')


    else:
        st.warning(
            f"This selection exceeds the number of similar pythochemicals related to {query} within the {database_name} corpus, please choose a lower number")
    st.markdown("---")

    # print()
    # print("Human genes similar to " + str(query))
    df1 = table.copy()
    df2 = pd.read_csv('kegg_compounds_lowercase.csv')
    m = df1.Word.isin(df2.compound)
    df1 = df1[m]
    df1.rename(columns={'Word': 'Compounds'}, inplace=True)
    df_len = len(df1)
    # df1["Human Gene"] = df1["Human Gene"].str.upper()
    # print(df1.head(50))
    # print()
    # df1.head(50).to_csv("clotting_sim2.csv", index=True, header=False)
    # time.sleep(2)
    # Create the slider with increments of 5 up to 100

    # Remove the slider and set the value_compound to the minimum of the number of rows in the dataframe and 100
    value_compound = min(df1.shape[0], 100)

    # st.markdown(f"<b><p style='font-family: Arial; font-size: 20px;'>Visualize "
    #             f"<span style='color:red; font-style: italic;'>KEGG compounds</span> contextually "
    #             f"and semantically similar to <span style='color:red; font-style: italic;'>{query}</span> "
    #             f"within the <span style='color:red; font-style: italic;'>{database_name}</span> corpus.</p></b>",
    #     unsafe_allow_html=True)

    st.markdown(
        f"<b><p style='font-family: Arial; font-size: 20px; font-style: Bold;'>Top <span style='color:red; font-style: italic;'>{value_compound} "
        f"</span>Compounds contextually and semantically similar to "
        f"<span style='color:red; font-style: italic;'>{query}</span> within the <span style='color:red; font-style: italic;'>{database_name}</span> corpus. "
        f"Click on the squares to expand and the Pubmed, Wikipedia, and KEGG links for more compound information (may take time to load)</span></p></b>",
        unsafe_allow_html=True)

    df12 = df1.head(value_compound).copy()

    df12.index = (1 / df12.index) * 10000
    sizes = df12.index.tolist()

    df12.set_index('Compounds', inplace=True)

    df5 = df1.copy()
    # print(df4.head(10))
    df5["SIMILARITY"] = 'Similarity Score ' + df5.head(value_compound)["SIMILARITY"].round(2).astype(str)
    df5.reset_index(inplace=True)
    # df4 = df4.rename(columns={'Protein': 'symbol2'})
    # print(df4)
    # # Use df.query to get a subset of df1 based on ids in df2
    # subset = df4.head(value_gene).query('symbol2 in @df2b.symbol2')
    # # Use merge to join the two DataFrames on id
    # result = pd.merge(subset, df2b, on='symbol2')
    # print(result)

    if value_compound <= df_len:
        # Define the `text` column for labels and `href` column for links
        # Reset the index
        df12.reset_index(inplace=True)

        # Replace hyphens with spaces in the 'text' column
        df12['Compounds'] = df12['Compounds'].str.replace('-', ' ')

        # Set the 'text' column back as the index
        df12.set_index('Compounds', inplace=True)
        df12['text'] = df12.index
        df12['href'] = [f'https://pubmed.ncbi.nlm.nih.gov/?term={database_name}%5Bmh%5D+NOT+review%5Bpt%5D' \
                        '+AND+english%5Bla%5D+AND+hasabstract+AND+1990:2022%5Bdp%5D+AND+' + c for c in df12['text']]
        df12['href2'] = [f'https://en.wikipedia.org/wiki/' + c for c in df12['text']]
        df12['href3'] = [f'https://www.genome.jp/entry/{compound_id}' for compound_id in get_compound_ids(df12['text'])]
        assert isinstance(df12, object)
        df12['database'] = database_name

        # df11['name'] = [c for c in result['Approved name']]

        # Create the treemap using `px.treemap`
        fig = px.treemap(df12, path=[df12['text']], values=sizes,
                         custom_data=['href', 'database', 'href2', 'text', 'href3'],
                         hover_name=(df5.head(value_compound)['SIMILARITY']))

        fig.update(layout_coloraxis_showscale=False)
        fig.update_layout(autosize=True, paper_bgcolor="#CCFFFF", margin=dict(t=0, b=0, l=0, r=0))
        fig.update_annotations(visible=False)
        fig.update_traces(marker=dict(cornerradius=5), root_color="#CCFFFF", hovertemplate=None,
                          hoverlabel_bgcolor="lightblue", hoverlabel_bordercolor="#000000",
                          texttemplate="<span style='font-family: Arial; font-size: 20px;'>%{customdata[3]}<br><br>"
                                       "<a href='%{customdata[0]}'>PubMed"
                                       "</a><br><br><a href='%{customdata[2]}'>Wikipedia"
                                       "</a><br><br><a href='%{customdata[4]}'>KEGG Compound Page"
                                       "</span></a>")

        fig.update_layout(uniformtext=dict(minsize=15), treemapcolorway=["LightYellow"])
        # # display the treemap in Streamlit
        # with treemap2:

        # st.pyplot(fig2)
        st.plotly_chart(fig, use_container_width=True)

        st.caption("Compound designation and database provided by KEGG: https://www.kegg.jp/kegg/compound/")

        csv = df1.head(value_compound).to_csv().encode('utf-8')
        st.download_button(label=f"download top {value_compound} compounds (csv)", data=csv,
                           file_name=f'{database_name}_compounds.csv', mime='text/csv')


    else:
        st.warning(
            f"This selection exceeds the number of similar proteins related to {query} within the {database_name} corpus, please choose a lower number")
    st.markdown("---")


    def save_comment(comment):
        with open('comments.txt', 'a') as f:
            f.write(f'{comment}\n')


    def save_comment_threaded(comment):
        t = threading.Thread(target=save_comment, args=(comment,))
        t.start()


    st.title("Abstractalytics Web App")
    st.write("We appreciate your feedback!")

    user_comment = st.text_area("Please send us your anonymous remarks/suggestions about the Abstractalytics Web App: "
                                "(app will pause while we save your comments)")

    if st.button("Submit"):
        if user_comment:
            save_comment_threaded(user_comment)
            st.success("Your comment has been saved. Thank you for your feedback!")
        else:
            st.warning("Please enter a comment before submitting.")

    st.markdown("---")

    st.subheader("Cancer-related videos")
    if query:
        idlist = []
        search_keyword = {query}
        html = urllib.request.urlopen("https://www.youtube.com/@NCIgov/search?query=cancer")
        html2 = urllib.request.urlopen("https://www.youtube.com/@CancerCenter/search?query=cancer")
        html3 = urllib.request.urlopen("https://www.youtube.com/@NorthwesternMedicine/search?query=cancer")
        html4 = urllib.request.urlopen("https://www.youtube.com/@TEDEd/search?query=cancer")
        html5 = urllib.request.urlopen("https://www.youtube.com/@CancerResearchUK/search?query=cancer")
        video_ids = re.findall(r"watch\?v=(\S{11})", html.read().decode())
        video_ids2 = re.findall(r"watch\?v=(\S{11})", html2.read().decode())
        video_ids3 = re.findall(r"watch\?v=(\S{11})", html3.read().decode())
        video_ids4 = re.findall(r"watch\?v=(\S{11})", html4.read().decode())
        video_ids5 = re.findall(r"watch\?v=(\S{11})", html5.read().decode())

        for i in video_ids2:
            video_ids.append(i)
        for i in video_ids3:
            video_ids.append(i)
        for i in video_ids4:
            video_ids.append(i)
        for i in video_ids5:
            video_ids.append(i)

        random.shuffle(video_ids)

        c1, c2, c3 = st.columns(3)

        with c1:
            st.video("https://www.youtube.com/watch?v=" + video_ids[0])
        with c2:
            st.video("https://www.youtube.com/watch?v=" + video_ids[1])
        with c3:
            st.video("https://www.youtube.com/watch?v=" + video_ids[2])
    st.markdown("---")

# else:
#     st.error("The password you entered is incorrect.")