Skip to content

Commit

Permalink
change registering to inheritance of abstract class
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
CunliangGeng committed Jun 17, 2024
1 parent 2636f78 commit 524ab08
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 20 deletions.
6 changes: 1 addition & 5 deletions src/nplinker/genomics/antismash/antismash_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
logger = logging.getLogger(__name__)


class AntismashBGCLoader:
class AntismashBGCLoader(BGCLoaderBase):
"""Build a loader for AntiSMASH BGC genbank (.gbk) files.
Note:
Expand Down Expand Up @@ -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)
12 changes: 2 additions & 10 deletions src/nplinker/genomics/bigscape/bigscape_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
logger = logging.getLogger(__name__)


class BigscapeGCFLoader:
class BigscapeGCFLoader(GCFLoaderBase):
"""Build a loader for BiG-SCAPE GCF cluster file.
Attributes:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
6 changes: 1 addition & 5 deletions src/nplinker/genomics/mibig/mibig_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

0 comments on commit 524ab08

Please sign in to comment.