3
$\begingroup$

I'm attempting to run a nextflow pipeline and have begun getting unexpected output for a few of the processes in my pipeline. I believe this to be a syntax error, but I am not sure where to correct it. Any help is finding where my error is located is appreciated.

Error

#!/usr/bin/env nextflow
 nextflow.enable.dsl=2
 import groovy.io.*




  process hisat2Alignment {
    fastq1 = NS.1389.002.NEBNext_dual_i7_*_R1.fastq.gz
    fastq2 = NS.1389.002.NEBNext_dual_i7_*_R2.fastq.gz
    input:
    tuple path("fastq1"), path("fastq2")

    output:
    tuple path("*.sam"), val(fastq1.baseName.substring(0, fastq1.baseName.indexOf("_R1")))
    script:
    """
    hisat2 -p 16 -x genome -1 ${fastq1} -2 ${fastq2} -S mapped_${baseName}.sam
    """


 }

process Stringtier {
    publishDir "${params.baseDir}/assembled/$baseName", mode: "move"
    env {
     PATH = $PATH:/data/selena/stringtie-2.2.1
    }

    input:
    tuple path(mapped_bam), val(baseName)
    output:
    tuple path("*.gtf"), val(baseName)


    script:
    """
    stringtie -e -G ${params.annotation} -o ${baseName}.gtf ${mapped_bam}

    """
}

 workflow {
    samples = new File(params.configFilePath).readLines()*.split('\t');
    samples  = Channel.fromList(samples);
    hisat2Alignment(samples);
    assembled = Stringtier(samples)
    
}
$\endgroup$
0

1 Answer 1

2
$\begingroup$

Nextflow does not have an env process directive. If stringtie is not already in your $PATH, you'll need to append it before running nextflow, for example:

export PATH="${PATH}:/data/selena/stringtie-2.2.1"
nextflow run de-pipeline.nf

However, you may prefer to avoid local tool installations altogether, and use either the conda or container process directives. The latter will however require a container runtime, like Docker or Singularity.

You may also consider including a 'sample name' or some sort of sample identifier in your config file, which I suspect is just a simple tab-separated file of filenames. This would greatly simplify your workflow. For example:

params.samplesheet = './samples.tsv'
params.genome = './genomes/GRCh38/GRCh38'
params.gtf = './Homo_sapiens.GRCh38.gtf'

genome_name = file( params.genome ).name
genome_path = file( params.genome ).parent

params.outdir = './results'
process HISAT2 {

    tag { sample }

    publishDir "${params.outdir}/HISAT2/${sample}", mode: 'copy'

    cpus 16

    input:
    tuple val(sample), path(reads)
    path genome_dir

    output:
    tuple val(sample), path("${sample}.sam")

    script:
    def (r1, r2) = reads

    """
    hisat2 \\
        -p ${task.cpus} \\
        -x "${genome_dir}/${genome_name}" \\
        -1 "${r1}" \\
        -2 "${r2}" \\
        -S "${sample}.sam"
    """
}
process SAMtools_sort {

    tag { sample }

    input:
    tuple val(sample), path(bam)

    output:
    tuple val(sample), path("${sample}.sorted.bam")

    """
    samtools sort \\
        -o "${sample}.sorted.bam" \\
        "${bam}"
    """
}
process StringTie {

    tag { sample }

    publishDir "${params.outdir}/StringTie/${sample}", mode: 'copy'

    input:
    tuple val(sample), path(bam)
    path gtf

    output:
    tuple val(sample), path("${sample}.gtf")

    """
    stringtie \\
        -e \\
        -G "${gtf}" \\
        -o "${sample}.gtf" \\
        "${bam}"
    """
}
workflow {

    gtf = file( params.gtf )

    Channel
        .fromPath( params.samplesheet )
        .splitCsv( sep: '\t' )
        .map { sample, fq1, fq2 ->
            def reads = tuple( file(fq1), file(fq2) )

            tuple( sample, reads )
        }
        .set { samples }

    HISAT2( samples, genome_path )

    SAMtools_sort( HISAT2.out )

    StringTie( SAMtools_sort.out, gtf )
}

Where the contents of the input sample sheet (e.g. samples.tsv) looks like:

sample_A    /path/to/reads/A_R1.fastq.gz    /path/to/reads/A_R2.fastq.gz
sample_B    /path/to/reads/B_R1.fastq.gz    /path/to/reads/B_R2.fastq.gz
sample_C    /path/to/reads/C_R1.fastq.gz    /path/to/reads/C_R2.fastq.gz

Results:

$ nextflow run main.nf
N E X T F L O W  ~  version 22.04.0
Launching `main.nf` [adoring_poisson] DSL2 - revision: 43e8c59949
executor >  local (9)
[60/1cba2f] process > HISAT2 (sample_A)        [100%] 3 of 3 ✔
[0a/931a07] process > SAMtools_sort (sample_A) [100%] 3 of 3 ✔
[6d/7689a2] process > StringTie (sample_A)     [100%] 3 of 3 ✔
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.