-
Notifications
You must be signed in to change notification settings - Fork 0
/
PARPAL.py
1070 lines (853 loc) · 49.2 KB
/
PARPAL.py
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
import os
import sys
from shiny import ui, render, reactive, App
import shinyswatch
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from skimage.io import imread
from matplotlib import colors
import asyncio
from htmltools import HTML, div
## root of data
DATAROOT=os.getenv("PARPAL_DATA_LOCATION", "/data")
## Load data and compute static values
meta=pd.read_table(f"{DATAROOT}/metadata.tsv")## CHANGE HERE ##
## add DATAROOT env var to gfp path.
meta["gfp path"]= f"{DATAROOT}/" + meta['gfp path']
## Select genes of interes to choose from
genesofi=sorted(meta["pairs display"].unique().tolist())
## Select my picture colors
mycmap=colors.LinearSegmentedColormap.from_list("custom", colors=["#262626",'#83f52c'], N=50)
################################################################################
##################### ASSUMPTIONS FOR THIS TO WORK #############################
# 0 - Metadata must be in /data folder, along with all images and tables.
# 1 - There must always be two pair in each paralos pair.
# 2 - There are only 2 Tpairs for each gene pair
# 3 - Only one gene-pair at the time
# 4 - Assuming "label" is always the same in the same format.
##################### ASSUMPTIONS FOR THIS TO WORK #############################
################################################################################
# app_ui #######################################################################
app_ui = ui.page_sidebar(
## Beginnning of Sidebar
ui.sidebar(
ui.input_selectize(id = "genepairs", label = "Search for Paralogs:"
, choices= genesofi
, multiple = False
, selected = None
, remove_button = True
).add_style("font-family:Helvetica Neue;"),
ui.input_action_button("submit", "Submit", class_="btn-success").add_style("background:#7393B3; border:white; font-family:Helvetica Neue;"),
# ui.output_ui("compute"), ## loading button slowes down processes
ui.output_text_verbatim("C3G", placeholder = False).add_style("text-align:center; background:#F8F8F8; border:white; font-size:9pt; font-family:Helvetica Neue;"),
ui.h3(
HTML("<a href='https://computationalgenomics.ca/team_profiles/#GZ'>https://computationalgenomics.ca</a>")
).add_style("text-align:center; font-size:8pt; font-family:Helvetica Neue;"),
ui.output_image("C3Gimage", inline = True).add_style("text-align:center; padding:10px;"),
shinyswatch.theme.litera(),
width=400,
padding=40, ## Padding btw things inside
),
## Beginning of the main page - Intro
# INTRO - MAIN PAGE #
ui.output_image("EKimage", inline = True).add_style("text-align:center; padding-right:100px; padding-left:100px;"),
ui.h3("Introduction").add_style("text-align:center; padding:40px; font-family:Helvetica Neue; font-size:22pt;"),
ui.div(),
ui.output_text_verbatim("message", placeholder = True
).add_style("text-align:center; padding:10px; background:white; font-size:14pt; border:white; font-family:Helvetica Neue;"),
ui.h6(
"Email: ", HTML("<a href='mailto:[email protected]'>[email protected]</a>")
).add_style("text-align:center; font-size:11pt;"),
ui.h6(
"Website: ",
HTML("<a href='https://kuzmin-lab.github.io/'>https://kuzmin-lab.github.io/</a>")
).add_style("text-align:center; font-size:11pt; font-family:Helvetica Neue;"),
ui.h1(" ").add_style("text-align:center; padding-top:100px; font-family:Helvetica Neue;"),
ui.h6("Please allow for some loading time when switching between paralog pairs!"
).add_style("text-align:center; font-size:12pt; font-family:Helvetica Neue;"),
## Beginning of the tabs
ui.page_navbar(
# GENE PAIR INFO - TAB 1 #
ui.nav_panel("Scores",
ui.output_table("paralogredis",
).add_style("padding-top:100px; padding-bottom:100px; font-family:Helvetica Neue; text-align:center;"),
ui.div(),
),
# GENE PAIR FIGURES WT - TAB 2 #
ui.nav_panel("Paralog 1",
ui.h6("Wild-type background").add_style("text-align:center; font-size:12pt; font-family:Helvetica Neue; padding-top:50px; padding-bottom:0px;"),
ui.output_plot("pair1_1", width = "1000px", height = "1000px").add_style("text-align:center; padding-top:50px;"),
ui.hr(),
ui.h6("Deletion background").add_style("text-align:center; font-size:12pt; font-family:Helvetica Neue; padding-top:100px; padding-bottom:0px;"),
ui.output_plot("pair1_2", width = "1000px", height = "1000px").add_style("text-align:center; padding-top:50px;"),
),
# GENE PAIR FIGURES DELTA - TAB 3 #
ui.nav_panel("Paralog 2",
ui.h6("Wild-type background").add_style("text-align:center; font-size:12pt; font-family:Helvetica Neue; padding-top:50px; padding-bottom:0px;"),
ui.output_plot("pair2_1", width = "1000px", height = "1000px").add_style("text-align:center; padding-top:50px;"),
ui.hr(),
ui.h6("Deletion background").add_style("text-align:center; font-size:12pt; font-family:Helvetica Neue; padding-top:100px; padding-bottom:0px;"),
ui.output_plot("pair2_2", width = "1000px", height = "1000px").add_style("text-align:center; padding-top:50px;"),
),
# EXTRA PAPER DOWNLOADS - TAB 4 #
ui.nav_panel("Supplemental files",
ui.h5("Download below supp. data").add_style("text-align:center; font-size:12pt; font-family:Helvetica Neue; padding-top:50px; padding-bottom:50px;"),
ui.div(),
ui.download_link("T1", "Table S1 - Yeast strains and plasmids used in this study").add_style("font-size:11pt; font-family:Helvetica Neue;"),
ui.div(),
ui.download_link("T2", "Table S2 - Protein abundance").add_style("font-size:11pt; font-family:Helvetica Neue;"),
ui.div(),
ui.download_link("T3", "Table S3 - Manual inspection of paralog pairs and negative controls").add_style("font-size:11pt; font-family:Helvetica Neue;"),
ui.div(),
ui.download_link("T4", "Table S4 - The redistribution, relative abundance change and relocalization").add_style("font-size:11pt; font-family:Helvetica Neue;"),
ui.div(),
ui.download_link("T5", "Table S5 - Features of paralogs").add_style("font-size:11pt; font-family:Helvetica Neue;"),
ui.div(),
ui.download_link("D1", "Data S1 - Features of single cells").add_style("font-size:11pt; font-family:Helvetica Neue;"),
# ui.h6("-- Features of single cells").add_style("font-size:10pt; font-family:Helvetica Neue;"),
ui.div(""),
ui.download_link("D2", "Data S2 - Protein abundance per single cell").add_style("font-size:11pt; font-family:Helvetica Neue;"),
ui.div(),
),
# OUTSIDE DATA - TAB 5 #
ui.nav_panel("External data and resources",
ui.h6("SGD (Saccharomyces Genome Database): ").add_style("text-align:center; padding-top:100px; font-size:11pt; font-family:Helvetica Neue;"),
ui.output_ui("YLink1").add_style("text-align:center; font-size:10pt; font-family:Helvetica Neue;"),
ui.div(),
ui.h6("Trigenic interaction fraction using single and double gene deletion mutants"
).add_style("padding-top:40px; text-align:center; font-size:11pt; font-family:Helvetica Neue;"),
ui.output_ui("TI1").add_style("text-align:center; font-size:10pt; font-family:Helvetica Neue;"),
ui.output_ui("TIL").add_style("text-align:center; font-size:10pt; font-family:Helvetica Neue;"),
ui.div(),
ui.h6("Protein-protein interaction change in response to paralog deletion"
).add_style("padding-top:40px; text-align:center; font-size:10pt; font-family:Helvetica Neue;"),
ui.output_ui("PP1").add_style("text-align:center; font-size:10pt; font-family:Helvetica Neue;"),
ui.output_ui("PPL").add_style("text-align:center; font-size:10pt; font-family:Helvetica Neue;"),
ui.div(),
ui.h6("Regulation of protein level in response to paralog deletion"
).add_style("padding-top:40px; text-align:center; font-size:10pt; font-family:Helvetica Neue;"),
ui.output_ui("RP1").add_style("text-align:center; font-size:10pt; font-family:Helvetica Neue;"),
ui.output_ui("RPL").add_style("text-align:center; font-size:10pt; font-family:Helvetica Neue;"),
ui.div(),
),
id="tab",
).add_style("font-family:Helvetica Neue;"),
# REFERENCES - MAIN PAGE #
## Beginning of the closing statement.
ui.h1(" ").add_style("text-align:center; padding-top:100px; font-family:Helvetica Neue;"),
ui.h3("References").add_style("text-align:center; padding:40px; font-family:Helvetica Neue;font-size:22pt;"),
ui.output_text_verbatim("acknowledge"
).add_style("text-align:center; padding:10px; background:white; font-size:14pt; border:white; font-family:Helvetica Neue;"),
ui.h6("DOI: ",
HTML("<a href='https://doi.org/10.1101/2023.11.23.568466'>https://doi.org/10.1101/2023.11.23.568466</a>"),
).add_style("text-align:center; font-size:11pt; padding-bottom:50px; font-family:Helvetica Neue;"),
# shinyswatch.theme.minty(),
shinyswatch.theme.litera(),
title="PARPAL",## Web title
)
# Server ######################################################################
def server(input, output, session):
# ESSETNAILS #
## Add Image for side bar
@render.image
def C3Gimage():
img: ImgData = {"src": f"{DATAROOT}/images/c3g.jpg", "width": "50%"}
return img
## Set code block for sidebar
@render.text
def C3G():
return f"\n\n\n\n\n" + \
f"Website developed & maintained by: \n" + \
f"Gerardo Zapata, Brittany Greco, \n" + \
f"Rohan Dandage, Vanessa Pereira and Elena Kuzmin \n\n" + \
f"In Collaboraton with: \n" + \
f"Canadian Centre for Computational Genomics (C3G) \n"
## Make little loading feature - form submit in sidebar
@output
@render.ui
@reactive.event(input.submit)
async def compute():
with ui.Progress(min=1, max=95) as p:
p.set(message="Calculation in progress", detail="This may take a while...")
for i in range(1, 35):
p.set(i, message="Computing")
await asyncio.sleep(0.05)
return
## Add Image for main page
@render.image
def EKimage():
img: ImgData = {"src": f"{DATAROOT}/images/20240417_PARPAL_logo.png", "width": "80%"}
return img
## remake metadata table --> for gene pair
@reactive.calc
def meta2():
meta2=meta[meta["pairs display"] == input.genepairs()].sort_values(by='label', ascending=False).reset_index(drop = True)
return meta2
## make variable for the two genes
@reactive.calc
@reactive.event(input.submit)
def gene1():
meta_gene=meta2()
meta_gene[["label1", "label2"]]=meta_gene['label_display2'].str.split(" ", expand=True)
lab1=meta_gene['label1'].str.contains("-GFP")
gene1=meta_gene[lab1]["gene symbol query"].unique()[0]
return gene1
@reactive.calc
@reactive.event(input.submit)
def gene2():
meta_gene=meta2()
meta_gene[["label1", "label2"]]=meta_gene['label_display2'].str.split(" ", expand=True)
lab2=meta_gene['label2'].str.contains("-GFP")
gene2=meta_gene[lab2]["gene symbol query"].unique()[0]
return gene2
## make variable for the two genes
@reactive.calc
@reactive.event(input.submit)
def gene11():
meta_gene=meta2()
genes_of_step=meta_gene["pairs display"][1].split("-")
gene11=genes_of_step[0]
return gene11
@reactive.calc
@reactive.event(input.submit)
def gene22():
meta_gene=meta2()
genes_of_step=meta_gene["pairs display"][1].split("-")
gene22=genes_of_step[1]
return gene22
# INTRO - MAIN PAGE #
## Set code block for text example
@render.text
def message():
return f"PARPAL is a web database for single-cell imaging \n" + \
f"of protein dynamics of paralogs revealing sources of gene retention \n\n" + \
f"Database statistics: \n" + \
f"Proteins screened = 164 \n" + \
f"Paralog pairs screened = 82 \n" + \
f"Total micrographs = ~3.5K \n" + \
f"Total cells = ~460K \n\n" + \
f"For details on the PARPAL project, data and website please contact Elena Kuzmin: \n"
# GENE PAIR INFO - TAB 1 #
## New mix table
@render.table
@reactive.event(input.submit)
def paralogredis():
redis=pd.read_csv(f"{DATAROOT}/scores/TableS4_forGerardo_qvalueedited.csv", sep=',')
redis=redis[(redis['Gene'] == gene11()) | (redis['Gene'] == gene22())]
redis["No redistribution or protein abundance change"] = ""
pd.set_option('display.float_format', '{:.3e}'.format)
redis['relative abundance change, q-value']=redis['relative abundance change, q-value'].map('{:.3e}'.format).replace("e", "x10^",regex=True)
## Loop to display whole table or only the one column
if len(redis) > 0:
## Selec column
redis=redis.drop("No redistribution or protein abundance change", axis=1)
## Change name - center
redis=redis.style.format({'relative abundance change, LFC': '{:.3f}',
'redistribution score': '{:.3f}'})\
.set_properties(**{'text-align':'center', 'font-size':'10px',
'font-family':'Helvetica Neue',})\
.hide(axis='index')\
.set_table_styles([{'selector':'th', 'props':
'text-align:center; font-size:12px; font-family:Helvetica Neue; border-bottom:1.5px solid black'}])
else:
## Selec column
redis=redis[["No redistribution or protein abundance change"]]
## Change name - center
redis=redis.style.set_properties(**{'text-align': 'center', 'font-size': '20px', 'font-family': 'Helvetica Neue'})\
.set_table_styles([{'selector':'th', 'props': 'text-align: center; font-size: 20px; font-family:Helvetica Neue;'}])
return redis
# GENE PAIR FIGURES - ESSENTIALS #
## Set variable for max intensity value per replicate
@reactive.calc
@reactive.event(input.submit)
def maxs1_1():
maxs=[0]
return maxs
## Set variable for max intensity value per replicate
@reactive.calc
@reactive.event(input.submit)
def maxs1_2():
maxs=[0]
return maxs
## Set variable for max intensity value per replicate
@reactive.calc
@reactive.event(input.submit)
def maxs2_1():
maxs=[0]
return maxs
## Set variable for max intensity value per replicate
@reactive.calc
@reactive.event(input.submit)
def maxs2_2():
maxs=[0]
return maxs
# GENE PAIR FIGURES WT - TAB 2 #
## Set pair1 WT ## CHANGE HERE ##
@render.plot
@reactive.event(input.submit)
def pair1_1():## CHANGE HERE ##
meta_of_step=meta2()
meta_of_step=meta_of_step.reset_index(drop = True)
## Select First gene pair. ## CHANGE HERE ##
meta_of_step=meta_of_step[meta_of_step["gene symbol query"] == gene1()].sort_values(by=['label display'], ascending=False).reset_index(drop = True) ## CHANGE HERE
## LOOP only for NSG1-NSG2 - gene pari 1 - remove rep3
if meta_of_step['pairs display'].unique() == "NSG1-NSG2":
meta_of_step=meta_of_step[meta_of_step["replicate"] != 'replicate3'].sort_values(by=['label display'], ascending=False).reset_index(drop = True) ## CHANGE HERE
else:
meta_of_step=meta_of_step
## Set inputs
if meta_of_step['pairs display'].unique() == "RPS22A-RPS22B":
meta_gfp=meta2()
gfp_path=meta_gfp["gfp path"]
else:
gfp_path=meta_of_step["gfp path"]
## Get range of both labels
ima_range=range(meta_of_step.index.min()
, meta_of_step.index.max() + 1
)
## Get mins and maxs. ## CHANGE HERE ##
maxlist=maxs1_1()
for i in ima_range:
im1=imread(fname = gfp_path[i])
maxi=np.percentile(im1, 99.9999)
# maxi=im1.max()
maxlist.append(maxi)
maxlistT=maxlist[1:]
## make meta_of_step either WT or DELTA
meta_of_step=meta_of_step[meta_of_step["status partner"] == "WT"].sort_values(by='image id', ascending=True).reset_index(drop = True)
# meta_of_step=meta_of_step[meta_of_step["status partner"] == "DELTA"].sort_values(by='image id', ascending=True).reset_index(drop = True)
## get name of partner
name=meta_of_step['label_display2'][0]
## Set number of rows/replicates within each partner
n_rows=len(meta_of_step['replicate'].unique())
###### ensure that there is at least one replicate
if n_rows > 1:
## Set fig --> for entire set of Axs
fig = plt.figure(constrained_layout=True,figsize=(10,10))
## Set number of rows based on # of reps
subplots = fig.subfigures(n_rows, 1)
#### Set Loop for each rep
for j in range(0, n_rows):
## num -- per rep
number=int(float(j)+1)
## number of figs -- per rep
n_cols=len(meta_of_step[meta_of_step["replicate"] == meta_of_step["replicate"].unique()[j]])##CHANGE HERE##
#### if there is more than one image per replicate if statement
if n_cols > 0:
locals()["ax" + str(j)] = subplots[j].subplots(1, n_cols, sharex = True, sharey=True, squeeze = False) if n_cols == 1 else subplots[j].subplots(1, n_cols, sharex = True, sharey=True)
locals()["ax" + str(j)] = locals()["ax" + str(j)].ravel()
## Set second loop for figs -- per rep
for i in range(0, n_cols):
test=imread(fname = meta_of_step[meta_of_step["replicate"] == meta_of_step["replicate"].unique()[j]]['gfp path'].reset_index(drop = True)[i]) ##CHANGE HERE##
locals()["ax" + str(j)][i].imshow(X=test, cmap = mycmap
, vmax = np.percentile(maxlistT, 2.5)
)
locals()["ax" + str(j)][i].set_title(meta_of_step[meta_of_step["replicate"] == meta_of_step["replicate"].unique()[j]]['label display'].reset_index(drop = True)[i] + " - rep" + str(number), size=8, y=0, pad=-2, verticalalignment="top") ##CHANGE HERE##
locals()["ax" + str(j)][i].set_xticks([])
locals()["ax" + str(j)][i].set_yticks([])
locals()["ax" + str(j)][i].spines['bottom'].set_color('white')
locals()["ax" + str(j)][i].spines['top'].set_color('white')
locals()["ax" + str(j)][i].spines['right'].set_color('white')
locals()["ax" + str(j)][i].spines['left'].set_color('white')
#### else print message when there is no image within one replicate
else:
locals()["ax" + str(j)] = plt.subplots()
locals()["ax" + str(j)].axis([0, 1, 0, 1])
locals()["ax" + str(j)].tick_params(axis='x', colors='white')
locals()["ax" + str(j)].tick_params(axis='y', colors='white')
locals()["ax" + str(j)].spines['bottom'].set_color('white')
locals()["ax" + str(j)].spines['top'].set_color('white')
locals()["ax" + str(j)].spines['right'].set_color('white')
locals()["ax" + str(j)].spines['left'].set_color('white')
locals()["ax" + str(j)].set_title('No images for rep' + str(number) , size=15)## CHANGE HERE ##
return fig
## This is if there is one one rep
elif n_rows == 1:
## make new J
j=0
## num -- per rep
number=int(float(j)+1)
## number of figs -- per rep
n_cols=len(meta_of_step[meta_of_step["replicate"] == meta_of_step["replicate"].unique()[j]])##CHANGE HERE##
fig, axs = plt.subplots(1, n_cols, sharex = True, sharey=True, figsize=(5, 5))
axs = axs.ravel()
## Loop per axs
for i in range(0, n_cols):
test=imread(fname = meta_of_step[meta_of_step["replicate"] == meta_of_step["replicate"].unique()[j]]['gfp path'].reset_index(drop = True)[i]) ##CHANGE HERE##
axs[i].imshow(X=test, cmap = mycmap
, vmax = np.percentile(maxlistT, 2.5)
)
axs[i].set_title(meta_of_step[meta_of_step["replicate"] == meta_of_step["replicate"].unique()[j]]['label display'].reset_index(drop = True)[i] + " - rep" + str(number), size=8, y=0, pad=-2, verticalalignment="top") ##CHANGE HERE##
axs[i].set_xticks([])
axs[i].set_yticks([])
axs[i].spines['bottom'].set_color('white')
axs[i].spines['top'].set_color('white')
axs[i].spines['right'].set_color('white')
axs[i].spines['left'].set_color('white')
return fig
###### else print message for all missing replicates - no figures
else:
## Notification "figure" for no image replicate
fig, ax = plt.subplots()
ax.axis([0, 1, 0, 1])
ax.tick_params(axis='x', colors='white')
ax.tick_params(axis='y', colors='white')
ax.spines['bottom'].set_color('white')
ax.spines['top'].set_color('white')
ax.spines['right'].set_color('white')
ax.spines['left'].set_color('white')
ax.set_title('No replicates for ' + str(name) , size=15)## CHANGE HERE ##
return fig
## Set pair1 DELTA ## CHANGE HERE ##
@render.plot
@reactive.event(input.submit)
def pair1_2():## CHANGE HERE ##
meta_of_step=meta2()
meta_of_step=meta_of_step.reset_index(drop = True)
## Select First gene pair. ## CHANGE HERE ##
meta_of_step=meta_of_step[meta_of_step["gene symbol query"] == gene1()].sort_values(by=['label display'], ascending=False).reset_index(drop = True) ## CHANGE HERE
## LOOP only for NSG1-NSG2 - gene pari 1 - remove rep3
if meta_of_step['pairs display'].unique() == "NSG1-NSG2":
meta_of_step=meta_of_step[meta_of_step["replicate"] != 'replicate3'].sort_values(by=['label display'], ascending=False).reset_index(drop = True) ## CHANGE HERE
else:
meta_of_step=meta_of_step
## Set inputs
if meta_of_step['pairs display'].unique() == "RPS22A-RPS22B":
meta_gfp=meta2()
gfp_path=meta_gfp["gfp path"]
else:
gfp_path=meta_of_step["gfp path"]
## Get range of both labels
ima_range=range(meta_of_step.index.min()
, meta_of_step.index.max() + 1
)
## Get mins and maxs. ## CHANGE HERE ##
maxlist=maxs1_2()
for i in ima_range:
im1=imread(fname = gfp_path[i])
maxi=np.percentile(im1, 99.9999)
maxlist.append(maxi)
maxlistT=maxlist[1:]
## make meta_of_step either WT or DELTA. ## CHANGE HERE ##
# meta_of_step=meta_of_step[meta_of_step["status partner"] == "WT"].sort_values(by='image id', ascending=True).reset_index(drop = True)
meta_of_step=meta_of_step[meta_of_step["status partner"] == "DELTA"].sort_values(by='image id', ascending=True).reset_index(drop = True)
## get name of partner
name=meta_of_step['label_display2'][0]
## Set number of rows/replicates within each partner
n_rows=len(meta_of_step['replicate'].unique())
###### ensure that there is at least one replicate
if n_rows > 1:
## Set fig --> for entire set of Axs
fig = plt.figure(constrained_layout=True,figsize=(10,10))
## Set number of rows based on # of reps
subplots = fig.subfigures(n_rows, 1)
#### Set Loop for each rep
for j in range(0, n_rows):
## num -- per rep
number=int(float(j)+1)
## number of figs -- per rep
n_cols=len(meta_of_step[meta_of_step["replicate"] == meta_of_step["replicate"].unique()[j]])##CHANGE HERE##
#### if there is more than one image per replicate if statement
if n_cols > 0:
locals()["ax" + str(j)] = subplots[j].subplots(1, n_cols, sharex = True, sharey=True, squeeze = False) if n_cols == 1 else subplots[j].subplots(1, n_cols, sharex = True, sharey=True)
locals()["ax" + str(j)] = locals()["ax" + str(j)].ravel()
## Set second loop for figs -- per rep
for i in range(0, n_cols):
test=imread(fname = meta_of_step[meta_of_step["replicate"] == meta_of_step["replicate"].unique()[j]]['gfp path'].reset_index(drop = True)[i]) ##CHANGE HERE##
locals()["ax" + str(j)][i].imshow(X=test, cmap = mycmap
, vmax = np.percentile(maxlistT, 2.5)
)
locals()["ax" + str(j)][i].set_title(meta_of_step[meta_of_step["replicate"] == meta_of_step["replicate"].unique()[j]]['label display'].reset_index(drop = True)[i] + " - rep" + str(number), size=8, y=0, pad=-2, verticalalignment="top") ##CHANGE HERE##
locals()["ax" + str(j)][i].set_xticks([])
locals()["ax" + str(j)][i].set_yticks([])
locals()["ax" + str(j)][i].spines['bottom'].set_color('white')
locals()["ax" + str(j)][i].spines['top'].set_color('white')
locals()["ax" + str(j)][i].spines['right'].set_color('white')
locals()["ax" + str(j)][i].spines['left'].set_color('white')
#### else print message when there is no image within one replicate
else:
locals()["ax" + str(j)] = plt.subplots()
locals()["ax" + str(j)].axis([0, 1, 0, 1])
locals()["ax" + str(j)].tick_params(axis='x', colors='white')
locals()["ax" + str(j)].tick_params(axis='y', colors='white')
locals()["ax" + str(j)].spines['bottom'].set_color('white')
locals()["ax" + str(j)].spines['top'].set_color('white')
locals()["ax" + str(j)].spines['right'].set_color('white')
locals()["ax" + str(j)].spines['left'].set_color('white')
locals()["ax" + str(j)].set_title('No images for rep' + str(number) , size=15)## CHANGE HERE ##
return fig
## This is if there is one one rep
elif n_rows == 1:
## make new J
j=0
## num -- per rep
number=int(float(j)+1)
## number of figs -- per rep
n_cols=len(meta_of_step[meta_of_step["replicate"] == meta_of_step["replicate"].unique()[j]])##CHANGE HERE##
fig, axs = plt.subplots(1, n_cols, sharex = True, sharey=True, figsize=(5, 5))
axs = axs.ravel()
## Loop per axs
for i in range(0, n_cols):
test=imread(fname = meta_of_step[meta_of_step["replicate"] == meta_of_step["replicate"].unique()[j]]['gfp path'].reset_index(drop = True)[i]) ##CHANGE HERE##
axs[i].imshow(X=test, cmap = mycmap
, vmax = np.percentile(maxlistT, 2.5)
)
axs[i].set_title(meta_of_step[meta_of_step["replicate"] == meta_of_step["replicate"].unique()[j]]['label display'].reset_index(drop = True)[i] + " - rep" + str(number), size=8, y=0, pad=-2, verticalalignment="top") ##CHANGE HERE##
axs[i].set_xticks([])
axs[i].set_yticks([])
axs[i].spines['bottom'].set_color('white')
axs[i].spines['top'].set_color('white')
axs[i].spines['right'].set_color('white')
axs[i].spines['left'].set_color('white')
return fig
###### else print message for all missing replicates - no figures
else:
## Notification "figure" for no image replicate
fig, ax = plt.subplots()
ax.axis([0, 1, 0, 1])
ax.tick_params(axis='x', colors='white')
ax.tick_params(axis='y', colors='white')
ax.spines['bottom'].set_color('white')
ax.spines['top'].set_color('white')
ax.spines['right'].set_color('white')
ax.spines['left'].set_color('white')
ax.set_title('No replicates for ' + str(name) , size=15)## CHANGE HERE ##
return fig
# GENE PAIR FIGURES DELTA - TAB 3 #
## Set pair2 WT ## CHANGE HERE ##
@render.plot
@reactive.event(input.submit)
def pair2_1():## CHANGE HERE ##
meta_of_step=meta2()
meta_of_step=meta_of_step.reset_index(drop = True)
## Select SECOND gene pair. ## CHANGE HERE ##
meta_of_step=meta_of_step[meta_of_step["gene symbol query"] == gene2()].sort_values(by=['label display'], ascending=False).reset_index(drop = True) ## CHANGE HERE
## Set inputs
if meta_of_step['pairs display'].unique() == "RPS22A-RPS22B":
meta_gfp=meta2()
gfp_path=meta_gfp["gfp path"]
else:
gfp_path=meta_of_step["gfp path"]
## Get range of both labels
ima_range=range(meta_of_step.index.min()
, meta_of_step.index.max() + 1
)
## Get mins and maxs. ## CHANGE HERE ##
maxlist=maxs2_1()
for i in ima_range:
im1=imread(fname = gfp_path[i])
maxi=np.percentile(im1, 99.9999)
maxlist.append(maxi)
maxlistT=maxlist[1:]
## make meta_of_step either WT or DELTA
meta_of_step=meta_of_step[meta_of_step["status partner"] == "WT"].sort_values(by='image id', ascending=True).reset_index(drop = True)
# meta_of_step=meta_of_step[meta_of_step["status partner"] == "DELTA"].sort_values(by='image id', ascending=True).reset_index(drop = True)
## get name of partner
name=meta_of_step['label_display2'][0]
## Set number of rows/replicates within each partner
n_rows=len(meta_of_step['replicate'].unique())
###### ensure that there is at least one replicate
if n_rows > 1:
## Set fig --> for entire set of Axs
fig = plt.figure(constrained_layout=True,figsize=(10,10))
## Set number of rows based on # of reps
subplots = fig.subfigures(n_rows, 1)
#### Set Loop for each rep
for j in range(0, n_rows):
## num -- per rep
number=int(float(j)+1)
## number of figs -- per rep
n_cols=len(meta_of_step[meta_of_step["replicate"] == meta_of_step["replicate"].unique()[j]])##CHANGE HERE##
#### if there is more than one image per replicate if statement
if n_cols > 0:
locals()["ax" + str(j)] = subplots[j].subplots(1, n_cols, sharex = True, sharey=True, squeeze = False) if n_cols == 1 else subplots[j].subplots(1, n_cols, sharex = True, sharey=True)
locals()["ax" + str(j)] = locals()["ax" + str(j)].ravel()
## Set second loop for figs -- per rep
for i in range(0, n_cols):
test=imread(fname = meta_of_step[meta_of_step["replicate"] == meta_of_step["replicate"].unique()[j]]['gfp path'].reset_index(drop = True)[i]) ##CHANGE HERE##
locals()["ax" + str(j)][i].imshow(X=test, cmap = mycmap
, vmax = np.percentile(maxlistT, 2.5)
)
locals()["ax" + str(j)][i].set_title(meta_of_step[meta_of_step["replicate"] == meta_of_step["replicate"].unique()[j]]['label display'].reset_index(drop = True)[i] + " - rep" + str(number), size=8, y=0, pad=-2, verticalalignment="top") ##CHANGE HERE##
locals()["ax" + str(j)][i].set_xticks([])
locals()["ax" + str(j)][i].set_yticks([])
locals()["ax" + str(j)][i].spines['bottom'].set_color('white')
locals()["ax" + str(j)][i].spines['top'].set_color('white')
locals()["ax" + str(j)][i].spines['right'].set_color('white')
locals()["ax" + str(j)][i].spines['left'].set_color('white')
#### else print message when there is no image within one replicate
else:
locals()["ax" + str(j)] = plt.subplots()
locals()["ax" + str(j)].axis([0, 1, 0, 1])
locals()["ax" + str(j)].tick_params(axis='x', colors='white')
locals()["ax" + str(j)].tick_params(axis='y', colors='white')
locals()["ax" + str(j)].spines['bottom'].set_color('white')
locals()["ax" + str(j)].spines['top'].set_color('white')
locals()["ax" + str(j)].spines['right'].set_color('white')
locals()["ax" + str(j)].spines['left'].set_color('white')
locals()["ax" + str(j)].set_title('No images for rep' + str(number) , size=15)## CHANGE HERE ##
return fig
## This is if there is one one rep
elif n_rows == 1:
## make new J
j=0
## num -- per rep
number=int(float(j)+1)
## number of figs -- per rep
n_cols=len(meta_of_step[meta_of_step["replicate"] == meta_of_step["replicate"].unique()[j]])##CHANGE HERE##
fig, axs = plt.subplots(1, n_cols, sharex = True, sharey=True, figsize=(5, 5))
axs = axs.ravel()
## Loop per axs
for i in range(0, n_cols):
test=imread(fname = meta_of_step[meta_of_step["replicate"] == meta_of_step["replicate"].unique()[j]]['gfp path'].reset_index(drop = True)[i]) ##CHANGE HERE##
axs[i].imshow(X=test, cmap = mycmap
, vmax = np.percentile(maxlistT, 2.5)
)
axs[i].set_title("\n\n\n" + meta_of_step[meta_of_step["replicate"] == meta_of_step["replicate"].unique()[j]]['label display'].reset_index(drop = True)[i] + " - rep" + str(number), size=8, y=0, pad=-2, verticalalignment="top") ##CHANGE HERE##
axs[i].set_xticks([])
axs[i].set_yticks([])
axs[i].spines['bottom'].set_color('white')
axs[i].spines['top'].set_color('white')
axs[i].spines['right'].set_color('white')
axs[i].spines['left'].set_color('white')
return fig
###### else print message for all missing replicates - no figures
else:
## Notification "figure" for no image replicate
fig, ax = plt.subplots()
ax.axis([0, 1, 0, 1])
ax.tick_params(axis='x', colors='white')
ax.tick_params(axis='y', colors='white')
ax.spines['bottom'].set_color('white')
ax.spines['top'].set_color('white')
ax.spines['right'].set_color('white')
ax.spines['left'].set_color('white')
ax.set_title('No replicates for ' + str(name) , size=15)## CHANGE HERE ##
return fig
## Set pair2 DELTA ## CHANGE HERE ##
@render.plot
@reactive.event(input.submit)
def pair2_2():## CHANGE HERE ##
meta_of_step=meta2()
meta_of_step=meta_of_step.reset_index(drop = True)
## Select SECOND gene pair. ## CHANGE HERE ##
meta_of_step=meta_of_step[meta_of_step["gene symbol query"] == gene2()].sort_values(by=['label display'], ascending=False).reset_index(drop = True) ## CHANGE HERE
## Set inputs
if meta_of_step['pairs display'].unique() == "RPS22A-RPS22B":
meta_gfp=meta2()
gfp_path=meta_gfp["gfp path"]
else:
gfp_path=meta_of_step["gfp path"]
## Get range of both labels
ima_range=range(meta_of_step.index.min()
, meta_of_step.index.max() + 1
)
## Get mins and maxs. ## CHANGE HERE ##
maxlist=maxs2_2()
for i in ima_range:
im1=imread(fname = gfp_path[i])
maxi=np.percentile(im1, 99.9999)
maxlist.append(maxi)
maxlistT=maxlist[1:]
## make meta_of_step either WT or DELTA. ## CHANGE HERE ##
# meta_of_step=meta_of_step[meta_of_step["status partner"] == "WT"].sort_values(by='image id', ascending=True).reset_index(drop = True)
meta_of_step=meta_of_step[meta_of_step["status partner"] == "DELTA"].sort_values(by='image id', ascending=True).reset_index(drop = True)
## get name of partner
name=meta_of_step['label_display2'][0]
## Set number of rows/replicates within each partner
n_rows=len(meta_of_step['replicate'].unique())
###### ensure that there is at least one replicate
if n_rows > 1:
## Set fig --> for entire set of Axs
fig = plt.figure(constrained_layout=True,figsize=(10,10))
## Set number of rows based on # of reps
subplots = fig.subfigures(n_rows, 1)
#### Set Loop for each rep
for j in range(0, n_rows):
## num -- per rep
number=int(float(j)+1)
## number of figs -- per rep
n_cols=len(meta_of_step[meta_of_step["replicate"] == meta_of_step["replicate"].unique()[j]])##CHANGE HERE##
#### if there is more than one image per replicate if statement
if n_cols > 0:
locals()["ax" + str(j)] = subplots[j].subplots(1, n_cols, sharex = True, sharey=True, squeeze = False) if n_cols == 1 else subplots[j].subplots(1, n_cols, sharex = True, sharey=True)
locals()["ax" + str(j)] = locals()["ax" + str(j)].ravel()
## Set second loop for figs -- per rep
for i in range(0, n_cols):
test=imread(fname = meta_of_step[meta_of_step["replicate"] == meta_of_step["replicate"].unique()[j]]['gfp path'].reset_index(drop = True)[i]) ##CHANGE HERE##
locals()["ax" + str(j)][i].imshow(X=test, cmap = mycmap
, vmax = np.percentile(maxlistT, 2.5)
)
locals()["ax" + str(j)][i].set_title(meta_of_step[meta_of_step["replicate"] == meta_of_step["replicate"].unique()[j]]['label display'].reset_index(drop = True)[i] + " - rep" + str(number), size=8, y=0, pad=-2, verticalalignment="top") ##CHANGE HERE##
locals()["ax" + str(j)][i].set_xticks([])
locals()["ax" + str(j)][i].set_yticks([])
locals()["ax" + str(j)][i].spines['bottom'].set_color('white')
locals()["ax" + str(j)][i].spines['top'].set_color('white')
locals()["ax" + str(j)][i].spines['right'].set_color('white')
locals()["ax" + str(j)][i].spines['left'].set_color('white')
#### else print message when there is no image within one replicate
else:
locals()["ax" + str(j)] = plt.subplots()
locals()["ax" + str(j)].axis([0, 1, 0, 1])
locals()["ax" + str(j)].tick_params(axis='x', colors='white')
locals()["ax" + str(j)].tick_params(axis='y', colors='white')
locals()["ax" + str(j)].spines['bottom'].set_color('white')
locals()["ax" + str(j)].spines['top'].set_color('white')
locals()["ax" + str(j)].spines['right'].set_color('white')
locals()["ax" + str(j)].spines['left'].set_color('white')
locals()["ax" + str(j)].set_title('No images for rep' + str(number) , size=15)## CHANGE HERE ##
return fig
## This is if there is one one rep
elif n_rows == 1:
## make new J
j=0
## num -- per rep
number=int(float(j)+1)
## number of figs -- per rep
n_cols=len(meta_of_step[meta_of_step["replicate"] == meta_of_step["replicate"].unique()[j]])##CHANGE HERE##
fig, axs = plt.subplots(1, n_cols, sharex = True, sharey=True, figsize=(5, 5))
axs = axs.ravel()
## Loop per axs
for i in range(0, n_cols):
test=imread(fname = meta_of_step[meta_of_step["replicate"] == meta_of_step["replicate"].unique()[j]]['gfp path'].reset_index(drop = True)[i]) ##CHANGE HERE##
axs[i].imshow(X=test, cmap = mycmap
, vmax = np.percentile(maxlistT, 2.5)
)
axs[i].set_title(meta_of_step[meta_of_step["replicate"] == meta_of_step["replicate"].unique()[j]]['label display'].reset_index(drop = True)[i] + " - rep" + str(number), size=8, y=0, pad=-2, verticalalignment="top") ##CHANGE HERE##
axs[i].set_xticks([])
axs[i].set_yticks([])
axs[i].spines['bottom'].set_color('white')
axs[i].spines['top'].set_color('white')
axs[i].spines['right'].set_color('white')
axs[i].spines['left'].set_color('white')
return fig
###### else print message for all missing replicates - no figures
else:
## Notification "figure" for no image replicate
fig, ax = plt.subplots()
ax.axis([0, 1, 0, 1])
ax.tick_params(axis='x', colors='white')
ax.tick_params(axis='y', colors='white')
ax.spines['bottom'].set_color('white')
ax.spines['top'].set_color('white')
ax.spines['right'].set_color('white')
ax.spines['left'].set_color('white')
ax.set_title('No replicates for ' + str(name) , size=15)## CHANGE HERE ##
return fig
# EXTRA PAPER DOWNLOADS - TAB 4 #
## Download D1
@render.download
def D1():
path=os.path.join(f"{DATAROOT}/to_download/DataS1.tsv")
return path
## Download D2
@render.download
def D2():
path=os.path.join(f"{DATAROOT}/to_download/DataS2.tsv")
return path
## Download T1
@render.download
def T1():
path=os.path.join(f"{DATAROOT}/to_download/TableS1.xlsx")
return path
## Download T2
@render.download
def T2():
path=os.path.join(f"{DATAROOT}/to_download/TableS2.xlsx")
return path
## Download T3
@render.download
def T3():
path=os.path.join(f"{DATAROOT}/to_download/TableS3.xlsx")
return path
## Download T4
@render.download
def T4():
path=os.path.join(f"{DATAROOT}/to_download/TableS4.xlsx")
return path
## Download T5
@render.download
def T5():
path=os.path.join(f"{DATAROOT}/to_download/TableS5.xlsx")
return path
# OUTSIDE DATA - TAB 5 #
## Yeast genome Link 1
# @reactive.calc
# @reactive.event(input.submit)
# def YL1():
# urlYL1="https://www.yeastgenome.org/locus/" + gene1()
# return ui.tags.a("Click here" , href=urlYL1, target='_blank')
#
# ## actual sentence YLink1
# @render.ui
# @reactive.event(input.submit)
# def YLink1():
# return ui.div(YL1(), " - ", gene11())
## Links to Sacc websites
@render.ui
@reactive.event(input.submit)
def YLink1():
## URL to each sacc. site
urlYL1="https://www.yeastgenome.org/locus/" + gene1()
urlYL2="https://www.yeastgenome.org/locus/" + gene2()
YLone=ui.tags.a(gene11(), href=urlYL1, target="_blank")
YLtwo=ui.tags.a(gene22(), href=urlYL2, target="_blank")
return ui.div(YLone, HTML("<br>"), YLtwo)
### Transgenic interaction
## ORF1 or ORF2 Value
@render.ui
@reactive.event(input.submit)
def TI1():
## Read