java-stream - NextFlow: how to use inputStream with DSL2
问题描述
Using NextFlow (DSL=2), I would like to use each line of a file as a streaming input of my workflow.
nextflow.enable.dsl=2
process bar {
input: val data
output: val result
exec:
result = data.toUpperCase()
}
workflow {
myFile = file('input_test.txt')
myReader = myFile.newReader()
myFile.withInputStream {
String line
while( line = myReader.readLine() ) {
channel.from(line) | bar | view
}
}
}
I face the problem that I can only use the "bar" process once:
Process 'bar' has been already used -- If you need to reuse the same component include it with a different name or include in a different workflow context
I have also tried to create a subworkflow that takes the channel from line and call bar.
Is there a way to use streamed data as an input using Nextflow?
Note: my final goal is not just to apply an upper case function. I would like to link several complex processes on the data stream.
Thank you!
解决方案
Your example code looks like an anti-pattern - it will try to create a new channel for each line in your input file. Instead, have a look at the splitting operators, especially the splitText operator:
workflow {
Channel.fromPath('input_test.txt')
| splitText { it.trim() } \
| bar \
| view()
}
If the above doesn't help, please describe exactly what you want to do with each line in your input file.
推荐阅读
- javascript - “prop `value` 的值无效”的错误是什么
- python - Fastest Way to Find the Dot Product of a Large Matrix of Vectors
- java - Spring Zuul - 抛出连接被拒绝
- typescript - 如何解决 passport-http-bearer TypeScript 重载类型问题?
- r - 如何计算 7 日均线?另一种方法
- html - 占位符和光标定位 CSS
- python - 动态更改 Python 'Requests' 标头以迭代 API URL 端点的问题
- laravel - Laravel 上的 Facade\Ignition\Exceptions\ViewException 错误?
- c - 为什么我的 Super Reduced String(HackerRank) 问题的解决方案在我的计算机上运行良好,但在 HackerRank 中给出错误答案?
- reactjs - 如何在功能组件中访问 props.match.params