How to access attributes from subMap and branch to print

Hi developers,

I’m interested to print attributes created by subMap but so far I’ve not been able to make much success.

workflow {

        .splitCsv(header: true).map { it ->
                it.subMap("batch", "timepoint", "tissue", "sequencing_type"),
        .branch { meta, fastq ->
            rna: meta.tissue == "rna" && meta.sequencing_type == "rna"
            germline: meta.tissue == "normal" && meta.sequencing_type == "wes"
            tumor: meta.tissue == "tumor" && meta.sequencing_type == "wes"
            other: true
        .set { input_ch }


I’d like to print say input_ch.germline.tumor or input_ch.germline.batch or input_ch.germline.tissue

How do I achieve it?

You can use closures with operators to achieve that. If you want to print to the screen, you can do with:


   input_ch.germline.view { it -> it[0]['batch'] }

This is your first channel element:

  [batch:SEMA-MM-001, timepoint:MM-3309-T-01, tissue:normal, sequencing_type:wes],
  [/data1/raw_data/WES/sema4/SEMA-MM-001DNA/MM-3309-DNA-N-01-01_L001_R1_001.fastq.gz, /data1/raw_data/WES/sema4/SEMA-MM001DNA/MM-3309-DNA-N-01-01_L001_R2_001.fastq.gz]

This is the first item (it[0]):


And this is it[0]['batch']:



Instead of viewing them all, you could want to see only the channel elements whose batch value equals SEMA-MM-003. Then you’d do:


  input_ch.germline.filter { it[0]['batch'] == 'SEMA-MM-003' }.view()


PS: No need to use the -dump-channels option here. I was answering your other question so I kept using it out of habit :laughing:

Thank you, it works and helps.

How about printing batch timepoint or tissue together?

input_ch.germline.view { it -> it[0]['batch'], it[0]['tissue']   }

I used following code it failed with error of

ERROR ~ Unknown method invocation call on LinkedHashMap type

long_format_data.csv (11.8 KB)

You need to encapsulate it within brackets. See the corrected snippet below:

input_ch.germline.view { it -> [it[0]['batch'], it[0]['tissue']]  }

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