How to access/print elements of a map?

Hello there,

I read a eight columnar CSV file. The data look like as the below:

sample1,DNA_N_R1,DNA_N_R2,DNA_T_R1,DNA_T_R2,RNA_T_01_R1,RNA_T_01_R2,T_01

sample1,DNA_N_R1,DNA_N_R2,DNA_T_R1,DNA_T_R2,RNA_T_02_R1,RNA_T_02_R2,T_02

sample2,DNA_N_R1,DNA_N_R2,DNA_T_R1,DNA_T_R2,RNA_T_01_R1,RNA_T_01_R2,T_01

I’d like to access/print elements of the map, say for example, time_point

Below is my code:

workflow {

Channel.fromPath(file(“input_timestamp.csv”))
.splitCsv(sep: ‘,’)
.map { row →
// Extract relevant information
def sample_ID = row[0]
def normal_Reads = tuple(file(row[1]), file(row[2]))
def tumor_Reads = tuple(file(row[3]), file(row[4]))
def rna_Reads = tuple(file(row[5]), file(row[6]))
def time_Point = row[7]

        // Return a map with the processed information
        return [sample_name: sample_ID, normal: normal_Reads, tumor: tumor_Reads, rna: rna_Reads, time_point: time_Point]
    }
    .set { samples }

samples.view { “$it” }
//samples[‘sample_name’].view { “$it” }

}

I print complete map using .view

You can print the value for the sample_name key the following way:

samples.view { "${it.sample_name}" }

Output:

Thank you. It worked.

1 Like

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