Skip to content

Commit

Permalink
⚡️ Adding low-memory profile for graph loading
Browse files Browse the repository at this point in the history
  • Loading branch information
dubssieg committed Jan 15, 2024
1 parent 1a56851 commit c31bed0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
16 changes: 11 additions & 5 deletions pgGraphs/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ class Graph():
'metadata'
]

def __init__(self, gfa_file: str | None = None, with_sequence: bool = True) -> None:
def __init__(
self,
gfa_file: str | None = None,
with_sequence: bool = True,
low_memory: bool = False
) -> None:
"""Constructor for GFA Graph object.
Args:
Expand All @@ -29,8 +34,8 @@ def __init__(self, gfa_file: str | None = None, with_sequence: bool = True) -> N
"""
# Declaring format attributes, generators...
self.metadata: dict = {
'version': GFAParser.get_gfa_format(gfa_file_path=gfa_file) if gfa_file else 'unknown',
'next_node_name': (x for x in count(start=1) if str(x) not in self.segments)
'version': GFAParser.get_gfa_format(gfa_file_path=gfa_file) if gfa_file and not low_memory else 'unknown',
'next_node_name': (x for x in count(start=1) if str(x) not in self.segments) if not low_memory else 'unknown'
}
self.segments: dict[str, dict] = {}
self.lines: dict[tuple[str, str], dict] = {}
Expand All @@ -49,7 +54,7 @@ def __init__(self, gfa_file: str | None = None, with_sequence: bool = True) -> N

name, line_type, datas = GFAParser.read_gfa_line(
[__.strip() for __ in gfa_line.split('\t')],
with_sequence
with_sequence and not low_memory
)
match line_type:
case GFALine.SEGMENT:
Expand Down Expand Up @@ -87,6 +92,7 @@ def unfold(
"""Applies an unfolding on cycles, that allows them to be linearized
WARNING: May solely be used on graphs with paths.
WARNING: Not fully tested yet, use at your own discretion.
TODO: fix closing edge of cycle not destroyed.
"""
if len(self.paths) == 0:
raise NotImplementedError(
Expand Down Expand Up @@ -118,7 +124,7 @@ def unfold(
ori_sink=oriT
)
except:
# Will happen if loop at first position in the graph (that would not happen normally)
# Will happen if loop at first position in the graph (that would not happen normally, right?)
pass
finally:
iters += 1
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[project]
name = "gfagraphs"
version = "0.2.18"
version = "0.2.19"
authors = [
{ name="Siegfried Dubois", email="siegfried.dubois@inria.fr" },
]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
DESCRIPTION: str = "Library to parse, edit and handle in memory GFA graphs"
REQUIRED_PYTHON: tuple = (3, 10)
OVERRIDE_VN: bool = True
VN: str = "0.2.19"
VN: str = "0.2.20"
URL: str = "https://github.com/Tharos-ux/gfagraphs"
REQUIREMENTS: list[str] = ['networkx', 'tharos-pytools']

Expand Down

0 comments on commit c31bed0

Please sign in to comment.