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
9bc8ae66
Commit
9bc8ae66
authored
Feb 06, 2017
by
Peter van 't Hof
Browse files
Added methods for runs and samples
parent
7eba2ad3
Changes
5
Hide whitespace changes
Inline
Side-by-side
biopet-tools/src/main/scala/nl/lumc/sasc/biopet/tools/SummaryToSqlite.scala
View file @
9bc8ae66
...
...
@@ -2,8 +2,12 @@ package nl.lumc.sasc.biopet.tools
import
java.io.File
import
nl.lumc.sasc.biopet.utils.summary.
db.Schema
import
nl.lumc.sasc.biopet.utils.summary.
SummaryDb
import
nl.lumc.sasc.biopet.utils.
{
ConfigUtils
,
ToolCommand
}
import
slick.driver.H2Driver.api._
import
scala.concurrent.Await
import
scala.concurrent.duration.Duration
/**
* Created by pjvanthof on 26/01/2017.
...
...
@@ -40,7 +44,17 @@ object SummaryToSqlite extends ToolCommand {
}
else
throw
new
IllegalArgumentException
(
s
"Db already exist: ${cmdArgs.outputSqlite}"
)
}
Schema
.
createEmptySqlite
(
cmdArgs
.
outputSqlite
)
val
db
=
Database
.
forURL
(
s
"jdbc:sqlite:${cmdArgs.outputSqlite.getAbsolutePath}"
,
driver
=
"org.sqlite.JDBC"
)
val
summary
=
new
SummaryDb
(
db
)
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
))
println
(
Await
.
result
(
summary
.
getSamples
(),
Duration
.
Inf
))
db
.
close
()
logger
.
info
(
"Done"
)
}
...
...
biopet-utils/src/main/scala/nl/lumc/sasc/biopet/utils/summary/Summary.scala
View file @
9bc8ae66
...
...
@@ -22,6 +22,8 @@ import nl.lumc.sasc.biopet.utils.ConfigUtils
* This class can read in a summary and extract values from it
*
* Created by pjvan_thof on 3/26/15.
*
* @deprecated
*/
class
Summary
(
val
map
:
Map
[
String
,
Any
])
{
...
...
biopet-utils/src/main/scala/nl/lumc/sasc/biopet/utils/summary/SummaryDb.scala
0 → 100644
View file @
9bc8ae66
package
nl.lumc.sasc.biopet.utils.summary
import
java.sql.Blob
import
slick.driver.H2Driver.api._
import
scala.concurrent.
{
Await
,
Future
}
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.
*/
class
SummaryDb
(
db
:
Database
)
{
/** This method will create all table */
def
createTables
()
:
Unit
=
{
try
{
val
setup
=
DBIO
.
seq
(
(
runs
.
schema
++
samples
.
schema
++
libraries
.
schema
++
pipelineNames
.
schema
++
moduleNames
.
schema
++
stats
.
schema
++
settings
.
schema
++
files
.
schema
++
executables
.
schema
).
create
)
val
setupFuture
=
db
.
run
(
setup
)
Await
.
result
(
setupFuture
,
Duration
.
Inf
)
}
}
def
createRun
(
runName
:
String
,
outputDir
:
String
)
:
Future
[
Int
]
=
{
val
id
=
Await
.
result
(
db
.
run
(
runs
.
size
.
result
),
Duration
.
Inf
)
db
.
run
(
runs
.
forceInsert
(
id
,
runName
,
outputDir
)).
map
(
_
=>
id
)
}
def
getRuns
(
runId
:
Option
[
Int
]
=
None
,
runName
:
Option
[
String
]
=
None
,
outputDir
:
Option
[
String
]
=
None
)
=
{
val
q
=
runs
.
filter
{
run
=>
List
(
runId
.
map
(
run
.
id
===
_
),
runName
.
map
(
run
.
runName
===
_
),
outputDir
.
map
(
run
.
outputDir
===
_
)
// not a condition as `criteriaRoast` evaluates to `None`
).
collect
({
case
Some
(
criteria
)
=>
criteria
}).
reduceLeftOption
(
_
&&
_
).
getOrElse
(
true
:
Rep
[
Boolean
])
}
db
.
run
(
q
.
result
)
}
def
createSample
(
runId
:
Int
,
name
:
String
,
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
)
}
def
getSamples
(
sampleId
:
Option
[
Int
]
=
None
,
runId
:
Option
[
Int
]
=
None
,
name
:
Option
[
String
]
=
None
)
=
{
val
q
=
samples
.
filter
{
sample
=>
List
(
sampleId
.
map
(
sample
.
id
===
_
),
runId
.
map
(
sample
.
runId
===
_
),
name
.
map
(
sample
.
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
.
runId
,
x
.
name
)).
result
)
}
def
sampleTags
(
sampleId
:
Int
)
:
Map
[
String
,
Any
]
=
{
samples
.
filter
(
_
.
id
===
sampleId
).
map
(
_
.
tags
)
}
}
biopet-utils/src/main/scala/nl/lumc/sasc/biopet/utils/summary/SummaryValue.scala
View file @
9bc8ae66
...
...
@@ -18,6 +18,8 @@ package nl.lumc.sasc.biopet.utils.summary
* This case class is used for easy access and calculations on those values
*
* Created by pjvan_thof on 4/23/15.
*
* @deprecated
*/
case
class
SummaryValue
(
value
:
Option
[
Any
])
{
...
...
biopet-utils/src/main/scala/nl/lumc/sasc/biopet/utils/summary/db/Schema.scala
View file @
9bc8ae66
package
nl.lumc.sasc.biopet.utils.summary.db
import
java.io.File
import
java.sql.Blob
import
slick.driver.H2Driver.api._
import
scala.concurrent.Await
import
scala.concurrent.duration.Duration
/**
* Created by pjvan_thof on 27-1-17.
*/
object
Schema
{
class
Runs
(
tag
:
Tag
)
extends
Table
[(
Int
,
String
)](
tag
,
"Runs"
)
{
def
runI
d
=
column
[
Int
](
"
runI
d"
,
O
.
PrimaryKey
)
class
Runs
(
tag
:
Tag
)
extends
Table
[(
Int
,
String
,
String
)](
tag
,
"Runs"
)
{
def
i
d
=
column
[
Int
](
"
i
d"
,
O
.
PrimaryKey
)
def
runName
=
column
[
String
](
"runName"
)
def
outputDir
=
column
[
String
](
"outputDir"
)
def
*
=
(
runI
d
,
runName
)
def
*
=
(
i
d
,
runName
,
outputDir
)
}
val
runs
=
TableQuery
[
Runs
]
class
Samples
(
tag
:
Tag
)
extends
Table
[(
Int
,
String
,
Option
[
Blob
])](
tag
,
"Samples"
)
{
def
sampleId
=
column
[
Int
](
"id"
,
O
.
PrimaryKey
)
def
sampleName
=
column
[
String
](
"name"
)
def
tags
=
column
[
Option
[
Blob
]](
"tags"
)
class
Samples
(
tag
:
Tag
)
extends
Table
[(
Int
,
Int
,
String
,
Option
[
String
])](
tag
,
"Samples"
)
{
def
id
=
column
[
Int
](
"id"
,
O
.
PrimaryKey
)
def
runId
=
column
[
Int
](
"runId"
)
def
name
=
column
[
String
](
"name"
)
def
tags
=
column
[
Option
[
String
]](
"tags"
)
def
*
=
(
sampleId
,
sampleN
ame
,
tags
)
def
*
=
(
id
,
runId
,
n
ame
,
tags
)
}
val
samples
=
TableQuery
[
Samples
]
class
SamplesRun
s
(
tag
:
Tag
)
extends
Table
[(
Int
,
Int
)](
tag
,
"SamplesRun
s"
)
{
def
sampleI
d
=
column
[
Int
](
"
sampleId"
)
class
Librarie
s
(
tag
:
Tag
)
extends
Table
[(
Int
,
Int
,
String
,
Int
,
Option
[
String
])](
tag
,
"Librarie
s"
)
{
def
i
d
=
column
[
Int
](
"
id"
,
O
.
PrimaryKey
)
def
runId
=
column
[
Int
](
"runId"
)
def
*
=
(
sampleId
,
runId
)
def
idx
=
index
(
"idx_samples_runs"
,
(
sampleId
,
runId
),
unique
=
true
)
}
val
samplesRuns
=
TableQuery
[
SamplesRuns
]
class
Libraries
(
tag
:
Tag
)
extends
Table
[(
Int
,
String
,
Int
,
Option
[
Blob
])](
tag
,
"Libraries"
)
{
def
libraryId
=
column
[
Int
](
"id"
,
O
.
PrimaryKey
)
def
libraryName
=
column
[
String
](
"name"
)
def
sampleId
=
column
[
Int
](
"sampleId"
)
def
tags
=
column
[
Option
[
Blob
]](
"tags"
)
def
tags
=
column
[
Option
[
String
]](
"tags"
)
def
*
=
(
library
Id
,
libraryName
,
sampleId
,
tags
)
def
*
=
(
id
,
run
Id
,
libraryName
,
sampleId
,
tags
)
}
val
libraries
=
TableQuery
[
Libraries
]
class
LibrariesRuns
(
tag
:
Tag
)
extends
Table
[(
Int
,
Int
)](
tag
,
"LibrariesRuns"
)
{
def
libraryId
=
column
[
Int
](
"libraryId"
)
def
runId
=
column
[
Int
](
"runId"
)
def
*
=
(
libraryId
,
runId
)
def
idx
=
index
(
"idx_libraries_runs"
,
(
libraryId
,
runId
),
unique
=
true
)
}
val
librariesRuns
=
TableQuery
[
LibrariesRuns
]
class
PipelineNames
(
tag
:
Tag
)
extends
Table
[(
Int
,
String
)](
tag
,
"PipelineNames"
)
{
def
id
=
column
[
Int
](
"id"
,
O
.
PrimaryKey
,
O
.
AutoInc
)
def
id
=
column
[
Int
](
"id"
,
O
.
PrimaryKey
)
def
name
=
column
[
String
](
"name"
)
def
*
=
(
id
,
name
)
...
...
@@ -81,13 +58,13 @@ object Schema {
val
moduleNames
=
TableQuery
[
ModuleNames
]
class
Stats
(
tag
:
Tag
)
extends
Table
[(
Int
,
Int
,
Option
[
Int
]
,
Option
[
Int
]
,
Option
[
Int
]
,
Blob
,
Option
[
String
])](
tag
,
"Stats"
)
{
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
moduleId
=
column
[
Option
[
Int
]](
"moduleId"
)
def
sampleId
=
column
[
Option
[
Int
]](
"sampleId"
)
def
libraryId
=
column
[
Option
[
Int
]](
"libraryId"
)
def
stats
=
column
[
Blob
](
"stats"
)
def
stats
=
column
[
String
](
"stats"
)
def
schema
=
column
[
Option
[
String
]](
"schema"
)
def
*
=
(
pipelineId
,
runId
,
moduleId
,
sampleId
,
libraryId
,
stats
,
schema
)
...
...
@@ -96,13 +73,13 @@ object Schema {
}
val
stats
=
TableQuery
[
Stats
]
class
Settings
(
tag
:
Tag
)
extends
Table
[(
Int
,
Int
,
Option
[
Int
]
,
Option
[
Int
]
,
Option
[
Int
]
,
Blob
,
Option
[
String
])](
tag
,
"Settings"
)
{
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
moduleId
=
column
[
Option
[
Int
]](
"moduleId"
)
def
sampleId
=
column
[
Option
[
Int
]](
"sampleId"
)
def
libraryId
=
column
[
Option
[
Int
]](
"libraryId"
)
def
stats
=
column
[
Blob
](
"stats"
)
def
stats
=
column
[
String
](
"stats"
)
def
schema
=
column
[
Option
[
String
]](
"schema"
)
def
*
=
(
pipelineId
,
runId
,
moduleId
,
sampleId
,
libraryId
,
stats
,
schema
)
...
...
@@ -111,20 +88,21 @@ object Schema {
}
val
settings
=
TableQuery
[
Settings
]
class
Files
(
tag
:
Tag
)
extends
Table
[(
Int
,
Int
,
Option
[
Int
]
,
Option
[
Int
]
,
Option
[
Int
]
,
String
,
String
,
Boolean
,
Long
)](
tag
,
"Files"
)
{
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
moduleId
=
column
[
Option
[
Int
]](
"moduleId"
)
def
sampleId
=
column
[
Option
[
Int
]](
"sampleId"
)
def
libraryId
=
column
[
Option
[
Int
]](
"libraryId"
)
def
name
=
column
[
String
](
"name"
)
def
path
=
column
[
String
](
"path"
)
def
md5
=
column
[
String
](
"md5"
)
def
link
=
column
[
Boolean
](
"link"
,
O
.
Default
(
false
))
def
size
=
column
[
Long
](
"size"
)
def
*
=
(
pipelineId
,
runId
,
moduleId
,
sampleId
,
libraryId
,
path
,
md5
,
link
,
size
)
def
*
=
(
pipelineId
,
runId
,
moduleId
,
sampleId
,
libraryId
,
name
,
path
,
md5
,
link
,
size
)
def
idx
=
index
(
"idx_files"
,
(
pipelineId
,
runId
,
sampleId
,
libraryId
,
path
),
unique
=
true
)
def
idx
=
index
(
"idx_files"
,
(
pipelineId
,
runId
,
sampleId
,
libraryId
,
name
),
unique
=
true
)
}
val
files
=
TableQuery
[
Files
]
...
...
@@ -142,20 +120,4 @@ object Schema {
}
val
executables
=
TableQuery
[
Executables
]
def
createEmptySqlite
(
file
:
File
)
:
Unit
=
{
val
db
=
Database
.
forURL
(
s
"jdbc:sqlite:${file.getAbsolutePath}"
,
driver
=
"org.sqlite.JDBC"
)
try
{
val
setup
=
DBIO
.
seq
(
(
runs
.
schema
++
samples
.
schema
++
samplesRuns
.
schema
++
libraries
.
schema
++
librariesRuns
.
schema
++
pipelineNames
.
schema
++
moduleNames
.
schema
++
stats
.
schema
++
settings
.
schema
++
files
.
schema
++
executables
.
schema
).
create
)
val
setupFuture
=
db
.
run
(
setup
)
Await
.
result
(
setupFuture
,
Duration
.
Inf
)
}
finally
db
.
close
}
}
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