Skip to content
GitLab
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
29601ac7
Commit
29601ac7
authored
Feb 07, 2017
by
Peter van 't Hof
Browse files
Adding library methods
parent
9bc8ae66
Changes
4
Hide whitespace changes
Inline
Side-by-side
biopet-tools/src/main/scala/nl/lumc/sasc/biopet/tools/SummaryToSqlite.scala
View file @
29601ac7
...
...
@@ -50,10 +50,16 @@ object SummaryToSqlite extends ToolCommand {
summary
.
createTables
val
runId
=
Await
.
result
(
summary
.
createRun
(
"runName"
,
"kdfhla"
),
Duration
.
Inf
)
List
(
"1"
,
"2"
,
"3"
,
"4"
).
foreach
(
x
=>
Await
.
result
(
summary
.
createSample
(
runId
,
x
),
Duration
.
Inf
))
List
(
"1"
,
"2"
,
"3"
,
"4"
).
foreach
(
x
=>
Await
.
result
(
summary
.
createSample
(
x
,
runId
,
Some
(
"""{"father": "blabla"}"""
)
),
Duration
.
Inf
))
println
(
Await
.
result
(
summary
.
getSamples
(),
Duration
.
Inf
))
println
(
Await
.
result
(
summary
.
getSampleTags
(
1
),
Duration
.
Inf
))
Await
.
result
(
summary
.
createLibrary
(
"lib1"
,
runId
,
1
),
Duration
.
Inf
)
println
(
Await
.
result
(
summary
.
getLibraries
(),
Duration
.
Inf
))
db
.
close
()
logger
.
info
(
"Done"
)
...
...
biopet-utils/src/main/scala/nl/lumc/sasc/biopet/utils/ConfigUtils.scala
View file @
29601ac7
...
...
@@ -122,6 +122,10 @@ object ConfigUtils extends Logging {
}
}
def
jsonTextToMap
(
json
:
String
)
:
Map
[
String
,
Any
]
=
{
jsonToMap
(
textToJson
(
json
))
}
/** Make json aboject from a file */
def
textToJson
(
jsonText
:
String
)
:
Json
=
{
logger
.
debug
(
"jsonText: "
+
jsonText
)
...
...
biopet-utils/src/main/scala/nl/lumc/sasc/biopet/utils/summary/SummaryDb.scala
View file @
29601ac7
package
nl.lumc.sasc.biopet.utils.summary
import
java.sql.Blob
import
nl.lumc.sasc.biopet.utils.ConfigUtils
import
slick.driver.H2Driver.api._
import
scala.concurrent.
{
Await
,
Future
}
...
...
@@ -9,7 +8,6 @@ import scala.concurrent.duration.Duration
import
nl.lumc.sasc.biopet.utils.summary.db.Schema._
import
scala.concurrent.ExecutionContext.Implicits.global
import
scala.io.Source
/**
* Created by pjvanthof on 05/02/2017.
...
...
@@ -45,9 +43,9 @@ class SummaryDb(db: Database) {
db
.
run
(
q
.
result
)
}
def
createSample
(
runId
:
Int
,
name
:
String
,
tags
:
Option
[
String
]
=
None
)
:
Future
[
Int
]
=
{
def
createSample
(
name
:
String
,
runId
:
Int
,
tags
:
Option
[
String
]
=
None
)
:
Future
[
Int
]
=
{
val
id
=
Await
.
result
(
db
.
run
(
samples
.
size
.
result
),
Duration
.
Inf
)
db
.
run
(
samples
.
forceInsert
(
id
,
runId
,
name
,
tags
)).
map
(
_
=>
id
)
db
.
run
(
samples
.
forceInsert
(
id
,
name
,
runId
,
tags
)).
map
(
_
=>
id
)
}
def
getSamples
(
sampleId
:
Option
[
Int
]
=
None
,
runId
:
Option
[
Int
]
=
None
,
name
:
Option
[
String
]
=
None
)
=
{
...
...
@@ -61,8 +59,31 @@ class SummaryDb(db: Database) {
db
.
run
(
q
.
map
(
x
=>
(
x
.
id
,
x
.
runId
,
x
.
name
)).
result
)
}
def
sampleTags
(
sampleId
:
Int
)
:
Map
[
String
,
Any
]
=
{
samples
.
filter
(
_
.
id
===
sampleId
).
map
(
_
.
tags
)
def
getSampleTags
(
sampleId
:
Int
)
:
Future
[
Option
[
Map
[
String
,
Any
]]]
=
{
db
.
run
(
samples
.
filter
(
_
.
id
===
sampleId
).
map
(
_
.
tags
).
result
)
.
map
(
_
.
headOption
.
flatten
.
map
(
ConfigUtils
.
jsonTextToMap
))
}
def
createLibrary
(
name
:
String
,
runId
:
Int
,
sampleId
:
Int
,
tags
:
Option
[
String
]
=
None
)
:
Future
[
Int
]
=
{
val
id
=
Await
.
result
(
db
.
run
(
libraries
.
size
.
result
),
Duration
.
Inf
)
db
.
run
(
libraries
.
forceInsert
(
id
,
name
,
runId
,
sampleId
,
tags
)).
map
(
_
=>
id
)
}
def
getLibraries
(
libId
:
Option
[
Int
]
=
None
,
name
:
Option
[
String
]
=
None
,
runId
:
Option
[
Int
]
=
None
,
sampleId
:
Option
[
Int
]
=
None
)
=
{
val
q
=
libraries
.
filter
{
lib
=>
List
(
libId
.
map
(
lib
.
id
===
_
),
sampleId
.
map
(
lib
.
sampleId
===
_
),
runId
.
map
(
lib
.
runId
===
_
),
name
.
map
(
lib
.
name
===
_
)
// not a condition as `criteriaRoast` evaluates to `None`
).
collect
({
case
Some
(
criteria
)
=>
criteria
}).
reduceLeftOption
(
_
&&
_
).
getOrElse
(
true
:
Rep
[
Boolean
])
}
db
.
run
(
q
.
map
(
x
=>
(
x
.
id
,
x
.
name
,
x
.
runId
,
x
.
sampleId
)).
result
)
}
def
getLibraryTags
(
libId
:
Int
)
:
Future
[
Option
[
Map
[
String
,
Any
]]]
=
{
db
.
run
(
libraries
.
filter
(
_
.
id
===
libId
).
map
(
_
.
tags
).
result
)
.
map
(
_
.
headOption
.
flatten
.
map
(
ConfigUtils
.
jsonTextToMap
))
}
}
biopet-utils/src/main/scala/nl/lumc/sasc/biopet/utils/summary/db/Schema.scala
View file @
29601ac7
...
...
@@ -16,24 +16,24 @@ object Schema {
}
val
runs
=
TableQuery
[
Runs
]
class
Samples
(
tag
:
Tag
)
extends
Table
[(
Int
,
Int
,
String
,
Option
[
String
])](
tag
,
"Samples"
)
{
class
Samples
(
tag
:
Tag
)
extends
Table
[(
Int
,
String
,
Int
,
Option
[
String
])](
tag
,
"Samples"
)
{
def
id
=
column
[
Int
](
"id"
,
O
.
PrimaryKey
)
def
runId
=
column
[
Int
](
"runId"
)
def
name
=
column
[
String
](
"name"
)
def
runId
=
column
[
Int
](
"runId"
)
def
tags
=
column
[
Option
[
String
]](
"tags"
)
def
*
=
(
id
,
runId
,
name
,
tags
)
def
*
=
(
id
,
name
,
runId
,
tags
)
}
val
samples
=
TableQuery
[
Samples
]
class
Libraries
(
tag
:
Tag
)
extends
Table
[(
Int
,
Int
,
String
,
Int
,
Option
[
String
])](
tag
,
"Libraries"
)
{
class
Libraries
(
tag
:
Tag
)
extends
Table
[(
Int
,
String
,
Int
,
Int
,
Option
[
String
])](
tag
,
"Libraries"
)
{
def
id
=
column
[
Int
](
"id"
,
O
.
PrimaryKey
)
def
name
=
column
[
String
](
"name"
)
def
runId
=
column
[
Int
](
"runId"
)
def
libraryName
=
column
[
String
](
"name"
)
def
sampleId
=
column
[
Int
](
"sampleId"
)
def
tags
=
column
[
Option
[
String
]](
"tags"
)
def
*
=
(
id
,
runId
,
libraryName
,
sampleId
,
tags
)
def
*
=
(
id
,
name
,
runId
,
sampleId
,
tags
)
}
val
libraries
=
TableQuery
[
Libraries
]
...
...
@@ -59,38 +59,38 @@ object Schema {
class
Stats
(
tag
:
Tag
)
extends
Table
[(
Int
,
Int
,
Option
[
Int
]
,
Option
[
Int
]
,
Option
[
Int
]
,
String
,
Option
[
String
])](
tag
,
"Stats"
)
{
def
pipelineId
=
column
[
Int
](
"pipelineId"
)
def
runId
=
column
[
Int
](
"runId"
)
def
pipelineId
=
column
[
Int
](
"pipelineId"
)
def
moduleId
=
column
[
Option
[
Int
]](
"moduleId"
)
def
sampleId
=
column
[
Option
[
Int
]](
"sampleId"
)
def
libraryId
=
column
[
Option
[
Int
]](
"libraryId"
)
def
stats
=
column
[
String
](
"stats"
)
def
schema
=
column
[
Option
[
String
]](
"schema"
)
def
*
=
(
pipelineId
,
runId
,
moduleId
,
sampleId
,
libraryId
,
stats
,
schema
)
def
*
=
(
runId
,
pipelineId
,
moduleId
,
sampleId
,
libraryId
,
stats
,
schema
)
def
idx
=
index
(
"idx_stats"
,
(
pipelineId
,
runId
,
moduleId
,
sampleId
,
libraryId
),
unique
=
true
)
def
idx
=
index
(
"idx_stats"
,
(
runId
,
pipelineId
,
moduleId
,
sampleId
,
libraryId
),
unique
=
true
)
}
val
stats
=
TableQuery
[
Stats
]
class
Settings
(
tag
:
Tag
)
extends
Table
[(
Int
,
Int
,
Option
[
Int
]
,
Option
[
Int
]
,
Option
[
Int
]
,
String
,
Option
[
String
])](
tag
,
"Settings"
)
{
def
pipelineId
=
column
[
Int
](
"pipelineId"
)
def
runId
=
column
[
Int
](
"runId"
)
def
pipelineId
=
column
[
Int
](
"pipelineId"
)
def
moduleId
=
column
[
Option
[
Int
]](
"moduleId"
)
def
sampleId
=
column
[
Option
[
Int
]](
"sampleId"
)
def
libraryId
=
column
[
Option
[
Int
]](
"libraryId"
)
def
stats
=
column
[
String
](
"stats"
)
def
schema
=
column
[
Option
[
String
]](
"schema"
)
def
*
=
(
pipelineId
,
runId
,
moduleId
,
sampleId
,
libraryId
,
stats
,
schema
)
def
*
=
(
runId
,
pipelineId
,
moduleId
,
sampleId
,
libraryId
,
stats
,
schema
)
def
idx
=
index
(
"idx_settings"
,
(
pipelineId
,
runId
,
moduleId
,
sampleId
,
libraryId
),
unique
=
true
)
def
idx
=
index
(
"idx_settings"
,
(
runId
,
pipelineId
,
moduleId
,
sampleId
,
libraryId
),
unique
=
true
)
}
val
settings
=
TableQuery
[
Settings
]
class
Files
(
tag
:
Tag
)
extends
Table
[(
Int
,
Int
,
Option
[
Int
]
,
Option
[
Int
]
,
Option
[
Int
]
,
String
,
String
,
String
,
Boolean
,
Long
)](
tag
,
"Files"
)
{
def
pipelineId
=
column
[
Int
](
"pipelineId"
)
def
runId
=
column
[
Int
](
"runId"
)
def
pipelineId
=
column
[
Int
](
"pipelineId"
)
def
moduleId
=
column
[
Option
[
Int
]](
"moduleId"
)
def
sampleId
=
column
[
Option
[
Int
]](
"sampleId"
)
def
libraryId
=
column
[
Option
[
Int
]](
"libraryId"
)
...
...
@@ -100,9 +100,9 @@ object Schema {
def
link
=
column
[
Boolean
](
"link"
,
O
.
Default
(
false
))
def
size
=
column
[
Long
](
"size"
)
def
*
=
(
pipelineId
,
runId
,
moduleId
,
sampleId
,
libraryId
,
name
,
path
,
md5
,
link
,
size
)
def
*
=
(
runId
,
pipelineId
,
moduleId
,
sampleId
,
libraryId
,
name
,
path
,
md5
,
link
,
size
)
def
idx
=
index
(
"idx_files"
,
(
pipelineId
,
runId
,
sampleId
,
libraryId
,
name
),
unique
=
true
)
def
idx
=
index
(
"idx_files"
,
(
runId
,
pipelineId
,
sampleId
,
libraryId
,
name
),
unique
=
true
)
}
val
files
=
TableQuery
[
Files
]
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment