sequence
stringlengths
546
16.2k
code
stringlengths
108
19.3k
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:greedy_max_inden_setcover; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:candidate_sets_dict; 5, identifier:items; 6, default_parameter; 6, 7; 6, 8; 7, identifier:max_covers; 8, None; 9, block; 9, 10; 9, 12; 9, 19; 9, 25; 9, 31; 9, 35; 9, 160;...
def greedy_max_inden_setcover(candidate_sets_dict, items, max_covers=None): """ greedy algorithm for maximum independent set cover Covers items with sets from candidate sets. Could be made faster. CommandLine: python -m utool.util_alg --test-greedy_max_inden_setcover Example0: >>>...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:setcover_greedy; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:candidate_sets_dict; 5, default_parameter; 5, 6; 5, 7; 6, identifier:items; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:set_weights; 10, None; 11, defa...
def setcover_greedy(candidate_sets_dict, items=None, set_weights=None, item_values=None, max_weight=None): r""" Greedy algorithm for various covering problems. approximation gaurentees depending on specifications like set_weights and item values Set Cover: log(len(items) + 1) approximation algorithm ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:get_nth_prime; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:n; 5, default_parameter; 5, 6; 5, 7; 6, identifier:max_prime; 7, integer:4100; 8, default_parameter; 8, 9; 8, 10; 9, identifier:safe; 10, True; 11, block; 11, 12; 11, 14; 11, 170; 1...
def get_nth_prime(n, max_prime=4100, safe=True): """ hacky but still brute force algorithm for finding nth prime for small tests """ if n <= 100: first_100_primes = ( 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 10...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:knapsack_ilp; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:items; 5, identifier:maxweight; 6, default_parameter; 6, 7; 6, 8; 7, identifier:verbose; 8, False; 9, block; 9, 10; 9, 12; 9, 15; 9, 16; 9, 26; 9, 36; 9, 46; 9, 47; 9, 59; 9, 60; 9, 8...
def knapsack_ilp(items, maxweight, verbose=False): """ solves knapsack using an integer linear program CommandLine: python -m utool.util_alg knapsack_ilp Example: >>> # DISABLE_DOCTEST >>> from utool.util_alg import * # NOQA >>> import utool as ut >>> # Solve h...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:knapsack_iterative_int; 3, parameters; 3, 4; 3, 5; 4, identifier:items; 5, identifier:maxweight; 6, block; 6, 7; 6, 9; 6, 19; 6, 29; 6, 35; 6, 36; 6, 50; 6, 62; 6, 66; 6, 67; 6, 82; 6, 83; 6, 207; 6, 208; 6, 212; 6, 247; 6, 254; 6, 264; 6, 277;...
def knapsack_iterative_int(items, maxweight): r""" Iterative knapsack method Math: maximize \sum_{i \in T} v_i subject to \sum_{i \in T} w_i \leq W Notes: dpmat is the dynamic programming memoization matrix. dpmat[i, w] is the total value of the items with weight at mos...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:knapsack_iterative_numpy; 3, parameters; 3, 4; 3, 5; 4, identifier:items; 5, identifier:maxweight; 6, block; 6, 7; 6, 9; 6, 10; 6, 19; 6, 27; 6, 28; 6, 42; 6, 48; 6, 49; 6, 63; 6, 71; 6, 80; 6, 86; 6, 103; 6, 123; 6, 127; 6, 142; 6, 240; 6, 244...
def knapsack_iterative_numpy(items, maxweight): """ Iterative knapsack method maximize \sum_{i \in T} v_i subject to \sum_{i \in T} w_i \leq W Notes: dpmat is the dynamic programming memoization matrix. dpmat[i, w] is the total value of the items with weight at most W T is ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:knapsack_greedy; 3, parameters; 3, 4; 3, 5; 4, identifier:items; 5, identifier:maxweight; 6, block; 6, 7; 6, 9; 6, 13; 6, 17; 6, 21; 6, 61; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 1...
def knapsack_greedy(items, maxweight): r""" non-optimal greedy version of knapsack algorithm does not sort input. Sort the input by largest value first if desired. Args: `items` (tuple): is a sequence of tuples `(value, weight, id_)`, where `value` is a scalar and `weight` is a ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:ungroup_gen; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:grouped_items; 5, identifier:groupxs; 6, default_parameter; 6, 7; 6, 8; 7, identifier:fill; 8, None; 9, block; 9, 10; 9, 12; 9, 17; 9, 18; 9, 19; 9, 20; 9, 37; 9, 50; 9, 59; 9, 68; 9, ...
def ungroup_gen(grouped_items, groupxs, fill=None): """ Ungroups items returning a generator. Note that this is much slower than the list version and is not gaurenteed to have better memory usage. Args: grouped_items (list): groupxs (list): maxval (int): (default = None) ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:standardize_boolexpr; 3, parameters; 3, 4; 3, 5; 4, identifier:boolexpr_; 5, default_parameter; 5, 6; 5, 7; 6, identifier:parens; 7, False; 8, block; 8, 9; 8, 11; 8, 16; 8, 19; 8, 23; 8, 34; 8, 45; 8, 56; 8, 67; 8, 78; 8, 96; 8, 108; 8, 117; 8,...
def standardize_boolexpr(boolexpr_, parens=False): r""" Standardizes a boolean expression into an or-ing of and-ed variables Args: boolexpr_ (str): Returns: str: final_expr CommandLine: sudo pip install git+https://github.com/tpircher/quine-mccluskey.git python -m ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:factors; 3, parameters; 3, 4; 4, identifier:n; 5, block; 5, 6; 5, 8; 6, expression_statement; 6, 7; 7, comment; 8, return_statement; 8, 9; 9, call; 9, 10; 9, 11; 10, identifier:set; 11, argument_list; 11, 12; 12, call; 12, 13; 12, 14; 13, ident...
def factors(n): """ Computes all the integer factors of the number `n` Example: >>> # ENABLE_DOCTEST >>> from utool.util_alg import * # NOQA >>> import utool as ut >>> result = sorted(ut.factors(10)) >>> print(result) [1, 2, 5, 10] References: h...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:dict_stack; 3, parameters; 3, 4; 3, 5; 4, identifier:dict_list; 5, default_parameter; 5, 6; 5, 7; 6, identifier:key_prefix; 7, string:''; 8, block; 8, 9; 8, 11; 8, 18; 8, 44; 8, 51; 9, expression_statement; 9, 10; 10, comment; 11, expression_st...
def dict_stack(dict_list, key_prefix=''): r""" stacks values from two dicts into a new dict where the values are list of the input values. the keys are the same. DEPRICATE in favor of dict_stack2 Args: dict_list (list): list of dicts with similar keys Returns: dict dict_stacke...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:invert_dict; 3, parameters; 3, 4; 3, 5; 4, identifier:dict_; 5, default_parameter; 5, 6; 5, 7; 6, identifier:unique_vals; 7, True; 8, block; 8, 9; 8, 11; 8, 59; 9, expression_statement; 9, 10; 10, comment; 11, if_statement; 11, 12; 11, 13; 11, ...
def invert_dict(dict_, unique_vals=True): """ Reverses the keys and values in a dictionary. Set unique_vals to False if the values in the dict are not unique. Args: dict_ (dict_): dictionary unique_vals (bool): if False, inverted keys are returned in a list. Returns: dict: ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:all_dict_combinations_lbls; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:varied_dict; 5, default_parameter; 5, 6; 5, 7; 6, identifier:remove_singles; 7, True; 8, default_parameter; 8, 9; 8, 10; 9, identifier:allow_lone_singles; 10, False; 11...
def all_dict_combinations_lbls(varied_dict, remove_singles=True, allow_lone_singles=False): """ returns a label for each variation in a varydict. It tries to not be oververbose and returns only what parameters are varied in each label. CommandLine: python -m utool.util_dict --test-all_dict...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 2, function_name:update_existing; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 4, identifier:dict1; 5, identifier:dict2; 6, default_parameter; 6, 7; 6, 8; 7, identifier:copy; 8, False; 9, default_parameter; 9, 10; 9, 11; 10, identifier:assert_exists; 1...
def update_existing(dict1, dict2, copy=False, assert_exists=False, iswarning=False, alias_dict=None): r""" updates vals in dict1 using vals from dict2 only if the key is already in dict1. Args: dict1 (dict): dict2 (dict): copy (bool): if true modifies diction...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:groupby_tags; 3, parameters; 3, 4; 3, 5; 4, identifier:item_list; 5, identifier:tags_list; 6, block; 6, 7; 6, 9; 6, 16; 6, 39; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identi...
def groupby_tags(item_list, tags_list): r""" case where an item can belong to multiple groups Args: item_list (list): tags_list (list): Returns: dict: groupid_to_items CommandLine: python -m utool.util_dict --test-groupby_tags Example: >>> # ENABLE_DOC...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:group_items; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:items; 5, default_parameter; 5, 6; 5, 7; 6, identifier:by; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:sorted_; 10, True; 11, block; 11, 12; 11, 14; 11, 80; 11, 81; 11, ...
def group_items(items, by=None, sorted_=True): """ Groups a list of items by group id. Args: items (list): a list of the values to be grouped. if `by` is None, then each item is assumed to be a (groupid, value) pair. by (list): a corresponding list to group items by....
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:hierarchical_map_vals; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:func; 5, identifier:node; 6, default_parameter; 6, 7; 6, 8; 7, identifier:max_depth; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:depth; 11, integer:0; ...
def hierarchical_map_vals(func, node, max_depth=None, depth=0): """ node is a dict tree like structure with leaves of type list TODO: move to util_dict CommandLine: python -m utool.util_dict --exec-hierarchical_map_vals Example: >>> # ENABLE_DOCTEST >>> from utool.util_dic...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:sort_dict; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:dict_; 5, default_parameter; 5, 6; 5, 7; 6, identifier:part; 7, string:'keys'; 8, default_parameter; 8, 9; 8, 10; 9, identifier:key; 10, None; 11, default_parameter; 11, 12; 11, ...
def sort_dict(dict_, part='keys', key=None, reverse=False): """ sorts a dictionary by its values or its keys Args: dict_ (dict_): a dictionary part (str): specifies to sort by keys or values key (Optional[func]): a function that takes specified part and returns a sortab...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:order_dict_by; 3, parameters; 3, 4; 3, 5; 4, identifier:dict_; 5, identifier:key_order; 6, block; 6, 7; 6, 9; 6, 20; 6, 29; 6, 39; 6, 57; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12;...
def order_dict_by(dict_, key_order): r""" Reorders items in a dictionary according to a custom key order Args: dict_ (dict_): a dictionary key_order (list): custom key order Returns: OrderedDict: sorted_dict CommandLine: python -m utool.util_dict --exec-order_dict...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:iteritems_sorted; 3, parameters; 3, 4; 4, identifier:dict_; 5, block; 5, 6; 5, 8; 6, expression_statement; 6, 7; 7, comment; 8, if_statement; 8, 9; 8, 14; 8, 22; 9, call; 9, 10; 9, 11; 10, identifier:isinstance; 11, argument_list; 11, 12; 11, 1...
def iteritems_sorted(dict_): """ change to iteritems ordered """ if isinstance(dict_, OrderedDict): return six.iteritems(dict_) else: return iter(sorted(six.iteritems(dict_)))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:num_fmt; 3, parameters; 3, 4; 3, 5; 4, identifier:num; 5, default_parameter; 5, 6; 5, 7; 6, identifier:max_digits; 7, None; 8, block; 8, 9; 8, 11; 8, 18; 8, 36; 8, 72; 9, expression_statement; 9, 10; 10, comment; 11, if_statement; 11, 12; 11, 1...
def num_fmt(num, max_digits=None): r""" Weird function. Not very well written. Very special case-y Args: num (int or float): max_digits (int): Returns: str: CommandLine: python -m utool.util_num --test-num_fmt Example: >>> # DISABLE_DOCTEST >>>...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 16; 2, function_name:inject_print_functions; 3, parameters; 3, 4; 3, 7; 3, 10; 3, 13; 4, default_parameter; 4, 5; 4, 6; 5, identifier:module_name; 6, None; 7, default_parameter; 7, 8; 7, 9; 8, identifier:module_prefix; 9, string:'[???]'; 10, default_parameter; 10,...
def inject_print_functions(module_name=None, module_prefix='[???]', DEBUG=False, module=None): """ makes print functions to be injected into the module """ module = _get_module(module_name, module) if SILENT: def print(*args): """ silent builtins.print ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:get_isobaric_ratios; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 3, 12; 4, identifier:psmfn; 5, identifier:psmheader; 6, identifier:channels; 7, identifier:denom_channels; 8, identifier:min_int; 9, identifier:targetfn; 10,...
def get_isobaric_ratios(psmfn, psmheader, channels, denom_channels, min_int, targetfn, accessioncol, normalize, normratiofn): """Main function to calculate ratios for PSMs, peptides, proteins, genes. Can do simple ratios, median-of-ratios and median-centering normalization.""" ps...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:clean_line_profile_text; 3, parameters; 3, 4; 4, identifier:text; 5, block; 5, 6; 5, 8; 5, 9; 5, 16; 5, 17; 5, 18; 5, 19; 5, 28; 5, 29; 5, 49; 5, 56; 5, 69; 5, 70; 5, 79; 5, 80; 5, 81; 5, 88; 5, 92; 6, expression_statement; 6, 7; 7, comment; 8,...
def clean_line_profile_text(text): """ Sorts the output from line profile by execution time Removes entries which were not run """ # profile_block_list = parse_rawprofile_blocks(text) #profile_block_list = fix_rawprofile_blocks(profile_block_list) #--- # FIXME can be written much nic...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:random_product; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:items; 5, default_parameter; 5, 6; 5, 7; 6, identifier:num; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:rng; 10, None; 11, block; 11, 12; 11, 14; 11, 19; 11, 29; 11, ...
def random_product(items, num=None, rng=None): """ Yields `num` items from the cartesian product of items in a random order. Args: items (list of sequences): items to get caresian product of packed in a list or tuple. (note this deviates from api of it.product) Example:...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:parse_dsn; 3, parameters; 3, 4; 4, identifier:dsn_string; 5, block; 5, 6; 5, 8; 5, 15; 5, 28; 5, 38; 5, 44; 5, 90; 5, 113; 5, 130; 5, 152; 5, 163; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9...
def parse_dsn(dsn_string): """Parse a connection string and return the associated driver""" dsn = urlparse(dsn_string) scheme = dsn.scheme.split('+')[0] username = password = host = port = None host = dsn.netloc if '@' in host: username, host = host.split('@') if ':' in username:...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 31; 2, function_name:numpy_str; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 3, 29; 4, identifier:arr; 5, default_parameter; 5, 6; 5, 7; 6, identifier:strvals; 7, False; 8, default_parameter; 8, 9; 8, 10; 9, identifier:precision; 10, ...
def numpy_str(arr, strvals=False, precision=None, pr=None, force_dtype=False, with_dtype=None, suppress_small=None, max_line_width=None, threshold=None, **kwargs): """ suppress_small = False turns off scientific representation """ # strvals = kwargs.get('strvals...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:list_str; 3, parameters; 3, 4; 3, 5; 4, identifier:list_; 5, dictionary_splat_pattern; 5, 6; 6, identifier:listkw; 7, block; 7, 8; 7, 10; 7, 15; 7, 31; 7, 41; 7, 51; 7, 60; 7, 69; 7, 78; 7, 94; 7, 104; 7, 105; 7, 115; 7, 119; 7, 128; 7, 136; 7,...
def list_str(list_, **listkw): r""" Makes a pretty list string Args: list_ (list): input list **listkw: nl, newlines, packed, truncate, nobr, nobraces, itemsep, trailing_sep, truncatekw, strvals, recursive, indent_, precision, use_numpy, with_dtype, force...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:horiz_string; 3, parameters; 3, 4; 3, 6; 4, list_splat_pattern; 4, 5; 5, identifier:args; 6, dictionary_splat_pattern; 6, 7; 7, identifier:kwargs; 8, block; 8, 9; 8, 11; 8, 14; 8, 24; 8, 34; 8, 65; 8, 82; 8, 86; 8, 90; 8, 91; 8, 267; 8, 280; 8,...
def horiz_string(*args, **kwargs): """ Horizontally concatenates strings reprs preserving indentation Concats a list of objects ensuring that the next item in the list is all the way to the right of any previous items. Args: *args: list of strings to concat **kwargs: precision, sep...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:get_textdiff; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:text1; 5, identifier:text2; 6, default_parameter; 6, 7; 6, 8; 7, identifier:num_context_lines; 8, integer:0; 9, default_parameter; 9, 10; 9, 11; 10, identifier:ignore_whitespac...
def get_textdiff(text1, text2, num_context_lines=0, ignore_whitespace=False): r""" Uses difflib to return a difference string between two similar texts Args: text1 (str): text2 (str): Returns: str: formatted difference text message SeeAlso: ut.color_diff_text ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 2, function_name:add; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 4, identifier:self; 5, identifier:data; 6, default_parameter; 6, 7; 6, 8; 7, identifier:value; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:timestamp; 11, None; 12, defau...
def add(self, data, value=None, timestamp=None, namespace=None, debug=False): """Queue a gauge or gauges to be written""" if value is not None: return self.add(((data, value),), timestamp=timestamp, namespace=namespace, debug=debug) writer = se...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:generate_psms_quanted; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 11; 4, identifier:quantdb; 5, identifier:tsvfn; 6, identifier:isob_header; 7, identifier:oldheader; 8, default_parameter; 8, 9; 8, 10; 9, identifier:isobaric; 10, False; 11...
def generate_psms_quanted(quantdb, tsvfn, isob_header, oldheader, isobaric=False, precursor=False): """Takes dbfn and connects, gets quants for each line in tsvfn, sorts them in line by using keys in quantheader list.""" allquants, sqlfields = quantdb.select_all_psm_quants(isobaric...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:total_purge_developed_repo; 3, parameters; 3, 4; 4, identifier:repodir; 5, block; 5, 6; 5, 8; 5, 12; 5, 17; 5, 20; 5, 33; 5, 41; 5, 86; 5, 107; 5, 112; 5, 122; 5, 141; 5, 149; 5, 157; 5, 162; 5, 211; 5, 216; 5, 233; 5, 355; 5, 370; 5, 373; 5, 3...
def total_purge_developed_repo(repodir): r""" Outputs commands to help purge a repo Args: repodir (str): path to developed repository CommandLine: python -m utool.util_sysreq total_purge_installed_repo --show Ignore: repodir = ut.truepath('~/code/Lasagne') Example: ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:nx_dag_node_rank; 3, parameters; 3, 4; 3, 5; 4, identifier:graph; 5, default_parameter; 5, 6; 5, 7; 6, identifier:nodes; 7, None; 8, block; 8, 9; 8, 11; 8, 16; 8, 30; 8, 52; 8, 62; 9, expression_statement; 9, 10; 10, comment; 11, import_stateme...
def nx_dag_node_rank(graph, nodes=None): """ Returns rank of nodes that define the "level" each node is on in a topological sort. This is the same as the Graphviz dot rank. Ignore: simple_graph = ut.simplify_graph(exi_graph) adj_dict = ut.nx_to_adj_dict(simple_graph) import plot...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 16; 2, function_name:nx_all_simple_edge_paths; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 3, 13; 4, identifier:G; 5, identifier:source; 6, identifier:target; 7, default_parameter; 7, 8; 7, 9; 8, identifier:cutoff; 9, None; 10, default_parameter; 10, 11; 10, 12;...
def nx_all_simple_edge_paths(G, source, target, cutoff=None, keys=False, data=False): """ Returns each path from source to target as a list of edges. This function is meant to be used with MultiGraphs or MultiDiGraphs. When ``keys`` is True each edge in the path is returned...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:nx_gen_node_attrs; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 14; 3, 17; 4, identifier:G; 5, identifier:key; 6, default_parameter; 6, 7; 6, 8; 7, identifier:nodes; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:default; 11, attribu...
def nx_gen_node_attrs(G, key, nodes=None, default=util_const.NoParam, on_missing='error', on_keyerr='default'): """ Improved generator version of nx.get_node_attributes Args: on_missing (str): Strategy for handling nodes missing from G. Can be {'error', 'default', ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:nx_gen_edge_values; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 14; 3, 17; 4, identifier:G; 5, identifier:key; 6, default_parameter; 6, 7; 6, 8; 7, identifier:edges; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:default; 11, attrib...
def nx_gen_edge_values(G, key, edges=None, default=util_const.NoParam, on_missing='error', on_keyerr='default'): """ Generates attributes values of specific edges Args: on_missing (str): Strategy for handling nodes missing from G. Can be {'error', 'default'}. def...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:nx_gen_edge_attrs; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 14; 3, 17; 4, identifier:G; 5, identifier:key; 6, default_parameter; 6, 7; 6, 8; 7, identifier:edges; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:default; 11, attribu...
def nx_gen_edge_attrs(G, key, edges=None, default=util_const.NoParam, on_missing='error', on_keyerr='default'): """ Improved generator version of nx.get_edge_attributes Args: on_missing (str): Strategy for handling nodes missing from G. Can be {'error', 'default', ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:nx_ensure_agraph_color; 3, parameters; 3, 4; 4, identifier:graph; 5, block; 5, 6; 5, 8; 5, 13; 5, 18; 5, 19; 5, 188; 5, 210; 6, expression_statement; 6, 7; 7, comment; 8, import_from_statement; 8, 9; 8, 11; 9, dotted_name; 9, 10; 10, identifier...
def nx_ensure_agraph_color(graph): """ changes colors to hex strings on graph attrs """ from plottool import color_funcs import plottool as pt #import six def _fix_agraph_color(data): try: orig_color = data.get('color', None) alpha = data.get('alpha', None) ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:simplify_graph; 3, parameters; 3, 4; 4, identifier:graph; 5, block; 5, 6; 5, 8; 5, 13; 5, 27; 5, 36; 5, 70; 5, 80; 5, 129; 5, 135; 5, 141; 5, 148; 5, 155; 6, expression_statement; 6, 7; 7, comment; 8, import_statement; 8, 9; 9, aliased_import; ...
def simplify_graph(graph): """ strips out everything but connectivity Args: graph (nx.Graph): Returns: nx.Graph: new_graph CommandLine: python3 -m utool.util_graph simplify_graph --show python2 -m utool.util_graph simplify_graph --show python2 -c "import n...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:subgraph_from_edges; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:G; 5, identifier:edge_list; 6, default_parameter; 6, 7; 6, 8; 7, identifier:ref_back; 8, True; 9, block; 9, 10; 9, 12; 9, 13; 9, 32; 9, 33; 9, 46; 9, 121; 10, expression_statem...
def subgraph_from_edges(G, edge_list, ref_back=True): """ Creates a networkx graph that is a subgraph of G defined by the list of edges in edge_list. Requires G to be a networkx MultiGraph or MultiDiGraph edge_list is a list of edges in either (u,v) or (u,v,d) form where u and v are nodes compr...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 30; 2, function_name:bfs_conditional; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 3, 24; 3, 27; 4, identifier:G; 5, identifier:source; 6, default_parameter; 6, 7; 6, 8; 7, identifier:reverse; 8, False; 9, default_parameter; 9, 10; 9, 11; 10,...
def bfs_conditional(G, source, reverse=False, keys=True, data=False, yield_nodes=True, yield_if=None, continue_if=None, visited_nodes=None, yield_source=False): """ Produce edges in a breadth-first-search starting at source, but only return nodes t...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:approx_min_num_components; 3, parameters; 3, 4; 3, 5; 4, identifier:nodes; 5, identifier:negative_edges; 6, block; 6, 7; 6, 9; 6, 14; 6, 18; 6, 26; 6, 33; 6, 40; 6, 41; 6, 89; 6, 111; 6, 112; 6, 123; 6, 124; 6, 133; 6, 163; 6, 164; 6, 290; 6, 2...
def approx_min_num_components(nodes, negative_edges): """ Find approximate minimum number of connected components possible Each edge represents that two nodes must be separated This code doesn't solve the problem. The problem is NP-complete and reduces to minimum clique cover (MCC). This is only an...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:generate_proteins; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 12; 4, identifier:pepfn; 5, identifier:proteins; 6, identifier:pepheader; 7, identifier:scorecol; 8, identifier:minlog; 9, default_parameter; 9, 10; 9, 11; 10, identifier...
def generate_proteins(pepfn, proteins, pepheader, scorecol, minlog, higherbetter=True, protcol=False): """Best peptide for each protein in a table""" protein_peptides = {} if minlog: higherbetter = False if not protcol: protcol = peptabledata.HEADER_MASTERPROTEINS ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 29; 2, function_name:grab_file_url; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 4, identifier:file_url; 5, default_parameter; 5, 6; 5, 7; 6, identifier:appname; 7, string:'utool'; 8, default_parameter; 8, 9; 8, 10; 9, identifier:down...
def grab_file_url(file_url, appname='utool', download_dir=None, delay=None, spoof=False, fname=None, verbose=True, redownload=False, check_hash=False): r""" Downloads a file and returns the local path of the file. The resulting file is cached, so multiple calls to this f...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_uniprot_evidence_level; 3, parameters; 3, 4; 4, identifier:header; 5, block; 5, 6; 5, 8; 5, 16; 5, 51; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:header; 11, call; 1...
def get_uniprot_evidence_level(header): """Returns uniprot protein existence evidence level for a fasta header. Evidence levels are 1-5, but we return 5 - x since sorting still demands that higher is better.""" header = header.split() for item in header: item = item.split('=') try: ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_drain; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:cycles; 7, None; 8, block; 8, 9; 8, 11; 8, 18; 8, 29; 8, 59; 8, 418; 9, expression_statement; 9, 10; 10, comment; 11, expression_statement; 1...
def _drain(self, cycles=None): """Activate the pump and let the flow go. This will call the process() method on each attached module until a StopIteration is raised, usually by a pump when it reached the EOF. A StopIteration is also raised when self.cycles was set and the numbe...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:start; 3, parameters; 3, 4; 4, default_parameter; 4, 5; 4, 6; 5, identifier:backdate; 6, None; 7, block; 7, 8; 7, 10; 7, 22; 7, 40; 7, 52; 7, 58; 7, 124; 7, 132; 7, 140; 7, 141; 7, 149; 7, 157; 8, expression_statement; 8, 9; 9, comment; 10, if_...
def start(backdate=None): """ Mark the start of timing, overwriting the automatic start data written on import, or the automatic start at the beginning of a subdivision. Notes: Backdating: For subdivisions only. Backdate time must be in the past but more recent than the latest stamp in...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 26; 2, function_name:stamp; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 4, identifier:name; 5, default_parameter; 5, 6; 5, 7; 6, identifier:backdate; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:unique; 10, None; 11, default_pa...
def stamp(name, backdate=None, unique=None, keep_subdivisions=None, quick_print=None, un=None, ks=None, qp=None): """ Mark the end of a timing interval. Notes: If keeping subdivisions, each subdivision currently awaiting assignment to a stamp (i.e. ended since the last s...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 28; 2, function_name:stop; 3, parameters; 3, 4; 3, 7; 3, 10; 3, 13; 3, 16; 3, 19; 3, 22; 3, 25; 4, default_parameter; 4, 5; 4, 6; 5, identifier:name; 6, None; 7, default_parameter; 7, 8; 7, 9; 8, identifier:backdate; 9, None; 10, default_parameter; 10, 11; 10, 12;...
def stop(name=None, backdate=None, unique=None, keep_subdivisions=None, quick_print=None, un=None, ks=None, qp=None): """ Mark the end of timing. Optionally performs a stamp, hence accepts the same arguments. Notes: If keeping subdivisions and not calling a stamp, any awaitin...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 38; 2, function_name:timed_loop; 3, parameters; 3, 4; 3, 7; 3, 10; 3, 15; 3, 18; 3, 23; 3, 28; 3, 33; 4, default_parameter; 4, 5; 4, 6; 5, identifier:name; 6, None; 7, default_parameter; 7, 8; 7, 9; 8, identifier:rgstr_stamps; 9, None; 10, default_parameter; 10, 1...
def timed_loop(name=None, rgstr_stamps=None, save_itrs=SET['SI'], loop_end_stamp=None, end_stamp_unique=SET['UN'], keep_prev_subdivisions=SET['KS'], keep_end_subdivisions=SET['KS'], quick_print=SET['QP']): """ ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 39; 2, function_name:timed_for; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 16; 3, 19; 3, 24; 3, 29; 3, 34; 4, identifier:iterable; 5, default_parameter; 5, 6; 5, 7; 6, identifier:name; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:rgstr_stamps; 10, Non...
def timed_for(iterable, name=None, rgstr_stamps=None, save_itrs=SET['SI'], loop_end_stamp=None, end_stamp_unique=SET['UN'], keep_prev_subdivisions=SET['KS'], keep_end_subdivisions=SET['KS'], quick_print=SET['...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:format_gmeta; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:data; 5, default_parameter; 5, 6; 5, 7; 6, identifier:acl; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:identifier; 10, None; 11, block; 11, 12; 11, 14; 12, expression_s...
def format_gmeta(data, acl=None, identifier=None): """Format input into GMeta format, suitable for ingesting into Globus Search. Formats a dictionary into a GMetaEntry. Formats a list of GMetaEntry into a GMetaList inside a GMetaIngest. **Example usage**:: glist = [] for document in al...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:insensitive_comparison; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:item1; 5, identifier:item2; 6, default_parameter; 6, 7; 6, 8; 7, identifier:type_insensitive; 8, False; 9, default_parameter; 9, 10; 9, 11; 10, identifier:string_inse...
def insensitive_comparison(item1, item2, type_insensitive=False, string_insensitive=False): """Compare two items without regard to order. The following rules are used to determine equivalence: * Items that are not of the same type can be equivalent only when ``type_insensitive=True``. * Mapping...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:template_to_filepath; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:template; 5, identifier:metadata; 6, default_parameter; 6, 7; 6, 8; 7, identifier:template_patterns; 8, None; 9, block; 9, 10; 9, 12; 9, 19; 9, 28; 9, 35; 9, 292; 10, expressi...
def template_to_filepath(template, metadata, template_patterns=None): """Create directory structure and file name based on metadata template. Note: A template meant to be a base directory for suggested names should have a trailing slash or backslash. Parameters: template (str or ~os.PathLike): A filepath whic...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_get_station_codes; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:force; 7, False; 8, block; 8, 9; 8, 11; 8, 25; 8, 33; 8, 34; 8, 38; 8, 99; 8, 105; 8, 153; 8, 250; 9, expression_statement; 9, 10...
def _get_station_codes(self, force=False): """ Gets and caches a list of station codes optionally within a bbox. Will return the cached version if it exists unless force is True. """ if not force and self.station_codes is not None: return self.station_codes ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_validate_query; 3, parameters; 3, 4; 4, identifier:query; 5, block; 5, 6; 5, 8; 5, 15; 5, 16; 5, 30; 5, 41; 5, 42; 5, 90; 5, 91; 5, 123; 5, 124; 5, 144; 5, 155; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assig...
def _validate_query(query): """Validate and clean up a query to be sent to Search. Cleans the query string, removes unneeded parameters, and validates for correctness. Does not modify the original argument. Raises an Exception on invalid input. Arguments: query (dict): The query to validate...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:show_fields; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:block; 7, None; 8, block; 8, 9; 8, 11; 8, 19; 8, 103; 9, expression_statement; 9, 10; 10, comment; 11, expression_statement; 11, 12; 12,...
def show_fields(self, block=None): """Retrieve and return the mapping for the given metadata block. Arguments: block (str): The top-level field to fetch the mapping for (for example, ``"mdf"``), or the special values ``None`` for everything or ``"top"`` for just the ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:sorted; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:by; 6, dictionary_splat_pattern; 6, 7; 7, identifier:kwargs; 8, block; 8, 9; 8, 11; 8, 24; 9, expression_statement; 9, 10; 10, comment; 11, expression_statement; 11, 12;...
def sorted(self, by, **kwargs): """Sort array by a column. Parameters ========== by: str Name of the columns to sort by(e.g. 'time'). """ sort_idc = np.argsort(self[by], **kwargs) return self.__class__( self[sort_idc], h5loc=se...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:create_multi_output_factor; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:self; 5, identifier:tool; 6, identifier:source; 7, identifier:splitting_node; 8, identifier:sink; 9, block; 9, 10; 9, 12; 9, 35; 9, 56; 9, 57; 9, 58; 9, 79; ...
def create_multi_output_factor(self, tool, source, splitting_node, sink): """ Creates a multi-output factor. This takes a single node, applies a MultiOutputTool to create multiple nodes on a new plate Instantiates a single tool for all of the input plate values, and connects the ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:to_dict; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:tool_long_names; 7, True; 8, block; 8, 9; 8, 11; 8, 29; 8, 84; 8, 220; 8, 231; 9, expression_statement; 9, 10; 10, comment; 11, expression_s...
def to_dict(self, tool_long_names=True): """ Get a representation of the workflow as a dictionary for display purposes :param tool_long_names: Indicates whether to use long names, such as SplitterFromStream(element=None, use_mapping_keys_only=True) ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:GenericPump; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:filenames; 5, default_parameter; 5, 6; 5, 7; 6, identifier:use_jppy; 7, False; 8, default_parameter; 8, 9; 8, 10; 9, identifier:name; 10, string:"GenericPump"; 11, dictionary_s...
def GenericPump(filenames, use_jppy=False, name="GenericPump", **kwargs): """A generic pump which utilises the appropriate pump.""" if isinstance(filenames, str): filenames = [filenames] try: iter(filenames) except TypeError: log.critical("Don't know how to iterate through filen...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:get_sources; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:plate; 6, identifier:plate_value; 7, default_parameter; 7, 8; 7, 9; 8, identifier:sources; 9, None; 10, block; 10, 11; 10, 13; 10, 22; 10, 89; 10, 127; 10, 1...
def get_sources(self, plate, plate_value, sources=None): """ Gets the source streams for a given plate value on a plate. Also populates with source streams that are valid for the parent plates of this plate, with the appropriate meta-data for the parent plate. :param plate: The ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:get_splitting_stream; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:input_plate_value; 6, block; 6, 7; 6, 9; 6, 17; 6, 38; 6, 62; 6, 63; 6, 85; 6, 95; 6, 262; 7, expression_statement; 7, 8; 8, comment; 9, if_statement; 9, 10; 9, ...
def get_splitting_stream(self, input_plate_value): """ Get the splitting stream :param input_plate_value: The input plate value :return: The splitting stream """ if not self.splitting_node: return None if len(self.splitting_node.plates) == 0: ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 16; 2, function_name:iter_cognates; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:dataset; 5, default_parameter; 5, 6; 5, 7; 6, identifier:column; 7, string:'Segments'; 8, default_parameter; 8, 9; 8, 10; 9, identifier:method; 10, string:'turchin'; 1...
def iter_cognates(dataset, column='Segments', method='turchin', threshold=0.5, **kw): """ Compute cognates automatically for a given dataset. """ if method == 'turchin': for row in dataset.objects['FormTable']: sounds = ''.join(lingpy.tokens2class(row[column], 'dolgo')) i...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:get_tool_class; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:tool; 6, block; 6, 7; 6, 9; 6, 41; 6, 45; 6, 46; 6, 110; 6, 120; 6, 121; 6, 129; 6, 139; 7, expression_statement; 7, 8; 8, comment; 9, if_statement; 9, 10; 9, 15; 9, 2...
def get_tool_class(self, tool): """ Gets the actual class which can then be instantiated with its parameters :param tool: The tool name or id :type tool: str | unicode | StreamId :rtype: Tool | MultiOutputTool :return: The tool class """ if isinstance(too...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:pmt_angles; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 47; 6, expression_statement; 6, 7; 7, comment; 8, if_statement; 8, 9; 8, 14; 9, comparison_operator:==; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:se...
def pmt_angles(self): """A list of PMT directions sorted by PMT channel, on DU-1, floor-1""" if self._pmt_angles == []: mask = (self.pmts.du == 1) & (self.pmts.floor == 1) self._pmt_angles = self.pmts.dir[mask] return self._pmt_angles
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_get_point; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:profile; 6, identifier:point; 7, block; 7, 8; 7, 10; 7, 24; 8, expression_statement; 8, 9; 9, comment; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, ...
def _get_point(self, profile, point): """ Finds the given point in the profile, or adds it in sorted z order. """ cur_points_z = [p.location.z for p in profile.elements] try: cur_idx = cur_points_z.index(point.z) return profile.elements[cur_idx] ex...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:metadata_sorter; 3, parameters; 3, 4; 3, 5; 4, identifier:x; 5, identifier:y; 6, block; 6, 7; 6, 9; 6, 16; 7, expression_statement; 7, 8; 8, comment; 9, if_statement; 9, 10; 9, 13; 10, comparison_operator:==; 10, 11; 10, 12; 11, identifier:x; 1...
def metadata_sorter(x, y): """ Sort metadata keys by priority. """ if x == y: return 0 if x in METADATA_SORTER_FIRST and y in METADATA_SORTER_FIRST: return -1 if METADATA_SORTER_FIRST.index(x) < METADATA_SORTER_FIRST.index(y) else 1 elif x in METADATA_SORTER_FIRST: return -1 ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:computeStrongestPaths; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:profile; 6, identifier:pairwisePreferences; 7, block; 7, 8; 7, 10; 7, 20; 7, 27; 7, 28; 7, 34; 7, 46; 7, 108; 7, 184; 8, expression_statement; 8, 9; 9, co...
def computeStrongestPaths(self, profile, pairwisePreferences): """ Returns a two-dimensional dictionary that associates every pair of candidates, cand1 and cand2, with the strongest path from cand1 to cand2. :ivar Profile profile: A Profile object that represents an election profile. ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:computePairwisePreferences; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:profile; 6, block; 6, 7; 6, 9; 6, 19; 6, 20; 6, 26; 6, 38; 6, 59; 6, 188; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, as...
def computePairwisePreferences(self, profile): """ Returns a two-dimensional dictionary that associates every pair of candidates, cand1 and cand2, with number of voters who prefer cand1 to cand2. :ivar Profile profile: A Profile object that represents an election profile. """ ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:STVsocwinners; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:profile; 6, block; 6, 7; 6, 9; 6, 17; 6, 25; 6, 31; 6, 66; 6, 80; 6, 87; 6, 93; 6, 94; 6, 100; 6, 101; 6, 110; 6, 114; 6, 121; 6, 274; 7, expression_statement; 7, 8; 8,...
def STVsocwinners(self, profile): """ Returns an integer list that represents all possible winners of a profile under STV rule. :ivar Profile profile: A Profile object that represents an election profile. """ ordering = profile.getOrderVectors() prefcounts = profile.getP...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:baldwinsoc_winners; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:profile; 6, block; 6, 7; 6, 9; 6, 17; 6, 23; 6, 31; 6, 66; 6, 80; 6, 86; 6, 87; 6, 93; 6, 94; 6, 103; 6, 107; 6, 114; 6, 295; 7, expression_statement; 7, 8; 8, com...
def baldwinsoc_winners(self, profile): """ Returns an integer list that represents all possible winners of a profile under baldwin rule. :ivar Profile profile: A Profile object that represents an election profile. """ ordering = profile.getOrderVectors() m = profile.numC...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:getWmg2; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:self; 5, identifier:prefcounts; 6, identifier:ordering; 7, identifier:state; 8, default_parameter; 8, 9; 8, 10; 9, identifier:normalize; 10, False; 11, block; 11, 12; 11, 14; ...
def getWmg2(self, prefcounts, ordering, state, normalize=False): """ Generate a weighted majority graph that represents the whole profile. The function will return a two-dimensional dictionary that associates integer representations of each pair of candidates, cand1 and cand2, with the n...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:PluRunOff_cowinners; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:profile; 6, block; 6, 7; 6, 9; 6, 10; 6, 11; 6, 19; 6, 41; 6, 42; 6, 50; 6, 57; 6, 65; 6, 76; 6, 82; 6, 83; 6, 87; 6, 186; 6, 187; 6, 313; 7, expression_statement...
def PluRunOff_cowinners(self, profile): """ Returns a list that associates all the winners of a profile under Plurality with Runoff rule. :ivar Profile profile: A Profile object that represents an election profile. """ # Currently, we expect the profile to contain complete orde...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:_cache_offsets; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:up_to_index; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:verbose; 10, True; 11, block; 11, 12; 11, 14; 11, 76; 1...
def _cache_offsets(self, up_to_index=None, verbose=True): """Cache all event offsets.""" if not up_to_index: if verbose: self.print("Caching event file offsets, this may take a bit.") self.blob_file.seek(0, 0) self.event_offsets = [] if not...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:getUtilities; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:decision; 6, identifier:binaryRelations; 7, block; 7, 8; 7, 10; 7, 17; 7, 21; 7, 136; 8, expression_statement; 8, 9; 9, comment; 10, expression_statement; 10, 11; ...
def getUtilities(self, decision, binaryRelations): """ Returns a floats that contains the utilities of every candidate in the decision. This was adapted from code written by Lirong Xia. :ivar list<int> decision: Contains a list of integer representations of candidates in the ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:execute; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:self; 5, identifier:sources; 6, identifier:sink; 7, identifier:interval; 8, default_parameter; 8, 9; 8, 10; 9, identifier:alignment_stream; 10, None; 11, block; 11, 12; 11, 14...
def execute(self, sources, sink, interval, alignment_stream=None): """ Execute the tool over the given time interval. If an alignment stream is given, the output instances will be aligned to this stream :param sources: The source streams (possibly None) :param sink: The sink str...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:upload_runsummary; 3, parameters; 3, 4; 3, 5; 4, identifier:csv_filename; 5, default_parameter; 5, 6; 5, 7; 6, identifier:dryrun; 7, False; 8, block; 8, 9; 8, 11; 8, 21; 8, 45; 8, 77; 8, 86; 8, 121; 8, 127; 8, 143; 8, 159; 8, 180; 8, 185; 8, 20...
def upload_runsummary(csv_filename, dryrun=False): """Reads the CSV file and uploads its contents to the runsummary table""" print("Checking '{}' for consistency.".format(csv_filename)) if not os.path.exists(csv_filename): log.critical("{} -> file not found.".format(csv_filename)) return ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_movie; 3, parameters; 3, 4; 4, identifier:tmdb_id; 5, block; 5, 6; 5, 8; 5, 14; 5, 23; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:redis_key; 11, binary_operator:%; 1...
def get_movie(tmdb_id): """ Get informations about a movie using its tmdb id. """ redis_key = 'm_%s' % tmdb_id cached = redis_ro_conn.get(redis_key) if cached: return Response(cached) else: try: details = get_on_tmdb(u'/movie/%d' % tmdb_id) cast = get_on_t...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:parse_pattern; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:format_string; 5, identifier:env; 6, default_parameter; 6, 7; 6, 8; 7, identifier:wrapper; 8, lambda; 8, 9; 8, 12; 9, lambda_parameters; 9, 10; 9, 11; 10, identifier:x; 11, identifi...
def parse_pattern(format_string, env, wrapper=lambda x, y: y): """ Parse the format_string and return prepared data according to the env. Pick each field found in the format_string from the env(ironment), apply the wrapper on each data and return a mapping between field-to-replace and values for each. ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 26; 2, function_name:calibrate_dom; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 3, 13; 3, 16; 3, 19; 3, 22; 4, identifier:dom_id; 5, identifier:data; 6, identifier:detector; 7, default_parameter; 7, 8; 7, 9; 8, identifier:livetime; 9, None; 10, default_parameter...
def calibrate_dom( dom_id, data, detector, livetime=None, fit_ang_dist=False, scale_mc_to_data=True, ad_fit_shape='pexp', fit_background=True, ctmin=-1. ): """Calibrate intra DOM PMT time offsets, efficiencies and sigmas Parameters ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:analyze; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:segments; 5, identifier:analysis; 6, default_parameter; 6, 7; 6, 8; 7, identifier:lookup; 8, call; 8, 9; 8, 10; 9, identifier:dict; 10, argument_list; 10, 11; 10, 14; 11, keyword_argument...
def analyze(segments, analysis, lookup=dict(bipa={}, dolgo={})): """ Test a sequence for compatibility with CLPA and LingPy. :param analysis: Pass a `TranscriptionAnalysis` instance for cumulative reporting. """ # raise a ValueError in case of empty segments/strings if not segments: rai...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:setup_limits; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:conf_file; 5, identifier:limits_file; 6, default_parameter; 6, 7; 6, 8; 7, identifier:do_reload; 8, True; 9, default_parameter; 9, 10; 9, 11; 10, identifier:dry_run; 11,...
def setup_limits(conf_file, limits_file, do_reload=True, dry_run=False, debug=False): """ Set up or update limits in the Redis database. :param conf_file: Name of the configuration file, for connecting to the Redis database. :param limits_file: Name of the XML fil...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:make_limit_node; 3, parameters; 3, 4; 3, 5; 4, identifier:root; 5, identifier:limit; 6, block; 6, 7; 6, 9; 6, 10; 6, 26; 6, 27; 7, expression_statement; 7, 8; 8, comment; 9, comment; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11,...
def make_limit_node(root, limit): """ Given a Limit object, generate an XML node. :param root: The root node of the XML tree being built. :param limit: The Limit object to serialize to XML. """ # Build the base limit node limit_node = etree.SubElement(root, 'limit', ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:turnstile_command; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:conf_file; 5, identifier:command; 6, default_parameter; 6, 7; 6, 8; 7, identifier:arguments; 8, list:[]; 9, default_parameter; 9, 10; 9, 11; 10, identifier:channel;...
def turnstile_command(conf_file, command, arguments=[], channel=None, debug=False): """ Issue a command to all running control daemons. :param conf_file: Name of the configuration file. :param command: The command to execute. Note that 'ping' is handled specia...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 1, 6; 2, function_name:humanize_timesince; 3, parameters; 3, 4; 4, identifier:start_time; 5, comment; 6, block; 6, 7; 6, 9; 6, 15; 6, 23; 6, 24; 6, 25; 6, 36; 6, 44; 6, 67; 6, 75; 6, 98; 6, 104; 6, 127; 6, 135; 6, 158; 6, 166; 6, 189; 7, expression_statement; 7...
def humanize_timesince(start_time): # pylint:disable=too-many-return-statements """Creates a string representation of time since the given `start_time`.""" if not start_time: return start_time delta = local_now() - start_time # assumption: negative delta values originate from clock # ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:fire; 3, parameters; 3, 4; 3, 5; 3, 7; 4, identifier:self; 5, list_splat_pattern; 5, 6; 6, identifier:args; 7, dictionary_splat_pattern; 7, 8; 8, identifier:kw; 9, block; 9, 10; 9, 12; 9, 16; 9, 29; 9, 359; 10, expression_statement; 10, 11; 11,...
def fire(self, *args, **kw): """ Stores all registered handlers in a queue for processing """ result = [] with self._hlock: handlers = self.handlers if self.threads == 0: # same-thread execution - synchronized for k in handlers: # handl...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 2, function_name:runGetResults; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:cmd; 5, default_parameter; 5, 6; 5, 7; 6, identifier:stdout; 7, True; 8, default_parameter; 8, 9; 8, 10; 9, identifier:stderr; 10, True; 11, default_parameter; 11, 12; 11, 13...
def runGetResults(cmd, stdout=True, stderr=True, encoding=sys.getdefaultencoding()): ''' runGetResults - Simple method to run a command and return the results of the execution as a dict. @param cmd <str/list> - String of command and arguments, or list of command and arguments ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_pathway_feature_permutation; 3, parameters; 3, 4; 3, 5; 4, identifier:pathway_feature_tuples; 5, identifier:permutation_max_iters; 6, block; 6, 7; 6, 9; 6, 26; 6, 33; 6, 40; 6, 44; 6, 48; 6, 262; 6, 269; 7, expression_statement; 7, 8; 8, comme...
def _pathway_feature_permutation(pathway_feature_tuples, permutation_max_iters): """Permute the pathways across features for one side in the network. Used in `permute_pathways_across_features` Parameters ----------- pathway_feature_tuples : list(tup(str, int)) ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:get_field_infos; 3, parameters; 3, 4; 3, 5; 4, identifier:code; 5, identifier:free_format; 6, block; 6, 7; 6, 9; 6, 13; 6, 17; 6, 24; 6, 28; 6, 199; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, ...
def get_field_infos(code, free_format): """ Gets the list of pic fields information from line |start| to line |end|. :param code: code to parse :returns: the list of pic fields info found in the specified text. """ offset = 0 field_infos = [] lines = _clean_code(code) previous_off...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_advanced_acronym_detection; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:s; 5, identifier:i; 6, identifier:words; 7, identifier:acronyms; 8, block; 8, 9; 8, 11; 8, 12; 8, 26; 8, 27; 8, 31; 8, 32; 8, 45; 8, 46; 8, 161; 8, 162; 8, 177; 8...
def _advanced_acronym_detection(s, i, words, acronyms): """ Detect acronyms by checking against a list of acronyms. Check a run of words represented by the range [s, i]. Return last index of new word groups. """ # Combine each letter into single string. acstr = ''.join(words[s:i]) # Li...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_separate_words; 3, parameters; 3, 4; 4, identifier:string; 5, block; 5, 6; 5, 8; 5, 12; 5, 16; 5, 17; 5, 18; 5, 22; 5, 23; 5, 27; 5, 28; 5, 37; 5, 38; 5, 39; 5, 43; 5, 62; 5, 63; 5, 64; 5, 222; 6, expression_statement; 6, 7; 7, comment; 8, exp...
def _separate_words(string): """ Segment string on separator into list of words. Arguments: string -- the string we want to process Returns: words -- list of words the string got minced to separator -- the separator char intersecting words was_upper -- whether string ha...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:parse_case; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:string; 5, default_parameter; 5, 6; 5, 7; 6, identifier:acronyms; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:preserve_case; 10, False; 11, block; 11, 12; 11, 14; 11, 24;...
def parse_case(string, acronyms=None, preserve_case=False): """ Parse a stringiable into a list of words. Also returns the case type, which can be one of the following: - upper: All words are upper-case. - lower: All words are lower-case. - pascal: All words are title-case or upper-...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:listen; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 9; 5, 10; 5, 11; 5, 22; 5, 23; 5, 27; 5, 48; 5, 58; 5, 59; 5, 73; 5, 80; 5, 81; 6, expression_statement; 6, 7; 7, comment; 8, comment; 9, comment; 10, comment; 11, expres...
def listen(self): """ Listen for incoming control messages. If the 'redis.shard_hint' configuration is set, its value will be passed to the pubsub() method when setting up the subscription. The control channel to subscribe to is specified by the 'redis.control_channel' ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:initialize; 3, parameters; 3, 4; 4, identifier:config; 5, block; 5, 6; 5, 8; 5, 9; 5, 37; 5, 38; 5, 42; 5, 68; 5, 69; 5, 85; 5, 86; 5, 90; 5, 94; 5, 98; 5, 205; 5, 214; 5, 215; 5, 235; 5, 236; 5, 237; 5, 321; 5, 322; 5, 329; 6, expression_state...
def initialize(config): """ Initialize a connection to the Redis database. """ # Determine the client class to use if 'redis_client' in config: client = utils.find_entrypoint('turnstile.redis_client', config['redis_client'], required=True) else: ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:read_attributes; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:attributes; 7, None; 8, block; 8, 9; 8, 11; 8, 24; 8, 32; 8, 41; 8, 68; 8, 69; 8, 149; 8, 150; 8, 157; 8, 169; 8, 170; 8, 208; 9, ex...
def read_attributes(self, attributes=None): ''' Collect read attributes across reads in this PileupCollection into a pandas.DataFrame. Valid attributes are the following properties of a pysam.AlignedSegment instance. See: http://pysam.readthedocs.org/en/latest/api.ht...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:group_by_allele; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:locus; 6, block; 6, 7; 6, 9; 6, 16; 6, 20; 6, 24; 6, 172; 6, 188; 6, 264; 6, 265; 6, 266; 6, 288; 7, expression_statement; 7, 8; 8, string:''' Split the Pileu...
def group_by_allele(self, locus): ''' Split the PileupCollection by the alleles suggested by the reads at the specified locus. If a read has an insertion immediately following the locus, then the insertion is included in the allele. For example, if locus is the 1-base ra...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:from_bam; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:pysam_samfile; 5, identifier:loci; 6, default_parameter; 6, 7; 6, 8; 7, identifier:normalized_contig_names; 8, True; 9, block; 9, 10; 9, 12; 9, 23; 9, 27; 9, 46; 10, expression_statement;...
def from_bam(pysam_samfile, loci, normalized_contig_names=True): ''' Create a PileupCollection for a set of loci from a BAM file. Parameters ---------- pysam_samfile : `pysam.Samfile` instance, or filename string to a BAM file. The BAM file must be indexed. ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:check_recommended_global_attributes; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:dataset; 6, block; 6, 7; 6, 9; 6, 19; 6, 35; 6, 44; 6, 54; 6, 66; 6, 89; 6, 90; 6, 140; 6, 149; 6, 170; 6, 171; 6, 191; 6, 199; 6, 208; 6, 217; 6,...
def check_recommended_global_attributes(self, dataset): ''' Check the global recommended attributes for 2.0 templates. These go an extra step besides just checking that they exist. :param netCDF4.Dataset dataset: An open netCDF dataset :id = "" ; //................................