@@ -3,9 +3,11 @@ require("rjson")
3
3
require(" XML" )
4
4
require(" stringr" )
5
5
require(" brew" )
6
+ require(" lubridate" )
6
7
# require("inline") #for date parsing
7
8
# require("Rcpp") #for date parsing
8
9
10
+
9
11
# ' reads uint16 vector from a raw vector matrix.
10
12
# '
11
13
# ' reads in a uint16 (2 bytes) from a raw vector
@@ -650,7 +652,7 @@ checkLTC <- function(df1, df2){
650
652
# ' TODO find logging library
651
653
# '
652
654
LOG <- function (st ){
653
- print(paste(date (), st ))
655
+ print(paste(now (), st ))
654
656
}
655
657
656
658
# '
@@ -921,8 +923,15 @@ parseRunParameters <- function(path){
921
923
cloudRunId <- xpathSApply(x ," //CloudRunId" ,xmlValue )
922
924
}
923
925
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 {
926
935
list ()
927
936
}
928
937
}
@@ -940,7 +949,52 @@ basespaceUrl <- function(runParameters){
940
949
}
941
950
}
942
951
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
+ }
943
987
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
+ }
944
998
945
999
# ' parses the run info
946
1000
# '
@@ -958,10 +1012,14 @@ parseRunInfo <- function(path){
958
1012
layout <- xmlAttrs(lay [[1 ]])
959
1013
layoutN <- as.integer(layout )
960
1014
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
+ }
965
1023
}
966
1024
967
1025
0 commit comments