Skip to content

Commit

Permalink
Add docker support to bowtie and bowtie2.
Browse files Browse the repository at this point in the history
  • Loading branch information
heuermh committed Oct 27, 2017
1 parent ad8cbaa commit a894bc8
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 10 deletions.
30 changes: 25 additions & 5 deletions cli/src/main/scala/org/bdgenomics/cannoli/cli/Bowtie.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ class BowtieArgs extends Args4jBase with ADAMSaveAnyArgs with ParquetArgs {
@Args4jOption(required = false, name = "-bowtie_path", usage = "Path to the Bowtie executable. Defaults to bowtie.")
var bowtiePath: String = "bowtie"

@Args4jOption(required = false, name = "-docker_image", usage = "Docker image to use. Defaults to heuermh/bowtie.")
var dockerImage: String = "heuermh/bowtie"

@Args4jOption(required = false, name = "-use_docker", usage = "If true, uses Docker to launch Bowtie. If false, uses the Bowtie executable path.")
var useDocker: Boolean = false

@Args4jOption(required = true, name = "-bowtie_index", usage = "Basename of the bowtie index to be searched, e.g. <ebwt> in bowtie [options]* <ebwt> ...")
var indexPath: String = null

Expand Down Expand Up @@ -79,11 +85,25 @@ class Bowtie(protected val args: BowtieArgs) extends BDGSparkCommand[BowtieArgs]
implicit val tFormatter = Tab5InFormatter
implicit val uFormatter = new AnySAMOutFormatter

val bowtieCommand = Seq(args.bowtiePath,
"-S",
args.indexPath,
"--12",
"-").mkString(" ")
val bowtieCommand = if (args.useDocker) {
Seq("docker",
"run",
"--rm",
args.dockerImage,
"bowtie",
"-S",
args.indexPath,
"--12",
"-"
).mkString(" ")
} else {
Seq(args.bowtiePath,
"-S",
args.indexPath,
"--12",
"-"
).mkString(" ")
}
val output: AlignmentRecordRDD = input.pipe[AlignmentRecord, AlignmentRecordRDD, Tab5InFormatter](bowtieCommand)
output.save(args)
}
Expand Down
35 changes: 30 additions & 5 deletions cli/src/main/scala/org/bdgenomics/cannoli/cli/Bowtie2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import org.kohsuke.args4j.{ Argument, Option => Args4jOption }

object Bowtie2 extends BDGCommandCompanion {
val commandName = "bowtie2"
val commandDescription = "ADAM Pipe API wrapper for Bowtie2."
val commandDescription = "ADAM Pipe API wrapper for Bowtie 2."

def apply(cmdLine: Array[String]) = {
new Bowtie2(Args4j[Bowtie2Args](cmdLine))
Expand All @@ -44,6 +44,15 @@ class Bowtie2Args extends Args4jBase with ADAMSaveAnyArgs with ParquetArgs {
@Argument(required = true, metaVar = "OUTPUT", usage = "Location to pipe to.", index = 1)
var outputPath: String = null

@Args4jOption(required = false, name = "-bowtie2_path", usage = "Path to the Bowtie 2 executable. Defaults to bowtie2.")
var bowtie2Path: String = "bowtie2"

@Args4jOption(required = false, name = "-docker_image", usage = "Docker image to use. Defaults to heuermh/bowtie2.")
var dockerImage: String = "heuermh/bowtie2"

@Args4jOption(required = false, name = "-use_docker", usage = "If true, uses Docker to launch Bowtie 2. If false, uses the Bowtie 2 executable path.")
var useDocker: Boolean = false

@Args4jOption(required = true, name = "-bowtie2_index", usage = "Basename of the index for the reference genome, e.g. <bt2-idx> in bowtie2 [options]* -x <bt2-idx>.")
var indexPath: String = null

Expand All @@ -64,7 +73,7 @@ class Bowtie2Args extends Args4jBase with ADAMSaveAnyArgs with ParquetArgs {
}

/**
* Bowtie2.
* Bowtie 2.
*/
class Bowtie2(protected val args: Bowtie2Args) extends BDGSparkCommand[Bowtie2Args] with Logging {
val companion = Bowtie2
Expand All @@ -76,10 +85,26 @@ class Bowtie2(protected val args: Bowtie2Args) extends BDGSparkCommand[Bowtie2Ar
implicit val tFormatter = InterleavedFASTQInFormatter
implicit val uFormatter = new AnySAMOutFormatter

val bowtie2Command = "bowtie2 -x " + args.indexPath + " --interleaved -"
val bowtie2Command = if (args.useDocker) {
Seq("docker",
"run",
"--rm",
args.dockerImage,
"bowtie2",
"-x",
args.indexPath,
"--interleaved",
"-"
).mkString(" ")
} else {
Seq(args.bowtie2Path,
"-x",
args.indexPath,
"--interleaved",
"-"
).mkString(" ")
}
val output: AlignmentRecordRDD = input.pipe[AlignmentRecord, AlignmentRecordRDD, InterleavedFASTQInFormatter](bowtie2Command)
.transform(_.cache())

output.save(args)
}
}

0 comments on commit a894bc8

Please sign in to comment.