Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Mirrors
biopet.biopet
Commits
104ed7fe
Commit
104ed7fe
authored
Nov 24, 2016
by
Peter van 't Hof
Browse files
Added yaml support to tsv parser
parent
606207b4
Changes
5
Hide whitespace changes
Inline
Side-by-side
biopet-tools-package/src/main/scala/nl/lumc/sasc/biopet/BiopetToolsExecutable.scala
View file @
104ed7fe
...
...
@@ -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
.
SamplesTsvTo
Json
,
nl
.
lumc
.
sasc
.
biopet
.
tools
.
SamplesTsvTo
Config
,
nl
.
lumc
.
sasc
.
biopet
.
tools
.
SeqStat
,
nl
.
lumc
.
sasc
.
biopet
.
tools
.
SquishBed
,
nl
.
lumc
.
sasc
.
biopet
.
tools
.
SummaryToTsv
,
...
...
biopet-tools/src/main/scala/nl/lumc/sasc/biopet/tools/SamplesTsvTo
Json
.scala
→
biopet-tools/src/main/scala/nl/lumc/sasc/biopet/tools/SamplesTsvTo
Config
.scala
View file @
104ed7fe
...
...
@@ -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
SamplesTsvTo
Json
extends
ToolCommand
{
object
SamplesTsvTo
Config
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
)
}
}
biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/SamplesTsvTo
Json
Test.scala
→
biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/SamplesTsvTo
Config
Test.scala
View file @
104ed7fe
...
...
@@ -25,8 +25,8 @@ import org.testng.annotations.Test
/**
* Created by ahbbollen on 28-8-15.
*/
class
SamplesTsvTo
Json
Test
extends
TestNGSuite
with
MockitoSugar
with
Matchers
{
import
SamplesTsvTo
Json
._
class
SamplesTsvTo
Config
Test
extends
TestNGSuite
with
MockitoSugar
with
Matchers
{
import
SamplesTsvTo
Config
._
private
def
resourcePath
(
p
:
String
)
:
String
=
{
Paths
.
get
(
getClass
.
getResource
(
p
).
toURI
).
toString
}
...
...
biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/SummaryToTsvTest.scala
View file @
104ed7fe
...
...
@@ -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.SamplesTsvTo
Json
._
import
nl.lumc.sasc.biopet.tools.SamplesTsvTo
Config
._
import
org.scalatest.Matchers
import
org.scalatest.mock.MockitoSugar
import
org.scalatest.testng.TestNGSuite
...
...
biopet-utils/pom.xml
View file @
104ed7fe
...
...
@@ -76,7 +76,7 @@
<dependency>
<groupId>
org.yaml
</groupId>
<artifactId>
snakeyaml
</artifactId>
<version>
1.1
5
</version>
<version>
1.1
7
</version>
</dependency>
<dependency>
<groupId>
io.argonaut
</groupId>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment