I'd like to merge files from different lanes for forward and reverse reads. For e.g., if a sample A has three lanes in forward, and three reverse, ultimately one reverse and one forward is to be generated. I have normal and tumor for each sample. N as normal and T as tumor.
The lanes files are for e.g. as:
MM-265-DNA-N-01-01_L003_R1_001.fastq.gz
MM-265-DNA-N-01-01_L003_R2_001.fastq.gz
MM-265-DNA-N-01-01_L004_R1_001.fastq.gz
MM-265-DNA-N-01-01_L004_R2_001.fastq.gz
MM-265-DNA-T-01-01_L003_R1_001.fastq.gz
MM-265-DNA-T-01-01_L003_R2_001.fastq.gz
MM-265-DNA-T-01-01_L004_R1_001.fastq.gz
MM-265-DNA-T-01-01_L004_R2_001.fastq.gz
MM-465-DNA-N-01-01_L003_R1_001.fastq.gz
MM-465-DNA-N-01-01_L003_R2_001.fastq.gz
MM-465-DNA-N-01-01_L004_R1_001.fastq.gz
MM-465-DNA-N-01-01_L004_R2_001.fastq.gz
MM-465-DNA-T-01-01_L003_R1_001.fastq.gz
MM-465-DNA-T-01-01_L003_R2_001.fastq.gz
MM-465-DNA-T-01-01_L004_R1_001.fastq.gz
MM-465-DNA-T-01-01_L004_R2_001.fastq.gz
The final output needs to be as:
MM-465_normal_R1.fastq MM-465_normal_R2.fastq
MM-465_tumor_R1.fastq MM-465_tumor_R2.fastq
MM-265_normal_R1.fastq MM-265_normal_R2.fastq
MM-265_tumor_R1.fastq MM-265_tumor_R2.fastq
I've code below broken in three parts:
- regular expression
- process that iterates over files
- workflow that calls the above two code blocks
regex:
def get_sample_id( file ) {
def matcher = (file =~ /(MM-\d+)-DNA-N-.+/)
if (matcher) {
return matcher[0][1]
} else {
return ''
}
}
process:
process file_print {
debug true
input:
tuple val(sample_id), path(datasetFile)
val(sample_status)
val(read_value)
output:
publishDir '/arion/learn_new_concepts/', mode:'copy'
tuple val (sample_id), path("${output_file_name}")
script:
output_file_name = "${sample_id}_${sample_status}_${read_value}.fastq"
for (g in datasetFile){
println(g)
"zcat ${g} >> ${output_file_name} "
}
}
Workflow:
workflow {
normal_reads=Channel.fromFilePairs("/sc/arion/MM-*-N-*_L00*_R{1,2}_*.fastq.gz")
//MM-2658-DNA-N-01-01_L004_R2_001.fastq.gz //
normal_forward_reads=normal_reads
.map{ file -> return tuple( get_sample_id(file), file[1][0] )}.groupTuple(sort:true )
file_print(normal_forward_reads,"normal","R1").view() /// similar for reverse [1][1], R2 .. for tumor pass reads, "tumor", "R1"/R2"
}
I have not put code for reverse, but I get error as:
Caused by: Process `file_print (1)` terminated with an error exit status (127) Command executed: null
Command exit status: 127
I tried many things such as ${ output_file_name }
, { output_file_name }
, $output_file_name
but in vain.
I'd like to improve few things in code:
a) The iteration/loop over file in datasetFile
I think something like each
could help, but I need order to be maintained
b) Order in which loop of datasetFile
is created. For instance, I'd like to keep lanes L003, L004, L005 in this order. Or, L001, L002, L003 order, I hope this is clear.
I cannot move ahead or able to sort this by myself.
I do not quite understand how and when to use .map{}
Edited: after output added tuple for val and path
. I still get same error.