<p>Below is a reproducible example. I tried to simulate the same channels using <code>chr1</code> as an example.</p>
<pre class="lang-java prettyprint-override"><code>#!/usr/bin/env nextflow

// Simulate the chunk channel
channel
    .fromPath('chunk.csv')
    .splitCsv(header:true)
    .map{row -&gt; tuple(row.chrom,row.chunks)}
    .set{chunk_ch}

// Simulate chr and chr_path as a single entry list
channel.from([&quot;chr1&quot;, &quot;chr1.txt&quot;]).toList().map{tuple(it[0], it[1])}.set{shape_in}

// uncomment to view the content
// shape_in.view()

// process of phased_ch. I modified it to output the chr and chr_path as given in your example
process phased_ch {
  echo true
  input:
  tuple val(chr), val(chr_path) from shape_in
  output:
  tuple val(&quot;<span class="math-container">${chr}"), path("$</span>{chr_path}&quot;) into phased
  script:
  &quot;&quot;&quot;
  echo <span class="math-container">${chr}
  touch $</span>{chr_path}
  &quot;&quot;&quot;
}

// joining the two channels to produce the correct join
chunk_ch.join(phased).view()

// will produce 
// [chr1, &quot;CHUNKS=([1]=&quot;&quot;0e6 3e6&quot;&quot; [2]=....)&quot;, /media/Documents/Nextflow/work/8e/2fcd9a00b04f0f5d44711068d68a0f/chr1.txt]
</code></pre>
<p><code>chunk.csv</code> contains</p>
<pre><code>chrom,chunks
chr1,&quot;CHUNKS=([1]=&quot;&quot;0e6 3e6&quot;&quot; [2]=....)&quot;
chr2,&quot;CHUNKS=([1]=&quot;&quot;0e6 3e6&quot;&quot; [2]=....)&quot;
chr3,&quot;CHUNKS=([1]=&quot;&quot;0e6 3e6&quot;&quot; [2]=....)&quot;
</code></pre>
<p>In your case, you should verify what are the contents of <code>chunk_ch</code> and <code>phased</code> on output. The first key of <code>join()</code> should be similar otherwise it won't give anything. From the documentation of <a href="https://www.nextflow.io/docs/latest/operator.html#join" rel="nofollow noreferrer">join</a>:</p>
<blockquote>
<p>The join operator creates a channel that joins together the items
emitted by two channels for which exists a matching key. The key is
defined, by default, as the first element in each item emitted.</p>
</blockquote>

CC BY-SA 4.0
2021-07-07T15:24:11.227Z
2021-07-07T15:24:11.227Z
user324810
<p>I have a csv file which describes number of chunks per chromosome, like;</p>
<pre><code>chrom,chunks
chr1,&quot;CHUNKS=([1]=&quot;&quot;0e6 3e6&quot;&quot; [2]=....)&quot;
chr2,&quot;CHUNKS=([1]=&quot;&quot;0e6 3e6&quot;&quot; [2]=....)&quot;
chr3,&quot;CHUNKS=([1]=&quot;&quot;0e6 3e6&quot;&quot; [2]=....)&quot;
.....
</code></pre>
<p>I could crate a channel as follows,</p>
<pre><code>channel
    .fromPath('chunks3.csv')
    .splitCsv(header:true)
    .map{row -&gt; tuple(row.chrom,row.chunks)}
    .set{chunk_ch}
</code></pre>
<p>It gives me chromosome with respective chunk definition.</p>
<p>But when I try to join this channel with another channel, it does not work.</p>
<p>For example I have a channel &quot;phased&quot;. It is a output channel created from a process.</p>
<pre><code>channel
    .fromFilePairs('/some/path/genetic_map_chr*_combined_b37.txt',size:1)
    .map {group_key, file_list -&gt; tuple(group_key.replaceFirst(/^*genetic_map_/,&quot;&quot;),file_list.first())}
    .set {genetic_map}

channel
    .fromFilePairs('/some/path/*hrc.r1-1.ega.grch37.chr*.{hap.gz,legend.gz,samples}',size:3)
    .map {group_key,file_list -&gt; tuple(group_key.replaceAll(/^.*.hrc\.r1-1\.ega\.grch37\.|\.haplotypes\.noibd|\.haplotypes/,&quot;&quot;),file_list)}
    .set {ref_panel}

qc1_chr
    .map{chrom,bfiles -&gt; tuple(chrom,bfiles.findAll{it.baseName.endsWith('step10')})}
    .join(ref_panel).join(genetic_map)
    .into {shape_in;imp_in}

