library(dplyr) ## spreadsheet manipulation
library(magrittr) ## piping
library(stringr) ## string manipulations
library(gitter)
## Run gitter.batch on all the directories
## with images. Creates directories for the
## output.
lapply(phenotyping.runs, fnRunGitterBatch)
path.to.images
phenotyping.runs
phenotyping.runs <- list.files('~/Dropbox/myResearch/eleonore-de-novo/data/robot-phenotyping/gitter-data-submission',
full.names = T)
phenotyping.runs <- list.files('~/Dropbox/myResearch/eleonore-de-novo/data/robot-phenotyping/gitter-data-submission',
full.names = T)
phenotyping.runs
phenotyping.runs <- phenotyping.runs[-5]
phenotyping.runs
## Run gitter.batch on all the directories
## with images. Creates directories for the
## output.
lapply(phenotyping.runs, fnRunGitterBatch)
pat.to.images <- phenotyping.runs
## Runs the gitter.batch function from gitter
## on images within the directory that you
## specify. Creates a directory for the output
setwd(path.to.images)
patg.to.images <- phenotyping.runs
path.to.images <- phenotyping.runs
## Runs the gitter.batch function from gitter
## on images within the directory that you
## specify. Creates a directory for the output
setwd(path.to.images)
current.dirs <- list.files(path = '../../gitter-data/')
current.dirs
## If a directory for the current file being run
## does not exist, then create a directory for it
## and run the gitter.batch function. I.e. if a
## directory exists then it skips those runs.
run <- gsub('.*/', '', path.to.images)
run
if(!run %in% current.dirs) {
dir.create(paste0('../../gitter-data/', run))
## Since gitter doesn't do very well at locating
## the colonies at the early time points. I am using
## the fact that you can add a reference image to
## help it locate colonies. For runs that have more
## than one time point, it will take the last
## time point and use that as the reference image.
## This needs you to have the image files ordered
## from first time point to last time point.
reference.image <- tail(list.files(path.to.images), 1)
path.to.reference.image <- paste(path.to.images, reference.image,
sep = '/')
gitter.batch(image.files = path.to.images,
ref.image.file = path.to.reference.image,
verbose = 'p',
grid.save = paste0(path.to.images, paste0('/../../gitter-data/', run)),
dat.save = paste0(path.to.images, paste0('/../../gitter-data/', run)),
plate.format = c(32, 48))
}
dir.create(paste0('../../gitter-data/', run))
paste0('../../gitter-data/', run)
current.dirs
run
dir.create(paste0('../../gitter-data/', run))
run
run <- run[1]
run
dir.create(paste0('../../gitter-data/', run))
dir.create(paste0('../../gitter-data/', run))
## Run gitter.batch on all the directories
## with images. Creates directories for the
## output.
lapply(phenotyping.runs, fnRunGitterBatch)
## Read in the plate layout
plate.layout <- read.table('plate-layout-1536.txt',
header = TRUE, stringsAsFactors = FALSE)
## Read in the plate layout
plate.layout <- read.table('~/Dropbox/myResearch/eleonore-de-novo/data/robot-phenotyping/gitter-data-submission/plate-layout-1536.txt',
header = TRUE, stringsAsFactors = FALSE)
## Directories with the .dat files for
## the phenotyping runs, lapply over these
## below
phenotyping.runs.dat <- list.files(
'~/Dropbox/myResearch/eleonore-de-novo/data/robot-phenotyping/gitter-data/', full.names = TRUE
)
## Read in the gitter.dat that you created
## using the fnRunGitterBatch above
phenotype.data <- lapply(phenotyping.runs.dat,
fnReadGitterData,
layout.plate = plate.layout)
phenotype.data
## Name the phenotype runs according to the names of
## the directories from which they came
names(phenotype.data) <- gsub('.*/', '', phenotyping.runs.dat)
phenotype.data$`glu-con-1`
phenotype.data$`glu-con-1`
str(phenotype.data$`glu-con-1`)
## Put the information about the strain in a more
## usable manner.
phenotype.data <- lapply(phenotype.data, FUN = function(x) lapply(x, fnLayoutCleanUp))
phenotype.data$`glu-con-1`
## Add the respective timepoints as a column
phenotype.data <- lapply(phenotype.data,
function(x) mapply(cbind, x,
'timepoint' = 1:length(x),
SIMPLIFY = F))
head(phenotype.data$`glu-con-1`[1])
head(phenotype.data$`glu-con-1`[[1]])
head(phenotype.data$`glu-con-1`[[2]])
phenotype.data.time.series <- lapply(phenotype.data, rbindlist)
head(phenotype.data.time.series)
## Extract timepoint 30
single.timepoint <- lapply(phenotype.data, FUN = function(x) x[[timepoint]])
timepoint <- 30
## Extract timepoint 30
single.timepoint <- lapply(phenotype.data, FUN = function(x) x[[timepoint]])
## Run summary on the single timepoint
## I'm going ahead without filtering the
## data for outliers, since there are none.
single.timepoint.summary <- lapply(single.timepoint, fnSingelTimepointSummary)
single.timepoint.summary <- lapply(single.timepoint.summary,
function(x) x[frame != 'Border'])
single.timepoint.summary <- Map(cbind, single.timepoint.summary, run = names(single.timepoint.summary))
####
## Using these curves for the figure
curve.data.mtx <- fnPlotGrowthCurve(strain.id = c('B_out_162702', 'B_in_162702'), run = 'glu-mtx-2')
library(ggplot2)
####
## Using these curves for the figure
curve.data.mtx <- fnPlotGrowthCurve(strain.id = c('B_out_162702', 'B_in_162702'), run = 'glu-mtx-2')
## In the plots, exchange my theme with your theme
## of choice
source(paste0('~/Dropbox/myResearch/general-scripts/',
'plotting/fnThemeOnestop.R')) ## My ggplot theme
####
## Using these curves for the figure
curve.data.mtx <- fnPlotGrowthCurve(strain.id = c('B_out_162702', 'B_in_162702'), run = 'glu-mtx-2')
curve.data.mtx
curve.data.dmso <- fnPlotGrowthCurve(strain.id = c('B_out_162702', 'B_in_162702'), run = 'glu-con-2')
curve.data.dmso
plot.mtx.curve  <- ggplot(curve.data.mtx$data, aes(timepoint, size, color = frame)) +
geom_point() + theme_oneStop() + scale_color_oneStop() +
theme(aspect.ratio = 1)
plot.mtx.curve
summary.concatenated <- lapply(environments, fnMergeConAndMtx,
data = single.timepoint.summary)
summary.concatenated <- do.call(rbind, single.timepoint.summary)
summary.concatenated
## Create a wide data frame with the in and out
## in different columns to be able to make scatter
## plots
summary.concatenated.scatter <- lapply(summary.concatenated,
fnScatterFormat)
## Create a wide data frame with the in and out
## in different columns to be able to make scatter
## plots
summary.concatenated.scatter <- fnScatterFormat(summary.concatenated)
summary.concatenated.scatter
## Plot for supplementary figure
plot.supp.scatter <- ggplot(summary.concatenated.scatter$glu,
aes(log2(median.y), log2(median.x), color = strain)) +
geom_point() +
geom_point(data = summary.concatenated.scatter$glu[strain == 'CTRL'], color = 'gray', size = 0.5) +
facet_wrap(~run) +
theme_oneStop() +
scale_color_manual(values = c(color.SpA, color.SpB, color.SpC, color.SpC)) +
geom_abline(slope = 1, intercept = 0, linetype = 'dashed') + theme(aspect.ratio = 1) +
labs(title = 'Colony size at 60h', x = 'out of frame', y = 'in frame') +
scale_x_continuous(limits = c(5, 11.5)) +
scale_y_continuous(limits = c(5, 11.5))
color.SpA <- 'green3'
color.SpB <- 'red2'
color.SpC <- 'blue4'
strains <- unique(phenotype.data.time.series[[1]]$id)
strains
strains <- strains[strains != 'Border'] ## Remove border colonies
strains <- strains[strains != '0'] ## Some border colonies' strain name = 0
strains
## Plot for supplementary figure
plot.supp.scatter <- ggplot(summary.concatenated.scatter$glu,
aes(log2(median.y), log2(median.x), color = strain)) +
geom_point() +
geom_point(data = summary.concatenated.scatter$glu[strain == 'CTRL'], color = 'gray', size = 0.5) +
facet_wrap(~run) +
theme_oneStop() +
scale_color_manual(values = c(color.SpA, color.SpB, color.SpC, color.SpC)) +
geom_abline(slope = 1, intercept = 0, linetype = 'dashed') + theme(aspect.ratio = 1) +
labs(title = 'Colony size at 60h', x = 'out of frame', y = 'in frame') +
scale_x_continuous(limits = c(5, 11.5)) +
scale_y_continuous(limits = c(5, 11.5))
summary.concatenated.scatter
## Plot for supplementary figure
plot.supp.scatter <- ggplot(summary.concatenated.scatter,
aes(log2(median.y), log2(median.x), color = strain)) +
geom_point() +
geom_point(data = summary.concatenated.scatter$glu[strain == 'CTRL'], color = 'gray', size = 0.5) +
facet_wrap(~run) +
theme_oneStop() +
scale_color_manual(values = c(color.SpA, color.SpB, color.SpC, color.SpC)) +
geom_abline(slope = 1, intercept = 0, linetype = 'dashed') + theme(aspect.ratio = 1) +
labs(title = 'Colony size at 60h', x = 'out of frame', y = 'in frame') +
scale_x_continuous(limits = c(5, 11.5)) +
scale_y_continuous(limits = c(5, 11.5))
summary.concatenated.scatter
## Plot for main figure
main.scatter <- summary.concatenated.scatter[run == 'glu-mtx-2']
## Create a wide data frame with the in and out
## in different columns to be able to make scatter
## plots
summary.concatenated.scatter <- fnScatterFormat(summary.concatenated)
## Plot for supplementary figure
plot.supp.scatter <- ggplot(summary.concatenated.scatter,
aes(log2(median.y), log2(median.x), color = strain)) +
geom_point() +
geom_point(data = summary.concatenated.scatter$glu[strain == 'CTRL'], color = 'gray', size = 0.5) +
facet_wrap(~run) +
theme_oneStop() +
scale_color_manual(values = c(color.SpA, color.SpB, color.SpC, color.SpC)) +
geom_abline(slope = 1, intercept = 0, linetype = 'dashed') + theme(aspect.ratio = 1) +
labs(title = 'Colony size at 60h', x = 'out of frame', y = 'in frame') +
scale_x_continuous(limits = c(5, 11.5)) +
scale_y_continuous(limits = c(5, 11.5))
## Plot for supplementary figure
plot.supp.scatter <- ggplot(summary.concatenated.scatter,
aes(log2(median.y), log2(median.x), color = strain)) +
geom_point() +
geom_point(data = summary.concatenated.scatter$glu[strain == 'CTRL'], color = 'gray', size = 0.5) +
facet_wrap(~run) +
theme_oneStop() +
scale_color_manual(values = c(color.SpA, color.SpB, color.SpC, color.SpC)) +
geom_abline(slope = 1, intercept = 0, linetype = 'dashed') + theme(aspect.ratio = 1) +
labs(title = 'Colony size at 60h', x = 'out of frame', y = 'in frame') +
scale_x_continuous(limits = c(5, 11.5)) +
scale_y_continuous(limits = c(5, 11.5))
plot.supp.scatter
summary.concatenated.scatter
## Plot for main figure
main.scatter <- summary.concatenated.scatter[run == 'glu-mtx-2']
plot.main.scatter <- ggplot(main.scatter,
aes(log2(median.y), log2(median.x), color = strain)) +
geom_point() +
geom_point(data = main.scatter[strain == 'CTRL'], color = 'gray', size = 0.5) +
theme_oneStop() +
scale_color_manual(values = c(color.SpA, color.SpB, color.SpC, color.SpC)) +
geom_abline(slope = 1, intercept = 0, linetype = 'dashed') + theme(aspect.ratio = 1) +
labs(title = 'Colony size at 60h', x = 'out of frame', y = 'in frame') +
scale_x_continuous(limits = c(5, 11.5)) +
scale_y_continuous(limits = c(5, 11.5))
plot.main.scatter
main.scatter
head(main.scatter)
## Plot for supplementary figure
plot.supp.scatter <- ggplot(summary.concatenated.scatter,
aes(log2(median.y), log2(median.x), color = strain)) +
geom_point() +
geom_point(data = summary.concatenated.scatter$glu[strain == 'CTRL'], color = 'gray', size = 0.5) +
facet_wrap(~run) +
theme_oneStop() +
scale_color_manual(values = c(color.SpA, color.SpB, color.SpC, color.SpC)) +
geom_abline(slope = 1, intercept = 0, linetype = 'dashed') + theme(aspect.ratio = 1) +
labs(title = 'Colony size at 60h', x = 'out of frame', y = 'in frame') +
scale_x_continuous(limits = c(5, 11.5)) +
scale_y_continuous(limits = c(5, 11.5))
## Plot for supplementary figure
plot.supp.scatter <- ggplot(summary.concatenated.scatter, aes(log2(median.y), log2(median.x), color = strain)) +
geom_point() +
geom_point(data = summary.concatenated.scatter$glu[strain == 'CTRL'], color = 'gray', size = 0.5) +
facet_wrap(~run) +
theme_oneStop() +
scale_color_manual(values = c(color.SpA, color.SpB, color.SpC, color.SpC)) +
geom_abline(slope = 1, intercept = 0, linetype = 'dashed') + theme(aspect.ratio = 1) +
labs(title = 'Colony size at 60h', x = 'out of frame', y = 'in frame') +
scale_x_continuous(limits = c(5, 11.5)) +
scale_y_continuous(limits = c(5, 11.5))
as.data.frame(summary.concatenated.scatter)
testas.data.frame(summary.concatenated.scatter)
test <- as.data.frame(summary.concatenated.scatter)
## Plot for supplementary figure
plot.supp.scatter <- ggplot(test, aes(log2(median.y), log2(median.x), color = strain)) +
geom_point() +
geom_point(data = test$glu[strain == 'CTRL'], color = 'gray', size = 0.5) +
facet_wrap(~run) +
theme_oneStop() +
scale_color_manual(values = c(color.SpA, color.SpB, color.SpC, color.SpC)) +
geom_abline(slope = 1, intercept = 0, linetype = 'dashed') + theme(aspect.ratio = 1) +
labs(title = 'Colony size at 60h', x = 'out of frame', y = 'in frame') +
scale_x_continuous(limits = c(5, 11.5)) +
scale_y_continuous(limits = c(5, 11.5))
summary.concatenated.scatter
names(summary.concatenated.scatter)
## Plot for supplementary figure
plot.supp.scatter <- ggplot(summary.concatenated.scatter, aes(log2(median.y), log2(median.x), color = strain)) +
geom_point() +
geom_point(data = summary.concatenated.scatter[strain == 'CTRL'], color = 'gray', size = 0.5) +
facet_wrap(~run) +
theme_oneStop() +
scale_color_manual(values = c(color.SpA, color.SpB, color.SpC, color.SpC)) +
geom_abline(slope = 1, intercept = 0, linetype = 'dashed') + theme(aspect.ratio = 1) +
labs(title = 'Colony size at 60h', x = 'out of frame', y = 'in frame') +
scale_x_continuous(limits = c(5, 11.5)) +
scale_y_continuous(limits = c(5, 11.5))
plot.supp.scatter
####
## 181129 | This data is what is accompanying the submission
## of the paper as supplementary table 6. It contains data
## for the second run of both the mtx and dmso condition
raw.data.submission <- Map(cbind, single.timepoint,
run = names(single.timepoint))
raw.data.submission.181129 <- rbind(raw.data.eleonore$`glu-con-2`,
raw.data.eleonore$`glu-mtx-2`)
raw.data.submission.181129
raw.data.submission
raw.data.submission.181129 <- rbind(raw.data.submission$`glu-con-2`,
raw.data.submission$`glu-mtx-2`)
head(raw.data.submission.181129)
rm(list = ls())
timepoint <- 30
color.SpA <- 'green3'
color.SpB <- 'red2'
color.SpC <- 'blue4'
setwd('~/Dropbox/myResearch/eleonore-de-novo/data/robot-phenotyping/DHFR-expression-analysis/')
path.to.images = '.'
## Runs the gitter.batch function from gitter
## on images within the directory that you
## specify. Creates a directory for the output
setwd(path.to.images)
getwd()
current.dirs <- list.files(path = 'gitter-data/')
current.dirs
## If a directory for the current file being run
## does not exist, then create a directory for it
## and run the gitter.batch function. I.e. if a
## directory exists then it skips those runs.
## The gitter-data directory has to exist though!
run <- gsub('.*/', '', path.to.images)
run
dir.create(paste0('../../gitter-data/', run))
dir.create(paste0('gitter-data/', run))
dir.create(paste0('/gitter-data/', run))
path.to.images
current.dirs <- list.files(path = 'gitter-data/')
current.dirs
path.to.images
path.to.images <- '~/Dropbox/myResearch/eleonore-de-novo/data/robot-phenotyping/DHFR-expression-analysis/')
path.to.images <- '~/Dropbox/myResearch/eleonore-de-novo/data/robot-phenotyping/DHFR-expression-analysis/'
current.dirs <- list.files(path = '../../gitter-data/')
current.dirs
## If a directory for the current file being run
## does not exist, then create a directory for it
## and run the gitter.batch function. I.e. if a
## directory exists then it skips those runs.
## The gitter-data directory has to exist though!
run <- gsub('.*/', '', path.to.images)
run
current.dirs <- list.files(path = 'gitter-data/')
current.dirs
## If a directory for the current file being run
## does not exist, then create a directory for it
## and run the gitter.batch function. I.e. if a
## directory exists then it skips those runs.
## The gitter-data directory has to exist though!
run <- gsub('.*/', '', path.to.images)
run
path.to.images
path.to.images <- '~/Dropbox/myResearch/eleonore-de-novo/data/robot-phenotyping/DHFR-expression-analysis'
## If a directory for the current file being run
## does not exist, then create a directory for it
## and run the gitter.batch function. I.e. if a
## directory exists then it skips those runs.
## The gitter-data directory has to exist though!
run <- gsub('.*/', '', path.to.images)
run
## Runs the gitter.batch function from gitter
## on images within the directory that you
## specify. Creates a directory for the output
setwd(path.to.images)
path.to.images
run <- gsub('.*/', '', path.to.images)
run
path.to.images
path.to.images <- '~/Dropbox/myResearch/eleonore-de-novo/data/robot-phenotyping/DHFR-expression-analysis/'
dir.create(paste0('../../gitter-data/', run))
run <- gsub('.*/', '', path.to.images)
run
path.to.images
## Directories wit the images on which I will run the
## gitter.batch analysis
phenotyping.runs <- list.files('~/Dropbox/myResearch/eleonore-de-novo/data/robot-phenotyping/DHFR-expression-analysis/',
full.names = TRUE)
phenotyping.runs
## Directories wit the images on which I will run the
## gitter.batch analysis
phenotyping.runs <- list.files('~/Dropbox/myResearch/eleonore-de-novo/data/robot-phenotyping/DHFR-expression-analysis/',
pattern = 'glu', full.names = TRUE)
phenotyping.runs
path.to.images <- phenotyping.runs[1]
## Runs the gitter.batch function from gitter
## on images within the directory that you
## specify. Creates a directory for the output
setwd(path.to.images)
getwd()
run <- gsub('.*/', '', path.to.images)
run
dir.create(paste0('../gitter-data/', run))
## Run gitter.batch on all the directories
## with images. Creates directories for the
## output.
lapply(phenotyping.runs, fnRunGitterBatch)
fnRunGitterBatch <- function(path.to.images) {
## Runs the gitter.batch function from gitter
## on images within the directory that you
## specify. Creates a directory for the output
setwd(path.to.images)
run <- gsub('.*/', '', path.to.images)
dir.create(paste0('../gitter-data/', run))
## Since gitter doesn't do very well at locating
## the colonies at the early time points. I am using
## the fact that you can add a reference image to
## help it locate colonies. For runs that have more
## than one time point, it will take the last
## time point and use that as the reference image.
## This requires you to have the image files ordered
## from first time point to last time point.
reference.image <- tail(list.files(path.to.images), 1)
path.to.reference.image <- paste(path.to.images, reference.image,
sep = '/')
gitter.batch(image.files = path.to.images,
ref.image.file = path.to.reference.image,
verbose = 'p',
grid.save = paste0(path.to.images, paste0('/../gitter-data/', run)),
dat.save = paste0(path.to.images, paste0('/../gitter-data/', run)),
plate.format = c(32, 48))
}
fnReadGitterData <- function(path.to.gitter.data, layout.plate) {
## This function takes the path to the folder with
## the gitter data and reads in all the .dat files
## within that directory. Each directory should
## contain the dat from the images of one plate
gitter.data.files <- list.files(path = path.to.gitter.data,
pattern = '.dat', full.names = TRUE)
gitter.data <- lapply(gitter.data.files, read.table, sep ='\t',
col.names = c('row', 'col', 'size',
'circularity', 'flags'))
## Put the plate layout in here as well, merge on
## col and row
gitter.data.layout <- lapply(gitter.data,
function(x) merge(x, layout.plate)
)
stopifnot(length(gitter.data) > 1)
return(gitter.data.layout)
}
## Run gitter.batch on all the directories
## with images. Creates directories for the
## output.
lapply(phenotyping.runs, fnRunGitterBatch)
getwd()
setwd('~/Dropbox/myResearch/eleonore-de-novo/data/robot-phenotyping/DHFR-expression-analysis/'
)
## Directories wit the images on which I will run the
## gitter.batch analysis
phenotyping.runs <- list.files('.',
pattern = 'glu', full.names = TRUE)
phenotyping.runs
list.files()
fnReadGitterData <- function(path.to.gitter.data, layout.plate) {
## This function takes the path to the folder with
## the gitter data and reads in all the .dat files
## within that directory. Each directory should
## contain the dat from the images of one plate
gitter.data.files <- list.files(path = path.to.gitter.data,
pattern = '.dat', full.names = TRUE)
gitter.data <- lapply(gitter.data.files, read.table, sep ='\t',
col.names = c('row', 'col', 'size',
'circularity', 'flags'))
## Put the plate layout in here as well, merge on
## col and row
gitter.data.layout <- lapply(gitter.data,
function(x) merge(x, layout.plate)
)
stopifnot(length(gitter.data) > 1)
return(gitter.data.layout)
}
## Directories with the .dat files for
## the phenotyping runs, lapply over these
## below
phenotyping.runs.dat <- list.files(
'gitter-data/', full.names = TRUE
)
phenotyping.runs.dat
## Directories with the .dat files for
## the phenotyping runs, lapply over these
## below
phenotyping.runs.dat <- list.files(
'gitter-data', full.names = TRUE
)
phenotyping.runs.dat
## Read in the gitter.dat that you created
## using the fnRunGitterBatch above
phenotype.data <- lapply(phenotyping.runs.dat,
fnReadGitterData,
layout.plate = plate.layout)
## Read in the plate layout
plate.layout <- read.table('plate-layout-1536.txt',
header = TRUE, stringsAsFactors = FALSE)
## Read in the gitter.dat that you created
## using the fnRunGitterBatch above
phenotype.data <- lapply(phenotyping.runs.dat,
fnReadGitterData,
layout.plate = plate.layout)
phenotype.data
phenotyping.runs.dat
