This function processes Multi-Electrode Array (MEA) data files by reading CSV files, extracting measurements and metadata, applying filters, and optionally normalizing to baseline conditions. It automatically excludes standard deviation variables and handles exclusion flags to produce clean, analysis-ready datasets.
process_mea_flexible(
main_dir,
selected_experiments = NULL,
selected_timepoints = NULL,
grouping_variables = c("Treatment", "Genotype"),
baseline_timepoint = NULL,
unique_id_vars = c("Well", "Variable"),
exclude_std_variables = TRUE,
experiment_pattern = "MEA\\d+",
timepoint_fusions = NULL,
verbose = TRUE,
output_path = NULL
)A list containing: - raw_data: Processed data in long format - normalized_data: Baseline-normalized data (if baseline_timepoint specified) - processing_params: List of parameters used for processing - output_path: Path to saved Excel file (only if output_path was provided) - experiment_name: Combined experiment identifier
Character. Path to the main directory containing experiment folders
Character vector. Experiment names to process (default: NULL = all)
Character vector. Timepoints to include (default: NULL = all)
Character vector. Metadata columns to include ("Treatment", "Genotype")
Character. Timepoint to use for normalization (default: NULL = no normalization)
Character vector. Variables that uniquely identify observations for normalization
Logical. Whether to automatically exclude standard deviation variables (default: TRUE)
Character. Regex pattern for experiment directories (default: "MEA\d+")
Timepoint fusions to generate
Logical. Whether to print progress messages (default: TRUE)
Character. Optional path for output file (default: NULL saves to main_dir with auto-generated name)
The function automatically detects and excludes variables containing "Std", "std", or "STD" in their names (e.g., "Number of Spikes - Std") while keeping average/mean variables (e.g., "Number of Spikes - Avg"). Wells marked with "Ex" or "ex" in row 124 are excluded.
By default, no files are written. To save output, provide an explicit output_path parameter. Normalization creates fold-change values relative to baseline timepoint.
Process data without saving (returns data frames only) Save output by providing explicit path