Unverified Commit 1c933ec1 authored by Maximilian von der Linde's avatar Maximilian von der Linde Committed by GitHub
Browse files

Add files via upload

parent 74fda16d
This diff is collapsed.
################## Some functions to import XML DTS data ################## Some functions to import XML DTS data
require("XML") require("XML")
####################### Functions for importing data ########################## ####################### Functions for importing data ##########################
## Importing DTS data from an XML file ## Importing DTS data from an XML file
flyDataImport <- function(xml_name) { flyDataImport <- function(xml_name) {
## Import the data from the .xml file. ## Import the data from the .xml file.
flyData <- xmlParse(xml_name) flyData <- xmlParse(xml_name)
flyDataXMLtop = xmlRoot(flyData) flyDataXMLtop = xmlRoot(flyData)
#parse the metadata #parse the metadata
URIs <- xmlToDataFrame(nodes=getNodeSet(flyData,"//metadata/URIs")) URIs <- xmlToDataFrame(nodes=getNodeSet(flyData,"//metadata/URIs"))
experimenter <- xmlToDataFrame(nodes=getNodeSet(flyData,"//metadata/experimenter"))
fly <- xmlToDataFrame(nodes=getNodeSet(flyData,"//metadata/fly")) experimenter <- xmlToDataFrame(nodes=getNodeSet(flyData,"//metadata/experimenter"))
experiment <- xmlToDataFrame(nodes=getNodeSet(flyData,"//metadata/experiment")) fly <- xmlToDataFrame(nodes=getNodeSet(flyData,"//metadata/fly"))
#parse sequence data experiment <- xmlToDataFrame(nodes=getNodeSet(flyData,"//metadata/experiment"))
NofPeriods = as.integer(xmlGetAttr(flyDataXMLtop[['sequence']], "periods")) #parse sequence data
sequence <- xmlToDataFrame(nodes=getNodeSet(flyData,"//sequence/period")) NofPeriods = as.integer(xmlGetAttr(flyDataXMLtop[['sequence']], "periods"))
#parse time series meta-data sequence <- xmlToDataFrame(nodes=getNodeSet(flyData,"//sequence/period"))
CSV_descriptor <- xmlToDataFrame(nodes=getNodeSet(flyData,"//timeseries/CSV_descriptor")) #parse time series meta-data
variables <- xmlToDataFrame(nodes=getNodeSet(flyData,"//timeseries/variables/variable")) CSV_descriptor <- xmlToDataFrame(nodes=getNodeSet(flyData,"//timeseries/CSV_descriptor"))
#parse the time series raw data variables <- xmlToDataFrame(nodes=getNodeSet(flyData,"//timeseries/variables/variable"))
rawdata <- read.table(text=xmlSApply(flyDataXMLtop[['timeseries']][['csv_data']], xmlValue), col.names=variables$type) #parse the time series raw data
rawdata <- read.table(text=xmlSApply(flyDataXMLtop[['timeseries']][['csv_data']], xmlValue), col.names=variables$type)
options(digits.secs = 3)
rawdata$date<-as.POSIXct(rawdata$time/1000, origin="1970-01-01", tz="UTC") options(digits.secs = 3)
rawdata$date<-as.POSIXct(rawdata$time/1000, origin="1970-01-01", tz="UTC")
##list all data
singleflydata <- list(URIs, experimenter, fly, experiment, NofPeriods, sequence, CSV_descriptor, variables, rawdata) ##list all data
singleflydata <- list(URIs, experimenter, fly, experiment, NofPeriods, sequence, CSV_descriptor, variables, rawdata)
return(singleflydata)
} return(singleflydata)
}
## make sure all flies in a group have the identical experimental design
MultiFlyDataVerification <- function(xml_list) ## make sure all flies in a group have the identical experimental design
{ MultiFlyDataVerification <- function(xml_list)
for (l in 1:length(xml_list)) {
{ for (l in 1:length(xml_list))
xml_name=xml_list[l] {
xml_name=xml_list[l]
##### read the data with the corresponding function ####### ##### read the data with the corresponding function (readXMLdatafile.R) #######
singleflydata <- flyDataImport(xml_name) singleflydata <- flyDataImport(xml_name)
##extract meta-data ##extract meta-data
experiment <- singleflydata[[4]] experiment <- singleflydata[[4]]
sequence <- singleflydata[[6]] sequence <- singleflydata[[6]]
flymetadata <- c(as.vector(experiment$duration), flymetadata <- c(as.vector(experiment$duration),
as.vector(experiment$sample_rate), as.vector(experiment$sample_rate),
as.vector(experiment$arena_type), as.vector(experiment$arena_type),
as.vector(experiment$meter_type), as.vector(experiment$meter_type),
as.vector(sequence$type), as.vector(sequence$type),
as.vector(sequence$duration), as.vector(sequence$duration),
as.vector(sequence$outcome), as.vector(sequence$outcome),
as.vector(sequence$pattern), as.vector(sequence$pattern),
as.vector(sequence$coup_coeff)) as.vector(sequence$coup_coeff))
if(l==1){metadata<-data.frame(flymetadata)}else{metadata[,l]<-data.frame(flymetadata)} if(l==1){
} metadata<-data.frame(flymetadata)}else{
return(length(unique(as.list(metadata))) == 1) metadata[,l]<-data.frame(flymetadata)}
} }
return(length(unique(as.list(metadata))) == 1)
##gather experimental metadata in a single vector for plotting in summary pages }
collect.metadata <-function(singleflydata)
{ ##gather experimental metadata in a single vector for plotting in summary pages
#retrieve meta-data collect.metadata <-function(singleflydata)
experimenter <- singleflydata[[2]] {
experiment <- singleflydata[[4]] #retrieve meta-data
fly <- singleflydata[[3]] experimenter <- singleflydata[[2]]
#create reporting strings experiment <- singleflydata[[4]]
exp.name = paste("Experimenter:", experimenter$firstname, experimenter$lastname, sep = " ") fly <- singleflydata[[3]]
exp.orcid = paste("ORCID: ",experimenter$orcid) #create reporting strings
exp.date = paste("Date and time of the experiment: ",experiment$dateTime ) exp.name = paste("Experimenter:", experimenter$firstname, experimenter$lastname, sep = " ")
exp.duration = paste("Experiment duration:", experiment$duration, "s", sep = " ") exp.orcid = paste("ORCID: ",experimenter$orcid)
exp.description = paste("Experiment description: ", experiment$description) exp.date = paste("Date and time of the experiment: ",experiment$dateTime )
exp.setup = paste("Samplingrate: ", experiment$sample_rate, "Hz. Arena type:", experiment$arena_type, ". Torquemeter type: ", experiment$meter_type) exp.duration = paste("Experiment duration:", experiment$duration, "s", sep = " ")
fly = paste("Fly description: ", fly$description, ". FlybaseID: ", fly$flybase) exp.description = paste("Experiment description: ", experiment$description)
mdata = c(exp.name, exp.orcid, exp.date, exp.duration, exp.description, exp.setup, fly) exp.setup = paste("Samplingrate: ", experiment$sample_rate, "Hz. Arena type:", experiment$arena_type, ". Torquemeter type: ", experiment$meter_type)
return(mdata) fly = paste("Fly description: ", fly$description, ". FlybaseID: ", fly$flybase)
} mdata = c(exp.name, exp.orcid, exp.date, exp.duration, exp.description, exp.setup, fly)
\ No newline at end of file return(mdata)
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment