Skip to content

Commit abd3dba

Browse files
committed
readInfiniteXML2 function that also works for kinetic measurements
1 parent 28cb261 commit abd3dba

File tree

5 files changed

+99
-2
lines changed

5 files changed

+99
-2
lines changed

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ Depends:
1616
jpeg,
1717
rmarkdown,
1818
knitr,
19-
TSP
19+
TSP,
20+
lubridate
2021
Import:
2122
License: file LICENCE
2223
URL: https://github.com/dcangst/rrobot

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export(plotColonies)
3636
export(rc_to_well)
3737
export(readColonies)
3838
export(readInfiniteXML)
39+
export(readInfiniteXML2)
3940
export(read_gwl)
4041
export(read_gwl_df)
4142
export(read_storex)

R/iControlFunctions.R

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,79 @@ readInfiniteXML <- function(file){
7171

7272
return(list(data = as_tibble(data), parameter = parameter))
7373
}
74+
75+
76+
#' read XML from Tecan Infinity Reader
77+
#'
78+
#' reads iControl XML file and returns a tibble
79+
#'
80+
#' @param file path to XML file
81+
#' @section Output:
82+
#' \code{list} with data in longform format and parameters
83+
#' @export
84+
readInfiniteXML2 <- function(file) {
85+
dataXML <- XML::xmlToList(XML::xmlParse(file))
86+
87+
measurements <- lapply(dataXML[which(names(dataXML) == "Section")], function(section) {
88+
attributesSection <- t(as.data.frame(section$.attrs)) %>%
89+
as_tibble()
90+
data <- lapply(
91+
section[which(names(section) == "Data")],
92+
function(data) {
93+
dataAttributes <- t(as.data.frame(data$.attrs)) %>%
94+
as_tibble()
95+
measurements <- lapply(
96+
data[which(names(data) == "Well")],
97+
function(well) {
98+
unlist(well)
99+
}) %>%
100+
bind_rows() %>%
101+
bind_cols(dataAttributes)
102+
if ("Time_Start" %in% names(measurements)) {
103+
measurements <- measurements %>%
104+
rename(Time_Start_Inc = Time_Start)
105+
}
106+
return(measurements)
107+
}) %>%
108+
bind_rows() %>%
109+
bind_cols(attributesSection)
110+
})
111+
dataDf <- measurements$Section
112+
113+
# format data
114+
rows <- str_sub(dataDf$.attrs.Pos, 1, 1)
115+
rows_n <- as.integer(sapply(rows, function(x){
116+
which(x == LETTERS)
117+
}))
118+
cols <- as.integer(str_sub(dataDf$.attrs.Pos, 2))
119+
wells <- (rows_n - 1) * max(cols) + cols
120+
121+
if ("Time_Start_Inc" %in% names(dataDf)) {
122+
data <- dataDf %>%
123+
transmute(
124+
plate = dataXML$Plate$ID,
125+
cycle = as.integer(Cycle),
126+
tStart = lubridate::as_datetime(Time_Start) + lubridate::as.duration(Time_Start_Inc),
127+
name = Name,
128+
pos = .attrs.Pos,
129+
row = rows,
130+
col = cols,
131+
well = wells,
132+
value = as.numeric(Single.text)
133+
)
134+
} else {
135+
data <- dataDf %>%
136+
transmute(
137+
plate = dataXML$Plate$ID,
138+
cycle = as.integer(Cycle),
139+
tStart = lubridate::as_datetime(Time_Start),
140+
name = Name,
141+
pos = .attrs.Pos,
142+
row = rows,
143+
col = cols,
144+
well = wells,
145+
value = as.numeric(Single.text)
146+
)
147+
}
148+
return(data)
149+
}

man/readInfiniteXML.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/readInfiniteXML2.Rd

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)