-
Notifications
You must be signed in to change notification settings - Fork 0
/
02.01.phylogenetic-pruning.R
120 lines (98 loc) · 3.03 KB
/
02.01.phylogenetic-pruning.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
#### recommended machine: 02 ----
#### packages ----
library("tidyverse")
library("tidyr")
library("picante")
library("future")
library("furrr")
#### load sPlot data ----
load("~/share/groups/sPlot/releases//sPlot3.0/DT_sPlot3.0.RData")
load("~/share/groups/sPlot/releases//sPlot3.0/header_sPlot3.0.RData")
load("02.data/PhyloTree_sPlot3.0.Rdata")
load("~/share/groups/sPlot/releases//sPlot3.0/Traits_CWMs_sPlot3.RData")
# select sPlot species present in the Phylogeny and with known traits
sPlot.species <- DT2 %>%
distinct(Species)
species.trait <- sPlot.traits %>%
select(Species, SLA_mean, PlantHeight_mean, SpecificRootLength_mean) %>%
filter(complete.cases(.)) %>%
pull(Species)
sPlot.in.Tree <- sPlot.species %>%
filter(Species %in% (tree.species %>%
filter(status != "fail to bind") %>%
pull(species))) %>%
filter(Species %in% species.trait)
pruning <- function(myspecies, tree.to.prune) {
spp1 <- matrix(
data = 1,
nrow = 1,
ncol = length(unique(myspecies)),
dimnames = list(
"mydataset",
unique(myspecies)
)
)
pruned.tree <- prune.sample(spp1, tree.to.prune)
return(pruned.tree)
}
### Build the pruned tree once for each dataset ----
PD.out0 <- DT2 %>%
left_join(
header %>%
dplyr::select(PlotObservationID, `GIVD ID`),
by = "PlotObservationID"
) %>%
filter(Species %in% sPlot.in.Tree$Species) %>%
mutate(Species = gsub(" ", "_", Species)) %>%
group_by(`GIVD ID`) %>%
dplyr::summarize(pruned.tree = list(pruning(
myspecies = Species,
tree.to.prune = sPlot.phylo.tree$scenario.3
)))
save(PD.out0, sPlot.in.Tree, file = "02.data/pruned.trees.traitsp.RData")
rm(list = ls())
#### redo for sPlotOpen----
#### load data ----
load("02.data/sPlotOpen.RData")
load("02.data/PhyloTree_sPlot3.0.Rdata")
load("02.data/Traits_CWMs_sPlot3.RData")
# select species in phylogeny and with known traits
sPlot.species <- DT2.oa %>%
distinct(Species)
species.trait <- sPlot.traits %>%
select(Species, SLA_mean, PlantHeight_mean, SpecificRootLength_mean) %>%
filter(complete.cases(.)) %>%
pull(Species)
sPlot.in.Tree <- sPlot.species %>%
filter(Species %in% (tree.species %>%
filter(status != "fail to bind") %>%
pull(species))) %>%
filter(Species %in% species.trait)
pruning <- function(myspecies, tree.to.prune) {
spp1 <- matrix(
data = 1,
nrow = 1,
ncol = length(unique(myspecies)),
dimnames = list(
"mydataset",
unique(myspecies)
)
)
pruned.tree <- prune.sample(spp1, tree.to.prune)
return(pruned.tree)
}
### Build the pruned tree once for each dataset ----
PD.out0 <- DT2.oa %>%
left_join(
header.oa %>%
dplyr::select(PlotObservationID, GIVD_ID),
by = "PlotObservationID"
) %>%
filter(Species %in% sPlot.in.Tree$Species) %>%
mutate(Species = gsub(" ", "_", Species)) %>%
group_by(GIVD_ID) %>%
dplyr::summarize(pruned.tree = list(pruning(
myspecies = Species,
tree.to.prune = sPlot.phylo.tree$scenario.3
)))
save(PD.out0, sPlot.in.Tree, file = "02.data/pruned.trees.traitsp.sPlotOpen.RData")