Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
biopet.biopet
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Jobs
Commits
Open sidebar
Mirrors
biopet.biopet
Commits
020acbfe
Commit
020acbfe
authored
Apr 12, 2017
by
Sander Bollen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PedigreeQscript testing
parent
e00f888e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
291 additions
and
7 deletions
+291
-7
biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/PedigreeQscript.scala
...main/scala/nl/lumc/sasc/biopet/core/PedigreeQscript.scala
+10
-7
biopet-core/src/test/resources/full.ped
biopet-core/src/test/resources/full.ped
+6
-0
biopet-core/src/test/resources/trio.ped
biopet-core/src/test/resources/trio.ped
+3
-0
biopet-core/src/test/scala/nl/lumc/sasc/biopet/core/PedigreeQScriptTest.scala
.../scala/nl/lumc/sasc/biopet/core/PedigreeQScriptTest.scala
+272
-0
No files found.
biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/PedigreeQscript.scala
View file @
020acbfe
...
...
@@ -13,14 +13,14 @@ import scala.io.Source
*
* A multi-sample Qscript with additional Pedigree information.
* Pedigrees follow the PED standard.
* See: http://
pngu.mgh.harvard.edu/~purcell/plink/data.shtml for the format
* See: http://
zzz.bwh.harvard.edu/plink/data.shtml#ped
*
* Pedigrees may be parsed from the sample config and/or a supplied PED file.
*/
trait
PedigreeQscript
extends
MultiSampleQScript
{
qscript
:
QScript
=>
/* Optionally parse from ped file */
def
ped
:
Option
[
File
]
=
None
def
ped
:
Option
[
File
]
=
config
(
"ped_file"
,
default
=
None
)
/* The merge stategy to use when we have both a ped file and sample tag information */
def
mergeStrategy
:
PedMergeStrategy.Value
=
PedMergeStrategy
.
Concatenate
...
...
@@ -28,14 +28,14 @@ trait PedigreeQscript extends MultiSampleQScript { qscript: QScript =>
/**
* Case class representing a PED samples
* For the PED format, see:
* http://
pngu.mgh.harvard.edu/~purcell/plink/data.shtml
* http://
zzz.bwh.harvard.edu/plink/data.shtml#ped
* @param familyId family id
* @param individualId individual id
* @param paternalId Optional paternal id
* @param maternalId Optional maternal id
* @param gender gender
* @param affectedPhenotype Optional boolean
* @param genotypeFields optional genotype fi
le
ds
* @param genotypeFields optional genotype fi
el
ds
*/
case
class
PedSample
(
familyId
:
String
,
individualId
:
String
,
paternalId
:
Option
[
String
],
...
...
@@ -57,7 +57,7 @@ trait PedigreeQscript extends MultiSampleQScript { qscript: QScript =>
* @return List[PedSample]
*/
def
getIndexSamples
:
List
[
PedSample
]
=
{
pedSamples
.
filter
(
x
=>
x
.
affectedPhenotype
)
pedSamples
.
filter
(
x
=>
x
.
affectedPhenotype
.
contains
(
true
)
)
}
/**
...
...
@@ -186,8 +186,11 @@ trait PedigreeQscript extends MultiSampleQScript { qscript: QScript =>
}
case
_
=>
"0"
}
val
line
:
String
=
s
"${p.familyId}\t${p.individualId}\t$paternalField\t$maternalField\t$genderField\t$affectedField\t"
+
p
.
genotypeFields
.
mkString
(
"\t"
)
val
mainLine
:
String
=
s
"${p.familyId}\t${p.individualId}\t$paternalField\t$maternalField\t$genderField\t$affectedField"
val
line
=
if
(
p
.
genotypeFields
.
nonEmpty
)
{
mainLine
+
"\t"
+
p
.
genotypeFields
.
mkString
(
"\t"
)
}
else
mainLine
writer
.
write
(
line
+
"\n"
)
}
writer
.
close
()
...
...
biopet-core/src/test/resources/full.ped
0 → 100644
View file @
020acbfe
fam01 sample1 sample2 sample3 2 0
fam01 sample2 0 0 1 0
fam01 sample3 0 0 2 0
fam02 sample4 sample5 sample6 2 2
fam02 sample5 0 0 1 1
fam02 sample6 0 0 2 1
biopet-core/src/test/resources/trio.ped
0 → 100644
View file @
020acbfe
fam02 sample4 sample5 sample6 2 2
fam02 sample5 0 0 1 1
fam02 sample6 0 0 2 1
biopet-core/src/test/scala/nl/lumc/sasc/biopet/core/PedigreeQScriptTest.scala
0 → 100644
View file @
020acbfe
package
nl.lumc.sasc.biopet.core
import
java.io.File
import
java.nio.file.Paths
import
nl.lumc.sasc.biopet.core.MultiSampleQScript.Gender
import
nl.lumc.sasc.biopet.core.extensions.Md5sum
import
nl.lumc.sasc.biopet.utils.config.Config
import
nl.lumc.sasc.biopet.utils.
{
ConfigUtils
,
Logging
}
import
org.broadinstitute.gatk.queue.
{
QScript
,
QSettings
}
import
org.scalatest.Matchers
import
org.scalatest.testng.TestNGSuite
import
org.testng.annotations.Test
import
scala.language.reflectiveCalls
import
scala.collection.mutable.ListBuffer
import
scala.io.Source
/**
* Created by Sander Bollen on 11-4-17.
*/
class
PedigreeQScriptTest
extends
TestNGSuite
with
Matchers
{
import
PedigreeQScriptTest._
@Test
def
testConfigPedigree
()
:
Unit
=
{
val
script
=
PedigreeQScriptTest
(
sample1
::
sample2
::
sample3
::
Nil
)
script
.
init
()
script
.
biopetScript
()
script
.
pedSamples
.
size
shouldBe
3
script
.
pedSamples
.
map
(
_
.
individualId
).
contains
(
"sample1"
)
shouldBe
true
script
.
pedSamples
.
map
(
_
.
individualId
).
contains
(
"sample2"
)
shouldBe
true
script
.
pedSamples
.
map
(
_
.
individualId
).
contains
(
"sample3"
)
shouldBe
true
}
@Test
def
testGenderCorrect
()
:
Unit
=
{
val
script
=
PedigreeQScriptTest
(
sample2
::
Nil
)
script
.
init
()
script
.
biopetScript
()
script
.
pedSamples
.
size
shouldBe
1
script
.
pedSamples
.
head
.
gender
shouldEqual
Gender
.
Male
val
script2
=
PedigreeQScriptTest
(
sample3
::
Nil
)
script2
.
init
()
script2
.
biopetScript
()
script2
.
pedSamples
.
size
shouldBe
1
script2
.
pedSamples
.
head
.
gender
shouldEqual
Gender
.
Female
}
@Test
def
testIsSingle
()
:
Unit
=
{
val
script
=
PedigreeQScriptTest
(
sample2
::
Nil
)
script
.
init
()
script
.
biopetScript
()
script
.
isSingle
shouldBe
true
}
@Test
def
testPedParsing
()
:
Unit
=
{
val
script
=
PedigreeQScriptTest
(
trioPed
::
Nil
)
script
.
init
()
script
.
biopetScript
()
script
.
pedSamples
.
size
shouldBe
3
script
.
pedSamples
.
map
(
_
.
individualId
).
contains
(
"sample4"
)
shouldBe
true
script
.
pedSamples
.
map
(
_
.
individualId
).
contains
(
"sample5"
)
shouldBe
true
script
.
pedSamples
.
map
(
_
.
individualId
).
contains
(
"sample6"
)
shouldBe
true
}
@Test
def
testIsMother
()
=
{
val
script
=
PedigreeQScriptTest
(
trioPed
::
Nil
)
script
.
init
()
script
.
biopetScript
()
script
.
isMother
(
script
.
pedSamples
.
filter
(
_
.
individualId
==
"sample6"
).
head
)
shouldBe
true
}
@Test
def
testIsFather
()
=
{
val
script
=
PedigreeQScriptTest
(
trioPed
::
Nil
)
script
.
init
()
script
.
biopetScript
()
script
.
isFather
(
script
.
pedSamples
.
filter
(
_
.
individualId
==
"sample5"
).
head
)
shouldBe
true
}
@Test
def
testIsTrio
()
=
{
val
script
=
PedigreeQScriptTest
(
trioPed
::
Nil
)
script
.
init
()
script
.
biopetScript
()
script
.
isTrio
shouldBe
true
val
script2
=
PedigreeQScriptTest
(
sample1
::
sample2
::
sample3
::
Nil
)
script2
.
init
()
script2
.
biopetScript
()
script2
.
isTrio
shouldBe
false
}
@Test
def
testConcatenation
()
=
{
val
script
=
PedigreeQScriptTest
(
sample1
::
sample2
::
sample3
::
trioPed
::
Nil
)
script
.
init
()
script
.
biopetScript
()
script
.
pedSamples
.
size
shouldBe
6
script
.
pedSamples
.
map
(
_
.
individualId
).
contains
(
"sample1"
)
shouldBe
true
script
.
pedSamples
.
map
(
_
.
individualId
).
contains
(
"sample2"
)
shouldBe
true
script
.
pedSamples
.
map
(
_
.
individualId
).
contains
(
"sample3"
)
shouldBe
true
script
.
pedSamples
.
map
(
_
.
individualId
).
contains
(
"sample4"
)
shouldBe
true
script
.
pedSamples
.
map
(
_
.
individualId
).
contains
(
"sample5"
)
shouldBe
true
script
.
pedSamples
.
map
(
_
.
individualId
).
contains
(
"sample6"
)
shouldBe
true
}
@Test
def
testWritePedFile
()
:
Unit
=
{
val
script
=
PedigreeQScriptTest
(
sample1
::
sample2
::
sample3
::
trioPed
::
Nil
)
script
.
init
()
script
.
biopetScript
()
val
tmpFile
=
File
.
createTempFile
(
"test"
,
".ped"
)
tmpFile
.
deleteOnExit
()
script
.
writeToPedFile
(
tmpFile
)
val
expectedLines
=
Source
.
fromFile
(
resourcePath
(
"/full.ped"
)).
getLines
().
toList
.
sorted
val
writtenLines
=
Source
.
fromFile
(
tmpFile
).
getLines
().
toList
.
sorted
writtenLines
shouldEqual
expectedLines
}
}
object
PedigreeQScriptTest
{
private
def
resourcePath
(
p
:
String
)
:
String
=
{
Paths
.
get
(
getClass
.
getResource
(
p
).
toURI
).
toString
}
val
sample1
=
Map
(
"samples"
->
Map
(
"sample1"
->
Map
(
"tags"
->
Map
(
"gender"
->
"female"
,
"father"
->
"sample2"
,
"mother"
->
"sample3"
,
"family"
->
"fam01"
)
)
)
)
val
sample2
=
Map
(
"samples"
->
Map
(
"sample2"
->
Map
(
"tags"
->
Map
(
"gender"
->
"male"
,
"family"
->
"fam01"
)
)
)
)
val
sample3
=
Map
(
"samples"
->
Map
(
"sample3"
->
Map
(
"tags"
->
Map
(
"gender"
->
"female"
,
"family"
->
"fam01"
)
)
)
)
val
trioPed
=
Map
(
"ped_file"
->
resourcePath
(
"/trio.ped"
))
def
apply
(
configs
:
List
[
Map
[
String
,
Any
]],
only
:
List
[
String
]
=
Nil
)
=
{
new
QScript
with
PedigreeQscript
{
qscript
=>
qSettings
=
new
QSettings
()
qSettings
.
runName
=
"test"
override
val
onlySamples
=
only
var
buffer
=
new
ListBuffer
[
String
]()
override
def
globalConfig
=
new
Config
(
configs
.
foldLeft
(
Map
[
String
,
Any
]())
{
case
(
a
,
b
)
=>
ConfigUtils
.
mergeMaps
(
a
,
b
)
})
val
parent
=
null
def
getLastLogMessage
:
String
=
{
Logging
.
errors
.
toList
.
last
.
getMessage
}
class
Sample
(
id
:
String
)
extends
AbstractSample
(
id
)
{
class
Library
(
id
:
String
)
extends
AbstractLibrary
(
id
)
{
/** Function that add library jobs */
protected
def
addJobs
()
:
Unit
=
{
buffer
+=
config
(
"test"
)
}
/** Must return files to store into summary */
def
summaryFiles
:
Map
[
String
,
File
]
=
Map
()
/** Must returns stats to store into summary */
def
summaryStats
=
Map
()
}
/**
* Factory method for Library class
* @param id SampleId
* @return Sample class
*/
def
makeLibrary
(
id
:
String
)
:
Library
=
new
Library
(
id
)
/** Function to add sample jobs */
protected
def
addJobs
()
:
Unit
=
{
buffer
+=
s
"$sampleId"
addPerLibJobs
()
add
(
new
Md5sum
(
qscript
))
}
/** Must return files to store into summary */
def
summaryFiles
:
Map
[
String
,
File
]
=
Map
()
/** Must returns stats to store into summary */
def
summaryStats
=
Map
()
}
/**
* Method where the multisample jobs should be added, this will be executed only when running the -sample argument is not given.
*/
def
addMultiSampleJobs
()
:
Unit
=
{
add
(
new
Md5sum
(
qscript
))
}
/**
* Factory method for Sample class
* @param id SampleId
* @return Sample class
*/
def
makeSample
(
id
:
String
)
:
Sample
=
new
Sample
(
id
)
/** Must return a map with used settings for this pipeline */
def
summarySettings
:
Map
[
String
,
Any
]
=
Map
()
/** File to put in the summary for thie pipeline */
def
summaryFiles
:
Map
[
String
,
File
]
=
Map
()
/** Name of summary output file */
def
summaryFile
:
File
=
new
File
(
"./summary.json"
)
/** Init for pipeline */
def
init
()
:
Unit
=
{
}
/** Pipeline itself */
def
biopetScript
()
:
Unit
=
{
addSamplesJobs
()
addSummaryJobs
()
}
}
}
}
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