Created
October 16, 2013 06:18
-
-
Save thomaskelder/7003350 to your computer and use it in GitHub Desktop.
load nutritech data from dbnp
This file contains hidden or 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
| ## Fill out your own dbNP user / pass here | |
| authenticate("****", "****", "****") | |
| studies = getStudies() | |
| studyName = "NutriTechHIS" | |
| study = studies[[grep(studyName, sapply(studies, function(x) x$code))]] | |
| studyToken = study['token'] | |
| studyAssays = getAssaysForStudy(studyToken) | |
| names(studyAssays) = sapply(studyAssays, getElement, "name") | |
| assayData = list() | |
| for(assayName in names(studyAssays)) { | |
| message(assayName) | |
| assayToken = studyAssays[[assayName]][2] | |
| ad = assayDataAsMatrix(assayToken) | |
| if(ad != "No data!") assayData[[assayName]] = ad$data | |
| } | |
| studyEvents = getSamplingEventsForStudy(studyToken) | |
| events = namedListToDataFrame(studyEvents) | |
| ## Reformat data | |
| data = assayData[[1]] ## Only clinical chemistry for now | |
| subjects = t(namedListToDataFrame(getSubjectsForStudy(studyToken))) | |
| data = cbind(subjects[data$subject,], data) | |
| relativeTimes = unlist(lapply(data$samplingEvent, function(x) studyEvents[[x]]$relativeTimeInRelatedEvent)) | |
| eventDay = unlist(lapply(data$samplingEvent, function(x) studyEvents[[x]]$startTime)) | |
| data$relatedEvent = unlist(lapply(data$samplingEvent, function(x) studyEvents[[x]]$'samplingNameShort')) | |
| data$eventDay = floor(as.numeric(as.character(eventDay)) / 60 / 60 / 24) | |
| data$relativeTime = as.numeric(as.character(relativeTimes)) / 60 | |
| data$relatedEvent = gsub(" $", "", data$relatedEvent) | |
| save(events, subjects, data, file = "data/nutritech.clinchem.RData") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment