From bc954144d1e02a98e0e243e6b0525b24d9d7ff88 Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Thu, 10 Aug 2017 19:50:45 +0200 Subject: [PATCH] Move circulation functions to utils They will also be used by the meta path algorithms too --- src/pybel_tools/analysis/stability.py | 21 --------------------- src/pybel_tools/utils.py | 27 ++++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/pybel_tools/analysis/stability.py b/src/pybel_tools/analysis/stability.py index b29fd3f2..16dd58ff 100644 --- a/src/pybel_tools/analysis/stability.py +++ b/src/pybel_tools/analysis/stability.py @@ -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) diff --git a/src/pybel_tools/utils.py b/src/pybel_tools/utils.py index ad06e75d..45b65179 100644 --- a/src/pybel_tools/utils.py +++ b/src/pybel_tools/utils.py @@ -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 ( @@ -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)