From 524ab08f97039b085b8fb0d2b180498f324c9942 Mon Sep 17 00:00:00 2001 From: Cunliang Geng Date: Mon, 17 Jun 2024 15:34:03 +0200 Subject: [PATCH] change registering to inheritance of abstract class Registering as virtual class can avoid metclass conflicts. However, it's not an issue we need to worry in this codebase, since all concrete classes, e.g. AntismashBGCLoader, inherit only one base class instead of multiple classes that have different metaclasses. Using inheritance of abstract class is more straightforward and explict. --- src/nplinker/genomics/antismash/antismash_loader.py | 6 +----- src/nplinker/genomics/bigscape/bigscape_loader.py | 12 ++---------- src/nplinker/genomics/mibig/mibig_loader.py | 6 +----- 3 files changed, 4 insertions(+), 20 deletions(-) diff --git a/src/nplinker/genomics/antismash/antismash_loader.py b/src/nplinker/genomics/antismash/antismash_loader.py index 31a631625..0994a2126 100644 --- a/src/nplinker/genomics/antismash/antismash_loader.py +++ b/src/nplinker/genomics/antismash/antismash_loader.py @@ -17,7 +17,7 @@ logger = logging.getLogger(__name__) -class AntismashBGCLoader: +class AntismashBGCLoader(BGCLoaderBase): """Build a loader for AntiSMASH BGC genbank (.gbk) files. Note: @@ -163,7 +163,3 @@ def _parse_antismash_genbank(record: SeqRecord.SeqRecord) -> dict: smiles = tuple(i.replace(" ", "") for i in smiles) features["smiles"] = smiles return features - - -# register as virtual class to prevent metaclass conflicts -BGCLoaderBase.register(AntismashBGCLoader) diff --git a/src/nplinker/genomics/bigscape/bigscape_loader.py b/src/nplinker/genomics/bigscape/bigscape_loader.py index c4e7637b3..f38f47af6 100644 --- a/src/nplinker/genomics/bigscape/bigscape_loader.py +++ b/src/nplinker/genomics/bigscape/bigscape_loader.py @@ -10,7 +10,7 @@ logger = logging.getLogger(__name__) -class BigscapeGCFLoader: +class BigscapeGCFLoader(GCFLoaderBase): """Build a loader for BiG-SCAPE GCF cluster file. Attributes: @@ -61,11 +61,7 @@ def _parse_gcf(cluster_file: str) -> list[GCF]: return list(gcf_dict.values()) -# register as virtual class to prevent metaclass conflicts -GCFLoaderBase.register(BigscapeGCFLoader) - - -class BigscapeV2GCFLoader: +class BigscapeV2GCFLoader(GCFLoaderBase): """Build a loader for BiG-SCAPE v2 database file. Attributes: @@ -137,7 +133,3 @@ def _parse_gcf(db_file: str) -> list[GCF]: gcf_dict[family_id].bgc_ids.add(bgc_id) return list(gcf_dict.values()) - - -# register as virtual class to prevent metaclass conflicts -GCFLoaderBase.register(BigscapeV2GCFLoader) diff --git a/src/nplinker/genomics/mibig/mibig_loader.py b/src/nplinker/genomics/mibig/mibig_loader.py index 00f8c03c5..b588a189f 100644 --- a/src/nplinker/genomics/mibig/mibig_loader.py +++ b/src/nplinker/genomics/mibig/mibig_loader.py @@ -12,7 +12,7 @@ logger = logging.getLogger(__name__) -class MibigLoader: +class MibigLoader(BGCLoaderBase): """Parse MIBiG metadata files and return BGC objects. MIBiG metadata file (json) contains annotations/metadata information @@ -118,7 +118,3 @@ def parse_bgc_metadata_json(file: str | PathLike) -> BGC: mibig_bgc.mibig_bgc_class = metadata.biosyn_class mibig_bgc.strain = Strain(metadata.mibig_accession) return mibig_bgc - - -# register as virtual class to prevent metaclass conflicts -BGCLoaderBase.register(MibigLoader)