# How to access attributes from subMap and branch to print

**URL:** <https://community.seqera.io/t/how-to-access-attributes-from-submap-and-branch-to-print/522>\
**Category:** Ask for help\
**Created:** [February 28, 2024, 8:38pm UTC](https://community.seqera.io/t/how-to-access-attributes-from-submap-and-branch-to-print/522 "2024-02-28T20:38:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![complexgenome](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/complexgenome/32/392_2.png) [@complexgenome](https://community.seqera.io/u/complexgenome)\
**Post date:** [February 28, 2024, 8:38pm UTC](https://community.seqera.io/t/how-to-access-attributes-from-submap-and-branch-to-print/522/1 "2024-02-28T20:38:53Z")

</div>

Hi developers,

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

```auto
workflow {

Channel.fromPath("long_format_data.csv")
        .splitCsv(header: true).map { it ->
            [
                it.subMap("batch", "timepoint", "tissue", "sequencing_type"),
                [
                    file(it.fastq_1),
                    file(it.fastq_2)
                ]
            ]
        }
        .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 }

input_ch.germline.view()
    
}

```

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?

---

<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:** [February 29, 2024, 12:10pm UTC](https://community.seqera.io/t/how-to-access-attributes-from-submap-and-branch-to-print/522/2 "2024-02-29T12:10:43Z")

</div>

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

```Groovy

  ...

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

```

This is your first channel element:

```Groovy
[
  [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]`):

```Groovy
[
  batch:SEMA-MM-001,
  timepoint:MM-3309-T-01,
  tissue:normal,
  sequencing_type:wes
]

```

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

```Groovy
SEMA-MM-001

```

Output:

 ![Captura de Tela 2024-02-29 às 09.10.36](https://europe1.discourse-cdn.com/flex013/uploads/seqera/original/1X/69b722ce0662486b348e660a7246523d78424311.jpeg)

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:

```Groovy

  ...

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

```

Output:

 ![Captura de Tela 2024-02-29 às 09.15.38](https://europe1.discourse-cdn.com/flex013/uploads/seqera/original/1X/27bdb03aef3f4c87dc9e1629f870095d75c7e370.jpeg)

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

---

<div class="post-metadata">

**Author:** ![complexgenome](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/complexgenome/32/392_2.png) [@complexgenome](https://community.seqera.io/u/complexgenome)\
**Post date:** [February 29, 2024, 5:31pm UTC](https://community.seqera.io/t/how-to-access-attributes-from-submap-and-branch-to-print/522/3 "2024-02-29T17:31:04Z")

</div>

@mribeirodantas  
Thank you, it works and helps.

How about printing batch timepoint or tissue together?

```auto
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](https://community.seqera.io/uploads/short-url/wyvvoimoennM1EjqiVrslLrR9KY.csv) (11.8 KB)

---

<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:** [February 29, 2024, 8:16pm UTC](https://community.seqera.io/t/how-to-access-attributes-from-submap-and-branch-to-print/522/4 "2024-02-29T20:16:45Z")

</div>

> [@complexgenome](#):
>
> ```auto
> input_ch.germline.view { it -> it[0]['batch'], it[0]['tissue'] }
> 
> ```

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

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

```

---

<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:** [March 13, 2024, 1:36pm UTC](https://community.seqera.io/t/how-to-access-attributes-from-submap-and-branch-to-print/522/5 "2024-03-13T13:36:36Z")

</div>

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