-
Notifications
You must be signed in to change notification settings - Fork 651
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Paolo Di Tommaso <[email protected]>
- Loading branch information
1 parent
e7c8722
commit 88ae57e
Showing
4 changed files
with
116 additions
and
32 deletions.
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
modules/nextflow/src/main/groovy/nextflow/extension/ChainOp.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* Copyright 2013-2024, Seqera Labs | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package nextflow.extension | ||
|
||
import groovy.transform.CompileStatic | ||
import groovyx.gpars.dataflow.DataflowReadChannel | ||
import groovyx.gpars.dataflow.DataflowWriteChannel | ||
import groovyx.gpars.dataflow.operator.ChainWithClosure | ||
import groovyx.gpars.dataflow.operator.DataflowEventListener | ||
|
||
import static nextflow.extension.DataflowHelper.newOperator | ||
import static nextflow.extension.DataflowHelper.OpParams | ||
|
||
/** | ||
* Implements the chain operator | ||
* | ||
* @author Paolo Di Tommaso <[email protected]> | ||
*/ | ||
@CompileStatic | ||
class ChainOp { | ||
|
||
private DataflowReadChannel source | ||
private DataflowWriteChannel target | ||
private List<DataflowEventListener> listeners = List.of() | ||
private boolean accumulator | ||
private Closure action | ||
|
||
static ChainOp create() { | ||
new ChainOp() | ||
} | ||
|
||
ChainOp withSource(DataflowReadChannel source) { | ||
assert source | ||
this.source = source | ||
return this | ||
} | ||
|
||
ChainOp withTarget(DataflowWriteChannel target) { | ||
assert target | ||
this.target = target | ||
return this | ||
} | ||
|
||
ChainOp withListener(DataflowEventListener listener) { | ||
assert listener != null | ||
this.listeners = List.of(listener) | ||
return this | ||
} | ||
|
||
ChainOp withListeners(List<DataflowEventListener> listeners) { | ||
assert listeners != null | ||
this.listeners = listeners | ||
return this | ||
} | ||
|
||
ChainOp withAccumulator(boolean value) { | ||
this.accumulator = value | ||
return this | ||
} | ||
|
||
ChainOp withAction(Closure action) { | ||
this.action = action | ||
return this | ||
} | ||
|
||
DataflowWriteChannel apply() { | ||
assert source | ||
assert target | ||
assert action | ||
|
||
final OpParams parameters = new OpParams() | ||
.withInput(source) | ||
.withOutput(target) | ||
.withAccumulator(accumulator) | ||
.withListeners(listeners) | ||
|
||
newOperator(parameters, new ChainWithClosure(action)) | ||
return target | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters