Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docker support to bowtie and bowtie2. #81

Merged
merged 2 commits into from
Jan 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions cli/src/main/scala/org/bdgenomics/cannoli/cli/Bowtie.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import htsjdk.samtools.ValidationStringency
import org.apache.spark.SparkContext
import org.bdgenomics.adam.rdd.ADAMContext._
import org.bdgenomics.adam.rdd.ADAMSaveAnyArgs
import org.bdgenomics.adam.rdd.fragment.{ FragmentRDD, Tab5InFormatter }
import org.bdgenomics.adam.rdd.fragment.{ FragmentRDD, InterleavedFASTQInFormatter }
import org.bdgenomics.adam.rdd.read.{ AlignmentRecordRDD, AnySAMOutFormatter }
import org.bdgenomics.formats.avro.AlignmentRecord
import org.bdgenomics.utils.cli._
Expand All @@ -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 quay.io/biocontainers/bowtie.")
var dockerImage: String = "quay.io/biocontainers/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 @@ -76,15 +82,30 @@ class Bowtie(protected val args: BowtieArgs) extends BDGSparkCommand[BowtieArgs]
def run(sc: SparkContext) {
val input: FragmentRDD = sc.loadFragments(args.inputPath)

implicit val tFormatter = Tab5InFormatter
implicit val tFormatter = InterleavedFASTQInFormatter
implicit val uFormatter = new AnySAMOutFormatter

val bowtieCommand = Seq(args.bowtiePath,
"-S",
args.indexPath,
"--12",
"-").mkString(" ")
val output: AlignmentRecordRDD = input.pipe[AlignmentRecord, AlignmentRecordRDD, Tab5InFormatter](bowtieCommand)
val bowtieCommand = if (args.useDocker) {
Seq("docker",
"run",
"--interactive",
"--rm",
args.dockerImage,
"bowtie",
"-S",
args.indexPath,
"--interleaved",
"-"
).mkString(" ")
} else {
Seq(args.bowtiePath,
"-S",
args.indexPath,
"--interleaved",
"-"
).mkString(" ")
}
val output: AlignmentRecordRDD = input.pipe[AlignmentRecord, AlignmentRecordRDD, InterleavedFASTQInFormatter](bowtieCommand)
output.save(args)
}
}
36 changes: 31 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 quay.io/biocontainers/bowtie2.")
var dockerImage: String = "quay.io/biocontainers/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,27 @@ 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",
"--interactive",
"--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)
}
}