https://www.cell.com/trends/neurosciences/fulltext/S0166-2236(12)00087-2

https://www.cell.com/trends/neurosciences/fulltext/S0166-2236(12)00087-2

https://webvision.med.utah.edu/wp-content/uploads/2018/05/DONfig1.jpg - DARK and LIGHT data are obtained separately for each mice

Open excel workbook containing several sheets

library(readxl)
library(purrr)
## Warning: package 'purrr' was built under R version 3.4.4
read_excel_allsheets <- function(ERG_file) {
  sheets <- readxl::excel_sheets(ERG_file)
  Open_sheets <- map(sheets, function(X) readxl::read_excel(ERG_file, sheet = X,skip = 1))
  names(Open_sheets) <- sheets
  return(Open_sheets)
}

Call “read_excel_allsheets” function

ERG_1M <- read_excel_allsheets("~/Desktop/Reanalysis of ERG/BC5/ERG 1M/ERG 1 mo SA43-159_164.xlsx")
str(ERG_1M, max.level = 1)
## List of 12
##  $ SA43 159 DARK :Classes 'tbl_df', 'tbl' and 'data.frame':  25 obs. of  16 variables:
##  $ SA43 159 LIGHT:Classes 'tbl_df', 'tbl' and 'data.frame':  25 obs. of  16 variables:
##  $ SA43 160 DARK :Classes 'tbl_df', 'tbl' and 'data.frame':  25 obs. of  16 variables:
##  $ SA43 160 LIGHT:Classes 'tbl_df', 'tbl' and 'data.frame':  25 obs. of  16 variables:
##  $ SA43 161 DARK :Classes 'tbl_df', 'tbl' and 'data.frame':  25 obs. of  16 variables:
##  $ SA43 161 LIGHT:Classes 'tbl_df', 'tbl' and 'data.frame':  25 obs. of  16 variables:
##  $ SA43 162 DARK :Classes 'tbl_df', 'tbl' and 'data.frame':  25 obs. of  16 variables:
##  $ SA43 162 LIGHT:Classes 'tbl_df', 'tbl' and 'data.frame':  25 obs. of  16 variables:
##  $ SA43 163 DARK :Classes 'tbl_df', 'tbl' and 'data.frame':  25 obs. of  16 variables:
##  $ SA43 163 LIGHT:Classes 'tbl_df', 'tbl' and 'data.frame':  25 obs. of  16 variables:
##  $ SA43 164 DARK :Classes 'tbl_df', 'tbl' and 'data.frame':  25 obs. of  16 variables:
##  $ SA43 164 LIGHT:Classes 'tbl_df', 'tbl' and 'data.frame':  25 obs. of  16 variables:
ERG_1M$`SA43 159 DARK`

Select Scotopic (DARG) ERG data

DARK_ERG_1M <- ERG_1M[grep("DARK",names(ERG_1M))]
str(DARK_ERG_1M, max.level = 1)
## List of 6
##  $ SA43 159 DARK:Classes 'tbl_df', 'tbl' and 'data.frame':   25 obs. of  16 variables:
##  $ SA43 160 DARK:Classes 'tbl_df', 'tbl' and 'data.frame':   25 obs. of  16 variables:
##  $ SA43 161 DARK:Classes 'tbl_df', 'tbl' and 'data.frame':   25 obs. of  16 variables:
##  $ SA43 162 DARK:Classes 'tbl_df', 'tbl' and 'data.frame':   25 obs. of  16 variables:
##  $ SA43 163 DARK:Classes 'tbl_df', 'tbl' and 'data.frame':   25 obs. of  16 variables:
##  $ SA43 164 DARK:Classes 'tbl_df', 'tbl' and 'data.frame':   25 obs. of  16 variables:

Format the elements of the list

library(dplyr)
## Warning: package 'dplyr' was built under R version 3.4.4
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(tidyverse)
## ── Attaching packages ────────────────────────────────────────── tidyverse 1.2.1 ──
## ✔ ggplot2 3.0.0     ✔ readr   1.1.1
## ✔ tibble  1.4.2     ✔ stringr 1.3.1
## ✔ tidyr   0.8.1     ✔ forcats 0.3.0
## Warning: package 'ggplot2' was built under R version 3.4.4
## Warning: package 'tidyr' was built under R version 3.4.4
## Warning: package 'stringr' was built under R version 3.4.4
## ── Conflicts ───────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
Format_ERG_Table <- function(ERG_list){
  smalltibble <- ERG_list %>% 
    slice(2:25) %>% 
    rename('wave'='Name__1') %>% 
    mutate(uV = if_else(wave == 'a', -uV, uV)) %>%  # Only mutate uV if wave = a
    select(2,6,9,10,11)
    
}

