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

[CANNOLI-110] Split commands with subcommands into separate Cannoli CLI classes. #117

Merged
merged 1 commit into from
Mar 22, 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
29 changes: 25 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@ Usage: cannoli-submit [<spark-args> --] <cannoli-args>
Choose one of the following commands:

CANNOLI
bedtools : ADAM Pipe API wrapper for Bedtools intersect.
bcftoolsNorm : ADAM Pipe API wrapper for BCFtools norm.
bedtoolsIntersect : ADAM Pipe API wrapper for Bedtools intersect.
bowtie : ADAM Pipe API wrapper for Bowtie.
bowtie2 : ADAM Pipe API wrapper for Bowtie2.
bowtie2 : ADAM Pipe API wrapper for Bowtie 2.
bwa : ADAM Pipe API wrapper for BWA.
freebayes : ADAM Pipe API wrapper for Freebayes.
samtoolsMpileup : ADAM Pipe API wrapper for samtools mpileup.
snpEff : ADAM Pipe API wrapper for SnpEff.
vtNormalize : ADAM Pipe API wrapper for vt normalize.

CANNOLI TOOLS
interleaveFastq : Interleaves two FASTQ files.
Expand All @@ -65,7 +68,7 @@ $ ./bin/cannoli-submit \
-add_indices
```

or can be run using Docker.
or can be run using Docker

```
$ ./bin/cannoli-submit \
Expand All @@ -79,6 +82,24 @@ $ ./bin/cannoli-submit \
-sequence_dictionary hg38.dict \
-fragments \
-use_docker \
-docker_image quay.io/ucsc_cgl/bwa:0.7.12--256539928ea162949d8a65ca5c79a72ef557ce7c \
-image quay.io/ucsc_cgl/bwa:0.7.12--256539928ea162949d8a65ca5c79a72ef557ce7c \
-add_indices
```

or can be run using Singularity

```
$ ./bin/cannoli-submit \
<spark-args>
-- \
bwa \
sample.unaligned.fragments.adam \
sample.bwa.hg38.alignments.adam \
sample \
-index hg38.fa \
-sequence_dictionary hg38.dict \
-fragments \
-use_singularity \
-image quay.io/ucsc_cgl/bwa:0.7.12--256539928ea162949d8a65ca5c79a72ef557ce7c \
-add_indices
```
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ import org.kohsuke.args4j.{ Argument, Option => Args4jOption }
import scala.collection.JavaConversions._

/**
* Bcftools function arguments.
* Bcftools norm function arguments.
*/
class BcftoolsFnArgs extends Args4jBase {
class BcftoolsNormFnArgs extends Args4jBase {
@Args4jOption(required = false, name = "-executable", usage = "Path to the BCFtools executable. Defaults to bcftools.")
var executable: String = "bcftools"

Expand All @@ -62,14 +62,14 @@ class BcftoolsFnArgs extends Args4jBase {
}

/**
* Bcftools wrapper as a function VariantContextRDD &rarr; VariantContextRDD,
* Bcftools norm wrapper as a function VariantContextRDD &rarr; VariantContextRDD,
* for use in cannoli-shell or notebooks.
*
* @param args Bcftools function arguments.
* @param args Bcftools norm function arguments.
* @param sc Spark context.
*/
class BcftoolsFn(
val args: BcftoolsFnArgs,
class BcftoolsNormFn(
val args: BcftoolsNormFnArgs,
sc: SparkContext) extends CannoliFn[VariantContextRDD, VariantContextRDD](sc) with Logging {

override def apply(variantContexts: VariantContextRDD): VariantContextRDD = {
Expand Down Expand Up @@ -105,19 +105,19 @@ class BcftoolsFn(
}
}

object Bcftools extends BDGCommandCompanion {
val commandName = "bcftools"
object BcftoolsNorm extends BDGCommandCompanion {
val commandName = "bcftoolsNorm"
val commandDescription = "ADAM Pipe API wrapper for BCFtools norm."

def apply(cmdLine: Array[String]) = {
new Bcftools(Args4j[BcftoolsArgs](cmdLine))
new BcftoolsNorm(Args4j[BcftoolsNormArgs](cmdLine))
}
}

/**
* Bcftools command line arguments.
* Bcftools norm command line arguments.
*/
class BcftoolsArgs extends BcftoolsFnArgs with ADAMSaveAnyArgs with ParquetArgs {
class BcftoolsNormArgs extends BcftoolsNormFnArgs with ADAMSaveAnyArgs with ParquetArgs {
@Argument(required = true, metaVar = "INPUT", usage = "Location to pipe from, in VCF format.", index = 0)
var inputPath: String = null

Expand All @@ -141,15 +141,15 @@ class BcftoolsArgs extends BcftoolsFnArgs with ADAMSaveAnyArgs with ParquetArgs
}

/**
* Bcftools command line wrapper.
* Bcftools norm command line wrapper.
*/
class Bcftools(protected val args: BcftoolsArgs) extends BDGSparkCommand[BcftoolsArgs] with Logging {
val companion = Bcftools
class BcftoolsNorm(protected val args: BcftoolsNormArgs) extends BDGSparkCommand[BcftoolsNormArgs] with Logging {
val companion = BcftoolsNorm
val stringency: ValidationStringency = ValidationStringency.valueOf(args.stringency)

def run(sc: SparkContext) {
val variantContexts = sc.loadVcf(args.inputPath, stringency = stringency)
val pipedVariantContexts = new BcftoolsFn(args, sc).apply(variantContexts)
val pipedVariantContexts = new BcftoolsNormFn(args, sc).apply(variantContexts)
pipedVariantContexts.saveAsVcf(args, stringency)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ import org.kohsuke.args4j.{ Argument, Option => Args4jOption }
import scala.collection.JavaConversions._

/**
* Bedtools function arguments.
* Bedtools intersect function arguments.
*/
class BedtoolsFnArgs extends Args4jBase {
class BedtoolsIntersectFnArgs extends Args4jBase {
@Args4jOption(required = false, name = "-a", usage = "Bedtools intersect -a option. One of {-a,-b} should be left unspecified to accept piped input.")
var a: String = null

Expand Down Expand Up @@ -68,22 +68,22 @@ class BedtoolsFnArgs extends Args4jBase {
}

/**
* Bedtools wrapper as a function FeatureRDD &rarr; FeatureRDD,
* Bedtools intersect wrapper as a function FeatureRDD &rarr; FeatureRDD,
* for use in cannoli-shell or notebooks.
*
* <code>
* val args = new BedtoolsFnArgs()
* val args = new BedtoolsIntersectFnArgs()
* args.b = "foo.bed"
* args.useDocker = true
* val features = ...
* val pipedFeatures = new BedtoolsFn(args, sc).apply(features)
* val pipedFeatures = new BedtoolsIntersectFn(args, sc).apply(features)
* </code>
*
* @param args Bedtools function arguments.
* @param args Bedtools intersect function arguments.
* @param sc Spark context.
*/
class BedtoolsFn(
val args: BedtoolsFnArgs,
class BedtoolsIntersectFn(
val args: BedtoolsIntersectFnArgs,
sc: SparkContext) extends CannoliFn[FeatureRDD, FeatureRDD](sc) with Logging {

override def apply(features: FeatureRDD): FeatureRDD = {
Expand Down Expand Up @@ -125,19 +125,19 @@ class BedtoolsFn(
}
}

object Bedtools extends BDGCommandCompanion {
val commandName = "bedtools"
object BedtoolsIntersect extends BDGCommandCompanion {
val commandName = "bedtoolsIntersect"
val commandDescription = "ADAM Pipe API wrapper for Bedtools intersect."

def apply(cmdLine: Array[String]) = {
new Bedtools(Args4j[BedtoolsArgs](cmdLine))
new BedtoolsIntersect(Args4j[BedtoolsIntersectArgs](cmdLine))
}
}

/**
* Bedtools command line arguments.
* Bedtools intersect command line arguments.
*/
class BedtoolsArgs extends BedtoolsFnArgs with ADAMSaveAnyArgs with ParquetArgs {
class BedtoolsIntersectArgs extends BedtoolsIntersectFnArgs with ADAMSaveAnyArgs with ParquetArgs {
@Argument(required = true, metaVar = "INPUT", usage = "Location to pipe features from (e.g., .bed, .gff/.gtf, .gff3, .interval_list, .narrowPeak). If extension is not detected, Parquet is assumed.", index = 0)
var inputPath: String = null

Expand All @@ -164,10 +164,10 @@ class BedtoolsArgs extends BedtoolsFnArgs with ADAMSaveAnyArgs with ParquetArgs
}

/**
* Bedtools command line wrapper.
* Bedtools intersect command line wrapper.
*/
class Bedtools(protected val args: BedtoolsArgs) extends BDGSparkCommand[BedtoolsArgs] with Logging {
val companion = Bedtools
class BedtoolsIntersect(protected val args: BedtoolsIntersectArgs) extends BDGSparkCommand[BedtoolsIntersectArgs] with Logging {
val companion = BedtoolsIntersect

override def run(sc: SparkContext) {
val projection = Projection(
Expand All @@ -184,7 +184,7 @@ class Bedtools(protected val args: BedtoolsArgs) extends BDGSparkCommand[Bedtool
optMinPartitions = Option(args.partitions),
optProjection = if (args.limitProjection) Some(projection) else None
)
val pipedFeatures = new BedtoolsFn(args, sc).apply(features)
val pipedFeatures = new BedtoolsIntersectFn(args, sc).apply(features)

pipedFeatures.save(args.outputPath,
asSingleFile = args.asSingleFile,
Expand Down
8 changes: 4 additions & 4 deletions cli/src/main/scala/org/bdgenomics/cannoli/cli/Cannoli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ import org.bdgenomics.utils.cli._

object Cannoli {

val defaultCommandGroups = List(CommandGroup("CANNOLI", List(Bcftools,
Bedtools,
val defaultCommandGroups = List(CommandGroup("CANNOLI", List(BcftoolsNorm,
BedtoolsIntersect,
Bowtie,
Bowtie2,
Bwa,
Freebayes,
Samtools,
SamtoolsMpileup,
SnpEff,
Vt)),
VtNormalize)),
CommandGroup("CANNOLI TOOLS", List(InterleaveFastq,
SampleReads)))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ import org.kohsuke.args4j.{ Argument, Option => Args4jOption }
import scala.collection.JavaConversions._

/**
* Samtools function arguments.
* Samtools mpileup function arguments.
*/
class SamtoolsFnArgs extends Args4jBase {
class SamtoolsMpileupFnArgs extends Args4jBase {
@Args4jOption(required = false, name = "-executable", usage = "Path to the samtools executable. Defaults to samtools.")
var executable: String = "samtools"

Expand All @@ -60,14 +60,14 @@ class SamtoolsFnArgs extends Args4jBase {
}

/**
* Samtools wrapper as a function AlignmentRecordRDD &rarr; VariantContextRDD,
* Samtools mpileup wrapper as a function AlignmentRecordRDD &rarr; VariantContextRDD,
* for use in cannoli-shell or notebooks.
*
* @param args Samtools function arguments.
* @param args Samtools mpileup function arguments.
* @param sc Spark context.
*/
class SamtoolsFn(
val args: SamtoolsFnArgs,
class SamtoolsMpileupFn(
val args: SamtoolsMpileupFnArgs,
sc: SparkContext) extends CannoliFn[AlignmentRecordRDD, VariantContextRDD](sc) with Logging {

override def apply(alignments: AlignmentRecordRDD): VariantContextRDD = {
Expand Down Expand Up @@ -106,19 +106,19 @@ class SamtoolsFn(
}
}

object Samtools extends BDGCommandCompanion {
val commandName = "samtools"
object SamtoolsMpileup extends BDGCommandCompanion {
val commandName = "samtoolsMpileup"
val commandDescription = "ADAM Pipe API wrapper for samtools mpileup."

def apply(cmdLine: Array[String]) = {
new Samtools(Args4j[SamtoolsArgs](cmdLine))
new SamtoolsMpileup(Args4j[SamtoolsMpileupArgs](cmdLine))
}
}

/**
* Samtools command line arguments.
* Samtools mpileup command line arguments.
*/
class SamtoolsArgs extends SamtoolsFnArgs with ADAMSaveAnyArgs with ParquetArgs {
class SamtoolsMpileupArgs extends SamtoolsMpileupFnArgs with ADAMSaveAnyArgs with ParquetArgs {
@Argument(required = true, metaVar = "INPUT", usage = "Location to pipe alignment records from (e.g. .bam, .cram, .sam). If extension is not detected, Parquet is assumed.", index = 0)
var inputPath: String = null

Expand All @@ -142,15 +142,15 @@ class SamtoolsArgs extends SamtoolsFnArgs with ADAMSaveAnyArgs with ParquetArgs
}

/**
* Samtools command line wrapper.
* Samtools mpileup command line wrapper.
*/
class Samtools(protected val args: SamtoolsArgs) extends BDGSparkCommand[SamtoolsArgs] with Logging {
val companion = Samtools
class SamtoolsMpileup(protected val args: SamtoolsMpileupArgs) extends BDGSparkCommand[SamtoolsMpileupArgs] with Logging {
val companion = SamtoolsMpileup
val stringency: ValidationStringency = ValidationStringency.valueOf(args.stringency)

def run(sc: SparkContext) {
val alignments = sc.loadAlignments(args.inputPath, stringency = stringency)
val variantContexts = new SamtoolsFn(args, sc).apply(alignments)
val variantContexts = new SamtoolsMpileupFn(args, sc).apply(alignments)

if (isVcfExt(args.outputPath)) {
variantContexts.saveAsVcf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ import org.kohsuke.args4j.{ Argument, Option => Args4jOption }
import scala.collection.JavaConversions._

/**
* Vt function arguments.
* Vt normalize function arguments.
*/
class VtFnArgs extends Args4jBase {
class VtNormalizeFnArgs extends Args4jBase {
@Args4jOption(required = false, name = "-executable", usage = "Path to the vt executable. Defaults to vt.")
var executable: String = "vt"

Expand All @@ -65,14 +65,14 @@ class VtFnArgs extends Args4jBase {
}

/**
* Vt wrapper as a function VariantContextRDD &rarr; VariantContextRDD,
* Vt normalize wrapper as a function VariantContextRDD &rarr; VariantContextRDD,
* for use in cannoli-shell or notebooks.
*
* @param args Vt function arguments.
* @param args Vt normalize function arguments.
* @param sc Spark context.
*/
class VtFn(
val args: VtFnArgs,
class VtNormalizeFn(
val args: VtNormalizeFnArgs,
sc: SparkContext) extends CannoliFn[VariantContextRDD, VariantContextRDD](sc) with Logging {

override def apply(variantContexts: VariantContextRDD): VariantContextRDD = {
Expand Down Expand Up @@ -108,19 +108,19 @@ class VtFn(
}
}

object Vt extends BDGCommandCompanion {
val commandName = "vt"
object VtNormalize extends BDGCommandCompanion {
val commandName = "vtNormalize"
val commandDescription = "ADAM Pipe API wrapper for vt normalize."

def apply(cmdLine: Array[String]) = {
new Vt(Args4j[VtArgs](cmdLine))
new VtNormalize(Args4j[VtNormalizeArgs](cmdLine))
}
}

/**
* Vt command line arguments.
* Vt normalize command line arguments.
*/
class VtArgs extends VtFnArgs with ADAMSaveAnyArgs with ParquetArgs {
class VtNormalizeArgs extends VtNormalizeFnArgs with ADAMSaveAnyArgs with ParquetArgs {
@Argument(required = true, metaVar = "INPUT", usage = "Location to pipe from, in VCF format.", index = 0)
var inputPath: String = null

Expand All @@ -144,15 +144,15 @@ class VtArgs extends VtFnArgs with ADAMSaveAnyArgs with ParquetArgs {
}

/**
* Vt command line wrapper.
* Vt normalize command line wrapper.
*/
class Vt(protected val args: VtArgs) extends BDGSparkCommand[VtArgs] with Logging {
val companion = Vt
class VtNormalize(protected val args: VtNormalizeArgs) extends BDGSparkCommand[VtNormalizeArgs] with Logging {
val companion = VtNormalize
val stringency: ValidationStringency = ValidationStringency.valueOf(args.stringency)

def run(sc: SparkContext) {
val variantContexts = sc.loadVcf(args.inputPath, stringency = stringency)
val pipedVariantContexts = new VtFn(args, sc).apply(variantContexts)
val pipedVariantContexts = new VtNormalizeFn(args, sc).apply(variantContexts)
pipedVariantContexts.saveAsVcf(args, stringency)
}
}