# Optional publishable output?

**URL:** <https://community.seqera.io/t/optional-publishable-output/897>\
**Category:** Ask for help\
**Created:** [June 27, 2024, 11:40pm UTC](https://community.seqera.io/t/optional-publishable-output/897 "2024-06-27T23:40:26Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![bskubi](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/bskubi/32/545_2.png) [@bskubi](https://community.seqera.io/u/bskubi)\
**Post date:** [June 27, 2024, 11:40pm UTC](https://community.seqera.io/t/optional-publishable-output/897/1 "2024-06-27T23:40:27Z")

</div>

I have a process allowing the user to optionally generate a statistics file in addition to the main process output. I’d like to have it returned as a process output and published if it is generated, but to have nothing published and no error from a failure to generated expected process outputs if the user does not specify for it to be created. Is this possible in Nextflow?

---

<div class="post-metadata">

**Author:** ![mribeirodantas](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/mribeirodantas/32/235_2.png) [@mribeirodantas](https://community.seqera.io/u/mribeirodantas)\
**Post date:** [June 28, 2024, 12:29pm UTC](https://community.seqera.io/t/optional-publishable-output/897/2 "2024-06-28T12:29:01Z")

</div>

Is it a problem if the output filenames are similar? If it’s OK, you can use the `arity` option. See the example below:

```auto
process FOO {
  input:
  path ifile

  output:
  // exactly one or two files are expected
  path('output_*.txt', arity: '1..2')

  script:
  """
  # ./do_something_with ${ifile} --output something.txt
  # ./do_something_else ${ifile} --output somethingelse.txt
  touch something.txt
  touch somethingelse.txt

  mv something.txt output_something.txt
  mv somethingelse.txt output_somethingelse.txt
  """
}

workflow {
  Channel
    .of(file('foo.txt'))
    | FOO
}

```

Output

```auto
tree work/c1/32c4bd0c9be8d84641010fb7475bac/
work/c1/32c4bd0c9be8d84641010fb7475bac/
├── foo.txt -> /Users/mribeirodantas/foo.txt
├── output_something.txt
└── output_somethingelse.txt

1 directory, 3 files

```

Commenting one of the `touch` (but it could be a conditional expression, etc):

```auto
process FOO {
  input:
  path ifile

  output:
  // exactly one or two files are expected
  path('output_*.txt', arity: '1..2')

  script:
  """
  # ./do_something_with ${ifile} --output something.txt
  # ./do_something_else ${ifile} --output somethingelse.txt
  touch something.txt
  # touch somethingelse.txt

  mv something.txt output_something.txt
  # mv somethingelse.txt output_somethingelse.txt
  """
}

workflow {
  Channel
    .of(file('foo.txt'))
    | FOO
}

```

```auto
tree work/e2/7dbaa857eb62ed98e3be3064402867/
work/e2/7dbaa857eb62ed98e3be3064402867/
├── foo.txt -> /Users/mribeirodantas/foo.txt
└── output_something.txt

1 directory, 2 files

```

---

<div class="post-metadata">

**Author:** ![bskubi](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/bskubi/32/545_2.png) [@bskubi](https://community.seqera.io/u/bskubi)\
**Post date:** [June 28, 2024, 6:49pm UTC](https://community.seqera.io/t/optional-publishable-output/897/3 "2024-06-28T18:49:49Z")

</div>

That could possibly be made to work, but the challenge is that the files produced are of distinct filetypes, and the filename extensions are used downstream to process them differently.

---

<div class="post-metadata">

**Author:** ![mribeirodantas](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/mribeirodantas/32/235_2.png) [@mribeirodantas](https://community.seqera.io/u/mribeirodantas)\
**Post date:** [June 29, 2024, 2:10am UTC](https://community.seqera.io/t/optional-publishable-output/897/4 "2024-06-29T02:10:14Z")

</div>

```auto
...
  path('output_*', arity: '1..2')
...

```

😄

---

<div class="post-metadata">

**Author:** ![bskubi](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/bskubi/32/545_2.png) [@bskubi](https://community.seqera.io/u/bskubi)\
**Post date:** [July 1, 2024, 1:40am UTC](https://community.seqera.io/t/optional-publishable-output/897/5 "2024-07-01T01:40:32Z")

</div>

Oh thanks, I’ll give that a try!

---

<div class="post-metadata">

**Author:** ![bentsherman](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/bentsherman/32/52_2.png) [@bentsherman](https://community.seqera.io/u/bentsherman)\
**Post date:** [July 1, 2024, 8:55pm UTC](https://community.seqera.io/t/optional-publishable-output/897/6 "2024-07-01T20:55:25Z")

</div>

I would not recommend using the `arity` to express this optional output because it’s not quite expressing what you mean. Instead I would specify a separate optional output channel and then publish that channel using the new [workflow output definition](https://nextflow.io/docs/latest/workflow.html#publishing-outputs).

That being said, if you aren’t willing to use this new syntax, the arity is probably the next best thing.

---

<div class="post-metadata">

**Author:** ![mahesh.binzerpanchal](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/mahesh.binzerpanchal/32/253_2.png) [@mahesh.binzerpanchal](https://community.seqera.io/u/mahesh.binzerpanchal)\
**Post date:** [July 2, 2024, 6:04pm UTC](https://community.seqera.io/t/optional-publishable-output/897/7 "2024-07-02T18:04:33Z")

</div>

There’s also the `optional: true` for files that are only sometimes created (e.g. with a flag).  
[https://www.nextflow.io/docs/latest/process.html#additional-options](https://www.nextflow.io/docs/latest/process.html#additional-options)

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/system/32/2402_2.png) [@system](https://community.seqera.io/u/system)\
**Post date:** [July 9, 2024, 6:04pm UTC](https://community.seqera.io/t/optional-publishable-output/897/8 "2024-07-09T18:04:58Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