process phasing {
    publishDir params.out, mode:'copy'
    
    input:
    tuple val(chrom), path(input_bed), path(input_ref), path(input_map) from shape_in
    
    output:
    tuple val(&quot;<span class="math-container">${chrom}"),path("$</span>{chrom}.*&quot;) into phased

    script:
    def (bed, bim, fam) = input_bed
    def (haplotype, legend, sample) = input_ref
    &quot;&quot;&quot;
    shapeit --thread &quot;<span class="math-container">${task.cpus}" --input-bed "$</span>{bed}&quot; &quot;<span class="math-container">${bim}" "$</span>{fam}&quot; --input-map &quot;<span class="math-container">${input_map}" --input-ref "$</span>{haplotype}&quot; &quot;<span class="math-container">${legend}" "$</span>{sample}&quot; --duohmm --
    output-max &quot;${chrom}.step10&quot; --seed 54321
    &quot;&quot;&quot;
}
</code></pre>
<p>Which emits something like:</p>
<pre><code>phased.view()
[chr1,[file1]
chr2,[file2]
chr3,[file3]....]
</code></pre>
<p>If I try <code>chunk_ch.join(phased)</code> it gives nothing.</p>
<p>Any help?</p>

<nextflow>
splitCsv map with text, join with another channel, nextflow
# splitCsv map with text, join with another channel, nextflow

(Asked by: username_0 on 2021-04-15)

I have a csv file which describes number of chunks per chromosome, like;
chrom,chunks
chr1,"CHUNKS=([1]=""0e6 3e6"" [2]=....)"
chr2,"CHUNKS=([1]=""0e6 3e6"" [2]=....)"
chr3,"CHUNKS=([1]=""0e6 3e6"" [2]=....)"
.....

I could crate a channel as follows,
channel
    .fromPath('chunks3.csv')
    .splitCsv(header:true)
    .map{row -> tuple(row.chrom,row.chunks)}
    .set{chunk_ch}

It gives me chromosome with respective chunk definition.
But when I try to join this channel with another channel, it does not work.
For example I have a channel "phased". It is a output channel created from a process.
channel
    .fromFilePairs('/some/path/genetic_map_chr*_combined_b37.txt',size:1)
    .map {group_key, file_list -> tuple(group_key.replaceFirst(/^*genetic_map_/,""),file_list.first())}
    .set {genetic_map}

channel
    .fromFilePairs('/some/path/*hrc.r1-1.ega.grch37.chr*.{hap.gz,legend.gz,samples}',size:3)
    .map {group_key,file_list -> tuple(group_key.replaceAll(/^.*.hrc\.r1-1\.ega\.grch37\.|\.haplotypes\.noibd|\.haplotypes/,""),file_list)}
    .set {ref_panel}

qc1_chr
    .map{chrom,bfiles -> tuple(chrom,bfiles.findAll{it.baseName.endsWith('step10')})}
    .join(ref_panel).join(genetic_map)
    .into {shape_in;imp_in}

process phasing {
    publishDir params.out, mode:'copy'
    
    input:
    tuple val(chrom), path(input_bed), path(input_ref), path(input_map) from shape_in
    
    output:
    tuple val("${chrom}"),path("${chrom}.*") into phased

    script:
    def (bed, bim, fam) = input_bed
    def (haplotype, legend, sample) = input_ref
    """
    shapeit --thread "${task.cpus}" --input-bed "${bed}" "${bim}" "${fam}" --input-map "${input_map}" --input-ref "${haplotype}" "${legend}" "${sample}" --duohmm --
    output-max "${chrom}.step10" --seed 54321
    """
}

Which emits something like:
phased.view()
[chr1,[file1]
chr2,[file2]
chr3,[file3]....]

If I try chunk_ch.join(phased) it gives nothing.
Any help?

**Tags:** nextflow

---

## 1 answers

### Answer by username_1 on 2021-07-07. Score: 1 | Accepted answer

Below is a reproducible example. I tried to simulate the same channels using chr1 as an example.
#!/usr/bin/env nextflow

// Simulate the chunk channel
channel
    .fromPath('chunk.csv')
    .splitCsv(header:true)
    .map{row -> tuple(row.chrom,row.chunks)}
    .set{chunk_ch}

// Simulate chr and chr_path as a single entry list
channel.from(["chr1", "chr1.txt"]).toList().map{tuple(it[0], it[1])}.set{shape_in}

// uncomment to view the content
// shape_in.view()

// process of phased_ch. I modified it to output the chr and chr_path as given in your example
process phased_ch {
  echo true
  input:
  tuple val(chr), val(chr_path) from shape_in
  output:
  tuple val("${chr}"), path("${chr_path}") into phased
  script:
  """
  echo ${chr}
  touch ${chr_path}
  """
}

// joining the two channels to produce the correct join
chunk_ch.join(phased).view()

// will produce 
// [chr1, "CHUNKS=([1]=""0e6 3e6"" [2]=....)", /media/Documents/Nextflow/work/8e/2fcd9a00b04f0f5d44711068d68a0f/chr1.txt]

chunk.csv contains
chrom,chunks
chr1,"CHUNKS=([1]=""0e6 3e6"" [2]=....)"
chr2,"CHUNKS=([1]=""0e6 3e6"" [2]=....)"
chr3,"CHUNKS=([1]=""0e6 3e6"" [2]=....)"

In your case, you should verify what are the contents of chunk_ch and phased on output. The first key of join() should be similar otherwise it won't give anything. From the documentation of join:

The join operator creates a channel that joins together the items
emitted by two channels for which exists a matching key. The key is
defined, by default, as the first element in each item emitted.


---

