Skip to content

Commit 1f82b63

Browse files
committed
date() => now()
1 parent 8657ec4 commit 1f82b63

File tree

5 files changed

+1146
-9
lines changed

5 files changed

+1146
-9
lines changed

DESCRIPTION

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ Imports:
1414
plyr,
1515
reshape2,
1616
rjson,
17-
brew
17+
brew,
18+
lubridate
1819
License: GPLv3
1920
LazyData: true
2021
RoxygenNote: 5.0.1

NAMESPACE

+5
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
11
# Generated by roxygen2: do not edit by hand
22

3+
export(allMetaFromFolder)
34
export(correctedIntensityMetricsParser2)
5+
export(cycleTimesStats)
46
export(errorMetricsParser3)
57
export(extractionMetricsParser2)
68
export(joinLaneTileCycle)
79
export(makeSite)
810
export(makeSiteInRunfolder)
911
export(metricsToJson)
12+
export(parseCycleTimes)
1013
export(parseMetricsLong)
1114
export(parseMetricsWide)
1215
export(parseRunInfo)
1316
export(parseRunParameters)
1417
export(qualityMetricsParser4)
1518
export(qualityMetricsParser5)
19+
export(runFoldersInInterval)
1620
export(setStatusFinished)
1721
export(tileMetricsParser2)
1822
export(write.json)
1923
import(XML)
2024
import(brew)
2125
import(ggplot2)
26+
import(lubridate)
2227
import(plyr)
2328
import(reshape2)
2429
import(rjson)

R/illuminasavr-package.r

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
#'
33
#' @name illuminasavr
44
#' @docType package
5-
#' @import XML reshape2 rjson ggplot2 plyr stringr brew
5+
#' @import XML reshape2 rjson ggplot2 plyr stringr brew lubridate
66

77
NULL

R/parser.R

+65-7
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ require("rjson")
33
require("XML")
44
require("stringr")
55
require("brew")
6+
require("lubridate")
67
#require("inline") #for date parsing
78
#require("Rcpp") #for date parsing
89

10+
911
#' reads uint16 vector from a raw vector matrix.
1012
#'
1113
#' reads in a uint16 (2 bytes) from a raw vector
@@ -650,7 +652,7 @@ checkLTC <- function(df1, df2){
650652
#' TODO find logging library
651653
#'
652654
LOG <- function(st){
653-
print(paste(date(), st))
655+
print(paste(now(), st))
654656
}
655657

656658
#'
@@ -921,8 +923,15 @@ parseRunParameters <- function(path){
921923
cloudRunId <- xpathSApply(x,"//CloudRunId",xmlValue)
922924
}
923925
experimentName <- xpathSApply(x,"//ExperimentName",xmlValue)
924-
list(version=version,cloudRunId=cloudRunId,experimentName=experimentName)
925-
}else{
926+
templateCycleCount <- xpathSApply(x,"//TemplateCycleCount", xmlValue)
927+
bay <- xpathSApply(x,"//FCPosition", xmlValue)
928+
instrument <- xpathSApply(x,"//ScannerID", xmlValue)
929+
runNr <- xpathSApply(x,"//ScanNumber", xmlValue)
930+
flowcell <- xpathSApply(x,"//Barcode", xmlValue) #WTF?
931+
list(version=version,cloudRunId=cloudRunId,experimentName=experimentName,
932+
templateCycleCount=as.integer(templateCycleCount),bay=bay,instrument=instrument,
933+
runNr=as.integer(runNr),flowcell=flowcell)
934+
} else {
926935
list()
927936
}
928937
}
@@ -940,7 +949,52 @@ basespaceUrl <- function(runParameters){
940949
}
941950
}
942951

952+
#' reads cycle times into table
953+
#'
954+
#' @export
955+
parseCycleTimes <- function(path){
956+
if(file.exists(path)){
957+
ct <- read.table(path, header=TRUE, sep="\t", strings=FALSE)
958+
dt <- mdy_hms(paste(ct$Date,ct$Time))
959+
ct$dateTime <- dt
960+
ct
961+
} else {
962+
NULL
963+
}
964+
}
965+
966+
#' statistics on cycle times
967+
#'
968+
#' @export
969+
cycleTimesStats <- function(cycleTimes){
970+
secondsPerCycle <- ddply(cycleTimes, .(Cycle), summarize, seconds=interval(dateTime[1],dateTime[4]) )
971+
runLength <- interval(cycleTimes$dateTime[1],cycleTimes$dateTime[nrow(cycleTimes)])
972+
list(secondsPerCycle=secondsPerCycle,runLength=runLength,meanSecondsPerCycle=mean(secondsPerCycle$seconds))
973+
}
974+
975+
#' run folders by date
976+
#'
977+
#' fromTo: lubridate::interval(lubridate::dmy("31/3/2015"),lubridate::ymd("2016/4/17"))
978+
#'
979+
#' @export
980+
runFoldersInInterval <- function(paths, fromTo){
981+
runFolders <- str_detect(paths, "\\d{6}_\\w{8}_\\d{4}_\\w{10}")
982+
folders <- paths[runFolders]
983+
dates <- ymd(unlist(lapply(strsplit(basename(folders), "_"), function(folder){ folder[[1]][1] })))
984+
ins <- dates %within% fromTo
985+
folders[ins]
986+
}
943987

988+
#' reads all metadata from folder
989+
#'
990+
#' @export
991+
allMetaFromFolder <- function(path){
992+
rp <- parseRunParameters(paste(path, "runParameters.xml",sep="/"))
993+
ri <- parseRunInfo(paste(path, "RunInfo.xml", sep="/"))
994+
ct <- parseCycleTimes(paste(path, "/Logs/CycleTimes.txt",sep=""))
995+
cts <- if(! is.null(ct)){ cycleTimesStats(ct) }else{ NULL }
996+
list(runParameters=rp, runInfo=ri, cycleTimes=ct, cycleTimesStats=cts)
997+
}
944998

945999
#' parses the run info
9461000
#'
@@ -958,10 +1012,14 @@ parseRunInfo <- function(path){
9581012
layout <- xmlAttrs(lay[[1]])
9591013
layoutN <- as.integer(layout)
9601014
names(layoutN) <- names(layout)
961-
list(flowcell=flowcell, totalCycles=totalCycles, reads=reads, layout=layoutN)
962-
}else{
963-
list(flowcell="NA",totalCycles=0,reads=data.frame(Number=NA,NumCycles=NA,IsIndexedRead=NA))
964-
}
1015+
rapid <- if(layoutN['LaneCount'] == 2){ "rapid" }else{ "HO" }
1016+
PE <- if(nrow(subset(reads, IsIndexedRead == "N")) == 2){ "PE" }else{ "SR" }
1017+
rl <- cut(reads[1,]$NumCycles, breaks=c(0,52,80,103,130,160,220,310,1000), labels=c(50,75,100,125,150,200,300,1000))
1018+
modus <- paste(PE,":",rl,sep="")
1019+
list(flowcell=flowcell, totalCycles=totalCycles, reads=reads, layout=layoutN, PE=PE, rl=rl, modus=modus, rapid=rapid)
1020+
} else {
1021+
list(flowcell="NA",totalCycles=0,reads=data.frame(Number=NA,NumCycles=NA,IsIndexedRead=NA), layout=NA, PE=NA, rl=NA, modus=NA, rapid=NA )
1022+
}
9651023
}
9661024

9671025

0 commit comments

Comments
 (0)