From 51dcd364a50a456fd4fc7557b1f7bb0368d19662 Mon Sep 17 00:00:00 2001 From: pdexheimer Date: Mon, 25 Nov 2013 11:00:55 -0500 Subject: [PATCH 1/4] Added logDirectory argument Signed-off-by: Khalid Shakir --- .../main/scala/org/broadinstitute/sting/queue/QSettings.scala | 3 +++ 1 file changed, 3 insertions(+) diff --git a/public/queue-framework/src/main/scala/org/broadinstitute/sting/queue/QSettings.scala b/public/queue-framework/src/main/scala/org/broadinstitute/sting/queue/QSettings.scala index e74e235d4..197d45e0a 100644 --- a/public/queue-framework/src/main/scala/org/broadinstitute/sting/queue/QSettings.scala +++ b/public/queue-framework/src/main/scala/org/broadinstitute/sting/queue/QSettings.scala @@ -95,4 +95,7 @@ class QSettings { @Argument(fullName="job_scatter_gather_directory", shortName="jobSGDir", doc="Default directory to place scatter gather output for compute farm jobs.", required=false) var jobScatterGatherDirectory: File = _ + + @Argument(fullName="log_directory", shortName="logDir", doc="Directory to write log files into.", required=false) + var logDirectory: File = _ } From 504c125c26c1964296631030c0cbe7b6f03f50db Mon Sep 17 00:00:00 2001 From: pdexheimer Date: Mon, 25 Nov 2013 11:03:01 -0500 Subject: [PATCH 2/4] Ensure .out files are saved into logDirectory Signed-off-by: Khalid Shakir --- .../sting/queue/function/QFunction.scala | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/public/queue-framework/src/main/scala/org/broadinstitute/sting/queue/function/QFunction.scala b/public/queue-framework/src/main/scala/org/broadinstitute/sting/queue/function/QFunction.scala index 3afd289af..7f77a27d3 100644 --- a/public/queue-framework/src/main/scala/org/broadinstitute/sting/queue/function/QFunction.scala +++ b/public/queue-framework/src/main/scala/org/broadinstitute/sting/queue/function/QFunction.scala @@ -377,9 +377,18 @@ trait QFunction extends Logging with QJobReport { jobName = qSettings.runName + "-" + this.addOrder.mkString("-") if (jobOutputFile == null) { + /*If the outputFile has been set to an absolute path, respect that. + Otherwise, place it in (possibly a subdirectory of) the log directory + The relative case is first as it's arguably the most common condition + */ jobOutputFile = firstOutput match { - case file: File if (!IOUtils.isSpecialFile(file)) => new File(file.getParentFile, file.getName + ".out") - case _ => new File(jobName + ".out") + case file: File if (!IOUtils.isSpecialFile(file) && !file.isAbsolute) => { + val logDir : File = if (file.getParentFile() == null) qSettings.logDirectory else new File(qSettings.logDirectory, file.getParent) + new File(logDir, file.getName + ".out") + } + case file: File if (!IOUtils.isSpecialFile(file) && file.isAbsolute) => + new File(file.getParentFile, file.getName + ".out") + case _ => new File(qSettings.logDirectory, jobName + ".out") } } From 0405afeab24e5ac24300cd8294575ad870ca2ae0 Mon Sep 17 00:00:00 2001 From: pdexheimer Date: Wed, 27 Nov 2013 10:47:04 -0500 Subject: [PATCH 3/4] Inherit BamGatherFunction from MergeSamFiles rather than PicardBamFunction - This change means that BamGatherFunction will now have an @Output field for the BAM index, which will allow the bai to be deleted for intermediate functions Signed-off-by: Khalid Shakir --- .../queue/extensions/gatk/BamGatherFunction.scala | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/public/queue-framework/src/main/scala/org/broadinstitute/sting/queue/extensions/gatk/BamGatherFunction.scala b/public/queue-framework/src/main/scala/org/broadinstitute/sting/queue/extensions/gatk/BamGatherFunction.scala index aaddeb28b..bfaebfb91 100644 --- a/public/queue-framework/src/main/scala/org/broadinstitute/sting/queue/extensions/gatk/BamGatherFunction.scala +++ b/public/queue-framework/src/main/scala/org/broadinstitute/sting/queue/extensions/gatk/BamGatherFunction.scala @@ -26,7 +26,7 @@ package org.broadinstitute.sting.queue.extensions.gatk import org.broadinstitute.sting.queue.function.scattergather.GatherFunction -import org.broadinstitute.sting.queue.extensions.picard.PicardBamFunction +import org.broadinstitute.sting.queue.extensions.picard.MergeSamFiles import org.broadinstitute.sting.queue.function.{RetryMemoryLimit, QFunction} import org.broadinstitute.sting.gatk.io.stubs.SAMFileWriterArgumentTypeDescriptor import org.broadinstitute.sting.queue.util.ClassFieldCache @@ -34,13 +34,17 @@ import org.broadinstitute.sting.queue.util.ClassFieldCache /** * Merges BAM files using net.sf.picard.sam.MergeSamFiles. */ -class BamGatherFunction extends GatherFunction with PicardBamFunction with RetryMemoryLimit { - this.javaMainClass = "net.sf.picard.sam.MergeSamFiles" +class BamGatherFunction extends MergeSamFiles with GatherFunction with RetryMemoryLimit { this.assumeSorted = Some(true) - protected def inputBams = gatherParts - protected def outputBam = originalOutput override def freezeFieldValues() { + this.input = this.gatherParts + this.output = this.originalOutput + //Left to its own devices (ie, MergeSamFiles.freezeFieldValues), outputIndex + //will be in the gather directory. Ensure that it actually matches this.output + if (output != null) + outputIndex = new File(output.getParentFile(), output.getName.stripSuffix(".bam") + ".bai") + val originalGATK = originalFunction.asInstanceOf[CommandLineGATK] // Whatever the original function can handle, merging *should* do less. From f02ce6eca7617307e7de76f7c58f4dddfaca69de Mon Sep 17 00:00:00 2001 From: Khalid Shakir Date: Mon, 24 Feb 2014 19:33:22 +0800 Subject: [PATCH 4/4] Added tests for cleaning up scattered .bai files, and using the log directory. Re-added import java.io.File for BamGatherFunction. Other cleanup to resolve scala syntax warnings from intellij. Moved Example UG script to from protected to public. --- .../ExampleUnifiedGenotyperPipelineTest.scala | 117 ------------------ ...llOutput.scala => ExamplePrintReads.scala} | 9 +- .../broadinstitute/sting/queue/QScript.scala | 7 ++ .../extensions/gatk/BamGatherFunction.scala | 5 +- .../sting/queue/function/QFunction.scala | 12 +- .../sting/queue/pipeline/PipelineTest.scala | 44 +++++-- .../queue/pipeline/PipelineTestSpec.scala | 6 + ...la => ExamplePrintReadsPipelineTest.scala} | 21 +++- .../ExampleUnifiedGenotyperPipelineTest.scala | 111 +++++++++++++++++ .../examples/HelloWorldPipelineTest.scala | 11 ++ 10 files changed, 205 insertions(+), 138 deletions(-) delete mode 100644 protected/scala/test/org/broadinstitute/sting/queue/pipeline/examples/ExampleUnifiedGenotyperPipelineTest.scala rename public/queue-framework/src/main/qscripts/org/broadinstitute/sting/queue/qscripts/examples/{DevNullOutput.scala => ExamplePrintReads.scala} (88%) rename public/queue-framework/src/test/scala/org/broadinstitute/sting/queue/pipeline/examples/{DevNullOutputPipelineTest.scala => ExamplePrintReadsPipelineTest.scala} (78%) create mode 100644 public/queue-framework/src/test/scala/org/broadinstitute/sting/queue/pipeline/examples/ExampleUnifiedGenotyperPipelineTest.scala diff --git a/protected/scala/test/org/broadinstitute/sting/queue/pipeline/examples/ExampleUnifiedGenotyperPipelineTest.scala b/protected/scala/test/org/broadinstitute/sting/queue/pipeline/examples/ExampleUnifiedGenotyperPipelineTest.scala deleted file mode 100644 index fdbd7ca1f..000000000 --- a/protected/scala/test/org/broadinstitute/sting/queue/pipeline/examples/ExampleUnifiedGenotyperPipelineTest.scala +++ /dev/null @@ -1,117 +0,0 @@ -/* -* By downloading the PROGRAM you agree to the following terms of use: -* -* BROAD INSTITUTE - SOFTWARE LICENSE AGREEMENT - FOR ACADEMIC NON-COMMERCIAL RESEARCH PURPOSES ONLY -* -* This Agreement is made between the Broad Institute, Inc. with a principal address at 7 Cambridge Center, Cambridge, MA 02142 (BROAD) and the LICENSEE and is effective at the date the downloading is completed (EFFECTIVE DATE). -* -* WHEREAS, LICENSEE desires to license the PROGRAM, as defined hereinafter, and BROAD wishes to have this PROGRAM utilized in the public interest, subject only to the royalty-free, nonexclusive, nontransferable license rights of the United States Government pursuant to 48 CFR 52.227-14; and -* WHEREAS, LICENSEE desires to license the PROGRAM and BROAD desires to grant a license on the following terms and conditions. -* NOW, THEREFORE, in consideration of the promises and covenants made herein, the parties hereto agree as follows: -* -* 1. DEFINITIONS -* 1.1 PROGRAM shall mean copyright in the object code and source code known as GATK2 and related documentation, if any, as they exist on the EFFECTIVE DATE and can be downloaded from http://www.broadinstitute/GATK on the EFFECTIVE DATE. -* -* 2. LICENSE -* 2.1 Grant. Subject to the terms of this Agreement, BROAD hereby grants to LICENSEE, solely for academic non-commercial research purposes, a non-exclusive, non-transferable license to: (a) download, execute and display the PROGRAM and (b) create bug fixes and modify the PROGRAM. -* The LICENSEE may apply the PROGRAM in a pipeline to data owned by users other than the LICENSEE and provide these users the results of the PROGRAM provided LICENSEE does so for academic non-commercial purposes only. For clarification purposes, academic sponsored research is not a commercial use under the terms of this Agreement. -* 2.2 No Sublicensing or Additional Rights. LICENSEE shall not sublicense or distribute the PROGRAM, in whole or in part, without prior written permission from BROAD. LICENSEE shall ensure that all of its users agree to the terms of this Agreement. LICENSEE further agrees that it shall not put the PROGRAM on a network, server, or other similar technology that may be accessed by anyone other than the LICENSEE and its employees and users who have agreed to the terms of this agreement. -* 2.3 License Limitations. Nothing in this Agreement shall be construed to confer any rights upon LICENSEE by implication, estoppel, or otherwise to any computer software, trademark, intellectual property, or patent rights of BROAD, or of any other entity, except as expressly granted herein. LICENSEE agrees that the PROGRAM, in whole or part, shall not be used for any commercial purpose, including without limitation, as the basis of a commercial software or hardware product or to provide services. LICENSEE further agrees that the PROGRAM shall not be copied or otherwise adapted in order to circumvent the need for obtaining a license for use of the PROGRAM. -* -* 3. OWNERSHIP OF INTELLECTUAL PROPERTY -* LICENSEE acknowledges that title to the PROGRAM shall remain with BROAD. The PROGRAM is marked with the following BROAD copyright notice and notice of attribution to contributors. LICENSEE shall retain such notice on all copies. LICENSEE agrees to include appropriate attribution if any results obtained from use of the PROGRAM are included in any publication. -* Copyright 2012 Broad Institute, Inc. -* Notice of attribution: The GATK2 program was made available through the generosity of Medical and Population Genetics program at the Broad Institute, Inc. -* LICENSEE shall not use any trademark or trade name of BROAD, or any variation, adaptation, or abbreviation, of such marks or trade names, or any names of officers, faculty, students, employees, or agents of BROAD except as states above for attribution purposes. -* -* 4. INDEMNIFICATION -* LICENSEE shall indemnify, defend, and hold harmless BROAD, and their respective officers, faculty, students, employees, associated investigators and agents, and their respective successors, heirs and assigns, (Indemnitees), against any liability, damage, loss, or expense (including reasonable attorneys fees and expenses) incurred by or imposed upon any of the Indemnitees in connection with any claims, suits, actions, demands or judgments arising out of any theory of liability (including, without limitation, actions in the form of tort, warranty, or strict liability and regardless of whether such action has any factual basis) pursuant to any right or license granted under this Agreement. -* -* 5. NO REPRESENTATIONS OR WARRANTIES -* THE PROGRAM IS DELIVERED AS IS. BROAD MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE PROGRAM OR THE COPYRIGHT, EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, WHETHER OR NOT DISCOVERABLE. BROAD EXTENDS NO WARRANTIES OF ANY KIND AS TO PROGRAM CONFORMITY WITH WHATEVER USER MANUALS OR OTHER LITERATURE MAY BE ISSUED FROM TIME TO TIME. -* IN NO EVENT SHALL BROAD OR ITS RESPECTIVE DIRECTORS, OFFICERS, EMPLOYEES, AFFILIATED INVESTIGATORS AND AFFILIATES BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, INCLUDING, WITHOUT LIMITATION, ECONOMIC DAMAGES OR INJURY TO PROPERTY AND LOST PROFITS, REGARDLESS OF WHETHER BROAD SHALL BE ADVISED, SHALL HAVE OTHER REASON TO KNOW, OR IN FACT SHALL KNOW OF THE POSSIBILITY OF THE FOREGOING. -* -* 6. ASSIGNMENT -* This Agreement is personal to LICENSEE and any rights or obligations assigned by LICENSEE without the prior written consent of BROAD shall be null and void. -* -* 7. MISCELLANEOUS -* 7.1 Export Control. LICENSEE gives assurance that it will comply with all United States export control laws and regulations controlling the export of the PROGRAM, including, without limitation, all Export Administration Regulations of the United States Department of Commerce. Among other things, these laws and regulations prohibit, or require a license for, the export of certain types of software to specified countries. -* 7.2 Termination. LICENSEE shall have the right to terminate this Agreement for any reason upon prior written notice to BROAD. If LICENSEE breaches any provision hereunder, and fails to cure such breach within thirty (30) days, BROAD may terminate this Agreement immediately. Upon termination, LICENSEE shall provide BROAD with written assurance that the original and all copies of the PROGRAM have been destroyed, except that, upon prior written authorization from BROAD, LICENSEE may retain a copy for archive purposes. -* 7.3 Survival. The following provisions shall survive the expiration or termination of this Agreement: Articles 1, 3, 4, 5 and Sections 2.2, 2.3, 7.3, and 7.4. -* 7.4 Notice. Any notices under this Agreement shall be in writing, shall specifically refer to this Agreement, and shall be sent by hand, recognized national overnight courier, confirmed facsimile transmission, confirmed electronic mail, or registered or certified mail, postage prepaid, return receipt requested. All notices under this Agreement shall be deemed effective upon receipt. -* 7.5 Amendment and Waiver; Entire Agreement. This Agreement may be amended, supplemented, or otherwise modified only by means of a written instrument signed by all parties. Any waiver of any rights or failure to act in a specific instance shall relate only to such instance and shall not be construed as an agreement to waive any rights or fail to act in any other instance, whether or not similar. This Agreement constitutes the entire agreement among the parties with respect to its subject matter and supersedes prior agreements or understandings between the parties relating to its subject matter. -* 7.6 Binding Effect; Headings. This Agreement shall be binding upon and inure to the benefit of the parties and their respective permitted successors and assigns. All headings are for convenience only and shall not affect the meaning of any provision of this Agreement. -* 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles. -*/ - -package org.broadinstitute.sting.queue.pipeline.examples - -import org.testng.annotations.{DataProvider, Test} -import org.broadinstitute.sting.queue.pipeline.{PipelineTest, PipelineTestSpec} -import org.broadinstitute.sting.BaseTest - -class ExampleUnifiedGenotyperPipelineTest { - @Test(timeOut=36000000) - def testUnifiedGenotyper() { - val spec = new PipelineTestSpec - spec.name = "unifiedgenotyper" - spec.args = Array( - " -S public/scala/qscript/org/broadinstitute/sting/queue/qscripts/examples/ExampleUnifiedGenotyper.scala", - " -R " + BaseTest.publicTestDir + "exampleFASTA.fasta", - " -I " + BaseTest.publicTestDir + "exampleBAM.bam", - " -filter QD", - " -filterExpression 'QD < 2.0'").mkString - spec.jobRunners = PipelineTest.allJobRunners - PipelineTest.executeTest(spec) - } - - @DataProvider(name = "ugIntervals") - def getUnifiedGenotyperIntervals = - Array( - Array("gatk_intervals", BaseTest.validationDataLocation + "intervalTest.intervals"), - Array("bed_intervals", BaseTest.validationDataLocation + "intervalTest.bed"), - Array("vcf_intervals", BaseTest.validationDataLocation + "intervalTest.1.vcf") - ).asInstanceOf[Array[Array[Object]]] - - @Test(dataProvider = "ugIntervals", timeOut=36000000) - def testUnifiedGenotyperWithIntervals(intervalsName: String, intervalsPath: String) { - val spec = new PipelineTestSpec - spec.name = "unifiedgenotyper_with_" + intervalsName - spec.args = Array( - " -S public/scala/qscript/org/broadinstitute/sting/queue/qscripts/examples/ExampleUnifiedGenotyper.scala", - " -I " + BaseTest.validationDataLocation + "OV-0930.normal.chunk.bam", - " -R " + BaseTest.hg18Reference, - " -L " + intervalsPath).mkString - spec.jobRunners = Seq("Lsf706") - PipelineTest.executeTest(spec) - } - - @Test(timeOut=36000000) - def testUnifiedGenotyperNoGCOpt() { - val spec = new PipelineTestSpec - spec.name = "unifiedgenotyper_no_gc_opt" - spec.args = Array( - " -S public/scala/qscript/org/broadinstitute/sting/queue/qscripts/examples/ExampleUnifiedGenotyper.scala", - " -R " + BaseTest.publicTestDir + "exampleFASTA.fasta", - " -I " + BaseTest.publicTestDir + "exampleBAM.bam", - " -noGCOpt").mkString - spec.jobRunners = PipelineTest.allJobRunners - PipelineTest.executeTest(spec) - } - - @DataProvider(name="resMemReqParams") - def getResMemReqParam = Array(Array("mem_free"), Array("virtual_free")).asInstanceOf[Array[Array[Object]]] - - @Test(dataProvider = "resMemReqParams", timeOut=36000000) - def testUnifiedGenotyperResMemReqParam(reqParam: String) { - val spec = new PipelineTestSpec - spec.name = "unifiedgenotyper_" + reqParam - spec.args = Array( - " -S public/scala/qscript/org/broadinstitute/sting/queue/qscripts/examples/ExampleUnifiedGenotyper.scala", - " -R " + BaseTest.publicTestDir + "exampleFASTA.fasta", - " -I " + BaseTest.publicTestDir + "exampleBAM.bam", - " -resMemReqParam " + reqParam).mkString - spec.jobRunners = Seq("GridEngine") - PipelineTest.executeTest(spec) - } -} diff --git a/public/queue-framework/src/main/qscripts/org/broadinstitute/sting/queue/qscripts/examples/DevNullOutput.scala b/public/queue-framework/src/main/qscripts/org/broadinstitute/sting/queue/qscripts/examples/ExamplePrintReads.scala similarity index 88% rename from public/queue-framework/src/main/qscripts/org/broadinstitute/sting/queue/qscripts/examples/DevNullOutput.scala rename to public/queue-framework/src/main/qscripts/org/broadinstitute/sting/queue/qscripts/examples/ExamplePrintReads.scala index 0021f5ae5..18f2895b9 100644 --- a/public/queue-framework/src/main/qscripts/org/broadinstitute/sting/queue/qscripts/examples/DevNullOutput.scala +++ b/public/queue-framework/src/main/qscripts/org/broadinstitute/sting/queue/qscripts/examples/ExamplePrintReads.scala @@ -29,22 +29,25 @@ import org.broadinstitute.sting.queue.QScript import org.broadinstitute.sting.queue.extensions.gatk._ /** - * Script used for testing output to /dev/null + * Script used for testing output to /dev/null, deleting .bai files, etc. */ -class DevNullOutput extends QScript { +class ExamplePrintReads extends QScript { @Input(doc="The reference file for the bam files.", shortName="R") var referenceFile: File = _ @Input(doc="Bam file to genotype.", shortName="I") var bamFile: File = _ + @Output(doc="Bam output", shortName="out") + var outFile: File = _ + def script() { val printReads = new PrintReads printReads.reference_sequence = referenceFile printReads.memoryLimit = 2 printReads.scatterCount = 3 printReads.input_file :+= bamFile - printReads.out = "/dev/null" + printReads.out = outFile add(printReads) } } diff --git a/public/queue-framework/src/main/scala/org/broadinstitute/sting/queue/QScript.scala b/public/queue-framework/src/main/scala/org/broadinstitute/sting/queue/QScript.scala index fc1d4599e..afd1bbc19 100644 --- a/public/queue-framework/src/main/scala/org/broadinstitute/sting/queue/QScript.scala +++ b/public/queue-framework/src/main/scala/org/broadinstitute/sting/queue/QScript.scala @@ -174,4 +174,11 @@ object QScript { addOrder += 1 Seq(addOrder) } + + /** + * Resets the add order back to zero. Useful for testing purposes. + */ + def resetAddOrder() { + addOrder = 0 + } } diff --git a/public/queue-framework/src/main/scala/org/broadinstitute/sting/queue/extensions/gatk/BamGatherFunction.scala b/public/queue-framework/src/main/scala/org/broadinstitute/sting/queue/extensions/gatk/BamGatherFunction.scala index bfaebfb91..f580ba116 100644 --- a/public/queue-framework/src/main/scala/org/broadinstitute/sting/queue/extensions/gatk/BamGatherFunction.scala +++ b/public/queue-framework/src/main/scala/org/broadinstitute/sting/queue/extensions/gatk/BamGatherFunction.scala @@ -27,9 +27,10 @@ package org.broadinstitute.sting.queue.extensions.gatk import org.broadinstitute.sting.queue.function.scattergather.GatherFunction import org.broadinstitute.sting.queue.extensions.picard.MergeSamFiles -import org.broadinstitute.sting.queue.function.{RetryMemoryLimit, QFunction} +import org.broadinstitute.sting.queue.function.RetryMemoryLimit import org.broadinstitute.sting.gatk.io.stubs.SAMFileWriterArgumentTypeDescriptor import org.broadinstitute.sting.queue.util.ClassFieldCache +import java.io.File /** * Merges BAM files using net.sf.picard.sam.MergeSamFiles. @@ -43,7 +44,7 @@ class BamGatherFunction extends MergeSamFiles with GatherFunction with RetryMemo //Left to its own devices (ie, MergeSamFiles.freezeFieldValues), outputIndex //will be in the gather directory. Ensure that it actually matches this.output if (output != null) - outputIndex = new File(output.getParentFile(), output.getName.stripSuffix(".bam") + ".bai") + outputIndex = new File(output.getParentFile, output.getName.stripSuffix(".bam") + ".bai") val originalGATK = originalFunction.asInstanceOf[CommandLineGATK] diff --git a/public/queue-framework/src/main/scala/org/broadinstitute/sting/queue/function/QFunction.scala b/public/queue-framework/src/main/scala/org/broadinstitute/sting/queue/function/QFunction.scala index 7f77a27d3..9208c04f7 100644 --- a/public/queue-framework/src/main/scala/org/broadinstitute/sting/queue/function/QFunction.scala +++ b/public/queue-framework/src/main/scala/org/broadinstitute/sting/queue/function/QFunction.scala @@ -382,13 +382,15 @@ trait QFunction extends Logging with QJobReport { The relative case is first as it's arguably the most common condition */ jobOutputFile = firstOutput match { - case file: File if (!IOUtils.isSpecialFile(file) && !file.isAbsolute) => { - val logDir : File = if (file.getParentFile() == null) qSettings.logDirectory else new File(qSettings.logDirectory, file.getParent) + case file: File if !IOUtils.isSpecialFile(file) && !file.isAbsolute => + val logDir : File = if (file.getParentFile == null) qSettings.logDirectory else new File(qSettings.logDirectory, file.getParent) new File(logDir, file.getName + ".out") - } - case file: File if (!IOUtils.isSpecialFile(file) && file.isAbsolute) => + + case file: File if !IOUtils.isSpecialFile(file) && file.isAbsolute => new File(file.getParentFile, file.getName + ".out") - case _ => new File(qSettings.logDirectory, jobName + ".out") + + case _ => + new File(qSettings.logDirectory, jobName + ".out") } } diff --git a/public/queue-framework/src/test/scala/org/broadinstitute/sting/queue/pipeline/PipelineTest.scala b/public/queue-framework/src/test/scala/org/broadinstitute/sting/queue/pipeline/PipelineTest.scala index 251b1c511..2800ba2da 100644 --- a/public/queue-framework/src/test/scala/org/broadinstitute/sting/queue/pipeline/PipelineTest.scala +++ b/public/queue-framework/src/test/scala/org/broadinstitute/sting/queue/pipeline/PipelineTest.scala @@ -25,7 +25,6 @@ package org.broadinstitute.sting.queue.pipeline -import collection.JavaConversions._ import org.broadinstitute.sting.utils.Utils import org.testng.Assert import org.broadinstitute.sting.commandline.CommandLineProgram @@ -33,12 +32,12 @@ import java.util.Date import java.text.SimpleDateFormat import org.broadinstitute.sting.BaseTest import org.broadinstitute.sting.MD5DB -import org.broadinstitute.sting.queue.QCommandLine +import org.broadinstitute.sting.queue.{QScript, QCommandLine} import org.broadinstitute.sting.queue.util.Logging -import java.io.File +import java.io.{FilenameFilter, File} import org.broadinstitute.sting.gatk.report.GATKReport import org.apache.commons.io.FileUtils -import org.broadinstitute.sting.queue.engine.CommandLinePluginManager +import org.apache.commons.io.filefilter.WildcardFileFilter object PipelineTest extends BaseTest with Logging { @@ -86,7 +85,7 @@ object PipelineTest extends BaseTest with Logging { def executeTest(pipelineTest: PipelineTestSpec) { var jobRunners = pipelineTest.jobRunners if (jobRunners == null) - jobRunners = defaultJobRunners; + jobRunners = defaultJobRunners jobRunners.foreach(executeTest(pipelineTest, _)) } @@ -96,15 +95,22 @@ object PipelineTest extends BaseTest with Logging { * @param jobRunner The name of the job manager to run the jobs. */ def executeTest(pipelineTest: PipelineTestSpec, jobRunner: String) { + // Reset the order of functions added to the graph. + QScript.resetAddOrder() + val name = pipelineTest.name if (name == null) Assert.fail("PipelineTestSpec.name is null") - println(Utils.dupString('-', 80)); + println(Utils.dupString('-', 80)) executeTest(name, pipelineTest.args, pipelineTest.jobQueue, pipelineTest.expectedException, jobRunner) if (BaseTest.pipelineTestRunModeIsSet) { assertMatchingMD5s(name, pipelineTest.fileMD5s.map{case (file, md5) => new File(runDir(name, jobRunner), file) -> md5}, pipelineTest.parameterize) if (pipelineTest.evalSpec != null) validateEval(name, pipelineTest.evalSpec, jobRunner) + for (path <- pipelineTest.expectedFilePaths) + assertPathExists(runDir(name, jobRunner), path) + for (path <- pipelineTest.unexpectedFilePaths) + assertPathDoesNotExist(runDir(name, jobRunner), path) println(" => %s PASSED (%s)".format(name, jobRunner)) } else @@ -128,9 +134,9 @@ object PipelineTest extends BaseTest with Logging { val reportLocation = "%s%s/%s/validation.%s.eval".format(validationReportsDataLocation, jobRunner, name, formatter.format(new Date)) val reportFile = new File(reportLocation) - FileUtils.copyFile(new File(runDir(name, jobRunner) + evalSpec.evalReport), reportFile); + FileUtils.copyFile(new File(runDir(name, jobRunner) + evalSpec.evalReport), reportFile) - val report = new GATKReport(reportFile); + val report = new GATKReport(reportFile) var allInRange = true @@ -215,6 +221,28 @@ object PipelineTest extends BaseTest with Logging { } } + private def assertPathExists(runDir: String, path: String) { + val orig = new File(runDir, path) + var dir = orig.getParentFile + if (dir == null) + dir = new File(".") + Assert.assertTrue(dir.exists, "Missing directory: " + dir.getAbsolutePath) + val filter: FilenameFilter = new WildcardFileFilter(orig.getName) + Assert.assertNotEquals(dir.listFiles(filter).length, 0, "Missing file: " + orig.getAbsolutePath) + } + + private def assertPathDoesNotExist(runDir: String, path: String) { + val orig = new File(runDir, path) + var dir = orig.getParentFile + if (dir == null) + dir = new File(".") + if (dir.exists) { + val filter: FilenameFilter = new WildcardFileFilter(orig.getName) + Assert.assertEquals(dir.listFiles(filter).length, 0, + "Found unexpected file(s): " + dir.listFiles().map(_.getAbsolutePath).mkString(", ")) + } + } + private var runningCommandLines = Set.empty[QCommandLine] Runtime.getRuntime.addShutdownHook(new Thread { diff --git a/public/queue-framework/src/test/scala/org/broadinstitute/sting/queue/pipeline/PipelineTestSpec.scala b/public/queue-framework/src/test/scala/org/broadinstitute/sting/queue/pipeline/PipelineTestSpec.scala index a27af17be..3dc761382 100644 --- a/public/queue-framework/src/test/scala/org/broadinstitute/sting/queue/pipeline/PipelineTestSpec.scala +++ b/public/queue-framework/src/test/scala/org/broadinstitute/sting/queue/pipeline/PipelineTestSpec.scala @@ -45,6 +45,12 @@ class PipelineTestSpec(var name: String = null) { /** Expected exception from the test. */ var expectedException: Class[_ <: Exception] = null + /** Expected files. The file name may contain wildcards acceptable by the WildcardFileFilter. */ + var expectedFilePaths: Seq[String] = Seq.empty + + /** Unexpected files. The file name may contain wildcards acceptable by the WildcardFileFilter. */ + var unexpectedFilePaths: Seq[String] = Seq.empty + /** If true will check the MD5s without failing. */ var parameterize = false diff --git a/public/queue-framework/src/test/scala/org/broadinstitute/sting/queue/pipeline/examples/DevNullOutputPipelineTest.scala b/public/queue-framework/src/test/scala/org/broadinstitute/sting/queue/pipeline/examples/ExamplePrintReadsPipelineTest.scala similarity index 78% rename from public/queue-framework/src/test/scala/org/broadinstitute/sting/queue/pipeline/examples/DevNullOutputPipelineTest.scala rename to public/queue-framework/src/test/scala/org/broadinstitute/sting/queue/pipeline/examples/ExamplePrintReadsPipelineTest.scala index 10c3245e5..b9964d187 100644 --- a/public/queue-framework/src/test/scala/org/broadinstitute/sting/queue/pipeline/examples/DevNullOutputPipelineTest.scala +++ b/public/queue-framework/src/test/scala/org/broadinstitute/sting/queue/pipeline/examples/ExamplePrintReadsPipelineTest.scala @@ -53,16 +53,31 @@ import org.testng.annotations.Test import org.broadinstitute.sting.queue.pipeline.{PipelineTest, PipelineTestSpec} import org.broadinstitute.sting.BaseTest -class DevNullOutputPipelineTest { +class ExamplePrintReadsPipelineTest { @Test(timeOut=36000000) def testDevNullOutput() { val spec = new PipelineTestSpec spec.name = "devnulloutput" spec.args = Array( - " -S public/scala/qscript/org/broadinstitute/sting/queue/qscripts/examples/DevNullOutput.scala", + " -S public/scala/qscript/org/broadinstitute/sting/queue/qscripts/examples/ExamplePrintReads.scala", " -R " + BaseTest.publicTestDir + "exampleFASTA.fasta", - " -I " + BaseTest.publicTestDir + "exampleBAM.bam").mkString + " -I " + BaseTest.publicTestDir + "exampleBAM.bam", + " -out /dev/null").mkString spec.jobRunners = PipelineTest.allJobRunners PipelineTest.executeTest(spec) } + + @Test(timeOut=36000000) + def testCleanupBai() { + val spec = new PipelineTestSpec + spec.name = "cleanupbai" + spec.args = Array( + " -S public/scala/qscript/org/broadinstitute/sting/queue/qscripts/examples/ExamplePrintReads.scala", + " -R " + BaseTest.publicTestDir + "exampleFASTA.fasta", + " -I " + BaseTest.publicTestDir + "exampleBAM.bam", + " -out exampleOut.bam").mkString + spec.jobRunners = PipelineTest.allJobRunners + spec.unexpectedFilePaths :+= ".queue/scatterGather/ExamplePrintReads-1-sg/temp_1_of_1/exampleOut.bai" + PipelineTest.executeTest(spec) + } } diff --git a/public/queue-framework/src/test/scala/org/broadinstitute/sting/queue/pipeline/examples/ExampleUnifiedGenotyperPipelineTest.scala b/public/queue-framework/src/test/scala/org/broadinstitute/sting/queue/pipeline/examples/ExampleUnifiedGenotyperPipelineTest.scala new file mode 100644 index 000000000..b054164a1 --- /dev/null +++ b/public/queue-framework/src/test/scala/org/broadinstitute/sting/queue/pipeline/examples/ExampleUnifiedGenotyperPipelineTest.scala @@ -0,0 +1,111 @@ +/* +* Copyright (c) 2012 The Broad Institute +* +* Permission is hereby granted, free of charge, to any person +* obtaining a copy of this software and associated documentation +* files (the "Software"), to deal in the Software without +* restriction, including without limitation the rights to use, +* copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following +* conditions: +* +* The above copyright notice and this permission notice shall be +* included in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR +* THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.broadinstitute.sting.queue.pipeline.examples + +import org.testng.annotations.{DataProvider, Test} +import org.broadinstitute.sting.queue.pipeline.{PipelineTest, PipelineTestSpec} +import org.broadinstitute.sting.BaseTest + +class ExampleUnifiedGenotyperPipelineTest { + @Test(timeOut=36000000) + def testUnifiedGenotyper() { + val spec = new PipelineTestSpec + spec.name = "unifiedgenotyper" + spec.args = Array( + " -S public/scala/qscript/org/broadinstitute/sting/queue/qscripts/examples/ExampleUnifiedGenotyper.scala", + " -R " + BaseTest.publicTestDir + "exampleFASTA.fasta", + " -I " + BaseTest.publicTestDir + "exampleBAM.bam", + " -filter QD", + " -filterExpression 'QD < 2.0'").mkString + spec.jobRunners = PipelineTest.allJobRunners + PipelineTest.executeTest(spec) + } + + @DataProvider(name = "ugIntervals") + def getUnifiedGenotyperIntervals = + Array( + Array("gatk_intervals", BaseTest.validationDataLocation + "intervalTest.intervals"), + Array("bed_intervals", BaseTest.validationDataLocation + "intervalTest.bed"), + Array("vcf_intervals", BaseTest.validationDataLocation + "intervalTest.1.vcf") + ).asInstanceOf[Array[Array[Object]]] + + @Test(dataProvider = "ugIntervals", timeOut=36000000) + def testUnifiedGenotyperWithIntervals(intervalsName: String, intervalsPath: String) { + val spec = new PipelineTestSpec + spec.name = "unifiedgenotyper_with_" + intervalsName + spec.args = Array( + " -S public/scala/qscript/org/broadinstitute/sting/queue/qscripts/examples/ExampleUnifiedGenotyper.scala", + " -I " + BaseTest.validationDataLocation + "OV-0930.normal.chunk.bam", + " -R " + BaseTest.hg18Reference, + " -L " + intervalsPath).mkString + spec.jobRunners = Seq("Lsf706") + PipelineTest.executeTest(spec) + } + + @Test(timeOut=36000000) + def testUnifiedGenotyperNoGCOpt() { + val spec = new PipelineTestSpec + spec.name = "unifiedgenotyper_no_gc_opt" + spec.args = Array( + " -S public/scala/qscript/org/broadinstitute/sting/queue/qscripts/examples/ExampleUnifiedGenotyper.scala", + " -R " + BaseTest.publicTestDir + "exampleFASTA.fasta", + " -I " + BaseTest.publicTestDir + "exampleBAM.bam", + " -noGCOpt").mkString + spec.jobRunners = PipelineTest.allJobRunners + PipelineTest.executeTest(spec) + } + + @DataProvider(name="resMemReqParams") + def getResMemReqParam = Array(Array("mem_free"), Array("virtual_free")).asInstanceOf[Array[Array[Object]]] + + @Test(dataProvider = "resMemReqParams", timeOut=36000000) + def testUnifiedGenotyperResMemReqParam(reqParam: String) { + val spec = new PipelineTestSpec + spec.name = "unifiedgenotyper_" + reqParam + spec.args = Array( + " -S public/scala/qscript/org/broadinstitute/sting/queue/qscripts/examples/ExampleUnifiedGenotyper.scala", + " -R " + BaseTest.publicTestDir + "exampleFASTA.fasta", + " -I " + BaseTest.publicTestDir + "exampleBAM.bam", + " -resMemReqParam " + reqParam).mkString + spec.jobRunners = Seq("GridEngine") + PipelineTest.executeTest(spec) + } + + @Test(timeOut=36000000) + def testUnifiedGenotyperLogDirectory() { + val spec = new PipelineTestSpec + spec.name = "unifiedgenotyper_with_log_directory" + spec.args = Array( + " -S public/scala/qscript/org/broadinstitute/sting/queue/qscripts/examples/ExampleUnifiedGenotyper.scala", + " -R " + BaseTest.publicTestDir + "exampleFASTA.fasta", + " -I " + BaseTest.publicTestDir + "exampleBAM.bam", + " -logDir exampleUGLogDir").mkString + spec.jobRunners = PipelineTest.allJobRunners + spec.expectedFilePaths :+= "exampleUGLogDir/exampleBAM.unfiltered.vcf.out" + spec.expectedFilePaths :+= "exampleUGLogDir/exampleBAM.unfiltered.eval.out" + PipelineTest.executeTest(spec) + } +} diff --git a/public/queue-framework/src/test/scala/org/broadinstitute/sting/queue/pipeline/examples/HelloWorldPipelineTest.scala b/public/queue-framework/src/test/scala/org/broadinstitute/sting/queue/pipeline/examples/HelloWorldPipelineTest.scala index 83e50c9c5..0f645cb2a 100644 --- a/public/queue-framework/src/test/scala/org/broadinstitute/sting/queue/pipeline/examples/HelloWorldPipelineTest.scala +++ b/public/queue-framework/src/test/scala/org/broadinstitute/sting/queue/pipeline/examples/HelloWorldPipelineTest.scala @@ -138,4 +138,15 @@ class HelloWorldPipelineTest { spec.jobRunners = PipelineTest.allJobRunners PipelineTest.executeTest(spec) } + + @Test(timeOut=36000000) + def testHelloWorldWithLogDirectory() { + val spec = new PipelineTestSpec + spec.name = "HelloWorldWithLogDirectory" + spec.args = "-S public/scala/qscript/org/broadinstitute/sting/queue/qscripts/examples/HelloWorld.scala" + + " -logDir pipelineLogDir" + spec.jobRunners = PipelineTest.allJobRunners + spec.expectedFilePaths = Seq("pipelineLogDir/HelloWorld-1.out") + PipelineTest.executeTest(spec) + } }