<p>I think this cheat sheet might help:
<a href="https://github.com/danrlu/Nextflow_cheatsheet/blob/main/nextflow_cheatsheet.pdf" rel="nofollow noreferrer">https://github.com/danrlu/Nextflow_cheatsheet/blob/main/nextflow_cheatsheet.pdf</a></p>

CC BY-SA 4.0
2022-02-10T13:23:55.543Z
 Love the cheat sheet!
Mark Ebbert
CC BY-SA 4.0
2022-02-10T10:38:07.617Z
2022-02-10T10:38:07.617Z
juke34
<p>The <a href="https://www.nextflow.io/docs/latest/operator.html#combine" rel="nofollow noreferrer">combine</a> operator can be used to produce the Cartesian product:</p>
<pre><code>sample_bams = Channel.fromPath( './path/to/bams/*.bam' )
intervals = Channel.of( '1:10000-20000', '5:55555-77777' )

sample_bams
    .combine(intervals)
    .set { combined_inputs }


process test {

    echo true

    input:
    tuple path(bam), val(interval) from combined_inputs

    &quot;&quot;&quot;
    echo -n &quot;<span class="math-container">${interval} $</span>{bam}&quot;
    &quot;&quot;&quot;
}
</code></pre>
<p>Regarding the related query: Correct. The from and into 'bind' declarations can be omitted</p>

CC BY-SA 4.0
2022-02-10T10:35:15.877Z
we should crown Steve as King Of Nextflow Answers
Pallie
CC BY-SA 4.0
2022-02-10T01:57:46.470Z
2022-02-10T23:13:31.693Z
2022-02-10T23:13:31.693Z
Steve
<p>Using <code>Nextflow</code>, I need to submit <code>x * y</code> jobs where <code>x</code> is the number of input <code>.bam</code> files and <code>y</code> is the number of genome intervals (e.g., <code>&lt;chrom&gt;:&lt;start&gt;-&lt;end&gt;</code>). i.e., for every <code>.bam</code> file, submit a single job for every defined interval.</p>
<p>I have tried a few variations with no luck (see below).</p>
<p><strong>Ultimate question:</strong> For each <code>.bam</code> file, how do I submit a single job for every defined genome interval using <code>NextFlow</code>?</p>
<h2>Attempts</h2>
<p><strong>Attempt 1 (submit both as individual <code>Channels</code>):</strong></p>
<p>Only submits one <code>.bam</code> for all intervals.</p>
<pre><code>sample_bams = Channel.fromPath(sample_input_path + &quot;*.bam&quot;)
intervals = Channel.from(['1:10000-20000', '5:55555-77777'])
PROC(sample_bams, intervals)
</code></pre>
<p><strong>Attempt 2 (submit as tuple of mapped <code>Channel</code>s):</strong></p>
<p>Submits only 10 jobs and fails because the interval <code>Channel</code> is passed as <code>DataflowBroadcast around DataflowStream[?]</code> object. The <code>PROC</code> was changed to receive a tuple rather than individual arguments.</p>
<pre><code>sample_interval_tuples = Channel.fromPath(sample_input_path + &quot;*.bam&quot;)
                         .map { sample_file -&gt; tuple(sample_file, align_to_ref, DRF_jar, Channel.from(['1:10000-20000', '5:55555-77777'])) }
</code></pre>
<p><strong>Attempt 3 (submit as tuple of mapped <code>.bam</code>s to non-<code>Channel</code> of intervals)</strong>:</p>
<p>Submits 10 jobs and fails because the intervals are passed as a single list. The <code>PROC</code> was changed to receive a tuple rather than individual arguments.</p>
<pre><code>sample_interval_tuples = Channel.fromPath(sample_input_path + &quot;*.bam&quot;)
                         .map { sample_file -&gt; tuple(sample_file, align_to_ref, DRF_jar, ['1:10000-20000', '5:55555-77777']) }
</code></pre>
<p>Really appreciate your help!</p>
<p>related query: for DSL v2, we wouldn't include from combined_inputs in the input, yeah?</p>

<nextflow>
Nextflow: how to create many-to-many tuple for process
# Nextflow: how to create many-to-many tuple for process

(Asked by: username_0 on 2022-02-10)

Using Nextflow, I need to submit x * y jobs where x is the number of input .bam files and y is the number of genome intervals (e.g., :-). i.e., for every .bam file, submit a single job for every defined interval.
I have tried a few variations with no luck (see below).
Ultimate question: For each .bam file, how do I submit a single job for every defined genome interval using NextFlow?
Attempts
Attempt 1 (submit both as individual Channels):
Only submits one .bam for all intervals.
sample_bams = Channel.fromPath(sample_input_path + "*.bam")
intervals = Channel.from(['1:10000-20000', '5:55555-77777'])
PROC(sample_bams, intervals)

Attempt 2 (submit as tuple of mapped Channels):
Submits only 10 jobs and fails because the interval Channel is passed as DataflowBroadcast around DataflowStream[?] object. The PROC was changed to receive a tuple rather than individual arguments.
sample_interval_tuples = Channel.fromPath(sample_input_path + "*.bam")
                         .map { sample_file -> tuple(sample_file, align_to_ref, DRF_jar, Channel.from(['1:10000-20000', '5:55555-77777'])) }

Attempt 3 (submit as tuple of mapped .bams to non-Channel of intervals):
Submits 10 jobs and fails because the intervals are passed as a single list. The PROC was changed to receive a tuple rather than individual arguments.
sample_interval_tuples = Channel.fromPath(sample_input_path + "*.bam")
                         .map { sample_file -> tuple(sample_file, align_to_ref, DRF_jar, ['1:10000-20000', '5:55555-77777']) }

Really appreciate your help!
related query: for DSL v2, we wouldn't include from combined_inputs in the input, yeah?

**Tags:** nextflow

---

## 2 answers

### Answer by username_2 on 2022-02-10. Score: 4 | Accepted answer

The combine operator can be used to produce the Cartesian product:
sample_bams = Channel.fromPath( './path/to/bams/*.bam' )
intervals = Channel.of( '1:10000-20000', '5:55555-77777' )

sample_bams
    .combine(intervals)
    .set { combined_inputs }


process test {

    echo true

    input:
    tuple path(bam), val(interval) from combined_inputs

    """
    echo -n "${interval} ${bam}"
    """
}

Regarding the related query: Correct. The from and into 'bind' declarations can be omitted

> **Comments:**
> **username_3**: we should crown Steve as King Of Nextflow Answers  

---

### Answer by username_1 on 2022-02-10. Score: 2

I think this cheat sheet might help:
<https://github.com/danrlu/Nextflow_cheatsheet/blob/main/nextflow_cheatsheet.pdf>

> **Comments:**
> **username_0**:  Love the cheat sheet!  

---