Call the function “Format_ERG_Table”

DARK_ERG_1M <- map(DARK_ERG_1M,Format_ERG_Table)
## Warning: package 'bindrcpp' was built under R version 3.4.4
DARK_ERG_1M$`SA43 159 DARK`

Associate S with the corresponding intensity

Mutate_S <- function(DARK_ERG){
DARK_Intensity <- DARK_ERG %>% mutate('Intensity' = case_when (S == 2 ~ -4,
          S == 3 ~ -3,
          S == 4 ~ -2,
          S == 5 ~ -1,
          S == 6 ~ 0,
          S == 7 ~ 1))
}

Call “Mutate_S” the function

DARK_ERG_1M <- map(DARK_ERG_1M,Mutate_S)
str(DARK_ERG_1M, max.level = 2)
## List of 6
##  $ SA43 159 DARK:Classes 'tbl_df', 'tbl' and 'data.frame':   24 obs. of  6 variables:
##   ..$ Name     : chr [1:24] "159 SA44 159" "159 SA44 159" "159 SA44 159" "159 SA44 159" ...
##   ..$ S        : num [1:24] 2 3 4 5 6 7 2 3 4 5 ...
##   ..$ Eye      : chr [1:24] "OS" "OS" "OS" "OS" ...
##   ..$ wave     : chr [1:24] "a" "a" "a" "a" ...
##   ..$ uV       : num [1:24] -19.3 4.74 1.23 116.8 388.4 ...
##   ..$ Intensity: num [1:24] -4 -3 -2 -1 0 1 -4 -3 -2 -1 ...
##  $ SA43 160 DARK:Classes 'tbl_df', 'tbl' and 'data.frame':   24 obs. of  6 variables:
##   ..$ Name     : chr [1:24] "160 SA44 160" "160 SA44 160" "160 SA44 160" "160 SA44 160" ...
##   ..$ S        : num [1:24] 2 3 4 5 6 7 2 3 4 5 ...
##   ..$ Eye      : chr [1:24] "OS" "OS" "OS" "OS" ...
##   ..$ wave     : chr [1:24] "a" "a" "a" "a" ...
##   ..$ uV       : num [1:24] 11.1 11.2 20.1 90.3 307.5 ...
##   ..$ Intensity: num [1:24] -4 -3 -2 -1 0 1 -4 -3 -2 -1 ...
##  $ SA43 161 DARK:Classes 'tbl_df', 'tbl' and 'data.frame':   24 obs. of  6 variables:
##   ..$ Name     : chr [1:24] "161 SA43 161" "161 SA43 161" "161 SA43 161" "161 SA43 161" ...
##   ..$ S        : num [1:24] 2 3 4 5 6 7 2 3 4 5 ...
##   ..$ Eye      : chr [1:24] "OS" "OS" "OS" "OS" ...
##   ..$ wave     : chr [1:24] "a" "a" "a" "a" ...
##   ..$ uV       : num [1:24] 4.55 3.21 13.73 72.21 232 ...
##   ..$ Intensity: num [1:24] -4 -3 -2 -1 0 1 -4 -3 -2 -1 ...
##  $ SA43 162 DARK:Classes 'tbl_df', 'tbl' and 'data.frame':   24 obs. of  6 variables:
##   ..$ Name     : chr [1:24] "162 SA44 162" "162 SA44 162" "162 SA44 162" "162 SA44 162" ...
##   ..$ S        : num [1:24] 2 3 4 5 6 7 2 3 4 5 ...
##   ..$ Eye      : chr [1:24] "OS" "OS" "OS" "OS" ...
##   ..$ wave     : chr [1:24] "a" "a" "a" "a" ...
##   ..$ uV       : num [1:24] -5.889 38.5 -0.215 109.6 360.7 ...
##   ..$ Intensity: num [1:24] -4 -3 -2 -1 0 1 -4 -3 -2 -1 ...
##  $ SA43 163 DARK:Classes 'tbl_df', 'tbl' and 'data.frame':   24 obs. of  6 variables:
##   ..$ Name     : chr [1:24] "163 SA44 163" "163 SA44 163" "163 SA44 163" "163 SA44 163" ...
##   ..$ S        : num [1:24] 2 3 4 5 6 7 2 3 4 5 ...
##   ..$ Eye      : chr [1:24] "OS" "OS" "OS" "OS" ...
##   ..$ wave     : chr [1:24] "a" "a" "a" "a" ...
##   ..$ uV       : num [1:24] -5.29 15.47 12.85 110.4 426.2 ...
##   ..$ Intensity: num [1:24] -4 -3 -2 -1 0 1 -4 -3 -2 -1 ...
##  $ SA43 164 DARK:Classes 'tbl_df', 'tbl' and 'data.frame':   24 obs. of  6 variables:
##   ..$ Name     : chr [1:24] "164 SA44 164" "164 SA44 164" "164 SA44 164" "164 SA44 164" ...
##   ..$ S        : num [1:24] 2 3 4 5 6 7 2 3 4 5 ...
##   ..$ Eye      : chr [1:24] "OS" "OS" "OS" "OS" ...
##   ..$ wave     : chr [1:24] "a" "a" "a" "a" ...
##   ..$ uV       : num [1:24] -15.9 -12.1 26.6 112.2 375.4 ...
##   ..$ Intensity: num [1:24] -4 -3 -2 -1 0 1 -4 -3 -2 -1 ...

