Skip to content
Snippets Groups Projects
hicstuff_sub.nf 918 B

include { BOWTIE2_ALIGNMENT } from '../../modules/local/hicstuff/align_bowtie2'

// Paired-end to Single-end
def pairToSingle(row, mates) {
    def meta = row[0].clone()
    meta.single_end = true
    meta.mates = mates
    if (mates == "R1") {
        return [meta, [ row[1][0]] ]
    }else if (mates == "R2"){
        return [meta, [ row[1][1]] ]
    }
}

// Single-end to Paired-end
def singleToPair(row){
    def meta = row[0].clone()
    meta.remove('mates')
    meta.single_end = false
    return [ meta, row[1] ]
}

workflow HICSTUFF_SUB {

    take:
    reads
    index
    ligation_site

    main:

    // Align each mates separetly and add mates information in [meta]
    ch_reads_r1 = reads.map{ it -> pairToSingle(it,"R1") }
    ch_reads_r2 = reads.map{ it -> pairToSingle(it,"R2") }
    ch_reads = ch_reads_r1.concat(ch_reads_r2)

    BOWTIE2_ALIGNMENT(
        ch_reads,
        index.collect()
    )
}