|
| 1 | +version 1.0 |
| 2 | + |
| 3 | + |
| 4 | +import "../../../tasks/Utility/BAMutils.wdl" as BU |
| 5 | +import "../../../tasks/Utility/GeneralUtils.wdl" as GU |
| 6 | + |
| 7 | +import "../../../tasks/Visualization/NanoPlot.wdl" as QC0 |
| 8 | +import "../../TechAgnostic/Utility/CountTheBeans.wdl" as QC1 |
| 9 | +import "../../TechAgnostic/Utility/DystPeaker.wdl" as QC2 |
| 10 | +import "../../TechAgnostic/Utility/FASTQstats.wdl" as QC3 |
| 11 | + |
| 12 | +import "../../../tasks/Utility/Finalize.wdl" as FF |
| 13 | +import "../../TechAgnostic/Utility/SaveFilesToDestination.wdl" as SAVE |
| 14 | + |
| 15 | +workflow ProcessOnInstrumentDemuxedChunkRefFree { |
| 16 | + |
| 17 | + meta { |
| 18 | + desciption: "Given an on-instrument demultiplexed hifi_reads.bam, perform ref-independent prep work, and collect a few metrics" |
| 19 | + } |
| 20 | + |
| 21 | + parameter_meta { |
| 22 | + readgroup_id: |
| 23 | + "Unique ID for a readgroup, for example (D|E)A[0-9]{6}-<barcode>" |
| 24 | + |
| 25 | + short_reads_threshold: |
| 26 | + "a length threshold below which reads are classified as short" |
| 27 | + |
| 28 | + bam_descriptor: |
| 29 | + "a one-word description of the purpose of the BAM (e.g. 'a_particular_seq_center'; used for saving the reads that don't have any MM/ML tags; doesn't need to be single-file specific)" |
| 30 | + |
| 31 | + hifi_stats: |
| 32 | + "A few metrics output by Nanoplot" |
| 33 | + hifi_fq_stats: |
| 34 | + "A few metrics output by seqkit stats" |
| 35 | + |
| 36 | + read_len_summaries: |
| 37 | + "A few metrics summarizing the read length distribution" |
| 38 | + read_len_peaks: |
| 39 | + "Peaks of the read length distribution (heruistic)" |
| 40 | + read_len_deciles: |
| 41 | + "Deciles of the read length distribution" |
| 42 | + |
| 43 | + methyl_tag_simple_stats: |
| 44 | + "Simple stats on the reads with & without SAM methylation tags (MM/ML)." |
| 45 | + |
| 46 | + uBAM_metrics_files_out: |
| 47 | + "A map where keys are summary-names and values are paths to files generated from the various QC/metrics tasks" |
| 48 | + } |
| 49 | + |
| 50 | + input { |
| 51 | + File uBAM |
| 52 | + String readgroup_id |
| 53 | + |
| 54 | + String bam_descriptor |
| 55 | + Int short_reads_threshold |
| 56 | + |
| 57 | + String disk_type = "SSD" |
| 58 | + |
| 59 | + String gcs_out_root_dir |
| 60 | + } |
| 61 | + |
| 62 | + output { |
| 63 | + String movie = movie_name |
| 64 | + |
| 65 | + File hifi_fq = FinalizeFQ.gcs_path |
| 66 | + |
| 67 | + String last_processing_date = today.yyyy_mm_dd |
| 68 | + |
| 69 | + # todo merge these two together |
| 70 | + Map[String, Float] hifi_stats = NanoPlotFromUBam.stats_map |
| 71 | + Map[String, Float] hifi_fq_stats = FASTQstats.stats |
| 72 | + |
| 73 | + Map[String, String] read_len_summaries = DystPeaker.read_len_summaries |
| 74 | + Array[Int] read_len_peaks = DystPeaker.read_len_peaks |
| 75 | + Array[Int] read_len_deciles = DystPeaker.read_len_deciles |
| 76 | + |
| 77 | + # methylation call rate stats |
| 78 | + Map[String, String] methyl_tag_simple_stats = NoMissingBeans.methyl_tag_simple_stats |
| 79 | + |
| 80 | + # file-based outputs all packed into a finalization map |
| 81 | + Map[String, String] uBAM_metrics_files_out = FF.result |
| 82 | + } |
| 83 | + |
| 84 | + ################################################################################### |
| 85 | + # prep work |
| 86 | +
|
| 87 | + # where to store final results |
| 88 | + String workflow_name = "ProcessOnInstrumentDemuxedChunkRefFree" |
| 89 | + String outdir = sub(gcs_out_root_dir, "/$", "") + "/" + workflow_name |
| 90 | + |
| 91 | + String outdir_ref_free = outdir + '/RefFree' # ideally, this isn't necessary, but it's a relic we'd not touch right now (2023-12-23) |
| 92 | + String bc_specific_out = outdir_ref_free + '/' + readgroup_id |
| 93 | + String bc_specific_metrics_out = bc_specific_out + "/metrics" |
| 94 | + |
| 95 | + ################################################################################### |
| 96 | + call BU.GetReadGroupInfo as RG {input: bam = uBAM, keys = ['PU']} |
| 97 | + String movie_name = RG.read_group_info['PU'] |
| 98 | +
|
| 99 | + ################################################################################### |
| 100 | + # convert to FASTQ (most for assembly) |
| 101 | + call BU.BamToFastq {input: bam = uBAM, prefix = "does_not_matter"} |
| 102 | + call FF.FinalizeToFile as FinalizeFQ { input: |
| 103 | + outdir = bc_specific_out, |
| 104 | + file = BamToFastq.reads_fq, |
| 105 | + name = readgroup_id + '.hifi.fq.gz' |
| 106 | + } |
| 107 | +
|
| 108 | + ################################################################################### |
| 109 | + # more QCs and metrics |
| 110 | +
|
| 111 | + ########## |
| 112 | + call QC0.NanoPlotFromUBam {input: uBAM = uBAM} |
| 113 | + FinalizationManifestLine a = object |
| 114 | + {files_to_save: flatten([[NanoPlotFromUBam.stats], NanoPlotFromUBam.plots]), |
| 115 | + is_singleton_file: false, |
| 116 | + destination: bc_specific_metrics_out + "/nanoplot", |
| 117 | + output_attribute_name: "nanoplot"} |
| 118 | + ########## |
| 119 | + call QC1.CountTheBeans as NoMissingBeans { input: |
| 120 | + bam=uBAM, |
| 121 | + bam_descriptor=bam_descriptor, |
| 122 | + gcs_out_root_dir=bc_specific_metrics_out, |
| 123 | + use_local_ssd=disk_type=='LOCAL' |
| 124 | + } |
| 125 | + Map[String, String] methyl_out = {"missing_methyl_tag_reads": |
| 126 | + NoMissingBeans.methyl_tag_simple_stats['files_holding_reads_without_tags']} |
| 127 | + ########## |
| 128 | + call QC2.DystPeaker { input: |
| 129 | + input_file=uBAM, input_is_bam=true, |
| 130 | + id=readgroup_id, short_reads_threshold=short_reads_threshold, |
| 131 | + gcs_out_root_dir=bc_specific_metrics_out |
| 132 | + } |
| 133 | + Map[String, String] read_len_out = {"read_len_hist": DystPeaker.read_len_hist, |
| 134 | + "raw_rl_file": DystPeaker.read_len_summaries['raw_rl_file']} |
| 135 | + |
| 136 | + ########## |
| 137 | + call QC3.FASTQstats { input: |
| 138 | + reads=BamToFastq.reads_fq, |
| 139 | + file_type='FASTQ' |
| 140 | + } |
| 141 | +
|
| 142 | + ################################################################################### |
| 143 | + call SAVE.SaveFilestoDestination as FF { input: |
| 144 | + instructions = select_all([a]), |
| 145 | + already_finalized = select_all([methyl_out, |
| 146 | + read_len_out]) |
| 147 | + } |
| 148 | +
|
| 149 | + call GU.GetTodayDate as today {} |
| 150 | +} |
0 commit comments