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
2540e8fd
Commit
2540e8fd
authored
Jul 13, 2017
by
Peter van 't Hof
Browse files
Inspection round biopet utils
parent
2c840f96
Changes
46
Hide whitespace changes
Inline
Side-by-side
bam2wig/src/main/scala/nl/lumc/sasc/biopet/pipelines/bamtobigwig/Bam2Wig.scala
View file @
2540e8fd
...
...
@@ -31,7 +31,7 @@ class Bam2Wig(val parent: Configurable) extends QScript with BiopetQScript {
def
this
()
=
this
(
null
)
@Input
(
doc
=
"Input bam file"
,
required
=
true
)
var
bamFile
:
File
=
null
var
bamFile
:
File
=
_
def
init
()
:
Unit
=
{
inputFiles
:+=
new
InputFile
(
bamFile
)
...
...
bam2wig/src/test/scala/nl/lumc/sasc/biopet/pipelines/bamtobigwig/BamToChromSizesTest.scala
View file @
2540e8fd
...
...
@@ -32,7 +32,7 @@ class BamToChromSizesTest extends TestNGSuite with Matchers {
}
@Test
def
testChromSizes
:
Unit
=
{
def
testChromSizes
()
:
Unit
=
{
val
bamFile
=
new
File
(
resourcePath
(
"/empty.bam"
))
val
bamToChromSizes
=
new
BamToChromSizes
(
null
)
bamToChromSizes
.
bamFile
=
bamFile
...
...
bammetrics/src/main/resources/nl/lumc/sasc/biopet/pipelines/bammetrics/bamMetricsFront.ssp
View file @
2540e8fd
...
...
@@ -13,8 +13,8 @@
<tr><th>Version</th><td>${run.version}</td></tr>
<tr><th>Last commit hash</th><td>${run.commitHash}</td></tr>
<tr><th>Output directory</th><td>${run.outputDir}</td></tr>
<tr><th>Sample</th><td>${allSamples.fi
lter
(_.id == sampleId.get).
headOption.
map(_.name)}</td></tr>
<tr><th>Library</th><td>${allLibraries.fi
lter
(_.id == libId.get).
headOption.
map(_.name)}</td></tr>
<tr><th>Sample</th><td>${allSamples.fi
nd
(_.id == sampleId.get).map(_.name)}</td></tr>
<tr><th>Library</th><td>${allLibraries.fi
nd
(_.id == libId.get).map(_.name)}</td></tr>
</tbody>
</table>
<br/>
...
...
bammetrics/src/main/scala/nl/lumc/sasc/biopet/pipelines/bammetrics/BamMetrics.scala
View file @
2540e8fd
...
...
@@ -48,7 +48,7 @@ class BamMetrics(val parent: Configurable)
override
def
defaults
=
Map
(
"bedtoolscoverage"
->
Map
(
"sorted"
->
true
))
/** returns files to store in summary */
def
summaryFiles
=
def
summaryFiles
:
Map
[
String
,
File
]
=
Map
(
"reference"
->
referenceFasta
(),
"input_bam"
->
inputBam
)
++
ampliconBedFile
.
map
(
"amplicon"
->
_
).
toMap
++
ampliconBedFile
.
map
(
x
=>
"roi_"
+
x
.
getName
.
stripSuffix
(
".bed"
)
->
x
).
toMap
...
...
@@ -58,7 +58,7 @@ class BamMetrics(val parent: Configurable)
Map
(
"amplicon_name"
->
ampliconBedFile
.
collect
{
case
x
=>
x
.
getName
.
stripSuffix
(
".bed"
)
},
"roi_name"
->
roiBedFiles
.
map
(
_
.
getName
.
stripSuffix
(
".bed"
)))
override
def
reportClass
=
{
override
def
reportClass
:
Some
[
BammetricsReport
]
=
{
val
bammetricsReport
=
new
BammetricsReport
(
this
)
bammetricsReport
.
outputDir
=
new
File
(
outputDir
,
"report"
)
bammetricsReport
.
summaryDbFile
=
summaryDbFile
...
...
bammetrics/src/main/scala/nl/lumc/sasc/biopet/pipelines/bammetrics/BammetricsReport.scala
View file @
2540e8fd
...
...
@@ -487,7 +487,7 @@ object BammetricsReport extends ReportBuilder {
}
def
writeTableToTsv
(
tsvFile
:
File
,
table
:
Map
[
String
,
Array
[
Any
]],
firstColumn
:
String
)
:
Unit
=
{
require
(
table
.
map
(
_
.
_2
.
size
).
toList
.
distinct
.
size
==
1
,
require
(
table
.
map
(
_
.
_2
.
length
).
toList
.
distinct
.
size
==
1
,
"Not all values has the same number or rows"
)
val
keys
=
table
.
keys
.
filterNot
(
_
==
firstColumn
).
toList
.
sorted
val
writer
=
new
PrintWriter
(
tsvFile
)
...
...
bammetrics/src/test/scala/nl/lumc/sasc/biopet/pipelines/bammetrics/BamMetricsTest.scala
View file @
2540e8fd
...
...
@@ -44,7 +44,7 @@ class BamMetricsTest extends TestNGSuite with Matchers {
}
@DataProvider
(
name
=
"bammetricsOptions"
)
def
bammetricsOptions
=
{
def
bammetricsOptions
:
Array
[
Array
[
AnyVal
]]
=
{
val
rois
=
Array
(
0
,
1
,
2
,
3
)
val
bool
=
Array
(
true
,
false
)
...
...
@@ -57,7 +57,7 @@ class BamMetricsTest extends TestNGSuite with Matchers {
private
var
dirs
:
List
[
File
]
=
Nil
@Test
(
dataProvider
=
"bammetricsOptions"
)
def
testBamMetrics
(
rois
:
Int
,
amplicon
:
Boolean
,
rna
:
Boolean
,
wgs
:
Boolean
)
=
{
def
testBamMetrics
(
rois
:
Int
,
amplicon
:
Boolean
,
rna
:
Boolean
,
wgs
:
Boolean
)
:
Unit
=
{
val
outputDir
=
Files
.
createTempDir
()
dirs
:+=
outputDir
val
map
=
ConfigUtils
.
mergeMaps
(
Map
(
"output_dir"
->
outputDir
,
...
...
@@ -74,8 +74,6 @@ class BamMetricsTest extends TestNGSuite with Matchers {
bammetrics
.
libId
=
Some
(
"1"
)
bammetrics
.
script
()
var
regions
:
Int
=
rois
+
(
if
(
amplicon
)
1
else
0
)
bammetrics
.
functions
.
count
(
_
.
isInstanceOf
[
CollectRnaSeqMetrics
])
shouldBe
(
if
(
rna
)
1
else
0
)
bammetrics
.
functions
.
count
(
_
.
isInstanceOf
[
CollectWgsMetrics
])
shouldBe
(
if
(
wgs
)
1
else
0
)
bammetrics
.
functions
.
count
(
_
.
isInstanceOf
[
CollectMultipleMetrics
])
shouldBe
1
...
...
@@ -86,13 +84,13 @@ class BamMetricsTest extends TestNGSuite with Matchers {
}
// remove temporary run directory all tests in the class have been run
@AfterClass
def
removeTempOutputDir
()
=
{
@AfterClass
def
removeTempOutputDir
()
:
Unit
=
{
dirs
.
foreach
(
FileUtils
.
deleteDirectory
)
}
}
object
BamMetricsTest
{
val
inputDir
=
Files
.
createTempDir
()
val
inputDir
:
File
=
Files
.
createTempDir
()
val
bam
=
new
File
(
inputDir
,
"bla.bam"
)
Files
.
touch
(
bam
)
...
...
@@ -100,7 +98,7 @@ object BamMetricsTest {
Files
.
touch
(
ampliconBed
)
def
roi
(
i
:
Int
)
:
File
=
{
val
roi
=
new
File
(
inputDir
,
s
"roi$
{i}
.bed"
)
val
roi
=
new
File
(
inputDir
,
s
"roi$
i
.bed"
)
Files
.
touch
(
roi
)
roi
}
...
...
basty/src/main/scala/nl/lumc/sasc/biopet/pipelines/basty/Basty.scala
View file @
2540e8fd
...
...
@@ -42,7 +42,7 @@ class Basty(val parent: Configurable) extends QScript with MultiSampleQScript {
def
variantcallers
=
List
(
"unifiedgenotyper"
)
val
numBoot
=
config
(
"boot_runs"
,
default
=
100
,
namespace
=
"raxml"
).
asInt
val
numBoot
:
Int
=
config
(
"boot_runs"
,
default
=
100
,
namespace
=
"raxml"
).
asInt
override
def
defaults
=
Map
(
"ploidy"
->
1
,
...
...
basty/src/test/scala/nl/lumc/sasc/biopet/pipelines/basty/BastyTest.scala
View file @
2540e8fd
...
...
@@ -48,7 +48,7 @@ class BastyTest extends TestNGSuite with Matchers {
}
@DataProvider
(
name
=
"bastyOptions"
)
def
bastyOptions
=
{
def
bastyOptions
:
Array
[
Array
[
Any
]]
=
{
for
(
s1
<-
sample1
;
s2
<-
sample2
)
yield
Array
(
""
,
s1
,
s2
)
}
...
...
@@ -114,7 +114,7 @@ class BastyTest extends TestNGSuite with Matchers {
numberSamples
else
0
)
pipeline
.
functions
.
count
(
_
.
isInstanceOf
[
BaseRecalibrator
])
shouldBe
(
if
(
dbsnp
&&
baseRecalibration
)
(
numberLibs
*
2
)
numberLibs
*
2
else
0
)
pipeline
.
functions
.
count
(
_
.
isInstanceOf
[
PrintReads
])
shouldBe
(
if
(
dbsnp
&&
baseRecalibration
)
numberLibs
...
...
@@ -125,7 +125,7 @@ class BastyTest extends TestNGSuite with Matchers {
pipeline
.
summaryFiles
shouldBe
Map
()
pipeline
.
samples
foreach
{
case
(
sampleId
,
sample
)
=>
case
(
_
,
sample
)
=>
sample
.
summarySettings
shouldBe
Map
()
sample
.
summaryFiles
.
get
(
"variants_fasta"
)
should
not
be
None
sample
.
summaryFiles
.
get
(
"consensus_fasta"
)
should
not
be
None
...
...
@@ -135,7 +135,7 @@ class BastyTest extends TestNGSuite with Matchers {
sample
.
summaryFiles
.
get
(
"snps_only_consensus_variants_fasta"
)
should
not
be
None
sample
.
summaryStats
shouldBe
Map
()
sample
.
libraries
.
foreach
{
case
(
libId
,
lib
)
=>
case
(
_
,
lib
)
=>
lib
.
summarySettings
shouldBe
Map
()
lib
.
summaryFiles
shouldBe
Map
()
lib
.
summaryStats
shouldBe
Map
()
...
...
@@ -154,14 +154,14 @@ class BastyTest extends TestNGSuite with Matchers {
}
// remove temporary run directory all tests in the class have been run
@AfterClass
def
removeTempOutputDir
()
=
{
@AfterClass
def
removeTempOutputDir
()
:
Unit
=
{
dirs
.
foreach
(
FileUtils
.
deleteDirectory
)
}
}
object
BastyTest
{
def
outputDir
=
Files
.
createTempDir
()
val
inputDir
=
Files
.
createTempDir
()
def
outputDir
:
File
=
Files
.
createTempDir
()
val
inputDir
:
File
=
Files
.
createTempDir
()
def
inputTouch
(
name
:
String
)
:
String
=
{
val
file
=
new
File
(
inputDir
,
name
)
...
...
biopet-utils/src/main/scala/nl/lumc/sasc/biopet/utils/BamUtils.scala
View file @
2540e8fd
...
...
@@ -35,7 +35,7 @@ object BamUtils {
*
* @throws IllegalArgumentException
* @param bamFiles input bam files
* @return
* @return
Map of sample bam files
*/
def
sampleBamMap
(
bamFiles
:
List
[
File
])
:
Map
[
String
,
File
]
=
{
val
temp
=
bamFiles
.
map
{
file
=>
...
...
@@ -59,7 +59,7 @@ object BamUtils {
*
* @param inputBam input bam file
* @param contig contig to scan for
* @param end postion to stop scanning
* @param end pos
i
tion to stop scanning
* @return Int with insertsize for this contig
*/
def
contigInsertSize
(
inputBam
:
File
,
...
...
@@ -82,7 +82,7 @@ object BamUtils {
val
counts
:
mutable.Map
[
Int
,
Int
]
=
mutable
.
Map
()
for
(
i
<-
0
until
samplingSize
if
samIterator
.
hasNext
)
{
for
(
_
<-
0
until
samplingSize
if
samIterator
.
hasNext
)
{
val
rec
=
samIterator
.
next
()
val
isPaired
=
rec
.
getReadPairedFlag
val
minQ10
=
rec
.
getMappingQuality
>=
10
...
...
@@ -97,27 +97,24 @@ object BamUtils {
counts
.
keys
.
size
match
{
case
1
=>
Some
(
counts
.
keys
.
head
)
case
0
=>
None
case
_
=>
{
case
_
=>
Some
(
counts
.
foldLeft
(
0
)((
old
,
observation
)
=>
{
observation
match
{
case
(
insertSize
:
Int
,
observations
:
Int
)
=>
{
case
(
insertSize
:
Int
,
observations
:
Int
)
=>
(
old
+
(
insertSize
*
observations
))
/
(
observations
+
1
)
}
case
_
=>
0
}
}))
}
}
})
insertSizesOnAllFragments
.
size
match
{
case
1
=>
Some
(
insertSizesOnAllFragments
.
head
)
case
0
=>
None
case
_
=>
{
case
_
=>
Some
(
insertSizesOnAllFragments
.
foldLeft
(
0
)((
old
,
observation
)
=>
{
(
old
+
observation
)
/
2
}))
}
}
}
...
...
@@ -140,10 +137,10 @@ object BamUtils {
binSize
)
})
.
toList
val
counts
=
bamInsertSizes
.
flat
Map
(
x
=>
x
)
val
counts
=
bamInsertSizes
.
flat
ten
// avoid division by zero
if
(
counts
.
size
!=
0
)
counts
.
sum
/
counts
.
size
if
(
counts
.
nonEmpty
)
counts
.
sum
/
counts
.
size
else
0
}
...
...
@@ -161,7 +158,7 @@ object BamUtils {
}.
toMap
/** This class will add functionality to [[SAMSequenceDictionary]] */
implicit
class
SamDictCheck
(
samDics
:
SAMSequenceDictionary
)
{
implicit
class
SamDictCheck
(
samDic
t
s
:
SAMSequenceDictionary
)
{
/**
* This method will check if all contig and sizes are the same without looking at the order of the contigs
...
...
@@ -172,15 +169,15 @@ object BamUtils {
*/
def
assertSameDictionary
(
that
:
SAMSequenceDictionary
,
ignoreOrder
:
Boolean
)
:
Unit
=
{
if
(
ignoreOrder
)
{
assert
(
samDics
.
getReferenceLength
==
that
.
getReferenceLength
)
assert
(
samDic
t
s
.
getReferenceLength
==
that
.
getReferenceLength
)
val
thisContigNames
=
samDics
.
getSequences
.
map
(
x
=>
(
x
.
getSequenceName
,
x
.
getSequenceLength
)).
sorted
.
toSet
samDic
t
s
.
getSequences
.
map
(
x
=>
(
x
.
getSequenceName
,
x
.
getSequenceLength
)).
sorted
.
toSet
assert
(
thisContigNames
==
that
.
getSequences
.
map
(
x
=>
(
x
.
getSequenceName
,
x
.
getSequenceLength
))
.
sorted
.
toSet
)
}
else
samDics
.
assertSameDictionary
(
that
)
}
else
samDic
t
s
.
assertSameDictionary
(
that
)
}
}
}
biopet-utils/src/main/scala/nl/lumc/sasc/biopet/utils/ConfigUtils.scala
View file @
2540e8fd
...
...
@@ -35,7 +35,7 @@ object ConfigUtils extends Logging {
*
* @param map1 input map
* @param map2 input map
* @return Uniqe map1
* @return Uniq
u
e map1
*/
def
uniqueKeys
(
map1
:
Map
[
String
,
Any
],
map2
:
Map
[
String
,
Any
])
:
Map
[
String
,
Any
]
=
{
filterEmtpyMapValues
(
...
...
@@ -57,32 +57,34 @@ object ConfigUtils extends Logging {
*/
def
filterEmtpyMapValues
(
map
:
Map
[
String
,
Any
])
:
Map
[
String
,
Any
]
=
{
map
.
filter
{
case
(
key
,
value
:
Map
[
_
,
_
])
=>
value
.
nonEmpty
case
(
_
,
value
:
Map
[
_
,
_
])
=>
value
.
nonEmpty
case
_
=>
true
}
}
/**
* Merge 2 maps, when value is in a map in map1 and map2 the value calls recursively this function
*
* @param map1 Prio over map2
* @param map2 Backup for map1
* @return merged map
*/
//noinspection ScalaUnnecessaryParentheses,ScalaUnnecessaryParentheses,ScalaUnnecessaryParentheses,ScalaUnnecessaryParentheses,ScalaUnnecessaryParentheses
def
mergeMaps
(
map1
:
Map
[
String
,
Any
],
map2
:
Map
[
String
,
Any
],
resolveConflict
:
(
Any
,
Any
,
String
)
=>
Any
=
(
m1
,
m2
,
key
)
=>
m1
)
:
Map
[
String
,
Any
]
=
{
resolveConflict
:
(
Any
,
Any
,
String
)
=>
Any
=
(
m1
,
_
,
_
)
=>
m1
)
:
Map
[
String
,
Any
]
=
{
(
for
(
key
<-
map1
.
keySet
.++(
map2
.
keySet
))
yield
{
if
(!
map2
.
contains
(
key
))
(
key
->
map1
(
key
)
)
else
if
(!
map1
.
contains
(
key
))
(
key
->
map2
(
key
)
)
if
(!
map2
.
contains
(
key
))
key
->
map1
(
key
)
else
if
(!
map1
.
contains
(
key
))
key
->
map2
(
key
)
else
{
map1
(
key
)
match
{
case
m1
:
Map
[
_
,
_
]
=>
map2
(
key
)
match
{
case
m2
:
Map
[
_
,
_
]
=>
(
key
->
mergeMaps
(
any2map
(
m1
),
any2map
(
m2
),
resolveConflict
)
)
case
_
=>
(
key
->
map1
(
key
)
)
case
m2
:
Map
[
_
,
_
]
=>
key
->
mergeMaps
(
any2map
(
m1
),
any2map
(
m2
),
resolveConflict
)
case
_
=>
key
->
map1
(
key
)
}
case
_
=>
(
key
->
resolveConflict
(
map1
(
key
),
map2
(
key
),
key
)
)
case
_
=>
key
->
resolveConflict
(
map1
(
key
),
map2
(
key
),
key
)
}
}
}).
toMap
...
...
@@ -122,7 +124,7 @@ object ConfigUtils extends Logging {
}
else
Some
(
map
)
}
/** Make json
ab
oject from a file */
/** Make json o
b
ject from a file */
def
fileToJson
(
configFile
:
File
)
:
Json
=
{
logger
.
debug
(
"Jsonfile: "
+
configFile
)
val
jsonText
=
scala
.
io
.
Source
.
fromFile
(
configFile
).
mkString
...
...
@@ -172,15 +174,16 @@ object ConfigUtils extends Logging {
lazy
val
yaml
=
new
Yaml
()
def
mapToYaml
(
map
:
Map
[
String
,
Any
])
=
yaml
.
dump
(
yaml
.
load
(
ConfigUtils
.
mapToJson
(
map
).
nospaces
))
def
mapToYaml
(
map
:
Map
[
String
,
Any
])
:
JsonField
=
yaml
.
dump
(
yaml
.
load
(
ConfigUtils
.
mapToJson
(
map
).
nospaces
))
def
mapToYamlFile
(
map
:
Map
[
String
,
Any
],
outputFile
:
File
)
=
{
def
mapToYamlFile
(
map
:
Map
[
String
,
Any
],
outputFile
:
File
)
:
Unit
=
{
val
writer
=
new
PrintWriter
(
outputFile
)
writer
.
println
(
mapToYaml
(
map
))
writer
.
close
()
}
def
mapToJsonFile
(
map
:
Map
[
String
,
Any
],
outputFile
:
File
)
=
{
def
mapToJsonFile
(
map
:
Map
[
String
,
Any
],
outputFile
:
File
)
:
Unit
=
{
val
writer
=
new
PrintWriter
(
outputFile
)
writer
.
println
(
anyToJson
(
map
).
toString
())
writer
.
close
()
...
...
@@ -531,13 +534,13 @@ object ConfigUtils extends Logging {
/** Convert ConfigValue to List[Double] */
implicit
def
configValue2doubleList
(
value
:
ConfigValue
)
:
List
[
Double
]
=
{
if
(
requiredValue
(
value
))
any2list
(
value
.
value
).
map
(
any2double
(
_
)
)
if
(
requiredValue
(
value
))
any2list
(
value
.
value
).
map
(
any2double
)
else
Nil
}
/** Convert ConfigValue to List[Int] */
implicit
def
configValue2intList
(
value
:
ConfigValue
)
:
List
[
Int
]
=
{
if
(
requiredValue
(
value
))
any2list
(
value
.
value
).
map
(
any2int
(
_
)
)
if
(
requiredValue
(
value
))
any2list
(
value
.
value
).
map
(
any2int
)
else
Nil
}
...
...
biopet-utils/src/main/scala/nl/lumc/sasc/biopet/utils/FastaUtils.scala
View file @
2540e8fd
...
...
@@ -43,7 +43,7 @@ object FastaUtils {
private
var
dictCache
:
Map
[
File
,
SAMSequenceDictionary
]
=
Map
()
/** This will clear the dict cache */
def
clearCache
()
=
{
def
clearCache
()
:
Unit
=
{
dictCache
=
Map
()
}
...
...
@@ -84,8 +84,8 @@ object FastaUtils {
.
map
{
line
=>
val
columns
=
line
.
split
(
"\t"
)
val
refContig
=
columns
(
0
)
val
alterniveNames
=
columns
(
1
).
split
(
";"
).
toSet
refContig
->
alterniveNames
val
altern
at
iveNames
=
columns
(
1
).
split
(
";"
).
toSet
refContig
->
altern
at
iveNames
}
.
toMap
reader
.
close
()
...
...
biopet-utils/src/main/scala/nl/lumc/sasc/biopet/utils/IoUtils.scala
View file @
2540e8fd
...
...
@@ -72,12 +72,7 @@ object IoUtils {
else
fname
}
/**
* This return the contends of a file as a List[String]
*
* @param file
* @return
*/
/** This return the contends of a file as a List[String] */
def
getLinesFromFile
(
file
:
File
)
:
List
[
String
]
=
{
val
reader
=
Source
.
fromFile
(
file
)
val
lines
=
reader
.
getLines
().
toList
...
...
@@ -87,16 +82,15 @@ object IoUtils {
def
executableExist
(
exe
:
String
)
:
Boolean
=
{
try
{
val
process
=
Process
(
Seq
(
exe
)).
run
()
true
}
catch
{
case
e
:
IOException
=>
false
case
_
:
IOException
=>
false
}
}
def
writeLinesToFile
(
output
:
File
,
lines
:
List
[
String
])
:
Unit
=
{
val
writer
=
new
PrintWriter
(
output
)
lines
.
foreach
(
writer
.
println
(
_
)
)
lines
.
foreach
(
writer
.
println
)
writer
.
close
()
}
}
biopet-utils/src/main/scala/nl/lumc/sasc/biopet/utils/LazyCheck.scala
View file @
2540e8fd
...
...
@@ -19,12 +19,12 @@ package nl.lumc.sasc.biopet.utils
*/
class
LazyCheck
[
T
](
function
:
=>
T
)
{
private
var
_isSet
=
false
def
isSet
=
_isSet
lazy
val
value
=
{
def
isSet
:
Boolean
=
_isSet
lazy
val
value
:
T
=
{
val
cache
=
function
_isSet
=
true
cache
}
def
apply
()
=
value
def
get
=
value
def
apply
()
:
T
=
value
def
get
:
T
=
value
}
biopet-utils/src/main/scala/nl/lumc/sasc/biopet/utils/MainCommand.scala
View file @
2540e8fd
...
...
@@ -19,7 +19,7 @@ package nl.lumc.sasc.biopet.utils
*/
trait
MainCommand
{
lazy
val
commandName
=
this
.
getClass
.
getSimpleName
lazy
val
commandName
:
String
=
this
.
getClass
.
getSimpleName
.
split
(
"\\$"
)
.
last
...
...
biopet-utils/src/main/scala/nl/lumc/sasc/biopet/utils/Question.scala
View file @
2540e8fd
...
...
@@ -22,24 +22,24 @@ object Question {
def
string
(
name
:
String
,
default
:
Option
[
String
]
=
None
,
description
:
Option
[
String
]
=
None
,
posibleValues
:
List
[
String
]
=
Nil
,
pos
s
ibleValues
:
List
[
String
]
=
Nil
,
validation
:
List
[(
String
)
=>
Boolean
]
=
Nil
)
:
String
=
{
description
.
foreach
(
println
)
if
(
posibleValues
.
nonEmpty
)
println
(
s
"possible values: ${posibleValues.mkString("
,
")}"
)
if
(
pos
s
ibleValues
.
nonEmpty
)
println
(
s
"possible values: ${pos
s
ibleValues.mkString("
,
")}"
)
default
.
foreach
(
x
=>
println
(
s
"Default value: $x"
))
print
(
s
"$name > "
)
(
scala
.
io
.
StdIn
.
readLine
.
trim
,
default
)
match
{
case
(
a
,
Some
(
d
))
if
a
.
isEmpty
=>
d
case
(
a
,
None
)
if
a
.
isEmpty
=>
println
(
"ERROR: Value is required"
)
string
(
name
,
default
,
description
,
posibleValues
,
validation
)
string
(
name
,
default
,
description
,
pos
s
ibleValues
,
validation
)
case
(
a
,
_
)
=>
if
(!
validation
.
forall
(
_
(
a
)))
{
println
(
"ERROR: Validation of failed"
)
string
(
name
,
default
,
description
,
posibleValues
,
validation
)
}
else
if
(
posibleValues
.
nonEmpty
&&
!
posibleValues
.
contains
(
a
))
{
string
(
name
,
default
,
description
,
pos
s
ibleValues
,
validation
)
}
else
if
(
pos
s
ibleValues
.
nonEmpty
&&
!
pos
s
ibleValues
.
contains
(
a
))
{
println
(
"ERROR: Value not allowed"
)
string
(
name
,
default
,
description
,
posibleValues
,
validation
)
string
(
name
,
default
,
description
,
pos
s
ibleValues
,
validation
)
}
else
a
}
}
...
...
@@ -69,24 +69,24 @@ object Question {
def
list
(
name
:
String
,
default
:
Option
[
List
[
String
]]
=
None
,
description
:
Option
[
String
]
=
None
,
posibleValues
:
List
[
String
]
=
Nil
,
validation
:
(
String
)
=>
Boolean
=
String
=>
true
)
:
List
[
String
]
=
{
pos
s
ibleValues
:
List
[
String
]
=
Nil
,
validation
:
(
String
)
=>
Boolean
=
_
=>
true
)
:
List
[
String
]
=
{
description
.
foreach
(
println
)
if
(
posibleValues
.
nonEmpty
)
println
(
s
"possible values: ${posibleValues.mkString("
,
")}"
)
if
(
pos
s
ibleValues
.
nonEmpty
)
println
(
s
"possible values: ${pos
s
ibleValues.mkString("
,
")}"
)
default
.
foreach
(
x
=>
println
(
s
"Default value: $x"
))
print
(
s
"$name > "
)
(
scala
.
io
.
StdIn
.
readLine
.
split
(
","
).
toList
.
map
(
_
.
trim
),
default
)
match
{
case
(
List
(
""
),
Some
(
d
))
=>
d
case
(
List
(
""
),
None
)
=>
println
(
"ERROR: Value is required"
)
list
(
name
,
default
,
description
,
posibleValues
,
validation
)
list
(
name
,
default
,
description
,
pos
s
ibleValues
,
validation
)
case
(
a
,
_
)
=>
if
(!
a
.
forall
(
validation
))
{
println
(
"ERROR: Validation of failed"
)
list
(
name
,
default
,
description
,
posibleValues
,
validation
)
}
else
if
(
posibleValues
.
nonEmpty
&&
!
a
.
forall
(
posibleValues
.
contains
))
{
list
(
name
,
default
,
description
,
pos
s
ibleValues
,
validation
)
}
else
if
(
pos
s
ibleValues
.
nonEmpty
&&
!
a
.
forall
(
pos
s
ibleValues
.
contains
))
{
println
(
"ERROR: Value not allowed"
)
list
(
name
,
default
,
description
,
posibleValues
,
validation
)
list
(
name
,
default
,
description
,
pos
s
ibleValues
,
validation
)
}
else
a
}
}
...
...
biopet-utils/src/main/scala/nl/lumc/sasc/biopet/utils/SemanticVersion.scala
View file @
2540e8fd
package
nl.lumc.sasc.biopet.utils
import
scala.util.matching.Regex
/**
* Created by pjvanthof on 29/04/2017.
...
...
@@ -34,7 +35,7 @@ case class SemanticVersion(major: Int, minor: Int, patch: Int, build: Option[Str
}
object
SemanticVersion
{
val
semanticVersionRegex
=
"[vV]?(\\d+)\\.(\\d+)\\.(\\d+)(-.*)?"
.
r
val
semanticVersionRegex
:
Regex
=
"[vV]?(\\d+)\\.(\\d+)\\.(\\d+)(-.*)?"
.
r
/**
* Check whether a version string is a semantic version.
...
...
biopet-utils/src/main/scala/nl/lumc/sasc/biopet/utils/ToolCommand.scala
View file @
2540e8fd
...
...
@@ -25,7 +25,7 @@ trait ToolCommand extends MainCommand with Logging {
protected
abstract
class
AbstractArgs
{}
/**
* Abstract opt parser to add efault args to each biopet tool
* Abstract opt parser to add
d
efault args to each biopet tool
*/
protected
abstract
class
AbstractOptParser
extends
scopt
.
OptionParser
[
Args
](
commandName
)
{
opt
[
String
](
'l'
,
"log_level"
)
foreach
{
x
=>
...
...
biopet-utils/src/main/scala/nl/lumc/sasc/biopet/utils/VcfUtils.scala
View file @
2540e8fd
...
...
@@ -31,7 +31,7 @@ object VcfUtils {
* @param vcfRecord record to check
* @return allele with most nucleotides
*/
def
getLongestAllele
(
vcfRecord
:
VariantContext
)
=
{
def
getLongestAllele
(
vcfRecord
:
VariantContext
)
:
Allele
=
{
val
alleles
=
vcfRecord
.
getAlleles
val
longestAlleleId
=
alleles
.
map
(
_
.
getBases
.
length
).
zipWithIndex
.
maxBy
(
_
.
_1
).
_2
alleles
(
longestAlleleId
)
...
...
biopet-utils/src/main/scala/nl/lumc/sasc/biopet/utils/annotation/Feature.scala
View file @
2540e8fd
...
...
@@ -52,8 +52,8 @@ case class Feature(contig: String,
attributes
.
map
(
x
=>
x
.
_1
+
s
"=${x._2}"
).
mkString
(
";"
)
).
mkString
(
"\t"
)
def
minPosition
=
if
(
start
<
end
)
start
else
end
def
maxPosition
=
if
(
start
>
end
)
start
else
end
def
minPosition
:
Int
=
if
(
start
<
end
)
start
else
end
def
maxPosition
:
Int
=
if
(
start
>
end
)
start
else
end
}
object
Feature
{
...
...
@@ -72,11 +72,11 @@ object Feature {
s
"strand only allows '+' or '-', not ${values(6)}, gtf line: $line"
)
}
val
a
r
tibutes
=
values
.
lift
(
8
).
map
(
_
.
split
(
";"
)).
getOrElse
(
Array
()).
map
{
case
a
r
tibutesGtfRegex
(
key
,
value
)
=>
key
->
value
case
a
r
tibutesGffRegex
(
key
,
value
)
=>
key
->
value
val
at
tr
ibutes
=
values
.
lift
(
8
).
map
(
_
.
split
(
";"
)).
getOrElse
(
Array
()).
map
{
case
at
tr
ibutesGtfRegex
(
key
,
value
)
=>
key
->
value