-
Notifications
You must be signed in to change notification settings - Fork 0
/
11a.plotting_trees_and_summaries.R
executable file
·1982 lines (1689 loc) · 147 KB
/
11a.plotting_trees_and_summaries.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
###This script collects and summarizes results from previous analyses by HybPhaser, ASTRAL-III, ASTRAL-Pro, and IQ-TREE.
#LOAD PACKAGES ----
library(ape)
library(treeio)
library(tidytree)
library(devtools); devtools::install_github("chutter/AstralPlane")
library(AstralPlane)
library(reshape2)
library(tidyr)
library(dplyr)
library(ggplot2); library(ggtree)
library(ggimage)
library(ggnewscale)
library(cowplot)
library(colorRamps)
library(phytools)
library(sf)
library(rnaturalearth)
library(rnaturalearthdata)
library(TreeDist)
library(phangorn)
#READ IN METADATA ----
metadata<-read.csv("2e.metadata.csv", header=T, stringsAsFactors=FALSE, fileEncoding="latin1")
#READ IN PHYLOGENETIC RESULTS ----
####TEMP NEW DATA CLOCKLIKE GENES
tree_ASTRALIII_superstrict_and_clocklike<-read.tree(file = "results_ASTRALIII_superstrict_and_clocklike/species_tree.tre")
tree_ASTRALIII_superstrict_and_clocklike<-root(tree_ASTRALIII_superstrict_and_clocklike, outgroup = "S1321")
tree_ASTRALIII_superstrict_and_clocklike_astral_annotations<-createAstralPlane(astral.tree = "results_ASTRALIII_superstrict_and_clocklike/species_tree_t2.tre",
outgroups = "S1321",
tip.length = 1)
tree_ASTRALIII_superstrict_and_clocklike_astral_annotations_piecharts<-nodepie(tree_ASTRALIII_superstrict_and_clocklike_astral_annotations@nodeData, cols=2:4)
tree_ASTRALIII_superstrict_and_clocklike_astral_annotations_piecharts<-lapply(tree_ASTRALIII_superstrict_and_clocklike_astral_annotations_piecharts, function(g) g+scale_fill_manual(values = c("darkblue","lightblue","grey")))
mean(tree_ASTRALIII_superstrict_and_clocklike_astral_annotations@nodeData$q1, na.rm = T)
## ASTRAL-III inclusive ----
tree_ASTRALIII_inclusive<-read.tree(file = "results_ASTRALIII_inclusive/species_tree.tre")
#Root the tree to the outgroup
tree_ASTRALIII_inclusive<-root(tree_ASTRALIII_inclusive, outgroup = "S1321")
#Import ASTRAL results to use node annotations with R package AstralPlane.
#Note that here we import the "-t 2" version from ASTRAL-III, in which all the annotations for node support have been logged.
tree_ASTRALIII_inclusive_astral_annotations<-createAstralPlane(astral.tree = "results_ASTRALIII_inclusive/species_tree_t2.tre",
outgroups = "S1321",
tip.length = 1)
#Use the nicely ordered dataframe from this object to create a list object with pie charts for plotting in ggtree later.
#Put pie chart data into a list that can be read by ggtree (see https://yulab-smu.top/treedata-book/chapter8.html).
tree_ASTRALIII_inclusive_astral_annotations_piecharts<-nodepie(tree_ASTRALIII_inclusive_astral_annotations@nodeData, cols=2:4)
tree_ASTRALIII_inclusive_astral_annotations_piecharts<-lapply(tree_ASTRALIII_inclusive_astral_annotations_piecharts, function(g) g+scale_fill_manual(values = c("darkblue","lightblue","grey")))
#Also read in the set of gene trees used by ASTRAL.
tree_ASTRALIII_inclusive_gene_trees<-read.tree(file = "results_ASTRALIII_inclusive/gene_trees_combined.tre")
## ASTRAL-III strict ----
tree_ASTRALIII_strict<-read.tree(file = "results_ASTRALIII_strict/species_tree.tre")
#Root the tree to the outgroup
tree_ASTRALIII_strict<-root(tree_ASTRALIII_strict, outgroup = "PAFTOL_019361")
#Import ASTRAL results to use node annotations with R package AstralPlane.
#Note that here we import the "-t 2" version from ASTRAL-III, in which all the annotations for node support have been logged.
tree_ASTRALIII_strict_astral_annotations<-createAstralPlane(astral.tree = "results_ASTRALIII_strict/species_tree_t2.tre",
outgroups = "PAFTOL_019361",
tip.length = 1)
#Use the nicely ordered dataframe from this object to create a list object with pie charts for plotting in ggtree later.
#Put pie chart data into a list that can be read by ggtree (see https://yulab-smu.top/treedata-book/chapter8.html).
tree_ASTRALIII_strict_astral_annotations_piecharts<-nodepie(tree_ASTRALIII_strict_astral_annotations@nodeData, cols=2:4)
tree_ASTRALIII_strict_astral_annotations_piecharts<-lapply(tree_ASTRALIII_strict_astral_annotations_piecharts, function(g) g+scale_fill_manual(values = c("darkblue","lightblue","grey")))
#Also read in the set of gene trees used by ASTRAL.
tree_ASTRALIII_strict_gene_tree<-read.tree(file = "results_ASTRALIII_strict/gene_trees_combined.tre")
## ASTRAL-III superstrict ----
tree_ASTRALIII_superstrict<-read.tree(file = "results_ASTRALIII_superstrict/species_tree.tre")
#Root the tree to the outgroup
tree_ASTRALIII_superstrict<-root(tree_ASTRALIII_superstrict, outgroup = "PAFTOL_019361")
#Import ASTRAL results to use node annotations with R package AstralPlane.
#Note that here we import the "-t 2" version from ASTRAL-III, in which all the annotations for node support have been logged.
tree_ASTRALIII_superstrict_astral_annotations<-createAstralPlane(astral.tree = "results_ASTRALIII_superstrict/species_tree_t2.tre",
outgroups = "PAFTOL_019361",
tip.length = 1)
#Use the nicely ordered dataframe from this object to create a list object with pie charts for plotting in ggtree later.
#Put pie chart data into a list that can be read by ggtree (see https://yulab-smu.top/treedata-book/chapter8.html).
tree_ASTRALIII_superstrict_astral_annotations_piecharts<-nodepie(tree_ASTRALIII_superstrict_astral_annotations@nodeData, cols=2:4)
tree_ASTRALIII_superstrict_astral_annotations_piecharts<-lapply(tree_ASTRALIII_superstrict_astral_annotations_piecharts, function(g) g+scale_fill_manual(values = c("darkblue","lightblue","grey")))
#Also read in the set of gene trees used by ASTRAL.
tree_ASTRALIII_superstrict_gene_trees<-read.tree(file = "results_ASTRALIII_superstrict/gene_trees_combined.tre")
## ASTRAL-III superstrict-by-tribe ----
tree_ASTRALIII_superstrict_by_tribe<-read.tree(file = "results_ASTRALIII_superstrict_by_tribe/species_tree.tre")
#Root the tree to the outgroup
tree_ASTRALIII_superstrict_by_tribe<-root(tree_ASTRALIII_superstrict_by_tribe, outgroup = "PAFTOL_019361")
#Import ASTRAL results to use node annotations with R package AstralPlane.
#Note that here we import the "-t 2" version from ASTRAL-III, in which all the annotations for node support have been logged.
tree_ASTRALIII_superstrict_by_tribe_astral_annotations<-createAstralPlane(astral.tree = "results_ASTRALIII_superstrict_by_tribe/species_tree_t2.tre",
outgroups = "PAFTOL_019361",
tip.length = 1)
#Use the nicely ordered dataframe from this object to create a list object with pie charts for plotting in ggtree later.
#Put pie chart data into a list that can be read by ggtree (see https://yulab-smu.top/treedata-book/chapter8.html).
tree_ASTRALIII_superstrict_by_tribe_astral_annotations_piecharts<-nodepie(tree_ASTRALIII_superstrict_by_tribe_astral_annotations@nodeData, cols=2:4)
tree_ASTRALIII_superstrict_by_tribe_astral_annotations_piecharts<-lapply(tree_ASTRALIII_superstrict_by_tribe_astral_annotations_piecharts, function(g) g+scale_fill_manual(values = c("darkblue","lightblue","grey")))
#Also read in the set of gene trees used by ASTRAL.
tree_ASTRALIII_superstrict_by_tribe_gene_trees<-read.tree(file = "results_ASTRALIII_superstrict_by_tribe/gene_trees_combined.tre")
## ASTRAL-Pro ----
tree_ASTRAL_Pro<-read.tree(file = "6i.ASTRAL_Pro_species_tree.tre")
#Root the tree to the outgroup
tree_ASTRAL_Pro<-root(tree_ASTRAL_Pro, outgroup = "S1321")
#Import ASTRAL results to use node annotations with R package AstralPlane.
#Note that here we import the "-t 2" version from ASTRAL-III, in which all the annotations for node support have been logged.
tree_ASTRAL_Pro_astral_annotations<-createAstralPlane(astral.tree = "6i.ASTRAL_Pro_species_tree.tre",
outgroups = "S1321",
tip.length = 1)
#Use the nicely ordered dataframe from this object to create a list object with pie charts for plotting in ggtree later.
#Put pie chart data into a list that can be read by ggtree (see https://yulab-smu.top/treedata-book/chapter8.html).
tree_ASTRAL_Pro_astral_annotations_piecharts<-nodepie(tree_ASTRAL_Pro_astral_annotations@nodeData, cols=2:4)
tree_ASTRAL_Pro_astral_annotations_piecharts<-lapply(tree_ASTRAL_Pro_astral_annotations_piecharts, function(g) g+scale_fill_manual(values = c("darkblue","lightblue","grey")))
#Also read in the set of gene trees used by ASTRAL.
tree_ASTRAL_Pro_gene_trees<-read.tree(file = "6f.ASTRAL_Pro_input_gene_trees.tre")
##ML nuclear ----
#Read in the ML IQ-TREE that was calibrated in treePL. This tree was already rooted to S1321 in IQ-TREE.
tree_IQ_TREE_supermatrix_calibrated<-read.beast(file = "results_treePL_calibration/output_treePL_dating/treePL_calibrated_phylogeny_summary.tre")
#Also read in the IQ-TREE version of this same tree with cGF and sCF concordance factors.
tree_IQ_TREE_supermatrix_concordance_factors<-read.tree(file = "results_treePL_calibration/output_iqtree_condordance_factors/iqtree_ML_tree_with_concordance_factors.tree")
#Add the concordance factors to the calibrated tree, such that all tree node annotations are held within a single tree object.
tree_IQ_TREE_supermatrix_calibrated@data$node_cf<-NA
tree_IQ_TREE_supermatrix_calibrated@data$gCF<-NA
tree_IQ_TREE_supermatrix_calibrated@data$sCF<-NA
tree_IQ_TREE_supermatrix_calibrated@data$concordance_factors<-NA
tree_IQ_TREE_supermatrix_calibrated@data$bootstrap<-NA
tree_IQ_TREE_supermatrix_calibrated@data$bootstrap_symbol<-NA
tree_IQ_TREE_supermatrix_calibrated@data$support<-NA
#And eight more columns to score gCF and sCF values in bins, which will be useful for plotting node labels later.
tree_IQ_TREE_supermatrix_calibrated@data$sCF_support<-NA
tree_IQ_TREE_supermatrix_calibrated@data$gCF_support<-NA
#Use phytools function matchNodes to find correspondence among node numbers in both trees.
matched_nodes<-data.frame(matchNodes(tree_IQ_TREE_supermatrix_calibrated@phylo, tree_IQ_TREE_supermatrix_concordance_factors, method = "descendants"))
tree_IQ_TREE_supermatrix_calibrated@data$node_cf<-matched_nodes$tr2[match(tree_IQ_TREE_supermatrix_calibrated@data$node, matched_nodes$tr1)]
#Loop through nodes to find concordance factors and store results.
for (i in 1:nrow(tree_IQ_TREE_supermatrix_calibrated@data)){
node_cf<-tree_IQ_TREE_supermatrix_calibrated@data$node_cf[i]
if(is.na(node_cf)==F){
#Find concordance factors.
concordance_factor<-tree_IQ_TREE_supermatrix_concordance_factors$node.label[node_cf-length(tree_IQ_TREE_supermatrix_concordance_factors$tip.label)]
#Update notation.
bootstrap<-as.numeric(strsplit(concordance_factor, "/")[[1]][1])
bootstrap_symbol<-as.numeric(strsplit(concordance_factor, "/")[[1]][1])
if(is.na(bootstrap_symbol)==F){if(round(bootstrap_symbol, 0)==100){bootstrap_symbol<-"*"}}
gCF<-as.numeric(strsplit(concordance_factor, "/")[[1]][3])
sCF<-as.numeric(strsplit(concordance_factor, "/")[[1]][4])
#Store results.
tree_IQ_TREE_supermatrix_calibrated@data$bootstrap[i]<-bootstrap
tree_IQ_TREE_supermatrix_calibrated@data$bootstrap_symbol[i]<-bootstrap_symbol
tree_IQ_TREE_supermatrix_calibrated@data$gCF[i]<-gCF
tree_IQ_TREE_supermatrix_calibrated@data$sCF[i]<-sCF
if(is.na(bootstrap)==F){if(round(bootstrap, 0)==100){bootstrap<-"*"}}
#Define the support from these values to colour labels in tree plot later (rules based on suggestion by Lars Nauheimer).
if(is.na(sCF)==F | is.na(gCF)==F){
if(sCF>40){support="blue"}
if(gCF>20){support="black"}
if(sCF<40){support="orange"}
if(sCF<35){support="red"}
concordance_factor_combined<-paste(round(as.numeric(gCF), 0),
round(as.numeric(sCF), 0),
sep="/")
#Store results.
tree_IQ_TREE_supermatrix_calibrated@data$concordance_factors[i]<-concordance_factor_combined
tree_IQ_TREE_supermatrix_calibrated@data$support[i]<-support
#Also define support from gCF and sCF for plotting node support later using the bins defined above.
if(sCF>50) {
tree_IQ_TREE_supermatrix_calibrated@data$sCF_support[i]<-"black"
} else if (sCF>40) {
tree_IQ_TREE_supermatrix_calibrated@data$sCF_support[i]<-"blue"
} else if(sCF>30) {
tree_IQ_TREE_supermatrix_calibrated@data$sCF_support[i]<-"orange"
} else {
tree_IQ_TREE_supermatrix_calibrated@data$sCF_support[i]<-"red"
}
if(gCF>30) {
tree_IQ_TREE_supermatrix_calibrated@data$gCF_support[i]<-"black"
} else if (gCF>25) {
tree_IQ_TREE_supermatrix_calibrated@data$gCF_support[i]<-"blue"
} else if(gCF>20) {
tree_IQ_TREE_supermatrix_calibrated@data$gCF_support[i]<-"orange"
} else {
tree_IQ_TREE_supermatrix_calibrated@data$gCF_support[i]<-"red"
}
}
}
}
#Check from a plot that these categories of support are realistic and make sense.
plot(cbind(tree_IQ_TREE_supermatrix_calibrated_ingroups@data$gCF,tree_IQ_TREE_supermatrix_calibrated_ingroups@data$sCF))
#(Re)rooting the tree is not needed in this case, because the tree was already rooted to S1321 in IQ-TREE.
##ML nuclear excluding hybrids ----
#Read in the IQ-TREE version of this same tree (but excluding hybrids) with cGF and sCF concordance factors.
tree_IQ_TREE_supermatrix_excluding_hybrids_concordance_factors<-read.tree(file = "9b.IQ-TREE_supermatrix_supermatrix_excluding_hybrids_with_concordance_factors.tree")
#Add the concordance factors to the calibrated tree, such that all tree node annotations are held within a single tree object.
##ML plastome ----
#Read in the ML IQ-TREE that was calibrated in treePL. This tree was already rooted to S1321 in IQ-TREE.
tree_IQ_TREE_chloroplast_calibrated<-read.beast(file = "7.chloroplast_treePL_BS_analysis_TreeAnnotator_EDITED.tre")
#Also read in the IQ-TREE version of this same tree with BS and sCF concordance factors.
tree_IQ_TREE_chloroplast_concordance_factors<-read.tree(file = "7.chloroplast.concord.cf.EDITED.tree")
#Add the concordance factors to the calibrated tree, such that all tree node annotations are held within a single tree object.
tree_IQ_TREE_chloroplast_calibrated@data$node_cf<-NA
tree_IQ_TREE_chloroplast_calibrated@data$concordance_factors<-NA
tree_IQ_TREE_chloroplast_calibrated@data$bootstrap<-NA
tree_IQ_TREE_chloroplast_calibrated@data$bootstrap_symbol<-NA
tree_IQ_TREE_chloroplast_calibrated@data$sCF<-NA
tree_IQ_TREE_chloroplast_calibrated@data$sCF_support<-NA
#Use phytools function matchNodes to find correspondence among node numbers in both trees.
matched_nodes<-data.frame(matchNodes(tree_IQ_TREE_chloroplast_calibrated@phylo, tree_IQ_TREE_chloroplast_concordance_factors, method = "descendants"))
tree_IQ_TREE_chloroplast_calibrated@data$node_cf<-matched_nodes$tr2[match(tree_IQ_TREE_chloroplast_calibrated@data$node, matched_nodes$tr1)]
#Loop through nodes to find concordance factors and store results.
for (i in 1:nrow(tree_IQ_TREE_chloroplast_calibrated@data)){
node_cf<-tree_IQ_TREE_chloroplast_calibrated@data$node_cf[i]
if(is.na(node_cf)==F){
#Find concordance factors.
concordance_factor<-tree_IQ_TREE_chloroplast_concordance_factors$node.label[node_cf-length(tree_IQ_TREE_chloroplast_concordance_factors$tip.label)]
#Update notation.
sCF<-as.numeric(strsplit(concordance_factor, "/")[[1]][2])
bootstrap<-as.numeric(strsplit(concordance_factor, "/")[[1]][1])
bootstrap_symbol<-bootstrap
if(is.na(bootstrap)==F){if(round(bootstrap, 0)==100){bootstrap_symbol<-"*"}}
#Define the support from these values to colour labels in tree plot later (rules based on suggestion by Lars Nauheimer).
if(is.na(sCF)==F){
if(sCF>50){sCF_support="black"}
if(sCF>40){sCF_support="blue"}
if(sCF>30){sCF_support="orange"}
if(sCF<=30){sCF_support="red"}
concordance_factor_combined<-paste(round(as.numeric(sCF), 0),
sep="/")
#Store results.
tree_IQ_TREE_chloroplast_calibrated@data$bootstrap[i]<-bootstrap
tree_IQ_TREE_chloroplast_calibrated@data$bootstrap_symbol[i]<-bootstrap_symbol
tree_IQ_TREE_chloroplast_calibrated@data$sCF[i]<-sCF
tree_IQ_TREE_chloroplast_calibrated@data$concordance_factors[i]<-concordance_factor_combined
tree_IQ_TREE_chloroplast_calibrated@data$sCF_support[i]<-sCF_support
}
}
}
# LOG ASTRAL NODE SUPPORT ----
#These are defined as "the local posterior Probability (PP) that the branch is in the species tree" (Sayyari et al 2016).
branch_support_compared<-rbind(cbind(tree_ASTRALIII_inclusive_astral_annotations@nodeData,sampling_routine = rep("ASTRAL-III inclusive", nrow(tree_ASTRALIII_inclusive_astral_annotations@nodeData))),
cbind(tree_ASTRALIII_strict_astral_annotations@nodeData,sampling_routine = rep("ASTRAL-III strict", nrow(tree_ASTRALIII_strict_astral_annotations@nodeData))),
cbind(tree_ASTRALIII_superstrict_astral_annotations@nodeData,sampling_routine = rep("ASTRAL-III superstrict", nrow(tree_ASTRALIII_superstrict_astral_annotations@nodeData))),
cbind(tree_ASTRALIII_superstrict_by_tribe_astral_annotations@nodeData,sampling_routine = rep("ASTRAL-III superstrict_by_tribe", nrow(tree_ASTRALIII_superstrict_by_tribe_astral_annotations@nodeData))),
cbind(tree_ASTRAL_Pro_astral_annotations@nodeData,sampling_routine = rep("ASTRAL-Pro", nrow(tree_ASTRAL_Pro_astral_annotations@nodeData))))
# ANNOTATIONS DATAFRAME ----
tip_labels<-unique(c(tree_ASTRALIII_inclusive$tip.label,
tree_ASTRALIII_strict$tip.label,
tree_ASTRALIII_superstrict$tip.label,
tree_ASTRAL_Pro$tip.label,
tree_IQ_TREE_supermatrix_concordance_factors$tip.label,
tree_IQ_TREE_chloroplast_calibrated@phylo$tip.label,
tree_IQ_TREE_supermatrix_excluding_hybrids_concordance_factors$tip.label))
# tip_labels<-tree_IQ_TREE_supermatrix_calibrated@phylo$tip.label
annotations<-data.frame(Library_ID=tip_labels)
#Add taxonomic data to annotations dataframe.
annotations$tribe<-metadata$Tribe[match(annotations$Library_ID,metadata$Library_ID)]
annotations$genus<-metadata$Genus[match(annotations$Library_ID,metadata$Library_ID)]
list_of_Brassicaceae_ingroup_genera<-unique(annotations$genus[!grepl("Outgroup_", annotations$tribe)])
list_of_Brassicaceae_ingroup_tribes<-unique(annotations$tribe[!grepl("Outgroup_", annotations$tribe)])
annotations$species<-metadata$Name[match(annotations$Library_ID,metadata$Library_ID)]
annotations$Library_ID2<-metadata$Library_ID[match(annotations$Library_ID,metadata$Library_ID)]
#In case tip label data come from another source (such as in the case of the chloroplast tree), simply copy the Library_ID from that tip label.
annotations[is.na(annotations$Library_ID2),]$Library_ID2<-annotations[is.na(annotations$Library_ID2),]$Library_ID
#Add details of collection country for plot of map at the end.
annotations$country<-metadata$Country[match(annotations$Library_ID,metadata$Library_ID)]
##Sample numbers ASTRAL-III inclusive----
number_samples_ingroup_ASTRALIII_inclusive<-length(annotations$Library_ID[!grepl("Outgroup_", annotations$tribe) & annotations$Library_ID %in% tree_ASTRALIII_inclusive$tip.label])
number_samples_outgroup_ASTRALIII_inclusive<-length(annotations$Library_ID[grepl("Outgroup_", annotations$tribe) & annotations$Library_ID %in% tree_ASTRALIII_inclusive$tip.label])
number_species_ingroup_ASTRALIII_inclusive<-length(unique(annotations$species[annotations$Library_ID %in% annotations$Library_ID[!grepl("Outgroup_", annotations$tribe) & annotations$Library_ID %in% tree_ASTRALIII_inclusive$tip.label]]))-1 #Minus one for the two populations of Clausia aprica
number_species_outgroup_ASTRALIII_inclusive<-length(unique(annotations$species[annotations$Library_ID %in% annotations$Library_ID[grepl("Outgroup_", annotations$tribe) & annotations$Library_ID %in% tree_ASTRALIII_inclusive$tip.label]]))
number_genera_ingroup_ASTRALIII_inclusive<-length(unique(annotations$genus[annotations$Library_ID %in% annotations$Library_ID[!grepl("Outgroup_", annotations$tribe) & annotations$Library_ID %in% tree_ASTRALIII_inclusive$tip.label]]))
number_tribes_ingroup_ASTRALIII_inclusive<-length(sort(unique(annotations$tribe[annotations$Library_ID %in% annotations$Library_ID[!grepl("Outgroup_", annotations$tribe) & annotations$Library_ID %in% tree_ASTRALIII_inclusive$tip.label]])))-4 #Minus three for doubles in Brassica, Camelinea and Iberideae
number_families_outgroup_ASTRALIII_inclusive<-length(sort(unique(annotations$tribe[annotations$Library_ID %in% annotations$Library_ID[grepl("Outgroup_", annotations$tribe) & annotations$Library_ID %in% tree_ASTRALIII_inclusive$tip.label]])))
number_samples_new_in_this_study_ASTRALIII_inclusive<-sort(annotations$Library_ID[annotations$Library_ID %in% tree_ASTRALIII_inclusive$tip.label])
##Sample numbers chloroplast----
number_samples_ingroup_chloroplast<-length(annotations$Library_ID[!grepl("Outgroup_", annotations$tribe) & annotations$Library_ID %in% tree_IQ_TREE_chloroplast_calibrated@phylo$tip.label])
number_samples_outgroup_chloroplast<-length(annotations$Library_ID[grepl("Outgroup_", annotations$tribe) & annotations$Library_ID %in% tree_IQ_TREE_chloroplast_calibrated@phylo$tip.label])
number_species_ingroup_chloroplast<-length(unique(annotations$species[annotations$Library_ID %in% annotations$Library_ID[!grepl("Outgroup_", annotations$tribe) & annotations$Library_ID %in% tree_IQ_TREE_chloroplast_calibrated@phylo$tip.label]]))-1 #Minus one for the two populations of Clausia aprica
number_species_outgroup_chloroplast<-length(unique(annotations$species[annotations$Library_ID %in% annotations$Library_ID[grepl("Outgroup_", annotations$tribe) & annotations$Library_ID %in% tree_IQ_TREE_chloroplast_calibrated@phylo$tip.label]]))
number_genera_ingroup_chloroplast<-length(unique(annotations$genus[annotations$Library_ID %in% annotations$Library_ID[!grepl("Outgroup_", annotations$tribe) & annotations$Library_ID %in% tree_IQ_TREE_chloroplast_calibrated@phylo$tip.label]]))
number_tribes_ingroup_chloroplast<-length(sort(unique(annotations$tribe[annotations$Library_ID %in% annotations$Library_ID[!grepl("Outgroup_", annotations$tribe) & annotations$Library_ID %in% tree_IQ_TREE_chloroplast_calibrated@phylo$tip.label]])))-4 #Minus three for doubles in Brassica, Camelinea and Iberideae
number_families_outgroup_chloroplast<-length(sort(unique(annotations$tribe[annotations$Library_ID %in% annotations$Library_ID[grepl("Outgroup_", annotations$tribe) & annotations$Library_ID %in% tree_IQ_TREE_chloroplast_calibrated@phylo$tip.label]])))
number_samples_new_in_this_study_chloroplast<-sort(annotations$Library_ID[annotations$Library_ID %in% tree_IQ_TREE_chloroplast_calibrated@phylo$tip.label])
##Summary metrics for in publication----
(B764_samples_with_target_length<-sum(!is.na(as.numeric(metadata$bp_Nikolov2019[metadata$Library_ID %in% tree_ASTRALIII_inclusive$tip.label]))))
(A353_samples_with_target_length<-sum(!is.na(as.numeric(metadata$bp_Angiosperms353[metadata$Library_ID %in% tree_ASTRALIII_inclusive$tip.label]))))
(B764_mean_target_length<-mean(as.numeric(metadata$bp_Nikolov2019[metadata$Library_ID %in% tree_ASTRALIII_inclusive$tip.label]), na.rm = T))
(B764_mean_target_length_prop<-mean(as.numeric(metadata$bpoftarget_Nikolov2019[metadata$Library_ID %in% tree_ASTRALIII_inclusive$tip.label]), na.rm = T))
(B764_mean_target_length_prop<-mean(as.numeric(metadata$nloci_Nikolov2019[metadata$Library_ID %in% tree_ASTRALIII_inclusive$tip.label]), na.rm = T))
(A353_mean_target_length<-mean(as.numeric(metadata$bp_Angiosperms353[metadata$Library_ID %in% tree_ASTRALIII_inclusive$tip.label]), na.rm = T))
(A353_mean_target_length_prop<-mean(as.numeric(metadata$bpoftarget_Angiosperms353[metadata$Library_ID %in% tree_ASTRALIII_inclusive$tip.label]), na.rm = T))
(A353_mean_target_length_prop<-mean(as.numeric(metadata$nloci_Angiosperms353[metadata$Library_ID %in% tree_ASTRALIII_inclusive$tip.label]), na.rm = T))
#Register which samples were included in which analyses.
annotations$sample_in_inclusive_dataset<-""
annotations$sample_in_inclusive_dataset[annotations$Library_ID %in% tree_ASTRALIII_inclusive$tip.label]<-"Y"
annotations$sample_in_strict_dataset<-""
annotations$sample_in_strict_dataset[annotations$Library_ID %in% tree_ASTRALIII_strict$tip.label]<-"Y"
annotations$sample_in_superstrict_dataset<-""
annotations$sample_in_superstrict_dataset[annotations$Library_ID %in% tree_ASTRALIII_superstrict$tip.label]<-"Y"
annotations$sample_in_superstrict_by_tribe_dataset<-""
annotations$sample_in_superstrict_by_tribe_dataset[annotations$Library_ID %in% tree_ASTRALIII_superstrict_by_tribe$tip.label]<-"Y"
annotations$sample_in_ASTRAL_Pro_dataset<-""
annotations$sample_in_ASTRAL_Pro_dataset[annotations$Library_ID %in% tree_ASTRAL_Pro$tip.label]<-"Y"
annotations$tree_IQ_TREE_supermatrix_concordance_factors<-""
annotations$tree_IQ_TREE_supermatrix_concordance_factors[annotations$Library_ID %in% tree_IQ_TREE_supermatrix_concordance_factors$tip.label]<-"Y"
annotations$sample_in_chloroplast_dataset<-""
annotations$sample_in_chloroplast_dataset[annotations$Library_ID %in% tree_IQ_TREE_chloroplast_calibrated@phylo$tip.label]<-"Y"
#Further list collection details.
annotations$collection<-metadata[,17][match(annotations$Library_ID,metadata$Library_ID)]
annotations$collection_number<-metadata$voucher[match(annotations$Library_ID,metadata$Library_ID)]
annotations$collection_date<-metadata$Collection_year[match(annotations$Library_ID,metadata$Library_ID)]
annotations$collection_date[annotations$collection_date %in% c("NA","unknown")]<-""
annotations$collection_date[is.na(annotations$collection_date)]<-""
annotations$trait_state<-as.character(metadata$Sample_because[match(annotations$Library_ID,metadata$Library_ID)])
#Add taxon occupancy from ASTRAL log-files.
annotations$ASTRAL_taxon_occupancy_inclusive<-as.numeric(as.character(metadata$ASTRAL_taxon_occupancy_inclusive[match(annotations$Library_ID,metadata$Library_ID)]))
annotations$ASTRAL_taxon_occupancy_strict<-as.numeric(as.character(metadata$ASTRAL_taxon_occupancy_strict[match(annotations$Library_ID,metadata$Library_ID)]))
annotations$ASTRAL_taxon_occupancy_superstrict<-as.numeric(as.character(metadata$ASTRAL_taxon_occupancy_superstrict[match(annotations$Library_ID,metadata$Library_ID)]))
annotations$ASTRAL_taxon_occupancy_superstrict_by_tribe<-as.numeric(as.character(metadata$ASTRAL_taxon_occupancy_superstrict_by_tribe[match(annotations$Library_ID,metadata$Library_ID)]))
annotations$ASTRAL_Pro_taxon_occupancy<-as.numeric(as.character(metadata$ASTRAL_PRO_taxon_occupancy[match(annotations$Library_ID,metadata$Library_ID)]))
##ASTRAL sampling overview for publication ----
###KASPERH: need to still update this to include results from ASTRAL-Pro!!!
#Calculate the number of libraries, species, and tribes covered by this phylogenetic tree;
#make sure to exclude outgroup samples when counting species, genera, and tribes!
sampling_overview<-data.frame(sampling_routine=NA,
locus_sample_Prop_threshold=NA,
locus_sample_length_Prop_threshold=NA,
sample_target_length_threshold=NA,
sample_locus_Prop_threshold=NA,
locus_remove_for_all_samples_SNPs_theshold=NA,
sample_remove_outlier_loci=NA,
no_libraries=NA,
mean_ASTRAL_taxon_occupancy=NA,
no_species=NA,
no_genera=NA,
no_tribes=NA,
LPP_mean=NA,
LPP_median=NA,
q1_mean=NA,
q1_median=NA)
#Now fill this dataframe with relevant data.
k=0
for (i in c("inclusive","strict","superstrict","superstrict_by_tribe")){
k=k+1
#Add empty row if needed.
if(sum(is.na(sampling_overview$sampling_routine))==0) {sampling_overview[nrow(sampling_overview)+1,] <- NA}
#Fill out the data.
sampling_overview$sampling_routine[k]<-i
#Read config file for this routine.
source(paste0("results_HybPhaser_allGenes/config_",i,".txt"))
#Add the data from the config file to the dataframe.
sampling_overview$locus_sample_Prop_threshold[k]<-remove_loci_with_less_than_this_propotion_of_samples_recovered
sampling_overview$locus_sample_length_Prop_threshold[k]<-remove_loci_with_less_than_this_propotion_of_samples_recovered
sampling_overview$sample_locus_Prop_threshold[k]<-remove_samples_with_less_than_this_propotion_of_loci_recovered
sampling_overview$sample_target_length_threshold[k]<-remove_samples_with_less_than_this_propotion_of_target_sequence_length_recovered
sampling_overview$locus_remove_for_all_samples_SNPs_theshold[k]<-remove_loci_for_all_samples_with_more_than_this_mean_proportion_of_SNPs
sampling_overview$sample_remove_outlier_loci[k]<-remove_outlier_loci_for_each_sample
#Collect sampling statistics from ASTRAL-III output.
sampling_overview$no_libraries[k]<-length(annotations[!grepl("^Outgroup",annotations$tribe) & annotations[,paste0("sample_in_",i,"_dataset")]=="Y",]$Library_ID)
sampling_overview$mean_ASTRAL_taxon_occupancy[k]<-mean(as.numeric(annotations[,paste0("ASTRAL_taxon_occupancy_",i)]), na.rm = T)
sampling_overview$no_species[k]<-length(unique(annotations[!grepl("^Outgroup",annotations$tribe) & annotations[,paste0("sample_in_",i,"_dataset")]=="Y",]$species))
sampling_overview$no_genera[k]<-length(unique(annotations[!grepl("^Outgroup",annotations$tribe) & annotations[,paste0("sample_in_",i,"_dataset")]=="Y",]$genus))
sampling_overview$no_tribes[k]<-length(unique(annotations[!grepl("^Outgroup",annotations$tribe) & annotations[,paste0("sample_in_",i,"_dataset")]=="Y",]$tribe))
#Collect node support summary statistics from ASTRAL-III output.
sampling_overview$LPP_mean[k]<-round(mean(branch_support_compared[which(branch_support_compared$sampling_routine==paste0("ASTRAL-III ",i)),]$pp1, na.rm = T),3)
sampling_overview$LPP_median[k]<-round(median(branch_support_compared[which(branch_support_compared$sampling_routine==paste0("ASTRAL-III ",i)),]$pp1, na.rm = T),3)
sampling_overview$q1_mean[k]<-round(mean(branch_support_compared[which(branch_support_compared$sampling_routine==paste0("ASTRAL-III ",i)),]$q1, na.rm = T),3)
sampling_overview$q1_median[k]<-round(median(branch_support_compared[which(branch_support_compared$sampling_routine==paste0("ASTRAL-III ",i)),]$q1, na.rm = T),3)
}
sampling_overview<-t(sampling_overview)
##Plot comparison of ASTRAL quartet scores ----
plot_quartet_scores<-ggplot(data=branch_support_compared, aes(colour=sampling_routine, x=q1))+
geom_density()+
theme_classic()+
scale_colour_manual(values=c("#999999", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7"))+
theme (plot.margin = unit(c(0.1,0.1,0.1,0.1), "cm"))
ggsave(file = "results_plots_phylogenies/plot_quartet_scores.pdf", plot_quartet_scores + theme(legend.position="none"),
width = 3, height = 3)
ggsave(file = "results_plots_phylogenies/plot_quartet_scores_legend.pdf", cowplot::get_legend(plot_quartet_scores),
width = 3, height = 1.5)
##Save table with sampling-overview for publication ----
write.table(sampling_overview, file = "11c.ASTRALIII_sample_summary.csv", append = FALSE, sep = " ", dec = ".",
row.names = TRUE, col.names = TRUE)
#CONTINUE ANNOTATIONS DATAFRAME ----
#Let's remove the "Outgroup_" in the tribe names to save space when plotting later.
annotations<-data.frame(lapply(annotations, function(x) {gsub("Outgroup_","",x)}))
#Add annotation data for plotting later.
library(stringr)
annotations$type_specimen<-str_split_fixed(annotations$trait_state, ", ",2)[,2]
annotations$genus_type_species<-str_split_fixed(annotations$trait_state, ", ",2)[,1]
annotations$genus_type_species[!(annotations$genus_type_species %in% c("C","W","S","Ta","A","CW","C?","O", "N"))] <- "Y"
annotations$genus_type_species[annotations$genus_type_species %in% c("C","W","S","Ta","A","CW","C?","O", "N")] <- ""
annotations$calibration<-str_split_fixed(annotations$trait_state, ", ",2)[,1]
annotations$calibration[!(annotations$calibration %in% c("T","WT","Ta","S","A","W","O","T?"))] <- "Y"
annotations$calibration[annotations$calibration %in% c("T","WT","Ta","S","A","W","O","T?")] <- ""
annotations$woody_sample<-str_split_fixed(annotations$trait_state, ", ",2)[,1]
annotations$woody_sample[!(annotations$trait_state %in% c("WT","W"))] <- "H"
annotations$woody_sample[annotations$trait_state %in% c("WT","W")] <- "W"
annotations$old_sample<-""
annotations$old_sample[as.integer(as.character(annotations$collection_date))<1900 & !is.na(as.integer(as.character(annotations$collection_date)))]<-"Y"
annotations$old_sample[is.na(annotations$old_sample)]<-""
#Create multiple vectors for "species", dependent on the species being the genus type or not.
#This will assist plotting later.
annotations$species_genus_type<-NA
annotations[annotations$genus_type_species!="",]$species_genus_type<-annotations[annotations$genus_type_species!="",]$species
annotations$species_genus_type[is.na(annotations$species_genus_type)]<-""
annotations$not_species_genus_type<-NA
annotations[annotations$genus_type_species=="",]$not_species_genus_type<-annotations[annotations$genus_type_species=="",]$species
annotations$not_species_genus_type[is.na(annotations$not_species_genus_type)]<-""
#Add results from HybPhaser on AD and LH.
annotations$allele_divergence<-as.numeric(metadata$allele_divergence[match(annotations$Library_ID,metadata$Library_ID)])
annotations$locus_heterozygosity<-as.numeric(metadata$locus_heterozygosity[match(annotations$Library_ID,metadata$Library_ID)])
annotations$nloci<-as.numeric(metadata$nloci[match(annotations$Library_ID,metadata$Library_ID)])
annotations$HybPhaser_bp<-as.numeric(metadata$bp[match(annotations$Library_ID,metadata$Library_ID)])
#Add annotations from Lineage assignments by previous authors.
annotations$Lineages_Koch_Al_Shehbaz<-as.character(metadata$Lineages_Koch_Al_Shehbaz[match(annotations$Library_ID,metadata$Library_ID)])
annotations$Lineages_Franzke_et_al<-metadata$Lineages_Franzke_et_al[match(annotations$Library_ID,metadata$Library_ID)]
annotations$Lineages_Nikolov_et_al<-metadata$Lineages_Nikolov_et_al[match(annotations$Library_ID,metadata$Library_ID)]
annotations$Lineages_unplaced<-metadata$Lineages_unplaced[match(annotations$Library_ID,metadata$Library_ID)]
#Update rownames to be the same as tip labels from trees; this is needed for ggtree's gheatmap function.
rownames(annotations)<-annotations$Library_ID
#Save the annotations table for publication and use in following scripts.
write.table(annotations, file = "11e.Sampling_overview.csv", append = FALSE, sep = ", ", dec = ".",
row.names = FALSE, col.names = TRUE)
#PLOT SMALL CLADOGRAMS OF TREES FOR COMPARISON ----
plot_tree_ASTRALIII_inclusive_cladogram<-ggtree(drop.tip(tree_ASTRALIII_inclusive, tree_ASTRALIII_inclusive$tip.label[!tree_ASTRALIII_inclusive$tip.label %in% c("S1116", "S1106sl", "S1239", "S1498", "S1093sl", "S1100", "PAFTOL_019361")]),
aes(), branch.length='none', size=1.5) %<+% annotations
plot_tree_ASTRALIII_inclusive_cladogram<-gheatmap(plot_tree_ASTRALIII_inclusive_cladogram, data = annotations[,c("Lineages_Nikolov_et_al","Lineages_unplaced")], width=.6, colnames = FALSE)+
scale_fill_manual(values=c("transparent","#FF4F33","lightblue","chartreuse3","pink","#FFC425","pink","red","#FFC425"), na.translate = F)+
geom_tiplab(aes(label=c("I","Ae","Out","III","IV","V","II","","","","","","")), size=6, offset = 1.8, color = "black", hjust='center')+
theme (legend.position= "none", plot.margin = unit(c(0,0,0,0), "cm"))
plot_tree_ASTRALIII_strict_cladogram<-ggtree(drop.tip(tree_ASTRALIII_strict, tree_ASTRALIII_strict$tip.label[!tree_ASTRALIII_strict$tip.label %in% c("S1116", "S1106sl", "S1239", "S1498", "S1093sl", "S1100", "PAFTOL_019361")]),
aes(), branch.length='none', size=1.5) %<+% annotations
plot_tree_ASTRALIII_strict_cladogram<-gheatmap(plot_tree_ASTRALIII_strict_cladogram, data = annotations[,c("Lineages_Nikolov_et_al","Lineages_unplaced")], width=.6, colnames = FALSE)+
scale_fill_manual(values=c("transparent","#FF4F33","lightblue","chartreuse3","pink","#FFC425","pink","red","#FFC425"), na.translate = F)+
geom_tiplab(aes(label=c("I","IV","Out","Ae","III","V","II","","","","","","")), size=6, offset = 1.8, color = "black", hjust='center')+
theme (legend.position= "none", plot.margin = unit(c(0,0,0,0), "cm"))
plot_tree_ASTRALIII_superstrict_cladogram<-ggtree(drop.tip(tree_ASTRALIII_superstrict, tree_ASTRALIII_superstrict$tip.label[!tree_ASTRALIII_superstrict$tip.label %in% c("S1116", "S1106sl", "S1239", "S1498", "S1093sl", "S1100", "PAFTOL_019361")]),
aes(), branch.length='none', size=1.5) %<+% annotations
plot_tree_ASTRALIII_superstrict_cladogram<-gheatmap(plot_tree_ASTRALIII_superstrict_cladogram, data = annotations[,c("Lineages_Nikolov_et_al","Lineages_unplaced")], width=.6, colnames = FALSE)+
scale_fill_manual(values=c("transparent","#FF4F33","lightblue","chartreuse3","pink","#FFC425","pink","red","#FFC425"), na.translate = F)+
geom_tiplab(aes(label=c("I","V","II","Out","Ae","III","IV","","","","","","")), size=6, offset = 1.8, color = "black", hjust='center')+
theme (legend.position= "none", plot.margin = unit(c(0,0,0,0), "cm"))
plot_tree_ASTRALIII_superstrict_by_tribe_cladogram<-ggtree(drop.tip(tree_ASTRALIII_superstrict_by_tribe, tree_ASTRALIII_superstrict_by_tribe$tip.label[!tree_ASTRALIII_superstrict_by_tribe$tip.label %in% c("S1116", "S1106sl", "S1239", "S1498", "S1093sl", "S1100", "PAFTOL_019361")]),
aes(), branch.length='none', size=1.5) %<+% annotations
plot_tree_ASTRALIII_superstrict_by_tribe_cladogram<-gheatmap(plot_tree_ASTRALIII_superstrict_by_tribe_cladogram, data = annotations[,c("Lineages_Nikolov_et_al","Lineages_unplaced")], width=.6, colnames = FALSE)+
scale_fill_manual(values=c("transparent","#FF4F33","lightblue","chartreuse3","pink","#FFC425","pink","red","#FFC425"), na.translate = F)+
geom_tiplab(aes(label=c("I","IV","Out","Ae","III","V","II","","","","","","")), size=6, offset = 1.8, color = "black", hjust='center')+
theme (legend.position= "none", plot.margin = unit(c(0,0,0,0), "cm"))
plot_tree_ASTRAL_Pro_cladogram<-ggtree(drop.tip(tree_ASTRAL_Pro, tree_ASTRAL_Pro$tip.label[!tree_ASTRAL_Pro$tip.label %in% c("S1116", "S1331", "S1239", "S1498", "S1579", "S1100", "PAFTOL_019361")]),
aes(), branch.length='none', size=1.5) %<+% annotations
plot_tree_ASTRAL_Pro_cladogram<-gheatmap(plot_tree_ASTRAL_Pro_cladogram, data = annotations[,c("Lineages_Nikolov_et_al","Lineages_unplaced")], width=.6, colnames = FALSE)+
scale_fill_manual(values=c("transparent","#FF4F33","#FFC425","chartreuse3","pink","lightblue","pink","red","#FFC425"), na.translate = F)+
geom_tiplab(aes(label=c("II","V","III","Out","Ae","I","IV","","","","","","")), size=6, offset = 1.8, color = "black", hjust='center')+
theme (legend.position= "none", plot.margin = unit(c(0,0,0,0), "cm"))
plot_tree_ASTRAL_Pro_cladogram<-flip(plot_tree_ASTRAL_Pro_cladogram, 2, 1)
#Note in this tree that the last tips needed to be flipped (which does not change the topology, only the view of the topology in a graph;
#this also required to reorder the colours in the heatmap!)
plot_tree_IQ_TREE_supermatrix_cladogram<-ggtree(drop.tip(tree_IQ_TREE_supermatrix_concordance_factors, tree_IQ_TREE_supermatrix_concordance_factors$tip.label[!tree_IQ_TREE_supermatrix_concordance_factors$tip.label %in% c("S1116", "S1106sl", "S1239", "S1498", "S1093sl", "S1100", "PAFTOL_019361")]),
aes(), branch.length='none', size=1.5) %<+% annotations
plot_tree_IQ_TREE_supermatrix_cladogram<-gheatmap(plot_tree_IQ_TREE_supermatrix_cladogram, data = annotations[,c("Lineages_Nikolov_et_al","Lineages_unplaced")], width=.6, colnames = FALSE)+
scale_fill_manual(values=c("transparent","#FF4F33","lightblue","chartreuse3","pink","#FFC425","pink","red","#FFC425"), na.translate = F)+
geom_tiplab(aes(label=c("IV","I","V","II","III","Ae","Out","","","","","","")), size=6, offset = 1.8, color = "black", hjust='center')+
theme (legend.position= "none", plot.margin = unit(c(0,0,0,0), "cm"))
plot_tree_chloroplast_cladogram<-ggtree(drop.tip(tree_IQ_TREE_chloroplast_calibrated@phylo, tree_IQ_TREE_chloroplast_calibrated@phylo$tip.label[!tree_IQ_TREE_chloroplast_calibrated@phylo$tip.label %in% c("S1116", "S0399", "S1239", "S0748", "S1129", "S1100", "PAFTOL_019361")]),
aes(), branch.length='none', size=1.5) %<+% annotations
plot_tree_chloroplast_cladogram<-gheatmap(plot_tree_chloroplast_cladogram, data = annotations[,c("Lineages_Nikolov_et_al","Lineages_unplaced")], width=.6, colnames = FALSE)+
scale_fill_manual(values=c("transparent","#FF4F33","lightblue","chartreuse3","pink","#FFC425","pink","red","#FFC425"), na.translate = F)+
geom_tiplab(aes(label=c("Out","Ae","IV","II*","V","III","I","","","","","","")), size=6, offset = 1.8, color = "black", hjust='center')+
theme (legend.position= "none", plot.margin = unit(c(0,0,0,0), "cm"))
#Plot the above cladograms side by side for easy comparison.
plot_trees_combined_cladograms<-plot_grid(plot_tree_IQ_TREE_supermatrix_cladogram,
plot_tree_ASTRAL_Pro_cladogram,
plot_tree_ASTRALIII_inclusive_cladogram,
plot_tree_ASTRALIII_strict_cladogram,
plot_tree_ASTRALIII_superstrict_cladogram,
plot_tree_ASTRALIII_superstrict_by_tribe_cladogram,
plot_tree_chloroplast_cladogram,
nrow = 1,
labels = c("(a)","(b)","(c)","(d)","(e)","(f)","(g)"),
label_size = 22,
label_fontface = "bold")
ggsave(filename = "results_plots_phylogenies/plot_trees_combined_cladograms.png", plot_trees_combined_cladograms,
width = 12,
height = 2)
ggsave(filename = "results_plots_phylogenies/plot_trees_combined_cladograms.pdf", plot_trees_combined_cladograms,
width = 12,
height = 2)
#PLOT SMALL VERSIONS OF TREES FOR COMPARISON ----
plot_tree_ASTRALIII_inclusive_small<-ggtree(tree_ASTRALIII_inclusive, aes(color="grey"), branch.length='none', size=0.3, layout = 'circular') %<+% annotations +
scale_color_manual(values = c("darkgrey","#00BFC4"), na.value = "darkgrey")
plot_tree_ASTRALIII_inclusive_small<-gheatmap(plot_tree_ASTRALIII_inclusive_small, data = annotations[,c("Lineages_Nikolov_et_al","Lineages_unplaced")], width=.2, colnames = FALSE)+
# c("Anast.", "basal", "Bisc" "Cochle" , "I", "Iberis", "II", "III", "IV", "Mega", Teesd", "V")
scale_fill_manual(values=c("darkolivegreen","transparent","deeppink3","black","#FF4F33","darkblue","lightblue","chartreuse3","pink", "darkcyan", "chocolate", "#FFC425"), na.translate = F)+
theme (legend.position= "none", plot.margin = unit(c(0,0,0,0), "cm"))
ggsave(filename = "results_plots_phylogenies/plot_tree_ASTRALIII_inclusive_small.pdf", plot_tree_ASTRALIII_inclusive_small,
width = 6, height = 6)
plot_tree_ASTRALIII_strict_small<-ggtree(tree_ASTRALIII_strict, aes(color="grey"), branch.length='none', size=0.3, layout = 'circular') %<+% annotations +
scale_color_manual(values = c("darkgrey","#00BFC4"), na.value = "darkgrey")
plot_tree_ASTRALIII_strict_small<-gheatmap(plot_tree_ASTRALIII_strict_small, data = annotations[,c("Lineages_Nikolov_et_al","Lineages_unplaced")], width=.2, colnames = FALSE)+
scale_fill_manual(values=c("darkolivegreen","transparent","deeppink3","black","#FF4F33","darkblue","lightblue","chartreuse3","pink", "darkcyan", "chocolate", "#FFC425"), na.translate = F)+
theme (legend.position= "none", plot.margin = unit(c(0,0,0,0), "cm"))
ggsave(filename = "results_plots_phylogenies/plot_tree_ASTRALIII_strict_small.pdf", plot_tree_ASTRALIII_strict_small,
width = 6, height = 6)
plot_tree_ASTRALIII_superstrict_small<-ggtree(tree_ASTRALIII_superstrict, aes(color="grey"), branch.length='none', size=0.3, layout = 'circular') %<+% annotations +
scale_color_manual(values = c("darkgrey","#00BFC4"), na.value = "darkgrey")
plot_tree_ASTRALIII_superstrict_small<-gheatmap(plot_tree_ASTRALIII_superstrict_small, data = annotations[,c("Lineages_Nikolov_et_al","Lineages_unplaced")], width=.2, colnames = FALSE)+
scale_fill_manual(values=c("darkolivegreen","transparent","deeppink3","black","#FF4F33","darkblue","lightblue","chartreuse3","pink", "darkcyan", "chocolate", "#FFC425"), na.translate = F)+
theme (legend.position= "none", plot.margin = unit(c(0,0,0,0), "cm"))
ggsave(filename = "results_plots_phylogenies/plot_tree_ASTRALIII_superstrict_small.pdf", plot_tree_ASTRALIII_superstrict_small,
width = 6, height = 6)
plot_tree_ASTRALIII_superstrict_by_tribe_small<-ggtree(tree_ASTRALIII_superstrict_by_tribe, aes(color="grey"), branch.length='none', size=0.3, layout = 'circular') %<+% annotations +
scale_color_manual(values = c("darkgrey","#00BFC4"), na.value = "darkgrey")
plot_tree_ASTRALIII_superstrict_by_tribe_small<-gheatmap(plot_tree_ASTRALIII_superstrict_by_tribe_small, data = annotations[,c("Lineages_Nikolov_et_al","Lineages_unplaced")], width=.2, colnames = FALSE)+
scale_fill_manual(values=c("darkolivegreen","transparent","deeppink3","black","#FF4F33","darkblue","lightblue","chartreuse3","pink", "darkcyan", "chocolate", "#FFC425"), na.translate = F)+
theme (legend.position= "none", plot.margin = unit(c(0,0,0,0), "cm"))
ggsave(filename = "results_plots_phylogenies/plot_tree_ASTRALIII_superstrict_by_tribe_small.pdf", plot_tree_ASTRALIII_superstrict_by_tribe_small,
width = 6, height = 6)
#For ASTRAL-Pro output, for which are listed the full node annotations, check how the LPP ("pp1") value was selected for annotation in this plot!
plot_tree_ASTRAL_Pro_small<-ggtree(tree_ASTRAL_Pro, aes(color="grey"), branch.length='none', size=0.3, layout = 'circular') %<+% annotations +
scale_color_manual(values = c("darkgrey","#00BFC4"), na.value = "darkgrey")
plot_tree_ASTRAL_Pro_small<-gheatmap(plot_tree_ASTRAL_Pro_small, data = annotations[,c("Lineages_Nikolov_et_al","Lineages_unplaced")], width=.2, colnames = FALSE)+
scale_fill_manual(values=c("darkolivegreen","transparent","deeppink3","black","#FF4F33","darkblue","lightblue","chartreuse3","pink", "darkcyan", "chocolate", "#FFC425"), na.translate = F)+
theme (legend.position= "none", plot.margin = unit(c(0,0,0,0), "cm"))
ggsave(filename = "results_plots_phylogenies/plot_tree_ASTRAL_Pro_small.pdf", plot_tree_ASTRAL_Pro_small,
width = 6, height = 6)
plot_tree_IQ_TREE_supermatrix_small<-ggtree(tree_IQ_TREE_supermatrix_concordance_factors, aes(color="grey"), branch.length='none', size=0.3, layout = 'circular') %<+% annotations +
scale_color_manual(values = c("darkgrey","#00BFC4"), na.value = "darkgrey")
plot_tree_IQ_TREE_supermatrix_small<-gheatmap(plot_tree_IQ_TREE_supermatrix_small, data = annotations[,c("Lineages_Nikolov_et_al","Lineages_unplaced")], width=.2, colnames = FALSE)+
scale_fill_manual(values=c("darkolivegreen","transparent","deeppink3","black","#FF4F33","darkblue","lightblue","chartreuse3","pink", "darkcyan", "chocolate", "#FFC425"), na.translate = F)+
theme (legend.position= "none", plot.margin = unit(c(0,0,0,0), "cm"))
ggsave(filename = "results_plots_phylogenies/plot_tree_IQ_TREE_supermatrix_small.pdf", plot_tree_IQ_TREE_supermatrix_small,
width = 6, height = 6)
#Take care to update the colour scale below for the main Lineages after final tree data comes in!
#Now Megacarpaeeae missing and thus one colour removed by hand...!
plot_tree_chloroplast_small<-ggtree(tree_IQ_TREE_chloroplast_calibrated@phylo, aes(color="grey"), branch.length='none', size=0.3, layout = 'circular') %<+% annotations +
scale_color_manual(values = c("darkgrey","#00BFC4"), na.value = "darkgrey")
plot_tree_chloroplast_small<-gheatmap(plot_tree_chloroplast_small, data = annotations[,c("Lineages_Nikolov_et_al","Lineages_unplaced")], width=.2, colnames = FALSE)+
scale_fill_manual(values=c("darkolivegreen","transparent","deeppink3","black","#FF4F33","darkblue","lightblue","chartreuse3","pink", "darkcyan", "chocolate", "#FFC425"), na.translate = F)+
theme (legend.position= "none", plot.margin = unit(c(0,0,0,0), "cm"))
ggsave(filename = "results_plots_phylogenies/plot_tree_chloroplast_small.pdf", plot_tree_chloroplast_small,
width = 6, height = 6)
#Plot one of the legends for inclusion in publication plot later.
ggsave(filename = "results_plots_phylogenies/plot_tree_legend_small.pdf", cowplot::get_legend(plot_tree_ASTRALIII_inclusive_small + theme(legend.position= "right")),
width = 3, height = 3)
#PLOT FULL-SIZE VERSIONS OF TREES FOR PUBLICATION ----
####TEMP NEW PLOT CLOCKLIKE GENES
plot_tree_ASTRALIII_superstrict_and_clocklike_large<-ggtree(tree_ASTRALIII_superstrict_and_clocklike, aes(color="grey"), size=0.3, branch.length = "none") %<+% annotations +
scale_color_manual(values = c("darkgrey","#00BFC4"), na.value = "darkgrey")+
geom_inset(tree_ASTRALIII_superstrict_and_clocklike_astral_annotations_piecharts, width = 0.05, height = 0.05, hjust = 0.175, vjust = 0.15)+
#Highlight the calibration nodes.
geom_tiplab(aes(label=Library_ID2), size=1, offset = 8.1, color = "black")+
geom_tiplab(aes(label=tribe), size=1, offset = 2.7, color = "black")+
geom_tiplab(aes(label=species), fontface='italic', size=1, offset = 4.5, color = "black")
plot_tree_ASTRALIII_superstrict_and_clocklike_large<-plot_tree_ASTRALIII_superstrict_and_clocklike_large+new_scale_fill()
plot_tree_ASTRALIII_superstrict_and_clocklike_large<-gheatmap(plot_tree_ASTRALIII_superstrict_and_clocklike_large, data = annotations[,c("Lineages_Nikolov_et_al","Lineages_unplaced")], width=.05, colnames_position = "top", colnames_angle = 45, font.size = 2, custom_column_labels = c("Nikolov","jumpy"), colnames_offset_y = 2)+
# scale_fill_manual(values=c("darkslategrey","transparent","darkmagenta","blue","#FF4F33","lightblue","chartreuse3","pink","red","#FFC425"), na.translate = F)
scale_fill_manual(values=c("darkslategrey","transparent","darkmagenta","#FF4F33","lightblue","chartreuse3","pink","red","#FFC425","red","#FFC425"), na.translate = F)
# plot_tree_ASTRALIII_superstrict_and_clocklike_large<-plot_tree_ASTRALIII_superstrict_and_clocklike_large+new_scale_fill()
# plot_tree_ASTRALIII_superstrict_and_clocklike_large<-gheatmap(plot_tree_ASTRALIII_superstrict_and_clocklike_large, data = annotations[,c("locus_heterozygosity"), drop=FALSE], width=.01, offset = 1.8, colnames_position = "top", colnames_angle = 45, font.size = 2, custom_column_labels = c("LH"), colnames_offset_y = 2)+
# scale_fill_gradient(low = "yellow", high = "red", na.value = NA)
# plot_tree_ASTRALIII_superstrict_and_clocklike_large<-plot_tree_ASTRALIII_superstrict_and_clocklike_large+new_scale_fill()
# plot_tree_ASTRALIII_superstrict_and_clocklike_large<-gheatmap(plot_tree_ASTRALIII_superstrict_and_clocklike_large, data = annotations[,c("allele_divergence"), drop=FALSE], width=.01, offset = 2.1, colnames_position = "top", colnames_angle = 45, font.size = 2, custom_column_labels = c("AD"), colnames_offset_y = 2) +
# scale_fill_gradient(low = "yellow", high = "red", na.value = NA)+
# theme(legend.position= "none", plot.margin = unit(c(0,0,0,0), "cm"))
ggsave(filename = "results_plots_phylogenies/plot_tree_ASTRALIII_superstrict_and_clocklike_large.pdf", plot_tree_ASTRALIII_superstrict_and_clocklike_large,
width = 12, height = 18)
##ML nuclear ----
#Find all tribes_n in the tree for proper annotation below.
tribes_n<-unique(metadata[metadata$Library_ID %in% tree_IQ_TREE_supermatrix_calibrated@phylo$tip.label, ]$Tribe)
tribes_n<-tribes_n[!grepl("Outgroup_", tribes_n)]
plot_tree_IQ_TREE_supermatrix_large<-ggtree(tree_IQ_TREE_supermatrix_calibrated, aes(color="black"), size=0.25) %<+% annotations +
scale_color_manual(values = c("black","#00BFC4"), na.value = "black")+
#Highlight the calibration nodes.
geom_point2(aes(subset=(node %in% c(MRCA(tree_IQ_TREE_supermatrix_calibrated, "PAFTOL_014331", "S1408")))), shape=23, size=0.2, fill='red', stroke=NA)+
# geom_point2(aes(subset=(node %in% c(MRCA(tree_IQ_TREE_supermatrix_calibrated, "[ml]", "HYZL"), MRCA(tree_IQ_TREE_supermatrix_calibrated, "PAFTOL_014331", "S1408"), MRCA(tree_IQ_TREE_supermatrix_calibrated, "PAFTOL_019361", "S1408"), MRCA(tree_IQ_TREE_supermatrix_calibrated, "S0416", "S1376")))), shape=23, size=0.5, fill='red', stroke=NA)+
geom_range(range='height_0.95_HPD', color='red', alpha=.6, size=0.5)
plot_tree_IQ_TREE_supermatrix_large<-plot_tree_IQ_TREE_supermatrix_large+new_scale_color()
plot_tree_IQ_TREE_supermatrix_large<-plot_tree_IQ_TREE_supermatrix_large +
geom_nodelab(aes(x=branch, label=concordance_factors, color=support), vjust=1.4, size=1)+
scale_colour_manual(values=sort(unique(tree_IQ_TREE_supermatrix_calibrated@data$support)[c(2,3,4,5)]))+
geom_nodelab(aes(x=branch, label=bootstrap), vjust=-.6, size=1, color = "black")
#Loop through the tribes_n to add annotation layers to the ggtree object.
for (i in 1:length(tribes_n)){
tribes_n[i]
samples_in_tribe<-length(which(tree_IQ_TREE_supermatrix_calibrated@phylo$tip.label %in% annotations[annotations$tribe==tribes_n[i],]$Library_ID2))
node_tribe<-getMRCA(tree_IQ_TREE_supermatrix_calibrated@phylo, which(tree_IQ_TREE_supermatrix_calibrated@phylo$tip.label %in% annotations[annotations$tribe==tribes_n[i],]$Library_ID2))
plot_tree_IQ_TREE_supermatrix_large<-plot_tree_IQ_TREE_supermatrix_large+
geom_cladelab(node=
if(samples_in_tribe==1)
{which(tree_IQ_TREE_supermatrix_calibrated@phylo$tip.label %in% annotations[annotations$tribe==tribes_n[i],]$Library_ID2)}
else
{node_tribe},
label=tribes_n[i], align=TRUE, offset = 11, barsize=2, fontsize=1.5)
}
plot_tree_IQ_TREE_supermatrix_large<-plot_tree_IQ_TREE_supermatrix_large+
# geom_tiplab(aes(label=tribe), size=1, offset = 14, color = "black")+
# geom_tiplab(aes(label=Library_ID2), size=1, offset = 7, color = "black") +
geom_tiplab(aes(label=species_genus_type), fontface='bold.italic', size=1, offset = 0.1, color = "black") +
geom_tiplab(aes(label=not_species_genus_type), fontface='italic', size=1, offset = 0.1, color = "black") +
theme_tree2()
plot_tree_IQ_TREE_supermatrix_large<-plot_tree_IQ_TREE_supermatrix_large+new_scale_fill()
plot_tree_IQ_TREE_supermatrix_large<-gheatmap(plot_tree_IQ_TREE_supermatrix_large, data = annotations[,c("Lineages_Nikolov_et_al"), drop=F], width=.01, offset=16, colnames=F)+
scale_fill_manual(values=c("transparent", "orange", "lightblue","green","pink","yellow"), na.translate = F)
# plot_tree_IQ_TREE_supermatrix_large<-plot_tree_IQ_TREE_supermatrix_large+new_scale_fill()
# plot_tree_IQ_TREE_supermatrix_large<-gheatmap(plot_tree_IQ_TREE_supermatrix_large, data = annotations[,c("locus_heterozygosity"), drop=FALSE], width=.01, offset = 5.2, colnames_position = "top", colnames_angle = 45, font.size = 2, custom_column_labels = c("LH"), colnames_offset_y = 2)+
# scale_fill_gradient(low = "yellow", high = "red", na.value = NA)
# plot_tree_IQ_TREE_supermatrix_large<-plot_tree_IQ_TREE_supermatrix_large+new_scale_fill()
# plot_tree_IQ_TREE_supermatrix_large<-gheatmap(plot_tree_IQ_TREE_supermatrix_large, data = annotations[,c("allele_divergence"), drop=FALSE], width=.01, offset = 6, colnames_position = "top", colnames_angle = 45, font.size = 2, custom_column_labels = c("AD"), colnames_offset_y = 2) +
# scale_fill_gradient(low = "yellow", high = "red", na.value = NA)+
# theme_tree2(legend.position= "right", plot.margin = unit(c(0,0,0,0), "cm"))
# plot_tree_IQ_TREE_supermatrix_large<-revts(plot_tree_IQ_TREE_supermatrix_large)
ggsave(filename = "results_plots_phylogenies/plot_tree_IQ_TREE_supermatrix_large.pdf", plot_tree_IQ_TREE_supermatrix_large + theme(legend.position="none"),
width = 8, height = 21)
##ML nuclear circular ----
#Remove outgroups from the tree that we don't want to print now. This helps reduce branch lengths of most ancestral branches.
tree_IQ_TREE_supermatrix_calibrated_ingroups<-drop.tip(tree_IQ_TREE_supermatrix_calibrated, which(tree_IQ_TREE_supermatrix_calibrated@phylo$tip.label %in% annotations$Library_ID2[!annotations$genus %in% c(list_of_Brassicaceae_ingroup_genera, 'Cleome')]))
plot_tree_IQ_TREE_supermatrix_large_circular<-ggtree(tree_IQ_TREE_supermatrix_calibrated_ingroups, aes(color="black"), size=0.25, layout = 'circular') %<+% annotations +
scale_color_manual(values = c("black","#00BFC4"), na.value = "black")+
geom_nodelab(aes(x=branch, label=round(height_median,1)), vjust=-.6, size=1, color = "darkgreen")+
geom_nodelab(aes(x=branch, label=sCF), vjust=-.6, size=1, color = "cyan3")+
geom_nodelab(aes(x=branch, label=gCF), vjust=-.6, size=1, color = "darksalmon")
plot_tree_IQ_TREE_supermatrix_large_circular<-plot_tree_IQ_TREE_supermatrix_large_circular+
new_scale_color()+
geom_point2(aes(fill=sCF_support), shape=21 , stroke=0.5, colour="deeppink2", size=1.5)+
geom_point2(aes(fill=gCF_support), shape=21 , stroke=0.5, colour="firebrick2", size=1)+
scale_fill_manual(values = c("black","darkgrey","grey", "lightgrey"), na.value = "darkseagreen2")
#Loop through the tribes_n to add annotation layers to the ggtree object.
for (i in 1:length(tribes_n)){
tribes_n[i]
samples_in_tribe<-length(which(tree_IQ_TREE_supermatrix_calibrated_ingroups@phylo$tip.label %in% annotations[annotations$tribe==tribes_n[i],]$Library_ID2))
if(samples_in_tribe>0){
node_tribe<-getMRCA(tree_IQ_TREE_supermatrix_calibrated_ingroups@phylo, which(tree_IQ_TREE_supermatrix_calibrated_ingroups@phylo$tip.label %in% annotations[annotations$tribe==tribes_n[i],]$Library_ID2))
plot_tree_IQ_TREE_supermatrix_large_circular<-plot_tree_IQ_TREE_supermatrix_large_circular+
geom_cladelab(node=
if(samples_in_tribe==1)
{which(tree_IQ_TREE_supermatrix_calibrated_ingroups@phylo$tip.label %in% annotations[annotations$tribe==tribes_n[i],]$Library_ID2)}
else
{node_tribe},
label=tribes_n[i], align=TRUE, offset = 11, barsize=2, fontsize=1.5)
}
}
plot_tree_IQ_TREE_supermatrix_large_circular<-plot_tree_IQ_TREE_supermatrix_large_circular+
# geom_tiplab(aes(label=tribe), size=1, offset = 14, color = "black")+
# geom_tiplab(aes(label=Library_ID2), size=1, offset = 7, color = "black") +
geom_tiplab(aes(label=species_genus_type), fontface='bold.italic', size=1, offset = 0.3, color = "black") +
geom_tiplab(aes(label=not_species_genus_type), fontface='italic', size=1, offset = 0.3, color = "black") +
theme_tree2()
plot_tree_IQ_TREE_supermatrix_large_circular<-plot_tree_IQ_TREE_supermatrix_large_circular+new_scale_fill()
plot_tree_IQ_TREE_supermatrix_large_circular<-gheatmap(plot_tree_IQ_TREE_supermatrix_large_circular, data = annotations[,c("Lineages_Nikolov_et_al"), drop=F], width=.03, offset=14, colnames=F)+
scale_fill_manual(values=c("transparent", "orange", "lightblue","green","pink","yellow"), na.translate = F)
# plot_tree_IQ_TREE_supermatrix_large_circular<-plot_tree_IQ_TREE_supermatrix_large_circular+new_scale_fill()
# plot_tree_IQ_TREE_supermatrix_large_circular<-gheatmap(plot_tree_IQ_TREE_supermatrix_large_circular, data = annotations[,c("locus_heterozygosity"), drop=FALSE], width=.01, offset = 5.2, colnames_position = "top", colnames_angle = 45, font.size = 2, custom_column_labels = c("LH"), colnames_offset_y = 2)+
# scale_fill_gradient(low = "yellow", high = "red", na.value = NA)
# plot_tree_IQ_TREE_supermatrix_large_circular<-plot_tree_IQ_TREE_supermatrix_large_circular+new_scale_fill()
# plot_tree_IQ_TREE_supermatrix_large_circular<-gheatmap(plot_tree_IQ_TREE_supermatrix_large_circular, data = annotations[,c("allele_divergence"), drop=FALSE], width=.01, offset = 6, colnames_position = "top", colnames_angle = 45, font.size = 2, custom_column_labels = c("AD"), colnames_offset_y = 2) +
# scale_fill_gradient(low = "yellow", high = "red", na.value = NA)+
# theme_tree2(legend.position= "right", plot.margin = unit(c(0,0,0,0), "cm"))
# plot_tree_IQ_TREE_supermatrix_large_circular<-revts(plot_tree_IQ_TREE_supermatrix_large_circular)
ggsave(filename = "results_plots_phylogenies/plot_tree_IQ_TREE_supermatrix_large_circular_for_print.pdf", plot_tree_IQ_TREE_supermatrix_large_circular + theme(legend.position="none"),
width = 10, height = 10)
##ML nuclear excluding hybrids ----
#Create a plot of the phylogeny with branch lengths.
plot_tree_IQ_TREE_supermatrix_excluding_hybrids_large<-ggtree(tree_IQ_TREE_supermatrix_excluding_hybrids_concordance_factors, aes(color="black"), size=0.25) %<+% annotations +
scale_color_manual(values = c("black","#00BFC4"), na.value = "black")+
geom_nodelab(aes(x=branch, label=c(rep("", length(tree_IQ_TREE_supermatrix_excluding_hybrids_concordance_factors$tip.label)),tree_IQ_TREE_supermatrix_excluding_hybrids_concordance_factors$node.label)), vjust=-.3, size=1.2, color = "black")
#And a second plot with the annotations.
#We do this because ggtree cannot properly add annotations to a tree that has branch lengths, so we need to be creative here.
plot_tree_IQ_TREE_supermatrix_excluding_hybrids_large_annotations<-ggtree(tree_IQ_TREE_supermatrix_excluding_hybrids_concordance_factors, aes(color="black"), size=0.25, branch.length = "none") %<+% annotations +
scale_color_manual(values = c("grey","grey"), na.value = "black") +
geom_tiplab(aes(label=tribe), size=1, offset = 1, color = "black") +
geom_tiplab(aes(label=Library_ID2), size=1, offset = 6, color = "black")
plot_tree_IQ_TREE_supermatrix_excluding_hybrids_large_annotations<-gheatmap(plot_tree_IQ_TREE_supermatrix_excluding_hybrids_large_annotations, data = annotations[,c("Lineages_Nikolov_et_al"), drop=F], offset=0.5, colnames=F)+
scale_fill_manual(values=c("transparent", "orange", "lightblue","green","pink","yellow"), na.translate = F)
plot_tree_IQ_TREE_supermatrix_excluding_hybrids_large_annotations<-plot_tree_IQ_TREE_supermatrix_excluding_hybrids_large_annotations +
geom_tiplab(aes(label=species_genus_type), fontface='bold.italic', size=1, offset = 3, color = "black") +
geom_tiplab(aes(label=not_species_genus_type), fontface='italic', size=1, offset = 3, color = "black")
#Combine the above two plots.
plot_tree_IQ_TREE_supermatrix_excluding_hybrids_large_combined<-
cowplot::plot_grid(plot_tree_IQ_TREE_supermatrix_excluding_hybrids_large,
plot_tree_IQ_TREE_supermatrix_excluding_hybrids_large_annotations,
nrow = 1)
#And save for publication.
ggsave(filename = "results_plots_phylogenies/plot_tree_IQ_TREE_supermatrix_excluding_hybrids_large.pdf", plot_tree_IQ_TREE_supermatrix_excluding_hybrids_large_combined + theme(legend.position="none"),
width = 18, height = 10)
##ML plastome ----
#Copy the annotations object in order for us to make small adjustments relating to polyphyly in the plastome phylogeny.
annotations_cp<-annotations
annotations_cp$tribe[annotations_cp$Library_ID=="SRR8528386"]<-"Brassiceae"
annotations_cp$tribe[annotations_cp$Library_ID=="MK637787"]<-"Sisymbrieae II"
annotations_cp$tribe[annotations_cp$Library_ID=="S0753"]<-"Cremolobeae III"
annotations_cp$tribe[annotations_cp$Library_ID=="S1095"]<-"Schizopetaleae II"
annotations_cp$tribe[annotations_cp$Library_ID=="MK637821"]<-"Schizopetaleae II"
annotations_cp$tribe[annotations_cp$Library_ID=="MK637768"]<-"Cremolobeae II"
annotations_cp$tribe[annotations_cp$Library_ID=="MK637749"]<-"Cremolobeae II"
annotations_cp$tribe[annotations_cp$Library_ID=="MK637760"]<-"Cremolobeae IIIb"
annotations_cp$tribe[annotations_cp$Library_ID=="S0399"]<-"Eudemeae II"
annotations_cp$tribe[annotations_cp$Library_ID=="MK637822"]<-"Conringieae II"
annotations_cp$tribe[annotations_cp$Library_ID=="S1371"]<-"Hemilophieae trib. nov. II"
annotations_cp$tribe[annotations_cp$Library_ID=="MK637702"]<-"Hemilophieae trib. nov. II"
#Add outgroup family names as in metadata dataframe.
annotations_cp$tribe2<-metadata$Tribe[match(annotations_cp$Library_ID, metadata$Library_ID)]
#Find all tribes in the tree for proper annotation below.
tribes_cp<-unique(annotations_cp[annotations_cp$Library_ID %in% tree_IQ_TREE_chloroplast_calibrated@phylo$tip.label & !grepl("Outgroup_", annotations_cp$tribe2), ]$tribe)
plot_tree_IQ_TREE_chloroplast_large<-ggtree(tree_IQ_TREE_chloroplast_calibrated, aes(color="black"), size=0.25) %<+% annotations_cp +
scale_color_manual(values = c("black","#00BFC4"), na.value = "black")+
#Highlight the calibration nodes.
# geom_point2(aes(subset=(node %in% c(MRCA(tree_IQ_TREE_chloroplast_calibrated, "PAFTOL_014331", "S1408")))), shape=23, size=0.2, fill='red', stroke=NA)+
geom_range(range='height_0.95_HPD', color='red', alpha=.6, size=0.5)
plot_tree_IQ_TREE_chloroplast_large<-plot_tree_IQ_TREE_chloroplast_large+new_scale_color()
plot_tree_IQ_TREE_chloroplast_large<-plot_tree_IQ_TREE_chloroplast_large +
geom_nodelab(aes(x=branch, label=concordance_factors, color=support), vjust=1.4, size=1)+
scale_colour_manual(values=sort(unique(tree_IQ_TREE_chloroplast_calibrated@data$support)[c(2,3,5,4)]))+
geom_nodelab(aes(x=branch, label=bootstrap), vjust=-.6, size=1, color = "black")
#Loop through the tribes_cp to add annotation layers to the ggtree object.
for (i in 1:length(tribes_cp)){
tribes_cp[i]
samples_in_tribe<-length(which(tree_IQ_TREE_chloroplast_calibrated@phylo$tip.label %in% annotations_cp[annotations_cp$tribe==tribes_cp[i],]$Library_ID2))
node_tribe<-getMRCA(tree_IQ_TREE_chloroplast_calibrated@phylo, which(tree_IQ_TREE_chloroplast_calibrated@phylo$tip.label %in% annotations_cp[annotations_cp$tribe==tribes_cp[i],]$Library_ID2))
plot_tree_IQ_TREE_chloroplast_large<-plot_tree_IQ_TREE_chloroplast_large+
geom_cladelab(node=
if(samples_in_tribe==1)
{which(tree_IQ_TREE_chloroplast_calibrated@phylo$tip.label %in% annotations_cp[annotations_cp$tribe==tribes_cp[i],]$Library_ID2)}
else
{node_tribe},
label=tribes_cp[i], align=TRUE, offset = 14, barsize=2, fontsize=1.5)
}
plot_tree_IQ_TREE_chloroplast_large<-plot_tree_IQ_TREE_chloroplast_large+
geom_tiplab(aes(label=tribe), size=1, offset = 11, color = "black")+
geom_tiplab(aes(label=Library_ID2), size=1, offset = 5.5, color = "black") +
geom_tiplab(aes(label=collection_number), size=1, offset = 8, color = "black") +
geom_tiplab(aes(label=species_genus_type), fontface='bold.italic', size=1, offset = 0.1, color = "black") +
geom_tiplab(aes(label=not_species_genus_type), fontface='italic', size=1, offset = 0.1, color = "black") +
theme_tree2()
plot_tree_IQ_TREE_chloroplast_large<-plot_tree_IQ_TREE_chloroplast_large+new_scale_fill()
plot_tree_IQ_TREE_chloroplast_large<-gheatmap(plot_tree_IQ_TREE_chloroplast_large, data = annotations_cp[,c("Lineages_Nikolov_et_al"), drop=F], width=.01, offset=13, colnames=F)+
scale_fill_manual(values=c("transparent", "orange", "lightblue","green","pink","yellow"), na.translate = F)
# plot_tree_IQ_TREE_chloroplast_large<-plot_tree_IQ_TREE_chloroplast_large+new_scale_fill()
# plot_tree_IQ_TREE_chloroplast_large<-gheatmap(plot_tree_IQ_TREE_chloroplast_large, data = annotations_cp[,c("locus_heterozygosity"), drop=FALSE], width=.01, offset = 5.2, colnames_position = "top", colnames_angle = 45, font.size = 2, custom_column_labels = c("LH"), colnames_offset_y = 2)+
# scale_fill_gradient(low = "yellow", high = "red", na.value = NA)
# plot_tree_IQ_TREE_chloroplast_large<-plot_tree_IQ_TREE_chloroplast_large+new_scale_fill()
# plot_tree_IQ_TREE_chloroplast_large<-gheatmap(plot_tree_IQ_TREE_chloroplast_large, data = annotations_cp[,c("allele_divergence"), drop=FALSE], width=.01, offset = 6, colnames_position = "top", colnames_angle = 45, font.size = 2, custom_column_labels = c("AD"), colnames_offset_y = 2) +
# scale_fill_gradient(low = "yellow", high = "red", na.value = NA)+
# theme_tree2(legend.position= "right", plot.margin = unit(c(0,0,0,0), "cm"))
# plot_tree_IQ_TREE_chloroplast_large<-revts(plot_tree_IQ_TREE_chloroplast_large)
ggsave(filename = "results_plots_phylogenies/plot_tree_IQ_TREE_chloroplast_large.pdf", plot_tree_IQ_TREE_chloroplast_large + theme(legend.position="right"),
width = 18, height = 25)
##ML plastome circular ----
#Copy the annotations object in order for us to make small adjustments relating to polyphyly in the plastome phylogeny.
annotations_cp<-annotations
annotations_cp$tribe[annotations_cp$Library_ID=="SRR8528386"]<-"Brassiceae"
annotations_cp$tribe[annotations_cp$Library_ID=="MK637787"]<-"Sisymbrieae II"
annotations_cp$tribe[annotations_cp$Library_ID=="S0753"]<-"Cremolobeae III"
annotations_cp$tribe[annotations_cp$Library_ID=="S1095"]<-"Schizopetaleae II"
annotations_cp$tribe[annotations_cp$Library_ID=="MK637821"]<-"Schizopetaleae II"
annotations_cp$tribe[annotations_cp$Library_ID=="MK637768"]<-"Cremolobeae II"
annotations_cp$tribe[annotations_cp$Library_ID=="MK637749"]<-"Cremolobeae II"
annotations_cp$tribe[annotations_cp$Library_ID=="MK637760"]<-"Cremolobeae IIIb"
annotations_cp$tribe[annotations_cp$Library_ID=="S0399"]<-"Eudemeae II"
annotations_cp$tribe[annotations_cp$Library_ID=="MK637822"]<-"Conringieae II"
annotations_cp$tribe[annotations_cp$Library_ID=="S1371"]<-"Hemilophieae trib. nov. II"
annotations_cp$tribe[annotations_cp$Library_ID=="MK637702"]<-"Hemilophieae trib. nov. II"
#Add outgroup family names as in metadata dataframe.
annotations_cp$tribe2<-metadata$Tribe[match(annotations_cp$Library_ID, metadata$Library_ID)]
#Remove outgroups from the tree that we don't want to print now. This helps reduce branch lengths of most ancestral branches.
tree_IQ_TREE_chloroplast_calibrated_ingroups<-drop.tip(tree_IQ_TREE_chloroplast_calibrated, which(tree_IQ_TREE_chloroplast_calibrated@phylo$tip.label %in% annotations_cp$Library_ID2[!annotations_cp$genus %in% c(list_of_Brassicaceae_ingroup_genera, 'Cleome')]))
#Find all tribes in the tree for proper annotation below.
tribes_cp<-unique(annotations_cp[annotations_cp$Library_ID %in% tree_IQ_TREE_chloroplast_calibrated_ingroups@phylo$tip.label & !grepl("Outgroup_", annotations_cp$tribe2), ]$tribe)
plot_tree_IQ_TREE_chloroplast_large_circular<-ggtree(tree_IQ_TREE_chloroplast_calibrated_ingroups, aes(color="black"), size=0.25, layout='circular') %<+% annotations_cp +
scale_color_manual(values = c("black","#00BFC4"), na.value = "black")+
geom_nodelab(aes(x=branch, label=round(height_median,1)), vjust=-.6, size=1, color = "darkgreen")+
geom_nodelab(aes(x=branch, label=sCF), vjust=-.6, size=1, color = "cyan3")+
geom_range(range='height_0.95_HPD', color='red', alpha=.6, size=0.5)
plot_tree_IQ_TREE_chloroplast_large_circular<-plot_tree_IQ_TREE_chloroplast_large_circular+
new_scale_color()+
geom_point2(aes(fill=sCF_support), shape=21, colour = "deeppink", size=1.5)+
scale_fill_manual(values = c("black","darkgrey","grey", "lightgrey"), na.value = "darkseagreen2")
plot_tree_IQ_TREE_chloroplast_large_circular<-plot_tree_IQ_TREE_chloroplast_large_circular+
new_scale_color()
#Loop through the tribes_cp to add annotation layers to the ggtree object.
for (i in 1:length(tribes_cp)){
tribes_cp[i]
samples_in_tribe<-length(which(tree_IQ_TREE_chloroplast_calibrated_ingroups@phylo$tip.label %in% annotations_cp[annotations_cp$tribe==tribes_cp[i],]$Library_ID2))
if(samples_in_tribe>1){
node_tribe<-getMRCA(tree_IQ_TREE_chloroplast_calibrated_ingroups@phylo, which(tree_IQ_TREE_chloroplast_calibrated_ingroups@phylo$tip.label %in% annotations_cp[annotations_cp$tribe==tribes_cp[i],]$Library_ID2))
plot_tree_IQ_TREE_chloroplast_large_circular<-plot_tree_IQ_TREE_chloroplast_large_circular+
geom_cladelab(node=node_tribe, label=tribes_cp[i], align=TRUE, offset = 14, barsize=2, fontsize=1.5,textcolor=col_vector[i], barcolor=col_vector[i] )
}
}
plot_tree_IQ_TREE_chloroplast_large_circular<-plot_tree_IQ_TREE_chloroplast_large_circular+
geom_tiplab(aes(label=species_genus_type), fontface='bold.italic', size=1, offset = 0.4, color = "black") +
geom_tiplab(aes(label=not_species_genus_type), fontface='italic', size=1, offset = 0.4, color = "black") +
theme_tree2()
plot_tree_IQ_TREE_chloroplast_large_circular<-plot_tree_IQ_TREE_chloroplast_large_circular+
new_scale_fill()
plot_tree_IQ_TREE_chloroplast_large_circular<-gheatmap(plot_tree_IQ_TREE_chloroplast_large_circular, data = annotations_cp[,c("Lineages_Nikolov_et_al"), drop=F], width=.01, offset=13, colnames=F)+
scale_fill_manual(values=c("transparent", "orange", "lightblue","green","pink","yellow"), na.translate = F)
ggsave(filename = "results_plots_phylogenies/plot_tree_IQ_TREE_chloroplast_large_circular_for_print.pdf", plot_tree_IQ_TREE_chloroplast_large_circular + theme(legend.position="none"),
width = 10, height = 10)
##ASTRAL-III inclusive ----
plot_tree_ASTRALIII_inclusive_large<-ggtree(tree_ASTRALIII_inclusive, aes(color="grey"), size=0.3, branch.length = "none") %<+% annotations +
scale_color_manual(values = c("darkgrey","#00BFC4"), na.value = "darkgrey")+
geom_inset(tree_ASTRALIII_inclusive_astral_annotations_piecharts, width = 0.05, height = 0.05, hjust = 0.175, vjust = 0.15)+
#Highlight the calibration nodes.
geom_tiplab(aes(label=ASTRAL_taxon_occupancy_inclusive), size=0.6, offset = 7.6, color = "black")+
geom_tiplab(aes(label=Library_ID2), size=1, offset = 8.1, color = "black")+
geom_tiplab(aes(label=tribe), size=1, offset = 2.7, color = "black")+
geom_tiplab(aes(label=species), fontface='italic', size=1, offset = 4.5, color = "black")
plot_tree_ASTRALIII_inclusive_large<-plot_tree_ASTRALIII_inclusive_large+new_scale_fill()
plot_tree_ASTRALIII_inclusive_large<-gheatmap(plot_tree_ASTRALIII_inclusive_large, data = annotations[,c("Lineages_Nikolov_et_al","Lineages_unplaced")], width=.05, colnames_position = "top", colnames_angle = 45, font.size = 2, custom_column_labels = c("Nikolov","Franzke","Koch","jumpy"), colnames_offset_y = 2)+
scale_fill_manual(values=c("darkslategrey","transparent","darkmagenta","blue","#FF4F33","lightblue","chartreuse3","pink","red","#FFC425"), na.translate = F)
plot_tree_ASTRALIII_inclusive_large<-plot_tree_ASTRALIII_inclusive_large+new_scale_fill()
plot_tree_ASTRALIII_inclusive_large<-gheatmap(plot_tree_ASTRALIII_inclusive_large, data = annotations[,c("locus_heterozygosity"), drop=FALSE], width=.01, offset = 1.8, colnames_position = "top", colnames_angle = 45, font.size = 2, custom_column_labels = c("LH"), colnames_offset_y = 2)+
scale_fill_gradient(low = "yellow", high = "red", na.value = NA)
plot_tree_ASTRALIII_inclusive_large<-plot_tree_ASTRALIII_inclusive_large+new_scale_fill()
plot_tree_ASTRALIII_inclusive_large<-gheatmap(plot_tree_ASTRALIII_inclusive_large, data = annotations[,c("allele_divergence"), drop=FALSE], width=.01, offset = 2.1, colnames_position = "top", colnames_angle = 45, font.size = 2, custom_column_labels = c("AD"), colnames_offset_y = 2) +
scale_fill_gradient(low = "yellow", high = "red", na.value = NA)+
theme(legend.position= "none", plot.margin = unit(c(0,0,0,0), "cm"))
ggsave(filename = "results_plots_phylogenies/plot_tree_ASTRALIII_inclusive_large.pdf", plot_tree_ASTRALIII_inclusive_large,
width = 12, height = 18)
##ASTRAL-III strict ----
plot_tree_ASTRALIII_strict_large<-ggtree(tree_ASTRALIII_strict, aes(color="grey"), size=0.3, branch.length = "none") %<+% annotations +
scale_color_manual(values = c("darkgrey","#00BFC4"), na.value = "darkgrey")+
geom_inset(tree_ASTRALIII_strict_astral_annotations_piecharts, width = 0.05, height = 0.05, hjust = 0.175, vjust = 0.15)+
#Highlight the calibration nodes.
geom_tiplab(aes(label=ASTRAL_taxon_occupancy_strict), size=0.6, offset = 7.6, color = "black")+
geom_tiplab(aes(label=Library_ID2), size=1, offset = 8.1, color = "black")+
geom_tiplab(aes(label=tribe), size=1, offset = 2.7, color = "black")+
geom_tiplab(aes(label=species), fontface='italic', size=1, offset = 4.5, color = "black")
plot_tree_ASTRALIII_strict_large<-plot_tree_ASTRALIII_strict_large+new_scale_fill()
plot_tree_ASTRALIII_strict_large<-gheatmap(plot_tree_ASTRALIII_strict_large, data = annotations[,c("Lineages_Nikolov_et_al","Lineages_unplaced")], width=.05, colnames_position = "top", colnames_angle = 45, font.size = 2, custom_column_labels = c("Nikolov","Franzke","Koch","jumpy"), colnames_offset_y = 2)+
scale_fill_manual(values=c("darkslategrey","transparent","darkmagenta","blue","#FF4F33","lightblue","chartreuse3","pink","red","#FFC425"), na.translate = F)
plot_tree_ASTRALIII_strict_large<-plot_tree_ASTRALIII_strict_large+new_scale_fill()
plot_tree_ASTRALIII_strict_large<-gheatmap(plot_tree_ASTRALIII_strict_large, data = annotations[,c("locus_heterozygosity"), drop=FALSE], width=.01, offset = 1.8, colnames_position = "top", colnames_angle = 45, font.size = 2, custom_column_labels = c("LH"), colnames_offset_y = 2)+
scale_fill_gradient(low = "yellow", high = "red", na.value = NA)
plot_tree_ASTRALIII_strict_large<-plot_tree_ASTRALIII_strict_large+new_scale_fill()
plot_tree_ASTRALIII_strict_large<-gheatmap(plot_tree_ASTRALIII_strict_large, data = annotations[,c("allele_divergence"), drop=FALSE], width=.01, offset = 2.1, colnames_position = "top", colnames_angle = 45, font.size = 2, custom_column_labels = c("AD"), colnames_offset_y = 2) +
scale_fill_gradient(low = "yellow", high = "red", na.value = NA)+
theme(legend.position= "none", plot.margin = unit(c(0,0,0,0), "cm"))
ggsave(filename = "results_plots_phylogenies/plot_tree_ASTRALIII_strict_large.pdf", plot_tree_ASTRALIII_strict_large,
width = 12, height = 18)
#ASTRAL ROUTINE BINARY HEATMAPS ----
##Inclusive routine ----
#Read in the names of all gene tree files.
tree_ASTRALIII_inclusive_gene_trees_files<-list.files("results_iqtree_final_inclusive", pattern="*.treefile")
#Sort by origin of bait kit (using simply length of the file name).
tree_ASTRALIII_inclusive_gene_trees_files<-tree_ASTRALIII_inclusive_gene_trees_files[order(nchar(tree_ASTRALIII_inclusive_gene_trees_files))]
#Create a dataframe to be filled with binary data for presence/absence for each sample in each gene tree.
tree_ASTRALIII_inclusive_presence<-data.frame(matrix(nrow=length(tree_ASTRALIII_inclusive$tip.label), ncol=length(tree_ASTRALIII_inclusive_gene_trees_files)), 0)
colnames(tree_ASTRALIII_inclusive_presence)<-lapply(strsplit(tree_ASTRALIII_inclusive_gene_trees_files, "_"), "[", 1)
rownames(tree_ASTRALIII_inclusive_presence)<-tree_ASTRALIII_inclusive$tip.label
#Loop through the gene trees and tip labels to score presence of the samples in each gene tree.
for (i in 1:length(tree_ASTRALIII_inclusive_gene_trees_files)){
gene_tree_i<-read.tree(paste0("results_iqtree_final_inclusive/", tree_ASTRALIII_inclusive_gene_trees_files[i]))
for (j in 1:length(gene_tree_i$tip.label)){
gene_tree_i_tip_label_j<-gene_tree_i$tip.label[j]
#And put a "1" in the table in the correct cell.
tree_ASTRALIII_inclusive_presence[which(rownames(tree_ASTRALIII_inclusive_presence) == gene_tree_i_tip_label_j), i] <- 1
}
}
#Reformat the dataframe into long format.
tree_ASTRALIII_inclusive_presence<-tree_ASTRALIII_inclusive_presence[,which(!is.na(colnames(tree_ASTRALIII_inclusive_presence))==T)] #Remove any columns with a colname that does not exist (NA)
tree_ASTRALIII_inclusive_presence$samples<-rownames(tree_ASTRALIII_inclusive_presence)
tree_ASTRALIII_inclusive_presence_long<-tree_ASTRALIII_inclusive_presence %>% gather(genes, value, colnames(tree_ASTRALIII_inclusive_presence)[1:length(colnames(tree_ASTRALIII_inclusive_presence))-1])
##Strict routine ----