|
| 1 | +version 1.0 |
| 2 | + |
| 3 | +import "../../../tasks/Utility/GeneralUtils.wdl" as GU |
| 4 | + |
| 5 | +import "../../../tasks/Alignment/AlignHiFiUBAM.wdl" as ALN |
| 6 | + |
| 7 | +import "../../TechAgnostic/Utility/AlignedBamQCandMetrics.wdl" as QCMetrics |
| 8 | + |
| 9 | +import "../../../tasks/Utility/Finalize.wdl" as FF |
| 10 | +import "../../TechAgnostic/Utility/SaveFilesToDestination.wdl" as SAVE |
| 11 | + |
| 12 | +workflow ProcessOnInstrumentDemuxedChunk { |
| 13 | + |
| 14 | + meta { |
| 15 | + desciption: "Given an on-instrument demultiplexed hifi_reads.bam, perform alignment and QC check, and collect a few metrics." |
| 16 | + } |
| 17 | + |
| 18 | + parameter_meta { |
| 19 | + |
| 20 | + ######### |
| 21 | + # inputs |
| 22 | + readgroup_id: |
| 23 | + "Unique ID for a readgroup, for example (D|E)A[0-9]{6}-<barcode>; no whitespaces allowed" |
| 24 | + |
| 25 | + bam_SM_field: |
| 26 | + "value to place in the SM field of the resulting BAM header's @RG line" |
| 27 | + |
| 28 | + platform: |
| 29 | + "PacBio platform used for generating the data; accepted value: [Sequel, Revio]" |
| 30 | + |
| 31 | + bam_descriptor: |
| 32 | + "a one-word description of the purpose of the BAM (e.g. 'rg_post_aln'; used for saving the reads that don't have any MM/ML tags; doesn't need to be single-file specific)" |
| 33 | + |
| 34 | + gcs_out_root_dir: |
| 35 | + "output files will be copied over there" |
| 36 | + |
| 37 | + cov_bed: |
| 38 | + "An optional BED file on which coverage will be collected (a mean value for each interval)" |
| 39 | + cov_bed_descriptor: |
| 40 | + "A short description of the BED provided for targeted coverage estimation; will be used in naming output files." |
| 41 | + |
| 42 | + fingerprint_store: |
| 43 | + "A GCS 'folder' holding fingerprint VCF files" |
| 44 | + sample_id_at_store: |
| 45 | + "The ID of the sample supposedly this BAM belongs to; note that the fingerprint VCF is assumed to be located at {fingerprint_store}/{sample_id_at_store}*.vcf(.gz?)" |
| 46 | + |
| 47 | + vbid2_config_json: |
| 48 | + "A config json to for running the VBID2 contamination estimation sub-workflow; if provided, will trigger the VBID2 sub-workflow for cross-(human)individual contamination estimation." |
| 49 | + |
| 50 | + expected_sex_type: |
| 51 | + "If provided, triggers sex concordance check. Accepted value: [M, F, NA, na]" |
| 52 | + |
| 53 | + check_postaln_methyl_tags: |
| 54 | + "If true, will run a sub-workflow to collect methylation tags information." |
| 55 | + |
| 56 | + ######### |
| 57 | + # outputs |
| 58 | + wgs_cov: |
| 59 | + "whole genome mean coverage" |
| 60 | + |
| 61 | + nanoplot_summ: |
| 62 | + "Summary on alignment metrics provided by Nanoplot (todo: study the value of this output)" |
| 63 | + |
| 64 | + sam_flag_stats: |
| 65 | + "SAM flag stats" |
| 66 | + |
| 67 | + contamination_est: |
| 68 | + "cross-(human)individual contamination estimation by VerifyBAMID2" |
| 69 | + |
| 70 | + inferred_sex_info: |
| 71 | + "Inferred sex concordance information if expected sex type is provided" |
| 72 | + |
| 73 | + methyl_tag_simple_stats: |
| 74 | + "Simple stats on the reads with & without SAM methylation tags (MM/ML)." |
| 75 | + |
| 76 | + aBAM_metrics_files_out: |
| 77 | + "A map where keys are summary-names and values are paths to files generated from the various QC/metrics tasks" |
| 78 | + } |
| 79 | + |
| 80 | + input { |
| 81 | + File uBAM |
| 82 | + File? uPBI |
| 83 | + |
| 84 | + String readgroup_id |
| 85 | + |
| 86 | + String bam_SM_field |
| 87 | + |
| 88 | + String platform |
| 89 | + |
| 90 | + File ref_map_file |
| 91 | + |
| 92 | + String gcs_out_root_dir |
| 93 | + |
| 94 | + String disk_type = "SSD" |
| 95 | + |
| 96 | + # args for optional QC subworkflows |
| 97 | + String bam_descriptor |
| 98 | + String tech |
| 99 | + |
| 100 | + File? cov_bed |
| 101 | + String? cov_bed_descriptor |
| 102 | + |
| 103 | + String? fingerprint_store |
| 104 | + String? sample_id_at_store |
| 105 | + |
| 106 | + File? vbid2_config_json |
| 107 | + String? expected_sex_type |
| 108 | + Boolean check_postaln_methyl_tags = true |
| 109 | + } |
| 110 | + |
| 111 | + output { |
| 112 | + String last_processing_date = today.yyyy_mm_dd |
| 113 | + |
| 114 | + File aligned_bam = FinalizeAlignedBam.gcs_path |
| 115 | + File aligned_bai = FinalizeAlignedBai.gcs_path |
| 116 | + File aligned_pbi = FinalizeAlignedPbi.gcs_path |
| 117 | + |
| 118 | + String movie = AlignHiFiUBAM.movie |
| 119 | + |
| 120 | + # metrics block (caveat: always has to keep an eye on the QC subworkflow about outputs) |
| 121 | + Float wgs_cov = QCandMetrics.wgs_cov |
| 122 | + Map[String, Float] nanoplot_summ = QCandMetrics.nanoplot_summ |
| 123 | + Map[String, Float] sam_flag_stats = QCandMetrics.sam_flag_stats |
| 124 | + |
| 125 | + # fingerprint |
| 126 | + Map[String, String]? fingerprint_check = QCandMetrics.fingerprint_check |
| 127 | + |
| 128 | + # contam |
| 129 | + Float? contamination_est = QCandMetrics.contamination_est |
| 130 | + |
| 131 | + # sex concordance |
| 132 | + Map[String, String]? inferred_sex_info = QCandMetrics.inferred_sex_info |
| 133 | + |
| 134 | + # methyl |
| 135 | + Map[String, String]? methyl_tag_simple_stats = QCandMetrics.methyl_tag_simple_stats |
| 136 | + |
| 137 | + # file-based QC/metrics outputs all packed into a finalization map |
| 138 | + Map[String, String] aBAM_metrics_files_out = QCandMetrics.aBAM_metrics_files_out |
| 139 | + } |
| 140 | + |
| 141 | + ################################################################################### |
| 142 | + # prep work |
| 143 | +
|
| 144 | + # where to store final results |
| 145 | + String workflow_name = "ProcessOnInstrumentDemuxedChunk" |
| 146 | + String outdir = sub(gcs_out_root_dir, "/$", "") + "/" + workflow_name |
| 147 | + |
| 148 | + # String bc_specific_out = outdir + '/' + readgroup_id |
| 149 | + String bc_specific_aln_out = outdir + '/alignments/' + readgroup_id |
| 150 | + String bc_specific_metrics_out = outdir + "/metrics/" + readgroup_id |
| 151 | + |
| 152 | + ################################################################################### |
| 153 | + # align |
| 154 | + call ALN.AlignHiFiUBAM as AlignHiFiUBAM { input: |
| 155 | + uBAM = uBAM, |
| 156 | + uPBI = uPBI, |
| 157 | + bam_sample_name = bam_SM_field, |
| 158 | + ref_map_file = ref_map_file, |
| 159 | + application = 'HIFI' |
| 160 | + } |
| 161 | +
|
| 162 | + File aBAM = AlignHiFiUBAM.aligned_bam |
| 163 | + File aBAI = AlignHiFiUBAM.aligned_bai |
| 164 | + File aPBI = AlignHiFiUBAM.aligned_pbi |
| 165 | +
|
| 166 | + # save |
| 167 | + call FF.FinalizeToFile as FinalizeAlignedBam { input: outdir = bc_specific_aln_out, file = aBAM, name = readgroup_id + '.bam' } |
| 168 | + call FF.FinalizeToFile as FinalizeAlignedBai { input: outdir = bc_specific_aln_out, file = aBAI, name = readgroup_id + '.bai' } |
| 169 | + call FF.FinalizeToFile as FinalizeAlignedPbi { input: outdir = bc_specific_aln_out, file = aPBI, name = readgroup_id + '.pbi' } |
| 170 | +
|
| 171 | + ################################################################################### |
| 172 | + # QC |
| 173 | + call QCMetrics.Work as QCandMetrics { input: |
| 174 | + bam = aBAM, |
| 175 | + bai = aBAI, |
| 176 | +
|
| 177 | + bam_descriptor = bam_descriptor, |
| 178 | + tech = platform, |
| 179 | +
|
| 180 | + cov_bed = cov_bed, |
| 181 | + cov_bed_descriptor = cov_bed_descriptor, |
| 182 | +
|
| 183 | + fingerprint_store = fingerprint_store, |
| 184 | + sample_id_at_store = sample_id_at_store, |
| 185 | +
|
| 186 | + vbid2_config_json = vbid2_config_json, |
| 187 | + expected_sex_type = expected_sex_type, |
| 188 | + check_postaln_methyl_tags = check_postaln_methyl_tags, |
| 189 | +
|
| 190 | + ref_map_file = ref_map_file, |
| 191 | + disk_type = disk_type, |
| 192 | +
|
| 193 | + output_prefix = readgroup_id, # String output_prefix = bam_sample_name + "." + flowcell |
| 194 | + gcs_out_root_dir = bc_specific_metrics_out, |
| 195 | + } |
| 196 | +
|
| 197 | + ################################################################################### |
| 198 | +
|
| 199 | + call GU.GetTodayDate as today {} |
| 200 | +} |
0 commit comments