Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
DataExploration-AAPF/reshape_xray.r
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
74 lines (50 sloc)
2.12 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
path.xray.out <- './df_xray_long.csv' | |
# Columns to be retrieved from rgb data and added to xray data | |
col.add <- c('POT_BARCODE', 'TREATMENT', 'VARIETY', 'DFP', 'GROWTH_STAGE') | |
# File path to rgb dataframe to retrieve TREATMENT, VARIETY, DFP, GROWTH_STAGE | |
path.rgb.long <- './df_rgb_long.csv' | |
# File path pattern containing xray results | |
pattern <- paste0('/depot/smarterag/data/XRAY/', | |
'Experiment_Bayer2/', | |
'Experiment_*/', | |
'kimimaro_out_200/', | |
'*.txt') | |
# Get file paths containing individual phenotyping results | |
files <- Sys.glob(file.path(pattern)) | |
# Open individual files and merge them into a dataframe | |
xray <- data.frame() | |
for (f in files){ | |
tmp <- read.csv(f) | |
xray <- rbind(xray, tmp) | |
} | |
# Change column names | |
names(xray)[names(xray)=='experiment_ID'] <- 'EXP ID' | |
names(xray)[names(xray)=='plant_ID'] <- 'POT_BARCODE' | |
names(xray)[names(xray)=='RESOLUTION'] <- 'View' | |
# Remove unnecessary columns | |
xray <- subset(xray, select=-c(pot_height)) | |
# Load rgb dataframe (long format table) | |
rgb.long <- read.csv(path.rgb.long) | |
# Get attributes per each POT_BARCODE (TREATMENT, VARIEY, DFP, GRWOTH_STAGE) | |
attributes <- rgb.long %>% | |
group_by(POT_BARCODE) %>% | |
summarise(TREATMENT=names(which.max(table(TREATMENT))), | |
VARIETY=names(which.max(table(VARIETY))), | |
DFP=names(which.max(table(DFP))), | |
GROWTH_STAGE=names(which.max(table(GROWTH_STAGE)))) %>% | |
ungroup() | |
# Add more attributes for consistency with rgb and hsi data | |
#attributes$SCAN_TIME <- -1 | |
#attributes$SCAN_DATE <- -1 | |
attributes$frame_nr <- -1 | |
# Add the attributes to xray data | |
xray <- left_join(xray, attributes, by = 'POT_BARCODE') | |
# Reshape xray dataframe | |
id.vars.xray <- c("EXP ID", "POT_BARCODE", "VARIETY", "TREATMENT", "DFP", | |
"GROWTH_STAGE", "View", "frame_nr") | |
xray.long <- reshape2::melt(xray, id.vars = id.vars.xray, | |
variable.name = "variable") | |
# Export dataframe | |
write.csv(xray.long, path.xray.out, row.names=F) | |
# EOF |