Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
biopet.biopet
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mirrors
biopet.biopet
Commits
7ef47a09
Commit
7ef47a09
authored
10 years ago
by
Peter van 't Hof
Browse files
Options
Downloads
Patches
Plain Diff
Switch to Argonaut library
parent
6294de9f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
biopet-framework/pom.xml
+5
-0
5 additions, 0 deletions
biopet-framework/pom.xml
biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/config/Config.scala
+36
-13
36 additions, 13 deletions
...c/main/scala/nl/lumc/sasc/biopet/core/config/Config.scala
with
41 additions
and
13 deletions
biopet-framework/pom.xml
+
5
−
0
View file @
7ef47a09
...
...
@@ -54,6 +54,11 @@
<artifactId>
gatk-queue-package-distribution
</artifactId>
<version>
3.2
</version>
</dependency>
<dependency>
<groupId>
io.argonaut
</groupId>
<artifactId>
argonaut_2.11
</artifactId>
<version>
6.1-M3
</version>
</dependency>
</dependencies>
<build>
<plugins>
...
...
This diff is collapsed.
Click to expand it.
biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/config/Config.scala
+
36
−
13
View file @
7ef47a09
package
nl.lumc.sasc.biopet.core.config
import
nl.lumc.sasc.biopet.core._
import
scala.util.parsing.json._
import
java.io.File
import
org.broadinstitute.gatk.queue.util.Logging
import
argonaut._
,
Argonaut
.
_
import
scalaz._
,
Scalaz
.
_
class
Config
(
var
map
:
Map
[
String
,
Any
])
extends
Logging
{
logger
.
debug
(
"Init phase of config"
)
...
...
@@ -24,23 +25,45 @@ class Config(var map: Map[String,Any]) extends Logging {
}
def
loadConfigFile
(
configFile
:
File
)
{
var
configJson
=
JSON
.
parseFull
(
scala
.
io
.
Source
.
fromFile
(
configFile
).
mkString
)
logger
.
debug
(
"Jsonfile: "
+
configFile
)
val
jsonText
=
scala
.
io
.
Source
.
fromFile
(
configFile
).
mkString
val
json
=
Parse
.
parseOption
(
jsonText
)
logger
.
debug
(
json
)
val
configJson
=
jsonToMap
(
json
.
get
)
logger
.
debug
(
"Contain: "
+
configJson
)
if
(
configJson
==
None
)
{
throw
new
IllegalStateException
(
"The config JSON file is either not properly formatted or not a JSON file, file: "
+
configFile
)
}
this
.
logger
.
debug
(
"Jsonfile: "
+
configFile
)
this
.
logger
.
debug
(
"Contain: "
+
configJson
)
configJson
.
get
match
{
case
m
:
Map
[
_
,
_
]
=>
{
logger
.
debug
(
m
)
if
(
map
.
isEmpty
)
map
=
m
.
asInstanceOf
[
Map
[
String
,
Any
]]
else
map
=
Config
.
mergeMaps
(
m
.
asInstanceOf
[
Map
[
String
,
Any
]],
map
)
if
(
map
.
isEmpty
)
map
=
configJson
else
map
=
Config
.
mergeMaps
(
configJson
,
map
)
logger
.
debug
(
"New config: "
+
map
)
}
private
def
jsonToMap
(
json
:
Json
)
:
Map
[
String
,
Any
]
=
{
var
output
:
Map
[
String
,
Any
]
=
Map
()
if
(
json
.
isObject
)
{
for
(
key
<-
json
.
objectFieldsOrEmpty
)
{
val
value
:
Any
=
jsonToAny
(
json
.
field
(
key
).
get
)
output
+=
(
key
->
value
)
}
case
null
=>
logger
.
warn
(
"Config "
+
configFile
+
" wrong format"
)
}
this
.
logger
.
debug
(
"config: "
+
map
)
}
else
return
null
return
output
}
private
def
jsonToAny
(
json
:
Json
)
:
Any
=
{
if
(
json
.
isObject
)
return
jsonToMap
(
json
)
else
if
(
json
.
isArray
)
{
var
list
:
List
[
Any
]
=
List
()
for
(
value
<-
json
.
objectValues
.
get
)
list
::=
jsonToAny
(
value
)
return
list
}
else
if
(
json
.
isBool
)
return
json
.
bool
.
get
else
if
(
json
.
isString
)
return
json
.
string
.
get
.
toString
else
if
(
json
.
isNumber
)
{
val
num
=
json
.
number
.
get
if
(
num
.
toString
.
contains
(
"."
))
return
num
.
toDouble
else
return
num
.
toLong
}
else
throw
new
IllegalStateException
(
"Config value type not supported, value: "
+
json
)
}
def
getMap
()
:
Map
[
String
,
Any
]
=
map
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment