-
Notifications
You must be signed in to change notification settings - Fork 2
/
Data Analysis Scriptb- Raw to Traits.R
98 lines (81 loc) · 4.42 KB
/
Data Analysis Scriptb- Raw to Traits.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
## Plotting Genetic Variation
## -------------
## Burn In
bi <- 3
fileloc <- paste("/Volumes/Seagate Backup Plus Drive/Dispersal Evolution Model Data/Env Change ",bi," (v=0.01)/",sep="")
maxgen <- 3950
mingen <- 10
totlen <- length(seq(from=mingen, to=maxgen, by=10))
dispa_varlist <- vector(length=totlen)
dispb_varlist <- vector(length=totlen)
env_varlist <- vector(length=totlen)
neut_varlist <- vector(length=totlen)
for (i in seq(from=mingen, to=5000, by=10)){
filename <- paste("Burn_In",bi,"_Gen",i,".csv",sep="")
gendata <- read.csv(paste(fileloc,filename,sep=""))
LocCorrData <- cbind(gendata$generation+1, gendata$individual_ID, gendata$location, apply(gendata[,5:14], 1, sum), apply(gendata[,15:24], 1, sum), apply(gendata[,25:44], 1, sum), apply(gendata[,45:64], 1, sum))
LocCorrData <- as.data.frame(LocCorrData)
colnames(LocCorrData) <- c("Generation", "Individual_ID", "Locations", "Disp_a_trait", "Disp_b_trait", "Env_trait", "Neut_trait")
dispa_varlist[(i/10)] = var(LocCorrData$Disp_a_trait)
dispb_varlist[(i/10)] = var(LocCorrData$Disp_b_trait)
env_varlist[(i/10)] = var(LocCorrData$Env_trait)
neut_varlist[(i/10)] = var(LocCorrData$Neut_trait)
write.csv(LocCorrData, paste("/Users/Courtney/Documents/Rotation 3 - Melbourne & Flaxman Labs/Simulation Results/Burn In ",bi," Trait Data/Trait_Data_Burn_In_",bi,"_Gen_",i,".csv",sep=""))
}
## -------------
## Extension
bi <- 3
maxgen <- 25000
mingen <- 5010
totlen <- length(seq(from=mingen, to=maxgen, by=10))
fileloc <- paste("/Users/Courtney/Documents/Rotation 3 - Melbourne & Flaxman Labs/Simulation Results/No Change Extension ",bi,"/",sep="")
for (i in seq(from=mingen, to=maxgen, by=10)){
print(i)
filename <- paste("NoChange_Extension_Gen",i,".csv",sep="")
gendata <- read.csv(paste(fileloc,filename,sep=""))
LocCorrData <- cbind(gendata$generation+1, gendata$individual_ID, gendata$location, apply(gendata[,5:14], 1, sum), apply(gendata[,15:24], 1, sum), apply(gendata[,25:44], 1, sum), apply(gendata[,45:64], 1, sum))
LocCorrData <- as.data.frame(LocCorrData)
colnames(LocCorrData) <- c("Generation", "Individual_ID", "Locations", "Disp_a_trait", "Disp_b_trait", "Env_trait", "Neut_trait")
write.csv(LocCorrData, paste("/Users/Courtney/Documents/Rotation 3 - Melbourne & Flaxman Labs/Simulation Results/No Change Extension ",bi," Trait Data/Trait_Data_NoChange_Extension_",bi,"_Gen_",i,".csv",sep=""))
}
## -------------
## Env Change
bi <- 3
fileloc <- paste("/Volumes/Seagate Backup Plus Drive/Dispersal Evolution Model Data/Env Change ",bi," (v=0.01)/",sep="")
maxgen <- 25000
mingen <- 10
totlen <- length(seq(from=mingen, to=maxgen, by=10))
dispa_varlist <- vector(length=totlen)
dispb_varlist <- vector(length=totlen)
env_varlist <- vector(length=totlen)
neut_varlist <- vector(length=totlen)
for (i in seq(from=mingen, to=maxgen, by=10)){
print(i)
filename <- paste("Env_Change_F_BI",bi,"_Gen",i,".csv",sep="")
gendata <- read.csv(paste(fileloc,filename,sep=""))
LocCorrData <- cbind(gendata$generation+5001, gendata$individual_ID, gendata$location, apply(gendata[,5:14], 1, sum), apply(gendata[,15:24], 1, sum), apply(gendata[,25:44], 1, sum), apply(gendata[,45:64], 1, sum))
LocCorrData <- as.data.frame(LocCorrData)
colnames(LocCorrData) <- c("Generation", "Individual_ID", "Locations", "Disp_a_trait", "Disp_b_trait", "Env_trait", "Neut_trait")
#dispa_varlist[(i/10)] = var(LocCorrData$Disp_a_trait)
#dispb_varlist[(i/10)] = var(LocCorrData$Disp_b_trait)
#env_varlist[(i/10)] = var(LocCorrData$Env_trait)
#neut_varlist[(i/10)] = var(LocCorrData$Neut_trait)
write.csv(LocCorrData, paste("/Users/Courtney/Documents/Melbourne & Flaxman Labs/Simulation Results/Env Change ",bi," (v=0.01) Trait Data/Trait_Data_Env_Change_(v=0.01)_",bi,"_Gen_",(i+5000),".csv",sep=""))
}
par(mfrow=c(2,2))
plot(dispa_varlist)
plot(dispb_varlist)
plot(env_varlist)
plot(neut_varlist)
## -----------------------------------------------
## Change file names on no change extension 1 data
fileloc <- "/Users/Courtney/Documents/Rotation 3 - Melbourne & Flaxman Labs/Simulation Results/No Change Extension 3/"
for (i in seq(from=14590, to=16000, by=10)){
filename <- paste("No_Change_BI3_Gen",i,".csv",sep="")
gendata <- read.csv(paste(fileloc,filename,sep=""))
c_p2 <- gendata[,-1]
c_p2[,1] <- c_p2[,1]+1
current_population <- c_p2
print(paste("NoChange_Extension3_Gen",i,".csv",sep=""))
write.csv(current_population, paste(fileloc,"NoChange_Extension3_Gen",i,".csv", sep=""))
}