diff --git a/plugins/nf-iridanext/src/main/nextflow/iridanext/IDParser.groovy b/plugins/nf-iridanext/src/main/nextflow/iridanext/IDParser.groovy new file mode 100644 index 0000000..78747b6 --- /dev/null +++ b/plugins/nf-iridanext/src/main/nextflow/iridanext/IDParser.groovy @@ -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 + } + +} diff --git a/plugins/nf-iridanext/src/main/nextflow/iridanext/IridaNextJSONOutput.groovy b/plugins/nf-iridanext/src/main/nextflow/iridanext/IridaNextJSONOutput.groovy index d128245..dcb4a3b 100644 --- a/plugins/nf-iridanext/src/main/nextflow/iridanext/IridaNextJSONOutput.groovy +++ b/plugins/nf-iridanext/src/main/nextflow/iridanext/IridaNextJSONOutput.groovy @@ -39,7 +39,7 @@ import groovy.util.logging.Slf4j class IridaNextJSONOutput { private Map files = ["global": [], "samples": [:]] private Map metadata = ["samples": [:]] - private Map> scopeIds = ["samples": [] as Set] + private static Map> scopeIds = ["samples": [] as Set] private Path relativizePath private Boolean shouldRelativize private Schema jsonSchema @@ -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) } diff --git a/plugins/nf-iridanext/src/resources/META-INF/extensions.idx b/plugins/nf-iridanext/src/resources/META-INF/extensions.idx index 34261d1..1a2e867 100644 --- a/plugins/nf-iridanext/src/resources/META-INF/extensions.idx +++ b/plugins/nf-iridanext/src/resources/META-INF/extensions.idx @@ -1 +1,2 @@ -nextflow.iridanext.IridaNextObserverFactory \ No newline at end of file +nextflow.iridanext.IridaNextObserverFactory +nextflow.iridanext.IDParser \ No newline at end of file