Skip to content

Commit 30c1a99

Browse files
committed
add output tracking how long the alignment step took
1 parent 8dd4d1f commit 30c1a99

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

wdl/pipelines/PacBio/Utility/ProcessOnInstrumentDemuxedChunk.wdl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ workflow ProcessOnInstrumentDemuxedChunk {
8888

8989
output {
9090
String last_processing_date = today.yyyy_mm_dd
91+
String aln_wallclock_time = AlignHiFiUBAM.total_runtime
9192

9293
File aligned_bam = FinalizeAlignedBam.gcs_path
9394
File aligned_bai = FinalizeAlignedBai.gcs_path

wdl/tasks/Alignment/AlignHiFiUBAM.wdl

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ workflow AlignHiFiUBAM {
3636
File aligned_pbi = IndexAlignedReads.pbi
3737

3838
String movie = movie_name
39+
String total_runtime = select_first([sumRuntimes.total_runtime, AlignReadsTogether.wallclocktime])
3940
}
4041

4142
# todo: verify if this is still necessary
@@ -86,6 +87,7 @@ workflow AlignHiFiUBAM {
8687
}
8788
8889
call Utils.MergeBams as MergeAlignedReads { input: bams = AlignReads.aligned_bam, prefix = basename(uBAM, ".bam") }
90+
call sumRuntimes { input: runtimes = AlignReads.wallclocktime }
8991
}
9092
if (! (ceil(size(uBAM, "GiB")) > shard_threshold)) {
9193
call PB.Align as AlignReadsTogether { input:
@@ -102,4 +104,38 @@ workflow AlignHiFiUBAM {
102104
File aBAM = select_first([MergeAlignedReads.merged_bam, AlignReadsTogether.aligned_bam])
103105
File aBAI = select_first([MergeAlignedReads.merged_bai, AlignReadsTogether.aligned_bai])
104106
call PB.PBIndex as IndexAlignedReads { input: bam = aBAM }
105-
}
107+
}
108+
109+
task sumRuntimes {
110+
input {
111+
Array[String] runtimes
112+
}
113+
114+
output {
115+
String total_runtime = read_string("total.txt")
116+
}
117+
command <<<
118+
total_minutes=0
119+
120+
# Read each runtime and sum up
121+
while IFS= read -r line; do
122+
# Extract hours and minutes from format "XX hours, YY minutes"
123+
hours=$(echo "$line" | grep -oP '\d+(?=H)')
124+
minutes=$(echo "$line" | grep -oP '\d+(?=M)')
125+
126+
# Convert to total minutes and add
127+
total_minutes=$((total_minutes + hours * 60 + minutes))
128+
done < ~{write_lines(runtimes)}
129+
130+
# Convert back to hours and minutes
131+
final_hours=$((total_minutes / 60))
132+
final_minutes=$((total_minutes % 60))
133+
134+
# Output in same format with padding
135+
printf "%02dH%02dM\n" $final_hours $final_minutes > total.txt
136+
>>>
137+
runtime {
138+
disks: "local-disk 10 HDD"
139+
docker: "gcr.io/cloud-marketplace/google/ubuntu2004:latest"
140+
}
141+
}

wdl/tasks/Utility/PBUtils.wdl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,7 @@ task Align {
943943

944944
command <<<
945945
set -euxo pipefail
946+
start_time=$(date +%s)
946947
947948
pbmm2 align ~{bam} \
948949
~{ref_fasta} \
@@ -975,11 +976,18 @@ task Align {
975976
976977
samtools calmd -b --no-PG ~{prefix}.pre.bam ~{ref_fasta} > ~{prefix}.bam
977978
samtools index ~{prefix}.bam
979+
980+
end_time=$(date +%s)
981+
total_seconds=$((end_time - start_time))
982+
hours=$((total_seconds / 3600))
983+
minutes=$(((total_seconds % 3600) / 60))
984+
printf "%02dH%02dM\n" $hours $minutes > wallclocktime.txt
978985
>>>
979986

980987
output {
981988
File aligned_bam = "~{prefix}.bam"
982989
File aligned_bai = "~{prefix}.bam.bai"
990+
String wallclocktime = read_string("wallclocktime.txt")
983991
}
984992

985993
#########################

0 commit comments

Comments
 (0)