sequence
stringlengths
1.19k
35k
code
stringlengths
75
8.58k
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'greedy_max_inden_setcover'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'childr...
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 ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'setcover_greedy'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']}; {'id': '4', 'type': 'identifier', 'chi...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_nth_prime'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'v...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'knapsack_ilp'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'val...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'knapsack_iterative_int'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [],...
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):...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'knapsack_iterative_numpy'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'knapsack_greedy'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value...
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 ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'ungroup_gen'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'valu...
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) ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'standardize_boolexpr'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], '...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'factors'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id...
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)))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'dict_stack'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'd...
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
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'invert_dict'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': '...
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
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'all_dict_combinations_lbls'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'chil...
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)...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'update_existing'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']}; {'id': '4', 'type': 'identifier',...
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,...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'groupby_tags'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': ...
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
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'group_items'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'val...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'hierarchical_map_vals'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'chil...
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 ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_dict'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': [], ...
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): ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'order_dict_by'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value':...
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
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'iteritems_sorted'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': '...
def iteritems_sorted(dict_): if isinstance(dict_, OrderedDict): return six.iteritems(dict_) else: return iter(sorted(six.iteritems(dict_)))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'num_fmt'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'num'...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'inject_print_functions'}, {'id': '3', 'type': 'parameters', 'children': ['4', '7', '10', '13']}; {'id': '4', 'type': 'default_paramet...
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 ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_isobaric_ratios'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10', '11', '12']}; {'id': '4', '...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'clean_line_profile_text'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'va...
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....
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'random_product'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], '...
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 ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_dsn'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'dsn_str...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '31']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'numpy_str'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29']}; {'id': '4', 't...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_str'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'lis...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'horiz_string'}, {'id': '3', 'type': 'parameters', 'children': ['4', '6']}; {'id': '4', 'type': 'list_splat_pattern', 'children': ['5']...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_textdiff'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': []...
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_...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'add'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']}; {'id': '4', 'type': 'identifier', 'children':...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'generate_psms_quanted'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '11']}; {'id': '4', 'type': 'identif...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'total_purge_developed_repo'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], ...
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, ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'nx_dag_node_rank'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'valu...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'nx_all_simple_edge_paths'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13']}; {'id': '4', 'type': 'ide...
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(): ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'nx_gen_node_attrs'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '14', '17']}; {'id': '4', 'type': 'identifier...
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 =...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'nx_gen_edge_values'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '14', '17']}; {'id': '4', 'type': 'identifie...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'nx_gen_edge_attrs'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '14', '17']}; {'id': '4', 'type': 'identifier...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'ERROR', 'children': ['2', '3', '5', '10', '15', '16', '18', '188', '199']}; {'id': '2', 'type': 'identifier', 'children': [], 'value': 'nx_ensure_agraph_color'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier',...
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: ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'simplify_graph'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'gr...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'subgraph_from_edges'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [...
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: ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '30']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'bfs_conditional'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24', '27']}; {'id': '4...
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): ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'approx_min_num_components'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': ...
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 ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'generate_proteins'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '12']}; {'id': '4', 'type': 'identi...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '29']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'grab_file_url'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26']}; {'id': '4', 'typ...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_uniprot_evidence_level'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], ...
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
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_drain'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'...
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....
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'start'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}, {'id'...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '26']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'stamp'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23']}; {'id': '4', 'type': 'identifie...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '28']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'stop'}, {'id': '3', 'type': 'parameters', 'children': ['4', '7', '10', '13', '16', '19', '22', '25']}; {'id': '4', 'type': 'default_p...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '38']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'timed_loop'}, {'id': '3', 'type': 'parameters', 'children': ['4', '7', '10', '15', '18', '23', '28', '33']}; {'id': '4', 'type': 'def...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '39']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'timed_for'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '16', '19', '24', '29', '34']}; {'id': '4', 'type': ...
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['...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'format_gmeta'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'va...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'insensitive_comparison'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'chi...
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): ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'template_to_filepath'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': ...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_station_codes'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'va...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_validate_query'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'q...
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[...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'show_fields'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': '...
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: ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sorted'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': '...
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 )
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'create_multi_output_factor'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']}; {'id': '4', 'type': 'identifie...
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))) ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'to_dict'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'GenericPump'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': []...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_sources'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [],...
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]) ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_splitting_stream'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], '...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'iter_cognates'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']}; {'id': '4', 'type': 'identifier', 'child...
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 ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_tool_class'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value'...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'pmt_angles'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}...
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
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_point'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'metadata_sorter'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'computeStrongestPaths'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children':...
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): ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'computePairwisePreferences'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children':...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'STVsocwinners'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value':...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'baldwinsoc_winners'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'va...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'getWmg2'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']}; {'id': '4', 'type': 'identifier', 'children': []...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'PluRunOff_cowinners'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'v...
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) ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_cache_offsets'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], '...
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....
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'getUtilities'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'val...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'execute'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']}; {'id': '4', 'type': 'identifier', 'children': []...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'upload_runsummary'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'val...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_movie'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'tmdb_id...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_pattern'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'v...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '26']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'calibrate_dom'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16', '19', '22']}; {'id': '4', 'type...
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':...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'analyze'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value':...
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 ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'setup_limits'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'childre...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'make_limit_node'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'turnstile_command'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'ch...
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':...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'humanize_timesince'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value':...
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 ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'fire'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'se...
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) ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'runGetResults'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': ...
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 ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_pathway_feature_permutation'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_field_infos'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_advanced_acronym_detection'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', ...
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: ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_separate_words'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 's...
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): ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_case'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'valu...
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 ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'listen'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'...
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') ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'initialize'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'config...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'read_attributes'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'group_by_allele'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'from_bam'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value':...
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...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'check_recommended_global_attributes'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'c...
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 = "" ; //..................................