Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow storeDir for RunBQSR #1001

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 19 additions & 20 deletions pipeline.nf
Original file line number Diff line number Diff line change
Expand Up @@ -489,27 +489,25 @@ if (params.mapping) {

// Check for FASTQ files which might have different path but contains the same reads, based only on the name of the first read.
def allReadIds = [:]
sortedBam.map { idSample, target, bam, fileID, lane, readIdFile -> def readId = "@" + readIdFile.getSimpleName().replaceAll("@", ":")

// Use the first line of the fastq file (the name of the first read) as unique identifier to check across all the samples if there is any two fastq files contains the same read name, if so, we consider there are some human error of mixing up the same reads into different fastq files
sortedBam
.groupTuple(by:[3])
.map { idSample, target, bam, fileID, lane, readIdFile ->
def idSample_first = idSample instanceof Collection ? idSample.first() : idSample
def target_first = target instanceof Collection ? target.first() : target
// Use the first line of the fastq file (the name of the first read) as unique identifier to check across all the samples if there is any two fastq files contains the same read name, if so, we consider there are some human error of mixing up the same reads into different fastq files
if ( !params.watch ){
if(!TempoUtils.checkDuplicates(allReadIds, readId, idSample + "\t" + bam, "the follwoing samples, since they contain the same read: \n${readId}")){exit 1}
for (i in readIdFile.flatten().unique()){
def readId = "@" + i.getSimpleName().replaceAll("@", ":")
if(!TempoUtils.checkDuplicates(allReadIds, readId, idSample_first + "\t" + fileID, "the following samples, since they contain the same read: \n${readId}")){exit 1}
}
}

[idSample, target, bam, fileID, lane]
}
.groupTuple(by: [3])
.map{ item ->
def idSample = item[0] instanceof Collection ? item[0].first() : item[0]
def target = item[1] instanceof Collection ? item[1].first() : item[1]
def bams = item[2]
[idSample, target, bams]
[idSample_first, target_first, bam.flatten().unique()]
}
.groupTuple(by: [0])
.map{ item ->
def idSample = item[0]
def target = item[1] instanceof Collection ? item[1].first() : item[1]
def bams = item[2].flatten()
def bams = item[2].flatten().unique()
[idSample, bams, target]
}
.set{ groupedBam }
Expand Down Expand Up @@ -581,8 +579,7 @@ if (params.mapping) {
referenceMap.knownIndelsIndex
])
output:
set idSample, target, file("${idSample}.bam"), file("${idSample}.bam.bai") into bamsBQSR4Alfred, bamsBQSR4CollectHsMetrics, bamsBQSR4Tumor, bamsBQSR4Normal, bamsBQSR4QcPileup, bamsBQSR4Qualimap
set idSample, target, val("${file(outDir).toString()}/bams/${idSample}/${idSample}.bam"), val("${file(outDir).toString()}/bams/${idSample}/${idSample}.bam.bai") into bamResults
set idSample, target, file("${idSample}.bam"), file("${idSample}.bam.bai") into bamsBQSR4Alfred, bamsBQSR4CollectHsMetrics, bamsBQSR4Tumor, bamsBQSR4Normal, bamsBQSR4QcPileup, bamsBQSR4Qualimap, bamResults
file("file-size.txt") into bamSize
script:
if (workflow.profile == "juno") {
Expand Down Expand Up @@ -661,13 +658,15 @@ if (params.mapping) {
"""
}

File file = new File(outname)
file.newWriter().withWriter { w ->
File file_bammapping = new File(outname)
file_bammapping.newWriter().withWriter { w ->
w << "SAMPLE\tTARGET\tBAM\tBAI\n"
}

bamResults.subscribe { Object obj ->
file.withWriterAppend { out ->
bamResults.map{ idSample, target, bam, bai ->
[ idSample, target, "${file(outDir).toString()}/bams/${idSample}/${idSample}.bam", "${file(outDir).toString()}/bams/${idSample}/${idSample}.bam.bai" ]
}.subscribe { Object obj ->
file_bammapping.withWriterAppend { out ->
out.println "${obj[0]}\t${obj[1]}\t${obj[2]}\t${obj[3]}"
}
}
Expand Down