Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example for optional input in tuple? #42

Open
ScottNortonPhD opened this issue Feb 2, 2023 · 1 comment
Open

Example for optional input in tuple? #42

ScottNortonPhD opened this issue Feb 2, 2023 · 1 comment

Comments

@ScottNortonPhD
Copy link

ScottNortonPhD commented Feb 2, 2023

I am trying to run a configuration where the input is a tuple of paths, some of which are optional. The pattern in this repository works for separate path inputs (or, so says the author), but extending it to my use case results in the error Not a valid path value: NO_FILE.

In this simple example demonstrating the issue, the input is a CSV file defining RNA-seq sample names, forward and reverse read fastqs, and a STAR genome index to align them to. The reverse read is optional.

My question to the community is how I can work around this issue.

Repository setup

nextflow.config

params {
  manifest = null  // csv file name,R1,R2?,index
  outdir = "outs"  // save output bams
}
profiles {
  conda {
    conda.enabled = true
    process.conda = "star samtools"
  }
}

main.nf

process MyProcess {
  publishDir outdir, mode: "copy"
  input:
    tuple val(name), path(R1), path(R2), path(index)
    path outdir
  output:
    path "${name}_Aligned.out.sortedByCoord.bam"
    path "${name}_Aligned.out.sortedByCoord.bam.bai"
  script:
    R2_arg = R2.name == "NO_FILE" ? "" : R2
"""
STAR --readFilesIn $R1 $R2_arg --readFilesCommand gunzip -c \
     --genomeDir $index --outSAMtype BAM SortedByCoordinate \
     --outFileNamePrefix ${name}_
samtools index ${name}_Aligned.out.sortedByCoord.bam
"""
}

workflow {
  MyProcess(
    file(manifest).read().splitCsv(header: ["name", "R1", "R2", "index"]).map{it.R2 = it.R2 ?: "NO_FILE"},
    params.outdir
  )
}

Run

nextflow run main.nf [-profile conda] --manifest path/to/manifest.csv
@mribeirodantas
Copy link
Member

mribeirodantas commented Feb 2, 2023

Hello, Scott.

"NO_FILE" is a value, not a path. If you pass file("NO_FILE"), the process will accept the channel as valid. Check the code below. It does one thing is the input is a file, and something else if it's a string that equals NO_FILE:

process FOO {
  debug true
  input:
    path x
  output:
    stdout
  script:
    if (x.name == 'NO_FILE')
      """
      echo $x
      """
    else
      """
      cat $x
      """
}

workflow {
  // FOO(file('NO_FILE'))
  FOO(file('asd.nf'))
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants