123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- source('D:/gin-cli-latest-windows64/attempt2/Codes/meaRtools/MEA_analysis_Axion.R')
- library(svDialogs)
- Filesdirectory<-paste0(choose.dir(default = "", caption = "SELECT THE FOLDER WITH THE FILES"),"\\")
- #my.files2 <- as.list(choose.files(default = "", caption = "SELECT YOUR SPIKE FILES", multi = TRUE))#,
- my.files2=as.list(list.files(Filesdirectory, full.names=TRUE))
- WorF <- (dlgInput("Enter your experiment type: (w) for weekly and (p) for pharma")$res)#, Sys.info()["user"])$res
- View(my.files2)
- my.files2[[1]]
- my.files2[[2]]
- my.files2[[3]]
- if (WorF == 'w') {
- pattern="week\\s\\d{1}"
- string=Filesdirectory
- DIV=regmatches(string, regexpr(pattern, string))
- DIV=paste0('DIV',gsub(" ", "", DIV, fixed = TRUE))
- ExpName='beforePFF'
- } else if (WorF == 'p') {
- dday=regmatches(Filesdirectory, regexpr('\\+\\d+', Filesdirectory))
- ExpName=paste0('PFFday',gsub("+", "", dday, fixed = TRUE))
- } else {
- stop("Please, enter the appropriate experiment type: (w) for weekly and (p) for pharma!")
- }
- library(svDialogs)
- Filesdirectory<-paste0(choose.dir(default = "", caption = "SELECT THE FOLDER WITH THE FILES"),"\\")
- #my.files2 <- as.list(choose.files(default = "", caption = "SELECT YOUR SPIKE FILES", multi = TRUE))#,
- my.files2=as.list(list.files(Filesdirectory, full.names=TRUE))
- WorF <- (dlgInput("Enter your experiment type: (w) for weekly and (p) for pharma")$res)#, Sys.info()["user"])$res
- if (WorF == 'w') {
- pattern="week\\s\\d{1}"
- string=Filesdirectory
- DIV=regmatches(string, regexpr(pattern, string))
- DIV=paste0('DIV',gsub(" ", "", DIV, fixed = TRUE))
- ExpName='beforePFF'
- } else if (WorF == 'p') {
- dday=regmatches(Filesdirectory, regexpr('\\+\\d+', Filesdirectory))
- ExpName=paste0('PFFday',gsub("+", "", dday, fixed = TRUE))
- } else {
- stop("Please, enter the appropriate experiment type: (w) for weekly and (p) for pharma!")
- }
- my.channels2=my.explog <- choose.files(default = "", caption = "SELECT YOUR POSITION FILE (e.g. 1well_8x8.csv or so)", multi = FALSE)
- my.input2 <- choose.dir(default = "", caption = "SELECT YOUR OUTPUT FOLDER")
- #my.channel_text_file <- '1well_8x8.csv' # name of your positions file - add .csv to end !!
- # note that channel_text_file determines the well information you wish to use
- # inform the number of wells - this will be added to the exported file name
- my.well_number <- '6w' # e.g. '6w' or '1w'
- # extracting data
- my.spike_data <- list()
- for (i in 1:length(my.files2)) {
- my.spike_data[[i]] <- read.csv(my.files2[[i]])
- }
- my.channel_data <- read.csv(my.channels2, stringsAsFactors = FALSE)
- # creating new spike data with well indo added to the electrode name
- new.channels <- my.channel_data$Channel
- new.ch <- list()
- for (i in 1:length(my.spike_data)) {
- new.ch[[i]] <- rep(0, times = length(my.spike_data[[i]]$Channel))
- for (k in 1:length(new.channels)) {
- new.ch[[i]][which(my.spike_data[[i]]$Channel == strsplit(new.channels[k], split = '_')[[1]][2])] <- new.channels[k]
- }
- }
- new.times <- list()
- for (i in 1:length(my.spike_data)) {
- new.times[[i]] <- my.spike_data[[i]]$Time
- }
- # creating and exporting data frames as csv
- for (i in 1:length(my.spike_data)) {
- new.df <- data.frame()
- new.df <- data.frame('Channel' = new.ch[[i]], 'Time' = new.times[[i]])
- #new.basename <- c()
- #new.basename <- strsplit(basename(my.files2[[i]]), split = '.csv')[[1]][1]
- if (WorF == 'p') {
- pattern3="baseline1|baseline2|AMPA|CNQX|NMDA|DAP5"
- DIV=regmatches(basename(my.files2[[i]]), regexpr(pattern3, basename(my.files2[[i]])))
- DIV=paste0('DIV',DIV)
- }
- pattern2="N\\d{3,}"
- plateN=regmatches(basename(my.files2[[i]]), regexpr(pattern2,basename(my.files2[[i]])))
- CHECKTHIS THING!!!ExpDate="210226"
- #=regmatches(basename(my.files2[[i]]), regexpr('\\d{5,}', basename(my.files2[[i]])))
- export_name <- paste0(my.input2, '/',plateN, '_', ExpDate, '_', ExpName,'_', DIV, '_', 'spikes', '_', my.well_number, '.csv')
- #export_name <- paste0(my.input2, '/',new.basename, '_', my.well_number, '.csv')
- write.csv(new.df, file = export_name, row.names = FALSE, quote = FALSE)
- }
- # creating and exporting data frames as csv
- for (i in 1:length(my.spike_data)) {
- new.df <- data.frame()
- new.df <- data.frame('Channel' = new.ch[[i]], 'Time' = new.times[[i]])
- #new.basename <- c()
- #new.basename <- strsplit(basename(my.files2[[i]]), split = '.csv')[[1]][1]
- if (WorF == 'p') {
- pattern3="baseline1|baseline2|AMPA|CNQX|NMDA|DAP5"
- DIV=regmatches(basename(my.files2[[i]]), regexpr(pattern3, basename(my.files2[[i]])))
- DIV=paste0('DIV',DIV)
- }
- pattern2="N\\d{3,}"
- plateN=regmatches(basename(my.files2[[i]]), regexpr(pattern2,basename(my.files2[[i]])))
- CHECKTHIS THING!!!ExpDate="210226"
- #=regmatches(basename(my.files2[[i]]), regexpr('\\d{5,}', basename(my.files2[[i]])))
- export_name <- paste0(my.input2, '/',plateN, '_', ExpDate, '_', ExpName,'_', DIV, '_', 'spikes', '_', my.well_number, '.csv')
- #export_name <- paste0(my.input2, '/',new.basename, '_', my.well_number, '.csv')
- write.csv(new.df, file = export_name, row.names = FALSE, quote = FALSE)
- }
- View(my.files2)
- my.files2[[1]]
- pattern2="N\\d{3,}"
- plateN=regmatches(basename(my.files2[[1]]), regexpr(pattern2,basename(my.files2[[1]])))
- regmatches(basename(my.files2[[1]]), regexpr('\\d{5,}', basename(my.files2[[1]])))
- ExpDate=regmatches(basename(my.files2[[1]]), regexpr('\\d{5,}', basename(my.files2[[1]])))
- # creating and exporting data frames as csv
- for (i in 1:length(my.spike_data)) {
- new.df <- data.frame()
- new.df <- data.frame('Channel' = new.ch[[i]], 'Time' = new.times[[i]])
- #new.basename <- c()
- #new.basename <- strsplit(basename(my.files2[[i]]), split = '.csv')[[1]][1]
- if (WorF == 'p') {
- pattern3="baseline1|baseline2|AMPA|CNQX|NMDA|DAP5"
- DIV=regmatches(basename(my.files2[[i]]), regexpr(pattern3, basename(my.files2[[i]])))
- DIV=paste0('DIV',DIV)
- }
- pattern2="N\\d{3,}"
- plateN=regmatches(basename(my.files2[[i]]), regexpr(pattern2,basename(my.files2[[i]])))
- # CHECKTHIS THING!!!ExpDate="210226"
- #=regmatches(basename(my.files2[[i]]), regexpr('\\d{5,}', basename(my.files2[[i]])))
- export_name <- paste0(my.input2, '/',plateN, '_', ExpDate, '_', ExpName,'_', DIV, '_', 'spikes', '_', my.well_number, '.csv')
- #export_name <- paste0(my.input2, '/',new.basename, '_', my.well_number, '.csv')
- write.csv(new.df, file = export_name, row.names = FALSE, quote = FALSE)
- }
|