sequence
stringlengths
492
15.9k
code
stringlengths
75
8.58k
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, 17; 9, 23; 9, 29; 9, 33; 9, 152; 9, 159...
def greedy_max_inden_setcover(candidate_sets_dict, items, max_covers=None): uncovered_set = set(items) rejected_keys = set() accepted_keys = set() covered_items_list = [] while True: if max_covers is not None and len(covered_items_list) >= max_covers: break maxkey = None ...
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 import utool as ut solution_cover = {} if items is None: items = ut.flatten(candidate_sets_dict.values()) if set_weights is None: get_weight = len else: def get_we...
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, 166; 12, if_st...
def get_nth_prime(n, max_prime=4100, safe=True): 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, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193...
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, 13; 9, 23; 9, 33; 9, 43; 9, 55; 9, 82; 9, 104; 9, 129; 9, 140; 9...
def knapsack_ilp(items, maxweight, verbose=False): import pulp values = [t[0] for t in items] weights = [t[1] for t in items] indices = [t[2] for t in items] prob = pulp.LpProblem("Knapsack", pulp.LpMaximize) x = pulp.LpVariable.dicts(name='x', indexs=indices, lowB...
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, 49; 6, 61; 6, 65; 6, 80; 6, 203; 6, 207; 6, 242; 6, 249; 6, 259; 6, 272; 7, expression_statement; 7, ...
def knapsack_iterative_int(items, maxweight): r values = [t[0] for t in items] weights = [t[1] for t in items] maxsize = maxweight + 1 dpmat = defaultdict(lambda: defaultdict(lambda: np.inf)) kmat = defaultdict(lambda: defaultdict(lambda: False)) idx_subset = [] for w in range(maxsize):...
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, 16; 6, 24; 6, 38; 6, 44; 6, 58; 6, 66; 6, 75; 6, 81; 6, 98; 6, 118; 6, 122; 6, 137; 6, 235; 6, 239; 6, 274; 6, 281; 6, 291; 6,...
def knapsack_iterative_numpy(items, maxweight): items = np.array(items) weights = items.T[1] max_exp = max([number_of_decimals(w_) for w_ in weights]) coeff = 10 ** max_exp weights = (weights * coeff).astype(np.int) values = items.T[0] MAXWEIGHT = int(maxweight * coeff) W_SIZE = MAXWEIG...
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, identifier:r; 9, expression_statement; 9, 10; 10, assignment; 10, 11; ...
def knapsack_greedy(items, maxweight): r items_subset = [] total_weight = 0 total_value = 0 for item in items: value, weight = item[0:2] if total_weight + weight > maxweight: continue else: items_subset.append(item) total_weight += weight ...
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, 15; 9, 32; 9, 45; 9, 54; 9, 63; 9, 73; 9, 82; 9, 86; 9, 90; 9, ...
def ungroup_gen(grouped_items, groupxs, fill=None): import utool as ut minpergroup = [min(xs) if len(xs) else 0 for xs in groupxs] minval = min(minpergroup) if len(minpergroup) else 0 flat_groupx = ut.flatten(groupxs) sortx = ut.argsort(flat_groupx) groupx_sorted = ut.take(flat_groupx, sortx) ...
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 import utool as ut import re onlyvars = boolexpr_ onlyvars = re.sub('\\bnot\\b', '', onlyvars) onlyvars = re.sub('\\band\\b', '', onlyvars) onlyvars = re.sub('\\bor\\b', '', onlyvars) onlyvars = re.sub('\\(', '', onlyvars) onlyvars...
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; 6, return_statement; 6, 7; 7, call; 7, 8; 7, 9; 8, identifier:set; 9, argument_list; 9, 10; 10, call; 10, 11; 10, 12; 11, identifier:reduce; 12, argument_list; 12, 13; 12, 16; 13, a...
def factors(n): return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
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, identifier:r; 11, expressi...
def dict_stack(dict_list, key_prefix=''): r dict_stacked_ = defaultdict(list) for dict_ in dict_list: for key, val in six.iteritems(dict_): dict_stacked_[key_prefix + key].append(val) dict_stacked = dict(dict_stacked_) return dict_stacked
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, 57; 9, if_statement; 9, 10; 9, 11; 9, 39; 10, identifier:unique_vals; 11, block; 11, 12; 11, 2...
def invert_dict(dict_, unique_vals=True): if unique_vals: inverted_items = [(val, key) for key, val in six.iteritems(dict_)] inverted_dict = type(dict_)(inverted_items) else: inverted_dict = group_items(dict_.keys(), dict_.values()) return inverted_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): is_lone_single = all([ isinstance(val_list, (list, tuple)) and len(val_list) == 1 for key, val_list in iteritems_sorted(varied_dict) ]) if not remove_singles or (allow_lone_singles and is_lone_single)...
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 if assert_exists: try: assert_keys_are_subset(dict1, dict2) except AssertionError as ex: from utool import util_dbg util_dbg.printex(ex,...
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, identifier:r; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, i...
def groupby_tags(item_list, tags_list): r groupid_to_items = defaultdict(list) for tags, item in zip(tags_list, item_list): for tag in tags: groupid_to_items[tag].append(item) return groupid_to_items
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, 75; 11, 82; 11, 97; 12, ...
def group_items(items, by=None, sorted_=True): if by is not None: pairs = list(zip(by, items)) if sorted_: try: pairs = sorted(pairs, key=op.itemgetter(0)) except TypeError: pairs = sorted(pairs, key=lambda tup: str(tup[0])) else: p...
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): if not hasattr(node, 'items'): return func(node) elif max_depth is not None and depth >= max_depth: return map_dict_vals(func, node) else: keyval_list = [(key, hierarchical_map_vals(func, val, max_depth, depth + 1)) for ...
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): if part == 'keys': index = 0 elif part in {'vals', 'values'}: index = 1 else: raise ValueError('Unknown method part=%r' % (part,)) if key is None: _key = op.itemgetter(index) else: def _key(item): ...
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, identifier:r; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10...
def order_dict_by(dict_, key_order): r dict_keys = set(dict_.keys()) other_keys = dict_keys - set(key_order) key_order = it.chain(key_order, other_keys) sorted_dict = OrderedDict( (key, dict_[key]) for key in key_order if key in dict_keys ) return sorted_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; 6, if_statement; 6, 7; 6, 12; 6, 20; 7, call; 7, 8; 7, 9; 8, identifier:isinstance; 9, argument_list; 9, 10; 9, 11; 10, identifier:dict_; 11, identifier:OrderedDict; 12...
def iteritems_sorted(dict_): 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, 71; 9, expression_statement; 9, 10; 10, identifier:r; 11, if_statement; 11, 12; ...
def num_fmt(num, max_digits=None): r if num is None: return 'None' def num_in_mag(num, mag): return mag > num and num > (-1 * mag) if max_digits is None: if num_in_mag(num, 1): if num_in_mag(num, .1): max_digits = 4 else: ma...
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): module = _get_module(module_name, module) if SILENT: def print(*args): pass def printDBG(*args): pass def print_(*args): pass ...
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): psm_or_feat_ratios = get_psmratios(psmfn, psmheader, channels, denom_channels, min_int, accessioncol) if normalize and norm...
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, 13; 5, 22; 5, 42; 5, 49; 5, 62; 5, 71; 5, 78; 5, 82; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:profile_block_list; 9, call; 9, 10...
def clean_line_profile_text(text): profile_block_list = parse_rawprofile_blocks(text) prefix_list, timemap = parse_timemap_from_blocks(profile_block_list) sorted_lists = sorted(six.iteritems(timemap), key=operator.itemgetter(0)) newlist = prefix_list[:] for key, val in sorted_lists: newlist....
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, 17; 11, 27; 11, 33; 11, ...
def random_product(items, num=None, rng=None): import utool as ut rng = ut.ensure_rng(rng, 'python') seen = set() items = [list(g) for g in items] max_num = ut.prod(map(len, items)) if num is None: num = max_num if num > max_num: raise ValueError('num exceedes maximum number ...
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, 13; 5, 26; 5, 36; 5, 42; 5, 88; 5, 111; 5, 128; 5, 150; 5, 161; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:dsn; 9, call; 9, 10; 9, 11; 10,...
def parse_dsn(dsn_string): 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: username, password = username.split(':') pas...
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): itemsep = kwargs.get('itemsep', ' ') newlines = kwargs.pop('nl', kwargs.pop('newlines', 1)) data = arr...
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, 114; 7, 118; 7, 127; 7, 135; 7, 148; 7,...
def list_str(list_, **listkw): r import utool as ut newlines = listkw.pop('nl', listkw.pop('newlines', 1)) packed = listkw.pop('packed', False) truncate = listkw.pop('truncate', False) listkw['nl'] = _rectify_countdown_or_bool(newlines) listkw['truncate'] = _rectify_countdown_or_bool(truncat...
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, 12; 8, 22; 8, 32; 8, 63; 8, 80; 8, 84; 8, 88; 8, 258; 8, 271; 8, 280; 9, impor...
def horiz_string(*args, **kwargs): import unicodedata precision = kwargs.get('precision', None) sep = kwargs.get('sep', '') if len(args) == 1 and not isinstance(args[0], six.string_types): val_list = args[0] else: val_list = args val_list = [unicodedata.normalize('NFC', ensure_un...
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 import difflib text1 = ensure_unicode(text1) text2 = ensure_unicode(text2) text1_lines = text1.splitlines() text2_lines = text2.splitlines() if ignore_whitespace: text1_lines = [t.rstrip() for t in text1_...
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): if value is not None: return self.add(((data, value),), timestamp=timestamp, namespace=namespace, debug=debug) writer = self.writer if writer is None: rai...
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): allquants, sqlfields = quantdb.select_all_psm_quants(isobaric, precursor) quant = next(allquants) for rownr, psm in enumerate(readers.generate_tsv_psms(tsvfn, oldheader)): ou...
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, 106; 5, 111; 5, 121; 5, 140; 5, 148; 5, 156; 5, 201; 5, 216; 5, 235; 5, 357; 5, 372; 5, 375; 5, 383; 6, e...
def total_purge_developed_repo(repodir): r assert repodir is not None import utool as ut import os repo = ut.util_git.Repo(dpath=repodir) user = os.environ['USER'] fmtdict = dict( user=user, modname=repo.modname, reponame=repo.reponame, dpath=repo.dpath, ...
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, 14; 8, 28; 8, 50; 8, 60; 9, import_statement; 9, 10; 10, aliased_import; 10, 11; 10, 13; 11, do...
def nx_dag_node_rank(graph, nodes=None): import utool as ut source = list(ut.nx_source_nodes(graph))[0] longest_paths = dict([(target, dag_longest_path(graph, source, target)) for target in graph.nodes()]) node_to_rank = ut.map_dict_vals(len, longest_paths) if nodes is None...
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): if cutoff is None: cutoff = len(G) - 1 if cutoff < 1: return import utool as ut import six visited_nodes = [source] visited_edges = [] if G.is_multigraph(): ...
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'): if on_missing is None: on_missing = 'error' if default is util_const.NoParam and on_keyerr == 'default': on_keyerr = 'error' if nodes is None: nodes =...
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'): if edges is None: edges = G.edges() if on_missing is None: on_missing = 'error' if on_keyerr is None: on_keyerr = 'default' if default is util_c...
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'): if on_missing is None: on_missing = 'error' if default is util_const.NoParam and on_keyerr == 'default': on_keyerr = 'error' if edges is None: if G.is...
0, module; 0, 1; 1, ERROR; 1, 2; 1, 3; 1, 5; 1, 10; 1, 15; 1, 16; 1, 18; 1, 188; 1, 199; 2, identifier:nx_ensure_agraph_color; 3, parameters; 3, 4; 4, identifier:graph; 5, import_from_statement; 5, 6; 5, 8; 6, dotted_name; 6, 7; 7, identifier:plottool; 8, dotted_name; 8, 9; 9, identifier:color_funcs; 10, import_stateme...
def nx_ensure_agraph_color(graph): from plottool import color_funcs import plottool as pt def _fix_agraph_color(data): try: orig_color = data.get('color', None) alpha = data.get('alpha', None) color = orig_color if color is None and alpha is not 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, 11; 5, 25; 5, 34; 5, 68; 5, 78; 5, 127; 5, 133; 5, 139; 5, 146; 5, 153; 6, import_statement; 6, 7; 7, aliased_import; 7, 8; 7, 10; 8, dotted_name; 8, 9; 9, identifier:...
def simplify_graph(graph): import utool as ut nodes = sorted(list(graph.nodes())) node_lookup = ut.make_index_lookup(nodes) if graph.is_multigraph(): edges = list(graph.edges(keys=True)) else: edges = list(graph.edges()) new_nodes = ut.take(node_lookup, nodes) if graph.is_mul...
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, 29; 9, 42; 9, 117; 10, expression_statement; 10, 11; 11, assi...
def subgraph_from_edges(G, edge_list, ref_back=True): sub_nodes = list({y for x in edge_list for y in x[0:2]}) multi_edge_list = [edge[0:3] for edge in edge_list] if ref_back: G_sub = G.subgraph(sub_nodes) for edge in G_sub.edges(keys=True): if edge not in multi_edge_list: ...
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): if reverse and hasattr(G, 'reverse'): G = G.reverse() if isinstance(G, nx.Graph): ...
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, 12; 6, 16; 6, 24; 6, 31; 6, 38; 6, 86; 6, 107; 6, 118; 6, 127; 6, 157; 6, 275; 6, 283; 7, import_statement; 7, 8; 8, ali...
def approx_min_num_components(nodes, negative_edges): import utool as ut num = 0 g_neg = nx.Graph() g_neg.add_nodes_from(nodes) g_neg.add_edges_from(negative_edges) if nx.__version__.startswith('2'): deg0_nodes = [n for n, d in g_neg.degree() if d == 0] else: deg0_nodes = [n ...
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): protein_peptides = {} if minlog: higherbetter = False if not protcol: protcol = peptabledata.HEADER_MASTERPROTEINS for psm in reader.generate_tsv_psms(pepfn, pephe...
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 file_url = clean_dropbox_link(file_url) if fname is None: fname = basename(file_url) if download_dir is No...
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, 14; 5, 49; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:header; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, ident...
def get_uniprot_evidence_level(header): header = header.split() for item in header: item = item.split('=') try: if item[0] == 'PE': return 5 - int(item[1]) except IndexError: continue return -1
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, 16; 8, 27; 8, 57; 8, 408; 9, expression_statement; 9, 10; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12...
def _drain(self, cycles=None): log.info("Now draining...") if not cycles: log.info("No cycle count, the pipeline may be drained forever.") if self.calibration: log.info("Setting up the detector calibration.") for module in self.modules: module....
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, 20; 7, 38; 7, 50; 7, 56; 7, 122; 7, 130; 7, 138; 7, 146; 7, 154; 8, if_statement; 8, 9; 8, 14; 9, attribute; 9, 10; 9, 13; 10, att...
def start(backdate=None): if f.s.cum: raise StartError("Already have stamps, can't start again (must reset).") if f.t.subdvsn_awaiting or f.t.par_subdvsn_awaiting: raise StartError("Already have subdivisions, can't start again (must reset).") if f.t.stopped: raise StoppedError("Timer...
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): t = timer() if f.t.stopped: raise StoppedError("Cannot stamp stopped timer.") if f.t.paused: raise PausedError("Cannot stamp paused timer.") if backdate i...
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): t = timer() if f.t.stopped: raise StoppedError("Timer already stopped.") if backdate is None: t_stop = t else: if f.t is f.root: rai...
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']): retur...
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; 12, if_statement; 12, 13...
def format_gmeta(data, acl=None, identifier=None): if isinstance(data, dict): if acl is None or identifier is None: raise ValueError("acl and identifier are required when formatting a GMetaEntry.") if isinstance(acl, str): acl = [acl] prefixed_acl = [] for uui...
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): if not type_insensitive and type(item1) != type(item2): return False if isinstance(item1, Mapping): if not isinstance(item2, Mapping): return False if not len(item1) == len(item2): ...
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, 17; 9, 26; 9, 33; 9, 289; 10, expression_stat...
def template_to_filepath(template, metadata, template_patterns=None): path = Path(template) if template_patterns is None: template_patterns = TEMPLATE_PATTERNS suggested_filename = suggest_filename(metadata) if ( path == Path.cwd() or path == Path('%suggested%') ): filepath = Path(suggested_filename) elif...
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, 23; 8, 31; 8, 35; 8, 96; 8, 102; 8, 150; 8, 246; 9, if_statement; 9, 10; 9, 18; 10, boolean_o...
def _get_station_codes(self, force=False): if not force and self.station_codes is not None: return self.station_codes state_urls = self._get_state_urls() state_matches = None if self.bbox: with collection( os.path.join( "resourc...
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, 13; 5, 27; 5, 38; 5, 85; 5, 116; 5, 136; 5, 147; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:query; 9, call; 9, 10; 9, 11; 10, identifier:...
def _validate_query(query): query = deepcopy(query) if query["q"] == BLANK_QUERY["q"]: raise ValueError("No query specified.") query["q"] = _clean_query_string(query["q"]) if query["limit"] is None: query["limit"] = SEARCH_LIMIT if query["advanced"] else NONADVANCED_LIMIT elif query[...
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, 17; 8, 101; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:mapping; 1...
def show_fields(self, block=None): mapping = self._mapping() if block is None: return mapping elif block == "top": blocks = set() for key in mapping.keys(): blocks.add(key.split(".")[0]) block_map = {} for b in blocks: ...
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, 22; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:sort_i...
def sorted(self, by, **kwargs): sort_idc = np.argsort(self[by], **kwargs) return self.__class__( self[sort_idc], h5loc=self.h5loc, split_h5=self.split_h5, name=self.name )
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, 33; 9, 54; 9, 75; 9, 84; 9, 90; 9, 100;...
def create_multi_output_factor(self, tool, source, splitting_node, sink): if source and not isinstance(source, Node): raise ValueError("Expected Node, got {}".format(type(source))) if not isinstance(sink, Node): raise ValueError("Expected Node, got {}".format(type(sink))) ...
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, 27; 8, 82; 8, 218; 8, 229; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, ...
def to_dict(self, tool_long_names=True): d = dict(nodes=[], factors=[], plates=defaultdict(list)) for node in self.nodes: node_id = self.nodes[node].node_id d['nodes'].append({'id': node_id}) for plate_id in self.nodes[node].plate_ids: d['plates'][plat...
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): if isinstance(filenames, str): filenames = [filenames] try: iter(filenames) except TypeError: log.critical("Don't know how to iterate through filenames.") raise TypeError("Invalid filenames.") exten...
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, 20; 10, 84; 10, 121; 11, if_statem...
def get_sources(self, plate, plate_value, sources=None): if sources is None: sources = [] if self.sources: for si, source in enumerate(self.sources): if len(source.streams) == 1 and None in source.streams: sources.append(source.streams[None]) ...
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, 15; 6, 35; 6, 59; 6, 81; 6, 91; 6, 252; 7, if_statement; 7, 8; 7, 12; 8, not_operator; 8, 9; 9, attribute; 9, 10; 9, 11; 10...
def get_splitting_stream(self, input_plate_value): if not self.splitting_node: return None if len(self.splitting_node.plates) == 0: return self.splitting_node.streams[None] if len(self.splitting_node.plates) > 1: raise ValueError("Splitting node cannot live on...
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): if method == 'turchin': for row in dataset.objects['FormTable']: sounds = ''.join(lingpy.tokens2class(row[column], 'dolgo')) if sounds.startswith('V'): sounds = 'H' + sounds ...
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, 39; 6, 43; 6, 105; 6, 115; 6, 123; 6, 133; 7, if_statement; 7, 8; 7, 13; 7, 21; 7, 32; 8, call; 8, 9; 8, 10; 9, identifier:isinstance; 10, arg...
def get_tool_class(self, tool): if isinstance(tool, string_types): tool_id = StreamId(tool) elif isinstance(tool, StreamId): tool_id = tool else: raise TypeError(tool) tool_stream_view = None if tool_id in self.tools: tool_stream_vi...
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, 45; 6, if_statement; 6, 7; 6, 12; 7, comparison_operator:==; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:_pmt_angles; 11, list:[]; 12, block;...
def pmt_angles(self): 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, 22; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:cur_points_z; 11, list_comprehension;...
def _get_point(self, profile, point): 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] except ValueError: new_idx = bisect_left(cur_points_z, point.z) new_point = Po...
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, 14; 7, if_statement; 7, 8; 7, 11; 8, comparison_operator:==; 8, 9; 8, 10; 9, identifier:x; 10, identifier:y; 11, block; 11, 12; 12, return_statemen...
def metadata_sorter(x, y): 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 elif y in METADATA_SORTER_FIRST: ret...
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, 18; 7, 25; 7, 31; 7, 43; 7, 105; 7, 181; 8, expression_statement; 8, 9; 9, assignment; 9, 1...
def computeStrongestPaths(self, profile, pairwisePreferences): cands = profile.candMap.keys() numCands = len(cands) strongestPaths = dict() for cand in cands: strongestPaths[cand] = dict() for i in range(1, numCands + 1): for j in range(1, numCands + 1): ...
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, 17; 6, 23; 6, 35; 6, 56; 6, 183; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:cands; 10, call; 10, ...
def computePairwisePreferences(self, profile): cands = profile.candMap.keys() pairwisePreferences = dict() for cand in cands: pairwisePreferences[cand] = dict() for cand1 in cands: for cand2 in cands: if cand1 != cand2: pairwise...
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, 15; 6, 23; 6, 29; 6, 64; 6, 78; 6, 85; 6, 91; 6, 97; 6, 106; 6, 110; 6, 117; 6, 264; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, ...
def STVsocwinners(self, profile): ordering = profile.getOrderVectors() prefcounts = profile.getPreferenceCounts() m = profile.numCands if min(ordering[0]) == 0: startstate = set(range(m)) else: startstate = set(range(1, m + 1)) ordering, startstate...
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, 15; 6, 21; 6, 29; 6, 64; 6, 78; 6, 84; 6, 90; 6, 99; 6, 103; 6, 110; 6, 283; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10;...
def baldwinsoc_winners(self, profile): ordering = profile.getOrderVectors() m = profile.numCands prefcounts = profile.getPreferenceCounts() if min(ordering[0]) == 0: startstate = set(range(m)) else: startstate = set(range(1, m + 1)) wmg = self.getW...
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, 18; ...
def getWmg2(self, prefcounts, ordering, state, normalize=False): wmgMap = dict() for cand in state: wmgMap[cand] = dict() for cand1, cand2 in itertools.combinations(state, 2): wmgMap[cand1][cand2] = 0 wmgMap[cand2][cand1] = 0 for i in range(0, len(pref...
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, 15; 6, 37; 6, 45; 6, 52; 6, 60; 6, 71; 6, 77; 6, 81; 6, 180; 6, 306; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, ide...
def PluRunOff_cowinners(self, profile): elecType = profile.getElecType() if elecType != "soc" and elecType != "toc" and elecType != "csv": print("ERROR: unsupported election type") exit() prefcounts = profile.getPreferenceCounts() len_prefcounts = len(prefcounts) ...
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, 74; 11, 153; ...
def _cache_offsets(self, up_to_index=None, verbose=True): 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 self.raw_header: self....
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, 15; 7, 19; 7, 134; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:m; 11, ca...
def getUtilities(self, decision, binaryRelations): m = len(binaryRelations) utilities = [] for cand in decision: tops = [cand-1] index = 0 while index < len(tops): s = tops[index] for j in range(m): if j == s...
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, 33...
def execute(self, sources, sink, interval, alignment_stream=None): if not isinstance(interval, TimeInterval): raise TypeError('Expected TimeInterval, got {}'.format(type(interval))) if interval.end > sink.channel.up_to_timestamp: raise StreamNotAvailableError(sink.channel.up_to_t...
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, 19; 8, 43; 8, 75; 8, 84; 8, 119; 8, 125; 8, 141; 8, 157; 8, 178; 8, 183; 8, 203; 8, 2...
def upload_runsummary(csv_filename, dryrun=False): print("Checking '{}' for consistency.".format(csv_filename)) if not os.path.exists(csv_filename): log.critical("{} -> file not found.".format(csv_filename)) return try: df = pd.read_csv(csv_filename, sep='\t') except pd.errors.Em...
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, 12; 5, 21; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:redis_key; 9, binary_operator:%; 9, 10; 9, 11; 10, string:'m_%s'; 11, identifier:tmdb_i...
def get_movie(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_tmdb(u'/movie/%d/casts' % tmdb_id) alternative = get_on...
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): formatter = Formatter() fields = [x[1] for x in formatter.parse(format_string) if x[1] is not None] prepared_env = {} for field in fields: for field_alt in (x.strip() for x in field.split('|')): if field_alt[0] in '\'"' a...
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. ): if isinstance(data, str): filename = data loaders = { '.h5':...
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={})): if not segments: raise ValueError('Empty sequence.') if not [segment for segment in segments if segment.strip()]: raise ValueError('No information in the sequence.') try: bipa_analysis, sc_analysis = [], [] for ...
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): if dry_run: debug = True conf = config.Config(conf_file=conf_file) db = conf.get_database() limits_key = conf['control'].get('limits_key', 'limits') control_channel = conf['control'].get('c...
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, 23; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:limit_node; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11...
def make_limit_node(root, limit): limit_node = etree.SubElement(root, 'limit', {'class': limit._limit_full_name}) for attr in sorted(limit.attrs): desc = limit.attrs[attr] attr_type = desc.get('type', str) value = getattr(limit, attr) if 'default...
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): conf = config.Config(conf_file=conf_file) db = conf.get_database() control_channel = conf['control'].get('channel', 'control') command = command.lower() ts_conv = False if command == 'ping':...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:humanize_timesince; 3, parameters; 3, 4; 4, identifier:start_time; 5, block; 5, 6; 5, 12; 5, 20; 5, 31; 5, 39; 5, 62; 5, 70; 5, 93; 5, 99; 5, 122; 5, 130; 5, 153; 5, 161; 5, 184; 6, if_statement; 6, 7; 6, 9; 7, not_operator; 7, 8; 8, identifier...
def humanize_timesince(start_time): if not start_time: return start_time delta = local_now() - start_time if delta.total_seconds() < 0: return 'a few seconds ago' num_years = delta.days // 365 if num_years > 0: return '{} year{} ago'.format( *((num_years, 's') if ...
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, 14; 9, 27; 9, 345; 10, expression_statement; 10, 11; 11, assign...
def fire(self, *args, **kw): result = [] with self._hlock: handlers = self.handlers if self.threads == 0: for k in handlers: h, m, t = handlers[k] try: r = self._memoize(h, m, t, *args, **kw) ...
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, 24; 6, 31; 6, 38; 6, 42; 6, 46; 6, 245; 6, 252; 7, expression_statement; 7, 8; 8, assignment;...
def _pathway_feature_permutation(pathway_feature_tuples, permutation_max_iters): pathways, features = [list(elements_at_position) for elements_at_position in zip(*pathway_feature_tuples)] original_pathways = pathways[:] ran...
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, 11; 6, 15; 6, 22; 6, 26; 6, 190; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:offset; 10, integer:0; 11, e...
def get_field_infos(code, free_format): offset = 0 field_infos = [] lines = _clean_code(code) previous_offset = 0 for row in process_cobol(lines, free_format): fi = PicFieldInfo() fi.name = row["name"] fi.level = row["level"] fi.pic = row["pic"] fi.occurs = ro...
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, 23; 8, 27; 8, 40; 8, 151; 8, 166; 8, 172; 8, 184; 8, 219; 9, expression_statem...
def _advanced_acronym_detection(s, i, words, acronyms): acstr = ''.join(words[s:i]) range_list = [] not_range = set(range(len(acstr))) for acronym in acronyms: rac = regex.compile(unicode(acronym)) n = 0 while True: m = rac.search(acstr, n) if not m: ...
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, 10; 5, 14; 5, 18; 5, 22; 5, 31; 5, 35; 5, 54; 5, 200; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:words; 9, list:[]; 10, expression_state...
def _separate_words(string): words = [] separator = "" i = 1 s = 0 p = string[0:1] was_upper = False if string.isupper(): string = string.lower() was_upper = True while i <= len(string): c = string[i:i + 1] split = False if i < len(string): ...
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, 22; 11, 46;...
def parse_case(string, acronyms=None, preserve_case=False): words, separator, was_upper = _separate_words(string) if acronyms: acronyms = _sanitize_acronyms(acronyms) check_acronym = _advanced_acronym_detection else: acronyms = [] check_acronym = _simple_acronym_detection ...
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, 17; 5, 21; 5, 42; 5, 52; 5, 66; 5, 73; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:db; 9, call; 9, 10; 9, 15; 10, attribute; 10, 11; 10, 14; 11, att...
def listen(self): db = self.config.get_database('control') kwargs = {} if 'shard_hint' in self.config['control']: kwargs['shard_hint'] = self.config['control']['shard_hint'] pubsub = db.pubsub(**kwargs) channel = self.config['control'].get('channel', 'control') ...
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, 34; 5, 38; 5, 64; 5, 80; 5, 84; 5, 88; 5, 92; 5, 199; 5, 208; 5, 228; 5, 309; 5, 316; 6, if_statement; 6, 7; 6, 10; 6, 26; 7, comparison_operator:in; 7, 8; 7, 9; 8, strin...
def initialize(config): if 'redis_client' in config: client = utils.find_entrypoint('turnstile.redis_client', config['redis_client'], required=True) else: client = redis.StrictRedis kwargs = {} for cfg_var, type_ in REDIS_CONFIGS.items(): if...
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, 148; 8, 155; 8, 167; 8, 205; 9, expression_statement; 9, ...
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.htm...
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, 170; 6, 186; 6, 262; 6, 284; 7, expression_statement; 7, 8; 8, string:''' Split the PileupCollection by t...
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 ran...
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. lo...
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, 138; 6, 147; 6, 168; 6, 188; 6, 196; 6, 205; 6, 214; 6, 232; 6, 254; 7...
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 = "" ; //..................................