nextflow.enable.dsl=2

/*
Testing pipeline for marseq scRNASeq analysis
*/

include { SPLIT } from "./modules/split"
include { FASTKMERS } from "./modules/fastkmers"
include { MERGEKMER } from "./modules/mergekmer"
include { COLLATEKMER } from "./modules/mergekmer"


Channel.fromPath( file(params.csv) )
                    .splitCsv(header: true)
                    .multiMap{row ->
                        fastq_r1 = file("${row.r1}")
                        fastq_r2 = file("${row.r2}")
                        r1: [['id': fastq_r1.simpleName, 'specie': row.specie, 'sex': row.sex, 'read': 'r1'], fastq_r1]
                        r2: [['id': fastq_r1.simpleName, 'specie': row.specie, 'sex': row.sex, 'read': 'r2'], fastq_r2]
                    }
                    .set{ fastq }

workflow {
  SPLIT(fastq.r1.mix(fastq.r2))
  FASTKMERS(SPLIT.out.fastq.transpose())
  MERGEKMER(FASTKMERS.out.csv.groupTuple())
  COLLATEKMER(MERGEKMER.out.csv)
}