Skip to content

Commit

Permalink
fix inputs passed in wrong order to parallel stage after 'produce' wh…
Browse files Browse the repository at this point in the history
…en lexical sorting differs to input order
  • Loading branch information
ssadedin committed Aug 28, 2014
1 parent b2bdf7c commit 32cc237
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 9 deletions.
21 changes: 16 additions & 5 deletions src/main/groovy/bpipe/InputSplitter.groovy
@@ -1,9 +1,12 @@
package bpipe

import groovy.util.logging.Log;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.naming.ldap.SortResponseControl;

/**
* Implements logic for splitting input files into groups by sample using simple
* wildcard patterns. The goal is to provide a simpler way for people to specify
Expand All @@ -26,6 +29,8 @@ import java.util.regex.Pattern;
*/
@Log
class InputSplitter {

boolean sortResults = true

/**
* Splits the given inputs up according to the specified pattern
Expand Down Expand Up @@ -85,11 +90,17 @@ class InputSplitter {
unsortedResult[group] << inp
}

// We now have all the inputs keyed on the part matching the split char,
// however we want to also sort them
Map sortedResult = [:]
unsortedResult.each { k,v ->
sortedResult[k] = this.sortNumericThenLexically(pattern, splitGroups, v)
if(sortResults) {
// We now have all the inputs keyed on the part matching the split char,
// however we want to also sort them
Map sortedResult = [:]
unsortedResult.each { k,v ->
sortedResult[k] = this.sortNumericThenLexically(pattern, splitGroups, v)
}
return sortedResult
}
else {
return unsortedResult
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/groovy/bpipe/PipelineCategory.groovy
Expand Up @@ -156,7 +156,7 @@ class PipelineCategory {
*/
static Object plus(Closure other, List segments) {
Pipeline pipeline = Pipeline.currentUnderConstructionPipeline
Closure mul = splitOnFiles("*", segments, false)
Closure mul = splitOnFiles("*", segments, false, false)
def plusImplementation = { input1 ->

def currentStage = new PipelineStage(Pipeline.currentRuntimePipeline.get().createContext(), other)
Expand Down Expand Up @@ -331,15 +331,15 @@ class PipelineCategory {
* @param requireMatch if true, the pipeline will fail if there are
* no matches to the pattern
*/
static Object splitOnFiles(def pattern, List segments, boolean requireMatch) {
static Object splitOnFiles(def pattern, List segments, boolean requireMatch, boolean sortResults=true) {
Pipeline pipeline = Pipeline.currentRuntimePipeline.get() ?: Pipeline.currentUnderConstructionPipeline

def multiplyImplementation = { input ->

log.info "multiply on input $input with pattern $pattern"

// Match the input
InputSplitter splitter = new InputSplitter()
InputSplitter splitter = new InputSplitter(sortResults:sortResults)
Map samples = splitter.split(pattern, input)

if(samples.isEmpty() && !requireMatch && pattern == "*")
Expand Down
2 changes: 1 addition & 1 deletion src/main/groovy/bpipe/PipelineContext.groovy
Expand Up @@ -959,7 +959,7 @@ class PipelineContext {

if(doExecute) {
if(Utils.box(this.@output)) {
this.output = Utils.box(fixedOutputs) + Utils.box(this.@output)
this.output = Utils.box(fixedOutputs) + Utils.box(this.@output).grep { ! it in fixedOutputs }
this.output.removeAll { it in replacedOutputs || toOutputFolder(it) in replacedOutputs}
}
else {
Expand Down
1 change: 1 addition & 0 deletions tests/ordered_input_to_parallel/cleanup.sh
@@ -0,0 +1 @@
rm -f *cutadapt.*
7 changes: 7 additions & 0 deletions tests/ordered_input_to_parallel/run.sh
@@ -0,0 +1,7 @@
source ../testsupport.sh

run

grep -q "inputs should not be equal" test.out && err "Input referenced multiple times"

true
Empty file.
Empty file.
13 changes: 13 additions & 0 deletions tests/ordered_input_to_parallel/test.groovy
@@ -0,0 +1,13 @@

cutadapt = {
produce(["cutadapt.1.fq.gz", "cutadapt.2.fq.gz"]){
exec "touch $output1; touch $output2; "
}
}

tophat = {
if(input1.toString() == input2.toString())
fail "inputs should not be equal"
}

run { cutadapt + [tophat] }
Empty file.

0 comments on commit 32cc237

Please sign in to comment.