Skip to content

Commit

Permalink
Adding channel operator to include sample IDs.
Browse files Browse the repository at this point in the history
  • Loading branch information
emarinier committed Jan 28, 2025
1 parent d4b27a8 commit 61cc54f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
36 changes: 36 additions & 0 deletions plugins/nf-iridanext/src/main/nextflow/iridanext/IDParser.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package nextflow.iridanext

import groovyx.gpars.dataflow.DataflowWriteChannel
import groovyx.gpars.dataflow.DataflowReadChannel
import nextflow.Channel
import nextflow.extension.CH
import nextflow.extension.DataflowHelper
import nextflow.Session
import nextflow.plugin.extension.Operator
import nextflow.plugin.extension.PluginExtensionPoint
import nextflow.iridanext.IridaNextJSONOutput


class IDParser extends PluginExtensionPoint {

@Override
void init(Session session) {}

@Operator
DataflowWriteChannel parseSamplesheet( DataflowReadChannel source ) {
final target = CH.createBy(source)

final next = { it ->
IridaNextJSONOutput.addId("samples", it[0].id)
target.bind(it)
}

final done = {
target.bind(Channel.STOP)
}

DataflowHelper.subscribeImpl(source, [onNext: next, onComplete: done])
return target
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import groovy.util.logging.Slf4j
class IridaNextJSONOutput {
private Map files = ["global": [], "samples": [:]]
private Map metadata = ["samples": [:]]
private Map<String,Set<String>> scopeIds = ["samples": [] as Set<String>]
private static Map<String,Set<String>> scopeIds = ["samples": [] as Set<String>]
private Path relativizePath
private Boolean shouldRelativize
private Schema jsonSchema
Expand Down Expand Up @@ -99,7 +99,7 @@ class IridaNextJSONOutput {
}
}

public void addId(String scope, String id) {
public static void addId(String scope, String id) {
log.trace "Adding scope=${scope} id=${id}"
scopeIds[scope].add(id)
}
Expand Down
3 changes: 2 additions & 1 deletion plugins/nf-iridanext/src/resources/META-INF/extensions.idx
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
nextflow.iridanext.IridaNextObserverFactory
nextflow.iridanext.IridaNextObserverFactory
nextflow.iridanext.IDParser

0 comments on commit 61cc54f

Please sign in to comment.