sequence
stringlengths
1.27k
35.1k
code
stringlengths
75
8.58k
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_keys'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'data_list'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'leading_columns'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'LEADING_COLUMNS'}; {'id': '8', 'type': 'block', 'children': ['9', '32', '36', '60']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'all_keys'}; {'id': '12', 'type': 'call', 'children': ['13', '18']}; {'id': '13', 'type': 'attribute', 'children': ['14', '17']}; {'id': '14', 'type': 'call', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '16', 'type': 'argument_list', 'children': []}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'union'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}; {'id': '19', 'type': 'list_splat', 'children': ['20']}; {'id': '20', 'type': 'generator_expression', 'children': ['21', '29']}; {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '28']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '28', 'type': 'argument_list', 'children': []}; {'id': '29', 'type': 'for_in_clause', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'data_list'}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'leading_keys'}; {'id': '35', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '36', 'type': 'for_statement', 'children': ['37', '38', '39']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'leading_columns'}; {'id': '39', 'type': 'block', 'children': ['40', '46', '53']}; {'id': '40', 'type': 'if_statement', 'children': ['41', '44']}; {'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': 'not'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'all_keys'}; {'id': '44', 'type': 'block', 'children': ['45']}; {'id': '45', 'type': 'continue_statement', 'children': []}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}; {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'leading_keys'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '58']}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'all_keys'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'remove'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '60', 'type': 'return_statement', 'children': ['61']}; {'id': '61', 'type': 'binary_operator', 'children': ['62', '63'], 'value': '+'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'leading_keys'}; {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'all_keys'}
def get_keys(data_list, leading_columns=LEADING_COLUMNS): all_keys = set().union(*(list(d.keys()) for d in data_list)) leading_keys = [] for key in leading_columns: if key not in all_keys: continue leading_keys.append(key) all_keys.remove(key) return leading_keys + sorted(all_keys)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'to_file'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '8', 'type': 'True', 'children': []}; {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'relativize'}; {'id': '11', 'type': 'True', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'nl'}; {'id': '14', 'type': 'None', 'children': []}; {'id': '15', 'type': 'block', 'children': ['16', '33', '48', '73']}; {'id': '16', 'type': 'if_statement', 'children': ['17', '22', '27']}; {'id': '17', 'type': 'comparison_operator', 'children': ['18', '21'], 'value': '>='}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'hexversion'}; {'id': '21', 'type': 'integer', 'children': [], 'value': '0x02030000'}; {'id': '22', 'type': 'block', 'children': ['23']}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'str_type'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'basestring'}; {'id': '27', 'type': 'else_clause', 'children': ['28']}; {'id': '28', 'type': 'block', 'children': ['29']}; {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'str_type'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '33', 'type': 'if_statement', 'children': ['34', '37', '42']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': 'is'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'nl'}; {'id': '36', 'type': 'None', 'children': []}; {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}; {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '41', 'type': 'string', 'children': [], 'value': "'w'"}; {'id': '42', 'type': 'else_clause', 'children': ['43']}; {'id': '43', 'type': 'block', 'children': ['44']}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}; {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '47', 'type': 'string', 'children': [], 'value': "'wb'"}; {'id': '48', 'type': 'if_statement', 'children': ['49', '54', '67']}; {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '51', 'type': 'argument_list', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'str_type'}; {'id': '54', 'type': 'block', 'children': ['55', '63']}; {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '58', 'type': 'call', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '60', 'type': 'argument_list', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'want_close'}; {'id': '66', 'type': 'True', 'children': []}; {'id': '67', 'type': 'else_clause', 'children': ['68']}; {'id': '68', 'type': 'block', 'children': ['69']}; {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'want_close'}; {'id': '72', 'type': 'False', 'children': []}; {'id': '73', 'type': 'try_statement', 'children': ['74', '150']}; {'id': '74', 'type': 'block', 'children': ['75', '102']}; {'id': '75', 'type': 'if_statement', 'children': ['76', '77', '92']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '77', 'type': 'block', 'children': ['78', '86']}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}; {'id': '79', 'type': 'assignment', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '81', 'type': 'call', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '85', 'type': 'argument_list', 'children': []}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}; {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '91', 'type': 'argument_list', 'children': []}; {'id': '92', 'type': 'else_clause', 'children': ['93']}; {'id': '93', 'type': 'block', 'children': ['94']}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}; {'id': '95', 'type': 'assignment', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '97', 'type': 'call', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'iterkeys'}; {'id': '101', 'type': 'argument_list', 'children': []}; {'id': '102', 'type': 'for_statement', 'children': ['103', '104', '105']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '105', 'type': 'block', 'children': ['106', '125']}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}; {'id': '107', 'type': 'assignment', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '109', 'type': 'call', 'children': ['110', '115']}; {'id': '110', 'type': 'attribute', 'children': ['111', '114']}; {'id': '111', 'type': 'subscript', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'to_text'}; {'id': '115', 'type': 'argument_list', 'children': ['116', '117', '122']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '117', 'type': 'keyword_argument', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'origin'}; {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'origin'}; {'id': '122', 'type': 'keyword_argument', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'relativize'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'relativize'}; {'id': '125', 'type': 'if_statement', 'children': ['126', '129', '134']}; {'id': '126', 'type': 'comparison_operator', 'children': ['127', '128'], 'value': 'is'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'nl'}; {'id': '128', 'type': 'None', 'children': []}; {'id': '129', 'type': 'block', 'children': ['130']}; {'id': '130', 'type': 'print_statement', 'children': ['131', '133']}; {'id': '131', 'type': 'chevron', 'children': ['132']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '134', 'type': 'else_clause', 'children': ['135']}; {'id': '135', 'type': 'block', 'children': ['136', '143']}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}; {'id': '137', 'type': 'call', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'call', 'children': ['145', '148']}; {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '148', 'type': 'argument_list', 'children': ['149']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'nl'}; {'id': '150', 'type': 'finally_clause', 'children': ['151']}; {'id': '151', 'type': 'block', 'children': ['152']}; {'id': '152', 'type': 'if_statement', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'want_close'}; {'id': '154', 'type': 'block', 'children': ['155']}; {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'call', 'children': ['157', '160']}; {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'close'}; {'id': '160', 'type': 'argument_list', 'children': []}
def to_file(self, f, sorted=True, relativize=True, nl=None): if sys.hexversion >= 0x02030000: str_type = basestring else: str_type = str if nl is None: opts = 'w' else: opts = 'wb' if isinstance(f, str_type): f = file(f, opts) want_close = True else: want_close = False try: if sorted: names = self.keys() names.sort() else: names = self.iterkeys() for n in names: l = self[n].to_text(n, origin=self.origin, relativize=relativize) if nl is None: print >> f, l else: f.write(l) f.write(nl) finally: if want_close: f.close()
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_sorted_keys'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '31', '76', '105', '125']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'sorted_keys'}; {'id': '10', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '11', 'type': 'if_statement', 'children': ['12', '23']}; {'id': '12', 'type': 'boolean_operator', 'children': ['13', '17'], 'value': 'and'}; {'id': '13', 'type': '()', 'children': ['14']}; {'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': 'in'}; {'id': '15', 'type': 'string', 'children': [], 'value': "'epoch'"}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '17', 'type': '()', 'children': ['18']}; {'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': 'not'}; {'id': '19', 'type': 'string', 'children': [], 'value': "'epoch'"}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'keys_ignored_'}; {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}; {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'sorted_keys'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'string', 'children': [], 'value': "'epoch'"}; {'id': '31', 'type': 'for_statement', 'children': ['32', '33', '37']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'if_statement', 'children': ['39', '68']}; {'id': '39', 'type': 'not_operator', 'children': ['40']}; {'id': '40', 'type': '()', 'children': ['41']}; {'id': '41', 'type': 'boolean_operator', 'children': ['42', '62'], 'value': 'or'}; {'id': '42', 'type': 'boolean_operator', 'children': ['43', '56'], 'value': 'or'}; {'id': '43', 'type': 'boolean_operator', 'children': ['44', '50'], 'value': 'or'}; {'id': '44', 'type': '()', 'children': ['45']}; {'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': 'in'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '47', 'type': 'tuple', 'children': ['48', '49']}; {'id': '48', 'type': 'string', 'children': [], 'value': "'epoch'"}; {'id': '49', 'type': 'string', 'children': [], 'value': "'dur'"}; {'id': '50', 'type': '()', 'children': ['51']}; {'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': 'in'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'keys_ignored_'}; {'id': '56', 'type': 'call', 'children': ['57', '60']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'endswith'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}; {'id': '61', 'type': 'string', 'children': [], 'value': "'_best'"}; {'id': '62', 'type': 'call', 'children': ['63', '66']}; {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}; {'id': '67', 'type': 'string', 'children': [], 'value': "'event_'"}; {'id': '68', 'type': 'block', 'children': ['69']}; {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'call', 'children': ['71', '74']}; {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'sorted_keys'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '76', 'type': 'for_statement', 'children': ['77', '78', '82']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '78', 'type': 'call', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '82', 'type': 'block', 'children': ['83']}; {'id': '83', 'type': 'if_statement', 'children': ['84', '97']}; {'id': '84', 'type': 'boolean_operator', 'children': ['85', '91'], 'value': 'and'}; {'id': '85', 'type': 'call', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'string', 'children': [], 'value': "'event_'"}; {'id': '91', 'type': '()', 'children': ['92']}; {'id': '92', 'type': 'comparison_operator', 'children': ['93', '94'], 'value': 'not'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'keys_ignored_'}; {'id': '97', 'type': 'block', 'children': ['98']}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}; {'id': '99', 'type': 'call', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'sorted_keys'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '103', 'type': 'argument_list', 'children': ['104']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '105', 'type': 'if_statement', 'children': ['106', '117']}; {'id': '106', 'type': 'boolean_operator', 'children': ['107', '111'], 'value': 'and'}; {'id': '107', 'type': '()', 'children': ['108']}; {'id': '108', 'type': 'comparison_operator', 'children': ['109', '110'], 'value': 'in'}; {'id': '109', 'type': 'string', 'children': [], 'value': "'dur'"}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '111', 'type': '()', 'children': ['112']}; {'id': '112', 'type': 'comparison_operator', 'children': ['113', '114'], 'value': 'not'}; {'id': '113', 'type': 'string', 'children': [], 'value': "'dur'"}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'keys_ignored_'}; {'id': '117', 'type': 'block', 'children': ['118']}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}; {'id': '119', 'type': 'call', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'sorted_keys'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '123', 'type': 'argument_list', 'children': ['124']}; {'id': '124', 'type': 'string', 'children': [], 'value': "'dur'"}; {'id': '125', 'type': 'return_statement', 'children': ['126']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'sorted_keys'}
def _sorted_keys(self, keys): sorted_keys = [] if ('epoch' in keys) and ('epoch' not in self.keys_ignored_): sorted_keys.append('epoch') for key in sorted(keys): if not ( (key in ('epoch', 'dur')) or (key in self.keys_ignored_) or key.endswith('_best') or key.startswith('event_') ): sorted_keys.append(key) for key in sorted(keys): if key.startswith('event_') and (key not in self.keys_ignored_): sorted_keys.append(key) if ('dur' in keys) and ('dur' not in self.keys_ignored_): sorted_keys.append('dur') return sorted_keys
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_values'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'by'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '8', 'type': 'True', 'children': []}; {'id': '9', 'type': 'block', 'children': ['10', '23', '42']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '17']}; {'id': '11', 'type': 'not_operator', 'children': ['12']}; {'id': '12', 'type': 'call', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'by'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'by'}; {'id': '21', 'type': 'list', 'children': ['22'], 'value': '[by, ]'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'by'}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'by'}; {'id': '26', 'type': 'list_comprehension', 'children': ['27', '39']}; {'id': '27', 'type': 'conditional_expression', 'children': ['28', '32', '38'], 'value': 'if'}; {'id': '28', 'type': 'call', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'it'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '32', 'type': 'call', 'children': ['33', '36']}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'inspect'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'isfunction'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'it'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'it'}; {'id': '39', 'type': 'for_in_clause', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'it'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'by'}; {'id': '42', 'type': 'return_statement', 'children': ['43']}; {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'SortedCollectionExpr'}; {'id': '45', 'type': 'argument_list', 'children': ['46', '47', '50', '53']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '47', 'type': 'keyword_argument', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': '_sorted_fields'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'by'}; {'id': '50', 'type': 'keyword_argument', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': '_ascending'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': '_schema'}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': '_schema'}
def sort_values(expr, by, ascending=True): if not isinstance(by, list): by = [by, ] by = [it(expr) if inspect.isfunction(it) else it for it in by] return SortedCollectionExpr(expr, _sorted_fields=by, _ascending=ascending, _schema=expr._schema)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'reshuffle'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'by'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '13', 'type': 'True', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '23', '32', '47']}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'by'}; {'id': '18', 'type': 'boolean_operator', 'children': ['19', '20'], 'value': 'or'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'by'}; {'id': '20', 'type': 'call', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'RandomScalar'}; {'id': '22', 'type': 'argument_list', 'children': []}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'grouped'}; {'id': '26', 'type': 'call', 'children': ['27', '30']}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'groupby'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'by'}; {'id': '32', 'type': 'if_statement', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '34', 'type': 'block', 'children': ['35']}; {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'grouped'}; {'id': '38', 'type': 'call', 'children': ['39', '42']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'grouped'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'sort_values'}; {'id': '42', 'type': 'argument_list', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '47', 'type': 'return_statement', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'ReshuffledCollectionExpr'}; {'id': '50', 'type': 'argument_list', 'children': ['51', '54']}; {'id': '51', 'type': 'keyword_argument', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': '_input'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'grouped'}; {'id': '54', 'type': 'keyword_argument', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': '_schema'}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': '_schema'}
def reshuffle(expr, by=None, sort=None, ascending=True): by = by or RandomScalar() grouped = expr.groupby(by) if sort: grouped = grouped.sort_values(sort, ascending=ascending) return ReshuffledCollectionExpr(_input=grouped, _schema=expr._schema)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'cumsum'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '10', 'type': 'True', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'unique'}; {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'preceding'}; {'id': '16', 'type': 'None', 'children': []}; {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'following'}; {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'block', 'children': ['21', '44']}; {'id': '21', 'type': 'if_statement', 'children': ['22', '29', '36']}; {'id': '22', 'type': 'comparison_operator', 'children': ['23', '26'], 'value': '=='}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': '_data_type'}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'types'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'boolean'}; {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'output_type'}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'types'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'int64'}; {'id': '36', 'type': 'else_clause', 'children': ['37']}; {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}; {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'output_type'}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': '_data_type'}; {'id': '44', 'type': 'return_statement', 'children': ['45']}; {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': '_cumulative_op'}; {'id': '47', 'type': 'argument_list', 'children': ['48', '49', '50', '53', '56', '59', '62', '65']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'CumSum'}; {'id': '50', 'type': 'keyword_argument', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'unique'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'unique'}; {'id': '59', 'type': 'keyword_argument', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'preceding'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'preceding'}; {'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'following'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'following'}; {'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'data_type'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'output_type'}
def cumsum(expr, sort=None, ascending=True, unique=False, preceding=None, following=None): if expr._data_type == types.boolean: output_type = types.int64 else: output_type = expr._data_type return _cumulative_op(expr, CumSum, sort=sort, ascending=ascending, unique=unique, preceding=preceding, following=following, data_type=output_type)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'cummax'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '10', 'type': 'True', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'unique'}; {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'preceding'}; {'id': '16', 'type': 'None', 'children': []}; {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'following'}; {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'block', 'children': ['21']}; {'id': '21', 'type': 'return_statement', 'children': ['22']}; {'id': '22', 'type': 'call', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': '_cumulative_op'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '26', '27', '30', '33', '36', '39']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'CumMax'}; {'id': '27', 'type': 'keyword_argument', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'unique'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'unique'}; {'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'preceding'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'preceding'}; {'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'following'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'following'}
def cummax(expr, sort=None, ascending=True, unique=False, preceding=None, following=None): return _cumulative_op(expr, CumMax, sort=sort, ascending=ascending, unique=unique, preceding=preceding, following=following)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'cummin'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '10', 'type': 'True', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'unique'}; {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'preceding'}; {'id': '16', 'type': 'None', 'children': []}; {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'following'}; {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'block', 'children': ['21']}; {'id': '21', 'type': 'return_statement', 'children': ['22']}; {'id': '22', 'type': 'call', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': '_cumulative_op'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '26', '27', '30', '33', '36', '39']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'CumMin'}; {'id': '27', 'type': 'keyword_argument', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'unique'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'unique'}; {'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'preceding'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'preceding'}; {'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'following'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'following'}
def cummin(expr, sort=None, ascending=True, unique=False, preceding=None, following=None): return _cumulative_op(expr, CumMin, sort=sort, ascending=ascending, unique=unique, preceding=preceding, following=following)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'cummean'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '10', 'type': 'True', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'unique'}; {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'preceding'}; {'id': '16', 'type': 'None', 'children': []}; {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'following'}; {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'block', 'children': ['21', '28']}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'data_type'}; {'id': '24', 'type': 'call', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': '_stats_type'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '28', 'type': 'return_statement', 'children': ['29']}; {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': '_cumulative_op'}; {'id': '31', 'type': 'argument_list', 'children': ['32', '33', '34', '37', '40', '43', '46', '49']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'CumMean'}; {'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'unique'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'unique'}; {'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'preceding'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'preceding'}; {'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'following'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'following'}; {'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'data_type'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'data_type'}
def cummean(expr, sort=None, ascending=True, unique=False, preceding=None, following=None): data_type = _stats_type(expr) return _cumulative_op(expr, CumMean, sort=sort, ascending=ascending, unique=unique, preceding=preceding, following=following, data_type=data_type)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'cummedian'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '10', 'type': 'True', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'unique'}; {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'preceding'}; {'id': '16', 'type': 'None', 'children': []}; {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'following'}; {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'block', 'children': ['21', '28']}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'data_type'}; {'id': '24', 'type': 'call', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': '_stats_type'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '28', 'type': 'return_statement', 'children': ['29']}; {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': '_cumulative_op'}; {'id': '31', 'type': 'argument_list', 'children': ['32', '33', '34', '37', '40', '43', '46', '49']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'CumMedian'}; {'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'unique'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'unique'}; {'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'preceding'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'preceding'}; {'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'following'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'following'}; {'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'data_type'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'data_type'}
def cummedian(expr, sort=None, ascending=True, unique=False, preceding=None, following=None): data_type = _stats_type(expr) return _cumulative_op(expr, CumMedian, sort=sort, ascending=ascending, unique=unique, preceding=preceding, following=following, data_type=data_type)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'cumcount'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '10', 'type': 'True', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'unique'}; {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'preceding'}; {'id': '16', 'type': 'None', 'children': []}; {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'following'}; {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'block', 'children': ['21', '27']}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'data_type'}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'types'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'int64'}; {'id': '27', 'type': 'return_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': '_cumulative_op'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '32', '33', '36', '39', '42', '45', '48']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'CumCount'}; {'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'unique'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'unique'}; {'id': '42', 'type': 'keyword_argument', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'preceding'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'preceding'}; {'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'following'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'following'}; {'id': '48', 'type': 'keyword_argument', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'data_type'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'data_type'}
def cumcount(expr, sort=None, ascending=True, unique=False, preceding=None, following=None): data_type = types.int64 return _cumulative_op(expr, CumCount, sort=sort, ascending=ascending, unique=unique, preceding=preceding, following=following, data_type=data_type)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'cumstd'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '10', 'type': 'True', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'unique'}; {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'preceding'}; {'id': '16', 'type': 'None', 'children': []}; {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'following'}; {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'block', 'children': ['21', '28']}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'data_type'}; {'id': '24', 'type': 'call', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': '_stats_type'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '28', 'type': 'return_statement', 'children': ['29']}; {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': '_cumulative_op'}; {'id': '31', 'type': 'argument_list', 'children': ['32', '33', '34', '37', '40', '43', '46', '49']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'CumStd'}; {'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'unique'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'unique'}; {'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'preceding'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'preceding'}; {'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'following'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'following'}; {'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'data_type'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'data_type'}
def cumstd(expr, sort=None, ascending=True, unique=False, preceding=None, following=None): data_type = _stats_type(expr) return _cumulative_op(expr, CumStd, sort=sort, ascending=ascending, unique=unique, preceding=preceding, following=following, data_type=data_type)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'nth_value'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'nth'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'skip_nulls'}; {'id': '8', 'type': 'False', 'children': []}; {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '14', 'type': 'True', 'children': []}; {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'return_statement', 'children': ['17']}; {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': '_cumulative_op'}; {'id': '19', 'type': 'argument_list', 'children': ['20', '21', '22', '27', '30', '33', '36']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'NthValue'}; {'id': '22', 'type': 'keyword_argument', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'data_type'}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': '_data_type'}; {'id': '27', 'type': 'keyword_argument', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': '_nth'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'nth'}; {'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': '_skip_nulls'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'skip_nulls'}
def nth_value(expr, nth, skip_nulls=False, sort=None, ascending=True): return _cumulative_op(expr, NthValue, data_type=expr._data_type, sort=sort, ascending=ascending, _nth=nth, _skip_nulls=skip_nulls)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'rank'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '10', 'type': 'True', 'children': []}; {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'return_statement', 'children': ['13']}; {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '_rank_op'}; {'id': '15', 'type': 'argument_list', 'children': ['16', '17', '18', '21', '24']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'Rank'}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'types'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'int64'}; {'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'ascending'}
def rank(expr, sort=None, ascending=True): return _rank_op(expr, Rank, types.int64, sort=sort, ascending=ascending)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'dense_rank'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '10', 'type': 'True', 'children': []}; {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'return_statement', 'children': ['13']}; {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '_rank_op'}; {'id': '15', 'type': 'argument_list', 'children': ['16', '17', '18', '21', '24']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'DenseRank'}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'types'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'int64'}; {'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'ascending'}
def dense_rank(expr, sort=None, ascending=True): return _rank_op(expr, DenseRank, types.int64, sort=sort, ascending=ascending)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'percent_rank'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '10', 'type': 'True', 'children': []}; {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'return_statement', 'children': ['13']}; {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '_rank_op'}; {'id': '15', 'type': 'argument_list', 'children': ['16', '17', '18', '21', '24']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'PercentRank'}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'types'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'float64'}; {'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'ascending'}
def percent_rank(expr, sort=None, ascending=True): return _rank_op(expr, PercentRank, types.float64, sort=sort, ascending=ascending)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'row_number'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '10', 'type': 'True', 'children': []}; {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'return_statement', 'children': ['13']}; {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '_rank_op'}; {'id': '15', 'type': 'argument_list', 'children': ['16', '17', '18', '21', '24']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'RowNumber'}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'types'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'int64'}; {'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'ascending'}
def row_number(expr, sort=None, ascending=True): return _rank_op(expr, RowNumber, types.int64, sort=sort, ascending=ascending)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'qcut'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'bins'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '8', 'type': 'False', 'children': []}; {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '14', 'type': 'True', 'children': []}; {'id': '15', 'type': 'block', 'children': ['16', '28']}; {'id': '16', 'type': 'if_statement', 'children': ['17', '22']}; {'id': '17', 'type': 'boolean_operator', 'children': ['18', '21'], 'value': 'or'}; {'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': 'is'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '20', 'type': 'None', 'children': []}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '22', 'type': 'block', 'children': ['23']}; {'id': '23', 'type': 'raise_statement', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'NotImplementedError'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}; {'id': '27', 'type': 'string', 'children': [], 'value': "'Showing bins or customizing labels not supported'"}; {'id': '28', 'type': 'return_statement', 'children': ['29']}; {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': '_rank_op'}; {'id': '31', 'type': 'argument_list', 'children': ['32', '33', '34', '37', '40', '43']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'QCut'}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'types'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'int64'}; {'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': '_bins'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'bins'}
def qcut(expr, bins, labels=False, sort=None, ascending=True): if labels is None or labels: raise NotImplementedError('Showing bins or customizing labels not supported') return _rank_op(expr, QCut, types.int64, sort=sort, ascending=ascending, _bins=bins)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'cume_dist'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '10', 'type': 'True', 'children': []}; {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'return_statement', 'children': ['13']}; {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '_rank_op'}; {'id': '15', 'type': 'argument_list', 'children': ['16', '17', '18', '21', '24']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'CumeDist'}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'types'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'float64'}; {'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'ascending'}
def cume_dist(expr, sort=None, ascending=True): return _rank_op(expr, CumeDist, types.float64, sort=sort, ascending=ascending)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'lag'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '8', 'type': 'None', 'children': []}; {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '14', 'type': 'True', 'children': []}; {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'return_statement', 'children': ['17']}; {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': '_shift_op'}; {'id': '19', 'type': 'argument_list', 'children': ['20', '21', '22', '23', '26', '29']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'Lag'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '23', 'type': 'keyword_argument', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '29', 'type': 'keyword_argument', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'ascending'}
def lag(expr, offset, default=None, sort=None, ascending=True): return _shift_op(expr, Lag, offset, default=default, sort=sort, ascending=ascending)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'lead'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '8', 'type': 'None', 'children': []}; {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '14', 'type': 'True', 'children': []}; {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'return_statement', 'children': ['17']}; {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': '_shift_op'}; {'id': '19', 'type': 'argument_list', 'children': ['20', '21', '22', '23', '26', '29']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'Lead'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '23', 'type': 'keyword_argument', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '29', 'type': 'keyword_argument', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'ascending'}
def lead(expr, offset, default=None, sort=None, ascending=True): return _shift_op(expr, Lead, offset, default=default, sort=sort, ascending=ascending)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'value_counts'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '7', 'type': 'True', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '10', 'type': 'False', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'dropna'}; {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '23', '33']}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '18', 'type': 'list', 'children': ['19', '22'], 'value': "[expr.name, 'count']"}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '22', 'type': 'string', 'children': [], 'value': "'count'"}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'typos'}; {'id': '26', 'type': 'list', 'children': ['27', '30'], 'value': '[expr.dtype, types.int64]'}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'types'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'int64'}; {'id': '33', 'type': 'return_statement', 'children': ['34']}; {'id': '34', 'type': 'call', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'ValueCounts'}; {'id': '36', 'type': 'argument_list', 'children': ['37', '40', '49', '52', '55']}; {'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': '_input'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': '_schema'}; {'id': '42', 'type': 'call', 'children': ['43', '46']}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'Schema'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'from_lists'}; {'id': '46', 'type': 'argument_list', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'typos'}; {'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': '_sort'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': '_ascending'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': '_dropna'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'dropna'}
def value_counts(expr, sort=True, ascending=False, dropna=False): names = [expr.name, 'count'] typos = [expr.dtype, types.int64] return ValueCounts(_input=expr, _schema=Schema.from_lists(names, typos), _sort=sort, _ascending=ascending, _dropna=dropna)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'last'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '7', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '8', 'type': 'dictionary_splat_pattern', 'children': ['9']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '10', 'type': 'block', 'children': ['11']}; {'id': '11', 'type': 'return_statement', 'children': ['12']}; {'id': '12', 'type': 'call', 'children': ['13', '16']}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'collection_instance'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}; {'id': '17', 'type': 'call', 'children': ['18', '42']}; {'id': '18', 'type': 'attribute', 'children': ['19', '41']}; {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'db_adapter'}; {'id': '23', 'type': 'argument_list', 'children': ['24', '32']}; {'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'db_name'}; {'id': '26', 'type': 'call', 'children': ['27', '30']}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}; {'id': '31', 'type': 'string', 'children': [], 'value': "'db'"}; {'id': '32', 'type': 'keyword_argument', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'role'}; {'id': '34', 'type': 'call', 'children': ['35', '38']}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '38', 'type': 'argument_list', 'children': ['39', '40']}; {'id': '39', 'type': 'string', 'children': [], 'value': "'role'"}; {'id': '40', 'type': 'string', 'children': [], 'value': "'replica'"}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'select'}; {'id': '42', 'type': 'argument_list', 'children': ['43', '46', '49']}; {'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'where'}; {'id': '45', 'type': 'string', 'children': [], 'value': "'created_at IS NOT NULL'"}; {'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '48', 'type': 'string', 'children': [], 'value': "'created_at DESC'"}; {'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'limit'}
def last(self, limit=1, **kwargs): return self.collection_instance( self.db_adapter( db_name=kwargs.get('db'), role=kwargs.get('role', 'replica') ).select( where='created_at IS NOT NULL', order='created_at DESC', limit=limit ) )
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_compile_itemsort'}; {'id': '3', 'type': 'parameters', 'children': []}; {'id': '4', 'type': 'block', 'children': ['5', '7', '16', '27', '38', '50', '60', '79', '106']}; {'id': '5', 'type': 'expression_statement', 'children': ['6']}; {'id': '6', 'type': 'string', 'children': [], 'value': "'''return sort function of mappings'''"}; {'id': '7', 'type': 'function_definition', 'children': ['8', '9', '11']}; {'id': '8', 'type': 'function_name', 'children': [], 'value': 'is_extra'}; {'id': '9', 'type': 'parameters', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'key_'}; {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'return_statement', 'children': ['13']}; {'id': '13', 'type': 'comparison_operator', 'children': ['14', '15'], 'value': 'is'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'key_'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'Extra'}; {'id': '16', 'type': 'function_definition', 'children': ['17', '18', '20']}; {'id': '17', 'type': 'function_name', 'children': [], 'value': 'is_remove'}; {'id': '18', 'type': 'parameters', 'children': ['19']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'key_'}; {'id': '20', 'type': 'block', 'children': ['21']}; {'id': '21', 'type': 'return_statement', 'children': ['22']}; {'id': '22', 'type': 'call', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'key_'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'Remove'}; {'id': '27', 'type': 'function_definition', 'children': ['28', '29', '31']}; {'id': '28', 'type': 'function_name', 'children': [], 'value': 'is_marker'}; {'id': '29', 'type': 'parameters', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'key_'}; {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'return_statement', 'children': ['33']}; {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '35', 'type': 'argument_list', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'key_'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'Marker'}; {'id': '38', 'type': 'function_definition', 'children': ['39', '40', '42']}; {'id': '39', 'type': 'function_name', 'children': [], 'value': 'is_type'}; {'id': '40', 'type': 'parameters', 'children': ['41']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'key_'}; {'id': '42', 'type': 'block', 'children': ['43']}; {'id': '43', 'type': 'return_statement', 'children': ['44']}; {'id': '44', 'type': 'call', 'children': ['45', '48']}; {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'inspect'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'isclass'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'key_'}; {'id': '50', 'type': 'function_definition', 'children': ['51', '52', '54']}; {'id': '51', 'type': 'function_name', 'children': [], 'value': 'is_callable'}; {'id': '52', 'type': 'parameters', 'children': ['53']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'key_'}; {'id': '54', 'type': 'block', 'children': ['55']}; {'id': '55', 'type': 'return_statement', 'children': ['56']}; {'id': '56', 'type': 'call', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'callable'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'key_'}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}; {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'priority'}; {'id': '63', 'type': 'list', 'children': ['64', '67', '70', '73', '76'], 'value': '[(1, is_remove),\n (2, is_marker),\n (4, is_type),\n (3, is_callable),\n (5, is_extra)]'}; {'id': '64', 'type': 'tuple', 'children': ['65', '66']}; {'id': '65', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'is_remove'}; {'id': '67', 'type': 'tuple', 'children': ['68', '69']}; {'id': '68', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'is_marker'}; {'id': '70', 'type': 'tuple', 'children': ['71', '72']}; {'id': '71', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'is_type'}; {'id': '73', 'type': 'tuple', 'children': ['74', '75']}; {'id': '74', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'is_callable'}; {'id': '76', 'type': 'tuple', 'children': ['77', '78']}; {'id': '77', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'is_extra'}; {'id': '79', 'type': 'function_definition', 'children': ['80', '81', '83']}; {'id': '80', 'type': 'function_name', 'children': [], 'value': 'item_priority'}; {'id': '81', 'type': 'parameters', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'item_'}; {'id': '83', 'type': 'block', 'children': ['84', '90', '104']}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}; {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'key_'}; {'id': '87', 'type': 'subscript', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'item_'}; {'id': '89', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '90', 'type': 'for_statement', 'children': ['91', '94', '95']}; {'id': '91', 'type': 'pattern_list', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'check_'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'priority'}; {'id': '95', 'type': 'block', 'children': ['96']}; {'id': '96', 'type': 'if_statement', 'children': ['97', '101']}; {'id': '97', 'type': 'call', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'check_'}; {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'key_'}; {'id': '101', 'type': 'block', 'children': ['102']}; {'id': '102', 'type': 'return_statement', 'children': ['103']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '104', 'type': 'return_statement', 'children': ['105']}; {'id': '105', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '106', 'type': 'return_statement', 'children': ['107']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'item_priority'}
def _compile_itemsort(): '''return sort function of mappings''' def is_extra(key_): return key_ is Extra def is_remove(key_): return isinstance(key_, Remove) def is_marker(key_): return isinstance(key_, Marker) def is_type(key_): return inspect.isclass(key_) def is_callable(key_): return callable(key_) priority = [(1, is_remove), (2, is_marker), (4, is_type), (3, is_callable), (5, is_extra)] def item_priority(item_): key_ = item_[0] for i, check_ in priority: if check_(key_): return i return 0 return item_priority
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_compile_dict'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'schema'}; {'id': '6', 'type': 'block', 'children': ['7', '19', '23', '27', '83', '308']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'base_validate'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': '_compile_mapping'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'schema'}; {'id': '16', 'type': 'keyword_argument', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'invalid_msg'}; {'id': '18', 'type': 'string', 'children': [], 'value': "'dictionary value'"}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'groups_of_exclusion'}; {'id': '22', 'type': 'dictionary', 'children': []}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'groups_of_inclusion'}; {'id': '26', 'type': 'dictionary', 'children': []}; {'id': '27', 'type': 'for_statement', 'children': ['28', '29', '30']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'schema'}; {'id': '30', 'type': 'block', 'children': ['31']}; {'id': '31', 'type': 'if_statement', 'children': ['32', '37', '57']}; {'id': '32', 'type': 'call', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'Exclusive'}; {'id': '37', 'type': 'block', 'children': ['38', '50']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}; {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'groups_of_exclusion'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'setdefault'}; {'id': '45', 'type': 'argument_list', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'group_of_exclusion'}; {'id': '49', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}; {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '57', 'type': 'elif_clause', 'children': ['58', '63']}; {'id': '58', 'type': 'call', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '60', 'type': 'argument_list', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'Inclusive'}; {'id': '63', 'type': 'block', 'children': ['64', '76']}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}; {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'groups_of_inclusion'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'setdefault'}; {'id': '71', 'type': 'argument_list', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'group_of_inclusion'}; {'id': '75', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}; {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '83', 'type': 'function_definition', 'children': ['84', '85', '88']}; {'id': '84', 'type': 'function_name', 'children': [], 'value': 'validate_dict'}; {'id': '85', 'type': 'parameters', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '88', 'type': 'block', 'children': ['89', '105', '109', '184', '194', '280', '290', '298']}; {'id': '89', 'type': 'if_statement', 'children': ['90', '96']}; {'id': '90', 'type': 'not_operator', 'children': ['91']}; {'id': '91', 'type': 'call', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '93', 'type': 'argument_list', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '96', 'type': 'block', 'children': ['97']}; {'id': '97', 'type': 'raise_statement', 'children': ['98']}; {'id': '98', 'type': 'call', 'children': ['99', '102']}; {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'er'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'DictInvalid'}; {'id': '102', 'type': 'argument_list', 'children': ['103', '104']}; {'id': '103', 'type': 'string', 'children': [], 'value': "'expected a dictionary'"}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '108', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '109', 'type': 'for_statement', 'children': ['110', '113', '118']}; {'id': '110', 'type': 'pattern_list', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '113', 'type': 'call', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'groups_of_exclusion'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '117', 'type': 'argument_list', 'children': []}; {'id': '118', 'type': 'block', 'children': ['119', '123']}; {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'exists'}; {'id': '122', 'type': 'False', 'children': []}; {'id': '123', 'type': 'for_statement', 'children': ['124', '125', '126']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'exclusive'}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '126', 'type': 'block', 'children': ['127']}; {'id': '127', 'type': 'if_statement', 'children': ['128', '133']}; {'id': '128', 'type': 'comparison_operator', 'children': ['129', '132'], 'value': 'in'}; {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'exclusive'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'schema'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '133', 'type': 'block', 'children': ['134', '180']}; {'id': '134', 'type': 'if_statement', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'exists'}; {'id': '136', 'type': 'block', 'children': ['137', '156', '166', '179']}; {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'assignment', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '140', 'type': 'conditional_expression', 'children': ['141', '144', '153'], 'value': 'if'}; {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'exclusive'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '144', 'type': 'boolean_operator', 'children': ['145', '150'], 'value': 'and'}; {'id': '145', 'type': 'call', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '147', 'type': 'argument_list', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'exclusive'}; {'id': '149', 'type': 'string', 'children': [], 'value': "'msg'"}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'exclusive'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '153', 'type': 'binary_operator', 'children': ['154', '155'], 'value': '%'}; {'id': '154', 'type': 'string', 'children': [], 'value': '"two or more values in the same group of exclusion \'%s\'"'}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}; {'id': '157', 'type': 'assignment', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'next_path'}; {'id': '159', 'type': 'binary_operator', 'children': ['160', '161'], 'value': '+'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '161', 'type': 'list', 'children': ['162'], 'value': '[VirtualPathComponent(label)]'}; {'id': '162', 'type': 'call', 'children': ['163', '164']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'VirtualPathComponent'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}; {'id': '167', 'type': 'call', 'children': ['168', '171']}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '171', 'type': 'argument_list', 'children': ['172']}; {'id': '172', 'type': 'call', 'children': ['173', '176']}; {'id': '173', 'type': 'attribute', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'er'}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'ExclusiveInvalid'}; {'id': '176', 'type': 'argument_list', 'children': ['177', '178']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'next_path'}; {'id': '179', 'type': 'break_statement', 'children': []}; {'id': '180', 'type': 'expression_statement', 'children': ['181']}; {'id': '181', 'type': 'assignment', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'exists'}; {'id': '183', 'type': 'True', 'children': []}; {'id': '184', 'type': 'if_statement', 'children': ['185', '186']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '186', 'type': 'block', 'children': ['187']}; {'id': '187', 'type': 'raise_statement', 'children': ['188']}; {'id': '188', 'type': 'call', 'children': ['189', '192']}; {'id': '189', 'type': 'attribute', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'er'}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'MultipleInvalid'}; {'id': '192', 'type': 'argument_list', 'children': ['193']}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '194', 'type': 'for_statement', 'children': ['195', '198', '203']}; {'id': '195', 'type': 'pattern_list', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '198', 'type': 'call', 'children': ['199', '202']}; {'id': '199', 'type': 'attribute', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'groups_of_inclusion'}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '202', 'type': 'argument_list', 'children': []}; {'id': '203', 'type': 'block', 'children': ['204', '216']}; {'id': '204', 'type': 'expression_statement', 'children': ['205']}; {'id': '205', 'type': 'assignment', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'included'}; {'id': '207', 'type': 'list_comprehension', 'children': ['208', '213']}; {'id': '208', 'type': 'comparison_operator', 'children': ['209', '212'], 'value': 'in'}; {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'schema'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '213', 'type': 'for_in_clause', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '216', 'type': 'if_statement', 'children': ['217', '227']}; {'id': '217', 'type': 'boolean_operator', 'children': ['218', '222'], 'value': 'and'}; {'id': '218', 'type': 'call', 'children': ['219', '220']}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'any'}; {'id': '220', 'type': 'argument_list', 'children': ['221']}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'included'}; {'id': '222', 'type': 'not_operator', 'children': ['223']}; {'id': '223', 'type': 'call', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '225', 'type': 'argument_list', 'children': ['226']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'included'}; {'id': '227', 'type': 'block', 'children': ['228', '234', '256', '266', '279']}; {'id': '228', 'type': 'expression_statement', 'children': ['229']}; {'id': '229', 'type': 'assignment', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '231', 'type': 'binary_operator', 'children': ['232', '233'], 'value': '%'}; {'id': '232', 'type': 'string', 'children': [], 'value': '"some but not all values in the same group of inclusion \'%s\'"'}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '234', 'type': 'for_statement', 'children': ['235', '236', '237']}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '237', 'type': 'block', 'children': ['238']}; {'id': '238', 'type': 'if_statement', 'children': ['239', '248']}; {'id': '239', 'type': 'boolean_operator', 'children': ['240', '245'], 'value': 'and'}; {'id': '240', 'type': 'call', 'children': ['241', '242']}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '242', 'type': 'argument_list', 'children': ['243', '244']}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '244', 'type': 'string', 'children': [], 'value': "'msg'"}; {'id': '245', 'type': 'attribute', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '248', 'type': 'block', 'children': ['249', '255']}; {'id': '249', 'type': 'expression_statement', 'children': ['250']}; {'id': '250', 'type': 'assignment', 'children': ['251', '252']}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '252', 'type': 'attribute', 'children': ['253', '254']}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '255', 'type': 'break_statement', 'children': []}; {'id': '256', 'type': 'expression_statement', 'children': ['257']}; {'id': '257', 'type': 'assignment', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'next_path'}; {'id': '259', 'type': 'binary_operator', 'children': ['260', '261'], 'value': '+'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '261', 'type': 'list', 'children': ['262'], 'value': '[VirtualPathComponent(label)]'}; {'id': '262', 'type': 'call', 'children': ['263', '264']}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'VirtualPathComponent'}; {'id': '264', 'type': 'argument_list', 'children': ['265']}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '266', 'type': 'expression_statement', 'children': ['267']}; {'id': '267', 'type': 'call', 'children': ['268', '271']}; {'id': '268', 'type': 'attribute', 'children': ['269', '270']}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '271', 'type': 'argument_list', 'children': ['272']}; {'id': '272', 'type': 'call', 'children': ['273', '276']}; {'id': '273', 'type': 'attribute', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'er'}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'InclusiveInvalid'}; {'id': '276', 'type': 'argument_list', 'children': ['277', '278']}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'next_path'}; {'id': '279', 'type': 'break_statement', 'children': []}; {'id': '280', 'type': 'if_statement', 'children': ['281', '282']}; {'id': '281', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '282', 'type': 'block', 'children': ['283']}; {'id': '283', 'type': 'raise_statement', 'children': ['284']}; {'id': '284', 'type': 'call', 'children': ['285', '288']}; {'id': '285', 'type': 'attribute', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'er'}; {'id': '287', 'type': 'identifier', 'children': [], 'value': 'MultipleInvalid'}; {'id': '288', 'type': 'argument_list', 'children': ['289']}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '290', 'type': 'expression_statement', 'children': ['291']}; {'id': '291', 'type': 'assignment', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '293', 'type': 'call', 'children': ['294', '297']}; {'id': '294', 'type': 'attribute', 'children': ['295', '296']}; {'id': '295', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': '__class__'}; {'id': '297', 'type': 'argument_list', 'children': []}; {'id': '298', 'type': 'return_statement', 'children': ['299']}; {'id': '299', 'type': 'call', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'base_validate'}; {'id': '301', 'type': 'argument_list', 'children': ['302', '303', '307']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '303', 'type': 'call', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'iteritems'}; {'id': '305', 'type': 'argument_list', 'children': ['306']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '307', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '308', 'type': 'return_statement', 'children': ['309']}; {'id': '309', 'type': 'identifier', 'children': [], 'value': 'validate_dict'}
def _compile_dict(self, schema): base_validate = self._compile_mapping( schema, invalid_msg='dictionary value') groups_of_exclusion = {} groups_of_inclusion = {} for node in schema: if isinstance(node, Exclusive): g = groups_of_exclusion.setdefault(node.group_of_exclusion, []) g.append(node) elif isinstance(node, Inclusive): g = groups_of_inclusion.setdefault(node.group_of_inclusion, []) g.append(node) def validate_dict(path, data): if not isinstance(data, dict): raise er.DictInvalid('expected a dictionary', path) errors = [] for label, group in groups_of_exclusion.items(): exists = False for exclusive in group: if exclusive.schema in data: if exists: msg = exclusive.msg if hasattr(exclusive, 'msg') and exclusive.msg else \ "two or more values in the same group of exclusion '%s'" % label next_path = path + [VirtualPathComponent(label)] errors.append(er.ExclusiveInvalid(msg, next_path)) break exists = True if errors: raise er.MultipleInvalid(errors) for label, group in groups_of_inclusion.items(): included = [node.schema in data for node in group] if any(included) and not all(included): msg = "some but not all values in the same group of inclusion '%s'" % label for g in group: if hasattr(g, 'msg') and g.msg: msg = g.msg break next_path = path + [VirtualPathComponent(label)] errors.append(er.InclusiveInvalid(msg, next_path)) break if errors: raise er.MultipleInvalid(errors) out = data.__class__() return base_validate(path, iteritems(data), out) return validate_dict
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'to_list'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '6', 'type': 'block', 'children': ['7', '37', '57', '72', '115']}; {'id': '7', 'type': 'if_statement', 'children': ['8', '11']}; {'id': '8', 'type': 'comparison_operator', 'children': ['9', '10'], 'value': 'is'}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'if_statement', 'children': ['13', '19', '27']}; {'id': '13', 'type': 'not_operator', 'children': ['14']}; {'id': '14', 'type': 'call', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '19', 'type': 'block', 'children': ['20']}; {'id': '20', 'type': 'raise_statement', 'children': ['21']}; {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'binary_operator', 'children': ['25', '26'], 'value': '%'}; {'id': '25', 'type': 'string', 'children': [], 'value': "'length must be an int, not %r'"}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '27', 'type': 'elif_clause', 'children': ['28', '31']}; {'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': '<'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '30', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'raise_statement', 'children': ['33']}; {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'string', 'children': [], 'value': "'length must be non-negative'"}; {'id': '37', 'type': 'if_statement', 'children': ['38', '47']}; {'id': '38', 'type': 'binary_operator', 'children': ['39', '44'], 'value': '&'}; {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': '_query_flags'}; {'id': '43', 'type': 'argument_list', 'children': []}; {'id': '44', 'type': 'subscript', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': '_QUERY_OPTIONS'}; {'id': '46', 'type': 'string', 'children': [], 'value': "'tailable_cursor'"}; {'id': '47', 'type': 'block', 'children': ['48']}; {'id': '48', 'type': 'raise_statement', 'children': ['49']}; {'id': '49', 'type': 'call', 'children': ['50', '55']}; {'id': '50', 'type': 'attribute', 'children': ['51', '54']}; {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'pymongo'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'InvalidOperation'}; {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'string', 'children': [], 'value': '"Can\'t call to_list on tailable cursor"'}; {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'future'}; {'id': '60', 'type': 'call', 'children': ['61', '66']}; {'id': '61', 'type': 'attribute', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': '_framework'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'get_future'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}; {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'get_io_loop'}; {'id': '71', 'type': 'argument_list', 'children': []}; {'id': '72', 'type': 'if_statement', 'children': ['73', '77', '85']}; {'id': '73', 'type': 'not_operator', 'children': ['74']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'alive'}; {'id': '77', 'type': 'block', 'children': ['78']}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}; {'id': '79', 'type': 'call', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'future'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'set_result'}; {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '85', 'type': 'else_clause', 'children': ['86']}; {'id': '86', 'type': 'block', 'children': ['87', '91']}; {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'the_list'}; {'id': '90', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '98']}; {'id': '93', 'type': 'attribute', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': '_framework'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'add_future'}; {'id': '98', 'type': 'argument_list', 'children': ['99', '104', '109', '112', '113', '114']}; {'id': '99', 'type': 'call', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'get_io_loop'}; {'id': '103', 'type': 'argument_list', 'children': []}; {'id': '104', 'type': 'call', 'children': ['105', '108']}; {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': '_get_more'}; {'id': '108', 'type': 'argument_list', 'children': []}; {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': '_to_list'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'the_list'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'future'}; {'id': '115', 'type': 'return_statement', 'children': ['116']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'future'}
def to_list(self, length): if length is not None: if not isinstance(length, int): raise TypeError('length must be an int, not %r' % length) elif length < 0: raise ValueError('length must be non-negative') if self._query_flags() & _QUERY_OPTIONS['tailable_cursor']: raise pymongo.errors.InvalidOperation( "Can't call to_list on tailable cursor") future = self._framework.get_future(self.get_io_loop()) if not self.alive: future.set_result([]) else: the_list = [] self._framework.add_future( self.get_io_loop(), self._get_more(), self._to_list, length, the_list, future) return future
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'find'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'list_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '9', 'type': 'block', 'children': ['10', '24', '37']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}; {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'cursor'}; {'id': '13', 'type': 'call', 'children': ['14', '19']}; {'id': '14', 'type': 'attribute', 'children': ['15', '18']}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'delegate'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'find'}; {'id': '19', 'type': 'argument_list', 'children': ['20', '22']}; {'id': '20', 'type': 'list_splat', 'children': ['21']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '22', 'type': 'dictionary_splat', 'children': ['23']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}; {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'grid_out_cursor'}; {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'create_class_with_framework'}; {'id': '29', 'type': 'argument_list', 'children': ['30', '31', '34']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'AgnosticGridOutCursor'}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': '_framework'}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': '__module__'}; {'id': '37', 'type': 'return_statement', 'children': ['38']}; {'id': '38', 'type': 'call', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'grid_out_cursor'}; {'id': '40', 'type': 'argument_list', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'cursor'}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'collection'}
def find(self, *args, **kwargs): cursor = self.delegate.find(*args, **kwargs) grid_out_cursor = create_class_with_framework( AgnosticGridOutCursor, self._framework, self.__module__) return grid_out_cursor(cursor, self.collection)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_serial_poller'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '199']}; {'id': '6', 'type': 'while_statement', 'children': ['7', '8']}; {'id': '7', 'type': 'True', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '23']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': '_next'}; {'id': '12', 'type': 'call', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}; {'id': '15', 'type': 'call', 'children': ['16', '21']}; {'id': '16', 'type': 'attribute', 'children': ['17', '20']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': '_poller'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'poll'}; {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'POLLING_FREQUENCY_MS'}; {'id': '23', 'type': 'if_statement', 'children': ['24', '33', '58', '102', '164']}; {'id': '24', 'type': 'comparison_operator', 'children': ['25', '32'], 'value': 'in'}; {'id': '25', 'type': 'call', 'children': ['26', '31']}; {'id': '26', 'type': 'attribute', 'children': ['27', '30']}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': '_halt_read_file'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'fileno'}; {'id': '31', 'type': 'argument_list', 'children': []}; {'id': '32', 'type': 'identifier', 'children': [], 'value': '_next'}; {'id': '33', 'type': 'block', 'children': ['34', '49', '57']}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}; {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '44']}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'string', 'children': [], 'value': '"Poller [{}]: halt"'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}; {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'hash'}; {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'call', 'children': ['51', '56']}; {'id': '51', 'type': 'attribute', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': '_halt_read_file'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '56', 'type': 'argument_list', 'children': []}; {'id': '57', 'type': 'break_statement', 'children': []}; {'id': '58', 'type': 'elif_clause', 'children': ['59', '68']}; {'id': '59', 'type': 'comparison_operator', 'children': ['60', '67'], 'value': 'in'}; {'id': '60', 'type': 'call', 'children': ['61', '66']}; {'id': '61', 'type': 'attribute', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': '_connection'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'fileno'}; {'id': '66', 'type': 'argument_list', 'children': []}; {'id': '67', 'type': 'identifier', 'children': [], 'value': '_next'}; {'id': '68', 'type': 'block', 'children': ['69', '84', '95']}; {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'call', 'children': ['71', '74']}; {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}; {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}; {'id': '77', 'type': 'string', 'children': [], 'value': '"Poller [{}]: interrupt"'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'call', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'hash'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}; {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '87', 'type': 'call', 'children': ['88', '93']}; {'id': '88', 'type': 'attribute', 'children': ['89', '92']}; {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': '_connection'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'read_until'}; {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'SERIAL_ACK'}; {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'call', 'children': ['97', '100']}; {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': '_interrupt_callback'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '102', 'type': 'elif_clause', 'children': ['103', '112']}; {'id': '103', 'type': 'comparison_operator', 'children': ['104', '111'], 'value': 'in'}; {'id': '104', 'type': 'call', 'children': ['105', '110']}; {'id': '105', 'type': 'attribute', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': '_send_read_file'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'fileno'}; {'id': '110', 'type': 'argument_list', 'children': []}; {'id': '111', 'type': 'identifier', 'children': [], 'value': '_next'}; {'id': '112', 'type': 'block', 'children': ['113', '122', '134', '150', '159']}; {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'call', 'children': ['115', '120']}; {'id': '115', 'type': 'attribute', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': '_send_read_file'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}; {'id': '121', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}; {'id': '123', 'type': 'assignment', 'children': ['124', '127']}; {'id': '124', 'type': 'pattern_list', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'callback'}; {'id': '127', 'type': 'call', 'children': ['128', '133']}; {'id': '128', 'type': 'attribute', 'children': ['129', '132']}; {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': '_command_queue'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '133', 'type': 'argument_list', 'children': []}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}; {'id': '135', 'type': 'call', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'call', 'children': ['141', '144']}; {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'string', 'children': [], 'value': '"Poller [{}]: send {}"'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '144', 'type': 'argument_list', 'children': ['145', '149']}; {'id': '145', 'type': 'call', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'hash'}; {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}; {'id': '151', 'type': 'assignment', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '153', 'type': 'call', 'children': ['154', '157']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': '_send_command'}; {'id': '157', 'type': 'argument_list', 'children': ['158']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '159', 'type': 'expression_statement', 'children': ['160']}; {'id': '160', 'type': 'call', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'callback'}; {'id': '162', 'type': 'argument_list', 'children': ['163']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '164', 'type': 'else_clause', 'children': ['165']}; {'id': '165', 'type': 'block', 'children': ['166', '181', '192']}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}; {'id': '167', 'type': 'call', 'children': ['168', '171']}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '171', 'type': 'argument_list', 'children': ['172']}; {'id': '172', 'type': 'call', 'children': ['173', '176']}; {'id': '173', 'type': 'attribute', 'children': ['174', '175']}; {'id': '174', 'type': 'string', 'children': [], 'value': '"Poller [{}]: updating temp"'}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '176', 'type': 'argument_list', 'children': ['177']}; {'id': '177', 'type': 'call', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'hash'}; {'id': '179', 'type': 'argument_list', 'children': ['180']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '181', 'type': 'expression_statement', 'children': ['182']}; {'id': '182', 'type': 'assignment', 'children': ['183', '184']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '184', 'type': 'call', 'children': ['185', '188']}; {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '187', 'type': 'identifier', 'children': [], 'value': '_send_command'}; {'id': '188', 'type': 'argument_list', 'children': ['189']}; {'id': '189', 'type': 'subscript', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'GCODES'}; {'id': '191', 'type': 'string', 'children': [], 'value': "'GET_PLATE_TEMP'"}; {'id': '192', 'type': 'expression_statement', 'children': ['193']}; {'id': '193', 'type': 'call', 'children': ['194', '197']}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': '_status_callback'}; {'id': '197', 'type': 'argument_list', 'children': ['198']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'call', 'children': ['201', '204']}; {'id': '201', 'type': 'attribute', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '204', 'type': 'argument_list', 'children': ['205']}; {'id': '205', 'type': 'call', 'children': ['206', '209']}; {'id': '206', 'type': 'attribute', 'children': ['207', '208']}; {'id': '207', 'type': 'string', 'children': [], 'value': '"Exiting TC poller loop [{}]"'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '209', 'type': 'argument_list', 'children': ['210']}; {'id': '210', 'type': 'call', 'children': ['211', '212']}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'hash'}; {'id': '212', 'type': 'argument_list', 'children': ['213']}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'self'}
def _serial_poller(self): while True: _next = dict(self._poller.poll(POLLING_FREQUENCY_MS)) if self._halt_read_file.fileno() in _next: log.debug("Poller [{}]: halt".format(hash(self))) self._halt_read_file.read() break elif self._connection.fileno() in _next: log.debug("Poller [{}]: interrupt".format(hash(self))) res = self._connection.read_until(SERIAL_ACK) self._interrupt_callback(res) elif self._send_read_file.fileno() in _next: self._send_read_file.read(1) command, callback = self._command_queue.get() log.debug("Poller [{}]: send {}".format(hash(self), command)) res = self._send_command(command) callback(res) else: log.debug("Poller [{}]: updating temp".format(hash(self))) res = self._send_command(GCODES['GET_PLATE_TEMP']) self._status_callback(res) log.info("Exiting TC poller loop [{}]".format(hash(self)))
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'enqueue_at'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'scheduled_time'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '7', 'type': 'list_splat_pattern', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '9', 'type': 'dictionary_splat_pattern', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '11', 'type': 'block', 'children': ['12', '22', '32', '42', '52', '62', '72', '105', '125']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '15', 'type': 'call', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '19', 'type': 'argument_list', 'children': ['20', '21']}; {'id': '20', 'type': 'string', 'children': [], 'value': "'timeout'"}; {'id': '21', 'type': 'None', 'children': []}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'job_id'}; {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '29', 'type': 'argument_list', 'children': ['30', '31']}; {'id': '30', 'type': 'string', 'children': [], 'value': "'job_id'"}; {'id': '31', 'type': 'None', 'children': []}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'job_ttl'}; {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '39', 'type': 'argument_list', 'children': ['40', '41']}; {'id': '40', 'type': 'string', 'children': [], 'value': "'job_ttl'"}; {'id': '41', 'type': 'None', 'children': []}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}; {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'job_result_ttl'}; {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '49', 'type': 'argument_list', 'children': ['50', '51']}; {'id': '50', 'type': 'string', 'children': [], 'value': "'job_result_ttl'"}; {'id': '51', 'type': 'None', 'children': []}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}; {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'job_description'}; {'id': '55', 'type': 'call', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '59', 'type': 'argument_list', 'children': ['60', '61']}; {'id': '60', 'type': 'string', 'children': [], 'value': "'job_description'"}; {'id': '61', 'type': 'None', 'children': []}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}; {'id': '63', 'type': 'assignment', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '65', 'type': 'call', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '69', 'type': 'argument_list', 'children': ['70', '71']}; {'id': '70', 'type': 'string', 'children': [], 'value': "'meta'"}; {'id': '71', 'type': 'None', 'children': []}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}; {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'job'}; {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': '_create_job'}; {'id': '79', 'type': 'argument_list', 'children': ['80', '81', '84', '87', '90', '93', '96', '99', '102']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '81', 'type': 'keyword_argument', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '84', 'type': 'keyword_argument', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '87', 'type': 'keyword_argument', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '90', 'type': 'keyword_argument', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'job_id'}; {'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'result_ttl'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'job_result_ttl'}; {'id': '96', 'type': 'keyword_argument', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'ttl'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'job_ttl'}; {'id': '99', 'type': 'keyword_argument', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'description'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'job_description'}; {'id': '102', 'type': 'keyword_argument', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'call', 'children': ['107', '112']}; {'id': '107', 'type': 'attribute', 'children': ['108', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'connection'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'zadd'}; {'id': '112', 'type': 'argument_list', 'children': ['113', '116']}; {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'scheduled_jobs_key'}; {'id': '116', 'type': 'dictionary', 'children': ['117']}; {'id': '117', 'type': 'pair', 'children': ['118', '121']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'job'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '121', 'type': 'call', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'to_unix'}; {'id': '123', 'type': 'argument_list', 'children': ['124']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'scheduled_time'}; {'id': '125', 'type': 'return_statement', 'children': ['126']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'job'}
def enqueue_at(self, scheduled_time, func, *args, **kwargs): timeout = kwargs.pop('timeout', None) job_id = kwargs.pop('job_id', None) job_ttl = kwargs.pop('job_ttl', None) job_result_ttl = kwargs.pop('job_result_ttl', None) job_description = kwargs.pop('job_description', None) meta = kwargs.pop('meta', None) job = self._create_job(func, args=args, kwargs=kwargs, timeout=timeout, id=job_id, result_ttl=job_result_ttl, ttl=job_ttl, description=job_description, meta=meta) self.connection.zadd(self.scheduled_jobs_key, {job.id: to_unix(scheduled_time)}) return job
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_getMostActiveCells'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '12', '27', '40', '57', '68', '104']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'poolingActivation'}; {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': '_poolingActivation'}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'nonZeroCells'}; {'id': '15', 'type': 'subscript', 'children': ['16', '24', '26']}; {'id': '16', 'type': 'call', 'children': ['17', '20']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'argwhere'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}; {'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': '>'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'poolingActivation'}; {'id': '23', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '24', 'type': 'slice', 'children': ['25']}; {'id': '25', 'type': 'colon', 'children': []}; {'id': '26', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'poolingActivationSubset'}; {'id': '30', 'type': 'binary_operator', 'children': ['31', '34', '35'], 'value': '+'}; {'id': '31', 'type': 'subscript', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'poolingActivation'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'nonZeroCells'}; {'id': '34', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '35', 'type': 'subscript', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': '_poolingActivation_tieBreaker'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'nonZeroCells'}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}; {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'potentialUnionSDR'}; {'id': '43', 'type': 'subscript', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'nonZeroCells'}; {'id': '45', 'type': 'subscript', 'children': ['46', '52']}; {'id': '46', 'type': 'call', 'children': ['47', '50']}; {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'argsort'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'poolingActivationSubset'}; {'id': '52', 'type': 'slice', 'children': ['53', '54', '55']}; {'id': '53', 'type': 'colon', 'children': []}; {'id': '54', 'type': 'colon', 'children': []}; {'id': '55', 'type': 'unary_operator', 'children': ['56'], 'value': '-'}; {'id': '56', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'topCells'}; {'id': '60', 'type': 'subscript', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'potentialUnionSDR'}; {'id': '62', 'type': 'slice', 'children': ['63', '64', '65']}; {'id': '63', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '64', 'type': 'colon', 'children': []}; {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': '_maxUnionCells'}; {'id': '68', 'type': 'if_statement', 'children': ['69', '79', '96']}; {'id': '69', 'type': 'comparison_operator', 'children': ['70', '76'], 'value': '>'}; {'id': '70', 'type': 'call', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}; {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': '_poolingTimer'}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': '_minHistory'}; {'id': '79', 'type': 'block', 'children': ['80']}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}; {'id': '81', 'type': 'assignment', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': '_unionSDR'}; {'id': '85', 'type': 'call', 'children': ['86', '94']}; {'id': '86', 'type': 'attribute', 'children': ['87', '93']}; {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'topCells'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'astype'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'UINT_DTYPE'}; {'id': '96', 'type': 'else_clause', 'children': ['97']}; {'id': '97', 'type': 'block', 'children': ['98']}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}; {'id': '99', 'type': 'assignment', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': '_unionSDR'}; {'id': '103', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '104', 'type': 'return_statement', 'children': ['105']}; {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': '_unionSDR'}
def _getMostActiveCells(self): poolingActivation = self._poolingActivation nonZeroCells = numpy.argwhere(poolingActivation > 0)[:,0] poolingActivationSubset = poolingActivation[nonZeroCells] + \ self._poolingActivation_tieBreaker[nonZeroCells] potentialUnionSDR = nonZeroCells[numpy.argsort(poolingActivationSubset)[::-1]] topCells = potentialUnionSDR[0: self._maxUnionCells] if max(self._poolingTimer) > self._minHistory: self._unionSDR = numpy.sort(topCells).astype(UINT_DTYPE) else: self._unionSDR = [] return self._unionSDR
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'printNetwork'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'network'}; {'id': '5', 'type': 'block', 'children': ['6', '19']}; {'id': '6', 'type': 'print_statement', 'children': ['7', '8', '18']}; {'id': '7', 'type': 'string', 'children': [], 'value': '"The network has"'}; {'id': '8', 'type': 'call', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '10', 'type': 'argument_list', 'children': ['11']}; {'id': '11', 'type': 'call', 'children': ['12', '17']}; {'id': '12', 'type': 'attribute', 'children': ['13', '16']}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'network'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'regions'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '17', 'type': 'argument_list', 'children': []}; {'id': '18', 'type': 'string', 'children': [], 'value': '"regions"'}; {'id': '19', 'type': 'for_statement', 'children': ['20', '21', '29']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '28']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'network'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'getMaxPhase'}; {'id': '28', 'type': 'argument_list', 'children': []}; {'id': '29', 'type': 'block', 'children': ['30', '33']}; {'id': '30', 'type': 'print_statement', 'children': ['31', '32']}; {'id': '31', 'type': 'string', 'children': [], 'value': '"=== Phase"'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '33', 'type': 'for_statement', 'children': ['34', '35', '42']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'region'}; {'id': '35', 'type': 'call', 'children': ['36', '41']}; {'id': '36', 'type': 'attribute', 'children': ['37', '40']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'network'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'regions'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '41', 'type': 'argument_list', 'children': []}; {'id': '42', 'type': 'block', 'children': ['43']}; {'id': '43', 'type': 'if_statement', 'children': ['44', '56']}; {'id': '44', 'type': 'comparison_operator', 'children': ['45', '55'], 'value': '=='}; {'id': '45', 'type': 'subscript', 'children': ['46', '54']}; {'id': '46', 'type': 'call', 'children': ['47', '50']}; {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'network'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'getPhases'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}; {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'region'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '54', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '56', 'type': 'block', 'children': ['57']}; {'id': '57', 'type': 'print_statement', 'children': ['58', '59']}; {'id': '58', 'type': 'string', 'children': [], 'value': '" "'}; {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'region'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'name'}
def printNetwork(network): print "The network has",len(network.regions.values()),"regions" for p in range(network.getMaxPhase()): print "=== Phase",p for region in network.regions.values(): if network.getPhases(region.name)[0] == p: print " ",region.name
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'argmaxMulti'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'groupKeys'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'assumeSorted'}; {'id': '8', 'type': 'False', 'children': []}; {'id': '9', 'type': 'block', 'children': ['10', '38', '56', '68', '85', '97']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '13']}; {'id': '11', 'type': 'not_operator', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'assumeSorted'}; {'id': '13', 'type': 'block', 'children': ['14', '26', '32']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'sorter'}; {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'argsort'}; {'id': '21', 'type': 'argument_list', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'groupKeys'}; {'id': '23', 'type': 'keyword_argument', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'kind'}; {'id': '25', 'type': 'string', 'children': [], 'value': '"mergesort"'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}; {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '29', 'type': 'subscript', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'sorter'}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'groupKeys'}; {'id': '35', 'type': 'subscript', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'groupKeys'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'sorter'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}; {'id': '39', 'type': 'assignment', 'children': ['40', '44']}; {'id': '40', 'type': 'pattern_list', 'children': ['41', '42', '43']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'indices'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'lengths'}; {'id': '44', 'type': 'call', 'children': ['45', '48']}; {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'unique'}; {'id': '48', 'type': 'argument_list', 'children': ['49', '50', '53']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'groupKeys'}; {'id': '50', 'type': 'keyword_argument', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'return_index'}; {'id': '52', 'type': 'True', 'children': []}; {'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'return_counts'}; {'id': '55', 'type': 'True', 'children': []}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}; {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'maxValues'}; {'id': '59', 'type': 'call', 'children': ['60', '65']}; {'id': '60', 'type': 'attribute', 'children': ['61', '64']}; {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'maximum'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'reduceat'}; {'id': '65', 'type': 'argument_list', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'indices'}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}; {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'allMaxIndices'}; {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'flatnonzero'}; {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'comparison_operator', 'children': ['77', '84'], 'value': '=='}; {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'repeat'}; {'id': '81', 'type': 'argument_list', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'maxValues'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'lengths'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'indices'}; {'id': '88', 'type': 'subscript', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'allMaxIndices'}; {'id': '90', 'type': 'call', 'children': ['91', '94']}; {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'searchsorted'}; {'id': '94', 'type': 'argument_list', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'allMaxIndices'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'indices'}; {'id': '97', 'type': 'if_statement', 'children': ['98', '99', '102']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'assumeSorted'}; {'id': '99', 'type': 'block', 'children': ['100']}; {'id': '100', 'type': 'return_statement', 'children': ['101']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'indices'}; {'id': '102', 'type': 'else_clause', 'children': ['103']}; {'id': '103', 'type': 'block', 'children': ['104']}; {'id': '104', 'type': 'return_statement', 'children': ['105']}; {'id': '105', 'type': 'subscript', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'sorter'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'indices'}
def argmaxMulti(a, groupKeys, assumeSorted=False): if not assumeSorted: sorter = np.argsort(groupKeys, kind="mergesort") a = a[sorter] groupKeys = groupKeys[sorter] _, indices, lengths = np.unique(groupKeys, return_index=True, return_counts=True) maxValues = np.maximum.reduceat(a, indices) allMaxIndices = np.flatnonzero(np.repeat(maxValues, lengths) == a) indices = allMaxIndices[np.searchsorted(allMaxIndices, indices)] if assumeSorted: return indices else: return sorter[indices]
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'getAllCellsInColumns'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'cellsPerColumn'}; {'id': '6', 'type': 'block', 'children': ['7']}; {'id': '7', 'type': 'return_statement', 'children': ['8']}; {'id': '8', 'type': 'call', 'children': ['9', '34']}; {'id': '9', 'type': 'attribute', 'children': ['10', '33']}; {'id': '10', 'type': '()', 'children': ['11']}; {'id': '11', 'type': 'binary_operator', 'children': ['12', '24'], 'value': '+'}; {'id': '12', 'type': 'call', 'children': ['13', '19']}; {'id': '13', 'type': 'attribute', 'children': ['14', '18']}; {'id': '14', 'type': '()', 'children': ['15']}; {'id': '15', 'type': 'binary_operator', 'children': ['16', '17'], 'value': '*'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'cellsPerColumn'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'reshape'}; {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'tuple', 'children': ['21', '23']}; {'id': '21', 'type': 'unary_operator', 'children': ['22'], 'value': '-'}; {'id': '22', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '23', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '24', 'type': 'call', 'children': ['25', '28']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'arange'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'cellsPerColumn'}; {'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '32', 'type': 'string', 'children': [], 'value': '"uint32"'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'flatten'}; {'id': '34', 'type': 'argument_list', 'children': []}
def getAllCellsInColumns(columns, cellsPerColumn): return ((columns * cellsPerColumn).reshape((-1, 1)) + np.arange(cellsPerColumn, dtype="uint32")).flatten()
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'shuffle_sparse_matrix_and_labels'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'matrix'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '6', 'type': 'block', 'children': ['7', '9', '17', '27', '36', '45', '54', '56']}; {'id': '7', 'type': 'print_statement', 'children': ['8']}; {'id': '8', 'type': 'string', 'children': [], 'value': '"Shuffling data"'}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'new_matrix'}; {'id': '12', 'type': 'call', 'children': ['13', '16']}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'matrix'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'toDense'}; {'id': '16', 'type': 'argument_list', 'children': []}; {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'rng_state'}; {'id': '20', 'type': 'call', 'children': ['21', '26']}; {'id': '21', 'type': 'attribute', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'random'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'get_state'}; {'id': '26', 'type': 'argument_list', 'children': []}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '34']}; {'id': '29', 'type': 'attribute', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'random'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'shuffle'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'new_matrix'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}; {'id': '37', 'type': 'call', 'children': ['38', '43']}; {'id': '38', 'type': 'attribute', 'children': ['39', '42']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'random'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'set_state'}; {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'rng_state'}; {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '52']}; {'id': '47', 'type': 'attribute', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'random'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'shuffle'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '54', 'type': 'print_statement', 'children': ['55']}; {'id': '55', 'type': 'string', 'children': [], 'value': '"Data shuffled"'}; {'id': '56', 'type': 'return_statement', 'children': ['57']}; {'id': '57', 'type': 'expression_list', 'children': ['58', '62']}; {'id': '58', 'type': 'call', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'SM32'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'new_matrix'}; {'id': '62', 'type': 'call', 'children': ['63', '66']}; {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'asarray'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'labels'}
def shuffle_sparse_matrix_and_labels(matrix, labels): print "Shuffling data" new_matrix = matrix.toDense() rng_state = numpy.random.get_state() numpy.random.shuffle(new_matrix) numpy.random.set_state(rng_state) numpy.random.shuffle(labels) print "Data shuffled" return SM32(new_matrix), numpy.asarray(labels)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'compute'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'sensorToBodyByColumn'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sensorToSpecificObjectByColumn'}; {'id': '7', 'type': 'block', 'children': ['8', '22', '28', '103', '121', '135', '150']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'votesByCell'}; {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '15', 'type': 'argument_list', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'cellCount'}; {'id': '19', 'type': 'keyword_argument', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '21', 'type': 'string', 'children': [], 'value': '"int"'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'assignment', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'activeSegmentsByColumn'}; {'id': '27', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '28', 'type': 'for_statement', 'children': ['29', '33', '41']}; {'id': '29', 'type': 'tuple_pattern', 'children': ['30', '31', '32']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'connections'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'activeSensorToBodyCells'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'activeSensorToSpecificObjectCells'}; {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '35', 'type': 'argument_list', 'children': ['36', '39', '40']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'connectionsByColumn'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'sensorToBodyByColumn'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'sensorToSpecificObjectByColumn'}; {'id': '41', 'type': 'block', 'children': ['42', '57', '70', '79', '88', '94']}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}; {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'overlaps'}; {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'connections'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'computeActivity'}; {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'dictionary', 'children': ['51', '54']}; {'id': '51', 'type': 'pair', 'children': ['52', '53']}; {'id': '52', 'type': 'string', 'children': [], 'value': '"sensorToBody"'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'activeSensorToBodyCells'}; {'id': '54', 'type': 'pair', 'children': ['55', '56']}; {'id': '55', 'type': 'string', 'children': [], 'value': '"sensorToSpecificObject"'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'activeSensorToSpecificObjectCells'}; {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'activeSegments'}; {'id': '60', 'type': 'subscript', 'children': ['61', '69']}; {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'where'}; {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'comparison_operator', 'children': ['67', '68'], 'value': '>='}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'overlaps'}; {'id': '68', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '69', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}; {'id': '71', 'type': 'assignment', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'votes'}; {'id': '73', 'type': 'call', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'connections'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'mapSegmentsToCells'}; {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'activeSegments'}; {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'votes'}; {'id': '82', 'type': 'call', 'children': ['83', '86']}; {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'unique'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'votes'}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}; {'id': '89', 'type': 'augmented_assignment', 'children': ['90', '93'], 'value': '+='}; {'id': '90', 'type': 'subscript', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'votesByCell'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'votes'}; {'id': '93', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}; {'id': '95', 'type': 'call', 'children': ['96', '101']}; {'id': '96', 'type': 'attribute', 'children': ['97', '100']}; {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'activeSegmentsByColumn'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'activeSegments'}; {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'candidates'}; {'id': '106', 'type': 'subscript', 'children': ['107', '120']}; {'id': '107', 'type': 'call', 'children': ['108', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'where'}; {'id': '111', 'type': 'argument_list', 'children': ['112']}; {'id': '112', 'type': 'comparison_operator', 'children': ['113', '114'], 'value': '=='}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'votesByCell'}; {'id': '114', 'type': 'call', 'children': ['115', '118']}; {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'votesByCell'}; {'id': '120', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'assignment', 'children': ['123', '126']}; {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'activeCells'}; {'id': '126', 'type': 'call', 'children': ['127', '130']}; {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'intersect1d'}; {'id': '130', 'type': 'argument_list', 'children': ['131', '134']}; {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'activeCells'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'candidates'}; {'id': '135', 'type': 'if_statement', 'children': ['136', '143']}; {'id': '136', 'type': 'comparison_operator', 'children': ['137', '142'], 'value': '=='}; {'id': '137', 'type': 'attribute', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'activeCells'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '142', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '143', 'type': 'block', 'children': ['144']}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}; {'id': '145', 'type': 'assignment', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'activeCells'}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'candidates'}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}; {'id': '151', 'type': 'assignment', 'children': ['152', '155']}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'inhibitedCells'}; {'id': '155', 'type': 'call', 'children': ['156', '159']}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'setdiff1d'}; {'id': '159', 'type': 'argument_list', 'children': ['160', '170']}; {'id': '160', 'type': 'subscript', 'children': ['161', '169']}; {'id': '161', 'type': 'call', 'children': ['162', '165']}; {'id': '162', 'type': 'attribute', 'children': ['163', '164']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'where'}; {'id': '165', 'type': 'argument_list', 'children': ['166']}; {'id': '166', 'type': 'comparison_operator', 'children': ['167', '168'], 'value': '>'}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'votesByCell'}; {'id': '168', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '169', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'activeCells'}
def compute(self, sensorToBodyByColumn, sensorToSpecificObjectByColumn): votesByCell = np.zeros(self.cellCount, dtype="int") self.activeSegmentsByColumn = [] for (connections, activeSensorToBodyCells, activeSensorToSpecificObjectCells) in zip(self.connectionsByColumn, sensorToBodyByColumn, sensorToSpecificObjectByColumn): overlaps = connections.computeActivity({ "sensorToBody": activeSensorToBodyCells, "sensorToSpecificObject": activeSensorToSpecificObjectCells, }) activeSegments = np.where(overlaps >= 2)[0] votes = connections.mapSegmentsToCells(activeSegments) votes = np.unique(votes) votesByCell[votes] += 1 self.activeSegmentsByColumn.append(activeSegments) candidates = np.where(votesByCell == np.max(votesByCell))[0] self.activeCells = np.intersect1d(self.activeCells, candidates) if self.activeCells.size == 0: self.activeCells = candidates self.inhibitedCells = np.setdiff1d(np.where(votesByCell > 0)[0], self.activeCells)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'metricCompute'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'sensorToBody'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'bodyToSpecificObject'}; {'id': '7', 'type': 'block', 'children': ['8', '25', '40']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'overlaps'}; {'id': '11', 'type': 'call', 'children': ['12', '17']}; {'id': '12', 'type': 'attribute', 'children': ['13', '16']}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'metricConnections'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'computeActivity'}; {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'dictionary', 'children': ['19', '22']}; {'id': '19', 'type': 'pair', 'children': ['20', '21']}; {'id': '20', 'type': 'string', 'children': [], 'value': '"bodyToSpecificObject"'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'bodyToSpecificObject'}; {'id': '22', 'type': 'pair', 'children': ['23', '24']}; {'id': '23', 'type': 'string', 'children': [], 'value': '"sensorToBody"'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'sensorToBody'}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '30']}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'activeMetricSegments'}; {'id': '30', 'type': 'subscript', 'children': ['31', '39']}; {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'where'}; {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': '>='}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'overlaps'}; {'id': '38', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '39', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}; {'id': '41', 'type': 'assignment', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'activeCells'}; {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'unique'}; {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'call', 'children': ['51', '56']}; {'id': '51', 'type': 'attribute', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'metricConnections'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'mapSegmentsToCells'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'activeMetricSegments'}
def metricCompute(self, sensorToBody, bodyToSpecificObject): overlaps = self.metricConnections.computeActivity({ "bodyToSpecificObject": bodyToSpecificObject, "sensorToBody": sensorToBody, }) self.activeMetricSegments = np.where(overlaps >= 2)[0] self.activeCells = np.unique( self.metricConnections.mapSegmentsToCells( self.activeMetricSegments))
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'compute'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'feedforwardInput'}; {'id': '7', 'type': 'tuple', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'lateralInputs'}; {'id': '10', 'type': 'tuple', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'feedforwardGrowthCandidates'}; {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'learn'}; {'id': '16', 'type': 'True', 'children': []}; {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'predictedInput'}; {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'block', 'children': ['21', '30']}; {'id': '21', 'type': 'if_statement', 'children': ['22', '25']}; {'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': 'is'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'feedforwardGrowthCandidates'}; {'id': '24', 'type': 'None', 'children': []}; {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}; {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'feedforwardGrowthCandidates'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'feedforwardInput'}; {'id': '30', 'type': 'if_statement', 'children': ['31', '33', '42', '57']}; {'id': '31', 'type': 'not_operator', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'learn'}; {'id': '33', 'type': 'block', 'children': ['34']}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}; {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': '_computeInferenceMode'}; {'id': '39', 'type': 'argument_list', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'feedforwardInput'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'lateralInputs'}; {'id': '42', 'type': 'elif_clause', 'children': ['43', '47']}; {'id': '43', 'type': 'not_operator', 'children': ['44']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'onlineLearning'}; {'id': '47', 'type': 'block', 'children': ['48']}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}; {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': '_computeLearningMode'}; {'id': '53', 'type': 'argument_list', 'children': ['54', '55', '56']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'feedforwardInput'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'lateralInputs'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'feedforwardGrowthCandidates'}; {'id': '57', 'type': 'else_clause', 'children': ['58']}; {'id': '58', 'type': 'block', 'children': ['59']}; {'id': '59', 'type': 'if_statement', 'children': ['60', '73', '111', '144']}; {'id': '60', 'type': '()', 'children': ['61']}; {'id': '61', 'type': 'boolean_operator', 'children': ['62', '65'], 'value': 'and'}; {'id': '62', 'type': 'comparison_operator', 'children': ['63', '64'], 'value': 'is'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'predictedInput'}; {'id': '64', 'type': 'None', 'children': []}; {'id': '65', 'type': 'comparison_operator', 'children': ['66', '70'], 'value': '>'}; {'id': '66', 'type': 'call', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'predictedInput'}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'predictedInhibitionThreshold'}; {'id': '73', 'type': 'block', 'children': ['74', '84', '94', '102']}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}; {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'predictedActiveInput'}; {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'intersect1d'}; {'id': '81', 'type': 'argument_list', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'feedforwardInput'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'predictedInput'}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}; {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'predictedGrowthCandidates'}; {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'intersect1d'}; {'id': '91', 'type': 'argument_list', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'feedforwardGrowthCandidates'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'predictedInput'}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}; {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': '_computeInferenceMode'}; {'id': '99', 'type': 'argument_list', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'predictedActiveInput'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'lateralInputs'}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}; {'id': '103', 'type': 'call', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': '_computeLearningMode'}; {'id': '107', 'type': 'argument_list', 'children': ['108', '109', '110']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'predictedActiveInput'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'lateralInputs'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'feedforwardGrowthCandidates'}; {'id': '111', 'type': 'elif_clause', 'children': ['112', '126']}; {'id': '112', 'type': 'not_operator', 'children': ['113']}; {'id': '113', 'type': 'comparison_operator', 'children': ['114', '117', '123'], 'value': '<='}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'minSdrSize'}; {'id': '117', 'type': 'call', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'activeCells'}; {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'maxSdrSize'}; {'id': '126', 'type': 'block', 'children': ['127', '135']}; {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'call', 'children': ['129', '132']}; {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': '_computeInferenceMode'}; {'id': '132', 'type': 'argument_list', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'feedforwardInput'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'lateralInputs'}; {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'call', 'children': ['137', '140']}; {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '139', 'type': 'identifier', 'children': [], 'value': '_computeLearningMode'}; {'id': '140', 'type': 'argument_list', 'children': ['141', '142', '143']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'feedforwardInput'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'lateralInputs'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'feedforwardGrowthCandidates'}; {'id': '144', 'type': 'else_clause', 'children': ['145']}; {'id': '145', 'type': 'block', 'children': ['146']}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}; {'id': '147', 'type': 'call', 'children': ['148', '151']}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': '_computeLearningMode'}; {'id': '151', 'type': 'argument_list', 'children': ['152', '153', '154']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'feedforwardInput'}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'lateralInputs'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'feedforwardGrowthCandidates'}
def compute(self, feedforwardInput=(), lateralInputs=(), feedforwardGrowthCandidates=None, learn=True, predictedInput = None,): if feedforwardGrowthCandidates is None: feedforwardGrowthCandidates = feedforwardInput if not learn: self._computeInferenceMode(feedforwardInput, lateralInputs) elif not self.onlineLearning: self._computeLearningMode(feedforwardInput, lateralInputs, feedforwardGrowthCandidates) else: if (predictedInput is not None and len(predictedInput) > self.predictedInhibitionThreshold): predictedActiveInput = numpy.intersect1d(feedforwardInput, predictedInput) predictedGrowthCandidates = numpy.intersect1d( feedforwardGrowthCandidates, predictedInput) self._computeInferenceMode(predictedActiveInput, lateralInputs) self._computeLearningMode(predictedActiveInput, lateralInputs, feedforwardGrowthCandidates) elif not self.minSdrSize <= len(self.activeCells) <= self.maxSdrSize: self._computeInferenceMode(feedforwardInput, lateralInputs) self._computeLearningMode(feedforwardInput, lateralInputs, feedforwardGrowthCandidates) else: self._computeLearningMode(feedforwardInput, lateralInputs, feedforwardGrowthCandidates)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_learn'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10', '11', '12', '13']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'permanences'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'rng'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'activeCells'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'activeInput'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'growthCandidateInput'}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'sampleSize'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'initialPermanence'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'permanenceIncrement'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'permanenceDecrement'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'connectedPermanence'}; {'id': '14', 'type': 'block', 'children': ['15', '24', '34', '43']}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'call', 'children': ['17', '20']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'permanences'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'incrementNonZerosOnOuter'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '22', '23']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'activeCells'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'activeInput'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'permanenceIncrement'}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}; {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'permanences'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'incrementNonZerosOnRowsExcludingCols'}; {'id': '29', 'type': 'argument_list', 'children': ['30', '31', '32']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'activeCells'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'activeInput'}; {'id': '32', 'type': 'unary_operator', 'children': ['33'], 'value': '-'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'permanenceDecrement'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}; {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'permanences'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'clipRowsBelowAndAbove'}; {'id': '39', 'type': 'argument_list', 'children': ['40', '41', '42']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'activeCells'}; {'id': '41', 'type': 'float', 'children': [], 'value': '0.0'}; {'id': '42', 'type': 'float', 'children': [], 'value': '1.0'}; {'id': '43', 'type': 'if_statement', 'children': ['44', '48', '58']}; {'id': '44', 'type': 'comparison_operator', 'children': ['45', '46'], 'value': '=='}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'sampleSize'}; {'id': '46', 'type': 'unary_operator', 'children': ['47'], 'value': '-'}; {'id': '47', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '48', 'type': 'block', 'children': ['49']}; {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'call', 'children': ['51', '54']}; {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'permanences'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'setZerosOnOuter'}; {'id': '54', 'type': 'argument_list', 'children': ['55', '56', '57']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'activeCells'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'activeInput'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'initialPermanence'}; {'id': '58', 'type': 'else_clause', 'children': ['59']}; {'id': '59', 'type': 'block', 'children': ['60', '70', '85', '96']}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}; {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'existingSynapseCounts'}; {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'permanences'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'nNonZerosPerRowOnCols'}; {'id': '67', 'type': 'argument_list', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'activeCells'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'activeInput'}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}; {'id': '71', 'type': 'assignment', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'maxNewByCell'}; {'id': '73', 'type': 'call', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'empty'}; {'id': '77', 'type': 'argument_list', 'children': ['78', '82']}; {'id': '78', 'type': 'call', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'activeCells'}; {'id': '82', 'type': 'keyword_argument', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '84', 'type': 'string', 'children': [], 'value': '"int32"'}; {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'call', 'children': ['87', '90']}; {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'subtract'}; {'id': '90', 'type': 'argument_list', 'children': ['91', '92', '93']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'sampleSize'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'existingSynapseCounts'}; {'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'maxNewByCell'}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}; {'id': '97', 'type': 'call', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'permanences'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'setRandomZerosOnOuter'}; {'id': '101', 'type': 'argument_list', 'children': ['102', '103', '104', '105', '106']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'activeCells'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'growthCandidateInput'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'maxNewByCell'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'initialPermanence'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'rng'}
def _learn( permanences, rng, activeCells, activeInput, growthCandidateInput, sampleSize, initialPermanence, permanenceIncrement, permanenceDecrement, connectedPermanence): permanences.incrementNonZerosOnOuter( activeCells, activeInput, permanenceIncrement) permanences.incrementNonZerosOnRowsExcludingCols( activeCells, activeInput, -permanenceDecrement) permanences.clipRowsBelowAndAbove( activeCells, 0.0, 1.0) if sampleSize == -1: permanences.setZerosOnOuter( activeCells, activeInput, initialPermanence) else: existingSynapseCounts = permanences.nNonZerosPerRowOnCols( activeCells, activeInput) maxNewByCell = numpy.empty(len(activeCells), dtype="int32") numpy.subtract(sampleSize, existingSynapseCounts, out=maxNewByCell) permanences.setRandomZerosOnOuter( activeCells, growthCandidateInput, maxNewByCell, initialPermanence, rng)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'compute'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'deltaLocation'}; {'id': '7', 'type': 'tuple', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'newLocation'}; {'id': '10', 'type': 'tuple', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'featureLocationInput'}; {'id': '13', 'type': 'tuple', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'featureLocationGrowthCandidates'}; {'id': '16', 'type': 'tuple', 'children': []}; {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'learn'}; {'id': '19', 'type': 'True', 'children': []}; {'id': '20', 'type': 'block', 'children': ['21', '27', '72', '123']}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'prevActiveCells'}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'activeCells'}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '32']}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'activeDeltaSegments'}; {'id': '32', 'type': 'subscript', 'children': ['33', '71']}; {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'where'}; {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'binary_operator', 'children': ['39', '55'], 'value': '&'}; {'id': '39', 'type': '()', 'children': ['40']}; {'id': '40', 'type': 'comparison_operator', 'children': ['41', '52'], 'value': '>='}; {'id': '41', 'type': 'call', 'children': ['42', '47']}; {'id': '42', 'type': 'attribute', 'children': ['43', '46']}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'internalConnections'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'computeActivity'}; {'id': '47', 'type': 'argument_list', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'prevActiveCells'}; {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'connectedPermanence'}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'activationThreshold'}; {'id': '55', 'type': '()', 'children': ['56']}; {'id': '56', 'type': 'comparison_operator', 'children': ['57', '68'], 'value': '>='}; {'id': '57', 'type': 'call', 'children': ['58', '63']}; {'id': '58', 'type': 'attribute', 'children': ['59', '62']}; {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'deltaConnections'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'computeActivity'}; {'id': '63', 'type': 'argument_list', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'deltaLocation'}; {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'connectedPermanence'}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'activationThreshold'}; {'id': '71', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '72', 'type': 'if_statement', 'children': ['73', '79', '107']}; {'id': '73', 'type': 'comparison_operator', 'children': ['74', '78'], 'value': '=='}; {'id': '74', 'type': 'call', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'deltaLocation'}; {'id': '78', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '79', 'type': 'block', 'children': ['80']}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}; {'id': '81', 'type': 'assignment', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'activeFeatureLocationSegments'}; {'id': '85', 'type': 'subscript', 'children': ['86', '106']}; {'id': '86', 'type': 'call', 'children': ['87', '90']}; {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'where'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}; {'id': '91', 'type': 'comparison_operator', 'children': ['92', '103'], 'value': '>='}; {'id': '92', 'type': 'call', 'children': ['93', '98']}; {'id': '93', 'type': 'attribute', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'featureLocationConnections'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'computeActivity'}; {'id': '98', 'type': 'argument_list', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'featureLocationInput'}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'connectedPermanence'}; {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'activationThreshold'}; {'id': '106', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '107', 'type': 'else_clause', 'children': ['108']}; {'id': '108', 'type': 'block', 'children': ['109']}; {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'assignment', 'children': ['111', '114']}; {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'activeFeatureLocationSegments'}; {'id': '114', 'type': 'call', 'children': ['115', '118']}; {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'empty'}; {'id': '118', 'type': 'argument_list', 'children': ['119', '120']}; {'id': '119', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '120', 'type': 'keyword_argument', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '122', 'type': 'string', 'children': [], 'value': '"uint32"'}; {'id': '123', 'type': 'if_statement', 'children': ['124', '130', '158', '244']}; {'id': '124', 'type': 'comparison_operator', 'children': ['125', '129'], 'value': '>'}; {'id': '125', 'type': 'call', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'newLocation'}; {'id': '129', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '130', 'type': 'block', 'children': ['131', '137']}; {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '136']}; {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'activeCells'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'newLocation'}; {'id': '137', 'type': 'if_statement', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'learn'}; {'id': '139', 'type': 'block', 'children': ['140', '149']}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}; {'id': '141', 'type': 'call', 'children': ['142', '145']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': '_learnTransition'}; {'id': '145', 'type': 'argument_list', 'children': ['146', '147', '148']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'prevActiveCells'}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'deltaLocation'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'newLocation'}; {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'call', 'children': ['151', '154']}; {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '153', 'type': 'identifier', 'children': [], 'value': '_learnFeatureLocationPair'}; {'id': '154', 'type': 'argument_list', 'children': ['155', '156', '157']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'newLocation'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'featureLocationInput'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'featureLocationGrowthCandidates'}; {'id': '158', 'type': 'elif_clause', 'children': ['159', '165']}; {'id': '159', 'type': 'comparison_operator', 'children': ['160', '164'], 'value': '>'}; {'id': '160', 'type': 'call', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '162', 'type': 'argument_list', 'children': ['163']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'prevActiveCells'}; {'id': '164', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '165', 'type': 'block', 'children': ['166']}; {'id': '166', 'type': 'if_statement', 'children': ['167', '173', '198']}; {'id': '167', 'type': 'comparison_operator', 'children': ['168', '172'], 'value': '>'}; {'id': '168', 'type': 'call', 'children': ['169', '170']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '170', 'type': 'argument_list', 'children': ['171']}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'deltaLocation'}; {'id': '172', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '173', 'type': 'block', 'children': ['174', '187']}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}; {'id': '175', 'type': 'assignment', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'cellsForDeltaSegments'}; {'id': '177', 'type': 'call', 'children': ['178', '183']}; {'id': '178', 'type': 'attribute', 'children': ['179', '182']}; {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'internalConnections'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'mapSegmentsToCells'}; {'id': '183', 'type': 'argument_list', 'children': ['184']}; {'id': '184', 'type': 'attribute', 'children': ['185', '186']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'activeDeltaSegments'}; {'id': '187', 'type': 'expression_statement', 'children': ['188']}; {'id': '188', 'type': 'assignment', 'children': ['189', '192']}; {'id': '189', 'type': 'attribute', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'activeCells'}; {'id': '192', 'type': 'call', 'children': ['193', '196']}; {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'unique'}; {'id': '196', 'type': 'argument_list', 'children': ['197']}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'cellsForDeltaSegments'}; {'id': '198', 'type': 'else_clause', 'children': ['199']}; {'id': '199', 'type': 'block', 'children': ['200']}; {'id': '200', 'type': 'if_statement', 'children': ['201', '209', '236']}; {'id': '201', 'type': 'comparison_operator', 'children': ['202', '208'], 'value': '>'}; {'id': '202', 'type': 'call', 'children': ['203', '204']}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '204', 'type': 'argument_list', 'children': ['205']}; {'id': '205', 'type': 'attribute', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'activeFeatureLocationSegments'}; {'id': '208', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '209', 'type': 'block', 'children': ['210', '224']}; {'id': '210', 'type': 'expression_statement', 'children': ['211']}; {'id': '211', 'type': 'assignment', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'cellsForFeatureLocationSegments'}; {'id': '213', 'type': '()', 'children': ['214']}; {'id': '214', 'type': 'call', 'children': ['215', '220']}; {'id': '215', 'type': 'attribute', 'children': ['216', '219']}; {'id': '216', 'type': 'attribute', 'children': ['217', '218']}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'featureLocationConnections'}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'mapSegmentsToCells'}; {'id': '220', 'type': 'argument_list', 'children': ['221']}; {'id': '221', 'type': 'attribute', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'activeFeatureLocationSegments'}; {'id': '224', 'type': 'expression_statement', 'children': ['225']}; {'id': '225', 'type': 'assignment', 'children': ['226', '229']}; {'id': '226', 'type': 'attribute', 'children': ['227', '228']}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'activeCells'}; {'id': '229', 'type': 'call', 'children': ['230', '233']}; {'id': '230', 'type': 'attribute', 'children': ['231', '232']}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'intersect1d'}; {'id': '233', 'type': 'argument_list', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'prevActiveCells'}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'cellsForFeatureLocationSegments'}; {'id': '236', 'type': 'else_clause', 'children': ['237']}; {'id': '237', 'type': 'block', 'children': ['238']}; {'id': '238', 'type': 'expression_statement', 'children': ['239']}; {'id': '239', 'type': 'assignment', 'children': ['240', '243']}; {'id': '240', 'type': 'attribute', 'children': ['241', '242']}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'activeCells'}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'prevActiveCells'}; {'id': '244', 'type': 'elif_clause', 'children': ['245', '251']}; {'id': '245', 'type': 'comparison_operator', 'children': ['246', '250'], 'value': '>'}; {'id': '246', 'type': 'call', 'children': ['247', '248']}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '248', 'type': 'argument_list', 'children': ['249']}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'featureLocationInput'}; {'id': '250', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '251', 'type': 'block', 'children': ['252', '266']}; {'id': '252', 'type': 'expression_statement', 'children': ['253']}; {'id': '253', 'type': 'assignment', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'cellsForFeatureLocationSegments'}; {'id': '255', 'type': '()', 'children': ['256']}; {'id': '256', 'type': 'call', 'children': ['257', '262']}; {'id': '257', 'type': 'attribute', 'children': ['258', '261']}; {'id': '258', 'type': 'attribute', 'children': ['259', '260']}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'featureLocationConnections'}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'mapSegmentsToCells'}; {'id': '262', 'type': 'argument_list', 'children': ['263']}; {'id': '263', 'type': 'attribute', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'activeFeatureLocationSegments'}; {'id': '266', 'type': 'expression_statement', 'children': ['267']}; {'id': '267', 'type': 'assignment', 'children': ['268', '271']}; {'id': '268', 'type': 'attribute', 'children': ['269', '270']}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'activeCells'}; {'id': '271', 'type': 'call', 'children': ['272', '275']}; {'id': '272', 'type': 'attribute', 'children': ['273', '274']}; {'id': '273', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'unique'}; {'id': '275', 'type': 'argument_list', 'children': ['276']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'cellsForFeatureLocationSegments'}
def compute(self, deltaLocation=(), newLocation=(), featureLocationInput=(), featureLocationGrowthCandidates=(), learn=True): prevActiveCells = self.activeCells self.activeDeltaSegments = np.where( (self.internalConnections.computeActivity( prevActiveCells, self.connectedPermanence ) >= self.activationThreshold) & (self.deltaConnections.computeActivity( deltaLocation, self.connectedPermanence ) >= self.activationThreshold))[0] if len(deltaLocation) == 0: self.activeFeatureLocationSegments = np.where( self.featureLocationConnections.computeActivity( featureLocationInput, self.connectedPermanence ) >= self.activationThreshold)[0] else: self.activeFeatureLocationSegments = np.empty(0, dtype="uint32") if len(newLocation) > 0: self.activeCells = newLocation if learn: self._learnTransition(prevActiveCells, deltaLocation, newLocation) self._learnFeatureLocationPair(newLocation, featureLocationInput, featureLocationGrowthCandidates) elif len(prevActiveCells) > 0: if len(deltaLocation) > 0: cellsForDeltaSegments = self.internalConnections.mapSegmentsToCells( self.activeDeltaSegments) self.activeCells = np.unique(cellsForDeltaSegments) else: if len(self.activeFeatureLocationSegments) > 0: cellsForFeatureLocationSegments = ( self.featureLocationConnections.mapSegmentsToCells( self.activeFeatureLocationSegments)) self.activeCells = np.intersect1d(prevActiveCells, cellsForFeatureLocationSegments) else: self.activeCells = prevActiveCells elif len(featureLocationInput) > 0: cellsForFeatureLocationSegments = ( self.featureLocationConnections.mapSegmentsToCells( self.activeFeatureLocationSegments)) self.activeCells = np.unique(cellsForFeatureLocationSegments)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'getmerge'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'dst'}; {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'newline'}; {'id': '9', 'type': 'False', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'check_crc'}; {'id': '12', 'type': 'False', 'children': []}; {'id': '13', 'type': 'block', 'children': ['14', '16', '25', '34', '40', '48', '70']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'id': '15', 'type': 'string', 'children': [], 'value': "''' Get all the files in the directories that\n match the source file pattern and merge and sort them to only\n one file on local fs.\n :param paths: Directory containing files that will be merged\n :type paths: string\n :param dst: Path of file that will be written\n :type dst: string\n :param nl: Add a newline character at the end of each file.\n :type nl: boolean\n :returns: string content of the merged file at dst\n '''"}; {'id': '16', 'type': 'if_statement', 'children': ['17', '19']}; {'id': '17', 'type': 'not_operator', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '19', 'type': 'block', 'children': ['20']}; {'id': '20', 'type': 'raise_statement', 'children': ['21']}; {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'InvalidInputException'}; {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'string', 'children': [], 'value': '"getmerge: no path given"'}; {'id': '25', 'type': 'if_statement', 'children': ['26', '28']}; {'id': '26', 'type': 'not_operator', 'children': ['27']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'dst'}; {'id': '28', 'type': 'block', 'children': ['29']}; {'id': '29', 'type': 'raise_statement', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'InvalidInputException'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}; {'id': '33', 'type': 'string', 'children': [], 'value': '"getmerge: no destination given"'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}; {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'temporary_target'}; {'id': '37', 'type': 'binary_operator', 'children': ['38', '39'], 'value': '%'}; {'id': '38', 'type': 'string', 'children': [], 'value': '"%s._COPYING_"'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'dst'}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}; {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '45', 'type': 'argument_list', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'temporary_target'}; {'id': '47', 'type': 'string', 'children': [], 'value': "'w'"}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}; {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'processor'}; {'id': '51', 'type': 'lambda', 'children': ['52', '61']}; {'id': '52', 'type': 'lambda_parameters', 'children': ['53', '54', '55', '58']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '55', 'type': 'default_parameter', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'dst'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'dst'}; {'id': '58', 'type': 'default_parameter', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'check_crc'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'check_crc'}; {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': '_handle_getmerge'}; {'id': '65', 'type': 'argument_list', 'children': ['66', '67', '68', '69']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'dst'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'check_crc'}; {'id': '70', 'type': 'try_statement', 'children': ['71', '176']}; {'id': '71', 'type': 'block', 'children': ['72', '156']}; {'id': '72', 'type': 'for_statement', 'children': ['73', '74', '91']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '74', 'type': 'call', 'children': ['75', '78']}; {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': '_find_items'}; {'id': '78', 'type': 'argument_list', 'children': ['79', '81', '82', '85', '88']}; {'id': '79', 'type': 'list', 'children': ['80'], 'value': '[path]'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'processor'}; {'id': '82', 'type': 'keyword_argument', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'include_toplevel'}; {'id': '84', 'type': 'True', 'children': []}; {'id': '85', 'type': 'keyword_argument', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'recurse'}; {'id': '87', 'type': 'False', 'children': []}; {'id': '88', 'type': 'keyword_argument', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'include_children'}; {'id': '90', 'type': 'True', 'children': []}; {'id': '91', 'type': 'block', 'children': ['92', '142']}; {'id': '92', 'type': 'for_statement', 'children': ['93', '94', '95']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'load'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '95', 'type': 'block', 'children': ['96']}; {'id': '96', 'type': 'if_statement', 'children': ['97', '100', '110']}; {'id': '97', 'type': 'subscript', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'load'}; {'id': '99', 'type': 'string', 'children': [], 'value': "'result'"}; {'id': '100', 'type': 'block', 'children': ['101']}; {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'call', 'children': ['103', '106']}; {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}; {'id': '107', 'type': 'subscript', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'load'}; {'id': '109', 'type': 'string', 'children': [], 'value': "'response'"}; {'id': '110', 'type': 'elif_clause', 'children': ['111', '117']}; {'id': '111', 'type': 'not_operator', 'children': ['112']}; {'id': '112', 'type': 'comparison_operator', 'children': ['113', '116'], 'value': 'is'}; {'id': '113', 'type': 'subscript', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'load'}; {'id': '115', 'type': 'string', 'children': [], 'value': "'error'"}; {'id': '116', 'type': 'string', 'children': [], 'value': "''"}; {'id': '117', 'type': 'block', 'children': ['118', '135']}; {'id': '118', 'type': 'if_statement', 'children': ['119', '127']}; {'id': '119', 'type': 'call', 'children': ['120', '125']}; {'id': '120', 'type': 'attribute', 'children': ['121', '124']}; {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'isfile'}; {'id': '125', 'type': 'argument_list', 'children': ['126']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'temporary_target'}; {'id': '127', 'type': 'block', 'children': ['128']}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}; {'id': '129', 'type': 'call', 'children': ['130', '133']}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'remove'}; {'id': '133', 'type': 'argument_list', 'children': ['134']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'temporary_target'}; {'id': '135', 'type': 'raise_statement', 'children': ['136']}; {'id': '136', 'type': 'call', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'FatalException'}; {'id': '138', 'type': 'argument_list', 'children': ['139']}; {'id': '139', 'type': 'subscript', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'load'}; {'id': '141', 'type': 'string', 'children': [], 'value': "'error'"}; {'id': '142', 'type': 'if_statement', 'children': ['143', '148']}; {'id': '143', 'type': 'boolean_operator', 'children': ['144', '145'], 'value': 'and'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'newline'}; {'id': '145', 'type': 'subscript', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'load'}; {'id': '147', 'type': 'string', 'children': [], 'value': "'response'"}; {'id': '148', 'type': 'block', 'children': ['149']}; {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'call', 'children': ['151', '154']}; {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '154', 'type': 'argument_list', 'children': ['155']}; {'id': '155', 'type': 'string', 'children': [], 'value': '"\\n"'}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}; {'id': '157', 'type': 'yield', 'children': ['158']}; {'id': '158', 'type': 'dictionary', 'children': ['159', '162', '165', '168', '173']}; {'id': '159', 'type': 'pair', 'children': ['160', '161']}; {'id': '160', 'type': 'string', 'children': [], 'value': '"path"'}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'dst'}; {'id': '162', 'type': 'pair', 'children': ['163', '164']}; {'id': '163', 'type': 'string', 'children': [], 'value': '"response"'}; {'id': '164', 'type': 'string', 'children': [], 'value': "''"}; {'id': '165', 'type': 'pair', 'children': ['166', '167']}; {'id': '166', 'type': 'string', 'children': [], 'value': '"result"'}; {'id': '167', 'type': 'True', 'children': []}; {'id': '168', 'type': 'pair', 'children': ['169', '170']}; {'id': '169', 'type': 'string', 'children': [], 'value': '"error"'}; {'id': '170', 'type': 'subscript', 'children': ['171', '172']}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'load'}; {'id': '172', 'type': 'string', 'children': [], 'value': "'error'"}; {'id': '173', 'type': 'pair', 'children': ['174', '175']}; {'id': '174', 'type': 'string', 'children': [], 'value': '"source_path"'}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '176', 'type': 'finally_clause', 'children': ['177']}; {'id': '177', 'type': 'block', 'children': ['178']}; {'id': '178', 'type': 'if_statement', 'children': ['179', '187']}; {'id': '179', 'type': 'call', 'children': ['180', '185']}; {'id': '180', 'type': 'attribute', 'children': ['181', '184']}; {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'isfile'}; {'id': '185', 'type': 'argument_list', 'children': ['186']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'temporary_target'}; {'id': '187', 'type': 'block', 'children': ['188', '194']}; {'id': '188', 'type': 'expression_statement', 'children': ['189']}; {'id': '189', 'type': 'call', 'children': ['190', '193']}; {'id': '190', 'type': 'attribute', 'children': ['191', '192']}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'close'}; {'id': '193', 'type': 'argument_list', 'children': []}; {'id': '194', 'type': 'expression_statement', 'children': ['195']}; {'id': '195', 'type': 'call', 'children': ['196', '199']}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'rename'}; {'id': '199', 'type': 'argument_list', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'temporary_target'}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'dst'}
def getmerge(self, path, dst, newline=False, check_crc=False): ''' Get all the files in the directories that match the source file pattern and merge and sort them to only one file on local fs. :param paths: Directory containing files that will be merged :type paths: string :param dst: Path of file that will be written :type dst: string :param nl: Add a newline character at the end of each file. :type nl: boolean :returns: string content of the merged file at dst ''' if not path: raise InvalidInputException("getmerge: no path given") if not dst: raise InvalidInputException("getmerge: no destination given") temporary_target = "%s._COPYING_" % dst f = open(temporary_target, 'w') processor = lambda path, node, dst=dst, check_crc=check_crc: self._handle_getmerge(path, node, dst, check_crc) try: for item in self._find_items([path], processor, include_toplevel=True, recurse=False, include_children=True): for load in item: if load['result']: f.write(load['response']) elif not load['error'] is '': if os.path.isfile(temporary_target): os.remove(temporary_target) raise FatalException(load['error']) if newline and load['response']: f.write("\n") yield {"path": dst, "response": '', "result": True, "error": load['error'], "source_path": path} finally: if os.path.isfile(temporary_target): f.close() os.rename(temporary_target, dst)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'countByValue'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'return_statement', 'children': ['7']}; {'id': '7', 'type': 'call', 'children': ['8', '11']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'transform'}; {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'lambda', 'children': ['13', '15']}; {'id': '13', 'type': 'lambda_parameters', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'rdd'}; {'id': '15', 'type': 'call', 'children': ['16', '23']}; {'id': '16', 'type': 'attribute', 'children': ['17', '22']}; {'id': '17', 'type': 'attribute', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': '_context'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': '_context'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'parallelize'}; {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '32']}; {'id': '25', 'type': 'attribute', 'children': ['26', '31']}; {'id': '26', 'type': 'call', 'children': ['27', '30']}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'rdd'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'countByValue'}; {'id': '30', 'type': 'argument_list', 'children': []}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '32', 'type': 'argument_list', 'children': []}
def countByValue(self): return self.transform( lambda rdd: self._context._context.parallelize( rdd.countByValue().items()))
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_contiguous_offsets'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'offsets'}; {'id': '6', 'type': 'block', 'children': ['7', '13', '41']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'call', 'children': ['9', '12']}; {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'offsets'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '12', 'type': 'argument_list', 'children': []}; {'id': '13', 'type': 'for_statement', 'children': ['14', '15', '24']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'binary_operator', 'children': ['19', '23'], 'value': '-'}; {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'offsets'}; {'id': '23', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '24', 'type': 'block', 'children': ['25']}; {'id': '25', 'type': 'assert_statement', 'children': ['26', '37']}; {'id': '26', 'type': 'comparison_operator', 'children': ['27', '32'], 'value': '=='}; {'id': '27', 'type': 'binary_operator', 'children': ['28', '31'], 'value': '+'}; {'id': '28', 'type': 'subscript', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'offsets'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '31', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '32', 'type': 'subscript', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'offsets'}; {'id': '34', 'type': 'binary_operator', 'children': ['35', '36'], 'value': '+'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '36', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '37', 'type': 'binary_operator', 'children': ['38', '39'], 'value': '%'}; {'id': '38', 'type': 'string', 'children': [], 'value': '"Offsets not contiguous: %s"'}; {'id': '39', 'type': 'tuple', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'offsets'}; {'id': '41', 'type': 'return_statement', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'offsets'}
def _contiguous_offsets(self, offsets): offsets.sort() for i in range(len(offsets) - 1): assert offsets[i] + 1 == offsets[i + 1], \ "Offsets not contiguous: %s" % (offsets,) return offsets
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_collapse'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'intervals'}; {'id': '5', 'type': 'block', 'children': ['6', '10', '65']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'span'}; {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'for_statement', 'children': ['11', '14', '15']}; {'id': '11', 'type': 'pattern_list', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'intervals'}; {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'if_statement', 'children': ['17', '20', '29', '47']}; {'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': 'is'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'span'}; {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'block', 'children': ['21']}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'span'}; {'id': '24', 'type': 'call', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': '_Interval'}; {'id': '26', 'type': 'argument_list', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '29', 'type': 'elif_clause', 'children': ['30', '36']}; {'id': '30', 'type': 'comparison_operator', 'children': ['31', '32', '35'], 'value': '<='}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'span'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '36', 'type': 'block', 'children': ['37']}; {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'span'}; {'id': '40', 'type': 'call', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': '_Interval'}; {'id': '42', 'type': 'argument_list', 'children': ['43', '46']}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'span'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '47', 'type': 'elif_clause', 'children': ['48', '53']}; {'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': '>'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'span'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '53', 'type': 'block', 'children': ['54', '57']}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}; {'id': '55', 'type': 'yield', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'span'}; {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'span'}; {'id': '60', 'type': 'call', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': '_Interval'}; {'id': '62', 'type': 'argument_list', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '65', 'type': 'if_statement', 'children': ['66', '69']}; {'id': '66', 'type': 'comparison_operator', 'children': ['67', '68'], 'value': 'is'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'span'}; {'id': '68', 'type': 'None', 'children': []}; {'id': '69', 'type': 'block', 'children': ['70']}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}; {'id': '71', 'type': 'yield', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'span'}
def _collapse(intervals): span = None for start, stop in intervals: if span is None: span = _Interval(start, stop) elif start <= span.stop < stop: span = _Interval(span.start, stop) elif start > span.stop: yield span span = _Interval(start, stop) if span is not None: yield span
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'remove'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'hash'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'keepSorted'}; {'id': '13', 'type': 'True', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '32', '143', '160']}; {'id': '15', 'type': 'if_statement', 'children': ['16', '19']}; {'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'is'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '18', 'type': 'None', 'children': []}; {'id': '19', 'type': 'block', 'children': ['20']}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}; {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'clibrebound'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'reb_remove'}; {'id': '25', 'type': 'argument_list', 'children': ['26', '30', '31']}; {'id': '26', 'type': 'call', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'byref'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'keepSorted'}; {'id': '32', 'type': 'if_statement', 'children': ['33', '36']}; {'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': 'is'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'hash'}; {'id': '35', 'type': 'None', 'children': []}; {'id': '36', 'type': 'block', 'children': ['37', '44', '54', '80']}; {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'hash_types'}; {'id': '40', 'type': 'expression_list', 'children': ['41', '42', '43']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'c_uint32'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'c_uint'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'c_ulong'}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}; {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'PY3'}; {'id': '47', 'type': 'comparison_operator', 'children': ['48', '53'], 'value': '=='}; {'id': '48', 'type': 'subscript', 'children': ['49', '52']}; {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'version_info'}; {'id': '52', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '53', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '54', 'type': 'if_statement', 'children': ['55', '56', '67']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'PY3'}; {'id': '56', 'type': 'block', 'children': ['57', '62']}; {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'string_types'}; {'id': '60', 'type': 'expression_list', 'children': ['61']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}; {'id': '63', 'type': 'assignment', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'int_types'}; {'id': '65', 'type': 'expression_list', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '67', 'type': 'else_clause', 'children': ['68']}; {'id': '68', 'type': 'block', 'children': ['69', '74']}; {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'string_types'}; {'id': '72', 'type': 'expression_list', 'children': ['73']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'basestring'}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}; {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'int_types'}; {'id': '77', 'type': 'expression_list', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'long'}; {'id': '80', 'type': 'if_statement', 'children': ['81', '86', '102', '124']}; {'id': '81', 'type': 'call', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '83', 'type': 'argument_list', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'hash'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'string_types'}; {'id': '86', 'type': 'block', 'children': ['87']}; {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'call', 'children': ['89', '92']}; {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'clibrebound'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'reb_remove_by_hash'}; {'id': '92', 'type': 'argument_list', 'children': ['93', '97', '101']}; {'id': '93', 'type': 'call', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'byref'}; {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '97', 'type': 'call', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'rebhash'}; {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'hash'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'keepSorted'}; {'id': '102', 'type': 'elif_clause', 'children': ['103', '108']}; {'id': '103', 'type': 'call', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '105', 'type': 'argument_list', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'hash'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'int_types'}; {'id': '108', 'type': 'block', 'children': ['109']}; {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'call', 'children': ['111', '114']}; {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'clibrebound'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'reb_remove_by_hash'}; {'id': '114', 'type': 'argument_list', 'children': ['115', '119', '123']}; {'id': '115', 'type': 'call', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'byref'}; {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '119', 'type': 'call', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'c_uint32'}; {'id': '121', 'type': 'argument_list', 'children': ['122']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'hash'}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'keepSorted'}; {'id': '124', 'type': 'elif_clause', 'children': ['125', '130']}; {'id': '125', 'type': 'call', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '127', 'type': 'argument_list', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'hash'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'hash_types'}; {'id': '130', 'type': 'block', 'children': ['131']}; {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'call', 'children': ['133', '136']}; {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'clibrebound'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'reb_remove_by_hash'}; {'id': '136', 'type': 'argument_list', 'children': ['137', '141', '142']}; {'id': '137', 'type': 'call', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'byref'}; {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'hash'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'keepSorted'}; {'id': '143', 'type': 'if_statement', 'children': ['144', '149']}; {'id': '144', 'type': 'call', 'children': ['145', '146']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '146', 'type': 'argument_list', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '148', 'type': 'string', 'children': [], 'value': "'_widgets'"}; {'id': '149', 'type': 'block', 'children': ['150']}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}; {'id': '151', 'type': 'call', 'children': ['152', '155']}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': '_display_heartbeat'}; {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'call', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'pointer'}; {'id': '158', 'type': 'argument_list', 'children': ['159']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}; {'id': '161', 'type': 'call', 'children': ['162', '165']}; {'id': '162', 'type': 'attribute', 'children': ['163', '164']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'process_messages'}; {'id': '165', 'type': 'argument_list', 'children': []}
def remove(self, index=None, hash=None, keepSorted=True): if index is not None: clibrebound.reb_remove(byref(self), index, keepSorted) if hash is not None: hash_types = c_uint32, c_uint, c_ulong PY3 = sys.version_info[0] == 3 if PY3: string_types = str, int_types = int, else: string_types = basestring, int_types = int, long if isinstance(hash, string_types): clibrebound.reb_remove_by_hash(byref(self), rebhash(hash), keepSorted) elif isinstance(hash, int_types): clibrebound.reb_remove_by_hash(byref(self), c_uint32(hash), keepSorted) elif isinstance(hash, hash_types): clibrebound.reb_remove_by_hash(byref(self), hash, keepSorted) if hasattr(self, '_widgets'): self._display_heartbeat(pointer(self)) self.process_messages()
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'particles'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '14', '18', '41', '47', '76']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'sim'}; {'id': '9', 'type': 'attribute', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': '_sim'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'contents'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'ps'}; {'id': '17', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '18', 'type': 'if_statement', 'children': ['19', '24', '29']}; {'id': '19', 'type': 'comparison_operator', 'children': ['20', '23'], 'value': '>='}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'testparticle'}; {'id': '23', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '24', 'type': 'block', 'children': ['25']}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '28', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '29', 'type': 'else_clause', 'children': ['30']}; {'id': '30', 'type': 'block', 'children': ['31']}; {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '34', 'type': 'binary_operator', 'children': ['35', '38'], 'value': '-'}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'sim'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'sim'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'N_var'}; {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'ParticleList'}; {'id': '44', 'type': 'binary_operator', 'children': ['45', '46'], 'value': '*'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'Particle'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'ps'}; {'id': '50', 'type': 'call', 'children': ['51', '54']}; {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'ParticleList'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'from_address'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}; {'id': '55', 'type': 'binary_operator', 'children': ['56', '66'], 'value': '+'}; {'id': '56', 'type': 'call', 'children': ['57', '60']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'ctypes'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'addressof'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}; {'id': '61', 'type': 'attribute', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'sim'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': '_particles'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'contents'}; {'id': '66', 'type': 'binary_operator', 'children': ['67', '70'], 'value': '*'}; {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '70', 'type': 'call', 'children': ['71', '74']}; {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'ctypes'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'sizeof'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'Particle'}; {'id': '76', 'type': 'return_statement', 'children': ['77']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'ps'}
def particles(self): sim = self._sim.contents ps = [] if self.testparticle>=0: N = 1 else: N = sim.N-sim.N_var ParticleList = Particle*N ps = ParticleList.from_address(ctypes.addressof(sim._particles.contents)+self.index*ctypes.sizeof(Particle)) return ps
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'filter_queryset'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'queryset'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'view'}; {'id': '8', 'type': 'block', 'children': ['9', '17', '28', '39']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '14']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'ordering_param'}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'view'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'SORT'}; {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'ordering'}; {'id': '20', 'type': 'call', 'children': ['21', '24']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'get_ordering'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '26', '27']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'queryset'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'view'}; {'id': '28', 'type': 'if_statement', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'ordering'}; {'id': '30', 'type': 'block', 'children': ['31']}; {'id': '31', 'type': 'return_statement', 'children': ['32']}; {'id': '32', 'type': 'call', 'children': ['33', '36']}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'queryset'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'order_by'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}; {'id': '37', 'type': 'list_splat', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'ordering'}; {'id': '39', 'type': 'return_statement', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'queryset'}
def filter_queryset(self, request, queryset, view): self.ordering_param = view.SORT ordering = self.get_ordering(request, queryset, view) if ordering: return queryset.order_by(*ordering) return queryset
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_ordering'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'queryset'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'view'}; {'id': '8', 'type': 'block', 'children': ['9', '20', '62']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '12', 'type': 'call', 'children': ['13', '16']}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'view'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'get_request_feature'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'view'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'SORT'}; {'id': '20', 'type': 'if_statement', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '22', 'type': 'block', 'children': ['23', '35', '48']}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '26', 'type': 'list_comprehension', 'children': ['27', '32']}; {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '31', 'type': 'argument_list', 'children': []}; {'id': '32', 'type': 'for_in_clause', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '40']}; {'id': '37', 'type': 'pattern_list', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'valid_ordering'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'invalid_ordering'}; {'id': '40', 'type': 'call', 'children': ['41', '44']}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'remove_invalid_fields'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '46', '47']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'queryset'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'view'}; {'id': '48', 'type': 'if_statement', 'children': ['49', '50', '58']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'invalid_ordering'}; {'id': '50', 'type': 'block', 'children': ['51']}; {'id': '51', 'type': 'raise_statement', 'children': ['52']}; {'id': '52', 'type': 'call', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'ValidationError'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}; {'id': '55', 'type': 'binary_operator', 'children': ['56', '57'], 'value': '%'}; {'id': '56', 'type': 'string', 'children': [], 'value': '"Invalid filter field: %s"'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'invalid_ordering'}; {'id': '58', 'type': 'else_clause', 'children': ['59']}; {'id': '59', 'type': 'block', 'children': ['60']}; {'id': '60', 'type': 'return_statement', 'children': ['61']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'valid_ordering'}; {'id': '62', 'type': 'return_statement', 'children': ['63']}; {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'get_default_ordering'}; {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'view'}
def get_ordering(self, request, queryset, view): params = view.get_request_feature(view.SORT) if params: fields = [param.strip() for param in params] valid_ordering, invalid_ordering = self.remove_invalid_fields( queryset, fields, view ) if invalid_ordering: raise ValidationError( "Invalid filter field: %s" % invalid_ordering ) else: return valid_ordering return self.get_default_ordering(view)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'remove_invalid_fields'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'queryset'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'view'}; {'id': '8', 'type': 'block', 'children': ['9', '13', '17', '76']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'valid_orderings'}; {'id': '12', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'invalid_orderings'}; {'id': '16', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '17', 'type': 'for_statement', 'children': ['18', '19', '20']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'term'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '20', 'type': 'block', 'children': ['21', '30', '45', '55']}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'stripped_term'}; {'id': '24', 'type': 'call', 'children': ['25', '28']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'term'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'lstrip'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}; {'id': '29', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'reverse_sort_term'}; {'id': '33', 'type': 'conditional_expression', 'children': ['34', '35', '44'], 'value': 'if'}; {'id': '34', 'type': 'string', 'children': [], 'value': "''"}; {'id': '35', 'type': 'comparison_operator', 'children': ['36', '40'], 'value': 'is'}; {'id': '36', 'type': 'call', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'stripped_term'}; {'id': '40', 'type': 'call', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'term'}; {'id': '44', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'ordering'}; {'id': '48', 'type': 'call', 'children': ['49', '52']}; {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'ordering_for'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'stripped_term'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'view'}; {'id': '55', 'type': 'if_statement', 'children': ['56', '57', '67']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'ordering'}; {'id': '57', 'type': 'block', 'children': ['58']}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}; {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'valid_orderings'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'binary_operator', 'children': ['65', '66'], 'value': '+'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'reverse_sort_term'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'ordering'}; {'id': '67', 'type': 'else_clause', 'children': ['68']}; {'id': '68', 'type': 'block', 'children': ['69']}; {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'call', 'children': ['71', '74']}; {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'invalid_orderings'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'term'}; {'id': '76', 'type': 'return_statement', 'children': ['77']}; {'id': '77', 'type': 'expression_list', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'valid_orderings'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'invalid_orderings'}
def remove_invalid_fields(self, queryset, fields, view): valid_orderings = [] invalid_orderings = [] for term in fields: stripped_term = term.lstrip('-') reverse_sort_term = '' if len(stripped_term) is len(term) else '-' ordering = self.ordering_for(stripped_term, view) if ordering: valid_orderings.append(reverse_sort_term + ordering) else: invalid_orderings.append(term) return valid_orderings, invalid_orderings
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13', '17']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_format_dataframe'}; {'id': '3', 'type': 'parameters', 'children': ['4', '10']}; {'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '6', 'type': 'type', 'children': ['7']}; {'id': '7', 'type': 'attribute', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'pd'}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'DataFrame'}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'nautical_units'}; {'id': '12', 'type': 'True', 'children': []}; {'id': '13', 'type': 'type', 'children': ['14']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'pd'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'DataFrame'}; {'id': '17', 'type': 'block', 'children': ['18', '47', '115', '137', '176']}; {'id': '18', 'type': 'if_statement', 'children': ['19', '32']}; {'id': '19', 'type': 'boolean_operator', 'children': ['20', '25'], 'value': 'and'}; {'id': '20', 'type': 'comparison_operator', 'children': ['21', '22'], 'value': 'in'}; {'id': '21', 'type': 'string', 'children': [], 'value': '"callsign"'}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '25', 'type': 'comparison_operator', 'children': ['26', '31'], 'value': '=='}; {'id': '26', 'type': 'attribute', 'children': ['27', '30']}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'callsign'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'object'}; {'id': '32', 'type': 'block', 'children': ['33']}; {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '38']}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'callsign'}; {'id': '38', 'type': 'call', 'children': ['39', '46']}; {'id': '39', 'type': 'attribute', 'children': ['40', '45']}; {'id': '40', 'type': 'attribute', 'children': ['41', '44']}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'callsign'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '46', 'type': 'argument_list', 'children': []}; {'id': '47', 'type': 'if_statement', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'nautical_units'}; {'id': '49', 'type': 'block', 'children': ['50', '60', '77', '96']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}; {'id': '51', 'type': 'assignment', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'altitude'}; {'id': '55', 'type': 'binary_operator', 'children': ['56', '59'], 'value': '/'}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'altitude'}; {'id': '59', 'type': 'float', 'children': [], 'value': '0.3048'}; {'id': '60', 'type': 'if_statement', 'children': ['61', '66']}; {'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': 'in'}; {'id': '62', 'type': 'string', 'children': [], 'value': '"geoaltitude"'}; {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '66', 'type': 'block', 'children': ['67']}; {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '72']}; {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'geoaltitude'}; {'id': '72', 'type': 'binary_operator', 'children': ['73', '76'], 'value': '/'}; {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'geoaltitude'}; {'id': '76', 'type': 'float', 'children': [], 'value': '0.3048'}; {'id': '77', 'type': 'if_statement', 'children': ['78', '83']}; {'id': '78', 'type': 'comparison_operator', 'children': ['79', '80'], 'value': 'in'}; {'id': '79', 'type': 'string', 'children': [], 'value': '"groundspeed"'}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '83', 'type': 'block', 'children': ['84']}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}; {'id': '85', 'type': 'assignment', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'groundspeed'}; {'id': '89', 'type': 'binary_operator', 'children': ['90', '95'], 'value': '*'}; {'id': '90', 'type': 'binary_operator', 'children': ['91', '94'], 'value': '/'}; {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'groundspeed'}; {'id': '94', 'type': 'integer', 'children': [], 'value': '1852'}; {'id': '95', 'type': 'integer', 'children': [], 'value': '3600'}; {'id': '96', 'type': 'if_statement', 'children': ['97', '102']}; {'id': '97', 'type': 'comparison_operator', 'children': ['98', '99'], 'value': 'in'}; {'id': '98', 'type': 'string', 'children': [], 'value': '"vertical_rate"'}; {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '102', 'type': 'block', 'children': ['103']}; {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '108']}; {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'vertical_rate'}; {'id': '108', 'type': 'binary_operator', 'children': ['109', '114'], 'value': '*'}; {'id': '109', 'type': 'binary_operator', 'children': ['110', '113'], 'value': '/'}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'vertical_rate'}; {'id': '113', 'type': 'float', 'children': [], 'value': '0.3048'}; {'id': '114', 'type': 'integer', 'children': [], 'value': '60'}; {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '120']}; {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '120', 'type': 'call', 'children': ['121', '135']}; {'id': '121', 'type': 'attribute', 'children': ['122', '134']}; {'id': '122', 'type': 'attribute', 'children': ['123', '133']}; {'id': '123', 'type': 'call', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'pd'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'to_datetime'}; {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'binary_operator', 'children': ['129', '132'], 'value': '*'}; {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '132', 'type': 'float', 'children': [], 'value': '1e9'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'dt'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'tz_localize'}; {'id': '135', 'type': 'argument_list', 'children': ['136']}; {'id': '136', 'type': 'string', 'children': [], 'value': '"utc"'}; {'id': '137', 'type': 'if_statement', 'children': ['138', '143']}; {'id': '138', 'type': 'comparison_operator', 'children': ['139', '140'], 'value': 'in'}; {'id': '139', 'type': 'string', 'children': [], 'value': '"last_position"'}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '143', 'type': 'block', 'children': ['144']}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}; {'id': '145', 'type': 'assignment', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '147', 'type': 'call', 'children': ['148', '156']}; {'id': '148', 'type': 'attribute', 'children': ['149', '155']}; {'id': '149', 'type': 'call', 'children': ['150', '153']}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '153', 'type': 'argument_list', 'children': ['154']}; {'id': '154', 'type': 'string', 'children': [], 'value': '"last_position == last_position"'}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'assign'}; {'id': '156', 'type': 'argument_list', 'children': ['157']}; {'id': '157', 'type': 'keyword_argument', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'last_position'}; {'id': '159', 'type': 'call', 'children': ['160', '174']}; {'id': '160', 'type': 'attribute', 'children': ['161', '173']}; {'id': '161', 'type': 'attribute', 'children': ['162', '172']}; {'id': '162', 'type': 'call', 'children': ['163', '166']}; {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'pd'}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'to_datetime'}; {'id': '166', 'type': 'argument_list', 'children': ['167']}; {'id': '167', 'type': 'binary_operator', 'children': ['168', '171'], 'value': '*'}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'last_position'}; {'id': '171', 'type': 'float', 'children': [], 'value': '1e9'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'dt'}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'tz_localize'}; {'id': '174', 'type': 'argument_list', 'children': ['175']}; {'id': '175', 'type': 'string', 'children': [], 'value': '"utc"'}; {'id': '176', 'type': 'return_statement', 'children': ['177']}; {'id': '177', 'type': 'call', 'children': ['178', '181']}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'sort_values'}; {'id': '181', 'type': 'argument_list', 'children': ['182']}; {'id': '182', 'type': 'string', 'children': [], 'value': '"timestamp"'}
def _format_dataframe( df: pd.DataFrame, nautical_units=True ) -> pd.DataFrame: if "callsign" in df.columns and df.callsign.dtype == object: df.callsign = df.callsign.str.strip() if nautical_units: df.altitude = df.altitude / 0.3048 if "geoaltitude" in df.columns: df.geoaltitude = df.geoaltitude / 0.3048 if "groundspeed" in df.columns: df.groundspeed = df.groundspeed / 1852 * 3600 if "vertical_rate" in df.columns: df.vertical_rate = df.vertical_rate / 0.3048 * 60 df.timestamp = pd.to_datetime(df.timestamp * 1e9).dt.tz_localize("utc") if "last_position" in df.columns: df = df.query("last_position == last_position").assign( last_position=pd.to_datetime( df.last_position * 1e9 ).dt.tz_localize("utc") ) return df.sort_values("timestamp")
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_package_indexes_in_dir'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'simple_dir'}; {'id': '6', 'type': 'block', 'children': ['7', '26', '51']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'packages'}; {'id': '10', 'type': 'call', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '12', 'type': 'argument_list', 'children': ['13']}; {'id': '13', 'type': 'set_comprehension', 'children': ['14', '18']}; {'id': '14', 'type': 'call', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'canonicalize_name'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '18', 'type': 'for_in_clause', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '20', 'type': 'call', 'children': ['21', '24']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'listdir'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'simple_dir'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}; {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'packages'}; {'id': '29', 'type': 'list_comprehension', 'children': ['30', '31', '34']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '31', 'type': 'for_in_clause', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'packages'}; {'id': '34', 'type': 'if_clause', 'children': ['35']}; {'id': '35', 'type': 'call', 'children': ['36', '41']}; {'id': '36', 'type': 'attribute', 'children': ['37', '40']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'isdir'}; {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '48']}; {'id': '43', 'type': 'attribute', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '48', 'type': 'argument_list', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'simple_dir'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '51', 'type': 'return_statement', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'packages'}
def find_package_indexes_in_dir(self, simple_dir): packages = sorted( { canonicalize_name(x) for x in os.listdir(simple_dir) } ) packages = [x for x in packages if os.path.isdir(os.path.join(simple_dir, x))] return packages
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'factorize'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '11', '14']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'train'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'test'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'features'}; {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'na_value'}; {'id': '9', 'type': 'unary_operator', 'children': ['10'], 'value': '-'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '9999'}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'full'}; {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '16', 'type': 'True', 'children': []}; {'id': '17', 'type': 'block', 'children': ['18', '134']}; {'id': '18', 'type': 'for_statement', 'children': ['19', '20', '21']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'features'}; {'id': '21', 'type': 'block', 'children': ['22', '72', '85', '98']}; {'id': '22', 'type': 'if_statement', 'children': ['23', '24', '54']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'full'}; {'id': '24', 'type': 'block', 'children': ['25', '40']}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'vs'}; {'id': '28', 'type': 'call', 'children': ['29', '32']}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'pd'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'concat'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}; {'id': '33', 'type': 'list', 'children': ['34', '37'], 'value': '[train[column], test[column]]'}; {'id': '34', 'type': 'subscript', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'train'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '37', 'type': 'subscript', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'test'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}; {'id': '41', 'type': 'assignment', 'children': ['42', '45']}; {'id': '42', 'type': 'pattern_list', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'indexer'}; {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'pd'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'factorize'}; {'id': '49', 'type': 'argument_list', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'vs'}; {'id': '51', 'type': 'keyword_argument', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '54', 'type': 'else_clause', 'children': ['55']}; {'id': '55', 'type': 'block', 'children': ['56']}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}; {'id': '57', 'type': 'assignment', 'children': ['58', '61']}; {'id': '58', 'type': 'pattern_list', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'indexer'}; {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'pd'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'factorize'}; {'id': '65', 'type': 'argument_list', 'children': ['66', '69']}; {'id': '66', 'type': 'subscript', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'train'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '69', 'type': 'keyword_argument', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}; {'id': '73', 'type': 'assignment', 'children': ['74', '77']}; {'id': '74', 'type': 'subscript', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'train'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'indexer'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'get_indexer'}; {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'subscript', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'train'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '90']}; {'id': '87', 'type': 'subscript', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'test'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '90', 'type': 'call', 'children': ['91', '94']}; {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'indexer'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'get_indexer'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}; {'id': '95', 'type': 'subscript', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'test'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '98', 'type': 'if_statement', 'children': ['99', '103']}; {'id': '99', 'type': 'comparison_operator', 'children': ['100', '101'], 'value': '!='}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'na_value'}; {'id': '101', 'type': 'unary_operator', 'children': ['102'], 'value': '-'}; {'id': '102', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '103', 'type': 'block', 'children': ['104', '119']}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}; {'id': '105', 'type': 'assignment', 'children': ['106', '109']}; {'id': '106', 'type': 'subscript', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'train'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '109', 'type': 'call', 'children': ['110', '115']}; {'id': '110', 'type': 'attribute', 'children': ['111', '114']}; {'id': '111', 'type': 'subscript', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'train'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '115', 'type': 'argument_list', 'children': ['116', '118']}; {'id': '116', 'type': 'unary_operator', 'children': ['117'], 'value': '-'}; {'id': '117', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'na_value'}; {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '124']}; {'id': '121', 'type': 'subscript', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'test'}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '124', 'type': 'call', 'children': ['125', '130']}; {'id': '125', 'type': 'attribute', 'children': ['126', '129']}; {'id': '126', 'type': 'subscript', 'children': ['127', '128']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'test'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '130', 'type': 'argument_list', 'children': ['131', '133']}; {'id': '131', 'type': 'unary_operator', 'children': ['132'], 'value': '-'}; {'id': '132', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'na_value'}; {'id': '134', 'type': 'return_statement', 'children': ['135']}; {'id': '135', 'type': 'expression_list', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'train'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'test'}
def factorize(train, test, features, na_value=-9999, full=False, sort=True): for column in features: if full: vs = pd.concat([train[column], test[column]]) labels, indexer = pd.factorize(vs, sort=sort) else: labels, indexer = pd.factorize(train[column], sort=sort) train[column] = indexer.get_indexer(train[column]) test[column] = indexer.get_indexer(test[column]) if na_value != -1: train[column] = train[column].replace(-1, na_value) test[column] = test[column].replace(-1, na_value) return train, test
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'preferred_ordinal'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'attr_name'}; {'id': '6', 'type': 'block', 'children': ['7', '16', '45']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'attr_name'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'map'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'attr_name'}; {'id': '16', 'type': 'if_statement', 'children': ['17', '22', '34']}; {'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': 'in'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'attr_name'}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'preferred_order'}; {'id': '22', 'type': 'block', 'children': ['23']}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'ordinal'}; {'id': '26', 'type': 'call', 'children': ['27', '32']}; {'id': '27', 'type': 'attribute', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'preferred_order'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'attr_name'}; {'id': '34', 'type': 'else_clause', 'children': ['35']}; {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}; {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'ordinal'}; {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'preferred_order'}; {'id': '45', 'type': 'return_statement', 'children': ['46']}; {'id': '46', 'type': 'tuple', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'ordinal'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'attr_name'}
def preferred_ordinal(cls, attr_name): attr_name = cls.map(attr_name) if attr_name in cls.preferred_order: ordinal = cls.preferred_order.index(attr_name) else: ordinal = len(cls.preferred_order) return (ordinal, attr_name)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'patience_sort'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'xs'}; {'id': '5', 'type': 'block', 'children': ['6', '8', '14']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'string', 'children': [], 'value': '\'\'\'Patience sort an iterable, xs.\n This function generates a series of pairs (x, pile), where "pile"\n is the 0-based index of the pile "x" should be placed on top of.\n Elements of "xs" must be less-than comparable.\n \'\'\''}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'pile_tops'}; {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '13', 'type': 'argument_list', 'children': []}; {'id': '14', 'type': 'for_statement', 'children': ['15', '16', '17']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'xs'}; {'id': '17', 'type': 'block', 'children': ['18', '28', '51']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'pile'}; {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'bisect'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'bisect_left'}; {'id': '25', 'type': 'argument_list', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'pile_tops'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '28', 'type': 'if_statement', 'children': ['29', '35', '43']}; {'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': '=='}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'pile'}; {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'pile_tops'}; {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}; {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'pile_tops'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '43', 'type': 'else_clause', 'children': ['44']}; {'id': '44', 'type': 'block', 'children': ['45']}; {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '50']}; {'id': '47', 'type': 'subscript', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'pile_tops'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'pile'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'yield', 'children': ['53']}; {'id': '53', 'type': 'expression_list', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'pile'}
def patience_sort(xs): '''Patience sort an iterable, xs. This function generates a series of pairs (x, pile), where "pile" is the 0-based index of the pile "x" should be placed on top of. Elements of "xs" must be less-than comparable. ''' pile_tops = list() for x in xs: pile = bisect.bisect_left(pile_tops, x) if pile == len(pile_tops): pile_tops.append(x) else: pile_tops[pile] = x yield x, pile
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '5', 'type': 'block', 'children': ['6', '15', '31', '42', '61', '66', '80', '90', '98', '169', '189', '201', '207']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'OptionParser'}; {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '__doc__'}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'call', 'children': ['17', '20']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'add_option'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '22', '25', '28']}; {'id': '21', 'type': 'string', 'children': [], 'value': '"--sizes"'}; {'id': '22', 'type': 'keyword_argument', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '24', 'type': 'False', 'children': []}; {'id': '25', 'type': 'keyword_argument', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '27', 'type': 'string', 'children': [], 'value': '"store_true"'}; {'id': '28', 'type': 'keyword_argument', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'help'}; {'id': '30', 'type': 'string', 'children': [], 'value': '"Sort by decreasing size [default: %default]"'}; {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '36']}; {'id': '33', 'type': 'pattern_list', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '36', 'type': 'call', 'children': ['37', '40']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'parse_args'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '42', 'type': 'if_statement', 'children': ['43', '49']}; {'id': '43', 'type': 'comparison_operator', 'children': ['44', '48'], 'value': '!='}; {'id': '44', 'type': 'call', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '48', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '49', 'type': 'block', 'children': ['50']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}; {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'exit'}; {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'call', 'children': ['57', '60']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'print_help'}; {'id': '60', 'type': 'argument_list', 'children': []}; {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'assignment', 'children': ['63', '65']}; {'id': '63', 'type': 'pattern_list', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'fastafile'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}; {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'sortedfastafile'}; {'id': '69', 'type': 'binary_operator', 'children': ['70', '79'], 'value': '+'}; {'id': '70', 'type': 'subscript', 'children': ['71', '78']}; {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'fastafile'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'rsplit'}; {'id': '75', 'type': 'argument_list', 'children': ['76', '77']}; {'id': '76', 'type': 'string', 'children': [], 'value': '"."'}; {'id': '77', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '78', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '79', 'type': 'string', 'children': [], 'value': '".sorted.fasta"'}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}; {'id': '81', 'type': 'assignment', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '83', 'type': 'call', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'Fasta'}; {'id': '85', 'type': 'argument_list', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'fastafile'}; {'id': '87', 'type': 'keyword_argument', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '89', 'type': 'False', 'children': []}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}; {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'fw'}; {'id': '93', 'type': 'call', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'must_open'}; {'id': '95', 'type': 'argument_list', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'sortedfastafile'}; {'id': '97', 'type': 'string', 'children': [], 'value': '"w"'}; {'id': '98', 'type': 'if_statement', 'children': ['99', '102', '156']}; {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'sizes'}; {'id': '102', 'type': 'block', 'children': ['103', '127', '146']}; {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'sortlist'}; {'id': '106', 'type': 'call', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '108', 'type': 'argument_list', 'children': ['109', '114']}; {'id': '109', 'type': 'call', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'itersizes'}; {'id': '113', 'type': 'argument_list', 'children': []}; {'id': '114', 'type': 'keyword_argument', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '116', 'type': 'lambda', 'children': ['117', '119']}; {'id': '117', 'type': 'lambda_parameters', 'children': ['118']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '119', 'type': 'tuple', 'children': ['120', '124']}; {'id': '120', 'type': 'unary_operator', 'children': ['121'], 'value': '-'}; {'id': '121', 'type': 'subscript', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '123', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '124', 'type': 'subscript', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '126', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'call', 'children': ['129', '132']}; {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}; {'id': '133', 'type': 'call', 'children': ['134', '138']}; {'id': '134', 'type': 'attribute', 'children': ['135', '136', '137']}; {'id': '135', 'type': 'string', 'children': [], 'value': '"Sort by size: max: {0}, min: {1}"'}; {'id': '136', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '138', 'type': 'argument_list', 'children': ['139', '142']}; {'id': '139', 'type': 'subscript', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'sortlist'}; {'id': '141', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '142', 'type': 'subscript', 'children': ['143', '144']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'sortlist'}; {'id': '144', 'type': 'unary_operator', 'children': ['145'], 'value': '-'}; {'id': '145', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}; {'id': '147', 'type': 'assignment', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'sortlist'}; {'id': '149', 'type': 'list_comprehension', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '151', 'type': 'for_in_clause', 'children': ['152', '155']}; {'id': '152', 'type': 'pattern_list', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'sortlist'}; {'id': '156', 'type': 'else_clause', 'children': ['157']}; {'id': '157', 'type': 'block', 'children': ['158']}; {'id': '158', 'type': 'expression_statement', 'children': ['159']}; {'id': '159', 'type': 'assignment', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'sortlist'}; {'id': '161', 'type': 'call', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '163', 'type': 'argument_list', 'children': ['164']}; {'id': '164', 'type': 'call', 'children': ['165', '168']}; {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'iterkeys'}; {'id': '168', 'type': 'argument_list', 'children': []}; {'id': '169', 'type': 'for_statement', 'children': ['170', '171', '172']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'sortlist'}; {'id': '172', 'type': 'block', 'children': ['173', '179']}; {'id': '173', 'type': 'expression_statement', 'children': ['174']}; {'id': '174', 'type': 'assignment', 'children': ['175', '176']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '176', 'type': 'subscript', 'children': ['177', '178']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'call', 'children': ['181', '184']}; {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'SeqIO'}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '184', 'type': 'argument_list', 'children': ['185', '187', '188']}; {'id': '185', 'type': 'list', 'children': ['186'], 'value': '[rec]'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'fw'}; {'id': '188', 'type': 'string', 'children': [], 'value': '"fasta"'}; {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'call', 'children': ['191', '194']}; {'id': '191', 'type': 'attribute', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '194', 'type': 'argument_list', 'children': ['195']}; {'id': '195', 'type': 'call', 'children': ['196', '199']}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}; {'id': '197', 'type': 'string', 'children': [], 'value': '"Sorted file written to `{0}`."'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '199', 'type': 'argument_list', 'children': ['200']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'sortedfastafile'}; {'id': '201', 'type': 'expression_statement', 'children': ['202']}; {'id': '202', 'type': 'call', 'children': ['203', '206']}; {'id': '203', 'type': 'attribute', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'fw'}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'close'}; {'id': '206', 'type': 'argument_list', 'children': []}; {'id': '207', 'type': 'return_statement', 'children': ['208']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'sortedfastafile'}
def sort(args): p = OptionParser(sort.__doc__) p.add_option("--sizes", default=False, action="store_true", help="Sort by decreasing size [default: %default]") opts, args = p.parse_args(args) if len(args) != 1: sys.exit(p.print_help()) fastafile, = args sortedfastafile = fastafile.rsplit(".", 1)[0] + ".sorted.fasta" f = Fasta(fastafile, index=False) fw = must_open(sortedfastafile, "w") if opts.sizes: sortlist = sorted(f.itersizes(), key=lambda x: (-x[1], x[0])) logging.debug("Sort by size: max: {0}, min: {1}".\ format(sortlist[0], sortlist[-1])) sortlist = [x for x, s in sortlist] else: sortlist = sorted(f.iterkeys()) for key in sortlist: rec = f[key] SeqIO.write([rec], fw, "fasta") logging.debug("Sorted file written to `{0}`.".format(sortedfastafile)) fw.close() return sortedfastafile
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'posmap'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '5', 'type': 'block', 'children': ['6', '15', '26', '45', '52', '62', '68', '85', '91', '100', '106', '119', '125', '146', '152', '172', '178', '197', '203', '209', '238', '244']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'OptionParser'}; {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'posmap'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '__doc__'}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '20']}; {'id': '17', 'type': 'pattern_list', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '20', 'type': 'call', 'children': ['21', '24']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'parse_args'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '26', 'type': 'if_statement', 'children': ['27', '33']}; {'id': '27', 'type': 'comparison_operator', 'children': ['28', '32'], 'value': '!='}; {'id': '28', 'type': 'call', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '32', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '33', 'type': 'block', 'children': ['34']}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}; {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'exit'}; {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '44']}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'print_help'}; {'id': '44', 'type': 'argument_list', 'children': []}; {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '51']}; {'id': '47', 'type': 'pattern_list', 'children': ['48', '49', '50']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'frgscffile'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'fastafile'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'scf'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}; {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '55', 'type': 'call', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}; {'id': '57', 'type': 'string', 'children': [], 'value': '"faOneRecord {0} {1}"'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '59', 'type': 'argument_list', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'fastafile'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'scf'}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}; {'id': '63', 'type': 'assignment', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'scffastafile'}; {'id': '65', 'type': 'binary_operator', 'children': ['66', '67'], 'value': '+'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'scf'}; {'id': '67', 'type': 'string', 'children': [], 'value': '".fasta"'}; {'id': '68', 'type': 'if_statement', 'children': ['69', '76']}; {'id': '69', 'type': 'not_operator', 'children': ['70']}; {'id': '70', 'type': 'call', 'children': ['71', '74']}; {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'op'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'exists'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'scffastafile'}; {'id': '76', 'type': 'block', 'children': ['77']}; {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'sh'}; {'id': '80', 'type': 'argument_list', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '82', 'type': 'keyword_argument', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'outfile'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'scffastafile'}; {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'sizesfile'}; {'id': '88', 'type': 'binary_operator', 'children': ['89', '90'], 'value': '+'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'scffastafile'}; {'id': '90', 'type': 'string', 'children': [], 'value': '".sizes"'}; {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'sizes'}; {'id': '94', 'type': 'attribute', 'children': ['95', '99']}; {'id': '95', 'type': 'call', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'Sizes'}; {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'scffastafile'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'mapping'}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}; {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'scfsize'}; {'id': '103', 'type': 'subscript', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'sizes'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'scf'}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}; {'id': '107', 'type': 'call', 'children': ['108', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '111', 'type': 'argument_list', 'children': ['112']}; {'id': '112', 'type': 'call', 'children': ['113', '116']}; {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'string', 'children': [], 'value': '"`{0}` has length of {1}."'}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '116', 'type': 'argument_list', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'scf'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'scfsize'}; {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'gapsbedfile'}; {'id': '122', 'type': 'binary_operator', 'children': ['123', '124'], 'value': '+'}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'scf'}; {'id': '124', 'type': 'string', 'children': [], 'value': '".gaps.bed"'}; {'id': '125', 'type': 'if_statement', 'children': ['126', '133']}; {'id': '126', 'type': 'not_operator', 'children': ['127']}; {'id': '127', 'type': 'call', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'op'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'exists'}; {'id': '131', 'type': 'argument_list', 'children': ['132']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'gapsbedfile'}; {'id': '133', 'type': 'block', 'children': ['134', '141']}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}; {'id': '135', 'type': 'assignment', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '137', 'type': 'list', 'children': ['138', '139', '140'], 'value': '[scffastafile, "--bed", "--mingap=100"]'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'scffastafile'}; {'id': '139', 'type': 'string', 'children': [], 'value': '"--bed"'}; {'id': '140', 'type': 'string', 'children': [], 'value': '"--mingap=100"'}; {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'call', 'children': ['143', '144']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'gaps'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}; {'id': '147', 'type': 'assignment', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'posmapfile'}; {'id': '149', 'type': 'binary_operator', 'children': ['150', '151'], 'value': '+'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'scf'}; {'id': '151', 'type': 'string', 'children': [], 'value': '".posmap"'}; {'id': '152', 'type': 'if_statement', 'children': ['153', '160']}; {'id': '153', 'type': 'not_operator', 'children': ['154']}; {'id': '154', 'type': 'call', 'children': ['155', '158']}; {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'op'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'exists'}; {'id': '158', 'type': 'argument_list', 'children': ['159']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'posmapfile'}; {'id': '160', 'type': 'block', 'children': ['161', '167']}; {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'assignment', 'children': ['163', '164']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '164', 'type': 'list', 'children': ['165', '166'], 'value': '[frgscffile, scf]'}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'frgscffile'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'scf'}; {'id': '167', 'type': 'expression_statement', 'children': ['168']}; {'id': '168', 'type': 'call', 'children': ['169', '170']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '170', 'type': 'argument_list', 'children': ['171']}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}; {'id': '173', 'type': 'assignment', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'bedfile'}; {'id': '175', 'type': 'binary_operator', 'children': ['176', '177'], 'value': '+'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'scf'}; {'id': '177', 'type': 'string', 'children': [], 'value': '".bed"'}; {'id': '178', 'type': 'if_statement', 'children': ['179', '186']}; {'id': '179', 'type': 'not_operator', 'children': ['180']}; {'id': '180', 'type': 'call', 'children': ['181', '184']}; {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'op'}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'exists'}; {'id': '184', 'type': 'argument_list', 'children': ['185']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'bedfile'}; {'id': '186', 'type': 'block', 'children': ['187', '192']}; {'id': '187', 'type': 'expression_statement', 'children': ['188']}; {'id': '188', 'type': 'assignment', 'children': ['189', '190']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '190', 'type': 'list', 'children': ['191'], 'value': '[posmapfile]'}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'posmapfile'}; {'id': '192', 'type': 'expression_statement', 'children': ['193']}; {'id': '193', 'type': 'call', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'bed'}; {'id': '195', 'type': 'argument_list', 'children': ['196']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '197', 'type': 'expression_statement', 'children': ['198']}; {'id': '198', 'type': 'assignment', 'children': ['199', '200']}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'bedpefile'}; {'id': '200', 'type': 'binary_operator', 'children': ['201', '202'], 'value': '+'}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'scf'}; {'id': '202', 'type': 'string', 'children': [], 'value': '".bedpe"'}; {'id': '203', 'type': 'expression_statement', 'children': ['204']}; {'id': '204', 'type': 'assignment', 'children': ['205', '206']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'pairsbedfile'}; {'id': '206', 'type': 'binary_operator', 'children': ['207', '208'], 'value': '+'}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'scf'}; {'id': '208', 'type': 'string', 'children': [], 'value': '".pairs.bed"'}; {'id': '209', 'type': 'if_statement', 'children': ['210', '225']}; {'id': '210', 'type': 'not_operator', 'children': ['211']}; {'id': '211', 'type': '()', 'children': ['212']}; {'id': '212', 'type': 'boolean_operator', 'children': ['213', '219'], 'value': 'and'}; {'id': '213', 'type': 'call', 'children': ['214', '217']}; {'id': '214', 'type': 'attribute', 'children': ['215', '216']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'op'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'exists'}; {'id': '217', 'type': 'argument_list', 'children': ['218']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'bedpefile'}; {'id': '219', 'type': 'call', 'children': ['220', '223']}; {'id': '220', 'type': 'attribute', 'children': ['221', '222']}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'op'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'exists'}; {'id': '223', 'type': 'argument_list', 'children': ['224']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'pairsbedfile'}; {'id': '225', 'type': 'block', 'children': ['226']}; {'id': '226', 'type': 'expression_statement', 'children': ['227']}; {'id': '227', 'type': 'call', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'bed_to_bedpe'}; {'id': '229', 'type': 'argument_list', 'children': ['230', '231', '232', '235']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'bedfile'}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'bedpefile'}; {'id': '232', 'type': 'keyword_argument', 'children': ['233', '234']}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'pairsbedfile'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'pairsbedfile'}; {'id': '235', 'type': 'keyword_argument', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'ca'}; {'id': '237', 'type': 'True', 'children': []}; {'id': '238', 'type': 'expression_statement', 'children': ['239']}; {'id': '239', 'type': 'call', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'Coverage'}; {'id': '241', 'type': 'argument_list', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'bedfile'}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'sizesfile'}; {'id': '244', 'type': 'expression_statement', 'children': ['245']}; {'id': '245', 'type': 'call', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'Coverage'}; {'id': '247', 'type': 'argument_list', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'pairsbedfile'}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'sizesfile'}
def posmap(args): p = OptionParser(posmap.__doc__) opts, args = p.parse_args(args) if len(args) != 3: sys.exit(p.print_help()) frgscffile, fastafile, scf = args cmd = "faOneRecord {0} {1}".format(fastafile, scf) scffastafile = scf + ".fasta" if not op.exists(scffastafile): sh(cmd, outfile=scffastafile) sizesfile = scffastafile + ".sizes" sizes = Sizes(scffastafile).mapping scfsize = sizes[scf] logging.debug("`{0}` has length of {1}.".format(scf, scfsize)) gapsbedfile = scf + ".gaps.bed" if not op.exists(gapsbedfile): args = [scffastafile, "--bed", "--mingap=100"] gaps(args) posmapfile = scf + ".posmap" if not op.exists(posmapfile): args = [frgscffile, scf] query(args) bedfile = scf + ".bed" if not op.exists(bedfile): args = [posmapfile] bed(args) bedpefile = scf + ".bedpe" pairsbedfile = scf + ".pairs.bed" if not (op.exists(bedpefile) and op.exists(pairsbedfile)): bed_to_bedpe(bedfile, bedpefile, pairsbedfile=pairsbedfile, ca=True) Coverage(bedfile, sizesfile) Coverage(pairsbedfile, sizesfile)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'shred'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '5', 'type': 'block', 'children': ['6', '15', '26', '46', '51', '58', '64']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'OptionParser'}; {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'shred'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '__doc__'}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '20']}; {'id': '17', 'type': 'pattern_list', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '20', 'type': 'call', 'children': ['21', '24']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'parse_args'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '26', 'type': 'if_statement', 'children': ['27', '33']}; {'id': '27', 'type': 'comparison_operator', 'children': ['28', '32'], 'value': '!='}; {'id': '28', 'type': 'call', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '32', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '33', 'type': 'block', 'children': ['34']}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}; {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'exit'}; {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'not_operator', 'children': ['41']}; {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'print_help'}; {'id': '45', 'type': 'argument_list', 'children': []}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}; {'id': '47', 'type': 'assignment', 'children': ['48', '50']}; {'id': '48', 'type': 'pattern_list', 'children': ['49']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '54', 'type': 'call', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'UnitigLayout'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}; {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'shred'}; {'id': '63', 'type': 'argument_list', 'children': []}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}; {'id': '65', 'type': 'call', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'print_to_file'}; {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'keyword_argument', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'inplace'}; {'id': '72', 'type': 'True', 'children': []}
def shred(args): p = OptionParser(shred.__doc__) opts, args = p.parse_args(args) if len(args) != 1: sys.exit(not p.print_help()) s, = args u = UnitigLayout(s) u.shred() u.print_to_file(inplace=True)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'index'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '5', 'type': 'block', 'children': ['6', '15', '26', '45', '50', '56', '65', '82', '88', '97']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'OptionParser'}; {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '__doc__'}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '20']}; {'id': '17', 'type': 'pattern_list', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '20', 'type': 'call', 'children': ['21', '24']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'parse_args'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '26', 'type': 'if_statement', 'children': ['27', '33']}; {'id': '27', 'type': 'comparison_operator', 'children': ['28', '32'], 'value': '!='}; {'id': '28', 'type': 'call', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '32', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '33', 'type': 'block', 'children': ['34']}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}; {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'exit'}; {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '44']}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'print_help'}; {'id': '44', 'type': 'argument_list', 'children': []}; {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '49']}; {'id': '47', 'type': 'pattern_list', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'frgscffile'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}; {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'gzfile'}; {'id': '53', 'type': 'binary_operator', 'children': ['54', '55'], 'value': '+'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'frgscffile'}; {'id': '55', 'type': 'string', 'children': [], 'value': '".gz"'}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}; {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}; {'id': '61', 'type': 'string', 'children': [], 'value': '"bgzip -c {0}"'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'frgscffile'}; {'id': '65', 'type': 'if_statement', 'children': ['66', '73']}; {'id': '66', 'type': 'not_operator', 'children': ['67']}; {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'op'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'exists'}; {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'gzfile'}; {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}; {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'sh'}; {'id': '77', 'type': 'argument_list', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '79', 'type': 'keyword_argument', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'outfile'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'gzfile'}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}; {'id': '83', 'type': 'assignment', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'tbifile'}; {'id': '85', 'type': 'binary_operator', 'children': ['86', '87'], 'value': '+'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'gzfile'}; {'id': '87', 'type': 'string', 'children': [], 'value': '".tbi"'}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}; {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}; {'id': '93', 'type': 'string', 'children': [], 'value': '"tabix -s 2 -b 3 -e 4 {0}"'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'gzfile'}; {'id': '97', 'type': 'if_statement', 'children': ['98', '105']}; {'id': '98', 'type': 'not_operator', 'children': ['99']}; {'id': '99', 'type': 'call', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'op'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'exists'}; {'id': '103', 'type': 'argument_list', 'children': ['104']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'tbifile'}; {'id': '105', 'type': 'block', 'children': ['106']}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}; {'id': '107', 'type': 'call', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'sh'}; {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'cmd'}
def index(args): p = OptionParser(index.__doc__) opts, args = p.parse_args(args) if len(args) != 1: sys.exit(p.print_help()) frgscffile, = args gzfile = frgscffile + ".gz" cmd = "bgzip -c {0}".format(frgscffile) if not op.exists(gzfile): sh(cmd, outfile=gzfile) tbifile = gzfile + ".tbi" cmd = "tabix -s 2 -b 3 -e 4 {0}".format(gzfile) if not op.exists(tbifile): sh(cmd)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '5', 'type': 'block', 'children': ['6', '12', '21', '37', '56', '62', '68', '75', '86', '106', '111', '117', '157']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'valid_sort_methods'}; {'id': '9', 'type': 'tuple', 'children': ['10', '11']}; {'id': '10', 'type': 'string', 'children': [], 'value': '"unix"'}; {'id': '11', 'type': 'string', 'children': [], 'value': '"topo"'}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'OptionParser'}; {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': '__doc__'}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'call', 'children': ['23', '26']}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'add_option'}; {'id': '26', 'type': 'argument_list', 'children': ['27', '28', '31', '34']}; {'id': '27', 'type': 'string', 'children': [], 'value': '"--method"'}; {'id': '28', 'type': 'keyword_argument', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '30', 'type': 'string', 'children': [], 'value': '"unix"'}; {'id': '31', 'type': 'keyword_argument', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'choices'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'valid_sort_methods'}; {'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'help'}; {'id': '36', 'type': 'string', 'children': [], 'value': '"Specify sort method [default: %default]"'}; {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'call', 'children': ['39', '42']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'add_option'}; {'id': '42', 'type': 'argument_list', 'children': ['43', '44', '47', '50', '53']}; {'id': '43', 'type': 'string', 'children': [], 'value': '"-i"'}; {'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'dest'}; {'id': '46', 'type': 'string', 'children': [], 'value': '"inplace"'}; {'id': '47', 'type': 'keyword_argument', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '49', 'type': 'False', 'children': []}; {'id': '50', 'type': 'keyword_argument', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '52', 'type': 'string', 'children': [], 'value': '"store_true"'}; {'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'help'}; {'id': '55', 'type': 'string', 'children': [], 'value': '"If doing a unix sort, perform sort inplace [default: %default]"'}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}; {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'set_tmpdir'}; {'id': '61', 'type': 'argument_list', 'children': []}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}; {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'set_outfile'}; {'id': '67', 'type': 'argument_list', 'children': []}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}; {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'set_home'}; {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'string', 'children': [], 'value': '"gt"'}; {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '80']}; {'id': '77', 'type': 'pattern_list', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '80', 'type': 'call', 'children': ['81', '84']}; {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'parse_args'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '86', 'type': 'if_statement', 'children': ['87', '93']}; {'id': '87', 'type': 'comparison_operator', 'children': ['88', '92'], 'value': '!='}; {'id': '88', 'type': 'call', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '92', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '93', 'type': 'block', 'children': ['94']}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}; {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'exit'}; {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'not_operator', 'children': ['101']}; {'id': '101', 'type': 'call', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'print_help'}; {'id': '105', 'type': 'argument_list', 'children': []}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}; {'id': '107', 'type': 'assignment', 'children': ['108', '110']}; {'id': '108', 'type': 'pattern_list', 'children': ['109']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'gffile'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'sortedgff'}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'outfile'}; {'id': '117', 'type': 'if_statement', 'children': ['118', '121']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'inplace'}; {'id': '121', 'type': 'block', 'children': ['122']}; {'id': '122', 'type': 'if_statement', 'children': ['123', '141']}; {'id': '123', 'type': 'boolean_operator', 'children': ['124', '129'], 'value': 'or'}; {'id': '124', 'type': 'comparison_operator', 'children': ['125', '128'], 'value': '=='}; {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '128', 'type': 'string', 'children': [], 'value': '"topo"'}; {'id': '129', 'type': '()', 'children': ['130']}; {'id': '130', 'type': 'boolean_operator', 'children': ['131', '136'], 'value': 'and'}; {'id': '131', 'type': 'comparison_operator', 'children': ['132', '135'], 'value': '=='}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '135', 'type': 'string', 'children': [], 'value': '"unix"'}; {'id': '136', 'type': 'comparison_operator', 'children': ['137', '138'], 'value': 'in'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'gffile'}; {'id': '138', 'type': 'tuple', 'children': ['139', '140']}; {'id': '139', 'type': 'string', 'children': [], 'value': '"-"'}; {'id': '140', 'type': 'string', 'children': [], 'value': '"stdin"'}; {'id': '141', 'type': 'block', 'children': ['142', '151']}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}; {'id': '143', 'type': 'call', 'children': ['144', '147']}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'binary_operator', 'children': ['149', '150'], 'value': '+'}; {'id': '149', 'type': 'string', 'children': [], 'value': '"Cannot perform inplace sort when method is `topo`"'}; {'id': '150', 'type': 'string', 'children': [], 'value': '" or method is `unix` and input is `stdin` stream"'}; {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'call', 'children': ['153', '156']}; {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'exit'}; {'id': '156', 'type': 'argument_list', 'children': []}; {'id': '157', 'type': 'if_statement', 'children': ['158', '163', '216']}; {'id': '158', 'type': 'comparison_operator', 'children': ['159', '162'], 'value': '=='}; {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '162', 'type': 'string', 'children': [], 'value': '"unix"'}; {'id': '163', 'type': 'block', 'children': ['164', '168', '177', '193', '208']}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}; {'id': '165', 'type': 'assignment', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '167', 'type': 'string', 'children': [], 'value': '"sort"'}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}; {'id': '169', 'type': 'augmented_assignment', 'children': ['170', '171'], 'value': '+='}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '171', 'type': 'call', 'children': ['172', '175']}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}; {'id': '173', 'type': 'string', 'children': [], 'value': '" -k1,1 -k4,4n {0}"'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '175', 'type': 'argument_list', 'children': ['176']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'gffile'}; {'id': '177', 'type': 'if_statement', 'children': ['178', '181']}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'tmpdir'}; {'id': '181', 'type': 'block', 'children': ['182']}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}; {'id': '183', 'type': 'augmented_assignment', 'children': ['184', '185'], 'value': '+='}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '185', 'type': 'call', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}; {'id': '187', 'type': 'string', 'children': [], 'value': '" -T {0}"'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '189', 'type': 'argument_list', 'children': ['190']}; {'id': '190', 'type': 'attribute', 'children': ['191', '192']}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'tmpdir'}; {'id': '193', 'type': 'if_statement', 'children': ['194', '197']}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'inplace'}; {'id': '197', 'type': 'block', 'children': ['198', '204']}; {'id': '198', 'type': 'expression_statement', 'children': ['199']}; {'id': '199', 'type': 'augmented_assignment', 'children': ['200', '201'], 'value': '+='}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '201', 'type': 'attribute', 'children': ['202', '203']}; {'id': '202', 'type': 'string', 'children': [], 'value': '" -o {0}"'}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'gffile'}; {'id': '204', 'type': 'expression_statement', 'children': ['205']}; {'id': '205', 'type': 'assignment', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'sortedgff'}; {'id': '207', 'type': 'None', 'children': []}; {'id': '208', 'type': 'expression_statement', 'children': ['209']}; {'id': '209', 'type': 'call', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'sh'}; {'id': '211', 'type': 'argument_list', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '213', 'type': 'keyword_argument', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'outfile'}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'sortedgff'}; {'id': '216', 'type': 'elif_clause', 'children': ['217', '222']}; {'id': '217', 'type': 'comparison_operator', 'children': ['218', '221'], 'value': '=='}; {'id': '218', 'type': 'attribute', 'children': ['219', '220']}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '221', 'type': 'string', 'children': [], 'value': '"topo"'}; {'id': '222', 'type': 'block', 'children': ['223', '229', '256', '272', '281']}; {'id': '223', 'type': 'expression_statement', 'children': ['224']}; {'id': '224', 'type': 'assignment', 'children': ['225', '226']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'GT_HOME'}; {'id': '226', 'type': 'attribute', 'children': ['227', '228']}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'gt_home'}; {'id': '229', 'type': 'if_statement', 'children': ['230', '237']}; {'id': '230', 'type': 'not_operator', 'children': ['231']}; {'id': '231', 'type': 'call', 'children': ['232', '235']}; {'id': '232', 'type': 'attribute', 'children': ['233', '234']}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'op'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'isdir'}; {'id': '235', 'type': 'argument_list', 'children': ['236']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'GT_HOME'}; {'id': '237', 'type': 'block', 'children': ['238', '250']}; {'id': '238', 'type': 'expression_statement', 'children': ['239']}; {'id': '239', 'type': 'call', 'children': ['240', '243']}; {'id': '240', 'type': 'attribute', 'children': ['241', '242']}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '243', 'type': 'argument_list', 'children': ['244']}; {'id': '244', 'type': 'call', 'children': ['245', '248']}; {'id': '245', 'type': 'attribute', 'children': ['246', '247']}; {'id': '246', 'type': 'string', 'children': [], 'value': '"GT_HOME={0} directory does not exist"'}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '248', 'type': 'argument_list', 'children': ['249']}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'GT_HOME'}; {'id': '250', 'type': 'expression_statement', 'children': ['251']}; {'id': '251', 'type': 'call', 'children': ['252', '255']}; {'id': '252', 'type': 'attribute', 'children': ['253', '254']}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'exit'}; {'id': '255', 'type': 'argument_list', 'children': []}; {'id': '256', 'type': 'expression_statement', 'children': ['257']}; {'id': '257', 'type': 'assignment', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '259', 'type': 'call', 'children': ['260', '263']}; {'id': '260', 'type': 'attribute', 'children': ['261', '262']}; {'id': '261', 'type': 'string', 'children': [], 'value': '"{0}"'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '263', 'type': 'argument_list', 'children': ['264']}; {'id': '264', 'type': 'call', 'children': ['265', '268']}; {'id': '265', 'type': 'attribute', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'op'}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '268', 'type': 'argument_list', 'children': ['269', '270', '271']}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'GT_HOME'}; {'id': '270', 'type': 'string', 'children': [], 'value': '"bin"'}; {'id': '271', 'type': 'string', 'children': [], 'value': '"gt"'}; {'id': '272', 'type': 'expression_statement', 'children': ['273']}; {'id': '273', 'type': 'augmented_assignment', 'children': ['274', '275'], 'value': '+='}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '275', 'type': 'call', 'children': ['276', '279']}; {'id': '276', 'type': 'attribute', 'children': ['277', '278']}; {'id': '277', 'type': 'string', 'children': [], 'value': '" gff3 -sort -tidy -retainids -addids no {0}"'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '279', 'type': 'argument_list', 'children': ['280']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'gffile'}; {'id': '281', 'type': 'expression_statement', 'children': ['282']}; {'id': '282', 'type': 'call', 'children': ['283', '284']}; {'id': '283', 'type': 'identifier', 'children': [], 'value': 'sh'}; {'id': '284', 'type': 'argument_list', 'children': ['285', '286']}; {'id': '285', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '286', 'type': 'keyword_argument', 'children': ['287', '288']}; {'id': '287', 'type': 'identifier', 'children': [], 'value': 'outfile'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'sortedgff'}
def sort(args): valid_sort_methods = ("unix", "topo") p = OptionParser(sort.__doc__) p.add_option("--method", default="unix", choices=valid_sort_methods, help="Specify sort method [default: %default]") p.add_option("-i", dest="inplace", default=False, action="store_true", help="If doing a unix sort, perform sort inplace [default: %default]") p.set_tmpdir() p.set_outfile() p.set_home("gt") opts, args = p.parse_args(args) if len(args) != 1: sys.exit(not p.print_help()) gffile, = args sortedgff = opts.outfile if opts.inplace: if opts.method == "topo" or (opts.method == "unix" and gffile in ("-", "stdin")): logging.error("Cannot perform inplace sort when method is `topo`" + \ " or method is `unix` and input is `stdin` stream") sys.exit() if opts.method == "unix": cmd = "sort" cmd += " -k1,1 -k4,4n {0}".format(gffile) if opts.tmpdir: cmd += " -T {0}".format(opts.tmpdir) if opts.inplace: cmd += " -o {0}".gffile sortedgff = None sh(cmd, outfile=sortedgff) elif opts.method == "topo": GT_HOME = opts.gt_home if not op.isdir(GT_HOME): logging.error("GT_HOME={0} directory does not exist".format(GT_HOME)) sys.exit() cmd = "{0}".format(op.join(GT_HOME, "bin", "gt")) cmd += " gff3 -sort -tidy -retainids -addids no {0}".format(gffile) sh(cmd, outfile=sortedgff)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_layout'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'thread'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'listfile'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '8', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '9', 'type': 'block', 'children': ['10', '17', '31', '37', '45', '58', '62', '68', '104', '114', '127', '143', '150', '181', '198', '204']}; {'id': '10', 'type': 'import_from_statement', 'children': ['11', '15']}; {'id': '11', 'type': 'dotted_name', 'children': ['12', '13', '14']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'jcvi'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'formats'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '15', 'type': 'dotted_name', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'DictFile'}; {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'outfile'}; {'id': '20', 'type': 'binary_operator', 'children': ['21', '30'], 'value': '+'}; {'id': '21', 'type': 'subscript', 'children': ['22', '29']}; {'id': '22', 'type': 'call', 'children': ['23', '26']}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'listfile'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'rsplit'}; {'id': '26', 'type': 'argument_list', 'children': ['27', '28']}; {'id': '27', 'type': 'string', 'children': [], 'value': '"."'}; {'id': '28', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '29', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '30', 'type': 'string', 'children': [], 'value': '".sorted.list"'}; {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'threadorder'}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'thread'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'fw'}; {'id': '40', 'type': 'call', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '42', 'type': 'argument_list', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'outfile'}; {'id': '44', 'type': 'string', 'children': [], 'value': '"w"'}; {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'lt'}; {'id': '48', 'type': 'call', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'DictFile'}; {'id': '50', 'type': 'argument_list', 'children': ['51', '52', '55']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'listfile'}; {'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'keypos'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'valuepos'}; {'id': '57', 'type': 'None', 'children': []}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}; {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'threaded'}; {'id': '61', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}; {'id': '63', 'type': 'assignment', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'imported'}; {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '67', 'type': 'argument_list', 'children': []}; {'id': '68', 'type': 'for_statement', 'children': ['69', '70', '71']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'thread'}; {'id': '71', 'type': 'block', 'children': ['72', '78', '84', '91', '97']}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}; {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'accn'}; {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'accn'}; {'id': '78', 'type': 'if_statement', 'children': ['79', '82']}; {'id': '79', 'type': 'comparison_operator', 'children': ['80', '81'], 'value': 'not'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'accn'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'lt'}; {'id': '82', 'type': 'block', 'children': ['83']}; {'id': '83', 'type': 'continue_statement', 'children': []}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}; {'id': '85', 'type': 'call', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'imported'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'accn'}; {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'atoms'}; {'id': '94', 'type': 'subscript', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'lt'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'accn'}; {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'call', 'children': ['99', '102']}; {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'threaded'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'atoms'}; {'id': '104', 'type': 'assert_statement', 'children': ['105']}; {'id': '105', 'type': 'comparison_operator', 'children': ['106', '110'], 'value': '=='}; {'id': '106', 'type': 'call', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'threaded'}; {'id': '110', 'type': 'call', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'imported'}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}; {'id': '115', 'type': 'assignment', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'total'}; {'id': '117', 'type': 'call', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '119', 'type': 'generator_expression', 'children': ['120', '121']}; {'id': '120', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '121', 'type': 'for_in_clause', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '123', 'type': 'call', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '125', 'type': 'argument_list', 'children': ['126']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'listfile'}; {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'call', 'children': ['129', '132']}; {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}; {'id': '133', 'type': 'call', 'children': ['134', '137']}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}; {'id': '135', 'type': 'string', 'children': [], 'value': '"Total: {0}, currently threaded: {1}"'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '137', 'type': 'argument_list', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'total'}; {'id': '139', 'type': 'call', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'threaded'}; {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'assignment', 'children': ['145', '146']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'fp'}; {'id': '146', 'type': 'call', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '148', 'type': 'argument_list', 'children': ['149']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'listfile'}; {'id': '150', 'type': 'for_statement', 'children': ['151', '152', '153']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'fp'}; {'id': '153', 'type': 'block', 'children': ['154', '162', '168', '174']}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}; {'id': '155', 'type': 'assignment', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'atoms'}; {'id': '157', 'type': 'call', 'children': ['158', '161']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '161', 'type': 'argument_list', 'children': []}; {'id': '162', 'type': 'expression_statement', 'children': ['163']}; {'id': '163', 'type': 'assignment', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'accn'}; {'id': '165', 'type': 'subscript', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'atoms'}; {'id': '167', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '168', 'type': 'if_statement', 'children': ['169', '172']}; {'id': '169', 'type': 'comparison_operator', 'children': ['170', '171'], 'value': 'in'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'accn'}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'imported'}; {'id': '172', 'type': 'block', 'children': ['173']}; {'id': '173', 'type': 'continue_statement', 'children': []}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}; {'id': '175', 'type': 'call', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'insert_into_threaded'}; {'id': '177', 'type': 'argument_list', 'children': ['178', '179', '180']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'atoms'}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'threaded'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'threadorder'}; {'id': '181', 'type': 'for_statement', 'children': ['182', '183', '184']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'atoms'}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'threaded'}; {'id': '184', 'type': 'block', 'children': ['185']}; {'id': '185', 'type': 'expression_statement', 'children': ['186']}; {'id': '186', 'type': 'call', 'children': ['187', '188']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '188', 'type': 'argument_list', 'children': ['189', '195']}; {'id': '189', 'type': 'call', 'children': ['190', '193']}; {'id': '190', 'type': 'attribute', 'children': ['191', '192']}; {'id': '191', 'type': 'string', 'children': [], 'value': '"\\t"'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '193', 'type': 'argument_list', 'children': ['194']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'atoms'}; {'id': '195', 'type': 'keyword_argument', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'fw'}; {'id': '198', 'type': 'expression_statement', 'children': ['199']}; {'id': '199', 'type': 'call', 'children': ['200', '203']}; {'id': '200', 'type': 'attribute', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'fw'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'close'}; {'id': '203', 'type': 'argument_list', 'children': []}; {'id': '204', 'type': 'expression_statement', 'children': ['205']}; {'id': '205', 'type': 'call', 'children': ['206', '209']}; {'id': '206', 'type': 'attribute', 'children': ['207', '208']}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '209', 'type': 'argument_list', 'children': ['210']}; {'id': '210', 'type': 'call', 'children': ['211', '214']}; {'id': '211', 'type': 'attribute', 'children': ['212', '213']}; {'id': '212', 'type': 'string', 'children': [], 'value': '"File `{0}` sorted to `{1}`."'}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '214', 'type': 'argument_list', 'children': ['215', '216']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'outfile'}; {'id': '216', 'type': 'attribute', 'children': ['217', '218']}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'thread'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'filename'}
def sort_layout(thread, listfile, column=0): from jcvi.formats.base import DictFile outfile = listfile.rsplit(".", 1)[0] + ".sorted.list" threadorder = thread.order fw = open(outfile, "w") lt = DictFile(listfile, keypos=column, valuepos=None) threaded = [] imported = set() for t in thread: accn = t.accn if accn not in lt: continue imported.add(accn) atoms = lt[accn] threaded.append(atoms) assert len(threaded) == len(imported) total = sum(1 for x in open(listfile)) logging.debug("Total: {0}, currently threaded: {1}".format(total, len(threaded))) fp = open(listfile) for row in fp: atoms = row.split() accn = atoms[0] if accn in imported: continue insert_into_threaded(atoms, threaded, threadorder) for atoms in threaded: print("\t".join(atoms), file=fw) fw.close() logging.debug("File `{0}` sorted to `{1}`.".format(outfile, thread.filename))
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'fromgroups'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '5', 'type': 'block', 'children': ['6', '13', '22', '33', '53', '59', '67', '78', '85', '102']}; {'id': '6', 'type': 'import_from_statement', 'children': ['7', '11']}; {'id': '7', 'type': 'dotted_name', 'children': ['8', '9', '10']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'jcvi'}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'formats'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'bed'}; {'id': '11', 'type': 'dotted_name', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'Bed'}; {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '16', 'type': 'call', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'OptionParser'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'fromgroups'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': '__doc__'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'assignment', 'children': ['24', '27']}; {'id': '24', 'type': 'pattern_list', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'parse_args'}; {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '33', 'type': 'if_statement', 'children': ['34', '40']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '39'], 'value': '<'}; {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '39', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '40', 'type': 'block', 'children': ['41']}; {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '46']}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'exit'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}; {'id': '47', 'type': 'not_operator', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '52']}; {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'print_help'}; {'id': '52', 'type': 'argument_list', 'children': []}; {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'groupsfile'}; {'id': '56', 'type': 'subscript', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '58', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'bedfiles'}; {'id': '62', 'type': 'subscript', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '64', 'type': 'slice', 'children': ['65', '66']}; {'id': '65', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '66', 'type': 'colon', 'children': []}; {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'beds'}; {'id': '70', 'type': 'list_comprehension', 'children': ['71', '75']}; {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'Bed'}; {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '75', 'type': 'for_in_clause', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'bedfiles'}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}; {'id': '79', 'type': 'assignment', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'fp'}; {'id': '81', 'type': 'call', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'groupsfile'}; {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'groups'}; {'id': '88', 'type': 'list_comprehension', 'children': ['89', '99']}; {'id': '89', 'type': 'call', 'children': ['90', '97']}; {'id': '90', 'type': 'attribute', 'children': ['91', '96']}; {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '95', 'type': 'argument_list', 'children': []}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'string', 'children': [], 'value': '","'}; {'id': '99', 'type': 'for_in_clause', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'fp'}; {'id': '102', 'type': 'for_statement', 'children': ['103', '106', '113']}; {'id': '103', 'type': 'pattern_list', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'b1'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'b2'}; {'id': '106', 'type': 'call', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'product'}; {'id': '108', 'type': 'argument_list', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'beds'}; {'id': '110', 'type': 'keyword_argument', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'repeat'}; {'id': '112', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '113', 'type': 'block', 'children': ['114']}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}; {'id': '115', 'type': 'call', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'extract_pairs'}; {'id': '117', 'type': 'argument_list', 'children': ['118', '119', '120']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'b1'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'b2'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'groups'}
def fromgroups(args): from jcvi.formats.bed import Bed p = OptionParser(fromgroups.__doc__) opts, args = p.parse_args(args) if len(args) < 2: sys.exit(not p.print_help()) groupsfile = args[0] bedfiles = args[1:] beds = [Bed(x) for x in bedfiles] fp = open(groupsfile) groups = [row.strip().split(",") for row in fp] for b1, b2 in product(beds, repeat=2): extract_pairs(b1, b2, groups)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'merge_paths'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'paths'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'weights'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '19', '26']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'G'}; {'id': '12', 'type': 'call', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'make_paths'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'paths'}; {'id': '16', 'type': 'keyword_argument', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'weights'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'weights'}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'G'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'reduce_paths'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'G'}; {'id': '26', 'type': 'return_statement', 'children': ['27']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'G'}
def merge_paths(paths, weights=None): G = make_paths(paths, weights=weights) G = reduce_paths(G) return G
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'build'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '5', 'type': 'block', 'children': ['6', '13', '20', '27', '36', '52', '63', '83', '90', '106', '115', '123', '132', '138', '147', '153', '163', '168', '174']}; {'id': '6', 'type': 'import_from_statement', 'children': ['7', '11']}; {'id': '7', 'type': 'dotted_name', 'children': ['8', '9', '10']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'jcvi'}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'apps'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'cdhit'}; {'id': '11', 'type': 'dotted_name', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'deduplicate'}; {'id': '13', 'type': 'import_from_statement', 'children': ['14', '18']}; {'id': '14', 'type': 'dotted_name', 'children': ['15', '16', '17']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'jcvi'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'apps'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'vecscreen'}; {'id': '18', 'type': 'dotted_name', 'children': ['19']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'mask'}; {'id': '20', 'type': 'import_from_statement', 'children': ['21', '25']}; {'id': '21', 'type': 'dotted_name', 'children': ['22', '23', '24']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'jcvi'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'formats'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'fasta'}; {'id': '25', 'type': 'dotted_name', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '30', 'type': 'call', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'OptionParser'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'build'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': '__doc__'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}; {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'add_option'}; {'id': '41', 'type': 'argument_list', 'children': ['42', '43', '46', '49']}; {'id': '42', 'type': 'string', 'children': [], 'value': '"--nodedup"'}; {'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '45', 'type': 'False', 'children': []}; {'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '48', 'type': 'string', 'children': [], 'value': '"store_true"'}; {'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'help'}; {'id': '51', 'type': 'string', 'children': [], 'value': '"Do not deduplicate [default: deduplicate]"'}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}; {'id': '53', 'type': 'assignment', 'children': ['54', '57']}; {'id': '54', 'type': 'pattern_list', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'parse_args'}; {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '63', 'type': 'if_statement', 'children': ['64', '70']}; {'id': '64', 'type': 'comparison_operator', 'children': ['65', '69'], 'value': '!='}; {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '69', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '70', 'type': 'block', 'children': ['71']}; {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'call', 'children': ['73', '76']}; {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'exit'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}; {'id': '77', 'type': 'not_operator', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '82']}; {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'print_help'}; {'id': '82', 'type': 'argument_list', 'children': []}; {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '89']}; {'id': '85', 'type': 'pattern_list', 'children': ['86', '87', '88']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'fastafile'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'bacteria'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'pf'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}; {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'dd'}; {'id': '93', 'type': 'conditional_expression', 'children': ['94', '100', '101', '105'], 'value': 'if'}; {'id': '94', 'type': 'call', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'deduplicate'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}; {'id': '97', 'type': 'list', 'children': ['98', '99'], 'value': '[fastafile, "--pctid=100"]'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'fastafile'}; {'id': '99', 'type': 'string', 'children': [], 'value': '"--pctid=100"'}; {'id': '100', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '101', 'type': 'not_operator', 'children': ['102']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'nodedup'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'fastafile'}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}; {'id': '107', 'type': 'assignment', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'screenfasta'}; {'id': '109', 'type': 'call', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'screen'}; {'id': '111', 'type': 'argument_list', 'children': ['112']}; {'id': '112', 'type': 'list', 'children': ['113', '114'], 'value': '[dd, bacteria]'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'dd'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'bacteria'}; {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'tidyfasta'}; {'id': '118', 'type': 'call', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'mask'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}; {'id': '121', 'type': 'list', 'children': ['122'], 'value': '[screenfasta]'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'screenfasta'}; {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'sortedfasta'}; {'id': '126', 'type': 'call', 'children': ['127', '128']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '128', 'type': 'argument_list', 'children': ['129']}; {'id': '129', 'type': 'list', 'children': ['130', '131'], 'value': '[tidyfasta, "--sizes"]'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'tidyfasta'}; {'id': '131', 'type': 'string', 'children': [], 'value': '"--sizes"'}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}; {'id': '133', 'type': 'assignment', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'scaffoldfasta'}; {'id': '135', 'type': 'binary_operator', 'children': ['136', '137'], 'value': '+'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'pf'}; {'id': '137', 'type': 'string', 'children': [], 'value': '".assembly.fasta"'}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}; {'id': '139', 'type': 'call', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'list', 'children': ['143', '144', '145', '146'], 'value': '[sortedfasta, scaffoldfasta, "--prefix=scaffold_", "--sequential"]'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'sortedfasta'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'scaffoldfasta'}; {'id': '145', 'type': 'string', 'children': [], 'value': '"--prefix=scaffold_"'}; {'id': '146', 'type': 'string', 'children': [], 'value': '"--sequential"'}; {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'assignment', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'gapsplitfasta'}; {'id': '150', 'type': 'binary_operator', 'children': ['151', '152'], 'value': '+'}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'pf'}; {'id': '152', 'type': 'string', 'children': [], 'value': '".gapSplit.fasta"'}; {'id': '153', 'type': 'expression_statement', 'children': ['154']}; {'id': '154', 'type': 'assignment', 'children': ['155', '156']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '156', 'type': 'call', 'children': ['157', '160']}; {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'string', 'children': [], 'value': '"gapSplit -minGap=10 {0} {1}"'}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '160', 'type': 'argument_list', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'scaffoldfasta'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'gapsplitfasta'}; {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'call', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'sh'}; {'id': '166', 'type': 'argument_list', 'children': ['167']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}; {'id': '169', 'type': 'assignment', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'contigsfasta'}; {'id': '171', 'type': 'binary_operator', 'children': ['172', '173'], 'value': '+'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'pf'}; {'id': '173', 'type': 'string', 'children': [], 'value': '".contigs.fasta"'}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}; {'id': '175', 'type': 'call', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '177', 'type': 'argument_list', 'children': ['178']}; {'id': '178', 'type': 'list', 'children': ['179', '180', '181', '182'], 'value': '[gapsplitfasta, contigsfasta, "--prefix=contig_", "--sequential"]'}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'gapsplitfasta'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'contigsfasta'}; {'id': '181', 'type': 'string', 'children': [], 'value': '"--prefix=contig_"'}; {'id': '182', 'type': 'string', 'children': [], 'value': '"--sequential"'}
def build(args): from jcvi.apps.cdhit import deduplicate from jcvi.apps.vecscreen import mask from jcvi.formats.fasta import sort p = OptionParser(build.__doc__) p.add_option("--nodedup", default=False, action="store_true", help="Do not deduplicate [default: deduplicate]") opts, args = p.parse_args(args) if len(args) != 3: sys.exit(not p.print_help()) fastafile, bacteria, pf = args dd = deduplicate([fastafile, "--pctid=100"]) \ if not opts.nodedup else fastafile screenfasta = screen([dd, bacteria]) tidyfasta = mask([screenfasta]) sortedfasta = sort([tidyfasta, "--sizes"]) scaffoldfasta = pf + ".assembly.fasta" format([sortedfasta, scaffoldfasta, "--prefix=scaffold_", "--sequential"]) gapsplitfasta = pf + ".gapSplit.fasta" cmd = "gapSplit -minGap=10 {0} {1}".format(scaffoldfasta, gapsplitfasta) sh(cmd) contigsfasta = pf + ".contigs.fasta" format([gapsplitfasta, contigsfasta, "--prefix=contig_", "--sequential"])
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '5', 'type': 'block', 'children': ['6', '11']}; {'id': '6', 'type': 'import_statement', 'children': ['7']}; {'id': '7', 'type': 'dotted_name', 'children': ['8', '9', '10']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'jcvi'}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'formats'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'blast'}; {'id': '11', 'type': 'return_statement', 'children': ['12']}; {'id': '12', 'type': 'call', 'children': ['13', '20']}; {'id': '13', 'type': 'attribute', 'children': ['14', '19']}; {'id': '14', 'type': 'attribute', 'children': ['15', '18']}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'jcvi'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'formats'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'blast'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}; {'id': '21', 'type': 'binary_operator', 'children': ['22', '23'], 'value': '+'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '23', 'type': 'list', 'children': ['24'], 'value': '["--coords"]'}; {'id': '24', 'type': 'string', 'children': [], 'value': '"--coords"'}
def sort(args): import jcvi.formats.blast return jcvi.formats.blast.sort(args + ["--coords"])
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'coverage'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '5', 'type': 'block', 'children': ['6', '15', '34', '50', '56', '67', '87', '93', '99', '127', '139', '148', '158', '215', '221', '236', '243', '253', '283']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'OptionParser'}; {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'coverage'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '__doc__'}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'call', 'children': ['17', '20']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'add_option'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '22', '25', '31']}; {'id': '21', 'type': 'string', 'children': [], 'value': '"--format"'}; {'id': '22', 'type': 'keyword_argument', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '24', 'type': 'string', 'children': [], 'value': '"bigwig"'}; {'id': '25', 'type': 'keyword_argument', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'choices'}; {'id': '27', 'type': 'tuple', 'children': ['28', '29', '30']}; {'id': '28', 'type': 'string', 'children': [], 'value': '"bedgraph"'}; {'id': '29', 'type': 'string', 'children': [], 'value': '"bigwig"'}; {'id': '30', 'type': 'string', 'children': [], 'value': '"coverage"'}; {'id': '31', 'type': 'keyword_argument', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'help'}; {'id': '33', 'type': 'string', 'children': [], 'value': '"Output format"'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}; {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'add_option'}; {'id': '39', 'type': 'argument_list', 'children': ['40', '41', '44', '47']}; {'id': '40', 'type': 'string', 'children': [], 'value': '"--nosort"'}; {'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '43', 'type': 'False', 'children': []}; {'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '46', 'type': 'string', 'children': [], 'value': '"store_true"'}; {'id': '47', 'type': 'keyword_argument', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'help'}; {'id': '49', 'type': 'string', 'children': [], 'value': '"Do not sort BAM"'}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}; {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'set_outfile'}; {'id': '55', 'type': 'argument_list', 'children': []}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}; {'id': '57', 'type': 'assignment', 'children': ['58', '61']}; {'id': '58', 'type': 'pattern_list', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'parse_args'}; {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '67', 'type': 'if_statement', 'children': ['68', '74']}; {'id': '68', 'type': 'comparison_operator', 'children': ['69', '73'], 'value': '!='}; {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '73', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '74', 'type': 'block', 'children': ['75']}; {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'call', 'children': ['77', '80']}; {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'exit'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}; {'id': '81', 'type': 'not_operator', 'children': ['82']}; {'id': '82', 'type': 'call', 'children': ['83', '86']}; {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'print_help'}; {'id': '86', 'type': 'argument_list', 'children': []}; {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '92']}; {'id': '89', 'type': 'pattern_list', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'fastafile'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'bamfile'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '99', 'type': 'if_statement', 'children': ['100', '103', '111']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'nosort'}; {'id': '103', 'type': 'block', 'children': ['104']}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}; {'id': '105', 'type': 'call', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'string', 'children': [], 'value': '"BAM sorting skipped"'}; {'id': '111', 'type': 'else_clause', 'children': ['112']}; {'id': '112', 'type': 'block', 'children': ['113']}; {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'bamfile'}; {'id': '116', 'type': 'call', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}; {'id': '119', 'type': 'list', 'children': ['120', '121'], 'value': '[bamfile, "--fasta={0}".format(fastafile)]'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'bamfile'}; {'id': '121', 'type': 'call', 'children': ['122', '125']}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}; {'id': '123', 'type': 'string', 'children': [], 'value': '"--fasta={0}"'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '125', 'type': 'argument_list', 'children': ['126']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'fastafile'}; {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'assignment', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'pf'}; {'id': '130', 'type': 'subscript', 'children': ['131', '138']}; {'id': '131', 'type': 'call', 'children': ['132', '135']}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'bamfile'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'rsplit'}; {'id': '135', 'type': 'argument_list', 'children': ['136', '137']}; {'id': '136', 'type': 'string', 'children': [], 'value': '"."'}; {'id': '137', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '138', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'assignment', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'sizesfile'}; {'id': '142', 'type': 'attribute', 'children': ['143', '147']}; {'id': '143', 'type': 'call', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'Sizes'}; {'id': '145', 'type': 'argument_list', 'children': ['146']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'fastafile'}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}; {'id': '149', 'type': 'assignment', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '151', 'type': 'call', 'children': ['152', '155']}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}; {'id': '153', 'type': 'string', 'children': [], 'value': '"genomeCoverageBed -ibam {0} -g {1}"'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '155', 'type': 'argument_list', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'bamfile'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'sizesfile'}; {'id': '158', 'type': 'if_statement', 'children': ['159', '164']}; {'id': '159', 'type': 'comparison_operator', 'children': ['160', '161'], 'value': 'in'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '161', 'type': 'tuple', 'children': ['162', '163']}; {'id': '162', 'type': 'string', 'children': [], 'value': '"bedgraph"'}; {'id': '163', 'type': 'string', 'children': [], 'value': '"bigwig"'}; {'id': '164', 'type': 'block', 'children': ['165', '169', '175', '183', '190', '196', '208', '213']}; {'id': '165', 'type': 'expression_statement', 'children': ['166']}; {'id': '166', 'type': 'augmented_assignment', 'children': ['167', '168'], 'value': '+='}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '168', 'type': 'string', 'children': [], 'value': '" -bg"'}; {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'assignment', 'children': ['171', '172']}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'bedgraphfile'}; {'id': '172', 'type': 'binary_operator', 'children': ['173', '174'], 'value': '+'}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'pf'}; {'id': '174', 'type': 'string', 'children': [], 'value': '".bedgraph"'}; {'id': '175', 'type': 'expression_statement', 'children': ['176']}; {'id': '176', 'type': 'call', 'children': ['177', '178']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'sh'}; {'id': '178', 'type': 'argument_list', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '180', 'type': 'keyword_argument', 'children': ['181', '182']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'outfile'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'bedgraphfile'}; {'id': '183', 'type': 'if_statement', 'children': ['184', '187']}; {'id': '184', 'type': 'comparison_operator', 'children': ['185', '186'], 'value': '=='}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '186', 'type': 'string', 'children': [], 'value': '"bedgraph"'}; {'id': '187', 'type': 'block', 'children': ['188']}; {'id': '188', 'type': 'return_statement', 'children': ['189']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'bedgraphfile'}; {'id': '190', 'type': 'expression_statement', 'children': ['191']}; {'id': '191', 'type': 'assignment', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'bigwigfile'}; {'id': '193', 'type': 'binary_operator', 'children': ['194', '195'], 'value': '+'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'pf'}; {'id': '195', 'type': 'string', 'children': [], 'value': '".bigwig"'}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}; {'id': '197', 'type': 'assignment', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '199', 'type': 'call', 'children': ['200', '204']}; {'id': '200', 'type': 'attribute', 'children': ['201', '202', '203']}; {'id': '201', 'type': 'string', 'children': [], 'value': '"bedGraphToBigWig {0} {1} {2}"'}; {'id': '202', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '204', 'type': 'argument_list', 'children': ['205', '206', '207']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'bedgraphfile'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'sizesfile'}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'bigwigfile'}; {'id': '208', 'type': 'expression_statement', 'children': ['209']}; {'id': '209', 'type': 'call', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'sh'}; {'id': '211', 'type': 'argument_list', 'children': ['212']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '213', 'type': 'return_statement', 'children': ['214']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'bigwigfile'}; {'id': '215', 'type': 'expression_statement', 'children': ['216']}; {'id': '216', 'type': 'assignment', 'children': ['217', '218']}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'coveragefile'}; {'id': '218', 'type': 'binary_operator', 'children': ['219', '220'], 'value': '+'}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'pf'}; {'id': '220', 'type': 'string', 'children': [], 'value': '".coverage"'}; {'id': '221', 'type': 'if_statement', 'children': ['222', '227']}; {'id': '222', 'type': 'call', 'children': ['223', '224']}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'need_update'}; {'id': '224', 'type': 'argument_list', 'children': ['225', '226']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'fastafile'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'coveragefile'}; {'id': '227', 'type': 'block', 'children': ['228']}; {'id': '228', 'type': 'expression_statement', 'children': ['229']}; {'id': '229', 'type': 'call', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'sh'}; {'id': '231', 'type': 'argument_list', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '233', 'type': 'keyword_argument', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'outfile'}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'coveragefile'}; {'id': '236', 'type': 'expression_statement', 'children': ['237']}; {'id': '237', 'type': 'assignment', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'gcf'}; {'id': '239', 'type': 'call', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'GenomeCoverageFile'}; {'id': '241', 'type': 'argument_list', 'children': ['242']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'coveragefile'}; {'id': '243', 'type': 'expression_statement', 'children': ['244']}; {'id': '244', 'type': 'assignment', 'children': ['245', '246']}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'fw'}; {'id': '246', 'type': 'call', 'children': ['247', '248']}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'must_open'}; {'id': '248', 'type': 'argument_list', 'children': ['249', '252']}; {'id': '249', 'type': 'attribute', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'outfile'}; {'id': '252', 'type': 'string', 'children': [], 'value': '"w"'}; {'id': '253', 'type': 'for_statement', 'children': ['254', '257', '262']}; {'id': '254', 'type': 'pattern_list', 'children': ['255', '256']}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'seqid'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'cov'}; {'id': '257', 'type': 'call', 'children': ['258', '261']}; {'id': '258', 'type': 'attribute', 'children': ['259', '260']}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'gcf'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'iter_coverage_seqid'}; {'id': '261', 'type': 'argument_list', 'children': []}; {'id': '262', 'type': 'block', 'children': ['263']}; {'id': '263', 'type': 'expression_statement', 'children': ['264']}; {'id': '264', 'type': 'call', 'children': ['265', '266']}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '266', 'type': 'argument_list', 'children': ['267', '280']}; {'id': '267', 'type': 'call', 'children': ['268', '271']}; {'id': '268', 'type': 'attribute', 'children': ['269', '270']}; {'id': '269', 'type': 'string', 'children': [], 'value': '"\\t"'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '271', 'type': 'argument_list', 'children': ['272']}; {'id': '272', 'type': 'tuple', 'children': ['273', '274']}; {'id': '273', 'type': 'identifier', 'children': [], 'value': 'seqid'}; {'id': '274', 'type': 'call', 'children': ['275', '278']}; {'id': '275', 'type': 'attribute', 'children': ['276', '277']}; {'id': '276', 'type': 'string', 'children': [], 'value': '"{0:.1f}"'}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '278', 'type': 'argument_list', 'children': ['279']}; {'id': '279', 'type': 'identifier', 'children': [], 'value': 'cov'}; {'id': '280', 'type': 'keyword_argument', 'children': ['281', '282']}; {'id': '281', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'fw'}; {'id': '283', 'type': 'expression_statement', 'children': ['284']}; {'id': '284', 'type': 'call', 'children': ['285', '288']}; {'id': '285', 'type': 'attribute', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'fw'}; {'id': '287', 'type': 'identifier', 'children': [], 'value': 'close'}; {'id': '288', 'type': 'argument_list', 'children': []}
def coverage(args): p = OptionParser(coverage.__doc__) p.add_option("--format", default="bigwig", choices=("bedgraph", "bigwig", "coverage"), help="Output format") p.add_option("--nosort", default=False, action="store_true", help="Do not sort BAM") p.set_outfile() opts, args = p.parse_args(args) if len(args) != 2: sys.exit(not p.print_help()) fastafile, bamfile = args format = opts.format if opts.nosort: logging.debug("BAM sorting skipped") else: bamfile = index([bamfile, "--fasta={0}".format(fastafile)]) pf = bamfile.rsplit(".", 2)[0] sizesfile = Sizes(fastafile).filename cmd = "genomeCoverageBed -ibam {0} -g {1}".format(bamfile, sizesfile) if format in ("bedgraph", "bigwig"): cmd += " -bg" bedgraphfile = pf + ".bedgraph" sh(cmd, outfile=bedgraphfile) if format == "bedgraph": return bedgraphfile bigwigfile = pf + ".bigwig" cmd = "bedGraphToBigWig {0} {1} {2}".\ format(bedgraphfile, sizesfile, bigwigfile) sh(cmd) return bigwigfile coveragefile = pf + ".coverage" if need_update(fastafile, coveragefile): sh(cmd, outfile=coveragefile) gcf = GenomeCoverageFile(coveragefile) fw = must_open(opts.outfile, "w") for seqid, cov in gcf.iter_coverage_seqid(): print("\t".join((seqid, "{0:.1f}".format(cov))), file=fw) fw.close()
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_number_finder'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'regex'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'numconv'}; {'id': '7', 'type': 'block', 'children': ['8', '17', '30', '37', '64']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'regex'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '17', 'type': 'if_statement', 'children': ['18', '24']}; {'id': '18', 'type': 'comparison_operator', 'children': ['19', '23'], 'value': '=='}; {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '23', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '24', 'type': 'block', 'children': ['25']}; {'id': '25', 'type': 'return_statement', 'children': ['26']}; {'id': '26', 'type': 'call', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'remove_empty'}; {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '37', 'type': 'for_statement', 'children': ['38', '39', '46']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '46', 'type': 'block', 'children': ['47']}; {'id': '47', 'type': 'try_statement', 'children': ['48', '60']}; {'id': '48', 'type': 'block', 'children': ['49']}; {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '54']}; {'id': '51', 'type': 'subscript', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '54', 'type': 'call', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'numconv'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}; {'id': '57', 'type': 'subscript', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '60', 'type': 'except_clause', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '62', 'type': 'block', 'children': ['63']}; {'id': '63', 'type': 'pass_statement', 'children': []}; {'id': '64', 'type': 'if_statement', 'children': ['65', '75', '81']}; {'id': '65', 'type': 'not_operator', 'children': ['66']}; {'id': '66', 'type': 'call', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '68', 'type': 'argument_list', 'children': ['69', '72']}; {'id': '69', 'type': 'subscript', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '71', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'string_types'}; {'id': '75', 'type': 'block', 'children': ['76']}; {'id': '76', 'type': 'return_statement', 'children': ['77']}; {'id': '77', 'type': 'binary_operator', 'children': ['78', '80'], 'value': '+'}; {'id': '78', 'type': 'list', 'children': ['79'], 'value': "['']"}; {'id': '79', 'type': 'string', 'children': [], 'value': "''"}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '81', 'type': 'else_clause', 'children': ['82']}; {'id': '82', 'type': 'block', 'children': ['83']}; {'id': '83', 'type': 'return_statement', 'children': ['84']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 's'}
def _number_finder(s, regex, numconv): s = regex.split(s) if len(s) == 1: return tuple(s) s = remove_empty(s) for i in range(len(s)): try: s[i] = numconv(s[i]) except ValueError: pass if not isinstance(s[0], six.string_types): return [''] + s else: return s
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'index_natsorted'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '11', '14', '17']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '7', 'type': 'lambda', 'children': ['8', '10']}; {'id': '8', 'type': 'lambda_parameters', 'children': ['9']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'number_type'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'signed'}; {'id': '16', 'type': 'True', 'children': []}; {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'exp'}; {'id': '19', 'type': 'True', 'children': []}; {'id': '20', 'type': 'block', 'children': ['21', '26', '33', '58', '85']}; {'id': '21', 'type': 'import_from_statement', 'children': ['22', '24']}; {'id': '22', 'type': 'dotted_name', 'children': ['23']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'operator'}; {'id': '24', 'type': 'dotted_name', 'children': ['25']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'itemgetter'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}; {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'item1'}; {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'itemgetter'}; {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'index_seq_pair'}; {'id': '36', 'type': 'list_comprehension', 'children': ['37', '43']}; {'id': '37', 'type': 'list', 'children': ['38', '39'], 'value': '[x, key(y)]'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '43', 'type': 'for_in_clause', 'children': ['44', '47']}; {'id': '44', 'type': 'pattern_list', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '49', 'type': 'argument_list', 'children': ['50', '57']}; {'id': '50', 'type': 'call', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}; {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}; {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'index_seq_pair'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'keyword_argument', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '66', 'type': 'lambda', 'children': ['67', '69']}; {'id': '67', 'type': 'lambda_parameters', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'natsort_key'}; {'id': '71', 'type': 'argument_list', 'children': ['72', '76', '79', '82']}; {'id': '72', 'type': 'call', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'item1'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '76', 'type': 'keyword_argument', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'number_type'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'number_type'}; {'id': '79', 'type': 'keyword_argument', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'signed'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'signed'}; {'id': '82', 'type': 'keyword_argument', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'exp'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'exp'}; {'id': '85', 'type': 'return_statement', 'children': ['86']}; {'id': '86', 'type': 'list_comprehension', 'children': ['87', '90']}; {'id': '87', 'type': 'subscript', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '89', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '90', 'type': 'for_in_clause', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'index_seq_pair'}
def index_natsorted(seq, key=lambda x: x, number_type=float, signed=True, exp=True): from operator import itemgetter item1 = itemgetter(1) index_seq_pair = [[x, key(y)] for x, y in zip(range(len(seq)), seq)] index_seq_pair.sort(key=lambda x: natsort_key(item1(x), number_type=number_type, signed=signed, exp=exp)) return [x[0] for x in index_seq_pair]
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '5', 'type': 'block', 'children': ['6', '15', '35', '54', '70', '79', '85', '96', '116', '121', '127', '137', '143', '182', '192', '196', '212', '221', '232', '246']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'OptionParser'}; {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '__doc__'}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'call', 'children': ['17', '20']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'add_option'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '22', '23', '26', '29', '32']}; {'id': '21', 'type': 'string', 'children': [], 'value': '"-i"'}; {'id': '22', 'type': 'string', 'children': [], 'value': '"--inplace"'}; {'id': '23', 'type': 'keyword_argument', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'dest'}; {'id': '25', 'type': 'string', 'children': [], 'value': '"inplace"'}; {'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '28', 'type': 'False', 'children': []}; {'id': '29', 'type': 'keyword_argument', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '31', 'type': 'string', 'children': [], 'value': '"store_true"'}; {'id': '32', 'type': 'keyword_argument', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'help'}; {'id': '34', 'type': 'string', 'children': [], 'value': '"Sort bed file in place [default: %default]"'}; {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '40']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'add_option'}; {'id': '40', 'type': 'argument_list', 'children': ['41', '42', '45', '48', '51']}; {'id': '41', 'type': 'string', 'children': [], 'value': '"-u"'}; {'id': '42', 'type': 'keyword_argument', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'dest'}; {'id': '44', 'type': 'string', 'children': [], 'value': '"unique"'}; {'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '47', 'type': 'False', 'children': []}; {'id': '48', 'type': 'keyword_argument', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '50', 'type': 'string', 'children': [], 'value': '"store_true"'}; {'id': '51', 'type': 'keyword_argument', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'help'}; {'id': '53', 'type': 'string', 'children': [], 'value': '"Uniqify the bed file"'}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}; {'id': '55', 'type': 'call', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'add_option'}; {'id': '59', 'type': 'argument_list', 'children': ['60', '61', '64', '67']}; {'id': '60', 'type': 'string', 'children': [], 'value': '"--accn"'}; {'id': '61', 'type': 'keyword_argument', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '63', 'type': 'False', 'children': []}; {'id': '64', 'type': 'keyword_argument', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '66', 'type': 'string', 'children': [], 'value': '"store_true"'}; {'id': '67', 'type': 'keyword_argument', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'help'}; {'id': '69', 'type': 'string', 'children': [], 'value': '"Sort based on the accessions [default: %default]"'}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}; {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'set_outfile'}; {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'keyword_argument', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'outfile'}; {'id': '78', 'type': 'None', 'children': []}; {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'call', 'children': ['81', '84']}; {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'set_tmpdir'}; {'id': '84', 'type': 'argument_list', 'children': []}; {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '90']}; {'id': '87', 'type': 'pattern_list', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '90', 'type': 'call', 'children': ['91', '94']}; {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'parse_args'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '96', 'type': 'if_statement', 'children': ['97', '103']}; {'id': '97', 'type': 'comparison_operator', 'children': ['98', '102'], 'value': '!='}; {'id': '98', 'type': 'call', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '102', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '103', 'type': 'block', 'children': ['104']}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}; {'id': '105', 'type': 'call', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'exit'}; {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'not_operator', 'children': ['111']}; {'id': '111', 'type': 'call', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'print_help'}; {'id': '115', 'type': 'argument_list', 'children': []}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}; {'id': '117', 'type': 'assignment', 'children': ['118', '120']}; {'id': '118', 'type': 'pattern_list', 'children': ['119']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'bedfile'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'assignment', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'inplace'}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'inplace'}; {'id': '127', 'type': 'if_statement', 'children': ['128', '134']}; {'id': '128', 'type': 'boolean_operator', 'children': ['129', '131'], 'value': 'and'}; {'id': '129', 'type': 'not_operator', 'children': ['130']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'inplace'}; {'id': '131', 'type': 'comparison_operator', 'children': ['132', '133'], 'value': 'in'}; {'id': '132', 'type': 'string', 'children': [], 'value': '".sorted."'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'bedfile'}; {'id': '134', 'type': 'block', 'children': ['135']}; {'id': '135', 'type': 'return_statement', 'children': ['136']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'bedfile'}; {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'assignment', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'sortedbed'}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'outfile'}; {'id': '143', 'type': 'if_statement', 'children': ['144', '145', '150']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'inplace'}; {'id': '145', 'type': 'block', 'children': ['146']}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}; {'id': '147', 'type': 'assignment', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'sortedbed'}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'bedfile'}; {'id': '150', 'type': 'elif_clause', 'children': ['151', '156']}; {'id': '151', 'type': 'comparison_operator', 'children': ['152', '155'], 'value': 'is'}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'outfile'}; {'id': '155', 'type': 'None', 'children': []}; {'id': '156', 'type': 'block', 'children': ['157', '174']}; {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'assignment', 'children': ['159', '162']}; {'id': '159', 'type': 'pattern_list', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'pf'}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'sf'}; {'id': '162', 'type': 'call', 'children': ['163', '171']}; {'id': '163', 'type': 'attribute', 'children': ['164', '170']}; {'id': '164', 'type': 'call', 'children': ['165', '168']}; {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'op'}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'basename'}; {'id': '168', 'type': 'argument_list', 'children': ['169']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'bedfile'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'rsplit'}; {'id': '171', 'type': 'argument_list', 'children': ['172', '173']}; {'id': '172', 'type': 'string', 'children': [], 'value': '"."'}; {'id': '173', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}; {'id': '175', 'type': 'assignment', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'sortedbed'}; {'id': '177', 'type': 'binary_operator', 'children': ['178', '181'], 'value': '+'}; {'id': '178', 'type': 'binary_operator', 'children': ['179', '180'], 'value': '+'}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'pf'}; {'id': '180', 'type': 'string', 'children': [], 'value': '".sorted."'}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'sf'}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}; {'id': '183', 'type': 'assignment', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'sortopt'}; {'id': '185', 'type': 'conditional_expression', 'children': ['186', '187', '191'], 'value': 'if'}; {'id': '186', 'type': 'string', 'children': [], 'value': '"-k1,1 -k2,2n -k3,3n -k4,4"'}; {'id': '187', 'type': 'not_operator', 'children': ['188']}; {'id': '188', 'type': 'attribute', 'children': ['189', '190']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'accn'}; {'id': '191', 'type': 'string', 'children': [], 'value': '"-k4,4 -k1,1 -k2,2n -k3,3n"'}; {'id': '192', 'type': 'expression_statement', 'children': ['193']}; {'id': '193', 'type': 'assignment', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '195', 'type': 'string', 'children': [], 'value': '"sort"'}; {'id': '196', 'type': 'if_statement', 'children': ['197', '200']}; {'id': '197', 'type': 'attribute', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'tmpdir'}; {'id': '200', 'type': 'block', 'children': ['201']}; {'id': '201', 'type': 'expression_statement', 'children': ['202']}; {'id': '202', 'type': 'augmented_assignment', 'children': ['203', '204'], 'value': '+='}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '204', 'type': 'call', 'children': ['205', '208']}; {'id': '205', 'type': 'attribute', 'children': ['206', '207']}; {'id': '206', 'type': 'string', 'children': [], 'value': '" -T {0}"'}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '208', 'type': 'argument_list', 'children': ['209']}; {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'tmpdir'}; {'id': '212', 'type': 'if_statement', 'children': ['213', '216']}; {'id': '213', 'type': 'attribute', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'unique'}; {'id': '216', 'type': 'block', 'children': ['217']}; {'id': '217', 'type': 'expression_statement', 'children': ['218']}; {'id': '218', 'type': 'augmented_assignment', 'children': ['219', '220'], 'value': '+='}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '220', 'type': 'string', 'children': [], 'value': '" -u"'}; {'id': '221', 'type': 'expression_statement', 'children': ['222']}; {'id': '222', 'type': 'augmented_assignment', 'children': ['223', '224'], 'value': '+='}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '224', 'type': 'call', 'children': ['225', '228']}; {'id': '225', 'type': 'attribute', 'children': ['226', '227']}; {'id': '226', 'type': 'string', 'children': [], 'value': '" {0} {1} -o {2}"'}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '228', 'type': 'argument_list', 'children': ['229', '230', '231']}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'sortopt'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'bedfile'}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'sortedbed'}; {'id': '232', 'type': 'if_statement', 'children': ['233', '240']}; {'id': '233', 'type': 'boolean_operator', 'children': ['234', '235'], 'value': 'or'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'inplace'}; {'id': '235', 'type': 'call', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'need_update'}; {'id': '237', 'type': 'argument_list', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'bedfile'}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'sortedbed'}; {'id': '240', 'type': 'block', 'children': ['241']}; {'id': '241', 'type': 'expression_statement', 'children': ['242']}; {'id': '242', 'type': 'call', 'children': ['243', '244']}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'sh'}; {'id': '244', 'type': 'argument_list', 'children': ['245']}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '246', 'type': 'return_statement', 'children': ['247']}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'sortedbed'}
def sort(args): p = OptionParser(sort.__doc__) p.add_option("-i", "--inplace", dest="inplace", default=False, action="store_true", help="Sort bed file in place [default: %default]") p.add_option("-u", dest="unique", default=False, action="store_true", help="Uniqify the bed file") p.add_option("--accn", default=False, action="store_true", help="Sort based on the accessions [default: %default]") p.set_outfile(outfile=None) p.set_tmpdir() opts, args = p.parse_args(args) if len(args) != 1: sys.exit(not p.print_help()) bedfile, = args inplace = opts.inplace if not inplace and ".sorted." in bedfile: return bedfile sortedbed = opts.outfile if inplace: sortedbed = bedfile elif opts.outfile is None: pf, sf = op.basename(bedfile).rsplit(".", 1) sortedbed = pf + ".sorted." + sf sortopt = "-k1,1 -k2,2n -k3,3n -k4,4" if not opts.accn else \ "-k4,4 -k1,1 -k2,2n -k3,3n" cmd = "sort" if opts.tmpdir: cmd += " -T {0}".format(opts.tmpdir) if opts.unique: cmd += " -u" cmd += " {0} {1} -o {2}".format(sortopt, bedfile, sortedbed) if inplace or need_update(bedfile, sortedbed): sh(cmd) return sortedbed
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'by_image_seq'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'blocks'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'image_seq'}; {'id': '6', 'type': 'block', 'children': ['7']}; {'id': '7', 'type': 'return_statement', 'children': ['8']}; {'id': '8', 'type': 'call', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '10', 'type': 'argument_list', 'children': ['11']}; {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '13', 'type': 'argument_list', 'children': ['14', '26']}; {'id': '14', 'type': 'lambda', 'children': ['15', '17']}; {'id': '15', 'type': 'lambda_parameters', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'block'}; {'id': '17', 'type': 'comparison_operator', 'children': ['18', '25'], 'value': '=='}; {'id': '18', 'type': 'attribute', 'children': ['19', '24']}; {'id': '19', 'type': 'attribute', 'children': ['20', '23']}; {'id': '20', 'type': 'subscript', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'blocks'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'block'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'ec_hdr'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'image_seq'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'image_seq'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'blocks'}
def by_image_seq(blocks, image_seq): return list(filter(lambda block: blocks[block].ec_hdr.image_seq == image_seq, blocks))
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'by_vol_id'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'blocks'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'slist'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '13', '76']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'vol_blocks'}; {'id': '12', 'type': 'dictionary', 'children': []}; {'id': '13', 'type': 'for_statement', 'children': ['14', '15', '16']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'blocks'}; {'id': '16', 'type': 'block', 'children': ['17', '34', '57']}; {'id': '17', 'type': 'if_statement', 'children': ['18', '23', '25']}; {'id': '18', 'type': 'boolean_operator', 'children': ['19', '20'], 'value': 'and'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'slist'}; {'id': '20', 'type': 'comparison_operator', 'children': ['21', '22'], 'value': 'not'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'slist'}; {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'continue_statement', 'children': []}; {'id': '25', 'type': 'elif_clause', 'children': ['26', '32']}; {'id': '26', 'type': 'not_operator', 'children': ['27']}; {'id': '27', 'type': 'attribute', 'children': ['28', '31']}; {'id': '28', 'type': 'subscript', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'blocks'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'is_valid'}; {'id': '32', 'type': 'block', 'children': ['33']}; {'id': '33', 'type': 'continue_statement', 'children': []}; {'id': '34', 'type': 'if_statement', 'children': ['35', '44']}; {'id': '35', 'type': 'comparison_operator', 'children': ['36', '43'], 'value': 'not'}; {'id': '36', 'type': 'attribute', 'children': ['37', '42']}; {'id': '37', 'type': 'attribute', 'children': ['38', '41']}; {'id': '38', 'type': 'subscript', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'blocks'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'vid_hdr'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'vol_id'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'vol_blocks'}; {'id': '44', 'type': 'block', 'children': ['45']}; {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '56']}; {'id': '47', 'type': 'subscript', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'vol_blocks'}; {'id': '49', 'type': 'attribute', 'children': ['50', '55']}; {'id': '50', 'type': 'attribute', 'children': ['51', '54']}; {'id': '51', 'type': 'subscript', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'blocks'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'vid_hdr'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'vol_id'}; {'id': '56', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '70']}; {'id': '59', 'type': 'attribute', 'children': ['60', '69']}; {'id': '60', 'type': 'subscript', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'vol_blocks'}; {'id': '62', 'type': 'attribute', 'children': ['63', '68']}; {'id': '63', 'type': 'attribute', 'children': ['64', '67']}; {'id': '64', 'type': 'subscript', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'blocks'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'vid_hdr'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'vol_id'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}; {'id': '71', 'type': 'attribute', 'children': ['72', '75']}; {'id': '72', 'type': 'subscript', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'blocks'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'peb_num'}; {'id': '76', 'type': 'return_statement', 'children': ['77']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'vol_blocks'}
def by_vol_id(blocks, slist=None): vol_blocks = {} for i in blocks: if slist and i not in slist: continue elif not blocks[i].is_valid: continue if blocks[i].vid_hdr.vol_id not in vol_blocks: vol_blocks[blocks[i].vid_hdr.vol_id] = [] vol_blocks[blocks[i].vid_hdr.vol_id].append(blocks[i].peb_num) return vol_blocks
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'by_type'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'blocks'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'slist'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '13', '17', '21', '25', '100']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'layout'}; {'id': '12', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '16', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'int_vol'}; {'id': '20', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'unknown'}; {'id': '24', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '25', 'type': 'for_statement', 'children': ['26', '27', '28']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'blocks'}; {'id': '28', 'type': 'block', 'children': ['29', '37']}; {'id': '29', 'type': 'if_statement', 'children': ['30', '35']}; {'id': '30', 'type': 'boolean_operator', 'children': ['31', '32'], 'value': 'and'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'slist'}; {'id': '32', 'type': 'comparison_operator', 'children': ['33', '34'], 'value': 'not'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'slist'}; {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'continue_statement', 'children': []}; {'id': '37', 'type': 'if_statement', 'children': ['38', '49', '57', '77', '91']}; {'id': '38', 'type': 'boolean_operator', 'children': ['39', '44'], 'value': 'and'}; {'id': '39', 'type': 'attribute', 'children': ['40', '43']}; {'id': '40', 'type': 'subscript', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'blocks'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'is_vtbl'}; {'id': '44', 'type': 'attribute', 'children': ['45', '48']}; {'id': '45', 'type': 'subscript', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'blocks'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'is_valid'}; {'id': '49', 'type': 'block', 'children': ['50']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}; {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'layout'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '57', 'type': 'elif_clause', 'children': ['58', '69']}; {'id': '58', 'type': 'boolean_operator', 'children': ['59', '64'], 'value': 'and'}; {'id': '59', 'type': 'attribute', 'children': ['60', '63']}; {'id': '60', 'type': 'subscript', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'blocks'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'is_internal_vol'}; {'id': '64', 'type': 'attribute', 'children': ['65', '68']}; {'id': '65', 'type': 'subscript', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'blocks'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'is_valid'}; {'id': '69', 'type': 'block', 'children': ['70']}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}; {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'int_vol'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '77', 'type': 'elif_clause', 'children': ['78', '83']}; {'id': '78', 'type': 'attribute', 'children': ['79', '82']}; {'id': '79', 'type': 'subscript', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'blocks'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'is_valid'}; {'id': '83', 'type': 'block', 'children': ['84']}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}; {'id': '85', 'type': 'call', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '91', 'type': 'else_clause', 'children': ['92']}; {'id': '92', 'type': 'block', 'children': ['93']}; {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'call', 'children': ['95', '98']}; {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'unknown'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '100', 'type': 'return_statement', 'children': ['101']}; {'id': '101', 'type': 'expression_list', 'children': ['102', '103', '104', '105']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'layout'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'int_vol'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'unknown'}
def by_type(blocks, slist=None): layout = [] data = [] int_vol = [] unknown = [] for i in blocks: if slist and i not in slist: continue if blocks[i].is_vtbl and blocks[i].is_valid: layout.append(i) elif blocks[i].is_internal_vol and blocks[i].is_valid: int_vol.append(i) elif blocks[i].is_valid: data.append(i) else: unknown.append(i) return layout, data, int_vol, unknown
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'group_pairs'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'blocks'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'layout_blocks_list'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '48', '63']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'image_dict'}; {'id': '10', 'type': 'dictionary', 'children': []}; {'id': '11', 'type': 'for_statement', 'children': ['12', '13', '14']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'block_id'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'layout_blocks_list'}; {'id': '14', 'type': 'block', 'children': ['15', '25']}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'image_seq'}; {'id': '18', 'type': 'attribute', 'children': ['19', '24']}; {'id': '19', 'type': 'attribute', 'children': ['20', '23']}; {'id': '20', 'type': 'subscript', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'blocks'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'block_id'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'ec_hdr'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'image_seq'}; {'id': '25', 'type': 'if_statement', 'children': ['26', '29', '37']}; {'id': '26', 'type': 'comparison_operator', 'children': ['27', '28'], 'value': 'not'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'image_seq'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'image_dict'}; {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'assignment', 'children': ['32', '35']}; {'id': '32', 'type': 'subscript', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'image_dict'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'image_seq'}; {'id': '35', 'type': 'list', 'children': ['36'], 'value': '[block_id]'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'block_id'}; {'id': '37', 'type': 'else_clause', 'children': ['38']}; {'id': '38', 'type': 'block', 'children': ['39']}; {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '46']}; {'id': '41', 'type': 'attribute', 'children': ['42', '45']}; {'id': '42', 'type': 'subscript', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'image_dict'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'image_seq'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'block_id'}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}; {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '51', 'type': 'argument_list', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'group_pairs'}; {'id': '53', 'type': 'binary_operator', 'children': ['54', '55'], 'value': '%'}; {'id': '54', 'type': 'string', 'children': [], 'value': "'Layout blocks found at PEBs: %s'"}; {'id': '55', 'type': 'call', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '62']}; {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'image_dict'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '62', 'type': 'argument_list', 'children': []}; {'id': '63', 'type': 'return_statement', 'children': ['64']}; {'id': '64', 'type': 'call', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}; {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'image_dict'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '71', 'type': 'argument_list', 'children': []}
def group_pairs(blocks, layout_blocks_list): image_dict={} for block_id in layout_blocks_list: image_seq=blocks[block_id].ec_hdr.image_seq if image_seq not in image_dict: image_dict[image_seq]=[block_id] else: image_dict[image_seq].append(block_id) log(group_pairs, 'Layout blocks found at PEBs: %s' % list(image_dict.values())) return list(image_dict.values())
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'read_cBpack'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '5', 'type': 'block', 'children': ['6', '32', '38', '72']}; {'id': '6', 'type': 'with_statement', 'children': ['7', '19']}; {'id': '7', 'type': 'with_clause', 'children': ['8']}; {'id': '8', 'type': 'with_item', 'children': ['9']}; {'id': '9', 'type': 'as_pattern', 'children': ['10', '17']}; {'id': '10', 'type': 'call', 'children': ['11', '14']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'gzip'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '16', 'type': 'string', 'children': [], 'value': "'rb'"}; {'id': '17', 'type': 'as_pattern_target', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'infile'}; {'id': '19', 'type': 'block', 'children': ['20']}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}; {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'msgpack'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'load'}; {'id': '27', 'type': 'argument_list', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'infile'}; {'id': '29', 'type': 'keyword_argument', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'raw'}; {'id': '31', 'type': 'False', 'children': []}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '35', 'type': 'subscript', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '37', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '38', 'type': 'if_statement', 'children': ['39', '64']}; {'id': '39', 'type': '()', 'children': ['40']}; {'id': '40', 'type': 'boolean_operator', 'children': ['41', '56'], 'value': 'or'}; {'id': '41', 'type': 'boolean_operator', 'children': ['42', '48'], 'value': 'or'}; {'id': '42', 'type': 'not_operator', 'children': ['43']}; {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '45', 'type': 'argument_list', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '48', 'type': 'comparison_operator', 'children': ['49', '55'], 'value': '!='}; {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'string', 'children': [], 'value': "'format'"}; {'id': '55', 'type': 'string', 'children': [], 'value': "'cB'"}; {'id': '56', 'type': 'comparison_operator', 'children': ['57', '63'], 'value': '!='}; {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'string', 'children': [], 'value': "'version'"}; {'id': '63', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '64', 'type': 'block', 'children': ['65']}; {'id': '65', 'type': 'raise_statement', 'children': ['66']}; {'id': '66', 'type': 'call', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}; {'id': '69', 'type': 'binary_operator', 'children': ['70', '71'], 'value': '%'}; {'id': '70', 'type': 'string', 'children': [], 'value': '"Unexpected header: %r"'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '72', 'type': 'return_statement', 'children': ['73']}; {'id': '73', 'type': 'subscript', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '75', 'type': 'slice', 'children': ['76', '77']}; {'id': '76', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '77', 'type': 'colon', 'children': []}
def read_cBpack(filename): with gzip.open(filename, 'rb') as infile: data = msgpack.load(infile, raw=False) header = data[0] if ( not isinstance(header, dict) or header.get('format') != 'cB' or header.get('version') != 1 ): raise ValueError("Unexpected header: %r" % header) return data[1:]
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'addDiscreteOutcomeConstantMean'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'distribution'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '9', 'type': 'False', 'children': []}; {'id': '10', 'type': 'block', 'children': ['11', '13', '37', '54', '78']}; {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'string', 'children': [], 'value': "'''\n Adds a discrete outcome of x with probability p to an existing distribution,\n holding constant the relative probabilities of other outcomes and overall mean.\n Parameters\n ----------\n distribution : [np.array]\n Two element list containing a list of probabilities and a list of outcomes.\n x : float\n The new value to be added to the distribution.\n p : float\n The probability of the discrete outcome x occuring.\n sort: bool\n Whether or not to sort X before returning it\n Returns\n -------\n X : np.array\n Discrete points for discrete probability mass function.\n pmf : np.array\n Probability associated with each point in X.\n Written by Matthew N. White\n Latest update: 08 December 2015 by David Low\n '''"}; {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '16', 'type': 'call', 'children': ['17', '20']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '22', 'type': 'binary_operator', 'children': ['23', '33'], 'value': '/'}; {'id': '23', 'type': 'binary_operator', 'children': ['24', '27'], 'value': '*'}; {'id': '24', 'type': 'subscript', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'distribution'}; {'id': '26', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '27', 'type': '()', 'children': ['28']}; {'id': '28', 'type': 'binary_operator', 'children': ['29', '30'], 'value': '-'}; {'id': '29', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '30', 'type': 'binary_operator', 'children': ['31', '32'], 'value': '*'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '33', 'type': '()', 'children': ['34']}; {'id': '34', 'type': 'binary_operator', 'children': ['35', '36'], 'value': '-'}; {'id': '35', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'pmf'}; {'id': '40', 'type': 'call', 'children': ['41', '44']}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '46', 'type': 'binary_operator', 'children': ['47', '50'], 'value': '*'}; {'id': '47', 'type': 'subscript', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'distribution'}; {'id': '49', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '50', 'type': '()', 'children': ['51']}; {'id': '51', 'type': 'binary_operator', 'children': ['52', '53'], 'value': '-'}; {'id': '52', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '54', 'type': 'if_statement', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '56', 'type': 'block', 'children': ['57', '66', '72']}; {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'indices'}; {'id': '60', 'type': 'call', 'children': ['61', '64']}; {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'argsort'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}; {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '69', 'type': 'subscript', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'indices'}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}; {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'pmf'}; {'id': '75', 'type': 'subscript', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'pmf'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'indices'}; {'id': '78', 'type': 'return_statement', 'children': ['79']}; {'id': '79', 'type': '()', 'children': ['80']}; {'id': '80', 'type': 'list', 'children': ['81', '82'], 'value': '[pmf,X]'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'pmf'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'X'}
def addDiscreteOutcomeConstantMean(distribution, x, p, sort = False): ''' Adds a discrete outcome of x with probability p to an existing distribution, holding constant the relative probabilities of other outcomes and overall mean. Parameters ---------- distribution : [np.array] Two element list containing a list of probabilities and a list of outcomes. x : float The new value to be added to the distribution. p : float The probability of the discrete outcome x occuring. sort: bool Whether or not to sort X before returning it Returns ------- X : np.array Discrete points for discrete probability mass function. pmf : np.array Probability associated with each point in X. Written by Matthew N. White Latest update: 08 December 2015 by David Low ''' X = np.append(x,distribution[1]*(1-p*x)/(1-p)) pmf = np.append(p,distribution[0]*(1-p)) if sort: indices = np.argsort(X) X = X[indices] pmf = pmf[indices] return([pmf,X])
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'runStickyEregressionsInStata'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'infile_name'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'interval_size'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'meas_err'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'sticky'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'all_specs'}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'stata_exe'}; {'id': '10', 'type': 'block', 'children': ['11', '13', '17', '32', '45', '58', '75', '87', '97', '112', '157']}; {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'string', 'children': [], 'value': '\'\'\'\n Runs regressions for the main tables of the StickyC paper in Stata and produces a\n LaTeX table with results for one "panel". Running in Stata allows production of\n the KP-statistic, for which there is currently no command in statsmodels.api.\n Parameters\n ----------\n infile_name : str\n Name of tab-delimited text file with simulation data. Assumed to be in\n the results directory, and was almost surely generated by makeStickyEdataFile\n unless we resort to fabricating simulated data. THAT\'S A JOKE, FUTURE REFEREES.\n interval_size : int\n Number of periods in each regression sample (or interval).\n meas_err : bool\n Indicator for whether to add measurement error to DeltaLogC.\n sticky : bool\n Indicator for whether these results used sticky expectations.\n all_specs : bool\n Indicator for whether this panel should include all specifications or\n just the OLS on lagged consumption growth.\n stata_exe : str\n Absolute location where the Stata executable can be found on the computer\n running this code. Usually set at the top of StickyEparams.py.\n Returns\n -------\n panel_text : str\n String with one panel\'s worth of LaTeX input.\n \'\'\''}; {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'dofile'}; {'id': '16', 'type': 'string', 'children': [], 'value': '"StickyETimeSeries.do"'}; {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'infile_name_full'}; {'id': '20', 'type': 'call', 'children': ['21', '26']}; {'id': '21', 'type': 'attribute', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'abspath'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}; {'id': '27', 'type': 'binary_operator', 'children': ['28', '31'], 'value': '+'}; {'id': '28', 'type': 'binary_operator', 'children': ['29', '30'], 'value': '+'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'results_dir'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'infile_name'}; {'id': '31', 'type': 'string', 'children': [], 'value': '".txt"'}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'temp_name_full'}; {'id': '35', 'type': 'call', 'children': ['36', '41']}; {'id': '36', 'type': 'attribute', 'children': ['37', '40']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'abspath'}; {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'binary_operator', 'children': ['43', '44'], 'value': '+'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'results_dir'}; {'id': '44', 'type': 'string', 'children': [], 'value': '"temp.txt"'}; {'id': '45', 'type': 'if_statement', 'children': ['46', '47', '52']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'meas_err'}; {'id': '47', 'type': 'block', 'children': ['48']}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}; {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'meas_err_stata'}; {'id': '51', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '52', 'type': 'else_clause', 'children': ['53']}; {'id': '53', 'type': 'block', 'children': ['54']}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}; {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'meas_err_stata'}; {'id': '57', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}; {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '61', 'type': 'list', 'children': ['62', '63', '64', '65', '66', '67', '71'], 'value': '[stata_exe, "do", dofile, infile_name_full, temp_name_full, str(interval_size), str(meas_err_stata)]'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'stata_exe'}; {'id': '63', 'type': 'string', 'children': [], 'value': '"do"'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'dofile'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'infile_name_full'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'temp_name_full'}; {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'interval_size'}; {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'meas_err_stata'}; {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'stata_status'}; {'id': '78', 'type': 'call', 'children': ['79', '82']}; {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'subprocess'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'call'}; {'id': '82', 'type': 'argument_list', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '84', 'type': 'keyword_argument', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'shell'}; {'id': '86', 'type': 'string', 'children': [], 'value': "'true'"}; {'id': '87', 'type': 'if_statement', 'children': ['88', '91']}; {'id': '88', 'type': 'comparison_operator', 'children': ['89', '90'], 'value': '!='}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'stata_status'}; {'id': '90', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '91', 'type': 'block', 'children': ['92']}; {'id': '92', 'type': 'raise_statement', 'children': ['93']}; {'id': '93', 'type': 'call', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'string', 'children': [], 'value': "'Stata code could not run. Check the stata_exe in StickyEparams.py'"}; {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'stata_output'}; {'id': '100', 'type': 'call', 'children': ['101', '104']}; {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'pd'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'read_csv'}; {'id': '104', 'type': 'argument_list', 'children': ['105', '106', '109']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'temp_name_full'}; {'id': '106', 'type': 'keyword_argument', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'sep'}; {'id': '108', 'type': 'string', 'children': [], 'value': "','"}; {'id': '109', 'type': 'keyword_argument', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '111', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}; {'id': '113', 'type': 'assignment', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'panel_text'}; {'id': '115', 'type': 'call', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'makeResultsPanel'}; {'id': '117', 'type': 'argument_list', 'children': ['118', '123', '128', '133', '138', '143', '148', '151', '154']}; {'id': '118', 'type': 'keyword_argument', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'Coeffs'}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'stata_output'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'CoeffsArray'}; {'id': '123', 'type': 'keyword_argument', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'StdErrs'}; {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'stata_output'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'StdErrArray'}; {'id': '128', 'type': 'keyword_argument', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'Rsq'}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'stata_output'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'RsqArray'}; {'id': '133', 'type': 'keyword_argument', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'Pvals'}; {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'stata_output'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'PvalArray'}; {'id': '138', 'type': 'keyword_argument', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'OID'}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'stata_output'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'OIDarray'}; {'id': '143', 'type': 'keyword_argument', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'Counts'}; {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'stata_output'}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'ExtraInfo'}; {'id': '148', 'type': 'keyword_argument', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'meas_err'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'meas_err'}; {'id': '151', 'type': 'keyword_argument', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'sticky'}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'sticky'}; {'id': '154', 'type': 'keyword_argument', 'children': ['155', '156']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'all_specs'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'all_specs'}; {'id': '157', 'type': 'return_statement', 'children': ['158']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'panel_text'}
def runStickyEregressionsInStata(infile_name,interval_size,meas_err,sticky,all_specs,stata_exe): ''' Runs regressions for the main tables of the StickyC paper in Stata and produces a LaTeX table with results for one "panel". Running in Stata allows production of the KP-statistic, for which there is currently no command in statsmodels.api. Parameters ---------- infile_name : str Name of tab-delimited text file with simulation data. Assumed to be in the results directory, and was almost surely generated by makeStickyEdataFile unless we resort to fabricating simulated data. THAT'S A JOKE, FUTURE REFEREES. interval_size : int Number of periods in each regression sample (or interval). meas_err : bool Indicator for whether to add measurement error to DeltaLogC. sticky : bool Indicator for whether these results used sticky expectations. all_specs : bool Indicator for whether this panel should include all specifications or just the OLS on lagged consumption growth. stata_exe : str Absolute location where the Stata executable can be found on the computer running this code. Usually set at the top of StickyEparams.py. Returns ------- panel_text : str String with one panel's worth of LaTeX input. ''' dofile = "StickyETimeSeries.do" infile_name_full = os.path.abspath(results_dir + infile_name + ".txt") temp_name_full = os.path.abspath(results_dir + "temp.txt") if meas_err: meas_err_stata = 1 else: meas_err_stata = 0 cmd = [stata_exe, "do", dofile, infile_name_full, temp_name_full, str(interval_size), str(meas_err_stata)] stata_status = subprocess.call(cmd,shell = 'true') if stata_status!=0: raise ValueError('Stata code could not run. Check the stata_exe in StickyEparams.py') stata_output = pd.read_csv(temp_name_full, sep=',',header=0) panel_text = makeResultsPanel(Coeffs=stata_output.CoeffsArray, StdErrs=stata_output.StdErrArray, Rsq=stata_output.RsqArray, Pvals=stata_output.PvalArray, OID=stata_output.OIDarray, Counts=stata_output.ExtraInfo, meas_err=meas_err, sticky=sticky, all_specs=all_specs) return panel_text
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'capability_functions'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '6', 'type': 'block', 'children': ['7', '18', '22', '66', '80', '91']}; {'id': '7', 'type': 'if_statement', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': '_debug'}; {'id': '9', 'type': 'block', 'children': ['10']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}; {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'Collector'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '_debug'}; {'id': '15', 'type': 'argument_list', 'children': ['16', '17']}; {'id': '16', 'type': 'string', 'children': [], 'value': '"capability_functions %r"'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'fns'}; {'id': '21', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '22', 'type': 'for_statement', 'children': ['23', '24', '27']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'capabilities'}; {'id': '27', 'type': 'block', 'children': ['28', '37', '49']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}; {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'xfn'}; {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '33', 'type': 'argument_list', 'children': ['34', '35', '36']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '36', 'type': 'None', 'children': []}; {'id': '37', 'type': 'if_statement', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': '_debug'}; {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}; {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'Collector'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': '_debug'}; {'id': '45', 'type': 'argument_list', 'children': ['46', '47', '48']}; {'id': '46', 'type': 'string', 'children': [], 'value': '" - cls, xfn: %r, %r"'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'xfn'}; {'id': '49', 'type': 'if_statement', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'xfn'}; {'id': '51', 'type': 'block', 'children': ['52']}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}; {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'fns'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'tuple', 'children': ['59', '65']}; {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '61', 'type': 'argument_list', 'children': ['62', '63', '64']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '63', 'type': 'string', 'children': [], 'value': "'_zindex'"}; {'id': '64', 'type': 'None', 'children': []}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'xfn'}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}; {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'fns'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'keyword_argument', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '74', 'type': 'lambda', 'children': ['75', '77']}; {'id': '75', 'type': 'lambda_parameters', 'children': ['76']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '77', 'type': 'subscript', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '79', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '80', 'type': 'if_statement', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': '_debug'}; {'id': '82', 'type': 'block', 'children': ['83']}; {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'call', 'children': ['85', '88']}; {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'Collector'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': '_debug'}; {'id': '88', 'type': 'argument_list', 'children': ['89', '90']}; {'id': '89', 'type': 'string', 'children': [], 'value': '" - fns: %r"'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'fns'}; {'id': '91', 'type': 'for_statement', 'children': ['92', '95', '96']}; {'id': '92', 'type': 'pattern_list', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'xindx'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'xfn'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'fns'}; {'id': '96', 'type': 'block', 'children': ['97', '108']}; {'id': '97', 'type': 'if_statement', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': '_debug'}; {'id': '99', 'type': 'block', 'children': ['100']}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}; {'id': '101', 'type': 'call', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'Collector'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': '_debug'}; {'id': '105', 'type': 'argument_list', 'children': ['106', '107']}; {'id': '106', 'type': 'string', 'children': [], 'value': '" - yield xfn: %r"'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'xfn'}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}; {'id': '109', 'type': 'yield', 'children': ['110']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'xfn'}
def capability_functions(self, fn): if _debug: Collector._debug("capability_functions %r", fn) fns = [] for cls in self.capabilities: xfn = getattr(cls, fn, None) if _debug: Collector._debug(" - cls, xfn: %r, %r", cls, xfn) if xfn: fns.append( (getattr(cls, '_zindex', None), xfn) ) fns.sort(key=lambda v: v[0]) if _debug: Collector._debug(" - fns: %r", fns) for xindx, xfn in fns: if _debug: Collector._debug(" - yield xfn: %r", xfn) yield xfn
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'add'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'list_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '7', 'type': 'block', 'children': ['8', '35']}; {'id': '8', 'type': 'for_statement', 'children': ['9', '10', '11']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '11', 'type': 'block', 'children': ['12', '21', '27']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'call', 'children': ['14', '19']}; {'id': '14', 'type': 'attribute', 'children': ['15', '18']}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'unsorted'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '24', 'type': 'subscript', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '26', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '34']}; {'id': '29', 'type': 'subscript', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '35', 'type': 'return_statement', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}
def add(self, *items): for item in items: self.unsorted.append(item) key = item[0] self.index[key] = item return self
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '14', '22', '129', '137']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '11']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '13', 'type': 'argument_list', 'children': []}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'id': '15', 'type': 'assignment', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'pushed'}; {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '21', 'type': 'argument_list', 'children': []}; {'id': '22', 'type': 'for_statement', 'children': ['23', '24', '27']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'unsorted'}; {'id': '27', 'type': 'block', 'children': ['28', '32', '39', '116']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}; {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'popped'}; {'id': '31', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'push'}; {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '39', 'type': 'while_statement', 'children': ['40', '46']}; {'id': '40', 'type': 'call', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'stack'}; {'id': '46', 'type': 'block', 'children': ['47']}; {'id': '47', 'type': 'try_statement', 'children': ['48', '101']}; {'id': '48', 'type': 'block', 'children': ['49', '57', '66', '77', '94']}; {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'top'}; {'id': '52', 'type': 'call', 'children': ['53', '56']}; {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'top'}; {'id': '56', 'type': 'argument_list', 'children': []}; {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'ref'}; {'id': '60', 'type': 'call', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'next'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}; {'id': '63', 'type': 'subscript', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'top'}; {'id': '65', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}; {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'refd'}; {'id': '69', 'type': 'call', 'children': ['70', '75']}; {'id': '70', 'type': 'attribute', 'children': ['71', '74']}; {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'ref'}; {'id': '77', 'type': 'if_statement', 'children': ['78', '81']}; {'id': '78', 'type': 'comparison_operator', 'children': ['79', '80'], 'value': 'is'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'refd'}; {'id': '80', 'type': 'None', 'children': []}; {'id': '81', 'type': 'block', 'children': ['82', '93']}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}; {'id': '83', 'type': 'call', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '87', 'type': 'argument_list', 'children': ['88', '89']}; {'id': '88', 'type': 'string', 'children': [], 'value': '\'"%s" not found, skipped\''}; {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'Repr'}; {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'ref'}; {'id': '93', 'type': 'continue_statement', 'children': []}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}; {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'push'}; {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'refd'}; {'id': '101', 'type': 'except_clause', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'StopIteration'}; {'id': '103', 'type': 'block', 'children': ['104', '115']}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}; {'id': '105', 'type': 'call', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'popped'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'call', 'children': ['111', '114']}; {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '114', 'type': 'argument_list', 'children': []}; {'id': '115', 'type': 'continue_statement', 'children': []}; {'id': '116', 'type': 'for_statement', 'children': ['117', '118', '119']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'popped'}; {'id': '119', 'type': 'block', 'children': ['120']}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}; {'id': '121', 'type': 'call', 'children': ['122', '127']}; {'id': '122', 'type': 'attribute', 'children': ['123', '126']}; {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'assignment', 'children': ['131', '134']}; {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'unsorted'}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '137', 'type': 'return_statement', 'children': ['138']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'sorted'}
def sort(self): self.sorted = list() self.pushed = set() for item in self.unsorted: popped = [] self.push(item) while len(self.stack): try: top = self.top() ref = next(top[1]) refd = self.index.get(ref) if refd is None: log.debug('"%s" not found, skipped', Repr(ref)) continue self.push(refd) except StopIteration: popped.append(self.pop()) continue for p in popped: self.sorted.append(p) self.unsorted = self.sorted return self.sorted
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'push'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '6', 'type': 'block', 'children': ['7', '15', '26', '35']}; {'id': '7', 'type': 'if_statement', 'children': ['8', '13']}; {'id': '8', 'type': 'comparison_operator', 'children': ['9', '10'], 'value': 'in'}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'pushed'}; {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'return_statement', 'children': []}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'frame'}; {'id': '18', 'type': 'tuple', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '20', 'type': 'call', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'iter'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}; {'id': '23', 'type': 'subscript', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '25', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}; {'id': '27', 'type': 'call', 'children': ['28', '33']}; {'id': '28', 'type': 'attribute', 'children': ['29', '32']}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'stack'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'frame'}; {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '42']}; {'id': '37', 'type': 'attribute', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'pushed'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'item'}
def push(self, item): if item in self.pushed: return frame = (item, iter(item[1])) self.stack.append(frame) self.pushed.add(item)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'content'}; {'id': '6', 'type': 'block', 'children': ['7', '13', '39']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'content'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '13', 'type': 'if_statement', 'children': ['14', '19']}; {'id': '14', 'type': 'call', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'Object'}; {'id': '19', 'type': 'block', 'children': ['20', '26']}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}; {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'md'}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': '__metadata__'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}; {'id': '27', 'type': 'assignment', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'md'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'ordering'}; {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'ordering'}; {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'content'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'real'}; {'id': '39', 'type': 'return_statement', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'}
def sort(self, content): v = content.value if isinstance(v, Object): md = v.__metadata__ md.ordering = self.ordering(content.real) return self
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'alerts'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'alert_level'}; {'id': '7', 'type': 'string', 'children': [], 'value': "'High'"}; {'id': '8', 'type': 'block', 'children': ['9', '21', '29', '65']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'alerts'}; {'id': '12', 'type': 'call', 'children': ['13', '20']}; {'id': '13', 'type': 'attribute', 'children': ['14', '19']}; {'id': '14', 'type': 'attribute', 'children': ['15', '18']}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'zap'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'core'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'alerts'}; {'id': '20', 'type': 'argument_list', 'children': []}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'alert_level_value'}; {'id': '24', 'type': 'subscript', 'children': ['25', '28']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'alert_levels'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'alert_level'}; {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'alerts'}; {'id': '32', 'type': 'call', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '50', '62']}; {'id': '35', 'type': 'generator_expression', 'children': ['36', '37', '40']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '37', 'type': 'for_in_clause', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'alerts'}; {'id': '40', 'type': 'if_clause', 'children': ['41']}; {'id': '41', 'type': 'comparison_operator', 'children': ['42', '49'], 'value': '>='}; {'id': '42', 'type': 'subscript', 'children': ['43', '46']}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'alert_levels'}; {'id': '46', 'type': 'subscript', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '48', 'type': 'string', 'children': [], 'value': "'risk'"}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'alert_level_value'}; {'id': '50', 'type': 'keyword_argument', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '52', 'type': 'lambda', 'children': ['53', '55']}; {'id': '53', 'type': 'lambda_parameters', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '55', 'type': 'subscript', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'alert_levels'}; {'id': '59', 'type': 'subscript', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '61', 'type': 'string', 'children': [], 'value': "'risk'"}; {'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '64', 'type': 'True', 'children': []}; {'id': '65', 'type': 'return_statement', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'alerts'}
def alerts(self, alert_level='High'): alerts = self.zap.core.alerts() alert_level_value = self.alert_levels[alert_level] alerts = sorted((a for a in alerts if self.alert_levels[a['risk']] >= alert_level_value), key=lambda k: self.alert_levels[k['risk']], reverse=True) return alerts
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'assortativity_bin'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'CIJ'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'flag'}; {'id': '7', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '8', 'type': 'block', 'children': ['9', '11', '168', '181', '202', '222', '234']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'string', 'children': [], 'value': "'''\n The assortativity coefficient is a correlation coefficient between the\n degrees of all nodes on two opposite ends of a link. A positive\n assortativity coefficient indicates that nodes tend to link to other\n nodes with the same or similar degree.\n Parameters\n ----------\n CIJ : NxN np.ndarray\n binary directed/undirected connection matrix\n flag : int\n 0 : undirected graph; degree/degree correlation\n 1 : directed graph; out-degree/in-degree correlation\n 2 : directed graph; in-degree/out-degree correlation\n 3 : directed graph; out-degree/out-degree correlation\n 4 : directed graph; in-degree/in-degreen correlation\n Returns\n -------\n r : float\n assortativity coefficient\n Notes\n -----\n The function accepts weighted networks, but all connection\n weights are ignored. The main diagonal should be empty. For flag 1\n the function computes the directed assortativity described in Rubinov\n and Sporns (2010) NeuroImage.\n '''"}; {'id': '11', 'type': 'if_statement', 'children': ['12', '15', '61']}; {'id': '12', 'type': 'comparison_operator', 'children': ['13', '14'], 'value': '=='}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'flag'}; {'id': '14', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '15', 'type': 'block', 'children': ['16', '23', '42', '49', '55']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'deg'}; {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'degrees_und'}; {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'CIJ'}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '28']}; {'id': '25', 'type': 'pattern_list', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '28', 'type': 'call', 'children': ['29', '32']}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'where'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}; {'id': '33', 'type': 'comparison_operator', 'children': ['34', '41'], 'value': '>'}; {'id': '34', 'type': 'call', 'children': ['35', '38']}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'triu'}; {'id': '38', 'type': 'argument_list', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'CIJ'}; {'id': '40', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '41', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}; {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'K'}; {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'degi'}; {'id': '52', 'type': 'subscript', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'deg'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'degj'}; {'id': '58', 'type': 'subscript', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'deg'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '61', 'type': 'else_clause', 'children': ['62']}; {'id': '62', 'type': 'block', 'children': ['63', '73', '86', '93']}; {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '69']}; {'id': '65', 'type': 'pattern_list', 'children': ['66', '67', '68']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'od'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'deg'}; {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'degrees_dir'}; {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'CIJ'}; {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '78']}; {'id': '75', 'type': 'pattern_list', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '78', 'type': 'call', 'children': ['79', '82']}; {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'where'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}; {'id': '83', 'type': 'comparison_operator', 'children': ['84', '85'], 'value': '>'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'CIJ'}; {'id': '85', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}; {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'K'}; {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '93', 'type': 'if_statement', 'children': ['94', '97', '110', '127', '144', '161']}; {'id': '94', 'type': 'comparison_operator', 'children': ['95', '96'], 'value': '=='}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'flag'}; {'id': '96', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '97', 'type': 'block', 'children': ['98', '104']}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}; {'id': '99', 'type': 'assignment', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'degi'}; {'id': '101', 'type': 'subscript', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'od'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}; {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'degj'}; {'id': '107', 'type': 'subscript', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '110', 'type': 'elif_clause', 'children': ['111', '114']}; {'id': '111', 'type': 'comparison_operator', 'children': ['112', '113'], 'value': '=='}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'flag'}; {'id': '113', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '114', 'type': 'block', 'children': ['115', '121']}; {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'degi'}; {'id': '118', 'type': 'subscript', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'assignment', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'degj'}; {'id': '124', 'type': 'subscript', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'od'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '127', 'type': 'elif_clause', 'children': ['128', '131']}; {'id': '128', 'type': 'comparison_operator', 'children': ['129', '130'], 'value': '=='}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'flag'}; {'id': '130', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '131', 'type': 'block', 'children': ['132', '138']}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}; {'id': '133', 'type': 'assignment', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'degi'}; {'id': '135', 'type': 'subscript', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'od'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}; {'id': '139', 'type': 'assignment', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'degj'}; {'id': '141', 'type': 'subscript', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'od'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '144', 'type': 'elif_clause', 'children': ['145', '148']}; {'id': '145', 'type': 'comparison_operator', 'children': ['146', '147'], 'value': '=='}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'flag'}; {'id': '147', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '148', 'type': 'block', 'children': ['149', '155']}; {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'assignment', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'degi'}; {'id': '152', 'type': 'subscript', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'assignment', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'degj'}; {'id': '158', 'type': 'subscript', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '161', 'type': 'else_clause', 'children': ['162']}; {'id': '162', 'type': 'block', 'children': ['163']}; {'id': '163', 'type': 'raise_statement', 'children': ['164']}; {'id': '164', 'type': 'call', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '166', 'type': 'argument_list', 'children': ['167']}; {'id': '167', 'type': 'string', 'children': [], 'value': "'Flag must be 0-4'"}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}; {'id': '169', 'type': 'assignment', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'term1'}; {'id': '171', 'type': 'binary_operator', 'children': ['172', '180'], 'value': '/'}; {'id': '172', 'type': 'call', 'children': ['173', '176']}; {'id': '173', 'type': 'attribute', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '176', 'type': 'argument_list', 'children': ['177']}; {'id': '177', 'type': 'binary_operator', 'children': ['178', '179'], 'value': '*'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'degi'}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'degj'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'K'}; {'id': '181', 'type': 'expression_statement', 'children': ['182']}; {'id': '182', 'type': 'assignment', 'children': ['183', '184']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'term2'}; {'id': '184', 'type': 'call', 'children': ['185', '188']}; {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'square'}; {'id': '188', 'type': 'argument_list', 'children': ['189']}; {'id': '189', 'type': 'binary_operator', 'children': ['190', '201'], 'value': '/'}; {'id': '190', 'type': 'call', 'children': ['191', '194']}; {'id': '191', 'type': 'attribute', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '194', 'type': 'argument_list', 'children': ['195']}; {'id': '195', 'type': 'binary_operator', 'children': ['196', '197'], 'value': '*'}; {'id': '196', 'type': 'float', 'children': [], 'value': '.5'}; {'id': '197', 'type': '()', 'children': ['198']}; {'id': '198', 'type': 'binary_operator', 'children': ['199', '200'], 'value': '+'}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'degi'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'degj'}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'K'}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}; {'id': '203', 'type': 'assignment', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'term3'}; {'id': '205', 'type': 'binary_operator', 'children': ['206', '221'], 'value': '/'}; {'id': '206', 'type': 'call', 'children': ['207', '210']}; {'id': '207', 'type': 'attribute', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '210', 'type': 'argument_list', 'children': ['211']}; {'id': '211', 'type': 'binary_operator', 'children': ['212', '213'], 'value': '*'}; {'id': '212', 'type': 'float', 'children': [], 'value': '.5'}; {'id': '213', 'type': '()', 'children': ['214']}; {'id': '214', 'type': 'binary_operator', 'children': ['215', '218'], 'value': '+'}; {'id': '215', 'type': 'binary_operator', 'children': ['216', '217'], 'value': '*'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'degi'}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'degi'}; {'id': '218', 'type': 'binary_operator', 'children': ['219', '220'], 'value': '*'}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'degj'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'degj'}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'K'}; {'id': '222', 'type': 'expression_statement', 'children': ['223']}; {'id': '223', 'type': 'assignment', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '225', 'type': 'binary_operator', 'children': ['226', '230'], 'value': '/'}; {'id': '226', 'type': '()', 'children': ['227']}; {'id': '227', 'type': 'binary_operator', 'children': ['228', '229'], 'value': '-'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'term1'}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'term2'}; {'id': '230', 'type': '()', 'children': ['231']}; {'id': '231', 'type': 'binary_operator', 'children': ['232', '233'], 'value': '-'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'term3'}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'term2'}; {'id': '234', 'type': 'return_statement', 'children': ['235']}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'r'}
def assortativity_bin(CIJ, flag=0): ''' The assortativity coefficient is a correlation coefficient between the degrees of all nodes on two opposite ends of a link. A positive assortativity coefficient indicates that nodes tend to link to other nodes with the same or similar degree. Parameters ---------- CIJ : NxN np.ndarray binary directed/undirected connection matrix flag : int 0 : undirected graph; degree/degree correlation 1 : directed graph; out-degree/in-degree correlation 2 : directed graph; in-degree/out-degree correlation 3 : directed graph; out-degree/out-degree correlation 4 : directed graph; in-degree/in-degreen correlation Returns ------- r : float assortativity coefficient Notes ----- The function accepts weighted networks, but all connection weights are ignored. The main diagonal should be empty. For flag 1 the function computes the directed assortativity described in Rubinov and Sporns (2010) NeuroImage. ''' if flag == 0: deg = degrees_und(CIJ) i, j = np.where(np.triu(CIJ, 1) > 0) K = len(i) degi = deg[i] degj = deg[j] else: id, od, deg = degrees_dir(CIJ) i, j = np.where(CIJ > 0) K = len(i) if flag == 1: degi = od[i] degj = id[j] elif flag == 2: degi = id[i] degj = od[j] elif flag == 3: degi = od[i] degj = od[j] elif flag == 4: degi = id[i] degj = id[j] else: raise ValueError('Flag must be 0-4') term1 = np.sum(degi * degj) / K term2 = np.square(np.sum(.5 * (degi + degj)) / K) term3 = np.sum(.5 * (degi * degi + degj * degj)) / K r = (term1 - term2) / (term3 - term2) return r
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_coords'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'coord'}; {'id': '5', 'type': 'block', 'children': ['6', '9', '27', '38']}; {'id': '6', 'type': 'import_statement', 'children': ['7']}; {'id': '7', 'type': 'dotted_name', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'iris'}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '12', 'type': 'dictionary', 'children': ['13', '17', '21', '24']}; {'id': '13', 'type': 'pair', 'children': ['14', '15']}; {'id': '14', 'type': 'string', 'children': [], 'value': "'T'"}; {'id': '15', 'type': 'unary_operator', 'children': ['16'], 'value': '-'}; {'id': '16', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '17', 'type': 'pair', 'children': ['18', '19']}; {'id': '18', 'type': 'string', 'children': [], 'value': "'Z'"}; {'id': '19', 'type': 'unary_operator', 'children': ['20'], 'value': '-'}; {'id': '20', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '21', 'type': 'pair', 'children': ['22', '23']}; {'id': '22', 'type': 'string', 'children': [], 'value': "'X'"}; {'id': '23', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '24', 'type': 'pair', 'children': ['25', '26']}; {'id': '25', 'type': 'string', 'children': [], 'value': "'Y'"}; {'id': '26', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '30', 'type': 'call', 'children': ['31', '36']}; {'id': '31', 'type': 'attribute', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'iris'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'util'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'guess_coord_axis'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'coord'}; {'id': '38', 'type': 'return_statement', 'children': ['39']}; {'id': '39', 'type': 'tuple', 'children': ['40', '47']}; {'id': '40', 'type': 'call', 'children': ['41', '44']}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '46', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '47', 'type': 'boolean_operator', 'children': ['48', '49'], 'value': 'and'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'coord'}; {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'coord'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '53', 'type': 'argument_list', 'children': []}
def sort_coords(coord): import iris order = {'T': -2, 'Z': -1, 'X': 1, 'Y': 2} axis = iris.util.guess_coord_axis(coord) return (order.get(axis, 0), coord and coord.name())
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'separate_groups'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'groups'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'total'}; {'id': '7', 'type': 'block', 'children': ['8', '21', '33', '41', '56', '71', '77', '83']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '13']}; {'id': '10', 'type': 'pattern_list', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'optimum'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'extra'}; {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'compute_optimum'}; {'id': '15', 'type': 'argument_list', 'children': ['16', '20']}; {'id': '16', 'type': 'call', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'groups'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'total'}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '27']}; {'id': '23', 'type': 'pattern_list', 'children': ['24', '25', '26']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'over_loaded'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'under_loaded'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'optimal'}; {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': '_smart_separate_groups'}; {'id': '29', 'type': 'argument_list', 'children': ['30', '31', '32']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'groups'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'total'}; {'id': '33', 'type': 'if_statement', 'children': ['34', '36']}; {'id': '34', 'type': 'not_operator', 'children': ['35']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'extra'}; {'id': '36', 'type': 'block', 'children': ['37']}; {'id': '37', 'type': 'return_statement', 'children': ['38']}; {'id': '38', 'type': 'expression_list', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'over_loaded'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'under_loaded'}; {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'potential_under_loaded'}; {'id': '44', 'type': 'list_comprehension', 'children': ['45', '46', '49']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '46', 'type': 'for_in_clause', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'optimal'}; {'id': '49', 'type': 'if_clause', 'children': ['50']}; {'id': '50', 'type': 'comparison_operator', 'children': ['51', '55'], 'value': '=='}; {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'optimum'}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}; {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'potential_over_loaded'}; {'id': '59', 'type': 'list_comprehension', 'children': ['60', '61', '64']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '61', 'type': 'for_in_clause', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'optimal'}; {'id': '64', 'type': 'if_clause', 'children': ['65']}; {'id': '65', 'type': 'comparison_operator', 'children': ['66', '70'], 'value': '>'}; {'id': '66', 'type': 'call', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'optimum'}; {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'revised_under_loaded'}; {'id': '74', 'type': 'binary_operator', 'children': ['75', '76'], 'value': '+'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'under_loaded'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'potential_under_loaded'}; {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'revised_over_loaded'}; {'id': '80', 'type': 'binary_operator', 'children': ['81', '82'], 'value': '+'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'over_loaded'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'potential_over_loaded'}; {'id': '83', 'type': 'return_statement', 'children': ['84']}; {'id': '84', 'type': 'tuple', 'children': ['85', '95']}; {'id': '85', 'type': 'call', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '87', 'type': 'argument_list', 'children': ['88', '89', '92']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'revised_over_loaded'}; {'id': '89', 'type': 'keyword_argument', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '92', 'type': 'keyword_argument', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '94', 'type': 'True', 'children': []}; {'id': '95', 'type': 'call', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '97', 'type': 'argument_list', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'revised_under_loaded'}; {'id': '99', 'type': 'keyword_argument', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'key'}
def separate_groups(groups, key, total): optimum, extra = compute_optimum(len(groups), total) over_loaded, under_loaded, optimal = _smart_separate_groups(groups, key, total) if not extra: return over_loaded, under_loaded potential_under_loaded = [ group for group in optimal if key(group) == optimum ] potential_over_loaded = [ group for group in optimal if key(group) > optimum ] revised_under_loaded = under_loaded + potential_under_loaded revised_over_loaded = over_loaded + potential_over_loaded return ( sorted(revised_over_loaded, key=key, reverse=True), sorted(revised_under_loaded, key=key), )
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'zrange'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '11', '14']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'desc'}; {'id': '10', 'type': 'False', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'withscores'}; {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'score_cast_func'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '17', 'type': 'block', 'children': ['18', '33', '41', '54', '64']}; {'id': '18', 'type': 'if_statement', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'desc'}; {'id': '20', 'type': 'block', 'children': ['21']}; {'id': '21', 'type': 'return_statement', 'children': ['22']}; {'id': '22', 'type': 'await', 'children': ['23']}; {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'zrevrange'}; {'id': '27', 'type': 'argument_list', 'children': ['28', '29', '30', '31', '32']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'withscores'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'score_cast_func'}; {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'pieces'}; {'id': '36', 'type': 'list', 'children': ['37', '38', '39', '40'], 'value': "['ZRANGE', name, start, end]"}; {'id': '37', 'type': 'string', 'children': [], 'value': "'ZRANGE'"}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '41', 'type': 'if_statement', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'withscores'}; {'id': '43', 'type': 'block', 'children': ['44']}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}; {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'pieces'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'call', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}; {'id': '53', 'type': 'string', 'children': [], 'value': "'WITHSCORES'"}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}; {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'options'}; {'id': '57', 'type': 'dictionary', 'children': ['58', '61']}; {'id': '58', 'type': 'pair', 'children': ['59', '60']}; {'id': '59', 'type': 'string', 'children': [], 'value': "'withscores'"}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'withscores'}; {'id': '61', 'type': 'pair', 'children': ['62', '63']}; {'id': '62', 'type': 'string', 'children': [], 'value': "'score_cast_func'"}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'score_cast_func'}; {'id': '64', 'type': 'return_statement', 'children': ['65']}; {'id': '65', 'type': 'await', 'children': ['66']}; {'id': '66', 'type': 'call', 'children': ['67', '70']}; {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'execute_command'}; {'id': '70', 'type': 'argument_list', 'children': ['71', '73']}; {'id': '71', 'type': 'list_splat', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'pieces'}; {'id': '73', 'type': 'dictionary_splat', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'options'}
async def zrange(self, name, start, end, desc=False, withscores=False, score_cast_func=float): if desc: return await self.zrevrange(name, start, end, withscores, score_cast_func) pieces = ['ZRANGE', name, start, end] if withscores: pieces.append(b('WITHSCORES')) options = { 'withscores': withscores, 'score_cast_func': score_cast_func } return await self.execute_command(*pieces, **options)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'zremrangebyscore'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '8', 'type': 'block', 'children': ['9']}; {'id': '9', 'type': 'return_statement', 'children': ['10']}; {'id': '10', 'type': 'await', 'children': ['11']}; {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'execute_command'}; {'id': '15', 'type': 'argument_list', 'children': ['16', '17', '18', '19']}; {'id': '16', 'type': 'string', 'children': [], 'value': "'ZREMRANGEBYSCORE'"}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'max'}
async def zremrangebyscore(self, name, min, max): return await self.execute_command('ZREMRANGEBYSCORE', name, min, max)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '33']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'georadius'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '12', '15', '18', '21', '24', '27', '30']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'longitude'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'latitude'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'radius'}; {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'unit'}; {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'withdist'}; {'id': '14', 'type': 'False', 'children': []}; {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'withcoord'}; {'id': '17', 'type': 'False', 'children': []}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'withhash'}; {'id': '20', 'type': 'False', 'children': []}; {'id': '21', 'type': 'default_parameter', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '23', 'type': 'None', 'children': []}; {'id': '24', 'type': 'default_parameter', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '26', 'type': 'None', 'children': []}; {'id': '27', 'type': 'default_parameter', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'store'}; {'id': '29', 'type': 'None', 'children': []}; {'id': '30', 'type': 'default_parameter', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'store_dist'}; {'id': '32', 'type': 'None', 'children': []}; {'id': '33', 'type': 'block', 'children': ['34']}; {'id': '34', 'type': 'return_statement', 'children': ['35']}; {'id': '35', 'type': 'await', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '40']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': '_georadiusgeneric'}; {'id': '40', 'type': 'argument_list', 'children': ['41', '42', '43', '44', '45', '46', '49', '52', '55', '58', '61', '64', '67']}; {'id': '41', 'type': 'string', 'children': [], 'value': "'GEORADIUS'"}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'longitude'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'latitude'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'radius'}; {'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'unit'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'unit'}; {'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'withdist'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'withdist'}; {'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'withcoord'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'withcoord'}; {'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'withhash'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'withhash'}; {'id': '58', 'type': 'keyword_argument', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '61', 'type': 'keyword_argument', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '64', 'type': 'keyword_argument', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'store'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'store'}; {'id': '67', 'type': 'keyword_argument', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'store_dist'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'store_dist'}
async def georadius(self, name, longitude, latitude, radius, unit=None, withdist=False, withcoord=False, withhash=False, count=None, sort=None, store=None, store_dist=None): return await self._georadiusgeneric('GEORADIUS', name, longitude, latitude, radius, unit=unit, withdist=withdist, withcoord=withcoord, withhash=withhash, count=count, sort=sort, store=store, store_dist=store_dist)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '32']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'georadiusbymember'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '11', '14', '17', '20', '23', '26', '29']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'member'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'radius'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'unit'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'withdist'}; {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'withcoord'}; {'id': '16', 'type': 'False', 'children': []}; {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'withhash'}; {'id': '19', 'type': 'False', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '22', 'type': 'None', 'children': []}; {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '25', 'type': 'None', 'children': []}; {'id': '26', 'type': 'default_parameter', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'store'}; {'id': '28', 'type': 'None', 'children': []}; {'id': '29', 'type': 'default_parameter', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'store_dist'}; {'id': '31', 'type': 'None', 'children': []}; {'id': '32', 'type': 'block', 'children': ['33']}; {'id': '33', 'type': 'return_statement', 'children': ['34']}; {'id': '34', 'type': 'await', 'children': ['35']}; {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': '_georadiusgeneric'}; {'id': '39', 'type': 'argument_list', 'children': ['40', '41', '42', '43', '44', '47', '50', '53', '56', '59', '62', '65']}; {'id': '40', 'type': 'string', 'children': [], 'value': "'GEORADIUSBYMEMBER'"}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'member'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'radius'}; {'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'unit'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'unit'}; {'id': '47', 'type': 'keyword_argument', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'withdist'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'withdist'}; {'id': '50', 'type': 'keyword_argument', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'withcoord'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'withcoord'}; {'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'withhash'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'withhash'}; {'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '59', 'type': 'keyword_argument', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'store'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'store'}; {'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'store_dist'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'store_dist'}
async def georadiusbymember(self, name, member, radius, unit=None, withdist=False, withcoord=False, withhash=False, count=None, sort=None, store=None, store_dist=None): return await self._georadiusgeneric('GEORADIUSBYMEMBER', name, member, radius, unit=unit, withdist=withdist, withcoord=withcoord, withhash=withhash, count=count, sort=sort, store=store, store_dist=store_dist)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '32']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'search'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '7', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'per_page'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '50'}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '16', 'type': 'None', 'children': []}; {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'include_totals'}; {'id': '19', 'type': 'True', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '22', 'type': 'None', 'children': []}; {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'from_param'}; {'id': '25', 'type': 'None', 'children': []}; {'id': '26', 'type': 'default_parameter', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'take'}; {'id': '28', 'type': 'None', 'children': []}; {'id': '29', 'type': 'default_parameter', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'include_fields'}; {'id': '31', 'type': 'True', 'children': []}; {'id': '32', 'type': 'block', 'children': ['33', '87']}; {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '36', 'type': 'dictionary', 'children': ['37', '40', '43', '53', '56', '68', '78', '81', '84']}; {'id': '37', 'type': 'pair', 'children': ['38', '39']}; {'id': '38', 'type': 'string', 'children': [], 'value': "'per_page'"}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'per_page'}; {'id': '40', 'type': 'pair', 'children': ['41', '42']}; {'id': '41', 'type': 'string', 'children': [], 'value': "'page'"}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '43', 'type': 'pair', 'children': ['44', '45']}; {'id': '44', 'type': 'string', 'children': [], 'value': "'include_totals'"}; {'id': '45', 'type': 'call', 'children': ['46', '52']}; {'id': '46', 'type': 'attribute', 'children': ['47', '51']}; {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'include_totals'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '52', 'type': 'argument_list', 'children': []}; {'id': '53', 'type': 'pair', 'children': ['54', '55']}; {'id': '54', 'type': 'string', 'children': [], 'value': "'sort'"}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '56', 'type': 'pair', 'children': ['57', '58']}; {'id': '57', 'type': 'string', 'children': [], 'value': "'fields'"}; {'id': '58', 'type': 'boolean_operator', 'children': ['59', '67'], 'value': 'or'}; {'id': '59', 'type': 'boolean_operator', 'children': ['60', '61'], 'value': 'and'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}; {'id': '63', 'type': 'string', 'children': [], 'value': "','"}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '67', 'type': 'None', 'children': []}; {'id': '68', 'type': 'pair', 'children': ['69', '70']}; {'id': '69', 'type': 'string', 'children': [], 'value': "'include_fields'"}; {'id': '70', 'type': 'call', 'children': ['71', '77']}; {'id': '71', 'type': 'attribute', 'children': ['72', '76']}; {'id': '72', 'type': 'call', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'include_fields'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '77', 'type': 'argument_list', 'children': []}; {'id': '78', 'type': 'pair', 'children': ['79', '80']}; {'id': '79', 'type': 'string', 'children': [], 'value': "'q'"}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '81', 'type': 'pair', 'children': ['82', '83']}; {'id': '82', 'type': 'string', 'children': [], 'value': "'from'"}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'from_param'}; {'id': '84', 'type': 'pair', 'children': ['85', '86']}; {'id': '85', 'type': 'string', 'children': [], 'value': "'take'"}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'take'}; {'id': '87', 'type': 'return_statement', 'children': ['88']}; {'id': '88', 'type': 'call', 'children': ['89', '94']}; {'id': '89', 'type': 'attribute', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'client'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '94', 'type': 'argument_list', 'children': ['95', '100']}; {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': '_url'}; {'id': '99', 'type': 'argument_list', 'children': []}; {'id': '100', 'type': 'keyword_argument', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'params'}
def search(self, page=0, per_page=50, sort=None, q=None, include_totals=True, fields=None, from_param=None, take=None, include_fields=True): params = { 'per_page': per_page, 'page': page, 'include_totals': str(include_totals).lower(), 'sort': sort, 'fields': fields and ','.join(fields) or None, 'include_fields': str(include_fields).lower(), 'q': q, 'from': from_param, 'take': take } return self.client.get(self._url(), params=params)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '32']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'list'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '7', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'per_page'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '25'}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'connection'}; {'id': '16', 'type': 'None', 'children': []}; {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'search_engine'}; {'id': '22', 'type': 'None', 'children': []}; {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'include_totals'}; {'id': '25', 'type': 'True', 'children': []}; {'id': '26', 'type': 'default_parameter', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '28', 'type': 'None', 'children': []}; {'id': '29', 'type': 'default_parameter', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'include_fields'}; {'id': '31', 'type': 'True', 'children': []}; {'id': '32', 'type': 'block', 'children': ['33', '87']}; {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '36', 'type': 'dictionary', 'children': ['37', '40', '43', '53', '56', '59', '71', '81', '84']}; {'id': '37', 'type': 'pair', 'children': ['38', '39']}; {'id': '38', 'type': 'string', 'children': [], 'value': "'per_page'"}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'per_page'}; {'id': '40', 'type': 'pair', 'children': ['41', '42']}; {'id': '41', 'type': 'string', 'children': [], 'value': "'page'"}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '43', 'type': 'pair', 'children': ['44', '45']}; {'id': '44', 'type': 'string', 'children': [], 'value': "'include_totals'"}; {'id': '45', 'type': 'call', 'children': ['46', '52']}; {'id': '46', 'type': 'attribute', 'children': ['47', '51']}; {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'include_totals'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '52', 'type': 'argument_list', 'children': []}; {'id': '53', 'type': 'pair', 'children': ['54', '55']}; {'id': '54', 'type': 'string', 'children': [], 'value': "'sort'"}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '56', 'type': 'pair', 'children': ['57', '58']}; {'id': '57', 'type': 'string', 'children': [], 'value': "'connection'"}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'connection'}; {'id': '59', 'type': 'pair', 'children': ['60', '61']}; {'id': '60', 'type': 'string', 'children': [], 'value': "'fields'"}; {'id': '61', 'type': 'boolean_operator', 'children': ['62', '70'], 'value': 'or'}; {'id': '62', 'type': 'boolean_operator', 'children': ['63', '64'], 'value': 'and'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '64', 'type': 'call', 'children': ['65', '68']}; {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'string', 'children': [], 'value': "','"}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '70', 'type': 'None', 'children': []}; {'id': '71', 'type': 'pair', 'children': ['72', '73']}; {'id': '72', 'type': 'string', 'children': [], 'value': "'include_fields'"}; {'id': '73', 'type': 'call', 'children': ['74', '80']}; {'id': '74', 'type': 'attribute', 'children': ['75', '79']}; {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'include_fields'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '80', 'type': 'argument_list', 'children': []}; {'id': '81', 'type': 'pair', 'children': ['82', '83']}; {'id': '82', 'type': 'string', 'children': [], 'value': "'q'"}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '84', 'type': 'pair', 'children': ['85', '86']}; {'id': '85', 'type': 'string', 'children': [], 'value': "'search_engine'"}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'search_engine'}; {'id': '87', 'type': 'return_statement', 'children': ['88']}; {'id': '88', 'type': 'call', 'children': ['89', '94']}; {'id': '89', 'type': 'attribute', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'client'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '94', 'type': 'argument_list', 'children': ['95', '100']}; {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': '_url'}; {'id': '99', 'type': 'argument_list', 'children': []}; {'id': '100', 'type': 'keyword_argument', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'params'}
def list(self, page=0, per_page=25, sort=None, connection=None, q=None, search_engine=None, include_totals=True, fields=None, include_fields=True): params = { 'per_page': per_page, 'page': page, 'include_totals': str(include_totals).lower(), 'sort': sort, 'connection': connection, 'fields': fields and ','.join(fields) or None, 'include_fields': str(include_fields).lower(), 'q': q, 'search_engine': search_engine } return self.client.get(self._url(), params=params)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_log_events'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'user_id'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '8', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'per_page'}; {'id': '11', 'type': 'integer', 'children': [], 'value': '50'}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '14', 'type': 'None', 'children': []}; {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'include_totals'}; {'id': '17', 'type': 'False', 'children': []}; {'id': '18', 'type': 'block', 'children': ['19', '42', '56']}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '22', 'type': 'dictionary', 'children': ['23', '26', '29', '39']}; {'id': '23', 'type': 'pair', 'children': ['24', '25']}; {'id': '24', 'type': 'string', 'children': [], 'value': "'per_page'"}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'per_page'}; {'id': '26', 'type': 'pair', 'children': ['27', '28']}; {'id': '27', 'type': 'string', 'children': [], 'value': "'page'"}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '29', 'type': 'pair', 'children': ['30', '31']}; {'id': '30', 'type': 'string', 'children': [], 'value': "'include_totals'"}; {'id': '31', 'type': 'call', 'children': ['32', '38']}; {'id': '32', 'type': 'attribute', 'children': ['33', '37']}; {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'include_totals'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '38', 'type': 'argument_list', 'children': []}; {'id': '39', 'type': 'pair', 'children': ['40', '41']}; {'id': '40', 'type': 'string', 'children': [], 'value': "'sort'"}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}; {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': '_url'}; {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'call', 'children': ['51', '54']}; {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'string', 'children': [], 'value': "'{}/logs'"}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'user_id'}; {'id': '56', 'type': 'return_statement', 'children': ['57']}; {'id': '57', 'type': 'call', 'children': ['58', '63']}; {'id': '58', 'type': 'attribute', 'children': ['59', '62']}; {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'client'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '63', 'type': 'argument_list', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'params'}
def get_log_events(self, user_id, page=0, per_page=50, sort=None, include_totals=False): params = { 'per_page': per_page, 'page': page, 'include_totals': str(include_totals).lower(), 'sort': sort } url = self._url('{}/logs'.format(user_id)) return self.client.get(url, params=params)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_activities'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'before'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'after'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '27', '39', '51', '67']}; {'id': '15', 'type': 'if_statement', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'before'}; {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'before'}; {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': '_utc_datetime_to_epoch'}; {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'before'}; {'id': '27', 'type': 'if_statement', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'after'}; {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'after'}; {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': '_utc_datetime_to_epoch'}; {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'after'}; {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '42', 'type': 'call', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '48']}; {'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'before'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'before'}; {'id': '48', 'type': 'keyword_argument', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'after'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'after'}; {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'result_fetcher'}; {'id': '54', 'type': 'call', 'children': ['55', '58']}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'functools'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'partial'}; {'id': '58', 'type': 'argument_list', 'children': ['59', '64', '65']}; {'id': '59', 'type': 'attribute', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'protocol'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '64', 'type': 'string', 'children': [], 'value': "'/athlete/activities'"}; {'id': '65', 'type': 'dictionary_splat', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '67', 'type': 'return_statement', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'BatchedResultsIterator'}; {'id': '70', 'type': 'argument_list', 'children': ['71', '76', '79', '82']}; {'id': '71', 'type': 'keyword_argument', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'Activity'}; {'id': '76', 'type': 'keyword_argument', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'bind_client'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '79', 'type': 'keyword_argument', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'result_fetcher'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'result_fetcher'}; {'id': '82', 'type': 'keyword_argument', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'limit'}
def get_activities(self, before=None, after=None, limit=None): if before: before = self._utc_datetime_to_epoch(before) if after: after = self._utc_datetime_to_epoch(after) params = dict(before=before, after=after) result_fetcher = functools.partial(self.protocol.get, '/athlete/activities', **params) return BatchedResultsIterator(entity=model.Activity, bind_client=self, result_fetcher=result_fetcher, limit=limit)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '33']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_segment_leaderboard'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24', '27', '30']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'segment_id'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'gender'}; {'id': '8', 'type': 'None', 'children': []}; {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'age_group'}; {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'weight_class'}; {'id': '14', 'type': 'None', 'children': []}; {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'following'}; {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'club_id'}; {'id': '20', 'type': 'None', 'children': []}; {'id': '21', 'type': 'default_parameter', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'timeframe'}; {'id': '23', 'type': 'None', 'children': []}; {'id': '24', 'type': 'default_parameter', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'top_results_limit'}; {'id': '26', 'type': 'None', 'children': []}; {'id': '27', 'type': 'default_parameter', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '29', 'type': 'None', 'children': []}; {'id': '30', 'type': 'default_parameter', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'context_entries'}; {'id': '32', 'type': 'None', 'children': []}; {'id': '33', 'type': 'block', 'children': ['34', '38', '70', '80', '108', '124', '152', '166', '177', '213', '224', '235', '246']}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}; {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '37', 'type': 'dictionary', 'children': []}; {'id': '38', 'type': 'if_statement', 'children': ['39', '42']}; {'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': 'is'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'gender'}; {'id': '41', 'type': 'None', 'children': []}; {'id': '42', 'type': 'block', 'children': ['43', '64']}; {'id': '43', 'type': 'if_statement', 'children': ['44', '53']}; {'id': '44', 'type': 'comparison_operator', 'children': ['45', '50'], 'value': 'not'}; {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'gender'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'upper'}; {'id': '49', 'type': 'argument_list', 'children': []}; {'id': '50', 'type': 'tuple', 'children': ['51', '52']}; {'id': '51', 'type': 'string', 'children': [], 'value': "'M'"}; {'id': '52', 'type': 'string', 'children': [], 'value': "'F'"}; {'id': '53', 'type': 'block', 'children': ['54']}; {'id': '54', 'type': 'raise_statement', 'children': ['55']}; {'id': '55', 'type': 'call', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '62']}; {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'string', 'children': [], 'value': '"Invalid gender: {0}. Possible values: \'M\' or \'F\'"'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'gender'}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}; {'id': '65', 'type': 'assignment', 'children': ['66', '69']}; {'id': '66', 'type': 'subscript', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '68', 'type': 'string', 'children': [], 'value': "'gender'"}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'gender'}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}; {'id': '71', 'type': 'assignment', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'valid_age_groups'}; {'id': '73', 'type': 'tuple', 'children': ['74', '75', '76', '77', '78', '79']}; {'id': '74', 'type': 'string', 'children': [], 'value': "'0_24'"}; {'id': '75', 'type': 'string', 'children': [], 'value': "'25_34'"}; {'id': '76', 'type': 'string', 'children': [], 'value': "'35_44'"}; {'id': '77', 'type': 'string', 'children': [], 'value': "'45_54'"}; {'id': '78', 'type': 'string', 'children': [], 'value': "'55_64'"}; {'id': '79', 'type': 'string', 'children': [], 'value': "'65_plus'"}; {'id': '80', 'type': 'if_statement', 'children': ['81', '84']}; {'id': '81', 'type': 'comparison_operator', 'children': ['82', '83'], 'value': 'is'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'age_group'}; {'id': '83', 'type': 'None', 'children': []}; {'id': '84', 'type': 'block', 'children': ['85', '102']}; {'id': '85', 'type': 'if_statement', 'children': ['86', '90']}; {'id': '86', 'type': 'not_operator', 'children': ['87']}; {'id': '87', 'type': 'comparison_operator', 'children': ['88', '89'], 'value': 'in'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'age_group'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'valid_age_groups'}; {'id': '90', 'type': 'block', 'children': ['91']}; {'id': '91', 'type': 'raise_statement', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}; {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}; {'id': '97', 'type': 'string', 'children': [], 'value': '"Invalid age group: {0}. Possible values: {1!r}"'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '99', 'type': 'argument_list', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'age_group'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'valid_age_groups'}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}; {'id': '103', 'type': 'assignment', 'children': ['104', '107']}; {'id': '104', 'type': 'subscript', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '106', 'type': 'string', 'children': [], 'value': "'age_group'"}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'age_group'}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}; {'id': '109', 'type': 'assignment', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'valid_weight_classes'}; {'id': '111', 'type': 'tuple', 'children': ['112', '113', '114', '115', '116', '117', '118', '119', '120', '121', '122', '123']}; {'id': '112', 'type': 'string', 'children': [], 'value': "'0_124'"}; {'id': '113', 'type': 'string', 'children': [], 'value': "'125_149'"}; {'id': '114', 'type': 'string', 'children': [], 'value': "'150_164'"}; {'id': '115', 'type': 'string', 'children': [], 'value': "'165_179'"}; {'id': '116', 'type': 'string', 'children': [], 'value': "'180_199'"}; {'id': '117', 'type': 'string', 'children': [], 'value': "'200_plus'"}; {'id': '118', 'type': 'string', 'children': [], 'value': "'0_54'"}; {'id': '119', 'type': 'string', 'children': [], 'value': "'55_64'"}; {'id': '120', 'type': 'string', 'children': [], 'value': "'65_74'"}; {'id': '121', 'type': 'string', 'children': [], 'value': "'75_84'"}; {'id': '122', 'type': 'string', 'children': [], 'value': "'85_94'"}; {'id': '123', 'type': 'string', 'children': [], 'value': "'95_plus'"}; {'id': '124', 'type': 'if_statement', 'children': ['125', '128']}; {'id': '125', 'type': 'comparison_operator', 'children': ['126', '127'], 'value': 'is'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'weight_class'}; {'id': '127', 'type': 'None', 'children': []}; {'id': '128', 'type': 'block', 'children': ['129', '146']}; {'id': '129', 'type': 'if_statement', 'children': ['130', '134']}; {'id': '130', 'type': 'not_operator', 'children': ['131']}; {'id': '131', 'type': 'comparison_operator', 'children': ['132', '133'], 'value': 'in'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'weight_class'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'valid_weight_classes'}; {'id': '134', 'type': 'block', 'children': ['135']}; {'id': '135', 'type': 'raise_statement', 'children': ['136']}; {'id': '136', 'type': 'call', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '138', 'type': 'argument_list', 'children': ['139']}; {'id': '139', 'type': 'call', 'children': ['140', '143']}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}; {'id': '141', 'type': 'string', 'children': [], 'value': '"Invalid weight class: {0}. Possible values: {1!r}"'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '143', 'type': 'argument_list', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'weight_class'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'valid_weight_classes'}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}; {'id': '147', 'type': 'assignment', 'children': ['148', '151']}; {'id': '148', 'type': 'subscript', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '150', 'type': 'string', 'children': [], 'value': "'weight_class'"}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'weight_class'}; {'id': '152', 'type': 'if_statement', 'children': ['153', '156']}; {'id': '153', 'type': 'comparison_operator', 'children': ['154', '155'], 'value': 'is'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'following'}; {'id': '155', 'type': 'None', 'children': []}; {'id': '156', 'type': 'block', 'children': ['157']}; {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'assignment', 'children': ['159', '162']}; {'id': '159', 'type': 'subscript', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '161', 'type': 'string', 'children': [], 'value': "'following'"}; {'id': '162', 'type': 'call', 'children': ['163', '164']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'following'}; {'id': '166', 'type': 'if_statement', 'children': ['167', '170']}; {'id': '167', 'type': 'comparison_operator', 'children': ['168', '169'], 'value': 'is'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'club_id'}; {'id': '169', 'type': 'None', 'children': []}; {'id': '170', 'type': 'block', 'children': ['171']}; {'id': '171', 'type': 'expression_statement', 'children': ['172']}; {'id': '172', 'type': 'assignment', 'children': ['173', '176']}; {'id': '173', 'type': 'subscript', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '175', 'type': 'string', 'children': [], 'value': "'club_id'"}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'club_id'}; {'id': '177', 'type': 'if_statement', 'children': ['178', '181']}; {'id': '178', 'type': 'comparison_operator', 'children': ['179', '180'], 'value': 'is'}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'timeframe'}; {'id': '180', 'type': 'None', 'children': []}; {'id': '181', 'type': 'block', 'children': ['182', '190', '207']}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}; {'id': '183', 'type': 'assignment', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'valid_timeframes'}; {'id': '185', 'type': 'expression_list', 'children': ['186', '187', '188', '189']}; {'id': '186', 'type': 'string', 'children': [], 'value': "'this_year'"}; {'id': '187', 'type': 'string', 'children': [], 'value': "'this_month'"}; {'id': '188', 'type': 'string', 'children': [], 'value': "'this_week'"}; {'id': '189', 'type': 'string', 'children': [], 'value': "'today'"}; {'id': '190', 'type': 'if_statement', 'children': ['191', '195']}; {'id': '191', 'type': 'not_operator', 'children': ['192']}; {'id': '192', 'type': 'comparison_operator', 'children': ['193', '194'], 'value': 'in'}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'timeframe'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'valid_timeframes'}; {'id': '195', 'type': 'block', 'children': ['196']}; {'id': '196', 'type': 'raise_statement', 'children': ['197']}; {'id': '197', 'type': 'call', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '199', 'type': 'argument_list', 'children': ['200']}; {'id': '200', 'type': 'call', 'children': ['201', '204']}; {'id': '201', 'type': 'attribute', 'children': ['202', '203']}; {'id': '202', 'type': 'string', 'children': [], 'value': '"Invalid timeframe: {0}. Possible values: {1!r}"'}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '204', 'type': 'argument_list', 'children': ['205', '206']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'timeframe'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'valid_timeframes'}; {'id': '207', 'type': 'expression_statement', 'children': ['208']}; {'id': '208', 'type': 'assignment', 'children': ['209', '212']}; {'id': '209', 'type': 'subscript', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '211', 'type': 'string', 'children': [], 'value': "'date_range'"}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'timeframe'}; {'id': '213', 'type': 'if_statement', 'children': ['214', '217']}; {'id': '214', 'type': 'comparison_operator', 'children': ['215', '216'], 'value': 'is'}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'top_results_limit'}; {'id': '216', 'type': 'None', 'children': []}; {'id': '217', 'type': 'block', 'children': ['218']}; {'id': '218', 'type': 'expression_statement', 'children': ['219']}; {'id': '219', 'type': 'assignment', 'children': ['220', '223']}; {'id': '220', 'type': 'subscript', 'children': ['221', '222']}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '222', 'type': 'string', 'children': [], 'value': "'per_page'"}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'top_results_limit'}; {'id': '224', 'type': 'if_statement', 'children': ['225', '228']}; {'id': '225', 'type': 'comparison_operator', 'children': ['226', '227'], 'value': 'is'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '227', 'type': 'None', 'children': []}; {'id': '228', 'type': 'block', 'children': ['229']}; {'id': '229', 'type': 'expression_statement', 'children': ['230']}; {'id': '230', 'type': 'assignment', 'children': ['231', '234']}; {'id': '231', 'type': 'subscript', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '233', 'type': 'string', 'children': [], 'value': "'page'"}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '235', 'type': 'if_statement', 'children': ['236', '239']}; {'id': '236', 'type': 'comparison_operator', 'children': ['237', '238'], 'value': 'is'}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'context_entries'}; {'id': '238', 'type': 'None', 'children': []}; {'id': '239', 'type': 'block', 'children': ['240']}; {'id': '240', 'type': 'expression_statement', 'children': ['241']}; {'id': '241', 'type': 'assignment', 'children': ['242', '245']}; {'id': '242', 'type': 'subscript', 'children': ['243', '244']}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '244', 'type': 'string', 'children': [], 'value': "'context_entries'"}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'context_entries'}; {'id': '246', 'type': 'return_statement', 'children': ['247']}; {'id': '247', 'type': 'call', 'children': ['248', '253']}; {'id': '248', 'type': 'attribute', 'children': ['249', '252']}; {'id': '249', 'type': 'attribute', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'SegmentLeaderboard'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'deserialize'}; {'id': '253', 'type': 'argument_list', 'children': ['254', '267']}; {'id': '254', 'type': 'call', 'children': ['255', '260']}; {'id': '255', 'type': 'attribute', 'children': ['256', '259']}; {'id': '256', 'type': 'attribute', 'children': ['257', '258']}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'protocol'}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '260', 'type': 'argument_list', 'children': ['261', '262', '265']}; {'id': '261', 'type': 'string', 'children': [], 'value': "'/segments/{id}/leaderboard'"}; {'id': '262', 'type': 'keyword_argument', 'children': ['263', '264']}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'segment_id'}; {'id': '265', 'type': 'dictionary_splat', 'children': ['266']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '267', 'type': 'keyword_argument', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'bind_client'}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'self'}
def get_segment_leaderboard(self, segment_id, gender=None, age_group=None, weight_class=None, following=None, club_id=None, timeframe=None, top_results_limit=None, page=None, context_entries = None): params = {} if gender is not None: if gender.upper() not in ('M', 'F'): raise ValueError("Invalid gender: {0}. Possible values: 'M' or 'F'".format(gender)) params['gender'] = gender valid_age_groups = ('0_24', '25_34', '35_44', '45_54', '55_64', '65_plus') if age_group is not None: if not age_group in valid_age_groups: raise ValueError("Invalid age group: {0}. Possible values: {1!r}".format(age_group, valid_age_groups)) params['age_group'] = age_group valid_weight_classes = ('0_124', '125_149', '150_164', '165_179', '180_199', '200_plus', '0_54', '55_64', '65_74', '75_84', '85_94', '95_plus') if weight_class is not None: if not weight_class in valid_weight_classes: raise ValueError("Invalid weight class: {0}. Possible values: {1!r}".format(weight_class, valid_weight_classes)) params['weight_class'] = weight_class if following is not None: params['following'] = int(following) if club_id is not None: params['club_id'] = club_id if timeframe is not None: valid_timeframes = 'this_year', 'this_month', 'this_week', 'today' if not timeframe in valid_timeframes: raise ValueError("Invalid timeframe: {0}. Possible values: {1!r}".format(timeframe, valid_timeframes)) params['date_range'] = timeframe if top_results_limit is not None: params['per_page'] = top_results_limit if page is not None: params['page'] = page if context_entries is not None: params['context_entries'] = context_entries return model.SegmentLeaderboard.deserialize(self.protocol.get('/segments/{id}/leaderboard', id=segment_id, **params), bind_client=self)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_segment_efforts'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'segment_id'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'athlete_id'}; {'id': '8', 'type': 'None', 'children': []}; {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'start_date_local'}; {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'end_date_local'}; {'id': '14', 'type': 'None', 'children': []}; {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'block', 'children': ['19', '26', '37', '71', '105', '116', '132']}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '22', 'type': 'dictionary', 'children': ['23']}; {'id': '23', 'type': 'pair', 'children': ['24', '25']}; {'id': '24', 'type': 'string', 'children': [], 'value': '"segment_id"'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'segment_id'}; {'id': '26', 'type': 'if_statement', 'children': ['27', '30']}; {'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': 'is'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'athlete_id'}; {'id': '29', 'type': 'None', 'children': []}; {'id': '30', 'type': 'block', 'children': ['31']}; {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '36']}; {'id': '33', 'type': 'subscript', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '35', 'type': 'string', 'children': [], 'value': "'athlete_id'"}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'athlete_id'}; {'id': '37', 'type': 'if_statement', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'start_date_local'}; {'id': '39', 'type': 'block', 'children': ['40', '60']}; {'id': '40', 'type': 'if_statement', 'children': ['41', '48']}; {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '43', 'type': 'argument_list', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'start_date_local'}; {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'string_types'}; {'id': '48', 'type': 'block', 'children': ['49']}; {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'start_date_local'}; {'id': '52', 'type': 'attribute', 'children': ['53', '59']}; {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'arrow'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'start_date_local'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'naive'}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}; {'id': '61', 'type': 'assignment', 'children': ['62', '65']}; {'id': '62', 'type': 'subscript', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '64', 'type': 'string', 'children': [], 'value': '"start_date_local"'}; {'id': '65', 'type': 'call', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'start_date_local'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'strftime'}; {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'string', 'children': [], 'value': '"%Y-%m-%dT%H:%M:%SZ"'}; {'id': '71', 'type': 'if_statement', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'end_date_local'}; {'id': '73', 'type': 'block', 'children': ['74', '94']}; {'id': '74', 'type': 'if_statement', 'children': ['75', '82']}; {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '77', 'type': 'argument_list', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'end_date_local'}; {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'string_types'}; {'id': '82', 'type': 'block', 'children': ['83']}; {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'end_date_local'}; {'id': '86', 'type': 'attribute', 'children': ['87', '93']}; {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'arrow'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'end_date_local'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'naive'}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}; {'id': '95', 'type': 'assignment', 'children': ['96', '99']}; {'id': '96', 'type': 'subscript', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '98', 'type': 'string', 'children': [], 'value': '"end_date_local"'}; {'id': '99', 'type': 'call', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'end_date_local'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'strftime'}; {'id': '103', 'type': 'argument_list', 'children': ['104']}; {'id': '104', 'type': 'string', 'children': [], 'value': '"%Y-%m-%dT%H:%M:%SZ"'}; {'id': '105', 'type': 'if_statement', 'children': ['106', '109']}; {'id': '106', 'type': 'comparison_operator', 'children': ['107', '108'], 'value': 'is'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '108', 'type': 'None', 'children': []}; {'id': '109', 'type': 'block', 'children': ['110']}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}; {'id': '111', 'type': 'assignment', 'children': ['112', '115']}; {'id': '112', 'type': 'subscript', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '114', 'type': 'string', 'children': [], 'value': '"limit"'}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}; {'id': '117', 'type': 'assignment', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'result_fetcher'}; {'id': '119', 'type': 'call', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'functools'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'partial'}; {'id': '123', 'type': 'argument_list', 'children': ['124', '129', '130']}; {'id': '124', 'type': 'attribute', 'children': ['125', '128']}; {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'protocol'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '129', 'type': 'string', 'children': [], 'value': "'/segments/{segment_id}/all_efforts'"}; {'id': '130', 'type': 'dictionary_splat', 'children': ['131']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '132', 'type': 'return_statement', 'children': ['133']}; {'id': '133', 'type': 'call', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'BatchedResultsIterator'}; {'id': '135', 'type': 'argument_list', 'children': ['136', '141', '144', '147']}; {'id': '136', 'type': 'keyword_argument', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'BaseEffort'}; {'id': '141', 'type': 'keyword_argument', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'bind_client'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '144', 'type': 'keyword_argument', 'children': ['145', '146']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'result_fetcher'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'result_fetcher'}; {'id': '147', 'type': 'keyword_argument', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'limit'}
def get_segment_efforts(self, segment_id, athlete_id=None, start_date_local=None, end_date_local=None, limit=None): params = {"segment_id": segment_id} if athlete_id is not None: params['athlete_id'] = athlete_id if start_date_local: if isinstance(start_date_local, six.string_types): start_date_local = arrow.get(start_date_local).naive params["start_date_local"] = start_date_local.strftime("%Y-%m-%dT%H:%M:%SZ") if end_date_local: if isinstance(end_date_local, six.string_types): end_date_local = arrow.get(end_date_local).naive params["end_date_local"] = end_date_local.strftime("%Y-%m-%dT%H:%M:%SZ") if limit is not None: params["limit"] = limit result_fetcher = functools.partial(self.protocol.get, '/segments/{segment_id}/all_efforts', **params) return BatchedResultsIterator(entity=model.BaseEffort, bind_client=self, result_fetcher=result_fetcher, limit=limit)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'range'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'low'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'high'}; {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'with_scores'}; {'id': '9', 'type': 'False', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'desc'}; {'id': '12', 'type': 'False', 'children': []}; {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '15', 'type': 'False', 'children': []}; {'id': '16', 'type': 'block', 'children': ['17']}; {'id': '17', 'type': 'if_statement', 'children': ['18', '19', '34']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '19', 'type': 'block', 'children': ['20']}; {'id': '20', 'type': 'return_statement', 'children': ['21']}; {'id': '21', 'type': 'call', 'children': ['22', '27']}; {'id': '22', 'type': 'attribute', 'children': ['23', '26']}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'database'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'zrevrange'}; {'id': '27', 'type': 'argument_list', 'children': ['28', '31', '32', '33']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'low'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'high'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'with_scores'}; {'id': '34', 'type': 'else_clause', 'children': ['35']}; {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'return_statement', 'children': ['37']}; {'id': '37', 'type': 'call', 'children': ['38', '43']}; {'id': '38', 'type': 'attribute', 'children': ['39', '42']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'database'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'zrange'}; {'id': '43', 'type': 'argument_list', 'children': ['44', '47', '48', '49', '50']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'low'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'high'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'desc'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'with_scores'}
def range(self, low, high, with_scores=False, desc=False, reverse=False): if reverse: return self.database.zrevrange(self.key, low, high, with_scores) else: return self.database.zrange(self.key, low, high, desc, with_scores)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sfiles_to_event'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'sfile_list'}; {'id': '5', 'type': 'block', 'children': ['6', '10', '29', '43', '53', '59', '87', '92']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'event_list'}; {'id': '9', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}; {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'sort_list'}; {'id': '13', 'type': 'list_comprehension', 'children': ['14', '26']}; {'id': '14', 'type': 'tuple', 'children': ['15', '25']}; {'id': '15', 'type': 'attribute', 'children': ['16', '24']}; {'id': '16', 'type': 'subscript', 'children': ['17', '23']}; {'id': '17', 'type': 'attribute', 'children': ['18', '22']}; {'id': '18', 'type': 'call', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'readheader'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'sfile'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'origins'}; {'id': '23', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'sfile'}; {'id': '26', 'type': 'for_in_clause', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'sfile'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'sfile_list'}; {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '34']}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'sort_list'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}; {'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '37', 'type': 'lambda', 'children': ['38', '40']}; {'id': '38', 'type': 'lambda_parameters', 'children': ['39']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'tup'}; {'id': '40', 'type': 'subscript', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'tup'}; {'id': '42', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'sfile_list'}; {'id': '46', 'type': 'list_comprehension', 'children': ['47', '50']}; {'id': '47', 'type': 'subscript', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'sfile'}; {'id': '49', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '50', 'type': 'for_in_clause', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'sfile'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'sort_list'}; {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'catalog'}; {'id': '56', 'type': 'call', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'Catalog'}; {'id': '58', 'type': 'argument_list', 'children': []}; {'id': '59', 'type': 'for_statement', 'children': ['60', '63', '67']}; {'id': '60', 'type': 'pattern_list', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'sfile'}; {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'sfile_list'}; {'id': '67', 'type': 'block', 'children': ['68', '77']}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}; {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'event_list'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'tuple', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'sfile'}; {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '82']}; {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'catalog'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}; {'id': '83', 'type': 'call', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'readheader'}; {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'sfile'}; {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'call', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'write_event'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'catalog'}; {'id': '92', 'type': 'return_statement', 'children': ['93']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'event_list'}
def sfiles_to_event(sfile_list): event_list = [] sort_list = [(readheader(sfile).origins[0].time, sfile) for sfile in sfile_list] sort_list.sort(key=lambda tup: tup[0]) sfile_list = [sfile[1] for sfile in sort_list] catalog = Catalog() for i, sfile in enumerate(sfile_list): event_list.append((i, sfile)) catalog.append(readheader(sfile)) write_event(catalog) return event_list
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '24']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'call', 'children': ['8', '13']}; {'id': '8', 'type': 'attribute', 'children': ['9', '12']}; {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'families'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'keyword_argument', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '16', 'type': 'lambda', 'children': ['17', '19']}; {'id': '17', 'type': 'lambda_parameters', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '19', 'type': 'attribute', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'template'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '24', 'type': 'return_statement', 'children': ['25']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}
def sort(self): self.families.sort(key=lambda x: x.template.name) return self
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'decluster'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'trig_int'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'timing'}; {'id': '8', 'type': 'string', 'children': [], 'value': "'detect'"}; {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'metric'}; {'id': '11', 'type': 'string', 'children': [], 'value': "'avg_cor'"}; {'id': '12', 'type': 'block', 'children': ['13', '17', '32', '157', '172', '187', '210', '229', '233', '283', '299', '303', '354', '360']}; {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'all_detections'}; {'id': '16', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '17', 'type': 'for_statement', 'children': ['18', '19', '22']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'fam'}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'families'}; {'id': '22', 'type': 'block', 'children': ['23']}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '28']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'all_detections'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'fam'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'detections'}; {'id': '32', 'type': 'if_statement', 'children': ['33', '36', '86', '150']}; {'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': '=='}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'timing'}; {'id': '35', 'type': 'string', 'children': [], 'value': "'detect'"}; {'id': '36', 'type': 'block', 'children': ['37']}; {'id': '37', 'type': 'if_statement', 'children': ['38', '41', '60', '79']}; {'id': '38', 'type': 'comparison_operator', 'children': ['39', '40'], 'value': '=='}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'metric'}; {'id': '40', 'type': 'string', 'children': [], 'value': "'avg_cor'"}; {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}; {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'detect_info'}; {'id': '45', 'type': 'list_comprehension', 'children': ['46', '57']}; {'id': '46', 'type': 'tuple', 'children': ['47', '50']}; {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'detect_time'}; {'id': '50', 'type': 'binary_operator', 'children': ['51', '54'], 'value': '/'}; {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'detect_val'}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'no_chans'}; {'id': '57', 'type': 'for_in_clause', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'all_detections'}; {'id': '60', 'type': 'elif_clause', 'children': ['61', '64']}; {'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': '=='}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'metric'}; {'id': '63', 'type': 'string', 'children': [], 'value': "'cor_sum'"}; {'id': '64', 'type': 'block', 'children': ['65']}; {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'detect_info'}; {'id': '68', 'type': 'list_comprehension', 'children': ['69', '76']}; {'id': '69', 'type': 'tuple', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'detect_time'}; {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'detect_val'}; {'id': '76', 'type': 'for_in_clause', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'all_detections'}; {'id': '79', 'type': 'else_clause', 'children': ['80']}; {'id': '80', 'type': 'block', 'children': ['81']}; {'id': '81', 'type': 'raise_statement', 'children': ['82']}; {'id': '82', 'type': 'call', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'MatchFilterError'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}; {'id': '85', 'type': 'string', 'children': [], 'value': "'metric is not cor_sum or avg_cor'"}; {'id': '86', 'type': 'elif_clause', 'children': ['87', '90']}; {'id': '87', 'type': 'comparison_operator', 'children': ['88', '89'], 'value': '=='}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'timing'}; {'id': '89', 'type': 'string', 'children': [], 'value': "'origin'"}; {'id': '90', 'type': 'block', 'children': ['91']}; {'id': '91', 'type': 'if_statement', 'children': ['92', '95', '119', '143']}; {'id': '92', 'type': 'comparison_operator', 'children': ['93', '94'], 'value': '=='}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'metric'}; {'id': '94', 'type': 'string', 'children': [], 'value': "'avg_cor'"}; {'id': '95', 'type': 'block', 'children': ['96']}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}; {'id': '97', 'type': 'assignment', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'detect_info'}; {'id': '99', 'type': 'list_comprehension', 'children': ['100', '116']}; {'id': '100', 'type': 'tuple', 'children': ['101', '109']}; {'id': '101', 'type': 'attribute', 'children': ['102', '108']}; {'id': '102', 'type': 'call', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': '_get_origin'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}; {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '109', 'type': 'binary_operator', 'children': ['110', '113'], 'value': '/'}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'detect_val'}; {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'no_chans'}; {'id': '116', 'type': 'for_in_clause', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'all_detections'}; {'id': '119', 'type': 'elif_clause', 'children': ['120', '123']}; {'id': '120', 'type': 'comparison_operator', 'children': ['121', '122'], 'value': '=='}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'metric'}; {'id': '122', 'type': 'string', 'children': [], 'value': "'cor_sum'"}; {'id': '123', 'type': 'block', 'children': ['124']}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}; {'id': '125', 'type': 'assignment', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'detect_info'}; {'id': '127', 'type': 'list_comprehension', 'children': ['128', '140']}; {'id': '128', 'type': 'tuple', 'children': ['129', '137']}; {'id': '129', 'type': 'attribute', 'children': ['130', '136']}; {'id': '130', 'type': 'call', 'children': ['131', '132']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': '_get_origin'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}; {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'detect_val'}; {'id': '140', 'type': 'for_in_clause', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'all_detections'}; {'id': '143', 'type': 'else_clause', 'children': ['144']}; {'id': '144', 'type': 'block', 'children': ['145']}; {'id': '145', 'type': 'raise_statement', 'children': ['146']}; {'id': '146', 'type': 'call', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'MatchFilterError'}; {'id': '148', 'type': 'argument_list', 'children': ['149']}; {'id': '149', 'type': 'string', 'children': [], 'value': "'metric is not cor_sum or avg_cor'"}; {'id': '150', 'type': 'else_clause', 'children': ['151']}; {'id': '151', 'type': 'block', 'children': ['152']}; {'id': '152', 'type': 'raise_statement', 'children': ['153']}; {'id': '153', 'type': 'call', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'MatchFilterError'}; {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'string', 'children': [], 'value': "'timing is not detect or origin'"}; {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'assignment', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'min_det'}; {'id': '160', 'type': 'subscript', 'children': ['161', '171']}; {'id': '161', 'type': 'call', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '163', 'type': 'argument_list', 'children': ['164']}; {'id': '164', 'type': 'list_comprehension', 'children': ['165', '168']}; {'id': '165', 'type': 'subscript', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '167', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '168', 'type': 'for_in_clause', 'children': ['169', '170']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'detect_info'}; {'id': '171', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}; {'id': '173', 'type': 'assignment', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'detect_vals'}; {'id': '175', 'type': 'call', 'children': ['176', '179']}; {'id': '176', 'type': 'attribute', 'children': ['177', '178']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '179', 'type': 'argument_list', 'children': ['180']}; {'id': '180', 'type': 'list_comprehension', 'children': ['181', '184']}; {'id': '181', 'type': 'subscript', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '183', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '184', 'type': 'for_in_clause', 'children': ['185', '186']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'detect_info'}; {'id': '187', 'type': 'expression_statement', 'children': ['188']}; {'id': '188', 'type': 'assignment', 'children': ['189', '190']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'detect_times'}; {'id': '190', 'type': 'call', 'children': ['191', '194']}; {'id': '191', 'type': 'attribute', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '194', 'type': 'argument_list', 'children': ['195']}; {'id': '195', 'type': 'list_comprehension', 'children': ['196', '207']}; {'id': '196', 'type': 'call', 'children': ['197', '198']}; {'id': '197', 'type': 'identifier', 'children': [], 'value': '_total_microsec'}; {'id': '198', 'type': 'argument_list', 'children': ['199', '204']}; {'id': '199', 'type': 'attribute', 'children': ['200', '203']}; {'id': '200', 'type': 'subscript', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '202', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'min_det'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '207', 'type': 'for_in_clause', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'detect_info'}; {'id': '210', 'type': 'expression_statement', 'children': ['211']}; {'id': '211', 'type': 'assignment', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'peaks_out'}; {'id': '213', 'type': 'call', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'decluster'}; {'id': '215', 'type': 'argument_list', 'children': ['216', '219', '222']}; {'id': '216', 'type': 'keyword_argument', 'children': ['217', '218']}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'peaks'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'detect_vals'}; {'id': '219', 'type': 'keyword_argument', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'detect_times'}; {'id': '222', 'type': 'keyword_argument', 'children': ['223', '224']}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'trig_int'}; {'id': '224', 'type': 'binary_operator', 'children': ['225', '226'], 'value': '*'}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'trig_int'}; {'id': '226', 'type': 'binary_operator', 'children': ['227', '228'], 'value': '**'}; {'id': '227', 'type': 'integer', 'children': [], 'value': '10'}; {'id': '228', 'type': 'integer', 'children': [], 'value': '6'}; {'id': '229', 'type': 'expression_statement', 'children': ['230']}; {'id': '230', 'type': 'assignment', 'children': ['231', '232']}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'declustered_detections'}; {'id': '232', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '233', 'type': 'for_statement', 'children': ['234', '235', '236']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'ind'}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'peaks_out'}; {'id': '236', 'type': 'block', 'children': ['237', '253', '274']}; {'id': '237', 'type': 'expression_statement', 'children': ['238']}; {'id': '238', 'type': 'assignment', 'children': ['239', '240']}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'matching_time_indeces'}; {'id': '240', 'type': 'subscript', 'children': ['241', '252']}; {'id': '241', 'type': 'call', 'children': ['242', '245']}; {'id': '242', 'type': 'attribute', 'children': ['243', '244']}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'where'}; {'id': '245', 'type': 'argument_list', 'children': ['246']}; {'id': '246', 'type': 'comparison_operator', 'children': ['247', '248'], 'value': '=='}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'detect_times'}; {'id': '248', 'type': 'subscript', 'children': ['249', '250']}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'ind'}; {'id': '250', 'type': 'unary_operator', 'children': ['251'], 'value': '-'}; {'id': '251', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '252', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '253', 'type': 'expression_statement', 'children': ['254']}; {'id': '254', 'type': 'assignment', 'children': ['255', '256']}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'matches'}; {'id': '256', 'type': 'subscript', 'children': ['257', '258']}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'matching_time_indeces'}; {'id': '258', 'type': 'subscript', 'children': ['259', '273']}; {'id': '259', 'type': 'subscript', 'children': ['260', '272']}; {'id': '260', 'type': 'call', 'children': ['261', '264']}; {'id': '261', 'type': 'attribute', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'where'}; {'id': '264', 'type': 'argument_list', 'children': ['265']}; {'id': '265', 'type': 'comparison_operator', 'children': ['266', '269'], 'value': '=='}; {'id': '266', 'type': 'subscript', 'children': ['267', '268']}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'detect_vals'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'matching_time_indeces'}; {'id': '269', 'type': 'subscript', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'ind'}; {'id': '271', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '272', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '273', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '274', 'type': 'expression_statement', 'children': ['275']}; {'id': '275', 'type': 'call', 'children': ['276', '279']}; {'id': '276', 'type': 'attribute', 'children': ['277', '278']}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'declustered_detections'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '279', 'type': 'argument_list', 'children': ['280']}; {'id': '280', 'type': 'subscript', 'children': ['281', '282']}; {'id': '281', 'type': 'identifier', 'children': [], 'value': 'all_detections'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'matches'}; {'id': '283', 'type': 'expression_statement', 'children': ['284']}; {'id': '284', 'type': 'assignment', 'children': ['285', '286']}; {'id': '285', 'type': 'identifier', 'children': [], 'value': 'template_names'}; {'id': '286', 'type': 'call', 'children': ['287', '288']}; {'id': '287', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '288', 'type': 'argument_list', 'children': ['289']}; {'id': '289', 'type': 'call', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '291', 'type': 'argument_list', 'children': ['292']}; {'id': '292', 'type': 'list_comprehension', 'children': ['293', '296']}; {'id': '293', 'type': 'attribute', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '295', 'type': 'identifier', 'children': [], 'value': 'template_name'}; {'id': '296', 'type': 'for_in_clause', 'children': ['297', '298']}; {'id': '297', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'declustered_detections'}; {'id': '299', 'type': 'expression_statement', 'children': ['300']}; {'id': '300', 'type': 'assignment', 'children': ['301', '302']}; {'id': '301', 'type': 'identifier', 'children': [], 'value': 'new_families'}; {'id': '302', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '303', 'type': 'for_statement', 'children': ['304', '305', '306']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'template_name'}; {'id': '305', 'type': 'identifier', 'children': [], 'value': 'template_names'}; {'id': '306', 'type': 'block', 'children': ['307', '329']}; {'id': '307', 'type': 'expression_statement', 'children': ['308']}; {'id': '308', 'type': 'assignment', 'children': ['309', '310']}; {'id': '309', 'type': 'identifier', 'children': [], 'value': 'template'}; {'id': '310', 'type': 'subscript', 'children': ['311', '328']}; {'id': '311', 'type': 'list_comprehension', 'children': ['312', '315', '320']}; {'id': '312', 'type': 'attribute', 'children': ['313', '314']}; {'id': '313', 'type': 'identifier', 'children': [], 'value': 'fam'}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'template'}; {'id': '315', 'type': 'for_in_clause', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'fam'}; {'id': '317', 'type': 'attribute', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '319', 'type': 'identifier', 'children': [], 'value': 'families'}; {'id': '320', 'type': 'if_clause', 'children': ['321']}; {'id': '321', 'type': 'comparison_operator', 'children': ['322', '327'], 'value': '=='}; {'id': '322', 'type': 'attribute', 'children': ['323', '326']}; {'id': '323', 'type': 'attribute', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'fam'}; {'id': '325', 'type': 'identifier', 'children': [], 'value': 'template'}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '327', 'type': 'identifier', 'children': [], 'value': 'template_name'}; {'id': '328', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '329', 'type': 'expression_statement', 'children': ['330']}; {'id': '330', 'type': 'call', 'children': ['331', '334']}; {'id': '331', 'type': 'attribute', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'new_families'}; {'id': '333', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '334', 'type': 'argument_list', 'children': ['335']}; {'id': '335', 'type': 'call', 'children': ['336', '337']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'Family'}; {'id': '337', 'type': 'argument_list', 'children': ['338', '341']}; {'id': '338', 'type': 'keyword_argument', 'children': ['339', '340']}; {'id': '339', 'type': 'identifier', 'children': [], 'value': 'template'}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'template'}; {'id': '341', 'type': 'keyword_argument', 'children': ['342', '343']}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'detections'}; {'id': '343', 'type': 'list_comprehension', 'children': ['344', '345', '348']}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '345', 'type': 'for_in_clause', 'children': ['346', '347']}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '347', 'type': 'identifier', 'children': [], 'value': 'declustered_detections'}; {'id': '348', 'type': 'if_clause', 'children': ['349']}; {'id': '349', 'type': 'comparison_operator', 'children': ['350', '353'], 'value': '=='}; {'id': '350', 'type': 'attribute', 'children': ['351', '352']}; {'id': '351', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'template_name'}; {'id': '353', 'type': 'identifier', 'children': [], 'value': 'template_name'}; {'id': '354', 'type': 'expression_statement', 'children': ['355']}; {'id': '355', 'type': 'assignment', 'children': ['356', '359']}; {'id': '356', 'type': 'attribute', 'children': ['357', '358']}; {'id': '357', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'families'}; {'id': '359', 'type': 'identifier', 'children': [], 'value': 'new_families'}; {'id': '360', 'type': 'return_statement', 'children': ['361']}; {'id': '361', 'type': 'identifier', 'children': [], 'value': 'self'}
def decluster(self, trig_int, timing='detect', metric='avg_cor'): all_detections = [] for fam in self.families: all_detections.extend(fam.detections) if timing == 'detect': if metric == 'avg_cor': detect_info = [(d.detect_time, d.detect_val / d.no_chans) for d in all_detections] elif metric == 'cor_sum': detect_info = [(d.detect_time, d.detect_val) for d in all_detections] else: raise MatchFilterError('metric is not cor_sum or avg_cor') elif timing == 'origin': if metric == 'avg_cor': detect_info = [(_get_origin(d.event).time, d.detect_val / d.no_chans) for d in all_detections] elif metric == 'cor_sum': detect_info = [(_get_origin(d.event).time, d.detect_val) for d in all_detections] else: raise MatchFilterError('metric is not cor_sum or avg_cor') else: raise MatchFilterError('timing is not detect or origin') min_det = sorted([d[0] for d in detect_info])[0] detect_vals = np.array([d[1] for d in detect_info]) detect_times = np.array([ _total_microsec(d[0].datetime, min_det.datetime) for d in detect_info]) peaks_out = decluster( peaks=detect_vals, index=detect_times, trig_int=trig_int * 10 ** 6) declustered_detections = [] for ind in peaks_out: matching_time_indeces = np.where(detect_times == ind[-1])[0] matches = matching_time_indeces[ np.where(detect_vals[matching_time_indeces] == ind[0])[0][0]] declustered_detections.append(all_detections[matches]) template_names = list(set([d.template_name for d in declustered_detections])) new_families = [] for template_name in template_names: template = [fam.template for fam in self.families if fam.template.name == template_name][0] new_families.append(Family( template=template, detections=[d for d in declustered_detections if d.template_name == template_name])) self.families = new_families return self
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '25']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '11']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'detections'}; {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '13', 'type': 'argument_list', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'detections'}; {'id': '17', 'type': 'keyword_argument', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '19', 'type': 'lambda', 'children': ['20', '22']}; {'id': '20', 'type': 'lambda_parameters', 'children': ['21']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'detect_time'}; {'id': '25', 'type': 'return_statement', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}
def sort(self): self.detections = sorted(self.detections, key=lambda d: d.detect_time) return self
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '25']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '11']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'templates'}; {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '13', 'type': 'argument_list', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'templates'}; {'id': '17', 'type': 'keyword_argument', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '19', 'type': 'lambda', 'children': ['20', '22']}; {'id': '20', 'type': 'lambda_parameters', 'children': ['21']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '25', 'type': 'return_statement', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}
def sort(self): self.templates = sorted(self.templates, key=lambda x: x.name) return self
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '23']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'filter_picks'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'catalog'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'stations'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'channels'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'networks'}; {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'locations'}; {'id': '16', 'type': 'None', 'children': []}; {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'top_n_picks'}; {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'evaluation_mode'}; {'id': '22', 'type': 'string', 'children': [], 'value': "'all'"}; {'id': '23', 'type': 'block', 'children': ['24', '32', '70', '108', '146', '184', '252', '421', '427', '448']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}; {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'filtered_catalog'}; {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'catalog'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '31', 'type': 'argument_list', 'children': []}; {'id': '32', 'type': 'if_statement', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'stations'}; {'id': '34', 'type': 'block', 'children': ['35']}; {'id': '35', 'type': 'for_statement', 'children': ['36', '37', '38']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'filtered_catalog'}; {'id': '38', 'type': 'block', 'children': ['39', '50']}; {'id': '39', 'type': 'if_statement', 'children': ['40', '48']}; {'id': '40', 'type': 'comparison_operator', 'children': ['41', '47'], 'value': '=='}; {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'picks'}; {'id': '47', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '48', 'type': 'block', 'children': ['49']}; {'id': '49', 'type': 'continue_statement', 'children': []}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}; {'id': '51', 'type': 'assignment', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'picks'}; {'id': '55', 'type': 'list_comprehension', 'children': ['56', '57', '62']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'pick'}; {'id': '57', 'type': 'for_in_clause', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'pick'}; {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'picks'}; {'id': '62', 'type': 'if_clause', 'children': ['63']}; {'id': '63', 'type': 'comparison_operator', 'children': ['64', '69'], 'value': 'in'}; {'id': '64', 'type': 'attribute', 'children': ['65', '68']}; {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'pick'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'waveform_id'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'station_code'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'stations'}; {'id': '70', 'type': 'if_statement', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'channels'}; {'id': '72', 'type': 'block', 'children': ['73']}; {'id': '73', 'type': 'for_statement', 'children': ['74', '75', '76']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'filtered_catalog'}; {'id': '76', 'type': 'block', 'children': ['77', '88']}; {'id': '77', 'type': 'if_statement', 'children': ['78', '86']}; {'id': '78', 'type': 'comparison_operator', 'children': ['79', '85'], 'value': '=='}; {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'picks'}; {'id': '85', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '86', 'type': 'block', 'children': ['87']}; {'id': '87', 'type': 'continue_statement', 'children': []}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}; {'id': '89', 'type': 'assignment', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'picks'}; {'id': '93', 'type': 'list_comprehension', 'children': ['94', '95', '100']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'pick'}; {'id': '95', 'type': 'for_in_clause', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'pick'}; {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'picks'}; {'id': '100', 'type': 'if_clause', 'children': ['101']}; {'id': '101', 'type': 'comparison_operator', 'children': ['102', '107'], 'value': 'in'}; {'id': '102', 'type': 'attribute', 'children': ['103', '106']}; {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'pick'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'waveform_id'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'channel_code'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'channels'}; {'id': '108', 'type': 'if_statement', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'networks'}; {'id': '110', 'type': 'block', 'children': ['111']}; {'id': '111', 'type': 'for_statement', 'children': ['112', '113', '114']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'filtered_catalog'}; {'id': '114', 'type': 'block', 'children': ['115', '126']}; {'id': '115', 'type': 'if_statement', 'children': ['116', '124']}; {'id': '116', 'type': 'comparison_operator', 'children': ['117', '123'], 'value': '=='}; {'id': '117', 'type': 'call', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'picks'}; {'id': '123', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '124', 'type': 'block', 'children': ['125']}; {'id': '125', 'type': 'continue_statement', 'children': []}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}; {'id': '127', 'type': 'assignment', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'picks'}; {'id': '131', 'type': 'list_comprehension', 'children': ['132', '133', '138']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'pick'}; {'id': '133', 'type': 'for_in_clause', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'pick'}; {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'picks'}; {'id': '138', 'type': 'if_clause', 'children': ['139']}; {'id': '139', 'type': 'comparison_operator', 'children': ['140', '145'], 'value': 'in'}; {'id': '140', 'type': 'attribute', 'children': ['141', '144']}; {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'pick'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'waveform_id'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'network_code'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'networks'}; {'id': '146', 'type': 'if_statement', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'locations'}; {'id': '148', 'type': 'block', 'children': ['149']}; {'id': '149', 'type': 'for_statement', 'children': ['150', '151', '152']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'filtered_catalog'}; {'id': '152', 'type': 'block', 'children': ['153', '164']}; {'id': '153', 'type': 'if_statement', 'children': ['154', '162']}; {'id': '154', 'type': 'comparison_operator', 'children': ['155', '161'], 'value': '=='}; {'id': '155', 'type': 'call', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '157', 'type': 'argument_list', 'children': ['158']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'picks'}; {'id': '161', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '162', 'type': 'block', 'children': ['163']}; {'id': '163', 'type': 'continue_statement', 'children': []}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}; {'id': '165', 'type': 'assignment', 'children': ['166', '169']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'picks'}; {'id': '169', 'type': 'list_comprehension', 'children': ['170', '171', '176']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'pick'}; {'id': '171', 'type': 'for_in_clause', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'pick'}; {'id': '173', 'type': 'attribute', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'picks'}; {'id': '176', 'type': 'if_clause', 'children': ['177']}; {'id': '177', 'type': 'comparison_operator', 'children': ['178', '183'], 'value': 'in'}; {'id': '178', 'type': 'attribute', 'children': ['179', '182']}; {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'pick'}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'waveform_id'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'location_code'}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'locations'}; {'id': '184', 'type': 'if_statement', 'children': ['185', '188', '211', '238']}; {'id': '185', 'type': 'comparison_operator', 'children': ['186', '187'], 'value': '=='}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'evaluation_mode'}; {'id': '187', 'type': 'string', 'children': [], 'value': "'manual'"}; {'id': '188', 'type': 'block', 'children': ['189']}; {'id': '189', 'type': 'for_statement', 'children': ['190', '191', '192']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'filtered_catalog'}; {'id': '192', 'type': 'block', 'children': ['193']}; {'id': '193', 'type': 'expression_statement', 'children': ['194']}; {'id': '194', 'type': 'assignment', 'children': ['195', '198']}; {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'picks'}; {'id': '198', 'type': 'list_comprehension', 'children': ['199', '200', '205']}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'pick'}; {'id': '200', 'type': 'for_in_clause', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'pick'}; {'id': '202', 'type': 'attribute', 'children': ['203', '204']}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'picks'}; {'id': '205', 'type': 'if_clause', 'children': ['206']}; {'id': '206', 'type': 'comparison_operator', 'children': ['207', '210'], 'value': '=='}; {'id': '207', 'type': 'attribute', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'pick'}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'evaluation_mode'}; {'id': '210', 'type': 'string', 'children': [], 'value': "'manual'"}; {'id': '211', 'type': 'elif_clause', 'children': ['212', '215']}; {'id': '212', 'type': 'comparison_operator', 'children': ['213', '214'], 'value': '=='}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'evaluation_mode'}; {'id': '214', 'type': 'string', 'children': [], 'value': "'automatic'"}; {'id': '215', 'type': 'block', 'children': ['216']}; {'id': '216', 'type': 'for_statement', 'children': ['217', '218', '219']}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'filtered_catalog'}; {'id': '219', 'type': 'block', 'children': ['220']}; {'id': '220', 'type': 'expression_statement', 'children': ['221']}; {'id': '221', 'type': 'assignment', 'children': ['222', '225']}; {'id': '222', 'type': 'attribute', 'children': ['223', '224']}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'picks'}; {'id': '225', 'type': 'list_comprehension', 'children': ['226', '227', '232']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'pick'}; {'id': '227', 'type': 'for_in_clause', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'pick'}; {'id': '229', 'type': 'attribute', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'picks'}; {'id': '232', 'type': 'if_clause', 'children': ['233']}; {'id': '233', 'type': 'comparison_operator', 'children': ['234', '237'], 'value': '=='}; {'id': '234', 'type': 'attribute', 'children': ['235', '236']}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'pick'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'evaluation_mode'}; {'id': '237', 'type': 'string', 'children': [], 'value': "'automatic'"}; {'id': '238', 'type': 'elif_clause', 'children': ['239', '242']}; {'id': '239', 'type': 'comparison_operator', 'children': ['240', '241'], 'value': '!='}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'evaluation_mode'}; {'id': '241', 'type': 'string', 'children': [], 'value': "'all'"}; {'id': '242', 'type': 'block', 'children': ['243']}; {'id': '243', 'type': 'expression_statement', 'children': ['244']}; {'id': '244', 'type': 'call', 'children': ['245', '248']}; {'id': '245', 'type': 'attribute', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'warnings'}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'warn'}; {'id': '248', 'type': 'argument_list', 'children': ['249']}; {'id': '249', 'type': 'binary_operator', 'children': ['250', '251'], 'value': '%'}; {'id': '250', 'type': 'string', 'children': [], 'value': "'Unrecognised evaluation_mode: %s, using all picks'"}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'evaluation_mode'}; {'id': '252', 'type': 'if_statement', 'children': ['253', '254']}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'top_n_picks'}; {'id': '254', 'type': 'block', 'children': ['255', '259', '283', '294', '298', '380']}; {'id': '255', 'type': 'expression_statement', 'children': ['256']}; {'id': '256', 'type': 'assignment', 'children': ['257', '258']}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'all_picks'}; {'id': '258', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '259', 'type': 'for_statement', 'children': ['260', '261', '262']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'filtered_catalog'}; {'id': '262', 'type': 'block', 'children': ['263']}; {'id': '263', 'type': 'expression_statement', 'children': ['264']}; {'id': '264', 'type': 'augmented_assignment', 'children': ['265', '266'], 'value': '+='}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'all_picks'}; {'id': '266', 'type': 'list_comprehension', 'children': ['267', '278']}; {'id': '267', 'type': 'tuple', 'children': ['268', '273']}; {'id': '268', 'type': 'attribute', 'children': ['269', '272']}; {'id': '269', 'type': 'attribute', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'pick'}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'waveform_id'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'station_code'}; {'id': '273', 'type': 'attribute', 'children': ['274', '277']}; {'id': '274', 'type': 'attribute', 'children': ['275', '276']}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'pick'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'waveform_id'}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'channel_code'}; {'id': '278', 'type': 'for_in_clause', 'children': ['279', '280']}; {'id': '279', 'type': 'identifier', 'children': [], 'value': 'pick'}; {'id': '280', 'type': 'attribute', 'children': ['281', '282']}; {'id': '281', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'picks'}; {'id': '283', 'type': 'expression_statement', 'children': ['284']}; {'id': '284', 'type': 'assignment', 'children': ['285', '286']}; {'id': '285', 'type': 'identifier', 'children': [], 'value': 'counted'}; {'id': '286', 'type': 'call', 'children': ['287', '293']}; {'id': '287', 'type': 'attribute', 'children': ['288', '292']}; {'id': '288', 'type': 'call', 'children': ['289', '290']}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'Counter'}; {'id': '290', 'type': 'argument_list', 'children': ['291']}; {'id': '291', 'type': 'identifier', 'children': [], 'value': 'all_picks'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'most_common'}; {'id': '293', 'type': 'argument_list', 'children': []}; {'id': '294', 'type': 'expression_statement', 'children': ['295']}; {'id': '295', 'type': 'assignment', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'all_picks'}; {'id': '297', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '298', 'type': 'for_statement', 'children': ['299', '300', '308']}; {'id': '299', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '300', 'type': 'call', 'children': ['301', '302']}; {'id': '301', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '302', 'type': 'argument_list', 'children': ['303']}; {'id': '303', 'type': 'subscript', 'children': ['304', '307']}; {'id': '304', 'type': 'subscript', 'children': ['305', '306']}; {'id': '305', 'type': 'identifier', 'children': [], 'value': 'counted'}; {'id': '306', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '307', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '308', 'type': 'block', 'children': ['309', '331', '346', '362']}; {'id': '309', 'type': 'expression_statement', 'children': ['310']}; {'id': '310', 'type': 'assignment', 'children': ['311', '312']}; {'id': '311', 'type': 'identifier', 'children': [], 'value': 'highest'}; {'id': '312', 'type': 'list_comprehension', 'children': ['313', '316', '319']}; {'id': '313', 'type': 'subscript', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '315', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '316', 'type': 'for_in_clause', 'children': ['317', '318']}; {'id': '317', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'counted'}; {'id': '319', 'type': 'if_clause', 'children': ['320']}; {'id': '320', 'type': 'comparison_operator', 'children': ['321', '324'], 'value': '>='}; {'id': '321', 'type': 'subscript', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '323', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '324', 'type': 'binary_operator', 'children': ['325', '330'], 'value': '-'}; {'id': '325', 'type': 'subscript', 'children': ['326', '329']}; {'id': '326', 'type': 'subscript', 'children': ['327', '328']}; {'id': '327', 'type': 'identifier', 'children': [], 'value': 'counted'}; {'id': '328', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '329', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '331', 'type': 'expression_statement', 'children': ['332']}; {'id': '332', 'type': 'assignment', 'children': ['333', '334']}; {'id': '333', 'type': 'identifier', 'children': [], 'value': 'highest'}; {'id': '334', 'type': 'call', 'children': ['335', '336']}; {'id': '335', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '336', 'type': 'argument_list', 'children': ['337', '338']}; {'id': '337', 'type': 'identifier', 'children': [], 'value': 'highest'}; {'id': '338', 'type': 'keyword_argument', 'children': ['339', '340']}; {'id': '339', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '340', 'type': 'lambda', 'children': ['341', '343']}; {'id': '341', 'type': 'lambda_parameters', 'children': ['342']}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'tup'}; {'id': '343', 'type': 'subscript', 'children': ['344', '345']}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'tup'}; {'id': '345', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '346', 'type': 'for_statement', 'children': ['347', '348', '349']}; {'id': '347', 'type': 'identifier', 'children': [], 'value': 'stachan'}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'highest'}; {'id': '349', 'type': 'block', 'children': ['350']}; {'id': '350', 'type': 'if_statement', 'children': ['351', '354']}; {'id': '351', 'type': 'comparison_operator', 'children': ['352', '353'], 'value': 'not'}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'stachan'}; {'id': '353', 'type': 'identifier', 'children': [], 'value': 'all_picks'}; {'id': '354', 'type': 'block', 'children': ['355']}; {'id': '355', 'type': 'expression_statement', 'children': ['356']}; {'id': '356', 'type': 'call', 'children': ['357', '360']}; {'id': '357', 'type': 'attribute', 'children': ['358', '359']}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'all_picks'}; {'id': '359', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '360', 'type': 'argument_list', 'children': ['361']}; {'id': '361', 'type': 'identifier', 'children': [], 'value': 'stachan'}; {'id': '362', 'type': 'if_statement', 'children': ['363', '369']}; {'id': '363', 'type': 'comparison_operator', 'children': ['364', '368'], 'value': '>'}; {'id': '364', 'type': 'call', 'children': ['365', '366']}; {'id': '365', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '366', 'type': 'argument_list', 'children': ['367']}; {'id': '367', 'type': 'identifier', 'children': [], 'value': 'all_picks'}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'top_n_picks'}; {'id': '369', 'type': 'block', 'children': ['370', '379']}; {'id': '370', 'type': 'expression_statement', 'children': ['371']}; {'id': '371', 'type': 'assignment', 'children': ['372', '373']}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'all_picks'}; {'id': '373', 'type': 'subscript', 'children': ['374', '375']}; {'id': '374', 'type': 'identifier', 'children': [], 'value': 'all_picks'}; {'id': '375', 'type': 'slice', 'children': ['376', '377', '378']}; {'id': '376', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '377', 'type': 'colon', 'children': []}; {'id': '378', 'type': 'identifier', 'children': [], 'value': 'top_n_picks'}; {'id': '379', 'type': 'break_statement', 'children': []}; {'id': '380', 'type': 'for_statement', 'children': ['381', '382', '383']}; {'id': '381', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '382', 'type': 'identifier', 'children': [], 'value': 'filtered_catalog'}; {'id': '383', 'type': 'block', 'children': ['384', '395']}; {'id': '384', 'type': 'if_statement', 'children': ['385', '393']}; {'id': '385', 'type': 'comparison_operator', 'children': ['386', '392'], 'value': '=='}; {'id': '386', 'type': 'call', 'children': ['387', '388']}; {'id': '387', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '388', 'type': 'argument_list', 'children': ['389']}; {'id': '389', 'type': 'attribute', 'children': ['390', '391']}; {'id': '390', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '391', 'type': 'identifier', 'children': [], 'value': 'picks'}; {'id': '392', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '393', 'type': 'block', 'children': ['394']}; {'id': '394', 'type': 'continue_statement', 'children': []}; {'id': '395', 'type': 'expression_statement', 'children': ['396']}; {'id': '396', 'type': 'assignment', 'children': ['397', '400']}; {'id': '397', 'type': 'attribute', 'children': ['398', '399']}; {'id': '398', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '399', 'type': 'identifier', 'children': [], 'value': 'picks'}; {'id': '400', 'type': 'list_comprehension', 'children': ['401', '402', '407']}; {'id': '401', 'type': 'identifier', 'children': [], 'value': 'pick'}; {'id': '402', 'type': 'for_in_clause', 'children': ['403', '404']}; {'id': '403', 'type': 'identifier', 'children': [], 'value': 'pick'}; {'id': '404', 'type': 'attribute', 'children': ['405', '406']}; {'id': '405', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '406', 'type': 'identifier', 'children': [], 'value': 'picks'}; {'id': '407', 'type': 'if_clause', 'children': ['408']}; {'id': '408', 'type': 'comparison_operator', 'children': ['409', '420'], 'value': 'in'}; {'id': '409', 'type': 'tuple', 'children': ['410', '415']}; {'id': '410', 'type': 'attribute', 'children': ['411', '414']}; {'id': '411', 'type': 'attribute', 'children': ['412', '413']}; {'id': '412', 'type': 'identifier', 'children': [], 'value': 'pick'}; {'id': '413', 'type': 'identifier', 'children': [], 'value': 'waveform_id'}; {'id': '414', 'type': 'identifier', 'children': [], 'value': 'station_code'}; {'id': '415', 'type': 'attribute', 'children': ['416', '419']}; {'id': '416', 'type': 'attribute', 'children': ['417', '418']}; {'id': '417', 'type': 'identifier', 'children': [], 'value': 'pick'}; {'id': '418', 'type': 'identifier', 'children': [], 'value': 'waveform_id'}; {'id': '419', 'type': 'identifier', 'children': [], 'value': 'channel_code'}; {'id': '420', 'type': 'identifier', 'children': [], 'value': 'all_picks'}; {'id': '421', 'type': 'expression_statement', 'children': ['422']}; {'id': '422', 'type': 'assignment', 'children': ['423', '424']}; {'id': '423', 'type': 'identifier', 'children': [], 'value': 'tmp_catalog'}; {'id': '424', 'type': 'call', 'children': ['425', '426']}; {'id': '425', 'type': 'identifier', 'children': [], 'value': 'Catalog'}; {'id': '426', 'type': 'argument_list', 'children': []}; {'id': '427', 'type': 'for_statement', 'children': ['428', '429', '430']}; {'id': '428', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '429', 'type': 'identifier', 'children': [], 'value': 'filtered_catalog'}; {'id': '430', 'type': 'block', 'children': ['431']}; {'id': '431', 'type': 'if_statement', 'children': ['432', '440']}; {'id': '432', 'type': 'comparison_operator', 'children': ['433', '439'], 'value': '>'}; {'id': '433', 'type': 'call', 'children': ['434', '435']}; {'id': '434', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '435', 'type': 'argument_list', 'children': ['436']}; {'id': '436', 'type': 'attribute', 'children': ['437', '438']}; {'id': '437', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '438', 'type': 'identifier', 'children': [], 'value': 'picks'}; {'id': '439', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '440', 'type': 'block', 'children': ['441']}; {'id': '441', 'type': 'expression_statement', 'children': ['442']}; {'id': '442', 'type': 'call', 'children': ['443', '446']}; {'id': '443', 'type': 'attribute', 'children': ['444', '445']}; {'id': '444', 'type': 'identifier', 'children': [], 'value': 'tmp_catalog'}; {'id': '445', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '446', 'type': 'argument_list', 'children': ['447']}; {'id': '447', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '448', 'type': 'return_statement', 'children': ['449']}; {'id': '449', 'type': 'identifier', 'children': [], 'value': 'tmp_catalog'}
def filter_picks(catalog, stations=None, channels=None, networks=None, locations=None, top_n_picks=None, evaluation_mode='all'): filtered_catalog = catalog.copy() if stations: for event in filtered_catalog: if len(event.picks) == 0: continue event.picks = [pick for pick in event.picks if pick.waveform_id.station_code in stations] if channels: for event in filtered_catalog: if len(event.picks) == 0: continue event.picks = [pick for pick in event.picks if pick.waveform_id.channel_code in channels] if networks: for event in filtered_catalog: if len(event.picks) == 0: continue event.picks = [pick for pick in event.picks if pick.waveform_id.network_code in networks] if locations: for event in filtered_catalog: if len(event.picks) == 0: continue event.picks = [pick for pick in event.picks if pick.waveform_id.location_code in locations] if evaluation_mode == 'manual': for event in filtered_catalog: event.picks = [pick for pick in event.picks if pick.evaluation_mode == 'manual'] elif evaluation_mode == 'automatic': for event in filtered_catalog: event.picks = [pick for pick in event.picks if pick.evaluation_mode == 'automatic'] elif evaluation_mode != 'all': warnings.warn('Unrecognised evaluation_mode: %s, using all picks' % evaluation_mode) if top_n_picks: all_picks = [] for event in filtered_catalog: all_picks += [(pick.waveform_id.station_code, pick.waveform_id.channel_code) for pick in event.picks] counted = Counter(all_picks).most_common() all_picks = [] for i in range(counted[0][1]): highest = [item[0] for item in counted if item[1] >= counted[0][1] - i] highest = sorted(highest, key=lambda tup: tup[0]) for stachan in highest: if stachan not in all_picks: all_picks.append(stachan) if len(all_picks) > top_n_picks: all_picks = all_picks[0:top_n_picks] break for event in filtered_catalog: if len(event.picks) == 0: continue event.picks = [pick for pick in event.picks if (pick.waveform_id.station_code, pick.waveform_id.channel_code) in all_picks] tmp_catalog = Catalog() for event in filtered_catalog: if len(event.picks) > 0: tmp_catalog.append(event) return tmp_catalog