-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prepare bam file to each individual taxid
- Loading branch information
1 parent
37ddce2
commit 3ae2e29
Showing
4 changed files
with
172 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
process SUBSET_BAM { | ||
|
||
tag "$meta.id" | ||
label 'process_low' | ||
|
||
conda "bioconda::samtools:1.21" | ||
container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ? | ||
'https://depot.galaxyproject.org/singularity/samtools:1.21--h50ea8bc_0': | ||
'biocontainers/samtools:1.21--h50ea8bc_0' }" | ||
|
||
input: | ||
tuple val(meta), path(bam), path(bai) | ||
val taxid_accession | ||
|
||
output: | ||
tuple val(meta), path("*.bam"), emit: bam | ||
path "versions.yml" , emit: versions | ||
|
||
when: | ||
task.ext.when == null || task.ext.when | ||
|
||
script: | ||
def prefix = task.ext.prefix ?: "${meta.id}" | ||
def accessions = taxid_accession.join(" ") | ||
|
||
""" | ||
samtools view $bam $accessions -o ${prefix}.bam | ||
cat <<-END_VERSIONS > versions.yml | ||
"${task.process}": | ||
samtools: \$(samtools --version |& sed '1!d ; s/samtools //') | ||
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,64 @@ | ||
include { SUBSET_BAM } from '../../modules/local/subset_bam' | ||
include { SAMTOOLS_SORT } from '../../modules/nf-core/samtools/sort/main' | ||
include { SAMTOOLS_INDEX } from '../../modules/nf-core/samtools/index/main' | ||
include { SAMTOOLS_IDXSTATS } from '../../modules/nf-core/samtools/idxstats/main' | ||
|
||
|
||
workflow TAXID_BAM { | ||
take: | ||
bam | ||
bai | ||
accession2taxid | ||
|
||
main: | ||
ch_versions = Channel.empty() | ||
ch_multiqc_files = Channel.empty() | ||
|
||
input_bam = bam.combine( bai,by: 0 ) | ||
SAMTOOLS_IDXSTATS( input_bam ) | ||
ch_accession = SAMTOOLS_IDXSTATS.out.idxstats | ||
.map { it[1] } | ||
.splitCsv( header: false,sep:"\t" ) | ||
.filter { it -> it[0]!= "*" } | ||
|
||
ch_versions.mix( SAMTOOLS_IDXSTATS.out.versions.first() ) | ||
|
||
// Load accession2taxid.map | ||
ch_accession2taxidmap = accession2taxid.splitCsv( header: false,sep:"\t" ) | ||
|
||
ch_accession_taxid = ch_accession2taxidmap | ||
.join( ch_accession ) | ||
.filter { it -> it[3] != "0" } | ||
.map { [ it[0], it[1] ] } | ||
.groupTuple( by: 1 ) | ||
|
||
ch_samtools_view = ch_accession_taxid | ||
.combine(input_bam) | ||
//.view() | ||
.map {accession_list, taxid, meta, bam, bam_index -> | ||
def new_meta = meta.clone() | ||
new_meta.taxid = taxid | ||
return [ new_meta, bam, bam_index, accession_list ] | ||
} | ||
.multiMap { | ||
meta, bam, bam_index, accession_list -> | ||
bam: [meta, bam, bam_index] | ||
accession: accession_list.flatten() | ||
} | ||
|
||
SUBSET_BAM ( ch_samtools_view.bam, ch_samtools_view.accession ) | ||
ch_versions = ch_versions.mix( SUBSET_BAM.out.versions.first() ) | ||
|
||
SAMTOOLS_SORT ( SUBSET_BAM.out.bam, [[],[]] ) | ||
ch_versions = ch_versions.mix(SAMTOOLS_SORT.out.versions.first()) | ||
|
||
SAMTOOLS_INDEX ( SAMTOOLS_SORT.out.bam ) | ||
ch_versions = ch_versions.mix( SAMTOOLS_INDEX.out.versions.first() ) | ||
|
||
emit: | ||
accession = ch_accession | ||
versions = ch_versions | ||
taxid_bam = SAMTOOLS_SORT.out.bam | ||
taxid_bam_bai = SAMTOOLS_INDEX.out.bai | ||
|
||
} |
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