-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ascomycota_genomes_gap_analysis.r
1705 lines (1464 loc) · 68.4 KB
/
Ascomycota_genomes_gap_analysis.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
#########################################
#########################################
###### ######
###### Ascomycota Gap Analysis ######
###### ######
#########################################
#########################################
##This script uses some webpage scraping, so results will differ as new data becomes available##
##CS = genome assemblies, noCS = cytometric##
#Written in R v4.0.2
library(ape) #5.4-1
library(cowplot) #1.1.0
library(DescTools) #0.99.38
library(dplyr) #1.0.2
library(ggplot2) #3.3.2
library(ggpubr) #0.4.0
library(ggstance) #0.3.4
library(ggtree) #2.3.4
library(grid) #4.0.2
library(gridExtra) #2.3
library(gtable) #0.3.0
library(multcompView) #0.1-8
library(RCurl) #1.98-1.2
library(rvest) #0.3.6
library(scales) #1.1.1
library(stringr) #1.4.0
library(taxize) #0.9.99
##############
## FIGURE 2 ##
##############
#Read in genome size data from Le Cam et al. 2019
lecam <- read.csv("data/lecam.csv", skip=1)
#Make columns numeric
lecam[c(13, 14, 22)] <- sapply(lecam[c(13, 14, 22)], as.numeric)
#Correct names
lecam$Species <- sub("V\\.", "Venturia", lecam$Species)
lecam$Species <- sub("pirina", "pyrina", lecam$Species)
#Add a column for cytometric completeness
lecam$cytometric.completeness <- lecam$Assembly..size..Mb. / lecam$Genome.size..Mb. * 100
#Make dataframe of BUSCO and cytometric completness completness for ggplot
lecam.df <- rbind(data.frame(ID=lecam$ID[!is.na(lecam$cytometric.completeness)],
num=lecam$X.CSC.BUSCO[!is.na(lecam$cytometric.completeness)],
species=lecam$Species[!is.na(lecam$cytometric.completeness)],
type="busco"),
data.frame(ID=lecam$ID[!is.na(lecam$cytometric.completeness)],
num=lecam$cytometric.completeness[!is.na(lecam$cytometric.completeness)],
species=lecam$Species[!is.na(lecam$cytometric.completeness)],
type="cytometry"))
#Faceted barplot of completeness for each species
gg.completeness <- ggplot(lecam.df, aes(x=ID, y=num, fill=type)) +
geom_bar(stat="identity",
colour="black",
size=0.2,
width=0.8,
position="dodge") +
facet_grid(. ~ species,
scale="free",
space="free",
labeller=label_wrap_gen(width=8)) +
labs(x=expression(paste(italic("Venturia"), " strain ID (Le Cam et al., 2019)")),
y="Completeness (%)",
fill="") +
scale_y_continuous(limits=c(0, 100),
expand=c(0, 0)) +
scale_fill_manual(values=c("white", "dimgrey"),
labels=c("Gene set (BUSCO)", "Cytometric genome size estimate"),
guide=guide_legend(title="Method of assessing assembly completeness",
title.position="top",
title.hjust=0.5)) +
theme(legend.position="top",
legend.key.size=unit(0.5,"line"),
legend.title=element_text(size=9.5),
legend.margin=margin(0,0,0,0),
legend.box="vertical",
strip.text=element_text(face="bold.italic", size=5),
panel.spacing=unit(0.1, "lines"),
axis.text.x=element_text(size=5.5),
axis.title.y=element_text(margin=margin(0,10,0,0)),
axis.title.x=element_text(margin=margin(5,0,0,0)),
plot.margin=unit(c(0,0,0,0), "mm"),
panel.grid.major.x=element_blank())
#Write to file
tiff(file=paste0("Fig2-", Sys.Date(), ".tiff"), height=3, width=8, units="in", res=300)
gg.completeness
dev.off()
##############
## FIGURE 1 ##
##############
##Generate Ascomycota order-level phylogeny for side by side plot##
#Read in Ascomycota taxonomy (from Wijayawardene et al. 2018)
tax.df <- read.csv("data/Ascomycota outline 2017.csv", stringsAsFactors=TRUE)
#Add phylum column
tax.df$Phylum <- as.factor("Ascomycota")
#Remove incertae sedis orders
tax.df <- tax.df[!grepl("incertae sedis", tax.df$Order, ignore.case=TRUE),]
#Add column for species count
tax.df$Species <- NA
progress.bar <- txtProgressBar(1, length(tax.df$Genus), initial=0, char="=", style=3)
#For each genus...
for (i in 1:length(tax.df$Genus)) {
setTxtProgressBar(progress.bar, i)
#Pull a dataframe of all hits from Index Fungorum
temp.df <- fg_name_search(tax.df$Genus[i], anywhere=TRUE, limit=5000)
#Filter for species-level
temp.df <- temp.df[temp.df$infraspecific_rank == "sp.",]
#If there are legitimate current names...
if ("current_name" %in% colnames(temp.df)) {
#Make a variable for the current names
names <- temp.df$current_name[!is.na(temp.df$current_name)]
#Check that the current names are still the same genus
names <- names[grep(tax.df$Genus[i], names)]
#Add count of species to dataframe
tax.df$Species[i] <- length(unique(names))
} else {
#Add that there are no legitimate species to dataframe
tax.df$Species[i] <- 0
}
}
#Remove taxon levels with no current species
tax.df <- tax.df[tax.df$Species != 0,]
#Remove duplicate orders
tax.df2 <- tax.df[!duplicated(tax.df$Order),c(1:2,5)]
#Make order level tree with dataframe
asc.tree <- as.phylo(~Phylum/Class/Order, data=tax.df2)
##Cytometric genome size data (from http://www.zbi.ee/fungal-genomesize/, not from assemblies)##
#Read in genome size data
df <- read.csv("data/fungi_genome_sizes.csv")
#Subset genome size dataframe for just Ascomycota
asc.df <- subset(df, PHYLUM == "Ascomycota")
#Correct size from original paper
asc.df$X1C.in.Mbp[asc.df$FGSDID == 2788] <- 34.36
asc.df$X1C.in.pg[asc.df$FGSDID == 2788] <- 0.035
asc.df$SPECIES[asc.df$FGSDID == 2355] <- "pulchella"
#Add estimates from Le Cam et al. 2019
asc.df <- rbind(asc.df,
data.frame(PHYLUM="Ascomycota",
ORDER="Venturiales",
GENUS="Venturia",
SPECIES=sub("Venturia ", "", lecam$Species[!is.na(lecam$Genome.size..Mb.)]),
METHOD="PI-FC",
X1C.in.pg="",
X1C.in.Mbp=lecam$Genome.size..Mb.[!is.na(lecam$Genome.size..Mb.)],
x=NA,
FGSDID=NA,
SPECIMEN.ID=lecam$Name[!is.na(lecam$Genome.size..Mb.)]))
#Fix genus and species names for unknown (sp.) taxa
for (i in 1:length(asc.df$GENUS)) {
if(length(grep("\\bsp\\.", asc.df$GENUS[i])) > 0) {
asc.df$GENUS[i] <- sub(" sp\\.", "", asc.df$GENUS[i])
asc.df$SPECIES[i] <- "sp."
}
}
#Create vector of method to exclude (genome assembly, unreliable or unknown methods)
exclude <- c("CS", "genomic reconstruction", "", "CHEF gel electrophoresis", "DAPI-PC", "DAPI-IC", "PFGE", "CS and PFGE", "quantitative real-time PCR", "Re-association kinetics", "Integrated Physical/Genetic Map", "diphenylamine method")
#Remove genome size data for these methods
no.CS.df <- subset(asc.df, !METHOD %in% exclude)
#Find genera that don't match current classification to check for species synonyms
synonym.df <- data.frame(old=sort(unique(paste(no.CS.df$GENUS, no.CS.df$SPECIES)[is.na(match(no.CS.df$GENUS, tax.df$Genus))])),
current=NA)
#Remove taxa that aren't identified to species-level
synonym.df <- synonym.df[-grep("sp\\.", synonym.df$old),]
#Remove 'cf.' from names
synonym.df$old <- sub(" cf.", "", synonym.df$old)
#For each species...
for (i in 1:length(synonym.df$old)) {
#Pull a dataframe of all hits from Index Fungorum
temp.df <- fg_name_search(synonym.df$old[i], anywhere=TRUE, limit=5000)
#If there is a current name...
if ("current_name" %in% colnames(temp.df)) {
#Put newest
synonym.df$current[i] <- temp.df$current_name[!is.na(temp.df$current_name)][1]
}
}
#For each species...
for (i in 1:length(no.CS.df$SPECIES)) {
#If the species name matches the list of name to correct..
if (length(grep(paste(no.CS.df$GENUS[i], no.CS.df$SPECIES[i]), synonym.df$old)) > 0) {
idx <- grep(paste(no.CS.df$GENUS[i], no.CS.df$SPECIES[i]), synonym.df$old)
#Replace the genus and species names with the current names
no.CS.df$GENUS[i] <- unlist(str_split(synonym.df$current[idx], " "))[1]
no.CS.df$SPECIES[i] <- unlist(str_split(synonym.df$current[idx], " "))[2]
}
}
#Update taxonomy data
no.CS.df$ORDER <- tax.df$Order[match(no.CS.df$GENUS, tax.df$Genus)]
no.CS.df$CLASS <- tax.df$Class[match(no.CS.df$GENUS, tax.df$Genus)]
#Remove rows with no order classification
no.CS.df <- no.CS.df[!is.na(no.CS.df$ORDER),]
#Make dataframe of genome sizes for orders
no.CS.df2 <- data.frame(order=no.CS.df$ORDER,
size=no.CS.df$X1C.in.Mbp)
#Remove NA genome sizes
no.CS.df2 <- no.CS.df2[!is.na(no.CS.df2$size),]
##Assembly-based genome size data##
#Download and read in ncbi genome data (< 3 MB file)
download.file("ftp://ftp.ncbi.nlm.nih.gov/genomes/GENOME_REPORTS/eukaryotes.txt", destfile=paste0(Sys.Date(), "_eukaryotes.txt"))
ncbi <- read.csv(paste0(Sys.Date(), "_eukaryotes.txt"), header=TRUE, sep="\t")
#Filter for Ascomycota
ncbi.asc <- ncbi[ncbi$SubGroup == "Ascomycetes",]
#Remove duplicate biosamples
ncbi.asc <- ncbi.asc[!duplicated(ncbi.asc$BioSample.Accession[ncbi.asc$BioSample.Accession != "-"]),]
#Remove genomes which are too small to be credible
ncbi.asc <- ncbi.asc[ncbi.asc$Size..Mb. > 1,]
#Extract assembly method information
#Download and read in file with ftp links to assemblies (< 300 MB file)
download.file("ftp://ftp.ncbi.nlm.nih.gov/genomes/ASSEMBLY_REPORTS/assembly_summary_genbank.txt", destfile=paste0(Sys.Date(), "_assembly_summary_genbank.txt"))
assembly.sum <- read.csv(paste0(Sys.Date(), "_assembly_summary_genbank.txt"), skip=1, header=TRUE, sep="\t", quote="")
#Match to ncbi data
assembly.sum <- assembly.sum[match(ncbi.asc$Assembly.Accession, assembly.sum$X..assembly_accession),]
#Scrape Mycocosm website for data
mycocosm.asc <- read_html("https://mycocosm.jgi.doe.gov/ascomycota/ascomycota.info.html")
#Make dataframe
myc.asc <- as.data.frame(mycocosm.asc %>%
html_nodes(xpath="/html/body/div[4]/div/table") %>%
html_table())
#Add portal code
myc.asc$Portal <- sub("/", "", mycocosm.asc %>%
html_nodes("td:nth-child(2) a") %>%
html_attr("href"))
#Remove ncbi assemblies duplicated in mycocosm
assembly.sum <- assembly.sum[is.na(match(assembly.sum$asm_name, myc.asc$Portal)),]
ncbi.asc <- ncbi.asc[match(assembly.sum$X..assembly_accession, ncbi.asc$Assembly.Accession),]
#Remove square brackets from ncbi names
ncbi.asc$X.Organism.Name <- sub('\\[', "", ncbi.asc$X.Organism.Name)
ncbi.asc$X.Organism.Name <- sub('\\]', "", ncbi.asc$X.Organism.Name)
#Add column for genus
ncbi.asc$Genus <- gsub(" .*", "", ncbi.asc$X.Organism.Name)
myc.asc$Genus <- gsub(" .*", "", myc.asc$Name)
#Correct Mycocosm genome size units
myc.asc$Assembly.Length <- as.numeric(gsub(",","", myc.asc$Assembly.Length)) / 1000000
#Add taxonomy data to ncbi and mycocosm dataframes
for (i in c("Family", "Order", "Class")) {
myc.asc[[i]] <- tax.df[match(myc.asc$Genus, tax.df$Genus), i]
ncbi.asc[[i]] <- tax.df[match(ncbi.asc$Genus, tax.df$Genus), i]
}
#Combine Mycocosm and NCBI to make dataframe of genome sizes
CS.df <- data.frame(order=c(as.character(ncbi.asc$Order), as.character(myc.asc$Order)), size=c(as.numeric(ncbi.asc$Size..Mb.), as.numeric(myc.asc$Assembly.Length)))
#Remove incertae sedis and NA orders
CS.df2 <- CS.df[!is.na(CS.df$order),]
CS.df2 <- CS.df2[!grepl("incertae sedis", CS.df2$order),]
##Test significant difference of mean for each order##
#Make vector with unique orders for both datasets
no.CS.orders <- as.vector(unique(no.CS.df2$order))
CS.orders <- as.vector(unique(CS.df2$order))
#Filter for orders with 3 or more genome size measurements (for normality testing)
no.CS.filt <- no.CS.df2
CS.filt <- CS.df2
for (i in 1:length(CS.orders)) {
if (length(CS.filt$order[grepl(CS.orders[i], CS.filt$order)]) < 3) {
CS.filt <- CS.filt[CS.filt$order != CS.orders[i],]
}
}
for (i in 1:length(no.CS.orders)) {
if (length(no.CS.filt$order[grepl(no.CS.orders[i], no.CS.filt$order)]) < 3) {
no.CS.filt <- no.CS.filt[no.CS.filt$order != no.CS.orders[i],]
}
}
#Create vector of orders with both CS and no CS data
both.filt <- intersect(no.CS.filt$order, CS.filt$order)
#Create dataframe for results
sig <- data.frame(order=both.filt, pvalue=NA, noCS=NA, CS=NA)
#Significance testing
for (i in 1:length(both.filt)) {
print(both.filt[i])
x <- no.CS.df2$size[no.CS.df2$order == both.filt[i]]
y <- CS.df2$size[CS.df2$order == both.filt[i]]
#Add columns with means
sig$noCS[i] <- mean(x)
sig$CS[i] <- mean(y)
#Test for normality of data
shapiro.x <- shapiro.test(x)
shapiro.y <- shapiro.test(y)
#Reject normality if p-value < 0.05 and do Wilcoxon, otherwise do t-test
if (shapiro.x$p.value < 0.05 || shapiro.y$p.value < 0.05) {
print("Reject normality, doing Wilcoxon test")
wilcox <- wilcox.test(x=x, y=y, mu=0)
sig$pvalue[sig$order == both.filt[i]] <- wilcox$p.value
} else {
print("Normal data, doing t-test")
ttest <- t.test(x=x, y=y, mu=0)
sig$pvalue[sig$order == both.filt[i]] <- ttest$p.value
}
}
##Create plotting dataframes
#Create dataframe for branch labels
branches <- data.frame(node=asc.tree$edge[,2],
edge_num=1:nrow(asc.tree$edge),
branch_label=rep(NA,nrow(asc.tree$edge)))
#Read in tree node labels for classes
classnodes <- read.csv("data/classnodes.csv", header=TRUE)
#Add class
for (i in 1:length(classnodes$class)) {
branches$branch_label[branches$edge_num == classnodes$node[i]] <- as.character(classnodes$class[i])
}
#Order by node
branches <- branches[order(branches$node),]
#Add colour
branches$colour <- classnodes$colour[match(branches$branch_label, classnodes$class)]
#Make dataframe matching taxonomy data with the Ascomycota tree tip labels for colours
tax.df3 <- data.frame(order=asc.tree$tip.label,
class=tax.df2$Class[match(asc.tree$tip.label, unique(tax.df2$Order))],
CS="N",
noCS="N")
#Add to CS column for whether the order has CS genome size data
tax.df3$CS[!is.na(match(tax.df3$order, CS.df$order))] <- "Y"
#Add to noCS column for whether the order has noCS genome size data
tax.df3$noCS[!is.na(match(tax.df3$order, no.CS.df2$order))] <- "Y"
#Add column for number of species
tax.df3$species <- NA
for (i in 1:length(tax.df3$order)) {
tax.df3$species[i] <- sum(tax.df$Species[tax.df$Order == tax.df3$order[i]])
}
#Make dataframe of class data to colour class branches
class.df <- data.frame(class=unique(tax.df3$class),
CS="N",
noCS="N")
#Add genome data to class dataframe
class.df$CS[match(unique(tax.df3$class[which(tax.df3$CS == "Y")]), class.df$class)] <- "Y"
class.df$noCS[match(unique(tax.df3$class[which(tax.df3$noCS == "Y")]), class.df$class)] <- "Y"
#Add genome data to branches dataframe
branches$CS.fontcol <- class.df$CS[match(branches$branch_label, class.df$class)]
branches$noCS.fontface <- class.df$noCS[match(branches$branch_label, class.df$class)]
#Dataframes for vertical grid lines
box.lines <- data.frame(x=seq(0, 240, 10), .panel="Genome size (Mbp/1C)", stringsAsFactors=TRUE)
supp.box.lines <- data.frame(x=seq(0, RoundTo(max(c(no.CS.df2$size, CS.df2$size)), 100, FUN=ceiling), 100), .panel="Genome size (Mbp/1C)", stringsAsFactors=TRUE)
#Dataframe for mean lines for cytometric and assembly-based methods
no.CS.mean <- data.frame(x=mean(no.CS.df2$size), .panel="Genome size (Mbp/1C)", stringsAsFactors=TRUE)
CS.mean <- data.frame(x=mean(CS.df2$size), .panel="Genome size (Mbp/1C)", stringsAsFactors=TRUE)
#Add class data to genome size dataframe for plot colours
no.CS.df3 <- no.CS.df2
no.CS.df3$class <- tax.df2$Class[match(no.CS.df3$order,tax.df2$Order)]
#Create dataframe for adding sample size to plot
counts.df <- tax.df3
#Remove orders without genome size data
counts.df <- counts.df[which(counts.df$noCS == "Y" | counts.df$CS == "Y"),]
#Add column with count of sample size for no CS/CS
counts.df$noCScount <- table(unlist(no.CS.df2$order))[match(counts.df$order, names(table(unlist(no.CS.df2$order))))]
counts.df$CScount <- table(unlist(CS.df2$order))[match(counts.df$order,names(table(unlist(CS.df2$order))))]
#Put brackets around count numbers
counts.df$noCScount <- paste0("(", counts.df$noCScount,")")
counts.df$CScount <- paste0("(", counts.df$CScount,")")
#Replace NA with 0
counts.df$noCScount[counts.df$noCScount == "(NA)"] <- "(0)"
counts.df$CScount[counts.df$CScount == "(NA)"] <- "(0)"
#Add column with asterisks for orders with significant difference of means
#0.05 > x > 0.01
for (i in 1:length(sig$order[sig$pvalue < 0.05 & sig$pvalue > 0.01])) {
counts.df$sig[counts.df$order == sig$order[sig$pvalue < 0.05 & sig$pvalue > 0.01][i]] <- "*"
}
#0.01 > x > 0.001
for (i in 1:length(sig$order[sig$pvalue < 0.01 & sig$pvalue > 0.001])) {
counts.df$sig[counts.df$order == sig$order[sig$pvalue < 0.01 & sig$pvalue > 0.001][i]] <- "**"
}
#0.001 > x
for (i in 1:length(sig$order[sig$pvalue < 0.001])) {
counts.df$sig[counts.df$order == sig$order[sig$pvalue < 0.001][i]] <- "***"
}
#Add column with the upper limit per order (to position labels)
counts.df$noCSmax <- NA
for (i in unique(no.CS.df2$order)) {
counts.df[counts.df$order==i,]$noCSmax <- max(no.CS.df2[no.CS.df2$order==i & no.CS.df2$size < 240,]$size)
}
counts.df$noCSmax.out <- NA
for (i in unique(no.CS.df2$order)) {
counts.df[counts.df$order==i,]$noCSmax.out <- max(no.CS.df2[no.CS.df2$order==i,]$size)
}
counts.df$CSmax.out <- NA
for (i in unique(CS.df2$order)) {
counts.df[counts.df$order==i,]$CSmax.out <- max(CS.df2[CS.df2$order==i,]$size)
}
#Add column to mark if there are outliers
counts.df$outliers[!is.na(match(counts.df$order, unique(rbind(no.CS.df2, CS.df2)$order[which(rbind(no.CS.df2, CS.df2)$size > 240)])))] <- "Y"
##Number of genome assemblies##
#Create data frame for number of genome assemblies per order
num.df <- data.frame(order=tax.df3$order)
#Add column with number of genomes in mycocosm and ncbi
for (i in 1:length(num.df$order)) {
num.df$num[i] <- length(grepl(num.df$order[i], myc.asc$Order)[grepl(num.df$order[i], myc.asc$Order) == TRUE]) + length(grepl(num.df$order[i], ncbi.asc$Order)[grepl(num.df$order[i], ncbi.asc$Order) == TRUE])
}
#Delete rows with no genomes
num.df <- num.df[num.df$num > 0,]
#Dataframes for vertical grid lines
bar.lines <- data.frame(x=seq(0, RoundTo(max(num.df$num), 200, FUN=ceiling) + 100, 100), .panel="Number of genome assemblies", stringsAsFactors=TRUE)
#Make dataframe of tree tip order for row shading
tips.df <- subset(fortify(asc.tree), isTip)
tips.df <- with(tips.df, label[order(y, decreasing=T)])
tips.df <- data.frame(tip=tips.df, min=seq(length(tips.df))-0.5, max=seq(length(tips.df))+0.5, col=NA)
tips.df$col <- rep_len(c(0,1),length(tips.df$tip))
#Function to remove unwanted elements from plots (https://stackoverflow.com/questions/36779537/ggplot2-facet-wrap-y-axis-scale-on-the-first-row-only)
gtable_filter_remove <- function (x, name, trim=TRUE){
matches <- !(x$layout$name %in% name)
x$layout <- x$layout[matches, , drop=FALSE]
x$grobs <- x$grobs[matches]
if (trim)
x <- gtable_trim(x)
x
}
##Plot tree against number of genomes and CS/noCS genome sizes##
#Dummy plot for correct scale of boxplot (not showing extreme outliers)
gg.dummy <- ggtree(asc.tree) +
geom_rect(data=tips.df,
aes(x=NULL,
y=NULL,
ymin=min,
ymax=max,
fill=as.factor(col),
xmin=-Inf,
xmax=+Inf),
alpha=0.15) +
geom_tree()
gg.dummy1 <- gg.dummy %<+% tax.df3 +
geom_tiplab(size=2.8,
aes(subset=noCS != "Y", colour=CS),
offset=0.1,) +
geom_tiplab(size=2.8,
aes(subset=noCS == "Y", colour=CS),
offset=0.1,
fontface="bold.italic") +
geom_tippoint(colour="white",
size=6) +
geom_tiplab(size=2,
aes(colour=CS, label=species),
offset=-0.01,
hjust=0.5)
gg.dummy2 <- gg.dummy1 %<+% branches +
geom_label2(aes(x=branch, label=branch_label, colour=CS.fontcol, subset=noCS.fontface == "N"),
fill="white",
size=2.8,
label.padding=unit(0.15, "lines"),
label.size=0) +
geom_label2(aes(x=branch, label=branch_label, colour=CS.fontcol, subset=noCS.fontface == "Y"),
fontface="bold.italic",
fill="white",
size=2.8,
label.padding=unit(0.15, "lines"),
label.size=0) +
scale_colour_manual(values=c("darkgrey", "black"))
gg.dummy3 <- gg.dummy2 +
geom_vline(data=box.lines,
color="grey94",
aes(xintercept=x)) +
geom_vline(data=no.CS.mean,
color="black",
linetype="dashed",
aes(xintercept=x)) +
geom_vline(data=CS.mean,
color="darkgrey",
linetype="dashed",
aes(xintercept=x))
gg.dummy4 <- facet_plot(gg.dummy3,
panel="Number of genome assemblies",
data=num.df,
geom=geom_barh,
aes(x=num, fill=class),
stat='identity')
gg.dummy5 <- facet_plot(gg.dummy4,
panel="Genome size (Mbp/1C)",
data=no.CS.df2,
geom=geom_boxploth,
outlier.size=1,
aes(x=size, group=label, fill=class))
gg.dummy5 <- facet_plot(gg.dummy5,
panel="Genome size (Mbp/1C)",
data=CS.df2,
geom=geom_boxploth,
outlier.size=1,
colour="darkgrey",
linetype="dotted",
alpha=0.3,
aes(x=size, group=label, fill=class))
gg.dummy5 <- facet_plot(gg.dummy5,
panel="Genome size (Mbp/1C)",
data=counts.df,
geom=geom_text,
size=2,
nudge_x=10,
aes(x=noCSmax, label=noCScount))
gg.dummy5 <- facet_plot(gg.dummy5,
panel="Genome size (Mbp/1C)",
data=counts.df,
geom=geom_text,
size=2,
nudge_x=10,
nudge_y=0.5,
aes(x=noCSmax, label=sig))
gg.dummy5 <- facet_plot(gg.dummy5,
panel="Genome size (Mbp/1C)",
data=counts.df[which(counts.df$outliers == "Y"),],
geom=geom_text,
label="\u25BA",
size=2,
aes(x=235)) +
scale_x_continuous(breaks=seq(0, 240, by=20),
expand=c(0, 0),
position="top",
sec.axis=dup_axis()) +
scale_y_continuous(expand=expansion(mult=0.005)) +
scale_fill_manual(values=c("snow3", "white", as.vector(classnodes$colour[classnodes$colour != ""]))) +
coord_cartesian(xlim=c(0, 240), clip="off") +
theme_classic() +
theme(panel.border=element_blank(),
legend.position="none",
strip.placement="outside",
axis.text.x.top=element_text(angle=45, vjust=0.3),
axis.text.x.bottom=element_text(angle=45, hjust=1),
panel.spacing=unit(1, "lines"),
strip.background=element_blank())
#Make plot into table
dummy <- ggplotGrob(gg.dummy5)
#Change widths of bar and box panels
dummy$widths[7] <- 0.70*dummy$widths[7]
dummy$widths[9] <- 0.70*dummy$widths[9]
#Main plot
gg.main <- ggtree(asc.tree) +
geom_rect(data=tips.df,
aes(x=NULL,
y=NULL,
ymin=min,
ymax=max,
fill=as.factor(col),
xmin=-Inf,
xmax=+Inf),
alpha=0.15)
for (i in 1:length(na.omit(branches[branches$colour != "",])$node)) {
gg.main <- gg.main +
geom_hilight(node=na.omit(branches[branches$colour != "",])$node[i],
extend=1.2,
alpha=0.1, fill=na.omit(branches[branches$colour != "",])$colour[i])
}
gg.main <- gg.main + geom_tree()
gg.main1 <- gg.main %<+% tax.df3 +
geom_tiplab(size=2.8,
aes(subset=noCS != "Y", colour=CS),
offset=0.1) +
geom_tiplab(size=2.8,
aes(subset=noCS == "Y", colour=CS),
offset=0.1,
fontface="bold.italic") +
geom_tippoint(colour="white",
size=6) +
geom_tiplab(size=2,
aes(colour=CS, label=species),
offset=-0.01,
hjust=0.5)
gg.main2 <- gg.main1 %<+% branches +
geom_label2(aes(x=branch, label=branch_label, colour=CS.fontcol, subset=noCS.fontface == "N"),
fill="white",
size=2.8,
label.padding=unit(0.15, "lines"),
label.size=0) +
geom_label2(aes(x=branch, label=branch_label, colour=CS.fontcol, subset=noCS.fontface == "Y"),
fontface="bold.italic",
fill="white",
size=2.8,
label.padding=unit(0.15, "lines"),
label.size=0) +
scale_colour_manual(values=c("darkgrey", "black"))
gg.main3 <- gg.main2 +
geom_vline(data=box.lines,
color="grey94",
aes(xintercept=x)) +
geom_vline(data=no.CS.mean,
color="black",
linetype="dashed",
aes(xintercept=x)) +
geom_vline(data=CS.mean,
color="darkgrey",
linetype="dashed",
aes(xintercept=x)) +
geom_vline(data=bar.lines,
color="grey94",
aes(xintercept=x))
gg.main4 <- facet_plot(gg.main3 + xlim_tree(3.2),
panel="Number of genome assemblies",
data=num.df,
geom=geom_barh,
aes(x=num, fill=class),
stat='identity')
gg.main4 <- facet_plot(gg.main4,
panel="Number of genome assemblies",
data=num.df,
geom=geom_text,
size=2,
hjust=0,
aes(x=num, label=paste0("(",num,")")))
gg.main5 <- facet_plot(gg.main4,
panel="Genome size (Mbp/1C)",
data=no.CS.df2,
geom=geom_boxploth,
outlier.size=1,
aes(x=size, group=label, fill=class))
gg.main5 <- facet_plot(gg.main5,
panel="Genome size (Mbp/1C)",
data=CS.df2,
geom=geom_boxploth,
outlier.size=1,
colour="darkgrey",
linetype="dotted",
alpha=0.3,
aes(x=size, group=label, fill=class))
gg.main5 <- facet_plot(gg.main5,
panel="Genome size (Mbp/1C)",
data=counts.df,
geom=geom_text,
size=2,
hjust=0,
aes(x=noCSmax, label=noCScount)) +
scale_x_continuous(breaks=pretty_breaks(10),
expand=c(0, 0),
position="top",
sec.axis=dup_axis()) +
scale_y_continuous(expand=expansion(mult=0.005)) +
scale_fill_manual(values=c("snow3","white",as.vector(classnodes$colour[classnodes$colour != ""]))) +
theme_classic() +
theme(panel.border=element_blank(),
legend.position="none",
strip.placement="outside",
axis.text.x.top=element_text(angle=45, vjust=0.3),
axis.text.x.bottom=element_text(angle=45, hjust=1),
panel.spacing=unit(1, "lines"),
strip.background=element_blank())
#Make plot into table
gg.main.tab <- ggplotGrob(gg.main5)
#Change widths of bar and box panels
gg.main.tab$widths[7] <- 0.70*gg.main.tab$widths[7]
gg.main.tab$widths[9] <- 0.70*gg.main.tab$widths[9]
#Make vector of elements in table
elements <- gg.main.tab$layout$name
#Remove unwanted axes on tree panel and entire third panel with bad scale
gg.main6 <- gtable_filter_remove(gg.main.tab, name=elements[c(5,8,11,13,4,7,10)], trim=FALSE)
#Replace third panel with dummy boxplot and axes
element.replace <- c("panel-1-3", "axis-t-3", "axis-b-3")
for (i in element.replace) {
pos <- c(subset(dummy$layout, name == i, se=t:r))
gg.main6 <- gtable_add_grob(gg.main6, dummy$grobs[[which(dummy$layout$name == i)]], pos$t, pos$l, pos$b, pos$r, name=i)
}
#Plot to file
tiff(file=paste0("Fig1-", Sys.Date(), ".tiff"), height=15, width=10, units="in", res=300)
plot(gg.main6)
dev.off()
############################
## SUPPLEMENTARY FIGURE 1 ##
############################
#Supplementary figure including extreme outliers
gg.supp <- ggtree(asc.tree) +
geom_rect(data=tips.df,
aes(x=NULL,
y=NULL,
ymin=min,
ymax=max,
fill=as.factor(col),
xmin=-Inf,
xmax=+Inf),
alpha=0.15)
for (i in 1:length(na.omit(branches[branches$colour != "",])$node)) {
gg.supp <- gg.supp +
geom_hilight(node=na.omit(branches[branches$colour != "",])$node[i],
extend=1.2,
alpha=0.1, fill=na.omit(branches[branches$colour != "",])$colour[i])
}
gg.supp <- gg.supp +
geom_tree()
gg.supp1 <- gg.supp %<+% tax.df3 +
geom_tiplab(size=2.8,
aes(subset=noCS != "Y", colour=CS),
offset=0.1) +
geom_tiplab(size=2.8,
aes(subset=noCS == "Y", colour=CS), fontface="bold.italic",
offset=0.1) +
geom_tippoint(colour="white",
size=6) +
geom_tiplab(size=2,
aes(colour=CS, label=species),
offset=-0.01,
hjust=0.5) +
scale_colour_manual(values=c("darkgrey", "black"))
gg.supp2 <- gg.supp1 %<+% branches +
geom_label2(aes(x=branch, label=branch_label, colour=CS.fontcol, subset=noCS.fontface == "N"),
fill="white",
size=2.8,
label.padding=unit(0.15, "lines"),
label.size=0) +
geom_label2(aes(x=branch, label=branch_label, colour=CS.fontcol, subset=noCS.fontface == "Y"),
fontface="bold.italic",
fill="white",
size=2.8,
label.padding=unit(0.15, "lines"),
label.size=0)
gg.supp3 <- gg.supp2 +
geom_vline(data=supp.box.lines,
color="grey94",
aes(xintercept=x))
gg.supp3 <- facet_plot(gg.supp3 + xlim_tree(3),
panel="Genome size (Mbp/1C)",
data=no.CS.df2,
geom=geom_boxploth,
outlier.size=1,
aes(x=size, group=label, fill=class))
gg.supp3 <- facet_plot(gg.supp3,
panel="Genome size (Mbp/1C)",
data=CS.df2,
geom=geom_boxploth,
outlier.size=1,
colour="darkgrey",
linetype="dotted",
alpha=0.3,
aes(x=size, group=label, fill=class))
gg.supp4 <- facet_plot(gg.supp3,
panel="Sample size",
data=counts.df[counts.df$CS == "Y",],
geom=geom_text,
size=2,
hjust=1,
aes(x=500, label=CScount))
gg.supp4 <- facet_plot(gg.supp4,
panel="Sample size",
data=counts.df[counts.df$noCS == "Y",],
geom=geom_text,
fontface="bold.italic",
size=2,
hjust=0,
aes(x=600, label=noCScount)) +
xlim_expand(c(0, 1000), panel="Sample size") +
scale_x_continuous(breaks=pretty_breaks(10),
expand=c(0, 0),
position="top",
sec.axis=dup_axis()) +
scale_y_continuous(expand=expansion(mult=0.005)) +
scale_fill_manual(values=c("snow3","white",as.vector(classnodes$colour[classnodes$colour != ""]))) +
coord_cartesian(clip="off") +
theme_classic() +
theme(panel.border=element_blank(),
legend.position="none",
panel.spacing=unit(0, "lines"),
plot.margin=unit(c(0,0,5,0), "mm"),
strip.placement="outside",
strip.background=element_blank())
#Remove unwanted axes on tree panel
gg.supp.tab <- ggplotGrob(gg.supp4)
elements <- gg.supp.tab$layout$name
gg.supp5 <- gtable_filter_remove(gg.supp.tab, name=elements[c(5, 7, 8, 10, 11, 13, 15)], trim=FALSE)
#Change widths of bar and box panels
gg.supp5$widths[9] <- 0.1*gg.supp5$widths[9]
#Plot to file
tiff(file=paste0("SuppFig1-", Sys.Date(), ".tiff"), height=15, width=10, units="in", res=300)
plot(gg.supp5)
dev.off()
##############
## FIGURE 3 ##
##############
## FIGURE 3A ##
##Identify case study species with both cytometric and assembly-based measurements
#Add name field to genome size dataframe
no.CS.df$name <- paste0(no.CS.df$GENUS, " ", no.CS.df$SPECIES)
#Create an empty list for species with both cytometric and assembly-based
species.comp <- list()
#For each species with cytometric data...
for (i in 1:length(unique(no.CS.df$name))) {
#If a genome assembly is also in NCBI...
if (length(grep(unique(no.CS.df$name)[i], ncbi.asc$X.Organism.Name)) > 0) {
#Add the number of genome assemblies to the list
species.comp[[unique(no.CS.df$name)[i]]] <- length(grep(unique(no.CS.df$name)[i], ncbi.asc$X.Organism.Name))
}
}
#Remove unknown species (i.e. sp.)
species.comp <- species.comp[-grep("\\bsp\\b", names(species.comp))]
#Print number of species-level comparisons possible
length(species.comp)
#Make vector of abbreviations
abb <- abbreviate(names(species.comp), minlength=3)
#For each species-level case study...
for (i in 1:length(species.comp)) {
#Print progress
cat("Pulling genome reports ", (i - 1), "/", length(species.comp), " species", "\r")
#Get NCBI assembly links
assemblies <- assembly.sum[agrep(names(species.comp)[i], assembly.sum$organism_name),]
ftp.links <- paste0(assemblies$ftp_path, "/", assemblies$X..assembly_accession,"_", assemblies$asm_name, "_assembly_report.txt")
#Create a results dataframe of genome sizes and assembly methods
ncbi.methods.df <- data.frame(species=rep(names(species.comp)[i], length(ftp.links)),
size=ncbi.asc$Size..Mb.[agrep(names(species.comp)[i], ncbi.asc$X.Organism.Name)],
method=NA,
type="CS")
#For each assembly...
for (j in 1:length(ftp.links)) {
#Try to download the assembly report
report <- NULL
report <- tryCatch(unlist(strsplit(getURL(ftp.links[j]), "\\r*\\n")), error=function(e) {e$message})
#If the assembly method is recorded...
if (length(report[grep("Assembly method", report)]) > 0) {
#Extract the assembly method and add to dataframe
ncbi.methods.df$method[j] <- sub("# Assembly method: ", "", report[grep("Assembly method", report)])
}
}
#Create a dataframe of genome sizes and cytometric methods from the fungal genome size database
no.CS.methods.df <- data.frame(species=no.CS.df$name[grep(names(species.comp)[i], no.CS.df$name)],
size=no.CS.df$X1C.in.Mbp[grep(names(species.comp)[i], no.CS.df$name)],
method=no.CS.df$METHOD[grep(names(species.comp)[i], no.CS.df$name)],
type="noCS")
#Combine the assembly-based and cytometric dataframes
methods.df <- rbind(ncbi.methods.df, no.CS.methods.df)
#Remove any rows without methods
methods.df <- methods.df[!is.na(methods.df$method),]
#Make species name uniform
methods.df$species <- names(species.comp)[i]
#Rename with abbreviation
assign(paste0(abb[i],".methods.df"), methods.df)
}
#Combine all methods dataframes
all.methods.df <- do.call("rbind", mget(paste0(abb, ".methods.df")))
rownames(all.methods.df) <- NULL
#Correct method names
all.methods.df$method[grep("allpaths lg", all.methods.df$method, ignore.case=TRUE)] <- "ALLPATHS-LG"
all.methods.df$method[grep("smrt", all.methods.df$method, ignore.case=TRUE)] <- "SMRT Analysis"
all.methods.df$method[grep("//bgs", all.methods.df$method, ignore.case=TRUE)] <- "Newbler"
all.methods.df$method <- gsub("_", " ", all.methods.df$method)
#Make method names uniform
assemblers <- read.csv("data/assemblers.csv", header=FALSE)$V1
for (i in assemblers) {
all.methods.df$method[grep(paste0("\\b", i), all.methods.df$method, ignore.case=TRUE)] <- i
}
#Add asterisk if reported method isn't known
if (length(all.methods.df$method[is.na(match(all.methods.df$method, assemblers))]) > 0) {
all.methods.df$method[is.na(match(all.methods.df$method, assemblers)) & all.methods.df$type == "CS"] <- paste(all.methods.df$method[is.na(match(all.methods.df$method, assemblers)) & all.methods.df$type == "CS"], "*")
}
#For each species-level case study...
for (i in 1:length(species.comp)) {
#Get the dataframe for the species
methods.df <- all.methods.df[grep(names(species.comp)[i], all.methods.df$species),]
#If there are at least 3 unique methods with more than 1 measurement...
if (length(unique(methods.df$method)) > 2 & length(methods.df$method) != length(unique(methods.df$method))) {
#Remove hyphens for Tukey testing
methods.df$method <- gsub("-", " ", methods.df$method)
#Tukey significance testing
tukey <- TukeyHSD(aov(lm(size ~ method, data=methods.df)))
#Make dataframe for ggplot with tukey groups
sig.df <- data.frame(multcompLetters(tukey[["method"]][,4])["Letters"])
sig.df <- data.frame(Treatment=rownames(sig.df), Letters=sig.df$Letters)
if (length(sig.df$Treatment) > 0) {
sig.df$species <- names(species.comp)[i]
}
#Rename with abbreviation
assign(paste0(abb[names(abb) == names(species.comp)[i]],".methods.df"), methods.df)
assign(paste0(abb[names(abb) == names(species.comp)[i]],".tukey.df"), sig.df)
}
}
#Find species for which there were enough different methods to perform Tukey testing
species.mainfig <- list()
counter <- 0
for (i in 1:length(abb)) {
if (exists(paste0(abb[i], ".tukey.df"))) {
counter <- counter + 1
species.mainfig[counter] <- abb[i]
}
}
species.mainfig <- unlist(species.mainfig)
#Combine species dataframes
spec.df <- do.call("rbind", mget(paste0(species.mainfig, ".methods.df")))
rownames(spec.df) <- NULL
spec.df$size <- as.numeric(spec.df$size)
#Combine Tukey dataframe
tukey.df <- do.call("rbind", mget(paste0(species.mainfig, ".tukey.df")))
#Create dataframe for plot labels
labels.df <- unique(spec.df[c(1,3,4)])
for (i in 1:length(labels.df$species)) {
#Add field with max y position for label
labels.df$max[i] <- max(spec.df$size[spec.df$species == labels.df$species[i] & spec.df$method == labels.df$method[i]])
#Add field with sample size
labels.df$count[i] <- paste0("n=",length(spec.df$size[spec.df$species == labels.df$species[i] & spec.df$method == labels.df$method[i]]))
}