-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo_box1.R
263 lines (216 loc) · 14.5 KB
/
demo_box1.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
# external installation of Rtools may be required on windows!
# https://cran.r-project.org/bin/windows/Rtools/index.html
# load libraries
libs = c("BH",
"raster",
"sp",
"stringr",
"tools",
"optparse",
"gdistance")
sapply(libs, require, character.only = T)
#install.packages(libs)
#install.packages("gen3sis_0.9.2.tar.gz", repos = NULL, type = "source")
#library("rgasm")
library("gen3sis")
#Experiment: dynamic island with initial colonizers, with dynamics including only area
Replicates<- 30
Timesteps<-140
#Scenario 1: high mutation rate
Species_richness_TimeSeries<-matrix(0,nrow=Timesteps, ncol=Replicates)
for(i in 1:Replicates){
gen3sis::run_simulation(config_file = paste(getwd(),"/config/CaseStudy1/high_trait_evolution/config_hte_randomseed.R",sep=""),
input_directory = paste(getwd(),"/landscape/CaseStudy1",sep=""),
output_directory = paste(getwd(),"/output/CaseStudy1/high_trait_evolution",sep=""),
timestep_restart = NA,
save_intermediate_results = "all")
load(paste(getwd(),"/output/CaseStudy1/high_trait_evolution/config_hte_randomseed/sgen3sis.RData",sep=""))
Species_richness_TimeSeries[,i]<-sgen3sis$turnover[,3]
print(i)
}
Species_richness_TimeSeries2<-as.data.frame(Species_richness_TimeSeries)
stringtimestepsnames<-as.character(1:Replicates)
colnames(Species_richness_TimeSeries2)<-stringtimestepsnames
summary(Species_richness_TimeSeries2)
Species_richness_TimeSeries2$Means<- rowMeans(Species_richness_TimeSeries2)
#plot(Species_richness_TimeSeries2$Means)
#Number of replicate with non-zero final communities:
Species_richness_TimeSeries3<-Species_richness_TimeSeries2[,-which(Species_richness_TimeSeries2[80,]==0)]
Numberofreplicates<-ncol(Species_richness_TimeSeries3)-1
Numberofreplicates #14 for higher mutation (less Phylo constraint)
#dataframe:
Species_richness_TimeSeries_Dataframe<-matrix(0,nrow=Timesteps*(ncol(Species_richness_TimeSeries3)-1), ncol=4)
counting<-1
for(time in 1:nrow(Species_richness_TimeSeries3)){
for(rep in 1:(ncol(Species_richness_TimeSeries3)-1)){
Species_richness_TimeSeries_Dataframe[counting,1]<-"HighTraitEvolution"
Species_richness_TimeSeries_Dataframe[counting,2]<-rep
Species_richness_TimeSeries_Dataframe[counting,3]<-time
Species_richness_TimeSeries_Dataframe[counting,4]<-Species_richness_TimeSeries3[time, rep]
counting<-counting+1
}
}
Species_richness_TimeSeries_Dataframe<-as.data.frame(Species_richness_TimeSeries_Dataframe)
colnames(Species_richness_TimeSeries_Dataframe)<-c("Scenario","Replicate", "Timestep", "Richness")
Species_richness_TimeSeries_Dataframe$Replicate<-as.numeric(as.character(Species_richness_TimeSeries_Dataframe$Replicate))
Species_richness_TimeSeries_Dataframe$Timestep<-as.numeric(as.character(Species_richness_TimeSeries_Dataframe$Timestep))
Species_richness_TimeSeries_Dataframe$Richness<-as.numeric(as.character(Species_richness_TimeSeries_Dataframe$Richness))
Species_richness_TimeSeries3$Means<- tapply(Species_richness_TimeSeries_Dataframe$Richness, Species_richness_TimeSeries_Dataframe$Timestep, mean)
Species_richness_TimeSeries3$SDs<- tapply(Species_richness_TimeSeries_Dataframe$Richness, Species_richness_TimeSeries_Dataframe$Timestep, sd)
par(mfrow=c(1,1))
plot(Species_richness_TimeSeries3$Means, las=1, type="l",lwd=4,ylim=c(0,2200),xlab="Time step", ylab="Number of species", bty="l")
lines(Species_richness_TimeSeries3$Means-Species_richness_TimeSeries3$SDs, lwd=1)
lines(Species_richness_TimeSeries3$Means+Species_richness_TimeSeries3$SDs, lwd=1)
plot(log(Species_richness_TimeSeries3$Means), las=1, type="l",lwd=4,ylim=c(0,8),xlab="Time step", ylab="Number of species", bty="l")
Lowerline<-log(Species_richness_TimeSeries3$Means-Species_richness_TimeSeries3$SDs)
Lowerline[which(Lowerline<0)]<-0
lines(Lowerline, lwd=1)
lines(log(Species_richness_TimeSeries3$Means+Species_richness_TimeSeries3$SDs), lwd=1)
saveRDS(Species_richness_TimeSeries3, paste(getwd(),"/output/CaseStudy1/Richness_Timeseries_HighTraitEvo_OnlySurvivingReps.rds", sep=""))
saveRDS(Species_richness_TimeSeries2, paste(getwd(),"/output/CaseStudy1/Richness_Timeseries_HighTraitEvo_AllReps.rds", sep=""))
Species_richness_TimeSeries4<-Species_richness_TimeSeries2 #to bind next results
#Scenario 2: reference mutation rate
Species_richness_TimeSeries<-matrix(0,nrow=Timesteps, ncol=Replicates)
for(i in 1:Replicates){
gen3sis::run_simulation(config_file = paste(getwd(),"/config/CaseStudy1/ref_trait_evolution/config_rte_randomseed.R",sep=""),
input_directory = paste(getwd(),"/landscape/CaseStudy1",sep=""),
output_directory = paste(getwd(),"/output/CaseStudy1/ref_trait_evolution",sep=""),
timestep_restart = NA,
save_intermediate_results = "all")
load(paste(getwd(),"/output/CaseStudy1/ref_trait_evolution/config_rte_randomseed/sgen3sis.RData",sep=""))
Species_richness_TimeSeries[,i]<-sgen3sis$turnover[,3]
print(i)
}
Species_richness_TimeSeries2<-as.data.frame(Species_richness_TimeSeries)
stringtimestepsnames<-as.character(1:Replicates)
colnames(Species_richness_TimeSeries2)<-stringtimestepsnames
summary(Species_richness_TimeSeries2)
Species_richness_TimeSeries2$Means<- rowMeans(Species_richness_TimeSeries2)
#plot(Species_richness_TimeSeries2$Means)
#Number of replicate with non-zero final communities:
Species_richness_TimeSeries_Dataframe2<-Species_richness_TimeSeries_Dataframe[,-which(Species_richness_TimeSeries_Dataframe[,4]==0)]
Species_richness_TimeSeries3<-Species_richness_TimeSeries2[,-which(Species_richness_TimeSeries2[80,]==0)]
Numberofreplicates<-ncol(Species_richness_TimeSeries3)-1
Numberofreplicates #27 for reference mutation (reference Phylo constraint)
#dataframe:
Species_richness_TimeSeries_Dataframe<-matrix(0,nrow=Timesteps*(ncol(Species_richness_TimeSeries3)-1), ncol=4)
counting<-1
for(time in 1:nrow(Species_richness_TimeSeries3)){
for(rep in 1:(ncol(Species_richness_TimeSeries3)-1)){
Species_richness_TimeSeries_Dataframe[counting,1]<-"ReferenceTraitEvolution"
Species_richness_TimeSeries_Dataframe[counting,2]<-rep
Species_richness_TimeSeries_Dataframe[counting,3]<-time
Species_richness_TimeSeries_Dataframe[counting,4]<-Species_richness_TimeSeries3[time, rep]
counting<-counting+1
}
}
Species_richness_TimeSeries_Dataframe<-as.data.frame(Species_richness_TimeSeries_Dataframe)
colnames(Species_richness_TimeSeries_Dataframe)<-c("Scenario","Replicate", "Timestep", "Richness")
Species_richness_TimeSeries_Dataframe$Replicate<-as.numeric(as.character(Species_richness_TimeSeries_Dataframe$Replicate))
Species_richness_TimeSeries_Dataframe$Timestep<-as.numeric(as.character(Species_richness_TimeSeries_Dataframe$Timestep))
Species_richness_TimeSeries_Dataframe$Richness<-as.numeric(as.character(Species_richness_TimeSeries_Dataframe$Richness))
Species_richness_TimeSeries3$Means<- tapply(Species_richness_TimeSeries_Dataframe$Richness, Species_richness_TimeSeries_Dataframe$Timestep, mean)
Species_richness_TimeSeries3$SDs<- tapply(Species_richness_TimeSeries_Dataframe$Richness, Species_richness_TimeSeries_Dataframe$Timestep, sd)
par(mfrow=c(1,1))
plot(Species_richness_TimeSeries3$Means, las=1, type="l",lwd=4,ylim=c(0,15000),xlab="Time step", ylab="Number of species", bty="l")
lines(Species_richness_TimeSeries3$Means-Species_richness_TimeSeries3$SDs, lwd=1)
lines(Species_richness_TimeSeries3$Means+Species_richness_TimeSeries3$SDs, lwd=1)
plot(log(Species_richness_TimeSeries3$Means), las=1, type="l",lwd=4,ylim=c(0,10),xlab="Time step", ylab="Number of species", bty="l")
Lowerline<-log(Species_richness_TimeSeries3$Means-Species_richness_TimeSeries3$SDs)
Lowerline[which(Lowerline<0)]<-0
lines(Lowerline, lwd=1)
lines(log(Species_richness_TimeSeries3$Means+Species_richness_TimeSeries3$SDs), lwd=1)
saveRDS(Species_richness_TimeSeries3, paste(getwd(),"/output/CaseStudy1/Richness_Timeseries_RefTraitEvo_OnlySurvivingReps.rds", sep=""))
saveRDS(Species_richness_TimeSeries2, paste(getwd(),"/output/CaseStudy1/Richness_Timeseries_RefTraitEvo_AllReps.rds", sep=""))
Species_richness_TimeSeries4<-rbind(Species_richness_TimeSeries4,Species_richness_TimeSeries2) #to bind next results
summary(Species_richness_TimeSeries4)
#Scenario 3: low mutation rate
Species_richness_TimeSeries<-matrix(0,nrow=Timesteps, ncol=Replicates)
for(i in 1:Replicates){
gen3sis::run_simulation(config_file = paste(getwd(),"/config/CaseStudy1/low_trait_evolution/config_lte_randomseed.R",sep=""),
input_directory = paste(getwd(),"/landscape/CaseStudy1",sep=""),
output_directory = paste(getwd(),"/output/CaseStudy1/low_trait_evolution",sep=""),
timestep_restart = NA,
save_intermediate_results = "all")
load(paste(getwd(),"/output/CaseStudy1/low_trait_evolution/config_lte_randomseed/sgen3sis.RData",sep=""))
Species_richness_TimeSeries[,i]<-sgen3sis$turnover[,3]
print(i)
}
Species_richness_TimeSeries2<-as.data.frame(Species_richness_TimeSeries)
stringtimestepsnames<-as.character(1:Replicates)
colnames(Species_richness_TimeSeries2)<-stringtimestepsnames
summary(Species_richness_TimeSeries2)
Species_richness_TimeSeries2$Means<- rowMeans(Species_richness_TimeSeries2)
#plot(Species_richness_TimeSeries2$Means)
#Number of replicate with non-zero final communities:
Species_richness_TimeSeries3<-Species_richness_TimeSeries2[,-which(Species_richness_TimeSeries2[80,]==0)]
Numberofreplicates<-ncol(Species_richness_TimeSeries3)-1
Numberofreplicates #30 for reference mutation (low Phylo constraint)
Species_richness_TimeSeries3<-Species_richness_TimeSeries2
#dataframe:
Species_richness_TimeSeries_Dataframe<-matrix(0,nrow=Timesteps*(ncol(Species_richness_TimeSeries3)-1), ncol=4)
counting<-1
for(time in 1:nrow(Species_richness_TimeSeries3)){
for(rep in 1:(ncol(Species_richness_TimeSeries3)-1)){
Species_richness_TimeSeries_Dataframe[counting,1]<-"LowTraitEvolution"
Species_richness_TimeSeries_Dataframe[counting,2]<-rep
Species_richness_TimeSeries_Dataframe[counting,3]<-time
Species_richness_TimeSeries_Dataframe[counting,4]<-Species_richness_TimeSeries3[time, rep]
counting<-counting+1
}
}
Species_richness_TimeSeries_Dataframe<-as.data.frame(Species_richness_TimeSeries_Dataframe)
colnames(Species_richness_TimeSeries_Dataframe)<-c("Scenario","Replicate", "Timestep", "Richness")
Species_richness_TimeSeries_Dataframe$Replicate<-as.numeric(as.character(Species_richness_TimeSeries_Dataframe$Replicate))
Species_richness_TimeSeries_Dataframe$Timestep<-as.numeric(as.character(Species_richness_TimeSeries_Dataframe$Timestep))
Species_richness_TimeSeries_Dataframe$Richness<-as.numeric(as.character(Species_richness_TimeSeries_Dataframe$Richness))
Species_richness_TimeSeries3$Means<- tapply(Species_richness_TimeSeries_Dataframe$Richness, Species_richness_TimeSeries_Dataframe$Timestep, mean)
Species_richness_TimeSeries3$SDs<- tapply(Species_richness_TimeSeries_Dataframe$Richness, Species_richness_TimeSeries_Dataframe$Timestep, sd)
par(mfrow=c(1,1))
plot(Species_richness_TimeSeries3$Means, las=1, type="l",lwd=4,ylim=c(0,19000),xlab="Time step", ylab="Number of species", bty="l")
lines(Species_richness_TimeSeries3$Means-Species_richness_TimeSeries3$SDs, lwd=1)
lines(Species_richness_TimeSeries3$Means+Species_richness_TimeSeries3$SDs, lwd=1)
plot(log(Species_richness_TimeSeries3$Means), las=1, type="l",lwd=4,ylim=c(0,10),xlab="Time step", ylab="Number of species", bty="l")
Lowerline<-log(Species_richness_TimeSeries3$Means-Species_richness_TimeSeries3$SDs)
Lowerline[which(Lowerline<0)]<-0
lines(Lowerline, lwd=1)
lines(log(Species_richness_TimeSeries3$Means+Species_richness_TimeSeries3$SDs), lwd=1)
saveRDS(Species_richness_TimeSeries3, paste(getwd(),"/output/CaseStudy1/Richness_Timeseries_LowTraitEvo_OnlySurvivingReps.rds", sep=""))
saveRDS(Species_richness_TimeSeries2, paste(getwd(),"/output/CaseStudy1/Richness_Timeseries_LowTraitEvo_AllReps.rds", sep=""))
Species_richness_TimeSeries4<-rbind(Species_richness_TimeSeries4,Species_richness_TimeSeries2) #to bind next results
saveRDS(Species_richness_TimeSeries4, paste(getwd(),"/output/CaseStudy1/Richness_Timeseries_AllScenarios_AllReps.rds", sep=""))
###############################Plotting experiments together:
Richness_Timeseries_Experiment <- readRDS("~/workshops/sELDIG/Genesis/gen3sis_beta/output/CaseStudy1/Richness_Timeseries_LowTraitEvo_OnlySurvivingReps.rds")
plot(log(Richness_Timeseries_Experiment$Means), las=1, type="l",lwd=4,ylim=c(0,10),xlab="Time step", ylab="Number of species (log)", bty="l")
Lowerline<-log(Richness_Timeseries_Experiment$Means-Richness_Timeseries_Experiment$SDs)
Lowerline[which(Lowerline<0)]<-0
lines(Lowerline, lwd=1)
lines(log(Richness_Timeseries_Experiment$Means+Richness_Timeseries_Experiment$SDs), lwd=1)
Richness_Timeseries_Experiment_2 <- readRDS("~/workshops/sELDIG/Genesis/gen3sis_beta/output/CaseStudy1/Richness_Timeseries_RefTraitEvo_OnlySurvivingReps.rds")
ncol(Richness_Timeseries_Experiment_2)-2 #number of simulations: 27
lines(log(Richness_Timeseries_Experiment_2$Means), lwd=4, lty=2,las=1, type="l",ylim=c(0,10),xlab="Time step", ylab="Number of species", bty="l")
Lowerline<-log(Richness_Timeseries_Experiment_2$Means-Richness_Timeseries_Experiment_2$SDs)
Lowerline[which(Lowerline<0)]<-0
lines(Lowerline, lwd=1, lty=2)
lines(log(Richness_Timeseries_Experiment_2$Means+Richness_Timeseries_Experiment_2$SDs), lwd=1, lty=2)
Richness_Timeseries_Experiment_3 <- readRDS("~/workshops/sELDIG/Genesis/gen3sis_beta/output/CaseStudy1/Richness_Timeseries_HighTraitEvo_OnlySurvivingReps.rds")
ncol(Richness_Timeseries_Experiment_3)-2 #number of simulations: 14
lines(log(Richness_Timeseries_Experiment_3$Means), lwd=4, lty=3,las=1, type="l",ylim=c(0,10),xlab="Time step", ylab="Number of species", bty="l")
Lowerline<-log(Richness_Timeseries_Experiment_3$Means-Richness_Timeseries_Experiment_3$SDs)
Lowerline[which(Lowerline<0)]<-0
lines(Lowerline, lwd=1, lty=3)
lines(log(Richness_Timeseries_Experiment_3$Means+Richness_Timeseries_Experiment_3$SDs), lwd=1, lty=3)
Ltys<-c(1,2,3)
legends<-c("Low trait evolution", "Reference trait evolution", "High trait evolution")
legend(x=-7,y=10.5, lty=Ltys, legend=legends, bty="n")
#Checking landscape
all_geo_hab <- readRDS("~/workshops/sELDIG/Genesis/rgasm_beta/input/my_experiment/all_geo_hab.rds")
is.list(all_geo_hab)
is.data.frame(all_geo_hab)
ls(all_geo_hab)
all_geo_hab$temp[1:10,1:4]
dim(all_geo_hab$temp)
which(!is.na(all_geo_hab$temp[,3]))
summary(all_geo_hab$temp [,1:4])
length(levels(as.factor(as.numeric(all_geo_hab$temp [,1]))))
length(levels(as.factor(as.numeric(all_geo_hab$temp [,2]))))