Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
biopet.biopet
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Mirrors
biopet.biopet
Commits
6dd0c8cf
Commit
6dd0c8cf
authored
Mar 07, 2017
by
Peter van 't Hof
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change sample and libraries to createOrUpdate
parent
cfb37cde
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
28 additions
and
5 deletions
+28
-5
biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/MultiSampleQScript.scala
...n/scala/nl/lumc/sasc/biopet/core/MultiSampleQScript.scala
+2
-2
biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/summary/WriteSummary.scala
...scala/nl/lumc/sasc/biopet/core/summary/WriteSummary.scala
+2
-2
biopet-utils/src/main/scala/nl/lumc/sasc/biopet/utils/summary/db/SummaryDb.scala
...cala/nl/lumc/sasc/biopet/utils/summary/db/SummaryDb.scala
+19
-0
biopet-utils/src/test/scala/nl/lumc/sasc/biopet/utils/summary/db/SummaryDbTest.scala
.../nl/lumc/sasc/biopet/utils/summary/db/SummaryDbTest.scala
+5
-1
No files found.
biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/MultiSampleQScript.scala
View file @
6dd0c8cf
...
...
@@ -264,12 +264,12 @@ trait MultiSampleQScript extends SummaryQScript { qscript: QScript =>
for
((
sampleName
,
sample
)
<-
samples
)
{
val
sampleTags
=
if
(
sample
.
sampleTags
.
nonEmpty
)
Some
(
ConfigUtils
.
mapToJson
(
sample
.
sampleTags
).
nospaces
)
else
None
val
sampleId
:
Int
=
if
(!
namesOld
.
contains
(
sampleName
))
Await
.
result
(
db
.
createSample
(
sampleName
,
summaryRunId
,
sampleTags
),
Duration
.
Inf
)
Await
.
result
(
db
.
create
OrUpdate
Sample
(
sampleName
,
summaryRunId
,
sampleTags
),
Duration
.
Inf
)
else
Await
.
result
(
db
.
getSamples
(
runId
=
Some
(
summaryRunId
),
name
=
Some
(
sampleName
)).
map
(
_
.
head
.
id
),
Duration
.
Inf
)
val
libNamesOld
=
Await
.
result
(
db
.
getLibraries
(
runId
=
summaryRunId
,
sampleId
=
sampleId
).
map
(
_
.
map
(
_
.
name
)),
Duration
.
Inf
)
for
((
libName
,
lib
)
<-
sample
.
libraries
)
{
val
libraryTags
=
if
(
lib
.
libTags
.
nonEmpty
)
Some
(
ConfigUtils
.
mapToJson
(
sample
.
sampleTags
).
nospaces
)
else
None
if
(!
libNamesOld
.
contains
(
libName
))
Await
.
result
(
db
.
createLibrary
(
libName
,
summaryRunId
,
sampleId
,
libraryTags
),
Duration
.
Inf
)
if
(!
libNamesOld
.
contains
(
libName
))
Await
.
result
(
db
.
create
OrUpdate
Library
(
libName
,
summaryRunId
,
sampleId
,
libraryTags
),
Duration
.
Inf
)
}
}
}
...
...
biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/summary/WriteSummary.scala
View file @
6dd0c8cf
...
...
@@ -67,11 +67,11 @@ class WriteSummary(val parent: SummaryQScript) extends InProcessFunction with Co
case
t
:
SampleLibraryTag
=>
t
.
sampleId
.
foreach
{
case
sampleName
=>
val
sampleId
=
Await
.
result
(
db
.
getSamples
(
name
=
Some
(
sampleName
),
runId
=
Some
(
qscript
.
summaryRunId
)).
map
(
_
.
headOption
.
map
(
_
.
id
)),
Duration
.
Inf
).
getOrElse
{
Await
.
result
(
db
.
createSample
(
sampleName
,
qscript
.
summaryRunId
),
Duration
.
Inf
)
Await
.
result
(
db
.
create
OrUpdate
Sample
(
sampleName
,
qscript
.
summaryRunId
),
Duration
.
Inf
)
}
t
.
libId
.
foreach
{
libName
=>
val
libId
=
Await
.
result
(
db
.
getSamples
(
name
=
Some
(
libName
),
runId
=
Some
(
qscript
.
summaryRunId
),
sampleId
=
Some
(
sampleId
)).
map
(
_
.
headOption
.
map
(
_
.
id
)),
Duration
.
Inf
).
getOrElse
{
Await
.
result
(
db
.
createLibrary
(
libName
,
qscript
.
summaryRunId
,
sampleId
),
Duration
.
Inf
)
Await
.
result
(
db
.
create
OrUpdate
Library
(
libName
,
qscript
.
summaryRunId
,
sampleId
),
Duration
.
Inf
)
}
}
}
...
...
biopet-utils/src/main/scala/nl/lumc/sasc/biopet/utils/summary/db/SummaryDb.scala
View file @
6dd0c8cf
...
...
@@ -62,6 +62,16 @@ class SummaryDb(val db: Database) extends Closeable {
db
.
run
(
samples
.
forceInsert
(
Sample
(
id
,
name
,
runId
,
tags
))).
map
(
_
=>
id
)
}
def
createOrUpdateSample
(
name
:
String
,
runId
:
Int
,
tags
:
Option
[
String
]
=
None
)
:
Future
[
Int
]
=
{
getSampleId
(
runId
,
name
).
flatMap
(
_
match
{
case
Some
(
id
:
Int
)
=>
db
.
run
(
samples
.
filter
(
_
.
name
===
name
).
filter
(
_
.
id
===
id
).
map
(
_
.
tags
).
update
(
tags
))
.
map
(
_
=>
id
)
case
_
=>
createSample
(
name
,
runId
,
tags
)
})
}
/** This will return all samples that match given criteria */
def
getSamples
(
sampleId
:
Option
[
Int
]
=
None
,
runId
:
Option
[
Int
]
=
None
,
name
:
Option
[
String
]
=
None
)
:
Future
[
Seq
[
Sample
]]
=
{
val
q
=
samples
.
filter
{
sample
=>
...
...
@@ -96,6 +106,15 @@ class SummaryDb(val db: Database) extends Closeable {
db
.
run
(
libraries
.
forceInsert
(
Library
(
id
,
name
,
runId
,
sampleId
,
tags
))).
map
(
_
=>
id
)
}
def
createOrUpdateLibrary
(
name
:
String
,
runId
:
Int
,
sampleId
:
Int
,
tags
:
Option
[
String
]
=
None
)
:
Future
[
Int
]
=
{
getLibraryId
(
runId
,
sampleId
,
name
).
flatMap
(
_
match
{
case
Some
(
id
:
Int
)
=>
db
.
run
(
libraries
.
filter
(
_
.
name
===
name
).
filter
(
_
.
id
===
id
).
filter
(
_
.
sampleId
===
sampleId
).
map
(
_
.
tags
).
update
(
tags
))
.
map
(
_
=>
id
)
case
_
=>
createLibrary
(
name
,
runId
,
sampleId
,
tags
)
})
}
/** This returns all libraries that match the given criteria */
def
getLibraries
(
libId
:
Option
[
Int
]
=
None
,
name
:
Option
[
String
]
=
None
,
runId
:
Option
[
Int
]
=
None
,
sampleId
:
Option
[
Int
]
=
None
)
:
Future
[
Seq
[
Library
]]
=
{
val
q
=
libraries
.
filter
{
lib
=>
...
...
biopet-utils/src/test/scala/nl/lumc/sasc/biopet/utils/summary/db/SummaryDbTest.scala
View file @
6dd0c8cf
...
...
@@ -49,14 +49,17 @@ class SummaryDbTest extends TestNGSuite with Matchers {
val
runId
=
Await
.
result
(
db
.
createRun
(
"name"
,
"dir"
,
"version"
,
"hash"
,
date
),
Duration
.
Inf
)
Await
.
result
(
db
.
getSamples
(),
Duration
.
Inf
)
shouldBe
empty
val
sampleId
=
Await
.
result
(
db
.
createSample
(
"test_sample"
,
runId
),
Duration
.
Inf
)
Await
.
result
(
db
.
createOrUpdateSample
(
"test_sample"
,
runId
),
Duration
.
Inf
)
shouldBe
sampleId
Await
.
result
(
db
.
getSamples
(),
Duration
.
Inf
)
shouldBe
Seq
(
Schema
.
Sample
(
sampleId
,
"test_sample"
,
runId
,
None
))
Await
.
result
(
db
.
getSampleName
(
sampleId
),
Duration
.
Inf
)
shouldBe
Some
(
"test_sample"
)
Await
.
result
(
db
.
getSampleId
(
runId
,
"test_sample"
),
Duration
.
Inf
)
shouldBe
Some
(
sampleId
)
Await
.
result
(
db
.
getSampleTags
(
sampleId
),
Duration
.
Inf
)
shouldBe
None
Await
.
result
(
db
.
createOrUpdateSample
(
"test_sample"
,
runId
,
Some
(
"""{"test": "test"}"""
)),
Duration
.
Inf
)
shouldBe
sampleId
Await
.
result
(
db
.
getSampleTags
(
sampleId
),
Duration
.
Inf
)
shouldBe
Some
(
Map
(
"test"
->
"test"
))
val
sampleId2
=
Await
.
result
(
db
.
createSample
(
"test_sample2"
,
runId
,
Some
(
"""{"test": "test"}"""
)),
Duration
.
Inf
)
Await
.
result
(
db
.
getSampleTags
(
sampleId2
),
Duration
.
Inf
)
shouldBe
Some
(
Map
(
"test"
->
"test"
))
Await
.
result
(
db
.
getSamples
(),
Duration
.
Inf
)
shouldBe
Seq
(
Schema
.
Sample
(
sampleId
,
"test_sample"
,
runId
,
None
),
Schema
.
Sample
(
sampleId2
,
"test_sample2"
,
runId
,
Some
(
"""{"test": "test"}"""
)))
Await
.
result
(
db
.
getSamples
(),
Duration
.
Inf
)
shouldBe
Seq
(
Schema
.
Sample
(
sampleId
,
"test_sample"
,
runId
,
Some
(
"""{"test": "test"}"""
)
),
Schema
.
Sample
(
sampleId2
,
"test_sample2"
,
runId
,
Some
(
"""{"test": "test"}"""
)))
db
.
close
()
}
...
...
@@ -74,6 +77,7 @@ class SummaryDbTest extends TestNGSuite with Matchers {
val
sampleId
=
Await
.
result
(
db
.
createSample
(
"test_sample"
,
runId
),
Duration
.
Inf
)
Await
.
result
(
db
.
getLibraries
(),
Duration
.
Inf
)
shouldBe
empty
val
libraryId
=
Await
.
result
(
db
.
createLibrary
(
"test_lib"
,
runId
,
sampleId
),
Duration
.
Inf
)
Await
.
result
(
db
.
createOrUpdateLibrary
(
"test_lib"
,
runId
,
sampleId
),
Duration
.
Inf
)
shouldBe
libraryId
Await
.
result
(
db
.
getLibraries
(),
Duration
.
Inf
)
shouldBe
Seq
(
Schema
.
Library
(
libraryId
,
"test_lib"
,
runId
,
sampleId
,
None
))
Await
.
result
(
db
.
getLibraryName
(
libraryId
),
Duration
.
Inf
)
shouldBe
Some
(
"test_lib"
)
...
...
Write
Preview
Markdown
is supported
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