sequence
stringlengths
1.25k
34.6k
code
stringlengths
75
8.58k
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'check_levels'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'imls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'imt'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'min_iml'},{'id': '8', 'type': 'float', 'children': [], 'value': '1E-10'},{'id': '9', 'type': 'block', 'children': ['10']},{'id': '10', 'type': 'if_statement', 'children': ['11', '17', '27', '44', '67', '92']},{'id': '11', 'type': 'comparison_operator', 'children': ['12', '16'], 'value': '<'},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'imls'},{'id': '16', 'type': 'integer', 'children': [], 'value': '1'},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'raise_statement', 'children': ['19']},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'binary_operator', 'children': ['23', '24'], 'value': '%'},{'id': '23', 'type': 'string', 'children': [], 'value': "'No imls for %s: %s'"},{'id': '24', 'type': 'tuple', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'imt'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'imls'},{'id': '27', 'type': 'elif_clause', 'children': ['28', '34']},{'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': '!='},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'imls'},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'imls'},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'raise_statement', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'binary_operator', 'children': ['40', '41'], 'value': '%'},{'id': '40', 'type': 'string', 'children': [], 'value': "'The imls for %s are not sorted: %s'"},{'id': '41', 'type': 'tuple', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'imt'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'imls'},{'id': '44', 'type': 'elif_clause', 'children': ['45', '57']},{'id': '45', 'type': 'comparison_operator', 'children': ['46', '53'], 'value': '<'},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'distinct'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'imls'},{'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': 'imls'},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'raise_statement', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'binary_operator', 'children': ['63', '64'], 'value': '%'},{'id': '63', 'type': 'string', 'children': [], 'value': '"Found duplicated levels for %s: %s"'},{'id': '64', 'type': 'tuple', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'imt'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'imls'},{'id': '67', 'type': 'elif_clause', 'children': ['68', '79']},{'id': '68', 'type': 'boolean_operator', 'children': ['69', '74'], 'value': 'and'},{'id': '69', 'type': 'comparison_operator', 'children': ['70', '73'], 'value': '=='},{'id': '70', 'type': 'subscript', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'imls'},{'id': '72', 'type': 'integer', 'children': [], 'value': '0'},{'id': '73', 'type': 'integer', 'children': [], 'value': '0'},{'id': '74', 'type': 'comparison_operator', 'children': ['75', '78'], 'value': '<='},{'id': '75', 'type': 'subscript', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'imls'},{'id': '77', 'type': 'integer', 'children': [], 'value': '1'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'min_iml'},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'raise_statement', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'binary_operator', 'children': ['85', '88'], 'value': '%'},{'id': '85', 'type': 'concatenated_string', 'children': ['86', '87']},{'id': '86', 'type': 'string', 'children': [], 'value': '"The min_iml %s=%s is larger than the second level "'},{'id': '87', 'type': 'string', 'children': [], 'value': '"for %s"'},{'id': '88', 'type': 'tuple', 'children': ['89', '90', '91']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'imt'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'min_iml'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'imls'},{'id': '92', 'type': 'elif_clause', 'children': ['93', '104']},{'id': '93', 'type': 'boolean_operator', 'children': ['94', '99'], 'value': 'and'},{'id': '94', 'type': 'comparison_operator', 'children': ['95', '98'], 'value': '=='},{'id': '95', 'type': 'subscript', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'imls'},{'id': '97', 'type': 'integer', 'children': [], 'value': '0'},{'id': '98', 'type': 'integer', 'children': [], 'value': '0'},{'id': '99', 'type': 'comparison_operator', 'children': ['100', '103'], 'value': '>'},{'id': '100', 'type': 'subscript', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'imls'},{'id': '102', 'type': 'integer', 'children': [], 'value': '1'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'min_iml'},{'id': '104', 'type': 'block', 'children': ['105']},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '110']},{'id': '107', 'type': 'subscript', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'imls'},{'id': '109', 'type': 'integer', 'children': [], 'value': '0'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'min_iml'}
def check_levels(imls, imt, min_iml=1E-10): if len(imls) < 1: raise ValueError('No imls for %s: %s' % (imt, imls)) elif imls != sorted(imls): raise ValueError('The imls for %s are not sorted: %s' % (imt, imls)) elif len(distinct(imls)) < len(imls): raise ValueError("Found duplicated levels for %s: %s" % (imt, imls)) elif imls[0] == 0 and imls[1] <= min_iml: raise ValueError("The min_iml %s=%s is larger than the second level " "for %s" % (imt, min_iml, imls)) elif imls[0] == 0 and imls[1] > min_iml: imls[0] = min_iml
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'values'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '20']},{'id': '6', 'type': 'function_definition', 'children': ['7', '8', '10']},{'id': '7', 'type': 'function_name', 'children': [], 'value': 'key'},{'id': '8', 'type': 'parameters', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'th'},{'id': '10', 'type': 'block', 'children': ['11']},{'id': '11', 'type': 'return_statement', 'children': ['12']},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'attribute', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'th'},{'id': '18', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '19', 'type': 'identifier', 'children': [], 'value': '__mro__'},{'id': '20', 'type': 'return_statement', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '23', 'type': 'argument_list', 'children': ['24', '30', '33']},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '35', 'type': 'True', 'children': []}
def values(self): def key(th): return len(th.__class__.__mro__) return sorted(dict.values(self), key=key, reverse=True)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'topological_sort'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '12', '16', '26', '42', '48', '66', '70', '117']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'in_degree'},{'id': '15', 'type': 'dictionary', 'children': []},{'id': '16', 'type': 'for_statement', 'children': ['17', '18', '19']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '25']},{'id': '22', 'type': 'subscript', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'in_degree'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '25', 'type': 'integer', 'children': [], 'value': '0'},{'id': '26', 'type': 'for_statement', 'children': ['27', '28', '29']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'for_statement', 'children': ['31', '32', '35']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '32', 'type': 'subscript', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'augmented_assignment', 'children': ['38', '41'], 'value': '+='},{'id': '38', 'type': 'subscript', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'in_degree'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '41', 'type': 'integer', 'children': [], 'value': '1'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'queue'},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'deque'},{'id': '47', 'type': 'argument_list', 'children': []},{'id': '48', 'type': 'for_statement', 'children': ['49', '50', '51']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'in_degree'},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'if_statement', 'children': ['53', '58']},{'id': '53', 'type': 'comparison_operator', 'children': ['54', '57'], 'value': '=='},{'id': '54', 'type': 'subscript', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'in_degree'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '57', 'type': 'integer', 'children': [], 'value': '0'},{'id': '58', 'type': 'block', 'children': ['59']},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'queue'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'appendleft'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'sorted_graph'},{'id': '69', 'type': 'list', 'children': [], 'value': '[]'},{'id': '70', 'type': 'while_statement', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'queue'},{'id': '72', 'type': 'block', 'children': ['73', '81', '88']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'queue'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '80', 'type': 'argument_list', 'children': []},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'sorted_graph'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '88', 'type': 'for_statement', 'children': ['89', '90', '96']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'subscript', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '96', 'type': 'block', 'children': ['97', '103']},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'augmented_assignment', 'children': ['99', '102'], 'value': '-='},{'id': '99', 'type': 'subscript', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'in_degree'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '102', 'type': 'integer', 'children': [], 'value': '1'},{'id': '103', 'type': 'if_statement', 'children': ['104', '109']},{'id': '104', 'type': 'comparison_operator', 'children': ['105', '108'], 'value': '=='},{'id': '105', 'type': 'subscript', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'in_degree'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '108', 'type': 'integer', 'children': [], 'value': '0'},{'id': '109', 'type': 'block', 'children': ['110']},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'queue'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'appendleft'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '117', 'type': 'if_statement', 'children': ['118', '127', '130']},{'id': '118', 'type': 'comparison_operator', 'children': ['119', '123'], 'value': '=='},{'id': '119', 'type': 'call', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'sorted_graph'},{'id': '123', 'type': 'call', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '127', 'type': 'block', 'children': ['128']},{'id': '128', 'type': 'return_statement', 'children': ['129']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'sorted_graph'},{'id': '130', 'type': 'else_clause', 'children': ['131']},{'id': '131', 'type': 'block', 'children': ['132']},{'id': '132', 'type': 'raise_statement', 'children': ['133']},{'id': '133', 'type': 'call', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'string', 'children': [], 'value': "'graph is not acyclic'"}
def topological_sort(self): graph = self.graph in_degree = {} for u in graph: in_degree[u] = 0 for u in graph: for v in graph[u]: in_degree[v] += 1 queue = deque() for u in in_degree: if in_degree[u] == 0: queue.appendleft(u) sorted_graph = [] while queue: u = queue.pop() sorted_graph.append(u) for v in sorted(graph[u]): in_degree[v] -= 1 if in_degree[v] == 0: queue.appendleft(v) if len(sorted_graph) == len(graph): return sorted_graph else: raise ValueError('graph is not acyclic')
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_music_lib_search'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'max_items'},{'id': '8', 'type': 'block', 'children': ['9', '38', '42', '63']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '12', 'type': 'call', 'children': ['13', '18']},{'id': '13', 'type': 'attribute', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'contentDirectory'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'Browse'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'list', 'children': ['20', '23', '26', '29', '32', '35'], 'value': "[\n ('ObjectID', search),\n ('BrowseFlag', 'BrowseDirectChildren'),\n ('Filter', '*'),\n ('StartingIndex', start),\n ('RequestedCount', max_items),\n ('SortCriteria', '')\n ]"},{'id': '20', 'type': 'tuple', 'children': ['21', '22']},{'id': '21', 'type': 'string', 'children': [], 'value': "'ObjectID'"},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '23', 'type': 'tuple', 'children': ['24', '25']},{'id': '24', 'type': 'string', 'children': [], 'value': "'BrowseFlag'"},{'id': '25', 'type': 'string', 'children': [], 'value': "'BrowseDirectChildren'"},{'id': '26', 'type': 'tuple', 'children': ['27', '28']},{'id': '27', 'type': 'string', 'children': [], 'value': "'Filter'"},{'id': '28', 'type': 'string', 'children': [], 'value': "'*'"},{'id': '29', 'type': 'tuple', 'children': ['30', '31']},{'id': '30', 'type': 'string', 'children': [], 'value': "'StartingIndex'"},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '32', 'type': 'tuple', 'children': ['33', '34']},{'id': '33', 'type': 'string', 'children': [], 'value': "'RequestedCount'"},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'max_items'},{'id': '35', 'type': 'tuple', 'children': ['36', '37']},{'id': '36', 'type': 'string', 'children': [], 'value': "'SortCriteria'"},{'id': '37', 'type': 'string', 'children': [], 'value': "''"},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '41', 'type': 'dictionary', 'children': []},{'id': '42', 'type': 'for_statement', 'children': ['43', '44', '48']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '44', 'type': 'list', 'children': ['45', '46', '47'], 'value': "['NumberReturned', 'TotalMatches', 'UpdateID']"},{'id': '45', 'type': 'string', 'children': [], 'value': "'NumberReturned'"},{'id': '46', 'type': 'string', 'children': [], 'value': "'TotalMatches'"},{'id': '47', 'type': 'string', 'children': [], 'value': "'UpdateID'"},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '57']},{'id': '51', 'type': 'subscript', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'camel_to_underscore'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'subscript', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '63', 'type': 'return_statement', 'children': ['64']},{'id': '64', 'type': 'expression_list', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'metadata'}
def _music_lib_search(self, search, start, max_items): response = self.contentDirectory.Browse([ ('ObjectID', search), ('BrowseFlag', 'BrowseDirectChildren'), ('Filter', '*'), ('StartingIndex', start), ('RequestedCount', max_items), ('SortCriteria', '') ]) metadata = {} for tag in ['NumberReturned', 'TotalMatches', 'UpdateID']: metadata[camel_to_underscore(tag)] = int(response[tag]) return response, metadata
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'unique'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '5', 'type': 'block', 'children': ['6', '10', '26']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'cleaned'},{'id': '9', 'type': 'list', 'children': [], 'value': '[]'},{'id': '10', 'type': 'for_statement', 'children': ['11', '12', '13']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'each'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'if_statement', 'children': ['15', '18']},{'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': 'not'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'each'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'cleaned'},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'cleaned'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'each'},{'id': '26', 'type': 'return_statement', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'cleaned'}
def unique(seq): cleaned = [] for each in seq: if each not in cleaned: cleaned.append(each) return cleaned
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'build_schema_info'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'connection_alias'},{'id': '5', 'type': 'block', 'children': ['6', '13', '17', '127']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'connection'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'get_valid_connection'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'connection_alias'},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '16', 'type': 'list', 'children': [], 'value': '[]'},{'id': '17', 'type': 'with_statement', 'children': ['18', '28']},{'id': '18', 'type': 'with_clause', 'children': ['19']},{'id': '19', 'type': 'with_item', 'children': ['20']},{'id': '20', 'type': 'as_pattern', 'children': ['21', '26']},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'connection'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '25', 'type': 'argument_list', 'children': []},{'id': '26', 'type': 'as_pattern_target', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '28', 'type': 'block', 'children': ['29', '45']},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'tables_to_introspect'},{'id': '32', 'type': 'call', 'children': ['33', '38']},{'id': '33', 'type': 'attribute', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'connection'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'introspection'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'table_names'},{'id': '38', 'type': 'argument_list', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'include_views'},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': '_include_views'},{'id': '44', 'type': 'argument_list', 'children': []},{'id': '45', 'type': 'for_statement', 'children': ['46', '47', '48']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'table_name'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'tables_to_introspect'},{'id': '48', 'type': 'block', 'children': ['49', '57', '61', '73', '118']},{'id': '49', 'type': 'if_statement', 'children': ['50', '55']},{'id': '50', 'type': 'not_operator', 'children': ['51']},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': '_include_table'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'table_name'},{'id': '55', 'type': 'block', 'children': ['56']},{'id': '56', 'type': 'continue_statement', 'children': []},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'td'},{'id': '60', 'type': 'list', 'children': [], 'value': '[]'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'table_description'},{'id': '64', 'type': 'call', 'children': ['65', '70']},{'id': '65', 'type': 'attribute', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'connection'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'introspection'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'get_table_description'},{'id': '70', 'type': 'argument_list', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'table_name'},{'id': '73', 'type': 'for_statement', 'children': ['74', '75', '76']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'table_description'},{'id': '76', 'type': 'block', 'children': ['77', '83', '109']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'column_name'},{'id': '80', 'type': 'subscript', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '82', 'type': 'integer', 'children': [], 'value': '0'},{'id': '83', 'type': 'try_statement', 'children': ['84', '99']},{'id': '84', 'type': 'block', 'children': ['85']},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'field_type'},{'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': 'connection'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'introspection'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'get_field_type'},{'id': '94', 'type': 'argument_list', 'children': ['95', '98']},{'id': '95', 'type': 'subscript', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '97', 'type': 'integer', 'children': [], 'value': '1'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '99', 'type': 'except_clause', 'children': ['100', '104']},{'id': '100', 'type': 'as_pattern', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '102', 'type': 'as_pattern_target', 'children': ['103']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '104', 'type': 'block', 'children': ['105']},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'field_type'},{'id': '108', 'type': 'string', 'children': [], 'value': "'Unknown'"},{'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': 'td'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'tuple', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'column_name'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'field_type'},{'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': 'ret'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'tuple', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'table_name'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'td'},{'id': '127', 'type': 'return_statement', 'children': ['128']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'ret'}
def build_schema_info(connection_alias): connection = get_valid_connection(connection_alias) ret = [] with connection.cursor() as cursor: tables_to_introspect = connection.introspection.table_names(cursor, include_views=_include_views()) for table_name in tables_to_introspect: if not _include_table(table_name): continue td = [] table_description = connection.introspection.get_table_description(cursor, table_name) for row in table_description: column_name = row[0] try: field_type = connection.introspection.get_field_type(row[1], row) except KeyError as e: field_type = 'Unknown' td.append((column_name, field_type)) ret.append((table_name, td)) return ret
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'fetchThreads'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'thread_location'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'before'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'after'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'block', 'children': ['16', '20', '24', '106', '154', '170']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'threads'},{'id': '19', 'type': 'list', 'children': [], 'value': '[]'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'last_thread_timestamp'},{'id': '23', 'type': 'None', 'children': []},{'id': '24', 'type': 'while_statement', 'children': ['25', '26']},{'id': '25', 'type': 'True', 'children': []},{'id': '26', 'type': 'block', 'children': ['27', '38', '52', '71', '80']},{'id': '27', 'type': 'if_statement', 'children': ['28', '36']},{'id': '28', 'type': 'boolean_operator', 'children': ['29', '30'], 'value': 'and'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '30', 'type': 'comparison_operator', 'children': ['31', '35'], 'value': '>='},{'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': 'threads'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'break_statement', 'children': []},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'candidates'},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'fetchThreadList'},{'id': '45', 'type': 'argument_list', 'children': ['46', '49']},{'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'before'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'last_thread_timestamp'},{'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'thread_location'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'thread_location'},{'id': '52', 'type': 'if_statement', 'children': ['53', '59', '68']},{'id': '53', 'type': 'comparison_operator', 'children': ['54', '58'], 'value': '>'},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'candidates'},{'id': '58', 'type': 'integer', 'children': [], 'value': '1'},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'augmented_assignment', 'children': ['62', '63'], 'value': '+='},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'threads'},{'id': '63', 'type': 'subscript', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'candidates'},{'id': '65', 'type': 'slice', 'children': ['66', '67']},{'id': '66', 'type': 'integer', 'children': [], 'value': '1'},{'id': '67', 'type': 'colon', 'children': []},{'id': '68', 'type': 'else_clause', 'children': ['69']},{'id': '69', 'type': 'block', 'children': ['70']},{'id': '70', 'type': 'break_statement', 'children': []},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'last_thread_timestamp'},{'id': '74', 'type': 'attribute', 'children': ['75', '79']},{'id': '75', 'type': 'subscript', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'threads'},{'id': '77', 'type': 'unary_operator', 'children': ['78'], 'value': '-'},{'id': '78', 'type': 'integer', 'children': [], 'value': '1'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'last_message_timestamp'},{'id': '80', 'type': 'if_statement', 'children': ['81', '104']},{'id': '81', 'type': 'boolean_operator', 'children': ['82', '93'], 'value': 'or'},{'id': '82', 'type': '()', 'children': ['83']},{'id': '83', 'type': 'boolean_operator', 'children': ['84', '87'], 'value': 'and'},{'id': '84', 'type': 'comparison_operator', 'children': ['85', '86'], 'value': 'is'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'before'},{'id': '86', 'type': 'None', 'children': []},{'id': '87', 'type': 'comparison_operator', 'children': ['88', '92'], 'value': '>'},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'last_thread_timestamp'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'before'},{'id': '93', 'type': '()', 'children': ['94']},{'id': '94', 'type': 'boolean_operator', 'children': ['95', '98'], 'value': 'and'},{'id': '95', 'type': 'comparison_operator', 'children': ['96', '97'], 'value': 'is'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'after'},{'id': '97', 'type': 'None', 'children': []},{'id': '98', 'type': 'comparison_operator', 'children': ['99', '103'], 'value': '<'},{'id': '99', 'type': 'call', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'last_thread_timestamp'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'after'},{'id': '104', 'type': 'block', 'children': ['105']},{'id': '105', 'type': 'break_statement', 'children': []},{'id': '106', 'type': 'if_statement', 'children': ['107', '114']},{'id': '107', 'type': 'boolean_operator', 'children': ['108', '111'], 'value': 'or'},{'id': '108', 'type': 'comparison_operator', 'children': ['109', '110'], 'value': 'is'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'before'},{'id': '110', 'type': 'None', 'children': []},{'id': '111', 'type': 'comparison_operator', 'children': ['112', '113'], 'value': 'is'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'after'},{'id': '113', 'type': 'None', 'children': []},{'id': '114', 'type': 'block', 'children': ['115']},{'id': '115', 'type': 'for_statement', 'children': ['116', '117', '118']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'threads'},{'id': '118', 'type': 'block', 'children': ['119', '128']},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'last_message_timestamp'},{'id': '122', 'type': 'call', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'last_message_timestamp'},{'id': '128', 'type': 'if_statement', 'children': ['129', '146']},{'id': '129', 'type': 'boolean_operator', 'children': ['130', '138'], 'value': 'or'},{'id': '130', 'type': '()', 'children': ['131']},{'id': '131', 'type': 'boolean_operator', 'children': ['132', '135'], 'value': 'and'},{'id': '132', 'type': 'comparison_operator', 'children': ['133', '134'], 'value': 'is'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'before'},{'id': '134', 'type': 'None', 'children': []},{'id': '135', 'type': 'comparison_operator', 'children': ['136', '137'], 'value': '>'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'last_message_timestamp'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'before'},{'id': '138', 'type': '()', 'children': ['139']},{'id': '139', 'type': 'boolean_operator', 'children': ['140', '143'], 'value': 'and'},{'id': '140', 'type': 'comparison_operator', 'children': ['141', '142'], 'value': 'is'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'after'},{'id': '142', 'type': 'None', 'children': []},{'id': '143', 'type': 'comparison_operator', 'children': ['144', '145'], 'value': '<'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'last_message_timestamp'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'after'},{'id': '146', 'type': 'block', 'children': ['147']},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'call', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'threads'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '154', 'type': 'if_statement', 'children': ['155', '163']},{'id': '155', 'type': 'boolean_operator', 'children': ['156', '157'], 'value': 'and'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '157', 'type': 'comparison_operator', 'children': ['158', '162'], 'value': '>'},{'id': '158', 'type': 'call', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'threads'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '163', 'type': 'block', 'children': ['164']},{'id': '164', 'type': 'return_statement', 'children': ['165']},{'id': '165', 'type': 'subscript', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'threads'},{'id': '167', 'type': 'slice', 'children': ['168', '169']},{'id': '168', 'type': 'colon', 'children': []},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '170', 'type': 'return_statement', 'children': ['171']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'threads'}
def fetchThreads(self, thread_location, before=None, after=None, limit=None): threads = [] last_thread_timestamp = None while True: if limit and len(threads) >= limit: break candidates = self.fetchThreadList( before=last_thread_timestamp, thread_location=thread_location ) if len(candidates) > 1: threads += candidates[1:] else: break last_thread_timestamp = threads[-1].last_message_timestamp if (before is not None and int(last_thread_timestamp) > before) or ( after is not None and int(last_thread_timestamp) < after ): break if before is not None or after is not None: for t in threads: last_message_timestamp = int(t.last_message_timestamp) if (before is not None and last_message_timestamp > before) or ( after is not None and last_message_timestamp < after ): threads.remove(t) if limit and len(threads) > limit: return threads[:limit] return threads
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_key_value'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'is_hll'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '12']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'string', 'children': [], 'value': "'''\n Returns the proper key value for the stats\n @param key: the redis key\n @param is_hll: the key is a HyperLogLog, else is a sorted set\n '''"},{'id': '12', 'type': 'if_statement', 'children': ['13', '14', '25']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'is_hll'},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'return_statement', 'children': ['16']},{'id': '16', 'type': 'call', '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': 'redis_conn'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'execute_command'},{'id': '22', 'type': 'argument_list', 'children': ['23', '24']},{'id': '23', 'type': 'string', 'children': [], 'value': '"PFCOUNT"'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '25', 'type': 'else_clause', 'children': ['26']},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'return_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': 'self'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'redis_conn'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'zcard'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'key'}
def _get_key_value(self, key, is_hll=False): ''' Returns the proper key value for the stats @param key: the redis key @param is_hll: the key is a HyperLogLog, else is a sorted set ''' if is_hll: return self.redis_conn.execute_command("PFCOUNT", key) else: return self.redis_conn.zcard(key)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_bin'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '6', 'type': 'block', 'children': ['7', '9', '13', '62']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'string', 'children': [], 'value': "'''\n Returns a binned dictionary based on redis zscore\n @return: The sorted dict\n '''"},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'sortedDict'},{'id': '12', 'type': 'dictionary', 'children': []},{'id': '13', 'type': 'for_statement', 'children': ['14', '15', '23']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'item'},{'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': 'redis_conn'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'zscan_iter'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '23', 'type': 'block', 'children': ['24', '35', '42', '53']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'my_item'},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'ujson'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'loads'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'subscript', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '34', 'type': 'integer', 'children': [], 'value': '0'},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'my_score'},{'id': '38', 'type': 'unary_operator', 'children': ['39'], 'value': '-'},{'id': '39', 'type': 'subscript', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '41', 'type': 'integer', 'children': [], 'value': '1'},{'id': '42', 'type': 'if_statement', 'children': ['43', '46']},{'id': '43', 'type': 'comparison_operator', 'children': ['44', '45'], 'value': 'not'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'my_score'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'sortedDict'},{'id': '46', 'type': 'block', 'children': ['47']},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '52']},{'id': '49', 'type': 'subscript', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'sortedDict'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'my_score'},{'id': '52', 'type': 'list', 'children': [], 'value': '[]'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '60']},{'id': '55', 'type': 'attribute', 'children': ['56', '59']},{'id': '56', 'type': 'subscript', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'sortedDict'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'my_score'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'my_item'},{'id': '62', 'type': 'return_statement', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'sortedDict'}
def _get_bin(self, key): ''' Returns a binned dictionary based on redis zscore @return: The sorted dict ''' sortedDict = {} for item in self.redis_conn.zscan_iter(key): my_item = ujson.loads(item[0]) my_score = -item[1] if my_score not in sortedDict: sortedDict[my_score] = [] sortedDict[my_score].append(my_item) return sortedDict
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_is_viable_phone_number'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '5', 'type': 'block', 'children': ['6', '16', '24']},{'id': '6', 'type': 'if_statement', 'children': ['7', '13']},{'id': '7', 'type': 'comparison_operator', 'children': ['8', '12'], 'value': '<'},{'id': '8', 'type': 'call', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '10', 'type': 'argument_list', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '12', 'type': 'identifier', 'children': [], 'value': '_MIN_LENGTH_FOR_NSN'},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'return_statement', 'children': ['15']},{'id': '15', 'type': 'False', 'children': []},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'fullmatch'},{'id': '21', 'type': 'argument_list', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': '_VALID_PHONE_NUMBER_PATTERN'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '24', 'type': 'return_statement', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'match'}
def _is_viable_phone_number(number): if len(number) < _MIN_LENGTH_FOR_NSN: return False match = fullmatch(_VALID_PHONE_NUMBER_PATTERN, number) return bool(match)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '__encoded_params_for_signature'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '6', 'type': 'block', 'children': ['7', '109']},{'id': '7', 'type': 'function_definition', 'children': ['8', '9', '11']},{'id': '8', 'type': 'function_name', 'children': [], 'value': 'encoded_pairs'},{'id': '9', 'type': 'parameters', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'for_statement', 'children': ['13', '16', '22']},{'id': '13', 'type': 'pattern_list', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '22', 'type': 'block', 'children': ['23', '29', '62', '81', '94']},{'id': '23', 'type': 'if_statement', 'children': ['24', '27']},{'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': '=='},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '26', 'type': 'string', 'children': [], 'value': "'hmac'"},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'continue_statement', 'children': []},{'id': '29', 'type': 'if_statement', 'children': ['30', '36']},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'string', 'children': [], 'value': "'[]'"},{'id': '36', 'type': 'block', 'children': ['37', '46']},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'rstrip'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'string', 'children': [], 'value': "'[]'"},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '49', 'type': 'call', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '59', 'type': 'argument_list', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '65', 'type': 'call', 'children': ['66', '78']},{'id': '66', 'type': 'attribute', 'children': ['67', '77']},{'id': '67', 'type': 'call', 'children': ['68', '74']},{'id': '68', 'type': 'attribute', 'children': ['69', '73']},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '74', 'type': 'argument_list', 'children': ['75', '76']},{'id': '75', 'type': 'string', 'children': [], 'value': '"%"'},{'id': '76', 'type': 'string', 'children': [], 'value': '"%25"'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '78', 'type': 'argument_list', 'children': ['79', '80']},{'id': '79', 'type': 'string', 'children': [], 'value': '"="'},{'id': '80', 'type': 'string', 'children': [], 'value': '"%3D"'},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '84', 'type': 'call', 'children': ['85', '91']},{'id': '85', 'type': 'attribute', 'children': ['86', '90']},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '91', 'type': 'argument_list', 'children': ['92', '93']},{'id': '92', 'type': 'string', 'children': [], 'value': '"%"'},{'id': '93', 'type': 'string', 'children': [], 'value': '"%25"'},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'yield', 'children': ['96']},{'id': '96', 'type': 'call', 'children': ['97', '106']},{'id': '97', 'type': 'attribute', 'children': ['98', '105']},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'string', 'children': [], 'value': "'{0}={1}'"},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '102', 'type': 'argument_list', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '106', 'type': 'argument_list', 'children': ['107', '108']},{'id': '107', 'type': 'string', 'children': [], 'value': '"&"'},{'id': '108', 'type': 'string', 'children': [], 'value': '"%26"'},{'id': '109', 'type': 'return_statement', 'children': ['110']},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'string', 'children': [], 'value': '"&"'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'call', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '117', 'type': 'argument_list', 'children': ['118']},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'encoded_pairs'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'params'}
def __encoded_params_for_signature(cls, params): def encoded_pairs(params): for k, v in six.iteritems(params): if k == 'hmac': continue if k.endswith('[]'): k = k.rstrip('[]') v = json.dumps(list(map(str, v))) k = str(k).replace("%", "%25").replace("=", "%3D") v = str(v).replace("%", "%25") yield '{0}={1}'.format(k, v).replace("&", "%26") return "&".join(sorted(encoded_pairs(params)))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'group_keys'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6']},{'id': '6', 'type': 'for_statement', 'children': ['7', '8', '20']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '8', 'type': 'call', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '10', 'type': 'argument_list', 'children': ['11']},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'listdir'},{'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': '_store'},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': '_path'},{'id': '20', 'type': 'block', 'children': ['21', '29']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '24', 'type': 'binary_operator', 'children': ['25', '28'], 'value': '+'},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '27', 'type': 'identifier', 'children': [], 'value': '_key_prefix'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '29', 'type': 'if_statement', 'children': ['30', '37']},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'contains_group'},{'id': '32', 'type': 'argument_list', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'identifier', 'children': [], 'value': '_store'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'yield', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'key'}
def group_keys(self): for key in sorted(listdir(self._store, self._path)): path = self._key_prefix + key if contains_group(self._store, path): yield key
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'array_keys'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6']},{'id': '6', 'type': 'for_statement', 'children': ['7', '8', '20']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '8', 'type': 'call', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '10', 'type': 'argument_list', 'children': ['11']},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'listdir'},{'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': '_store'},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': '_path'},{'id': '20', 'type': 'block', 'children': ['21', '29']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '24', 'type': 'binary_operator', 'children': ['25', '28'], 'value': '+'},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '27', 'type': 'identifier', 'children': [], 'value': '_key_prefix'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '29', 'type': 'if_statement', 'children': ['30', '37']},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'contains_array'},{'id': '32', 'type': 'argument_list', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'identifier', 'children': [], 'value': '_store'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'yield', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'key'}
def array_keys(self): for key in sorted(listdir(self._store, self._path)): path = self._key_prefix + key if contains_array(self._store, path): yield key
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '36']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'init_array'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24', '27', '30', '33']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'chunks'},{'id': '8', 'type': 'True', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'compressor'},{'id': '14', 'type': 'string', 'children': [], 'value': "'default'"},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'fill_value'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '20', 'type': 'string', 'children': [], 'value': "'C'"},{'id': '21', 'type': 'default_parameter', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'overwrite'},{'id': '23', 'type': 'False', 'children': []},{'id': '24', 'type': 'default_parameter', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '26', 'type': 'None', 'children': []},{'id': '27', 'type': 'default_parameter', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'chunk_store'},{'id': '29', 'type': 'None', 'children': []},{'id': '30', 'type': 'default_parameter', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '32', 'type': 'None', 'children': []},{'id': '33', 'type': 'default_parameter', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'object_codec'},{'id': '35', 'type': 'None', 'children': []},{'id': '36', 'type': 'block', 'children': ['37', '44', '58']},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'normalize_storage_path'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': '_require_parent_group'},{'id': '47', 'type': 'argument_list', 'children': ['48', '49', '52', '55']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'chunk_store'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'chunk_store'},{'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'overwrite'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'overwrite'},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': '_init_array_metadata'},{'id': '61', 'type': 'argument_list', 'children': ['62', '63', '66', '69', '72', '75', '78', '81', '84', '87', '90', '93']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '63', 'type': 'keyword_argument', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '66', 'type': 'keyword_argument', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'chunks'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'chunks'},{'id': '69', 'type': 'keyword_argument', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '72', 'type': 'keyword_argument', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'compressor'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'compressor'},{'id': '75', 'type': 'keyword_argument', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'fill_value'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'fill_value'},{'id': '78', 'type': 'keyword_argument', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '81', 'type': 'keyword_argument', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'overwrite'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'overwrite'},{'id': '84', 'type': 'keyword_argument', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '87', 'type': 'keyword_argument', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'chunk_store'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'chunk_store'},{'id': '90', 'type': 'keyword_argument', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'object_codec'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'object_codec'}
def init_array(store, shape, chunks=True, dtype=None, compressor='default', fill_value=None, order='C', overwrite=False, path=None, chunk_store=None, filters=None, object_codec=None): path = normalize_storage_path(path) _require_parent_group(path, store=store, chunk_store=chunk_store, overwrite=overwrite) _init_array_metadata(store, shape=shape, chunks=chunks, dtype=dtype, compressor=compressor, fill_value=fill_value, order=order, overwrite=overwrite, path=path, chunk_store=chunk_store, filters=filters, object_codec=object_codec)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '26']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'view'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'chunks'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'fill_value'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'read_only'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'synchronizer'},{'id': '25', 'type': 'None', 'children': []},{'id': '26', 'type': 'block', 'children': ['27', '33', '39', '45', '56', '67', '91', '97', '125', '151', '173', '184', '195']},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '32', 'type': 'identifier', 'children': [], 'value': '_store'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'chunk_store'},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '38', 'type': 'identifier', 'children': [], 'value': '_chunk_store'},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '44', 'type': 'identifier', 'children': [], 'value': '_path'},{'id': '45', 'type': 'if_statement', 'children': ['46', '49']},{'id': '46', 'type': 'comparison_operator', 'children': ['47', '48'], 'value': 'is'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'read_only'},{'id': '48', 'type': 'None', 'children': []},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'read_only'},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '55', 'type': 'identifier', 'children': [], 'value': '_read_only'},{'id': '56', 'type': 'if_statement', 'children': ['57', '60']},{'id': '57', 'type': 'comparison_operator', 'children': ['58', '59'], 'value': 'is'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'synchronizer'},{'id': '59', 'type': 'None', 'children': []},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'synchronizer'},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '66', 'type': 'identifier', 'children': [], 'value': '_synchronizer'},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '70', 'type': 'call', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'Array'},{'id': '72', 'type': 'argument_list', 'children': ['73', '76', '79', '82', '85', '88']},{'id': '73', 'type': 'keyword_argument', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '76', 'type': 'keyword_argument', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '79', 'type': 'keyword_argument', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'chunk_store'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'chunk_store'},{'id': '82', 'type': 'keyword_argument', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'read_only'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'read_only'},{'id': '85', 'type': 'keyword_argument', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'synchronizer'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'synchronizer'},{'id': '88', 'type': 'keyword_argument', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'cache_metadata'},{'id': '90', 'type': 'True', 'children': []},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '95', 'type': 'identifier', 'children': [], 'value': '_is_view'},{'id': '96', 'type': 'True', 'children': []},{'id': '97', 'type': 'if_statement', 'children': ['98', '101', '108']},{'id': '98', 'type': 'comparison_operator', 'children': ['99', '100'], 'value': 'is'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '100', 'type': 'None', 'children': []},{'id': '101', 'type': 'block', 'children': ['102']},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '107', 'type': 'identifier', 'children': [], 'value': '_dtype'},{'id': '108', 'type': 'else_clause', 'children': ['109']},{'id': '109', 'type': 'block', 'children': ['110', '119']},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'assignment', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '113', 'type': 'call', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '117', 'type': 'argument_list', 'children': ['118']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '123', 'type': 'identifier', 'children': [], 'value': '_dtype'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '125', 'type': 'if_statement', 'children': ['126', '129', '136']},{'id': '126', 'type': 'comparison_operator', 'children': ['127', '128'], 'value': 'is'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '128', 'type': 'None', 'children': []},{'id': '129', 'type': 'block', 'children': ['130']},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '135', 'type': 'identifier', 'children': [], 'value': '_shape'},{'id': '136', 'type': 'else_clause', 'children': ['137']},{'id': '137', 'type': 'block', 'children': ['138', '145']},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'assignment', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '141', 'type': 'call', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'normalize_shape'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '149', 'type': 'identifier', 'children': [], 'value': '_shape'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '151', 'type': 'if_statement', 'children': ['152', '155']},{'id': '152', 'type': 'comparison_operator', 'children': ['153', '154'], 'value': 'is'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'chunks'},{'id': '154', 'type': 'None', 'children': []},{'id': '155', 'type': 'block', 'children': ['156', '167']},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'assignment', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'chunks'},{'id': '159', 'type': 'call', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'normalize_chunks'},{'id': '161', 'type': 'argument_list', 'children': ['162', '163', '164']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'chunks'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'itemsize'},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'assignment', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '171', 'type': 'identifier', 'children': [], 'value': '_chunks'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'chunks'},{'id': '173', 'type': 'if_statement', 'children': ['174', '177']},{'id': '174', 'type': 'comparison_operator', 'children': ['175', '176'], 'value': 'is'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'fill_value'},{'id': '176', 'type': 'None', 'children': []},{'id': '177', 'type': 'block', 'children': ['178']},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'assignment', 'children': ['180', '183']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '182', 'type': 'identifier', 'children': [], 'value': '_fill_value'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'fill_value'},{'id': '184', 'type': 'if_statement', 'children': ['185', '188']},{'id': '185', 'type': 'comparison_operator', 'children': ['186', '187'], 'value': 'is'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '187', 'type': 'None', 'children': []},{'id': '188', 'type': 'block', 'children': ['189']},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'assignment', 'children': ['191', '194']},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '193', 'type': 'identifier', 'children': [], 'value': '_filters'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '195', 'type': 'return_statement', 'children': ['196']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'a'}
def view(self, shape=None, chunks=None, dtype=None, fill_value=None, filters=None, read_only=None, synchronizer=None): store = self._store chunk_store = self._chunk_store path = self._path if read_only is None: read_only = self._read_only if synchronizer is None: synchronizer = self._synchronizer a = Array(store=store, path=path, chunk_store=chunk_store, read_only=read_only, synchronizer=synchronizer, cache_metadata=True) a._is_view = True if dtype is None: dtype = self._dtype else: dtype = np.dtype(dtype) a._dtype = dtype if shape is None: shape = self._shape else: shape = normalize_shape(shape) a._shape = shape if chunks is not None: chunks = normalize_chunks(chunks, shape, dtype.itemsize) a._chunks = chunks if fill_value is not None: a._fill_value = fill_value if filters is not None: a._filters = filters return a
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'image_field_data'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'include_empty_option'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '37', '51', '61', '93', '105']},{'id': '9', 'type': 'try_statement', 'children': ['10', '23']},{'id': '10', 'type': 'block', 'children': ['11']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'images'},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'get_available_images'},{'id': '16', 'type': 'argument_list', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '18', 'type': 'attribute', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'project_id'},{'id': '23', 'type': 'except_clause', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'exceptions'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'handle'},{'id': '31', 'type': 'argument_list', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'string', 'children': [], 'value': "'Unable to retrieve images'"},{'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': 'images'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '45', 'type': 'lambda', 'children': ['46', '48']},{'id': '46', 'type': 'lambda_parameters', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'images_list'},{'id': '54', 'type': 'list', 'children': ['55'], 'value': "[('', _('Select Image'))]"},{'id': '55', 'type': 'tuple', 'children': ['56', '57']},{'id': '56', 'type': 'string', 'children': [], 'value': "''"},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'string', 'children': [], 'value': "'Select Image'"},{'id': '61', 'type': 'for_statement', 'children': ['62', '63', '64']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'images'},{'id': '64', 'type': 'block', 'children': ['65', '82']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'image_label'},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'string', 'children': [], 'value': 'u"{} ({})"'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '72', 'type': 'argument_list', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'filesizeformat'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'size'},{'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': 'images_list'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'tuple', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'image_label'},{'id': '93', 'type': 'if_statement', 'children': ['94', '96']},{'id': '94', 'type': 'not_operator', 'children': ['95']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'images'},{'id': '96', 'type': 'block', 'children': ['97']},{'id': '97', 'type': 'return_statement', 'children': ['98']},{'id': '98', 'type': 'list', 'children': ['99'], 'value': '[("", _("No images available")), ]'},{'id': '99', 'type': 'tuple', 'children': ['100', '101']},{'id': '100', 'type': 'string', 'children': [], 'value': '""'},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'string', 'children': [], 'value': '"No images available"'},{'id': '105', 'type': 'return_statement', 'children': ['106']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'images_list'}
def image_field_data(request, include_empty_option=False): try: images = get_available_images(request, request.user.project_id) except Exception: exceptions.handle(request, _('Unable to retrieve images')) images.sort(key=lambda c: c.name) images_list = [('', _('Select Image'))] for image in images: image_label = u"{} ({})".format(image.name, filesizeformat(image.size)) images_list.append((image.id, image_label)) if not images: return [("", _("No images available")), ] return images_list
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_flavor_list'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'flavors'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'with_menu_label'},{'id': '8', 'type': 'True', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '43']},{'id': '10', 'type': 'function_definition', 'children': ['11', '12', '15']},{'id': '11', 'type': 'function_name', 'children': [], 'value': 'get_key'},{'id': '12', 'type': 'parameters', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'flavor'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'try_statement', 'children': ['17', '24']},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'return_statement', 'children': ['19']},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '21', 'type': 'argument_list', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'flavor'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '24', 'type': 'except_clause', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '26', 'type': 'block', 'children': ['27', '37']},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'LOG'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '32', 'type': 'argument_list', 'children': ['33', '36']},{'id': '33', 'type': 'concatenated_string', 'children': ['34', '35']},{'id': '34', 'type': 'string', 'children': [], 'value': '\'Could not find sort key "%s". Using the default \''},{'id': '35', 'type': 'string', 'children': [], 'value': '\'"ram" instead.\''},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '37', 'type': 'return_statement', 'children': ['38']},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '40', 'type': 'argument_list', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'flavor'},{'id': '42', 'type': 'string', 'children': [], 'value': "'ram'"},{'id': '43', 'type': 'try_statement', 'children': ['44', '143']},{'id': '44', 'type': 'block', 'children': ['45', '54', '64', '74', '98', '141']},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'flavor_sort'},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '50', 'type': 'argument_list', 'children': ['51', '52', '53']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '52', 'type': 'string', 'children': [], 'value': "'CREATE_INSTANCE_FLAVOR_SORT'"},{'id': '53', 'type': 'dictionary', 'children': []},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '57', 'type': 'call', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'flavor_sort'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '61', 'type': 'argument_list', 'children': ['62', '63']},{'id': '62', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '63', 'type': 'string', 'children': [], 'value': "'ram'"},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'rev'},{'id': '67', 'type': 'call', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'flavor_sort'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '71', 'type': 'argument_list', 'children': ['72', '73']},{'id': '72', 'type': 'string', 'children': [], 'value': "'reverse'"},{'id': '73', 'type': 'False', 'children': []},{'id': '74', 'type': 'if_statement', 'children': ['75', '80', '92']},{'id': '75', 'type': 'not_operator', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'callable'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '80', 'type': 'block', 'children': ['81']},{'id': '81', 'type': 'function_definition', 'children': ['82', '83', '85']},{'id': '82', 'type': 'function_name', 'children': [], 'value': 'key'},{'id': '83', 'type': 'parameters', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'flavor'},{'id': '85', 'type': 'block', 'children': ['86']},{'id': '86', 'type': 'return_statement', 'children': ['87']},{'id': '87', 'type': 'call', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'get_key'},{'id': '89', 'type': 'argument_list', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'flavor'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'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': 'key'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '98', 'type': 'if_statement', 'children': ['99', '100', '126']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'with_menu_label'},{'id': '100', 'type': 'block', 'children': ['101']},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'flavor_list'},{'id': '104', 'type': 'list_comprehension', 'children': ['105', '114']},{'id': '105', 'type': 'tuple', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'flavor'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '109', 'type': 'binary_operator', 'children': ['110', '111'], 'value': '%'},{'id': '110', 'type': 'string', 'children': [], 'value': "'%s'"},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'flavor'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '114', 'type': 'for_in_clause', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'flavor'},{'id': '116', 'type': 'call', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '118', 'type': 'argument_list', 'children': ['119', '120', '123']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'flavors'},{'id': '120', 'type': 'keyword_argument', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '123', 'type': 'keyword_argument', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'rev'},{'id': '126', 'type': 'else_clause', 'children': ['127']},{'id': '127', 'type': 'block', 'children': ['128']},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'assignment', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'flavor_list'},{'id': '131', 'type': 'call', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '133', 'type': 'argument_list', 'children': ['134', '135', '138']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'flavors'},{'id': '135', 'type': 'keyword_argument', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '138', 'type': 'keyword_argument', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'rev'},{'id': '141', 'type': 'return_statement', 'children': ['142']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'flavor_list'},{'id': '143', 'type': 'except_clause', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '145', 'type': 'block', 'children': ['146', '157']},{'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': 'exceptions'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'handle'},{'id': '151', 'type': 'argument_list', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '153', 'type': 'call', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'string', 'children': [], 'value': "'Unable to sort instance flavors.'"},{'id': '157', 'type': 'return_statement', 'children': ['158']},{'id': '158', 'type': 'list', 'children': [], 'value': '[]'}
def sort_flavor_list(request, flavors, with_menu_label=True): def get_key(flavor, sort_key): try: return getattr(flavor, sort_key) except AttributeError: LOG.warning('Could not find sort key "%s". Using the default ' '"ram" instead.', sort_key) return getattr(flavor, 'ram') try: flavor_sort = getattr(settings, 'CREATE_INSTANCE_FLAVOR_SORT', {}) sort_key = flavor_sort.get('key', 'ram') rev = flavor_sort.get('reverse', False) if not callable(sort_key): def key(flavor): return get_key(flavor, sort_key) else: key = sort_key if with_menu_label: flavor_list = [(flavor.id, '%s' % flavor.name) for flavor in sorted(flavors, key=key, reverse=rev)] else: flavor_list = sorted(flavors, key=key, reverse=rev) return flavor_list except Exception: exceptions.handle(request, _('Unable to sort instance flavors.')) return []
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '25']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'image_list_detailed'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'marker'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'sort_dir'},{'id': '10', 'type': 'string', 'children': [], 'value': "'desc'"},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '13', 'type': 'string', 'children': [], 'value': "'created_at'"},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'paginate'},{'id': '19', 'type': 'False', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'reversed_order'},{'id': '22', 'type': 'False', 'children': []},{'id': '23', 'type': 'dictionary_splat_pattern', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '25', 'type': 'block', 'children': ['26', '35', '44', '59', '66', '75', '84', '90', '113', '134', '138', '142', '249', '253', '267']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '31', 'type': 'argument_list', 'children': ['32', '33', '34']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '33', 'type': 'string', 'children': [], 'value': "'API_RESULT_LIMIT'"},{'id': '34', 'type': 'integer', 'children': [], 'value': '1000'},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'get_page_size'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '44', 'type': 'if_statement', 'children': ['45', '46', '53']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'paginate'},{'id': '46', 'type': 'block', 'children': ['47']},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'request_size'},{'id': '50', 'type': 'binary_operator', 'children': ['51', '52'], 'value': '+'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '52', 'type': 'integer', 'children': [], 'value': '1'},{'id': '53', 'type': 'else_clause', 'children': ['54']},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'request_size'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': '_normalize_list_input'},{'id': '62', 'type': 'argument_list', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '64', 'type': 'dictionary_splat', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '69', 'type': 'dictionary', 'children': ['70']},{'id': '70', 'type': 'pair', 'children': ['71', '72']},{'id': '71', 'type': 'string', 'children': [], 'value': "'filters'"},{'id': '72', 'type': 'boolean_operator', 'children': ['73', '74'], 'value': 'or'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '74', 'type': 'dictionary', 'children': []},{'id': '75', 'type': 'if_statement', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'marker'},{'id': '77', 'type': 'block', 'children': ['78']},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '83']},{'id': '80', 'type': 'subscript', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '82', 'type': 'string', 'children': [], 'value': "'marker'"},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'marker'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '89']},{'id': '86', 'type': 'subscript', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '88', 'type': 'string', 'children': [], 'value': "'sort_key'"},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '90', 'type': 'if_statement', 'children': ['91', '93', '100']},{'id': '91', 'type': 'not_operator', 'children': ['92']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'reversed_order'},{'id': '93', 'type': 'block', 'children': ['94']},{'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': 'kwargs'},{'id': '98', 'type': 'string', 'children': [], 'value': "'sort_dir'"},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'sort_dir'},{'id': '100', 'type': 'else_clause', 'children': ['101']},{'id': '101', 'type': 'block', 'children': ['102']},{'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': 'kwargs'},{'id': '106', 'type': 'string', 'children': [], 'value': "'sort_dir'"},{'id': '107', 'type': 'conditional_expression', 'children': ['108', '109', '112'], 'value': 'if'},{'id': '108', 'type': 'string', 'children': [], 'value': "'desc'"},{'id': '109', 'type': 'comparison_operator', 'children': ['110', '111'], 'value': '=='},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'sort_dir'},{'id': '111', 'type': 'string', 'children': [], 'value': "'asc'"},{'id': '112', 'type': 'string', 'children': [], 'value': "'asc'"},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'images_iter'},{'id': '116', 'type': 'call', 'children': ['117', '125']},{'id': '117', 'type': 'attribute', 'children': ['118', '124']},{'id': '118', 'type': 'attribute', 'children': ['119', '123']},{'id': '119', 'type': 'call', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'glanceclient'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'images'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '125', 'type': 'argument_list', 'children': ['126', '129', '132']},{'id': '126', 'type': 'keyword_argument', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'request_size'},{'id': '129', 'type': 'keyword_argument', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '132', 'type': 'dictionary_splat', 'children': ['133']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'has_prev_data'},{'id': '137', 'type': 'False', 'children': []},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'assignment', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'has_more_data'},{'id': '141', 'type': 'False', 'children': []},{'id': '142', 'type': 'if_statement', 'children': ['143', '144', '240']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'paginate'},{'id': '144', 'type': 'block', 'children': ['145', '158', '207']},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'images'},{'id': '148', 'type': 'call', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '150', 'type': 'argument_list', 'children': ['151']},{'id': '151', 'type': 'call', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'itertools'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'islice'},{'id': '155', 'type': 'argument_list', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'images_iter'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'request_size'},{'id': '158', 'type': 'if_statement', 'children': ['159', '165', '187', '198']},{'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': 'images'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '165', 'type': 'block', 'children': ['166', '174', '178']},{'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': 'images'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'unary_operator', 'children': ['173'], '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': 'has_more_data'},{'id': '177', 'type': 'True', 'children': []},{'id': '178', 'type': 'if_statement', 'children': ['179', '182']},{'id': '179', 'type': 'comparison_operator', 'children': ['180', '181'], 'value': 'is'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'marker'},{'id': '181', 'type': 'None', 'children': []},{'id': '182', 'type': 'block', 'children': ['183']},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'assignment', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'has_prev_data'},{'id': '186', 'type': 'True', 'children': []},{'id': '187', 'type': 'elif_clause', 'children': ['188', '193']},{'id': '188', 'type': 'boolean_operator', 'children': ['189', '190'], 'value': 'and'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'reversed_order'},{'id': '190', 'type': 'comparison_operator', 'children': ['191', '192'], 'value': 'is'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'marker'},{'id': '192', 'type': 'None', 'children': []},{'id': '193', 'type': 'block', 'children': ['194']},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'assignment', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'has_more_data'},{'id': '197', 'type': 'True', 'children': []},{'id': '198', 'type': 'elif_clause', 'children': ['199', '202']},{'id': '199', 'type': 'comparison_operator', 'children': ['200', '201'], 'value': 'is'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'marker'},{'id': '201', 'type': 'None', 'children': []},{'id': '202', 'type': 'block', 'children': ['203']},{'id': '203', 'type': 'expression_statement', 'children': ['204']},{'id': '204', 'type': 'assignment', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'has_prev_data'},{'id': '206', 'type': 'True', 'children': []},{'id': '207', 'type': 'if_statement', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'reversed_order'},{'id': '209', 'type': 'block', 'children': ['210']},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'id': '211', 'type': 'assignment', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'images'},{'id': '213', 'type': 'call', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '215', 'type': 'argument_list', 'children': ['216', '217', '234']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'images'},{'id': '217', 'type': 'keyword_argument', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '219', 'type': 'lambda', 'children': ['220', '222']},{'id': '220', 'type': 'lambda_parameters', 'children': ['221']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '222', 'type': 'call', 'children': ['223', '233']},{'id': '223', 'type': 'attribute', 'children': ['224', '232']},{'id': '224', 'type': '()', 'children': ['225']},{'id': '225', 'type': 'boolean_operator', 'children': ['226', '231'], 'value': 'or'},{'id': '226', 'type': 'call', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '228', 'type': 'argument_list', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '231', 'type': 'string', 'children': [], 'value': "''"},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '233', 'type': 'argument_list', 'children': []},{'id': '234', 'type': 'keyword_argument', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '236', 'type': '()', 'children': ['237']},{'id': '237', 'type': 'comparison_operator', 'children': ['238', '239'], 'value': '=='},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'sort_dir'},{'id': '239', 'type': 'string', 'children': [], 'value': "'desc'"},{'id': '240', 'type': 'else_clause', 'children': ['241']},{'id': '241', 'type': 'block', 'children': ['242']},{'id': '242', 'type': 'expression_statement', 'children': ['243']},{'id': '243', 'type': 'assignment', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'images'},{'id': '245', 'type': 'call', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '247', 'type': 'argument_list', 'children': ['248']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'images_iter'},{'id': '249', 'type': 'expression_statement', 'children': ['250']},{'id': '250', 'type': 'assignment', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'wrapped_images'},{'id': '252', 'type': 'list', 'children': [], 'value': '[]'},{'id': '253', 'type': 'for_statement', 'children': ['254', '255', '256']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'images'},{'id': '256', 'type': 'block', 'children': ['257']},{'id': '257', 'type': 'expression_statement', 'children': ['258']},{'id': '258', 'type': 'call', 'children': ['259', '262']},{'id': '259', 'type': 'attribute', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'wrapped_images'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '262', 'type': 'argument_list', 'children': ['263']},{'id': '263', 'type': 'call', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'Image'},{'id': '265', 'type': 'argument_list', 'children': ['266']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '267', 'type': 'return_statement', 'children': ['268']},{'id': '268', 'type': 'expression_list', 'children': ['269', '270', '271']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'wrapped_images'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'has_more_data'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'has_prev_data'}
def image_list_detailed(request, marker=None, sort_dir='desc', sort_key='created_at', filters=None, paginate=False, reversed_order=False, **kwargs): limit = getattr(settings, 'API_RESULT_LIMIT', 1000) page_size = utils.get_page_size(request) if paginate: request_size = page_size + 1 else: request_size = limit _normalize_list_input(filters, **kwargs) kwargs = {'filters': filters or {}} if marker: kwargs['marker'] = marker kwargs['sort_key'] = sort_key if not reversed_order: kwargs['sort_dir'] = sort_dir else: kwargs['sort_dir'] = 'desc' if sort_dir == 'asc' else 'asc' images_iter = glanceclient(request).images.list(page_size=request_size, limit=limit, **kwargs) has_prev_data = False has_more_data = False if paginate: images = list(itertools.islice(images_iter, request_size)) if len(images) > page_size: images.pop(-1) has_more_data = True if marker is not None: has_prev_data = True elif reversed_order and marker is not None: has_more_data = True elif marker is not None: has_prev_data = True if reversed_order: images = sorted(images, key=lambda image: (getattr(image, sort_key) or '').lower(), reverse=(sort_dir == 'desc')) else: images = list(images_iter) wrapped_images = [] for image in images: wrapped_images.append(Image(image)) return wrapped_images, has_more_data, has_prev_data
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'metadefs_namespace_list'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'sort_dir'},{'id': '10', 'type': 'string', 'children': [], 'value': "'asc'"},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '13', 'type': 'string', 'children': [], 'value': "'namespace'"},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'marker'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'paginate'},{'id': '19', 'type': 'False', 'children': []},{'id': '20', 'type': 'block', 'children': ['21', '33', '42', '51', '60', '75', '82', '91', '97', '103', '125', '134', '143', '157', '161', '165', '241', '252']},{'id': '21', 'type': 'if_statement', 'children': ['22', '27']},{'id': '22', 'type': 'comparison_operator', 'children': ['23', '26'], 'value': '<'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'get_version'},{'id': '25', 'type': 'argument_list', 'children': []},{'id': '26', 'type': 'integer', 'children': [], 'value': '2'},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'return_statement', 'children': ['29']},{'id': '29', 'type': 'expression_list', 'children': ['30', '31', '32']},{'id': '30', 'type': 'list', 'children': [], 'value': '[]'},{'id': '31', 'type': 'False', 'children': []},{'id': '32', 'type': 'False', 'children': []},{'id': '33', 'type': 'if_statement', 'children': ['34', '37']},{'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': 'is'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'filters'},{'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': 'filters'},{'id': '41', 'type': 'dictionary', 'children': []},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '47', 'type': 'argument_list', 'children': ['48', '49', '50']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '49', 'type': 'string', 'children': [], 'value': "'API_RESULT_LIMIT'"},{'id': '50', 'type': 'integer', 'children': [], 'value': '1000'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'get_page_size'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '60', 'type': 'if_statement', 'children': ['61', '62', '69']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'paginate'},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'request_size'},{'id': '66', 'type': 'binary_operator', 'children': ['67', '68'], 'value': '+'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '68', 'type': 'integer', 'children': [], 'value': '1'},{'id': '69', 'type': 'else_clause', 'children': ['70']},{'id': '70', 'type': 'block', 'children': ['71']},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'request_size'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '78', 'type': 'dictionary', 'children': ['79']},{'id': '79', 'type': 'pair', 'children': ['80', '81']},{'id': '80', 'type': 'string', 'children': [], 'value': "'filters'"},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '82', 'type': 'if_statement', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'marker'},{'id': '84', 'type': 'block', 'children': ['85']},{'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': 'kwargs'},{'id': '89', 'type': 'string', 'children': [], 'value': "'marker'"},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'marker'},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '96']},{'id': '93', 'type': 'subscript', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '95', 'type': 'string', 'children': [], 'value': "'sort_dir'"},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'sort_dir'},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '102']},{'id': '99', 'type': 'subscript', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '101', 'type': 'string', 'children': [], 'value': "'sort_key'"},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'namespaces_iter'},{'id': '106', 'type': 'call', 'children': ['107', '116']},{'id': '107', 'type': 'attribute', 'children': ['108', '115']},{'id': '108', 'type': 'attribute', 'children': ['109', '114']},{'id': '109', 'type': 'call', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'glanceclient'},{'id': '111', 'type': 'argument_list', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '113', 'type': 'string', 'children': [], 'value': "'2'"},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'metadefs_namespace'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '116', 'type': 'argument_list', 'children': ['117', '120', '123']},{'id': '117', 'type': 'keyword_argument', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'request_size'},{'id': '120', 'type': 'keyword_argument', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '123', 'type': 'dictionary_splat', 'children': ['124']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'resource_types'},{'id': '128', 'type': 'call', 'children': ['129', '132']},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'string', 'children': [], 'value': "'resource_types'"},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'properties_target'},{'id': '137', 'type': 'call', 'children': ['138', '141']},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'string', 'children': [], 'value': "'properties_target'"},{'id': '143', 'type': 'if_statement', 'children': ['144', '147']},{'id': '144', 'type': 'boolean_operator', 'children': ['145', '146'], 'value': 'and'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'resource_types'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'properties_target'},{'id': '147', 'type': 'block', 'children': ['148']},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'namespaces_iter'},{'id': '151', 'type': 'call', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'filter_properties_target'},{'id': '153', 'type': 'argument_list', 'children': ['154', '155', '156']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'namespaces_iter'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'resource_types'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'properties_target'},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'has_prev_data'},{'id': '160', 'type': 'False', 'children': []},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'has_more_data'},{'id': '164', 'type': 'False', 'children': []},{'id': '165', 'type': 'if_statement', 'children': ['166', '167', '232']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'paginate'},{'id': '167', 'type': 'block', 'children': ['168', '181']},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'assignment', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'namespaces'},{'id': '171', 'type': 'call', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '173', 'type': 'argument_list', 'children': ['174']},{'id': '174', 'type': 'call', 'children': ['175', '178']},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'itertools'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'islice'},{'id': '178', 'type': 'argument_list', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'namespaces_iter'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'request_size'},{'id': '181', 'type': 'if_statement', 'children': ['182', '188', '210', '223']},{'id': '182', 'type': 'comparison_operator', 'children': ['183', '187'], 'value': '>'},{'id': '183', 'type': 'call', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '185', 'type': 'argument_list', 'children': ['186']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'namespaces'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '188', 'type': 'block', 'children': ['189', '197', '201']},{'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': 'namespaces'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '194', 'type': 'argument_list', 'children': ['195']},{'id': '195', 'type': 'unary_operator', 'children': ['196'], 'value': '-'},{'id': '196', 'type': 'integer', 'children': [], 'value': '1'},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'assignment', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'has_more_data'},{'id': '200', 'type': 'True', 'children': []},{'id': '201', 'type': 'if_statement', 'children': ['202', '205']},{'id': '202', 'type': 'comparison_operator', 'children': ['203', '204'], 'value': 'is'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'marker'},{'id': '204', 'type': 'None', 'children': []},{'id': '205', 'type': 'block', 'children': ['206']},{'id': '206', 'type': 'expression_statement', 'children': ['207']},{'id': '207', 'type': 'assignment', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'has_prev_data'},{'id': '209', 'type': 'True', 'children': []},{'id': '210', 'type': 'elif_clause', 'children': ['211', '218']},{'id': '211', 'type': 'boolean_operator', 'children': ['212', '215'], 'value': 'and'},{'id': '212', 'type': 'comparison_operator', 'children': ['213', '214'], 'value': '=='},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'sort_dir'},{'id': '214', 'type': 'string', 'children': [], 'value': "'desc'"},{'id': '215', 'type': 'comparison_operator', 'children': ['216', '217'], 'value': 'is'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'marker'},{'id': '217', 'type': 'None', 'children': []},{'id': '218', 'type': 'block', 'children': ['219']},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'assignment', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'has_more_data'},{'id': '222', 'type': 'True', 'children': []},{'id': '223', 'type': 'elif_clause', 'children': ['224', '227']},{'id': '224', 'type': 'comparison_operator', 'children': ['225', '226'], 'value': 'is'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'marker'},{'id': '226', 'type': 'None', 'children': []},{'id': '227', 'type': 'block', 'children': ['228']},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'assignment', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'has_prev_data'},{'id': '231', 'type': 'True', 'children': []},{'id': '232', 'type': 'else_clause', 'children': ['233']},{'id': '233', 'type': 'block', 'children': ['234']},{'id': '234', 'type': 'expression_statement', 'children': ['235']},{'id': '235', 'type': 'assignment', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'namespaces'},{'id': '237', 'type': 'call', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '239', 'type': 'argument_list', 'children': ['240']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'namespaces_iter'},{'id': '241', 'type': 'expression_statement', 'children': ['242']},{'id': '242', 'type': 'assignment', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'namespaces'},{'id': '244', 'type': 'list_comprehension', 'children': ['245', '249']},{'id': '245', 'type': 'call', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'Namespace'},{'id': '247', 'type': 'argument_list', 'children': ['248']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'namespace'},{'id': '249', 'type': 'for_in_clause', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'namespace'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'namespaces'},{'id': '252', 'type': 'return_statement', 'children': ['253']},{'id': '253', 'type': 'expression_list', 'children': ['254', '255', '256']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'namespaces'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'has_more_data'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'has_prev_data'}
def metadefs_namespace_list(request, filters=None, sort_dir='asc', sort_key='namespace', marker=None, paginate=False): if get_version() < 2: return [], False, False if filters is None: filters = {} limit = getattr(settings, 'API_RESULT_LIMIT', 1000) page_size = utils.get_page_size(request) if paginate: request_size = page_size + 1 else: request_size = limit kwargs = {'filters': filters} if marker: kwargs['marker'] = marker kwargs['sort_dir'] = sort_dir kwargs['sort_key'] = sort_key namespaces_iter = glanceclient(request, '2').metadefs_namespace.list( page_size=request_size, limit=limit, **kwargs) resource_types = filters.get('resource_types') properties_target = filters.get('properties_target') if resource_types and properties_target: namespaces_iter = filter_properties_target(namespaces_iter, resource_types, properties_target) has_prev_data = False has_more_data = False if paginate: namespaces = list(itertools.islice(namespaces_iter, request_size)) if len(namespaces) > page_size: namespaces.pop(-1) has_more_data = True if marker is not None: has_prev_data = True elif sort_dir == 'desc' and marker is not None: has_more_data = True elif marker is not None: has_prev_data = True else: namespaces = list(namespaces_iter) namespaces = [Namespace(namespace) for namespace in namespaces] return namespaces, has_more_data, has_prev_data
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_js_files'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'js_files'},{'id': '5', 'type': 'block', 'children': ['6', '21', '36', '51', '84', '90']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'modules'},{'id': '9', 'type': 'list_comprehension', 'children': ['10', '11', '14']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '11', 'type': 'for_in_clause', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'js_files'},{'id': '14', 'type': 'if_clause', 'children': ['15']},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'MODULE_EXT'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'mocks'},{'id': '24', 'type': 'list_comprehension', 'children': ['25', '26', '29']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '26', 'type': 'for_in_clause', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'js_files'},{'id': '29', 'type': 'if_clause', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'MOCK_EXT'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'specs'},{'id': '39', 'type': 'list_comprehension', 'children': ['40', '41', '44']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '41', 'type': 'for_in_clause', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'js_files'},{'id': '44', 'type': 'if_clause', 'children': ['45']},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'SPEC_EXT'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'other_sources'},{'id': '54', 'type': 'list_comprehension', 'children': ['55', '56', '59']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '56', 'type': 'for_in_clause', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'js_files'},{'id': '59', 'type': 'if_clause', 'children': ['60']},{'id': '60', 'type': '()', 'children': ['61']},{'id': '61', 'type': 'boolean_operator', 'children': ['62', '77'], 'value': 'and'},{'id': '62', 'type': 'boolean_operator', 'children': ['63', '70'], 'value': 'and'},{'id': '63', 'type': 'not_operator', 'children': ['64']},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'MODULE_EXT'},{'id': '70', 'type': 'not_operator', 'children': ['71']},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'MOCK_EXT'},{'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': 'f'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'SPEC_EXT'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'sources'},{'id': '87', 'type': 'binary_operator', 'children': ['88', '89'], 'value': '+'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'modules'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'other_sources'},{'id': '90', 'type': 'return_statement', 'children': ['91']},{'id': '91', 'type': 'expression_list', 'children': ['92', '93', '94']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'sources'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'mocks'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'specs'}
def sort_js_files(js_files): modules = [f for f in js_files if f.endswith(MODULE_EXT)] mocks = [f for f in js_files if f.endswith(MOCK_EXT)] specs = [f for f in js_files if f.endswith(SPEC_EXT)] other_sources = [f for f in js_files if (not f.endswith(MODULE_EXT) and not f.endswith(MOCK_EXT) and not f.endswith(SPEC_EXT))] sources = modules + other_sources return sources, mocks, specs
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_slice_mostly_sorted'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'keep'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'rest'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'ind'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'block', 'children': ['11', '28', '46', '50', '70', '80', '97', '131', '160', '177']},{'id': '11', 'type': 'if_statement', 'children': ['12', '15']},{'id': '12', 'type': 'comparison_operator', 'children': ['13', '14'], 'value': 'is'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'ind'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'ind'},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'arange'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'idx'},{'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': 'argsort'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'concatenate'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'list', 'children': ['42', '43'], 'value': '[keep, ind[rest]]'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'keep'},{'id': '43', 'type': 'subscript', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'ind'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'rest'},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'slices'},{'id': '49', 'type': 'list', 'children': [], 'value': '[]'},{'id': '50', 'type': 'if_statement', 'children': ['51', '56']},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '55'], 'value': '>'},{'id': '52', 'type': 'subscript', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'keep'},{'id': '54', 'type': 'integer', 'children': [], 'value': '0'},{'id': '55', 'type': 'integer', 'children': [], 'value': '0'},{'id': '56', 'type': 'block', 'children': ['57']},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'slices'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'slice'},{'id': '65', 'type': 'argument_list', 'children': ['66', '67']},{'id': '66', 'type': 'None', 'children': []},{'id': '67', 'type': 'subscript', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'keep'},{'id': '69', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'slices'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'list', 'children': ['77'], 'value': '[keep[0]]'},{'id': '77', 'type': 'subscript', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'keep'},{'id': '79', 'type': 'integer', 'children': [], 'value': '0'},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'windows'},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '85', 'type': 'argument_list', 'children': ['86', '92']},{'id': '86', 'type': 'subscript', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'keep'},{'id': '88', 'type': 'slice', 'children': ['89', '90']},{'id': '89', 'type': 'colon', 'children': []},{'id': '90', 'type': 'unary_operator', 'children': ['91'], 'value': '-'},{'id': '91', 'type': 'integer', 'children': [], 'value': '1'},{'id': '92', 'type': 'subscript', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'keep'},{'id': '94', 'type': 'slice', 'children': ['95', '96']},{'id': '95', 'type': 'integer', 'children': [], 'value': '1'},{'id': '96', 'type': 'colon', 'children': []},{'id': '97', 'type': 'for_statement', 'children': ['98', '101', '102']},{'id': '98', 'type': 'pattern_list', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'windows'},{'id': '102', 'type': 'block', 'children': ['103', '123']},{'id': '103', 'type': 'if_statement', 'children': ['104', '109']},{'id': '104', 'type': 'comparison_operator', 'children': ['105', '106'], 'value': '>'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '106', 'type': 'binary_operator', 'children': ['107', '108'], 'value': '+'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '108', 'type': 'integer', 'children': [], 'value': '1'},{'id': '109', 'type': 'block', 'children': ['110']},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'slices'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'call', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'slice'},{'id': '118', 'type': 'argument_list', 'children': ['119', '122']},{'id': '119', 'type': 'binary_operator', 'children': ['120', '121'], 'value': '+'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '121', 'type': 'integer', 'children': [], 'value': '1'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'call', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'slices'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'list', 'children': ['130'], 'value': '[r]'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '131', 'type': 'if_statement', 'children': ['132', '143']},{'id': '132', 'type': 'comparison_operator', 'children': ['133', '137'], 'value': '<'},{'id': '133', 'type': 'subscript', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'keep'},{'id': '135', 'type': 'unary_operator', 'children': ['136'], 'value': '-'},{'id': '136', 'type': 'integer', 'children': [], 'value': '1'},{'id': '137', 'type': 'binary_operator', 'children': ['138', '142'], 'value': '-'},{'id': '138', 'type': 'call', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '142', 'type': 'integer', 'children': [], 'value': '1'},{'id': '143', 'type': 'block', 'children': ['144']},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'call', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'slices'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '149', 'type': 'argument_list', 'children': ['150']},{'id': '150', 'type': 'call', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'slice'},{'id': '152', 'type': 'argument_list', 'children': ['153', '159']},{'id': '153', 'type': 'binary_operator', 'children': ['154', '158'], 'value': '+'},{'id': '154', 'type': 'subscript', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'keep'},{'id': '156', 'type': 'unary_operator', 'children': ['157'], 'value': '-'},{'id': '157', 'type': 'integer', 'children': [], 'value': '1'},{'id': '158', 'type': 'integer', 'children': [], 'value': '1'},{'id': '159', 'type': 'None', 'children': []},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '163', 'type': 'call', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'da'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'concatenate'},{'id': '167', 'type': 'argument_list', 'children': ['168']},{'id': '168', 'type': 'list_comprehension', 'children': ['169', '174']},{'id': '169', 'type': 'subscript', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '171', 'type': 'subscript', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'slice_'},{'id': '174', 'type': 'for_in_clause', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'slice_'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'slices'},{'id': '177', 'type': 'return_statement', 'children': ['178']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'result'}
def _slice_mostly_sorted(array, keep, rest, ind=None): if ind is None: ind = np.arange(len(array)) idx = np.argsort(np.concatenate([keep, ind[rest]])) slices = [] if keep[0] > 0: slices.append(slice(None, keep[0])) slices.append([keep[0]]) windows = zip(keep[:-1], keep[1:]) for l, r in windows: if r > l + 1: slices.append(slice(l + 1, r)) slices.append([r]) if keep[-1] < len(array) - 1: slices.append(slice(keep[-1] + 1, None)) result = da.concatenate([array[idx[slice_]] for slice_ in slices]) return result
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12', '24']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_servers_closest'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'servers'},{'id': '6', 'type': 'type', 'children': ['7']},{'id': '7', 'type': 'generic_type', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'Sequence'},{'id': '9', 'type': 'type_parameter', 'children': ['10']},{'id': '10', 'type': 'type', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '12', 'type': 'type', 'children': ['13']},{'id': '13', 'type': 'generic_type', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'Sequence'},{'id': '15', 'type': 'type_parameter', 'children': ['16']},{'id': '16', 'type': 'type', 'children': ['17']},{'id': '17', 'type': 'generic_type', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'Tuple'},{'id': '19', 'type': 'type_parameter', 'children': ['20', '22']},{'id': '20', 'type': 'type', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '22', 'type': 'type', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '24', 'type': 'block', 'children': ['25', '50', '74', '84', '123', '133']},{'id': '25', 'type': 'if_statement', 'children': ['26', '44']},{'id': '26', 'type': 'not_operator', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '40']},{'id': '28', 'type': 'attribute', 'children': ['29', '39']},{'id': '29', 'type': 'set_comprehension', 'children': ['30', '36']},{'id': '30', 'type': 'attribute', 'children': ['31', '35']},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'urlparse'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'id': '36', 'type': 'for_in_clause', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'servers'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'issubset'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'set', 'children': ['42', '43']},{'id': '42', 'type': 'string', 'children': [], 'value': "'http'"},{'id': '43', 'type': 'string', 'children': [], 'value': "'https'"},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'raise_statement', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'TransportError'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'string', 'children': [], 'value': "'Invalid server urls'"},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'get_rtt_jobs'},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '55', 'type': 'generator_expression', 'children': ['56', '71']},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'gevent'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'spawn'},{'id': '60', 'type': 'argument_list', 'children': ['61', '70']},{'id': '61', 'type': 'lambda', 'children': ['62', '64']},{'id': '62', 'type': 'lambda_parameters', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '64', 'type': 'tuple', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '66', 'type': 'call', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'get_http_rtt'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'server_url'},{'id': '71', 'type': 'for_in_clause', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'server_url'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'servers'},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'gevent'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'joinall'},{'id': '79', 'type': 'argument_list', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'get_rtt_jobs'},{'id': '81', 'type': 'keyword_argument', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'raise_error'},{'id': '83', 'type': 'False', 'children': []},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87', '99']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'sorted_servers'},{'id': '87', 'type': 'type', 'children': ['88']},{'id': '88', 'type': 'generic_type', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'List'},{'id': '90', 'type': 'type_parameter', 'children': ['91']},{'id': '91', 'type': 'type', 'children': ['92']},{'id': '92', 'type': 'generic_type', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'Tuple'},{'id': '94', 'type': 'type_parameter', 'children': ['95', '97']},{'id': '95', 'type': 'type', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '97', 'type': 'type', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '99', 'type': 'call', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '101', 'type': 'argument_list', 'children': ['102', '117']},{'id': '102', 'type': 'generator_expression', 'children': ['103', '106', '109']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '106', 'type': 'for_in_clause', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'get_rtt_jobs'},{'id': '109', 'type': 'if_clause', 'children': ['110']},{'id': '110', 'type': 'comparison_operator', 'children': ['111', '116'], 'value': 'is'},{'id': '111', 'type': 'subscript', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '115', 'type': 'integer', 'children': [], 'value': '1'},{'id': '116', 'type': 'None', 'children': []},{'id': '117', 'type': 'keyword_argument', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '119', 'type': 'call', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'itemgetter'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'integer', 'children': [], 'value': '1'},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'call', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '128', 'type': 'argument_list', 'children': ['129', '130']},{'id': '129', 'type': 'string', 'children': [], 'value': "'Matrix homeserver RTT times'"},{'id': '130', 'type': 'keyword_argument', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'rtt_times'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'sorted_servers'},{'id': '133', 'type': 'return_statement', 'children': ['134']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'sorted_servers'}
def sort_servers_closest(servers: Sequence[str]) -> Sequence[Tuple[str, float]]: if not {urlparse(url).scheme for url in servers}.issubset({'http', 'https'}): raise TransportError('Invalid server urls') get_rtt_jobs = set( gevent.spawn(lambda url: (url, get_http_rtt(url)), server_url) for server_url in servers ) gevent.joinall(get_rtt_jobs, raise_error=False) sorted_servers: List[Tuple[str, float]] = sorted( (job.value for job in get_rtt_jobs if job.value[1] is not None), key=itemgetter(1), ) log.debug('Matrix homeserver RTT times', rtt_times=sorted_servers) return sorted_servers
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_runs_by_id'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'config_id'},{'id': '6', 'type': 'block', 'children': ['7', '15', '19', '108', '122']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '10', 'type': 'subscript', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'config_id'},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'runs'},{'id': '18', 'type': 'list', 'children': [], 'value': '[]'},{'id': '19', 'type': 'for_statement', 'children': ['20', '21', '28']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'b'},{'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': 'd'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '27', 'type': 'argument_list', 'children': []},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'try_statement', 'children': ['30', '105']},{'id': '30', 'type': 'block', 'children': ['31', '43', '98']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'err_logs'},{'id': '34', 'type': 'call', 'children': ['35', '40']},{'id': '35', 'type': 'attribute', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'exceptions'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '40', 'type': 'argument_list', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '42', 'type': 'None', 'children': []},{'id': '43', 'type': 'if_statement', 'children': ['44', '51', '68']},{'id': '44', 'type': 'comparison_operator', 'children': ['45', '50'], 'value': 'is'},{'id': '45', 'type': 'subscript', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '50', 'type': 'None', 'children': []},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'Run'},{'id': '57', 'type': 'argument_list', 'children': ['58', '59', '60', '61', '62', '67']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'config_id'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '60', 'type': 'None', 'children': []},{'id': '61', 'type': 'None', 'children': []},{'id': '62', 'type': 'subscript', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'time_stamps'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'err_logs'},{'id': '68', 'type': 'else_clause', 'children': ['69']},{'id': '69', 'type': 'block', 'children': ['70']},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'Run'},{'id': '75', 'type': 'argument_list', 'children': ['76', '77', '78', '85', '92', '97']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'config_id'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '78', 'type': 'subscript', 'children': ['79', '84']},{'id': '79', 'type': 'subscript', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '84', 'type': 'string', 'children': [], 'value': "'loss'"},{'id': '85', 'type': 'subscript', 'children': ['86', '91']},{'id': '86', 'type': 'subscript', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '91', 'type': 'string', 'children': [], 'value': "'info'"},{'id': '92', 'type': 'subscript', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'time_stamps'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'err_logs'},{'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': 'runs'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '105', 'type': 'except_clause', 'children': ['106']},{'id': '106', 'type': 'block', 'children': ['107']},{'id': '107', 'type': 'raise_statement', 'children': []},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'call', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'runs'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'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': 'r'},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'budget'},{'id': '122', 'type': 'return_statement', 'children': ['123']},{'id': '123', 'type': '()', 'children': ['124']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'runs'}
def get_runs_by_id(self, config_id): d = self.data[config_id] runs = [] for b in d.results.keys(): try: err_logs = d.exceptions.get(b, None) if d.results[b] is None: r = Run(config_id, b, None, None , d.time_stamps[b], err_logs) else: r = Run(config_id, b, d.results[b]['loss'], d.results[b]['info'] , d.time_stamps[b], err_logs) runs.append(r) except: raise runs.sort(key=lambda r: r.budget) return(runs)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'spell'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '7', 'type': 'type', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '9', 'type': 'type', 'children': ['10']},{'id': '10', 'type': 'generic_type', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'List'},{'id': '12', 'type': 'type_parameter', 'children': ['13']},{'id': '13', 'type': 'type', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '15', 'type': 'block', 'children': ['16', '22', '56', '70']},{'id': '16', 'type': 'if_statement', 'children': ['17', '19']},{'id': '17', 'type': 'not_operator', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'return_statement', 'children': ['21']},{'id': '21', 'type': 'string', 'children': [], 'value': '""'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'candidates'},{'id': '25', 'type': '()', 'children': ['26']},{'id': '26', 'type': 'boolean_operator', 'children': ['27', '54'], 'value': 'or'},{'id': '27', 'type': 'boolean_operator', 'children': ['28', '45'], 'value': 'or'},{'id': '28', 'type': 'boolean_operator', 'children': ['29', '36'], 'value': 'or'},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'known'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'list', 'children': ['35'], 'value': '[word]'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'word'},{'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': 'known'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': '_edits1'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'word'},{'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': 'known'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': '_edits2'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '54', 'type': 'list', 'children': ['55'], 'value': '[word]'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'word'},{'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': 'candidates'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '61', 'type': 'argument_list', 'children': ['62', '67']},{'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'freq'},{'id': '67', 'type': 'keyword_argument', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '69', 'type': 'True', 'children': []},{'id': '70', 'type': 'return_statement', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'candidates'}
def spell(self, word: str) -> List[str]: if not word: return "" candidates = ( self.known([word]) or self.known(_edits1(word)) or self.known(_edits2(word)) or [word] ) candidates.sort(key=self.freq, reverse=True) return candidates
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17', '19']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'rank'},{'id': '3', 'type': 'parameters', 'children': ['4', '12']},{'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'words'},{'id': '6', 'type': 'type', 'children': ['7']},{'id': '7', 'type': 'generic_type', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'List'},{'id': '9', 'type': 'type_parameter', 'children': ['10']},{'id': '10', 'type': 'type', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '12', 'type': 'typed_default_parameter', 'children': ['13', '14', '16']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'exclude_stopwords'},{'id': '14', 'type': 'type', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '16', 'type': 'False', 'children': []},{'id': '17', 'type': 'type', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'Counter'},{'id': '19', 'type': 'block', 'children': ['20', '26', '41']},{'id': '20', 'type': 'if_statement', 'children': ['21', '23']},{'id': '21', 'type': 'not_operator', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'words'},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'return_statement', 'children': ['25']},{'id': '25', 'type': 'None', 'children': []},{'id': '26', 'type': 'if_statement', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'exclude_stopwords'},{'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': 'words'},{'id': '32', 'type': 'list_comprehension', 'children': ['33', '34', '37']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '34', 'type': 'for_in_clause', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'words'},{'id': '37', 'type': 'if_clause', 'children': ['38']},{'id': '38', 'type': 'comparison_operator', 'children': ['39', '40'], 'value': 'not'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '40', 'type': 'identifier', 'children': [], 'value': '_STOPWORDS'},{'id': '41', 'type': 'return_statement', 'children': ['42']},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'Counter'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'words'}
def rank(words: List[str], exclude_stopwords: bool = False) -> Counter: if not words: return None if exclude_stopwords: words = [word for word in words if word not in _STOPWORDS] return Counter(words)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'iter'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '7', 'type': 'integer', 'children': [], 'value': '0'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'pagesize'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'dictionary_splat_pattern', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '16', 'type': 'block', 'children': ['17', '25', '36', '40']},{'id': '17', 'type': 'assert_statement', 'children': ['18']},{'id': '18', 'type': 'boolean_operator', 'children': ['19', '22'], 'value': 'or'},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': 'is'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'pagesize'},{'id': '21', 'type': 'None', 'children': []},{'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': '>'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'pagesize'},{'id': '24', 'type': 'integer', 'children': [], 'value': '0'},{'id': '25', 'type': 'if_statement', 'children': ['26', '29']},{'id': '26', 'type': 'comparison_operator', 'children': ['27', '28'], 'value': 'is'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '28', 'type': 'None', 'children': []},{'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': 'count'},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'null_count'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'fetched'},{'id': '39', 'type': 'integer', 'children': [], 'value': '0'},{'id': '40', 'type': 'while_statement', 'children': ['41', '50']},{'id': '41', 'type': 'boolean_operator', 'children': ['42', '47'], 'value': 'or'},{'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': '=='},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'null_count'},{'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': '<'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'fetched'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '50', 'type': 'block', 'children': ['51', '69', '78', '85', '89', '96', '106', '110']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '58', 'type': 'argument_list', 'children': ['59', '64', '67']},{'id': '59', 'type': 'keyword_argument', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '61', 'type': 'boolean_operator', 'children': ['62', '63'], 'value': 'or'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'pagesize'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '64', 'type': 'keyword_argument', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '67', 'type': 'dictionary_splat', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '75', 'type': 'identifier', 'children': [], 'value': '_load_list'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'augmented_assignment', 'children': ['87', '88'], 'value': '+='},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'fetched'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '89', 'type': 'for_statement', 'children': ['90', '91', '92']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '92', 'type': 'block', 'children': ['93']},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'yield', 'children': ['95']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '96', 'type': 'if_statement', 'children': ['97', '104']},{'id': '97', 'type': 'boolean_operator', 'children': ['98', '101'], 'value': 'or'},{'id': '98', 'type': 'comparison_operator', 'children': ['99', '100'], 'value': 'is'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'pagesize'},{'id': '100', 'type': 'None', 'children': []},{'id': '101', 'type': 'comparison_operator', 'children': ['102', '103'], 'value': '<'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'pagesize'},{'id': '104', 'type': 'block', 'children': ['105']},{'id': '105', 'type': 'break_statement', 'children': []},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'augmented_assignment', 'children': ['108', '109'], 'value': '+='},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '115', 'type': 'argument_list', 'children': ['116', '117', '118', '119', '120', '121']},{'id': '116', 'type': 'string', 'children': [], 'value': '"pagesize=%d, fetched=%d, offset=%d, N=%d, kwargs=%s"'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'pagesize'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'fetched'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'kwargs'}
def iter(self, offset=0, count=None, pagesize=None, **kwargs): assert pagesize is None or pagesize > 0 if count is None: count = self.null_count fetched = 0 while count == self.null_count or fetched < count: response = self.get(count=pagesize or count, offset=offset, **kwargs) items = self._load_list(response) N = len(items) fetched += N for item in items: yield item if pagesize is None or N < pagesize: break offset += N logging.debug("pagesize=%d, fetched=%d, offset=%d, N=%d, kwargs=%s", pagesize, fetched, offset, N, kwargs)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'list'},{'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': 'count'},{'id': '7', 'type': 'None', 'children': []},{'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', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '19', 'type': 'argument_list', 'children': ['20', '23']},{'id': '20', 'type': 'keyword_argument', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '23', 'type': 'dictionary_splat', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'kwargs'}
def list(self, count=None, **kwargs): return list(self.iter(count=count, **kwargs))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'query'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '7', 'type': 'block', 'children': ['8']},{'id': '8', 'type': 'return_statement', 'children': ['9']},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'loads'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'call', 'children': ['15', '31']},{'id': '15', 'type': 'attribute', 'children': ['16', '30']},{'id': '16', 'type': 'call', 'children': ['17', '29']},{'id': '17', 'type': 'attribute', 'children': ['18', '28']},{'id': '18', 'type': 'attribute', 'children': ['19', '27']},{'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': '_get'},{'id': '23', 'type': 'argument_list', 'children': ['24', '25']},{'id': '24', 'type': 'string', 'children': [], 'value': "''"},{'id': '25', 'type': 'dictionary_splat', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '29', 'type': 'argument_list', 'children': []},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'string', 'children': [], 'value': "'utf-8'"}
def query(self, **query): return json.loads(self._get('', **query).body.read().decode('utf-8'))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '28']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'query'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'area'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'date'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'raw'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'area_relation'},{'id': '16', 'type': 'string', 'children': [], 'value': "'Intersects'"},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '25', 'type': 'integer', 'children': [], 'value': '0'},{'id': '26', 'type': 'dictionary_splat_pattern', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '28', 'type': 'block', 'children': ['29', '43', '56', '63', '77', '87']},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'format_query'},{'id': '36', 'type': 'argument_list', 'children': ['37', '38', '39', '40', '41']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'area'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'date'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'raw'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'area_relation'},{'id': '41', 'type': 'dictionary_splat', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'call', 'children': ['45', '50']},{'id': '45', 'type': 'attribute', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '50', 'type': 'argument_list', 'children': ['51', '52', '53', '54', '55']},{'id': '51', 'type': 'string', 'children': [], 'value': '"Running query: order_by=%s, limit=%s, offset=%s, query=%s"'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'formatted_order_by'},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': '_format_order_by'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '68']},{'id': '65', 'type': 'pattern_list', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '71', 'type': 'identifier', 'children': [], 'value': '_load_query'},{'id': '72', 'type': 'argument_list', 'children': ['73', '74', '75', '76']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'formatted_order_by'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'call', 'children': ['79', '84']},{'id': '79', 'type': 'attribute', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '84', 'type': 'argument_list', 'children': ['85', '86']},{'id': '85', 'type': 'string', 'children': [], 'value': '"Found %s products"'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '87', 'type': 'return_statement', 'children': ['88']},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': '_parse_opensearch_response'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'response'}
def query(self, area=None, date=None, raw=None, area_relation='Intersects', order_by=None, limit=None, offset=0, **keywords): query = self.format_query(area, date, raw, area_relation, **keywords) self.logger.debug("Running query: order_by=%s, limit=%s, offset=%s, query=%s", order_by, limit, offset, query) formatted_order_by = _format_order_by(order_by) response, count = self._load_query(query, formatted_order_by, limit, offset) self.logger.info("Found %s products", count) return _parse_opensearch_response(response)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_suggested_type_names'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'output_type'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'field_name'},{'id': '7', 'type': 'block', 'children': ['8', '128']},{'id': '8', 'type': 'if_statement', 'children': ['9', '16']},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '11', 'type': 'argument_list', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'output_type'},{'id': '13', 'type': 'tuple', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'GraphQLInterfaceType'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'GraphQLUnionType'},{'id': '16', 'type': 'block', 'children': ['17', '21', '27', '94', '119', '126']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'suggested_object_types'},{'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': 'interface_usage_count'},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '26', 'type': 'argument_list', 'children': []},{'id': '27', 'type': 'for_statement', 'children': ['28', '29', '35']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'possible_type'},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'get_possible_types'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'output_type'},{'id': '35', 'type': 'block', 'children': ['36', '48', '57']},{'id': '36', 'type': 'if_statement', 'children': ['37', '46']},{'id': '37', 'type': 'not_operator', 'children': ['38']},{'id': '38', 'type': 'call', 'children': ['39', '44']},{'id': '39', 'type': 'attribute', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'possible_type'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'field_name'},{'id': '46', 'type': 'block', 'children': ['47']},{'id': '47', 'type': 'return_statement', 'children': []},{'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': 'suggested_object_types'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'possible_type'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '57', 'type': 'for_statement', 'children': ['58', '59', '62']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'possible_interface'},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'possible_type'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'interfaces'},{'id': '62', 'type': 'block', 'children': ['63', '75']},{'id': '63', 'type': 'if_statement', 'children': ['64', '73']},{'id': '64', 'type': 'not_operator', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '71']},{'id': '66', 'type': 'attribute', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'possible_interface'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'field_name'},{'id': '73', 'type': 'block', 'children': ['74']},{'id': '74', 'type': 'continue_statement', 'children': []},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '82']},{'id': '77', 'type': 'subscript', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'interface_usage_count'},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'possible_interface'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '82', 'type': '()', 'children': ['83']},{'id': '83', 'type': 'binary_operator', 'children': ['84', '93'], 'value': '+'},{'id': '84', 'type': 'call', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'interface_usage_count'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '88', 'type': 'argument_list', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'possible_interface'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '92', 'type': 'integer', 'children': [], 'value': '0'},{'id': '93', 'type': 'integer', 'children': [], 'value': '1'},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'suggested_interface_types'},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '99', 'type': 'argument_list', 'children': ['100', '108', '116']},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'interface_usage_count'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '107', 'type': 'argument_list', 'children': []},{'id': '108', 'type': 'keyword_argument', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '110', 'type': 'lambda', 'children': ['111', '113']},{'id': '111', 'type': 'lambda_parameters', 'children': ['112']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '113', 'type': 'subscript', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'interface_usage_count'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '116', 'type': 'keyword_argument', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '118', 'type': 'True', 'children': []},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'call', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'suggested_interface_types'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'suggested_object_types'},{'id': '126', 'type': 'return_statement', 'children': ['127']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'suggested_interface_types'},{'id': '128', 'type': 'return_statement', 'children': ['129']},{'id': '129', 'type': 'list', 'children': [], 'value': '[]'}
def get_suggested_type_names(schema, output_type, field_name): if isinstance(output_type, (GraphQLInterfaceType, GraphQLUnionType)): suggested_object_types = [] interface_usage_count = OrderedDict() for possible_type in schema.get_possible_types(output_type): if not possible_type.fields.get(field_name): return suggested_object_types.append(possible_type.name) for possible_interface in possible_type.interfaces: if not possible_interface.fields.get(field_name): continue interface_usage_count[possible_interface.name] = ( interface_usage_count.get(possible_interface.name, 0) + 1 ) suggested_interface_types = sorted( list(interface_usage_count.keys()), key=lambda k: interface_usage_count[k], reverse=True, ) suggested_interface_types.extend(suggested_object_types) return suggested_interface_types return []
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'suggestion_list'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'inp'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '6', 'type': 'block', 'children': ['7', '13', '22', '59']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'options_by_distance'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '12', 'type': 'argument_list', 'children': []},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'input_threshold'},{'id': '16', 'type': 'binary_operator', 'children': ['17', '21'], 'value': '/'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'inp'},{'id': '21', 'type': 'integer', 'children': [], 'value': '2'},{'id': '22', 'type': 'for_statement', 'children': ['23', '24', '25']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'option'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '25', 'type': 'block', 'children': ['26', '34', '48']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'distance'},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'lexical_distance'},{'id': '31', 'type': 'argument_list', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'inp'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'option'},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '39', 'type': 'argument_list', 'children': ['40', '41', '47']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'input_threshold'},{'id': '41', 'type': 'binary_operator', 'children': ['42', '46'], 'value': '/'},{'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': 'option'},{'id': '46', 'type': 'integer', 'children': [], 'value': '2'},{'id': '47', 'type': 'integer', 'children': [], 'value': '1'},{'id': '48', 'type': 'if_statement', 'children': ['49', '52']},{'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': '<='},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'distance'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '52', 'type': 'block', 'children': ['53']},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '58']},{'id': '55', 'type': 'subscript', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'options_by_distance'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'option'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'distance'},{'id': '59', 'type': 'return_statement', 'children': ['60']},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '62', 'type': 'argument_list', 'children': ['63', '71']},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'options_by_distance'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '70', 'type': 'argument_list', 'children': []},{'id': '71', 'type': 'keyword_argument', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '73', 'type': 'lambda', 'children': ['74', '76']},{'id': '74', 'type': 'lambda_parameters', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '76', 'type': 'subscript', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'options_by_distance'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'k'}
def suggestion_list(inp, options): options_by_distance = OrderedDict() input_threshold = len(inp) / 2 for option in options: distance = lexical_distance(inp, option) threshold = max(input_threshold, len(option) / 2, 1) if distance <= threshold: options_by_distance[option] = distance return sorted( list(options_by_distance.keys()), key=lambda k: options_by_distance[k] )
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'lexical_distance'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '6', 'type': 'block', 'children': ['7', '26', '35', '80', '221']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '10', 'type': 'boolean_operator', 'children': ['11', '25'], 'value': 'or'},{'id': '11', 'type': 'list_comprehension', 'children': ['12', '14']},{'id': '12', 'type': 'list', 'children': ['13'], 'value': '[i]'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '14', 'type': 'for_in_clause', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'binary_operator', 'children': ['20', '24'], 'value': '+'},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '24', 'type': 'integer', 'children': [], 'value': '1'},{'id': '25', 'type': 'list', 'children': [], 'value': '[]'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'd_len'},{'id': '29', 'type': 'boolean_operator', 'children': ['30', '34'], 'value': 'or'},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '34', 'type': 'integer', 'children': [], 'value': '1'},{'id': '35', 'type': 'for_statement', 'children': ['36', '37', '41']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'd_len'},{'id': '41', 'type': 'block', 'children': ['42']},{'id': '42', 'type': 'for_statement', 'children': ['43', '44', '54']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '46', 'type': 'argument_list', 'children': ['47', '48']},{'id': '47', 'type': 'integer', 'children': [], 'value': '1'},{'id': '48', 'type': 'binary_operator', 'children': ['49', '53'], 'value': '+'},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '53', 'type': 'integer', 'children': [], 'value': '1'},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'if_statement', 'children': ['56', '59', '69']},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': '=='},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '58', 'type': 'integer', 'children': [], 'value': '0'},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'call', 'children': ['62', '67']},{'id': '62', 'type': 'attribute', 'children': ['63', '66']},{'id': '63', 'type': 'subscript', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '69', 'type': 'else_clause', 'children': ['70']},{'id': '70', 'type': 'block', 'children': ['71']},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'call', 'children': ['73', '78']},{'id': '73', 'type': 'attribute', 'children': ['74', '77']},{'id': '74', 'type': 'subscript', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'integer', 'children': [], 'value': '0'},{'id': '80', 'type': 'for_statement', 'children': ['81', '82', '92']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '84', 'type': 'argument_list', 'children': ['85', '86']},{'id': '85', 'type': 'integer', 'children': [], 'value': '1'},{'id': '86', 'type': 'binary_operator', 'children': ['87', '91'], 'value': '+'},{'id': '87', 'type': 'call', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '91', 'type': 'integer', 'children': [], 'value': '1'},{'id': '92', 'type': 'block', 'children': ['93']},{'id': '93', 'type': 'for_statement', 'children': ['94', '95', '105']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '95', 'type': 'call', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '97', 'type': 'argument_list', 'children': ['98', '99']},{'id': '98', 'type': 'integer', 'children': [], 'value': '1'},{'id': '99', 'type': 'binary_operator', 'children': ['100', '104'], 'value': '+'},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '104', 'type': 'integer', 'children': [], 'value': '1'},{'id': '105', 'type': 'block', 'children': ['106', '123', '162']},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'cost'},{'id': '109', 'type': 'conditional_expression', 'children': ['110', '111', '122'], 'value': 'if'},{'id': '110', 'type': 'integer', 'children': [], 'value': '0'},{'id': '111', 'type': 'comparison_operator', 'children': ['112', '117'], 'value': '=='},{'id': '112', 'type': 'subscript', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '114', 'type': 'binary_operator', 'children': ['115', '116'], 'value': '-'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '116', 'type': 'integer', 'children': [], 'value': '1'},{'id': '117', 'type': 'subscript', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '119', 'type': 'binary_operator', 'children': ['120', '121'], 'value': '-'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '121', 'type': 'integer', 'children': [], 'value': '1'},{'id': '122', 'type': 'integer', 'children': [], 'value': '1'},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'assignment', 'children': ['125', '130']},{'id': '125', 'type': 'subscript', 'children': ['126', '129']},{'id': '126', 'type': 'subscript', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '132', 'type': 'argument_list', 'children': ['133', '142', '151']},{'id': '133', 'type': 'binary_operator', 'children': ['134', '141'], 'value': '+'},{'id': '134', 'type': 'subscript', 'children': ['135', '140']},{'id': '135', 'type': 'subscript', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '137', 'type': 'binary_operator', 'children': ['138', '139'], 'value': '-'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '139', 'type': 'integer', 'children': [], 'value': '1'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '141', 'type': 'integer', 'children': [], 'value': '1'},{'id': '142', 'type': 'binary_operator', 'children': ['143', '150'], 'value': '+'},{'id': '143', 'type': 'subscript', 'children': ['144', '147']},{'id': '144', 'type': 'subscript', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '147', 'type': 'binary_operator', 'children': ['148', '149'], 'value': '-'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '149', 'type': 'integer', 'children': [], 'value': '1'},{'id': '150', 'type': 'integer', 'children': [], 'value': '1'},{'id': '151', 'type': 'binary_operator', 'children': ['152', '161'], 'value': '+'},{'id': '152', 'type': 'subscript', 'children': ['153', '158']},{'id': '153', 'type': 'subscript', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '155', 'type': 'binary_operator', 'children': ['156', '157'], 'value': '-'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '157', 'type': 'integer', 'children': [], 'value': '1'},{'id': '158', 'type': 'binary_operator', 'children': ['159', '160'], 'value': '-'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '160', 'type': 'integer', 'children': [], 'value': '1'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'cost'},{'id': '162', 'type': 'if_statement', 'children': ['163', '194']},{'id': '163', 'type': 'boolean_operator', 'children': ['164', '183'], 'value': 'and'},{'id': '164', 'type': 'boolean_operator', 'children': ['165', '172'], 'value': 'and'},{'id': '165', 'type': 'boolean_operator', 'children': ['166', '169'], 'value': 'and'},{'id': '166', 'type': 'comparison_operator', 'children': ['167', '168'], 'value': '>'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '168', 'type': 'integer', 'children': [], 'value': '1'},{'id': '169', 'type': 'comparison_operator', 'children': ['170', '171'], 'value': '<'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '171', 'type': 'integer', 'children': [], 'value': '1'},{'id': '172', 'type': 'comparison_operator', 'children': ['173', '178'], 'value': '=='},{'id': '173', 'type': 'subscript', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '175', 'type': 'binary_operator', 'children': ['176', '177'], 'value': '-'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '177', 'type': 'integer', 'children': [], 'value': '1'},{'id': '178', 'type': 'subscript', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '180', 'type': 'binary_operator', 'children': ['181', '182'], 'value': '-'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '182', 'type': 'integer', 'children': [], 'value': '2'},{'id': '183', 'type': 'comparison_operator', 'children': ['184', '189'], 'value': '=='},{'id': '184', 'type': 'subscript', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '186', 'type': 'binary_operator', 'children': ['187', '188'], 'value': '-'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '188', 'type': 'integer', 'children': [], 'value': '2'},{'id': '189', 'type': 'subscript', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '191', 'type': 'binary_operator', 'children': ['192', '193'], 'value': '-'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '193', 'type': 'integer', 'children': [], 'value': '1'},{'id': '194', 'type': 'block', 'children': ['195']},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'assignment', 'children': ['197', '202']},{'id': '197', 'type': 'subscript', 'children': ['198', '201']},{'id': '198', 'type': 'subscript', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '202', 'type': 'call', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '204', 'type': 'argument_list', 'children': ['205', '210']},{'id': '205', 'type': 'subscript', 'children': ['206', '209']},{'id': '206', 'type': 'subscript', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '210', 'type': 'binary_operator', 'children': ['211', '220'], 'value': '+'},{'id': '211', 'type': 'subscript', 'children': ['212', '217']},{'id': '212', 'type': 'subscript', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '214', 'type': 'binary_operator', 'children': ['215', '216'], 'value': '-'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '216', 'type': 'integer', 'children': [], 'value': '2'},{'id': '217', 'type': 'binary_operator', 'children': ['218', '219'], 'value': '-'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '219', 'type': 'integer', 'children': [], 'value': '2'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'cost'},{'id': '221', 'type': 'return_statement', 'children': ['222']},{'id': '222', 'type': 'subscript', 'children': ['223', '229']},{'id': '223', 'type': 'subscript', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '225', 'type': 'call', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '227', 'type': 'argument_list', 'children': ['228']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '229', 'type': 'call', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '231', 'type': 'argument_list', 'children': ['232']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'b'}
def lexical_distance(a, b): d = [[i] for i in range(len(a) + 1)] or [] d_len = len(d) or 1 for i in range(d_len): for j in range(1, len(b) + 1): if i == 0: d[i].append(j) else: d[i].append(0) for i in range(1, len(a) + 1): for j in range(1, len(b) + 1): cost = 0 if a[i - 1] == b[j - 1] else 1 d[i][j] = min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost) if i > 1 and j < 1 and a[i - 1] == b[j - 2] and a[i - 2] == b[j - 1]: d[i][j] = min(d[i][j], d[i - 2][j - 2] + cost) return d[len(a)][len(b)]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'arrange'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'df'},{'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', '21', '56', '75', '92']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'flat_args'},{'id': '13', 'type': 'list_comprehension', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '15', 'type': 'for_in_clause', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'flatten'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '24', 'type': 'list_comprehension', 'children': ['25', '53']},{'id': '25', 'type': 'conditional_expression', 'children': ['26', '29', '34'], 'value': 'if'},{'id': '26', 'type': 'subscript', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '31', 'type': 'argument_list', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '34', 'type': 'conditional_expression', 'children': ['35', '42', '47'], 'value': 'if'},{'id': '35', 'type': 'subscript', 'children': ['36', '39', '41']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'iloc'},{'id': '39', 'type': 'slice', 'children': ['40']},{'id': '40', 'type': 'colon', 'children': []},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '44', 'type': 'argument_list', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'Series'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '53', 'type': 'for_in_clause', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'flat_args'},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'sorter'},{'id': '59', 'type': 'call', 'children': ['60', '71']},{'id': '60', 'type': 'attribute', 'children': ['61', '70']},{'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': 'concat'},{'id': '65', 'type': 'argument_list', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '67', 'type': 'keyword_argument', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '69', 'type': 'integer', 'children': [], 'value': '1'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'reset_index'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'keyword_argument', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'drop'},{'id': '74', 'type': 'True', 'children': []},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'sorter'},{'id': '78', 'type': 'call', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'sorter'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'sort_values'},{'id': '82', 'type': 'argument_list', 'children': ['83', '90']},{'id': '83', 'type': 'call', 'children': ['84', '89']},{'id': '84', 'type': 'attribute', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'sorter'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'tolist'},{'id': '89', 'type': 'argument_list', 'children': []},{'id': '90', 'type': 'dictionary_splat', 'children': ['91']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '92', 'type': 'return_statement', 'children': ['93']},{'id': '93', 'type': 'subscript', 'children': ['94', '97', '100']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'iloc'},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'sorter'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '100', 'type': 'slice', 'children': ['101']},{'id': '101', 'type': 'colon', 'children': []}
def arrange(df, *args, **kwargs): flat_args = [a for a in flatten(args)] series = [df[arg] if isinstance(arg, str) else df.iloc[:, arg] if isinstance(arg, int) else pd.Series(arg) for arg in flat_args] sorter = pd.concat(series, axis=1).reset_index(drop=True) sorter = sorter.sort_values(sorter.columns.tolist(), **kwargs) return df.iloc[sorter.index, :]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'csort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'objs'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '6', 'type': 'block', 'children': ['7', '24']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'idxs'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '12', 'type': 'generator_expression', 'children': ['13', '16']},{'id': '13', 'type': 'tuple', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '16', 'type': 'for_in_clause', 'children': ['17', '20']},{'id': '17', 'type': 'tuple_pattern', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'objs'},{'id': '24', 'type': 'return_statement', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '27', 'type': 'argument_list', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'objs'},{'id': '29', 'type': 'keyword_argument', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '31', 'type': 'lambda', 'children': ['32', '34']},{'id': '32', 'type': 'lambda_parameters', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '34', 'type': 'tuple', 'children': ['35', '39']},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '39', 'type': 'subscript', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'idxs'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'obj'}
def csort(objs, key): idxs = dict((obj, i) for (i, obj) in enumerate(objs)) return sorted(objs, key=lambda obj: (key(obj), idxs[obj]))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'fast_combine_pairs'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'force_single'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'full_name'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'separators'},{'id': '8', 'type': 'block', 'children': ['9', '16', '26', '40', '51', '58', '85', '103']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'sort_filenames'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'chunks'},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'tz'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'sliding_window'},{'id': '23', 'type': 'argument_list', 'children': ['24', '25']},{'id': '24', 'type': 'integer', 'children': [], 'value': '10'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'pairs'},{'id': '29', 'type': 'list_comprehension', 'children': ['30', '37']},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'combine_pairs'},{'id': '32', 'type': 'argument_list', 'children': ['33', '34', '35', '36']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'chunk'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'force_single'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'full_name'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'separators'},{'id': '37', 'type': 'for_in_clause', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'chunk'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'chunks'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'pairs'},{'id': '43', 'type': 'list_comprehension', 'children': ['44', '45', '48']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '45', 'type': 'for_in_clause', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'pairs'},{'id': '48', 'type': 'for_in_clause', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'longest'},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '58', 'type': 'for_statement', 'children': ['59', '60', '61']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'pair'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'pairs'},{'id': '61', 'type': 'block', 'children': ['62']},{'id': '62', 'type': 'for_statement', 'children': ['63', '64', '65']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'pair'},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'if_statement', 'children': ['67', '78']},{'id': '67', 'type': 'comparison_operator', 'children': ['68', '74'], 'value': '<'},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'subscript', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'longest'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'file'},{'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': 'pair'},{'id': '78', 'type': 'block', 'children': ['79']},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '84']},{'id': '81', 'type': 'subscript', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'longest'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'pair'},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'longest'},{'id': '88', 'type': 'set_comprehension', 'children': ['89', '96']},{'id': '89', 'type': 'call', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'sort_filenames'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '96', 'type': 'for_in_clause', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'longest'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '102', 'type': 'argument_list', 'children': []},{'id': '103', 'type': 'return_statement', 'children': ['104']},{'id': '104', 'type': 'list_comprehension', 'children': ['105', '112']},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'sort_filenames'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'call', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '112', 'type': 'for_in_clause', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'longest'}
def fast_combine_pairs(files, force_single, full_name, separators): files = sort_filenames(files) chunks = tz.sliding_window(10, files) pairs = [combine_pairs(chunk, force_single, full_name, separators) for chunk in chunks] pairs = [y for x in pairs for y in x] longest = defaultdict(list) for pair in pairs: for file in pair: if len(longest[file]) < len(pair): longest[file] = pair longest = {tuple(sort_filenames(x)) for x in longest.values()} return [sort_filenames(list(x)) for x in longest]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'align_bam'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'in_bam'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'ref_file'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'align_dir'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '9', 'type': 'block', 'children': ['10', '16', '35', '45', '55', '65', '77', '98', '219']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '13', 'type': 'subscript', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '15', 'type': 'string', 'children': [], 'value': '"config"'},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '19', 'type': 'call', 'children': ['20', '25']},{'id': '20', 'type': 'attribute', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'align_dir'},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'string', 'children': [], 'value': '"{0}-sort.bam"'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'subscript', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '34', 'type': 'string', 'children': [], 'value': '"lane"'},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'samtools'},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'config_utils'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'get_program'},{'id': '42', 'type': 'argument_list', 'children': ['43', '44']},{'id': '43', 'type': 'string', 'children': [], 'value': '"samtools"'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'bedtools'},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'config_utils'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'get_program'},{'id': '52', 'type': 'argument_list', 'children': ['53', '54']},{'id': '53', 'type': 'string', 'children': [], 'value': '"bedtools"'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'resources'},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'config_utils'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'get_resources'},{'id': '62', 'type': 'argument_list', 'children': ['63', '64']},{'id': '63', 'type': 'string', 'children': [], 'value': '"samtools"'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'num_cores'},{'id': '68', 'type': 'call', 'children': ['69', '74']},{'id': '69', 'type': 'attribute', 'children': ['70', '73']},{'id': '70', 'type': 'subscript', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '72', 'type': 'string', 'children': [], 'value': '"algorithm"'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '74', 'type': 'argument_list', 'children': ['75', '76']},{'id': '75', 'type': 'string', 'children': [], 'value': '"num_cores"'},{'id': '76', 'type': 'integer', 'children': [], 'value': '1'},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'max_mem'},{'id': '80', 'type': 'call', 'children': ['81', '97']},{'id': '81', 'type': 'attribute', 'children': ['82', '96']},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'config_utils'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'adjust_memory'},{'id': '86', 'type': 'argument_list', 'children': ['87', '94', '95']},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'resources'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '91', 'type': 'argument_list', 'children': ['92', '93']},{'id': '92', 'type': 'string', 'children': [], 'value': '"memory"'},{'id': '93', 'type': 'string', 'children': [], 'value': '"1G"'},{'id': '94', 'type': 'integer', 'children': [], 'value': '3'},{'id': '95', 'type': 'string', 'children': [], 'value': '"decrease"'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '97', 'type': 'argument_list', 'children': []},{'id': '98', 'type': 'if_statement', 'children': ['99', '106']},{'id': '99', 'type': 'not_operator', 'children': ['100']},{'id': '100', 'type': 'call', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'file_exists'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '106', 'type': 'block', 'children': ['107']},{'id': '107', 'type': 'with_statement', 'children': ['108', '117']},{'id': '108', 'type': 'with_clause', 'children': ['109']},{'id': '109', 'type': 'with_item', 'children': ['110']},{'id': '110', 'type': 'as_pattern', 'children': ['111', '115']},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'tx_tmpdir'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '115', 'type': 'as_pattern_target', 'children': ['116']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '117', 'type': 'block', 'children': ['118']},{'id': '118', 'type': 'with_statement', 'children': ['119', '139']},{'id': '119', 'type': 'with_clause', 'children': ['120']},{'id': '120', 'type': 'with_item', 'children': ['121']},{'id': '121', 'type': 'as_pattern', 'children': ['122', '135']},{'id': '122', 'type': 'call', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'postalign'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'tobam_cl'},{'id': '126', 'type': 'argument_list', 'children': ['127', '128', '129']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '129', 'type': 'call', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'bam'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'is_paired'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'in_bam'},{'id': '135', 'type': 'as_pattern_target', 'children': ['136']},{'id': '136', 'type': 'tuple', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'tobam_cl'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'tx_out_file'},{'id': '139', 'type': 'block', 'children': ['140', '150', '163', '169', '178', '192']},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'assignment', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'bwa_cmd'},{'id': '143', 'type': 'call', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': '_get_bwa_mem_cmd'},{'id': '145', 'type': 'argument_list', 'children': ['146', '147', '148', '149']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'ref_file'},{'id': '149', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'tx_out_prefix'},{'id': '153', 'type': 'subscript', 'children': ['154', '162']},{'id': '154', 'type': 'call', 'children': ['155', '160']},{'id': '155', 'type': 'attribute', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'splitext'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'tx_out_file'},{'id': '162', 'type': 'integer', 'children': [], 'value': '0'},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'prefix1'},{'id': '166', 'type': 'binary_operator', 'children': ['167', '168'], 'value': '%'},{'id': '167', 'type': 'string', 'children': [], 'value': '"%s-in1"'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'tx_out_prefix'},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'assignment', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '172', 'type': '()', 'children': ['173']},{'id': '173', 'type': 'concatenated_string', 'children': ['174', '175', '176', '177']},{'id': '174', 'type': 'string', 'children': [], 'value': '"unset JAVA_HOME && "'},{'id': '175', 'type': 'string', 'children': [], 'value': '"{samtools} sort -n -o -l 1 -@ {num_cores} -m {max_mem} {in_bam} {prefix1} "'},{'id': '176', 'type': 'string', 'children': [], 'value': '"| {bedtools} bamtofastq -i /dev/stdin -fq /dev/stdout -fq2 /dev/stdout "'},{'id': '177', 'type': 'string', 'children': [], 'value': '"| {bwa_cmd} | "'},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'assignment', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '181', 'type': 'binary_operator', 'children': ['182', '191'], 'value': '+'},{'id': '182', 'type': 'call', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '186', 'type': 'argument_list', 'children': ['187']},{'id': '187', 'type': 'dictionary_splat', 'children': ['188']},{'id': '188', 'type': 'call', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'locals'},{'id': '190', 'type': 'argument_list', 'children': []},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'tobam_cl'},{'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': 'do'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'run'},{'id': '197', 'type': 'argument_list', 'children': ['198', '199', '204', '205']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '199', 'type': 'binary_operator', 'children': ['200', '201'], 'value': '%'},{'id': '200', 'type': 'string', 'children': [], 'value': '"bwa mem alignment from BAM: %s"'},{'id': '201', 'type': 'subscript', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '203', 'type': 'string', 'children': [], 'value': '"sample"'},{'id': '204', 'type': 'None', 'children': []},{'id': '205', 'type': 'list', 'children': ['206', '212'], 'value': '[do.file_nonempty(tx_out_file), do.file_reasonable_size(tx_out_file, in_bam)]'},{'id': '206', 'type': 'call', 'children': ['207', '210']},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'do'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'file_nonempty'},{'id': '210', 'type': 'argument_list', 'children': ['211']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'tx_out_file'},{'id': '212', 'type': 'call', 'children': ['213', '216']},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'do'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'file_reasonable_size'},{'id': '216', 'type': 'argument_list', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'tx_out_file'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'in_bam'},{'id': '219', 'type': 'return_statement', 'children': ['220']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'out_file'}
def align_bam(in_bam, ref_file, names, align_dir, data): config = data["config"] out_file = os.path.join(align_dir, "{0}-sort.bam".format(names["lane"])) samtools = config_utils.get_program("samtools", config) bedtools = config_utils.get_program("bedtools", config) resources = config_utils.get_resources("samtools", config) num_cores = config["algorithm"].get("num_cores", 1) max_mem = config_utils.adjust_memory(resources.get("memory", "1G"), 3, "decrease").upper() if not utils.file_exists(out_file): with tx_tmpdir(data) as work_dir: with postalign.tobam_cl(data, out_file, bam.is_paired(in_bam)) as (tobam_cl, tx_out_file): bwa_cmd = _get_bwa_mem_cmd(data, out_file, ref_file, "-") tx_out_prefix = os.path.splitext(tx_out_file)[0] prefix1 = "%s-in1" % tx_out_prefix cmd = ("unset JAVA_HOME && " "{samtools} sort -n -o -l 1 -@ {num_cores} -m {max_mem} {in_bam} {prefix1} " "| {bedtools} bamtofastq -i /dev/stdin -fq /dev/stdout -fq2 /dev/stdout " "| {bwa_cmd} | ") cmd = cmd.format(**locals()) + tobam_cl do.run(cmd, "bwa mem alignment from BAM: %s" % names["sample"], None, [do.file_nonempty(tx_out_file), do.file_reasonable_size(tx_out_file, in_bam)]) return out_file
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_combine_regions'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'all_regions'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'ref_regions'},{'id': '6', 'type': 'block', 'children': ['7', '11', '28', '47', '51', '81', '90', '106']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'chrom_order'},{'id': '10', 'type': 'dictionary', 'children': []},{'id': '11', 'type': 'for_statement', 'children': ['12', '15', '19']},{'id': '12', 'type': 'pattern_list', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'ref_regions'},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '27']},{'id': '22', 'type': 'subscript', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'chrom_order'},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '28', 'type': 'function_definition', 'children': ['29', '30', '32']},{'id': '29', 'type': 'function_name', 'children': [], 'value': 'wchrom_key'},{'id': '30', 'type': 'parameters', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '32', 'type': 'block', 'children': ['33', '40']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '39']},{'id': '35', 'type': 'pattern_list', 'children': ['36', '37', '38']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '40', 'type': 'return_statement', 'children': ['41']},{'id': '41', 'type': 'tuple', 'children': ['42', '45', '46']},{'id': '42', 'type': 'subscript', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'chrom_order'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'all_intervals'},{'id': '50', 'type': 'list', 'children': [], 'value': '[]'},{'id': '51', 'type': 'for_statement', 'children': ['52', '53', '54']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'region_group'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'all_regions'},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'for_statement', 'children': ['56', '57', '58']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'region'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'region_group'},{'id': '58', 'type': 'block', 'children': ['59']},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'all_intervals'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'tuple', 'children': ['66', '69', '75']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'region'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'region'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'region'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'all_intervals'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'keyword_argument', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'wchrom_key'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'bed_lines'},{'id': '93', 'type': 'list_comprehension', 'children': ['94', '100']},{'id': '94', 'type': 'binary_operator', 'children': ['95', '96'], 'value': '%'},{'id': '95', 'type': 'string', 'children': [], 'value': '"%s\\t%s\\t%s"'},{'id': '96', 'type': 'tuple', 'children': ['97', '98', '99']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '100', 'type': 'for_in_clause', 'children': ['101', '105']},{'id': '101', 'type': 'tuple_pattern', 'children': ['102', '103', '104']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'all_intervals'},{'id': '106', 'type': 'return_statement', 'children': ['107']},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'pybedtools'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'BedTool'},{'id': '111', 'type': 'argument_list', 'children': ['112', '118']},{'id': '112', 'type': 'call', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'bed_lines'},{'id': '118', 'type': 'keyword_argument', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'from_string'},{'id': '120', 'type': 'True', 'children': []}
def _combine_regions(all_regions, ref_regions): chrom_order = {} for i, x in enumerate(ref_regions): chrom_order[x.chrom] = i def wchrom_key(x): chrom, start, end = x return (chrom_order[chrom], start, end) all_intervals = [] for region_group in all_regions: for region in region_group: all_intervals.append((region.chrom, int(region.start), int(region.stop))) all_intervals.sort(key=wchrom_key) bed_lines = ["%s\t%s\t%s" % (c, s, e) for (c, s, e) in all_intervals] return pybedtools.BedTool("\n".join(bed_lines), from_string=True)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_add_meta'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'xs'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'sample'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '16', '153']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '15', 'type': 'list', 'children': [], 'value': '[]'},{'id': '16', 'type': 'for_statement', 'children': ['17', '18', '19']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'xs'},{'id': '19', 'type': 'block', 'children': ['20', '51', '64', '100', '146']},{'id': '20', 'type': 'if_statement', 'children': ['21', '43']},{'id': '21', 'type': 'boolean_operator', 'children': ['22', '32'], 'value': 'or'},{'id': '22', 'type': 'not_operator', 'children': ['23']},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '25', 'type': 'argument_list', 'children': ['26', '29']},{'id': '26', 'type': 'subscript', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '28', 'type': 'string', 'children': [], 'value': '"path"'},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'string_types'},{'id': '32', 'type': 'not_operator', 'children': ['33']},{'id': '33', 'type': 'call', 'children': ['34', '39']},{'id': '34', 'type': 'attribute', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'subscript', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '42', 'type': 'string', 'children': [], 'value': '"path"'},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'raise_statement', 'children': ['45']},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'binary_operator', 'children': ['49', '50'], 'value': '%'},{'id': '49', 'type': 'string', 'children': [], 'value': '"Unexpected path for upload: %s"'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '56']},{'id': '53', 'type': 'subscript', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '55', 'type': 'string', 'children': [], 'value': '"mtime"'},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'shared'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'get_file_timestamp'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'subscript', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '63', 'type': 'string', 'children': [], 'value': '"path"'},{'id': '64', 'type': 'if_statement', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'sample'},{'id': '66', 'type': 'block', 'children': ['67', '76']},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'sample_name'},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'dd'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'get_sample_name'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'sample'},{'id': '76', 'type': 'if_statement', 'children': ['77', '80', '87']},{'id': '77', 'type': 'comparison_operator', 'children': ['78', '79'], 'value': 'not'},{'id': '78', 'type': 'string', 'children': [], 'value': '"sample"'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '80', 'type': 'block', 'children': ['81']},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '86']},{'id': '83', 'type': 'subscript', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '85', 'type': 'string', 'children': [], 'value': '"sample"'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'sample_name'},{'id': '87', 'type': 'elif_clause', 'children': ['88', '93']},{'id': '88', 'type': 'comparison_operator', 'children': ['89', '92'], 'value': '!='},{'id': '89', 'type': 'subscript', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '91', 'type': 'string', 'children': [], 'value': '"sample"'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'sample_name'},{'id': '93', 'type': 'block', 'children': ['94']},{'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': 'x'},{'id': '98', 'type': 'string', 'children': [], 'value': '"run"'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'sample_name'},{'id': '100', 'type': 'if_statement', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '102', 'type': 'block', 'children': ['103', '114', '136']},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'fc_name'},{'id': '106', 'type': 'boolean_operator', 'children': ['107', '113'], 'value': 'or'},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'string', 'children': [], 'value': '"fc_name"'},{'id': '113', 'type': 'string', 'children': [], 'value': '"project"'},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'fc_date'},{'id': '117', 'type': 'boolean_operator', 'children': ['118', '124'], 'value': 'or'},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'string', 'children': [], 'value': '"fc_date"'},{'id': '124', 'type': 'call', 'children': ['125', '134']},{'id': '125', 'type': 'attribute', 'children': ['126', '133']},{'id': '126', 'type': 'call', 'children': ['127', '132']},{'id': '127', 'type': 'attribute', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '132', 'type': 'argument_list', 'children': []},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'strftime'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'string', 'children': [], 'value': '"%Y-%m-%d"'},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '141']},{'id': '138', 'type': 'subscript', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '140', 'type': 'string', 'children': [], 'value': '"run"'},{'id': '141', 'type': 'binary_operator', 'children': ['142', '143'], 'value': '%'},{'id': '142', 'type': 'string', 'children': [], 'value': '"%s_%s"'},{'id': '143', 'type': 'tuple', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'fc_date'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'fc_name'},{'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': 'out'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '151', 'type': 'argument_list', 'children': ['152']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '153', 'type': 'return_statement', 'children': ['154']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'out'}
def _add_meta(xs, sample=None, config=None): out = [] for x in xs: if not isinstance(x["path"], six.string_types) or not os.path.exists(x["path"]): raise ValueError("Unexpected path for upload: %s" % x) x["mtime"] = shared.get_file_timestamp(x["path"]) if sample: sample_name = dd.get_sample_name(sample) if "sample" not in x: x["sample"] = sample_name elif x["sample"] != sample_name: x["run"] = sample_name if config: fc_name = config.get("fc_name") or "project" fc_date = config.get("fc_date") or datetime.datetime.now().strftime("%Y-%m-%d") x["run"] = "%s_%s" % (fc_date, fc_name) out.append(x) return out
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'report'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'align_bam'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'ref_file'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'is_paired'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'bait_file'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'target_file'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'variant_region_file'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '12', 'type': 'block', 'children': ['13', '22', '32', '36', '46', '60', '144', '153', '168', '172', '193', '214']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'dup_metrics'},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': '_get_current_dup_metrics'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'align_bam'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'align_metrics'},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': '_collect_align_metrics'},{'id': '29', 'type': 'argument_list', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'align_bam'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'ref_file'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'gc_graph'},{'id': '35', 'type': 'None', 'children': []},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '42']},{'id': '38', 'type': 'pattern_list', 'children': ['39', '40', '41']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'insert_graph'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'insert_metrics'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'hybrid_metrics'},{'id': '42', 'type': 'tuple', 'children': ['43', '44', '45']},{'id': '43', 'type': 'None', 'children': []},{'id': '44', 'type': 'None', 'children': []},{'id': '45', 'type': 'None', 'children': []},{'id': '46', 'type': 'if_statement', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'is_paired'},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '54']},{'id': '51', 'type': 'pattern_list', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'insert_graph'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'insert_metrics'},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '57', 'type': 'identifier', 'children': [], 'value': '_insert_sizes'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'align_bam'},{'id': '60', 'type': 'if_statement', 'children': ['61', '64', '100']},{'id': '61', 'type': 'boolean_operator', 'children': ['62', '63'], 'value': 'and'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'bait_file'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'target_file'},{'id': '64', 'type': 'block', 'children': ['65', '77', '89']},{'id': '65', 'type': 'assert_statement', 'children': ['66', '74']},{'id': '66', 'type': 'call', 'children': ['67', '72']},{'id': '67', 'type': 'attribute', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'bait_file'},{'id': '74', 'type': 'tuple', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'bait_file'},{'id': '76', 'type': 'string', 'children': [], 'value': '"does not exist!"'},{'id': '77', 'type': 'assert_statement', 'children': ['78', '86']},{'id': '78', 'type': 'call', 'children': ['79', '84']},{'id': '79', 'type': 'attribute', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'target_file'},{'id': '86', 'type': 'tuple', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'target_file'},{'id': '88', 'type': 'string', 'children': [], 'value': '"does not exist!"'},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'hybrid_metrics'},{'id': '92', 'type': 'call', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '95', 'type': 'identifier', 'children': [], 'value': '_hybrid_select_metrics'},{'id': '96', 'type': 'argument_list', 'children': ['97', '98', '99']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'align_bam'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'bait_file'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'target_file'},{'id': '100', 'type': 'elif_clause', 'children': ['101', '120']},{'id': '101', 'type': '()', 'children': ['102']},{'id': '102', 'type': 'boolean_operator', 'children': ['103', '104'], 'value': 'and'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'variant_region_file'},{'id': '104', 'type': 'comparison_operator', 'children': ['105', '118'], 'value': 'in'},{'id': '105', 'type': 'call', 'children': ['106', '117']},{'id': '106', 'type': 'attribute', 'children': ['107', '116']},{'id': '107', 'type': 'call', 'children': ['108', '113']},{'id': '108', 'type': 'attribute', 'children': ['109', '112']},{'id': '109', 'type': 'subscript', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '111', 'type': 'string', 'children': [], 'value': '"algorithm"'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '113', 'type': 'argument_list', 'children': ['114', '115']},{'id': '114', 'type': 'string', 'children': [], 'value': '"coverage_interval"'},{'id': '115', 'type': 'string', 'children': [], 'value': '""'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '117', 'type': 'argument_list', 'children': []},{'id': '118', 'type': 'list', 'children': ['119'], 'value': '["exome"]'},{'id': '119', 'type': 'string', 'children': [], 'value': '"exome"'},{'id': '120', 'type': 'block', 'children': ['121', '133']},{'id': '121', 'type': 'assert_statement', 'children': ['122', '130']},{'id': '122', 'type': 'call', 'children': ['123', '128']},{'id': '123', 'type': 'attribute', 'children': ['124', '127']},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'variant_region_file'},{'id': '130', 'type': 'tuple', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'variant_region_file'},{'id': '132', 'type': 'string', 'children': [], 'value': '"does not exist"'},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'hybrid_metrics'},{'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': '_hybrid_select_metrics'},{'id': '140', 'type': 'argument_list', 'children': ['141', '142', '143']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'align_bam'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'variant_region_file'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'variant_region_file'},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'vrn_vals'},{'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': '_variant_eval_metrics'},{'id': '151', 'type': 'argument_list', 'children': ['152']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'align_bam'},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'summary_info'},{'id': '156', 'type': 'call', 'children': ['157', '162']},{'id': '157', 'type': 'attribute', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '160', 'type': 'identifier', 'children': [], 'value': '_parser'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'get_summary_metrics'},{'id': '162', 'type': 'argument_list', 'children': ['163', '164', '165', '166', '167']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'align_metrics'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'dup_metrics'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'insert_metrics'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'hybrid_metrics'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'vrn_vals'},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'assignment', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'graphs'},{'id': '171', 'type': 'list', 'children': [], 'value': '[]'},{'id': '172', 'type': 'if_statement', 'children': ['173', '183']},{'id': '173', 'type': 'boolean_operator', 'children': ['174', '175'], 'value': 'and'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'gc_graph'},{'id': '175', 'type': 'call', 'children': ['176', '181']},{'id': '176', 'type': 'attribute', 'children': ['177', '180']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'gc_graph'},{'id': '183', 'type': 'block', 'children': ['184']},{'id': '184', 'type': 'expression_statement', 'children': ['185']},{'id': '185', 'type': 'call', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'graphs'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'tuple', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'gc_graph'},{'id': '192', 'type': 'string', 'children': [], 'value': '"Distribution of GC content across reads"'},{'id': '193', 'type': 'if_statement', 'children': ['194', '204']},{'id': '194', 'type': 'boolean_operator', 'children': ['195', '196'], 'value': 'and'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'insert_graph'},{'id': '196', 'type': 'call', 'children': ['197', '202']},{'id': '197', 'type': 'attribute', 'children': ['198', '201']},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '202', 'type': 'argument_list', 'children': ['203']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'insert_graph'},{'id': '204', 'type': 'block', 'children': ['205']},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'call', 'children': ['207', '210']},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'graphs'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '210', 'type': 'argument_list', 'children': ['211']},{'id': '211', 'type': 'tuple', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'insert_graph'},{'id': '213', 'type': 'string', 'children': [], 'value': '"Distribution of paired end insert sizes"'},{'id': '214', 'type': 'return_statement', 'children': ['215']},{'id': '215', 'type': 'expression_list', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'summary_info'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'graphs'}
def report(self, align_bam, ref_file, is_paired, bait_file, target_file, variant_region_file, config): dup_metrics = self._get_current_dup_metrics(align_bam) align_metrics = self._collect_align_metrics(align_bam, ref_file) gc_graph = None insert_graph, insert_metrics, hybrid_metrics = (None, None, None) if is_paired: insert_graph, insert_metrics = self._insert_sizes(align_bam) if bait_file and target_file: assert os.path.exists(bait_file), (bait_file, "does not exist!") assert os.path.exists(target_file), (target_file, "does not exist!") hybrid_metrics = self._hybrid_select_metrics(align_bam, bait_file, target_file) elif (variant_region_file and config["algorithm"].get("coverage_interval", "").lower() in ["exome"]): assert os.path.exists(variant_region_file), (variant_region_file, "does not exist") hybrid_metrics = self._hybrid_select_metrics( align_bam, variant_region_file, variant_region_file) vrn_vals = self._variant_eval_metrics(align_bam) summary_info = self._parser.get_summary_metrics(align_metrics, dup_metrics, insert_metrics, hybrid_metrics, vrn_vals) graphs = [] if gc_graph and os.path.exists(gc_graph): graphs.append((gc_graph, "Distribution of GC content across reads")) if insert_graph and os.path.exists(insert_graph): graphs.append((insert_graph, "Distribution of paired end insert sizes")) return summary_info, graphs
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'report'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'align_bam'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'ref_file'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'gtf_file'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'is_paired'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'rrna_file'},{'id': '13', 'type': 'string', 'children': [], 'value': '"null"'},{'id': '14', 'type': 'block', 'children': ['15', '24', '34', '42', '56', '67', '85', '89', '106']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'dup_metrics'},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': '_get_current_dup_metrics'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'align_bam'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'align_metrics'},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '30', 'type': 'identifier', 'children': [], 'value': '_collect_align_metrics'},{'id': '31', 'type': 'argument_list', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'align_bam'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'ref_file'},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '39']},{'id': '36', 'type': 'pattern_list', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'insert_graph'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'insert_metrics'},{'id': '39', 'type': 'tuple', 'children': ['40', '41']},{'id': '40', 'type': 'None', 'children': []},{'id': '41', 'type': 'None', 'children': []},{'id': '42', 'type': 'if_statement', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'is_paired'},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '50']},{'id': '47', 'type': 'pattern_list', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'insert_graph'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'insert_metrics'},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '53', 'type': 'identifier', 'children': [], 'value': '_insert_sizes'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'align_bam'},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'rnaseq_metrics'},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '62', 'type': 'identifier', 'children': [], 'value': '_rnaseq_metrics'},{'id': '63', 'type': 'argument_list', 'children': ['64', '65', '66']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'align_bam'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'gtf_file'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'rrna_file'},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'summary_info'},{'id': '70', 'type': 'call', 'children': ['71', '76']},{'id': '71', 'type': 'attribute', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '74', 'type': 'identifier', 'children': [], 'value': '_parser'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'get_summary_metrics'},{'id': '76', 'type': 'argument_list', 'children': ['77', '78', '79', '82']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'align_metrics'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'dup_metrics'},{'id': '79', 'type': 'keyword_argument', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'insert_metrics'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'insert_metrics'},{'id': '82', 'type': 'keyword_argument', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'rnaseq_metrics'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'rnaseq_metrics'},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'graphs'},{'id': '88', 'type': 'list', 'children': [], 'value': '[]'},{'id': '89', 'type': 'if_statement', 'children': ['90', '96']},{'id': '90', 'type': 'boolean_operator', 'children': ['91', '92'], 'value': 'and'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'insert_graph'},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'file_exists'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'insert_graph'},{'id': '96', 'type': 'block', 'children': ['97']},{'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': 'graphs'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'tuple', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'insert_graph'},{'id': '105', 'type': 'string', 'children': [], 'value': '"Distribution of paired end insert sizes"'},{'id': '106', 'type': 'return_statement', 'children': ['107']},{'id': '107', 'type': 'expression_list', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'summary_info'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'graphs'}
def report(self, align_bam, ref_file, gtf_file, is_paired=False, rrna_file="null"): dup_metrics = self._get_current_dup_metrics(align_bam) align_metrics = self._collect_align_metrics(align_bam, ref_file) insert_graph, insert_metrics = (None, None) if is_paired: insert_graph, insert_metrics = self._insert_sizes(align_bam) rnaseq_metrics = self._rnaseq_metrics(align_bam, gtf_file, rrna_file) summary_info = self._parser.get_summary_metrics(align_metrics, dup_metrics, insert_metrics=insert_metrics, rnaseq_metrics=rnaseq_metrics) graphs = [] if insert_graph and file_exists(insert_graph): graphs.append((insert_graph, "Distribution of paired end insert sizes")) return summary_info, graphs
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'apply_recal'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '5', 'type': 'block', 'children': ['6', '22', '28', '141', '163', '200']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'orig_bam'},{'id': '9', 'type': 'boolean_operator', 'children': ['10', '16'], 'value': 'or'},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'dd'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'get_align_bam'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'dd'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'get_work_bam'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'had_work_bam'},{'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': 'in'},{'id': '26', 'type': 'string', 'children': [], 'value': '"work_bam"'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '28', 'type': 'if_statement', 'children': ['29', '39', '74', '120']},{'id': '29', 'type': 'comparison_operator', 'children': ['30', '36'], 'value': 'in'},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'dd'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'get_recalibrate'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '36', 'type': 'list', 'children': ['37', '38'], 'value': '[True, "gatk"]'},{'id': '37', 'type': 'True', 'children': []},{'id': '38', 'type': 'string', 'children': [], 'value': '"gatk"'},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'if_statement', 'children': ['41', '47']},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'string', 'children': [], 'value': '"prep_recal"'},{'id': '47', 'type': 'block', 'children': ['48', '65']},{'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': 'logger'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'binary_operator', 'children': ['55', '56'], 'value': '%'},{'id': '55', 'type': 'string', 'children': [], 'value': '"Applying BQSR recalibration with GATK: %s "'},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'dd'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'get_sample_name'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '70']},{'id': '67', 'type': 'subscript', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '69', 'type': 'string', 'children': [], 'value': '"work_bam"'},{'id': '70', 'type': 'call', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': '_gatk_apply_bqsr'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '74', 'type': 'elif_clause', 'children': ['75', '83']},{'id': '75', 'type': 'comparison_operator', 'children': ['76', '82'], 'value': '=='},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'dd'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'get_recalibrate'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '82', 'type': 'string', 'children': [], 'value': '"sentieon"'},{'id': '83', 'type': 'block', 'children': ['84']},{'id': '84', 'type': 'if_statement', 'children': ['85', '91']},{'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': 'get'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'string', 'children': [], 'value': '"prep_recal"'},{'id': '91', 'type': 'block', 'children': ['92', '109']},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'binary_operator', 'children': ['99', '100'], 'value': '%'},{'id': '99', 'type': 'string', 'children': [], 'value': '"Applying BQSR recalibration with sentieon: %s "'},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'dd'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'get_sample_name'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '114']},{'id': '111', 'type': 'subscript', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '113', 'type': 'string', 'children': [], 'value': '"work_bam"'},{'id': '114', 'type': 'call', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'sentieon'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'apply_bqsr'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '120', 'type': 'elif_clause', 'children': ['121', '127']},{'id': '121', 'type': 'call', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'dd'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'get_recalibrate'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '127', 'type': 'block', 'children': ['128']},{'id': '128', 'type': 'raise_statement', 'children': ['129']},{'id': '129', 'type': 'call', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'NotImplementedError'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'binary_operator', 'children': ['133', '134'], 'value': '%'},{'id': '133', 'type': 'string', 'children': [], 'value': '"Unsupported recalibration type: %s"'},{'id': '134', 'type': '()', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'dd'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'get_recalibrate'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '141', 'type': 'if_statement', 'children': ['142', '151']},{'id': '142', 'type': 'boolean_operator', 'children': ['143', '145'], 'value': 'and'},{'id': '143', 'type': 'not_operator', 'children': ['144']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'had_work_bam'},{'id': '145', 'type': 'call', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'dd'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'get_work_bam'},{'id': '149', 'type': 'argument_list', 'children': ['150']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '151', 'type': 'block', 'children': ['152']},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '157']},{'id': '154', 'type': 'subscript', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '156', 'type': 'string', 'children': [], 'value': '"align_bam"'},{'id': '157', 'type': 'call', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'dd'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'get_work_bam'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '163', 'type': 'if_statement', 'children': ['164', '181']},{'id': '164', 'type': 'boolean_operator', 'children': ['165', '173'], 'value': 'and'},{'id': '165', 'type': 'comparison_operator', 'children': ['166', '167'], 'value': '!='},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'orig_bam'},{'id': '167', 'type': 'call', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'dd'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'get_work_bam'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '173', 'type': 'comparison_operator', 'children': ['174', '175'], 'value': '!='},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'orig_bam'},{'id': '175', 'type': 'call', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'dd'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'get_align_bam'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '181', 'type': 'block', 'children': ['182']},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'call', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'save_diskspace'},{'id': '187', 'type': 'argument_list', 'children': ['188', '189', '197']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'orig_bam'},{'id': '189', 'type': 'binary_operator', 'children': ['190', '191'], 'value': '%'},{'id': '190', 'type': 'string', 'children': [], 'value': '"BAM recalibrated to %s"'},{'id': '191', 'type': 'call', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'dd'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'get_work_bam'},{'id': '195', 'type': 'argument_list', 'children': ['196']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '197', 'type': 'subscript', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '199', 'type': 'string', 'children': [], 'value': '"config"'},{'id': '200', 'type': 'return_statement', 'children': ['201']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'data'}
def apply_recal(data): orig_bam = dd.get_align_bam(data) or dd.get_work_bam(data) had_work_bam = "work_bam" in data if dd.get_recalibrate(data) in [True, "gatk"]: if data.get("prep_recal"): logger.info("Applying BQSR recalibration with GATK: %s " % str(dd.get_sample_name(data))) data["work_bam"] = _gatk_apply_bqsr(data) elif dd.get_recalibrate(data) == "sentieon": if data.get("prep_recal"): logger.info("Applying BQSR recalibration with sentieon: %s " % str(dd.get_sample_name(data))) data["work_bam"] = sentieon.apply_bqsr(data) elif dd.get_recalibrate(data): raise NotImplementedError("Unsupported recalibration type: %s" % (dd.get_recalibrate(data))) if not had_work_bam and dd.get_work_bam(data): data["align_bam"] = dd.get_work_bam(data) if orig_bam != dd.get_work_bam(data) and orig_bam != dd.get_align_bam(data): utils.save_diskspace(orig_bam, "BAM recalibrated to %s" % dd.get_work_bam(data), data["config"]) return data
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_prep_callable_bed'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'in_file'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'stats'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '8', 'type': 'block', 'children': ['9', '37', '47', '106']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '12', 'type': 'call', 'children': ['13', '18']},{'id': '13', 'type': 'attribute', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '18', 'type': 'argument_list', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '20', 'type': 'binary_operator', 'children': ['21', '22'], 'value': '%'},{'id': '21', 'type': 'string', 'children': [], 'value': '"%s-merge.bed.gz"'},{'id': '22', 'type': 'subscript', 'children': ['23', '36']},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'splitext_plus'},{'id': '27', 'type': 'argument_list', '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': 'os'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'in_file'},{'id': '36', 'type': 'integer', 'children': [], 'value': '0'},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'gsort'},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'config_utils'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'get_program'},{'id': '44', 'type': 'argument_list', 'children': ['45', '46']},{'id': '45', 'type': 'string', 'children': [], 'value': '"gsort"'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '47', 'type': 'if_statement', 'children': ['48', '56']},{'id': '48', 'type': 'not_operator', 'children': ['49']},{'id': '49', 'type': 'call', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'file_uptodate'},{'id': '53', 'type': 'argument_list', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'in_file'},{'id': '56', 'type': 'block', 'children': ['57']},{'id': '57', 'type': 'with_statement', 'children': ['58', '68']},{'id': '58', 'type': 'with_clause', 'children': ['59']},{'id': '59', 'type': 'with_item', 'children': ['60']},{'id': '60', 'type': 'as_pattern', 'children': ['61', '66']},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'file_transaction'},{'id': '63', 'type': 'argument_list', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '66', 'type': 'as_pattern_target', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'tx_out_file'},{'id': '68', 'type': 'block', 'children': ['69', '83', '90']},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'fai_file'},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'fasta_idx'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'dd'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'get_ref_file'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '86', 'type': '()', 'children': ['87']},{'id': '87', 'type': 'concatenated_string', 'children': ['88', '89']},{'id': '88', 'type': 'string', 'children': [], 'value': '"{gsort} {in_file} {fai_file} | bedtools merge -i - -d {stats[merge_size]} | "'},{'id': '89', 'type': 'string', 'children': [], 'value': '"bgzip -c > {tx_out_file}"'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'do'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'run'},{'id': '95', 'type': 'argument_list', 'children': ['96', '105']},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'dictionary_splat', 'children': ['102']},{'id': '102', 'type': 'call', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'locals'},{'id': '104', 'type': 'argument_list', 'children': []},{'id': '105', 'type': 'string', 'children': [], 'value': '"Prepare SV callable BED regions"'},{'id': '106', 'type': 'return_statement', 'children': ['107']},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'vcfutils'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'bgzip_and_index'},{'id': '111', 'type': 'argument_list', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '113', 'type': 'subscript', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '115', 'type': 'string', 'children': [], 'value': '"config"'}
def _prep_callable_bed(in_file, work_dir, stats, data): out_file = os.path.join(work_dir, "%s-merge.bed.gz" % utils.splitext_plus(os.path.basename(in_file))[0]) gsort = config_utils.get_program("gsort", data) if not utils.file_uptodate(out_file, in_file): with file_transaction(data, out_file) as tx_out_file: fai_file = ref.fasta_idx(dd.get_ref_file(data)) cmd = ("{gsort} {in_file} {fai_file} | bedtools merge -i - -d {stats[merge_size]} | " "bgzip -c > {tx_out_file}") do.run(cmd.format(**locals()), "Prepare SV callable BED regions") return vcfutils.bgzip_and_index(out_file, data["config"])
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'fake_index'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'in_bam'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '6', 'type': 'block', 'children': ['7', '13', '53']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'index_file'},{'id': '10', 'type': 'binary_operator', 'children': ['11', '12'], 'value': '%'},{'id': '11', 'type': 'string', 'children': [], 'value': '"%s.bai"'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'in_bam'},{'id': '13', 'type': 'if_statement', 'children': ['14', '21']},{'id': '14', 'type': 'not_operator', 'children': ['15']},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'file_exists'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'index_file'},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'with_statement', 'children': ['23', '33']},{'id': '23', 'type': 'with_clause', 'children': ['24']},{'id': '24', 'type': 'with_item', 'children': ['25']},{'id': '25', 'type': 'as_pattern', 'children': ['26', '31']},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'file_transaction'},{'id': '28', 'type': 'argument_list', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'index_file'},{'id': '31', 'type': 'as_pattern_target', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'tx_out_file'},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'with_statement', 'children': ['35', '45']},{'id': '35', 'type': 'with_clause', 'children': ['36']},{'id': '36', 'type': 'with_item', 'children': ['37']},{'id': '37', 'type': 'as_pattern', 'children': ['38', '43']},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '40', 'type': 'argument_list', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'tx_out_file'},{'id': '42', 'type': 'string', 'children': [], 'value': '"w"'},{'id': '43', 'type': 'as_pattern_target', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'out_handle'},{'id': '45', 'type': 'block', 'children': ['46']},{'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': 'out_handle'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'string', 'children': [], 'value': '"name sorted -- no index"'},{'id': '53', 'type': 'return_statement', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'index_file'}
def fake_index(in_bam, data): index_file = "%s.bai" % in_bam if not utils.file_exists(index_file): with file_transaction(data, index_file) as tx_out_file: with open(tx_out_file, "w") as out_handle: out_handle.write("name sorted -- no index") return index_file
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'in_bam'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '8', 'type': 'string', 'children': [], 'value': '"coordinate"'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'out_dir'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '21', '31', '40', '46', '203']},{'id': '13', 'type': 'assert_statement', 'children': ['14', '18']},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'is_bam'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'in_bam'},{'id': '18', 'type': 'binary_operator', 'children': ['19', '20'], 'value': '%'},{'id': '19', 'type': 'string', 'children': [], 'value': '"%s in not a BAM file"'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'in_bam'},{'id': '21', 'type': 'if_statement', 'children': ['22', '28']},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'bam_already_sorted'},{'id': '24', 'type': 'argument_list', 'children': ['25', '26', '27']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'in_bam'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'return_statement', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'in_bam'},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'sort_stem'},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': '_get_sort_stem'},{'id': '36', 'type': 'argument_list', 'children': ['37', '38', '39']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'in_bam'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'out_dir'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'sort_file'},{'id': '43', 'type': 'binary_operator', 'children': ['44', '45'], 'value': '+'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'sort_stem'},{'id': '45', 'type': 'string', 'children': [], 'value': '".bam"'},{'id': '46', 'type': 'if_statement', 'children': ['47', '54']},{'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': 'utils'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'file_exists'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'sort_file'},{'id': '54', 'type': 'block', 'children': ['55', '65', '77']},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'samtools'},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'config_utils'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'get_program'},{'id': '62', 'type': 'argument_list', 'children': ['63', '64']},{'id': '63', 'type': 'string', 'children': [], 'value': '"samtools"'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'cores'},{'id': '68', 'type': 'call', 'children': ['69', '74']},{'id': '69', 'type': 'attribute', 'children': ['70', '73']},{'id': '70', 'type': 'subscript', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '72', 'type': 'string', 'children': [], 'value': '"algorithm"'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '74', 'type': 'argument_list', 'children': ['75', '76']},{'id': '75', 'type': 'string', 'children': [], 'value': '"num_cores"'},{'id': '76', 'type': 'integer', 'children': [], 'value': '1'},{'id': '77', 'type': 'with_statement', 'children': ['78', '88']},{'id': '78', 'type': 'with_clause', 'children': ['79']},{'id': '79', 'type': 'with_item', 'children': ['80']},{'id': '80', 'type': 'as_pattern', 'children': ['81', '86']},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'file_transaction'},{'id': '83', 'type': 'argument_list', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'sort_file'},{'id': '86', 'type': 'as_pattern_target', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'tx_sort_file'},{'id': '88', 'type': 'block', 'children': ['89', '102', '118', '127', '137', '161', '168']},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'tx_sort_stem'},{'id': '92', 'type': 'subscript', 'children': ['93', '101']},{'id': '93', 'type': 'call', 'children': ['94', '99']},{'id': '94', 'type': 'attribute', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'splitext'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'tx_sort_file'},{'id': '101', 'type': 'integer', 'children': [], 'value': '0'},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'tx_dir'},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'safe_makedir'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'call', 'children': ['111', '116']},{'id': '111', 'type': 'attribute', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'dirname'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'tx_sort_file'},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'order_flag'},{'id': '121', 'type': 'conditional_expression', 'children': ['122', '123', '126'], 'value': 'if'},{'id': '122', 'type': 'string', 'children': [], 'value': '"-n"'},{'id': '123', 'type': 'comparison_operator', 'children': ['124', '125'], 'value': '=='},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '125', 'type': 'string', 'children': [], 'value': '"queryname"'},{'id': '126', 'type': 'string', 'children': [], 'value': '""'},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'resources'},{'id': '130', 'type': 'call', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'config_utils'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'get_resources'},{'id': '134', 'type': 'argument_list', 'children': ['135', '136']},{'id': '135', 'type': 'string', 'children': [], 'value': '"samtools"'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'assignment', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'mem'},{'id': '140', 'type': 'call', 'children': ['141', '160']},{'id': '141', 'type': 'attribute', 'children': ['142', '159']},{'id': '142', 'type': 'call', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'config_utils'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'adjust_memory'},{'id': '146', 'type': 'argument_list', 'children': ['147', '154', '155', '156']},{'id': '147', 'type': 'call', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'resources'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '151', 'type': 'argument_list', 'children': ['152', '153']},{'id': '152', 'type': 'string', 'children': [], 'value': '"memory"'},{'id': '153', 'type': 'string', 'children': [], 'value': '"2G"'},{'id': '154', 'type': 'float', 'children': [], 'value': '1.25'},{'id': '155', 'type': 'string', 'children': [], 'value': '"decrease"'},{'id': '156', 'type': 'keyword_argument', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'out_modifier'},{'id': '158', 'type': 'string', 'children': [], 'value': '"M"'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '160', 'type': 'argument_list', 'children': []},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '164', 'type': '()', 'children': ['165']},{'id': '165', 'type': 'concatenated_string', 'children': ['166', '167']},{'id': '166', 'type': 'string', 'children': [], 'value': '"{samtools} sort -@ {cores} -m {mem} -O BAM {order_flag} "'},{'id': '167', 'type': 'string', 'children': [], 'value': '"-T {tx_sort_stem}-sort -o {tx_sort_file} {in_bam}"'},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'call', 'children': ['170', '173']},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'do'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'run'},{'id': '173', 'type': 'argument_list', 'children': ['174', '183']},{'id': '174', 'type': 'call', 'children': ['175', '178']},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '178', 'type': 'argument_list', 'children': ['179']},{'id': '179', 'type': 'dictionary_splat', 'children': ['180']},{'id': '180', 'type': 'call', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'locals'},{'id': '182', 'type': 'argument_list', 'children': []},{'id': '183', 'type': 'binary_operator', 'children': ['184', '185'], 'value': '%'},{'id': '184', 'type': 'string', 'children': [], 'value': '"Sort BAM file %s: %s to %s"'},{'id': '185', 'type': 'tuple', 'children': ['186', '187', '195']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '187', 'type': 'call', 'children': ['188', '193']},{'id': '188', 'type': 'attribute', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '193', 'type': 'argument_list', 'children': ['194']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'in_bam'},{'id': '195', 'type': 'call', 'children': ['196', '201']},{'id': '196', 'type': 'attribute', 'children': ['197', '200']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '201', 'type': 'argument_list', 'children': ['202']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'sort_file'},{'id': '203', 'type': 'return_statement', 'children': ['204']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'sort_file'}
def sort(in_bam, config, order="coordinate", out_dir=None): assert is_bam(in_bam), "%s in not a BAM file" % in_bam if bam_already_sorted(in_bam, config, order): return in_bam sort_stem = _get_sort_stem(in_bam, order, out_dir) sort_file = sort_stem + ".bam" if not utils.file_exists(sort_file): samtools = config_utils.get_program("samtools", config) cores = config["algorithm"].get("num_cores", 1) with file_transaction(config, sort_file) as tx_sort_file: tx_sort_stem = os.path.splitext(tx_sort_file)[0] tx_dir = utils.safe_makedir(os.path.dirname(tx_sort_file)) order_flag = "-n" if order == "queryname" else "" resources = config_utils.get_resources("samtools", config) mem = config_utils.adjust_memory(resources.get("memory", "2G"), 1.25, "decrease", out_modifier="M").upper() cmd = ("{samtools} sort -@ {cores} -m {mem} -O BAM {order_flag} " "-T {tx_sort_stem}-sort -o {tx_sort_file} {in_bam}") do.run(cmd.format(**locals()), "Sort BAM file %s: %s to %s" % (order, os.path.basename(in_bam), os.path.basename(sort_file))) return sort_file
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'tobam_cl'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'is_paired'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '17', '26']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'do_dedup'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': '_check_dedup'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'umi_consensus'},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'dd'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'get_umi_consensus'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '26', 'type': 'with_statement', 'children': ['27', '37']},{'id': '27', 'type': 'with_clause', 'children': ['28']},{'id': '28', 'type': 'with_item', 'children': ['29']},{'id': '29', 'type': 'as_pattern', 'children': ['30', '35']},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'file_transaction'},{'id': '32', 'type': 'argument_list', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '35', 'type': 'as_pattern_target', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'tx_out_file'},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'if_statement', 'children': ['39', '41', '51', '64', '148']},{'id': '39', 'type': 'not_operator', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'do_dedup'},{'id': '41', 'type': 'block', 'children': ['42']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'yield', 'children': ['44']},{'id': '44', 'type': 'tuple', 'children': ['45', '50']},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'sam_to_sortbam_cl'},{'id': '47', 'type': 'argument_list', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'tx_out_file'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'tx_out_file'},{'id': '51', 'type': 'elif_clause', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'umi_consensus'},{'id': '53', 'type': 'block', 'children': ['54']},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'yield', 'children': ['56']},{'id': '56', 'type': 'tuple', 'children': ['57', '63']},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': '_sam_to_grouped_umi_cl'},{'id': '59', 'type': 'argument_list', 'children': ['60', '61', '62']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'umi_consensus'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'tx_out_file'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'tx_out_file'},{'id': '64', 'type': 'elif_clause', 'children': ['65', '82']},{'id': '65', 'type': 'boolean_operator', 'children': ['66', '72'], 'value': 'and'},{'id': '66', 'type': 'boolean_operator', 'children': ['67', '68'], 'value': 'and'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'is_paired'},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': '_need_sr_disc_reads'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '72', 'type': 'not_operator', 'children': ['73']},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': '_too_many_contigs'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'dd'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'get_ref_file'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '82', 'type': 'block', 'children': ['83', '98', '113']},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'sr_file'},{'id': '86', 'type': 'binary_operator', 'children': ['87', '88'], 'value': '%'},{'id': '87', 'type': 'string', 'children': [], 'value': '"%s-sr.bam"'},{'id': '88', 'type': 'subscript', 'children': ['89', '97']},{'id': '89', 'type': 'call', 'children': ['90', '95']},{'id': '90', 'type': 'attribute', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'splitext'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '97', 'type': 'integer', 'children': [], 'value': '0'},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'disc_file'},{'id': '101', 'type': 'binary_operator', 'children': ['102', '103'], 'value': '%'},{'id': '102', 'type': 'string', 'children': [], 'value': '"%s-disc.bam"'},{'id': '103', 'type': 'subscript', 'children': ['104', '112']},{'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': 'os'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'splitext'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '112', 'type': 'integer', 'children': [], 'value': '0'},{'id': '113', 'type': 'with_statement', 'children': ['114', '124']},{'id': '114', 'type': 'with_clause', 'children': ['115']},{'id': '115', 'type': 'with_item', 'children': ['116']},{'id': '116', 'type': 'as_pattern', 'children': ['117', '122']},{'id': '117', 'type': 'call', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'file_transaction'},{'id': '119', 'type': 'argument_list', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'sr_file'},{'id': '122', 'type': 'as_pattern_target', 'children': ['123']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'tx_sr_file'},{'id': '124', 'type': 'block', 'children': ['125']},{'id': '125', 'type': 'with_statement', 'children': ['126', '136']},{'id': '126', 'type': 'with_clause', 'children': ['127']},{'id': '127', 'type': 'with_item', 'children': ['128']},{'id': '128', 'type': 'as_pattern', 'children': ['129', '134']},{'id': '129', 'type': 'call', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'file_transaction'},{'id': '131', 'type': 'argument_list', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'disc_file'},{'id': '134', 'type': 'as_pattern_target', 'children': ['135']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'tx_disc_file'},{'id': '136', 'type': 'block', 'children': ['137']},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'yield', 'children': ['139']},{'id': '139', 'type': 'tuple', 'children': ['140', '147']},{'id': '140', 'type': 'call', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'samblaster_dedup_sort'},{'id': '142', 'type': 'argument_list', 'children': ['143', '144', '145', '146']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'tx_out_file'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'tx_sr_file'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'tx_disc_file'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'tx_out_file'},{'id': '148', 'type': 'else_clause', 'children': ['149']},{'id': '149', 'type': 'block', 'children': ['150']},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'yield', 'children': ['152']},{'id': '152', 'type': 'tuple', 'children': ['153', '158']},{'id': '153', 'type': 'call', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': '_biobambam_dedup_sort'},{'id': '155', 'type': 'argument_list', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'tx_out_file'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'tx_out_file'}
def tobam_cl(data, out_file, is_paired=False): do_dedup = _check_dedup(data) umi_consensus = dd.get_umi_consensus(data) with file_transaction(data, out_file) as tx_out_file: if not do_dedup: yield (sam_to_sortbam_cl(data, tx_out_file), tx_out_file) elif umi_consensus: yield (_sam_to_grouped_umi_cl(data, umi_consensus, tx_out_file), tx_out_file) elif is_paired and _need_sr_disc_reads(data) and not _too_many_contigs(dd.get_ref_file(data)): sr_file = "%s-sr.bam" % os.path.splitext(out_file)[0] disc_file = "%s-disc.bam" % os.path.splitext(out_file)[0] with file_transaction(data, sr_file) as tx_sr_file: with file_transaction(data, disc_file) as tx_disc_file: yield (samblaster_dedup_sort(data, tx_out_file, tx_sr_file, tx_disc_file), tx_out_file) else: yield (_biobambam_dedup_sort(data, tx_out_file), tx_out_file)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sam_to_sortbam_cl'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'tx_out_file'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'name_sort'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '22', '34', '47', '54']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'samtools'},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'config_utils'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'get_program'},{'id': '17', 'type': 'argument_list', 'children': ['18', '19']},{'id': '18', 'type': 'string', 'children': [], 'value': '"samtools"'},{'id': '19', 'type': 'subscript', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '21', 'type': 'string', 'children': [], 'value': '"config"'},{'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': 'cores'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'mem'},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': '_get_cores_memory'},{'id': '29', 'type': 'argument_list', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '31', 'type': 'keyword_argument', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'downscale'},{'id': '33', 'type': 'integer', 'children': [], 'value': '2'},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'tmp_file'},{'id': '37', 'type': 'binary_operator', 'children': ['38', '39'], 'value': '%'},{'id': '38', 'type': 'string', 'children': [], 'value': '"%s-sorttmp"'},{'id': '39', 'type': 'subscript', 'children': ['40', '46']},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'splitext_plus'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'tx_out_file'},{'id': '46', 'type': 'integer', 'children': [], 'value': '0'},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'sort_flag'},{'id': '50', 'type': 'conditional_expression', 'children': ['51', '52', '53'], 'value': 'if'},{'id': '51', 'type': 'string', 'children': [], 'value': '"-n"'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'name_sort'},{'id': '53', 'type': 'string', 'children': [], 'value': '""'},{'id': '54', 'type': 'return_statement', 'children': ['55']},{'id': '55', 'type': '()', 'children': ['56']},{'id': '56', 'type': 'call', 'children': ['57', '62']},{'id': '57', 'type': 'attribute', 'children': ['58', '61']},{'id': '58', 'type': 'concatenated_string', 'children': ['59', '60']},{'id': '59', 'type': 'string', 'children': [], 'value': '"{samtools} sort -@ {cores} -m {mem} {sort_flag} "'},{'id': '60', 'type': 'string', 'children': [], 'value': '"-T {tmp_file} -o {tx_out_file} /dev/stdin"'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'dictionary_splat', 'children': ['64']},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'locals'},{'id': '66', 'type': 'argument_list', 'children': []}
def sam_to_sortbam_cl(data, tx_out_file, name_sort=False): samtools = config_utils.get_program("samtools", data["config"]) cores, mem = _get_cores_memory(data, downscale=2) tmp_file = "%s-sorttmp" % utils.splitext_plus(tx_out_file)[0] sort_flag = "-n" if name_sort else "" return ("{samtools} sort -@ {cores} -m {mem} {sort_flag} " "-T {tmp_file} -o {tx_out_file} /dev/stdin".format(**locals()))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'samblaster_dedup_sort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'tx_out_file'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'tx_sr_file'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'tx_disc_file'},{'id': '8', 'type': 'block', 'children': ['9', '21', '33', '46', '51', '63', '81', '100', '148', '152', '164', '184', '204', '211']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'samblaster'},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'config_utils'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'get_program'},{'id': '16', 'type': 'argument_list', 'children': ['17', '18']},{'id': '17', 'type': 'string', 'children': [], 'value': '"samblaster"'},{'id': '18', 'type': 'subscript', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '20', 'type': 'string', 'children': [], 'value': '"config"'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'samtools'},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'config_utils'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'get_program'},{'id': '28', 'type': 'argument_list', 'children': ['29', '30']},{'id': '29', 'type': 'string', 'children': [], 'value': '"samtools"'},{'id': '30', 'type': 'subscript', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '32', 'type': 'string', 'children': [], 'value': '"config"'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'tmp_prefix'},{'id': '36', 'type': 'binary_operator', 'children': ['37', '38'], 'value': '%'},{'id': '37', 'type': 'string', 'children': [], 'value': '"%s-sorttmp"'},{'id': '38', 'type': 'subscript', 'children': ['39', '45']},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'splitext_plus'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'tx_out_file'},{'id': '45', 'type': 'integer', 'children': [], 'value': '0'},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'tobam_cmd'},{'id': '49', 'type': '()', 'children': ['50']},{'id': '50', 'type': 'string', 'children': [], 'value': '"{samtools} sort {sort_opt} -@ {cores} -m {mem} -T {tmp_prefix}-{dext} {out_file} -"'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '56']},{'id': '53', 'type': 'pattern_list', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'cores'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'mem'},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': '_get_cores_memory'},{'id': '58', 'type': 'argument_list', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '60', 'type': 'keyword_argument', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'downscale'},{'id': '62', 'type': 'integer', 'children': [], 'value': '2'},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'ds_cmd'},{'id': '66', 'type': 'conditional_expression', 'children': ['67', '68', '74'], 'value': 'if'},{'id': '67', 'type': 'None', 'children': []},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'string', 'children': [], 'value': '"align_split"'},{'id': '74', 'type': 'call', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'bam'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'get_maxcov_downsample_cl'},{'id': '78', 'type': 'argument_list', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '80', 'type': 'string', 'children': [], 'value': '"samtools"'},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'sort_opt'},{'id': '84', 'type': 'conditional_expression', 'children': ['85', '86', '99'], 'value': 'if'},{'id': '85', 'type': 'string', 'children': [], 'value': '"-n"'},{'id': '86', 'type': 'boolean_operator', 'children': ['87', '93'], 'value': 'and'},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'string', 'children': [], 'value': '"align_split"'},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'dd'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'get_mark_duplicates'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '99', 'type': 'string', 'children': [], 'value': '""'},{'id': '100', 'type': 'if_statement', 'children': ['101', '102', '126']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'ds_cmd'},{'id': '102', 'type': 'block', 'children': ['103']},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'dedup_cmd'},{'id': '106', 'type': 'binary_operator', 'children': ['107', '108'], 'value': '%'},{'id': '107', 'type': 'string', 'children': [], 'value': '"%s %s > %s"'},{'id': '108', 'type': 'tuple', 'children': ['109', '124', '125']},{'id': '109', 'type': 'call', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'tobam_cmd'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '113', 'type': 'argument_list', 'children': ['114', '117', '120']},{'id': '114', 'type': 'keyword_argument', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '116', 'type': 'string', 'children': [], 'value': '""'},{'id': '117', 'type': 'keyword_argument', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'dext'},{'id': '119', 'type': 'string', 'children': [], 'value': '"full"'},{'id': '120', 'type': 'dictionary_splat', 'children': ['121']},{'id': '121', 'type': 'call', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'locals'},{'id': '123', 'type': 'argument_list', 'children': []},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'ds_cmd'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'tx_out_file'},{'id': '126', 'type': 'else_clause', 'children': ['127']},{'id': '127', 'type': 'block', 'children': ['128']},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'assignment', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'dedup_cmd'},{'id': '131', 'type': 'call', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'tobam_cmd'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '135', 'type': 'argument_list', 'children': ['136', '141', '144']},{'id': '136', 'type': 'keyword_argument', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '138', 'type': 'binary_operator', 'children': ['139', '140'], 'value': '%'},{'id': '139', 'type': 'string', 'children': [], 'value': '"-o %s"'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'tx_out_file'},{'id': '141', 'type': 'keyword_argument', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'dext'},{'id': '143', 'type': 'string', 'children': [], 'value': '"full"'},{'id': '144', 'type': 'dictionary_splat', 'children': ['145']},{'id': '145', 'type': 'call', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'locals'},{'id': '147', 'type': 'argument_list', 'children': []},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'sort_opt'},{'id': '151', 'type': 'string', 'children': [], 'value': '""'},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '157']},{'id': '154', 'type': 'pattern_list', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'cores'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'mem'},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': '_get_cores_memory'},{'id': '159', 'type': 'argument_list', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '161', 'type': 'keyword_argument', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'downscale'},{'id': '163', 'type': 'integer', 'children': [], 'value': '4'},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'assignment', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'splitter_cmd'},{'id': '167', 'type': 'call', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'tobam_cmd'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '171', 'type': 'argument_list', 'children': ['172', '177', '180']},{'id': '172', 'type': 'keyword_argument', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '174', 'type': 'binary_operator', 'children': ['175', '176'], 'value': '%'},{'id': '175', 'type': 'string', 'children': [], 'value': '"-o %s"'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'tx_sr_file'},{'id': '177', 'type': 'keyword_argument', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'dext'},{'id': '179', 'type': 'string', 'children': [], 'value': '"spl"'},{'id': '180', 'type': 'dictionary_splat', 'children': ['181']},{'id': '181', 'type': 'call', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'locals'},{'id': '183', 'type': 'argument_list', 'children': []},{'id': '184', 'type': 'expression_statement', 'children': ['185']},{'id': '185', 'type': 'assignment', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'discordant_cmd'},{'id': '187', 'type': 'call', 'children': ['188', '191']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'tobam_cmd'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '191', 'type': 'argument_list', 'children': ['192', '197', '200']},{'id': '192', 'type': 'keyword_argument', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '194', 'type': 'binary_operator', 'children': ['195', '196'], 'value': '%'},{'id': '195', 'type': 'string', 'children': [], 'value': '"-o %s"'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'tx_disc_file'},{'id': '197', 'type': 'keyword_argument', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'dext'},{'id': '199', 'type': 'string', 'children': [], 'value': '"disc"'},{'id': '200', 'type': 'dictionary_splat', 'children': ['201']},{'id': '201', 'type': 'call', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'locals'},{'id': '203', 'type': 'argument_list', 'children': []},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'assignment', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '207', 'type': '()', 'children': ['208']},{'id': '208', 'type': 'concatenated_string', 'children': ['209', '210']},{'id': '209', 'type': 'string', 'children': [], 'value': '"{samblaster} --addMateTags -M --splitterFile >({splitter_cmd}) --discordantFile >({discordant_cmd}) "'},{'id': '210', 'type': 'string', 'children': [], 'value': '"| {dedup_cmd}"'},{'id': '211', 'type': 'return_statement', 'children': ['212']},{'id': '212', 'type': 'call', 'children': ['213', '216']},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '216', 'type': 'argument_list', 'children': ['217']},{'id': '217', 'type': 'dictionary_splat', 'children': ['218']},{'id': '218', 'type': 'call', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'locals'},{'id': '220', 'type': 'argument_list', 'children': []}
def samblaster_dedup_sort(data, tx_out_file, tx_sr_file, tx_disc_file): samblaster = config_utils.get_program("samblaster", data["config"]) samtools = config_utils.get_program("samtools", data["config"]) tmp_prefix = "%s-sorttmp" % utils.splitext_plus(tx_out_file)[0] tobam_cmd = ("{samtools} sort {sort_opt} -@ {cores} -m {mem} -T {tmp_prefix}-{dext} {out_file} -") cores, mem = _get_cores_memory(data, downscale=2) ds_cmd = None if data.get("align_split") else bam.get_maxcov_downsample_cl(data, "samtools") sort_opt = "-n" if data.get("align_split") and dd.get_mark_duplicates(data) else "" if ds_cmd: dedup_cmd = "%s %s > %s" % (tobam_cmd.format(out_file="", dext="full", **locals()), ds_cmd, tx_out_file) else: dedup_cmd = tobam_cmd.format(out_file="-o %s" % tx_out_file, dext="full", **locals()) sort_opt = "" cores, mem = _get_cores_memory(data, downscale=4) splitter_cmd = tobam_cmd.format(out_file="-o %s" % tx_sr_file, dext="spl", **locals()) discordant_cmd = tobam_cmd.format(out_file="-o %s" % tx_disc_file, dext="disc", **locals()) cmd = ("{samblaster} --addMateTags -M --splitterFile >({splitter_cmd}) --discordantFile >({discordant_cmd}) " "| {dedup_cmd}") return cmd.format(**locals())
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_biobambam_dedup_sort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'tx_out_file'},{'id': '6', 'type': 'block', 'children': ['7', '19', '31', '44', '124']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'samtools'},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'config_utils'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'get_program'},{'id': '14', 'type': 'argument_list', 'children': ['15', '16']},{'id': '15', 'type': 'string', 'children': [], 'value': '"samtools"'},{'id': '16', 'type': 'subscript', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '18', 'type': 'string', 'children': [], 'value': '"config"'},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '24']},{'id': '21', 'type': 'pattern_list', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'cores'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'mem'},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': '_get_cores_memory'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '28', 'type': 'keyword_argument', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'downscale'},{'id': '30', 'type': 'integer', 'children': [], 'value': '2'},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'tmp_file'},{'id': '34', 'type': 'binary_operator', 'children': ['35', '36'], 'value': '%'},{'id': '35', 'type': 'string', 'children': [], 'value': '"%s-sorttmp"'},{'id': '36', 'type': 'subscript', 'children': ['37', '43']},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'splitext_plus'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'tx_out_file'},{'id': '43', 'type': 'integer', 'children': [], 'value': '0'},{'id': '44', 'type': 'if_statement', 'children': ['45', '51', '75']},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'string', 'children': [], 'value': '"align_split"'},{'id': '51', 'type': 'block', 'children': ['52', '69']},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'sort_opt'},{'id': '55', 'type': 'conditional_expression', 'children': ['56', '57', '68'], 'value': 'if'},{'id': '56', 'type': 'string', 'children': [], 'value': '"-n"'},{'id': '57', 'type': 'boolean_operator', 'children': ['58', '64'], 'value': 'and'},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'string', 'children': [], 'value': '"align_split"'},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': '_check_dedup'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '68', 'type': 'string', 'children': [], 'value': '""'},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '72', 'type': 'binary_operator', 'children': ['73', '74'], 'value': '%'},{'id': '73', 'type': 'string', 'children': [], 'value': '"{samtools} sort %s -@ {cores} -m {mem} -O bam -T {tmp_file}-namesort -o {tx_out_file} -"'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'sort_opt'},{'id': '75', 'type': 'else_clause', 'children': ['76']},{'id': '76', 'type': 'block', 'children': ['77', '95', '105', '115']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'cores'},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '82', 'type': 'argument_list', 'children': ['83', '84']},{'id': '83', 'type': 'integer', 'children': [], 'value': '1'},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'math'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'ceil'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'binary_operator', 'children': ['93', '94'], 'value': '*'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'cores'},{'id': '94', 'type': 'float', 'children': [], 'value': '0.75'},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'assignment', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'ds_cmd'},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'bam'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'get_maxcov_downsample_cl'},{'id': '102', 'type': 'argument_list', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '104', 'type': 'string', 'children': [], 'value': '"bamsormadup"'},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'bamsormadup'},{'id': '108', 'type': 'call', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'config_utils'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'get_program'},{'id': '112', 'type': 'argument_list', 'children': ['113', '114']},{'id': '113', 'type': 'string', 'children': [], 'value': '"bamsormadup"'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '118', 'type': '()', 'children': ['119']},{'id': '119', 'type': 'binary_operator', 'children': ['120', '123'], 'value': '%'},{'id': '120', 'type': 'concatenated_string', 'children': ['121', '122']},{'id': '121', 'type': 'string', 'children': [], 'value': '"{bamsormadup} inputformat=sam threads={cores} tmpfile={tmp_file}-markdup "'},{'id': '122', 'type': 'string', 'children': [], 'value': '"SO=coordinate %s > {tx_out_file}"'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'ds_cmd'},{'id': '124', 'type': 'return_statement', 'children': ['125']},{'id': '125', 'type': 'call', 'children': ['126', '129']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'dictionary_splat', 'children': ['131']},{'id': '131', 'type': 'call', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'locals'},{'id': '133', 'type': 'argument_list', 'children': []}
def _biobambam_dedup_sort(data, tx_out_file): samtools = config_utils.get_program("samtools", data["config"]) cores, mem = _get_cores_memory(data, downscale=2) tmp_file = "%s-sorttmp" % utils.splitext_plus(tx_out_file)[0] if data.get("align_split"): sort_opt = "-n" if data.get("align_split") and _check_dedup(data) else "" cmd = "{samtools} sort %s -@ {cores} -m {mem} -O bam -T {tmp_file}-namesort -o {tx_out_file} -" % sort_opt else: cores = max(1, int(math.ceil(cores * 0.75))) ds_cmd = bam.get_maxcov_downsample_cl(data, "bamsormadup") bamsormadup = config_utils.get_program("bamsormadup", data) cmd = ("{bamsormadup} inputformat=sam threads={cores} tmpfile={tmp_file}-markdup " "SO=coordinate %s > {tx_out_file}" % ds_cmd) return cmd.format(**locals())
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_prepare_bam_file'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'bam_file'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'tmp_dir'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '7', 'type': 'block', 'children': ['8', '16', '30']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'sort_mode'},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': '_get_sort_order'},{'id': '13', 'type': 'argument_list', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'bam_file'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '16', 'type': 'if_statement', 'children': ['17', '20']},{'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': '!='},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'sort_mode'},{'id': '19', 'type': 'string', 'children': [], 'value': '"queryname"'},{'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': 'bam_file'},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28', '29']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'bam_file'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '29', 'type': 'string', 'children': [], 'value': '"queryname"'},{'id': '30', 'type': 'return_statement', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'bam_file'}
def _prepare_bam_file(bam_file, tmp_dir, config): sort_mode = _get_sort_order(bam_file, config) if sort_mode != "queryname": bam_file = sort(bam_file, config, "queryname") return bam_file
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_concat_records'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'items_by_key'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'input_order'},{'id': '6', 'type': 'block', 'children': ['7', '11', '33', '42', '51', '99']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'all_records'},{'id': '10', 'type': 'list', 'children': [], 'value': '[]'},{'id': '11', 'type': 'for_statement', 'children': ['12', '15', '20']},{'id': '12', 'type': 'tuple_pattern', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'input_order'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '19', 'type': 'argument_list', 'children': []},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'if_statement', 'children': ['22', '25']},{'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': '=='},{'id': '23', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '24', 'type': 'string', 'children': [], 'value': '"record"'},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'all_records'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'out_items_by_key'},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'deepish_copy'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'items_by_key'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'out_input_order'},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'deepish_copy'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'input_order'},{'id': '51', 'type': 'if_statement', 'children': ['52', '58']},{'id': '52', 'type': 'comparison_operator', 'children': ['53', '57'], 'value': '>'},{'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': 'all_records'},{'id': '57', 'type': 'integer', 'children': [], 'value': '1'},{'id': '58', 'type': 'block', 'children': ['59', '65', '71', '93']},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'final_k'},{'id': '62', 'type': 'subscript', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'all_records'},{'id': '64', 'type': 'integer', 'children': [], 'value': '0'},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'final_v'},{'id': '68', 'type': 'subscript', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'items_by_key'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'final_k'},{'id': '71', 'type': 'for_statement', 'children': ['72', '73', '78']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '73', 'type': 'subscript', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'all_records'},{'id': '75', 'type': 'slice', 'children': ['76', '77']},{'id': '76', 'type': 'integer', 'children': [], 'value': '1'},{'id': '77', 'type': 'colon', 'children': []},{'id': '78', 'type': 'block', 'children': ['79', '85', '89']},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'augmented_assignment', 'children': ['81', '82'], 'value': '+='},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'final_v'},{'id': '82', 'type': 'subscript', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'items_by_key'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '85', 'type': 'delete_statement', 'children': ['86']},{'id': '86', 'type': 'subscript', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'out_items_by_key'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '89', 'type': 'delete_statement', 'children': ['90']},{'id': '90', 'type': 'subscript', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'out_input_order'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '98']},{'id': '95', 'type': 'subscript', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'out_items_by_key'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'final_k'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'final_v'},{'id': '99', 'type': 'return_statement', 'children': ['100']},{'id': '100', 'type': 'expression_list', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'out_items_by_key'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'out_input_order'}
def _concat_records(items_by_key, input_order): all_records = [] for (k, t) in input_order.items(): if t == "record": all_records.append(k) out_items_by_key = utils.deepish_copy(items_by_key) out_input_order = utils.deepish_copy(input_order) if len(all_records) > 1: final_k = all_records[0] final_v = items_by_key[final_k] for k in all_records[1:]: final_v += items_by_key[k] del out_items_by_key[k] del out_input_order[k] out_items_by_key[final_k] = final_v return out_items_by_key, out_input_order
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_combine_files'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'tsv_files'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '7', 'type': 'block', 'children': ['8', '28', '37', '52', '122']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'string', 'children': [], 'value': '"\\t"'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'list', 'children': ['17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27'], 'value': '["caller", "sample", "chrom", "start", "end", "svtype",\n "lof", "annotation", "split_read_support", "paired_support_PE", "paired_support_PR"]'},{'id': '17', 'type': 'string', 'children': [], 'value': '"caller"'},{'id': '18', 'type': 'string', 'children': [], 'value': '"sample"'},{'id': '19', 'type': 'string', 'children': [], 'value': '"chrom"'},{'id': '20', 'type': 'string', 'children': [], 'value': '"start"'},{'id': '21', 'type': 'string', 'children': [], 'value': '"end"'},{'id': '22', 'type': 'string', 'children': [], 'value': '"svtype"'},{'id': '23', 'type': 'string', 'children': [], 'value': '"lof"'},{'id': '24', 'type': 'string', 'children': [], 'value': '"annotation"'},{'id': '25', 'type': 'string', 'children': [], 'value': '"split_read_support"'},{'id': '26', 'type': 'string', 'children': [], 'value': '"paired_support_PE"'},{'id': '27', 'type': 'string', 'children': [], 'value': '"paired_support_PR"'},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'sample'},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'dd'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'get_sample_name'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '40', 'type': 'call', 'children': ['41', '46']},{'id': '41', 'type': 'attribute', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '46', 'type': 'argument_list', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '48', 'type': 'binary_operator', 'children': ['49', '50'], 'value': '%'},{'id': '49', 'type': 'string', 'children': [], 'value': '"%s-prioritize.tsv"'},{'id': '50', 'type': '()', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'sample'},{'id': '52', 'type': 'if_statement', 'children': ['53', '60']},{'id': '53', 'type': 'not_operator', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'file_exists'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'with_statement', 'children': ['62', '72']},{'id': '62', 'type': 'with_clause', 'children': ['63']},{'id': '63', 'type': 'with_item', 'children': ['64']},{'id': '64', 'type': 'as_pattern', 'children': ['65', '70']},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'file_transaction'},{'id': '67', 'type': 'argument_list', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '70', 'type': 'as_pattern_target', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'tx_out_file'},{'id': '72', 'type': 'block', 'children': ['73', '84', '93', '102', '106']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'tmpdir'},{'id': '76', 'type': 'call', 'children': ['77', '82']},{'id': '77', 'type': 'attribute', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'dirname'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'tx_out_file'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'string', 'children': [], 'value': '" "'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'tsv_files'},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'sort_cmd'},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'bedutils'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'get_sort_cmd'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'tmpdir'},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '105', 'type': 'string', 'children': [], 'value': '"{{ echo \'{header}\'; cat {input_files} | {sort_cmd} -k3,3 -k4,4n; }} > {tx_out_file}"'},{'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': 'do'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'run'},{'id': '111', 'type': 'argument_list', 'children': ['112', '121']},{'id': '112', 'type': 'call', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'dictionary_splat', 'children': ['118']},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'locals'},{'id': '120', 'type': 'argument_list', 'children': []},{'id': '121', 'type': 'string', 'children': [], 'value': '"Combine prioritized from multiple callers"'},{'id': '122', 'type': 'return_statement', 'children': ['123']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'out_file'}
def _combine_files(tsv_files, work_dir, data): header = "\t".join(["caller", "sample", "chrom", "start", "end", "svtype", "lof", "annotation", "split_read_support", "paired_support_PE", "paired_support_PR"]) sample = dd.get_sample_name(data) out_file = os.path.join(work_dir, "%s-prioritize.tsv" % (sample)) if not utils.file_exists(out_file): with file_transaction(data, out_file) as tx_out_file: tmpdir = os.path.dirname(tx_out_file) input_files = " ".join(tsv_files) sort_cmd = bedutils.get_sort_cmd(tmpdir) cmd = "{{ echo '{header}'; cat {input_files} | {sort_cmd} -k3,3 -k4,4n; }} > {tx_out_file}" do.run(cmd.format(**locals()), "Combine prioritized from multiple callers") return out_file
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_filenames'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'filenames'},{'id': '5', 'type': 'block', 'children': ['6', '21', '45']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'basenames'},{'id': '9', 'type': 'list_comprehension', 'children': ['10', '18']},{'id': '10', 'type': 'call', 'children': ['11', '16']},{'id': '11', 'type': 'attribute', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'basename'},{'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': 'identifier', 'children': [], 'value': 'filenames'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '24', 'type': 'list_comprehension', 'children': ['25', '28']},{'id': '25', 'type': 'subscript', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '27', 'type': 'integer', 'children': [], 'value': '0'},{'id': '28', 'type': 'for_in_clause', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '32', 'type': 'argument_list', 'children': ['33', '37']},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'basenames'},{'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '39', 'type': 'lambda', 'children': ['40', '42']},{'id': '40', 'type': 'lambda_parameters', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '42', 'type': 'subscript', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '44', 'type': 'integer', 'children': [], 'value': '1'},{'id': '45', 'type': 'return_statement', 'children': ['46']},{'id': '46', 'type': 'list_comprehension', 'children': ['47', '50']},{'id': '47', 'type': 'subscript', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'filenames'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '50', 'type': 'for_in_clause', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'indexes'}
def sort_filenames(filenames): basenames = [os.path.basename(x) for x in filenames] indexes = [i[0] for i in sorted(enumerate(basenames), key=lambda x:x[1])] return [filenames[x] for x in indexes]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_csv'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'in_file'},{'id': '5', 'type': 'block', 'children': ['6', '12', '73']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '9', 'type': 'binary_operator', 'children': ['10', '11'], 'value': '%'},{'id': '10', 'type': 'string', 'children': [], 'value': '"%s.sort"'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'in_file'},{'id': '12', 'type': 'if_statement', 'children': ['13', '34']},{'id': '13', 'type': 'not_operator', 'children': ['14']},{'id': '14', 'type': '()', 'children': ['15']},{'id': '15', 'type': 'boolean_operator', 'children': ['16', '24'], 'value': 'and'},{'id': '16', 'type': 'call', 'children': ['17', '22']},{'id': '17', 'type': 'attribute', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '24', 'type': 'comparison_operator', 'children': ['25', '33'], 'value': '>'},{'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': 'os'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'getsize'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '33', 'type': 'integer', 'children': [], 'value': '0'},{'id': '34', 'type': 'block', 'children': ['35', '43']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'cl'},{'id': '38', 'type': 'list', 'children': ['39', '40', '41', '42'], 'value': '["sort", "-k", "1,1", in_file]'},{'id': '39', 'type': 'string', 'children': [], 'value': '"sort"'},{'id': '40', 'type': 'string', 'children': [], 'value': '"-k"'},{'id': '41', 'type': 'string', 'children': [], 'value': '"1,1"'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'in_file'},{'id': '43', 'type': 'with_statement', 'children': ['44', '54']},{'id': '44', 'type': 'with_clause', 'children': ['45']},{'id': '45', 'type': 'with_item', 'children': ['46']},{'id': '46', 'type': 'as_pattern', 'children': ['47', '52']},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '49', 'type': 'argument_list', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '51', 'type': 'string', 'children': [], 'value': '"w"'},{'id': '52', 'type': 'as_pattern_target', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'out_handle'},{'id': '54', 'type': 'block', 'children': ['55', '67']},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'subprocess'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'Popen'},{'id': '62', 'type': 'argument_list', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'cl'},{'id': '64', 'type': 'keyword_argument', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'out_handle'},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'wait'},{'id': '72', 'type': 'argument_list', 'children': []},{'id': '73', 'type': 'return_statement', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'out_file'}
def sort_csv(in_file): out_file = "%s.sort" % in_file if not (os.path.exists(out_file) and os.path.getsize(out_file) > 0): cl = ["sort", "-k", "1,1", in_file] with open(out_file, "w") as out_handle: child = subprocess.Popen(cl, stdout=out_handle) child.wait() return out_file
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'hydra_to_vcf_writer'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'hydra_file'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'genome_2bit'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'out_handle'},{'id': '8', 'type': 'block', 'children': ['9', '14', '26', '39']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': '_write_vcf_header'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'out_handle'},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'brends'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': '_get_vcf_breakends'},{'id': '22', 'type': 'argument_list', 'children': ['23', '24', '25']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'hydra_file'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'genome_2bit'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'brends'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'keyword_argument', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'attrgetter'},{'id': '36', 'type': 'argument_list', 'children': ['37', '38']},{'id': '37', 'type': 'string', 'children': [], 'value': '"chrom"'},{'id': '38', 'type': 'string', 'children': [], 'value': '"pos"'},{'id': '39', 'type': 'for_statement', 'children': ['40', '41', '42']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'brend'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'brends'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': '_write_vcf_breakend'},{'id': '46', 'type': 'argument_list', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'brend'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'out_handle'}
def hydra_to_vcf_writer(hydra_file, genome_2bit, options, out_handle): _write_vcf_header(out_handle) brends = list(_get_vcf_breakends(hydra_file, genome_2bit, options)) brends.sort(key=attrgetter("chrom", "pos")) for brend in brends: _write_vcf_breakend(brend, out_handle)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_split_by_ready_regions'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'ext'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'file_key'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'dir_ext_fn'},{'id': '7', 'type': 'block', 'children': ['8', '30', '103', '251']},{'id': '8', 'type': 'function_definition', 'children': ['9', '10', '12']},{'id': '9', 'type': 'function_name', 'children': [], 'value': '_sort_by_size'},{'id': '10', 'type': 'parameters', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'region_w_bams'},{'id': '12', 'type': 'block', 'children': ['13', '19', '26']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '18']},{'id': '15', 'type': 'pattern_list', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'region'},{'id': '17', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'region_w_bams'},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '25']},{'id': '21', 'type': 'pattern_list', 'children': ['22', '23', '24']},{'id': '22', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'region'},{'id': '26', 'type': 'return_statement', 'children': ['27']},{'id': '27', 'type': 'binary_operator', 'children': ['28', '29'], 'value': '-'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '30', 'type': 'function_definition', 'children': ['31', '32', '34']},{'id': '31', 'type': 'function_name', 'children': [], 'value': '_assign_bams_to_regions'},{'id': '32', 'type': 'parameters', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'for_statement', 'children': ['36', '39', '45']},{'id': '36', 'type': 'pattern_list', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'region'},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'subscript', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '44', 'type': 'string', 'children': [], 'value': '"region"'},{'id': '45', 'type': 'block', 'children': ['46', '50', '84', '98']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'work_bams'},{'id': '49', 'type': 'list', 'children': [], 'value': '[]'},{'id': '50', 'type': 'for_statement', 'children': ['51', '52', '55']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'xs'},{'id': '52', 'type': 'subscript', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '54', 'type': 'string', 'children': [], 'value': '"region_bams"'},{'id': '55', 'type': 'block', 'children': ['56']},{'id': '56', 'type': 'if_statement', 'children': ['57', '63', '73']},{'id': '57', 'type': 'comparison_operator', 'children': ['58', '62'], 'value': '=='},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'xs'},{'id': '62', 'type': 'integer', 'children': [], 'value': '1'},{'id': '63', 'type': 'block', 'children': ['64']},{'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': 'work_bams'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'subscript', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'xs'},{'id': '72', 'type': 'integer', 'children': [], 'value': '0'},{'id': '73', 'type': 'else_clause', 'children': ['74']},{'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': 'work_bams'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'subscript', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'xs'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '84', 'type': 'for_statement', 'children': ['85', '86', '87']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'work_bam'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'work_bams'},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'assert_statement', 'children': ['89', '97']},{'id': '89', 'type': 'call', 'children': ['90', '95']},{'id': '90', 'type': 'attribute', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'work_bam'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'work_bam'},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'yield', 'children': ['100']},{'id': '100', 'type': 'expression_list', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'region'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'work_bams'},{'id': '103', 'type': 'function_definition', 'children': ['104', '105', '107']},{'id': '104', 'type': 'function_name', 'children': [], 'value': '_do_work'},{'id': '105', 'type': 'parameters', 'children': ['106']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '107', 'type': 'block', 'children': ['108']},{'id': '108', 'type': 'if_statement', 'children': ['109', '112', '245']},{'id': '109', 'type': 'comparison_operator', 'children': ['110', '111'], 'value': 'in'},{'id': '110', 'type': 'string', 'children': [], 'value': '"region"'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '112', 'type': 'block', 'children': ['113', '128', '147', '163', '173', '177', '241']},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '116', 'type': 'conditional_expression', 'children': ['117', '122', '125'], 'value': 'if'},{'id': '117', 'type': 'subscript', 'children': ['118', '121']},{'id': '118', 'type': 'subscript', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '120', 'type': 'string', 'children': [], 'value': '"group"'},{'id': '121', 'type': 'integer', 'children': [], 'value': '0'},{'id': '122', 'type': 'comparison_operator', 'children': ['123', '124'], 'value': 'in'},{'id': '123', 'type': 'string', 'children': [], 'value': '"group"'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '125', 'type': 'subscript', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '127', 'type': 'string', 'children': [], 'value': '"description"'},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'assignment', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'out_dir'},{'id': '131', 'type': 'call', 'children': ['132', '137']},{'id': '132', 'type': 'attribute', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '137', 'type': 'argument_list', 'children': ['138', '143']},{'id': '138', 'type': 'subscript', 'children': ['139', '142']},{'id': '139', 'type': 'subscript', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '141', 'type': 'string', 'children': [], 'value': '"dirs"'},{'id': '142', 'type': 'string', 'children': [], 'value': '"work"'},{'id': '143', 'type': 'call', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'dir_ext_fn'},{'id': '145', 'type': 'argument_list', 'children': ['146']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'assignment', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '150', 'type': 'call', 'children': ['151', '156']},{'id': '151', 'type': 'attribute', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '156', 'type': 'argument_list', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'out_dir'},{'id': '158', 'type': 'binary_operator', 'children': ['159', '160'], 'value': '%'},{'id': '159', 'type': 'string', 'children': [], 'value': '"%s%s"'},{'id': '160', 'type': 'tuple', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'ext'},{'id': '163', 'type': 'assert_statement', 'children': ['164']},{'id': '164', 'type': 'call', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '166', 'type': 'argument_list', 'children': ['167', '170']},{'id': '167', 'type': 'subscript', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '169', 'type': 'string', 'children': [], 'value': '"region"'},{'id': '170', 'type': 'tuple', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'assignment', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'out_parts'},{'id': '176', 'type': 'list', 'children': [], 'value': '[]'},{'id': '177', 'type': 'for_statement', 'children': ['178', '181', '194']},{'id': '178', 'type': 'pattern_list', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'work_bams'},{'id': '181', 'type': 'call', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '183', 'type': 'argument_list', 'children': ['184', '188', '191']},{'id': '184', 'type': 'call', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': '_assign_bams_to_regions'},{'id': '186', 'type': 'argument_list', 'children': ['187']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '188', 'type': 'keyword_argument', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '190', 'type': 'identifier', 'children': [], 'value': '_sort_by_size'},{'id': '191', 'type': 'keyword_argument', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '193', 'type': 'True', 'children': []},{'id': '194', 'type': 'block', 'children': ['195', '209', '231']},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'assignment', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'out_region_dir'},{'id': '198', 'type': 'call', 'children': ['199', '204']},{'id': '199', 'type': 'attribute', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '204', 'type': 'argument_list', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'out_dir'},{'id': '206', 'type': 'subscript', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '208', 'type': 'integer', 'children': [], 'value': '0'},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'assignment', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'out_region_file'},{'id': '212', 'type': 'call', 'children': ['213', '218']},{'id': '213', 'type': 'attribute', 'children': ['214', '217']},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '218', 'type': 'argument_list', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'out_region_dir'},{'id': '220', 'type': 'binary_operator', 'children': ['221', '222'], 'value': '%'},{'id': '221', 'type': 'string', 'children': [], 'value': '"%s-%s%s"'},{'id': '222', 'type': 'tuple', 'children': ['223', '224', '230']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '224', 'type': 'call', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'pregion'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'to_safestr'},{'id': '228', 'type': 'argument_list', 'children': ['229']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'ext'},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'call', 'children': ['233', '236']},{'id': '233', 'type': 'attribute', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'out_parts'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '236', 'type': 'argument_list', 'children': ['237']},{'id': '237', 'type': 'tuple', 'children': ['238', '239', '240']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'work_bams'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'out_region_file'},{'id': '241', 'type': 'return_statement', 'children': ['242']},{'id': '242', 'type': 'expression_list', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'out_parts'},{'id': '245', 'type': 'else_clause', 'children': ['246']},{'id': '246', 'type': 'block', 'children': ['247']},{'id': '247', 'type': 'return_statement', 'children': ['248']},{'id': '248', 'type': 'expression_list', 'children': ['249', '250']},{'id': '249', 'type': 'None', 'children': []},{'id': '250', 'type': 'list', 'children': [], 'value': '[]'},{'id': '251', 'type': 'return_statement', 'children': ['252']},{'id': '252', 'type': 'identifier', 'children': [], 'value': '_do_work'}
def _split_by_ready_regions(ext, file_key, dir_ext_fn): def _sort_by_size(region_w_bams): region, _ = region_w_bams _, start, end = region return end - start def _assign_bams_to_regions(data): for i, region in enumerate(data["region"]): work_bams = [] for xs in data["region_bams"]: if len(xs) == 1: work_bams.append(xs[0]) else: work_bams.append(xs[i]) for work_bam in work_bams: assert os.path.exists(work_bam), work_bam yield region, work_bams def _do_work(data): if "region" in data: name = data["group"][0] if "group" in data else data["description"] out_dir = os.path.join(data["dirs"]["work"], dir_ext_fn(data)) out_file = os.path.join(out_dir, "%s%s" % (name, ext)) assert isinstance(data["region"], (list, tuple)) out_parts = [] for r, work_bams in sorted(_assign_bams_to_regions(data), key=_sort_by_size, reverse=True): out_region_dir = os.path.join(out_dir, r[0]) out_region_file = os.path.join(out_region_dir, "%s-%s%s" % (name, pregion.to_safestr(r), ext)) out_parts.append((r, work_bams, out_region_file)) return out_file, out_parts else: return None, [] return _do_work
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'ERROR', 'children': ['2', '137']},{'id': '2', 'type': 'function_definition', 'children': ['3', '4', '9']},{'id': '3', 'type': 'function_name', 'children': [], 'value': '_combine_variants'},{'id': '4', 'type': 'parameters', 'children': ['5', '6', '7', '8']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'in_vcfs'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'ref_file'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '9', 'type': 'block', 'children': ['10', '16', '20', '121']},{'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': 'in_vcfs'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '15', 'type': 'argument_list', 'children': []},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'wrote_header'},{'id': '19', 'type': 'False', 'children': []},{'id': '20', 'type': 'with_statement', 'children': ['21', '31']},{'id': '21', 'type': 'with_clause', 'children': ['22']},{'id': '22', 'type': 'with_item', 'children': ['23']},{'id': '23', 'type': 'as_pattern', 'children': ['24', '29']},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '28', 'type': 'string', 'children': [], 'value': '"w"'},{'id': '29', 'type': 'as_pattern_target', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'out_handle'},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'for_statement', 'children': ['33', '34', '42']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'in_vcf'},{'id': '34', 'type': 'generator_expression', 'children': ['35', '39']},{'id': '35', 'type': 'subscript', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '37', 'type': 'unary_operator', 'children': ['38'], 'value': '-'},{'id': '38', 'type': 'integer', 'children': [], 'value': '1'},{'id': '39', 'type': 'for_in_clause', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'in_vcfs'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'with_statement', 'children': ['44', '53', '93']},{'id': '44', 'type': 'with_clause', 'children': ['45']},{'id': '45', 'type': 'with_item', 'children': ['46']},{'id': '46', 'type': 'as_pattern', 'children': ['47', '51']},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'in_vcf'},{'id': '51', 'type': 'as_pattern_target', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'in_handle'},{'id': '53', 'type': 'ERROR', 'children': ['54', '55', '56', '71']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'itertools'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'takewhile'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'lambda', 'children': ['62', '64']},{'id': '62', 'type': 'lambda_parameters', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '68', 'type': 'argument_list', 'children': ['69', '70']},{'id': '69', 'type': 'ERROR', 'children': []},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'in_handle'},{'id': '71', 'type': 'not_operator', 'children': ['72']},{'id': '72', 'type': 'comparison_operator', 'children': ['73', '89', '92'], 'value': 'in'},{'id': '73', 'type': 'call', 'children': ['74', '79']},{'id': '74', 'type': 'attribute', 'children': ['75', '78']},{'id': '75', 'type': 'subscript', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '77', 'type': 'integer', 'children': [], 'value': '0'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'binary_operator', 'children': ['81', '82', '86', '88'], 'value': '%'},{'id': '81', 'type': 'string', 'children': [], 'value': '"\n raise ValueError("'},{'id': '82', 'type': 'ERROR', 'children': ['83', '84', '85']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'Unexpected'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'VCF'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '86', 'type': 'ERROR', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'in_vcf'},{'id': '89', 'type': 'ERROR', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'for'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'in_handle'},{'id': '93', 'type': 'block', 'children': ['94', '114']},{'id': '94', 'type': 'if_statement', 'children': ['95', '97']},{'id': '95', 'type': 'not_operator', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'wrote_header'},{'id': '97', 'type': 'block', 'children': ['98', '102']},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'wrote_header'},{'id': '101', 'type': 'True', 'children': []},{'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': 'out_handle'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'call', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'string', 'children': [], 'value': '""'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'call', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'out_handle'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '121', 'type': 'if_statement', 'children': ['122', '124']},{'id': '122', 'type': 'not_operator', 'children': ['123']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'wrote_header'},{'id': '124', 'type': 'block', 'children': ['125']},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'call', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'out_handle'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'call', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'string', 'children': [], 'value': '""'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '137', 'type': 'return_statement', 'children': ['138']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'out_file'}
def _combine_variants(in_vcfs, out_file, ref_file, config): in_vcfs.sort() wrote_header = False with open(out_file, "w") as out_handle: for in_vcf in (x[-1] for x in in_vcfs): with open(in_vcf) as in_handle: header = list(itertools.takewhile(lambda x: x.startswith(" in_handle)) if not header[0].startswith(" raise ValueError("Unexpected VCF file: %s" % in_vcf) for line in in_handle: if not wrote_header: wrote_header = True out_handle.write("".join(header)) out_handle.write(line) if not wrote_header: out_handle.write("".join(header)) return out_file
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'picard_sort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'picard'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'align_bam'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'sort_order'},{'id': '8', 'type': 'string', 'children': [], 'value': '"coordinate"'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'compression_level'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'pipe'},{'id': '17', 'type': 'False', 'children': []},{'id': '18', 'type': 'block', 'children': ['19', '32', '45', '121']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '24']},{'id': '21', 'type': 'pattern_list', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'ext'},{'id': '24', 'type': 'call', 'children': ['25', '30']},{'id': '25', 'type': 'attribute', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'splitext'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'align_bam'},{'id': '32', 'type': 'if_statement', 'children': ['33', '36']},{'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': 'is'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '35', 'type': 'None', 'children': []},{'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': 'out_file'},{'id': '40', 'type': 'binary_operator', 'children': ['41', '42'], 'value': '%'},{'id': '41', 'type': 'string', 'children': [], 'value': '"%s-sort%s"'},{'id': '42', 'type': 'tuple', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'ext'},{'id': '45', 'type': 'if_statement', 'children': ['46', '51']},{'id': '46', 'type': 'not_operator', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'file_exists'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'with_statement', 'children': ['53', '64']},{'id': '53', 'type': 'with_clause', 'children': ['54']},{'id': '54', 'type': 'with_item', 'children': ['55']},{'id': '55', 'type': 'as_pattern', 'children': ['56', '62']},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'tx_tmpdir'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'picard'},{'id': '61', 'type': 'identifier', 'children': [], 'value': '_config'},{'id': '62', 'type': 'as_pattern_target', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'tmp_dir'},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'with_statement', 'children': ['66', '78']},{'id': '66', 'type': 'with_clause', 'children': ['67']},{'id': '67', 'type': 'with_item', 'children': ['68']},{'id': '68', 'type': 'as_pattern', 'children': ['69', '76']},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'file_transaction'},{'id': '71', 'type': 'argument_list', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'picard'},{'id': '74', 'type': 'identifier', 'children': [], 'value': '_config'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '76', 'type': 'as_pattern_target', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'tx_out_file'},{'id': '78', 'type': 'block', 'children': ['79', '98', '110']},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '82', 'type': 'list', 'children': ['83', '86', '92', '95'], 'value': '[("INPUT", align_bam),\n ("OUTPUT", out_file if pipe else tx_out_file),\n ("TMP_DIR", tmp_dir),\n ("SORT_ORDER", sort_order)]'},{'id': '83', 'type': 'tuple', 'children': ['84', '85']},{'id': '84', 'type': 'string', 'children': [], 'value': '"INPUT"'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'align_bam'},{'id': '86', 'type': 'tuple', 'children': ['87', '88']},{'id': '87', 'type': 'string', 'children': [], 'value': '"OUTPUT"'},{'id': '88', 'type': 'conditional_expression', 'children': ['89', '90', '91'], 'value': 'if'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'pipe'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'tx_out_file'},{'id': '92', 'type': 'tuple', 'children': ['93', '94']},{'id': '93', 'type': 'string', 'children': [], 'value': '"TMP_DIR"'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'tmp_dir'},{'id': '95', 'type': 'tuple', 'children': ['96', '97']},{'id': '96', 'type': 'string', 'children': [], 'value': '"SORT_ORDER"'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'sort_order'},{'id': '98', 'type': 'if_statement', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'compression_level'},{'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': 'opts'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'tuple', 'children': ['108', '109']},{'id': '108', 'type': 'string', 'children': [], 'value': '"COMPRESSION_LEVEL"'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'compression_level'},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'picard'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'run'},{'id': '115', 'type': 'argument_list', 'children': ['116', '117', '118']},{'id': '116', 'type': 'string', 'children': [], 'value': '"SortSam"'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '118', 'type': 'keyword_argument', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'pipe'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'pipe'},{'id': '121', 'type': 'return_statement', 'children': ['122']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'out_file'}
def picard_sort(picard, align_bam, sort_order="coordinate", out_file=None, compression_level=None, pipe=False): base, ext = os.path.splitext(align_bam) if out_file is None: out_file = "%s-sort%s" % (base, ext) if not file_exists(out_file): with tx_tmpdir(picard._config) as tmp_dir: with file_transaction(picard._config, out_file) as tx_out_file: opts = [("INPUT", align_bam), ("OUTPUT", out_file if pipe else tx_out_file), ("TMP_DIR", tmp_dir), ("SORT_ORDER", sort_order)] if compression_level: opts.append(("COMPRESSION_LEVEL", compression_level)) picard.run("SortSam", opts, pipe=pipe) return out_file
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'picard_fix_rgs'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'picard'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'in_bam'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '7', 'type': 'block', 'children': ['8', '23', '110']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '11', 'type': 'binary_operator', 'children': ['12', '13'], 'value': '%'},{'id': '12', 'type': 'string', 'children': [], 'value': '"%s-fixrgs.bam"'},{'id': '13', 'type': 'subscript', 'children': ['14', '22']},{'id': '14', 'type': 'call', 'children': ['15', '20']},{'id': '15', 'type': 'attribute', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'splitext'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'in_bam'},{'id': '22', 'type': 'integer', 'children': [], 'value': '0'},{'id': '23', 'type': 'if_statement', 'children': ['24', '29']},{'id': '24', 'type': 'not_operator', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'file_exists'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'with_statement', 'children': ['31', '42']},{'id': '31', 'type': 'with_clause', 'children': ['32']},{'id': '32', 'type': 'with_item', 'children': ['33']},{'id': '33', 'type': 'as_pattern', 'children': ['34', '40']},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'tx_tmpdir'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'picard'},{'id': '39', 'type': 'identifier', 'children': [], 'value': '_config'},{'id': '40', 'type': 'as_pattern_target', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'tmp_dir'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'with_statement', 'children': ['44', '56']},{'id': '44', 'type': 'with_clause', 'children': ['45']},{'id': '45', 'type': 'with_item', 'children': ['46']},{'id': '46', 'type': 'as_pattern', 'children': ['47', '54']},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'file_transaction'},{'id': '49', 'type': 'argument_list', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'picard'},{'id': '52', 'type': 'identifier', 'children': [], 'value': '_config'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '54', 'type': 'as_pattern_target', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'tx_out_file'},{'id': '56', 'type': 'block', 'children': ['57', '102']},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '60', 'type': 'list', 'children': ['61', '64', '67', '70', '75', '84', '89', '94', '99'], 'value': '[("INPUT", in_bam),\n ("OUTPUT", tx_out_file),\n ("SORT_ORDER", "coordinate"),\n ("RGID", names["rg"]),\n ("RGLB", names.get("lb", "unknown")),\n ("RGPL", names["pl"]),\n ("RGPU", names["pu"]),\n ("RGSM", names["sample"]),\n ("TMP_DIR", tmp_dir)]'},{'id': '61', 'type': 'tuple', 'children': ['62', '63']},{'id': '62', 'type': 'string', 'children': [], 'value': '"INPUT"'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'in_bam'},{'id': '64', 'type': 'tuple', 'children': ['65', '66']},{'id': '65', 'type': 'string', 'children': [], 'value': '"OUTPUT"'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'tx_out_file'},{'id': '67', 'type': 'tuple', 'children': ['68', '69']},{'id': '68', 'type': 'string', 'children': [], 'value': '"SORT_ORDER"'},{'id': '69', 'type': 'string', 'children': [], 'value': '"coordinate"'},{'id': '70', 'type': 'tuple', 'children': ['71', '72']},{'id': '71', 'type': 'string', 'children': [], 'value': '"RGID"'},{'id': '72', 'type': 'subscript', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '74', 'type': 'string', 'children': [], 'value': '"rg"'},{'id': '75', 'type': 'tuple', 'children': ['76', '77']},{'id': '76', 'type': 'string', 'children': [], 'value': '"RGLB"'},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '81', 'type': 'argument_list', 'children': ['82', '83']},{'id': '82', 'type': 'string', 'children': [], 'value': '"lb"'},{'id': '83', 'type': 'string', 'children': [], 'value': '"unknown"'},{'id': '84', 'type': 'tuple', 'children': ['85', '86']},{'id': '85', 'type': 'string', 'children': [], 'value': '"RGPL"'},{'id': '86', 'type': 'subscript', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '88', 'type': 'string', 'children': [], 'value': '"pl"'},{'id': '89', 'type': 'tuple', 'children': ['90', '91']},{'id': '90', 'type': 'string', 'children': [], 'value': '"RGPU"'},{'id': '91', 'type': 'subscript', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '93', 'type': 'string', 'children': [], 'value': '"pu"'},{'id': '94', 'type': 'tuple', 'children': ['95', '96']},{'id': '95', 'type': 'string', 'children': [], 'value': '"RGSM"'},{'id': '96', 'type': 'subscript', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '98', 'type': 'string', 'children': [], 'value': '"sample"'},{'id': '99', 'type': 'tuple', 'children': ['100', '101']},{'id': '100', 'type': 'string', 'children': [], 'value': '"TMP_DIR"'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'tmp_dir'},{'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': 'picard'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'run'},{'id': '107', 'type': 'argument_list', 'children': ['108', '109']},{'id': '108', 'type': 'string', 'children': [], 'value': '"AddOrReplaceReadGroups"'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '110', 'type': 'return_statement', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'out_file'}
def picard_fix_rgs(picard, in_bam, names): out_file = "%s-fixrgs.bam" % os.path.splitext(in_bam)[0] if not file_exists(out_file): with tx_tmpdir(picard._config) as tmp_dir: with file_transaction(picard._config, out_file) as tx_out_file: opts = [("INPUT", in_bam), ("OUTPUT", tx_out_file), ("SORT_ORDER", "coordinate"), ("RGID", names["rg"]), ("RGLB", names.get("lb", "unknown")), ("RGPL", names["pl"]), ("RGPU", names["pu"]), ("RGSM", names["sample"]), ("TMP_DIR", tmp_dir)] picard.run("AddOrReplaceReadGroups", opts) return out_file
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_enforce_max_region_size'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'in_file'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '6', 'type': 'block', 'children': ['7', '11', '15', '41', '52', '120']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'max_size'},{'id': '10', 'type': 'integer', 'children': [], 'value': '20000'},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'overlap_size'},{'id': '14', 'type': 'integer', 'children': [], 'value': '250'},{'id': '15', 'type': 'function_definition', 'children': ['16', '17', '19']},{'id': '16', 'type': 'function_name', 'children': [], 'value': '_has_larger_regions'},{'id': '17', 'type': 'parameters', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'return_statement', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '23', 'type': 'generator_expression', 'children': ['24', '33']},{'id': '24', 'type': 'comparison_operator', 'children': ['25', '32'], 'value': '>'},{'id': '25', 'type': 'binary_operator', 'children': ['26', '29'], 'value': '-'},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'max_size'},{'id': '33', 'type': 'for_in_clause', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'pybedtools'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'BedTool'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '44', 'type': 'binary_operator', 'children': ['45', '46'], 'value': '%'},{'id': '45', 'type': 'string', 'children': [], 'value': '"%s-regionlimit%s"'},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'splitext_plus'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'in_file'},{'id': '52', 'type': 'if_statement', 'children': ['53', '60']},{'id': '53', 'type': 'not_operator', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'file_exists'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'if_statement', 'children': ['62', '66', '110']},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': '_has_larger_regions'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'in_file'},{'id': '66', 'type': 'block', 'children': ['67']},{'id': '67', 'type': 'with_statement', 'children': ['68', '78']},{'id': '68', 'type': 'with_clause', 'children': ['69']},{'id': '69', 'type': 'with_item', 'children': ['70']},{'id': '70', 'type': 'as_pattern', 'children': ['71', '76']},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'file_transaction'},{'id': '73', 'type': 'argument_list', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '76', 'type': 'as_pattern_target', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'tx_out_file'},{'id': '78', 'type': 'block', 'children': ['79']},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'call', 'children': ['81', '108']},{'id': '81', 'type': 'attribute', 'children': ['82', '107']},{'id': '82', 'type': 'call', 'children': ['83', '90']},{'id': '83', 'type': 'attribute', 'children': ['84', '89']},{'id': '84', 'type': 'call', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'pybedtools'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'BedTool'},{'id': '88', 'type': 'argument_list', 'children': []},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'window_maker'},{'id': '90', 'type': 'argument_list', 'children': ['91', '94', '99']},{'id': '91', 'type': 'keyword_argument', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'max_size'},{'id': '94', 'type': 'keyword_argument', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '96', 'type': 'binary_operator', 'children': ['97', '98'], 'value': '-'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'max_size'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'overlap_size'},{'id': '99', 'type': 'keyword_argument', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'pybedtools'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'BedTool'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'in_file'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'saveas'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'tx_out_file'},{'id': '110', 'type': 'else_clause', 'children': ['111']},{'id': '111', 'type': 'block', 'children': ['112']},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'call', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'symlink_plus'},{'id': '117', 'type': 'argument_list', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'in_file'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '120', 'type': 'return_statement', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'out_file'}
def _enforce_max_region_size(in_file, data): max_size = 20000 overlap_size = 250 def _has_larger_regions(f): return any(r.stop - r.start > max_size for r in pybedtools.BedTool(f)) out_file = "%s-regionlimit%s" % utils.splitext_plus(in_file) if not utils.file_exists(out_file): if _has_larger_regions(in_file): with file_transaction(data, out_file) as tx_out_file: pybedtools.BedTool().window_maker(w=max_size, s=max_size - overlap_size, b=pybedtools.BedTool(in_file)).saveas(tx_out_file) else: utils.symlink_plus(in_file, out_file) return out_file
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_prep_vrn_file'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'in_file'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'vcaller'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'somatic_info'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'ignore_file'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '10', 'type': 'block', 'children': ['11', '41', '71', '289']},{'id': '11', 'type': 'if_statement', 'children': ['12', '18', '23', '32']},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'vcaller'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'string', 'children': [], 'value': '"vardict"'},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'variant_type'},{'id': '22', 'type': 'string', 'children': [], 'value': '"vardict"'},{'id': '23', 'type': 'elif_clause', 'children': ['24', '27']},{'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': '=='},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'vcaller'},{'id': '26', 'type': 'string', 'children': [], 'value': '"mutect"'},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'variant_type'},{'id': '31', 'type': 'string', 'children': [], 'value': '"mutect-smchet"'},{'id': '32', 'type': 'else_clause', 'children': ['33']},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'raise_statement', 'children': ['35']},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'binary_operator', 'children': ['39', '40'], 'value': '%'},{'id': '39', 'type': 'string', 'children': [], 'value': '"Unexpected variant caller for PhyloWGS prep: %s"'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'vcaller'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '44', 'type': 'call', 'children': ['45', '50']},{'id': '45', 'type': 'attribute', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '50', 'type': 'argument_list', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '52', 'type': 'binary_operator', 'children': ['53', '54'], 'value': '%'},{'id': '53', 'type': 'string', 'children': [], 'value': '"%s-%s-prep.vcf"'},{'id': '54', 'type': 'tuple', 'children': ['55', '70']},{'id': '55', 'type': 'subscript', 'children': ['56', '69']},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'splitext_plus'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'call', 'children': ['62', '67']},{'id': '62', 'type': 'attribute', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'in_file'},{'id': '69', 'type': 'integer', 'children': [], 'value': '0'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'vcaller'},{'id': '71', 'type': 'if_statement', 'children': ['72', '80']},{'id': '72', 'type': 'not_operator', 'children': ['73']},{'id': '73', 'type': 'call', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'file_uptodate'},{'id': '77', 'type': 'argument_list', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'in_file'},{'id': '80', 'type': 'block', 'children': ['81', '88']},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'check_fn'},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': '_min_sample_pass'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'ignore_file'},{'id': '88', 'type': 'with_statement', 'children': ['89', '101']},{'id': '89', 'type': 'with_clause', 'children': ['90']},{'id': '90', 'type': 'with_item', 'children': ['91']},{'id': '91', 'type': 'as_pattern', 'children': ['92', '99']},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'file_transaction'},{'id': '94', 'type': 'argument_list', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'somatic_info'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'tumor_data'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '99', 'type': 'as_pattern_target', 'children': ['100']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'tx_out_file'},{'id': '101', 'type': 'block', 'children': ['102', '113', '167', '228']},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'tx_out_file_raw'},{'id': '105', 'type': 'binary_operator', 'children': ['106', '107'], 'value': '%'},{'id': '106', 'type': 'string', 'children': [], 'value': '"%s-raw%s"'},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'splitext_plus'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'tx_out_file'},{'id': '113', 'type': 'with_statement', 'children': ['114', '123']},{'id': '114', 'type': 'with_clause', 'children': ['115']},{'id': '115', 'type': 'with_item', 'children': ['116']},{'id': '116', 'type': 'as_pattern', 'children': ['117', '121']},{'id': '117', 'type': 'call', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'VariantFile'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'in_file'},{'id': '121', 'type': 'as_pattern_target', 'children': ['122']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'bcf_in'},{'id': '123', 'type': 'block', 'children': ['124', '142', '151']},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'assignment', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'depths'},{'id': '127', 'type': 'list_comprehension', 'children': ['128', '135']},{'id': '128', 'type': 'call', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': '_sample_depth'},{'id': '130', 'type': 'argument_list', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'rec'},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'somatic_info'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'tumor_name'},{'id': '135', 'type': 'for_in_clause', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'rec'},{'id': '137', 'type': 'call', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '139', 'type': 'argument_list', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'check_fn'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'bcf_in'},{'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': 'depths'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'keyword_argument', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '150', 'type': 'True', 'children': []},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'depth_thresh'},{'id': '154', 'type': 'conditional_expression', 'children': ['155', '165', '166'], 'value': 'if'},{'id': '155', 'type': 'subscript', 'children': ['156', '163']},{'id': '156', 'type': 'subscript', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'depths'},{'id': '158', 'type': 'slice', 'children': ['159', '160']},{'id': '159', 'type': 'colon', 'children': []},{'id': '160', 'type': 'subscript', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '162', 'type': 'string', 'children': [], 'value': '"sample_size"'},{'id': '163', 'type': 'unary_operator', 'children': ['164'], 'value': '-'},{'id': '164', 'type': 'integer', 'children': [], 'value': '1'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'depths'},{'id': '166', 'type': 'integer', 'children': [], 'value': '0'},{'id': '167', 'type': 'with_statement', 'children': ['168', '177']},{'id': '168', 'type': 'with_clause', 'children': ['169']},{'id': '169', 'type': 'with_item', 'children': ['170']},{'id': '170', 'type': 'as_pattern', 'children': ['171', '175']},{'id': '171', 'type': 'call', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'VariantFile'},{'id': '173', 'type': 'argument_list', 'children': ['174']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'in_file'},{'id': '175', 'type': 'as_pattern_target', 'children': ['176']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'bcf_in'},{'id': '177', 'type': 'block', 'children': ['178']},{'id': '178', 'type': 'with_statement', 'children': ['179', '194']},{'id': '179', 'type': 'with_clause', 'children': ['180']},{'id': '180', 'type': 'with_item', 'children': ['181']},{'id': '181', 'type': 'as_pattern', 'children': ['182', '192']},{'id': '182', 'type': 'call', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'VariantFile'},{'id': '184', 'type': 'argument_list', 'children': ['185', '186', '187']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'tx_out_file_raw'},{'id': '186', 'type': 'string', 'children': [], 'value': '"w"'},{'id': '187', 'type': 'keyword_argument', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'bcf_in'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '192', 'type': 'as_pattern_target', 'children': ['193']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'bcf_out'},{'id': '194', 'type': 'block', 'children': ['195']},{'id': '195', 'type': 'for_statement', 'children': ['196', '197', '198']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'rec'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'bcf_in'},{'id': '198', 'type': 'block', 'children': ['199']},{'id': '199', 'type': 'if_statement', 'children': ['200', '220']},{'id': '200', 'type': '()', 'children': ['201']},{'id': '201', 'type': 'boolean_operator', 'children': ['202', '206'], 'value': 'and'},{'id': '202', 'type': 'call', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'check_fn'},{'id': '204', 'type': 'argument_list', 'children': ['205']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'rec'},{'id': '206', 'type': '()', 'children': ['207']},{'id': '207', 'type': 'boolean_operator', 'children': ['208', '211'], 'value': 'or'},{'id': '208', 'type': 'comparison_operator', 'children': ['209', '210'], 'value': '<'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'depth_thresh'},{'id': '210', 'type': 'integer', 'children': [], 'value': '5'},{'id': '211', 'type': 'comparison_operator', 'children': ['212', '219'], 'value': '>='},{'id': '212', 'type': 'call', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': '_sample_depth'},{'id': '214', 'type': 'argument_list', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'rec'},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'somatic_info'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'tumor_name'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'depth_thresh'},{'id': '220', 'type': 'block', 'children': ['221']},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'call', 'children': ['223', '226']},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'bcf_out'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '226', 'type': 'argument_list', 'children': ['227']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'rec'},{'id': '228', 'type': 'with_statement', 'children': ['229', '238']},{'id': '229', 'type': 'with_clause', 'children': ['230']},{'id': '230', 'type': 'with_item', 'children': ['231']},{'id': '231', 'type': 'as_pattern', 'children': ['232', '236']},{'id': '232', 'type': 'call', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '234', 'type': 'argument_list', 'children': ['235']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'tx_out_file_raw'},{'id': '236', 'type': 'as_pattern_target', 'children': ['237']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'in_handle'},{'id': '238', 'type': 'block', 'children': ['239']},{'id': '239', 'type': 'with_statement', 'children': ['240', '250']},{'id': '240', 'type': 'with_clause', 'children': ['241']},{'id': '241', 'type': 'with_item', 'children': ['242']},{'id': '242', 'type': 'as_pattern', 'children': ['243', '248']},{'id': '243', 'type': 'call', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '245', 'type': 'argument_list', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'tx_out_file'},{'id': '247', 'type': 'string', 'children': [], 'value': '"w"'},{'id': '248', 'type': 'as_pattern_target', 'children': ['249']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'out_handle'},{'id': '250', 'type': 'block', 'children': ['251']},{'id': '251', 'type': 'for_statement', 'children': ['252', '253', '254', '288']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'in_handle'},{'id': '254', 'type': 'ERROR', 'children': ['255', '282']},{'id': '255', 'type': 'ERROR', 'children': ['256', '269', '275', '276']},{'id': '256', 'type': 'not_operator', 'children': ['257']},{'id': '257', 'type': 'subscript', 'children': ['258', '266', '268']},{'id': '258', 'type': 'call', 'children': ['259', '262']},{'id': '259', 'type': 'attribute', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '262', 'type': 'argument_list', 'children': ['263', '264']},{'id': '263', 'type': 'string', 'children': [], 'value': '"\n parts = line.split("'},{'id': '264', 'type': 'ERROR', 'children': ['265']},{'id': '265', 'type': 'escape_sequence', 'children': [], 'value': '\\t'},{'id': '266', 'type': 'ERROR', 'children': ['267']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '268', 'type': 'integer', 'children': [], 'value': '0'},{'id': '269', 'type': 'call', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': '_phylowgs_compatible_chroms'},{'id': '271', 'type': 'argument_list', 'children': ['272']},{'id': '272', 'type': 'subscript', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '274', 'type': 'integer', 'children': [], 'value': '0'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '276', 'type': 'call', 'children': ['277', '280']},{'id': '277', 'type': 'attribute', 'children': ['278', '279']},{'id': '278', 'type': 'string', 'children': [], 'value': '"\\t"'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '280', 'type': 'argument_list', 'children': ['281']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '282', 'type': 'call', 'children': ['283', '286']},{'id': '283', 'type': 'attribute', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'out_handle'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '286', 'type': 'argument_list', 'children': ['287']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '288', 'type': 'block', 'children': [], 'value': ''},{'id': '289', 'type': 'return_statement', 'children': ['290']},{'id': '290', 'type': 'expression_list', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'variant_type'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'out_file'}
def _prep_vrn_file(in_file, vcaller, work_dir, somatic_info, ignore_file, config): if vcaller.startswith("vardict"): variant_type = "vardict" elif vcaller == "mutect": variant_type = "mutect-smchet" else: raise ValueError("Unexpected variant caller for PhyloWGS prep: %s" % vcaller) out_file = os.path.join(work_dir, "%s-%s-prep.vcf" % (utils.splitext_plus(os.path.basename(in_file))[0], vcaller)) if not utils.file_uptodate(out_file, in_file): check_fn = _min_sample_pass(ignore_file) with file_transaction(somatic_info.tumor_data, out_file) as tx_out_file: tx_out_file_raw = "%s-raw%s" % utils.splitext_plus(tx_out_file) with VariantFile(in_file) as bcf_in: depths = [_sample_depth(rec, somatic_info.tumor_name) for rec in filter(check_fn, bcf_in)] depths.sort(reverse=True) depth_thresh = depths[:config["sample_size"]][-1] if depths else 0 with VariantFile(in_file) as bcf_in: with VariantFile(tx_out_file_raw, "w", header=bcf_in.header) as bcf_out: for rec in bcf_in: if (check_fn(rec) and (depth_thresh < 5 or _sample_depth(rec, somatic_info.tumor_name) >= depth_thresh)): bcf_out.write(rec) with open(tx_out_file_raw) as in_handle: with open(tx_out_file, "w") as out_handle: for line in in_handle: if not line.startswith(" parts = line.split("\t") parts[0] = _phylowgs_compatible_chroms(parts[0]) line = "\t".join(parts) out_handle.write(line) return variant_type, out_file
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'concat'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'bed_files'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'catted'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '19', '68', '113']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'bed_files'},{'id': '12', 'type': 'list_comprehension', 'children': ['13', '14', '17']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '14', 'type': 'for_in_clause', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'bed_files'},{'id': '17', 'type': 'if_clause', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '19', 'type': 'if_statement', 'children': ['20', '26']},{'id': '20', 'type': 'comparison_operator', 'children': ['21', '25'], 'value': '=='},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'bed_files'},{'id': '25', 'type': 'integer', 'children': [], 'value': '0'},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'if_statement', 'children': ['28', '29', '64']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'catted'},{'id': '29', 'type': 'block', 'children': ['30', '38']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'sorted_bed'},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'catted'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '37', 'type': 'argument_list', 'children': []},{'id': '38', 'type': 'if_statement', 'children': ['39', '48', '60']},{'id': '39', 'type': 'not_operator', 'children': ['40']},{'id': '40', 'type': 'call', 'children': ['41', '46']},{'id': '41', 'type': 'attribute', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'sorted_bed'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'fn'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'string', 'children': [], 'value': '".bed"'},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'return_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'sorted_bed'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'moveto'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'binary_operator', 'children': ['56', '59'], 'value': '+'},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'sorted_bed'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'fn'},{'id': '59', 'type': 'string', 'children': [], 'value': '".bed"'},{'id': '60', 'type': 'else_clause', 'children': ['61']},{'id': '61', 'type': 'block', 'children': ['62']},{'id': '62', 'type': 'return_statement', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'sorted_bed'},{'id': '64', 'type': 'else_clause', 'children': ['65']},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'return_statement', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'catted'},{'id': '68', 'type': 'if_statement', 'children': ['69', '71', '92']},{'id': '69', 'type': 'not_operator', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'catted'},{'id': '71', 'type': 'block', 'children': ['72', '79']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'bed_files'},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'bed_files'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'catted'},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'bt'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'BedTool'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'bed_files'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'pop'},{'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': 'catted'},{'id': '97', 'type': 'call', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'catted'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'cat'},{'id': '101', 'type': 'argument_list', 'children': ['102', '107', '110']},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'bed_files'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '106', 'type': 'argument_list', 'children': []},{'id': '107', 'type': 'keyword_argument', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'postmerge'},{'id': '109', 'type': 'False', 'children': []},{'id': '110', 'type': 'keyword_argument', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'force_truncate'},{'id': '112', 'type': 'False', 'children': []},{'id': '113', 'type': 'return_statement', 'children': ['114']},{'id': '114', 'type': 'call', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'concat'},{'id': '116', 'type': 'argument_list', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'bed_files'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'catted'}
def concat(bed_files, catted=None): bed_files = [x for x in bed_files if x] if len(bed_files) == 0: if catted: sorted_bed = catted.sort() if not sorted_bed.fn.endswith(".bed"): return sorted_bed.moveto(sorted_bed.fn + ".bed") else: return sorted_bed else: return catted if not catted: bed_files = list(bed_files) catted = bt.BedTool(bed_files.pop()) else: catted = catted.cat(bed_files.pop(), postmerge=False, force_truncate=False) return concat(bed_files, catted)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_sv_callers'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '5', 'type': 'block', 'children': ['6', '10', '33']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'callers'},{'id': '9', 'type': 'list', 'children': [], 'value': '[]'},{'id': '10', 'type': 'for_statement', 'children': ['11', '12', '13']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'for_statement', 'children': ['15', '16', '23']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'sv'},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '20', 'type': 'argument_list', 'children': ['21', '22']},{'id': '21', 'type': 'string', 'children': [], 'value': '"sv"'},{'id': '22', 'type': 'list', 'children': [], 'value': '[]'},{'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': 'callers'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'subscript', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'sv'},{'id': '32', 'type': 'string', 'children': [], 'value': '"variantcaller"'},{'id': '33', 'type': 'return_statement', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '52']},{'id': '35', 'type': 'attribute', 'children': ['36', '51']},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'list_comprehension', 'children': ['43', '44', '47']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '44', 'type': 'for_in_clause', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'callers'},{'id': '47', 'type': 'if_clause', 'children': ['48']},{'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': '!='},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '50', 'type': 'string', 'children': [], 'value': '"sv-ensemble"'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '52', 'type': 'argument_list', 'children': []}
def _get_sv_callers(items): callers = [] for data in items: for sv in data.get("sv", []): callers.append(sv["variantcaller"]) return list(set([x for x in callers if x != "sv-ensemble"])).sort()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_sort_cmd'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'tmp_dir'},{'id': '6', 'type': 'None', 'children': []},{'id': '7', 'type': 'block', 'children': ['8', '24', '37', '64']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'has_versionsort'},{'id': '11', 'type': 'call', 'children': ['12', '23']},{'id': '12', 'type': 'attribute', 'children': ['13', '22']},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'subprocess'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'check_output'},{'id': '17', 'type': 'argument_list', 'children': ['18', '19']},{'id': '18', 'type': 'string', 'children': [], 'value': '"sort --help | grep version-sort; exit 0"'},{'id': '19', 'type': 'keyword_argument', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'shell'},{'id': '21', 'type': 'True', 'children': []},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '23', 'type': 'argument_list', 'children': []},{'id': '24', 'type': 'if_statement', 'children': ['25', '26', '31']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'has_versionsort'},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '30', 'type': 'string', 'children': [], 'value': '"sort -V"'},{'id': '31', 'type': 'else_clause', 'children': ['32']},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '36', 'type': 'string', 'children': [], 'value': '"sort"'},{'id': '37', 'type': 'if_statement', 'children': ['38', '57']},{'id': '38', 'type': 'boolean_operator', 'children': ['39', '49'], 'value': 'and'},{'id': '39', 'type': 'boolean_operator', 'children': ['40', '41'], 'value': 'and'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'tmp_dir'},{'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': 'os'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'tmp_dir'},{'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': 'os'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'isdir'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'tmp_dir'},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'augmented_assignment', 'children': ['60', '61'], 'value': '+='},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '61', 'type': 'binary_operator', 'children': ['62', '63'], 'value': '%'},{'id': '62', 'type': 'string', 'children': [], 'value': '" -T %s"'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'tmp_dir'},{'id': '64', 'type': 'return_statement', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'cmd'}
def get_sort_cmd(tmp_dir=None): has_versionsort = subprocess.check_output("sort --help | grep version-sort; exit 0", shell=True).strip() if has_versionsort: cmd = "sort -V" else: cmd = "sort" if tmp_dir and os.path.exists(tmp_dir) and os.path.isdir(tmp_dir): cmd += " -T %s" % tmp_dir return cmd
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'clean_file'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'in_file'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '8', 'type': 'string', 'children': [], 'value': '""'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'bedprep_dir'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'simple'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'block', 'children': ['16', '23']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'simple'},{'id': '19', 'type': 'conditional_expression', 'children': ['20', '21', '22'], 'value': 'if'},{'id': '20', 'type': 'string', 'children': [], 'value': '"iconv -c -f utf-8 -t ascii | sed \'s/ //g\' |"'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'simple'},{'id': '22', 'type': 'string', 'children': [], 'value': '""'},{'id': '23', 'type': 'if_statement', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'in_file'},{'id': '25', 'type': 'block', 'children': ['26', '51', '70', '93', '103', '120', '216', '233']},{'id': '26', 'type': 'if_statement', 'children': ['27', '29']},{'id': '27', 'type': 'not_operator', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'bedprep_dir'},{'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': 'bedprep_dir'},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'safe_makedir'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'call', 'children': ['39', '44']},{'id': '39', 'type': 'attribute', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '44', 'type': 'argument_list', 'children': ['45', '50']},{'id': '45', 'type': 'subscript', 'children': ['46', '49']},{'id': '46', 'type': 'subscript', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '48', 'type': 'string', 'children': [], 'value': '"dirs"'},{'id': '49', 'type': 'string', 'children': [], 'value': '"work"'},{'id': '50', 'type': 'string', 'children': [], 'value': '"bedprep"'},{'id': '51', 'type': 'if_statement', 'children': ['52', '67']},{'id': '52', 'type': 'boolean_operator', 'children': ['53', '54'], 'value': 'and'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '54', 'type': 'call', 'children': ['55', '65']},{'id': '55', 'type': 'attribute', 'children': ['56', '64']},{'id': '56', 'type': 'call', 'children': ['57', '62']},{'id': '57', 'type': 'attribute', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'in_file'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'return_statement', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'in_file'},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '73', 'type': 'call', 'children': ['74', '79']},{'id': '74', 'type': 'attribute', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '79', 'type': 'argument_list', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'bedprep_dir'},{'id': '81', 'type': 'binary_operator', 'children': ['82', '83'], 'value': '%'},{'id': '82', 'type': 'string', 'children': [], 'value': '"%s%s"'},{'id': '83', 'type': 'tuple', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '85', 'type': 'call', 'children': ['86', '91']},{'id': '86', 'type': 'attribute', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'in_file'},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '100', 'type': 'argument_list', 'children': ['101', '102']},{'id': '101', 'type': 'string', 'children': [], 'value': '".interval_list"'},{'id': '102', 'type': 'string', 'children': [], 'value': '".bed"'},{'id': '103', 'type': 'if_statement', 'children': ['104', '110']},{'id': '104', 'type': 'call', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'string', 'children': [], 'value': '".gz"'},{'id': '110', 'type': 'block', 'children': ['111']},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '114', 'type': 'subscript', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '116', 'type': 'slice', 'children': ['117', '118']},{'id': '117', 'type': 'colon', 'children': []},{'id': '118', 'type': 'unary_operator', 'children': ['119'], 'value': '-'},{'id': '119', 'type': 'integer', 'children': [], 'value': '3'},{'id': '120', 'type': 'if_statement', 'children': ['121', '129']},{'id': '121', 'type': 'not_operator', 'children': ['122']},{'id': '122', 'type': 'call', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'file_uptodate'},{'id': '126', 'type': 'argument_list', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'in_file'},{'id': '129', 'type': 'block', 'children': ['130', '136', '142']},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'call', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'check_bed_contigs'},{'id': '133', 'type': 'argument_list', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'in_file'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'call', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'check_bed_coords'},{'id': '139', 'type': 'argument_list', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'in_file'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '142', 'type': 'with_statement', 'children': ['143', '153']},{'id': '143', 'type': 'with_clause', 'children': ['144']},{'id': '144', 'type': 'with_item', 'children': ['145']},{'id': '145', 'type': 'as_pattern', 'children': ['146', '151']},{'id': '146', 'type': 'call', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'file_transaction'},{'id': '148', 'type': 'argument_list', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '151', 'type': 'as_pattern_target', 'children': ['152']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'tx_out_file'},{'id': '153', 'type': 'block', 'children': ['154', '160', '172', '186', '199']},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'assignment', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'bcbio_py'},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'executable'},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'cat_cmd'},{'id': '163', 'type': 'conditional_expression', 'children': ['164', '165', '171'], 'value': 'if'},{'id': '164', 'type': 'string', 'children': [], 'value': '"zcat"'},{'id': '165', 'type': 'call', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'in_file'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '169', 'type': 'argument_list', 'children': ['170']},{'id': '170', 'type': 'string', 'children': [], 'value': '".gz"'},{'id': '171', 'type': 'string', 'children': [], 'value': '"cat"'},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'assignment', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'sort_cmd'},{'id': '175', 'type': 'call', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'get_sort_cmd'},{'id': '177', 'type': 'argument_list', 'children': ['178']},{'id': '178', 'type': 'call', 'children': ['179', '184']},{'id': '179', 'type': 'attribute', 'children': ['180', '183']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'dirname'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'tx_out_file'},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '189', 'type': '()', 'children': ['190']},{'id': '190', 'type': 'binary_operator', 'children': ['191', '196'], 'value': '^'},{'id': '191', 'type': 'binary_operator', 'children': ['192', '193', '195'], 'value': '-'},{'id': '192', 'type': 'string', 'children': [], 'value': '"{cat_cmd} {in_file} | grep -v ^track | grep -v ^browser | grep -v ^@ | "'},{'id': '193', 'type': 'ERROR', 'children': ['194']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'grep'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '196', 'type': 'concatenated_string', 'children': ['197', '198']},{'id': '197', 'type': 'string', 'children': [], 'value': '"{bcbio_py} -c \'from bcbio.variation import bedutils; bedutils.remove_bad()\' | "'},{'id': '198', 'type': 'string', 'children': [], 'value': '"{sort_cmd} -k1,1 -k2,2n > {tx_out_file}"'},{'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': 'do'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'run'},{'id': '204', 'type': 'argument_list', 'children': ['205', '214', '215']},{'id': '205', 'type': 'call', 'children': ['206', '209']},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '209', 'type': 'argument_list', 'children': ['210']},{'id': '210', 'type': 'dictionary_splat', 'children': ['211']},{'id': '211', 'type': 'call', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'locals'},{'id': '213', 'type': 'argument_list', 'children': []},{'id': '214', 'type': 'string', 'children': [], 'value': '"Prepare cleaned BED file"'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '216', 'type': 'expression_statement', 'children': ['217']},{'id': '217', 'type': 'call', 'children': ['218', '221']},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'vcfutils'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'bgzip_and_index'},{'id': '221', 'type': 'argument_list', 'children': ['222', '223', '230']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '223', 'type': 'call', 'children': ['224', '227']},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '227', 'type': 'argument_list', 'children': ['228', '229']},{'id': '228', 'type': 'string', 'children': [], 'value': '"config"'},{'id': '229', 'type': 'dictionary', 'children': []},{'id': '230', 'type': 'keyword_argument', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'remove_orig'},{'id': '232', 'type': 'False', 'children': []},{'id': '233', 'type': 'return_statement', 'children': ['234']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'out_file'}
def clean_file(in_file, data, prefix="", bedprep_dir=None, simple=None): simple = "iconv -c -f utf-8 -t ascii | sed 's/ //g' |" if simple else "" if in_file: if not bedprep_dir: bedprep_dir = utils.safe_makedir(os.path.join(data["dirs"]["work"], "bedprep")) if prefix and os.path.basename(in_file).startswith(prefix): return in_file out_file = os.path.join(bedprep_dir, "%s%s" % (prefix, os.path.basename(in_file))) out_file = out_file.replace(".interval_list", ".bed") if out_file.endswith(".gz"): out_file = out_file[:-3] if not utils.file_uptodate(out_file, in_file): check_bed_contigs(in_file, data) check_bed_coords(in_file, data) with file_transaction(data, out_file) as tx_out_file: bcbio_py = sys.executable cat_cmd = "zcat" if in_file.endswith(".gz") else "cat" sort_cmd = get_sort_cmd(os.path.dirname(tx_out_file)) cmd = ("{cat_cmd} {in_file} | grep -v ^track | grep -v ^browser | grep -v ^@ | " "grep -v ^ "{bcbio_py} -c 'from bcbio.variation import bedutils; bedutils.remove_bad()' | " "{sort_cmd} -k1,1 -k2,2n > {tx_out_file}") do.run(cmd.format(**locals()), "Prepare cleaned BED file", data) vcfutils.bgzip_and_index(out_file, data.get("config", {}), remove_orig=False) return out_file
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_sort_by_region'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'fnames'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'regions'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'ref_file'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '8', 'type': 'block', 'children': ['9', '13', '36', '40', '53', '60', '174', '180']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'contig_order'},{'id': '12', 'type': 'dictionary', 'children': []},{'id': '13', 'type': 'for_statement', 'children': ['14', '17', '27']},{'id': '14', 'type': 'pattern_list', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'sq'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'file_contigs'},{'id': '24', 'type': 'argument_list', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'ref_file'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '35']},{'id': '30', 'type': 'subscript', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'contig_order'},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'sq'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'sitems'},{'id': '39', 'type': 'list', 'children': [], 'value': '[]'},{'id': '40', 'type': 'assert_statement', 'children': ['41', '50']},{'id': '41', 'type': 'comparison_operator', 'children': ['42', '46'], 'value': '=='},{'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': 'regions'},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'fnames'},{'id': '50', 'type': 'tuple', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'regions'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'fnames'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'added_fnames'},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'list', 'children': [], 'value': '[]'},{'id': '60', 'type': 'for_statement', 'children': ['61', '64', '69']},{'id': '61', 'type': 'pattern_list', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'region'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'fname'},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '66', 'type': 'argument_list', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'regions'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'fnames'},{'id': '69', 'type': 'block', 'children': ['70']},{'id': '70', 'type': 'if_statement', 'children': ['71', '74']},{'id': '71', 'type': 'comparison_operator', 'children': ['72', '73'], 'value': 'not'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'fname'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'added_fnames'},{'id': '74', 'type': 'block', 'children': ['75', '152', '167']},{'id': '75', 'type': 'if_statement', 'children': ['76', '83', '91', '138']},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '78', 'type': 'argument_list', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'region'},{'id': '80', 'type': 'tuple', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '83', 'type': 'block', 'children': ['84']},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '90']},{'id': '86', 'type': 'pattern_list', 'children': ['87', '88', '89']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'region'},{'id': '91', 'type': 'elif_clause', 'children': ['92', '108']},{'id': '92', 'type': 'boolean_operator', 'children': ['93', '100'], 'value': 'and'},{'id': '93', 'type': 'call', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '95', 'type': 'argument_list', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'region'},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'string_types'},{'id': '100', 'type': 'comparison_operator', 'children': ['101', '107'], 'value': '>='},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'region'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'string', 'children': [], 'value': '":"'},{'id': '107', 'type': 'integer', 'children': [], 'value': '0'},{'id': '108', 'type': 'block', 'children': ['109', '120']},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '114']},{'id': '111', 'type': 'pattern_list', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'coords'},{'id': '114', 'type': 'call', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'region'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'string', 'children': [], 'value': '":"'},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '125']},{'id': '122', 'type': 'pattern_list', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '125', 'type': 'list_comprehension', 'children': ['126', '130']},{'id': '126', 'type': 'call', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '130', 'type': 'for_in_clause', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '132', 'type': 'call', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'coords'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '138', 'type': 'else_clause', 'children': ['139']},{'id': '139', 'type': 'block', 'children': ['140', '144']},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'assignment', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'region'},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '149']},{'id': '146', 'type': 'pattern_list', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '149', 'type': 'expression_list', 'children': ['150', '151']},{'id': '150', 'type': 'integer', 'children': [], 'value': '0'},{'id': '151', 'type': 'integer', 'children': [], 'value': '0'},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'call', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'sitems'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'tuple', 'children': ['159', '165', '166']},{'id': '159', 'type': 'tuple', 'children': ['160', '163', '164']},{'id': '160', 'type': 'subscript', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'contig_order'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'fname'},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'call', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'added_fnames'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'fname'},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'call', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'sitems'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '179', 'type': 'argument_list', 'children': []},{'id': '180', 'type': 'return_statement', 'children': ['181']},{'id': '181', 'type': 'list_comprehension', 'children': ['182', '189']},{'id': '182', 'type': 'tuple', 'children': ['183', '186']},{'id': '183', 'type': 'subscript', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '185', 'type': 'integer', 'children': [], 'value': '1'},{'id': '186', 'type': 'subscript', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '188', 'type': 'integer', 'children': [], 'value': '2'},{'id': '189', 'type': 'for_in_clause', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'sitems'}
def _sort_by_region(fnames, regions, ref_file, config): contig_order = {} for i, sq in enumerate(ref.file_contigs(ref_file, config)): contig_order[sq.name] = i sitems = [] assert len(regions) == len(fnames), (regions, fnames) added_fnames = set([]) for region, fname in zip(regions, fnames): if fname not in added_fnames: if isinstance(region, (list, tuple)): c, s, e = region elif isinstance(region, six.string_types) and region.find(":") >= 0: c, coords = region.split(":") s, e = [int(x) for x in coords.split("-")] else: c = region s, e = 0, 0 sitems.append(((contig_order[c], s, e), c, fname)) added_fnames.add(fname) sitems.sort() return [(x[1], x[2]) for x in sitems]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_file_list'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'orig_files'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'regions'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'ref_file'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '9', 'type': 'block', 'children': ['10', '20', '46', '102', '117', '130', '155']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'sorted_files'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': '_sort_by_region'},{'id': '15', 'type': 'argument_list', 'children': ['16', '17', '18', '19']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'orig_files'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'regions'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'ref_file'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'exist_files'},{'id': '23', 'type': 'list_comprehension', 'children': ['24', '27', '32']},{'id': '24', 'type': 'tuple', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '27', 'type': 'for_in_clause', 'children': ['28', '31']},{'id': '28', 'type': 'pattern_list', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'sorted_files'},{'id': '32', 'type': 'if_clause', 'children': ['33']},{'id': '33', 'type': 'boolean_operator', 'children': ['34', '42'], 'value': 'and'},{'id': '34', 'type': 'call', 'children': ['35', '40']},{'id': '35', 'type': 'attribute', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'vcf_has_variants'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '46', 'type': 'if_statement', 'children': ['47', '53', '73', '90']},{'id': '47', 'type': 'comparison_operator', 'children': ['48', '52'], 'value': '=='},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'exist_files'},{'id': '52', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'exist_files'},{'id': '57', 'type': 'list_comprehension', 'children': ['58', '59', '64']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '59', 'type': 'for_in_clause', 'children': ['60', '63']},{'id': '60', 'type': 'pattern_list', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'sorted_files'},{'id': '64', 'type': 'if_clause', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '71']},{'id': '66', 'type': 'attribute', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '73', 'type': 'elif_clause', 'children': ['74', '80']},{'id': '74', 'type': 'comparison_operator', 'children': ['75', '79'], 'value': '>'},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'exist_files'},{'id': '79', 'type': 'integer', 'children': [], 'value': '1'},{'id': '80', 'type': 'block', 'children': ['81']},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'exist_files'},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': '_fix_gatk_header'},{'id': '86', 'type': 'argument_list', 'children': ['87', '88', '89']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'exist_files'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '90', 'type': 'else_clause', 'children': ['91']},{'id': '91', 'type': 'block', 'children': ['92']},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'exist_files'},{'id': '95', 'type': 'list_comprehension', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '97', 'type': 'for_in_clause', 'children': ['98', '101']},{'id': '98', 'type': 'pattern_list', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'exist_files'},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'ready_files'},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'run_multicore'},{'id': '107', 'type': 'argument_list', 'children': ['108', '109', '116']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'p_bgzip_and_index'},{'id': '109', 'type': 'list_comprehension', 'children': ['110', '113']},{'id': '110', 'type': 'list', 'children': ['111', '112'], 'value': '[x, config]'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '113', 'type': 'for_in_clause', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'exist_files'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'input_file_list'},{'id': '120', 'type': 'binary_operator', 'children': ['121', '122'], 'value': '%'},{'id': '121', 'type': 'string', 'children': [], 'value': '"%s-files.list"'},{'id': '122', 'type': 'subscript', 'children': ['123', '129']},{'id': '123', 'type': 'call', 'children': ['124', '127']},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'splitext_plus'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '129', 'type': 'integer', 'children': [], 'value': '0'},{'id': '130', 'type': 'with_statement', 'children': ['131', '141']},{'id': '131', 'type': 'with_clause', 'children': ['132']},{'id': '132', 'type': 'with_item', 'children': ['133']},{'id': '133', 'type': 'as_pattern', 'children': ['134', '139']},{'id': '134', 'type': 'call', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '136', 'type': 'argument_list', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'input_file_list'},{'id': '138', 'type': 'string', 'children': [], 'value': '"w"'},{'id': '139', 'type': 'as_pattern_target', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'out_handle'},{'id': '141', 'type': 'block', 'children': ['142']},{'id': '142', 'type': 'for_statement', 'children': ['143', '144', '145']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'fname'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'ready_files'},{'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': 'out_handle'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '151', 'type': 'argument_list', 'children': ['152']},{'id': '152', 'type': 'binary_operator', 'children': ['153', '154'], 'value': '+'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'fname'},{'id': '154', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '155', 'type': 'return_statement', 'children': ['156']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'input_file_list'}
def _get_file_list(orig_files, out_file, regions, ref_file, config): sorted_files = _sort_by_region(orig_files, regions, ref_file, config) exist_files = [(c, x) for c, x in sorted_files if os.path.exists(x) and vcf_has_variants(x)] if len(exist_files) == 0: exist_files = [x for c, x in sorted_files if os.path.exists(x)] elif len(exist_files) > 1: exist_files = _fix_gatk_header(exist_files, out_file, config) else: exist_files = [x for c, x in exist_files] ready_files = run_multicore(p_bgzip_and_index, [[x, config] for x in exist_files], config) input_file_list = "%s-files.list" % utils.splitext_plus(out_file)[0] with open(input_file_list, "w") as out_handle: for fname in ready_files: out_handle.write(fname + "\n") return input_file_list
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_by_ref'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'vcf_file'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '6', 'type': 'block', 'children': ['7', '20', '148']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '10', 'type': 'binary_operator', 'children': ['11', '12'], 'value': '%'},{'id': '11', 'type': 'string', 'children': [], 'value': '"%s-prep.vcf.gz"'},{'id': '12', 'type': 'subscript', 'children': ['13', '19']},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'splitext_plus'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'vcf_file'},{'id': '19', 'type': 'integer', 'children': [], 'value': '0'},{'id': '20', 'type': 'if_statement', 'children': ['21', '29']},{'id': '21', 'type': 'not_operator', 'children': ['22']},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'file_uptodate'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'vcf_file'},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'with_statement', 'children': ['31', '41']},{'id': '31', 'type': 'with_clause', 'children': ['32']},{'id': '32', 'type': 'with_item', 'children': ['33']},{'id': '33', 'type': 'as_pattern', 'children': ['34', '39']},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'file_transaction'},{'id': '36', 'type': 'argument_list', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '39', 'type': 'as_pattern_target', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'tx_out_file'},{'id': '41', 'type': 'block', 'children': ['42', '55', '115']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'header_file'},{'id': '45', 'type': 'binary_operator', 'children': ['46', '47'], 'value': '%'},{'id': '46', 'type': 'string', 'children': [], 'value': '"%s-header.txt"'},{'id': '47', 'type': 'subscript', 'children': ['48', '54']},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'splitext_plus'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'tx_out_file'},{'id': '54', 'type': 'integer', 'children': [], 'value': '0'},{'id': '55', 'type': 'with_statement', 'children': ['56', '66']},{'id': '56', 'type': 'with_clause', 'children': ['57']},{'id': '57', 'type': 'with_item', 'children': ['58']},{'id': '58', 'type': 'as_pattern', 'children': ['59', '64']},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '61', 'type': 'argument_list', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'header_file'},{'id': '63', 'type': 'string', 'children': [], 'value': '"w"'},{'id': '64', 'type': 'as_pattern_target', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'out_handle'},{'id': '66', 'type': 'block', 'children': ['67']},{'id': '67', 'type': 'for_statement', 'children': ['68', '69', '83']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'region'},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'file_contigs'},{'id': '73', 'type': 'argument_list', 'children': ['74', '80']},{'id': '74', 'type': 'call', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'dd'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'get_ref_file'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '80', 'type': 'subscript', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '82', 'type': 'string', 'children': [], 'value': '"config"'},{'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': 'out_handle'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '89', 'type': 'argument_list', 'children': ['90', '107']},{'id': '90', 'type': 'ERROR', 'children': ['91', '100', '105']},{'id': '91', 'type': 'attribute', 'children': ['92', '97', '99']},{'id': '92', 'type': 'concatenated_string', 'children': ['93', '94', '96']},{'id': '93', 'type': 'string', 'children': [], 'value': '"\n cat_cmd = "'},{'id': '94', 'type': 'ERROR', 'children': ['95']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'zcat'},{'id': '96', 'type': 'string', 'children': [], 'value': '" if vcf_file.endswith("'},{'id': '97', 'type': 'ERROR', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'vcf'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'gz'},{'id': '100', 'type': 'concatenated_string', 'children': ['101', '102', '104']},{'id': '101', 'type': 'string', 'children': [], 'value': '") else "'},{'id': '102', 'type': 'ERROR', 'children': ['103']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'cat'},{'id': '104', 'type': 'string', 'children': [], 'value': '"\n cmd = ("'},{'id': '105', 'type': 'set', 'children': ['106']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'cat_cmd'},{'id': '107', 'type': 'binary_operator', 'children': ['108', '110'], 'value': '|'},{'id': '108', 'type': 'set', 'children': ['109']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'vcf_file'},{'id': '110', 'type': 'binary_operator', 'children': ['111', '114'], 'value': '^'},{'id': '111', 'type': 'binary_operator', 'children': ['112', '113'], 'value': '-'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'grep'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '114', 'type': 'string', 'children': [], 'value': '"vt sort -m full -o {tx_out_file} -"'},{'id': '115', 'type': 'with_statement', 'children': ['116', '131']},{'id': '116', 'type': 'with_clause', 'children': ['117']},{'id': '117', 'type': 'with_item', 'children': ['118']},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'chdir'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'call', 'children': ['124', '129']},{'id': '124', 'type': 'attribute', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'dirname'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'tx_out_file'},{'id': '131', 'type': 'block', 'children': ['132']},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'do'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'run'},{'id': '137', 'type': 'argument_list', 'children': ['138', '147']},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'dictionary_splat', 'children': ['144']},{'id': '144', 'type': 'call', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'locals'},{'id': '146', 'type': 'argument_list', 'children': []},{'id': '147', 'type': 'string', 'children': [], 'value': '"Sort VCF by reference"'},{'id': '148', 'type': 'return_statement', 'children': ['149']},{'id': '149', 'type': 'call', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'bgzip_and_index'},{'id': '151', 'type': 'argument_list', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '153', 'type': 'subscript', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '155', 'type': 'string', 'children': [], 'value': '"config"'}
def sort_by_ref(vcf_file, data): out_file = "%s-prep.vcf.gz" % utils.splitext_plus(vcf_file)[0] if not utils.file_uptodate(out_file, vcf_file): with file_transaction(data, out_file) as tx_out_file: header_file = "%s-header.txt" % utils.splitext_plus(tx_out_file)[0] with open(header_file, "w") as out_handle: for region in ref.file_contigs(dd.get_ref_file(data), data["config"]): out_handle.write(" cat_cmd = "zcat" if vcf_file.endswith("vcf.gz") else "cat" cmd = ("{cat_cmd} {vcf_file} | grep -v ^ "vt sort -m full -o {tx_out_file} -") with utils.chdir(os.path.dirname(tx_out_file)): do.run(cmd.format(**locals()), "Sort VCF by reference") return bgzip_and_index(out_file, data["config"])
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'align_to_sort_bam'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'fastq1'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'fastq2'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'aligner'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '8', 'type': 'block', 'children': ['9', '15', '28', '47', '55', '72', '85', '122', '211']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '12', 'type': 'subscript', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '14', 'type': 'string', 'children': [], 'value': '"rgnames"'},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'align_dir_parts'},{'id': '18', 'type': 'list', 'children': ['19', '24', '25'], 'value': '[data["dirs"]["work"], "align", names["sample"]]'},{'id': '19', 'type': 'subscript', 'children': ['20', '23']},{'id': '20', 'type': 'subscript', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '22', 'type': 'string', 'children': [], 'value': '"dirs"'},{'id': '23', 'type': 'string', 'children': [], 'value': '"work"'},{'id': '24', 'type': 'string', 'children': [], 'value': '"align"'},{'id': '25', 'type': 'subscript', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '27', 'type': 'string', 'children': [], 'value': '"sample"'},{'id': '28', 'type': 'if_statement', 'children': ['29', '35']},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'string', 'children': [], 'value': '"disambiguate"'},{'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': 'align_dir_parts'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'subscript', 'children': ['43', '46']},{'id': '43', 'type': 'subscript', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '45', 'type': 'string', 'children': [], 'value': '"disambiguate"'},{'id': '46', 'type': 'string', 'children': [], 'value': '"genome_build"'},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'aligner_index'},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': '_get_aligner_index'},{'id': '52', 'type': 'argument_list', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'aligner'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'align_dir'},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'safe_makedir'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'call', 'children': ['64', '69']},{'id': '64', 'type': 'attribute', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'list_splat', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'align_dir_parts'},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'ref_file'},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'tz'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'get_in'},{'id': '79', 'type': 'argument_list', 'children': ['80', '84']},{'id': '80', 'type': 'tuple', 'children': ['81', '82', '83']},{'id': '81', 'type': 'string', 'children': [], 'value': '"reference"'},{'id': '82', 'type': 'string', 'children': [], 'value': '"fasta"'},{'id': '83', 'type': 'string', 'children': [], 'value': '"base"'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '85', 'type': 'if_statement', 'children': ['86', '92', '106']},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'fastq1'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'string', 'children': [], 'value': '".bam"'},{'id': '92', 'type': 'block', 'children': ['93']},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': '_align_from_bam'},{'id': '98', 'type': 'argument_list', 'children': ['99', '100', '101', '102', '103', '104', '105']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'fastq1'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'aligner'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'aligner_index'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'ref_file'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'align_dir'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '106', 'type': 'else_clause', 'children': ['107']},{'id': '107', 'type': 'block', 'children': ['108']},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': '_align_from_fastq'},{'id': '113', 'type': 'argument_list', 'children': ['114', '115', '116', '117', '118', '119', '120', '121']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'fastq1'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'fastq2'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'aligner'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'aligner_index'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'ref_file'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'align_dir'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '122', 'type': 'if_statement', 'children': ['123', '135']},{'id': '123', 'type': 'boolean_operator', 'children': ['124', '127'], 'value': 'and'},{'id': '124', 'type': 'subscript', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '126', 'type': 'string', 'children': [], 'value': '"work_bam"'},{'id': '127', 'type': 'call', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'file_exists'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'subscript', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '134', 'type': 'string', 'children': [], 'value': '"work_bam"'},{'id': '135', 'type': 'block', 'children': ['136', '175']},{'id': '136', 'type': 'if_statement', 'children': ['137', '150', '161']},{'id': '137', 'type': 'boolean_operator', 'children': ['138', '144'], 'value': 'and'},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'string', 'children': [], 'value': '"align_split"'},{'id': '144', 'type': 'call', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'dd'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'get_mark_duplicates'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '150', 'type': 'block', 'children': ['151']},{'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': 'bam'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'fake_index'},{'id': '156', 'type': 'argument_list', 'children': ['157', '160']},{'id': '157', 'type': 'subscript', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '159', 'type': 'string', 'children': [], 'value': '"work_bam"'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '161', 'type': 'else_clause', 'children': ['162']},{'id': '162', 'type': 'block', 'children': ['163']},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'call', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'bam'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '168', 'type': 'argument_list', 'children': ['169', '172']},{'id': '169', 'type': 'subscript', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '171', 'type': 'string', 'children': [], 'value': '"work_bam"'},{'id': '172', 'type': 'subscript', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '174', 'type': 'string', 'children': [], 'value': '"config"'},{'id': '175', 'type': 'for_statement', 'children': ['176', '177', '180']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'extra'},{'id': '177', 'type': 'list', 'children': ['178', '179'], 'value': '["-sr", "-disc"]'},{'id': '178', 'type': 'string', 'children': [], 'value': '"-sr"'},{'id': '179', 'type': 'string', 'children': [], 'value': '"-disc"'},{'id': '180', 'type': 'block', 'children': ['181', '193']},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'assignment', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'extra_bam'},{'id': '184', 'type': 'call', 'children': ['185', '188']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'append_stem'},{'id': '188', 'type': 'argument_list', 'children': ['189', '192']},{'id': '189', 'type': 'subscript', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '191', 'type': 'string', 'children': [], 'value': "'work_bam'"},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'extra'},{'id': '193', 'type': 'if_statement', 'children': ['194', '200']},{'id': '194', 'type': 'call', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'file_exists'},{'id': '198', 'type': 'argument_list', 'children': ['199']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'extra_bam'},{'id': '200', 'type': 'block', 'children': ['201']},{'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': 'bam'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '206', 'type': 'argument_list', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'extra_bam'},{'id': '208', 'type': 'subscript', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '210', 'type': 'string', 'children': [], 'value': '"config"'},{'id': '211', 'type': 'return_statement', 'children': ['212']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'data'}
def align_to_sort_bam(fastq1, fastq2, aligner, data): names = data["rgnames"] align_dir_parts = [data["dirs"]["work"], "align", names["sample"]] if data.get("disambiguate"): align_dir_parts.append(data["disambiguate"]["genome_build"]) aligner_index = _get_aligner_index(aligner, data) align_dir = utils.safe_makedir(os.path.join(*align_dir_parts)) ref_file = tz.get_in(("reference", "fasta", "base"), data) if fastq1.endswith(".bam"): data = _align_from_bam(fastq1, aligner, aligner_index, ref_file, names, align_dir, data) else: data = _align_from_fastq(fastq1, fastq2, aligner, aligner_index, ref_file, names, align_dir, data) if data["work_bam"] and utils.file_exists(data["work_bam"]): if data.get("align_split") and dd.get_mark_duplicates(data): bam.fake_index(data["work_bam"], data) else: bam.index(data["work_bam"], data["config"]) for extra in ["-sr", "-disc"]: extra_bam = utils.append_stem(data['work_bam'], extra) if utils.file_exists(extra_bam): bam.index(extra_bam, data["config"]) return data
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_align_from_fastq'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'fastq1'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'fastq2'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'aligner'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'align_ref'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'sam_ref'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'align_dir'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '12', 'type': 'block', 'children': ['13', '19', '27', '39']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '16', 'type': 'subscript', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '18', 'type': 'string', 'children': [], 'value': '"config"'},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'align_fn'},{'id': '22', 'type': 'attribute', 'children': ['23', '26']},{'id': '23', 'type': 'subscript', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'TOOLS'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'aligner'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'align_fn'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'align_fn'},{'id': '32', 'type': 'argument_list', 'children': ['33', '34', '35', '36', '37', '38']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'fastq1'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'fastq2'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'align_ref'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'align_dir'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '39', 'type': 'if_statement', 'children': ['40', '45', '68']},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '42', 'type': 'argument_list', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '45', 'type': 'block', 'children': ['46', '66']},{'id': '46', 'type': 'assert_statement', 'children': ['47', '53']},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'string', 'children': [], 'value': '"work_bam"'},{'id': '53', 'type': 'tuple', 'children': ['54', '60']},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'dd'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'get_sample_name'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'string', 'children': [], 'value': '"work_bam"'},{'id': '66', 'type': 'return_statement', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '68', 'type': 'else_clause', 'children': ['69']},{'id': '69', 'type': 'block', 'children': ['70', '80', '92']},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'work_bam'},{'id': '73', 'type': 'call', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'bam'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'sam_to_bam'},{'id': '77', 'type': 'argument_list', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '85']},{'id': '82', 'type': 'subscript', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '84', 'type': 'string', 'children': [], 'value': '"work_bam"'},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'bam'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '89', 'type': 'argument_list', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'work_bam'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '92', 'type': 'return_statement', 'children': ['93']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'data'}
def _align_from_fastq(fastq1, fastq2, aligner, align_ref, sam_ref, names, align_dir, data): config = data["config"] align_fn = TOOLS[aligner].align_fn out = align_fn(fastq1, fastq2, align_ref, names, align_dir, data) if isinstance(out, dict): assert out.get("work_bam"), (dd.get_sample_name(data), out.get("work_bam")) return out else: work_bam = bam.sam_to_bam(out, config) data["work_bam"] = bam.sort(work_bam, config) return data
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'picard_prep'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'in_bam'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'ref_file'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'dirs'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '9', 'type': 'block', 'children': ['10', '22', '44', '52', '82', '110', '122', '133']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'runner'},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'broad'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'runner_from_path'},{'id': '17', 'type': 'argument_list', 'children': ['18', '19']},{'id': '18', 'type': 'string', 'children': [], 'value': '"picard"'},{'id': '19', 'type': 'subscript', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '21', 'type': 'string', 'children': [], 'value': '"config"'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'safe_makedir'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'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': 'os'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '36', 'type': 'argument_list', 'children': ['37', '40', '41']},{'id': '37', 'type': 'subscript', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'dirs'},{'id': '39', 'type': 'string', 'children': [], 'value': '"work"'},{'id': '40', 'type': 'string', 'children': [], 'value': '"bamclean"'},{'id': '41', 'type': 'subscript', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '43', 'type': 'string', 'children': [], 'value': '"sample"'},{'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': 'runner'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'run_fn'},{'id': '49', 'type': 'argument_list', 'children': ['50', '51']},{'id': '50', 'type': 'string', 'children': [], 'value': '"picard_index_ref"'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'ref_file'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'reorder_bam'},{'id': '55', 'type': 'call', 'children': ['56', '61']},{'id': '56', 'type': 'attribute', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '61', 'type': 'argument_list', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '63', 'type': 'binary_operator', 'children': ['64', '65'], 'value': '%'},{'id': '64', 'type': 'string', 'children': [], 'value': '"%s-reorder.bam"'},{'id': '65', 'type': 'subscript', 'children': ['66', '81']},{'id': '66', 'type': 'call', 'children': ['67', '72']},{'id': '67', 'type': 'attribute', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'splitext'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'call', 'children': ['74', '79']},{'id': '74', 'type': 'attribute', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'in_bam'},{'id': '81', 'type': 'integer', 'children': [], 'value': '0'},{'id': '82', 'type': 'if_statement', 'children': ['83', '90']},{'id': '83', 'type': 'not_operator', 'children': ['84']},{'id': '84', 'type': 'call', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'file_exists'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'reorder_bam'},{'id': '90', 'type': 'block', 'children': ['91']},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'reorder_bam'},{'id': '94', 'type': 'call', 'children': ['95', '100']},{'id': '95', 'type': 'attribute', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '100', 'type': 'argument_list', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '102', 'type': 'binary_operator', 'children': ['103', '104'], 'value': '%'},{'id': '103', 'type': 'string', 'children': [], 'value': '"%s-reorder.bam"'},{'id': '104', 'type': 'call', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'dd'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'get_sample_name'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'assignment', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'reorder_bam'},{'id': '113', 'type': 'call', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'runner'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'run_fn'},{'id': '117', 'type': 'argument_list', 'children': ['118', '119', '120', '121']},{'id': '118', 'type': 'string', 'children': [], 'value': '"picard_reorder"'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'in_bam'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'ref_file'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'reorder_bam'},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'rg_bam'},{'id': '125', 'type': 'call', 'children': ['126', '129']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'runner'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'run_fn'},{'id': '129', 'type': 'argument_list', 'children': ['130', '131', '132']},{'id': '130', 'type': 'string', 'children': [], 'value': '"picard_fix_rgs"'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'reorder_bam'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '133', 'type': 'return_statement', 'children': ['134']},{'id': '134', 'type': 'call', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': '_filter_bad_reads'},{'id': '136', 'type': 'argument_list', 'children': ['137', '138', '139']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'rg_bam'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'ref_file'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'data'}
def picard_prep(in_bam, names, ref_file, dirs, data): runner = broad.runner_from_path("picard", data["config"]) work_dir = utils.safe_makedir(os.path.join(dirs["work"], "bamclean", names["sample"])) runner.run_fn("picard_index_ref", ref_file) reorder_bam = os.path.join(work_dir, "%s-reorder.bam" % os.path.splitext(os.path.basename(in_bam))[0]) if not utils.file_exists(reorder_bam): reorder_bam = os.path.join(work_dir, "%s-reorder.bam" % dd.get_sample_name(data)) reorder_bam = runner.run_fn("picard_reorder", in_bam, ref_file, reorder_bam) rg_bam = runner.run_fn("picard_fix_rgs", reorder_bam, names) return _filter_bad_reads(rg_bam, ref_file, data)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'iterate_flattened_separately'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'dictionary'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'manually_sorted_keys'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '18', '34', '65', '79', '108']},{'id': '9', 'type': 'if_statement', 'children': ['10', '13']},{'id': '10', 'type': 'comparison_operator', 'children': ['11', '12'], 'value': 'is'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'manually_sorted_keys'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'manually_sorted_keys'},{'id': '17', 'type': 'list', 'children': [], 'value': '[]'},{'id': '18', 'type': 'for_statement', 'children': ['19', '20', '21']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'manually_sorted_keys'},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'if_statement', 'children': ['23', '26']},{'id': '23', 'type': 'comparison_operator', 'children': ['24', '25'], 'value': 'in'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'dictionary'},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'yield', 'children': ['29']},{'id': '29', 'type': 'expression_list', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '31', 'type': 'subscript', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'dictionary'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'single_line_keys'},{'id': '37', 'type': 'list_comprehension', 'children': ['38', '39', '46']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '39', 'type': 'for_in_clause', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'dictionary'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '45', 'type': 'argument_list', 'children': []},{'id': '46', 'type': 'if_clause', 'children': ['47']},{'id': '47', 'type': 'boolean_operator', 'children': ['48', '51'], 'value': 'and'},{'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': 'not'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'manually_sorted_keys'},{'id': '51', 'type': '()', 'children': ['52']},{'id': '52', 'type': 'boolean_operator', 'children': ['53', '57'], 'value': 'or'},{'id': '53', 'type': 'not_operator', 'children': ['54']},{'id': '54', 'type': 'subscript', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'dictionary'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '57', 'type': 'not_operator', 'children': ['58']},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '60', 'type': 'argument_list', 'children': ['61', '64']},{'id': '61', 'type': 'subscript', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'dictionary'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '65', 'type': 'for_statement', 'children': ['66', '67', '71']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'single_line_keys'},{'id': '71', 'type': 'block', 'children': ['72']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'yield', 'children': ['74']},{'id': '74', 'type': 'expression_list', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '76', 'type': 'subscript', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'dictionary'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'multi_line_keys'},{'id': '82', 'type': 'list_comprehension', 'children': ['83', '84', '91']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '84', 'type': 'for_in_clause', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'dictionary'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '90', 'type': 'argument_list', 'children': []},{'id': '91', 'type': 'if_clause', 'children': ['92']},{'id': '92', 'type': 'boolean_operator', 'children': ['93', '96'], 'value': 'and'},{'id': '93', 'type': 'comparison_operator', 'children': ['94', '95'], 'value': 'not'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'manually_sorted_keys'},{'id': '96', 'type': '()', 'children': ['97']},{'id': '97', 'type': 'boolean_operator', 'children': ['98', '101'], 'value': 'and'},{'id': '98', 'type': 'subscript', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'dictionary'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '103', 'type': 'argument_list', 'children': ['104', '107']},{'id': '104', 'type': 'subscript', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'dictionary'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '108', 'type': 'for_statement', 'children': ['109', '110', '114']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '110', 'type': 'call', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'multi_line_keys'},{'id': '114', 'type': 'block', 'children': ['115', '120']},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'yield', 'children': ['117']},{'id': '117', 'type': 'expression_list', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'PATHCHANGE'},{'id': '120', 'type': 'for_statement', 'children': ['121', '124', '131']},{'id': '121', 'type': 'pattern_list', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '124', 'type': 'call', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'iterate_flattened_separately'},{'id': '126', 'type': 'argument_list', 'children': ['127', '130']},{'id': '127', 'type': 'subscript', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'dictionary'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'manually_sorted_keys'},{'id': '131', 'type': 'block', 'children': ['132']},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'yield', 'children': ['134']},{'id': '134', 'type': 'expression_list', 'children': ['135', '140']},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'join_paths'},{'id': '137', 'type': 'argument_list', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'val'}
def iterate_flattened_separately(dictionary, manually_sorted_keys=None): if manually_sorted_keys is None: manually_sorted_keys = [] for key in manually_sorted_keys: if key in dictionary: yield key, dictionary[key] single_line_keys = [key for key in dictionary.keys() if key not in manually_sorted_keys and (not dictionary[key] or not isinstance(dictionary[key], dict))] for key in sorted(single_line_keys): yield key, dictionary[key] multi_line_keys = [key for key in dictionary.keys() if key not in manually_sorted_keys and (dictionary[key] and isinstance(dictionary[key], dict))] for key in sorted(multi_line_keys): yield key, PATHCHANGE for k, val in iterate_flattened_separately(dictionary[key], manually_sorted_keys): yield join_paths(key, k), val
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'gather_command_line_options'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'filter_disabled'},{'id': '6', 'type': 'None', 'children': []},{'id': '7', 'type': 'block', 'children': ['8', '22', '40']},{'id': '8', 'type': 'if_statement', 'children': ['9', '12']},{'id': '9', 'type': 'comparison_operator', 'children': ['10', '11'], 'value': 'is'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'filter_disabled'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'block', 'children': ['13']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'filter_disabled'},{'id': '16', 'type': 'not_operator', 'children': ['17']},{'id': '17', 'type': 'attribute', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'SETTINGS'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'COMMAND_LINE'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'SHOW_DISABLED_OPTIONS'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '25', 'type': 'list_comprehension', 'children': ['26', '27', '33']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'opt'},{'id': '27', 'type': 'for_in_clause', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'opt'},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'get_inheritors'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'CommandLineOption'},{'id': '33', 'type': 'if_clause', 'children': ['34']},{'id': '34', 'type': 'boolean_operator', 'children': ['35', '37'], 'value': 'or'},{'id': '35', 'type': 'not_operator', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'filter_disabled'},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'opt'},{'id': '39', 'type': 'identifier', 'children': [], 'value': '_enabled'},{'id': '40', 'type': 'return_statement', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '43', 'type': 'argument_list', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '47', 'type': 'lambda', 'children': ['48', '50']},{'id': '48', 'type': 'lambda_parameters', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'opt'},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'opt'},{'id': '52', 'type': 'identifier', 'children': [], 'value': '__name__'}
def gather_command_line_options(filter_disabled=None): if filter_disabled is None: filter_disabled = not SETTINGS.COMMAND_LINE.SHOW_DISABLED_OPTIONS options = [opt for opt in get_inheritors(CommandLineOption) if not filter_disabled or opt._enabled] return sorted(options, key=lambda opt: opt.__name__)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '37']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'bar'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '10', '13', '16', '19', '22', '25', '28', '31', '34']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'figsize'},{'id': '7', 'type': 'tuple', 'children': ['8', '9']},{'id': '8', 'type': 'integer', 'children': [], 'value': '24'},{'id': '9', 'type': 'integer', 'children': [], 'value': '10'},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'fontsize'},{'id': '12', 'type': 'integer', 'children': [], 'value': '16'},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '18', 'type': 'False', 'children': []},{'id': '19', 'type': 'default_parameter', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '21', 'type': 'string', 'children': [], 'value': "'dimgray'"},{'id': '22', 'type': 'default_parameter', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'inline'},{'id': '24', 'type': 'False', 'children': []},{'id': '25', 'type': 'default_parameter', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '27', 'type': 'None', 'children': []},{'id': '28', 'type': 'default_parameter', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '30', 'type': 'integer', 'children': [], 'value': '0'},{'id': '31', 'type': 'default_parameter', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '33', 'type': 'integer', 'children': [], 'value': '0'},{'id': '34', 'type': 'default_parameter', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '36', 'type': 'None', 'children': []},{'id': '37', 'type': 'block', 'children': ['38', '55', '71', '81', '90', '117', '125', '130', '287', '295', '302', '313', '324', '342', '349', '415']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'nullity_counts'},{'id': '41', 'type': 'binary_operator', 'children': ['42', '46'], 'value': '-'},{'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': 'df'},{'id': '46', 'type': 'call', 'children': ['47', '54']},{'id': '47', 'type': 'attribute', 'children': ['48', '53']},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'isnull'},{'id': '52', 'type': 'argument_list', 'children': []},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '54', 'type': 'argument_list', 'children': []},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'nullity_filter'},{'id': '60', 'type': 'argument_list', 'children': ['61', '62', '65', '68']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '68', 'type': 'keyword_argument', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'nullity_sort'},{'id': '76', 'type': 'argument_list', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '78', 'type': 'keyword_argument', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'figure'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'keyword_argument', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'figsize'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'figsize'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '101']},{'id': '92', 'type': 'attribute', 'children': ['93', '100']},{'id': '93', 'type': '()', 'children': ['94']},{'id': '94', 'type': 'binary_operator', 'children': ['95', '96'], 'value': '/'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'nullity_counts'},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'plot'},{'id': '101', 'type': 'argument_list', 'children': ['102', '105', '108', '111', '114']},{'id': '102', 'type': 'keyword_argument', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '104', 'type': 'string', 'children': [], 'value': "'bar'"},{'id': '105', 'type': 'keyword_argument', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'figsize'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'figsize'},{'id': '108', 'type': 'keyword_argument', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'fontsize'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'fontsize'},{'id': '111', 'type': 'keyword_argument', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '114', 'type': 'keyword_argument', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'ax1'},{'id': '120', 'type': 'call', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'gca'},{'id': '124', 'type': 'argument_list', 'children': []},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'axes'},{'id': '128', 'type': 'list', 'children': ['129'], 'value': '[ax1]'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'ax1'},{'id': '130', 'type': 'if_statement', 'children': ['131', '146', '278']},{'id': '131', 'type': 'boolean_operator', 'children': ['132', '133'], 'value': 'or'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '133', 'type': '()', 'children': ['134']},{'id': '134', 'type': 'boolean_operator', 'children': ['135', '138'], 'value': 'and'},{'id': '135', 'type': 'comparison_operator', 'children': ['136', '137'], 'value': 'is'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '137', 'type': 'None', 'children': []},{'id': '138', 'type': 'comparison_operator', 'children': ['139', '145'], 'value': '<='},{'id': '139', 'type': 'call', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '145', 'type': 'integer', 'children': [], 'value': '50'},{'id': '146', 'type': 'block', 'children': ['147', '167', '175', '182']},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'call', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'ax1'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'set_xticklabels'},{'id': '152', 'type': 'argument_list', 'children': ['153', '158', '161', '164']},{'id': '153', 'type': 'call', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'ax1'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'get_xticklabels'},{'id': '157', 'type': 'argument_list', 'children': []},{'id': '158', 'type': 'keyword_argument', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'rotation'},{'id': '160', 'type': 'integer', 'children': [], 'value': '45'},{'id': '161', 'type': 'keyword_argument', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'ha'},{'id': '163', 'type': 'string', 'children': [], 'value': "'right'"},{'id': '164', 'type': 'keyword_argument', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'fontsize'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'fontsize'},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'assignment', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'ax2'},{'id': '170', 'type': 'call', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'ax1'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'twinx'},{'id': '174', 'type': 'argument_list', 'children': []},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'call', 'children': ['177', '180']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'axes'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'ax2'},{'id': '182', 'type': 'if_statement', 'children': ['183', '185', '232']},{'id': '183', 'type': 'not_operator', 'children': ['184']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '185', 'type': 'block', 'children': ['186', '195', '206']},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'call', 'children': ['188', '191']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'ax1'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'set_ylim'},{'id': '191', 'type': 'argument_list', 'children': ['192']},{'id': '192', 'type': 'list', 'children': ['193', '194'], 'value': '[0, 1]'},{'id': '193', 'type': 'integer', 'children': [], 'value': '0'},{'id': '194', 'type': 'integer', 'children': [], 'value': '1'},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'call', 'children': ['197', '200']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'ax2'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'set_yticks'},{'id': '200', 'type': 'argument_list', 'children': ['201']},{'id': '201', 'type': 'call', 'children': ['202', '205']},{'id': '202', 'type': 'attribute', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'ax1'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'get_yticks'},{'id': '205', 'type': 'argument_list', 'children': []},{'id': '206', 'type': 'expression_statement', 'children': ['207']},{'id': '207', 'type': 'call', 'children': ['208', '211']},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'ax2'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'set_yticklabels'},{'id': '211', 'type': 'argument_list', 'children': ['212', '229']},{'id': '212', 'type': 'list_comprehension', 'children': ['213', '222']},{'id': '213', 'type': 'call', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '215', 'type': 'argument_list', 'children': ['216']},{'id': '216', 'type': 'binary_operator', 'children': ['217', '218'], 'value': '*'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '218', 'type': 'call', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '220', 'type': 'argument_list', 'children': ['221']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '222', 'type': 'for_in_clause', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '224', 'type': 'call', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'ax1'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'get_yticks'},{'id': '228', 'type': 'argument_list', 'children': []},{'id': '229', 'type': 'keyword_argument', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'fontsize'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'fontsize'},{'id': '232', 'type': 'else_clause', 'children': ['233']},{'id': '233', 'type': 'block', 'children': ['234', '241', '252']},{'id': '234', 'type': 'expression_statement', 'children': ['235']},{'id': '235', 'type': 'call', 'children': ['236', '239']},{'id': '236', 'type': 'attribute', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'ax2'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'set_yscale'},{'id': '239', 'type': 'argument_list', 'children': ['240']},{'id': '240', 'type': 'string', 'children': [], 'value': "'log'"},{'id': '241', 'type': 'expression_statement', 'children': ['242']},{'id': '242', 'type': 'call', 'children': ['243', '246']},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'ax2'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'set_ylim'},{'id': '246', 'type': 'argument_list', 'children': ['247']},{'id': '247', 'type': 'call', 'children': ['248', '251']},{'id': '248', 'type': 'attribute', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'ax1'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'get_ylim'},{'id': '251', 'type': 'argument_list', 'children': []},{'id': '252', 'type': 'expression_statement', 'children': ['253']},{'id': '253', 'type': 'call', 'children': ['254', '257']},{'id': '254', 'type': 'attribute', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'ax2'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'set_yticklabels'},{'id': '257', 'type': 'argument_list', 'children': ['258', '275']},{'id': '258', 'type': 'list_comprehension', 'children': ['259', '268']},{'id': '259', 'type': 'call', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '261', 'type': 'argument_list', 'children': ['262']},{'id': '262', 'type': 'binary_operator', 'children': ['263', '264'], 'value': '*'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '264', 'type': 'call', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '266', 'type': 'argument_list', 'children': ['267']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '268', 'type': 'for_in_clause', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '270', 'type': 'call', 'children': ['271', '274']},{'id': '271', 'type': 'attribute', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'ax1'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'get_yticks'},{'id': '274', 'type': 'argument_list', 'children': []},{'id': '275', 'type': 'keyword_argument', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'fontsize'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'fontsize'},{'id': '278', 'type': 'else_clause', 'children': ['279']},{'id': '279', 'type': 'block', 'children': ['280']},{'id': '280', 'type': 'expression_statement', 'children': ['281']},{'id': '281', 'type': 'call', 'children': ['282', '285']},{'id': '282', 'type': 'attribute', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'ax1'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'set_xticks'},{'id': '285', 'type': 'argument_list', 'children': ['286']},{'id': '286', 'type': 'list', 'children': [], 'value': '[]'},{'id': '287', 'type': 'expression_statement', 'children': ['288']},{'id': '288', 'type': 'assignment', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'ax3'},{'id': '290', 'type': 'call', 'children': ['291', '294']},{'id': '291', 'type': 'attribute', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'ax1'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'twiny'},{'id': '294', 'type': 'argument_list', 'children': []},{'id': '295', 'type': 'expression_statement', 'children': ['296']},{'id': '296', 'type': 'call', 'children': ['297', '300']},{'id': '297', 'type': 'attribute', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'axes'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '300', 'type': 'argument_list', 'children': ['301']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'ax3'},{'id': '302', 'type': 'expression_statement', 'children': ['303']},{'id': '303', 'type': 'call', 'children': ['304', '307']},{'id': '304', 'type': 'attribute', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'ax3'},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'set_xticks'},{'id': '307', 'type': 'argument_list', 'children': ['308']},{'id': '308', 'type': 'call', 'children': ['309', '312']},{'id': '309', 'type': 'attribute', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'ax1'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'get_xticks'},{'id': '312', 'type': 'argument_list', 'children': []},{'id': '313', 'type': 'expression_statement', 'children': ['314']},{'id': '314', 'type': 'call', 'children': ['315', '318']},{'id': '315', 'type': 'attribute', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'ax3'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'set_xlim'},{'id': '318', 'type': 'argument_list', 'children': ['319']},{'id': '319', 'type': 'call', 'children': ['320', '323']},{'id': '320', 'type': 'attribute', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'ax1'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'get_xlim'},{'id': '323', 'type': 'argument_list', 'children': []},{'id': '324', 'type': 'expression_statement', 'children': ['325']},{'id': '325', 'type': 'call', 'children': ['326', '329']},{'id': '326', 'type': 'attribute', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'ax3'},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'set_xticklabels'},{'id': '329', 'type': 'argument_list', 'children': ['330', '333', '336', '339']},{'id': '330', 'type': 'attribute', 'children': ['331', '332']},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'nullity_counts'},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '333', 'type': 'keyword_argument', 'children': ['334', '335']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'fontsize'},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'fontsize'},{'id': '336', 'type': 'keyword_argument', 'children': ['337', '338']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'rotation'},{'id': '338', 'type': 'integer', 'children': [], 'value': '45'},{'id': '339', 'type': 'keyword_argument', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'ha'},{'id': '341', 'type': 'string', 'children': [], 'value': "'left'"},{'id': '342', 'type': 'expression_statement', 'children': ['343']},{'id': '343', 'type': 'call', 'children': ['344', '347']},{'id': '344', 'type': 'attribute', 'children': ['345', '346']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'ax3'},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'grid'},{'id': '347', 'type': 'argument_list', 'children': ['348']},{'id': '348', 'type': 'False', 'children': []},{'id': '349', 'type': 'for_statement', 'children': ['350', '351', '352']},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'axes'},{'id': '352', 'type': 'block', 'children': ['353', '364', '375', '386', '397', '406']},{'id': '353', 'type': 'expression_statement', 'children': ['354']},{'id': '354', 'type': 'call', 'children': ['355', '362']},{'id': '355', 'type': 'attribute', 'children': ['356', '361']},{'id': '356', 'type': 'subscript', 'children': ['357', '360']},{'id': '357', 'type': 'attribute', 'children': ['358', '359']},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'spines'},{'id': '360', 'type': 'string', 'children': [], 'value': "'top'"},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'set_visible'},{'id': '362', 'type': 'argument_list', 'children': ['363']},{'id': '363', 'type': 'False', 'children': []},{'id': '364', 'type': 'expression_statement', 'children': ['365']},{'id': '365', 'type': 'call', 'children': ['366', '373']},{'id': '366', 'type': 'attribute', 'children': ['367', '372']},{'id': '367', 'type': 'subscript', 'children': ['368', '371']},{'id': '368', 'type': 'attribute', 'children': ['369', '370']},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'spines'},{'id': '371', 'type': 'string', 'children': [], 'value': "'right'"},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'set_visible'},{'id': '373', 'type': 'argument_list', 'children': ['374']},{'id': '374', 'type': 'False', 'children': []},{'id': '375', 'type': 'expression_statement', 'children': ['376']},{'id': '376', 'type': 'call', 'children': ['377', '384']},{'id': '377', 'type': 'attribute', 'children': ['378', '383']},{'id': '378', 'type': 'subscript', 'children': ['379', '382']},{'id': '379', 'type': 'attribute', 'children': ['380', '381']},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'spines'},{'id': '382', 'type': 'string', 'children': [], 'value': "'bottom'"},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'set_visible'},{'id': '384', 'type': 'argument_list', 'children': ['385']},{'id': '385', 'type': 'False', 'children': []},{'id': '386', 'type': 'expression_statement', 'children': ['387']},{'id': '387', 'type': 'call', 'children': ['388', '395']},{'id': '388', 'type': 'attribute', 'children': ['389', '394']},{'id': '389', 'type': 'subscript', 'children': ['390', '393']},{'id': '390', 'type': 'attribute', 'children': ['391', '392']},{'id': '391', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'spines'},{'id': '393', 'type': 'string', 'children': [], 'value': "'left'"},{'id': '394', 'type': 'identifier', 'children': [], 'value': 'set_visible'},{'id': '395', 'type': 'argument_list', 'children': ['396']},{'id': '396', 'type': 'False', 'children': []},{'id': '397', 'type': 'expression_statement', 'children': ['398']},{'id': '398', 'type': 'call', 'children': ['399', '404']},{'id': '399', 'type': 'attribute', 'children': ['400', '403']},{'id': '400', 'type': 'attribute', 'children': ['401', '402']},{'id': '401', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '402', 'type': 'identifier', 'children': [], 'value': 'xaxis'},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'set_ticks_position'},{'id': '404', 'type': 'argument_list', 'children': ['405']},{'id': '405', 'type': 'string', 'children': [], 'value': "'none'"},{'id': '406', 'type': 'expression_statement', 'children': ['407']},{'id': '407', 'type': 'call', 'children': ['408', '413']},{'id': '408', 'type': 'attribute', 'children': ['409', '412']},{'id': '409', 'type': 'attribute', 'children': ['410', '411']},{'id': '410', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '411', 'type': 'identifier', 'children': [], 'value': 'yaxis'},{'id': '412', 'type': 'identifier', 'children': [], 'value': 'set_ticks_position'},{'id': '413', 'type': 'argument_list', 'children': ['414']},{'id': '414', 'type': 'string', 'children': [], 'value': "'none'"},{'id': '415', 'type': 'if_statement', 'children': ['416', '417', '424']},{'id': '416', 'type': 'identifier', 'children': [], 'value': 'inline'},{'id': '417', 'type': 'block', 'children': ['418']},{'id': '418', 'type': 'expression_statement', 'children': ['419']},{'id': '419', 'type': 'call', 'children': ['420', '423']},{'id': '420', 'type': 'attribute', 'children': ['421', '422']},{'id': '421', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '422', 'type': 'identifier', 'children': [], 'value': 'show'},{'id': '423', 'type': 'argument_list', 'children': []},{'id': '424', 'type': 'else_clause', 'children': ['425']},{'id': '425', 'type': 'block', 'children': ['426']},{'id': '426', 'type': 'return_statement', 'children': ['427']},{'id': '427', 'type': 'identifier', 'children': [], 'value': 'ax1'}
def bar(df, figsize=(24, 10), fontsize=16, labels=None, log=False, color='dimgray', inline=False, filter=None, n=0, p=0, sort=None): nullity_counts = len(df) - df.isnull().sum() df = nullity_filter(df, filter=filter, n=n, p=p) df = nullity_sort(df, sort=sort) plt.figure(figsize=figsize) (nullity_counts / len(df)).plot(kind='bar', figsize=figsize, fontsize=fontsize, log=log, color=color) ax1 = plt.gca() axes = [ax1] if labels or (labels is None and len(df.columns) <= 50): ax1.set_xticklabels(ax1.get_xticklabels(), rotation=45, ha='right', fontsize=fontsize) ax2 = ax1.twinx() axes.append(ax2) if not log: ax1.set_ylim([0, 1]) ax2.set_yticks(ax1.get_yticks()) ax2.set_yticklabels([int(n*len(df)) for n in ax1.get_yticks()], fontsize=fontsize) else: ax2.set_yscale('log') ax2.set_ylim(ax1.get_ylim()) ax2.set_yticklabels([int(n*len(df)) for n in ax1.get_yticks()], fontsize=fontsize) else: ax1.set_xticks([]) ax3 = ax1.twiny() axes.append(ax3) ax3.set_xticks(ax1.get_xticks()) ax3.set_xlim(ax1.get_xlim()) ax3.set_xticklabels(nullity_counts.values, fontsize=fontsize, rotation=45, ha='left') ax3.grid(False) for ax in axes: ax.spines['top'].set_visible(False) ax.spines['right'].set_visible(False) ax.spines['bottom'].set_visible(False) ax.spines['left'].set_visible(False) ax.xaxis.set_ticks_position('none') ax.yaxis.set_ticks_position('none') if inline: plt.show() else: return ax1
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '44']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'heatmap'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '25', '28', '31', '34', '38', '41']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'inline'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '13', 'type': 'integer', 'children': [], 'value': '0'},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '16', 'type': 'integer', 'children': [], 'value': '0'},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'figsize'},{'id': '22', 'type': 'tuple', 'children': ['23', '24']},{'id': '23', 'type': 'integer', 'children': [], 'value': '20'},{'id': '24', 'type': 'integer', 'children': [], 'value': '12'},{'id': '25', 'type': 'default_parameter', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'fontsize'},{'id': '27', 'type': 'integer', 'children': [], 'value': '16'},{'id': '28', 'type': 'default_parameter', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '30', 'type': 'True', 'children': []},{'id': '31', 'type': 'default_parameter', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'cmap'},{'id': '33', 'type': 'string', 'children': [], 'value': "'RdBu'"},{'id': '34', 'type': 'default_parameter', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'vmin'},{'id': '36', 'type': 'unary_operator', 'children': ['37'], 'value': '-'},{'id': '37', 'type': 'integer', 'children': [], 'value': '1'},{'id': '38', 'type': 'default_parameter', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'vmax'},{'id': '40', 'type': 'integer', 'children': [], 'value': '1'},{'id': '41', 'type': 'default_parameter', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'cbar'},{'id': '43', 'type': 'True', 'children': []},{'id': '44', 'type': 'block', 'children': ['45', '61', '71', '80', '90', '101', '136', '148', '157', '168', '234', '242', '264', '283', '302', '311', '320', '329', '426']},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'nullity_filter'},{'id': '50', 'type': 'argument_list', 'children': ['51', '52', '55', '58']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '58', 'type': 'keyword_argument', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'nullity_sort'},{'id': '66', 'type': 'argument_list', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '68', 'type': 'keyword_argument', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'sort'},{'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': 'plt'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'figure'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'keyword_argument', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'figsize'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'figsize'},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'gs'},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'gridspec'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'GridSpec'},{'id': '87', 'type': 'argument_list', 'children': ['88', '89']},{'id': '88', 'type': 'integer', 'children': [], 'value': '1'},{'id': '89', 'type': 'integer', 'children': [], 'value': '1'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'ax0'},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'subplot'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'subscript', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'gs'},{'id': '100', 'type': 'integer', 'children': [], 'value': '0'},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '104', 'type': 'subscript', 'children': ['105', '108', '110']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'iloc'},{'id': '108', 'type': 'slice', 'children': ['109']},{'id': '109', 'type': 'colon', 'children': []},{'id': '110', 'type': 'list_comprehension', 'children': ['111', '112', '132']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '112', 'type': 'for_in_clause', 'children': ['113', '116']},{'id': '113', 'type': 'pattern_list', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '116', 'type': 'call', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'call', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '123', 'type': 'argument_list', 'children': ['124', '129']},{'id': '124', 'type': 'call', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'isnull'},{'id': '128', 'type': 'argument_list', 'children': []},{'id': '129', 'type': 'keyword_argument', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '131', 'type': 'string', 'children': [], 'value': "'rows'"},{'id': '132', 'type': 'if_clause', 'children': ['133']},{'id': '133', 'type': 'comparison_operator', 'children': ['134', '135'], 'value': '>'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '135', 'type': 'integer', 'children': [], 'value': '0'},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'corr_mat'},{'id': '139', 'type': 'call', 'children': ['140', '147']},{'id': '140', 'type': 'attribute', 'children': ['141', '146']},{'id': '141', 'type': 'call', 'children': ['142', '145']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'isnull'},{'id': '145', 'type': 'argument_list', 'children': []},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'corr'},{'id': '147', 'type': 'argument_list', 'children': []},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '151', 'type': 'call', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'zeros_like'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'corr_mat'},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '167']},{'id': '159', 'type': 'subscript', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'mask'},{'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': 'triu_indices_from'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '167', 'type': 'True', 'children': []},{'id': '168', 'type': 'if_statement', 'children': ['169', '170', '207']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '170', 'type': 'block', 'children': ['171']},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'call', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'sns'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'heatmap'},{'id': '176', 'type': 'argument_list', 'children': ['177', '178', '181', '184', '187', '190', '193', '201', '204']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'corr_mat'},{'id': '178', 'type': 'keyword_argument', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '181', 'type': 'keyword_argument', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'cmap'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'cmap'},{'id': '184', 'type': 'keyword_argument', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'ax0'},{'id': '187', 'type': 'keyword_argument', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'cbar'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'cbar'},{'id': '190', 'type': 'keyword_argument', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'annot'},{'id': '192', 'type': 'True', 'children': []},{'id': '193', 'type': 'keyword_argument', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'annot_kws'},{'id': '195', 'type': 'dictionary', 'children': ['196']},{'id': '196', 'type': 'pair', 'children': ['197', '198']},{'id': '197', 'type': 'string', 'children': [], 'value': "'size'"},{'id': '198', 'type': 'binary_operator', 'children': ['199', '200'], 'value': '-'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'fontsize'},{'id': '200', 'type': 'integer', 'children': [], 'value': '2'},{'id': '201', 'type': 'keyword_argument', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'vmin'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'vmin'},{'id': '204', 'type': 'keyword_argument', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'vmax'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'vmax'},{'id': '207', 'type': 'else_clause', 'children': ['208']},{'id': '208', 'type': 'block', 'children': ['209']},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'call', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'sns'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'heatmap'},{'id': '214', 'type': 'argument_list', 'children': ['215', '216', '219', '222', '225', '228', '231']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'corr_mat'},{'id': '216', 'type': 'keyword_argument', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '219', 'type': 'keyword_argument', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'cmap'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'cmap'},{'id': '222', 'type': 'keyword_argument', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'ax0'},{'id': '225', 'type': 'keyword_argument', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'cbar'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'cbar'},{'id': '228', 'type': 'keyword_argument', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'vmin'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'vmin'},{'id': '231', 'type': 'keyword_argument', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'vmax'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'vmax'},{'id': '234', 'type': 'expression_statement', 'children': ['235']},{'id': '235', 'type': 'call', 'children': ['236', '241']},{'id': '236', 'type': 'attribute', 'children': ['237', '240']},{'id': '237', 'type': 'attribute', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'ax0'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'xaxis'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'tick_bottom'},{'id': '241', 'type': 'argument_list', 'children': []},{'id': '242', 'type': 'expression_statement', 'children': ['243']},{'id': '243', 'type': 'call', 'children': ['244', '247']},{'id': '244', 'type': 'attribute', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'ax0'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'set_xticklabels'},{'id': '247', 'type': 'argument_list', 'children': ['248', '255', '258', '261']},{'id': '248', 'type': 'call', 'children': ['249', '254']},{'id': '249', 'type': 'attribute', 'children': ['250', '253']},{'id': '250', 'type': 'attribute', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'ax0'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'xaxis'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'get_majorticklabels'},{'id': '254', 'type': 'argument_list', 'children': []},{'id': '255', 'type': 'keyword_argument', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'rotation'},{'id': '257', 'type': 'integer', 'children': [], 'value': '45'},{'id': '258', 'type': 'keyword_argument', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'ha'},{'id': '260', 'type': 'string', 'children': [], 'value': "'right'"},{'id': '261', 'type': 'keyword_argument', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'fontsize'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'fontsize'},{'id': '264', 'type': 'expression_statement', 'children': ['265']},{'id': '265', 'type': 'call', 'children': ['266', '269']},{'id': '266', 'type': 'attribute', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'ax0'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'set_yticklabels'},{'id': '269', 'type': 'argument_list', 'children': ['270', '277', '280']},{'id': '270', 'type': 'call', 'children': ['271', '276']},{'id': '271', 'type': 'attribute', 'children': ['272', '275']},{'id': '272', 'type': 'attribute', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'ax0'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'yaxis'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'get_majorticklabels'},{'id': '276', 'type': 'argument_list', 'children': []},{'id': '277', 'type': 'keyword_argument', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'fontsize'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'fontsize'},{'id': '280', 'type': 'keyword_argument', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'rotation'},{'id': '282', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'ax0'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'set_yticklabels'},{'id': '288', 'type': 'argument_list', 'children': ['289', '296', '299']},{'id': '289', 'type': 'call', 'children': ['290', '295']},{'id': '290', 'type': 'attribute', 'children': ['291', '294']},{'id': '291', 'type': 'attribute', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'ax0'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'yaxis'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'get_majorticklabels'},{'id': '295', 'type': 'argument_list', 'children': []},{'id': '296', 'type': 'keyword_argument', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'rotation'},{'id': '298', 'type': 'integer', 'children': [], 'value': '0'},{'id': '299', 'type': 'keyword_argument', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'fontsize'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'fontsize'},{'id': '302', 'type': 'expression_statement', 'children': ['303']},{'id': '303', 'type': 'call', 'children': ['304', '309']},{'id': '304', 'type': 'attribute', 'children': ['305', '308']},{'id': '305', 'type': 'attribute', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'ax0'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'xaxis'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'set_ticks_position'},{'id': '309', 'type': 'argument_list', 'children': ['310']},{'id': '310', 'type': 'string', 'children': [], 'value': "'none'"},{'id': '311', 'type': 'expression_statement', 'children': ['312']},{'id': '312', 'type': 'call', 'children': ['313', '318']},{'id': '313', 'type': 'attribute', 'children': ['314', '317']},{'id': '314', 'type': 'attribute', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'ax0'},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'yaxis'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'set_ticks_position'},{'id': '318', 'type': 'argument_list', 'children': ['319']},{'id': '319', 'type': 'string', 'children': [], 'value': "'none'"},{'id': '320', 'type': 'expression_statement', 'children': ['321']},{'id': '321', 'type': 'call', 'children': ['322', '327']},{'id': '322', 'type': 'attribute', 'children': ['323', '326']},{'id': '323', 'type': 'attribute', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'ax0'},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'patch'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'set_visible'},{'id': '327', 'type': 'argument_list', 'children': ['328']},{'id': '328', 'type': 'False', 'children': []},{'id': '329', 'type': 'for_statement', 'children': ['330', '331', '334']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '331', 'type': 'attribute', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'ax0'},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'texts'},{'id': '334', 'type': 'block', 'children': ['335', '346']},{'id': '335', 'type': 'expression_statement', 'children': ['336']},{'id': '336', 'type': 'assignment', 'children': ['337', '338']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '338', 'type': 'call', 'children': ['339', '340']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '340', 'type': 'argument_list', 'children': ['341']},{'id': '341', 'type': 'call', 'children': ['342', '345']},{'id': '342', 'type': 'attribute', 'children': ['343', '344']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'get_text'},{'id': '345', 'type': 'argument_list', 'children': []},{'id': '346', 'type': 'if_statement', 'children': ['347', '351', '359', '374', '386', '399', '413']},{'id': '347', 'type': 'comparison_operator', 'children': ['348', '349', '350'], 'value': '<='},{'id': '348', 'type': 'float', 'children': [], 'value': '0.95'},{'id': '349', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '350', 'type': 'integer', 'children': [], 'value': '1'},{'id': '351', 'type': 'block', 'children': ['352']},{'id': '352', 'type': 'expression_statement', 'children': ['353']},{'id': '353', 'type': 'call', 'children': ['354', '357']},{'id': '354', 'type': 'attribute', 'children': ['355', '356']},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'set_text'},{'id': '357', 'type': 'argument_list', 'children': ['358']},{'id': '358', 'type': 'string', 'children': [], 'value': "'<1'"},{'id': '359', 'type': 'elif_clause', 'children': ['360', '366']},{'id': '360', 'type': 'comparison_operator', 'children': ['361', '363', '364'], 'value': '<'},{'id': '361', 'type': 'unary_operator', 'children': ['362'], 'value': '-'},{'id': '362', 'type': 'integer', 'children': [], 'value': '1'},{'id': '363', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '364', 'type': 'unary_operator', 'children': ['365'], 'value': '-'},{'id': '365', 'type': 'float', 'children': [], 'value': '0.95'},{'id': '366', 'type': 'block', 'children': ['367']},{'id': '367', 'type': 'expression_statement', 'children': ['368']},{'id': '368', 'type': 'call', 'children': ['369', '372']},{'id': '369', 'type': 'attribute', 'children': ['370', '371']},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'set_text'},{'id': '372', 'type': 'argument_list', 'children': ['373']},{'id': '373', 'type': 'string', 'children': [], 'value': "'>-1'"},{'id': '374', 'type': 'elif_clause', 'children': ['375', '378']},{'id': '375', 'type': 'comparison_operator', 'children': ['376', '377'], 'value': '=='},{'id': '376', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '377', 'type': 'integer', 'children': [], 'value': '1'},{'id': '378', 'type': 'block', 'children': ['379']},{'id': '379', 'type': 'expression_statement', 'children': ['380']},{'id': '380', 'type': 'call', 'children': ['381', '384']},{'id': '381', 'type': 'attribute', 'children': ['382', '383']},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'set_text'},{'id': '384', 'type': 'argument_list', 'children': ['385']},{'id': '385', 'type': 'string', 'children': [], 'value': "'1'"},{'id': '386', 'type': 'elif_clause', 'children': ['387', '391']},{'id': '387', 'type': 'comparison_operator', 'children': ['388', '389'], 'value': '=='},{'id': '388', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '389', 'type': 'unary_operator', 'children': ['390'], 'value': '-'},{'id': '390', 'type': 'integer', 'children': [], 'value': '1'},{'id': '391', 'type': 'block', 'children': ['392']},{'id': '392', 'type': 'expression_statement', 'children': ['393']},{'id': '393', 'type': 'call', 'children': ['394', '397']},{'id': '394', 'type': 'attribute', 'children': ['395', '396']},{'id': '395', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '396', 'type': 'identifier', 'children': [], 'value': 'set_text'},{'id': '397', 'type': 'argument_list', 'children': ['398']},{'id': '398', 'type': 'string', 'children': [], 'value': "'-1'"},{'id': '399', 'type': 'elif_clause', 'children': ['400', '405']},{'id': '400', 'type': 'comparison_operator', 'children': ['401', '403', '404'], 'value': '<'},{'id': '401', 'type': 'unary_operator', 'children': ['402'], 'value': '-'},{'id': '402', 'type': 'float', 'children': [], 'value': '0.05'},{'id': '403', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '404', 'type': 'float', 'children': [], 'value': '0.05'},{'id': '405', 'type': 'block', 'children': ['406']},{'id': '406', 'type': 'expression_statement', 'children': ['407']},{'id': '407', 'type': 'call', 'children': ['408', '411']},{'id': '408', 'type': 'attribute', 'children': ['409', '410']},{'id': '409', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '410', 'type': 'identifier', 'children': [], 'value': 'set_text'},{'id': '411', 'type': 'argument_list', 'children': ['412']},{'id': '412', 'type': 'string', 'children': [], 'value': "''"},{'id': '413', 'type': 'else_clause', 'children': ['414']},{'id': '414', 'type': 'block', 'children': ['415']},{'id': '415', 'type': 'expression_statement', 'children': ['416']},{'id': '416', 'type': 'call', 'children': ['417', '420']},{'id': '417', 'type': 'attribute', 'children': ['418', '419']},{'id': '418', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '419', 'type': 'identifier', 'children': [], 'value': 'set_text'},{'id': '420', 'type': 'argument_list', 'children': ['421']},{'id': '421', 'type': 'call', 'children': ['422', '423']},{'id': '422', 'type': 'identifier', 'children': [], 'value': 'round'},{'id': '423', 'type': 'argument_list', 'children': ['424', '425']},{'id': '424', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '425', 'type': 'integer', 'children': [], 'value': '1'},{'id': '426', 'type': 'if_statement', 'children': ['427', '428', '435']},{'id': '427', 'type': 'identifier', 'children': [], 'value': 'inline'},{'id': '428', 'type': 'block', 'children': ['429']},{'id': '429', 'type': 'expression_statement', 'children': ['430']},{'id': '430', 'type': 'call', 'children': ['431', '434']},{'id': '431', 'type': 'attribute', 'children': ['432', '433']},{'id': '432', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '433', 'type': 'identifier', 'children': [], 'value': 'show'},{'id': '434', 'type': 'argument_list', 'children': []},{'id': '435', 'type': 'else_clause', 'children': ['436']},{'id': '436', 'type': 'block', 'children': ['437']},{'id': '437', 'type': 'return_statement', 'children': ['438']},{'id': '438', 'type': 'identifier', 'children': [], 'value': 'ax0'}
def heatmap(df, inline=False, filter=None, n=0, p=0, sort=None, figsize=(20, 12), fontsize=16, labels=True, cmap='RdBu', vmin=-1, vmax=1, cbar=True ): df = nullity_filter(df, filter=filter, n=n, p=p) df = nullity_sort(df, sort=sort) plt.figure(figsize=figsize) gs = gridspec.GridSpec(1, 1) ax0 = plt.subplot(gs[0]) df = df.iloc[:,[i for i, n in enumerate(np.var(df.isnull(), axis='rows')) if n > 0]] corr_mat = df.isnull().corr() mask = np.zeros_like(corr_mat) mask[np.triu_indices_from(mask)] = True if labels: sns.heatmap(corr_mat, mask=mask, cmap=cmap, ax=ax0, cbar=cbar, annot=True, annot_kws={'size': fontsize - 2}, vmin=vmin, vmax=vmax) else: sns.heatmap(corr_mat, mask=mask, cmap=cmap, ax=ax0, cbar=cbar, vmin=vmin, vmax=vmax) ax0.xaxis.tick_bottom() ax0.set_xticklabels(ax0.xaxis.get_majorticklabels(), rotation=45, ha='right', fontsize=fontsize) ax0.set_yticklabels(ax0.yaxis.get_majorticklabels(), fontsize=fontsize, rotation=0) ax0.set_yticklabels(ax0.yaxis.get_majorticklabels(), rotation=0, fontsize=fontsize) ax0.xaxis.set_ticks_position('none') ax0.yaxis.set_ticks_position('none') ax0.patch.set_visible(False) for text in ax0.texts: t = float(text.get_text()) if 0.95 <= t < 1: text.set_text('<1') elif -1 < t <= -0.95: text.set_text('>-1') elif t == 1: text.set_text('1') elif t == -1: text.set_text('-1') elif -0.05 < t < 0.05: text.set_text('') else: text.set_text(round(t, 1)) if inline: plt.show() else: return ax0
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '32']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'dendrogram'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '7', 'type': 'string', 'children': [], 'value': "'average'"},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '13', 'type': 'integer', 'children': [], 'value': '0'},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '16', 'type': 'integer', 'children': [], 'value': '0'},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'orientation'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'figsize'},{'id': '25', 'type': 'None', 'children': []},{'id': '26', 'type': 'default_parameter', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'fontsize'},{'id': '28', 'type': 'integer', 'children': [], 'value': '16'},{'id': '29', 'type': 'default_parameter', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'inline'},{'id': '31', 'type': 'False', 'children': []},{'id': '32', 'type': 'block', 'children': ['33', '81', '90', '100', '111', '127', '137', '157', '167', '191', '225', '232', '241', '254', '263', '272', '283', '294', '305', '316', '325', '373', '422']},{'id': '33', 'type': 'if_statement', 'children': ['34', '36']},{'id': '34', 'type': 'not_operator', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'figsize'},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'if_statement', 'children': ['38', '54', '61']},{'id': '38', 'type': 'boolean_operator', 'children': ['39', '51'], 'value': 'or'},{'id': '39', 'type': 'boolean_operator', 'children': ['40', '48'], 'value': 'or'},{'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': 'df'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '47', 'type': 'integer', 'children': [], 'value': '50'},{'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': '=='},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'orientation'},{'id': '50', 'type': 'string', 'children': [], 'value': "'top'"},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': '=='},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'orientation'},{'id': '53', 'type': 'string', 'children': [], 'value': "'bottom'"},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'figsize'},{'id': '58', 'type': 'tuple', 'children': ['59', '60']},{'id': '59', 'type': 'integer', 'children': [], 'value': '25'},{'id': '60', 'type': 'integer', 'children': [], 'value': '10'},{'id': '61', 'type': 'else_clause', 'children': ['62']},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'figsize'},{'id': '66', 'type': 'tuple', 'children': ['67', '68']},{'id': '67', 'type': 'integer', 'children': [], 'value': '25'},{'id': '68', 'type': 'binary_operator', 'children': ['69', '80'], 'value': '*'},{'id': '69', 'type': '()', 'children': ['70']},{'id': '70', 'type': 'binary_operator', 'children': ['71', '79'], 'value': '-'},{'id': '71', 'type': 'binary_operator', 'children': ['72', '73'], 'value': '+'},{'id': '72', 'type': 'integer', 'children': [], 'value': '25'},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '79', 'type': 'integer', 'children': [], 'value': '50'},{'id': '80', 'type': 'float', 'children': [], 'value': '0.5'},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'figure'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'keyword_argument', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'figsize'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'figsize'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'gs'},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'gridspec'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'GridSpec'},{'id': '97', 'type': 'argument_list', 'children': ['98', '99']},{'id': '98', 'type': 'integer', 'children': [], 'value': '1'},{'id': '99', 'type': 'integer', 'children': [], 'value': '1'},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'ax0'},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'subplot'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'subscript', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'gs'},{'id': '110', 'type': 'integer', 'children': [], 'value': '0'},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '114', 'type': 'call', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'nullity_filter'},{'id': '116', 'type': 'argument_list', 'children': ['117', '118', '121', '124']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '118', 'type': 'keyword_argument', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '121', 'type': 'keyword_argument', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '124', 'type': 'keyword_argument', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'nullity_sort'},{'id': '132', 'type': 'argument_list', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '134', 'type': 'keyword_argument', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'assignment', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '140', 'type': 'call', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'transpose'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'attribute', 'children': ['146', '156']},{'id': '146', 'type': 'call', 'children': ['147', '154']},{'id': '147', 'type': 'attribute', 'children': ['148', '153']},{'id': '148', 'type': 'call', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'isnull'},{'id': '152', 'type': 'argument_list', 'children': []},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'astype'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '160', 'type': 'call', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'hierarchy'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'linkage'},{'id': '164', 'type': 'argument_list', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '167', 'type': 'if_statement', 'children': ['168', '170']},{'id': '168', 'type': 'not_operator', 'children': ['169']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'orientation'},{'id': '170', 'type': 'block', 'children': ['171']},{'id': '171', 'type': 'if_statement', 'children': ['172', '180', '185']},{'id': '172', 'type': 'comparison_operator', 'children': ['173', '179'], 'value': '>'},{'id': '173', 'type': 'call', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '179', 'type': 'integer', 'children': [], 'value': '50'},{'id': '180', 'type': 'block', 'children': ['181']},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'assignment', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'orientation'},{'id': '184', 'type': 'string', 'children': [], 'value': "'left'"},{'id': '185', 'type': 'else_clause', 'children': ['186']},{'id': '186', 'type': 'block', 'children': ['187']},{'id': '187', 'type': 'expression_statement', 'children': ['188']},{'id': '188', 'type': 'assignment', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'orientation'},{'id': '190', 'type': 'string', 'children': [], 'value': "'bottom'"},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'call', 'children': ['193', '196']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'hierarchy'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'dendrogram'},{'id': '196', 'type': 'argument_list', 'children': ['197', '198', '201', '210', '213', '219', '222']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '198', 'type': 'keyword_argument', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'orientation'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'orientation'},{'id': '201', 'type': 'keyword_argument', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '203', 'type': 'call', 'children': ['204', '209']},{'id': '204', 'type': 'attribute', 'children': ['205', '208']},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'tolist'},{'id': '209', 'type': 'argument_list', 'children': []},{'id': '210', 'type': 'keyword_argument', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'distance_sort'},{'id': '212', 'type': 'string', 'children': [], 'value': "'descending'"},{'id': '213', 'type': 'keyword_argument', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'link_color_func'},{'id': '215', 'type': 'lambda', 'children': ['216', '218']},{'id': '216', 'type': 'lambda_parameters', 'children': ['217']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '218', 'type': 'string', 'children': [], 'value': "'black'"},{'id': '219', 'type': 'keyword_argument', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'leaf_font_size'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'fontsize'},{'id': '222', 'type': 'keyword_argument', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'ax0'},{'id': '225', 'type': 'expression_statement', 'children': ['226']},{'id': '226', 'type': 'call', 'children': ['227', '230']},{'id': '227', 'type': 'attribute', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'ax0'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'set_aspect'},{'id': '230', 'type': 'argument_list', 'children': ['231']},{'id': '231', 'type': 'string', 'children': [], 'value': "'auto'"},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'call', 'children': ['234', '237']},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'ax0'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'grid'},{'id': '237', 'type': 'argument_list', 'children': ['238']},{'id': '238', 'type': 'keyword_argument', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '240', 'type': 'False', 'children': []},{'id': '241', 'type': 'if_statement', 'children': ['242', '245']},{'id': '242', 'type': 'comparison_operator', 'children': ['243', '244'], 'value': '=='},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'orientation'},{'id': '244', 'type': 'string', 'children': [], 'value': "'bottom'"},{'id': '245', 'type': 'block', 'children': ['246']},{'id': '246', 'type': 'expression_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': 'ax0'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'xaxis'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'tick_top'},{'id': '253', 'type': 'argument_list', 'children': []},{'id': '254', 'type': 'expression_statement', 'children': ['255']},{'id': '255', 'type': 'call', 'children': ['256', '261']},{'id': '256', 'type': 'attribute', 'children': ['257', '260']},{'id': '257', 'type': 'attribute', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'ax0'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'xaxis'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'set_ticks_position'},{'id': '261', 'type': 'argument_list', 'children': ['262']},{'id': '262', 'type': 'string', 'children': [], 'value': "'none'"},{'id': '263', 'type': 'expression_statement', 'children': ['264']},{'id': '264', 'type': 'call', 'children': ['265', '270']},{'id': '265', 'type': 'attribute', 'children': ['266', '269']},{'id': '266', 'type': 'attribute', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'ax0'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'yaxis'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'set_ticks_position'},{'id': '270', 'type': 'argument_list', 'children': ['271']},{'id': '271', 'type': 'string', 'children': [], 'value': "'none'"},{'id': '272', 'type': 'expression_statement', 'children': ['273']},{'id': '273', 'type': 'call', 'children': ['274', '281']},{'id': '274', 'type': 'attribute', 'children': ['275', '280']},{'id': '275', 'type': 'subscript', 'children': ['276', '279']},{'id': '276', 'type': 'attribute', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'ax0'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'spines'},{'id': '279', 'type': 'string', 'children': [], 'value': "'top'"},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'set_visible'},{'id': '281', 'type': 'argument_list', 'children': ['282']},{'id': '282', 'type': 'False', 'children': []},{'id': '283', 'type': 'expression_statement', 'children': ['284']},{'id': '284', 'type': 'call', 'children': ['285', '292']},{'id': '285', 'type': 'attribute', 'children': ['286', '291']},{'id': '286', 'type': 'subscript', 'children': ['287', '290']},{'id': '287', 'type': 'attribute', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'ax0'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'spines'},{'id': '290', 'type': 'string', 'children': [], 'value': "'right'"},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'set_visible'},{'id': '292', 'type': 'argument_list', 'children': ['293']},{'id': '293', 'type': 'False', 'children': []},{'id': '294', 'type': 'expression_statement', 'children': ['295']},{'id': '295', 'type': 'call', 'children': ['296', '303']},{'id': '296', 'type': 'attribute', 'children': ['297', '302']},{'id': '297', 'type': 'subscript', 'children': ['298', '301']},{'id': '298', 'type': 'attribute', 'children': ['299', '300']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'ax0'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'spines'},{'id': '301', 'type': 'string', 'children': [], 'value': "'bottom'"},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'set_visible'},{'id': '303', 'type': 'argument_list', 'children': ['304']},{'id': '304', 'type': 'False', 'children': []},{'id': '305', 'type': 'expression_statement', 'children': ['306']},{'id': '306', 'type': 'call', 'children': ['307', '314']},{'id': '307', 'type': 'attribute', 'children': ['308', '313']},{'id': '308', 'type': 'subscript', 'children': ['309', '312']},{'id': '309', 'type': 'attribute', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'ax0'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'spines'},{'id': '312', 'type': 'string', 'children': [], 'value': "'left'"},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'set_visible'},{'id': '314', 'type': 'argument_list', 'children': ['315']},{'id': '315', 'type': 'False', 'children': []},{'id': '316', 'type': 'expression_statement', 'children': ['317']},{'id': '317', 'type': 'call', 'children': ['318', '323']},{'id': '318', 'type': 'attribute', 'children': ['319', '322']},{'id': '319', 'type': 'attribute', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'ax0'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'patch'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'set_visible'},{'id': '323', 'type': 'argument_list', 'children': ['324']},{'id': '324', 'type': 'False', 'children': []},{'id': '325', 'type': 'if_statement', 'children': ['326', '329', '349']},{'id': '326', 'type': 'comparison_operator', 'children': ['327', '328'], 'value': '=='},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'orientation'},{'id': '328', 'type': 'string', 'children': [], 'value': "'bottom'"},{'id': '329', 'type': 'block', 'children': ['330']},{'id': '330', 'type': 'expression_statement', 'children': ['331']},{'id': '331', 'type': 'call', 'children': ['332', '335']},{'id': '332', 'type': 'attribute', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'ax0'},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'set_xticklabels'},{'id': '335', 'type': 'argument_list', 'children': ['336', '343', '346']},{'id': '336', 'type': 'call', 'children': ['337', '342']},{'id': '337', 'type': 'attribute', 'children': ['338', '341']},{'id': '338', 'type': 'attribute', 'children': ['339', '340']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'ax0'},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'xaxis'},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'get_majorticklabels'},{'id': '342', 'type': 'argument_list', 'children': []},{'id': '343', 'type': 'keyword_argument', 'children': ['344', '345']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'rotation'},{'id': '345', 'type': 'integer', 'children': [], 'value': '45'},{'id': '346', 'type': 'keyword_argument', 'children': ['347', '348']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'ha'},{'id': '348', 'type': 'string', 'children': [], 'value': "'left'"},{'id': '349', 'type': 'elif_clause', 'children': ['350', '353']},{'id': '350', 'type': 'comparison_operator', 'children': ['351', '352'], 'value': '=='},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'orientation'},{'id': '352', 'type': 'string', 'children': [], 'value': "'top'"},{'id': '353', 'type': 'block', 'children': ['354']},{'id': '354', 'type': 'expression_statement', 'children': ['355']},{'id': '355', 'type': 'call', 'children': ['356', '359']},{'id': '356', 'type': 'attribute', 'children': ['357', '358']},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'ax0'},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'set_xticklabels'},{'id': '359', 'type': 'argument_list', 'children': ['360', '367', '370']},{'id': '360', 'type': 'call', 'children': ['361', '366']},{'id': '361', 'type': 'attribute', 'children': ['362', '365']},{'id': '362', 'type': 'attribute', 'children': ['363', '364']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'ax0'},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'xaxis'},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'get_majorticklabels'},{'id': '366', 'type': 'argument_list', 'children': []},{'id': '367', 'type': 'keyword_argument', 'children': ['368', '369']},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'rotation'},{'id': '369', 'type': 'integer', 'children': [], 'value': '45'},{'id': '370', 'type': 'keyword_argument', 'children': ['371', '372']},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'ha'},{'id': '372', 'type': 'string', 'children': [], 'value': "'right'"},{'id': '373', 'type': 'if_statement', 'children': ['374', '381', '401']},{'id': '374', 'type': 'boolean_operator', 'children': ['375', '378'], 'value': 'or'},{'id': '375', 'type': 'comparison_operator', 'children': ['376', '377'], 'value': '=='},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'orientation'},{'id': '377', 'type': 'string', 'children': [], 'value': "'bottom'"},{'id': '378', 'type': 'comparison_operator', 'children': ['379', '380'], 'value': '=='},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'orientation'},{'id': '380', 'type': 'string', 'children': [], 'value': "'top'"},{'id': '381', 'type': 'block', 'children': ['382']},{'id': '382', 'type': 'expression_statement', 'children': ['383']},{'id': '383', 'type': 'call', 'children': ['384', '387']},{'id': '384', 'type': 'attribute', 'children': ['385', '386']},{'id': '385', 'type': 'identifier', 'children': [], 'value': 'ax0'},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'tick_params'},{'id': '387', 'type': 'argument_list', 'children': ['388', '391']},{'id': '388', 'type': 'keyword_argument', 'children': ['389', '390']},{'id': '389', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '390', 'type': 'string', 'children': [], 'value': "'y'"},{'id': '391', 'type': 'keyword_argument', 'children': ['392', '393']},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'labelsize'},{'id': '393', 'type': 'call', 'children': ['394', '395']},{'id': '394', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '395', 'type': 'argument_list', 'children': ['396']},{'id': '396', 'type': 'binary_operator', 'children': ['397', '400'], 'value': '*'},{'id': '397', 'type': 'binary_operator', 'children': ['398', '399'], 'value': '/'},{'id': '398', 'type': 'identifier', 'children': [], 'value': 'fontsize'},{'id': '399', 'type': 'integer', 'children': [], 'value': '16'},{'id': '400', 'type': 'integer', 'children': [], 'value': '20'},{'id': '401', 'type': 'else_clause', 'children': ['402']},{'id': '402', 'type': 'block', 'children': ['403']},{'id': '403', 'type': 'expression_statement', 'children': ['404']},{'id': '404', 'type': 'call', 'children': ['405', '408']},{'id': '405', 'type': 'attribute', 'children': ['406', '407']},{'id': '406', 'type': 'identifier', 'children': [], 'value': 'ax0'},{'id': '407', 'type': 'identifier', 'children': [], 'value': 'tick_params'},{'id': '408', 'type': 'argument_list', 'children': ['409', '412']},{'id': '409', 'type': 'keyword_argument', 'children': ['410', '411']},{'id': '410', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '411', 'type': 'string', 'children': [], 'value': "'x'"},{'id': '412', 'type': 'keyword_argument', 'children': ['413', '414']},{'id': '413', 'type': 'identifier', 'children': [], 'value': 'labelsize'},{'id': '414', 'type': 'call', 'children': ['415', '416']},{'id': '415', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '416', 'type': 'argument_list', 'children': ['417']},{'id': '417', 'type': 'binary_operator', 'children': ['418', '421'], 'value': '*'},{'id': '418', 'type': 'binary_operator', 'children': ['419', '420'], 'value': '/'},{'id': '419', 'type': 'identifier', 'children': [], 'value': 'fontsize'},{'id': '420', 'type': 'integer', 'children': [], 'value': '16'},{'id': '421', 'type': 'integer', 'children': [], 'value': '20'},{'id': '422', 'type': 'if_statement', 'children': ['423', '424', '431']},{'id': '423', 'type': 'identifier', 'children': [], 'value': 'inline'},{'id': '424', 'type': 'block', 'children': ['425']},{'id': '425', 'type': 'expression_statement', 'children': ['426']},{'id': '426', 'type': 'call', 'children': ['427', '430']},{'id': '427', 'type': 'attribute', 'children': ['428', '429']},{'id': '428', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '429', 'type': 'identifier', 'children': [], 'value': 'show'},{'id': '430', 'type': 'argument_list', 'children': []},{'id': '431', 'type': 'else_clause', 'children': ['432']},{'id': '432', 'type': 'block', 'children': ['433']},{'id': '433', 'type': 'return_statement', 'children': ['434']},{'id': '434', 'type': 'identifier', 'children': [], 'value': 'ax0'}
def dendrogram(df, method='average', filter=None, n=0, p=0, sort=None, orientation=None, figsize=None, fontsize=16, inline=False ): if not figsize: if len(df.columns) <= 50 or orientation == 'top' or orientation == 'bottom': figsize = (25, 10) else: figsize = (25, (25 + len(df.columns) - 50)*0.5) plt.figure(figsize=figsize) gs = gridspec.GridSpec(1, 1) ax0 = plt.subplot(gs[0]) df = nullity_filter(df, filter=filter, n=n, p=p) df = nullity_sort(df, sort=sort) x = np.transpose(df.isnull().astype(int).values) z = hierarchy.linkage(x, method) if not orientation: if len(df.columns) > 50: orientation = 'left' else: orientation = 'bottom' hierarchy.dendrogram(z, orientation=orientation, labels=df.columns.tolist(), distance_sort='descending', link_color_func=lambda c: 'black', leaf_font_size=fontsize, ax=ax0 ) ax0.set_aspect('auto') ax0.grid(b=False) if orientation == 'bottom': ax0.xaxis.tick_top() ax0.xaxis.set_ticks_position('none') ax0.yaxis.set_ticks_position('none') ax0.spines['top'].set_visible(False) ax0.spines['right'].set_visible(False) ax0.spines['bottom'].set_visible(False) ax0.spines['left'].set_visible(False) ax0.patch.set_visible(False) if orientation == 'bottom': ax0.set_xticklabels(ax0.xaxis.get_majorticklabels(), rotation=45, ha='left') elif orientation == 'top': ax0.set_xticklabels(ax0.xaxis.get_majorticklabels(), rotation=45, ha='right') if orientation == 'bottom' or orientation == 'top': ax0.tick_params(axis='y', labelsize=int(fontsize / 16 * 20)) else: ax0.tick_params(axis='x', labelsize=int(fontsize / 16 * 20)) if inline: plt.show() else: return ax0
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'nullity_sort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9']},{'id': '9', 'type': 'if_statement', 'children': ['10', '13', '36', '68']},{'id': '10', 'type': 'comparison_operator', 'children': ['11', '12'], 'value': '=='},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '12', 'type': 'string', 'children': [], 'value': "'ascending'"},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'return_statement', 'children': ['15']},{'id': '15', 'type': 'subscript', 'children': ['16', '19', '34']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'iloc'},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'attribute', 'children': ['25', '33']},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '32', 'type': 'string', 'children': [], 'value': "'columns'"},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '34', 'type': 'slice', 'children': ['35']},{'id': '35', 'type': 'colon', 'children': []},{'id': '36', 'type': 'elif_clause', 'children': ['37', '40']},{'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': '=='},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '39', 'type': 'string', 'children': [], 'value': "'descending'"},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'return_statement', 'children': ['42']},{'id': '42', 'type': 'subscript', 'children': ['43', '46', '66']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'iloc'},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'flipud'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'call', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'attribute', 'children': ['57', '65']},{'id': '57', 'type': 'call', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '64', 'type': 'string', 'children': [], 'value': "'columns'"},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '66', 'type': 'slice', 'children': ['67']},{'id': '67', 'type': 'colon', 'children': []},{'id': '68', 'type': 'else_clause', 'children': ['69']},{'id': '69', 'type': 'block', 'children': ['70']},{'id': '70', 'type': 'return_statement', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'df'}
def nullity_sort(df, sort=None): if sort == 'ascending': return df.iloc[np.argsort(df.count(axis='columns').values), :] elif sort == 'descending': return df.iloc[np.flipud(np.argsort(df.count(axis='columns').values)), :] else: return df
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sortino_ratio'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'returns'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'required_return'},{'id': '7', 'type': 'integer', 'children': [], 'value': '0'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'period'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'DAILY'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'annualization'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': '_downside_risk'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'block', 'children': ['21', '27', '45', '53', '82', '95', '103', '115', '131', '142', '171']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'allocated_output'},{'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': 'is'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '26', 'type': 'None', 'children': []},{'id': '27', 'type': 'if_statement', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'allocated_output'},{'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': 'out'},{'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': 'empty'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'subscript', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'returns'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '42', 'type': 'slice', 'children': ['43', '44']},{'id': '43', 'type': 'integer', 'children': [], 'value': '1'},{'id': '44', 'type': 'colon', 'children': []},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'return_1d'},{'id': '48', 'type': 'comparison_operator', 'children': ['49', '52'], 'value': '=='},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'returns'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '52', 'type': 'integer', 'children': [], 'value': '1'},{'id': '53', 'type': 'if_statement', 'children': ['54', '60']},{'id': '54', 'type': 'comparison_operator', 'children': ['55', '59'], 'value': '<'},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'returns'},{'id': '59', 'type': 'integer', 'children': [], 'value': '2'},{'id': '60', 'type': 'block', 'children': ['61', '69', '80']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '66']},{'id': '63', 'type': 'subscript', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '65', 'type': 'tuple', 'children': []},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'nan'},{'id': '69', 'type': 'if_statement', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'return_1d'},{'id': '71', 'type': 'block', 'children': ['72']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '79', 'type': 'argument_list', 'children': []},{'id': '80', 'type': 'return_statement', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'adj_returns'},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'asanyarray'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': '_adjust_returns'},{'id': '92', 'type': 'argument_list', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'returns'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'required_return'},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'assignment', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'ann_factor'},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'annualization_factor'},{'id': '100', 'type': 'argument_list', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'period'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'annualization'},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'average_annual_return'},{'id': '106', 'type': 'binary_operator', 'children': ['107', '114'], 'value': '*'},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'nanmean'},{'id': '109', 'type': 'argument_list', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'adj_returns'},{'id': '111', 'type': 'keyword_argument', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '113', 'type': 'integer', 'children': [], 'value': '0'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'ann_factor'},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'annualized_downside_risk'},{'id': '118', 'type': '()', 'children': ['119']},{'id': '119', 'type': 'conditional_expression', 'children': ['120', '121', '124'], 'value': 'if'},{'id': '120', 'type': 'identifier', 'children': [], 'value': '_downside_risk'},{'id': '121', 'type': 'comparison_operator', 'children': ['122', '123'], 'value': 'is'},{'id': '122', 'type': 'identifier', 'children': [], 'value': '_downside_risk'},{'id': '123', 'type': 'None', 'children': []},{'id': '124', 'type': 'call', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'downside_risk'},{'id': '126', 'type': 'argument_list', 'children': ['127', '128', '129', '130']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'returns'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'required_return'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'period'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'annualization'},{'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': 'np'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'divide'},{'id': '136', 'type': 'argument_list', 'children': ['137', '138', '139']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'average_annual_return'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'annualized_downside_risk'},{'id': '139', 'type': 'keyword_argument', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '142', 'type': 'if_statement', 'children': ['143', '144', '153']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'return_1d'},{'id': '144', 'type': 'block', 'children': ['145']},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '148', 'type': 'call', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '152', 'type': 'argument_list', 'children': []},{'id': '153', 'type': 'elif_clause', 'children': ['154', '161']},{'id': '154', 'type': 'call', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '156', 'type': 'argument_list', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'returns'},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'DataFrame'},{'id': '161', 'type': 'block', 'children': ['162']},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'assignment', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '165', 'type': 'call', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'Series'},{'id': '169', 'type': 'argument_list', 'children': ['170']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '171', 'type': 'return_statement', 'children': ['172']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'out'}
def sortino_ratio(returns, required_return=0, period=DAILY, annualization=None, out=None, _downside_risk=None): allocated_output = out is None if allocated_output: out = np.empty(returns.shape[1:]) return_1d = returns.ndim == 1 if len(returns) < 2: out[()] = np.nan if return_1d: out = out.item() return out adj_returns = np.asanyarray(_adjust_returns(returns, required_return)) ann_factor = annualization_factor(period, annualization) average_annual_return = nanmean(adj_returns, axis=0) * ann_factor annualized_downside_risk = ( _downside_risk if _downside_risk is not None else downside_risk(returns, required_return, period, annualization) ) np.divide(average_annual_return, annualized_downside_risk, out=out) if return_1d: out = out.item() elif isinstance(returns, pd.DataFrame): out = pd.Series(out) return out
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'downside_risk'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'returns'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'required_return'},{'id': '7', 'type': 'integer', 'children': [], 'value': '0'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'period'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'DAILY'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'annualization'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'block', 'children': ['18', '24', '42', '50', '79', '87', '114', '124', '135', '145', '161', '195']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'allocated_output'},{'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': 'is'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '23', 'type': 'None', 'children': []},{'id': '24', 'type': 'if_statement', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'allocated_output'},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'empty'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'subscript', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'returns'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '39', 'type': 'slice', 'children': ['40', '41']},{'id': '40', 'type': 'integer', 'children': [], 'value': '1'},{'id': '41', 'type': 'colon', 'children': []},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'returns_1d'},{'id': '45', 'type': 'comparison_operator', 'children': ['46', '49'], 'value': '=='},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'returns'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '49', 'type': 'integer', 'children': [], 'value': '1'},{'id': '50', 'type': 'if_statement', 'children': ['51', '57']},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '56'], 'value': '<'},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'returns'},{'id': '56', 'type': 'integer', 'children': [], 'value': '1'},{'id': '57', 'type': 'block', 'children': ['58', '66', '77']},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '63']},{'id': '60', 'type': 'subscript', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '62', 'type': 'tuple', 'children': []},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'nan'},{'id': '66', 'type': 'if_statement', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'returns_1d'},{'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': 'out'},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '76', 'type': 'argument_list', 'children': []},{'id': '77', 'type': 'return_statement', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'ann_factor'},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'annualization_factor'},{'id': '84', 'type': 'argument_list', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'period'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'annualization'},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'downside_diff'},{'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': 'clip'},{'id': '94', 'type': 'argument_list', 'children': ['95', '110', '113']},{'id': '95', 'type': 'call', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': '_adjust_returns'},{'id': '97', 'type': 'argument_list', 'children': ['98', '104']},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'asanyarray'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'returns'},{'id': '104', 'type': 'call', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'asanyarray'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'required_return'},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'NINF'},{'id': '113', 'type': 'integer', 'children': [], 'value': '0'},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'call', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'square'},{'id': '119', 'type': 'argument_list', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'downside_diff'},{'id': '121', 'type': 'keyword_argument', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'downside_diff'},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'call', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'nanmean'},{'id': '127', 'type': 'argument_list', 'children': ['128', '129', '132']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'downside_diff'},{'id': '129', 'type': 'keyword_argument', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '131', 'type': 'integer', 'children': [], 'value': '0'},{'id': '132', 'type': 'keyword_argument', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'out'},{'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': 'np'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'sqrt'},{'id': '140', 'type': 'argument_list', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '142', 'type': 'keyword_argument', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'call', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'multiply'},{'id': '150', 'type': 'argument_list', 'children': ['151', '152', '158']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '152', 'type': 'call', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'sqrt'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'ann_factor'},{'id': '158', 'type': 'keyword_argument', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '161', 'type': 'if_statement', 'children': ['162', '163', '172']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'returns_1d'},{'id': '163', 'type': 'block', 'children': ['164']},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'assignment', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '167', 'type': 'call', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '171', 'type': 'argument_list', 'children': []},{'id': '172', 'type': 'elif_clause', 'children': ['173', '180']},{'id': '173', 'type': 'call', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '175', 'type': 'argument_list', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'returns'},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'DataFrame'},{'id': '180', 'type': 'block', 'children': ['181']},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'assignment', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '184', 'type': 'call', 'children': ['185', '188']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'Series'},{'id': '188', 'type': 'argument_list', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '190', 'type': 'keyword_argument', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'returns'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '195', 'type': 'return_statement', 'children': ['196']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'out'}
def downside_risk(returns, required_return=0, period=DAILY, annualization=None, out=None): allocated_output = out is None if allocated_output: out = np.empty(returns.shape[1:]) returns_1d = returns.ndim == 1 if len(returns) < 1: out[()] = np.nan if returns_1d: out = out.item() return out ann_factor = annualization_factor(period, annualization) downside_diff = np.clip( _adjust_returns( np.asanyarray(returns), np.asanyarray(required_return), ), np.NINF, 0, ) np.square(downside_diff, out=downside_diff) nanmean(downside_diff, axis=0, out=out) np.sqrt(out, out=out) np.multiply(out, np.sqrt(ann_factor), out=out) if returns_1d: out = out.item() elif isinstance(returns, pd.DataFrame): out = pd.Series(out, index=returns.columns) return out
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'GetLoadingOrder'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '10', '39']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '9', 'type': 'dictionary', 'children': []},{'id': '10', 'type': 'for_statement', 'children': ['11', '14', '21']},{'id': '11', 'type': 'pattern_list', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'mapping'},{'id': '14', 'type': 'call', 'children': ['15', '20']},{'id': '15', 'type': 'attribute', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '18', 'type': 'identifier', 'children': [], 'value': '_file_mapping'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '20', 'type': 'argument_list', 'children': []},{'id': '21', 'type': 'block', 'children': ['22', '28']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'loading_order'},{'id': '25', 'type': 'subscript', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'mapping'},{'id': '27', 'type': 'string', 'children': [], 'value': "'loading_order'"},{'id': '28', 'type': 'if_statement', 'children': ['29', '32']},{'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': 'is'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'loading_order'},{'id': '31', 'type': 'None', 'children': []},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '38']},{'id': '35', 'type': 'subscript', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'loading_order'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '39', 'type': 'return_statement', 'children': ['40']},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '42', 'type': 'generator_expression', 'children': ['43', '46']},{'id': '43', 'type': 'subscript', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '46', 'type': 'for_in_clause', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'result'}
def GetLoadingOrder(self): result = {} for filename, mapping in self._file_mapping.iteritems(): loading_order = mapping['loading_order'] if loading_order is not None: result[loading_order] = filename return list(result[key] for key in sorted(result))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'GetOrderKey'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '11', '20', '31', '35', '51']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'context_attributes'},{'id': '9', 'type': 'list', 'children': ['10'], 'value': "['_type']"},{'id': '10', 'type': 'string', 'children': [], 'value': "'_type'"},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'context_attributes'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'ExceptionWithContext'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'CONTEXT_PARTS'},{'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': 'context_attributes'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': '_GetExtraOrderAttributes'},{'id': '30', 'type': 'argument_list', 'children': []},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '34', 'type': 'list', 'children': [], 'value': '[]'},{'id': '35', 'type': 'for_statement', 'children': ['36', '37', '38']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'context_attribute'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'context_attributes'},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '47', 'type': 'argument_list', 'children': ['48', '49', '50']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'context_attribute'},{'id': '50', 'type': 'None', 'children': []},{'id': '51', 'type': 'return_statement', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'tokens'}
def GetOrderKey(self): context_attributes = ['_type'] context_attributes.extend(ExceptionWithContext.CONTEXT_PARTS) context_attributes.extend(self._GetExtraOrderAttributes()) tokens = [] for context_attribute in context_attributes: tokens.append(getattr(self, context_attribute, None)) return tokens
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'AddShapePointObjectUnsorted'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'shapepoint'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'problems'},{'id': '7', 'type': 'block', 'children': ['8', '70', '100', '199', '216', '228', '240']},{'id': '8', 'type': 'if_statement', 'children': ['9', '29', '39', '54']},{'id': '9', 'type': '()', 'children': ['10']},{'id': '10', 'type': 'boolean_operator', 'children': ['11', '19'], 'value': 'or'},{'id': '11', 'type': 'comparison_operator', 'children': ['12', '18'], 'value': '=='},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'sequence'},{'id': '18', 'type': 'integer', 'children': [], 'value': '0'},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '23'], 'value': '>='},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'shapepoint'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'shape_pt_sequence'},{'id': '23', 'type': 'subscript', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'sequence'},{'id': '27', 'type': 'unary_operator', 'children': ['28'], 'value': '-'},{'id': '28', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'index'},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'sequence'},{'id': '39', 'type': 'elif_clause', 'children': ['40', '49']},{'id': '40', 'type': 'comparison_operator', 'children': ['41', '44'], 'value': '<='},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'shapepoint'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'shape_pt_sequence'},{'id': '44', 'type': 'subscript', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'sequence'},{'id': '48', 'type': 'integer', 'children': [], 'value': '0'},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '53', 'type': 'integer', 'children': [], 'value': '0'},{'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', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'bisect'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'bisect'},{'id': '63', 'type': 'argument_list', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'sequence'},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'shapepoint'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'shape_pt_sequence'},{'id': '70', 'type': 'if_statement', 'children': ['71', '78']},{'id': '71', 'type': 'comparison_operator', 'children': ['72', '75'], 'value': 'in'},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'shapepoint'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'shape_pt_sequence'},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'sequence'},{'id': '78', 'type': 'block', 'children': ['79']},{'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': 'problems'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'InvalidValue'},{'id': '84', 'type': 'argument_list', 'children': ['85', '86', '89']},{'id': '85', 'type': 'string', 'children': [], 'value': "'shape_pt_sequence'"},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'shapepoint'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'shape_pt_sequence'},{'id': '89', 'type': 'binary_operator', 'children': ['90', '93'], 'value': '%'},{'id': '90', 'type': 'concatenated_string', 'children': ['91', '92']},{'id': '91', 'type': 'string', 'children': [], 'value': "'The sequence number %d occurs more than once in '"},{'id': '92', 'type': 'string', 'children': [], 'value': "'shape %s.'"},{'id': '93', 'type': 'tuple', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'shapepoint'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'shape_pt_sequence'},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'shape_id'},{'id': '100', 'type': 'if_statement', 'children': ['101', '115']},{'id': '101', 'type': 'boolean_operator', 'children': ['102', '107'], 'value': 'and'},{'id': '102', 'type': 'comparison_operator', 'children': ['103', '106'], 'value': 'is'},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'shapepoint'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'shape_dist_traveled'},{'id': '106', 'type': 'None', 'children': []},{'id': '107', 'type': 'comparison_operator', 'children': ['108', '114'], 'value': '>'},{'id': '108', 'type': 'call', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'sequence'},{'id': '114', 'type': 'integer', 'children': [], 'value': '0'},{'id': '115', 'type': 'block', 'children': ['116', '158']},{'id': '116', 'type': 'if_statement', 'children': ['117', '136']},{'id': '117', 'type': '()', 'children': ['118']},{'id': '118', 'type': 'boolean_operator', 'children': ['119', '127'], 'value': 'and'},{'id': '119', 'type': 'comparison_operator', 'children': ['120', '121'], 'value': '!='},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '121', 'type': 'call', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'sequence'},{'id': '127', 'type': 'comparison_operator', 'children': ['128', '131'], 'value': '>'},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'shapepoint'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'shape_dist_traveled'},{'id': '131', 'type': 'subscript', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'distance'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '136', 'type': 'block', 'children': ['137']},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'problems'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'InvalidValue'},{'id': '142', 'type': 'argument_list', 'children': ['143', '144', '147']},{'id': '143', 'type': 'string', 'children': [], 'value': "'shape_dist_traveled'"},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'shapepoint'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'shape_dist_traveled'},{'id': '147', 'type': 'binary_operator', 'children': ['148', '153'], 'value': '%'},{'id': '148', 'type': 'concatenated_string', 'children': ['149', '150', '151', '152']},{'id': '149', 'type': 'string', 'children': [], 'value': "'Each subsequent point in a shape should have '"},{'id': '150', 'type': 'string', 'children': [], 'value': "'a distance value that shouldn\\'t be larger '"},{'id': '151', 'type': 'string', 'children': [], 'value': "'than the next ones. In this case, the next '"},{'id': '152', 'type': 'string', 'children': [], 'value': "'distance was %f.'"},{'id': '153', 'type': 'subscript', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'distance'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '158', 'type': 'if_statement', 'children': ['159', '175']},{'id': '159', 'type': '()', 'children': ['160']},{'id': '160', 'type': 'boolean_operator', 'children': ['161', '164'], 'value': 'and'},{'id': '161', 'type': 'comparison_operator', 'children': ['162', '163'], 'value': '>'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '163', 'type': 'integer', 'children': [], 'value': '0'},{'id': '164', 'type': 'comparison_operator', 'children': ['165', '168'], 'value': '<'},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'shapepoint'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'shape_dist_traveled'},{'id': '168', 'type': 'subscript', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'distance'},{'id': '172', 'type': 'binary_operator', 'children': ['173', '174'], 'value': '-'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '174', 'type': 'integer', 'children': [], 'value': '1'},{'id': '175', 'type': 'block', 'children': ['176']},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'call', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'problems'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'InvalidValue'},{'id': '181', 'type': 'argument_list', 'children': ['182', '183', '186']},{'id': '182', 'type': 'string', 'children': [], 'value': "'shape_dist_traveled'"},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'shapepoint'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'shape_dist_traveled'},{'id': '186', 'type': 'binary_operator', 'children': ['187', '192'], 'value': '%'},{'id': '187', 'type': 'concatenated_string', 'children': ['188', '189', '190', '191']},{'id': '188', 'type': 'string', 'children': [], 'value': "'Each subsequent point in a shape should have '"},{'id': '189', 'type': 'string', 'children': [], 'value': "'a distance value that\\'s at least as large as '"},{'id': '190', 'type': 'string', 'children': [], 'value': "'the previous ones. In this case, the previous '"},{'id': '191', 'type': 'string', 'children': [], 'value': "'distance was %f.'"},{'id': '192', 'type': 'subscript', 'children': ['193', '196']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'distance'},{'id': '196', 'type': 'binary_operator', 'children': ['197', '198'], 'value': '-'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '198', 'type': 'integer', 'children': [], 'value': '1'},{'id': '199', 'type': 'if_statement', 'children': ['200', '207']},{'id': '200', 'type': 'comparison_operator', 'children': ['201', '204'], 'value': '>'},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'shapepoint'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'shape_dist_traveled'},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'max_distance'},{'id': '207', 'type': 'block', 'children': ['208']},{'id': '208', 'type': 'expression_statement', 'children': ['209']},{'id': '209', 'type': 'assignment', 'children': ['210', '213']},{'id': '210', 'type': 'attribute', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'max_distance'},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'shapepoint'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'shape_dist_traveled'},{'id': '216', 'type': 'expression_statement', 'children': ['217']},{'id': '217', 'type': 'call', 'children': ['218', '223']},{'id': '218', 'type': 'attribute', 'children': ['219', '222']},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'sequence'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '223', 'type': 'argument_list', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'shapepoint'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'shape_pt_sequence'},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'call', 'children': ['230', '235']},{'id': '230', 'type': 'attribute', 'children': ['231', '234']},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'distance'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '235', 'type': 'argument_list', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '237', 'type': 'attribute', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'shapepoint'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'shape_dist_traveled'},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'call', 'children': ['242', '247']},{'id': '242', 'type': 'attribute', 'children': ['243', '246']},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'points'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '247', 'type': 'argument_list', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '249', 'type': 'tuple', 'children': ['250', '253', '256']},{'id': '250', 'type': 'attribute', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'shapepoint'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'shape_pt_lat'},{'id': '253', 'type': 'attribute', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'shapepoint'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'shape_pt_lon'},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'shapepoint'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'shape_dist_traveled'}
def AddShapePointObjectUnsorted(self, shapepoint, problems): if (len(self.sequence) == 0 or shapepoint.shape_pt_sequence >= self.sequence[-1]): index = len(self.sequence) elif shapepoint.shape_pt_sequence <= self.sequence[0]: index = 0 else: index = bisect.bisect(self.sequence, shapepoint.shape_pt_sequence) if shapepoint.shape_pt_sequence in self.sequence: problems.InvalidValue('shape_pt_sequence', shapepoint.shape_pt_sequence, 'The sequence number %d occurs more than once in ' 'shape %s.' % (shapepoint.shape_pt_sequence, self.shape_id)) if shapepoint.shape_dist_traveled is not None and len(self.sequence) > 0: if (index != len(self.sequence) and shapepoint.shape_dist_traveled > self.distance[index]): problems.InvalidValue('shape_dist_traveled', shapepoint.shape_dist_traveled, 'Each subsequent point in a shape should have ' 'a distance value that shouldn\'t be larger ' 'than the next ones. In this case, the next ' 'distance was %f.' % self.distance[index]) if (index > 0 and shapepoint.shape_dist_traveled < self.distance[index - 1]): problems.InvalidValue('shape_dist_traveled', shapepoint.shape_dist_traveled, 'Each subsequent point in a shape should have ' 'a distance value that\'s at least as large as ' 'the previous ones. In this case, the previous ' 'distance was %f.' % self.distance[index - 1]) if shapepoint.shape_dist_traveled > self.max_distance: self.max_distance = shapepoint.shape_dist_traveled self.sequence.insert(index, shapepoint.shape_pt_sequence) self.distance.insert(index, shapepoint.shape_dist_traveled) self.points.insert(index, (shapepoint.shape_pt_lat, shapepoint.shape_pt_lon, shapepoint.shape_dist_traveled))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'GetStopTimes'},{'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': 'problems'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '21', '37', '41', '51', '62', '138']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'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': '_schedule'},{'id': '18', 'type': 'identifier', 'children': [], 'value': '_connection'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '20', 'type': 'argument_list', 'children': []},{'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': 'cursor'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'execute'},{'id': '26', 'type': 'argument_list', 'children': ['27', '33']},{'id': '27', 'type': 'concatenated_string', 'children': ['28', '29', '30', '31', '32']},{'id': '28', 'type': 'string', 'children': [], 'value': "'SELECT arrival_secs,departure_secs,stop_headsign,pickup_type,'"},{'id': '29', 'type': 'string', 'children': [], 'value': "'drop_off_type,shape_dist_traveled,stop_id,stop_sequence,timepoint '"},{'id': '30', 'type': 'string', 'children': [], 'value': "'FROM stop_times '"},{'id': '31', 'type': 'string', 'children': [], 'value': "'WHERE trip_id=? '"},{'id': '32', 'type': 'string', 'children': [], 'value': "'ORDER BY stop_sequence'"},{'id': '33', 'type': 'tuple', 'children': ['34']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'trip_id'},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'stop_times'},{'id': '40', 'type': 'list', 'children': [], 'value': '[]'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'stoptime_class'},{'id': '44', 'type': 'attribute', 'children': ['45', '50']},{'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': 'GetGtfsFactory'},{'id': '49', 'type': 'argument_list', 'children': []},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'StopTime'},{'id': '51', 'type': 'if_statement', 'children': ['52', '55']},{'id': '52', 'type': 'comparison_operator', 'children': ['53', '54'], 'value': 'is'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'problems'},{'id': '54', 'type': 'None', 'children': []},{'id': '55', 'type': 'block', 'children': ['56']},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'problems'},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'problems_module'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'default_problem_reporter'},{'id': '62', 'type': 'for_statement', 'children': ['63', '64', '69']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'fetchall'},{'id': '68', 'type': 'argument_list', 'children': []},{'id': '69', 'type': 'block', 'children': ['70', '83']},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '73', 'type': 'call', 'children': ['74', '79']},{'id': '74', 'type': 'attribute', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '77', 'type': 'identifier', 'children': [], 'value': '_schedule'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'GetStop'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'subscript', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '82', 'type': 'integer', 'children': [], 'value': '6'},{'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': 'stop_times'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'call', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'stoptime_class'},{'id': '91', 'type': 'argument_list', 'children': ['92', '95', '98', '103', '108', '113', '118', '123', '128', '133']},{'id': '92', 'type': 'keyword_argument', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'problems'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'problems'},{'id': '95', 'type': 'keyword_argument', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '98', 'type': 'keyword_argument', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'arrival_secs'},{'id': '100', 'type': 'subscript', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '102', 'type': 'integer', 'children': [], 'value': '0'},{'id': '103', 'type': 'keyword_argument', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'departure_secs'},{'id': '105', 'type': 'subscript', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '107', 'type': 'integer', 'children': [], 'value': '1'},{'id': '108', 'type': 'keyword_argument', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'stop_headsign'},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '112', 'type': 'integer', 'children': [], 'value': '2'},{'id': '113', 'type': 'keyword_argument', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'pickup_type'},{'id': '115', 'type': 'subscript', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '117', 'type': 'integer', 'children': [], 'value': '3'},{'id': '118', 'type': 'keyword_argument', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'drop_off_type'},{'id': '120', 'type': 'subscript', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '122', 'type': 'integer', 'children': [], 'value': '4'},{'id': '123', 'type': 'keyword_argument', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'shape_dist_traveled'},{'id': '125', 'type': 'subscript', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '127', 'type': 'integer', 'children': [], 'value': '5'},{'id': '128', 'type': 'keyword_argument', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'stop_sequence'},{'id': '130', 'type': 'subscript', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '132', 'type': 'integer', 'children': [], 'value': '7'},{'id': '133', 'type': 'keyword_argument', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'timepoint'},{'id': '135', 'type': 'subscript', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '137', 'type': 'integer', 'children': [], 'value': '8'},{'id': '138', 'type': 'return_statement', 'children': ['139']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'stop_times'}
def GetStopTimes(self, problems=None): cursor = self._schedule._connection.cursor() cursor.execute( 'SELECT arrival_secs,departure_secs,stop_headsign,pickup_type,' 'drop_off_type,shape_dist_traveled,stop_id,stop_sequence,timepoint ' 'FROM stop_times ' 'WHERE trip_id=? ' 'ORDER BY stop_sequence', (self.trip_id,)) stop_times = [] stoptime_class = self.GetGtfsFactory().StopTime if problems is None: problems = problems_module.default_problem_reporter for row in cursor.fetchall(): stop = self._schedule.GetStop(row[6]) stop_times.append(stoptime_class(problems=problems, stop=stop, arrival_secs=row[0], departure_secs=row[1], stop_headsign=row[2], pickup_type=row[3], drop_off_type=row[4], shape_dist_traveled=row[5], stop_sequence=row[7], timepoint=row[8])) return stop_times
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'GetFrequencyStartTimes'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '10', '50']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'start_times'},{'id': '9', 'type': 'list', 'children': [], 'value': '[]'},{'id': '10', 'type': 'for_statement', 'children': ['11', '12', '17']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'freq_tuple'},{'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': 'GetFrequencyTuples'},{'id': '16', 'type': 'argument_list', 'children': []},{'id': '17', 'type': 'block', 'children': ['18', '30', '34']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '24']},{'id': '20', 'type': 'tuple_pattern', 'children': ['21', '22', '23']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'start_secs'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'end_secs'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'headway_secs'},{'id': '24', 'type': 'subscript', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'freq_tuple'},{'id': '26', 'type': 'slice', 'children': ['27', '28', '29']},{'id': '27', 'type': 'integer', 'children': [], 'value': '0'},{'id': '28', 'type': 'colon', 'children': []},{'id': '29', 'type': 'integer', 'children': [], 'value': '3'},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'run_secs'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'start_secs'},{'id': '34', 'type': 'while_statement', 'children': ['35', '38']},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': '<'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'run_secs'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'end_secs'},{'id': '38', 'type': 'block', 'children': ['39', '46']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'start_times'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'run_secs'},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'augmented_assignment', 'children': ['48', '49'], 'value': '+='},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'run_secs'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'headway_secs'},{'id': '50', 'type': 'return_statement', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'start_times'}
def GetFrequencyStartTimes(self): start_times = [] for freq_tuple in self.GetFrequencyTuples(): (start_secs, end_secs, headway_secs) = freq_tuple[0:3] run_secs = start_secs while run_secs < end_secs: start_times.append(run_secs) run_secs += headway_secs return start_times
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'create'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '6', 'type': 'block', 'children': ['7', '12', '50', '63', '74', '90', '103', '112', '146', '162', '191', '228', '234', '280', '301', '338', '381']},{'id': '7', 'type': 'import_from_statement', 'children': ['8', '10']},{'id': '8', 'type': 'relative_import', 'children': ['9']},{'id': '9', 'type': 'import_prefix', 'children': []},{'id': '10', 'type': 'dotted_name', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': '_segyio'},{'id': '12', 'type': 'if_statement', 'children': ['13', '18', '25']},{'id': '13', 'type': 'not_operator', 'children': ['14']},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'structured'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'tracecount'},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'tracecount'},{'id': '25', 'type': 'else_clause', 'children': ['26']},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'tracecount'},{'id': '30', 'type': 'binary_operator', 'children': ['31', '44'], 'value': '*'},{'id': '31', 'type': 'binary_operator', 'children': ['32', '38'], 'value': '*'},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'ilines'},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'xlines'},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'offsets'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'ext_headers'},{'id': '53', 'type': 'conditional_expression', 'children': ['54', '57', '62'], 'value': 'if'},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'ext_headers'},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '59', 'type': 'argument_list', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '61', 'type': 'string', 'children': [], 'value': "'ext_headers'"},{'id': '62', 'type': 'integer', 'children': [], 'value': '0'},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'samples'},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'asarray'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'samples'},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'endians'},{'id': '77', 'type': 'dictionary', 'children': ['78', '81', '84', '87']},{'id': '78', 'type': 'pair', 'children': ['79', '80']},{'id': '79', 'type': 'string', 'children': [], 'value': "'lsb'"},{'id': '80', 'type': 'integer', 'children': [], 'value': '256'},{'id': '81', 'type': 'pair', 'children': ['82', '83']},{'id': '82', 'type': 'string', 'children': [], 'value': "'little'"},{'id': '83', 'type': 'integer', 'children': [], 'value': '256'},{'id': '84', 'type': 'pair', 'children': ['85', '86']},{'id': '85', 'type': 'string', 'children': [], 'value': "'msb'"},{'id': '86', 'type': 'integer', 'children': [], 'value': '0'},{'id': '87', 'type': 'pair', 'children': ['88', '89']},{'id': '88', 'type': 'string', 'children': [], 'value': "'big'"},{'id': '89', 'type': 'integer', 'children': [], 'value': '0'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'endian'},{'id': '93', 'type': 'conditional_expression', 'children': ['94', '97', '102'], 'value': 'if'},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'endian'},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '99', 'type': 'argument_list', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '101', 'type': 'string', 'children': [], 'value': "'endian'"},{'id': '102', 'type': 'string', 'children': [], 'value': "'big'"},{'id': '103', 'type': 'if_statement', 'children': ['104', '107']},{'id': '104', 'type': 'comparison_operator', 'children': ['105', '106'], 'value': 'is'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'endian'},{'id': '106', 'type': 'None', 'children': []},{'id': '107', 'type': 'block', 'children': ['108']},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'endian'},{'id': '111', 'type': 'string', 'children': [], 'value': "'big'"},{'id': '112', 'type': 'if_statement', 'children': ['113', '116']},{'id': '113', 'type': 'comparison_operator', 'children': ['114', '115'], 'value': 'not'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'endian'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'endians'},{'id': '116', 'type': 'block', 'children': ['117', '121', '134']},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'problem'},{'id': '120', 'type': 'string', 'children': [], 'value': "'unknown endianness {}, expected one of: '"},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '124', 'type': 'call', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'string', 'children': [], 'value': "' '"},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'call', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'endians'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '133', 'type': 'argument_list', 'children': []},{'id': '134', 'type': 'raise_statement', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'binary_operator', 'children': ['139', '145'], 'value': '+'},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'problem'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'endian'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'assignment', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'fd'},{'id': '149', 'type': 'call', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': '_segyio'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'segyiofd'},{'id': '153', 'type': 'argument_list', 'children': ['154', '158', '159']},{'id': '154', 'type': 'call', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '158', 'type': 'string', 'children': [], 'value': "'w+'"},{'id': '159', 'type': 'subscript', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'endians'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'endian'},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'call', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'fd'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'segymake'},{'id': '167', 'type': 'argument_list', 'children': ['168', '174', '177', '185']},{'id': '168', 'type': 'keyword_argument', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'samples'},{'id': '170', 'type': 'call', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'samples'},{'id': '174', 'type': 'keyword_argument', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'tracecount'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'tracecount'},{'id': '177', 'type': 'keyword_argument', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '179', 'type': 'call', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '185', 'type': 'keyword_argument', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'ext_headers'},{'id': '187', 'type': 'call', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'ext_headers'},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '194', 'type': 'call', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'segyio'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'SegyFile'},{'id': '198', 'type': 'argument_list', 'children': ['199', '200', '206', '209', '217', '225']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'fd'},{'id': '200', 'type': 'keyword_argument', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '202', 'type': 'call', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '204', 'type': 'argument_list', 'children': ['205']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '206', 'type': 'keyword_argument', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '208', 'type': 'string', 'children': [], 'value': "'w+'"},{'id': '209', 'type': 'keyword_argument', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'iline'},{'id': '211', 'type': 'call', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '213', 'type': 'argument_list', 'children': ['214']},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'iline'},{'id': '217', 'type': 'keyword_argument', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'xline'},{'id': '219', 'type': 'call', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '221', 'type': 'argument_list', 'children': ['222']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'xline'},{'id': '225', 'type': 'keyword_argument', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'endian'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'endian'},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'assignment', 'children': ['230', '233']},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '232', 'type': 'identifier', 'children': [], 'value': '_samples'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'samples'},{'id': '234', 'type': 'if_statement', 'children': ['235', '239']},{'id': '235', 'type': 'call', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'structured'},{'id': '237', 'type': 'argument_list', 'children': ['238']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '239', 'type': 'block', 'children': ['240', '253', '264']},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'assignment', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'sorting'},{'id': '243', 'type': 'conditional_expression', 'children': ['244', '247', '252'], 'value': 'if'},{'id': '244', 'type': 'attribute', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'sorting'},{'id': '247', 'type': 'call', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '249', 'type': 'argument_list', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '251', 'type': 'string', 'children': [], 'value': "'sorting'"},{'id': '252', 'type': 'None', 'children': []},{'id': '253', 'type': 'if_statement', 'children': ['254', '257']},{'id': '254', 'type': 'comparison_operator', 'children': ['255', '256'], 'value': 'is'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'sorting'},{'id': '256', 'type': 'None', 'children': []},{'id': '257', 'type': 'block', 'children': ['258']},{'id': '258', 'type': 'expression_statement', 'children': ['259']},{'id': '259', 'type': 'assignment', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'sorting'},{'id': '261', 'type': 'attribute', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'TraceSortingFormat'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'INLINE_SORTING'},{'id': '264', 'type': 'expression_statement', 'children': ['265']},{'id': '265', 'type': 'call', 'children': ['266', '269']},{'id': '266', 'type': 'attribute', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'interpret'},{'id': '269', 'type': 'argument_list', 'children': ['270', '273', '276', '279']},{'id': '270', 'type': 'attribute', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'ilines'},{'id': '273', 'type': 'attribute', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'xlines'},{'id': '276', 'type': 'attribute', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'offsets'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'sorting'},{'id': '280', 'type': 'expression_statement', 'children': ['281']},{'id': '281', 'type': 'assignment', 'children': ['282', '287']},{'id': '282', 'type': 'subscript', 'children': ['283', '286']},{'id': '283', 'type': 'attribute', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '286', 'type': 'integer', 'children': [], 'value': '0'},{'id': '287', 'type': 'call', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'default_text_header'},{'id': '289', 'type': 'argument_list', 'children': ['290', '293', '296']},{'id': '290', 'type': 'attribute', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '292', 'type': 'identifier', 'children': [], 'value': '_il'},{'id': '293', 'type': 'attribute', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '295', 'type': 'identifier', 'children': [], 'value': '_xl'},{'id': '296', 'type': 'attribute', 'children': ['297', '300']},{'id': '297', 'type': 'attribute', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'segyio'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'TraceField'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '301', 'type': 'if_statement', 'children': ['302', '308', '320']},{'id': '302', 'type': 'comparison_operator', 'children': ['303', '307'], 'value': '=='},{'id': '303', 'type': 'call', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '305', 'type': 'argument_list', 'children': ['306']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'samples'},{'id': '307', 'type': 'integer', 'children': [], 'value': '1'},{'id': '308', 'type': 'block', 'children': ['309']},{'id': '309', 'type': 'expression_statement', 'children': ['310']},{'id': '310', 'type': 'assignment', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'interval'},{'id': '312', 'type': 'call', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '314', 'type': 'argument_list', 'children': ['315']},{'id': '315', 'type': 'binary_operator', 'children': ['316', '319'], 'value': '*'},{'id': '316', 'type': 'subscript', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'samples'},{'id': '318', 'type': 'integer', 'children': [], 'value': '0'},{'id': '319', 'type': 'integer', 'children': [], 'value': '1000'},{'id': '320', 'type': 'else_clause', 'children': ['321']},{'id': '321', 'type': 'block', 'children': ['322']},{'id': '322', 'type': 'expression_statement', 'children': ['323']},{'id': '323', 'type': 'assignment', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'interval'},{'id': '325', 'type': 'call', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '327', 'type': 'argument_list', 'children': ['328']},{'id': '328', 'type': 'binary_operator', 'children': ['329', '337'], 'value': '*'},{'id': '329', 'type': '()', 'children': ['330']},{'id': '330', 'type': 'binary_operator', 'children': ['331', '334'], 'value': '-'},{'id': '331', 'type': 'subscript', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'samples'},{'id': '333', 'type': 'integer', 'children': [], 'value': '1'},{'id': '334', 'type': 'subscript', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'samples'},{'id': '336', 'type': 'integer', 'children': [], 'value': '0'},{'id': '337', 'type': 'integer', 'children': [], 'value': '1000'},{'id': '338', 'type': 'expression_statement', 'children': ['339']},{'id': '339', 'type': 'call', 'children': ['340', '345']},{'id': '340', 'type': 'attribute', 'children': ['341', '344']},{'id': '341', 'type': 'attribute', 'children': ['342', '343']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'bin'},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '345', 'type': 'argument_list', 'children': ['346', '349', '352', '355', '358', '364', '370', '378']},{'id': '346', 'type': 'keyword_argument', 'children': ['347', '348']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'ntrpr'},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'tracecount'},{'id': '349', 'type': 'keyword_argument', 'children': ['350', '351']},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'nart'},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'tracecount'},{'id': '352', 'type': 'keyword_argument', 'children': ['353', '354']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'hdt'},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'interval'},{'id': '355', 'type': 'keyword_argument', 'children': ['356', '357']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'dto'},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'interval'},{'id': '358', 'type': 'keyword_argument', 'children': ['359', '360']},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'hns'},{'id': '360', 'type': 'call', 'children': ['361', '362']},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '362', 'type': 'argument_list', 'children': ['363']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'samples'},{'id': '364', 'type': 'keyword_argument', 'children': ['365', '366']},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'nso'},{'id': '366', 'type': 'call', 'children': ['367', '368']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '368', 'type': 'argument_list', 'children': ['369']},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'samples'},{'id': '370', 'type': 'keyword_argument', 'children': ['371', '372']},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '372', 'type': 'call', 'children': ['373', '374']},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '374', 'type': 'argument_list', 'children': ['375']},{'id': '375', 'type': 'attribute', 'children': ['376', '377']},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '378', 'type': 'keyword_argument', 'children': ['379', '380']},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'exth'},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'ext_headers'},{'id': '381', 'type': 'return_statement', 'children': ['382']},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'f'}
def create(filename, spec): from . import _segyio if not structured(spec): tracecount = spec.tracecount else: tracecount = len(spec.ilines) * len(spec.xlines) * len(spec.offsets) ext_headers = spec.ext_headers if hasattr(spec, 'ext_headers') else 0 samples = numpy.asarray(spec.samples) endians = { 'lsb': 256, 'little': 256, 'msb': 0, 'big': 0, } endian = spec.endian if hasattr(spec, 'endian') else 'big' if endian is None: endian = 'big' if endian not in endians: problem = 'unknown endianness {}, expected one of: ' opts = ' '.join(endians.keys()) raise ValueError(problem.format(endian) + opts) fd = _segyio.segyiofd(str(filename), 'w+', endians[endian]) fd.segymake( samples = len(samples), tracecount = tracecount, format = int(spec.format), ext_headers = int(ext_headers), ) f = segyio.SegyFile(fd, filename = str(filename), mode = 'w+', iline = int(spec.iline), xline = int(spec.xline), endian = endian, ) f._samples = samples if structured(spec): sorting = spec.sorting if hasattr(spec, 'sorting') else None if sorting is None: sorting = TraceSortingFormat.INLINE_SORTING f.interpret(spec.ilines, spec.xlines, spec.offsets, sorting) f.text[0] = default_text_header(f._il, f._xl, segyio.TraceField.offset) if len(samples) == 1: interval = int(samples[0] * 1000) else: interval = int((samples[1] - samples[0]) * 1000) f.bin.update( ntrpr = tracecount, nart = tracecount, hdt = interval, dto = interval, hns = len(samples), nso = len(samples), format = int(spec.format), exth = ext_headers, ) return f
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'rotation'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '7', 'type': 'string', 'children': [], 'value': "'fast'"},{'id': '8', 'type': 'block', 'children': ['9', '19', '43', '86', '92', '111', '131', '169']},{'id': '9', 'type': 'if_statement', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'unstructured'},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'raise_statement', 'children': ['15']},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'string', 'children': [], 'value': '"Rotation requires a structured file"'},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '22', 'type': 'dictionary', 'children': ['23', '28', '33', '38']},{'id': '23', 'type': 'pair', 'children': ['24', '25']},{'id': '24', 'type': 'string', 'children': [], 'value': "'fast'"},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'fast'},{'id': '28', 'type': 'pair', 'children': ['29', '30']},{'id': '29', 'type': 'string', 'children': [], 'value': "'slow'"},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'slow'},{'id': '33', 'type': 'pair', 'children': ['34', '35']},{'id': '34', 'type': 'string', 'children': [], 'value': "'iline'"},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'iline'},{'id': '38', 'type': 'pair', 'children': ['39', '40']},{'id': '39', 'type': 'string', 'children': [], 'value': "'xline'"},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'xline'},{'id': '43', 'type': 'if_statement', 'children': ['44', '47']},{'id': '44', 'type': 'comparison_operator', 'children': ['45', '46'], 'value': 'not'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '47', 'type': 'block', 'children': ['48', '57', '75']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '51', 'type': 'call', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'string', 'children': [], 'value': '"Unknown line {}"'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'solution'},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'string', 'children': [], 'value': '"Must be any of: {}"'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'string', 'children': [], 'value': "' '"},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '74', 'type': 'argument_list', 'children': []},{'id': '75', 'type': 'raise_statement', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'string', 'children': [], 'value': "'{} {}'"},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '83', 'type': 'argument_list', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'solution'},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '89', 'type': 'subscript', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'origin'},{'id': '95', 'type': 'subscript', 'children': ['96', '101', '106']},{'id': '96', 'type': 'subscript', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '100', 'type': 'integer', 'children': [], 'value': '0'},{'id': '101', 'type': 'attribute', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'segyio'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'su'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'cdpx'},{'id': '106', 'type': 'attribute', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'segyio'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'su'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'cdpy'},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '116']},{'id': '113', 'type': 'pattern_list', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'cdpx'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'cdpy'},{'id': '116', 'type': 'expression_list', 'children': ['117', '124']},{'id': '117', 'type': 'subscript', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'origin'},{'id': '119', 'type': 'attribute', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'segyio'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'su'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'cdpx'},{'id': '124', 'type': 'subscript', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'origin'},{'id': '126', 'type': 'attribute', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'segyio'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'su'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'cdpy'},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'rot'},{'id': '134', 'type': 'call', 'children': ['135', '140']},{'id': '135', 'type': 'attribute', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'xfd'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'rotation'},{'id': '140', 'type': 'argument_list', 'children': ['141', '145', '148', '154']},{'id': '141', 'type': 'call', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'stride'},{'id': '148', 'type': 'call', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '150', 'type': 'argument_list', 'children': ['151']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'offsets'},{'id': '154', 'type': 'call', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'fromiter'},{'id': '158', 'type': 'argument_list', 'children': ['159', '164']},{'id': '159', 'type': 'call', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '163', 'type': 'argument_list', 'children': []},{'id': '164', 'type': 'keyword_argument', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'intc'},{'id': '169', 'type': 'return_statement', 'children': ['170']},{'id': '170', 'type': 'expression_list', 'children': ['171', '172', '173']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'rot'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'cdpx'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'cdpy'}
def rotation(f, line = 'fast'): if f.unstructured: raise ValueError("Rotation requires a structured file") lines = { 'fast': f.fast, 'slow': f.slow, 'iline': f.iline, 'xline': f.xline, } if line not in lines: error = "Unknown line {}".format(line) solution = "Must be any of: {}".format(' '.join(lines.keys())) raise ValueError('{} {}'.format(error, solution)) l = lines[line] origin = f.header[0][segyio.su.cdpx, segyio.su.cdpy] cdpx, cdpy = origin[segyio.su.cdpx], origin[segyio.su.cdpy] rot = f.xfd.rotation( len(l), l.stride, len(f.offsets), np.fromiter(l.keys(), dtype = np.intc) ) return rot, cdpx, cdpy
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '23']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'from_array3D'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '17', '20']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'iline'},{'id': '8', 'type': 'integer', 'children': [], 'value': '189'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'xline'},{'id': '11', 'type': 'integer', 'children': [], 'value': '193'},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'SegySampleFormat'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'IBM_FLOAT_4_BYTE'},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'dt'},{'id': '19', 'type': 'integer', 'children': [], 'value': '4000'},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'delrt'},{'id': '22', 'type': 'integer', 'children': [], 'value': '0'},{'id': '23', 'type': 'block', 'children': ['24', '33', '42', '61']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'asarray'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'dimensions'},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '42', 'type': 'if_statement', 'children': ['43', '46']},{'id': '43', 'type': 'comparison_operator', 'children': ['44', '45'], 'value': '!='},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'dimensions'},{'id': '45', 'type': 'integer', 'children': [], 'value': '3'},{'id': '46', 'type': 'block', 'children': ['47', '56']},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'problem'},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'string', 'children': [], 'value': '"Expected 3 dimensions, {} was given"'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'dimensions'},{'id': '56', 'type': 'raise_statement', 'children': ['57']},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'problem'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'from_array'},{'id': '64', 'type': 'argument_list', 'children': ['65', '66', '67', '70', '73', '76', '79']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '67', 'type': 'keyword_argument', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'iline'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'iline'},{'id': '70', 'type': 'keyword_argument', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'xline'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'xline'},{'id': '73', 'type': 'keyword_argument', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '76', 'type': 'keyword_argument', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'dt'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'dt'},{'id': '79', 'type': 'keyword_argument', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'delrt'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'delrt'}
def from_array3D(filename, data, iline=189, xline=193, format=SegySampleFormat.IBM_FLOAT_4_BYTE, dt=4000, delrt=0): data = np.asarray(data) dimensions = len(data.shape) if dimensions != 3: problem = "Expected 3 dimensions, {} was given".format(dimensions) raise ValueError(problem) from_array(filename, data, iline=iline, xline=xline, format=format, dt=dt, delrt=delrt)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '23']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'open'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '7', 'type': 'string', 'children': [], 'value': '"r"'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'iline'},{'id': '10', 'type': 'integer', 'children': [], 'value': '189'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'xline'},{'id': '13', 'type': 'integer', 'children': [], 'value': '193'},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'strict'},{'id': '16', 'type': 'True', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'ignore_geometry'},{'id': '19', 'type': 'False', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'endian'},{'id': '22', 'type': 'string', 'children': [], 'value': "'big'"},{'id': '23', 'type': 'block', 'children': ['24', '49', '65', '99', '104', '120', '126', '134', '161', '224', '229']},{'id': '24', 'type': 'if_statement', 'children': ['25', '28']},{'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': 'in'},{'id': '26', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '28', 'type': 'block', 'children': ['29', '33', '37']},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'problem'},{'id': '32', 'type': 'string', 'children': [], 'value': "'w in mode would truncate the file'"},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'solution'},{'id': '36', 'type': 'string', 'children': [], 'value': "'use r+ to open in read-write'"},{'id': '37', 'type': 'raise_statement', 'children': ['38']},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'string', 'children': [], 'value': "', '"},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'tuple', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'problem'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'solution'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'endians'},{'id': '52', 'type': 'dictionary', 'children': ['53', '56', '59', '62']},{'id': '53', 'type': 'pair', 'children': ['54', '55']},{'id': '54', 'type': 'string', 'children': [], 'value': "'little'"},{'id': '55', 'type': 'integer', 'children': [], 'value': '256'},{'id': '56', 'type': 'pair', 'children': ['57', '58']},{'id': '57', 'type': 'string', 'children': [], 'value': "'lsb'"},{'id': '58', 'type': 'integer', 'children': [], 'value': '256'},{'id': '59', 'type': 'pair', 'children': ['60', '61']},{'id': '60', 'type': 'string', 'children': [], 'value': "'big'"},{'id': '61', 'type': 'integer', 'children': [], 'value': '0'},{'id': '62', 'type': 'pair', 'children': ['63', '64']},{'id': '63', 'type': 'string', 'children': [], 'value': "'msb'"},{'id': '64', 'type': 'integer', 'children': [], 'value': '0'},{'id': '65', 'type': 'if_statement', 'children': ['66', '69']},{'id': '66', 'type': 'comparison_operator', 'children': ['67', '68'], 'value': 'not'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'endian'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'endians'},{'id': '69', 'type': 'block', 'children': ['70', '74', '87']},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'problem'},{'id': '73', 'type': 'string', 'children': [], 'value': "'unknown endianness {}, expected one of: '"},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'string', 'children': [], 'value': "' '"},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'endians'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '86', 'type': 'argument_list', 'children': []},{'id': '87', 'type': 'raise_statement', 'children': ['88']},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'binary_operator', 'children': ['92', '98'], 'value': '+'},{'id': '92', 'type': 'call', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'problem'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'endian'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '99', 'type': 'import_from_statement', 'children': ['100', '102']},{'id': '100', 'type': 'relative_import', 'children': ['101']},{'id': '101', 'type': 'import_prefix', 'children': []},{'id': '102', 'type': 'dotted_name', 'children': ['103']},{'id': '103', 'type': 'identifier', 'children': [], 'value': '_segyio'},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'fd'},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': '_segyio'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'segyiofd'},{'id': '111', 'type': 'argument_list', 'children': ['112', '116', '117']},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '117', 'type': 'subscript', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'endians'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'endian'},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'call', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'fd'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'segyopen'},{'id': '125', 'type': 'argument_list', 'children': []},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'metrics'},{'id': '129', 'type': 'call', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'fd'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'metrics'},{'id': '133', 'type': 'argument_list', 'children': []},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '137', 'type': 'call', 'children': ['138', '141']},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'segyio'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'SegyFile'},{'id': '141', 'type': 'argument_list', 'children': ['142', '143', '149', '152', '155', '158']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'fd'},{'id': '143', 'type': 'keyword_argument', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '145', 'type': 'call', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '149', 'type': 'keyword_argument', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '152', 'type': 'keyword_argument', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'iline'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'iline'},{'id': '155', 'type': 'keyword_argument', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'xline'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'xline'},{'id': '158', 'type': 'keyword_argument', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'endian'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'endian'},{'id': '161', 'type': 'try_statement', 'children': ['162', '215']},{'id': '162', 'type': 'block', 'children': ['163', '179', '193', '199']},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'dt'},{'id': '166', 'type': 'binary_operator', 'children': ['167', '178'], 'value': '/'},{'id': '167', 'type': 'call', 'children': ['168', '173']},{'id': '168', 'type': 'attribute', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'segyio'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'tools'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'dt'},{'id': '173', 'type': 'argument_list', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '175', 'type': 'keyword_argument', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'fallback_dt'},{'id': '177', 'type': 'float', 'children': [], 'value': '4000.0'},{'id': '178', 'type': 'float', 'children': [], 'value': '1000.0'},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'assignment', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 't0'},{'id': '182', 'type': 'subscript', 'children': ['183', '188']},{'id': '183', 'type': 'subscript', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '187', 'type': 'integer', 'children': [], 'value': '0'},{'id': '188', 'type': 'attribute', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'segyio'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'TraceField'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'DelayRecordingTime'},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'assignment', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'samples'},{'id': '196', 'type': 'subscript', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'metrics'},{'id': '198', 'type': 'string', 'children': [], 'value': "'samplecount'"},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'assignment', 'children': ['201', '204']},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '203', 'type': 'identifier', 'children': [], 'value': '_samples'},{'id': '204', 'type': 'binary_operator', 'children': ['205', '214'], 'value': '+'},{'id': '205', 'type': '()', 'children': ['206']},{'id': '206', 'type': 'binary_operator', 'children': ['207', '213'], 'value': '*'},{'id': '207', 'type': 'call', 'children': ['208', '211']},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'arange'},{'id': '211', 'type': 'argument_list', 'children': ['212']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'samples'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'dt'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 't0'},{'id': '215', 'type': 'except_clause', 'children': ['216']},{'id': '216', 'type': 'block', 'children': ['217', '223']},{'id': '217', 'type': 'expression_statement', 'children': ['218']},{'id': '218', 'type': 'call', 'children': ['219', '222']},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '222', 'type': 'argument_list', 'children': []},{'id': '223', 'type': 'raise_statement', 'children': []},{'id': '224', 'type': 'if_statement', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'ignore_geometry'},{'id': '226', 'type': 'block', 'children': ['227']},{'id': '227', 'type': 'return_statement', 'children': ['228']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '229', 'type': 'return_statement', 'children': ['230']},{'id': '230', 'type': 'call', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'infer_geometry'},{'id': '232', 'type': 'argument_list', 'children': ['233', '234', '235', '236', '237']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'metrics'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'iline'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'xline'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'strict'}
def open(filename, mode="r", iline = 189, xline = 193, strict = True, ignore_geometry = False, endian = 'big'): if 'w' in mode: problem = 'w in mode would truncate the file' solution = 'use r+ to open in read-write' raise ValueError(', '.join((problem, solution))) endians = { 'little': 256, 'lsb': 256, 'big': 0, 'msb': 0, } if endian not in endians: problem = 'unknown endianness {}, expected one of: ' opts = ' '.join(endians.keys()) raise ValueError(problem.format(endian) + opts) from . import _segyio fd = _segyio.segyiofd(str(filename), mode, endians[endian]) fd.segyopen() metrics = fd.metrics() f = segyio.SegyFile(fd, filename = str(filename), mode = mode, iline = iline, xline = xline, endian = endian, ) try: dt = segyio.tools.dt(f, fallback_dt = 4000.0) / 1000.0 t0 = f.header[0][segyio.TraceField.DelayRecordingTime] samples = metrics['samplecount'] f._samples = (numpy.arange(samples) * dt) + t0 except: f.close() raise if ignore_geometry: return f return infer_geometry(f, metrics, iline, xline, strict)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'calc_min_interval'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'alpha'},{'id': '6', 'type': 'block', 'children': ['7', '14', '20', '34', '40', '54', '71', '80', '86', '94']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'cred_mass'},{'id': '17', 'type': 'binary_operator', 'children': ['18', '19'], 'value': '-'},{'id': '18', 'type': 'float', 'children': [], 'value': '1.0'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'alpha'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'interval_idx_inc'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'floor'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'binary_operator', 'children': ['32', '33'], 'value': '*'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'cred_mass'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'n_intervals'},{'id': '37', 'type': 'binary_operator', 'children': ['38', '39'], 'value': '-'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'interval_idx_inc'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'interval_width'},{'id': '43', 'type': 'binary_operator', 'children': ['44', '49'], 'value': '-'},{'id': '44', 'type': 'subscript', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '46', 'type': 'slice', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'interval_idx_inc'},{'id': '48', 'type': 'colon', 'children': []},{'id': '49', 'type': 'subscript', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '51', 'type': 'slice', 'children': ['52', '53']},{'id': '52', 'type': 'colon', 'children': []},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'n_intervals'},{'id': '54', 'type': 'if_statement', 'children': ['55', '61']},{'id': '55', 'type': 'comparison_operator', 'children': ['56', '60'], 'value': '=='},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'interval_width'},{'id': '60', 'type': 'integer', 'children': [], 'value': '0'},{'id': '61', 'type': 'block', 'children': ['62', '67']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'print_'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'string', 'children': [], 'value': "'Too few elements for interval calculation'"},{'id': '67', 'type': 'return_statement', 'children': ['68']},{'id': '68', 'type': 'list', 'children': ['69', '70'], 'value': '[None, None]'},{'id': '69', 'type': 'None', 'children': []},{'id': '70', 'type': 'None', 'children': []},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'min_idx'},{'id': '74', 'type': 'call', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'argmin'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'interval_width'},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'hdi_min'},{'id': '83', 'type': 'subscript', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'min_idx'},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'hdi_max'},{'id': '89', 'type': 'subscript', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '91', 'type': 'binary_operator', 'children': ['92', '93'], 'value': '+'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'min_idx'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'interval_idx_inc'},{'id': '94', 'type': 'return_statement', 'children': ['95']},{'id': '95', 'type': 'list', 'children': ['96', '97'], 'value': '[hdi_min, hdi_max]'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'hdi_min'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'hdi_max'}
def calc_min_interval(x, alpha): n = len(x) cred_mass = 1.0 - alpha interval_idx_inc = int(np.floor(cred_mass * n)) n_intervals = n - interval_idx_inc interval_width = x[interval_idx_inc:] - x[:n_intervals] if len(interval_width) == 0: print_('Too few elements for interval calculation') return [None, None] min_idx = np.argmin(interval_width) hdi_min = x[min_idx] hdi_max = x[min_idx + interval_idx_inc] return [hdi_min, hdi_max]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_compute_gas_price'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'probabilities'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'desired_probability'},{'id': '6', 'type': 'block', 'children': ['7', '13', '20', '48']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'first'},{'id': '10', 'type': 'subscript', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'probabilities'},{'id': '12', 'type': 'integer', 'children': [], 'value': '0'},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'last'},{'id': '16', 'type': 'subscript', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'probabilities'},{'id': '18', 'type': 'unary_operator', 'children': ['19'], 'value': '-'},{'id': '19', 'type': 'integer', 'children': [], 'value': '1'},{'id': '20', 'type': 'if_statement', 'children': ['21', '26', '34']},{'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': '>='},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'desired_probability'},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'first'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'prob'},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'return_statement', 'children': ['28']},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'first'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'gas_price'},{'id': '34', 'type': 'elif_clause', 'children': ['35', '40']},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': '<='},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'desired_probability'},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'last'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'prob'},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'return_statement', 'children': ['42']},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'last'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'gas_price'},{'id': '48', 'type': 'for_statement', 'children': ['49', '52', '57', '132']},{'id': '49', 'type': 'pattern_list', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'left'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'right'},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'sliding_window'},{'id': '54', 'type': 'argument_list', 'children': ['55', '56']},{'id': '55', 'type': 'integer', 'children': [], 'value': '2'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'probabilities'},{'id': '57', 'type': 'block', 'children': ['58', '78', '86', '96', '102', '112', '130']},{'id': '58', 'type': 'if_statement', 'children': ['59', '64', '66']},{'id': '59', 'type': 'comparison_operator', 'children': ['60', '61'], 'value': '<'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'desired_probability'},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'right'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'prob'},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'continue_statement', 'children': []},{'id': '66', 'type': 'elif_clause', 'children': ['67', '72']},{'id': '67', 'type': 'comparison_operator', 'children': ['68', '69'], 'value': '>'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'desired_probability'},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'left'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'prob'},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'raise_statement', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'string', 'children': [], 'value': "'Invariant'"},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'adj_prob'},{'id': '81', 'type': 'binary_operator', 'children': ['82', '83'], 'value': '-'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'desired_probability'},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'right'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'prob'},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'window_size'},{'id': '89', 'type': 'binary_operator', 'children': ['90', '93'], 'value': '-'},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'left'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'prob'},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'right'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'prob'},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '99', 'type': 'binary_operator', 'children': ['100', '101'], 'value': '/'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'adj_prob'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'window_size'},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'gas_window_size'},{'id': '105', 'type': 'binary_operator', 'children': ['106', '109'], 'value': '-'},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'left'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'gas_price'},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'right'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'gas_price'},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'gas_price'},{'id': '115', 'type': 'call', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '117', 'type': 'argument_list', 'children': ['118']},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'math'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'ceil'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'binary_operator', 'children': ['124', '127'], 'value': '+'},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'right'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'gas_price'},{'id': '127', 'type': 'binary_operator', 'children': ['128', '129'], 'value': '*'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'gas_window_size'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '130', 'type': 'return_statement', 'children': ['131']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'gas_price'},{'id': '132', 'type': 'else_clause', 'children': ['133']},{'id': '133', 'type': 'block', 'children': ['134']},{'id': '134', 'type': 'raise_statement', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'string', 'children': [], 'value': "'Invariant'"}
def _compute_gas_price(probabilities, desired_probability): first = probabilities[0] last = probabilities[-1] if desired_probability >= first.prob: return int(first.gas_price) elif desired_probability <= last.prob: return int(last.gas_price) for left, right in sliding_window(2, probabilities): if desired_probability < right.prob: continue elif desired_probability > left.prob: raise Exception('Invariant') adj_prob = desired_probability - right.prob window_size = left.prob - right.prob position = adj_prob / window_size gas_window_size = left.gas_price - right.gas_price gas_price = int(math.ceil(right.gas_price + gas_window_size * position)) return gas_price else: raise Exception('Invariant')
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'generate_X_grid'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '8', 'type': 'integer', 'children': [], 'value': '100'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'meshgrid'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '24', '38']},{'id': '13', 'type': 'if_statement', 'children': ['14', '18']},{'id': '14', 'type': 'not_operator', 'children': ['15']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': '_is_fitted'},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'raise_statement', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'string', 'children': [], 'value': "'GAM has not been fitted. Call fit first.'"},{'id': '24', 'type': 'if_statement', 'children': ['25', '32']},{'id': '25', 'type': 'attribute', 'children': ['26', '31']},{'id': '26', 'type': 'subscript', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'terms'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'isintercept'},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'raise_statement', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'string', 'children': [], 'value': "'cannot create grid for intercept term'"},{'id': '38', 'type': 'if_statement', 'children': ['39', '46', '116', '221']},{'id': '39', 'type': 'attribute', 'children': ['40', '45']},{'id': '40', 'type': 'subscript', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'terms'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'istensor'},{'id': '46', 'type': 'block', 'children': ['47', '51', '83', '96']},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'Xs'},{'id': '50', 'type': 'list', 'children': [], 'value': '[]'},{'id': '51', 'type': 'for_statement', 'children': ['52', '53', '58']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'term_'},{'id': '53', 'type': 'subscript', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'terms'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '58', 'type': 'block', 'children': ['59']},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'Xs'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'linspace'},{'id': '69', 'type': 'argument_list', 'children': ['70', '75', '80']},{'id': '70', 'type': 'subscript', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'term_'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'edge_knots_'},{'id': '74', 'type': 'integer', 'children': [], 'value': '0'},{'id': '75', 'type': 'subscript', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'term_'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'edge_knots_'},{'id': '79', 'type': 'integer', 'children': [], 'value': '1'},{'id': '80', 'type': 'keyword_argument', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'num'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'Xs'},{'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': 'meshgrid'},{'id': '90', 'type': 'argument_list', 'children': ['91', '93']},{'id': '91', 'type': 'list_splat', 'children': ['92']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'Xs'},{'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'indexing'},{'id': '95', 'type': 'string', 'children': [], 'value': "'ij'"},{'id': '96', 'type': 'if_statement', 'children': ['97', '98', '104']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'meshgrid'},{'id': '98', 'type': 'block', 'children': ['99']},{'id': '99', 'type': 'return_statement', 'children': ['100']},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'Xs'},{'id': '104', 'type': 'else_clause', 'children': ['105']},{'id': '105', 'type': 'block', 'children': ['106']},{'id': '106', 'type': 'return_statement', 'children': ['107']},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '110', 'type': 'identifier', 'children': [], 'value': '_flatten_mesh'},{'id': '111', 'type': 'argument_list', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'Xs'},{'id': '113', 'type': 'keyword_argument', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '116', 'type': 'elif_clause', 'children': ['117', '126']},{'id': '117', 'type': 'call', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '119', 'type': 'argument_list', 'children': ['120', '125']},{'id': '120', 'type': 'subscript', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'terms'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '125', 'type': 'string', 'children': [], 'value': "'edge_knots_'"},{'id': '126', 'type': 'block', 'children': ['127', '156', '162', '177', '191', '219']},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '130', 'type': 'call', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'linspace'},{'id': '134', 'type': 'argument_list', 'children': ['135', '144', '153']},{'id': '135', 'type': 'subscript', 'children': ['136', '143']},{'id': '136', 'type': 'attribute', 'children': ['137', '142']},{'id': '137', 'type': 'subscript', 'children': ['138', '141']},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'terms'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'edge_knots_'},{'id': '143', 'type': 'integer', 'children': [], 'value': '0'},{'id': '144', 'type': 'subscript', 'children': ['145', '152']},{'id': '145', 'type': 'attribute', 'children': ['146', '151']},{'id': '146', 'type': 'subscript', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'terms'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'edge_knots_'},{'id': '152', 'type': 'integer', 'children': [], 'value': '1'},{'id': '153', 'type': 'keyword_argument', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'num'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '156', 'type': 'if_statement', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'meshgrid'},{'id': '158', 'type': 'block', 'children': ['159']},{'id': '159', 'type': 'return_statement', 'children': ['160']},{'id': '160', 'type': 'tuple', 'children': ['161']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'assignment', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '165', 'type': 'call', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'zeros'},{'id': '169', 'type': 'argument_list', 'children': ['170']},{'id': '170', 'type': 'tuple', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '172', 'type': 'subscript', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'statistics_'},{'id': '176', 'type': 'string', 'children': [], 'value': "'m_features'"},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '190']},{'id': '179', 'type': 'subscript', 'children': ['180', '181', '183']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '181', 'type': 'slice', 'children': ['182']},{'id': '182', 'type': 'colon', 'children': []},{'id': '183', 'type': 'attribute', 'children': ['184', '189']},{'id': '184', 'type': 'subscript', 'children': ['185', '188']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'terms'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '191', 'type': 'if_statement', 'children': ['192', '204']},{'id': '192', 'type': 'comparison_operator', 'children': ['193', '203'], 'value': 'is'},{'id': '193', 'type': 'call', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '195', 'type': 'argument_list', 'children': ['196', '201', '202']},{'id': '196', 'type': 'subscript', 'children': ['197', '200']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'terms'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '201', 'type': 'string', 'children': [], 'value': "'by'"},{'id': '202', 'type': 'None', 'children': []},{'id': '203', 'type': 'None', 'children': []},{'id': '204', 'type': 'block', 'children': ['205']},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'assignment', 'children': ['207', '218']},{'id': '207', 'type': 'subscript', 'children': ['208', '209', '211']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '209', 'type': 'slice', 'children': ['210']},{'id': '210', 'type': 'colon', 'children': []},{'id': '211', 'type': 'attribute', 'children': ['212', '217']},{'id': '212', 'type': 'subscript', 'children': ['213', '216']},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'terms'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'by'},{'id': '218', 'type': 'float', 'children': [], 'value': '1.'},{'id': '219', 'type': 'return_statement', 'children': ['220']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '221', 'type': 'else_clause', 'children': ['222']},{'id': '222', 'type': 'block', 'children': ['223']},{'id': '223', 'type': 'raise_statement', 'children': ['224']},{'id': '224', 'type': 'call', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '226', 'type': 'argument_list', 'children': ['227']},{'id': '227', 'type': 'call', 'children': ['228', '231']},{'id': '228', 'type': 'attribute', 'children': ['229', '230']},{'id': '229', 'type': 'string', 'children': [], 'value': "'Unexpected term type: {}'"},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '231', 'type': 'argument_list', 'children': ['232']},{'id': '232', 'type': 'subscript', 'children': ['233', '236']},{'id': '233', 'type': 'attribute', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'terms'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'term'}
def generate_X_grid(self, term, n=100, meshgrid=False): if not self._is_fitted: raise AttributeError('GAM has not been fitted. Call fit first.') if self.terms[term].isintercept: raise ValueError('cannot create grid for intercept term') if self.terms[term].istensor: Xs = [] for term_ in self.terms[term]: Xs.append(np.linspace(term_.edge_knots_[0], term_.edge_knots_[1], num=n)) Xs = np.meshgrid(*Xs, indexing='ij') if meshgrid: return tuple(Xs) else: return self._flatten_mesh(Xs, term=term) elif hasattr(self.terms[term], 'edge_knots_'): x = np.linspace(self.terms[term].edge_knots_[0], self.terms[term].edge_knots_[1], num=n) if meshgrid: return (x,) X = np.zeros((n, self.statistics_['m_features'])) X[:, self.terms[term].feature] = x if getattr(self.terms[term], 'by', None) is not None: X[:, self.terms[term].by] = 1. return X else: raise TypeError('Unexpected term type: {}'.format(self.terms[term]))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'build_from_info'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '6', 'type': 'block', 'children': ['7', '11', '29']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'terms'},{'id': '10', 'type': 'list', 'children': [], 'value': '[]'},{'id': '11', 'type': 'for_statement', 'children': ['12', '13', '16']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'term_info'},{'id': '13', 'type': 'subscript', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '15', 'type': 'string', 'children': [], 'value': "'terms'"},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'terms'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'SplineTerm'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'build_from_info'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'term_info'},{'id': '29', 'type': 'return_statement', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'list_splat', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'terms'}
def build_from_info(cls, info): terms = [] for term_info in info['terms']: terms.append(SplineTerm.build_from_info(term_info)) return cls(*terms)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_kate_imports'},{'id': '3', 'type': 'parameters', 'children': ['4', '7']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'add_imports'},{'id': '6', 'type': 'tuple', 'children': []},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'remove_imports'},{'id': '9', 'type': 'tuple', 'children': []},{'id': '10', 'type': 'block', 'children': ['11', '19', '27', '35', '43', '90', '99', '114', '178']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'document'},{'id': '14', 'type': 'call', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'kate'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'activeDocument'},{'id': '18', 'type': 'argument_list', 'children': []},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'view'},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'document'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'activeView'},{'id': '26', 'type': 'argument_list', 'children': []},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'view'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'cursorPosition'},{'id': '34', 'type': 'argument_list', 'children': []},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'selection'},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'view'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'selectionRange'},{'id': '42', 'type': 'argument_list', 'children': []},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'sorter'},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'SortImports'},{'id': '48', 'type': 'argument_list', 'children': ['49', '56', '59', '62']},{'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'file_contents'},{'id': '51', 'type': 'call', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'document'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '55', 'type': 'argument_list', 'children': []},{'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'add_imports'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'add_imports'},{'id': '59', 'type': 'keyword_argument', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'remove_imports'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'remove_imports'},{'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'settings_path'},{'id': '64', 'type': 'call', 'children': ['65', '70']},{'id': '65', 'type': 'attribute', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'dirname'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'call', 'children': ['72', '77']},{'id': '72', 'type': 'attribute', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'abspath'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '89']},{'id': '82', 'type': 'attribute', 'children': ['83', '88']},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'document'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '87', 'type': 'argument_list', 'children': []},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '89', 'type': 'argument_list', 'children': []},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'document'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'setText'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'sorter'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'call', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'setLine'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'binary_operator', 'children': ['106', '111'], 'value': '+'},{'id': '106', 'type': 'call', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '110', 'type': 'argument_list', 'children': []},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'sorter'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'length_change'},{'id': '114', 'type': 'if_statement', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'selection'},{'id': '116', 'type': 'block', 'children': ['117', '125', '140', '148', '163', '171']},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '120', 'type': 'call', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'selection'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '124', 'type': 'argument_list', 'children': []},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'call', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'setLine'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'binary_operator', 'children': ['132', '137'], 'value': '+'},{'id': '132', 'type': 'call', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '136', 'type': 'argument_list', 'children': []},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'sorter'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'length_change'},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'assignment', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '143', 'type': 'call', 'children': ['144', '147']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'selection'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '147', 'type': 'argument_list', 'children': []},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'call', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'setLine'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'binary_operator', 'children': ['155', '160'], 'value': '+'},{'id': '155', 'type': 'call', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '159', 'type': 'argument_list', 'children': []},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'sorter'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'length_change'},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'call', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'selection'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'setRange'},{'id': '168', 'type': 'argument_list', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'call', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'view'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'setSelection'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'selection'},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'call', 'children': ['180', '183']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'view'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'setCursorPosition'},{'id': '183', 'type': 'argument_list', 'children': ['184']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'position'}
def sort_kate_imports(add_imports=(), remove_imports=()): document = kate.activeDocument() view = document.activeView() position = view.cursorPosition() selection = view.selectionRange() sorter = SortImports(file_contents=document.text(), add_imports=add_imports, remove_imports=remove_imports, settings_path=os.path.dirname(os.path.abspath(str(document.url().path())))) document.setText(sorter.output) position.setLine(position.line() + sorter.length_change) if selection: start = selection.start() start.setLine(start.line() + sorter.length_change) end = selection.end() end.setLine(end.line() + sorter.length_change) selection.setRange(start, end) view.setSelection(selection) view.setCursorPosition(position)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_line'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'type', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '7', 'type': 'block', 'children': ['8', '18', '24']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '11', 'type': 'subscript', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'in_lines'},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'augmented_assignment', 'children': ['20', '23'], 'value': '+='},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '23', 'type': 'integer', 'children': [], 'value': '1'},{'id': '24', 'type': 'return_statement', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'line'}
def _get_line(self) -> str: line = self.in_lines[self.index] self.index += 1 return line
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '22', '24']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_add_comments'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '17']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'comments'},{'id': '7', 'type': 'type', 'children': ['8']},{'id': '8', 'type': 'generic_type', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'Optional'},{'id': '10', 'type': 'type_parameter', 'children': ['11']},{'id': '11', 'type': 'type', 'children': ['12']},{'id': '12', 'type': 'generic_type', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'Sequence'},{'id': '14', 'type': 'type_parameter', 'children': ['15']},{'id': '15', 'type': 'type', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '17', 'type': 'typed_default_parameter', 'children': ['18', '19', '21']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'original_string'},{'id': '19', 'type': 'type', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '21', 'type': 'string', 'children': [], 'value': '""'},{'id': '22', 'type': 'type', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '24', 'type': 'block', 'children': ['25', '41']},{'id': '25', 'type': 'if_statement', 'children': ['26', '31']},{'id': '26', 'type': 'subscript', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '30', 'type': 'string', 'children': [], 'value': "'ignore_comments'"},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'return_statement', 'children': ['33']},{'id': '33', 'type': 'subscript', 'children': ['34', '40']},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': '_strip_comments'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'original_string'},{'id': '40', 'type': 'integer', 'children': [], 'value': '0'},{'id': '41', 'type': 'if_statement', 'children': ['42', '44', '47']},{'id': '42', 'type': 'not_operator', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'comments'},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'return_statement', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'original_string'},{'id': '47', 'type': 'else_clause', 'children': ['48']},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'return_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'string', 'children': [], 'value': '"{0}{1} {2}"'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '54', 'type': 'argument_list', 'children': ['55', '63', '68']},{'id': '55', 'type': 'subscript', 'children': ['56', '62']},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '59', 'type': 'identifier', 'children': [], 'value': '_strip_comments'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'original_string'},{'id': '62', 'type': 'integer', 'children': [], 'value': '0'},{'id': '63', 'type': 'subscript', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '67', 'type': 'string', 'children': [], 'value': "'comment_prefix'"},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'string', 'children': [], 'value': '"; "'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'comments'}
def _add_comments( self, comments: Optional[Sequence[str]], original_string: str = "" ) -> str: if self.config['ignore_comments']: return self._strip_comments(original_string)[0] if not comments: return original_string else: return "{0}{1} {2}".format(self._strip_comments(original_string)[0], self.config['comment_prefix'], "; ".join(comments))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_wrap'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '7', 'type': 'type', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '9', 'type': 'type', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '11', 'type': 'block', 'children': ['12', '20', '370']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'wrap_mode'},{'id': '15', 'type': 'subscript', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '19', 'type': 'string', 'children': [], 'value': "'multi_line_output'"},{'id': '20', 'type': 'if_statement', 'children': ['21', '37', '333']},{'id': '21', 'type': 'boolean_operator', 'children': ['22', '32'], 'value': 'and'},{'id': '22', 'type': 'comparison_operator', 'children': ['23', '27'], 'value': '>'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '27', 'type': 'subscript', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '31', 'type': 'string', 'children': [], 'value': "'line_length'"},{'id': '32', 'type': 'comparison_operator', 'children': ['33', '34'], 'value': '!='},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'wrap_mode'},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'WrapModes'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'NOQA'},{'id': '37', 'type': 'block', 'children': ['38', '42', '46']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'line_without_comment'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'comment'},{'id': '45', 'type': 'None', 'children': []},{'id': '46', 'type': 'if_statement', 'children': ['47', '56']},{'id': '47', 'type': 'comparison_operator', 'children': ['48', '49', '52'], 'value': 'in'},{'id': '48', 'type': 'string', 'children': [], 'value': "'\n line_without_comment, comment = line.split('"},{'id': '49', 'type': 'ERROR', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'for'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'splitter'},{'id': '52', 'type': 'tuple', 'children': ['53', '54', '55']},{'id': '53', 'type': 'string', 'children': [], 'value': '"import "'},{'id': '54', 'type': 'string', 'children': [], 'value': '"."'},{'id': '55', 'type': 'string', 'children': [], 'value': '"as "'},{'id': '56', 'type': 'block', 'children': ['57', '70']},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'exp'},{'id': '60', 'type': 'binary_operator', 'children': ['61', '69'], 'value': '+'},{'id': '61', 'type': 'binary_operator', 'children': ['62', '63'], 'value': '+'},{'id': '62', 'type': 'string', 'children': [], 'value': 'r"\\b"'},{'id': '63', 'type': 'call', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'escape'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'splitter'},{'id': '69', 'type': 'string', 'children': [], 'value': 'r"\\b"'},{'id': '70', 'type': 'if_statement', 'children': ['71', '90']},{'id': '71', 'type': 'boolean_operator', 'children': ['72', '79'], 'value': 'and'},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '76', 'type': 'argument_list', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'exp'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'line_without_comment'},{'id': '79', 'type': 'not_operator', 'children': ['80']},{'id': '80', 'type': 'call', 'children': ['81', '88']},{'id': '81', 'type': 'attribute', 'children': ['82', '87']},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'line_without_comment'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '86', 'type': 'argument_list', 'children': []},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'splitter'},{'id': '90', 'type': 'block', 'children': ['91', '101', '115', '159', '171', '195', '321']},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'line_parts'},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '98', 'type': 'argument_list', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'exp'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'line_without_comment'},{'id': '101', 'type': 'if_statement', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'comment'},{'id': '103', 'type': 'block', 'children': ['104']},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '110', '114']},{'id': '106', 'type': 'subscript', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'line_parts'},{'id': '108', 'type': 'unary_operator', 'children': ['109'], 'value': '-'},{'id': '109', 'type': 'integer', 'children': [], 'value': '1'},{'id': '110', 'type': 'ERROR', 'children': ['111', '113']},{'id': '111', 'type': 'interpolation', 'children': ['112']},{'id': '112', 'type': 'integer', 'children': [], 'value': '0'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'next_line'},{'id': '114', 'type': 'list', 'children': [], 'value': '[]'},{'id': '115', 'type': 'while_statement', 'children': ['116', '138']},{'id': '116', 'type': 'boolean_operator', 'children': ['117', '137'], 'value': 'and'},{'id': '117', 'type': 'comparison_operator', 'children': ['118', '125'], 'value': '>'},{'id': '118', 'type': '()', 'children': ['119']},{'id': '119', 'type': 'binary_operator', 'children': ['120', '124'], 'value': '+'},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '124', 'type': 'integer', 'children': [], 'value': '2'},{'id': '125', 'type': '()', 'children': ['126']},{'id': '126', 'type': 'boolean_operator', 'children': ['127', '132'], 'value': 'or'},{'id': '127', 'type': 'subscript', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '131', 'type': 'string', 'children': [], 'value': "'wrap_length'"},{'id': '132', 'type': 'subscript', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '136', 'type': 'string', 'children': [], 'value': "'line_length'"},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'line_parts'},{'id': '138', 'type': 'block', 'children': ['139', '150']},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'call', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'next_line'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'call', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'line_parts'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '149', 'type': 'argument_list', 'children': []},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '153', 'type': 'call', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'splitter'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'line_parts'},{'id': '159', 'type': 'if_statement', 'children': ['160', '162']},{'id': '160', 'type': 'not_operator', 'children': ['161']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '162', 'type': 'block', 'children': ['163']},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '166', 'type': 'call', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'next_line'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '170', 'type': 'argument_list', 'children': []},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'assignment', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'cont_line'},{'id': '174', 'type': 'call', 'children': ['175', '178']},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '177', 'type': 'identifier', 'children': [], 'value': '_wrap'},{'id': '178', 'type': 'argument_list', 'children': ['179']},{'id': '179', 'type': 'binary_operator', 'children': ['180', '185'], 'value': '+'},{'id': '180', 'type': 'subscript', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '184', 'type': 'string', 'children': [], 'value': "'indent'"},{'id': '185', 'type': 'call', 'children': ['186', '194']},{'id': '186', 'type': 'attribute', 'children': ['187', '193']},{'id': '187', 'type': 'call', 'children': ['188', '191']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'splitter'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '191', 'type': 'argument_list', 'children': ['192']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'next_line'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'lstrip'},{'id': '194', 'type': 'argument_list', 'children': []},{'id': '195', 'type': 'if_statement', 'children': ['196', '201']},{'id': '196', 'type': 'subscript', 'children': ['197', '200']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '200', 'type': 'string', 'children': [], 'value': "'use_parentheses'"},{'id': '201', 'type': 'block', 'children': ['202', '238', '249', '312']},{'id': '202', 'type': 'expression_statement', 'children': ['203']},{'id': '203', 'type': 'assignment', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '205', 'type': 'call', 'children': ['206', '209']},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'string', 'children': [], 'value': '"{0}{1}({2}{3}{4}{5})"'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '209', 'type': 'argument_list', 'children': ['210', '211', '212', '215', '216', '224']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'splitter'},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'line_separator'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'cont_line'},{'id': '216', 'type': 'conditional_expression', 'children': ['217', '218', '223'], 'value': 'if'},{'id': '217', 'type': 'string', 'children': [], 'value': '","'},{'id': '218', 'type': 'subscript', 'children': ['219', '222']},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '222', 'type': 'string', 'children': [], 'value': "'include_trailing_comma'"},{'id': '223', 'type': 'string', 'children': [], 'value': '""'},{'id': '224', 'type': 'conditional_expression', 'children': ['225', '228', '237'], 'value': 'if'},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'line_separator'},{'id': '228', 'type': 'comparison_operator', 'children': ['229', '230'], 'value': 'in'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'wrap_mode'},{'id': '230', 'type': 'set', 'children': ['231', '234']},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'WrapModes'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'VERTICAL_HANGING_INDENT'},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'WrapModes'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'VERTICAL_GRID_GROUPED'},{'id': '237', 'type': 'string', 'children': [], 'value': '""'},{'id': '238', 'type': 'expression_statement', 'children': ['239']},{'id': '239', 'type': 'assignment', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '241', 'type': 'call', 'children': ['242', '245']},{'id': '242', 'type': 'attribute', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '245', 'type': 'argument_list', 'children': ['246']},{'id': '246', 'type': 'attribute', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'line_separator'},{'id': '249', 'type': 'if_statement', 'children': ['250', '270']},{'id': '250', 'type': 'boolean_operator', 'children': ['251', '261'], 'value': 'and'},{'id': '251', 'type': 'comparison_operator', 'children': ['252', '257'], 'value': 'in'},{'id': '252', 'type': 'subscript', 'children': ['253', '256']},{'id': '253', 'type': 'attribute', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '256', 'type': 'string', 'children': [], 'value': "'comment_prefix'"},{'id': '257', 'type': 'subscript', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '259', 'type': 'unary_operator', 'children': ['260'], 'value': '-'},{'id': '260', 'type': 'integer', 'children': [], 'value': '1'},{'id': '261', 'type': 'call', 'children': ['262', '268']},{'id': '262', 'type': 'attribute', 'children': ['263', '267']},{'id': '263', 'type': 'subscript', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '265', 'type': 'unary_operator', 'children': ['266'], 'value': '-'},{'id': '266', 'type': 'integer', 'children': [], 'value': '1'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '268', 'type': 'argument_list', 'children': ['269']},{'id': '269', 'type': 'string', 'children': [], 'value': "')'"},{'id': '270', 'type': 'block', 'children': ['271', '290']},{'id': '271', 'type': 'expression_statement', 'children': ['272']},{'id': '272', 'type': 'assignment', 'children': ['273', '276']},{'id': '273', 'type': 'pattern_list', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'comment'},{'id': '276', 'type': 'call', 'children': ['277', '283']},{'id': '277', 'type': 'attribute', 'children': ['278', '282']},{'id': '278', 'type': 'subscript', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '280', 'type': 'unary_operator', 'children': ['281'], 'value': '-'},{'id': '281', 'type': 'integer', 'children': [], 'value': '1'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '283', 'type': 'argument_list', 'children': ['284', '289']},{'id': '284', 'type': 'subscript', 'children': ['285', '288']},{'id': '285', 'type': 'attribute', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '288', 'type': 'string', 'children': [], 'value': "'comment_prefix'"},{'id': '289', 'type': 'integer', 'children': [], 'value': '1'},{'id': '290', 'type': 'expression_statement', 'children': ['291']},{'id': '291', 'type': 'assignment', 'children': ['292', '296']},{'id': '292', 'type': 'subscript', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '294', 'type': 'unary_operator', 'children': ['295'], 'value': '-'},{'id': '295', 'type': 'integer', 'children': [], 'value': '1'},{'id': '296', 'type': 'binary_operator', 'children': ['297', '306'], 'value': '+'},{'id': '297', 'type': 'binary_operator', 'children': ['298', '301'], 'value': '+'},{'id': '298', 'type': 'binary_operator', 'children': ['299', '300'], 'value': '+'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '300', 'type': 'string', 'children': [], 'value': "')'"},{'id': '301', 'type': 'subscript', 'children': ['302', '305']},{'id': '302', 'type': 'attribute', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '305', 'type': 'string', 'children': [], 'value': "'comment_prefix'"},{'id': '306', 'type': 'subscript', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'comment'},{'id': '308', 'type': 'slice', 'children': ['309', '310']},{'id': '309', 'type': 'colon', 'children': []},{'id': '310', 'type': 'unary_operator', 'children': ['311'], 'value': '-'},{'id': '311', 'type': 'integer', 'children': [], 'value': '1'},{'id': '312', 'type': 'return_statement', 'children': ['313']},{'id': '313', 'type': 'call', 'children': ['314', '319']},{'id': '314', 'type': 'attribute', 'children': ['315', '318']},{'id': '315', 'type': 'attribute', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'line_separator'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '319', 'type': 'argument_list', 'children': ['320']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '321', 'type': 'return_statement', 'children': ['322']},{'id': '322', 'type': 'call', 'children': ['323', '326']},{'id': '323', 'type': 'attribute', 'children': ['324', '325']},{'id': '324', 'type': 'string', 'children': [], 'value': '"{0}{1}\\\\{2}{3}"'},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '326', 'type': 'argument_list', 'children': ['327', '328', '329', '332']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'splitter'},{'id': '329', 'type': 'attribute', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'line_separator'},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'cont_line'},{'id': '333', 'type': 'elif_clause', 'children': ['334', '352', '369']},{'id': '334', 'type': 'boolean_operator', 'children': ['335', '345'], 'value': 'and'},{'id': '335', 'type': 'comparison_operator', 'children': ['336', '340'], 'value': '>'},{'id': '336', 'type': 'call', 'children': ['337', '338']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '338', 'type': 'argument_list', 'children': ['339']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '340', 'type': 'subscript', 'children': ['341', '344']},{'id': '341', 'type': 'attribute', 'children': ['342', '343']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '344', 'type': 'string', 'children': [], 'value': "'line_length'"},{'id': '345', 'type': 'comparison_operator', 'children': ['346', '347'], 'value': '=='},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'wrap_mode'},{'id': '347', 'type': 'attribute', 'children': ['348', '351']},{'id': '348', 'type': 'attribute', 'children': ['349', '350']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'WrapModes'},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'NOQA'},{'id': '352', 'type': 'ERROR', 'children': ['353', '360']},{'id': '353', 'type': 'ERROR', 'children': ['354', '355', '357', '359']},{'id': '354', 'type': 'string', 'children': [], 'value': '"\n return "'},{'id': '355', 'type': 'set', 'children': ['356']},{'id': '356', 'type': 'integer', 'children': [], 'value': '0'},{'id': '357', 'type': 'set', 'children': ['358']},{'id': '358', 'type': 'integer', 'children': [], 'value': '1'},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'NOQA'},{'id': '360', 'type': 'call', 'children': ['361', '362']},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '362', 'type': 'argument_list', 'children': ['363', '364']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '364', 'type': 'subscript', 'children': ['365', '368']},{'id': '365', 'type': 'attribute', 'children': ['366', '367']},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '368', 'type': 'string', 'children': [], 'value': "'comment_prefix'"},{'id': '369', 'type': 'block', 'children': [], 'value': ''},{'id': '370', 'type': 'return_statement', 'children': ['371']},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'line'}
def _wrap(self, line: str) -> str: wrap_mode = self.config['multi_line_output'] if len(line) > self.config['line_length'] and wrap_mode != WrapModes.NOQA: line_without_comment = line comment = None if ' line_without_comment, comment = line.split(' for splitter in ("import ", ".", "as "): exp = r"\b" + re.escape(splitter) + r"\b" if re.search(exp, line_without_comment) and not line_without_comment.strip().startswith(splitter): line_parts = re.split(exp, line_without_comment) if comment: line_parts[-1] = '{0} next_line = [] while (len(line) + 2) > (self.config['wrap_length'] or self.config['line_length']) and line_parts: next_line.append(line_parts.pop()) line = splitter.join(line_parts) if not line: line = next_line.pop() cont_line = self._wrap(self.config['indent'] + splitter.join(next_line).lstrip()) if self.config['use_parentheses']: output = "{0}{1}({2}{3}{4}{5})".format( line, splitter, self.line_separator, cont_line, "," if self.config['include_trailing_comma'] else "", self.line_separator if wrap_mode in {WrapModes.VERTICAL_HANGING_INDENT, WrapModes.VERTICAL_GRID_GROUPED} else "") lines = output.split(self.line_separator) if self.config['comment_prefix'] in lines[-1] and lines[-1].endswith(')'): line, comment = lines[-1].split(self.config['comment_prefix'], 1) lines[-1] = line + ')' + self.config['comment_prefix'] + comment[:-1] return self.line_separator.join(lines) return "{0}{1}\\{2}{3}".format(line, splitter, self.line_separator, cont_line) elif len(line) > self.config['line_length'] and wrap_mode == settings.WrapModes.NOQA: if " return "{0}{1} NOQA".format(line, self.config['comment_prefix']) return line
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_formatter'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '5', 'type': 'block', 'children': ['6']},{'id': '6', 'type': 'for_statement', 'children': ['7', '8', '12']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '8', 'type': 'call', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '10', 'type': 'argument_list', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': '_FORMATTERS'},{'id': '12', 'type': 'block', 'children': ['13']},{'id': '13', 'type': 'if_statement', 'children': ['14', '20']},{'id': '14', 'type': 'call', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'return_statement', 'children': ['22']},{'id': '22', 'type': 'subscript', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': '_FORMATTERS'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'k'}
def get_formatter(name): for k in sorted(_FORMATTERS): if k.startswith(name): return _FORMATTERS[k]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'call_once'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '5', 'type': 'block', 'children': ['6', '15', '35', '73', '79', '88', '100']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'argspec'},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'inspect'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'getargspec'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '15', 'type': 'if_statement', 'children': ['16', '27']},{'id': '16', 'type': 'boolean_operator', 'children': ['17', '24'], 'value': 'or'},{'id': '17', 'type': 'boolean_operator', 'children': ['18', '21'], 'value': 'or'},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'argspec'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'argspec'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'varargs'},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'argspec'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'raise_statement', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '31', 'type': 'argument_list', 'children': ['32', '33', '34']},{'id': '32', 'type': 'string', 'children': [], 'value': "'Can only decorate functions with no args'"},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'argspec'},{'id': '35', 'type': 'decorated_definition', 'children': ['36', '43']},{'id': '36', 'type': 'decorator', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'functools'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'wraps'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '43', 'type': 'function_definition', 'children': ['44', '45', '46']},{'id': '44', 'type': 'function_name', 'children': [], 'value': '_wrapper'},{'id': '45', 'type': 'parameters', 'children': []},{'id': '46', 'type': 'block', 'children': ['47', '69']},{'id': '47', 'type': 'if_statement', 'children': ['48', '54']},{'id': '48', 'type': 'not_operator', 'children': ['49']},{'id': '49', 'type': 'call', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': '_wrapper'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'HasRun'},{'id': '53', 'type': 'argument_list', 'children': []},{'id': '54', 'type': 'block', 'children': ['55', '61']},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': '_wrapper'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'MarkAsRun'},{'id': '60', 'type': 'argument_list', 'children': []},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': '_wrapper'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'return_value'},{'id': '66', 'type': 'call', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '68', 'type': 'argument_list', 'children': []},{'id': '69', 'type': 'return_statement', 'children': ['70']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': '_wrapper'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'return_value'},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': '_wrapper'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'has_run'},{'id': '78', 'type': 'False', 'children': []},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': '_wrapper'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'HasRun'},{'id': '84', 'type': 'lambda', 'children': ['85']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': '_wrapper'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'has_run'},{'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': '_wrapper'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'MarkAsRun'},{'id': '93', 'type': 'lambda', 'children': ['94']},{'id': '94', 'type': 'call', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'setattr'},{'id': '96', 'type': 'argument_list', 'children': ['97', '98', '99']},{'id': '97', 'type': 'identifier', 'children': [], 'value': '_wrapper'},{'id': '98', 'type': 'string', 'children': [], 'value': "'has_run'"},{'id': '99', 'type': 'True', 'children': []},{'id': '100', 'type': 'return_statement', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': '_wrapper'}
def call_once(func): argspec = inspect.getargspec(func) if argspec.args or argspec.varargs or argspec.keywords: raise ValueError('Can only decorate functions with no args', func, argspec) @functools.wraps(func) def _wrapper(): if not _wrapper.HasRun(): _wrapper.MarkAsRun() _wrapper.return_value = func() return _wrapper.return_value _wrapper.has_run = False _wrapper.HasRun = lambda: _wrapper.has_run _wrapper.MarkAsRun = lambda: setattr(_wrapper, 'has_run', True) return _wrapper
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'paginate'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'model_class'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'page_num'},{'id': '9', 'type': 'integer', 'children': [], 'value': '1'},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '12', 'type': 'integer', 'children': [], 'value': '100'},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'conditions'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'block', 'children': ['20', '22', '32', '47', '73', '82', '86', '95', '101', '109', '119']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'string', 'children': [], 'value': "'''\n Selects records and returns a single page of model instances.\n - `model_class`: the model class matching the query's table,\n or `None` for getting back instances of an ad-hoc model.\n - `order_by`: columns to use for sorting the query (contents of the ORDER BY clause).\n - `page_num`: the page number (1-based), or -1 to get the last page.\n - `page_size`: number of records to return per page.\n - `conditions`: optional SQL conditions (contents of the WHERE clause).\n - `settings`: query settings to send as HTTP GET parameters\n The result is a namedtuple containing `objects` (list), `number_of_objects`,\n `pages_total`, `number` (of the current page), and `page_size`.\n '''"},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '29', 'type': 'argument_list', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'model_class'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'conditions'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'pages_total'},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'ceil'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'binary_operator', 'children': ['42', '43'], 'value': '/'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '47', 'type': 'if_statement', 'children': ['48', '52', '61']},{'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': '=='},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'page_num'},{'id': '50', 'type': 'unary_operator', 'children': ['51'], 'value': '-'},{'id': '51', 'type': 'integer', 'children': [], 'value': '1'},{'id': '52', 'type': 'block', 'children': ['53']},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'page_num'},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '58', 'type': 'argument_list', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'pages_total'},{'id': '60', 'type': 'integer', 'children': [], 'value': '1'},{'id': '61', 'type': 'elif_clause', 'children': ['62', '65']},{'id': '62', 'type': 'comparison_operator', 'children': ['63', '64'], 'value': '<'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'page_num'},{'id': '64', 'type': 'integer', 'children': [], 'value': '1'},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'raise_statement', 'children': ['67']},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'binary_operator', 'children': ['71', '72'], 'value': '%'},{'id': '71', 'type': 'string', 'children': [], 'value': "'Invalid page number: %d'"},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'page_num'},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '76', 'type': 'binary_operator', 'children': ['77', '81'], 'value': '*'},{'id': '77', 'type': '()', 'children': ['78']},{'id': '78', 'type': 'binary_operator', 'children': ['79', '80'], 'value': '-'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'page_num'},{'id': '80', 'type': 'integer', 'children': [], 'value': '1'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '85', 'type': 'string', 'children': [], 'value': "'SELECT * FROM $table'"},{'id': '86', 'type': 'if_statement', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'conditions'},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'augmented_assignment', 'children': ['91', '92'], 'value': '+='},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '92', 'type': 'binary_operator', 'children': ['93', '94'], 'value': '+'},{'id': '93', 'type': 'string', 'children': [], 'value': "' WHERE '"},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'conditions'},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'augmented_assignment', 'children': ['97', '98'], 'value': '+='},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '98', 'type': 'binary_operator', 'children': ['99', '100'], 'value': '%'},{'id': '99', 'type': 'string', 'children': [], 'value': "' ORDER BY %s'"},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'augmented_assignment', 'children': ['103', '104'], 'value': '+='},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '104', 'type': 'binary_operator', 'children': ['105', '106'], 'value': '%'},{'id': '105', 'type': 'string', 'children': [], 'value': "' LIMIT %d, %d'"},{'id': '106', 'type': 'tuple', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '112', 'type': 'call', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '115', 'type': 'identifier', 'children': [], 'value': '_substitute'},{'id': '116', 'type': 'argument_list', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'model_class'},{'id': '119', 'type': 'return_statement', 'children': ['120']},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'Page'},{'id': '122', 'type': 'argument_list', 'children': ['123', '139', '142', '145', '148']},{'id': '123', 'type': 'keyword_argument', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '125', 'type': 'conditional_expression', 'children': ['126', '137', '138'], 'value': 'if'},{'id': '126', 'type': 'call', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'call', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'select'},{'id': '133', 'type': 'argument_list', 'children': ['134', '135', '136']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'model_class'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '138', 'type': 'list', 'children': [], 'value': '[]'},{'id': '139', 'type': 'keyword_argument', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'number_of_objects'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '142', 'type': 'keyword_argument', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'pages_total'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'pages_total'},{'id': '145', 'type': 'keyword_argument', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'page_num'},{'id': '148', 'type': 'keyword_argument', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'page_size'}
def paginate(self, model_class, order_by, page_num=1, page_size=100, conditions=None, settings=None): ''' Selects records and returns a single page of model instances. - `model_class`: the model class matching the query's table, or `None` for getting back instances of an ad-hoc model. - `order_by`: columns to use for sorting the query (contents of the ORDER BY clause). - `page_num`: the page number (1-based), or -1 to get the last page. - `page_size`: number of records to return per page. - `conditions`: optional SQL conditions (contents of the WHERE clause). - `settings`: query settings to send as HTTP GET parameters The result is a namedtuple containing `objects` (list), `number_of_objects`, `pages_total`, `number` (of the current page), and `page_size`. ''' count = self.count(model_class, conditions) pages_total = int(ceil(count / float(page_size))) if page_num == -1: page_num = max(pages_total, 1) elif page_num < 1: raise ValueError('Invalid page number: %d' % page_num) offset = (page_num - 1) * page_size query = 'SELECT * FROM $table' if conditions: query += ' WHERE ' + conditions query += ' ORDER BY %s' % order_by query += ' LIMIT %d, %d' % (offset, page_size) query = self._substitute(query, model_class) return Page( objects=list(self.select(query, model_class, settings)) if count else [], number_of_objects=count, pages_total=pages_total, number=page_num, page_size=page_size )
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'compute_memory_contents_under_schedule'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'schedule'},{'id': '6', 'type': 'block', 'children': ['7', '15', '21', '25', '117']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'out_degree'},{'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': '_compute_initial_out_degree'},{'id': '14', 'type': 'argument_list', 'children': []},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'curr_memory_contents'},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'set'},{'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': 'memory_contents_for_each_operation'},{'id': '24', 'type': 'list', 'children': [], 'value': '[]'},{'id': '25', 'type': 'for_statement', 'children': ['26', '27', '28']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'operation_id'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'schedule'},{'id': '28', 'type': 'block', 'children': ['29', '39', '55', '65', '88']},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'operation_name'},{'id': '32', 'type': 'attribute', 'children': ['33', '38']},{'id': '33', 'type': 'subscript', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '36', 'type': 'identifier', 'children': [], 'value': '_operations'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'operation_id'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '39', 'type': 'for_statement', 'children': ['40', '41', '47']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'output_name'},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'get_operation_output_names'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'operation_name'},{'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': 'curr_memory_contents'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'output_name'},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'memory_contents_for_each_operation'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'frozenset'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'curr_memory_contents'},{'id': '65', 'type': 'for_statement', 'children': ['66', '67', '73']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'output_name'},{'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_operation_output_names'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'operation_name'},{'id': '73', 'type': 'block', 'children': ['74']},{'id': '74', 'type': 'if_statement', 'children': ['75', '80']},{'id': '75', 'type': 'comparison_operator', 'children': ['76', '79'], 'value': '=='},{'id': '76', 'type': 'subscript', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'out_degree'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'output_name'},{'id': '79', 'type': 'integer', 'children': [], 'value': '0'},{'id': '80', 'type': 'block', 'children': ['81']},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'curr_memory_contents'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'output_name'},{'id': '88', 'type': 'for_statement', 'children': ['89', '90', '96']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'input_name'},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'get_operation_input_names'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'operation_name'},{'id': '96', 'type': 'block', 'children': ['97', '103']},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'augmented_assignment', 'children': ['99', '102'], 'value': '-='},{'id': '99', 'type': 'subscript', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'out_degree'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'input_name'},{'id': '102', 'type': 'integer', 'children': [], 'value': '1'},{'id': '103', 'type': 'if_statement', 'children': ['104', '109']},{'id': '104', 'type': 'comparison_operator', 'children': ['105', '108'], 'value': '=='},{'id': '105', 'type': 'subscript', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'out_degree'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'input_name'},{'id': '108', 'type': 'integer', 'children': [], 'value': '0'},{'id': '109', 'type': 'block', 'children': ['110']},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'curr_memory_contents'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'input_name'},{'id': '117', 'type': 'return_statement', 'children': ['118']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'memory_contents_for_each_operation'}
def compute_memory_contents_under_schedule(self, schedule): out_degree = self._compute_initial_out_degree() curr_memory_contents = set() memory_contents_for_each_operation = [] for operation_id in schedule: operation_name = self._operations[operation_id].name for output_name in self.get_operation_output_names(operation_name): curr_memory_contents.add(output_name) memory_contents_for_each_operation.append(frozenset(curr_memory_contents)) for output_name in self.get_operation_output_names(operation_name): if out_degree[output_name] == 0: curr_memory_contents.remove(output_name) for input_name in self.get_operation_input_names(operation_name): out_degree[input_name] -= 1 if out_degree[input_name] == 0: curr_memory_contents.remove(input_name) return memory_contents_for_each_operation
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16', '18']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '9', '14']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'by'},{'id': '7', 'type': 'type', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '9', 'type': 'typed_default_parameter', 'children': ['10', '11', '13']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '11', 'type': 'type', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'object'},{'id': '13', 'type': 'string', 'children': [], 'value': "''"},{'id': '14', 'type': 'dictionary_splat_pattern', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '16', 'type': 'type', 'children': ['17']},{'id': '17', 'type': 'string', 'children': [], 'value': "'SASdata'"},{'id': '18', 'type': 'block', 'children': ['19', '23', '27', '117', '128', '147', '153', '157', '161', '177', '185', '192', '252']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'outstr'},{'id': '22', 'type': 'string', 'children': [], 'value': "''"},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '26', 'type': 'string', 'children': [], 'value': "''"},{'id': '27', 'type': 'if_statement', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'if_statement', 'children': ['31', '36', '91']},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '33', 'type': 'argument_list', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '36', 'type': 'block', 'children': ['37', '46']},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'fn'},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'partition'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '46', 'type': 'if_statement', 'children': ['47', '52', '73']},{'id': '47', 'type': 'comparison_operator', 'children': ['48', '51'], 'value': '=='},{'id': '48', 'type': 'subscript', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'fn'},{'id': '50', 'type': 'integer', 'children': [], 'value': '1'},{'id': '51', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '52', 'type': 'block', 'children': ['53', '59', '65']},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'libref'},{'id': '56', 'type': 'subscript', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'fn'},{'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': 'table'},{'id': '62', 'type': 'subscript', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'fn'},{'id': '64', 'type': 'integer', 'children': [], 'value': '2'},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'outstr'},{'id': '68', 'type': 'binary_operator', 'children': ['69', '70'], 'value': '%'},{'id': '69', 'type': 'string', 'children': [], 'value': '"out=%s.%s"'},{'id': '70', 'type': 'tuple', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'libref'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '73', 'type': 'else_clause', 'children': ['74']},{'id': '74', 'type': 'block', 'children': ['75', '79', '85']},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'libref'},{'id': '78', 'type': 'string', 'children': [], 'value': "''"},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '82', 'type': 'subscript', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'fn'},{'id': '84', 'type': 'integer', 'children': [], 'value': '0'},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'outstr'},{'id': '88', 'type': 'binary_operator', 'children': ['89', '90'], 'value': '+'},{'id': '89', 'type': 'string', 'children': [], 'value': '"out="'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '91', 'type': 'else_clause', 'children': ['92']},{'id': '92', 'type': 'block', 'children': ['93', '99', '105']},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'libref'},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'libref'},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'outstr'},{'id': '108', 'type': 'binary_operator', 'children': ['109', '110'], 'value': '%'},{'id': '109', 'type': 'string', 'children': [], 'value': '"out=%s.%s"'},{'id': '110', 'type': 'tuple', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'libref'},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '117', 'type': 'if_statement', 'children': ['118', '121']},{'id': '118', 'type': 'comparison_operator', 'children': ['119', '120'], 'value': 'in'},{'id': '119', 'type': 'string', 'children': [], 'value': "'options'"},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '121', 'type': 'block', 'children': ['122']},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '125', 'type': 'subscript', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '127', 'type': 'string', 'children': [], 'value': "'options'"},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'assignment', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '131', 'type': 'binary_operator', 'children': ['132', '133'], 'value': '%'},{'id': '132', 'type': 'string', 'children': [], 'value': '"proc sort data=%s.%s%s %s %s ;\\n"'},{'id': '133', 'type': 'tuple', 'children': ['134', '137', '140', '145', '146']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'libref'},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '140', 'type': 'call', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '143', 'type': 'identifier', 'children': [], 'value': '_dsopts'},{'id': '144', 'type': 'argument_list', 'children': []},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'outstr'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'augmented_assignment', 'children': ['149', '150'], 'value': '+='},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '150', 'type': 'binary_operator', 'children': ['151', '152'], 'value': '%'},{'id': '151', 'type': 'string', 'children': [], 'value': '"by %s;"'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'by'},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'augmented_assignment', 'children': ['155', '156'], 'value': '+='},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '156', 'type': 'string', 'children': [], 'value': '"run\\n;"'},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'runcode'},{'id': '160', 'type': 'True', 'children': []},{'id': '161', 'type': 'if_statement', 'children': ['162', '167']},{'id': '162', 'type': 'attribute', 'children': ['163', '166']},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'sas'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'nosub'},{'id': '167', 'type': 'block', 'children': ['168', '173']},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'call', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'assignment', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'runcode'},{'id': '176', 'type': 'False', 'children': []},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'll'},{'id': '180', 'type': 'call', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '183', 'type': 'identifier', 'children': [], 'value': '_is_valid'},{'id': '184', 'type': 'argument_list', 'children': []},{'id': '185', 'type': 'if_statement', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'll'},{'id': '187', 'type': 'block', 'children': ['188']},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'assignment', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'runcode'},{'id': '191', 'type': 'False', 'children': []},{'id': '192', 'type': 'if_statement', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'runcode'},{'id': '194', 'type': 'block', 'children': ['195', '207', '211', '236']},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'assignment', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'll'},{'id': '198', 'type': 'call', 'children': ['199', '204']},{'id': '199', 'type': 'attribute', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'sas'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'submit'},{'id': '204', 'type': 'argument_list', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '206', 'type': 'string', 'children': [], 'value': '"text"'},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'assignment', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'elog'},{'id': '210', 'type': 'list', 'children': [], 'value': '[]'},{'id': '211', 'type': 'for_statement', 'children': ['212', '213', '220']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '213', 'type': 'call', 'children': ['214', '219']},{'id': '214', 'type': 'attribute', 'children': ['215', '218']},{'id': '215', 'type': 'subscript', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'll'},{'id': '217', 'type': 'string', 'children': [], 'value': "'LOG'"},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'splitlines'},{'id': '219', 'type': 'argument_list', 'children': []},{'id': '220', 'type': 'block', 'children': ['221']},{'id': '221', 'type': 'if_statement', 'children': ['222', '228']},{'id': '222', 'type': 'call', 'children': ['223', '226']},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '226', 'type': 'argument_list', 'children': ['227']},{'id': '227', 'type': 'string', 'children': [], 'value': "'ERROR'"},{'id': '228', 'type': 'block', 'children': ['229']},{'id': '229', 'type': 'expression_statement', 'children': ['230']},{'id': '230', 'type': 'call', 'children': ['231', '234']},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'elog'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '234', 'type': 'argument_list', 'children': ['235']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '236', 'type': 'if_statement', 'children': ['237', '241']},{'id': '237', 'type': 'call', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '239', 'type': 'argument_list', 'children': ['240']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'elog'},{'id': '241', 'type': 'block', 'children': ['242']},{'id': '242', 'type': 'raise_statement', 'children': ['243']},{'id': '243', 'type': 'call', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '245', 'type': 'argument_list', 'children': ['246']},{'id': '246', 'type': 'call', 'children': ['247', '250']},{'id': '247', 'type': 'attribute', 'children': ['248', '249']},{'id': '248', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '250', 'type': 'argument_list', 'children': ['251']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'elog'},{'id': '252', 'type': 'if_statement', 'children': ['253', '254', '280']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '254', 'type': 'block', 'children': ['255']},{'id': '255', 'type': 'if_statement', 'children': ['256', '262', '265']},{'id': '256', 'type': 'not_operator', 'children': ['257']},{'id': '257', 'type': 'call', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '259', 'type': 'argument_list', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '262', 'type': 'block', 'children': ['263']},{'id': '263', 'type': 'return_statement', 'children': ['264']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '265', 'type': 'else_clause', 'children': ['266']},{'id': '266', 'type': 'block', 'children': ['267']},{'id': '267', 'type': 'return_statement', 'children': ['268']},{'id': '268', 'type': 'call', 'children': ['269', '274']},{'id': '269', 'type': 'attribute', 'children': ['270', '273']},{'id': '270', 'type': 'attribute', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'sas'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'sasdata'},{'id': '274', 'type': 'argument_list', 'children': ['275', '276', '277']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'libref'},{'id': '277', 'type': 'attribute', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '280', 'type': 'else_clause', 'children': ['281']},{'id': '281', 'type': 'block', 'children': ['282']},{'id': '282', 'type': 'return_statement', 'children': ['283']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'self'}
def sort(self, by: str, out: object = '', **kwargs) -> 'SASdata': outstr = '' options = '' if out: if isinstance(out, str): fn = out.partition('.') if fn[1] == '.': libref = fn[0] table = fn[2] outstr = "out=%s.%s" % (libref, table) else: libref = '' table = fn[0] outstr = "out=" + table else: libref = out.libref table = out.table outstr = "out=%s.%s" % (out.libref, out.table) if 'options' in kwargs: options = kwargs['options'] code = "proc sort data=%s.%s%s %s %s ;\n" % (self.libref, self.table, self._dsopts(), outstr, options) code += "by %s;" % by code += "run\n;" runcode = True if self.sas.nosub: print(code) runcode = False ll = self._is_valid() if ll: runcode = False if runcode: ll = self.sas.submit(code, "text") elog = [] for line in ll['LOG'].splitlines(): if line.startswith('ERROR'): elog.append(line) if len(elog): raise RuntimeError("\n".join(elog)) if out: if not isinstance(out, str): return out else: return self.sas.sasdata(table, libref, self.results) else: return self