Skip to content

Commit d536048

Browse files
authored
Merge pull request #20 from ikmb/devel
Updating pdf report layout and fixing resource issues with xHLA
2 parents 32a9215 + 6770807 commit d536048

File tree

9 files changed

+240
-67
lines changed

9 files changed

+240
-67
lines changed

assets/targets/genes.bed

+47-47
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
1-
chr6 29942554 29942626 HLA-A.ENST00000376809.1 100 +
2-
chr6 29942757 29943026 HLA-A.ENST00000376809.2 100 +
3-
chr6 29943268 29943543 HLA-A.ENST00000376809.3 100 +
4-
chr6 29944122 29944397 HLA-A.ENST00000376809.4 100 +
5-
chr6 29944500 29944616 HLA-A.ENST00000376809.5 100 +
6-
chr6 29945059 29945091 HLA-A.ENST00000376809.6 100 +
7-
chr6 29945234 29945281 HLA-A.ENST00000376809.7 100 +
8-
chr6 29945451 29945455 HLA-A.ENST00000376809.8 100 +
9-
chr6 31357086 31357158 HLA-B.ENST00000412585.1 100 -
10-
chr6 31356688 31356957 HLA-B.ENST00000412585.2 100 -
11-
chr6 31356167 31356442 HLA-B.ENST00000412585.3 100 -
12-
chr6 31355317 31355592 HLA-B.ENST00000412585.4 100 -
13-
chr6 31355107 31355223 HLA-B.ENST00000412585.5 100 -
14-
chr6 31354633 31354665 HLA-B.ENST00000412585.6 100 -
15-
chr6 31354483 31354526 HLA-B.ENST00000412585.7 100 -
16-
chr6 31271999 31272071 HLA-C.ENST00000376228.1 100 -
17-
chr6 31271599 31271868 HLA-C.ENST00000376228.2 100 -
18-
chr6 31271073 31271348 HLA-C.ENST00000376228.3 100 -
19-
chr6 31270210 31270485 HLA-C.ENST00000376228.4 100 -
20-
chr6 31269966 31270085 HLA-C.ENST00000376228.5 100 -
21-
chr6 31269493 31269525 HLA-C.ENST00000376228.6 100 -
22-
chr6 31269338 31269385 HLA-C.ENST00000376228.7 100 -
23-
chr6 31269169 31269173 HLA-C.ENST00000376228.8 100 -
24-
chr6 32589643 32589742 HLA-DRB1.ENST00000360004.1 100 -
25-
chr6 32584109 32584378 HLA-DRB1.ENST00000360004.2 100 -
26-
chr6 32581557 32581838 HLA-DRB1.ENST00000360004.3 100 -
27-
chr6 32580746 32580856 HLA-DRB1.ENST00000360004.4 100 -
28-
chr6 32580247 32580270 HLA-DRB1.ENST00000360004.5 100 -
29-
chr6 32579091 32579104 HLA-DRB1.ENST00000360004.6 100 -
30-
chr6 32637459 32637540 HLA-DQA1.ENST00000343139.1 100 +
31-
chr6 32641310 32641558 HLA-DQA1.ENST00000343139.2 100 +
32-
chr6 32641972 32642253 HLA-DQA1.ENST00000343139.3 100 +
33-
chr6 32642610 32642764 HLA-DQA1.ENST00000343139.4 100 +
34-
chr6 32666499 32666607 HLA-DQB1.ENST00000434651.1 100 -
35-
chr6 32664798 32665067 HLA-DQB1.ENST00000434651.2 100 -
36-
chr6 32661967 32662248 HLA-DQB1.ENST00000434651.3 100 -
37-
chr6 32661347 32661457 HLA-DQB1.ENST00000434651.4 100 -
38-
chr6 32660236 32660249 HLA-DQB1.ENST00000434651.5 100 -
39-
chr6 33073471 33073570 HLA-DPA1.ENST00000419277.2 100 -
40-
chr6 33069641 33069886 HLA-DPA1.ENST00000419277.3 100 -
41-
chr6 33069019 33069300 HLA-DPA1.ENST00000419277.4 100 -
42-
chr6 33068650 33068804 HLA-DPA1.ENST00000419277.5 100 -
43-
chr6 33076042 33076141 HLA-DPB1.ENST00000418931.1 100 +
44-
chr6 33080672 33080935 HLA-DPB1.ENST00000418931.2 100 +
45-
chr6 33084950 33085231 HLA-DPB1.ENST00000418931.3 100 +
46-
chr6 33085779 33085889 HLA-DPB1.ENST00000418931.4 100 +
47-
chr6 33086219 33086238 HLA-DPB1.ENST00000418931.5 100 +
1+
chr6 29942554 29942626 HLA-A.ENST00000376809.1 100 +
2+
chr6 29942757 29943026 HLA-A.ENST00000376809.2 100 +
3+
chr6 29943268 29943543 HLA-A.ENST00000376809.3 100 +
4+
chr6 29944122 29944397 HLA-A.ENST00000376809.4 100 +
5+
chr6 29944500 29944616 HLA-A.ENST00000376809.5 100 +
6+
chr6 29945059 29945091 HLA-A.ENST00000376809.6 100 +
7+
chr6 29945234 29945281 HLA-A.ENST00000376809.7 100 +
8+
chr6 29945451 29945455 HLA-A.ENST00000376809.8 100 +
9+
chr6 31357086 31357158 HLA-B.ENST00000412585.1 100 -
10+
chr6 31356688 31356957 HLA-B.ENST00000412585.2 100 -
11+
chr6 31356167 31356442 HLA-B.ENST00000412585.3 100 -
12+
chr6 31355317 31355592 HLA-B.ENST00000412585.4 100 -
13+
chr6 31355107 31355223 HLA-B.ENST00000412585.5 100 -
14+
chr6 31354633 31354665 HLA-B.ENST00000412585.6 100 -
15+
chr6 31354483 31354526 HLA-B.ENST00000412585.7 100 -
16+
chr6 31271999 31272071 HLA-C.ENST00000376228.1 100 -
17+
chr6 31271599 31271868 HLA-C.ENST00000376228.2 100 -
18+
chr6 31271073 31271348 HLA-C.ENST00000376228.3 100 -
19+
chr6 31270210 31270485 HLA-C.ENST00000376228.4 100 -
20+
chr6 31269966 31270085 HLA-C.ENST00000376228.5 100 -
21+
chr6 31269493 31269525 HLA-C.ENST00000376228.6 100 -
22+
chr6 31269338 31269385 HLA-C.ENST00000376228.7 100 -
23+
chr6 31269169 31269173 HLA-C.ENST00000376228.8 100 -
24+
chr6 32589643 32589742 HLA-DRB1.ENST00000360004.1 100 -
25+
chr6 32584109 32584378 HLA-DRB1.ENST00000360004.2 100 -
26+
chr6 32581557 32581838 HLA-DRB1.ENST00000360004.3 100 -
27+
chr6 32580746 32580856 HLA-DRB1.ENST00000360004.4 100 -
28+
chr6 32580247 32580270 HLA-DRB1.ENST00000360004.5 100 -
29+
chr6 32579091 32579104 HLA-DRB1.ENST00000360004.6 100 -
30+
chr6 32637459 32637540 HLA-DQA1.ENST00000343139.1 100 +
31+
chr6 32641310 32641558 HLA-DQA1.ENST00000343139.2 100 +
32+
chr6 32641972 32642253 HLA-DQA1.ENST00000343139.3 100 +
33+
chr6 32642610 32642764 HLA-DQA1.ENST00000343139.4 100 +
34+
chr6 32666499 32666607 HLA-DQB1.ENST00000434651.1 100 -
35+
chr6 32664798 32665067 HLA-DQB1.ENST00000434651.2 100 -
36+
chr6 32661967 32662248 HLA-DQB1.ENST00000434651.3 100 -
37+
chr6 32661347 32661457 HLA-DQB1.ENST00000434651.4 100 -
38+
chr6 32660236 32660249 HLA-DQB1.ENST00000434651.5 100 -
39+
chr6 33073471 33073570 HLA-DPA1.ENST00000419277.2 100 -
40+
chr6 33069641 33069886 HLA-DPA1.ENST00000419277.3 100 -
41+
chr6 33069019 33069300 HLA-DPA1.ENST00000419277.4 100 -
42+
chr6 33068650 33068804 HLA-DPA1.ENST00000419277.5 100 -
43+
chr6 33076042 33076141 HLA-DPB1.ENST00000418931.1 100 +
44+
chr6 33080672 33080935 HLA-DPB1.ENST00000418931.2 100 +
45+
chr6 33084950 33085231 HLA-DPB1.ENST00000418931.3 100 +
46+
chr6 33085779 33085889 HLA-DPB1.ENST00000418931.4 100 +
47+
chr6 33086219 33086238 HLA-DPB1.ENST00000418931.5 100 +

