Skip to content

Commit

Permalink
Move circulation functions to utils
Browse files Browse the repository at this point in the history
They will also be used by the meta path algorithms too
  • Loading branch information
cthoyt committed Aug 10, 2017
1 parent d443e3d commit bc95414
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
21 changes: 0 additions & 21 deletions src/pybel_tools/analysis/stability.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,24 +366,3 @@ def get_dampened_triplets(graph):
:rtype: iter[tuple]
"""
return _get_disregulated_triplets_helper(graph, CAUSAL_DECREASE_RELATIONS)


def get_circulations(t):
"""Iterate over all possible circulations of an ordered collection (tuple or list)
:param tuple or list t:
:rtype: iter
"""
for i in range(len(t)):
yield t[i:] + t[:i]


def canonical_circulation(t, key=None):
"""Get get a canonical representation of the ordered collection by finding its minimum circulation with the
given sort key
:param tuple or list t:
:param key: A function for sort
:return: The
"""
return min(get_circulations(t), key=key)
27 changes: 24 additions & 3 deletions src/pybel_tools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
import itertools as itt
import json
import logging
import os
import time
from collections import Counter, defaultdict
from itertools import zip_longest
from operator import itemgetter

import jinja2
import networkx as nx
import os
import pandas as pd
from collections import Counter, defaultdict
from operator import itemgetter
from pkg_resources import get_distribution

from pybel.constants import (
Expand Down Expand Up @@ -472,3 +472,24 @@ def hash_str_to_int(hash_str, length=16):
:rtype: int
"""
return int(hash_str, 16) % (10 ** length)


def get_circulations(t):
"""Iterate over all possible circulations of an ordered collection (tuple or list)
:param tuple or list t:
:rtype: iter
"""
for i in range(len(t)):
yield t[i:] + t[:i]


def canonical_circulation(t, key=None):
"""Get get a canonical representation of the ordered collection by finding its minimum circulation with the
given sort key
:param tuple or list t:
:param key: A function for sort
:return: The
"""
return min(get_circulations(t), key=key)

0 comments on commit bc95414

Please sign in to comment.