1 # Runs `waves` package with data from the NIRS Breedbase tool to predict phenotypes with trained NIRS models
4 # Jenna Hershberger (jmh579@cornell.edu)
15 ### Read in and assign arguments ####
16 args <- commandArgs(trailingOnly = TRUE)
18 # args[1] = new spectral data for prediction
19 dataset.input <- jsonlite::fromJSON(txt = args[1], flatten = T) %>%
20 rename("unique.id" = observationUnitId) %>%
21 rename_at(vars(starts_with("nirs_spectra")), ~str_replace(., "nirs_spectra.", "")) %>%
22 dplyr::select("unique.id", num_range(prefix = "X", range = 1:100000))
23 print(dataset.input[1:10,1:10])
25 predictions <- predict_spectra(input.data = dataset.input,
26 model.stats.location = args[2], # args[2] = model performance statistics filepath
27 model.location = args[3], # args[3] = model filepath
28 model.method = args[4]) # args[4] = model method as a string
31 write.csv(predictions, file = args[5], row.names = FALSE)