|
| 1 | +version 1.0 |
| 2 | + |
| 3 | +import "../../../structs/Structs.wdl" |
| 4 | + |
| 5 | +import "../../../tasks/Utility/Utils.wdl" |
| 6 | + |
| 7 | +import "../../../tasks/Utility/Finalize.wdl" as FF |
| 8 | + |
| 9 | +workflow HiFiCNV { |
| 10 | + meta { |
| 11 | + description: |
| 12 | + "Runs the PacBio HiFiCNV tool on a single (human) HiFi bam." |
| 13 | + } |
| 14 | + parameter_meta { |
| 15 | + exclude_bed: "BED holding regions that are known to cause artifacts during HiFiCNV data processing (e.g. centromeres)." |
| 16 | + sex_specific_cn: "Sex-specific files annotating the PAR regions on and expected copy numbers of sex chromosomes." |
| 17 | + ref_map_file: "table indicating reference sequence and auxiliary file locations" |
| 18 | + gcs_out_root_dir: "GCS bucket to store the variants, and metrics files" |
| 19 | + } |
| 20 | + input { |
| 21 | + File bam |
| 22 | + File bai |
| 23 | + |
| 24 | + File ref_map_file |
| 25 | + File exclude_bed |
| 26 | + File sex_specific_cn |
| 27 | + |
| 28 | + String gcs_out_root_dir |
| 29 | + } |
| 30 | + output { |
| 31 | + String vcf = FinalizeVCF.gcs_path |
| 32 | + String bedgraph = FinalizeBedGraph.gcs_path |
| 33 | + String depth_bw = FinalizeBigWig.gcs_path |
| 34 | + String log = FinalizeLog.gcs_path |
| 35 | + } |
| 36 | + |
| 37 | + Map[String, String] ref_map = read_map(ref_map_file) |
| 38 | + |
| 39 | + call Utils.InferSampleName { input: bam = bam, bai = bai} |
| 40 | + call PacBioHiFiCNV { input: |
| 41 | + bam = bam, bai = bai, |
| 42 | + sample_name = InferSampleName.sample_name, |
| 43 | + output_prefix = InferSampleName.sample_name, |
| 44 | + ref_fasta = ref_map['fasta'], |
| 45 | + ref_fasta_fai = ref_map['fai'], |
| 46 | + exclude_bed = exclude_bed, |
| 47 | + sex_specific_cn = sex_specific_cn |
| 48 | + } |
| 49 | +
|
| 50 | + String workflow_name = 'HiFiCNV' |
| 51 | + String outdir = sub(gcs_out_root_dir, "/$", "") + "/~{workflow_name}/~{InferSampleName.sample_name}" |
| 52 | + call FF.FinalizeToFile as FinalizeLog { input: outdir = outdir, file = PacBioHiFiCNV.log } |
| 53 | + call FF.FinalizeToFile as FinalizeVCF { input: outdir = outdir, file = PacBioHiFiCNV.vcf } |
| 54 | + call FF.FinalizeToFile as FinalizeBedGraph { input: outdir = outdir, file = PacBioHiFiCNV.bedgraph } |
| 55 | + call FF.FinalizeToFile as FinalizeBigWig { input: outdir = outdir, file = PacBioHiFiCNV.depth_bw } |
| 56 | +} |
| 57 | +
|
| 58 | +task PacBioHiFiCNV { |
| 59 | + input { |
| 60 | + File bam |
| 61 | + File bai |
| 62 | + String sample_name |
| 63 | + String output_prefix |
| 64 | + File ref_fasta |
| 65 | + File ref_fasta_fai |
| 66 | + |
| 67 | + File exclude_bed |
| 68 | + File sex_specific_cn |
| 69 | + |
| 70 | + RuntimeAttr? runtime_attr_override |
| 71 | + } |
| 72 | + |
| 73 | + output { |
| 74 | + File vcf = "~{output_prefix}.${sample_name}.vcf.gz" |
| 75 | + File bedgraph = "~{output_prefix}.${sample_name}.copynum.bedgraph" |
| 76 | + File log = "~{output_prefix}.log" |
| 77 | + File depth_bw = "~{output_prefix}.${sample_name}.depth.bw" |
| 78 | + } |
| 79 | + |
| 80 | + command <<< |
| 81 | + set -eux |
| 82 | +
|
| 83 | + num_core=$(cat /proc/cpuinfo | awk '/^processor/{print $3}' | wc -l) |
| 84 | +
|
| 85 | + # re-generate the bai to ensure it's not corrupted, as corrupted bai can cause hificnv to fail without a clear error message |
| 86 | + rm ~{bai} \ |
| 87 | + && \ |
| 88 | + samtools index ~{bam} |
| 89 | +
|
| 90 | + hificnv \ |
| 91 | + --bam ~{bam} \ |
| 92 | + --ref ~{ref_fasta} \ |
| 93 | + --exclude ~{exclude_bed} \ |
| 94 | + --expected-cn ~{sex_specific_cn} \ |
| 95 | + --threads "${num_core}" \ |
| 96 | + --output-prefix ~{output_prefix} |
| 97 | +
|
| 98 | + tree |
| 99 | + >>> |
| 100 | + |
| 101 | + ######################### |
| 102 | + Int min_disk = 40 |
| 103 | + Float disk_multiplier = 1 |
| 104 | + Int disk_size = ceil(disk_multiplier * size(bam, "GiB")) + 20 |
| 105 | + Int use_this_disk_sz = if (min_disk>disk_size) then min_disk else disk_size |
| 106 | + |
| 107 | + RuntimeAttr default_attr = object { |
| 108 | + cpu_cores: 2, |
| 109 | + mem_gb: 6, |
| 110 | + disk_gb: use_this_disk_sz, |
| 111 | + preemptible_tries: 3, |
| 112 | + max_retries: 0, |
| 113 | + docker: "us.gcr.io/broad-dsp-lrma/hificnv:1.0.1" |
| 114 | + } |
| 115 | + |
| 116 | + RuntimeAttr runtime_attr = select_first([runtime_attr_override, default_attr]) |
| 117 | + runtime { |
| 118 | + cpu: select_first([runtime_attr.cpu_cores, default_attr.cpu_cores]) |
| 119 | + memory: select_first([runtime_attr.mem_gb, default_attr.mem_gb]) + " GiB" |
| 120 | + disks: "local-disk " + select_first([runtime_attr.disk_gb, default_attr.disk_gb]) + " SSD" |
| 121 | + preemptible: select_first([runtime_attr.preemptible_tries, default_attr.preemptible_tries]) |
| 122 | + maxRetries: select_first([runtime_attr.max_retries, default_attr.max_retries]) |
| 123 | + docker: select_first([runtime_attr.docker, default_attr.docker]) |
| 124 | + |
| 125 | + noAddress: true |
| 126 | + } |
| 127 | +} |
0 commit comments