.Rhistory 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. source('D:/gin-cli-latest-windows64/attempt2/Codes/meaRtools/MEA_analysis_Axion.R')
  2. library(svDialogs)
  3. Filesdirectory<-paste0(choose.dir(default = "", caption = "SELECT THE FOLDER WITH THE FILES"),"\\")
  4. #my.files2 <- as.list(choose.files(default = "", caption = "SELECT YOUR SPIKE FILES", multi = TRUE))#,
  5. my.files2=as.list(list.files(Filesdirectory, full.names=TRUE))
  6. WorF <- (dlgInput("Enter your experiment type: (w) for weekly and (p) for pharma")$res)#, Sys.info()["user"])$res
  7. View(my.files2)
  8. my.files2[[1]]
  9. my.files2[[2]]
  10. my.files2[[3]]
  11. if (WorF == 'w') {
  12. pattern="week\\s\\d{1}"
  13. string=Filesdirectory
  14. DIV=regmatches(string, regexpr(pattern, string))
  15. DIV=paste0('DIV',gsub(" ", "", DIV, fixed = TRUE))
  16. ExpName='beforePFF'
  17. } else if (WorF == 'p') {
  18. dday=regmatches(Filesdirectory, regexpr('\\+\\d+', Filesdirectory))
  19. ExpName=paste0('PFFday',gsub("+", "", dday, fixed = TRUE))
  20. } else {
  21. stop("Please, enter the appropriate experiment type: (w) for weekly and (p) for pharma!")
  22. }
  23. library(svDialogs)
  24. Filesdirectory<-paste0(choose.dir(default = "", caption = "SELECT THE FOLDER WITH THE FILES"),"\\")
  25. #my.files2 <- as.list(choose.files(default = "", caption = "SELECT YOUR SPIKE FILES", multi = TRUE))#,
  26. my.files2=as.list(list.files(Filesdirectory, full.names=TRUE))
  27. WorF <- (dlgInput("Enter your experiment type: (w) for weekly and (p) for pharma")$res)#, Sys.info()["user"])$res
  28. if (WorF == 'w') {
  29. pattern="week\\s\\d{1}"
  30. string=Filesdirectory
  31. DIV=regmatches(string, regexpr(pattern, string))
  32. DIV=paste0('DIV',gsub(" ", "", DIV, fixed = TRUE))
  33. ExpName='beforePFF'
  34. } else if (WorF == 'p') {
  35. dday=regmatches(Filesdirectory, regexpr('\\+\\d+', Filesdirectory))
  36. ExpName=paste0('PFFday',gsub("+", "", dday, fixed = TRUE))
  37. } else {
  38. stop("Please, enter the appropriate experiment type: (w) for weekly and (p) for pharma!")
  39. }
  40. my.channels2=my.explog <- choose.files(default = "", caption = "SELECT YOUR POSITION FILE (e.g. 1well_8x8.csv or so)", multi = FALSE)
  41. my.input2 <- choose.dir(default = "", caption = "SELECT YOUR OUTPUT FOLDER")
  42. #my.channel_text_file <- '1well_8x8.csv' # name of your positions file - add .csv to end !!
  43. # note that channel_text_file determines the well information you wish to use
  44. # inform the number of wells - this will be added to the exported file name
  45. my.well_number <- '6w' # e.g. '6w' or '1w'
  46. # extracting data
  47. my.spike_data <- list()
  48. for (i in 1:length(my.files2)) {
  49. my.spike_data[[i]] <- read.csv(my.files2[[i]])
  50. }
  51. my.channel_data <- read.csv(my.channels2, stringsAsFactors = FALSE)
  52. # creating new spike data with well indo added to the electrode name
  53. new.channels <- my.channel_data$Channel
  54. new.ch <- list()
  55. for (i in 1:length(my.spike_data)) {
  56. new.ch[[i]] <- rep(0, times = length(my.spike_data[[i]]$Channel))
  57. for (k in 1:length(new.channels)) {
  58. new.ch[[i]][which(my.spike_data[[i]]$Channel == strsplit(new.channels[k], split = '_')[[1]][2])] <- new.channels[k]
  59. }
  60. }
  61. new.times <- list()
  62. for (i in 1:length(my.spike_data)) {
  63. new.times[[i]] <- my.spike_data[[i]]$Time
  64. }
  65. # creating and exporting data frames as csv
  66. for (i in 1:length(my.spike_data)) {
  67. new.df <- data.frame()
  68. new.df <- data.frame('Channel' = new.ch[[i]], 'Time' = new.times[[i]])
  69. #new.basename <- c()
  70. #new.basename <- strsplit(basename(my.files2[[i]]), split = '.csv')[[1]][1]
  71. if (WorF == 'p') {
  72. pattern3="baseline1|baseline2|AMPA|CNQX|NMDA|DAP5"
  73. DIV=regmatches(basename(my.files2[[i]]), regexpr(pattern3, basename(my.files2[[i]])))
  74. DIV=paste0('DIV',DIV)
  75. }
  76. pattern2="N\\d{3,}"
  77. plateN=regmatches(basename(my.files2[[i]]), regexpr(pattern2,basename(my.files2[[i]])))
  78. CHECKTHIS THING!!!ExpDate="210226"
  79. #=regmatches(basename(my.files2[[i]]), regexpr('\\d{5,}', basename(my.files2[[i]])))
  80. export_name <- paste0(my.input2, '/',plateN, '_', ExpDate, '_', ExpName,'_', DIV, '_', 'spikes', '_', my.well_number, '.csv')
  81. #export_name <- paste0(my.input2, '/',new.basename, '_', my.well_number, '.csv')
  82. write.csv(new.df, file = export_name, row.names = FALSE, quote = FALSE)
  83. }
  84. # creating and exporting data frames as csv
  85. for (i in 1:length(my.spike_data)) {
  86. new.df <- data.frame()
  87. new.df <- data.frame('Channel' = new.ch[[i]], 'Time' = new.times[[i]])
  88. #new.basename <- c()
  89. #new.basename <- strsplit(basename(my.files2[[i]]), split = '.csv')[[1]][1]
  90. if (WorF == 'p') {
  91. pattern3="baseline1|baseline2|AMPA|CNQX|NMDA|DAP5"
  92. DIV=regmatches(basename(my.files2[[i]]), regexpr(pattern3, basename(my.files2[[i]])))
  93. DIV=paste0('DIV',DIV)
  94. }
  95. pattern2="N\\d{3,}"
  96. plateN=regmatches(basename(my.files2[[i]]), regexpr(pattern2,basename(my.files2[[i]])))
  97. CHECKTHIS THING!!!ExpDate="210226"
  98. #=regmatches(basename(my.files2[[i]]), regexpr('\\d{5,}', basename(my.files2[[i]])))
  99. export_name <- paste0(my.input2, '/',plateN, '_', ExpDate, '_', ExpName,'_', DIV, '_', 'spikes', '_', my.well_number, '.csv')
  100. #export_name <- paste0(my.input2, '/',new.basename, '_', my.well_number, '.csv')
  101. write.csv(new.df, file = export_name, row.names = FALSE, quote = FALSE)
  102. }
  103. View(my.files2)
  104. my.files2[[1]]
  105. pattern2="N\\d{3,}"
  106. plateN=regmatches(basename(my.files2[[1]]), regexpr(pattern2,basename(my.files2[[1]])))
  107. regmatches(basename(my.files2[[1]]), regexpr('\\d{5,}', basename(my.files2[[1]])))
  108. ExpDate=regmatches(basename(my.files2[[1]]), regexpr('\\d{5,}', basename(my.files2[[1]])))
  109. # creating and exporting data frames as csv
  110. for (i in 1:length(my.spike_data)) {
  111. new.df <- data.frame()
  112. new.df <- data.frame('Channel' = new.ch[[i]], 'Time' = new.times[[i]])
  113. #new.basename <- c()
  114. #new.basename <- strsplit(basename(my.files2[[i]]), split = '.csv')[[1]][1]
  115. if (WorF == 'p') {
  116. pattern3="baseline1|baseline2|AMPA|CNQX|NMDA|DAP5"
  117. DIV=regmatches(basename(my.files2[[i]]), regexpr(pattern3, basename(my.files2[[i]])))
  118. DIV=paste0('DIV',DIV)
  119. }
  120. pattern2="N\\d{3,}"
  121. plateN=regmatches(basename(my.files2[[i]]), regexpr(pattern2,basename(my.files2[[i]])))
  122. # CHECKTHIS THING!!!ExpDate="210226"
  123. #=regmatches(basename(my.files2[[i]]), regexpr('\\d{5,}', basename(my.files2[[i]])))
  124. export_name <- paste0(my.input2, '/',plateN, '_', ExpDate, '_', ExpName,'_', DIV, '_', 'spikes', '_', my.well_number, '.csv')
  125. #export_name <- paste0(my.input2, '/',new.basename, '_', my.well_number, '.csv')
  126. write.csv(new.df, file = export_name, row.names = FALSE, quote = FALSE)
  127. }