0
|
1 #!/usr/bin/env Rscript
|
|
2
|
|
3 suppressPackageStartupMessages(library("data.table"))
|
|
4 suppressPackageStartupMessages(library("hash"))
|
|
5 suppressPackageStartupMessages(library("optparse"))
|
|
6
|
|
7 option_list <- list(
|
|
8 make_option(c("--input_data_dir"), action="store", dest="input_data_dir", help="Directory containing .csv outputs from insect_phenology_model"),
|
|
9 make_option(c("--end_date"), action="store", dest="end_date", help="End date for date interval"),
|
|
10 make_option(c("--start_date"), action="store", dest="start_date", help="Start date for date interval"),
|
|
11 make_option(c("--script_dir"), action="store", dest="script_dir", help="R script source directory"),
|
|
12 make_option(c("--tool_parameters"), action="store", dest="tool_parameters", help="Users defined parameters for executing the insect_phenology_model inputs")
|
|
13 )
|
|
14
|
|
15 parser <- OptionParser(usage="%prog [options] file", option_list=option_list);
|
|
16 args <- parse_args(parser, positional_arguments=TRUE);
|
|
17 opt <- args$options;
|
|
18
|
|
19 get_new_temperature_data_frame = function(input_data_file) {
|
|
20 # Read a csv file to produce a data frame
|
|
21 # consisting of the data which was produced
|
|
22 # by the insect_phenology_model tool.
|
|
23 temperature_data_frame = read.csv(file=input_data_file, header=T, strip.white=TRUE, stringsAsFactors=FALSE, sep=",");
|
|
24 return(temperature_data_frame);
|
|
25 }
|
|
26
|
|
27 parse_tool_parameters = function(tool_parameters) {
|
|
28 # Parse the tool parameters that were used to produce
|
|
29 # the input datasets found in input_data_dir. These
|
|
30 # datasets were produced by the insect_phenology_model
|
|
31 # tool.
|
|
32 raw_params = sub("^__SeP__", "", tool_parameters);
|
|
33 raw_param_items = strsplit(raw_params, "__SeP__")[[1]];
|
|
34 keys = raw_param_items[c(T, F)];
|
|
35 values = raw_param_items[c(F, T)];
|
|
36 num_keys_and_vals = length(keys);
|
|
37 for (i in 1:num_keys_and_vals) {
|
|
38 values[i] = restore_text(values[[i]]);
|
|
39 }
|
|
40 for (i in 1:num_keys_and_vals) {
|
|
41 key = keys[i];
|
|
42 if (endsWith(key, "cond")) {
|
|
43 value = values[i];
|
|
44 # Galaxy passes some input job parameters as json-like strings
|
|
45 # for complex objects like conditionals, so we should see if
|
|
46 # we can re-implement this using r-jsonlite if possible. An
|
|
47 # exception is currently thrown when we do this:
|
|
48 # params_hash = fromJSON(opt$tool_parameters);
|
|
49 # Error: lexical error: invalid char in json text.
|
|
50 # __SeP__adult_mortality__SeP____
|
|
51 # (right here) ------^
|
|
52 # Here is an example complex object parameter value, in
|
|
53 # this case the parameter name is plot_nymph_life_stage_cond.
|
|
54 # {"life_stages_nymph": ["Total"], "__current_case__": 0, "plot_nymph_life_stage": "yes"}
|
|
55 # This code is somewhat brittle, so a better approach is
|
|
56 # warranted if possible.
|
|
57 if (key == "merge_ytd_temperature_data_cond") {
|
|
58 val = grep("yes", value);
|
|
59 if (length(val)>0) {
|
|
60 # Get the location.
|
|
61 items = strsplit(value, "\"location\": ")[[1]];
|
|
62 location_str = items[2];
|
|
63 val = grep("\",", location_str);
|
|
64 if (length(val)>0) {
|
|
65 items = strsplit(location_str, "\",")[[1]];
|
|
66 location = items[1];
|
|
67 } else {
|
|
68 location = items[1];
|
|
69 }
|
|
70 if (location == "\"") {
|
|
71 location = "";
|
|
72 }
|
|
73 keys[i] = "location";
|
|
74 values[i] = location;
|
|
75 }
|
|
76 } else if (key =="plot_nymph_life_stage_cond") {
|
|
77 val = grep("yes", value);
|
|
78 if (length(val)==0) {
|
|
79 keys[i] = "plot_nymph_life_stage";
|
|
80 values[i] = "no";
|
|
81 } else {
|
|
82 # Get the value for "life_stages_nymph".
|
|
83 items = strsplit(value, "\"life_stages_nymph\": ")[[1]];
|
|
84 life_stages_nymph_str = items[2];
|
|
85 if (grep("],", life_stages_nymph_str)[[1]] > 0) {
|
|
86 items = strsplit(life_stages_nymph_str, "],")[[1]];
|
|
87 life_stages_nymph_str = items[1];
|
|
88 #life_stages_nymph_str = sub("^\\[", "", life_stages_nymph_str);
|
|
89 num_curent_keys = length(keys);
|
|
90 keys[num_curent_keys+1] = "life_stages_nymph";
|
|
91 values[num_curent_keys+1] = life_stages_nymph_str;
|
|
92 }
|
|
93 keys[i] = "plot_nymph_life_stage";
|
|
94 values[i] = "yes";
|
|
95 }
|
|
96 } else if (key =="plot_adult_life_stage_cond") {
|
|
97 val = grep("yes", value);
|
|
98 # The value of val is an integer if the pattern is not found.
|
|
99 if (length(val)==0) {
|
|
100 keys[i] = "plot_adult_life_stage";
|
|
101 values[i] = "no";
|
|
102 } else {
|
|
103 # Get the value for "life_stages_adult".
|
|
104 items = strsplit(value, "\"life_stages_adult\": ")[[1]];
|
|
105 life_stages_adult_str = items[2];
|
|
106 if (grep("],", life_stages_adult_str)[[1]] > 0) {
|
|
107 items = strsplit(life_stages_adult_str, "],")[[1]];
|
|
108 life_stages_adult_str = items[1];
|
|
109 #life_stages_adult_str = sub("^\\[", "", life_stages_adult_str);
|
|
110 num_curent_keys = length(keys);
|
|
111 keys[num_curent_keys+1] = "life_stages_adult";
|
|
112 values[num_curent_keys+1] = life_stages_adult_str;
|
|
113 }
|
|
114 keys[i] = "plot_adult_life_stage";
|
|
115 values[i] = "yes";
|
|
116 }
|
|
117 }
|
|
118 }
|
|
119 }
|
|
120 # Strip all double qu0tes from values.
|
|
121 for (i in 1:length(values)) {
|
|
122 value = values[i];
|
|
123 value = gsub("\"", "", value);
|
|
124 values[i] = value;
|
|
125 }
|
|
126 return(hash(keys, values));
|
|
127 }
|
|
128
|
|
129 prepare_plot = function(life_stage, file_path, maxval, ticks, date_labels, chart_type, plot_std_error, insect, location,
|
|
130 latitude, start_date, end_date, total_days_vector, replications, group, group_std_error, group2, group2_std_error,
|
|
131 group3, group3_std_error, sub_life_stage=NULL) {
|
|
132 # Start PDF device driver.
|
|
133 dev.new(width=20, height=30);
|
|
134 pdf(file=file_path, width=20, height=30, bg="white");
|
|
135 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1));
|
|
136 render_chart(ticks, date_labels, chart_type, plot_std_error, insect, location, latitude, start_date, end_date,
|
|
137 total_days_vector, maxval, replications, life_stage, group=group, group_std_error=group_std_error, group2=group2,
|
|
138 group2_std_error=group2_std_error, group3=group3, group3_std_error=group3_std_error, sub_life_stage=sub_life_stage);
|
|
139 # Turn off device driver to flush output.
|
|
140 dev.off();
|
|
141 }
|
|
142
|
|
143 restore_text = function(text) {
|
|
144 # Un-escape characters that are escaped by the
|
|
145 # Galaxy tool parameter handlers.
|
|
146 if (is.null(text) || length(text) == 0) {
|
|
147 return(text);
|
|
148 }
|
|
149 chars = list(">", "<", "'", '"', "[", "]", "{", "}", "@", "\n", "\r", "\t", "#");
|
|
150 mapped_chars = list("__gt__", "__lt__", "__sq__", "__dq__", "__ob__", "__cb__",
|
|
151 "__oc__", "__cc__", "__at__", "__cn__", "__cr__", "__tc__", "__pd__");
|
|
152 for (i in 1:length(mapped_chars)) {
|
|
153 char = chars[[i]];
|
|
154 mapped_char = mapped_chars[[i]];
|
|
155 text = gsub(mapped_char, char, text);
|
|
156 }
|
|
157 return(text);
|
|
158 }
|
|
159
|
|
160 # Import the shared utility functions.
|
|
161 utils_path <- paste(opt$script_dir, "utils.R", sep="/");
|
|
162 source(utils_path);
|
|
163
|
|
164 params_hash = parse_tool_parameters(opt$tool_parameters);
|
|
165
|
|
166 # Determine the data we need to generate for plotting.
|
|
167 if (params_hash$plot_generations_separately == "yes") {
|
|
168 plot_generations_separately = TRUE;
|
|
169 } else {
|
|
170 plot_generations_separately = FALSE;
|
|
171 }
|
|
172 if (params_hash$plot_std_error == "yes") {
|
|
173 plot_std_error = TRUE;
|
|
174 } else {
|
|
175 plot_std_error = FALSE;
|
|
176 }
|
|
177 process_eggs = FALSE;
|
|
178 process_nymphs = FALSE;
|
|
179 process_young_nymphs = FALSE;
|
|
180 process_old_nymphs = FALSE;
|
|
181 process_total_nymphs = FALSE;
|
|
182 process_adults = FALSE;
|
|
183 process_previttelogenic_adults = FALSE;
|
|
184 process_vittelogenic_adults = FALSE;
|
|
185 process_diapausing_adults = FALSE;
|
|
186 process_total_adults = FALSE;
|
|
187 if (params_hash$plot_egg_life_stage == "yes") {
|
|
188 process_eggs = TRUE;
|
|
189 }
|
|
190 if (params_hash$plot_nymph_life_stage == "yes") {
|
|
191 process_nymphs = TRUE;
|
|
192 # Get the selected life stages.
|
|
193 value = params_hash$life_stages_nymph;
|
|
194 val = grep("Young", value);
|
|
195 if (length(val)>0) {
|
|
196 process_young_nymphs = TRUE;
|
|
197 }
|
|
198 val = grep("Old", value);
|
|
199 if (length(val)>0) {
|
|
200 process_old_nymphs = TRUE;
|
|
201 }
|
|
202 val = grep("Total", value);
|
|
203 if (length(val)>0) {
|
|
204 process_total_nymphs = TRUE;
|
|
205 }
|
|
206 }
|
|
207 if (params_hash$plot_adult_life_stage == "yes") {
|
|
208 process_adults = TRUE;
|
|
209 # Get the selected life stages.
|
|
210 value = params_hash$life_stages_adult;
|
|
211 val = grep("Pre-vittelogenic", value);
|
|
212 if (length(val)>0) {
|
|
213 process_previttelogenic_adults = TRUE;
|
|
214 }
|
|
215 val = grep("Vittelogenic", value);
|
|
216 if (length(val)>0) {
|
|
217 process_vittelogenic_adults = TRUE;
|
|
218 }
|
|
219 val = grep("Diapausing", value);
|
|
220 if (length(val)>0) {
|
|
221 process_diapausing_adults = TRUE;
|
|
222 }
|
|
223 val = grep("Total", value);
|
|
224 if (length(val)>0) {
|
|
225 process_total_adults = TRUE;
|
|
226 }
|
|
227 }
|
|
228
|
|
229 if (params_hash$plot_egg_life_stage == "yes" & params_hash$plot_nymph_life_stage == "yes" & params_hash$plot_adult_life_stage == "yes") {
|
|
230 process_total = TRUE;
|
|
231 } else {
|
|
232 process_total = FALSE;
|
|
233 }
|
|
234
|
|
235
|
|
236 # FIXME: currently custom date fields are free text, but
|
|
237 # Galaxy should soon include support for a date selector
|
|
238 # at which point this tool should be enhanced to use it.
|
|
239 # Validate start_date.
|
|
240 start_date = format(opt$start_date);
|
|
241 end_date = format(opt$end_date);
|
|
242
|
|
243 # Calaculate the number of days in the date interval.
|
|
244 start_date = validate_date(start_date);
|
|
245 # Validate end_date.
|
|
246 end_date = validate_date(end_date);
|
|
247 if (start_date >= end_date) {
|
3
|
248 stop_err("The start date must be between 1 and 50 days before the end date.\n");
|
0
|
249 }
|
|
250 # Calculate the number of days in the date interval.
|
|
251 num_days = difftime(end_date, start_date, units=c("days"));
|
|
252 # Add 1 to the number of days to make the dates inclusive. For
|
|
253 # example, if the user enters a date range of 2018-01-01 to
|
|
254 # 2018-01-31, they likely expect the end date to be included.
|
|
255 num_days = num_days + 1;
|
|
256 if (num_days > 50) {
|
|
257 # We need to restrict date intervals since
|
|
258 # plots render tick marks for each day.
|
|
259 stop_err("Date intervals for plotting cannot exceed 50 days.");
|
|
260 }
|
|
261 # Display the total number of days in the Galaxy history item blurb.
|
|
262 cat("Number of days in date interval: ", num_days, "\n");
|
|
263
|
|
264 # Create the csv data files consisting of the date interval.
|
|
265 input_data_files = list.files(path=opt$input_data_dir, full.names=TRUE);
|
|
266 for (input_data_file in input_data_files) {
|
|
267 file_name = basename(input_data_file);
|
|
268 temperature_data_frame = get_new_temperature_data_frame(input_data_file);
|
|
269 start_date_row = which(temperature_data_frame$DATE==start_date);
|
|
270 end_date_row = which(temperature_data_frame$DATE==end_date);
|
3
|
271 if (length(start_date_row)==0 | length(end_date_row)==0) {
|
|
272 stop_err("Invalid date interval, make sure the start and end dates are both contained within the selected input data files.\n");
|
|
273 }
|
0
|
274 # Extract the date interval.
|
|
275 temperature_data_frame = temperature_data_frame[start_date_row:end_date_row,];
|
|
276 # Save the date interval data into an output file
|
|
277 # named the same as the input.
|
|
278 file_path = paste("output_data_dir", file_name, sep="/");
|
|
279 write.csv(temperature_data_frame, file=file_path, row.names=F);
|
|
280 }
|
|
281
|
|
282 # Extract the vectors needed for plots from the input data files
|
|
283 # produced by the insect_phenology_model tool.
|
|
284 total_days_vector = NULL;
|
|
285 ticks_and_labels = NULL;
|
|
286 latitude = NULL;
|
|
287 input_data_files = list.files(path="output_data_dir", full.names=TRUE);
|
|
288 for (input_data_file in input_data_files) {
|
|
289 file_name = basename(input_data_file);
|
|
290 temperature_data_frame = get_new_temperature_data_frame(input_data_file);
|
|
291 # Initialize the total_days_vector for later plotting.
|
|
292 if (is.null(total_days_vector)) {
|
|
293 total_days_vector = c(1:dim(temperature_data_frame)[1]);
|
|
294 }
|
|
295 if (is.null(ticks_and_labels)) {
|
|
296 # Get the ticks date labels for later plotting
|
|
297 ticks_and_labels = get_x_axis_ticks_and_labels(temperature_data_frame, date_interval=TRUE);
|
|
298 ticks = c(unlist(ticks_and_labels[1]));
|
|
299 date_labels = c(unlist(ticks_and_labels[2]));
|
|
300 }
|
|
301 if (is.null(latitude)) {
|
|
302 # Get the latitude for later plotting.
|
|
303 latitude = temperature_data_frame$LATITUDE[1];
|
|
304 }
|
|
305
|
|
306 if (file_name == "04_combined_generations.csv") {
|
|
307 if (process_eggs) {
|
|
308 eggs = temperature_data_frame$EGG;
|
|
309 if (plot_std_error) {
|
|
310 eggs.std_error = temperature_data_frame$EGGSE;
|
|
311 }
|
|
312 }
|
|
313 if (process_young_nymphs) {
|
|
314 young_nymphs = temperature_data_frame$YOUNGNYMPH;
|
|
315 if (plot_std_error) {
|
|
316 young_nymphs.std_error = temperature_data_frame$YOUNGNYMPHSE;
|
|
317 }
|
|
318 }
|
|
319 if (process_old_nymphs) {
|
|
320 old_nymphs = temperature_data_frame$OLDNYMPH;
|
|
321 if (plot_std_error) {
|
|
322 old_nymphs.std_error = temperature_data_frame$OLDNYMPHSE;
|
|
323 }
|
|
324 }
|
|
325 if (process_total_nymphs) {
|
|
326 total_nymphs = temperature_data_frame$TOTALNYMPH;
|
|
327 if (plot_std_error) {
|
|
328 total_nymphs.std_error = temperature_data_frame$TOTALNYMPHSE;
|
|
329 }
|
|
330 }
|
|
331 if (process_previttelogenic_adults) {
|
|
332 previttelogenic_adults = temperature_data_frame$PRE.VITADULT;
|
|
333 if (plot_std_error) {
|
|
334 previttelogenic_adults.std_error = temperature_data_frame$PRE.VITADULTSE;
|
|
335 }
|
|
336 }
|
|
337 if (process_vittelogenic_adults) {
|
|
338 vittelogenic_adults = temperature_data_frame$VITADULT;
|
|
339 if (plot_std_error) {
|
|
340 vittelogenic_adults.std_error = temperature_data_frame$VITADULTSE;
|
|
341 }
|
|
342 }
|
|
343 if (process_diapausing_adults) {
|
|
344 diapausing_adults = temperature_data_frame$DIAPAUSINGADULT;
|
|
345 if (plot_std_error) {
|
|
346 diapausing_adults.std_error = temperature_data_frame$DIAPAUSINGADULTSE;
|
|
347 }
|
|
348 }
|
|
349 if (process_total_adults) {
|
|
350 total_adults = temperature_data_frame$TOTALADULT;
|
|
351 if (plot_std_error) {
|
|
352 total_adults.std_error = temperature_data_frame$TOTALADULTSE;
|
|
353 }
|
|
354 }
|
|
355 } else if (file_name == "01_generation_P.csv") {
|
|
356 if (process_eggs) {
|
|
357 P_eggs = temperature_data_frame$EGG.P;
|
|
358 if (plot_std_error) {
|
|
359 P_eggs.std_error = temperature_data_frame$EGG.P.SE;
|
|
360 }
|
|
361 }
|
|
362 if (process_young_nymphs) {
|
|
363 P_young_nymphs = temperature_data_frame$YOUNGNYMPH.P;
|
|
364 if (plot_std_error) {
|
|
365 P_young_nymphs.std_error = temperature_data_frame$YOUNGNYMPH.P.SE;
|
|
366 }
|
|
367 }
|
|
368 if (process_old_nymphs) {
|
|
369 P_old_nymphs = temperature_data_frame$OLDNYMPH.P;
|
|
370 if (plot_std_error) {
|
|
371 P_old_nymphs.std_error = temperature_data_frame$OLDNYMPH.P.SE;
|
|
372 }
|
|
373 }
|
|
374 if (process_total_nymphs) {
|
|
375 P_total_nymphs = temperature_data_frame$TOTALNYMPH.P;
|
|
376 if (plot_std_error) {
|
|
377 P_total_nymphs.std_error = temperature_data_frame$TOTALNYMPH.P.SE;
|
|
378 }
|
|
379 }
|
|
380 if (process_previttelogenic_adults) {
|
|
381 P_previttelogenic_adults = temperature_data_frame$PRE.VITADULT.P;
|
|
382 if (plot_std_error) {
|
|
383 P_previttelogenic_adults.std_error = temperature_data_frame$PRE.VITADULT.P.SE;
|
|
384 }
|
|
385 }
|
|
386 if (process_vittelogenic_adults) {
|
|
387 P_vittelogenic_adults = temperature_data_frame$VITADULT.P;
|
|
388 if (plot_std_error) {
|
|
389 P_vittelogenic_adults.std_error = temperature_data_frame$VITADULT.P.SE;
|
|
390 }
|
|
391 }
|
|
392 if (process_diapausing_adults) {
|
|
393 P_diapausing_adults = temperature_data_frame$DIAPAUSINGADULT.P;
|
|
394 if (plot_std_error) {
|
|
395 P_diapausing_adults.std_error = temperature_data_frame$DIAPAUSINGADULT.P.SE;
|
|
396 }
|
|
397 }
|
|
398 if (process_total_adults) {
|
|
399 P_total_adults = temperature_data_frame$TOTALADULT.P;
|
|
400 if (plot_std_error) {
|
|
401 P_total_adults.std_error = temperature_data_frame$TOTALADULT.P.SE;
|
|
402 }
|
|
403 }
|
1
|
404 if (process_total) {
|
|
405 P_all_total = temperature_data_frame$ALL.TOTAL.P;
|
|
406 if (plot_std_error) {
|
|
407 P_all_total.std_error = temperature_data_frame$ALL.TOTAL.P.SE;
|
|
408 }
|
|
409 }
|
0
|
410 } else if (file_name == "02_generation_F1.csv") {
|
|
411 if (process_eggs) {
|
|
412 F1_eggs = temperature_data_frame$EGG.F1;
|
|
413 if (plot_std_error) {
|
|
414 F1_eggs.std_error = temperature_data_frame$EGG.F1.SE;
|
|
415 }
|
|
416 }
|
|
417 if (process_young_nymphs) {
|
|
418 F1_young_nymphs = temperature_data_frame$YOUNGNYMPH.F1;
|
|
419 if (plot_std_error) {
|
|
420 F1_young_nymphs.std_error = temperature_data_frame$YOUNGNYMPH.F1.SE;
|
|
421 }
|
|
422 }
|
|
423 if (process_old_nymphs) {
|
|
424 F1_old_nymphs = temperature_data_frame$OLDNYMPH.F1;
|
|
425 if (plot_std_error) {
|
|
426 F1_old_nymphs.std_error = temperature_data_frame$OLDNYMPH.F1.SE;
|
|
427 }
|
|
428 }
|
|
429 if (process_total_nymphs) {
|
|
430 F1_total_nymphs = temperature_data_frame$TOTALNYMPH.F1;
|
|
431 if (plot_std_error) {
|
|
432 F1_total_nymphs.std_error = temperature_data_frame$TOTALNYMPH.F1.SE;
|
|
433 }
|
|
434 }
|
|
435 if (process_previttelogenic_adults) {
|
|
436 F1_previttelogenic_adults = temperature_data_frame$PRE.VITADULT.F1;
|
|
437 if (plot_std_error) {
|
|
438 F1_previttelogenic_adults.std_error = temperature_data_frame$PRE.VITADULT.F1.SE;
|
|
439 }
|
|
440 }
|
|
441 if (process_vittelogenic_adults) {
|
|
442 F1_vittelogenic_adults = temperature_data_frame$VITADULT.F1;
|
|
443 if (plot_std_error) {
|
|
444 F1_vittelogenic_adults.std_error = temperature_data_frame$VITADULT.F1.SE;
|
|
445 }
|
|
446 }
|
|
447 if (process_diapausing_adults) {
|
|
448 F1_diapausing_adults = temperature_data_frame$DIAPAUSINGADULT.F1;
|
|
449 if (plot_std_error) {
|
|
450 F1_diapausing_adults.std_error = temperature_data_frame$DIAPAUSINGADULT.F1.SE;
|
|
451 }
|
|
452 }
|
|
453 if (process_total_adults) {
|
|
454 F1_total_adults = temperature_data_frame$TOTALADULT.F1;
|
|
455 if (plot_std_error) {
|
|
456 F1_total_adults.std_error = temperature_data_frame$TOTALADULT.F1.SE;
|
|
457 }
|
|
458 }
|
1
|
459 if (process_total) {
|
|
460 F1_all_total = temperature_data_frame$ALL.TOTAL.F1;
|
|
461 if (plot_std_error) {
|
|
462 F1_all_total.std_error = temperature_data_frame$ALL.TOTAL.F1.SE;
|
|
463 }
|
|
464 }
|
0
|
465 } else if (file_name == "03_generation_F2.csv") {
|
|
466 if (process_eggs) {
|
|
467 F2_eggs = temperature_data_frame$EGG.F2;
|
|
468 if (plot_std_error) {
|
|
469 F2_eggs.std_error = temperature_data_frame$EGG.F2.SE;
|
|
470 }
|
|
471 }
|
|
472 if (process_young_nymphs) {
|
|
473 F2_young_nymphs = temperature_data_frame$YOUNGNYMPH.F2;
|
|
474 if (plot_std_error) {
|
|
475 F2_young_nymphs.std_error = temperature_data_frame$YOUNGNYMPH.F2.SE;
|
|
476 }
|
|
477 }
|
|
478 if (process_old_nymphs) {
|
|
479 F2_old_nymphs = temperature_data_frame$OLDNYMPH.F2;
|
|
480 if (plot_std_error) {
|
|
481 F2_old_nymphs.std_error = temperature_data_frame$OLDNYMPH.F2.SE;
|
|
482 }
|
|
483 }
|
|
484 if (process_total_nymphs) {
|
|
485 F2_total_nymphs = temperature_data_frame$TOTALNYMPH.F2;
|
|
486 if (plot_std_error) {
|
|
487 F2_total_nymphs.std_error = temperature_data_frame$TOTALNYMPH.F2.SE;
|
|
488 }
|
|
489 }
|
|
490 if (process_previttelogenic_adults) {
|
|
491 F2_previttelogenic_adults = temperature_data_frame$PRE.VITADULT.F2;
|
|
492 if (plot_std_error) {
|
|
493 F2_previttelogenic_adults.std_error = temperature_data_frame$PRE.VITADULT.F2.SE;
|
|
494 }
|
|
495 }
|
|
496 if (process_vittelogenic_adults) {
|
|
497 F2_vittelogenic_adults = temperature_data_frame$VITADULT.F2;
|
|
498 if (plot_std_error) {
|
|
499 F2_vittelogenic_adults.std_error = temperature_data_frame$VITADULT.F2.SE;
|
|
500 }
|
|
501 }
|
|
502 if (process_diapausing_adults) {
|
|
503 F2_diapausing_adults = temperature_data_frame$DIAPAUSINGADULT.F2;
|
|
504 if (plot_std_error) {
|
|
505 F2_diapausing_adults.std_error = temperature_data_frame$DIAPAUSINGADULT.F2.SE;
|
|
506 }
|
|
507 }
|
|
508 if (process_total_adults) {
|
|
509 F2_total_adults = temperature_data_frame$TOTALADULT.F2;
|
|
510 if (plot_std_error) {
|
|
511 F2_total_adults.std_error = temperature_data_frame$TOTALADULT.F2.SE;
|
|
512 }
|
|
513 }
|
1
|
514 if (process_total) {
|
|
515 F2_all_total = temperature_data_frame$ALL.TOTAL.F2;
|
|
516 if (plot_std_error) {
|
|
517 F2_all_total.std_error = temperature_data_frame$ALL.TOTAL.F2.SE;
|
|
518 }
|
|
519 }
|
0
|
520 }
|
|
521 }
|
|
522
|
|
523 # Create the pdf plot files based on the date interval.
|
|
524 if (plot_generations_separately) {
|
|
525 chart_type = "pop_size_by_generation";
|
|
526 if (process_eggs) {
|
|
527 # Total population size by generation.
|
|
528 life_stage = "Egg";
|
|
529 file_path = get_file_path(life_stage, "egg_pop_by_generation.pdf")
|
|
530 maxval = max(P_eggs+F1_eggs+F2_eggs) + 100;
|
|
531 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
|
|
532 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
|
|
533 params_hash$replications, group=P_eggs, group_std_error=P_eggs.std_error, group2=F1_eggs,
|
|
534 group2_std_error=F1_eggs.std_error, group3=F2_eggs, group3_std_error=F2_eggs.std_error);
|
|
535 }
|
|
536 if (process_nymphs) {
|
|
537 life_stage = "Nymph";
|
|
538 if (process_young_nymphs) {
|
|
539 # Young nymph population size by generation.
|
|
540 sub_life_stage = "Young";
|
|
541 file_path = get_file_path(life_stage, "nymph_pop_by_generation.pdf", sub_life_stage=sub_life_stage)
|
|
542 maxval = max(P_young_nymphs+F1_young_nymphs+F2_young_nymphs) + 100;
|
|
543 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
|
|
544 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
|
|
545 params_hash$replications, group=P_young_nymphs, group_std_error=P_young_nymphs.std_error,
|
|
546 group2=F1_young_nymphs, group2_std_error=F1_young_nymphs.std_error, group3=F2_young_nymphs,
|
|
547 group3_std_error=F2_young_nymphs.std_error, sub_life_stage=sub_life_stage);
|
|
548 }
|
|
549 if (process_old_nymphs) {
|
|
550 # Old nymph population size by generation.
|
|
551 sub_life_stage = "Old";
|
|
552 file_path = get_file_path(life_stage, "nymph_pop_by_generation.pdf", sub_life_stage=sub_life_stage)
|
|
553 maxval = max(P_old_nymphs+F1_old_nymphs+F2_old_nymphs) + 100;
|
|
554 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
|
|
555 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
|
|
556 params_hash$replications, group=P_old_nymphs, group_std_error=P_old_nymphs.std_error,
|
|
557 group2=F1_old_nymphs, group2_std_error=F1_old_nymphs.std_error, group3=F2_old_nymphs,
|
|
558 group3_std_error=F2_old_nymphs.std_error, sub_life_stage=sub_life_stage);
|
|
559 }
|
|
560 if (process_total_nymphs) {
|
|
561 # Total nymph population size by generation.
|
|
562 sub_life_stage = "Total";
|
|
563 file_path = get_file_path(life_stage, "nymph_pop_by_generation.pdf", sub_life_stage=sub_life_stage)
|
|
564 maxval = max(P_total_nymphs+F1_total_nymphs+F2_total_nymphs) + 100;
|
|
565 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
|
|
566 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
|
|
567 params_hash$replications, group=P_total_nymphs, group_std_error=P_total_nymphs.std_error,
|
|
568 group2=F1_total_nymphs, group2_std_error=F1_total_nymphs.std_error, group3=F2_total_nymphs,
|
|
569 group3_std_error=F2_total_nymphs.std_error, sub_life_stage=sub_life_stage);
|
|
570 }
|
|
571 }
|
|
572 if (process_adults) {
|
|
573 life_stage = "Adult";
|
|
574 if (process_previttelogenic_adults) {
|
|
575 # Pre-vittelogenic adult population size by generation.
|
|
576 sub_life_stage = "Pre-vittelogenic";
|
|
577 file_path = get_file_path(life_stage, "adult_pop_by_generation.pdf", sub_life_stage=sub_life_stage)
|
|
578 maxval = max(P_previttelogenic_adults+F1_previttelogenic_adults+F2_previttelogenic_adults) + 100;
|
|
579 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
|
|
580 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
|
|
581 params_hash$replications, group=P_previttelogenic_adults,
|
|
582 group_std_error=P_previttelogenic_adults.std_error, group2=F1_previttelogenic_adults,
|
|
583 group2_std_error=F1_previttelogenic_adults.std_error, group3=F2_previttelogenic_adults,
|
|
584 group3_std_error=F2_previttelogenic_adults.std_error, sub_life_stage=sub_life_stage);
|
|
585 }
|
|
586 if (process_vittelogenic_adults) {
|
|
587 # Vittelogenic adult population size by generation.
|
|
588 sub_life_stage = "Vittelogenic";
|
|
589 file_path = get_file_path(life_stage, "adult_pop_by_generation.pdf", sub_life_stage=sub_life_stage)
|
|
590 maxval = max(P_vittelogenic_adults+F1_vittelogenic_adults+F2_vittelogenic_adults) + 100;
|
|
591 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
|
|
592 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
|
|
593 params_hash$replications, group=P_vittelogenic_adults,
|
|
594 group_std_error=P_vittelogenic_adults.std_error, group2=F1_vittelogenic_adults,
|
|
595 group2_std_error=F1_vittelogenic_adults.std_error, group3=F2_vittelogenic_adults,
|
|
596 group3_std_error=F2_vittelogenic_adults.std_error, sub_life_stage=sub_life_stage);
|
|
597 }
|
|
598 if (process_diapausing_adults) {
|
|
599 # Diapausing adult population size by generation.
|
|
600 sub_life_stage = "Diapausing";
|
|
601 file_path = get_file_path(life_stage, "adult_pop_by_generation.pdf", sub_life_stage=sub_life_stage)
|
|
602 maxval = max(P_diapausing_adults+F1_diapausing_adults+F2_diapausing_adults) + 100;
|
|
603 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
|
|
604 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
|
|
605 params_hash$replications, group=P_diapausing_adults, group_std_error=P_diapausing_adults.std_error,
|
|
606 group2=F1_diapausing_adults, group2_std_error=F1_diapausing_adults.std_error, group3=F2_diapausing_adults,
|
|
607 group3_std_error=F2_diapausing_adults.std_error, sub_life_stage=sub_life_stage);
|
|
608 }
|
|
609 if (process_total_adults) {
|
|
610 # Total adult population size by generation.
|
|
611 sub_life_stage = "Total";
|
|
612 file_path = get_file_path(life_stage, "adult_pop_by_generation.pdf", sub_life_stage=sub_life_stage)
|
|
613 maxval = max(P_total_adults+F1_total_adults+F2_total_adults) + 100;
|
|
614 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
|
|
615 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
|
|
616 params_hash$replications, group=P_total_adults, group_std_error=P_total_adults.std_error,
|
|
617 group2=F1_total_adults, group2_std_error=F1_total_adults.std_error, group3=F2_total_adults,
|
|
618 group3_std_error=F2_total_adults.std_error, sub_life_stage=sub_life_stage);
|
|
619 }
|
|
620 }
|
|
621 if (process_total) {
|
|
622 life_stage = "Total";
|
|
623 # Total population size for egg, nymph and adult by generation.
|
|
624 file_path = get_file_path(life_stage, "total_pop_by_generation.pdf")
|
|
625 maxval = max(total_adults+eggs+total_nymphs) + 100;
|
1
|
626 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
|
|
627 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
|
|
628 params_hash$replications, group=P_all_total, group_std_error=P_all_total.std_error, group2=F1_all_total,
|
|
629 group2_std_error=F1_all_total.std_error, group3=F2_all_total, group3_std_error=F2_all_total.std_error);
|
0
|
630 }
|
|
631 } else {
|
|
632 chart_type = "pop_size_by_life_stage";
|
|
633 if (process_eggs) {
|
|
634 # Egg population size.
|
|
635 life_stage = "Egg";
|
|
636 file_path = get_file_path(life_stage, "egg_pop.pdf")
|
|
637 maxval = max(eggs+eggs.std_error) + 100;
|
|
638 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
|
|
639 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
|
|
640 params_hash$replications, group=eggs, group_std_error=eggs.std_error);
|
|
641 }
|
|
642 if (process_nymphs) {
|
|
643 life_stage = "Nymph";
|
|
644 if (process_young_nymphs) {
|
|
645 # Young nymph population size.
|
|
646 sub_life_stage = "Young";
|
|
647 file_path = get_file_path(life_stage, "nymph_pop.pdf", sub_life_stage=sub_life_stage)
|
|
648 maxval = max(young_nymphs+young_nymphs.std_error) + 100;
|
|
649 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
|
|
650 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
|
|
651 params_hash$replications, group=young_nymphs, group_std_error=young_nymphs.std_error,
|
|
652 sub_life_stage=sub_life_stage);
|
|
653 }
|
|
654 if (process_old_nymphs) {
|
|
655 # Old nymph population size.
|
|
656 sub_life_stage = "Old";
|
|
657 file_path = get_file_path(life_stage, "nymph_pop.pdf", sub_life_stage=sub_life_stage)
|
|
658 maxval = max(old_nymphs+old_nymphs.std_error) + 100;
|
|
659 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
|
|
660 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
|
|
661 params_hash$replications, group=old_nymphs, group_std_error=old_nymphs.std_error,
|
|
662 sub_life_stage=sub_life_stage);
|
|
663 }
|
|
664 if (process_total_nymphs) {
|
|
665 # Total nymph population size.
|
|
666 sub_life_stage = "Total";
|
|
667 file_path = get_file_path(life_stage, "nymph_pop.pdf", sub_life_stage=sub_life_stage)
|
|
668 maxval = max(total_nymphs+total_nymphs.std_error) + 100;
|
|
669 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
|
|
670 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
|
|
671 params_hash$replications, group=total_nymphs, group_std_error=total_nymphs.std_error,
|
|
672 sub_life_stage=sub_life_stage);
|
|
673 }
|
|
674 }
|
|
675 if (process_adults) {
|
|
676 life_stage = "Adult";
|
|
677 if (process_previttelogenic_adults) {
|
|
678 # Pre-vittelogenic adult population size.
|
|
679 sub_life_stage = "Pre-vittelogenic";
|
|
680 file_path = get_file_path(life_stage, "adult_pop.pdf", sub_life_stage=sub_life_stage)
|
|
681 maxval = max(previttelogenic_adults+previttelogenic_adults.std_error) + 100;
|
|
682 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
|
|
683 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
|
|
684 params_hash$replications, group=previttelogenic_adults,
|
|
685 group_std_error=previttelogenic_adults.std_error, sub_life_stage=sub_life_stage);
|
|
686 }
|
|
687 if (process_vittelogenic_adults) {
|
|
688 # Vittelogenic adult population size.
|
|
689 sub_life_stage = "Vittelogenic";
|
|
690 file_path = get_file_path(life_stage, "adult_pop.pdf", sub_life_stage=sub_life_stage)
|
|
691 maxval = max(vittelogenic_adults+vittelogenic_adults.std_error) + 100;
|
|
692 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
|
|
693 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
|
|
694 params_hash$replications, group=vittelogenic_adults,
|
|
695 group_std_error=vittelogenic_adults.std_error, sub_life_stage=sub_life_stage);
|
|
696 }
|
|
697 if (process_diapausing_adults) {
|
|
698 # Diapausing adult population size.
|
|
699 sub_life_stage = "Diapausing";
|
|
700 file_path = get_file_path(life_stage, "adult_pop.pdf", sub_life_stage=sub_life_stage)
|
|
701 maxval = max(diapausing_adults+diapausing_adults.std_error) + 100;
|
|
702 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
|
|
703 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
|
|
704 params_hash$replications, group=diapausing_adults, group_std_error=diapausing_adults.std_error,
|
|
705 sub_life_stage=sub_life_stage);
|
|
706 }
|
|
707 if (process_total_adults) {
|
|
708 # Total adult population size.
|
|
709 sub_life_stage = "Total";
|
|
710 file_path = get_file_path(life_stage, "adult_pop.pdf", sub_life_stage=sub_life_stage)
|
|
711 maxval = max(total_adults+total_adults.std_error) + 100;
|
|
712 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
|
|
713 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
|
|
714 params_hash$replications, group=total_adults, group_std_error=total_adults.std_error,
|
|
715 sub_life_stage=sub_life_stage);
|
|
716 }
|
|
717 }
|
|
718 if (process_total) {
|
|
719 # Total population size.
|
|
720 life_stage = "Total";
|
|
721 file_path = get_file_path(life_stage, "total_pop.pdf")
|
|
722 maxval = max(eggs+eggs.std_error, total_nymphs+total_nymphs.std_error, total_adults+total_adults.std_error) + 100;
|
|
723 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
|
|
724 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
|
|
725 params_hash$replications, group=total_adults, group_std_error=total_adults.std_error,
|
|
726 group2=total_nymphs, group2_std_error=total_nymphs.std_error, group3=eggs, group3_std_error=eggs.std_error);
|
|
727 }
|
|
728 }
|
|
729
|