Identify each element of the list with its genotype

# Create a new list for each genotype
HET_DARK_ERG_1M <- DARK_ERG_1M[grep("160|163|164",names(DARK_ERG_1M))]

# Create a function to add a column with the Genotype identification for each element
HET_genotype <- function(HET_ERG_list){
  New_Genotype_column <- HET_ERG_list %>% cbind(Genotype='HET')
}
# Call the function
HET_DARK_ERG_1M <- map(HET_DARK_ERG_1M,HET_genotype)
str(HET_DARK_ERG_1M, max.level = 2)
## List of 3
##  $ SA43 160 DARK:'data.frame':   24 obs. of  7 variables:
##   ..$ Name     : chr [1:24] "160 SA44 160" "160 SA44 160" "160 SA44 160" "160 SA44 160" ...
##   ..$ S        : num [1:24] 2 3 4 5 6 7 2 3 4 5 ...
##   ..$ Eye      : chr [1:24] "OS" "OS" "OS" "OS" ...
##   ..$ wave     : chr [1:24] "a" "a" "a" "a" ...
##   ..$ uV       : num [1:24] 11.1 11.2 20.1 90.3 307.5 ...
##   ..$ Intensity: num [1:24] -4 -3 -2 -1 0 1 -4 -3 -2 -1 ...
##   ..$ Genotype : Factor w/ 1 level "HET": 1 1 1 1 1 1 1 1 1 1 ...
##  $ SA43 163 DARK:'data.frame':   24 obs. of  7 variables:
##   ..$ Name     : chr [1:24] "163 SA44 163" "163 SA44 163" "163 SA44 163" "163 SA44 163" ...
##   ..$ S        : num [1:24] 2 3 4 5 6 7 2 3 4 5 ...
##   ..$ Eye      : chr [1:24] "OS" "OS" "OS" "OS" ...
##   ..$ wave     : chr [1:24] "a" "a" "a" "a" ...
##   ..$ uV       : num [1:24] -5.29 15.47 12.85 110.4 426.2 ...
##   ..$ Intensity: num [1:24] -4 -3 -2 -1 0 1 -4 -3 -2 -1 ...
##   ..$ Genotype : Factor w/ 1 level "HET": 1 1 1 1 1 1 1 1 1 1 ...
##  $ SA43 164 DARK:'data.frame':   24 obs. of  7 variables:
##   ..$ Name     : chr [1:24] "164 SA44 164" "164 SA44 164" "164 SA44 164" "164 SA44 164" ...
##   ..$ S        : num [1:24] 2 3 4 5 6 7 2 3 4 5 ...
##   ..$ Eye      : chr [1:24] "OS" "OS" "OS" "OS" ...
##   ..$ wave     : chr [1:24] "a" "a" "a" "a" ...
##   ..$ uV       : num [1:24] -15.9 -12.1 26.6 112.2 375.4 ...
##   ..$ Intensity: num [1:24] -4 -3 -2 -1 0 1 -4 -3 -2 -1 ...
##   ..$ Genotype : Factor w/ 1 level "HET": 1 1 1 1 1 1 1 1 1 1 ...

Add a column for KO genotype

