forked from nf-core/sarek
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalignment_to_fastq.nf
More file actions
83 lines (66 loc) · 3.37 KB
/
alignment_to_fastq.nf
File metadata and controls
83 lines (66 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//
// BAM/CRAM to FASTQ conversion, paired end only
//
include { SAMTOOLS_VIEW as SAMTOOLS_VIEW_MAP_MAP } from '../../modules/nf-core/modules/samtools/view/main'
include { SAMTOOLS_VIEW as SAMTOOLS_VIEW_UNMAP_UNMAP } from '../../modules/nf-core/modules/samtools/view/main'
include { SAMTOOLS_VIEW as SAMTOOLS_VIEW_UNMAP_MAP } from '../../modules/nf-core/modules/samtools/view/main'
include { SAMTOOLS_VIEW as SAMTOOLS_VIEW_MAP_UNMAP } from '../../modules/nf-core/modules/samtools/view/main'
include { SAMTOOLS_MERGE as SAMTOOLS_MERGE_UNMAP } from '../../modules/nf-core/modules/samtools/merge/main'
include { SAMTOOLS_COLLATEFASTQ as COLLATE_FASTQ_UNMAP } from '../../modules/nf-core/modules/samtools/collatefastq/main'
include { SAMTOOLS_COLLATEFASTQ as COLLATE_FASTQ_MAP } from '../../modules/nf-core/modules/samtools/collatefastq/main'
include { CAT_FASTQ } from '../../modules/nf-core/modules/cat/fastq/main'
workflow ALIGNMENT_TO_FASTQ {
take:
input // channel: [meta, alignment (BAM or CRAM), index (optional)]
fasta // optional: reference file if CRAM format and reference not in header
main:
ch_versions = Channel.empty()
// Index File if not PROVIDED -> this also requires updates to samtools view possibly URGH
// MAP - MAP
SAMTOOLS_VIEW_MAP_MAP(input, fasta)
// UNMAP - UNMAP
SAMTOOLS_VIEW_UNMAP_UNMAP(input, fasta)
// UNMAP - MAP
SAMTOOLS_VIEW_UNMAP_MAP(input, fasta)
// MAP - UNMAP
SAMTOOLS_VIEW_MAP_UNMAP(input, fasta)
// Merge UNMAP
all_unmapped_bam = SAMTOOLS_VIEW_UNMAP_UNMAP.out.bam
.join(SAMTOOLS_VIEW_UNMAP_MAP.out.bam, remainder: true)
.join(SAMTOOLS_VIEW_MAP_UNMAP.out.bam, remainder: true)
.map{ meta, unmap_unmap, unmap_map, map_unmap ->
[meta, [unmap_unmap, unmap_map, map_unmap]]
}
SAMTOOLS_MERGE_UNMAP(all_unmapped_bam, fasta)
// Collate & convert unmapped
COLLATE_FASTQ_UNMAP(SAMTOOLS_MERGE_UNMAP.out.bam)
// Collate & convert mapped
COLLATE_FASTQ_MAP(SAMTOOLS_VIEW_MAP_MAP.out.bam)
// join Mapped & unmapped fastq
unmapped_reads = COLLATE_FASTQ_UNMAP.out.reads
.map{ meta, reads_R1_R2, reads_other, reads_singleton ->
[meta, reads_R1_R2]
}
mapped_reads = COLLATE_FASTQ_MAP.out.reads
.map{ meta, reads_R1_R2, reads_other, reads_singleton ->
[meta, reads_R1_R2]
}
reads_to_concat = mapped_reads.join(unmapped_reads)
.map{ meta, mapped_reads, unmapped_reads ->
[meta, [mapped_reads[0], mapped_reads[1], unmapped_reads[0], unmapped_reads[1]]]
}
// Concatenate Mapped_R1 with Unmapped_R1 and Mapped_R2 with Unmapped_R2
CAT_FASTQ(reads_to_concat)
// Gather versions of all tools used
ch_versions = ch_versions.mix(CAT_FASTQ.out.versions)
ch_versions = ch_versions.mix(COLLATE_FASTQ_MAP.out.versions)
ch_versions = ch_versions.mix(COLLATE_FASTQ_UNMAP.out.versions)
ch_versions = ch_versions.mix(SAMTOOLS_MERGE_UNMAP.out.versions)
ch_versions = ch_versions.mix(SAMTOOLS_VIEW_MAP_MAP.out.versions)
ch_versions = ch_versions.mix(SAMTOOLS_VIEW_MAP_UNMAP.out.versions)
ch_versions = ch_versions.mix(SAMTOOLS_VIEW_UNMAP_MAP.out.versions)
ch_versions = ch_versions.mix(SAMTOOLS_VIEW_UNMAP_UNMAP.out.versions)
emit:
reads = CAT_FASTQ.out.reads
versions = ch_versions
}