Accessing a complex key in a config file

Viewed 66

I'm trying to access a variable in a nextflow.config file during the execution of a pipeline. I want to supply image_standard as a string in run.nf and I want to receive eu.gcr.io/proj_name/image1:latest as an output. I figured out a way to obtain the content of the .config file within the nextflow script, but I don't know how to access this specific property.

This is my nextflow.config file:

process {
    withLabel: image_standard {
        container = "eu.gcr.io/proj_name/image1:latest"
    }
    withLabel: image_deluxe {
        container = "eu.gcr.io/proj_name/image2:latest"
    }
}

the run.nf

  x =  workflow.configFiles[0]
  Properties properties = new Properties()
  File propertiesFile = new File("${x}")
        propertiesFile.withInputStream {
        properties.load(it)
    }
    log.info "${properties.process}"

Which just prints the line:

{

1 Answers

You could try instead slurping the config file and selecting the process you want using the ProcessConfig class and the applyConfigSelector() method:

import nextflow.config.ConfigParser
import nextflow.script.ProcessConfig

def config_file = file("${baseDir}/nextflow.config")
def config = new ConfigParser().setIgnoreIncludes(true).parse(config_file.text)

def process = new ProcessConfig([:])
process.applyConfigSelector(config.process, 'withLabel:', 'image_standard')

println(process.container)
Related