Mercurial > repos > greg > bmsb
changeset 29:be7c61620bb1 draft
Uploaded
author | greg |
---|---|
date | Sun, 21 Aug 2016 10:18:33 -0400 |
parents | 22043dadfd2c |
children | 53d2ac56c953 |
files | bmsb.R |
diffstat | 1 files changed, 35 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/bmsb.R Fri Aug 19 14:52:06 2016 -0400 +++ b/bmsb.R Sun Aug 21 10:18:33 2016 -0400 @@ -3,7 +3,7 @@ suppressPackageStartupMessages(library("optparse")) options_list <- list( - make_option(c("-n", "--input"), action="store", help="Input dataset") + make_option(c("-i", "--input"), action="store", help="Input dataset"), make_option(c("-o", "--output"), action="store", help="Output dataset") ) @@ -181,12 +181,12 @@ if (vec.ind[1]==0 && vec.ind[2]==3) { # overwintering adult (previttelogenic) if (photoperiod>13.5 && vec.ind[3]>77 && day<180) { # add 77C to become fully reproductively matured vec.ind<-c(0,4,0,0,0) # transfer to vittelogenic - vec.mat[i,]<-vec.ind - + vec.mat[i,]<-vec.ind + } else { vec.ind[3]<-vec.ind[3]+dd.temp # add to DD vec.ind[4]<-vec.ind[4]+1 # add 1 day in current stage - vec.mat[i,]<-vec.ind + vec.mat[i,]<-vec.ind } } @@ -194,11 +194,11 @@ current.gen<-vec.ind[1] if (vec.ind[3]>77) { # add 77C to become fully reproductively matured vec.ind<-c(current.gen,4,0,0,0) # transfer to vittelogenic - vec.mat[i,]<-vec.ind + vec.mat[i,]<-vec.ind } else { vec.ind[3]<-vec.ind[3]+dd.temp # add to DD vec.ind[4]<-vec.ind[4]+1 # add 1 day in current stage - vec.mat[i,]<-vec.ind + vec.mat[i,]<-vec.ind } } @@ -214,14 +214,14 @@ } vec.ind[3]<-vec.ind[3]+dd.temp # add to DD vec.ind[4]<-vec.ind[4]+1 # add 1 day in current stage - vec.mat[i,]<-vec.ind + vec.mat[i,]<-vec.ind if (n.birth>0) { # add new birth -- might be in different generations - new.gen<-vec.ind[1]+1 # generation +1 - new.ind<-c(new.gen,0,0,0,0) # egg profile - new.vec<-rep(new.ind,n.birth) - new.vec<-t(matrix(new.vec,nrow=5)) # update batch of egg profile - birth.vec<-rbind(birth.vec,new.vec) # group with total eggs laid in that day - } + new.gen<-vec.ind[1]+1 # generation +1 + new.ind<-c(new.gen,0,0,0,0) # egg profile + new.vec<-rep(new.ind,n.birth) + new.vec<-t(matrix(new.vec,nrow=5)) # update batch of egg profile + birth.vec<-rbind(birth.vec,new.vec) # group with total eggs laid in that day + } } # event 2 oviposition -- for gen 1. @@ -234,14 +234,14 @@ } vec.ind[3]<-vec.ind[3]+dd.temp # add to DD vec.ind[4]<-vec.ind[4]+1 # add 1 day in current stage - vec.mat[i,]<-vec.ind + vec.mat[i,]<-vec.ind if (n.birth>0) { # add new birth -- might be in different generations - new.gen<-vec.ind[1]+1 # generation +1 - new.ind<-c(new.gen,0,0,0,0) # egg profile - new.vec<-rep(new.ind,n.birth) - new.vec<-t(matrix(new.vec,nrow=5)) # update batch of egg profile - birth.vec<-rbind(birth.vec,new.vec) # group with total eggs laid in that day - } + new.gen<-vec.ind[1]+1 # generation +1 + new.ind<-c(new.gen,0,0,0,0) # egg profile + new.vec<-rep(new.ind,n.birth) + new.vec<-t(matrix(new.vec,nrow=5)) # update batch of egg profile + birth.vec<-rbind(birth.vec,new.vec) # group with total eggs laid in that day + } } @@ -251,24 +251,24 @@ if (vec.ind[2]==0) { # egg stage vec.ind[3]<-vec.ind[3]+dd.temp # add to DD if (vec.ind[3]>=68) { # from egg to young nymph, DD requirement met - current.gen<-vec.ind[1] - vec.ind<-c(current.gen,1,0,0,0) # transfer to young nym stage - } else { - vec.ind[4]<-vec.ind[4]+1 # add 1 day in current stage - } - vec.mat[i,]<-vec.ind + current.gen<-vec.ind[1] + vec.ind<-c(current.gen,1,0,0,0) # transfer to young nym stage + } else { + vec.ind[4]<-vec.ind[4]+1 # add 1 day in current stage + } + vec.mat[i,]<-vec.ind } # event 3.2 young nymph to old nymph (vec.ind[2]=1 -> young nymph: determines diapause) if (vec.ind[2]==1) { # young nymph stage vec.ind[3]<-vec.ind[3]+dd.temp # add to DD if (vec.ind[3]>=250) { # from young to old nymph, DD requirement met - current.gen<-vec.ind[1] - vec.ind<-c(current.gen,2,0,0,0) # transfer to old nym stage - if (photoperiod<13.5 && day > 180) {vec.ind[5]<-1} # prepare for diapausing - } else { - vec.ind[4]<-vec.ind[4]+1 # add 1 day in current stage - } + current.gen<-vec.ind[1] + vec.ind<-c(current.gen,2,0,0,0) # transfer to old nym stage + if (photoperiod<13.5 && day > 180) {vec.ind[5]<-1} # prepare for diapausing + } else { + vec.ind[4]<-vec.ind[4]+1 # add 1 day in current stage + } vec.mat[i,]<-vec.ind } @@ -282,7 +282,7 @@ vec.ind<-c(current.gen,3,0,0,0) } else { # diapausing vec.ind<-c(current.gen,5,0,0,1) - } + } } else { vec.ind[4]<-vec.ind[4]+1 # add 1 day in current stage } @@ -341,11 +341,9 @@ N.newborn[day]<-n.newborn N.death[day]<-n.death N.adult[day]<-n.adult -print(c(day,n,n.adult)) +#print(c(day,n,n.adult)) } proc.time() - ptm dd.cum<-cumsum(dd.day) -save(dd.day,dd.cum,S0,S1,S2,S3,S4,S5,N.newborn,N.death,N.adult,tot.pop,gen0.pop,gen1.pop,gen2.pop,g0.adult,g1.adult,g2.adult,file="opt$output") - - +save(dd.day,dd.cum,S0,S1,S2,S3,S4,S5,N.newborn,N.death,N.adult,tot.pop,gen0.pop,gen1.pop,gen2.pop,g0.adult,g1.adult,g2.adult,file=opt$output)