Created
June 24, 2021 20:44
-
-
Save sebastianwagner/702af3f96f266101f9763f003186dec5 to your computer and use it in GitHub Desktop.
tooling for Technical Analysis Equipment wellplate flourescence measurement xlsx sheet csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# run with: | |
# R --no-save --no-restore --file=time-resolved-fluorescence-well-measurements.R | |
# Hombrechtikon tooling for Technical Analysis Equipment | |
library(ggplot2) | |
filename <- 'measurement.csv' | |
offset <- 56 | |
stop <- FALSE | |
wellMarker <- "Cycles / Well" | |
endMarker <- "End Time:" | |
testPoints <- 9 | |
# scan file for headers and column count | |
data <- read.csv2( | |
filename, | |
skip = offset, | |
header = FALSE, | |
stringsAsFactors = FALSE | |
) | |
columnCount <- length(names(data)) | |
# find all marked wells | |
headers <- data[,1] | |
rm(data) | |
# read rows of wells and their names from all header lines | |
getWellRows <- function (headers) { | |
wellRows <- NULL | |
wellRowNames <- NULL | |
headersLength <- length(headers); | |
stop <- FALSE | |
for (headerRow in 1:headersLength) { | |
if (! stop) { | |
header <- headers[[headerRow]] | |
if (header == endMarker) { | |
stop <- TRUE | |
} else { | |
if (header == wellMarker) { | |
wellRows <- c(wellRows, headerRow) | |
} | |
} | |
} | |
} | |
return (wellRows) | |
} | |
getWellRowNames <- function (headers) { | |
wellRows <- NULL | |
wellRowNames <- NULL | |
headersLength <- length(headers); | |
stop <- FALSE | |
for (headerRow in 1:headersLength) { | |
if (! stop) { | |
header <- headers[[headerRow]] | |
if (header == endMarker) { | |
stop <- TRUE | |
} else { | |
if (header == wellMarker) { | |
wellRowNames <- c(wellRowNames, headers[[headerRow + 1]]) | |
} | |
} | |
} | |
} | |
return (wellRowNames) | |
} | |
wellRows <- getWellRows(headers) | |
wellRowNames <- getWellRowNames(headers) | |
# go through all wells | |
colClasses <- c("character", rep("numeric", columnCount - 1)) | |
wellsCount <- min(length(wellRows), length(wellRowNames)) | |
for (wellRowIndex in 1:wellsCount) { | |
wellRow <- wellRows[wellRowIndex] | |
wellRowName <- wellRowNames[wellRowIndex] | |
wellData <- read.csv2( | |
filename, | |
skip = offset + wellRow, | |
nrows = 4 + testPoints, | |
header = TRUE, | |
row.names = 1, | |
colClasses = colClasses, | |
stringsAsFactors = FALSE | |
) | |
rownames(wellData)[1] <- 'time' | |
wellDataT <- data.frame(t(wellData)) | |
# prepare for rbind distinction | |
wellDataT$well <- wellRowName | |
} | |
#debug last well | |
plot <- ggplot() + | |
geom_line(data = wellDataT, aes(x = time, y = StDev)) + | |
geom_line(data = wellDataT, aes(x = time, y = Mean)) | |
print(plot) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment