Skip to content

Commit

Permalink
add keep_mibig_only to BigscapeGCFLoader.get_gcfs method
Browse files Browse the repository at this point in the history
- add parameter `keep_mibig_only`
- update and add unit tests
  • Loading branch information
CunliangGeng committed Oct 25, 2023
1 parent ba8e29a commit ae73971
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
14 changes: 12 additions & 2 deletions src/nplinker/genomics/bigscape/bigscape_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,18 @@ def __init__(self, cluster_file: str | PathLike, /) -> None:
self._gcf_dict = self._parse_gcf(self.cluster_file)
self._gcf_list = list(self._gcf_dict.values())

def get_gcfs(self) -> list[GCF]:
"""Get all GCF objects."""
def get_gcfs(self, keep_mibig_only=False) -> list[GCF]:
"""Get all GCF objects.
Args:
keep_mibig_only(bool): True to keep GCFs that contain only MIBiG
BGCs.
Returns:
list[GCF]: a list of GCF objects.
"""
if not keep_mibig_only:
return [gcf for gcf in self._gcf_list if not gcf.has_mibig_only()]
return self._gcf_list

@staticmethod
Expand Down
10 changes: 8 additions & 2 deletions tests/genomics/test_bigscape_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,19 @@ def test_init(self, loader):
"mix_clustering_c0.30.tsv")

def test_get_gcfs(self, loader):
gcfs = loader.get_gcfs()
gcfs = loader.get_gcfs(keep_mibig_only=True)
assert isinstance(gcfs, list)
assert len(gcfs) == 114
assert isinstance(gcfs[0], GCF)

def test_get_gcfs_without_mibig_only(self, loader):
gcfs = loader.get_gcfs(keep_mibig_only=False)
assert isinstance(gcfs, list)
assert len(gcfs) == 113
assert isinstance(gcfs[0], GCF)

def test_parse_gcf(self, loader):
gcf_dict = BigscapeGCFLoader._parse_gcf(loader.cluster_file) # noqa
gcf_dict = BigscapeGCFLoader._parse_gcf(loader.cluster_file) # noqa
assert isinstance(gcf_dict, dict)
assert len(gcf_dict) == 114
gcf = gcf_dict["135"]
Expand Down

0 comments on commit ae73971

Please sign in to comment.