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

Slow odgi depth no paths #149

Merged
merged 3 commits into from
Dec 3, 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
9 changes: 5 additions & 4 deletions slow_odgi/slow_odgi/__main__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import argparse
import sys
import io
from typing import Dict, Tuple, List
from typing import Dict, Tuple, List, Optional
from collections.abc import Callable
from mygfa import mygfa

Expand Down Expand Up @@ -58,9 +58,8 @@ def parse_args() -> Tuple[argparse.ArgumentParser, argparse.Namespace]:
)
depth_parser.add_argument(
"--paths",
nargs="?",
help="A file describing the paths you wish to query.",
required=True,
required=False,
)

subparsers.add_parser(
Expand Down Expand Up @@ -167,7 +166,9 @@ def dispatch(args: argparse.Namespace) -> None:
# Other functions, which typically print their own output.
other_funcs: Dict[str, Callable[[mygfa.Graph], object]] = {
"degree": degree.degree,
"depth": lambda g: depth.depth(g, parse_paths(args.paths)),
"depth": lambda g: depth.depth(
g, parse_paths(args.paths) if args.paths else None
),
"flatten": lambda g: flatten.flatten(g, f"{args.graph[:-4]}.og"),
"matrix": matrix.matrix,
"overlap": lambda g: overlap.overlap(g, parse_paths(args.paths)),
Expand Down
6 changes: 3 additions & 3 deletions slow_odgi/slow_odgi/depth.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from typing import List
from typing import List, Optional
from mygfa import mygfa, preprocess


def depth(graph: mygfa.Graph, inputpaths: List[str]) -> mygfa.Graph:
def depth(graph: mygfa.Graph, inputpaths: Optional[List[str]]) -> mygfa.Graph:
"""The depth of a node is the cardinality of node_step for that node."""
print("\t".join(["#node.id", "depth", "depth.uniq"]))
for seg, crossings in preprocess.node_steps(graph).items():
# Each crossing is a (path name, index on path, direction) tuple.
# We only want to count crossings that are on input paths.
crossings = [c for c in crossings if c[0] in inputpaths]
crossings = [c for c in crossings if inputpaths is None or c[0] in inputpaths]
# For depth.uniq, we need to know how many unique path-names there are.
uniq_path_names = set(c[0] for c in crossings)
print("\t".join([seg, str(len(crossings)), str(len(uniq_path_names))]))
Expand Down
2 changes: 1 addition & 1 deletion slow_odgi/slow_odgi/overlap.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List
from typing import List, Optional
from mygfa import mygfa, preprocess


Expand Down
Loading