Skip to content

Commit

Permalink
small updates
Browse files Browse the repository at this point in the history
  • Loading branch information
florianhartig committed Jan 16, 2016
1 parent 078b98e commit 2742f3a
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 19 deletions.
46 changes: 31 additions & 15 deletions PhyloSim/R/localPlots.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,54 @@
#' @export
localPlots <- function(simu,which.result=NULL,size, n, community=F){

if(n ==1){n <- 2
single = T}else{single=F}
if(n ==1){
n <- 2
single = T
}else{
single=F
}

#if("PhyloSim" %in% class(simu)==T){
if (is.null(which.result)) which.result = length(simu$Output)
simu <- simu$Output[[which.result]]#}
simu <- simu$Output[[which.result]]
#}

matrix <- simu$specMat
env <- simu$envMat


edge <- round(sqrt(size))-1
subPlots <- list()
envPlots <- list()
communityTable <- data.frame("species"= numeric())

for(i in 1:n)
{
x = sample(x=1:length(matrix[1,]),size=1)
y = sample(x=1:length(matrix[,1]),size=1)

# Check for boundary issues and implemant warped bounaries if necessary
if(x+edge > length(matrix[1,]) && y+edge <= length(matrix[,1]))
subPlot <- matrix[c(seq(x,length(matrix[1,])),
seq(1,(edge-length(seq(x,length(matrix[1,])))))),seq(y,y+edge)-1]
if(x+edge > length(matrix[1,]) && y+edge <= length(matrix[,1])){
rsel = c(seq(x,length(matrix[1,])), seq(1,(edge-length(seq(x,length(matrix[1,]))))))
csel = seq(y,y+edge)-1
}
else if(x+edge <= length(matrix[1,]) && y+edge > length(matrix[,1])){
rsel = seq(x,x+edge)-1
csel = c(seq(y,length(matrix[,1])),seq(1,(edge-length(seq(y,length(matrix[,1]))))))
}
else if(x+edge > length(matrix[1,]) && y+edge > length(matrix[,1])){
rsel = c(seq(x,length(matrix[1,])), seq(1,(edge-length(seq(x,length(matrix[1,]))))))
csel = c(seq(y,length(matrix[,1])),seq(1,(edge-length(seq(y,length(matrix[,1]))))))
}
else{
rsel = seq(x,x+edge)
csel = seq(y,y+edge)
}

else if(x+edge <= length(matrix[1,]) && y+edge > length(matrix[,1]))
subPlot <- matrix[seq(x,x+edge)-1, c(seq(y,length(matrix[,1])),seq(1,(edge-length(seq(y,length(matrix[,1]))))))]

else if(x+edge > length(matrix[1,]) && y+edge > length(matrix[,1]))
subPlot <- matrix[c(seq(x,length(matrix[1,])), seq(1,(edge-length(seq(x,length(matrix[1,])))))),
c(seq(y,length(matrix[,1])),seq(1,(edge-length(seq(y,length(matrix[,1]))))))]
else
subPlot <- matrix[seq(x,x+edge),seq(y,y+edge)]
subPlots[[i]] <- matrix[rsel, csel]
envPlots[[i]] <- env[rsel, csel]

subPlots[[i]] <- subPlot
if(community == T)
{
dataTable <- as.data.frame(table(subPlot))
Expand All @@ -66,6 +82,6 @@ localPlots <- function(simu,which.result=NULL,size, n, community=F){
}

if(single ==T){communityTable <- communityTable[-2,]}
return(list(subPlots=subPlots, communityTable=communityTable))
return(list(subPlots=subPlots, communityTable=communityTable, envPlots=envPlots))

}
29 changes: 29 additions & 0 deletions PhyloSim/examples/SAC/SAC.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
title: "U"
author: "Florian Hartig"
date: "14 Jan 2016"
output: html_document
---

```{r}
library(PhyloSim)
par <- createCompletePar(x = 50, y = 50, dispersal = 1, runs = 5000, density = 0, environment = 0.5, specRate = 1)
system.time(simu <- runSimulation(par))
plotSpatialPhylo(simu, plot = "both")
plots <- localPlots(simu, size = 25, n = 100)
library(fields)
image.plot(simu$Output[[1]]$envMat)
simu$Output[[1]]$specMat
```

3 changes: 1 addition & 2 deletions PhyloSim/vignettes/PhyloSimManual.Rnw
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ Tutorial for the PhyloSim package. Comments and contact: \href{https://florianha
library(devtools)
library(Rcpp)
install_github("biometry/phylosim", subdir = "PhyloSim", auth_token ="fb17360869e0bb3518677936611776687b48e17a", dependencies = TRUE,
build_vignettes = TRUE)
install_url("https://dl.dropboxusercontent.com/s/zkdof0b5b523qxt/PhyloSim_0.3.tar.gz")
?PhyloSim
browseVignettes("PhyloSim")
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ You can install directly from gh, using the 'devtools' package:

```{r}
# install.packages(c("devtools","Rcpp")) # I case you don't have them installed
library(devtools)
library(Rcpp)
library(Rcpp)
library(devtools)
install_url("https://dl.dropboxusercontent.com/s/zkdof0b5b523qxt/PhyloSim_0.3.tar.gz")
?PhyloSim
Expand Down
2 changes: 2 additions & 0 deletions copyDropbox.command
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
rsync -avz --delete /Users/Florian/Home/Projekte/Papers_in_Progress/15-PhylogeneticRpackage/phylosim/PhyloSim/vignettes/PhyloSimManual.pdf /Users/Florian/Dropbox/Projects/PhyloSim/Deploy

rsync -avz --delete /Users/Florian/Home/Projekte/Papers_in_Progress/15-PhylogeneticRpackage/phylosim/PhyloSim_0.3.tar.gz /Users/Florian/Dropbox/Projects/PhyloSim/Deploy




Expand Down

0 comments on commit 2742f3a

Please sign in to comment.