Skip to content

Commit

Permalink
config processing fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
kubranarci committed May 17, 2024
1 parent 2e79eee commit 46fc4d7
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 36 deletions.
71 changes: 43 additions & 28 deletions modules/local/get_contigs.nf
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,64 @@ process GET_CONTIGS {

input:
tuple val(meta), path(tumor), path(tumor_bai), path(control), path(control_bai)
each path(contig_file)

output:
path "contigs.bed" , emit: contigs
path "versions.yml" , emit: versions
tuple val(meta), path("contigs.bed") , emit: contigs
path "versions.yml" , emit: versions

script:
def args = task.ext.args ?: ''
def prefix = task.ext.prefix ?: "${meta.id}"

if (params.runcontigs == 'ALT_HLA')
if (contig_file)
{
"""
if [ -n "\$(samtools view -H $tumor | grep -P "_alt\\tLN")" ]; then
samtools view -H $tumor | grep -P "_alt\\tLN" | sed -e 's/@SQ\\tSN://' -e 's/\\tLN:/\\t0\\t/' -e 's/\\tAH.*//' | sort -V -k1,1 | cut -f 1 > ALT_contigs.bed
else
touch ALT_contigs.bed
fi
if [-n "\$(samtools view -H $tumor | grep -P "SN:HLA")" ]; then
samtools view -H $tumor | grep -P "SN:HLA" | sed -e 's/@SQ\\tSN://' -e 's/\\tLN:/\\t0\\t/' -e 's/\\tAH.*//' | sort -V -k1,1 | cut -f 1 > HLA_contigs.bed
else
touch HLA_contigs.bed
fi
cat ALT_contigs.bed HLA_contigs.bed > contigs.bed
cp $contig_file contigs.bed
cat <<-END_VERSIONS > versions.yml
"${task.process}":
samtools: \$(echo \$(samtools 2>&1) | sed -e 's/.*Version: //; s/ Usage.*//')
END_VERSIONS
"""
}
else {
"""
touch contigs.bed
if [-n "\$(samtools view -H $tumor | grep -P "SN:") "]; then
samtools view -H $tumor | grep -P "SN:" | sed -e 's/@SQ\\tSN://' -e 's/\tLN:/\\t0\\t/' -e 's/\\tAH.*//' | sort -V -k1,1 | cut -f 1 | tail -n +25 > contigs.bed
else
else{
if (params.runcontigs == 'ALT_HLA')
{
"""
if [ -n "\$(samtools view -H $tumor | grep -P "_alt\\tLN")" ]; then
samtools view -H $tumor | grep -P "_alt\\tLN" | sed -e 's/@SQ\\tSN://' -e 's/\\tLN:/\\t0\\t/' -e 's/\\tAH.*//' | sort -V -k1,1 | cut -f 1 > ALT_contigs.bed
else
touch ALT_contigs.bed
fi
if [-n "\$(samtools view -H $tumor | grep -P "SN:HLA")" ]; then
samtools view -H $tumor | grep -P "SN:HLA" | sed -e 's/@SQ\\tSN://' -e 's/\\tLN:/\\t0\\t/' -e 's/\\tAH.*//' | sort -V -k1,1 | cut -f 1 > HLA_contigs.bed
else
touch HLA_contigs.bed
fi
cat ALT_contigs.bed HLA_contigs.bed > contigs.bed
cat <<-END_VERSIONS > versions.yml
"${task.process}":
samtools: \$(echo \$(samtools 2>&1) | sed -e 's/.*Version: //; s/ Usage.*//')
END_VERSIONS
"""
}
else {
"""
touch contigs.bed
fi
cat <<-END_VERSIONS > versions.yml
"${task.process}":
samtools: \$(echo \$(samtools 2>&1) | sed -e 's/.*Version: //; s/ Usage.*//')
END_VERSIONS
"""
if [ -n "\$(samtools view -H $tumor | grep -P "SN:") "]; then
samtools view -H $tumor | grep -P "SN:" | sed -e 's/@SQ\\tSN://' -e 's/\tLN:/\\t0\\t/' -e 's/\\tAH.*//' | sort -V -k1,1 | cut -f 1 | tail -n +25 > contigs.bed
else
touch contigs.bed
fi
cat <<-END_VERSIONS > versions.yml
"${task.process}":
samtools: \$(echo \$(samtools 2>&1) | sed -e 's/.*Version: //; s/ Usage.*//')
END_VERSIONS
"""
}

}
}
}
9 changes: 5 additions & 4 deletions subworkflows/local/mpileup_snv_call.nf
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,29 @@ workflow MPILEUP_SNV_CALL {
sample_ch // channel: [val(meta), tumor,tumor_bai, control, control_bai, tumorname, controlname]
ref // channel: [path(fasta), path(fai)]
intervals // channel: [[chr, region], [chr, region], ...]
contigs // channel: [path(contigs.bed)]
contigs // channel: [val(meta), path(contigs.bed)]

main:
versions = Channel.empty()

// Combine intervals with samples to create 'interval x sample' number of parallel run and with contigs if exist

contigs.map { it -> ["contigs", it] }
contigs.map { it -> [it[0], "contigs", it[1],] }
.set{contig_ch}

intervals.take(24)
.map{it -> [it[0],[]]}
.map{it -> [[],it[0],[]]}
.set{ch_intervals}

ch_intervals.mix(contig_ch)
.set{intervals_ch}

sample_ch
.combine(intervals_ch)
.filter{ it[0] != it[7] }
.map{ it -> [it[0], it[1], it[2], it[3], it[4], it[5], it[6], it[8], it[9] ] }
.set { combined_inputs }

combined_inputs.view()
//
// MODULE:BCFTOOLS_MPILEUP
//
Expand Down
8 changes: 4 additions & 4 deletions workflows/snvcalling.nf
Original file line number Diff line number Diff line change
Expand Up @@ -205,18 +205,18 @@ workflow SNVCALLING {
}
interval_ch = chrlength.splitCsv(sep: '\t', by:1)

if ((params.runcontigs != "NONE") && (!params.contig_file)) {
if (params.runcontigs != "NONE") {
//
// MODULE: Prepare contigs file if not provided
//
GET_CONTIGS(
sample_ch
sample_ch,
contigs
)
ch_versions = ch_versions.mix(GET_CONTIGS.out.versions)
GET_CONTIGS.out.contigs.filter{contig -> WorkflowCommons.getNumLinesInFile(contig) > 0}
GET_CONTIGS.out.contigs.filter{meta, contig -> WorkflowCommons.getNumLinesInFile(contig) > 0}
.set{contigs}
}

//
// MODULE: Extract sample name from BAM
//
Expand Down

0 comments on commit 46fc4d7

Please sign in to comment.