Commit ae94babe authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Added scala docs

parent da1f145f
......@@ -10,6 +10,7 @@ import nl.lumc.sasc.biopet.utils.ConfigUtils
class Summary(file: File) {
val map = ConfigUtils.fileToConfigMap(file)
/** List of all samples in the summary */
lazy val samples: Set[String] = {
ConfigUtils.getValueFromPath(map, List("samples")) match {
case Some(samples) => ConfigUtils.any2map(samples).keySet
......@@ -17,6 +18,7 @@ class Summary(file: File) {
}
}
/** List of all libraries for each sample */
lazy val libraries: Map[String, Set[String]] = {
(for (sample <- samples) yield sample -> {
ConfigUtils.getValueFromPath(map, List("samples", sample, "libraries")) match {
......@@ -26,26 +28,33 @@ class Summary(file: File) {
}).toMap
}
/** getValue from on given nested path */
def getValue(path: String*): Option[Any] = {
ConfigUtils.getValueFromPath(map, path.toList)
}
/** getValue from on given nested path with prefix "samples" -> [sampleId] */
def getSampleValue(sampleId: String, path: String*): Option[Any] = {
ConfigUtils.getValueFromPath(map, "samples" :: sampleId :: path.toList)
}
/** Get values for all samples on given path with prefix "samples" -> [sampleId] */
def getSampleValues(path: String*): Map[String, Option[Any]] = {
(for (sample <- samples) yield sample -> getSampleValue(sample, path: _*)).toMap
}
/** Executes given function for each sample */
def getSampleValues(function: (Summary, String) => Option[Any]): Map[String, Option[Any]] = {
(for (sample <- samples) yield sample -> function(this, sample)).toMap
}
/** Get value on nested path with prefix "samples" -> [sampleId] -> "libraries" -> [libId] */
def getLibraryValue(sampleId: String, libId: String, path: String*): Option[Any] = {
ConfigUtils.getValueFromPath(map, "samples" :: sampleId :: "libraries" :: libId :: path.toList)
}
//TODO: rename method
/** Get value on nested path with prefix depending is sampleId and/or libId is None or not */
def getLibraryValue(sampleId: Option[String], libId: Option[String], path: String*): Option[Any] = {
(sampleId, libId) match {
case (Some(sample), Some(lib)) => getLibraryValue(sample, lib, path: _*)
......@@ -54,12 +63,22 @@ class Summary(file: File) {
}
}
/**
* Get values for all libraries on a given path
* @param path path to of value
* @return (sampleId, libId) -> value
*/
def getLibraryValues(path: String*): Map[(String, String), Option[Any]] = {
(for (sample <- samples; lib <- libraries.getOrElse(sample, Set())) yield {
(sample, lib) -> getLibraryValue(sample, lib, path: _*)
}).toMap
}
/**
* Executes method for each library
* @param function Function to execute
* @return (sampleId, libId) -> value
*/
def getLibraryValues(function: (Summary, String, String) => Option[Any]): Map[(String, String), Option[Any]] = {
(for (sample <- samples; lib <- libraries.getOrElse(sample, Set())) yield {
(sample, lib) -> function(this, sample, lib)
......
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