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?
EoreCampfire/eorePrep.R
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
103 lines (86 sloc)
4.22 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
# DATA PREP | |
# For: Shiny demo of Eore Radial Tree | |
# Trying to emulate: https://observablehq.com/d/e4c0d5b05b440e32 (Shweta's diagram) | |
# See also: https://rdrr.io/cran/networkD3/src/R/radialNetwork.R | |
library(shiny) | |
library(tidyverse) | |
library(networkD3) | |
library(data.tree) | |
library(readxl) | |
# Data preparation (comment out) | |
# Read in Shweta's file | |
eoreoutput_vsr <- read_excel("eoreoutput_vsr.xlsx") | |
eore.df <- eoreoutput_vsr %>% select("solute_name_initial_1", # Level 1 | |
"total_system_pressure_initial", # Level 2 | |
"temperature_initial", # Level 3 | |
"solute_name_initial_2", # Level 4a | |
"solid_name_initial_1", # Level 4b | |
"solute_concentration_initial_2", # Level 5a | |
"solid_mass_initial_1", # Level 5b | |
"max_polymer_length_final_3", # Level 6 | |
"paper_title", | |
"paper_author", | |
"paper_year" | |
) | |
eore.df <- data.frame(lapply(eore.df, function(x) { | |
gsub("--", NA , x) | |
})) | |
# Change `max_polymer_length_final_3` to numeric (for selection) | |
eore.df$max_polymer_length_final_3 <- as.numeric(eore.df$max_polymer_length_final_3) | |
# Append every non-NA row of Level 2 | |
eore.df$total_system_pressure_initial[!is.na(eore.df$total_system_pressure_initial)] <- paste0(eore.df$total_system_pressure_initial[!is.na(eore.df$total_system_pressure_initial)], " bar") | |
# Append every non-NA row of Level 3 | |
eore.df$temperature_initial[!is.na(eore.df$temperature_initial)] <- paste0(eore.df$temperature_initial[!is.na(eore.df$temperature_initial)], " C") | |
# Append every non-NA row of Level 5a, 5b | |
eore.df$solute_concentration_initial_2[!is.na(eore.df$solute_concentration_initial_2)] <- paste0(eore.df$solute_concentration_initial_2[!is.na(eore.df$solute_concentration_initial_2)], " mmol/l") | |
eore.df$solid_mass_initial_1[!is.na(eore.df$solid_mass_initial_1)] <- paste0(eore.df$solid_mass_initial_1[!is.na(eore.df$solid_mass_initial_1)], " mg") | |
# Find Level 4 multiples | |
lev4mults <- which(!is.na(eore.df$solute_name_initial_2) & !is.na(eore.df$solid_name_initial_1)) | |
# replicate those rows (at the end) | |
for (i in lev4mults) { | |
eore.df <- rbind(eore.df,eore.df[i,]) | |
eore.df$solute_name_initial_2[i] <- NA | |
eore.df$solid_name_initial_1[nrow(eore.df)] <- NA | |
} | |
# Find Level 5 multiples | |
lev5mults <- which(!is.na(eore.df$solute_concentration_initial_2) & !is.na(eore.df$solid_mass_initial_1)) | |
# replicate those rows (at the end) | |
for (i in lev5mults) { | |
eore.df <- rbind(eore.df, eore.df[i,]) | |
eore.df$solute_concentration_initial_2[i] <- NA | |
eore.df$solid_mass_initial_1[nrow(eore.df)] <- NA | |
} | |
# Combine Level 4's | |
eore.df$Level4 <- apply(eore.df[,4:5], 1, function(x) paste(x[!is.na(x) ], collapse = "")); | |
eore.df$Level5 <- apply(eore.df[,6:7], 1, function(x) paste(x[!is.na(x) ], collapse = "")); | |
# Reorganize | |
eore.df <- eore.df %>% select(solute_name_initial_1, | |
total_system_pressure_initial, | |
temperature_initial, | |
Level4, | |
Level5, | |
max_polymer_length_final_3, | |
paper_title, | |
paper_author, | |
paper_year) | |
colnames(eore.df) <- c("Level1", | |
"Level2", | |
"Level3", | |
"Level4", | |
"Level5", | |
"Level6", | |
"paper_title", | |
"paper_author", | |
"paper_year") | |
eore.df$pathString <-paste("RNA Experiments", | |
eore.df$Level1, | |
eore.df$Level2, | |
eore.df$Level3, | |
eore.df$Level4, | |
eore.df$Level5, | |
eore.df$Level6, | |
sep="|") | |
# Remove the first entry | |
eore.df <- eore.df[-1,] | |
# Save it! | |
saveRDS(eore.df, "eore.df.Rds") |