From fd5970fdd46880dea32a865901c8e7b57b151767 Mon Sep 17 00:00:00 2001 From: kshakir Date: Thu, 2 Sep 2010 21:30:48 +0000 Subject: [PATCH] At chartl's superb suggestion, command line files are now all Files instead of old method of sometimes "has a File". Should be easier when reassigning them. No longer generating deprecated GATK arguments on the Queue extensions. Emitting deprecation warnings to Queue compile to help debugging issues. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@4195 348d0f76-0448-11de-a6fe-93d51630548a --- .../gatk/ArgumentDefinitionField.java | 21 +++++----- .../depristo/manySampleUGPerformance.scala | 8 ++-- .../qscript/examples/ExampleCountReads.scala | 2 +- .../examples/ExampleUnifiedGenotyper.scala | 2 +- scala/qscript/fullCallingPipeline.q | 22 +++++------ scala/qscript/kshakir/CleanBamFile.scala | 12 ++---- scala/qscript/recalibrate.scala | 3 +- .../qscript/rpoplin/variantRecalibrator.scala | 9 ++--- .../sting/queue/QScriptManager.scala | 1 + .../queue/extensions/gatk/NamedFile.scala | 35 ----------------- .../extensions/gatk/NamedFileWrapper.scala | 8 ---- .../sting/queue/extensions/gatk/RodBind.scala | 14 +++++-- .../queue/extensions/gatk/TaggedFile.scala | 39 +++++++++++++++++++ .../sting/queue/extensions/gatk/package.scala | 13 ------- .../queue/function/CommandLineFunction.scala | 37 +++++++++++------- .../sting/queue/function/FileExtension.scala | 15 +++++++ .../sting/queue/function/FileProvider.scala | 11 ------ 17 files changed, 125 insertions(+), 127 deletions(-) delete mode 100644 scala/src/org/broadinstitute/sting/queue/extensions/gatk/NamedFile.scala delete mode 100644 scala/src/org/broadinstitute/sting/queue/extensions/gatk/NamedFileWrapper.scala create mode 100644 scala/src/org/broadinstitute/sting/queue/extensions/gatk/TaggedFile.scala delete mode 100644 scala/src/org/broadinstitute/sting/queue/extensions/gatk/package.scala create mode 100644 scala/src/org/broadinstitute/sting/queue/function/FileExtension.scala delete mode 100644 scala/src/org/broadinstitute/sting/queue/function/FileProvider.scala diff --git a/java/src/org/broadinstitute/sting/queue/extensions/gatk/ArgumentDefinitionField.java b/java/src/org/broadinstitute/sting/queue/extensions/gatk/ArgumentDefinitionField.java index 6d460185a..8e1324ebe 100644 --- a/java/src/org/broadinstitute/sting/queue/extensions/gatk/ArgumentDefinitionField.java +++ b/java/src/org/broadinstitute/sting/queue/extensions/gatk/ArgumentDefinitionField.java @@ -110,8 +110,9 @@ public abstract class ArgumentDefinitionField extends ArgumentField { public static List getArgumentFields(Class classType) { List argumentFields = new ArrayList(); for (ArgumentSource argumentSource: ParsingEngine.extractArgumentSources(classType)) - for (ArgumentDefinition argumentDefinition: argumentSource.createArgumentDefinitions()) - argumentFields.addAll(getArgumentFields(argumentDefinition)); + if (!argumentSource.isDeprecated()) + for (ArgumentDefinition argumentDefinition: argumentSource.createArgumentDefinitions()) + argumentFields.addAll(getArgumentFields(argumentDefinition)); return argumentFields; } @@ -131,7 +132,7 @@ public abstract class ArgumentDefinitionField extends ArgumentField { //return Collections.emptyList(); } else if ("input_file".equals(argumentDefinition.fullName) && argumentDefinition.ioType == ArgumentIOType.INPUT) { - return Arrays.asList(new InputNamedFileDefinitionField(argumentDefinition), new IndexFilesField()); + return Arrays.asList(new InputTaggedFileDefinitionField(argumentDefinition), new IndexFilesField()); } else if (argumentDefinition.ioType == ArgumentIOType.INPUT) { return Collections.singletonList(new InputArgumentField(argumentDefinition)); @@ -327,15 +328,15 @@ public abstract class ArgumentDefinitionField extends ArgumentField { /** * Named input_files. */ - public static class InputNamedFileDefinitionField extends ArgumentDefinitionField { - public InputNamedFileDefinitionField(ArgumentDefinition argumentDefinition) { + public static class InputTaggedFileDefinitionField extends ArgumentDefinitionField { + public InputTaggedFileDefinitionField(ArgumentDefinition argumentDefinition) { super(argumentDefinition); } - @Override protected Class getInnerType() { return null; } // NamedFile does not need to be imported. - @Override protected String getFieldType() { return "List[NamedFile]"; } + @Override protected Class getInnerType() { return null; } // TaggedFile does not need to be imported. + @Override protected String getFieldType() { return "List[File]"; } @Override protected String getDefaultValue() { return "Nil"; } @Override protected String getCommandLineTemplate() { - return " + repeat(\"\", %3$s, format=NamedFile.formatCommandLine(\"%1$s\"))"; + return " + repeat(\"\", %3$s, format=TaggedFile.formatCommandLine(\"%1$s\"))"; } } @@ -354,8 +355,8 @@ public abstract class ArgumentDefinitionField extends ArgumentField { @Override protected String getRawFieldName() { return "index_files"; } @Override protected String getFreezeFields() { return String.format( - "index_files ++= input_file.filter(bam => bam != null && bam.file.getName.endsWith(\".bam\")).map(bam => new File(bam.file.getPath + \".bai\"))%n" + - "index_files ++= input_file.filter(sam => sam != null && sam.file.getName.endsWith(\".sam\")).map(sam => new File(sam.file.getPath + \".sai\"))%n"); + "index_files ++= input_file.filter(bam => bam != null && bam.getName.endsWith(\".bam\")).map(bam => new File(bam.getPath + \".bai\"))%n" + + "index_files ++= input_file.filter(sam => sam != null && sam.getName.endsWith(\".sam\")).map(sam => new File(sam.getPath + \".sai\"))%n"); } } diff --git a/scala/qscript/depristo/manySampleUGPerformance.scala b/scala/qscript/depristo/manySampleUGPerformance.scala index df1be75a8..a985024b2 100755 --- a/scala/qscript/depristo/manySampleUGPerformance.scala +++ b/scala/qscript/depristo/manySampleUGPerformance.scala @@ -44,20 +44,20 @@ class Index(bamIn: File) extends SamtoolsIndexFunction { class MergeBAMs(bamList: File) extends PrintReads with UNIVERSAL_GATK_ARGS { this.memoryLimit = Some(3) - this.input_file :+= bamList.toNamedFile + this.input_file :+= bamList this.o = new File(MERGED_DIR + "/" + bamList.getName + ".bam") } -class Call(@Input(doc="foo") bamList: File, n: Integer, name: String) extends UnifiedGenotyper with UNIVERSAL_GATK_ARGS { +class Call(@Input(doc="foo") bamList: File, n: Int, name: String) extends UnifiedGenotyper with UNIVERSAL_GATK_ARGS { @Output(doc="foo") var outVCF: File = new File("%s.%d.%s.vcf".format(bamList.getName, n, name)) this.memoryLimit = Some(4) - this.input_file :+= bamList.toNamedFile + this.input_file :+= bamList this.jobQueue = "gsa" this.stand_call_conf = Option(10.0) this.o = outVCF } -class SliceList(n: Integer) extends CommandLineFunction { +class SliceList(n: Int) extends CommandLineFunction { @Output(doc="foo") var list: File = new File("bams.%d.list".format(n)) this.jobQueue = "gsa" def commandLine = "head -n %d %s > %s".format(n, FULL_BAM_LIST, list) diff --git a/scala/qscript/examples/ExampleCountReads.scala b/scala/qscript/examples/ExampleCountReads.scala index b000c9c91..c02362fa5 100644 --- a/scala/qscript/examples/ExampleCountReads.scala +++ b/scala/qscript/examples/ExampleCountReads.scala @@ -55,7 +55,7 @@ class ExampleCountReads extends QScript { singleCountReads.jarFile = gatkJar singleCountReads.reference_sequence = referenceFile // ':+' is the scala List append operator - singleCountReads.input_file :+= bamFile.toNamedFile + singleCountReads.input_file :+= bamFile add(singleCountReads) } } diff --git a/scala/qscript/examples/ExampleUnifiedGenotyper.scala b/scala/qscript/examples/ExampleUnifiedGenotyper.scala index 8c4f803e2..407268b2e 100644 --- a/scala/qscript/examples/ExampleUnifiedGenotyper.scala +++ b/scala/qscript/examples/ExampleUnifiedGenotyper.scala @@ -58,7 +58,7 @@ class ExampleUnifiedGenotyper extends QScript { // If you are running this on a compute farm, make sure that the Sting/shell // folder is in your path to use mergeText.sh and splitIntervals.sh. genotyper.scatterCount = 3 - genotyper.input_file :+= qscript.bamFile.toNamedFile + genotyper.input_file :+= qscript.bamFile genotyper.out = swapExt(qscript.bamFile, "bam", "unfiltered.vcf") evalUnfiltered.rodBind :+= RodBind("vcf", "VCF", genotyper.out) diff --git a/scala/qscript/fullCallingPipeline.q b/scala/qscript/fullCallingPipeline.q index a75c1f107..e3ab08822 100755 --- a/scala/qscript/fullCallingPipeline.q +++ b/scala/qscript/fullCallingPipeline.q @@ -80,7 +80,7 @@ class fullCallingPipeline extends QScript { val cleanedBase: String = projectBase + ".cleaned" val uncleanedBase: String = projectBase + ".uncleaned" // there are commands that use all the bam files - var cleanBamFiles = List.empty[NamedFile] + var cleanBamFiles = List.empty[File] for ( bam <- qscript.bamFiles ) { @@ -94,7 +94,7 @@ class fullCallingPipeline extends QScript { // create the cleaning commands val targetCreator = new RealignerTargetCreator with CommandLineGATKArgs - targetCreator.input_file :+= bam.toNamedFile + targetCreator.input_file :+= bam targetCreator.out = indel_targets val realigner = new IndelRealigner with CommandLineGATKArgs @@ -112,7 +112,7 @@ class fullCallingPipeline extends QScript { // put clean bams in clean genotypers - cleanBamFiles :+= realigner.out.toNamedFile + cleanBamFiles :+= realigner.out add(targetCreator,realigner,samtoolsindex) } @@ -122,7 +122,7 @@ class fullCallingPipeline extends QScript { endToEnd(cleanedBase,cleanBamFiles) } - def endToEnd(base: String, bamFiles: List[NamedFile]) = { + def endToEnd(base: String, bamFiles: List[File]) = { // step through the un-indel-cleaned graph: // 1a. call snps and indels @@ -158,7 +158,7 @@ class fullCallingPipeline extends QScript { var priority = "" for ( bam <- bamFiles ) { val indel = new IndelGenotyperV2 with CommandLineGATKArgs - indel.input_file :+= bam.toNamedFile + indel.input_file :+= bam indel.out = swapExt(bam,".bam",".indels.vcf") indel.downsample_to_coverage = Some(500) indelCallFiles :+= RodBind("v"+loopNo.toString, "VCF", indel.out) @@ -186,28 +186,28 @@ class fullCallingPipeline extends QScript { annotated.rodBind :+= RodBind("variant", "VCF", snps.out) annotated.rodBind :+= RodBind("refseq", "AnnotatorInputTable", qscript.refseqTable) annotated.rodBind :+= RodBind("dbsnp", "AnnotatorInputTable", qscript.dbsnpTable) - annotated.vcfOutput = swapExt(snps.out,".vcf",".annotated.vcf").getAbsolutePath + annotated.out = swapExt(snps.out,".vcf",".annotated.vcf") annotated.select :+= "dbsnp.name,dbsnp.refUCSC,dbsnp.strand,dbsnp.observed,dbsnp.avHet" annotated.rodToIntervalTrackName = "variant" // 2.a filter on cluster and near indels val masker = new VariantFiltration with CommandLineGATKArgs - masker.rodBind :+= RodBind("variant", "VCF", new File(annotated.vcfOutput)) - masker.rodBind :+= RodBind("mask", "VCF", new File(mergeIndels.out.getAbsolutePath)) + masker.rodBind :+= RodBind("variant", "VCF", annotated.out) + masker.rodBind :+= RodBind("mask", "VCF", mergeIndels.out) masker.maskName = "NearIndel" masker.clusterWindowSize = Some(qscript.snpClusterWindow) masker.clusterSize = Some(qscript.snpsInCluster) - masker.out = swapExt(new File(annotated.vcfOutput),".vcf",".indel.masked.vcf") + masker.out = swapExt(annotated.out,".vcf",".indel.masked.vcf") // 2.b hand filter with standard filter val handFilter = new VariantFiltration with CommandLineGATKArgs - handFilter.rodBind :+= RodBind("variant", "VCF", new File(annotated.vcfOutput)) + handFilter.rodBind :+= RodBind("variant", "VCF", annotated.out) handFilter.rodBind :+= RodBind("mask", "VCF", mergeIndels.out) handFilter.filterName ++= List("StrandBias","AlleleBalance","QualByDepth","HomopolymerRun") handFilter.filterExpression ++= List("\"SB>=0.10\"","\"AB>=0.75\"","QD<5","\"HRun>=4\"") - handFilter.out = swapExt(new File(annotated.vcfOutput),".vcf",".handfiltered.vcf") + handFilter.out = swapExt(annotated.out,".vcf",".handfiltered.vcf") // 3.i generate gaussian clusters on the masked vcf diff --git a/scala/qscript/kshakir/CleanBamFile.scala b/scala/qscript/kshakir/CleanBamFile.scala index 8a1d4d70e..cf2f4c32e 100644 --- a/scala/qscript/kshakir/CleanBamFile.scala +++ b/scala/qscript/kshakir/CleanBamFile.scala @@ -131,16 +131,12 @@ class CleanBamFile extends QScript { var fixedBam: File = null if (realigner.scatterCount > 1) { - realigner.output = baseFile(".cleaned.bam") + realigner.out = baseFile(".cleaned.bam") // While gathering run fix mates. realigner.setupScatterFunction = { case (scatter: IntervalScatterFunction, _) => scatter.splitIntervalsScript = indelRealignerScatterScript } - realigner.gatherClass = { - case source if (source.field.getName=="output") => - classOf[BamGatherFunction] - } realigner.setupGatherFunction = { case (gather: BamGatherFunction, _) => gather.memoryLimit = Some(4) @@ -151,9 +147,9 @@ class CleanBamFile extends QScript { gather.mergeTextScript = mergeTextScript } - fixedBam = realigner.output + fixedBam = realigner.out } else { - realigner.output = baseFile(".unfixed.cleaned.bam") + realigner.out = baseFile(".unfixed.cleaned.bam") // Explicitly run fix mates if the function won't be scattered. var fixMates = new PicardBamJarFunction { @@ -165,7 +161,7 @@ class CleanBamFile extends QScript { } fixMates.memoryLimit = Some(4) fixMates.jarFile = fixMatesJar - fixMates.unfixed = realigner.output + fixMates.unfixed = realigner.out fixMates.fixed = baseFile(".cleaned.bam") fixedBam = fixMates.fixed diff --git a/scala/qscript/recalibrate.scala b/scala/qscript/recalibrate.scala index f1211283b..25c6b2422 100755 --- a/scala/qscript/recalibrate.scala +++ b/scala/qscript/recalibrate.scala @@ -64,7 +64,6 @@ class CountCovariates(bamIn: File, recalDataIn: File) extends org.broadinstitute this.recal_file = recalDataIn this.DBSNP = new File("/humgen/gsa-hpprojects/GATK/data/dbsnp_129_hg18.rod") this.logging_level = "INFO" - this.max_reads_at_locus = Some(20000) this.covariate ++= List("ReadGroupCovariate", "QualityScoreCovariate", "CycleCovariate", "DinucCovariate") this.memoryLimit = Some(3) @@ -75,7 +74,7 @@ class TableRecalibrate(bamInArg: File, recalDataIn: File, bamOutArg: File) exten this.jarFile = gatkJarFile this.input_file :+= bamInArg this.recal_file = recalDataIn - this.output_bam = bamOutArg + this.out = bamOutArg this.logging_level = "INFO" this.memoryLimit = Some(2) this.skipUQUpdate = skipUQUpdateArg diff --git a/scala/qscript/rpoplin/variantRecalibrator.scala b/scala/qscript/rpoplin/variantRecalibrator.scala index 21a267465..4ec898ba8 100755 --- a/scala/qscript/rpoplin/variantRecalibrator.scala +++ b/scala/qscript/rpoplin/variantRecalibrator.scala @@ -26,24 +26,23 @@ for (g: Int <- gList) { gvc.logging_level = "INFO" gvc.intervalsString :+= "20" gvc.use_annotation ++= List("QD", "SB", "HaplotypeScore", "HRun") - gvc.path_to_resources = "/humgen/gsa-scr1/rpoplin/sting_dev_vb/R/" gvc.maxGaussians = Some(g) gvc.shrinkage = Some(s) gvc.shrinkageFormat = "%.6f" gvc.dirichlet = Some(d) gvc.dirichletFormat = "%.6f" - gvc.clusterFile = "g%d_s%.6f_d%.6f_b%.2f.cluster".format(g,s,d,b) - gvc.jobOutputFile = new File(gvc.clusterFile.stripSuffix(".cluster") + ".gvc.out") + gvc.clusterFile = new File("g%d_s%.6f_d%.6f_b%.2f.cluster".format(g,s,d,b)) + gvc.jobOutputFile = swapExt(gvc.clusterFile, ".cluster", ".gvc.out") vr.jarFile = gatkJarFile vr.rodBind :+= RodBind("input20", "VCF", new File("/broad/shptmp/rpoplin/CEUTSI.chr20.filtered.vcf")) vr.logging_level = "INFO" vr.intervalsString :+= "20" - vr.target_titv = Some(2.1) + vr.target_titv = 2.1 vr.ignore_filter :+= "HARD_TO_VALIDATE" vr.path_to_resources = "/humgen/gsa-scr1/rpoplin/sting_dev_vb/R/" vr.clusterFile = gvc.clusterFile - vr.jobOutputFile = new File(vr.clusterFile.stripSuffix(".cluster") + ".vr.out") + vr.jobOutputFile = swapExt(vr.clusterFile, ".cluster", ".vr.out") vr.backOff = Some(b) vr.backOffFormat = "%.2f" diff --git a/scala/src/org/broadinstitute/sting/queue/QScriptManager.scala b/scala/src/org/broadinstitute/sting/queue/QScriptManager.scala index fafbbb1a8..6630a1af3 100644 --- a/scala/src/org/broadinstitute/sting/queue/QScriptManager.scala +++ b/scala/src/org/broadinstitute/sting/queue/QScriptManager.scala @@ -49,6 +49,7 @@ object QScriptManager extends Logging { val settings = new Settings((error: String) => logger.error(error)) val outdir = IOUtils.tempDir("Q-classes") + settings.deprecation.value = true settings.outdir.value = outdir.getPath // Set the classpath to the current class path. diff --git a/scala/src/org/broadinstitute/sting/queue/extensions/gatk/NamedFile.scala b/scala/src/org/broadinstitute/sting/queue/extensions/gatk/NamedFile.scala deleted file mode 100644 index c5b3917e8..000000000 --- a/scala/src/org/broadinstitute/sting/queue/extensions/gatk/NamedFile.scala +++ /dev/null @@ -1,35 +0,0 @@ -package org.broadinstitute.sting.queue.extensions.gatk - -import java.io.File -import org.broadinstitute.sting.queue.function.FileProvider - -/** - * Used to provide -I input_file arguments to the GATK. - */ -class NamedFile(var file: File, var name: String = null) extends FileProvider { - require(file != null, "NamedFile file cannot be null") -} - -/** - * Used to provide -I input_file arguments to the GATK. - */ -object NamedFile { - /** - * Formats the rod binding on the command line. - * Used for optional and repeat. - * @param cmdLineParam command line parameter, ex: -I - * @param prefix unused - * @param value NamedFile to add. - * @param suffix unused - * @return The command line addition. - */ - def formatCommandLine(cmdLineParam: String)(prefix: String, value: Any, suffix: String) = { - value match { - case namedFile: NamedFile => - if (namedFile.name != null) - " %s:%s %s".format(cmdLineParam, namedFile.name, namedFile.file) - else - " %s %s".format(cmdLineParam, namedFile.file) - } - } -} diff --git a/scala/src/org/broadinstitute/sting/queue/extensions/gatk/NamedFileWrapper.scala b/scala/src/org/broadinstitute/sting/queue/extensions/gatk/NamedFileWrapper.scala deleted file mode 100644 index 6add6e700..000000000 --- a/scala/src/org/broadinstitute/sting/queue/extensions/gatk/NamedFileWrapper.scala +++ /dev/null @@ -1,8 +0,0 @@ -package org.broadinstitute.sting.queue.extensions.gatk - -import java.io.File - -class NamedFileWrapper(private val file: File) { - def toNamedFile = new NamedFile(file) - def toNamedFile(name: String) = new NamedFile(file, name) -} diff --git a/scala/src/org/broadinstitute/sting/queue/extensions/gatk/RodBind.scala b/scala/src/org/broadinstitute/sting/queue/extensions/gatk/RodBind.scala index 3cc5f4b33..db90b5321 100644 --- a/scala/src/org/broadinstitute/sting/queue/extensions/gatk/RodBind.scala +++ b/scala/src/org/broadinstitute/sting/queue/extensions/gatk/RodBind.scala @@ -1,21 +1,27 @@ package org.broadinstitute.sting.queue.extensions.gatk import java.io.File -import org.broadinstitute.sting.queue.function.FileProvider +import org.broadinstitute.sting.queue.function.FileExtension +import java.lang.String /** * Used to provide -B rodBind arguments to the GATK. */ -case class RodBind(var trackName: String, var trackType: String, var file: File) extends FileProvider { +class RodBind(var trackName: String, var trackType: String, path: String) extends File(path) with FileExtension { + def this(trackName: String, trackType: String, file: File) = + this(trackName, trackType, file.getPath) require(trackName != null, "RodBind trackName cannot be null") require(trackType != null, "RodBind trackType cannot be null") - require(file != null, "RodBind file cannot be null") + def withPath(newPath: String) = new RodBind(trackName, trackType, newPath) } /** * Used to provide -B rodBind arguments to the GATK. */ object RodBind { + def apply(trackName: String, trackType: String, path: String) = new RodBind(trackName, trackType, path) + def apply(trackName: String, trackType: String, file: File) = new RodBind(trackName, trackType, file) + /** * Formats the rod binding on the command line. * Used for optional and repeat. @@ -28,7 +34,7 @@ object RodBind { def formatCommandLine(cmdLineParam: String)(prefix: String, value: Any, suffix: String) = { value match { case rodBind: RodBind => - " %s:%s,%s %s".format(cmdLineParam, rodBind.trackName, rodBind.trackType, rodBind.file) + " %s:%s,%s %s".format(cmdLineParam, rodBind.trackName, rodBind.trackType, rodBind.getPath) } } } diff --git a/scala/src/org/broadinstitute/sting/queue/extensions/gatk/TaggedFile.scala b/scala/src/org/broadinstitute/sting/queue/extensions/gatk/TaggedFile.scala new file mode 100644 index 000000000..ed8158b49 --- /dev/null +++ b/scala/src/org/broadinstitute/sting/queue/extensions/gatk/TaggedFile.scala @@ -0,0 +1,39 @@ +package org.broadinstitute.sting.queue.extensions.gatk + +import java.io.File +import org.broadinstitute.sting.queue.function.FileExtension + +/** + * Used to provide tagged -I input_file arguments to the GATK. + */ +class TaggedFile(path: String, val tag: String) extends File(path) with FileExtension { + def this(file: File, tag: String) = + this(file.getPath, tag) + def withPath(path: String) = new TaggedFile(path, tag) +} + +/** + * Used to provide -I input_file arguments to the GATK. + */ +object TaggedFile { + def apply(path: String, tag: String) = new TaggedFile(path, tag) + def apply(file: File, tag: String) = new TaggedFile(file, tag) + + /** + * Formats the rod binding on the command line. + * Used for optional and repeat. + * @param cmdLineParam command line parameter, ex: -I + * @param prefix unused + * @param value TaggedFile to add. + * @param suffix unused + * @return The command line addition. + */ + def formatCommandLine(cmdLineParam: String)(prefix: String, value: Any, suffix: String) = { + value match { + case taggedFile: TaggedFile if (taggedFile.tag != null) => + " %s:%s %s".format(cmdLineParam, taggedFile.tag, taggedFile.getPath) + case file: File => + " %s %s".format(cmdLineParam, file.getPath) + } + } +} diff --git a/scala/src/org/broadinstitute/sting/queue/extensions/gatk/package.scala b/scala/src/org/broadinstitute/sting/queue/extensions/gatk/package.scala deleted file mode 100644 index f5ed0e38c..000000000 --- a/scala/src/org/broadinstitute/sting/queue/extensions/gatk/package.scala +++ /dev/null @@ -1,13 +0,0 @@ -package org.broadinstitute.sting.queue.extensions - -import java.io.File -import org.broadinstitute.sting.queue.extensions.gatk.NamedFile -import org.broadinstitute.sting.queue.extensions.gatk.NamedFileWrapper - -package object gatk { - implicit def fileToNamedFileWrapper(file: File) = new NamedFileWrapper(file) - // TODO: Get the syntax right so that the implicits kick in for a generic type, ex: Travesable[File], Traversable[_ <: File], etc. - // but need to return the same outter type, so T <: Traversable[File] : T[NamedFile], T <: Traversable[_ <: File]: T[NamedFile], etc. - implicit def filesToNamedFilesWrapper(files: List[File]) = files.map(file => if (file == null) null else new NamedFile(file)) - implicit def filesToNamedFilesWrapper(files: Set[File]) = files.map(file => if (file == null) null else new NamedFile(file)) -} diff --git a/scala/src/org/broadinstitute/sting/queue/function/CommandLineFunction.scala b/scala/src/org/broadinstitute/sting/queue/function/CommandLineFunction.scala index 55c10ffda..6d0fd27ec 100644 --- a/scala/src/org/broadinstitute/sting/queue/function/CommandLineFunction.scala +++ b/scala/src/org/broadinstitute/sting/queue/function/CommandLineFunction.scala @@ -94,7 +94,7 @@ trait CommandLineFunction extends QFunction with Logging { def outputs = getFieldFiles(outputFields) /** - * Gets the files from the fields. The fields must be a File, a FileProvider, or a List or Set of either. + * Gets the files from the fields. The fields must be a File, a FileExtension, or a List or Set of either. * @param fields Fields to get files. * @return Set[File] for the fields. */ @@ -121,7 +121,7 @@ trait CommandLineFunction extends QFunction with Logging { } /** - * Gets the files from the field. The field must be a File, a FileProvider, or a List or Set of either. + * Gets the files from the field. The field must be a File, a FileExtension, or a List or Set of either. * @param fields Field to get files. * @return Set[File] for the field. */ @@ -136,7 +136,7 @@ trait CommandLineFunction extends QFunction with Logging { } /** - * Gets the file from the field. The field must be a File or a FileProvider and not a List or Set. + * Gets the file from the field. The field must be a File or a FileExtension and not a List or Set. * @param field Field to get the file. * @return File for the field. */ @@ -144,17 +144,16 @@ trait CommandLineFunction extends QFunction with Logging { fieldValueToFile(field, getFieldValue(field)) /** - * Converts the field value to a file. The field must be a File or a FileProvider. + * Converts the field value to a file. The field must be a File or a FileExtension. * @param field Field to get the file. - * @param value Value of the File or FileProvider or null. + * @param value Value of the File or FileExtension or null. * @return Null if value is null, otherwise the File. - * @throws QException if the value is not a File or FileProvider. + * @throws QException if the value is not a File or FileExtension. */ private def fieldValueToFile(field: ArgumentSource, value: Any): File = value match { case file: File => file - case fileProvider: FileProvider => fileProvider.file case null => null - case unknown => throw new QException("Non-file found. Try removing the annotation, change the annotation to @Argument, or implement FileProvider: %s: %s".format(field.field, unknown)) + case unknown => throw new QException("Non-file found. Try removing the annotation, change the annotation to @Argument, or extend File with FileExtension: %s: %s".format(field.field, unknown)) } /** @@ -164,15 +163,19 @@ trait CommandLineFunction extends QFunction with Logging { */ def resetFieldFile(field: ArgumentSource, tempDir: File): File = { getFieldValue(field) match { + case fileExtension: FileExtension => { + val newFile = IOUtils.resetParent(tempDir, fileExtension) + val newFileExtension = fileExtension.withPath(newFile.getPath) + setFieldValue(field, newFileExtension) + newFileExtension + } case file: File => { + if (file.getClass == classOf[File]) + throw new QException("Extensions of file must also extend with FileExtension so that the path can be modified."); val newFile = IOUtils.resetParent(tempDir, file) setFieldValue(field, newFile) newFile } - case fileProvider: FileProvider => { - fileProvider.file = IOUtils.resetParent(tempDir, fileProvider.file) - fileProvider.file - } case null => null case unknown => throw new QException("Unable to set file from %s: %s".format(field, unknown)) @@ -242,8 +245,14 @@ trait CommandLineFunction extends QFunction with Logging { */ protected def canon(value: Any) = { value match { - case file: File => absolute(file) - case fileProvider: FileProvider => fileProvider.file = absolute(fileProvider.file); fileProvider + case fileExtension: FileExtension => + val newFile = absolute(fileExtension); + val newFileExtension = fileExtension.withPath(newFile.getPath) + newFileExtension + case file: File => + if (file.getClass != classOf[File]) + throw new QException("Extensions of file must also extend with FileExtension so that the path can be modified."); + absolute(file) case x => x } } diff --git a/scala/src/org/broadinstitute/sting/queue/function/FileExtension.scala b/scala/src/org/broadinstitute/sting/queue/function/FileExtension.scala new file mode 100644 index 000000000..e2394a5bf --- /dev/null +++ b/scala/src/org/broadinstitute/sting/queue/function/FileExtension.scala @@ -0,0 +1,15 @@ +package org.broadinstitute.sting.queue.function + +import java.io.File + +/** + * An trait for @Input or @Output CommandLineFunction fields that are extensions of files. + */ +trait FileExtension extends File { + /** + * Returns a clone of the FileExtension with the new path. + * @param newPath new path for the clone of this FileExtension + * @return a clone of the FileExtension with the new path. + */ + def withPath(newPath: String): File +} diff --git a/scala/src/org/broadinstitute/sting/queue/function/FileProvider.scala b/scala/src/org/broadinstitute/sting/queue/function/FileProvider.scala deleted file mode 100644 index b139cfff6..000000000 --- a/scala/src/org/broadinstitute/sting/queue/function/FileProvider.scala +++ /dev/null @@ -1,11 +0,0 @@ -package org.broadinstitute.sting.queue.function - -import java.io.File - -/** - * An trait for @Input or @Output CommandLineFunction fields that are not files, but have a File that can be get/set. - */ -trait FileProvider { - /** Gets/Sets the file. */ - var file: File -}