Commit 104ed7fe authored by Peter van 't Hof's avatar Peter van 't Hof

Added yaml support to tsv parser

parent 606207b4
......@@ -40,7 +40,7 @@ object BiopetToolsExecutable extends BiopetExecutable {
nl.lumc.sasc.biopet.tools.MpileupToVcf,
nl.lumc.sasc.biopet.tools.PrefixFastq,
nl.lumc.sasc.biopet.tools.SageCountFastq,
nl.lumc.sasc.biopet.tools.SamplesTsvToJson,
nl.lumc.sasc.biopet.tools.SamplesTsvToConfig,
nl.lumc.sasc.biopet.tools.SeqStat,
nl.lumc.sasc.biopet.tools.SquishBed,
nl.lumc.sasc.biopet.tools.SummaryToTsv,
......
......@@ -14,18 +14,18 @@
*/
package nl.lumc.sasc.biopet.tools
import java.io.{ PrintWriter, File }
import java.io.{File, PrintWriter}
import nl.lumc.sasc.biopet.utils.ConfigUtils._
import nl.lumc.sasc.biopet.utils.ToolCommand
import scala.collection.mutable
import nl.lumc.sasc.biopet.utils.{ConfigUtils, ToolCommand}
import scala.collection.mutable
import scala.io.Source
/**
* This tool can convert a tsv to a json file
*/
object SamplesTsvToJson extends ToolCommand {
object SamplesTsvToConfig extends ToolCommand {
case class Args(inputFiles: List[File] = Nil,
tagFiles: List[File] = Nil,
outputFile: Option[File] = None) extends AbstractArgs
......@@ -47,14 +47,16 @@ object SamplesTsvToJson extends ToolCommand {
val argsParser = new OptParser
val cmdArgs: Args = argsParser.parse(args, Args()) getOrElse (throw new IllegalArgumentException)
val jsonString = stringFromInputs(cmdArgs.inputFiles, cmdArgs.tagFiles)
val configMap = stringFromInputs(cmdArgs.inputFiles, cmdArgs.tagFiles)
cmdArgs.outputFile match {
case Some(file) if file.getName.endsWith(".yml") || file.getName.endsWith(".yaml") =>
ConfigUtils.mapToYamlFile(configMap, file)
case Some(file) => {
val writer = new PrintWriter(file)
writer.println(jsonString)
writer.println(ConfigUtils.mapToJson(configMap).spaces2)
writer.close()
}
case _ => println(jsonString)
case _ => println(ConfigUtils.mapToYaml(configMap))
}
}
......@@ -94,11 +96,11 @@ object SamplesTsvToJson extends ToolCommand {
librariesValues.foldLeft(Map[String, Any]())((acc, kv) => mergeMaps(acc, kv))
}
def stringFromInputs(inputs: List[File], tagsInputs: List[File]): String = {
def stringFromInputs(inputs: List[File], tagsInputs: List[File]): Map[String, Any] = {
val map = inputs.map(f => mapFromFile(f))
.foldLeft(Map[String, Any]())((acc, kv) => mergeMaps(acc, kv))
val tags = tagsInputs.map(f => mapFromFile(f, tags = true))
.foldLeft(Map[String, Any]())((acc, kv) => mergeMaps(acc, kv))
mapToJson(mergeMaps(map, tags)).spaces2
mergeMaps(map, tags)
}
}
......@@ -25,8 +25,8 @@ import org.testng.annotations.Test
/**
* Created by ahbbollen on 28-8-15.
*/
class SamplesTsvToJsonTest extends TestNGSuite with MockitoSugar with Matchers {
import SamplesTsvToJson._
class SamplesTsvToConfigTest extends TestNGSuite with MockitoSugar with Matchers {
import SamplesTsvToConfig._
private def resourcePath(p: String): String = {
Paths.get(getClass.getResource(p).toURI).toString
}
......
......@@ -17,7 +17,7 @@ package nl.lumc.sasc.biopet.tools
import java.io.File
import java.nio.file.Paths
import nl.lumc.sasc.biopet.tools.SamplesTsvToJson._
import nl.lumc.sasc.biopet.tools.SamplesTsvToConfig._
import org.scalatest.Matchers
import org.scalatest.mock.MockitoSugar
import org.scalatest.testng.TestNGSuite
......
......@@ -76,7 +76,7 @@
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.15</version>
<version>1.17</version>
</dependency>
<dependency>
<groupId>io.argonaut</groupId>
......
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