Hey, community! I’m trying to create a nextflow script to run a Python project. This software can take a config file or a directory as an argument to create a report. When a directory is provided, the idea is that the config file is generated from the folder structure, which contains different files (JSON files for interactive plots, static image formats like PNG, SVG, etc; tables in CSV, TXT, XLSX, etc).
Currently, the nf script is working with the config file argument but not with the directory, which is not being recognized. Therefore, I am wondering how to pass a directory path as input and build a channel from it in Nextflow, or if a file path is always expected.
Thanks in advance for your help.
This is my script:
#!/usr/bin/env nextflow
// Validate input: ensure only one of input_file or input_dir is provided
if ((params.input_file && params.input_dir) || (!params.input_file && !params.input_dir)) {
error "Provide either --input_file (config file) or --input_dir (directory), but not both."
}
process process_config_file {
input:
path config_file
val report_type
script:
"""
echo "Running VueGen with config file: $config_file"
python /Users/asaru/Downloads/vuegen-st-autorun/vuegen/main.py --config $config_file --report_type $report_type
"""
}
process process_directory {
input:
path input_dir
val report_type
script:
"""
echo "Running VueGen with directory: $input_dir"
python /Users/asaru/Downloads/vuegen-st-autorun/vuegen/main.py --directory $input_dir --report_type $report_type
"""
}
workflow {
// Create a channel for the report type
report_type_ch = Channel.value(params.report_type)
if (params.input_file) {
// Handle configuration file
file_ch = Channel.fromPath(params.input_file)
process_config_file(file_ch, report_type_ch)
} else if (params.input_dir) {
// Handle directory
dir_ch = Channel.fromPath(params.input_dir, type: 'dir', followLinks: true)
process_directory(dir_ch, report_type_ch)
}
}