Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: now creating a hub_plasmids.csv file when running the plasnet type command explicitly listing each hub plasmid #53

Merged
merged 1 commit into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion plasnet/hub_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,17 @@ def _get_hub_plasmids(self, use_cached: bool = False) -> list[str]:

return self._hub_plasmids

def remove_hub_plasmids(self) -> None:
def remove_hub_plasmids(self) -> set[str]:
all_hub_plasmids = set()
while True:
hub_plasmids = self._get_hub_plasmids()
all_hub_plasmids.update(hub_plasmids)
there_are_still_hub_plasmids = len(hub_plasmids) > 0
if there_are_still_hub_plasmids:
self.remove_nodes_from(hub_plasmids)
else:
break
return all_hub_plasmids

def _get_filters_HTML(self) -> str:
nb_of_hubs = len(self._get_hub_plasmids(use_cached=True))
Expand Down
8 changes: 7 additions & 1 deletion plasnet/plasnet_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,10 @@ def type(

logging.info("Typing communities (i.e. splitting them into subcommunities)")
all_subcommunities = Subcommunities()
all_hub_plasmids = set()
for community in communities:
community.remove_hub_plasmids()
hub_plasmids = community.remove_hub_plasmids()
all_hub_plasmids.update(hub_plasmids)
subcommunities = community.split_graph_into_subcommunities(
small_subcommunity_size_threshold
)
Expand All @@ -229,6 +231,10 @@ def type(
original_communities.save(objects_dir / "communities.pkl")
all_subcommunities.save(objects_dir / "subcommunities.pkl")
all_subcommunities.save_classification(objects_dir / "typing.tsv", "plasmid\ttype")
with open(objects_dir / "hub_plasmids.csv", "w") as hub_plasmids_fh:
print("hub_plasmids", file=hub_plasmids_fh)
for plasmid in all_hub_plasmids:
print(plasmid, file=hub_plasmids_fh)

logging.info("All done!")

Expand Down
4 changes: 4 additions & 0 deletions tests/data/hub/hub_plasmids.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
hub_plasmids
pKPC_CAV1320
pCAV1492-6393
pCAV1374-6538
8 changes: 8 additions & 0 deletions tests/test_integration_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,11 @@ def test_remove_hub_plasmids_iteratively(self) -> None:
sort=True,
)
)

self.assertTrue(
check_if_files_are_equal(
Path("tests/data/hub/out/type_out/objects/hub_plasmids.csv"),
Path("tests/data/hub/hub_plasmids.csv"),
sort=True,
)
)