ONR Identifying Pilot and General IDs that need Mobi - LeoLedesma237/LeoWebsite GitHub Wiki
The goal of this script is to identify which file names (GnG or Nback .xdf) need to be processed through MoBi. This process takes an .xdf file and extracts marker information from it, which gets saved as a .CSV file. In addition, the code creates two excel files, one that displays Pilot IDs that need MoBi and another that is for General IDs respectively. There are six parts to this script.
- Part 1: Load the file names of copied over .xdf files
- Part 2: Load in file names that have already been processed by MoBi
- Part 3: Identify the files that need to be processed by MoBi
- Part 4: Create a data frame containing this information
- Part 5: Identify which of these IDs are Pilot or General
- Part 6: Save these IDs separately
# Load in packages
library(tidyverse)
library(openxlsx)
# Load in all of the files from EEG_DATA and EEG_DATA_Pilot
setwd("M:/EEG_XDFs_Copy/EEG_DATA")
EEG_files <- list.files()
setwd("M:/EEG_XDFs_Copy/EEG_DATA_PILOT")
Pilot_EEG_files <- list.files()
# Remove any files that have MoBi in the name (These are folders)
EEG_files <- EEG_files[!grepl(pattern = "MoBI", EEG_files)]
Pilot_EEG_files <- Pilot_EEG_files[!grepl(pattern = "MoBI", Pilot_EEG_files)]
All_EEG_files <- sort(c(EEG_files, Pilot_EEG_files))
# Remove resting-state EEG files
All_EEG_files <- All_EEG_files[!grepl("rsEEG",All_EEG_files)]
# Load in data that has already been processed through MoBi
setwd("M:/EEG_XDFs_Copy/EEG_DATA_CSV_Files")
General.CSVs <- list.files()
setwd("M:/EEG_XDFs_Copy/EEG_DATA_PILOT_CSV_Files")
Pilot.CSVs <- list.files()
All.CSVs <- c(General.CSVs, Pilot.CSVs)
# Remove the extensions from both file names
may_need_MoBi <- gsub(pattern = ".xdf", "", All_EEG_files)
have_MoBi <- gsub(pattern = ".txt", "", All.CSVs)
# Obtain the files that need MoBi
need_MoBi <- setdiff(may_need_MoBi, have_MoBi)
# Create a data frame with IDs and the file names
data <- data.frame(IDs = IDs,
files = need_MoBi)
# Introduce a task variable
data <- data %>%
mutate(Task.Type = ifelse(grepl(pattern = "GnG",
x = files,
ignore.case = T),
"GnG",
"Nback"))
# Arrange by task variable
data <- arrange(data, Task.Type, IDs)
# Load in Pilot data information
# Set working directory
setwd("C:/Users/lledesma.TIMES/Documents/ONR/ROTC_Military_IDs")
# Load in the Military IDs
Military.ROTC.IDs <- read.csv("Pilot.sample.csv")$ID
# Create a function that lables files from Pilot IDs or General
data <- data %>%
mutate(status = ifelse(IDs %in% Military.ROTC.IDs,
"Pilot",
"General"))
# Separate them by Status
Pilot.data <- filter(data, status == "Pilot")
General.data <- filter(data, status == "General")
# Set a saving directory
setwd("M:/EEG_XDFs_Copy")
# Save the Pilots IDs that need MoBi
write.xlsx(Pilot.data, "Pilot IDs need MoBi.xlsx")
# Save the general IDs that need MoBi
write.xlsx(General.data, "General IDs need MoBi.xlsx")