From ed65c60b32d01248be9b96c08c2bac45c00eeefa Mon Sep 17 00:00:00 2001 From: jkgoodrich <33063077+jkgoodrich@users.noreply.github.com> Date: Fri, 26 Jan 2024 09:40:18 -0700 Subject: [PATCH 1/2] Add `read_args` parameter to the read functions of Resource Classes --- gnomad/resources/resource_utils.py | 49 ++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/gnomad/resources/resource_utils.py b/gnomad/resources/resource_utils.py index f245ce70d..6a03fef64 100644 --- a/gnomad/resources/resource_utils.py +++ b/gnomad/resources/resource_utils.py @@ -109,16 +109,23 @@ class TableResource(BaseResource): expected_file_extensions: List[str] = [".ht"] - def ht(self, force_import: bool = False) -> hl.Table: + def ht( + self, + force_import: bool = False, + read_args: Optional[Dict[str, Any]] = None, + ) -> hl.Table: """ Read and return the Hail Table resource. + :param force_import: If ``True``, force the import of the resource even if it + already exists. + :param read_args: Any additional arguments to pass to hl.read_table. :return: Hail Table resource """ if self.path is None or force_import: return self.import_func(**self.import_args) else: - return hl.read_table(self.path) + return hl.read_table(self.path, **(read_args or {})) def import_resource(self, overwrite: bool = True, **kwargs) -> None: """ @@ -144,16 +151,23 @@ class MatrixTableResource(BaseResource): expected_file_extensions: List[str] = [".mt"] - def mt(self, force_import: bool = False) -> hl.MatrixTable: + def mt( + self, + force_import: bool = False, + read_args: Optional[Dict[str, Any]] = None, + ) -> hl.MatrixTable: """ Read and return the Hail MatrixTable resource. + :param force_import: If ``True``, force the import of the resource even if it + already exists. + :param read_args: Any additional arguments to pass to hl.read_matrix_table. :return: Hail MatrixTable resource """ if self.path is None or force_import: return self.import_func(**self.import_args) else: - return hl.read_matrix_table(self.path) + return hl.read_matrix_table(self.path, **(read_args or {})) def import_resource(self, overwrite: bool = True, **kwargs) -> None: """ @@ -179,16 +193,23 @@ class VariantDatasetResource(BaseResource): expected_file_extensions: List[str] = [".vds"] - def vds(self, force_import: bool = False) -> hl.vds.VariantDataset: + def vds( + self, + force_import: bool = False, + read_args: Optional[Dict[str, Any]] = None, + ) -> hl.vds.VariantDataset: """ Read and return the Hail VariantDataset resource. + :param force_import: If ``True``, force the import of the resource even if it + already exists. + :param read_args: Any additional arguments to pass to hl.vds.read_vds. :return: Hail VariantDataset resource """ if self.path is None or force_import: return self.import_func(**self.import_args) else: - return hl.vds.read_vds(self.path) + return hl.vds.read_vds(self.path, **(read_args or {})) def import_resource(self, overwrite: bool = True, **kwargs) -> None: """ @@ -283,13 +304,14 @@ class BlockMatrixResource(BaseResource): expected_file_extensions: List[str] = [".bm"] - def bm(self) -> BlockMatrix: + def bm(self, read_args: Optional[Dict[str, Any]] = None) -> BlockMatrix: """ Read and return the Hail MatrixTable resource. + :param read_args: Any additional arguments to pass to BlockMatrix.read. :return: Hail MatrixTable resource """ - return BlockMatrix.read(self.path) + return BlockMatrix.read(self.path, **(read_args or {})) def import_resource(self, overwrite: bool = True, **kwargs) -> None: """ @@ -318,16 +340,23 @@ class ExpressionResource(BaseResource): expected_file_extensions: List[str] = [".he"] - def he(self, force_import: bool = False) -> hl.expr.Expression: + def he( + self, + force_import: bool = False, + read_args: Optional[Dict[str, Any]] = None, + ) -> hl.expr.Expression: """ Read and return the Hail Expression resource. + :param force_import: If ``True``, force the import of the resource even if it + already exists. + :param read_args: Any additional arguments to pass to hl.experimental. :return: Hail Expression resource. """ if self.path is None or force_import: return self.import_func(**self.import_args) else: - return hl.experimental.read_expression(self.path) + return hl.experimental.read_expression(self.path, **(read_args or {})) def import_resource(self, overwrite: bool = True, **kwargs) -> None: """ From 722ec0a3ebb9fe3c1215b5f48b256acf20208227 Mon Sep 17 00:00:00 2001 From: jkgoodrich <33063077+jkgoodrich@users.noreply.github.com> Date: Fri, 26 Jan 2024 10:42:19 -0700 Subject: [PATCH 2/2] Update gnomad/resources/resource_utils.py Co-authored-by: Katherine Chao --- gnomad/resources/resource_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnomad/resources/resource_utils.py b/gnomad/resources/resource_utils.py index 6a03fef64..2c6eb64a9 100644 --- a/gnomad/resources/resource_utils.py +++ b/gnomad/resources/resource_utils.py @@ -350,7 +350,7 @@ def he( :param force_import: If ``True``, force the import of the resource even if it already exists. - :param read_args: Any additional arguments to pass to hl.experimental. + :param read_args: Any additional arguments to pass to hl.experimental.read_expression. :return: Hail Expression resource. """ if self.path is None or force_import: