-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #156 from CKComputomics/contaminationFiltering
Contamination filtering
- Loading branch information
Showing
12 changed files
with
416 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
process BLAT_MIRNA { | ||
tag "$fasta" | ||
label 'process_medium' | ||
|
||
conda (params.enable_conda ? 'bioconda::blat=36' : null) | ||
container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ? | ||
'https://depot.galaxyproject.org/singularity/blat:36--0' : | ||
'quay.io/biocontainers/blat:36--0' }" | ||
|
||
input: | ||
val db_type | ||
path mirna | ||
path contaminants | ||
|
||
|
||
output: | ||
path 'filtered.fa' , emit: filtered_set | ||
path "versions.yml" , emit: versions | ||
|
||
script: | ||
|
||
if ( db_type == "cdna" ) | ||
""" | ||
echo $db_type | ||
awk '/^>/ { x=index(\$6, "transcript_biotype:miRNA") } { if(!x) print }' $contaminants > subset.fa | ||
blat -out=blast8 $mirna subset.fa /dev/stdout | awk 'BEGIN{FS="\t"}{if(\$11 < 1e-5)print \$1;}' | uniq > mirnahit.txt | ||
awk 'BEGIN { while((getline<"mirnahit.txt")>0) l[">"\$1]=1 } /^>/ {x = l[\$1]} {if(!x) print }' subset.fa > filtered.fa | ||
cat <<-END_VERSIONS > versions.yml | ||
"${task.process}": | ||
blat: \$(echo \$(blat) | grep Standalone | awk '{ if (match(\$0,/[0-9]*[0-9]/,m)) print m[0] }') | ||
END_VERSIONS | ||
""" | ||
|
||
else if ( db_type == "ncrna" ) | ||
""" | ||
echo $db_type | ||
awk '/^>/ { x=(index(\$6, "transcript_biotype:rRNA") || index(\$6, "transcript_biotype:miRNA")) } { if(!x) print }' $contaminants > subset.fa | ||
blat -out=blast8 $mirna subset.fa /dev/stdout | awk 'BEGIN{FS="\t"}{if(\$11 < 1e-5)print \$1;}' | uniq > mirnahit.txt | ||
awk 'BEGIN { while((getline<"mirnahit.txt")>0) l[">"\$1]=1 } /^>/ {x = l[\$1]} {if(!x) print }' subset.fa > filtered.fa | ||
cat <<-END_VERSIONS > versions.yml | ||
"${task.process}": | ||
blat: \$(echo \$(blat) | grep Standalone | awk '{ if (match(\$0,/[0-9]*[0-9]/,m)) print m[0] }') | ||
END_VERSIONS | ||
""" | ||
|
||
else | ||
""" | ||
echo $db_type | ||
blat -out=blast8 $mirna $contaminants /dev/stdout | awk 'BEGIN{FS="\t"}{if(\$11 < 1e-5)print \$1;}' | uniq > mirnahit.txt | ||
awk 'BEGIN { while((getline<"mirnahit.txt")>0) l[">"\$1]=1 } /^>/ {x = l[\$1]} {if(!x) print }' $contaminants > filtered.fa | ||
cat <<-END_VERSIONS > versions.yml | ||
"${task.process}": | ||
blat: \$(echo \$(blat) | grep Standalone | awk '{ if (match(\$0,/[0-9]*[0-9]/,m)) print m[0] }') | ||
END_VERSIONS | ||
""" | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
process INDEX_CONTAMINANTS { | ||
label 'process_medium' | ||
|
||
conda (params.enable_conda ? 'bowtie2=2.4.5' : null) | ||
container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ? | ||
'https://depot.galaxyproject.org/singularity/bowtie2:2.4.5--py39hd2f7db1_2' : | ||
'quay.io/biocontainers/bowtie2:2.4.5--py36hfca12d5_2' }" | ||
|
||
input: | ||
path fasta | ||
|
||
output: | ||
path 'fasta_bidx*' , emit: bt_indices | ||
path "versions.yml" , emit: versions | ||
|
||
script: | ||
""" | ||
bowtie2-build ${fasta} fasta_bidx --threads ${task.cpus} | ||
cat <<-END_VERSIONS > versions.yml | ||
"${task.process}": | ||
bowtie2: \$(echo \$(bowtie2 --version 2>&1) | sed 's/^.*bowtie2-align-s version //; s/ .*\$//') | ||
END_VERSIONS | ||
""" | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
process BOWTIE_MAP_CONTAMINANTS { | ||
label 'process_medium' | ||
|
||
conda (params.enable_conda ? 'bowtie2=2.4.5' : null) | ||
container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ? | ||
'https://depot.galaxyproject.org/singularity/bowtie2:2.4.5--py39hd2f7db1_2' : | ||
'quay.io/biocontainers/bowtie2:2.4.5--py36hfca12d5_2' }" | ||
|
||
input: | ||
tuple val(meta), path(reads) | ||
path index | ||
val contaminant_type | ||
|
||
output: | ||
tuple val(meta), path("*sam") , emit: bam | ||
tuple val(meta), path('*.filter.unmapped.contaminant.fastq'), emit: unmapped | ||
path "versions.yml" , emit: versions | ||
path "filtered.*.stats" , emit: stats | ||
|
||
script: | ||
def index_base = index.toString().tokenize(' ')[0].tokenize('.')[0] | ||
""" | ||
bowtie2 \\ | ||
--threads ${task.cpus} \\ | ||
--very-sensitive-local \\ | ||
-k 1 \\ | ||
-x $index_base \\ | ||
--un ${meta.id}.${contaminant_type}.filter.unmapped.contaminant.fastq \\ | ||
${reads} \\ | ||
-S ${meta.id}.filter.contaminant.sam > ${meta.id}.contaminant_bowtie.log 2>&1 | ||
# extracting number of reads from bowtie logs | ||
awk -v type=${contaminant_type} 'BEGIN{tot=0} {if(NR==4 || NR == 5){tot += \$1}} END {print "\\""type"\\": "tot }' ${meta.id}.contaminant_bowtie.log | tr -d , > filtered.${meta.id}_${contaminant_type}.stats | ||
cat <<-END_VERSIONS > versions.yml | ||
"${task.process}": | ||
bowtie2: \$(echo \$(bowtie2 --version 2>&1) | sed 's/^.*bowtie2-align-s version //; s/ .*\$//' | tr -d '\0') | ||
END_VERSIONS | ||
""" | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
process FILTER_STATS { | ||
label 'process_medium' | ||
|
||
conda (params.enable_conda ? 'bowtie2=2.4.5' : null) | ||
container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ? | ||
'https://depot.galaxyproject.org/singularity/bowtie2:2.4.5--py39hd2f7db1_2' : | ||
'quay.io/biocontainers/bowtie2:2.4.5--py36hfca12d5_2' }" | ||
|
||
input: | ||
tuple val(meta), path(reads) | ||
path stats_files | ||
|
||
output: | ||
path "*_mqc.yaml" , emit: stats | ||
tuple val(meta), path('*.filtered.fastq.gz') , emit: reads | ||
|
||
script: | ||
""" | ||
readnumber=\$(wc -l ${reads} | awk '{ print \$1/4 }') | ||
cat ./filtered.${meta.id}_*.stats | \\ | ||
tr '\n' ', ' | \\ | ||
awk -v sample=${meta.id} -v readnumber=\$readnumber '{ print "id: \\"my_pca_section\\"\\nsection_name: \\"Contamination Filtering\\"\\ndescription: \\"This plot shows the amount of reads filtered by contaminant type.\\"\\nplot_type: \\"bargraph\\"\\npconfig:\\n id: \\"contamination_filter_plot\\"\\n title: \\"Contamination Plot\\"\\n ylab: \\"Number of reads\\"\\ndata:\\n "sample": {"\$0"\\"remaining reads\\": "readnumber"}" }' > ${meta.id}.contamination_mqc.yaml | ||
gzip -c ${reads} > ${meta.id}.filtered.fastq.gz | ||
""" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.