|
| 1 | +import hail as hl |
| 2 | +import luigi |
| 3 | +import luigi.util |
| 4 | + |
| 5 | +from v03_pipeline.lib.paths import ( |
| 6 | + variant_annotations_table_path, |
| 7 | +) |
| 8 | +from v03_pipeline.lib.tasks.base.base_loading_pipeline_params import ( |
| 9 | + BaseLoadingPipelineParams, |
| 10 | +) |
| 11 | +from v03_pipeline.lib.tasks.base.base_update import ( |
| 12 | + BaseUpdateTask, |
| 13 | +) |
| 14 | +from v03_pipeline.lib.tasks.files import GCSorLocalTarget, HailTableTask |
| 15 | + |
| 16 | + |
| 17 | +@luigi.util.inherits(BaseLoadingPipelineParams) |
| 18 | +class UpdateVariantAnnotationsTableWithDroppedReferenceDatasetsTask( |
| 19 | + BaseUpdateTask, |
| 20 | +): |
| 21 | + run_id = luigi.Parameter() |
| 22 | + |
| 23 | + def output(self) -> luigi.Target: |
| 24 | + return GCSorLocalTarget( |
| 25 | + variant_annotations_table_path( |
| 26 | + self.reference_genome, |
| 27 | + self.dataset_type, |
| 28 | + ), |
| 29 | + ) |
| 30 | + |
| 31 | + def requires(self) -> list[luigi.Task]: |
| 32 | + return HailTableTask( |
| 33 | + variant_annotations_table_path( |
| 34 | + self.reference_genome, |
| 35 | + self.dataset_type, |
| 36 | + ), |
| 37 | + ) |
| 38 | + |
| 39 | + def complete(self) -> bool: |
| 40 | + return ( |
| 41 | + super().complete() and 'dbnsfp' not in hl.read_table(self.output().path).row |
| 42 | + ) |
| 43 | + |
| 44 | + def initialize_table(self) -> hl.Table: |
| 45 | + key_type = self.dataset_type.table_key_type(self.reference_genome) |
| 46 | + return hl.Table.parallelize( |
| 47 | + [], |
| 48 | + key_type, |
| 49 | + key=key_type.fields, |
| 50 | + globals=hl.Struct( |
| 51 | + enums=hl.Struct(), |
| 52 | + updates=hl.empty_set( |
| 53 | + hl.tstruct( |
| 54 | + callset=hl.tstr, |
| 55 | + project_guid=hl.tstr, |
| 56 | + remap_pedigree_hash=hl.tint32, |
| 57 | + ), |
| 58 | + ), |
| 59 | + migrations=hl.empty_array(hl.tstr), |
| 60 | + max_key_=hl.int64(-1), |
| 61 | + ), |
| 62 | + ) |
| 63 | + |
| 64 | + def update_table(self, ht: hl.Table) -> hl.Table: |
| 65 | + for field in [ |
| 66 | + 'clinvar', |
| 67 | + 'gnomad_mito', |
| 68 | + 'hmtvar', |
| 69 | + 'local_constraint_mito', |
| 70 | + 'dbnsfp', |
| 71 | + 'mitomap', |
| 72 | + 'mitimpact', |
| 73 | + 'helix_mito', |
| 74 | + 'gt_stats', |
| 75 | + 'high_constraint_region', |
| 76 | + 'eigen', |
| 77 | + 'splice_ai', |
| 78 | + 'exac', |
| 79 | + 'topmed', |
| 80 | + 'screen', |
| 81 | + 'gnomad_exomes', |
| 82 | + 'gnomad_genomes', |
| 83 | + 'hgmd', |
| 84 | + 'gnomad_non_coding_constraint', |
| 85 | + ]: |
| 86 | + if field in ht.row: |
| 87 | + ht = ht.drop(field) |
| 88 | + if field in ht.enums: |
| 89 | + ht = ht.annotate_globals(enums=ht.enums.drop(field)) |
| 90 | + return ht |
0 commit comments