Skip to content

Commit

Permalink
bugfix: gtf file writing
Browse files Browse the repository at this point in the history
  • Loading branch information
holmrenser committed May 31, 2024
1 parent b26408f commit 57dc20f
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 194 deletions.
15 changes: 6 additions & 9 deletions picea/dag.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Direct Acyclic Graphs"""

from collections import defaultdict
from copy import deepcopy
from typing import Callable, DefaultDict, Dict, Hashable, Iterable, List, Optional
Expand All @@ -9,6 +10,7 @@ class DAGElement:
"""
Element in a DAG, intended to be used as BaseClass
"""

def __init__(
self,
ID: str,
Expand Down Expand Up @@ -100,7 +102,8 @@ def _traverse(


class DirectedAcyclicGraph:
""""Base DAG class"""
"""Base DAG class"""

def __init__(self) -> None:
self._elements: Dict[Hashable, DAGElement] = dict()

Expand Down Expand Up @@ -142,10 +145,7 @@ def add(self, element: DAGElement) -> None:
def pop(self, ID: Hashable) -> DAGElement:
return self._elements.pop(ID)

def groupby(
self,
group_func: Callable[[DAGElement], Hashable]
) -> DefaultDict[Hashable, "DirectedAcyclicGraph"]:
def groupby(self, group_func: Callable[[DAGElement], Hashable]) -> DefaultDict[Hashable, "DirectedAcyclicGraph"]:
"""
Group elements in the current collection by calling 'group_func' and using \
the results as a dictionary key
Expand All @@ -165,10 +165,7 @@ def groupby(
element._container = self
return grouped

def filter(
self,
filter_func: Callable[[DAGElement], bool]
) -> "DirectedAcyclicGraph":
def filter(self, filter_func: Callable[[DAGElement], bool]) -> "DirectedAcyclicGraph":
"""
Filter elements in the current collection based on the output of filter_func
Expand Down
16 changes: 3 additions & 13 deletions picea/ontology.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,19 @@ def __getitem__(self, ID) -> OntologyTerm:
if not term._children and not term._parents and term.__dict__.get("alt_id"):
alt_id = term.__dict__.get("alt_id")[0]
term = self._elements[alt_id]
warnings.warn(
f"Accessed GO term by alt ID {ID}, "
f"returning main GO term with ID {alt_id}"
)
warnings.warn(f"Accessed GO term by alt ID {ID}, " f"returning main GO term with ID {alt_id}")
return term

@classmethod
def from_obo(
cls, filename: str = None, string: str = None, skip_obsolete=True
) -> "Ontology":
def from_obo(cls, filename: str = None, string: str = None, skip_obsolete=True) -> "Ontology":
assert filename or string
assert not (filename and string)
ontology = cls()
if filename:
with open(filename) as filehandle:
string = filehandle.read()

obo_iter = (
el
for _, el in groupby(
string.strip().split("\n"), lambda line: line[:1] == "["
)
)
obo_iter = (el for _, el in groupby(string.strip().split("\n"), lambda line: line[:1] == "["))

ontology._header = list(next(obo_iter))

Expand Down
Loading

0 comments on commit 57dc20f

Please sign in to comment.