KO_DARK_ERG_1M <- DARK_ERG_1M[grep("159|161|162",names(DARK_ERG_1M))]
KO_genotype <- function(KO_ERG_list){
  New_Genotype_column <- KO_ERG_list %>% cbind(Genotype='KO')
}
KO_DARK_ERG_1M <- map(KO_DARK_ERG_1M,KO_genotype)
str(KO_DARK_ERG_1M, max.level = 2)
## List of 3
##  $ SA43 159 DARK:'data.frame':   24 obs. of  7 variables:
##   ..$ Name     : chr [1:24] "159 SA44 159" "159 SA44 159" "159 SA44 159" "159 SA44 159" ...
##   ..$ S        : num [1:24] 2 3 4 5 6 7 2 3 4 5 ...
##   ..$ Eye      : chr [1:24] "OS" "OS" "OS" "OS" ...
##   ..$ wave     : chr [1:24] "a" "a" "a" "a" ...
##   ..$ uV       : num [1:24] -19.3 4.74 1.23 116.8 388.4 ...
##   ..$ Intensity: num [1:24] -4 -3 -2 -1 0 1 -4 -3 -2 -1 ...
##   ..$ Genotype : Factor w/ 1 level "KO": 1 1 1 1 1 1 1 1 1 1 ...
##  $ SA43 161 DARK:'data.frame':   24 obs. of  7 variables:
##   ..$ Name     : chr [1:24] "161 SA43 161" "161 SA43 161" "161 SA43 161" "161 SA43 161" ...
##   ..$ S        : num [1:24] 2 3 4 5 6 7 2 3 4 5 ...
##   ..$ Eye      : chr [1:24] "OS" "OS" "OS" "OS" ...
##   ..$ wave     : chr [1:24] "a" "a" "a" "a" ...
##   ..$ uV       : num [1:24] 4.55 3.21 13.73 72.21 232 ...
##   ..$ Intensity: num [1:24] -4 -3 -2 -1 0 1 -4 -3 -2 -1 ...
##   ..$ Genotype : Factor w/ 1 level "KO": 1 1 1 1 1 1 1 1 1 1 ...
##  $ SA43 162 DARK:'data.frame':   24 obs. of  7 variables:
##   ..$ Name     : chr [1:24] "162 SA44 162" "162 SA44 162" "162 SA44 162" "162 SA44 162" ...
##   ..$ S        : num [1:24] 2 3 4 5 6 7 2 3 4 5 ...
##   ..$ Eye      : chr [1:24] "OS" "OS" "OS" "OS" ...
##   ..$ wave     : chr [1:24] "a" "a" "a" "a" ...
##   ..$ uV       : num [1:24] -5.889 38.5 -0.215 109.6 360.7 ...
##   ..$ Intensity: num [1:24] -4 -3 -2 -1 0 1 -4 -3 -2 -1 ...
##   ..$ Genotype : Factor w/ 1 level "KO": 1 1 1 1 1 1 1 1 1 1 ...

Create a single dataframe containing all elements

Final_ERG_1M <- HET_DARK_ERG_1M %>% bind_rows(KO_DARK_ERG_1M)
## Warning in bind_rows_(x, .id): Unequal factor levels: coercing to character
## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector
Final_ERG_1M

Plot ERG graph for each mice

Final_ERG_1M  %>% 
  ggplot(aes(x=Intensity, y=uV, group=Eye, color=Eye)) + 
    geom_point() + geom_line() + labs(x='Intensity (log cd.s/m2)',y='Amplitude (uV)') +
    facet_wrap(~Name+wave, scales = "free_y")

Determine if there is a significant between a and b wave between heterozyguous and knockout mice

Final_ERG_1M  %>%  group_by(Genotype,wave)%>% 
   summarize(Mean_uV = mean(uV, na.rm=T), SEM_uV = sd(uV, na.rm=T)/sqrt(sum(!is.na(uV))))

t test for a wave

t.test(uV ~ Genotype, data=Final_ERG_1M, subset = wave== 'a')
## 
##  Welch Two Sample t-test
## 
## data:  uV by Genotype
## t = 0.53691, df = 68.357, p-value = 0.5931
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -71.75209 124.58398
## sample estimates:
## mean in group HET  mean in group KO 
##          178.2543          151.8384

t.test for b wave

t.test(uV ~ Genotype, data=Final_ERG_1M, subset = wave== 'b')
## 
##  Welch Two Sample t-test
## 
## data:  uV by Genotype
## t = 1.2442, df = 68.734, p-value = 0.2176
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -64.56811 278.56644
## sample estimates:
## mean in group HET  mean in group KO 
##          578.0617          471.0625