bin/json2pdf.rb

+135-3
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,32 @@
2727

2828
### Define modules and classes here
2929

30+
def build_intervals(regions)
31+
32+
answer = []
33+
34+
regions.each_with_index do |region,i|
35+
36+
exon = { "type" => "exon", "start" => region[0].to_i, "stop" => region[1].to_i , "coverage" => region[-1]}
37+
38+
unless region == regions.first
39+
prev_exon = answer[-1]
40+
intron = {"type" => "intron", "start" => prev_exon["stop"]+1, "stop" => exon["start"]-1 }
41+
answer << intron
42+
end
43+
44+
answer << exon
45+
46+
end
47+
return answer
48+
end
3049
### Get the script arguments and open relevant files
3150
options = OpenStruct.new()
3251
opts = OptionParser.new()
3352
opts.banner = "A script description here"
3453
opts.separator ""
3554
opts.on("-j","--json", "=JSON","JSON input") {|argument| options.json = argument }
55+
opts.on("-c","--coverage", "=COVERAGE","Coverage input") {|argument| options.cov = argument }
3656
opts.on("-l","--logo", "=LOGO","Logo to include") {|argument| options.logo = argument }
3757
opts.on("-o","--outfile", "=OUTFILE","Output file") {|argument| options.outfile = argument }
3858
opts.on("-h","--help","Display the usage information") {
@@ -42,6 +62,29 @@
4262

4363
opts.parse!
4464

65+
coverage = {}
66+
genes = {}
67+
68+
if options.cov
69+
IO.readlines(options.cov).each do |line|
70+
chr,from,to,exon,score,strand,cov = line.strip.split("\t")
71+
from = from.to_i
72+
to = to.to_i
73+
len = to-from
74+
mean = (cov.to_f/len.to_f).round()
75+
76+
gene = exon.split(".")[0]
77+
78+
if genes.has_key?(gene)
79+
genes[gene]["exons"] << [ from, to, mean ]
80+
else
81+
genes[gene] = { "strand" => strand, "exons" => [ [from, to, mean ]] }
82+
end
83+
84+
coverage[exon] = mean
85+
end
86+
end
87+
4588
json = JSON.parse(IO.readlines(options.json).join("\n"))
4689

4790
calls = json["calls"]
@@ -75,7 +118,7 @@
75118

76119
date = Date.today.strftime("%d.%m.%Y")
77120

78-
footer = "Bericht erstellt am: #{date} | Pipeline version: github.com/ikmb/hla:#{version}"
121+
footer = "Report created: #{date} | Pipeline version: github.com/ikmb/hla:#{version}"
79122

80123
pdf = Prawn::Document.new
81124

@@ -86,14 +129,14 @@
86129

87130
pdf.move_down 5
88131

89-
pdf.text "IKMB - HLA Typisierung mittels Sequenzierung (NGS)"
132+
pdf.text "IKMB - HLA Typing from short read sequencing data"
90133

91134
pdf.move_down 5
92135
pdf.stroke_horizontal_rule
93136

94137
pdf.font_size 10
95138
pdf.move_down 5
96-
pdf.text "Probe: #{sample}"
139+
pdf.text "Sample: #{sample}"
97140
pdf.move_down 20
98141

99142
t = pdf.make_table(
@@ -110,4 +153,93 @@
110153
pdf.move_down 5
111154
pdf.text footer
112155

156+
157+
if coverage.keys.length > 0
158+
159+
max_width = 300
160+
161+
pdf.start_new_page
162+
163+
h = 200
164+
165+
pdf.font_size 12
166+
pdf.text "Mean sequencing depth of relevant exons"
167+
pdf.move_down 5
168+
pdf.stroke_horizontal_rule
169+
170+
pdf.font_size 10
171+
pdf.move_down 5
172+
pdf.text "Green: >= 30X, Orange: >= 10X, Red: < 10X"
173+
174+
genes.each do |gene,data|
175+
176+
exons = data["exons"]
177+
strand = data["strand"]
178+
179+
exons.reverse! if strand == "-"
180+
181+
h += 5
182+
183+
pos = 10
184+
185+
start = exons[0][0]
186+
stop = exons[-1][1]
187+
188+
len = stop.to_i-start.to_i
189+
190+
intervals = build_intervals(exons)
191+
192+
pdf.bounding_box([pos,h], width: 500, height: 30) do
193+
194+
pdf.fill_color "000000"
195+
196+
pdf.text gene
197+
198+
intervals.each do |interval|
199+
istart = interval["start"]
200+
istop = interval["stop"]
201+
ilen = istop-istart
202+
typ = interval["type"]
203+
204+
if typ == "exon"
205+
height = 10
206+
mod = 0
207+
coverage = interval["coverage"]
208+
if coverage >= 30
209+
pdf.fill_color = "0EBB09"
210+
elsif coverage >= 10
211+
pdf.fill_color = "E48607"
212+
else
213+
pdf.fill_color = "E40707"
214+
end
215+
else
216+
height = 6
217+
mod = 2
218+
pdf.fill_color = "CDCDCD"
219+
end
220+
221+
i_norm_len = ((ilen.to_f/len.to_f)*max_width).round()
222+
i_norm_len = 1 if i_norm_len < 1
223+
224+
pdf.fill { pdf.rectangle [pos,20-mod], i_norm_len, height }
225+
pos += i_norm_len
226+
end
227+
end
228+
229+
h += 50
230+
231+
end
232+
233+
pdf.fill_color "000000"
234+
235+
pdf.move_cursor_to 30
236+
pdf.stroke_horizontal_rule
237+
pdf.move_down 10
238+
pdf.font_size 8
239+
pdf.move_down 5
240+
pdf.text footer
241+
242+
end
243+
244+
113245
pdf.render_file(options.outfile)

bin/report.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ def trim_allele(call,precision)
109109
gene,a,b = line.split("\t")
110110
if alleles.has_key?(gene)
111111
these_alleles = []
112-
these_alleles << trim_allele(a,precision) unless a.include?("Not typed") or a.include?("-")
113-
these_alleles << trim_allele(b,precision) unless b.include?("Not typed") or b.include?("-")
112+
these_alleles << trim_allele(a,precision) unless a.include?("Not typed") or a == "-"
113+
these_alleles << trim_allele(b,precision) unless b.include?("Not typed") or b == "-"
114114

115115
alleles[gene]["HLA-HD"] = these_alleles
116116
end

conf/base.config

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ process {
2424
}
2525
withLabel: medium_serial {
2626
time = { check_max( 8.h * task.attempt, 'time' ) }
27-
memory = { check_max( 8.GB * task.attempt, 'memory' ) }
27+
memory = { check_max( 32.GB * task.attempt, 'memory' ) }
2828
}
2929
withLabel: long_serial {
3030
time = { check_max( 12.h * task.attempt, 'time' ) }
31-
memory = { check_max( 16.GB * task.attempt, 'memory' ) }
31+
memory = { check_max( 64.GB * task.attempt, 'memory' ) }
3232
}
3333
withLabel: short_parallel {
3434
time = { check_max( 4.h * task.attempt, 'time' ) }

modules/mosdepth/main.nf

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
process MOSDEPTH {
2+
3+
container 'quay.io/biocontainers/mosdepth:0.3.3--hd299d5a_3'
4+
5+
publishDir "${params.outdir}/${meta.patient_id}/${meta.sample_id}/Coverage", mode: 'copy'
6+
7+
label 'medium_parallel'
8+
9+
tag "${meta.patient_id}|${meta.sample_id}"
10+
11+
input:
12+
tuple val(meta), path(bam), path(bai)
13+
path(bed)
14+
15+
output:
16+
tuple val(meta), path(genome_bed_coverage),path(genome_global_coverage), emit: coverage
17+
18+
script:
19+
base_name = bam.getBaseName()
20+
genome_bed_coverage = base_name + ".mosdepth.region.dist.txt"
21+
genome_global_coverage = base_name + ".mosdepth.global.dist.txt"
22+
23+
"""
24+
mosdepth -t ${task.cpus} -n -x -Q 10 -b $bed $base_name $bam
25+
26+
cat <<-END_VERSIONS > versions.yml
27+
"${task.process}":
28+
mosdepth: \$(mosdepth -h 2>1 | head -n1 | sed -e "s/mosdepth //g")
29+
END_VERSIONS
30+
"""
31+
}
32+

modules/reporting.nf

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ process JSON2PDF {
2828
publishDir "${params.outdir}/Reports", mode: 'copy'
2929

3030
input:
31-
tuple val(meta),path(json)
31+
tuple val(meta),path(json),path(bed)
3232

3333
output:
3434
tuple val(meta),path(pdf), emit: pdf
@@ -38,7 +38,7 @@ process JSON2PDF {
3838
pdf = "${sample}.pdf"
3939

4040
"""
41-
json2pdf.rb -j ${json} -o $pdf -l ${baseDir}/images/ikmb_bfx_logo.png
41+
json2pdf.rb -j ${json} -o $pdf -l ${baseDir}/images/ikmb_bfx_logo.png -c $bed
4242
"""
4343
}
4444

modules/samtools/bedcov.nf

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ process SAMTOOLS_BEDCOV {
44

55
tag "${meta.patient_id}|${meta.sample_id}"
66

7-
publishDir "${params.outdir}/${meta.patient_id}/${meta.sample_id}/", mode: 'copy'
7+
publishDir "${params.outdir}/${meta.patient_id}/${meta.sample_id}/Coverage", mode: 'copy'
88

99
input:
1010
tuple val(meta),path(bam),path(bai)

0 commit comments

Comments
 (0)