GENPRES/PRESENCE in a batch file

How to run GENPRES/PRESENCE in a batch file

To run GENPRES in batch mode, you will need to create a text file which calls the computational module of GENPRES with arguments specifying the input parameters. You can find out the format of these input arguments by typing 'genpres4.exe' in a terminal window (after changing the current directory to the directory containing 'genpres4.exe'. If you're using 'wine', you probably need to type 'wine genpres4.exe' instead of just 'genpres4.exe'.

For example, I could enter the following into a text file named 'script1.sh':

!#/usr/bin/sh
#                   script1.sh
wine genpres4 4 100 .75 .5 .5 .5 .5

This runs genpres with 4 surveys, 100 sites, psi=.75, p(1)=.5, p(2)=.5, p(3)=.5, p(4)=.5.

In a terminal window, I could then run the textfile by typing, 'script1.sh' or 'sh script1.sh'.

This example isn't very useful as it only runs genpres once and does nothing with the output. If I wanted to run genpres with different values of detection probabilities, my script file could be (script2.sh):

!#/usr/bin/sh
#                   script2.sh
wine genpres4 4 100 .75 .1 .1 .1 .1
mv genpres.pao genpres1.pao
wine genpres4 4 100 .75 .2 .2 .2 .2
mv genpres.pao genpres2.pao
wine genpres4 4 100 .75 .3 .3 .3 .3
mv genpres.pao genpres3.pao
wine genpres4 4 100 .75 .4 .4 .4 .4
mv genpres.pao genpres4.pao
wine genpres4 4 100 .75 .5 .5 .5 .5
mv genpres.pao genpres5.pao
wine genpres4 4 100 .75 .6 .6 .6 .6
mv genpres.pao genpres6.pao
wine genpres4 4 100 .75 .7 .7 .7 .7
mv genpres.pao genpres7.pao
wine genpres4 4 100 .75 .8 .8 .8 .8
mv genpres.pao genpres8.pao
wine genpres4 4 100 .75 .9 .9 .9 .9
mv genpres.pao genpres9.pao

This would run genpres with 9 different values of detection probability (from 0.1 to 0.9) and rename the default output files with different names. Of course, it would be easier to do this in a loop as in (script3.sh):

!#/usr/bin/sh
#                   script3.sh
for i in 1 2 3 4 5 6 7 8 9; do
  wine genpres4 4 100 .75 .$i .$i .$i .$i
  mv genpres.pao genpres$i.pao
end

You probably want to run PRESENCE on each of the files created by GENPRES. This script will do it (script4.sh):

!#/usr/bin/sh
#                   script4.sh
for i in 1 2 3 4 5 6 7 8 9; do
  wine genpres4 4 100 .75 .$i .$i .$i .$i
  mv genpres.pao genpres$i.pao
  wine presence.exe i=genpres$i.pao l=presence$i.out model=1c
end

The arguments to presence.exe are: i=inputfile, l=outputfile, model=xx, where xx=

To generate data for the multi-season model, just add colonization and extinction parameters to the command line:

  wine genpres4 4 100 .75 .5 .5 .5 .5 0 .1 0 0 .2 0 SRVYPERSEASN=2

Since we have 4 surveys, there are 4 detection probabilities, but only 3 colonization probabilities and 3 extinction probabilities. This is because colonization and extinction only occur between surveys and there are 3 intervals between the 4 surveys. I specified '0 .1 0' for the 3 colonization rates, meaning there is no colonization in the 1st interval (between surveys 1 and 2) and no colonization in the 3rd interval (between surveys 3 and 4). However, there is colonization in interval 2 (between surveys 2 and 3). The same applies to extinction as I specified '0 .2 0'. This is how to create multi-season data. Specify zero for colonization and extinction for intervals which are between surveys in the same season and non-zero values for intervals between seasons. So, we have 4 surveys, with 2 seasons of 2 surveys each. (Surveys 1 and 2 are in season 1, and surveys 3 and 4 are in season 2.)

To run PRESENCE with multi-season data, you will need to create a design-matrix file since there are no pre-defined models for multi-season models. The design-matrix file is a simple text file containing 6 tables. Each table is preceeded by a line containing the table number, number of rows in the table, and number of columns. These tables are just the design-matrix tables you see when you run the interactive PRESENCE program. Here is a design matrix file for a multi-season model (mod1.dm):

0 2 2
-,a1
psi,1
1 2 2
-,b1
gam1,1
2 2 2
-,c1
eps1,1
3 5 2
-,d1
p(1_1),1
p(1_2),1
p(2_1),1
p(2_2),1
4 0 0
5 0 0

Note that there is a line containing the column labels, and each row contains the parameter label as the 1st entry in the line. So, the row and column count preceeding each table includes these labels. Also, only 1 row per interval between seasons is needed for colonization and extinction in the design-matrix. The first table (table 0, 2 rows, 2 cols) is the design matrix for occupancy. The 2nd table is the design matrix for colonization (gam) (table 1, 2 rows, 2 cols). The 3rd table is the design matrix for extinction (eps) (table 2, 2 rows, 2 cols). The 4th table is the design matrix for detection (p) (table 3, 5 rows, 2 cols). The last two tables are empty (zero rows, zero columns) and not needed for a multi-season model. We could create this design matrix in a text editor, then specify it's filename in the script (script5.sh)

!#/usr/bin/sh
#                   script5.sh
for i in 1 2 3 4 5 6 7 8 9; do
  wine genpres4 4 100 .75 .$i .$i .$i .$i 0 .1 0 0 .2 0
  mv genpres.pao genpres$i.pao
  wine presence.exe i=genpres$i.pao l=presence$i.out j=mod1.dm model=200
end

Note that I added the argument 'j=mod1.dm' to specify the design-matrix file and changed the model to 'model=200' to specify a multi-season model. My preference is to incorporate the design matrix into the script, like this (script6.sh):

!#/usr/bin/sh
#                   script6.sh
echo '0 2 2' > tmp.dm
echo '-,a1' >> tmp.dm
echo 'psi,1' >> tmp.dm
echo '1 2 2' >> tmp.dm
echo '-,b1' >> tmp.dm
echo 'gam1,1' >> tmp.dm
echo '2 2 2' >> tmp.dm
echo '-,c1' >> tmp.dm
echo 'eps1,1' >> tmp.dm
echo '3 5 2' >> tmp.dm
echo '-,d1' >> tmp.dm
echo 'p(1_1),1' >> tmp.dm
echo 'p(1_2),1' >> tmp.dm
echo 'p(2_1),1' >> tmp.dm
echo 'p(2_2),1' >> tmp.dm
echo '4 0 0' >> tmp.dm
echo '5 0 0' >> tmp.dm
for i in 9; do
  echo $i
  wine genpres4.exe 4 100 .75 .$i .$i .$i .$i 0 .1 0 0 .2 0 SRVYPERSEASN=2
  mv genpres.pao genpres$i.pao
  wine presence.exe i=genpres$i.pao j=tmp.dm model=200 l=presence$i.out
done

We now should have 9 PRESENCE output files, and we could extract whatever we desire using the 'grep' command:

grep '^psi.+1 site_1' presence.out

Comments:

  1. These instructions show how to run GENPRES/PRESENCE in a batch file using the Bourne shell as the command processor. With modifications, it could be used with the Windows command processor.
  2. Since the Bourne shell and Windows command processor are limited in text processing, I prefer to use a text-processing program (eg., perl or awk/gawk) or Program R (www.r-project.org). R has the additional benefit of being able to do everything in these scripts, plus generate plots and summary stats of the estimates.
  3. If you want to see how to do something that isn't specified here, I suggest that you run the interactive GENPRES module(genpres4_int.exe) from the terminal window so you can see what arguments are passed to the genpres4.exe program. You can then specify those arguemnts in your script. Similarly, you can run the interactive PRESENCE module (presence_int.exe) from a terminal window and see which arguments are passed to the computational module (presence.exe). Actually, you can see these arguments in the output file created by PRESENCE.