0
votes

I tried to run my nextflow script and the first two precess worded fine, but the third process Conbinevcf reported an error, showing that the variable prefix was not found.

process Annovar_genebased {

publishDir "${params.output}/annovar", mode: 'copy'

    input:
    path 'snp_anatation' from anatation1.flatMap()
    val humandb
    val refgene

    output:
    path "*.exonic_variant_function" into end

   """
   prefix=\$(basename \$(readlink snp_anatation) .avinput)

   perl $refgene -geneanno -dbtype refGene -out \${prefix}.anatation -buildver hg19 $snp_anatation $humandb -hgvs

   rm *.log
   rm *.variant_function
   """
}


process Annovar {

publishDir "${params.output}/annovar", mode: 'copy'

    input:
    path 'snp_anatation' from anatation2.flatMap()
    val annovar_table
    val humandb

    output:
    path "*.csv" into end1

   """
   prefix=\$(basename \$(readlink snp_anatation) .avinput)

   perl $annovar_table $snp_anatation $humandb -buildver hg19 -out \${prefix}.anatation -remove -protocol refGene,cytoBand,exac03,clinvar_20200316,gnomad211_exome -operation g,r,f,f,f -nastring . -csvout  -polish
   """
}

I got stuck on this process

process Combinevcf {

publishDir "${params.output}/combinevcf", mode: 'copy'

    input:
    path 'genebased' from end.flatMap()
    path 'allbased' from end1.flatMap()

    output:
    path "*_3.csv" into end3

    """
    prefix=\$(basename \$(readlink genebased) .exonic_variant_function)
    prefix1=\$(basename \$(readlink allbased) .csv)

    cat ${prefix}.exonic_variant_function | tr -s ‘[:blank:]’ ‘,’ | awk 'BEGIN{FS=",";OFS="," }{ print \$3,\$13,\$22}' | awk ' BEGIN { OFS=", "; print "refGene", "refGene", "refGene", "refGene", "refGene", "Zogysity","chr", "filter" } { print \$0, "" } ' > ${prefix}_1.csv

    awk 'BEGIN{FS=",";OFS="," }{ print \$1,\$2,\$3,\$4,\$5,\$6,\$7,\$8,\$9,\$10,\$15,\$21,\$24,\$25}' ${prefix1}.csv > ${prefix1}_2.csv

    paste ${prefix}_1.csv ${prefix1}_2.csv > ${prefix}_3.csv
    """
}

I am not sure what went wrong, any help would be appreciated.

1

1 Answers

0
votes

You need to escape your ${prefix} with backslashes to tell nextflow that the variable prefix is in the script block scope, and not in the nextflow scope.

See https://www.nextflow.io/docs/latest/process.html#script for more info:

Since Nextflow uses the same Bash syntax for variable substitutions in strings, you must manage them carefully depending on whether you want to evaluate a Nextflow variable or a Bash variable