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

Speed up spot reading #302

Merged
merged 4 commits into from
Nov 26, 2024
Merged
Changes from 3 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
23 changes: 13 additions & 10 deletions ppanggolin/formats/readBinaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -979,28 +979,32 @@ def read_rgp(pangenome: Pangenome, h5f: tables.File, disable_bar: bool = False):

def read_spots(pangenome: Pangenome, h5f: tables.File, disable_bar: bool = False):
"""
Read hotspot in pangenome hdf5 file to add in pangenome object
Read hotspots in the pangenome HDF5 file and add them to the pangenome object.

:param pangenome: Pangenome object without spot
:param h5f: Pangenome HDF5 file with spot computed
:param disable_bar: Disable the progress bar
Args:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we changing format in the comment lines?

pangenome (Pangenome): Pangenome object.
h5f (tables.File): Pangenome HDF5 file with spots computed.
disable_bar (bool): Whether to disable the progress bar.
"""
table = h5f.root.spots
spots = {}
curr_spot_id = None
for row in tqdm(
read_chunks(table, chunk=20000),
total=table.nrows,
unit="spot",
disable=disable_bar,
):
curr_spot = spots.get(int(row["spot"]))
if curr_spot is None:
curr_spot = Spot(int(row["spot"]))
spots[row["spot"]] = curr_spot
if curr_spot_id != int(row["spot"]):
curr_spot_id = int(row["spot"])
curr_spot = spots.get(curr_spot_id)
if curr_spot is None:
curr_spot = Spot(int(row["spot"]))
spots[row["spot"]] = curr_spot
region = pangenome.get_region(row["RGP"].decode())
curr_spot.add(region)
curr_spot.spot_2_families()
for spot in spots.values():
spot.spot_2_families()
pangenome.add_spot(spot)
pangenome.status["spots"] = "Loaded"

Expand Down Expand Up @@ -1548,7 +1552,6 @@ def read_pangenome(
f"The pangenome in file '{filename}' does not have spots information, "
f"or has been improperly filled"
)

if modules:
if h5f.root.status._v_attrs.modules:
logging.getLogger("PPanGGOLiN").info("Reading the modules...")
Expand Down
Loading