-
Notifications
You must be signed in to change notification settings - Fork 1
/
SporeCostsTestGerm.R
1793 lines (1479 loc) · 72.5 KB
/
SporeCostsTestGerm.R
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
# Spore Costs v2
# 26 October 2023 - last update
# Author: C. Karakoc
# Global expression data from SporeWeb: https://sporeweb.molgenrug.nl/
# Alternative expression data for validation: https://doi.org/10.3390/ijms22179345
# Germination data: https://doi.org/10.3390/ijms232113614
# Germination expression data: https://doi.org/110.1128/mSphere.00463-20
# Single gene deletion library from: https://doi.org/10.1016/j.cels.2016.12.013
# Global protein abundance data: https://pax-db.org/
# List of gene categories & annotation: https://subtiwiki.uni-goettingen.de/
# Protein sequence: Uniprot https://www.uniprot.org/taxonomy/224308
# Amino acid costs: https://doi.org/10.1073/pnas.1701670114
# COGs: https://doi.org/10.1128/jb.00079
######################
# Packages & Plotting
######################
##########################################################################
library(tidyverse)
library(patchwork) # for nls
library(ggpmisc) # for the formulas of fits
library(stringr)
#devtools::install_github("dgrtwo/fuzzyjoin")
library(fuzzyjoin) # for merging protein sequences
# ggplot theme
library(ggsci) # nature publishing colors
library(scales)
# for COGs
library(vegan)
library(ggfortify)
library(ggrepel)
mytheme <- theme_bw()+
theme(axis.ticks.length = unit(.25, "cm"))+
theme(legend.text = element_text(size=16))+
theme(axis.text = element_text(size = 18, color = "black"), axis.title = element_text(size = 18))+
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.border = element_rect(fill=NA, colour = "black",
size=1))+
theme(strip.text.x = element_text(size = 18))+
theme(legend.title=element_blank())+
theme(panel.border = element_rect(fill=NA, colour = "black",
linewidth=1)) +
theme(axis.text.x.top = element_blank(), axis.title.x.top = element_blank(),
axis.text.y.right = element_blank(), axis.title.y.right = element_blank())+
theme(axis.title.x = element_text(margin=margin(10,0,0)),
axis.title.y = element_text(margin=margin(0,10,0,0)),
axis.text.x = element_text(margin=margin(10,0,0,0)),
axis.text.y = element_text(margin=margin(0,10,0,0)))
mytheme2 <- theme_bw()+
theme(axis.ticks.length = unit(.25, "cm"))+
theme(legend.text = element_text(size=14))+
theme(axis.text = element_text(size = 18, color = "black"), axis.title = element_text(size = 18))+
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.border = element_rect(fill=NA, colour = "black",
size=1))+
theme(strip.text.x = element_text(size = 18))+
theme(legend.title=element_blank())+
theme(panel.border = element_rect(fill=NA, colour = "black",
linewidth=1)) +
#theme(axis.text.x.top = element_blank(), axis.title.x.top = element_blank(),
# axis.text.y.right = element_blank(), axis.title.y.right = element_blank())+
theme(axis.title.x = element_text(margin=margin(10,0,0)),
axis.title.y = element_text(margin=margin(0,10,0,0)),
axis.text.x = element_text(margin=margin(10,0,0,0)),
axis.text.y = element_text(margin=margin(0,10,0,0)))+
theme(axis.title.x.top = element_text(margin=margin(10,10,0)),
axis.title.y.right = element_text(margin=margin(0,10,0,0)),
axis.text.x.top = element_text(margin=margin(10,0,10,0)),
axis.text.y.right = element_text(margin=margin(0,10,0,0)))
# Color palette inspired by plots in Nature Reviews Cancer
paletteNature <- c("Cinnabar" = "#E64B35", "Shakespeare" = "#4DBBD5",
"PersianGreen" = "#00A087", "Chambray" = "#3C5488",
"Apricot" = "#F39B7F", "WildBlueYonder" = "#8491B4",
"MonteCarlo" = "#91D1C2", "Monza" = "#DC0000",
"RomanCoffee" = "#7E6148", "Sandrift" = "#B09C85")
setwd("~/GitHub/sporeCostsVer2")
# Data
######################
# Data
######################
##########################################################################
# Gene&protein length from SubtiWiki
annotationData <- read.table("./otherData/subtiwiki.gene.export.2022-05-11.csv", sep = ",", dec = "." , header = T, stringsAsFactors = F, na.strings=c(" ","NA"))
# Regulator list - sigma factors - annotations
sigma <- read.table("./otherData/regulations.csv", sep = ",", dec = "." , header = T, stringsAsFactors = F, na.strings=c(" ","NA"))
functions <- read.table("./otherData/subtiwiki.gene.export.2023-11-17.csv", sep = ",", header = T, fill = TRUE, stringsAsFactors = F, na.strings=c(" ","NA"))
descriptions <- read.table("./otherData/SWxWWxRS_sporulation_genes.csv", sep = ",", header = T, stringsAsFactors = F, na.strings=c(" ","NA"))
# Data with synonyms # different sources
nameMap <- read.table("./otherData/nameMap.csv", sep = ",", dec = "." , header = T, stringsAsFactors = F)
# Protein abundances from PaxDB
protAbun <- read.table("./otherData/protAbunData.csv", sep = ',', dec = ".", header = T, stringsAsFactors = F, na.strings=c(" ","NA"))
# Protein sequences from Uniprot
protSeq <- read.delim("./otherData/uniprot-compressed_true_download_true_fields_accession_2Creviewed_2C-2023.02.08-14.23.07.59.txt")
#protSeq <- read.table("./otherData/uniprotkb_proteome_UP000001570_2023_09_01.csv", sep = ",", header = T)
# Nucleotide & Amino acid costs
aaCosts <- read.table("./otherData/aaCosts_pnas.1701670114.sd01.csv", sep = ",", dec = "." , header = T)
nucCosts <- read.table("./otherData/nucleotideCosts_pnas.1701670114.sd01.csv", sep = ",", dec = "." , header = T)
# Single gene deletion library from Koo et al., 2018
deletionLib <- read.table("./mutantLibraryData/mmc7_Koo_etal_2017_TableS6A.csv", sep = ",", dec = "." , header = T, stringsAsFactors = F, na.strings=c(" ","NA"))
mutantLib <- read.table("./mutantLibraryData/mmc7_Koo_etal_2017_TableS6B.csv", sep = ",", dec = "." , header = T, stringsAsFactors = F, na.strings=c(" ","NA"))
conservedLib <- read.table("./mutantLibraryData/mmc7_Koo_etal_2017_TableS6E.csv", sep = ",", dec = "." , header = T, stringsAsFactors = F, na.strings=c(" ","NA"))
# Other traits from SubtiWiki lists
otherTraits <- read.table("./otherData/traits.csv", sep = ",", dec = "." , header = T, stringsAsFactors = F)
# Germination time course - Gao et. al. 2022
germination <- read.table("./germinationData/proteinTimeCourseGaoEtAl2022.csv", sep = ",", header = T)
# Germination time course - Swarge et al. 2020
germination1 <- read.table("./germinationData/Swarge_DifferentiallyExpressedGenes.csv", sep = ",", header = T)
germination2 <- read.table("./germinationData/Swarge_DifferentialProteinExp.csv", sep = ",", header = T)
germination3 <- read.table("./germinationData/Swarge_NonDifferentiallyExpressedProt.csv", sep = ",", header = T)
germination4 <- read.table("./germinationData/Swarge_ProteinScore.csv", sep = ",", header = T)
germination5 <- read.table("./germinationData/Swarge_SporeNewproteinRatio_geoMean.csv", sep = ",", header = T)
germination6 <- read.table("./germinationData/SwargeEtAl_onlyNewProteins.csv", sep = ",", header = T)
# Spore time course alternative test
sporulation1 <- read.table("./otherData/TuEtAll_Sporulation_ProteinExpression.csv", sep = ",", header = T)
# Sporulation efficiency
efficiency <- read.table("./otherData/efficiency.csv", sep = ",", dec = "," , header = T, stringsAsFactors = F)
# COGs - Galperin
cogs_dat_gene <- read.table("./COGs_Galperin/geneMatrix.csv", sep = ",", dec = "." , header = T, stringsAsFactors = F)
cogs_dat_sp <- read.table("./COGs_Galperin/speciesMatrix.csv", sep = ",", dec = "." , header = T, stringsAsFactors = F)
#replaced empty cells with 0
###########
###########################SPORULATION#####################################
###########
#####################
# Time series prep
#####################
##########################################################################
# Expression data from SporeWeb
files <- list.files(path = "./SporeWebHeatmaps/" , pattern = "*.csv", full.names = T)
exp_files <- list()
for (i in 1:length(files)){
exp_files[[i]] <- read.table(files[i], header = T, sep = ",", dec = ".")
}
merged_exp <- bind_rows(exp_files, .id = 'sourceID')
merged_exp$sourceID <- as.factor(merged_exp$sourceID)
levels(merged_exp$sourceID ) <- c("1.vegetative", "2.starvation", "3.onset", "4.commitment", "5.engulfment")
# Wrangle
expressionLong <- merged_exp[,c(1, 3:5, 7:14)] %>%
pivot_longer(cols = c('t1','t2','t3','t4','t5','t6','t7','t8'),
names_to = "time", values_to = "expression") %>%
group_by(time, sourceID, regulators, gene, locus_tag) %>%
summarise(meanexp = mean(expression)) %>%
ungroup() %>%
filter(meanexp > 0) %>%
mutate(time_h = gsub('t', '', time))
# Abundance data prep
#####################
# Protein abundance
#####################
##########################################################################
# Protein abundance data does not include locus tags
# It is often easier to merge data sets with locus tags, because genes have a lot of synonyms
# A gene name assigned two different locus tag, corrected based on PaxDB
which(nameMap$gene1 =="nrgB")
nameMap[246,4] <- ""
# Logical map with matching gene names
MAP <- as.data.frame(t(apply(nameMap, 1, function(x) x %in% protAbun$gene)))
colnames(MAP) <- colnames(nameMap)
# Convert logical map into a column mapped with the matching column names
MAP$index = apply(MAP, 1, function(x) paste(names(x)[x], collapse=", "))
nameMap$index = MAP$index
# Match the column names by the rows
id <- lapply(seq(nrow(nameMap)), function(i) nameMap[i,nameMap$index[i]])
# Convert the list output to vector column, but prevent loosing NULLs, convert them
# First to NAs, so that we know which genes do not have abundance info
nameMap$gene <- do.call(rbind, lapply(id, function(x) if(is.null(x)) NA else x))
nameMap$gene <- ifelse(is.na(nameMap$gene), nameMap$geneP, nameMap$gene)
# Now use this collapsed matching column to merge abundances, genes and locus tag
# Merge data
mergedAbunData <- protAbun %>%
right_join(nameMap, by = "gene", multiple = "all") %>%
left_join(annotationData[-2], by = "locus_tag", multiple = "all") %>%
left_join(sigma[-4], by = "locus_tag", multiple = "all") %>%
distinct(locus_tag, .keep_all =TRUE) %>% #left join duplicates
dplyr::select(locus_tag, gene, regulator, abundance, protein_length, gene_length)
# Fill NAs with median values
# Average protein abundance length
protMed <- as.numeric(as.vector(protAbun$abundance))
median(protMed, na.rm = T) #17.6 #round
mergedAbunData$protein_length <- as.numeric(mergedAbunData$protein_length)
mergedAbunData$gene_length <- as.numeric(mergedAbunData$gene_length)
# Median protein and gene length
median(mergedAbunData$protein_length, na.rm = T) #254
median(mergedAbunData$gene_length, na.rm = T) #765
# This function takes a while to run
protSeqTidy <- protSeq %>%
regex_inner_join(mergedAbunData, by = "gene") %>%
distinct(sequence, .keep_all = TRUE) #remove the duplicated rows bases on unique sequences
# Amino acid alphabet
alphabet = c('A', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'Y')
seqCount <- protSeqTidy %>%
rowwise() %>%
reframe(aac = str_count(sequence, pattern = alphabet)) %>%
mutate(symbol = rep(alphabet, times = 4243)) %>%
mutate(gene = rep(1:4243, each = 20)) %>%
left_join(aaCosts, by = "symbol") %>%
mutate(aa_opportunity = aac*opportunity_costs, aa_direct = aac*direct_costs) %>%
group_by(gene) %>%
summarize(aa_opportunitySum = sum(aa_opportunity), aa_directSum = sum(aa_direct)) %>%
mutate(locus_tag = protSeqTidy$locus_tag) %>%
distinct(locus_tag, .keep_all = TRUE)
protSeqTidyAbun <- protSeqTidy %>%
left_join(seqCount[,-1], by = "locus_tag") %>%
select("gene.y", "protID", "locus_tag", "abundance", "protein_length", "gene_length", "aa_opportunitySum", "aa_directSum") %>%
distinct(locus_tag, .keep_all = TRUE)
# Accounting data prep
#####################
# Expression data
#####################
##########################################################################
# Merge with expression data
# Here I'll create two different data sets. One for calculating transcription
# costs, another for translation. Since proteins are degraded much slower, I
# I will account for only repolimerization costs of transcripts
# Here genes are accounted once base on first appearance
mergedExpData_time_distinct <- expressionLong %>%
distinct(locus_tag, .keep_all = TRUE) %>% # genes are accounted only once
left_join(protSeqTidyAbun, by = "locus_tag") %>%
mutate(abundance.filled = replace_na(abundance, 18)) %>%
mutate(gene_length.filled = replace_na(gene_length, 765)) %>%
mutate(protein_length.filled = replace_na(protein_length, 254))
mergedExpData_time <- expressionLong %>%
left_join(protSeqTidyAbun, by = "locus_tag") %>%
mutate(abundance.filled = replace_na(abundance, 18)) %>%
mutate(gene_length.filled = replace_na(gene_length, 765)) %>%
mutate(protein_length.filled = replace_na(protein_length, 254))
# Replication costs (Whole genome)
#####################
# Genome costs
#####################
##########################################################################
# Genome size = (https://www.nature.com/articles/36786)
# DNA unwinding 1ATP per base pair #https://doi.org/10.1016/j.cell.2006.10.049
unwind <- 4214810
# Opportunity
# 2 * Genome size * (34+1)
genome_opp <- 2 * 4214810 * 35 #295036700
# Direct
# 2 * Genome size * (11+2)
genome_dir <-( 2 * 4214810 * 14 ) + unwind #122229490
# Total
genome_tot <- genome_opp + genome_dir #417266190
#####################
# Membrane costs
#####################
##########################################################################
# Number of lipid molecules = Cellular membrane areas/head-group areas of membrane lipid molecules
# Head group area is a1 = 0.65 nm2 (Nagle and Tristram-Nagle 2000; Petrache et al. 2000; Kucerka et al. 2011).
# Thickness of the bilayer (h):
# The thickness of a bilayer is approximately twice the radius of the head-group area, which 0.5 nm in all cases,
# plus the total length of the internal hydrophobic tail domains (Lewis and Engelman 1983; Mitra et al. 2004),
# generally 3.0 nm, so total is 4nm
# Bacillus average length (a) and width (b) Barak et al. 2018
a1 <- 0.65
h <- 4
a <- 2.5*1000 #convert to nm
b <- 1*1000 #also septum
# height/width=2.5
c <- 0.4
# Outer #4πa*b
outer <- 4*pi*a*b
moleculesOut <- outer/a1
# Inner membrane 4π(a − h)(b - h)
inner <- 4*pi*((a-h)*(b-h))
moleculesInn <- inner/a1
# 50% discount, because of protein
totalMol <- (moleculesOut+moleculesInn)/2 #total lipid molecules
# Cost of lipid head & tail
# Opportunity = 212, Direct = 18
# costs
membraneOpp <- totalMol*212
membraneDir <- totalMol*18
membraneTot <- membraneOpp+membraneDir
# Septum should be 1µm 1000 nm (as the width of the cell)
septumOut <- ((4*b)/a1)/2
septumInn <- ((4*(b-h))/a1)/2
septumTot <- septumOut + septumInn
# costs
septumOpp <- septumTot*212
septumDir <- septumTot*18
# Germination assuming that they recycle membrane of the endospore
# Whole membrane - (endospore sphere + septum)
# Septum stretches
# Endospore size is 1/6 of the total cell
membraneGerm <- membraneTot/6
# Replication costs of expressed genes
#####################
# Spore Replication
#####################
##########################################################################
# 878 genes
# 4429 genes whole genome
sum(mergedExpData_time_distinct$gene_length.filled)
# total length = 722878
# genome length = 4214810
# 722878/4214810 %17
# 878/4429 %20
# Opportunity costs
sporeRep <- mergedExpData_time_distinct %>%
mutate(opportunity = 2*gene_length.filled*35) %>% #2 = doublestring 35 = nucleotide costs
mutate(direct = 2*gene_length.filled*14)
# Sum
sporeRepSum <- sporeRep %>%
summarise(sumOpp = sum(opportunity, na.rm =T), sumDir = sum(direct, na.rm =T))
sporeRepTotal <- sporeRepSum$sumOpp+sporeRepSum$sumDir
# opportunity 50601460
# direct 20240584
# total 70842044
# percentage compared to total genome
sporeRepTotal/413051380 #17%
# Transcription costs
#####################
# Spore Transcription
#####################
##########################################################################
# 1 mRNA can yield to 100-1000 proteins (Cell biology by the numbers)
# I will count opportunity costs separately, so I can consider repolimerization costs
# Opportunity costs
sporeTranscriptOpp <- mergedExpData_time_distinct %>%
mutate(estimation = (((abundance.filled/1e2)*1774445)/1e6)*gene_length.filled) %>% #protein abundance/1000 X 1.8 X gene length
# the reason I multiply with 1.8 is that the protein abundance is reported as parts per million. An average size bacteria has about 3 million protein molecules
# this was reported experimentally as average 1774445 in Bacillus (Maass et.al. 2011)
mutate(opportunity = estimation*31)
# Sum
sporeTranscriptOppSum <- sporeTranscriptOpp %>%
group_by(time) %>%
summarise(sumOpp = sum(opportunity, na.rm =T))
# Sum stages
sporeTranscriptOppSum2 <- sporeTranscriptOpp %>%
group_by(sourceID) %>%
summarise(sumOpp = sum(opportunity, na.rm =T))
# Direct costs
sporeTranscriptDir <- mergedExpData_time %>%
mutate(estimation = (((abundance.filled/1e2)*1774445)/1e6)*gene_length.filled) %>%
mutate(direct = estimation*(10+(2*12*1)))#hours
# average sporulation time is 8hours, median mRNA degradation rate of Bacillus is 12 per hour
# (DOI: 10.1007/s00438-003-0883-6)
# = 12 re-polymerization events per hour
# assuming nucleotides are well recycled and it only affects polymerization costs
# Sum
sporeTranscriptDirSum <-sporeTranscriptDir %>%
group_by(time_h) %>%
summarise(sumDir = sum(direct, na.rm =T))
# Stages
sporeTranscriptDirSum2 <-sporeTranscriptDir %>%
group_by(sourceID) %>%
summarise(sumDir = sum(direct, na.rm =T))
# Cumulative costs
transcriptCosts <- cbind.data.frame(sporeTranscriptDirSum$time_h, opportunity = sporeTranscriptOppSum$sumOpp,
direct = sporeTranscriptDirSum$sumDir,
total = sporeTranscriptOppSum$sumOpp + sporeTranscriptDirSum$sumDir)
transcriptSum <- colSums(transcriptCosts[,-1])
#Cost of genes
sporeTranscriptDirDist <- sporeTranscriptDir %>%
group_by(locus_tag) %>%
summarise(sumDist = sum(direct, na.rm =T))
# Translation costs
#####################
# Spore Translation
#####################
##########################################################################
# Fill missing protein sequence cost estimations
median(mergedExpData_time_distinct$aa_opportunitySum, na.rm = T) #5723
median(mergedExpData_time_distinct$aa_directSum, na.rm = T) #1351
# Opportunity and direct costs
sporeTranslationOppDir <- mergedExpData_time_distinct %>%
mutate(estimation = (abundance.filled*1774445)/1e6) %>%
mutate(aa_opportunitySum.filled = replace_na(aa_opportunitySum, 5723)) %>%
mutate(aa_directSum.filled = replace_na(aa_directSum, 1351)) %>%
mutate(direct = estimation*aa_directSum.filled) %>% # ignoring protein degradation
mutate(opportunity = estimation*aa_opportunitySum.filled) %>%
mutate(total = direct + opportunity)
# Sum
sporeTranslationOppDirSum <- sporeTranslationOppDir %>%
group_by(time_h) %>%
summarise(opportunity = sum(opportunity, na.rm = T),
direct = sum(direct, na.rm = T),
total = sum(total, na.rm = T))
translationSum <- colSums(sporeTranslationOppDirSum[,-1])
# Opportunity
opp <- translationSum[1]+genome_opp+sporeRepSum$sumOpp+septumOpp
# Direct
dir <- translationSum[2]+genome_dir+sporeRepSum$sumDir+septumDir
(opp/(opp+dir))*100 #78
(dir/(opp+dir))*100 #22
# Total costs, plots, pie, bars, model - TODO: Remove membrane
#####################
# Total, model, plot
#####################
##########################################################################
# Total costs
cost_rep_all <- genome_opp+genome_dir
cost_rep_part <- sporeRepSum$sumOpp+sporeRepSum$sumDir
cost_rep_rest <- cost_rep_all-cost_rep_part
cost_transcript <- sum(transcriptCosts$total)
cost_translation<- sum(sporeTranslationOppDirSum$total)
cost_membrane <- septumOpp+septumDir
all_pie_costs <- cost_rep_all+cost_transcript+cost_translation+cost_membrane
# % proportions
rep_partial <- cost_rep_part/all_pie_costs*100
rep_rest <- cost_rep_rest/all_pie_costs*100
((cost_rep_part+cost_rep_rest)/all_pie_costs)*100
transcript <- cost_transcript/all_pie_costs*100
translation <- cost_translation/all_pie_costs*100
membrane <- cost_membrane/all_pie_costs*100
proportion <- c(rep_partial, rep_rest, transcript, translation, membrane)
pieCost <- c("replication_partial", "replication_rest", "transcription", "translation", "membrane")
pieData <- cbind.data.frame(pieCost, proportion)
pieData$labels <- paste(pieData$pieCost, round(pieData$proportion, 1), "%")
pieSpore <- ggplot(pieData, aes(x = "", y = proportion, fill = pieCost))+
geom_bar(width = 1, stat = "identity")+
coord_polar("y", start = 0)+
mytheme+
scale_fill_npg()+
geom_text_repel(aes(label = labels), size = 4.5, show.legend = FALSE)+
theme_void()+
theme(legend.position = "none")
ggsave("~/GitHub/sporeCostsVer2/figures/pieSpore.pdf", pieSpore, height = 5, width = 6)
# spore percentage
(cost_rep_part/cost_rep_all)*100 #17%
### Total costs of sporulation ###
### Figure ###
time <- rep(c(1:8), times = 2)
opportunity <- transcriptCosts$opportunity + sporeTranslationOppDirSum$opportunity
direct <- transcriptCosts$direct + sporeTranslationOppDirSum$direct
costs <- c(opportunity, direct)
type <- rep(c("opportunity", "direct"), each = 8)
sporulationCosts <- cbind.data.frame(time, costs, type)
sum(sporulationCosts$costs) #1554146274 (transcription and translation)
cost_rep_part+cost_rep_rest+sum(sporulationCosts$costs) #1971412464
sporulationTotal <- cbind.data.frame(time = c(1:8),
costs = direct + opportunity)
# Figure 1 Model
fit <- nls(costs ~ SSasymp(time, yf, y0, log_alpha), data = sporulationTotal)
coef(fit)
label <- coef(fit)[3]
tt <- seq(1,8, by = 0.1)
pred <- predict(fit, list(time = tt))
preddata <- cbind.data.frame(pred, tt)
RSS.p <- sum(residuals(fit)^2)
y <- as.numeric(as.character(sporulationTotal$costs))
TSS <- sum((log10(y) - mean(y))^2)
R2 <- 1 - (RSS.p/TSS)
#scientific_10 <- function(x) {
# parse(text=gsub("e", " %*% 10^", scales::scientific_format()(x)))
#}
sporulationCosts_lay1 <- sporulationCosts %>%
group_by(time) %>%
summarize(sum = sum(costs))
sporulationCosts$type <- factor(sporulationCosts$type, c("opportunity","direct"))
# Plot
# Note that some adjustments are done in Adobe Illustrator
my_lab <- c(expression(P['D']),
expression(P['O']),
expression(P['T']))
f1 <- ggplot(NULL, aes(x = x, y = y))+
geom_vline(xintercept = 2, linetype = "dashed")+
geom_bar(data = sporulationCosts_lay1,
aes(x = time, y = sum), stat = "identity", color = "grey90", fill = "grey75", alpha = 0.5)+
geom_bar(data = sporulationCosts,
aes(x = time, fill = type, y = costs), stat = "identity", color = "grey25", position = position_dodge(width=1))+
ylab("ATP molecules")+
xlab("Time (h)")+
geom_line(data = preddata, aes(x = tt, y = pred), linewidth = 1)+
mytheme+
scale_y_continuous(breaks = c(2*10^8, 4*10^8, 6*10^8, 8*10^8, 10*10^8),
labels = c(2,4,6,8,10), sec.axis=dup_axis())+
scale_x_continuous(sec.axis=dup_axis())+
annotate("text",x=-0.7,y=1.2*10^9,label=paste("(x10^8)"), parse =T, size = 18/.pt)+
coord_cartesian(xlim = c(0.5, 8.5), clip="off")+
annotate(geom = "text", x = 8, y = 2e8, label = paste("-\U03BB==", round(label, 3)), hjust = "right", size = 6, fontface = 'italic', parse = T)+
annotate(geom = "text", x = 8, y = 1.2e8, label = paste("R^2==", round(R2, 3)), hjust = "right", size = 6, fontface = 'italic',
parse=TRUE)+
theme(legend.position = c(0.32, 0.83), legend.title = element_blank())+
scale_fill_npg(labels=c(my_lab[1],
my_lab[2],
my_lab[3]))
ggsave("~/GitHub/sporeCostsVer2/figures/sporeCostsTime.pdf", f1, height = 5, width = 6)
# END Figure 1
# Costs until full commitment
line_integral <- function(x, y) {
dx <- diff(x)
end <- length(y)
my <- (y[1:(end - 1)] + y[2:end]) / 2
sum(dx *my)
}
x <- preddata$tt[1:11] #2 hours
y <- preddata$pred[1:11]
plot(x,y,"l")
commitment <- line_integral(x,y)
(commitment/sum(sporulationTotal))*100 #34.9%. %only transcription and translation
# New figure for replication
type_rep <- c("opportunity", "direct", "opportunity", "direct")
cost_rep <- c(genome_opp, genome_dir, sporeRepSum$sumOpp, sporeRepSum$sumDir)
genes <- c("whole", "whole", "partial", "partial")
repCosts <- cbind.data.frame(type_rep, cost_rep, genes)
# Regulons
#selected <- c("SigE", "SigF", "SigG", "SigH", "SigK")
#SigE: early mother cell-specific sporulation sigma factor
#SigF: early forespore-specific sporulation sigma factor
#SigG: late forespore-specific sporulation sigma factor
#SigH: sigma factor that controls genes of the transition phase
#SigK: late mother cell-specific sporulation sigma factor
### Regulons
############################
################GERMINATION - UPDATED BELOW##################################
############################
#####################
# Time course of germination
#####################
##########################################################################
protSeqTidyAbun$gene <- protSeqTidyAbun$gene.y
germinationLong <- germination %>%
pivot_longer(cols = c("t30", "t60", "t90", "t120", "t150"), names_to = "time", values_to = "presence") %>%
left_join(protSeqTidyAbun, by = "gene") %>%
filter(!presence == 0) %>%
mutate(abundance.filled = replace_na(abundance, 18)) %>%
mutate(gene_length.filled = replace_na(gene_length, 765)) %>%
mutate(protein_length.filled = replace_na(protein_length, 254))
germinationLongDIST <- germination %>%
pivot_longer(cols = c("t30", "t60", "t90", "t120", "t150"), names_to = "time", values_to = "presence") %>%
filter(!presence == 0) %>%
distinct(gene, .keep_all = TRUE) %>% # genes are accounted only once
left_join(protSeqTidyAbun, by = "gene") %>%
mutate(abundance.filled = replace_na(abundance, 18)) %>%
mutate(gene_length.filled = replace_na(gene_length, 765)) %>%
mutate(protein_length.filled = replace_na(protein_length, 254))
#####################
# Replication costs
#####################
##########################################################################
germRep <- germinationLongDIST %>%
mutate(opportunity = 2*gene_length.filled*35) %>% #2 = doublestring 35 = nucleotide costs
mutate(direct = 2*gene_length.filled*14)
# Sum
germRepSum <- germRep %>%
group_by(time) %>%
summarise(sumOpp = sum(opportunity, na.rm =T), sumDir = sum(direct, na.rm =T))
germRepTotal <- germRepSum$sumOpp+germRepSum$sumDir
# Transcription costs
######################
# Transcription costs
######################
##########################################################################
# Opportunity costs
germTranscriptOpp <- germinationLongDIST %>%
mutate(estimation = (abundance.filled/1e2)*(1774445)/1e6) %>%
mutate(opportunity = estimation*31)
# Sum
germTranscriptOppSum <- germTranscriptOpp %>%
group_by(time) %>%
summarise(value = sum(opportunity, na.rm = T)) %>%
mutate(source = rep("transcription")) %>%
mutate(name = rep("opportunity"))
# Direct costs
germTranscriptDir <- germinationLong %>%
mutate(estimation = (abundance.filled/1e2)*(1774445/1e6)*gene_length.filled) %>%
mutate(direct = estimation*(10+(2*6))) # 6 repolimerization events every 30 min.
# Sum
germTranscriptDirSum <- germTranscriptDir %>%
group_by(time) %>%
summarise(value = sum(direct, na.rm = T)) %>%
mutate(source = rep("transcription")) %>%
mutate(name = rep("direct"))
######################
# Translation costs
######################
##########################################################################
# Opportunity and direct costs
# Fill empty cost estimations
median(germinationLongDIST$aa_opportunitySum, na.rm = T) #6337
median(germinationLongDIST$aa_directSum, na.rm = T) #1527
germTranslationOppDir <- germinationLongDIST %>%
mutate(estimation = ((abundance.filled)*(1774445))/1e6) %>%
mutate(aa_opportunitySum.filled = replace_na(aa_opportunitySum, 6337)) %>%
mutate(aa_directSum.filled = replace_na(aa_directSum, 1527)) %>%
mutate(direct = estimation*aa_directSum.filled) %>% # ignoring protein degradation
mutate(opportunity = estimation*aa_opportunitySum.filled)
# Sum
germTranslationOppDirSum <- germTranslationOppDir %>%
group_by(time) %>%
summarise(opportunity = sum(opportunity, na.rm = T),
direct = sum(direct, na.rm = T)) %>%
pivot_longer(cols = 2:3) %>%
mutate(source = rep("translation")) %>%
mutate(name = rep(c("direct", "opportunity"), times = 5))
sumAll_Germ <- rbind.data.frame(germTranscriptOppSum, germTranscriptDirSum, germTranslationOppDirSum)
######################
# Total costs, plots
######################
##########################################################################
all_Germ_sum <- sumAll_Germ %>%
group_by(time, name) %>%
summarise(costs = sum(value)) %>%
mutate(hours = case_when(
time == "t30" ~ 0.5,
time == "t60" ~ 1,
time == "t90" ~ 1.5,
time == "t120" ~ 2,
time == "t150" ~ 2.5))
# Figure Model
fit2 <- nls(costs ~ SSasymp(hours, yf, y0, log_alpha), data = all_Germ_sum)
coef(fit2)
label2 <- coef(fit2)[3]
tt2 <- seq(0.25, 2.5, by = 0.01)
pred2 <- predict(fit2, list(hours = tt2))
preddata2 <- cbind.data.frame(pred2, tt2)
RSS.p2 <- sum(residuals(fit2)^2)
y2 <- as.numeric(as.character(all_Germ_sum$costs))
TSS2 <- sum((log10(y2) - mean(y2))^2)
R22 <- 1 - (RSS.p2/TSS2)
# Figure 1 - germination
spore <- ggplot(NULL, aes(x = x, y = y))+
geom_bar(data = all_Germ_sum,
aes(x = hours, y = costs, fill = name), stat = "identity", color = 'grey25')+
ylab("ATP molecules")+
xlab("Time (h)")+
geom_line(data = preddata2, aes(x = tt2, y = pred2))+
mytheme+
scale_y_continuous(labels = scientific_10)+
scale_fill_npg()+
annotate(geom = "text", x = 2.5, y = 2e9, label = paste0("-\U03BB", "=" , round(label, 3)), hjust = "right", size = 4, fontface = 'italic')+
annotate(geom = "text", x = 2.5, y = 1.5e9, label = paste0("R2", "=" , round(R2, 3)), hjust = "right", size = 4, fontface = 'italic')+
theme(legend.position = c(0.8, 0.8), legend.title = element_blank())+
scale_x_continuous(breaks = c(0.5, 1, 1.5, 2, 2.5), limits = c(0.25,2.8))
# END Figure 1 - germination
# Pie
all_Germ_sum_pie<- sumAll_Germ %>%
group_by(source) %>%
summarise(costs = sum(value))
replicationGerm = sum(germRepTotal)/sum(all_Germ_sum$costs+germRepTotal)*100 #germination genes 0.6%
transcriptionGerm = sum(germTranscriptDirSum$value)/sum(all_Germ_sum$costs+germRepTotal)*100 #9.5%
translationGerm = sum(germTranslationOppDirSum$value)/sum(all_Germ_sum$costs+germRepTotal)*100 #74.8%
proportion2 <- c(round(replicationGerm, 2), round(transcriptionGerm, 2), round(translationGerm, 2))
pieCost2 <- c("replication", "transcription", "translation")
pieData2 <- cbind.data.frame(pieCost2, proportion2)
ggplot(pieData2, aes(x = "", y = proportion2, fill = pieCost2))+
geom_bar(width = 1, stat = "identity", color = "black")+
coord_polar("y", start=0)+
mytheme+
scale_fill_manual(values = c("#4DBBD5","#3C5488","#F39B7F"))
# OTHER TRAITS
######################
# Other traits- UPDATED BELOW
######################
##########################################################################
# Merge trait data
mergedTraitData <- otherTraits %>%
filter(!category == "sporulation") %>%
filter(!category == "germination") %>%
left_join(annotationData, by = "gene") %>%
left_join(protSeqTidyAbun[,c("locus_tag","abundance", "aa_opportunitySum", "aa_directSum")], by = "locus_tag") %>%
mutate(abundance.filled = replace_na(abundance, 18)) %>%
group_by(category) %>%
mutate(no_genes = length(category))
# All costs
totalCosts_traits <- mergedTraitData %>%
mutate(translationAll = abundance.filled*(1774445/1e6)) %>%
mutate(aa_opportunitySum.filled = median(aa_opportunitySum, na.rm = T)) %>%
mutate(aa_directSum.filled = median(aa_directSum, na.rm = T)) %>%
mutate(translationDirect = translationAll*aa_directSum) %>% #ignoring protein degradation
mutate(translationOpportunity = translationAll*aa_opportunitySum.filled) %>%
mutate(translationTotal = translationDirect + aa_opportunitySum.filled) %>%
mutate(transcriptionAll = (abundance.filled/1e2)*(1774445/1e6)*as.numeric(gene_length)) %>%
mutate(transcriptionDirect = transcriptionAll*(10+(2*12*1))) %>% #assuming that mRNAs transcribed at least 1 hour
mutate(transcriptionOpportunity = transcriptionAll*31) %>%
mutate(transcriptionTotal = transcriptionDirect + transcriptionOpportunity) %>%
mutate(costs = transcriptionTotal + translationTotal)
# Cumulative costs
costs_sum_traits <- totalCosts_traits %>%
group_by(category) %>%
summarize(sumCosts = sum(costs, na.rm = T),
number_genes = mean(no_genes)) %>%
select(category, sumCosts) %>%
add_row(category = "total_budget", sumCosts = 2.6e10) %>%
add_row(category = "basal_metabolism", sumCosts = 3.5e8) %>%
add_row(category = "sporulation", sumCosts = 1483262323)
# Plot cumulative costs
ggplot(costs_sum_traits, aes(x = log10(sumCosts), y = reorder(category, sumCosts)))+
geom_col(fill="grey", color="black")+
xlab("Log(Total translation costs in units of ATP)")+
ylab("Complex traits")+
coord_cartesian(xlim = c(7.8,10.5))+
mytheme
# Add a second axis
costs_sum_traits_rel <- costs_sum_traits %>%
mutate(relative = (sumCosts/2.6e10)*100)
### Figure 2 ###
ggplot(costs_sum_traits_rel, aes(x = log10(sumCosts), y = reorder(category, sumCosts)))+
geom_col(fill="grey", color="black")+
#geom_vline(xintercept = log10(1737135887), linetype = 'dashed')+
# Custom the Y scales:
scale_x_continuous(
# Features of the first axis
name = "ATP molecules",
# Add a second axis and specify its features
sec.axis = sec_axis(trans = ~log10((10^./2.6e10)*100), name = "Costs relative to the total budget (%)"))+
coord_cartesian(xlim = c(7.8,10.5))+
mytheme
### Figure 2 ###
# ESSENTIAL GENES #
######################
# Essential genes
######################
##########################################################################
# Distribution of essential genes and others
# Costs of genes genome wide
deletionLibMerge <- deletionLib %>%
left_join(protSeqTidyAbun, by = "locus_tag") %>%
mutate(abundance.filled = replace_na(abundance, 18)) %>%
mutate(gene_length.filled = replace_na(gene_length, 765)) %>%
mutate(protein_length.filled = replace_na(protein_length, 254))
# Average sporulation score under 50% - %90
mean(deletionLibMerge$rSS_average)*0.5
mean(deletionLibMerge$rSS_average)*0.9
deletionLibMergeRelevant <- deletionLibMerge %>%
mutate(success = case_when(rSS_average < 0.46 & rSS_average > 0.31 ~ "50% failure",
rSS_average < 0.83 & rSS_average > 0.46 ~ "10% failure",
rSS_average < 0.31 ~ "essential",
rSS_average > 0.83 ~ "90% success"))
# All costs
delAllCosts <- deletionLibMergeRelevant %>%
mutate(aa_opportunitySum.filled = median(aa_opportunitySum, na.rm = T)) %>%
mutate(aa_directSum.filled = median(aa_directSum, na.rm = T)) %>%
mutate(transcript = (((abundance.filled/1e2)*1774445)/1e6)*gene_length.filled) %>%
mutate(protein = (abundance.filled*1774445)/1e6) %>%
mutate(replicationOpp = gene_length.filled*35*2) %>%
mutate(replicationDir = gene_length.filled*14*2) %>%
mutate(transcriptOpp = transcript*31) %>%
mutate(transcriptDir = transcript*(10+(2*12*1))) %>%
mutate(translationOpp = protein*aa_opportunitySum.filled) %>% # ignoring protein degradation
mutate(translationDir = protein*aa_directSum.filled) %>%
group_by(success) %>%
summarise_at(vars(replicationOpp:translationDir),
sum, na.rm = TRUE) %>%
pivot_longer(!success, names_to = 'source', values_to = 'costs') %>%
mutate(process = rep(c("replication", "transcription", "translation"), each = 2, times = 4)) %>%
mutate(source = rep(c("opportunity", "direct"), times = 12)) %>%
filter(!success == "90% success")
delAllCosts$ratio <- delAllCosts$costs*100/sum(delAllCosts$costs)
sum(delAllCosts$ratio[7:12])
#totals
totals <- delAllCosts %>%
group_by(success, source) %>%
summarise(sum = sum(costs))
### Figure S ###
my_lab <- c(expression(P['D']),
expression(P['O']),
expression(P['T']))
essential <- ggplot(totals, aes(y = sum, x = success, fill = source))+
mytheme+
#facet_wrap(~source, scales = "free")+
geom_bar(stat="identity", width = 1, color="black")+
scale_fill_npg(labels = my_lab)+
theme(legend.position = c(0.85, 0.85))+
theme(axis.title.x = element_blank())+
ylab("ATP molecules")+
scale_y_continuous(breaks = c(0, 0.5*10^9, 1*10^9, 1.5*10^9),
labels = c(0,0.5,1,1.5), sec.axis=dup_axis())
### Figure S ###
ggsave("~/GitHub/sporeCostsVer2/figures/essentialGenes.pdf", essential, height = 4, width = 5)
######################
# Quality
#####################
###########################################################################
delAllCosts2 <- deletionLibMergeRelevant %>%
mutate(transcript = (((abundance.filled/1e2)*1774445)/1e6)*gene_length.filled) %>%
mutate(protein = (abundance.filled*1774445)/1e6) %>%
mutate(replicationOpp = gene_length.filled*35*2) %>%
mutate(replicationDir = gene_length.filled*14*2) %>%
mutate(transcriptOpp = transcript*31) %>%
mutate(transcriptDir = transcript*(10+(2*12*1))) %>%
mutate(aa_opportunitySum.filled = replace_na(median(aa_opportunitySum, na.rm = T))) %>%
mutate(aa_directSum.filled = replace_na(median(aa_directSum, na.rm = T))) %>%
mutate(translationOpp = protein*aa_opportunitySum.filled) %>%
mutate(translationDir = protein*aa_directSum.filled) %>%
mutate(sum = translationOpp+translationDir+replicationOpp+replicationDir+transcriptOpp+transcriptDir) %>%
right_join(mergedExpData_time_distinct, by = "locus_tag")
ggplot(delAllCosts2, aes(x = log10(sum), y = rSS_average))+
geom_point(alpha = .1)+
ylab("spore quality")+
xlab("gene costs")
# SPORULATION EFFICIENCY #
#####################
# Efficiency
#####################
##########################################################################
efficiency$efficiency <- as.numeric(efficiency$efficiency)
ggplot(efficiency, aes(efficiency))+
geom_density()+
xlab("Sporulation efficiency")+
ylab("Frequency")+
geom_vline(xintercept = 34.7, color = "#A42820", linetype = "dashed" )+
coord_cartesian(ylim = c(0.0025, 0.0125))+
mytheme
library(truncnorm)
fit <- density(efficiency$efficiency, from = 0, to = 100)
N <- 1e6
x.new <- rtruncnorm(a = 0, b = 100, N, sample(efficiency$efficiency, size = N, replace = TRUE))
plot(density(x.new, bw = fit$bw))
densityPlot <- as.data.frame(x.new)
means = densityPlot %>%
summarise(M = median(x.new), SD = sd(x.new), N = n())
# Sample size of 50. T Distribution intervals
means$error = qt(0.975, df = 50-1)*means$SD/sqrt(means$N)
means$upper = means$M+means$error
means$lower = means$M-means$error
### Figure Efficiency ###
efficiencyPlot <- ggplot(densityPlot, aes(x = x.new))+
geom_density(alpha = 0.1, linewidth = 0.8, bw = 11.35555)+
geom_vline(xintercept = c(means$M), linetype = 'dashed', color = "#A42820")+
annotate(geom = "label", x = 36, y = 0.013, color = "#A42820", fill = "white", label = "Median = 30.6%")+
labs(x="Sporulation efficiency", y = "Density")+
mytheme+
scale_x_continuous(limits = c(-30,130), sec.axis = dup_axis())+
scale_y_continuous(sec.axis = dup_axis())
### Figure Efficiency ###
ggsave("~/GitHub/sporeCostsVer2/figures/efficiency.pdf", efficiencyPlot, height = 5, width = 6)
####################
# EVOLUTION
####################
########################################################################
# Merge with mutant library
# Essential genes (66 of them)
mergedMutDataTranslation <- sporeTranslationOppDir %>%
left_join(mutantLib, by = "locus_tag") %>%
filter(mutant == "known sporulation mutant") %>%
select(locus_tag)
# Evolution of the genes