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
16182a89
Commit
16182a89
authored
Oct 08, 2014
by
Peter van 't Hof
Browse files
Refactor code
parent
4e9e3cb6
Changes
1
Hide whitespace changes
Inline
Side-by-side
biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/BiopetExecutable.scala
View file @
16182a89
package
nl.lumc.sasc.biopet.core
import
nl.lumc.sasc.biopet.core.apps.WipeReads
import
nl.lumc.sasc.biopet.pipelines.bammetrics.BamMetrics
import
nl.lumc.sasc.biopet.pipelines.basty.Basty
import
nl.lumc.sasc.biopet.pipelines.flexiprep.Flexiprep
import
nl.lumc.sasc.biopet.pipelines.gatk.GatkBenchmarkGenotyping
import
nl.lumc.sasc.biopet.pipelines.gatk.GatkGenotyping
import
nl.lumc.sasc.biopet.pipelines.gatk.GatkPipeline
import
nl.lumc.sasc.biopet.pipelines.gatk.GatkVariantRecalibration
import
nl.lumc.sasc.biopet.pipelines.gatk.GatkVariantcalling
import
nl.lumc.sasc.biopet.pipelines.gatk.GatkVcfSampleCompare
import
nl.lumc.sasc.biopet.pipelines.gentrap.Gentrap
import
nl.lumc.sasc.biopet.pipelines.mapping.Mapping
import
nl.lumc.sasc.biopet.pipelines.sage.Sage
object
BiopetExecutable
{
val
pipelines
:
List
[
MainCommand
]
=
List
(
Flexiprep
,
Mapping
,
Gentrap
,
BamMetrics
,
GatkBenchmarkGenotyping
,
GatkGenotyping
,
GatkVariantcalling
,
GatkPipeline
,
GatkVariantRecalibration
,
GatkVcfSampleCompare
,
Sage
,
Basty
)
val
tools
:
List
[
MainCommand
]
=
List
(
WipeReads
)
val
modules
:
Map
[
String
,
List
[
MainCommand
]]
=
Map
(
"pipeline"
->
List
(
nl
.
lumc
.
sasc
.
biopet
.
pipelines
.
flexiprep
.
Flexiprep
,
nl
.
lumc
.
sasc
.
biopet
.
pipelines
.
mapping
.
Mapping
,
nl
.
lumc
.
sasc
.
biopet
.
pipelines
.
gentrap
.
Gentrap
,
nl
.
lumc
.
sasc
.
biopet
.
pipelines
.
bammetrics
.
BamMetrics
,
nl
.
lumc
.
sasc
.
biopet
.
pipelines
.
gatk
.
GatkBenchmarkGenotyping
,
nl
.
lumc
.
sasc
.
biopet
.
pipelines
.
gatk
.
GatkGenotyping
,
nl
.
lumc
.
sasc
.
biopet
.
pipelines
.
gatk
.
GatkVariantcalling
,
nl
.
lumc
.
sasc
.
biopet
.
pipelines
.
gatk
.
GatkPipeline
,
nl
.
lumc
.
sasc
.
biopet
.
pipelines
.
gatk
.
GatkVariantRecalibration
,
nl
.
lumc
.
sasc
.
biopet
.
pipelines
.
gatk
.
GatkVcfSampleCompare
,
nl
.
lumc
.
sasc
.
biopet
.
pipelines
.
sage
.
Sage
,
nl
.
lumc
.
sasc
.
biopet
.
pipelines
.
basty
.
Basty
),
"tool"
->
List
(
nl
.
lumc
.
sasc
.
biopet
.
core
.
apps
.
WipeReads
)
)
/**
* @param args the command line arguments
*/
def
main
(
args
:
Array
[
String
])
:
Unit
=
{
def
toBulletedList
(
m
:
List
[
MainCommand
],
kind
:
String
=
""
,
bullet
:
String
=
"-"
)
=
"Available %s:\n "
.
format
(
kind
)
+
bullet
+
" "
+
m
.
map
(
x
=>
x
.
name
).
sorted
.
mkString
(
"\n "
+
bullet
+
" "
)
lazy
val
pipelineList
:
String
=
toBulletedList
(
pipelines
,
"pipelines"
)
lazy
val
toolList
:
String
=
toBulletedList
(
tools
,
"tools"
)
lazy
val
addendum
:
String
=
"""Questions or comments? Email sasc@lumc.nl or check out the project page at https://git.lumc.nl/biopet/biopet.git"""
.
stripMargin
lazy
val
baseUsage
:
String
=
"Available %ss:\n "
.
format
(
kind
)
+
bullet
+
" "
+
m
.
map
(
x
=>
x
.
name
).
sorted
.
mkString
(
"\n "
+
bullet
+
" "
)
def
usage
(
module
:
String
=
null
)
:
String
=
{
if
(
module
!=
null
)
checkModule
(
module
)
val
usage
:
String
=
{
val
set
=
if
(
module
==
null
)
modules
.
keySet
else
Set
(
module
)
val
u
=
for
(
m
<-
set
)
yield
toBulletedList
(
modules
(
m
),
m
)
u
.
mkString
(
"\n\n"
)
}
"""
|Usage: java -jar BiopetFramework.jar {
pipeline,tool} {pipeline/tool name} {pipeline/tool-specific options}
|Usage: java -jar BiopetFramework.jar {
%s} <name> [args]
|
|%s
|
|%s
"""
.
stripMargin
.
format
(
"%s"
,
addendum
)
lazy
val
mainUsage
:
String
=
baseUsage
.
format
(
pipelineList
+
"\n\n"
+
toolList
)
lazy
val
pipelineUsage
:
String
=
baseUsage
.
replaceFirst
(
"""\{pipeline,tool\}"""
,
"pipeline"
)
.
replace
(
"""pipeline/tool"""
,
"pipeline"
)
.
format
(
pipelineList
)
lazy
val
toolUsage
:
String
=
baseUsage
.
replaceFirst
(
"""\{pipeline,tool\}"""
,
"tool"
)
.
replace
(
"""pipeline/tool"""
,
"tool"
)
.
format
(
toolList
)
if
(
args
.
isEmpty
)
{
System
.
err
.
println
(
mainUsage
)
System
.
exit
(
1
)
|Questions or comments? Email sasc@lumc.nl or check out the project page at https://git.lumc.nl/biopet/biopet.git
"""
.
stripMargin
.
format
(
modules
.
keys
.
mkString
(
","
),
usage
)
}
def
retrieveCommand
(
q
:
String
,
cl
:
List
[
MainCommand
])
:
Option
[
MainCommand
]
=
cl
match
{
case
head
::
tail
if
head
.
name
.
toLowerCase
==
q
=>
Some
(
head
)
case
Nil
=>
None
case
head
::
tail
=>
retrieveCommand
(
q
,
tail
)
def
checkModule
(
module
:
String
)
{
if
(!
modules
.
contains
(
module
))
{
System
.
err
.
println
(
s
"ERROR: module '$module' does not exist\n"
+
usage
())
System
.
exit
(
1
)
}
args
match
{
case
Array
(
"pipeline"
,
pipelineName
,
pipelineArgs
@
_
*)
=>
retrieveCommand
(
pipelineName
.
toLowerCase
,
pipelines
)
match
{
case
Some
(
pipeline
)
=>
pipeline
.
main
(
pipelineArgs
.
toArray
)
System
.
exit
(
0
)
case
None
=>
System
.
err
.
println
(
s
"ERROR: pipeline '$pipelineName' does not exist"
)
System
.
err
.
println
(
pipelineUsage
)
System
.
exit
(
1
)
}
case
Array
(
"pipeline"
)
=>
System
.
err
.
println
(
pipelineUsage
)
System
.
exit
(
1
)
case
Array
(
"tool"
,
toolName
,
toolArgs
@
_
*)
=>
retrieveCommand
(
toolName
.
toLowerCase
,
tools
)
match
{
case
Some
(
tool
)
=>
tool
.
main
(
toolArgs
.
toArray
)
System
.
exit
(
0
)
case
None
=>
System
.
err
.
println
(
s
"ERROR: tool '$toolName' does not exist"
)
System
.
err
.
println
(
toolUsage
)
System
.
exit
(
1
)
}
case
Array
(
"tool"
)
=>
System
.
err
.
println
(
toolUsage
)
System
.
exit
(
1
)
case
_
=>
println
(
mainUsage
)
}
def
getCommand
(
module
:
String
,
name
:
String
)
:
MainCommand
=
{
checkModule
(
module
)
val
command
=
modules
(
module
).
find
(
p
=>
p
.
name
.
toLowerCase
==
name
.
toLowerCase
)
if
(
command
==
None
)
{
System
.
err
.
println
(
s
"ERROR: command '$name' does not exist in module '$module'\n"
+
usage
(
module
))
System
.
exit
(
1
)
}
return
command
.
get
}
args
match
{
case
Array
(
module
,
name
,
passArgs
@
_
*)
=>
{
getCommand
(
module
,
name
).
main
(
passArgs
.
toArray
)
}
case
Array
(
module
)
=>
{
System
.
err
.
println
(
usage
(
module
))
System
.
exit
(
1
)
}
case
_
=>
{
System
.
err
.
println
(
usage
())
System
.
exit
(
1
)
}
}
}
}
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