Search code examples
nextflow

nextflow error cause: Unexpected character: '"' @ line 27, column 27. value = "${baseDir}/db/$value"


process refs {
    output:
    path "fa", emit: fa
    path "sdf", emit: sdf
    path "chrsize", emit: chrsize
    path "non", emit: non
    path "dbsnp", emit:dbsnp
    path "pvcf", emit: pvcf
    
    script:
    def dblist = file("$baseDir/db/db.list")
    dblist.text.eachline {line ->
        def tokens = line.trim().split(/\s+/)
        def (key, value) = tokens
        def (ref1, suf) = key.split(".")
        if (ref1 == params.ref) {
            value = "$baseDir/db/$value"
            "echo $value > $suf"
        }
    } 

}
workflow {
    refs().out.fa.view()
}

db.list looks like this:

hg38.fa    path1
hg38.sdf   path2
hg38.snp   path3
...
hg19.fa    pathx
hg19.sdf   pathy
...

params.ref is hg19 or hg38. I got the error message in the title. Why I got an error in line value = "${baseDir}/db/$value" or do you have some other ways to write this


Solution

  • I think I can see what you're trying to do here. The problem is that, unless you're willing to localize all the files in the db.list, the files you're trying to select for won't be available inside the working directory. A better way would be to use a Map param to include the paths to the reference files, similar to how the nf-core defines their genomes param:

    params {
        // illumina iGenomes reference file paths
        genomes {
            'GRCh37' {
                fasta       = "${params.igenomes_base}/Homo_sapiens/Ensembl/GRCh37/Sequence/WholeGenomeFasta/genome.fa"
                bwa         = "${params.igenomes_base}/Homo_sapiens/Ensembl/GRCh37/Sequence/BWAIndex/version0.6.0/"
                bowtie2     = "${params.igenomes_base}/Homo_sapiens/Ensembl/GRCh37/Sequence/Bowtie2Index/"
                star        = "${params.igenomes_base}/Homo_sapiens/Ensembl/GRCh37/Sequence/STARIndex/"
                bismark     = "${params.igenomes_base}/Homo_sapiens/Ensembl/GRCh37/Sequence/BismarkIndex/"
                gtf         = "${params.igenomes_base}/Homo_sapiens/Ensembl/GRCh37/Annotation/Genes/genes.gtf"
                bed12       = "${params.igenomes_base}/Homo_sapiens/Ensembl/GRCh37/Annotation/Genes/genes.bed"
                readme      = "${params.igenomes_base}/Homo_sapiens/Ensembl/GRCh37/Annotation/README.txt"
                mito_name   = "MT"
                macs_gsize  = "2.7e9"
                blacklist   = "${projectDir}/assets/blacklists/GRCh37-blacklist.bed"
            }
            'GRCh38' {
                fasta       = "${params.igenomes_base}/Homo_sapiens/NCBI/GRCh38/Sequence/WholeGenomeFasta/genome.fa"
                bwa         = "${params.igenomes_base}/Homo_sapiens/NCBI/GRCh38/Sequence/BWAIndex/version0.6.0/"
                bowtie2     = "${params.igenomes_base}/Homo_sapiens/NCBI/GRCh38/Sequence/Bowtie2Index/"
                star        = "${params.igenomes_base}/Homo_sapiens/NCBI/GRCh38/Sequence/STARIndex/"
                bismark     = "${params.igenomes_base}/Homo_sapiens/NCBI/GRCh38/Sequence/BismarkIndex/"
                gtf         = "${params.igenomes_base}/Homo_sapiens/NCBI/GRCh38/Annotation/Genes/genes.gtf"
                bed12       = "${params.igenomes_base}/Homo_sapiens/NCBI/GRCh38/Annotation/Genes/genes.bed"
                mito_name   = "chrM"
                macs_gsize  = "2.7e9"
                blacklist   = "${projectDir}/assets/blacklists/hg38-blacklist.bed"
            }
            ...
    

    This would then let you access each of the required files using your params.ref as the key. The nf-core wraps this logic in a function1:

    //
    // Get attribute from genome config file e.g. fasta
    //
    public static Object getGenomeAttribute(params, attribute) {
        if (params.genomes && params.genome && params.genomes.containsKey(params.genome)) {
            if (params.genomes[ params.genome ].containsKey(attribute)) {
                return params.genomes[ params.genome ][ attribute ]
            }
        }
        return null
    }