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', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_findSamesetProteins'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'protToPeps'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'proteins'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '21', '28', '53', '59', '87']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'proteins'},{'id': '12', 'type': 'conditional_expression', 'children': ['13', '17', '20'], 'value': 'if'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'viewkeys'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'protToPeps'},{'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': 'is'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'proteins'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'proteins'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'equalEvidence'},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'ddict'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '28', 'type': 'for_statement', 'children': ['29', '30', '31']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'protein'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'proteins'},{'id': '31', 'type': 'block', 'children': ['32', '38']},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'peptides'},{'id': '35', 'type': 'subscript', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'protToPeps'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'protein'},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '51']},{'id': '40', 'type': 'attribute', 'children': ['41', '50']},{'id': '41', 'type': 'subscript', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'equalEvidence'},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'peptides'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'protein'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'equalProteins'},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '58', 'type': 'argument_list', 'children': []},{'id': '59', 'type': 'for_statement', 'children': ['60', '61', '65']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'proteins'},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'viewvalues'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'equalEvidence'},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'if_statement', 'children': ['67', '73']},{'id': '67', 'type': 'comparison_operator', 'children': ['68', '72'], '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': 'identifier', 'children': [], 'value': 'proteins'},{'id': '72', 'type': 'integer', 'children': [], 'value': '1'},{'id': '73', 'type': 'block', 'children': ['74']},{'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': 'equalProteins'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'proteins'},{'id': '87', 'type': 'return_statement', 'children': ['88']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'equalProteins'}
def _findSamesetProteins(protToPeps, proteins=None): proteins = viewkeys(protToPeps) if proteins is None else proteins equalEvidence = ddict(set) for protein in proteins: peptides = protToPeps[protein] equalEvidence[tuple(sorted(peptides))].add(protein) equalProteins = list() for proteins in viewvalues(equalEvidence): if len(proteins) > 1: equalProteins.append(tuple(sorted(proteins))) return equalProteins
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_findRedundantProteins'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'protToPeps'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'pepToProts'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'proteins'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '22', '29', '36', '45', '54', '60', '91', '97', '168', '185', '191', '234']},{'id': '10', 'type': 'if_statement', 'children': ['11', '14']},{'id': '11', 'type': 'comparison_operator', 'children': ['12', '13'], 'value': 'is'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'proteins'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'proteins'},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'viewkeys'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'protToPeps'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'pepFrequency'},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': '_getValueCounts'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'pepToProts'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'protPepCounts'},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': '_getValueCounts'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'protToPeps'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'getCount'},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'operator'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'itemgetter'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'integer', 'children': [], 'value': '1'},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'getProt'},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'operator'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'itemgetter'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'integer', 'children': [], 'value': '0'},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'proteinTuples'},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '59', 'type': 'argument_list', 'children': []},{'id': '60', 'type': 'for_statement', 'children': ['61', '62', '63']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'protein'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'proteins'},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'if_statement', 'children': ['65', '70', '78']},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '67', 'type': 'argument_list', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'protein'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '70', 'type': 'block', 'children': ['71']},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'proteinTuples'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'protein'},{'id': '78', 'type': 'else_clause', 'children': ['79']},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'proteinTuples'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'list', 'children': ['90'], 'value': '[protein]'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'protein'},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '94', 'type': 'call', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '96', 'type': 'argument_list', 'children': []},{'id': '97', 'type': 'for_statement', 'children': ['98', '99', '106']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'protein'},{'id': '99', 'type': 'call', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '101', 'type': 'argument_list', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'proteinTuples'},{'id': '103', 'type': 'keyword_argument', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '105', 'type': 'True', 'children': []},{'id': '106', 'type': 'block', 'children': ['107', '121', '133']},{'id': '107', 'type': 'if_statement', 'children': ['108', '114']},{'id': '108', 'type': 'comparison_operator', 'children': ['109', '113'], 'value': '=='},{'id': '109', 'type': 'call', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'protein'},{'id': '113', 'type': 'integer', 'children': [], 'value': '1'},{'id': '114', 'type': 'block', 'children': ['115']},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'protein'},{'id': '118', 'type': 'subscript', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'protein'},{'id': '120', 'type': 'integer', 'children': [], 'value': '0'},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'protPepFreq'},{'id': '124', 'type': 'list_comprehension', 'children': ['125', '128']},{'id': '125', 'type': 'subscript', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'pepFrequency'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'pep'},{'id': '128', 'type': 'for_in_clause', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'pep'},{'id': '130', 'type': 'subscript', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'protToPeps'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'protein'},{'id': '133', 'type': 'if_statement', 'children': ['134', '140']},{'id': '134', 'type': 'comparison_operator', 'children': ['135', '139'], 'value': '>'},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'protPepFreq'},{'id': '139', 'type': 'integer', 'children': [], 'value': '1'},{'id': '140', 'type': 'block', 'children': ['141', '159']},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'sortValue'},{'id': '144', 'type': 'tuple', 'children': ['145', '152']},{'id': '145', 'type': 'binary_operator', 'children': ['146', '150'], 'value': '*'},{'id': '146', 'type': 'call', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'protPepFreq'},{'id': '150', 'type': 'unary_operator', 'children': ['151'], 'value': '-'},{'id': '151', 'type': 'integer', 'children': [], 'value': '1'},{'id': '152', 'type': 'call', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '154', 'type': 'argument_list', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'protPepFreq'},{'id': '156', 'type': 'keyword_argument', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '158', 'type': 'True', 'children': []},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'call', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'tuple', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'protein'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'sortValue'},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'assignment', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'sortedProteins'},{'id': '171', 'type': 'call', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '173', 'type': 'argument_list', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'getProt'},{'id': '175', 'type': 'call', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '177', 'type': 'argument_list', 'children': ['178', '179', '182']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '179', 'type': 'keyword_argument', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'getCount'},{'id': '182', 'type': 'keyword_argument', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '184', 'type': 'True', 'children': []},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'assignment', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'redundantProteins'},{'id': '188', 'type': 'call', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '190', 'type': 'argument_list', 'children': []},{'id': '191', 'type': 'for_statement', 'children': ['192', '193', '194']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'protein'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'sortedProteins'},{'id': '194', 'type': 'block', 'children': ['195']},{'id': '195', 'type': 'for_statement', 'children': ['196', '197', '200', '209']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'pep'},{'id': '197', 'type': 'subscript', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'protToPeps'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'protein'},{'id': '200', 'type': 'block', 'children': ['201']},{'id': '201', 'type': 'if_statement', 'children': ['202', '207']},{'id': '202', 'type': 'comparison_operator', 'children': ['203', '206'], 'value': '<='},{'id': '203', 'type': 'subscript', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'pepFrequency'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'pep'},{'id': '206', 'type': 'integer', 'children': [], 'value': '1'},{'id': '207', 'type': 'block', 'children': ['208']},{'id': '208', 'type': 'break_statement', 'children': []},{'id': '209', 'type': 'else_clause', 'children': ['210']},{'id': '210', 'type': 'block', 'children': ['211', '220', '227']},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'assignment', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'protPepFrequency'},{'id': '214', 'type': 'call', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'Counter'},{'id': '216', 'type': 'argument_list', 'children': ['217']},{'id': '217', 'type': 'subscript', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'protToPeps'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'protein'},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'call', 'children': ['222', '225']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'pepFrequency'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'subtract'},{'id': '225', 'type': 'argument_list', 'children': ['226']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'protPepFrequency'},{'id': '227', 'type': 'expression_statement', 'children': ['228']},{'id': '228', 'type': 'call', 'children': ['229', '232']},{'id': '229', 'type': 'attribute', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'redundantProteins'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '232', 'type': 'argument_list', 'children': ['233']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'protein'},{'id': '234', 'type': 'return_statement', 'children': ['235']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'redundantProteins'}
def _findRedundantProteins(protToPeps, pepToProts, proteins=None): if proteins is None: proteins = viewkeys(protToPeps) pepFrequency = _getValueCounts(pepToProts) protPepCounts = _getValueCounts(protToPeps) getCount = operator.itemgetter(1) getProt = operator.itemgetter(0) proteinTuples = list() for protein in proteins: if isinstance(protein, tuple): proteinTuples.append(protein) else: proteinTuples.append(tuple([protein])) sort = list() for protein in sorted(proteinTuples, reverse=True): if len(protein) == 1: protein = protein[0] protPepFreq = [pepFrequency[pep] for pep in protToPeps[protein]] if min(protPepFreq) > 1: sortValue = (len(protPepFreq)*-1, sorted(protPepFreq, reverse=True)) sort.append((protein, sortValue)) sortedProteins = map(getProt, sorted(sort, key=getCount, reverse=True)) redundantProteins = set() for protein in sortedProteins: for pep in protToPeps[protein]: if pepFrequency[pep] <= 1: break else: protPepFrequency = Counter(protToPeps[protein]) pepFrequency.subtract(protPepFrequency) redundantProteins.add(protein) return redundantProteins
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_mergeProteinEntries'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'proteinLists'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'protToPeps'},{'id': '6', 'type': 'block', 'children': ['7', '14', '47']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'mergedProtToPeps'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'protToPeps'},{'id': '14', 'type': 'for_statement', 'children': ['15', '16', '17']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'proteins'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'proteinLists'},{'id': '17', 'type': 'block', 'children': ['18', '31', '41']},{'id': '18', 'type': 'for_statement', 'children': ['19', '20', '21']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'protein'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'proteins'},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'peptides'},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'mergedProtToPeps'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'protein'},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'mergedProtein'},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'proteins'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '46']},{'id': '43', 'type': 'subscript', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'mergedProtToPeps'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'mergedProtein'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'peptides'},{'id': '47', 'type': 'return_statement', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'mergedProtToPeps'}
def _mergeProteinEntries(proteinLists, protToPeps): mergedProtToPeps = dict(protToPeps) for proteins in proteinLists: for protein in proteins: peptides = mergedProtToPeps.pop(protein) mergedProtein = tuple(sorted(proteins)) mergedProtToPeps[mergedProtein] = peptides return mergedProtToPeps
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_list'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'foldername'},{'id': '7', 'type': 'string', 'children': [], 'value': '"INBOX"'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'since'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '33', '51', '68', '84', '97']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'folder'},{'id': '18', 'type': 'conditional_expression', 'children': ['19', '22', '23', '26', '27'], 'value': 'if'},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'folder'},{'id': '22', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '23', 'type': 'comparison_operator', 'children': ['24', '25'], 'value': '=='},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'foldername'},{'id': '25', 'type': 'string', 'children': [], 'value': '"INBOX"'},{'id': '26', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'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': '_getfolder'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'foldername'},{'id': '33', 'type': 'function_definition', 'children': ['34', '35', '37']},{'id': '34', 'type': 'function_name', 'children': [], 'value': 'sortcmp'},{'id': '35', 'type': 'parameters', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'try_statement', 'children': ['39', '46']},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'return_statement', 'children': ['41']},{'id': '41', 'type': 'attribute', 'children': ['42', '45']},{'id': '42', 'type': 'subscript', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '44', 'type': 'integer', 'children': [], 'value': '1'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'date'},{'id': '46', 'type': 'except_clause', 'children': ['47']},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'return_statement', 'children': ['49']},{'id': '49', 'type': 'unary_operator', 'children': ['50'], 'value': '-'},{'id': '50', 'type': 'integer', 'children': [], 'value': '1'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'lst'},{'id': '54', 'type': 'conditional_expression', 'children': ['55', '60', '62'], 'value': 'if'},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'folder'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '59', 'type': 'argument_list', 'children': []},{'id': '60', 'type': 'not_operator', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'since'},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'folder'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'items_since'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'since'},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'sorted_lst'},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '73', 'type': 'argument_list', 'children': ['74', '75', '78']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'lst'},{'id': '75', 'type': 'keyword_argument', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'sortcmp'},{'id': '78', 'type': 'keyword_argument', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '80', 'type': 'conditional_expression', 'children': ['81', '82', '83'], 'value': 'if'},{'id': '81', 'type': 'integer', 'children': [], 'value': '1'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '83', 'type': 'integer', 'children': [], 'value': '0'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'itemlist'},{'id': '87', 'type': 'list_comprehension', 'children': ['88', '92']},{'id': '88', 'type': 'tuple', 'children': ['89', '90', '91']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'folder'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '92', 'type': 'for_in_clause', 'children': ['93', '96']},{'id': '93', 'type': 'pattern_list', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'sorted_lst'},{'id': '97', 'type': 'return_statement', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'itemlist'}
def _list(self, foldername="INBOX", reverse=False, since=None): folder = self.folder \ if foldername == "INBOX" \ else self._getfolder(foldername) def sortcmp(d): try: return d[1].date except: return -1 lst = folder.items() if not since else folder.items_since(since) sorted_lst = sorted(lst, key=sortcmp, reverse=1 if reverse else 0) itemlist = [(folder, key, msg) for key,msg in sorted_lst] return itemlist
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_entries'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6']},{'id': '6', 'type': 'return_statement', 'children': ['7']},{'id': '7', 'type': 'call', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '9', 'type': 'argument_list', 'children': ['10', '13', '18']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '13', 'type': 'keyword_argument', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'sort_func'},{'id': '18', 'type': 'keyword_argument', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'get_reverse'},{'id': '24', 'type': 'argument_list', 'children': []}
def sort_entries(self): return sorted(self.data, key=self.sort_func, reverse=self.get_reverse())
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'expectedLabelPosition'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'peptide'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'labelStateInfo'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'sequence'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'modPositions'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '32', '48', '54', '136', '217', '238']},{'id': '13', 'type': 'if_statement', 'children': ['14', '17']},{'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': 'is'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'modPositions'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'modPositions'},{'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': 'maspy'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'peptidemethods'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'returnModPositions'},{'id': '27', 'type': 'argument_list', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'peptide'},{'id': '29', 'type': 'keyword_argument', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'indexStart'},{'id': '31', 'type': 'integer', 'children': [], 'value': '0'},{'id': '32', 'type': 'if_statement', 'children': ['33', '36']},{'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': 'is'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'sequence'},{'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': 'sequence'},{'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': 'maspy'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'peptidemethods'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'removeModifications'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'peptide'},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'currLabelMods'},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '53', 'type': 'argument_list', 'children': []},{'id': '54', 'type': 'for_statement', 'children': ['55', '58', '64']},{'id': '55', 'type': 'pattern_list', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'labelPosition'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'labelSymbols'},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'viewitems'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'subscript', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'labelStateInfo'},{'id': '63', 'type': 'string', 'children': [], 'value': "'aminoAcidLabels'"},{'id': '64', 'type': 'block', 'children': ['65', '74']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'labelSymbols'},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'aux'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'toList'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'labelSymbols'},{'id': '74', 'type': 'if_statement', 'children': ['75', '79', '81', '105']},{'id': '75', 'type': 'comparison_operator', 'children': ['76', '77'], 'value': '=='},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'labelSymbols'},{'id': '77', 'type': 'list', 'children': ['78'], 'value': "['']"},{'id': '78', 'type': 'string', 'children': [], 'value': "''"},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'pass_statement', 'children': []},{'id': '81', 'type': 'elif_clause', 'children': ['82', '85']},{'id': '82', 'type': 'comparison_operator', 'children': ['83', '84'], 'value': '=='},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'labelPosition'},{'id': '84', 'type': 'string', 'children': [], 'value': "'nTerm'"},{'id': '85', 'type': 'block', 'children': ['86', '96']},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'currLabelMods'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'setdefault'},{'id': '91', 'type': 'argument_list', 'children': ['92', '93']},{'id': '92', 'type': 'integer', 'children': [], 'value': '0'},{'id': '93', 'type': 'call', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '95', 'type': 'argument_list', 'children': []},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'call', 'children': ['98', '103']},{'id': '98', 'type': 'attribute', 'children': ['99', '102']},{'id': '99', 'type': 'subscript', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'currLabelMods'},{'id': '101', 'type': 'integer', 'children': [], 'value': '0'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'labelSymbols'},{'id': '105', 'type': 'else_clause', 'children': ['106']},{'id': '106', 'type': 'block', 'children': ['107']},{'id': '107', 'type': 'for_statement', 'children': ['108', '109', '116']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'sequencePosition'},{'id': '109', 'type': 'call', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'aux'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'findAllSubstrings'},{'id': '113', 'type': 'argument_list', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'sequence'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'labelPosition'},{'id': '116', 'type': 'block', 'children': ['117', '127']},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'currLabelMods'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'setdefault'},{'id': '122', 'type': 'argument_list', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'sequencePosition'},{'id': '124', 'type': 'call', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '126', 'type': 'argument_list', 'children': []},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'call', 'children': ['129', '134']},{'id': '129', 'type': 'attribute', 'children': ['130', '133']},{'id': '130', 'type': 'subscript', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'currLabelMods'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'sequencePosition'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'labelSymbols'},{'id': '136', 'type': 'if_statement', 'children': ['137', '142']},{'id': '137', 'type': 'comparison_operator', 'children': ['138', '141'], 'value': 'is'},{'id': '138', 'type': 'subscript', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'labelStateInfo'},{'id': '140', 'type': 'string', 'children': [], 'value': "'excludingModifications'"},{'id': '141', 'type': 'None', 'children': []},{'id': '142', 'type': 'block', 'children': ['143']},{'id': '143', 'type': 'for_statement', 'children': ['144', '147', '153']},{'id': '144', 'type': 'pattern_list', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'excludingMod'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'excludedLabelSymbol'},{'id': '147', 'type': 'call', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'viewitems'},{'id': '149', 'type': 'argument_list', 'children': ['150']},{'id': '150', 'type': 'subscript', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'labelStateInfo'},{'id': '152', 'type': 'string', 'children': [], 'value': "'excludingModifications'"},{'id': '153', 'type': 'block', 'children': ['154', '160']},{'id': '154', 'type': 'if_statement', 'children': ['155', '158']},{'id': '155', 'type': 'comparison_operator', 'children': ['156', '157'], 'value': 'not'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'excludingMod'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'modPositions'},{'id': '158', 'type': 'block', 'children': ['159']},{'id': '159', 'type': 'continue_statement', 'children': []},{'id': '160', 'type': 'for_statement', 'children': ['161', '162', '165']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'excludingModPos'},{'id': '162', 'type': 'subscript', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'modPositions'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'excludingMod'},{'id': '165', 'type': 'block', 'children': ['166', '172', '180']},{'id': '166', 'type': 'if_statement', 'children': ['167', '170']},{'id': '167', 'type': 'comparison_operator', 'children': ['168', '169'], 'value': 'not'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'excludingModPos'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'currLabelMods'},{'id': '170', 'type': 'block', 'children': ['171']},{'id': '171', 'type': 'continue_statement', 'children': []},{'id': '172', 'type': 'if_statement', 'children': ['173', '178']},{'id': '173', 'type': 'comparison_operator', 'children': ['174', '175'], 'value': 'not'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'excludedLabelSymbol'},{'id': '175', 'type': 'subscript', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'currLabelMods'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'excludingModPos'},{'id': '178', 'type': 'block', 'children': ['179']},{'id': '179', 'type': 'continue_statement', 'children': []},{'id': '180', 'type': 'if_statement', 'children': ['181', '189', '195']},{'id': '181', 'type': 'comparison_operator', 'children': ['182', '188'], 'value': '=='},{'id': '182', 'type': 'call', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'subscript', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'currLabelMods'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'excludingModPos'},{'id': '188', 'type': 'integer', 'children': [], 'value': '1'},{'id': '189', 'type': 'block', 'children': ['190']},{'id': '190', 'type': 'delete_statement', 'children': ['191']},{'id': '191', 'type': '()', 'children': ['192']},{'id': '192', 'type': 'subscript', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'currLabelMods'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'excludingModPos'},{'id': '195', 'type': 'else_clause', 'children': ['196']},{'id': '196', 'type': 'block', 'children': ['197', '208']},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'assignment', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'excludedModIndex'},{'id': '200', 'type': 'call', 'children': ['201', '206']},{'id': '201', 'type': 'attribute', 'children': ['202', '205']},{'id': '202', 'type': 'subscript', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'currLabelMods'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'excludingModPos'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '206', 'type': 'argument_list', 'children': ['207']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'excludedLabelSymbol'},{'id': '208', 'type': 'expression_statement', 'children': ['209']},{'id': '209', 'type': 'call', 'children': ['210', '215']},{'id': '210', 'type': 'attribute', 'children': ['211', '214']},{'id': '211', 'type': 'subscript', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'currLabelMods'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'excludingModPos'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '215', 'type': 'argument_list', 'children': ['216']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'excludedModIndex'},{'id': '217', 'type': 'for_statement', 'children': ['218', '219', '226']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'sequencePosition'},{'id': '219', 'type': 'call', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '221', 'type': 'argument_list', 'children': ['222']},{'id': '222', 'type': 'call', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'viewkeys'},{'id': '224', 'type': 'argument_list', 'children': ['225']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'currLabelMods'},{'id': '226', 'type': 'block', 'children': ['227']},{'id': '227', 'type': 'expression_statement', 'children': ['228']},{'id': '228', 'type': 'assignment', 'children': ['229', '232']},{'id': '229', 'type': 'subscript', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'currLabelMods'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'sequencePosition'},{'id': '232', 'type': 'call', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '234', 'type': 'argument_list', 'children': ['235']},{'id': '235', 'type': 'subscript', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'currLabelMods'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'sequencePosition'},{'id': '238', 'type': 'return_statement', 'children': ['239']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'currLabelMods'}
def expectedLabelPosition(peptide, labelStateInfo, sequence=None, modPositions=None): if modPositions is None: modPositions = maspy.peptidemethods.returnModPositions(peptide, indexStart=0 ) if sequence is None: sequence = maspy.peptidemethods.removeModifications(peptide) currLabelMods = dict() for labelPosition, labelSymbols in viewitems(labelStateInfo['aminoAcidLabels']): labelSymbols = aux.toList(labelSymbols) if labelSymbols == ['']: pass elif labelPosition == 'nTerm': currLabelMods.setdefault(0, list()) currLabelMods[0].extend(labelSymbols) else: for sequencePosition in aux.findAllSubstrings(sequence, labelPosition): currLabelMods.setdefault(sequencePosition, list()) currLabelMods[sequencePosition].extend(labelSymbols) if labelStateInfo['excludingModifications'] is not None: for excludingMod, excludedLabelSymbol in viewitems(labelStateInfo['excludingModifications']): if excludingMod not in modPositions: continue for excludingModPos in modPositions[excludingMod]: if excludingModPos not in currLabelMods: continue if excludedLabelSymbol not in currLabelMods[excludingModPos]: continue if len(currLabelMods[excludingModPos]) == 1: del(currLabelMods[excludingModPos]) else: excludedModIndex = currLabelMods[excludingModPos].index(excludedLabelSymbol) currLabelMods[excludingModPos].pop(excludedModIndex) for sequencePosition in list(viewkeys(currLabelMods)): currLabelMods[sequencePosition] = sorted(currLabelMods[sequencePosition]) return currLabelMods
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'rank'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'member'},{'id': '6', 'type': 'block', 'children': ['7', '29']},{'id': '7', 'type': 'if_statement', 'children': ['8', '11']},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'reversed'},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'return_statement', 'children': ['13']},{'id': '13', 'type': 'call', 'children': ['14', '19']},{'id': '14', 'type': 'attribute', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': '_client'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'zrevrank'},{'id': '19', 'type': 'argument_list', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'key_prefix'},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': '_dumps'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'member'},{'id': '29', 'type': 'return_statement', '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': 'self'},{'id': '34', 'type': 'identifier', 'children': [], 'value': '_client'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'zrank'},{'id': '36', 'type': 'argument_list', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'key_prefix'},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '43', 'type': 'identifier', 'children': [], 'value': '_dumps'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'member'}
def rank(self, member): if self.reversed: return self._client.zrevrank(self.key_prefix, self._dumps(member)) return self._client.zrank(self.key_prefix, self._dumps(member))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'prepareSiiImport'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'siiContainer'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'specfile'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'qcAttr'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'qcLargerBetter'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'qcCutoff'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'rankAttr'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'rankLargerBetter'},{'id': '12', 'type': 'block', 'children': ['13', '35', '45', '55', '65', '75']},{'id': '13', 'type': 'if_statement', 'children': ['14', '19', '28']},{'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': 'not'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'specfile'},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'siiContainer'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'siiContainer'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'addSpecfile'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'specfile'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '28', 'type': 'else_clause', 'children': ['29']},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'raise_statement', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'string', 'children': [], 'value': "'...'"},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '44']},{'id': '37', 'type': 'subscript', 'children': ['38', '43']},{'id': '38', 'type': 'subscript', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'siiContainer'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'specfile'},{'id': '43', 'type': 'string', 'children': [], 'value': "'qcAttr'"},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'qcAttr'},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '54']},{'id': '47', 'type': 'subscript', 'children': ['48', '53']},{'id': '48', 'type': 'subscript', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'siiContainer'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'specfile'},{'id': '53', 'type': 'string', 'children': [], 'value': "'qcLargerBetter'"},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'qcLargerBetter'},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '64']},{'id': '57', 'type': 'subscript', 'children': ['58', '63']},{'id': '58', 'type': 'subscript', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'siiContainer'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'specfile'},{'id': '63', 'type': 'string', 'children': [], 'value': "'qcCutoff'"},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'qcCutoff'},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '74']},{'id': '67', 'type': 'subscript', 'children': ['68', '73']},{'id': '68', 'type': 'subscript', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'siiContainer'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'specfile'},{'id': '73', 'type': 'string', 'children': [], 'value': "'rankAttr'"},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'rankAttr'},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '84']},{'id': '77', 'type': 'subscript', 'children': ['78', '83']},{'id': '78', 'type': 'subscript', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'siiContainer'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'specfile'},{'id': '83', 'type': 'string', 'children': [], 'value': "'rankLargerBetter'"},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'rankLargerBetter'}
def prepareSiiImport(siiContainer, specfile, path, qcAttr, qcLargerBetter, qcCutoff, rankAttr, rankLargerBetter): if specfile not in siiContainer.info: siiContainer.addSpecfile(specfile, path) else: raise Exception('...') siiContainer.info[specfile]['qcAttr'] = qcAttr siiContainer.info[specfile]['qcLargerBetter'] = qcLargerBetter siiContainer.info[specfile]['qcCutoff'] = qcCutoff siiContainer.info[specfile]['rankAttr'] = rankAttr siiContainer.info[specfile]['rankLargerBetter'] = rankLargerBetter
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_nearest'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'x0'},{'id': '6', 'type': 'type', 'children': ['7']},{'id': '7', 'type': 'generic_type', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'Tuple'},{'id': '9', 'type': 'type_parameter', 'children': ['10', '12']},{'id': '10', 'type': 'type', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '12', 'type': 'type', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'Any'},{'id': '14', 'type': 'block', 'children': ['15', '24', '33', '51', '65', '77', '137']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'asanyarray'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'x0'},{'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': 'atleast_1d'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'x0'},{'id': '33', 'type': 'if_statement', 'children': ['34', '45']},{'id': '34', 'type': 'boolean_operator', 'children': ['35', '40'], 'value': 'or'},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '39'], 'value': '=='},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '39', 'type': 'integer', 'children': [], 'value': '0'},{'id': '40', 'type': 'comparison_operator', 'children': ['41', '44'], 'value': '=='},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'x0'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '44', 'type': 'integer', 'children': [], 'value': '0'},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'raise_statement', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'string', 'children': [], 'value': "'empty input(s)'"},{'id': '51', 'type': 'if_statement', 'children': ['52', '59']},{'id': '52', 'type': 'comparison_operator', 'children': ['53', '56'], 'value': 'not'},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'x0'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '56', 'type': 'tuple', 'children': ['57', '58']},{'id': '57', 'type': 'integer', 'children': [], 'value': '0'},{'id': '58', 'type': 'integer', 'children': [], 'value': '1'},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'raise_statement', 'children': ['61']},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'string', 'children': [], 'value': "'2-D x0 not handled yet'"},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'ind'},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'empty_like'},{'id': '72', 'type': 'argument_list', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'x0'},{'id': '74', 'type': 'keyword_argument', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '77', 'type': 'for_statement', 'children': ['78', '81', '85']},{'id': '78', 'type': 'pattern_list', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'xi'},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'x0'},{'id': '85', 'type': 'block', 'children': ['86']},{'id': '86', 'type': 'if_statement', 'children': ['87', '113', '130']},{'id': '87', 'type': 'boolean_operator', 'children': ['88', '91'], 'value': 'and'},{'id': '88', 'type': 'comparison_operator', 'children': ['89', '90'], 'value': 'is'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'xi'},{'id': '90', 'type': 'None', 'children': []},{'id': '91', 'type': '()', 'children': ['92']},{'id': '92', 'type': 'boolean_operator', 'children': ['93', '107'], 'value': 'or'},{'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': 'xi'},{'id': '97', 'type': 'tuple', 'children': ['98', '101', '104']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'date'},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'datetime64'},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'isfinite'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'xi'},{'id': '113', 'type': 'block', 'children': ['114']},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '119']},{'id': '116', 'type': 'subscript', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'ind'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'i'},{'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': 'nanargmin'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'call', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'binary_operator', 'children': ['128', '129'], 'value': '-'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'xi'},{'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': "'x0 must NOT be None or NaN to avoid surprising None return value'"},{'id': '137', 'type': 'return_statement', 'children': ['138']},{'id': '138', 'type': 'expression_list', 'children': ['139', '146']},{'id': '139', 'type': 'subscript', 'children': ['140', '145']},{'id': '140', 'type': 'call', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'ind'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'squeeze'},{'id': '144', 'type': 'argument_list', 'children': []},{'id': '145', 'type': 'tuple', 'children': []},{'id': '146', 'type': 'subscript', 'children': ['147', '154']},{'id': '147', 'type': 'call', 'children': ['148', '153']},{'id': '148', 'type': 'attribute', 'children': ['149', '152']},{'id': '149', 'type': 'subscript', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'ind'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'squeeze'},{'id': '153', 'type': 'argument_list', 'children': []},{'id': '154', 'type': 'tuple', 'children': []}
def find_nearest(x, x0) -> Tuple[int, Any]: x = np.asanyarray(x) x0 = np.atleast_1d(x0) if x.size == 0 or x0.size == 0: raise ValueError('empty input(s)') if x0.ndim not in (0, 1): raise ValueError('2-D x0 not handled yet') ind = np.empty_like(x0, dtype=int) for i, xi in enumerate(x0): if xi is not None and (isinstance(xi, (datetime.datetime, datetime.date, np.datetime64)) or np.isfinite(xi)): ind[i] = np.nanargmin(abs(x-xi)) else: raise ValueError('x0 must NOT be None or NaN to avoid surprising None return value') return ind.squeeze()[()], x[ind].squeeze()[()]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'primary_mrna'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'entrystream'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'parenttype'},{'id': '7', 'type': 'string', 'children': [], 'value': "'gene'"},{'id': '8', 'type': 'block', 'children': ['9']},{'id': '9', 'type': 'for_statement', 'children': ['10', '11', '12']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'entrystream'},{'id': '12', 'type': 'block', 'children': ['13', '27', '73']},{'id': '13', 'type': 'if_statement', 'children': ['14', '22']},{'id': '14', 'type': 'not_operator', 'children': ['15']},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '17', 'type': 'argument_list', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'Feature'},{'id': '22', 'type': 'block', 'children': ['23', '26']},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'yield', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '26', 'type': 'continue_statement', 'children': []},{'id': '27', 'type': 'for_statement', 'children': ['28', '29', '41']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '29', 'type': 'call', 'children': ['30', '35']},{'id': '30', 'type': 'attribute', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'select'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'features'},{'id': '35', 'type': 'argument_list', 'children': ['36', '37', '38']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'parenttype'},{'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'traverse'},{'id': '40', 'type': 'True', 'children': []},{'id': '41', 'type': 'block', 'children': ['42', '58', '67']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'mrnas'},{'id': '45', 'type': 'list_comprehension', 'children': ['46', '47', '52']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '47', 'type': 'for_in_clause', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '52', 'type': 'if_clause', 'children': ['53']},{'id': '53', 'type': 'comparison_operator', 'children': ['54', '57'], 'value': '=='},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '57', 'type': 'string', 'children': [], 'value': "'mRNA'"},{'id': '58', 'type': 'if_statement', 'children': ['59', '65']},{'id': '59', 'type': 'comparison_operator', 'children': ['60', '64'], 'value': '=='},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'mrnas'},{'id': '64', 'type': 'integer', 'children': [], 'value': '0'},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'continue_statement', 'children': []},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': '_emplace_pmrna'},{'id': '70', 'type': 'argument_list', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'mrnas'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'yield', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'entry'}
def primary_mrna(entrystream, parenttype='gene'): for entry in entrystream: if not isinstance(entry, tag.Feature): yield entry continue for parent in tag.select.features(entry, parenttype, traverse=True): mrnas = [f for f in parent.children if f.type == 'mRNA'] if len(mrnas) == 0: continue _emplace_pmrna(mrnas, parent) yield entry
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'notes'},{'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': 'public_only'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '28', '40', '54', '69', '129']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'tag_index'},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '14', 'type': 'generator_expression', 'children': ['15', '18']},{'id': '15', 'type': 'tuple', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '18', 'type': 'for_in_clause', 'children': ['19', '22']},{'id': '19', 'type': 'pattern_list', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'Note'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'TAGS'},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'notes'},{'id': '31', 'type': 'call', 'children': ['32', '37']},{'id': '32', 'type': 'attribute', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'note_set'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '37', 'type': 'argument_list', 'children': ['38', '39']},{'id': '38', 'type': 'string', 'children': [], 'value': "'-sort_num'"},{'id': '39', 'type': 'string', 'children': [], 'value': "'created'"},{'id': '40', 'type': 'if_statement', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'public_only'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'notes'},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'notes'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'keyword_argument', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'is_public'},{'id': '53', 'type': 'True', 'children': []},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'known_issues'},{'id': '57', 'type': 'list_comprehension', 'children': ['58', '59', '62']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '59', 'type': 'for_in_clause', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'notes'},{'id': '62', 'type': 'if_clause', 'children': ['63']},{'id': '63', 'type': 'call', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'is_known_issue_for'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'new_features'},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '74', 'type': 'argument_list', 'children': ['75', '105', '126']},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '77', 'type': 'argument_list', 'children': ['78', '91']},{'id': '78', 'type': 'generator_expression', 'children': ['79', '80', '83']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '80', 'type': 'for_in_clause', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'notes'},{'id': '83', 'type': 'if_clause', 'children': ['84']},{'id': '84', 'type': 'not_operator', 'children': ['85']},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'is_known_issue_for'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '91', 'type': 'keyword_argument', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '93', 'type': 'lambda', 'children': ['94', '96']},{'id': '94', 'type': 'lambda_parameters', 'children': ['95']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'note'},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'tag_index'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '100', 'type': 'argument_list', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'note'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '104', 'type': 'integer', 'children': [], 'value': '0'},{'id': '105', 'type': 'keyword_argument', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '107', 'type': 'lambda', 'children': ['108', '110']},{'id': '108', 'type': 'lambda_parameters', 'children': ['109']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '110', 'type': 'boolean_operator', 'children': ['111', '116'], 'value': 'and'},{'id': '111', 'type': 'comparison_operator', 'children': ['112', '115'], 'value': '=='},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '115', 'type': 'string', 'children': [], 'value': "'Fixed'"},{'id': '116', 'type': 'call', 'children': ['117', '122']},{'id': '117', 'type': 'attribute', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'note'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '126', 'type': 'keyword_argument', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '128', 'type': 'True', 'children': []},{'id': '129', 'type': 'return_statement', 'children': ['130']},{'id': '130', 'type': 'expression_list', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'new_features'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'known_issues'}
def notes(self, public_only=False): tag_index = dict((tag, i) for i, tag in enumerate(Note.TAGS)) notes = self.note_set.order_by('-sort_num', 'created') if public_only: notes = notes.filter(is_public=True) known_issues = [n for n in notes if n.is_known_issue_for(self)] new_features = sorted( sorted( (n for n in notes if not n.is_known_issue_for(self)), key=lambda note: tag_index.get(note.tag, 0)), key=lambda n: n.tag == 'Fixed' and n.note.startswith(self.version), reverse=True) return new_features, known_issues
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'dispatchlist'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'keyword_separator', 'children': []},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'author'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'subcategory'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '17', 'type': 'string', 'children': [], 'value': "'new'"},{'id': '18', 'type': 'block', 'children': ['19', '26', '35', '89', '119']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '22', 'type': 'dictionary', 'children': ['23']},{'id': '23', 'type': 'pair', 'children': ['24', '25']},{'id': '24', 'type': 'string', 'children': [], 'value': "'sort'"},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '26', 'type': 'if_statement', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'author'},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '34']},{'id': '31', 'type': 'subscript', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '33', 'type': 'string', 'children': [], 'value': "'dispatchauthor'"},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'author'},{'id': '35', 'type': 'if_statement', 'children': ['36', '39', '63', '82']},{'id': '36', 'type': 'boolean_operator', 'children': ['37', '38'], 'value': 'and'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'subcategory'},{'id': '39', 'type': 'block', 'children': ['40', '57']},{'id': '40', 'type': 'if_statement', 'children': ['41', '51']},{'id': '41', 'type': '()', 'children': ['42']},{'id': '42', 'type': 'boolean_operator', 'children': ['43', '46'], 'value': 'or'},{'id': '43', 'type': 'comparison_operator', 'children': ['44', '45'], 'value': 'not'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'dispatch_categories'},{'id': '46', 'type': 'comparison_operator', 'children': ['47', '48'], 'value': 'not'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'subcategory'},{'id': '48', 'type': 'subscript', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'dispatch_categories'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'raise_statement', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'string', 'children': [], 'value': "'Invalid category/subcategory'"},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '62']},{'id': '59', 'type': 'subscript', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '61', 'type': 'string', 'children': [], 'value': "'dispatchcategory'"},{'id': '62', 'type': 'string', 'children': [], 'value': "f'{category}:{subcategory}'"},{'id': '63', 'type': 'elif_clause', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '65', 'type': 'block', 'children': ['66', '76']},{'id': '66', 'type': 'if_statement', 'children': ['67', '70']},{'id': '67', 'type': 'comparison_operator', 'children': ['68', '69'], 'value': 'not'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'dispatch_categories'},{'id': '70', 'type': 'block', 'children': ['71']},{'id': '71', 'type': 'raise_statement', 'children': ['72']},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'string', 'children': [], 'value': "'Invalid category'"},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '81']},{'id': '78', 'type': 'subscript', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '80', 'type': 'string', 'children': [], 'value': "'dispatchcategory'"},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '82', 'type': 'else_clause', 'children': ['83']},{'id': '83', 'type': 'block', 'children': ['84']},{'id': '84', 'type': 'raise_statement', 'children': ['85']},{'id': '85', 'type': 'call', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'string', 'children': [], 'value': "'Cannot request subcategory without category'"},{'id': '89', 'type': 'decorated_definition', 'children': ['90', '97']},{'id': '90', 'type': 'decorator', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'api_query'},{'id': '93', 'type': 'argument_list', 'children': ['94', '95']},{'id': '94', 'type': 'string', 'children': [], 'value': "'dispatchlist'"},{'id': '95', 'type': 'dictionary_splat', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '97', 'type': 'function_definition', 'children': ['98', '99', '102']},{'id': '98', 'type': 'function_name', 'children': [], 'value': 'result'},{'id': '99', 'type': 'parameters', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '102', 'type': 'block', 'children': ['103']},{'id': '103', 'type': 'return_statement', 'children': ['104']},{'id': '104', 'type': 'list_comprehension', 'children': ['105', '111']},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'DispatchThumbnail'},{'id': '108', 'type': 'identifier', 'children': [], 'value': '_from_elem'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '111', 'type': 'for_in_clause', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '113', 'type': 'call', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '117', 'type': 'argument_list', 'children': ['118']},{'id': '118', 'type': 'string', 'children': [], 'value': "'DISPATCHLIST'"},{'id': '119', 'type': 'return_statement', 'children': ['120']},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'self'}
def dispatchlist(self, *, author=None, category=None, subcategory=None, sort='new'): params = {'sort': sort} if author: params['dispatchauthor'] = author if category and subcategory: if (category not in dispatch_categories or subcategory not in dispatch_categories[category]): raise ValueError('Invalid category/subcategory') params['dispatchcategory'] = f'{category}:{subcategory}' elif category: if category not in dispatch_categories: raise ValueError('Invalid category') params['dispatchcategory'] = category else: raise ValueError('Cannot request subcategory without category') @api_query('dispatchlist', **params) async def result(_, root): return [ DispatchThumbnail._from_elem(elem) for elem in root.find('DISPATCHLIST') ] return result(self)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'have_cycle'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '6', 'type': 'type', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '8', 'type': 'type', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'frozenset'},{'id': '10', 'type': 'block', 'children': ['11', '17', '45', '52', '57', '103']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'walked'},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '16', 'type': 'argument_list', 'children': []},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'frozenset'},{'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': 'it'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '27', 'type': 'argument_list', 'children': ['28', '40']},{'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': 'it'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'from_iterable'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '39', 'type': 'argument_list', 'children': []},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '44', 'type': 'argument_list', 'children': []},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'preds'},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'reversed_graph'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'last_walked_len'},{'id': '55', 'type': 'unary_operator', 'children': ['56'], 'value': '-'},{'id': '56', 'type': 'integer', 'children': [], 'value': '1'},{'id': '57', 'type': 'while_statement', 'children': ['58', '64']},{'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': '!='},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'last_walked_len'},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'walked'},{'id': '64', 'type': 'block', 'children': ['65', '72']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'last_walked_len'},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'walked'},{'id': '72', 'type': 'for_statement', 'children': ['73', '74', '77']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '74', 'type': 'binary_operator', 'children': ['75', '76'], 'value': '-'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'walked'},{'id': '77', 'type': 'block', 'children': ['78']},{'id': '78', 'type': 'if_statement', 'children': ['79', '95']},{'id': '79', 'type': 'comparison_operator', 'children': ['80', '94'], 'value': '=='},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '82', 'type': 'argument_list', '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': 'preds'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '88', 'type': 'argument_list', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '92', 'type': 'argument_list', 'children': []},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'walked'},{'id': '94', 'type': 'integer', 'children': [], 'value': '0'},{'id': '95', 'type': 'block', 'children': ['96']},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'call', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'walked'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '103', 'type': 'return_statement', 'children': ['104']},{'id': '104', 'type': 'call', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'frozenset'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'binary_operator', 'children': ['108', '109'], 'value': '-'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'walked'}
def have_cycle(graph:dict) -> frozenset: walked = set() nodes = frozenset(it.chain(it.chain.from_iterable(graph.values()), graph.keys())) preds = reversed_graph(graph) last_walked_len = -1 while last_walked_len != len(walked): last_walked_len = len(walked) for node in nodes - walked: if len(preds.get(node, set()) - walked) == 0: walked.add(node) return frozenset(nodes - walked)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'time_pipeline'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'iterable'},{'id': '5', 'type': 'list_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'steps'},{'id': '7', 'type': 'block', 'children': ['8', '10', '56', '67', '71', '75', '197', '204', '211', '221']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'string', 'children': [], 'value': "'''\nThis times the steps in a pipeline. Give it an iterable to test against\nfollowed by the steps of the pipeline seperated in individual functions.\nExample Usage:\n```\n from random import choice, randint\n l = [randint(0,50) for i in range(100)]\n step1 = lambda iterable:(i for i in iterable if i%5==0)\n step2 = lambda iterable:(i for i in iterable if i%8==3)\n step3 = lambda iterable:sorted((1.0*i)/50 for i in iterable)\n step4 = lambda iterable:(float(float(float(float(i*3)))) for i in iterable)\n print('filter first')\n time_pipeline(l, step1, step2, step3, step4)\n print('process first')\n time_pipeline(l, step3, step4, step1, step2)\n print('filter, process, filter, process')\n time_pipeline(l, step1, step3, step2, step4)\n``` \nOutputs:\n filter first\n step 1 | 2.0427s | step1 = lambda iterable:(i for i in iterable if i%5==0)\n step 2 | 2.0510s | step2 = lambda iterable:(i for i in iterable if i%8==3)\n step 3 | 2.4839s | step3 = lambda iterable:sorted((1.0*i)/50 for i in iterable)\n step 4 | 2.8446s | step4 = lambda iterable:(float(float(float(float(i*3)))) for i in iterable)\n process first\n step 1 | 7.5291s | step3 = lambda iterable:sorted((1.0*i)/50 for i in iterable)\n step 2 | 20.6732s | step4 = lambda iterable:(float(float(float(float(i*3)))) for i in iterable)\n step 3 | 16.8470s | step1 = lambda iterable:(i for i in iterable if i%5==0)\n step 4 | 16.8269s | step2 = lambda iterable:(i for i in iterable if i%8==3)\n filter, process, filter, process\n step 1 | 2.0528s | step1 = lambda iterable:(i for i in iterable if i%5==0)\n step 2 | 3.3039s | step3 = lambda iterable:sorted((1.0*i)/50 for i in iterable)\n step 3 | 3.1385s | step2 = lambda iterable:(i for i in iterable if i%8==3)\n step 4 | 3.1489s | step4 = lambda iterable:(float(float(float(float(i*3)))) for i in iterable)\n'''"},{'id': '10', 'type': 'if_statement', 'children': ['11', '15', '36']},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'callable'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'iterable'},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'try_statement', 'children': ['17', '29']},{'id': '17', 'type': 'block', 'children': ['18', '25']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'iterable'},{'id': '24', 'type': 'argument_list', 'children': []},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'callable_base'},{'id': '28', 'type': 'True', 'children': []},{'id': '29', 'type': 'except_clause', 'children': ['30']},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'raise_statement', 'children': ['32']},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'string', 'children': [], 'value': "'time_pipeline needs the first argument to be an iterable or a function that produces an iterable.'"},{'id': '36', 'type': 'else_clause', 'children': ['37']},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'try_statement', 'children': ['39', '49']},{'id': '39', 'type': 'block', 'children': ['40', '45']},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'iterable'},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'callable_base'},{'id': '48', 'type': 'False', 'children': []},{'id': '49', 'type': 'except_clause', 'children': ['50']},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'raise_statement', 'children': ['52']},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'string', 'children': [], 'value': "'time_pipeline needs the first argument to be an iterable or a function that produces an iterable.'"},{'id': '56', 'type': 'if_statement', 'children': ['57', '59']},{'id': '57', 'type': 'not_operator', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'callable_base'},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'iterable'},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'iterable'},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'durations'},{'id': '70', 'type': 'list', 'children': [], 'value': '[]'},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '74', 'type': 'list', 'children': [], 'value': '[]'},{'id': '75', 'type': 'for_statement', 'children': ['76', '79', '83']},{'id': '76', 'type': 'pattern_list', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '78', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '79', 'type': 'call', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'steps'},{'id': '83', 'type': 'block', 'children': ['84', '94', '98', '156', '163']},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'current_tasks'},{'id': '87', 'type': 'subscript', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'steps'},{'id': '89', 'type': 'slice', 'children': ['90', '91']},{'id': '90', 'type': 'colon', 'children': []},{'id': '91', 'type': 'binary_operator', 'children': ['92', '93'], 'value': '+'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'i'},{'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': 'duration'},{'id': '97', 'type': 'float', 'children': [], 'value': '0.0'},{'id': '98', 'type': 'for_statement', 'children': ['99', '100', '104']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'integer', 'children': [], 'value': '100000'},{'id': '104', 'type': 'block', 'children': ['105', '120', '126', '137', '148']},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'test_generator'},{'id': '108', 'type': 'conditional_expression', 'children': ['109', '115', '116'], 'value': 'if'},{'id': '109', 'type': 'call', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'iterable'},{'id': '114', 'type': 'argument_list', 'children': []},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'callable_base'},{'id': '116', 'type': 'call', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'iterable'},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '123', 'type': 'call', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'ts'},{'id': '125', 'type': 'argument_list', 'children': []},{'id': '126', 'type': 'for_statement', 'children': ['127', '128', '129']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'current_tasks'},{'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': 'test_generator'},{'id': '133', 'type': 'call', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'test_generator'},{'id': '137', 'type': 'for_statement', 'children': ['138', '139', '146']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '139', 'type': 'call', 'children': ['140', '144']},{'id': '140', 'type': 'subscript', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'current_tasks'},{'id': '142', 'type': 'unary_operator', 'children': ['143'], 'value': '-'},{'id': '143', 'type': 'integer', 'children': [], 'value': '1'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'test_generator'},{'id': '146', 'type': 'block', 'children': ['147']},{'id': '147', 'type': 'pass_statement', 'children': []},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'augmented_assignment', 'children': ['150', '151'], 'value': '+='},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'duration'},{'id': '151', 'type': 'binary_operator', 'children': ['152', '155'], 'value': '-'},{'id': '152', 'type': 'call', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'ts'},{'id': '154', 'type': 'argument_list', 'children': []},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'call', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'durations'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'duration'},{'id': '163', 'type': 'if_statement', 'children': ['164', '170', '180']},{'id': '164', 'type': 'comparison_operator', 'children': ['165', '169'], 'value': '=='},{'id': '165', 'type': 'call', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '167', 'type': 'argument_list', 'children': ['168']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'durations'},{'id': '169', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'results'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'subscript', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'durations'},{'id': '179', 'type': 'integer', 'children': [], 'value': '0'},{'id': '180', 'type': 'else_clause', 'children': ['181']},{'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': 'results'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'binary_operator', 'children': ['189', '193'], 'value': '-'},{'id': '189', 'type': 'subscript', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'durations'},{'id': '191', 'type': 'unary_operator', 'children': ['192'], 'value': '-'},{'id': '192', 'type': 'integer', 'children': [], 'value': '1'},{'id': '193', 'type': 'subscript', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'durations'},{'id': '195', 'type': 'unary_operator', 'children': ['196'], 'value': '-'},{'id': '196', 'type': 'integer', 'children': [], 'value': '2'},{'id': '197', 'type': 'assert_statement', 'children': ['198']},{'id': '198', 'type': 'comparison_operator', 'children': ['199', '203'], 'value': '>'},{'id': '199', 'type': 'call', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '201', 'type': 'argument_list', 'children': ['202']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '203', 'type': 'integer', 'children': [], 'value': '0'},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'assignment', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'resultsum'},{'id': '207', 'type': 'call', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '209', 'type': 'argument_list', 'children': ['210']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'assignment', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'ratios'},{'id': '214', 'type': 'list_comprehension', 'children': ['215', '218']},{'id': '215', 'type': 'binary_operator', 'children': ['216', '217'], 'value': '/'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'resultsum'},{'id': '218', 'type': 'for_in_clause', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '221', 'type': 'for_statement', 'children': ['222', '223', '230']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '223', 'type': 'call', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '225', 'type': 'argument_list', 'children': ['226']},{'id': '226', 'type': 'call', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '228', 'type': 'argument_list', 'children': ['229']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'ratios'},{'id': '230', 'type': 'block', 'children': ['231', '267']},{'id': '231', 'type': 'try_statement', 'children': ['232', '252']},{'id': '232', 'type': 'block', 'children': ['233']},{'id': '233', 'type': 'expression_statement', 'children': ['234']},{'id': '234', 'type': 'assignment', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '236', 'type': 'call', 'children': ['237', '251']},{'id': '237', 'type': 'attribute', 'children': ['238', '250']},{'id': '238', 'type': 'subscript', 'children': ['239', '249']},{'id': '239', 'type': 'call', 'children': ['240', '248']},{'id': '240', 'type': 'attribute', 'children': ['241', '247']},{'id': '241', 'type': 'call', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'getsource'},{'id': '243', 'type': 'argument_list', 'children': ['244']},{'id': '244', 'type': 'subscript', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'steps'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'splitlines'},{'id': '248', 'type': 'argument_list', 'children': []},{'id': '249', 'type': 'integer', 'children': [], 'value': '0'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '251', 'type': 'argument_list', 'children': []},{'id': '252', 'type': 'except_clause', 'children': ['253']},{'id': '253', 'type': 'block', 'children': ['254']},{'id': '254', 'type': 'expression_statement', 'children': ['255']},{'id': '255', 'type': 'assignment', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '257', 'type': 'call', 'children': ['258', '266']},{'id': '258', 'type': 'attribute', 'children': ['259', '265']},{'id': '259', 'type': 'call', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'repr'},{'id': '261', 'type': 'argument_list', 'children': ['262']},{'id': '262', 'type': 'subscript', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'steps'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '266', 'type': 'argument_list', 'children': []},{'id': '267', 'type': 'expression_statement', 'children': ['268']},{'id': '268', 'type': 'call', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '270', 'type': 'argument_list', 'children': ['271']},{'id': '271', 'type': 'call', 'children': ['272', '275']},{'id': '272', 'type': 'attribute', 'children': ['273', '274']},{'id': '273', 'type': 'string', 'children': [], 'value': "'step {} | {:2.4f}s | {}'"},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '275', 'type': 'argument_list', 'children': ['276', '279', '282']},{'id': '276', 'type': 'binary_operator', 'children': ['277', '278'], 'value': '+'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '278', 'type': 'integer', 'children': [], 'value': '1'},{'id': '279', 'type': 'subscript', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'durations'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 's'}
def time_pipeline(iterable, *steps): ''' This times the steps in a pipeline. Give it an iterable to test against followed by the steps of the pipeline seperated in individual functions. Example Usage: ``` from random import choice, randint l = [randint(0,50) for i in range(100)] step1 = lambda iterable:(i for i in iterable if i%5==0) step2 = lambda iterable:(i for i in iterable if i%8==3) step3 = lambda iterable:sorted((1.0*i)/50 for i in iterable) step4 = lambda iterable:(float(float(float(float(i*3)))) for i in iterable) print('filter first') time_pipeline(l, step1, step2, step3, step4) print('process first') time_pipeline(l, step3, step4, step1, step2) print('filter, process, filter, process') time_pipeline(l, step1, step3, step2, step4) ``` Outputs: filter first step 1 | 2.0427s | step1 = lambda iterable:(i for i in iterable if i%5==0) step 2 | 2.0510s | step2 = lambda iterable:(i for i in iterable if i%8==3) step 3 | 2.4839s | step3 = lambda iterable:sorted((1.0*i)/50 for i in iterable) step 4 | 2.8446s | step4 = lambda iterable:(float(float(float(float(i*3)))) for i in iterable) process first step 1 | 7.5291s | step3 = lambda iterable:sorted((1.0*i)/50 for i in iterable) step 2 | 20.6732s | step4 = lambda iterable:(float(float(float(float(i*3)))) for i in iterable) step 3 | 16.8470s | step1 = lambda iterable:(i for i in iterable if i%5==0) step 4 | 16.8269s | step2 = lambda iterable:(i for i in iterable if i%8==3) filter, process, filter, process step 1 | 2.0528s | step1 = lambda iterable:(i for i in iterable if i%5==0) step 2 | 3.3039s | step3 = lambda iterable:sorted((1.0*i)/50 for i in iterable) step 3 | 3.1385s | step2 = lambda iterable:(i for i in iterable if i%8==3) step 4 | 3.1489s | step4 = lambda iterable:(float(float(float(float(i*3)))) for i in iterable) ''' if callable(iterable): try: iter(iterable()) callable_base = True except: raise TypeError('time_pipeline needs the first argument to be an iterable or a function that produces an iterable.') else: try: iter(iterable) callable_base = False except: raise TypeError('time_pipeline needs the first argument to be an iterable or a function that produces an iterable.') if not callable_base: iterable = tuple(iterable) durations = [] results = [] for i,_ in enumerate(steps): current_tasks = steps[:i+1] duration = 0.0 for t in range(100000): test_generator = iter(iterable()) if callable_base else iter(iterable) start = ts() for task in current_tasks: test_generator = task(test_generator) for i in current_tasks[-1](test_generator): pass duration += ts() - start durations.append(duration) if len(durations) == 1: results.append(durations[0]) else: results.append(durations[-1]-durations[-2]) assert sum(results) > 0 resultsum = sum(results) ratios = [i/resultsum for i in results] for i in range(len(ratios)): try: s = getsource(steps[i]).splitlines()[0].strip() except: s = repr(steps[i]).strip() print('step {} | {:2.4f}s | {}'.format(i+1, durations[i], s))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_matches'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'matches'},{'id': '5', 'type': 'block', 'children': ['6', '8', '30', '54']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'string', 'children': [], 'value': "'''Sorts a ``list`` of matches best to worst'''"},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'multipliers'},{'id': '11', 'type': 'dictionary', 'children': ['12', '17', '22', '27']},{'id': '12', 'type': 'pair', 'children': ['13', '14']},{'id': '13', 'type': 'string', 'children': [], 'value': "'exact'"},{'id': '14', 'type': 'binary_operator', 'children': ['15', '16'], 'value': '**'},{'id': '15', 'type': 'integer', 'children': [], 'value': '10'},{'id': '16', 'type': 'integer', 'children': [], 'value': '5'},{'id': '17', 'type': 'pair', 'children': ['18', '19']},{'id': '18', 'type': 'string', 'children': [], 'value': "'fname'"},{'id': '19', 'type': 'binary_operator', 'children': ['20', '21'], 'value': '**'},{'id': '20', 'type': 'integer', 'children': [], 'value': '10'},{'id': '21', 'type': 'integer', 'children': [], 'value': '4'},{'id': '22', 'type': 'pair', 'children': ['23', '24']},{'id': '23', 'type': 'string', 'children': [], 'value': "'fuzzy'"},{'id': '24', 'type': 'binary_operator', 'children': ['25', '26'], 'value': '**'},{'id': '25', 'type': 'integer', 'children': [], 'value': '10'},{'id': '26', 'type': 'integer', 'children': [], 'value': '2'},{'id': '27', 'type': 'pair', 'children': ['28', '29']},{'id': '28', 'type': 'string', 'children': [], 'value': "'fuzzy_fragment'"},{'id': '29', 'type': 'integer', 'children': [], 'value': '1'},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'matches'},{'id': '33', 'type': 'list_comprehension', 'children': ['34', '51']},{'id': '34', 'type': 'tuple', 'children': ['35', '50']},{'id': '35', 'type': 'binary_operator', 'children': ['36', '41'], 'value': '*'},{'id': '36', 'type': 'subscript', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'multipliers'},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '41', 'type': '()', 'children': ['42']},{'id': '42', 'type': 'conditional_expression', 'children': ['43', '46', '49'], 'value': 'if'},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'amount'},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'amount'},{'id': '49', 'type': 'integer', 'children': [], 'value': '1'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '51', 'type': 'for_in_clause', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'matches'},{'id': '54', 'type': 'return_statement', 'children': ['55']},{'id': '55', 'type': 'list_comprehension', 'children': ['56', '59']},{'id': '56', 'type': 'subscript', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '58', 'type': 'integer', 'children': [], 'value': '1'},{'id': '59', 'type': 'for_in_clause', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '63', 'type': 'argument_list', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'matches'},{'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '67', 'type': 'True', 'children': []}
def sort_matches(matches): '''Sorts a ``list`` of matches best to worst''' multipliers = {'exact':10**5,'fname':10**4,'fuzzy':10**2,'fuzzy_fragment':1} matches = [(multipliers[x.type]*(x.amount if x.amount else 1),x) for x in matches] return [x[1] for x in sorted(matches,reverse=True)]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_sorted_iterator'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '6', 'type': 'block', 'children': ['7', '17', '40', '43', '51', '66']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'next'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '17', 'type': 'if_statement', 'children': ['18', '26']},{'id': '18', 'type': 'comparison_operator', 'children': ['19', '23'], 'value': '<'},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'max_lines'},{'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': 'iter'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '33', 'type': 'argument_list', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '40', 'type': 'import_statement', 'children': ['41']},{'id': '41', 'type': 'dotted_name', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'tempfile'},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'tmp_dir'},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'tempfile'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'mkdtemp'},{'id': '50', 'type': 'argument_list', 'children': []},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'fnames'},{'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': '_split'},{'id': '58', 'type': 'argument_list', 'children': ['59', '65']},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '61', 'type': 'argument_list', 'children': ['62', '64']},{'id': '62', 'type': 'list', 'children': ['63'], 'value': '[lines]'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'tmp_dir'},{'id': '66', 'type': 'return_statement', 'children': ['67']},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'SortedIteratorMerger'},{'id': '69', 'type': 'argument_list', 'children': ['70', '82']},{'id': '70', 'type': 'list_comprehension', 'children': ['71', '79']},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'unpickle_iter'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '76', 'type': 'argument_list', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'fname'},{'id': '78', 'type': 'string', 'children': [], 'value': "'rb'"},{'id': '79', 'type': 'for_in_clause', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'fname'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'fnames'},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'key'}
def _get_sorted_iterator(self, iterator): lines = list(next(iterator)) if len(lines) < self.max_lines: return iter(sorted(lines, key=self.key)) import tempfile tmp_dir = tempfile.mkdtemp() fnames = self._split(chain([lines], iterator), tmp_dir) return SortedIteratorMerger([unpickle_iter(open(fname, 'rb')) for fname in fnames], self.key)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_split'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'tmp_dir'},{'id': '7', 'type': 'block', 'children': ['8', '12', '75']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'fnames'},{'id': '11', 'type': 'list', 'children': [], 'value': '[]'},{'id': '12', 'type': 'for_statement', 'children': ['13', '16', '20']},{'id': '13', 'type': 'pattern_list', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '20', 'type': 'block', 'children': ['21', '28', '49', '57', '64']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'out_fname'},{'id': '31', 'type': 'call', 'children': ['32', '37']},{'id': '32', 'type': 'attribute', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '37', 'type': 'argument_list', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'tmp_dir'},{'id': '39', 'type': 'call', 'children': ['40', '45']},{'id': '40', 'type': 'attribute', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'TMP_FNAME'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'binary_operator', 'children': ['47', '48'], 'value': '+'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '48', 'type': 'integer', 'children': [], 'value': '1'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '53', 'type': 'identifier', 'children': [], 'value': '_write'},{'id': '54', 'type': 'argument_list', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'out_fname'},{'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': 'fnames'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'out_fname'},{'id': '64', 'type': 'if_statement', 'children': ['65', '73']},{'id': '65', 'type': 'comparison_operator', 'children': ['66', '70'], 'value': '<'},{'id': '66', 'type': 'call', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'max_lines'},{'id': '73', 'type': 'block', 'children': ['74']},{'id': '74', 'type': 'break_statement', 'children': []},{'id': '75', 'type': 'return_statement', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'fnames'}
def _split(self, iterator, tmp_dir): fnames = [] for i, lines in enumerate(iterator): lines = list(lines) out_fname = os.path.join(tmp_dir, self.TMP_FNAME.format(i + 1)) self._write(lines, out_fname) fnames.append(out_fname) if len(lines) < self.max_lines: break return fnames
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_write'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'fname'},{'id': '7', 'type': 'block', 'children': ['8']},{'id': '8', 'type': 'with_statement', 'children': ['9', '19']},{'id': '9', 'type': 'with_clause', 'children': ['10']},{'id': '10', 'type': 'with_item', 'children': ['11']},{'id': '11', 'type': 'as_pattern', 'children': ['12', '17']},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '14', 'type': 'argument_list', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'fname'},{'id': '16', 'type': 'string', 'children': [], 'value': "'wb'"},{'id': '17', 'type': 'as_pattern_target', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'out_fhndl'},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'for_statement', 'children': ['21', '22', '31']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '24', 'type': 'argument_list', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'pickle'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'dump'},{'id': '37', 'type': 'argument_list', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'out_fhndl'}
def _write(self, lines, fname): with open(fname, 'wb') as out_fhndl: for line in sorted(lines, key=self.key): pickle.dump(line, out_fhndl)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'add'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'interval'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '7', 'type': 'block', 'children': ['8', '19']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '13']},{'id': '10', 'type': 'pattern_list', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'get_start_stop'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'interval'},{'id': '19', 'type': 'if_statement', 'children': ['20', '28', '77']},{'id': '20', 'type': 'comparison_operator', 'children': ['21', '27'], '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': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'starts'},{'id': '27', 'type': 'integer', 'children': [], 'value': '0'},{'id': '28', 'type': 'block', 'children': ['29', '55', '66']},{'id': '29', 'type': 'if_statement', 'children': ['30', '49']},{'id': '30', 'type': 'boolean_operator', 'children': ['31', '39'], 'value': 'or'},{'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': '<'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'start'},{'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': 'starts'},{'id': '37', 'type': 'unary_operator', 'children': ['38'], 'value': '-'},{'id': '38', 'type': 'integer', 'children': [], 'value': '1'},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': '<='},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '41', 'type': 'subscript', 'children': ['42', '48']},{'id': '42', 'type': 'subscript', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'offsets'},{'id': '46', 'type': 'unary_operator', 'children': ['47'], 'value': '-'},{'id': '47', 'type': 'integer', 'children': [], 'value': '1'},{'id': '48', 'type': 'integer', 'children': [], 'value': '1'},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'raise_statement', 'children': ['51']},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'string', 'children': [], 'value': "'intervals and offsets must be added in-order'"},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '65']},{'id': '57', 'type': 'subscript', 'children': ['58', '64']},{'id': '58', 'type': 'subscript', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'offsets'},{'id': '62', 'type': 'unary_operator', 'children': ['63'], 'value': '-'},{'id': '63', 'type': 'integer', 'children': [], 'value': '1'},{'id': '64', 'type': 'integer', 'children': [], 'value': '1'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'augmented_assignment', 'children': ['68', '76'], 'value': '+='},{'id': '68', 'type': 'subscript', 'children': ['69', '75']},{'id': '69', 'type': 'subscript', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'offsets'},{'id': '73', 'type': 'unary_operator', 'children': ['74'], 'value': '-'},{'id': '74', 'type': 'integer', 'children': [], 'value': '1'},{'id': '75', 'type': 'integer', 'children': [], 'value': '2'},{'id': '76', 'type': 'integer', 'children': [], 'value': '1'},{'id': '77', 'type': 'else_clause', 'children': ['78']},{'id': '78', 'type': 'block', 'children': ['79', '88', '97']},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'call', 'children': ['81', '86']},{'id': '81', 'type': 'attribute', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'starts'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'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': 'self'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'stops'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'call', 'children': ['99', '104']},{'id': '99', 'type': 'attribute', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'offsets'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'list', 'children': ['106', '107', '108'], 'value': '[offset, offset, 1]'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '108', 'type': 'integer', 'children': [], 'value': '1'}
def add(self, interval, offset): start, stop = self.get_start_stop(interval) if len(self.starts) > 0: if start < self.starts[-1] or offset <= self.offsets[-1][1]: raise ValueError('intervals and offsets must be added in-order') self.offsets[-1][1] = offset self.offsets[-1][2] += 1 else: self.starts.append(start) self.stops.append(stop) self.offsets.append([offset, offset, 1])
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_collection_documents_generator'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'database_name'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'collection_name'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'latest_n'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '10', 'type': 'block', 'children': ['11', '17', '23', '30', '108']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'mongo_database'},{'id': '14', 'type': 'subscript', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'database_name'},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'collection'},{'id': '20', 'type': 'subscript', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'mongo_database'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'collection_name'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'collection'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'create_index'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '30', 'type': 'if_statement', 'children': ['31', '34', '87']},{'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': 'is'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'latest_n'},{'id': '33', 'type': 'None', 'children': []},{'id': '34', 'type': 'block', 'children': ['35', '45', '60', '79']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'skip_n'},{'id': '38', 'type': 'binary_operator', 'children': ['39', '44'], 'value': '-'},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'collection'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '43', 'type': 'argument_list', 'children': []},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'latest_n'},{'id': '45', 'type': 'if_statement', 'children': ['46', '55']},{'id': '46', 'type': 'comparison_operator', 'children': ['47', '54'], 'value': '<'},{'id': '47', 'type': 'binary_operator', 'children': ['48', '53'], 'value': '-'},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'collection'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '52', 'type': 'argument_list', 'children': []},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'latest_n'},{'id': '54', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'skip_n'},{'id': '59', 'type': 'integer', 'children': [], 'value': '0'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '63', 'type': 'call', 'children': ['64', '74']},{'id': '64', 'type': 'attribute', 'children': ['65', '73']},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'collection'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'keyword_argument', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'list', 'children': ['76'], 'value': '[(sort_key, ASCENDING), ]'},{'id': '76', 'type': 'tuple', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'ASCENDING'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '82', 'type': 'subscript', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '84', 'type': 'slice', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'skip_n'},{'id': '86', 'type': 'colon', 'children': []},{'id': '87', 'type': 'else_clause', 'children': ['88']},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '92', 'type': 'call', 'children': ['93', '103']},{'id': '93', 'type': 'attribute', 'children': ['94', '102']},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'collection'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'keyword_argument', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'list', 'children': ['105'], 'value': '[(sort_key, ASCENDING), ]'},{'id': '105', 'type': 'tuple', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'ASCENDING'},{'id': '108', 'type': 'for_statement', 'children': ['109', '110', '111']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'document'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '111', 'type': 'block', 'children': ['112']},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'yield', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'document'}
def get_collection_documents_generator(client, database_name, collection_name, spec, latest_n, sort_key): mongo_database = client[database_name] collection = mongo_database[collection_name] collection.create_index(sort_key) if latest_n is not None: skip_n = collection.count() - latest_n if collection.count() - latest_n < 0: skip_n = 0 cursor = collection.find(filter=spec).sort([(sort_key, ASCENDING), ]) cursor = cursor[skip_n:] else: cursor = collection.find(filter=spec).sort([(sort_key, ASCENDING), ]) for document in cursor: yield document
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'save'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'list_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '9', 'type': 'block', 'children': ['10', '27', '44']},{'id': '10', 'type': 'if_statement', 'children': ['11', '15']},{'id': '11', 'type': 'not_operator', 'children': ['12']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'content_object'},{'id': '27', 'type': 'if_statement', 'children': ['28', '32']},{'id': '28', 'type': 'not_operator', 'children': ['29']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'actor_name'},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'actor_name'},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'actor'},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'call', 'children': ['46', '53']},{'id': '46', 'type': 'attribute', 'children': ['47', '52']},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'super'},{'id': '49', 'type': 'argument_list', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'Activity'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'save'},{'id': '53', 'type': 'argument_list', 'children': []}
def save(self, *args, **kwargs): if not self.target: self.target = str(self.content_object) if not self.actor_name: self.actor_name = str(self.actor) super(Activity, self).save()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_sort_modules'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'mods'},{'id': '5', 'type': 'block', 'children': ['6', '56']},{'id': '6', 'type': 'function_definition', 'children': ['7', '8', '11']},{'id': '7', 'type': 'function_name', 'children': [], 'value': 'compare'},{'id': '8', 'type': 'parameters', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '11', 'type': 'block', 'children': ['12', '18', '24', '31', '40', '54']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '15', 'type': 'subscript', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '17', 'type': 'integer', 'children': [], 'value': '1'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '21', 'type': 'subscript', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '23', 'type': 'integer', 'children': [], 'value': '1'},{'id': '24', 'type': 'if_statement', 'children': ['25', '28']},{'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': '=='},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'return_statement', 'children': ['30']},{'id': '30', 'type': 'integer', 'children': [], 'value': '0'},{'id': '31', 'type': 'if_statement', 'children': ['32', '37']},{'id': '32', 'type': 'comparison_operator', 'children': ['33', '36'], 'value': '=='},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'stem'},{'id': '36', 'type': 'string', 'children': [], 'value': '"__init__.py"'},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'return_statement', 'children': ['39']},{'id': '39', 'type': 'integer', 'children': [], 'value': '1'},{'id': '40', 'type': 'if_statement', 'children': ['41', '50']},{'id': '41', 'type': 'boolean_operator', 'children': ['42', '47'], 'value': 'or'},{'id': '42', 'type': 'comparison_operator', 'children': ['43', '46'], 'value': '=='},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'stem'},{'id': '46', 'type': 'string', 'children': [], 'value': '"__init__.py"'},{'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': '<'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'return_statement', 'children': ['52']},{'id': '52', 'type': 'unary_operator', 'children': ['53'], 'value': '-'},{'id': '53', 'type': 'integer', 'children': [], 'value': '1'},{'id': '54', 'type': 'return_statement', 'children': ['55']},{'id': '55', 'type': 'integer', 'children': [], 'value': '1'},{'id': '56', 'type': 'return_statement', 'children': ['57']},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '59', 'type': 'argument_list', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'mods'},{'id': '61', 'type': 'keyword_argument', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'cmp_to_key'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'compare'}
def _sort_modules(mods): def compare(x, y): x = x[1] y = y[1] if x == y: return 0 if y.stem == "__init__.py": return 1 if x.stem == "__init__.py" or x < y: return -1 return 1 return sorted(mods, key=cmp_to_key(compare))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_sort_results'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '6', 'type': 'block', 'children': ['7', '11', '15', '79', '83', '109']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'parents'},{'id': '10', 'type': 'list', 'children': [], 'value': '[]'},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '14', 'type': 'list', 'children': [], 'value': '[]'},{'id': '15', 'type': 'for_statement', 'children': ['16', '17', '18']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'if_statement', 'children': ['20', '30', '61']},{'id': '20', 'type': 'not_operator', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '24', 'type': 'identifier', 'children': [], 'value': '_in_list'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'parents'},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '30', 'type': 'block', 'children': ['31', '40', '47']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'parents'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'list', 'children': [], 'value': '[]'},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'call', 'children': ['49', '59']},{'id': '49', 'type': 'attribute', 'children': ['50', '58']},{'id': '50', 'type': 'subscript', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '52', 'type': 'binary_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': 'groups'},{'id': '57', 'type': 'integer', 'children': [], 'value': '1'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '61', 'type': 'else_clause', 'children': ['62']},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'call', 'children': ['65', '77']},{'id': '65', 'type': 'attribute', 'children': ['66', '76']},{'id': '66', 'type': 'subscript', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'parents'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '82', 'type': 'list', 'children': [], 'value': '[]'},{'id': '83', 'type': 'for_statement', 'children': ['84', '85', '86']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '86', 'type': 'block', 'children': ['87']},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'augmented_assignment', 'children': ['89', '90'], 'value': '+='},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '92', 'type': 'argument_list', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '94', 'type': 'keyword_argument', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '96', 'type': 'lambda', 'children': ['97', '99']},{'id': '97', 'type': 'lambda_parameters', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '99', 'type': 'call', 'children': ['100', '107']},{'id': '100', 'type': 'attribute', 'children': ['101', '106']},{'id': '101', 'type': 'attribute', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'contents'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '109', 'type': 'return_statement', 'children': ['110']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'array'}
def _sort_results(self, results): parents = [] groups = [] for result in results: if not self._in_list(parents, result.parent): parents.append(result.parent) groups.append([]) groups[len(groups) - 1].append(result) else: groups[parents.index(result.parent)].append(result) array = [] for group in groups: array += sorted( group, key=lambda element: element.parent.contents.index(element) ) return array
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_update_sorting'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '12', '18', '24', '30', '82', '92', '107']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'sorted_tops'},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'sorted_tops'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'tops'},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'tops'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'iterators'},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'iterators'},{'id': '30', 'type': 'for_statement', 'children': ['31', '32', '35']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'idxs'},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'try_statement', 'children': ['37', '78']},{'id': '37', 'type': 'block', 'children': ['38', '49', '58', '69']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '43']},{'id': '40', 'type': 'subscript', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'tops'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'next'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'subscript', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'iterators'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'top_key'},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'subscript', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'tops'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '58', 'type': 'if_statement', 'children': ['59', '62']},{'id': '59', 'type': 'comparison_operator', 'children': ['60', '61'], 'value': 'not'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'top_key'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'sorted_tops'},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '68']},{'id': '65', 'type': 'subscript', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'sorted_tops'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'top_key'},{'id': '68', 'type': 'list', 'children': [], 'value': '[]'},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '76']},{'id': '71', 'type': 'attribute', 'children': ['72', '75']},{'id': '72', 'type': 'subscript', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'sorted_tops'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'top_key'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '78', 'type': 'except_clause', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'StopIteration'},{'id': '80', 'type': 'block', 'children': ['81']},{'id': '81', 'type': 'pass_statement', 'children': []},{'id': '82', 'type': 'if_statement', 'children': ['83', '89']},{'id': '83', 'type': 'comparison_operator', 'children': ['84', '88'], 'value': '=='},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'sorted_tops'},{'id': '88', 'type': 'integer', 'children': [], 'value': '0'},{'id': '89', 'type': 'block', 'children': ['90']},{'id': '90', 'type': 'raise_statement', 'children': ['91']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'StopIteration'},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '99']},{'id': '94', 'type': 'pattern_list', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'idxs'},{'id': '99', 'type': 'call', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'sorted_tops'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'popitem'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'keyword_argument', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'last'},{'id': '106', 'type': 'False', 'children': []},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'c_idx'},{'id': '112', 'type': 'integer', 'children': [], 'value': '0'}
def _update_sorting(self): key = self.key sorted_tops = self.sorted_tops tops = self.tops iterators = self.iterators for idx in self.idxs: try: tops[idx] = next(iterators[idx]) top_key = key(tops[idx]) if top_key not in sorted_tops: sorted_tops[top_key] = [] sorted_tops[top_key].append(idx) except StopIteration: pass if len(sorted_tops) == 0: raise StopIteration key, self.idxs = sorted_tops.popitem(last=False) self.c_idx = 0
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'domain_user_stats'},{'id': '3', 'type': 'parameters', 'children': []},{'id': '4', 'type': 'block', 'children': ['5', '24', '42']},{'id': '5', 'type': 'expression_statement', 'children': ['6']},{'id': '6', 'type': 'assignment', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'fname'},{'id': '8', 'type': 'call', 'children': ['9', '14']},{'id': '9', 'type': 'attribute', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '14', 'type': 'argument_list', 'children': ['15', '23']},{'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': 'os'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'dirname'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': '__file__'},{'id': '23', 'type': 'string', 'children': [], 'value': '"email_domain_users.csv"'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'stats'},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'read_csv'},{'id': '31', 'type': 'argument_list', 'children': ['32', '33', '36', '39']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'fname'},{'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '35', 'type': 'integer', 'children': [], 'value': '0'},{'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'squeeze'},{'id': '38', 'type': 'True', 'children': []},{'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'index_col'},{'id': '41', 'type': 'integer', 'children': [], 'value': '0'},{'id': '42', 'type': 'return_statement', 'children': ['43']},{'id': '43', 'type': 'subscript', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'stats'},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'notnull'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'stats'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'index'}
def domain_user_stats(): fname = os.path.join(os.path.dirname(__file__), "email_domain_users.csv") stats = pd.read_csv(fname, header=0, squeeze=True, index_col=0) return stats[pd.notnull(stats.index)]
{'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', '10', '20', '33', '76', '93', '109', '156', '178']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'sorted_graph'},{'id': '9', 'type': 'list', 'children': [], 'value': '[]'},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'node_map'},{'id': '13', 'type': 'call', 'children': ['14', '19']},{'id': '14', 'type': 'attribute', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': '_graph'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'get_nodes'},{'id': '19', 'type': 'argument_list', 'children': []},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '23', 'type': 'list_comprehension', 'children': ['24', '30']},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'NodeVisitor'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'subscript', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'node_map'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '30', 'type': 'for_in_clause', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'node_map'},{'id': '33', 'type': 'function_definition', 'children': ['34', '35', '37']},{'id': '34', 'type': 'function_name', 'children': [], 'value': 'get_pointers_for_edge_nodes'},{'id': '35', 'type': 'parameters', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'visitor_decorated_node'},{'id': '37', 'type': 'block', 'children': ['38', '42', '54', '74']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '41', 'type': 'list', 'children': [], 'value': '[]'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'edge_ids'},{'id': '45', 'type': 'call', 'children': ['46', '53']},{'id': '46', 'type': 'attribute', 'children': ['47', '52']},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'visitor_decorated_node'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'get_node'},{'id': '51', 'type': 'argument_list', 'children': []},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'get_edges'},{'id': '53', 'type': 'argument_list', 'children': []},{'id': '54', 'type': 'for_statement', 'children': ['55', '56', '57']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'if_statement', 'children': ['59', '66']},{'id': '59', 'type': 'comparison_operator', 'children': ['60', '65'], 'value': 'in'},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'get_id'},{'id': '64', 'type': 'argument_list', 'children': []},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'edge_ids'},{'id': '66', 'type': 'block', 'children': ['67']},{'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': 'edges'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '74', 'type': 'return_statement', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '76', 'type': 'for_statement', 'children': ['77', '78', '79']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'for_statement', 'children': ['81', '82', '86']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'edge'},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'get_pointers_for_edge_nodes'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '86', 'type': 'block', 'children': ['87']},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'call', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'edge'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'increment'},{'id': '92', 'type': 'argument_list', 'children': []},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'resolved'},{'id': '96', 'type': 'list_comprehension', 'children': ['97', '98', '101']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '98', 'type': 'for_in_clause', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '101', 'type': 'if_clause', 'children': ['102']},{'id': '102', 'type': 'comparison_operator', 'children': ['103', '108'], 'value': '=='},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'get_weight'},{'id': '107', 'type': 'argument_list', 'children': []},{'id': '108', 'type': 'integer', 'children': [], 'value': '0'},{'id': '109', 'type': 'while_statement', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'resolved'},{'id': '111', 'type': 'block', 'children': ['112', '120', '127']},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '115', 'type': 'call', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'resolved'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '119', 'type': 'argument_list', 'children': []},{'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': 'sorted_graph'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '127', 'type': 'for_statement', 'children': ['128', '129', '133']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'edge'},{'id': '129', 'type': 'call', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'get_pointers_for_edge_nodes'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '133', 'type': 'block', 'children': ['134', '140']},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'edge'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'decrement'},{'id': '139', 'type': 'argument_list', 'children': []},{'id': '140', 'type': 'if_statement', 'children': ['141', '148']},{'id': '141', 'type': 'comparison_operator', 'children': ['142', '147'], 'value': '=='},{'id': '142', 'type': 'call', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'edge'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'get_weight'},{'id': '146', 'type': 'argument_list', 'children': []},{'id': '147', 'type': 'integer', 'children': [], 'value': '0'},{'id': '148', 'type': 'block', 'children': ['149']},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'call', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'resolved'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'edge'},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'assignment', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '160', 'type': 'identifier', 'children': [], 'value': '_circular_dependencies'},{'id': '161', 'type': 'list_comprehension', 'children': ['162', '167', '170']},{'id': '162', 'type': 'call', 'children': ['163', '166']},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'get_node'},{'id': '166', 'type': 'argument_list', 'children': []},{'id': '167', 'type': 'for_in_clause', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '170', 'type': 'if_clause', 'children': ['171']},{'id': '171', 'type': 'comparison_operator', 'children': ['172', '177'], 'value': '>'},{'id': '172', 'type': 'call', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'get_weight'},{'id': '176', 'type': 'argument_list', 'children': []},{'id': '177', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'self'},{'id': '182', 'type': 'identifier', 'children': [], 'value': '_sorted_nodes'},{'id': '183', 'type': 'call', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '185', 'type': 'argument_list', 'children': ['186']},{'id': '186', 'type': 'call', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'reversed'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'list_comprehension', 'children': ['190', '195']},{'id': '190', 'type': 'call', 'children': ['191', '194']},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'get_node'},{'id': '194', 'type': 'argument_list', 'children': []},{'id': '195', 'type': 'for_in_clause', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'sorted_graph'}
def _topological_sort(self): sorted_graph = [] node_map = self._graph.get_nodes() nodes = [NodeVisitor(node_map[node]) for node in node_map] def get_pointers_for_edge_nodes(visitor_decorated_node): edges = [] edge_ids = visitor_decorated_node.get_node().get_edges() for node in nodes: if node.get_id() in edge_ids: edges.append(node) return edges for node in nodes: for edge in get_pointers_for_edge_nodes(node): edge.increment() resolved = [node for node in nodes if node.get_weight() == 0] while resolved: node = resolved.pop() sorted_graph.append(node) for edge in get_pointers_for_edge_nodes(node): edge.decrement() if edge.get_weight() == 0: resolved.append(edge) self._circular_dependencies = [ node.get_node() for node in nodes if node.get_weight() > 0] self._sorted_nodes = list(reversed( [node.get_node() for node in sorted_graph]))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'plugins'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '11', '18', '29', '41']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'string', 'children': [], 'value': '\'\'\'\n Returns a `PluginSet` object for the specified setuptools-style\n entrypoint `group`. This is just a wrapper around\n `pkg_resources.iter_entry_points` that allows the plugins to sort\n and override themselves.\n The optional `spec` parameter controls how and what plugins are\n loaded. If it is ``None`` or the special value ``\'*\'``, then the\n normal plugin loading will occur, i.e. all registered plugins will\n be loaded and their self-declared ordering and dependencies will be\n applied.\n Otherwise, the `spec` is taken as a comma- or whitespace-separated\n list of plugins to load. In this mode, the `spec` can either specify\n an exact list of plugins to load, in the specified order, referred\n to as an "absolute" spec. Otherwise, it is a "relative" spec, which\n indicates that it only adjusts the standard registered plugin\n loading. A spec is a list of either absolute or relative\n instructions, and they cannot be mixed.\n In either mode, a plugin is identified either by name for registered\n plugins (e.g. ``foo``), or by fully-qualified Python module and\n symbol name for unregistered plugins\n (e.g. ``package.module.symbol``).\n Plugins in an absolute spec are loaded in the order specified and\n can be optionally prefixed with the following special characters:\n * ``\'?\'`` : the specified plugin should be loaded if available. If\n it is not registered, cannot be found, or cannot be loaded, then\n it is ignored (a DEBUG log message will be emitted, however).\n Plugins in a relative spec are always prefixed with at least one of\n the following special characters:\n * ``\'-\'`` : removes the specified plugin; this does not affect\n plugin ordering, it only removes the plugin from the loaded\n list. If the plugin does not exist, no error is thrown.\n * ``\'+\'`` : adds or requires the specified plugin to the loaded\n set. If the plugin is not a named/registered plugin, then it will\n be loaded as an asset-symbol, i.e. a Python-dotted module and\n symbol name. If the plugin does not exist or cannot be loaded,\n this will throw an error. It does not affect the plugin ordering\n of registered plugins.\n * ``\'/\'`` : the plugin name is taken as a regular expression that\n will be used to match plugin names and it must terminate in a\n slash. Note that this must be the **last** element in the spec\n list.\n Examples:\n * ``\'*\'`` : load all registered plugins.\n * ``\'foo,bar\'`` : load the "foo" plugin, then the "bar" plugin.\n * ``\'foo,?bar\'`` : load the "foo" plugin and if the "bar" plugin\n exists, load it too.\n * ``\'-zig\'`` : load all registered plugins except the "zig" plugin.\n * ``\'+pkg.foo.bar\'`` : load all registered plugins and then load\n the "pkg.foo.bar" Python symbol.\n * ``\'pkg.foo.bar\'`` : load only the "pkg.foo.bar" Python symbol.\n \'\'\''},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'pspec'},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': '_parse_spec'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'plugs'},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': '_get_registered_plugins'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'pspec'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'augmented_assignment', 'children': ['31', '32'], 'value': '+='},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'plugs'},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': '_get_unregistered_plugins'},{'id': '37', 'type': 'argument_list', 'children': ['38', '39', '40']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'plugs'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'pspec'},{'id': '41', 'type': 'return_statement', 'children': ['42']},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'PluginSet'},{'id': '44', 'type': 'argument_list', 'children': ['45', '46', '47']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': '_sort_plugins'},{'id': '52', 'type': 'argument_list', 'children': ['53', '54', '55', '56']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'plugs'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'pspec'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'spec'}
def plugins(group, spec=None): ''' Returns a `PluginSet` object for the specified setuptools-style entrypoint `group`. This is just a wrapper around `pkg_resources.iter_entry_points` that allows the plugins to sort and override themselves. The optional `spec` parameter controls how and what plugins are loaded. If it is ``None`` or the special value ``'*'``, then the normal plugin loading will occur, i.e. all registered plugins will be loaded and their self-declared ordering and dependencies will be applied. Otherwise, the `spec` is taken as a comma- or whitespace-separated list of plugins to load. In this mode, the `spec` can either specify an exact list of plugins to load, in the specified order, referred to as an "absolute" spec. Otherwise, it is a "relative" spec, which indicates that it only adjusts the standard registered plugin loading. A spec is a list of either absolute or relative instructions, and they cannot be mixed. In either mode, a plugin is identified either by name for registered plugins (e.g. ``foo``), or by fully-qualified Python module and symbol name for unregistered plugins (e.g. ``package.module.symbol``). Plugins in an absolute spec are loaded in the order specified and can be optionally prefixed with the following special characters: * ``'?'`` : the specified plugin should be loaded if available. If it is not registered, cannot be found, or cannot be loaded, then it is ignored (a DEBUG log message will be emitted, however). Plugins in a relative spec are always prefixed with at least one of the following special characters: * ``'-'`` : removes the specified plugin; this does not affect plugin ordering, it only removes the plugin from the loaded list. If the plugin does not exist, no error is thrown. * ``'+'`` : adds or requires the specified plugin to the loaded set. If the plugin is not a named/registered plugin, then it will be loaded as an asset-symbol, i.e. a Python-dotted module and symbol name. If the plugin does not exist or cannot be loaded, this will throw an error. It does not affect the plugin ordering of registered plugins. * ``'/'`` : the plugin name is taken as a regular expression that will be used to match plugin names and it must terminate in a slash. Note that this must be the **last** element in the spec list. Examples: * ``'*'`` : load all registered plugins. * ``'foo,bar'`` : load the "foo" plugin, then the "bar" plugin. * ``'foo,?bar'`` : load the "foo" plugin and if the "bar" plugin exists, load it too. * ``'-zig'`` : load all registered plugins except the "zig" plugin. * ``'+pkg.foo.bar'`` : load all registered plugins and then load the "pkg.foo.bar" Python symbol. * ``'pkg.foo.bar'`` : load only the "pkg.foo.bar" Python symbol. ''' pspec = _parse_spec(spec) plugs = list(_get_registered_plugins(group, pspec)) plugs += list(_get_unregistered_plugins(group, plugs, pspec)) return PluginSet(group, spec, list(_sort_plugins(group, plugs, pspec, spec)))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'match_any_string'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'strings'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '8', 'type': 'integer', 'children': [], 'value': '0'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '11', 'type': 'integer', 'children': [], 'value': '0'},{'id': '12', 'type': 'block', 'children': ['13', '32', '36', '40', '44', '77']},{'id': '13', 'type': 'if_statement', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '15', 'type': 'block', 'children': ['16', '25']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'current'},{'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_string'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '25', 'type': 'return_statement', 'children': ['26']},{'id': '26', 'type': 'conditional_expression', 'children': ['27', '28', '31'], 'value': 'if'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': 'in'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'strings'},{'id': '31', 'type': 'string', 'children': [], 'value': "''"},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '35', 'type': 'string', 'children': [], 'value': "''"},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'currentlength'},{'id': '39', 'type': 'integer', 'children': [], 'value': '0'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '43', 'type': 'integer', 'children': [], 'value': '0'},{'id': '44', 'type': 'for_statement', 'children': ['45', '46', '47']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'string'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'strings'},{'id': '47', 'type': 'block', 'children': ['48', '55', '70']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'string'},{'id': '55', 'type': 'if_statement', 'children': ['56', '59']},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': '!='},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'currentlength'},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '63', 'type': 'call', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'get_length'},{'id': '67', 'type': 'argument_list', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '70', 'type': 'if_statement', 'children': ['71', '74']},{'id': '71', 'type': 'comparison_operator', 'children': ['72', '73'], 'value': '=='},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'string'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '74', 'type': 'block', 'children': ['75']},{'id': '75', 'type': 'return_statement', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'string'},{'id': '77', 'type': 'return_statement', 'children': ['78']},{'id': '78', 'type': 'string', 'children': [], 'value': "''"}
def match_any_string(self, strings, word=0, offset=0): if word: current = self.get_string(offset) return current if current in strings else '' current = '' currentlength = 0 length = 0 for string in strings: length = len(string) if length != currentlength: current = self.get_length(length, offset) if string == current: return string return ''
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'decide_which_users_to_annotate'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'centrality_vector'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'number_to_annotate'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'already_annotated'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'node_to_id'},{'id': '8', 'type': 'block', 'children': ['9', '18', '32', '66', '72', '78', '82', '112']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'centrality_vector'},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'asarray'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'centrality_vector'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'ind'},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'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': 'squeeze'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'centrality_vector'},{'id': '32', 'type': 'if_statement', 'children': ['33', '38', '49']},{'id': '33', 'type': 'comparison_operator', 'children': ['34', '37'], 'value': '>'},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'centrality_vector'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '37', 'type': 'integer', 'children': [], 'value': '1'},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'reversed_ind'},{'id': '42', 'type': 'subscript', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'ind'},{'id': '44', 'type': 'slice', 'children': ['45', '46', '47']},{'id': '45', 'type': 'colon', 'children': []},{'id': '46', 'type': 'colon', 'children': []},{'id': '47', 'type': 'unary_operator', 'children': ['48'], 'value': '-'},{'id': '48', 'type': 'integer', 'children': [], 'value': '1'},{'id': '49', 'type': 'else_clause', 'children': ['50']},{'id': '50', 'type': 'block', 'children': ['51', '57']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'reversed_ind'},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '56', 'type': 'argument_list', 'children': []},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'reversed_ind'},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'reversed_ind'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'ind'},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'user_id_list'},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '71', 'type': 'argument_list', 'children': []},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'append_user_id'},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'user_id_list'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'counter'},{'id': '81', 'type': 'integer', 'children': [], 'value': '0'},{'id': '82', 'type': 'for_statement', 'children': ['83', '84', '85']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'reversed_ind'},{'id': '85', 'type': 'block', 'children': ['86', '92']},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'user_twitter_id'},{'id': '89', 'type': 'subscript', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'node_to_id'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '92', 'type': 'if_statement', 'children': ['93', '96']},{'id': '93', 'type': 'comparison_operator', 'children': ['94', '95'], 'value': 'not'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'user_twitter_id'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'already_annotated'},{'id': '96', 'type': 'block', 'children': ['97', '102', '106']},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'append_user_id'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'user_twitter_id'},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'augmented_assignment', 'children': ['104', '105'], 'value': '+='},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'counter'},{'id': '105', 'type': 'integer', 'children': [], 'value': '1'},{'id': '106', 'type': 'if_statement', 'children': ['107', '110']},{'id': '107', 'type': 'comparison_operator', 'children': ['108', '109'], 'value': '>='},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'counter'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'number_to_annotate'},{'id': '110', 'type': 'block', 'children': ['111']},{'id': '111', 'type': 'break_statement', 'children': []},{'id': '112', 'type': 'return_statement', 'children': ['113']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'user_id_list'}
def decide_which_users_to_annotate(centrality_vector, number_to_annotate, already_annotated, node_to_id): centrality_vector = np.asarray(centrality_vector) ind = np.argsort(np.squeeze(centrality_vector)) if centrality_vector.size > 1: reversed_ind = ind[::-1] else: reversed_ind = list() reversed_ind = reversed_ind.append(ind) user_id_list = list() append_user_id = user_id_list.append counter = 0 for node in reversed_ind: user_twitter_id = node_to_id[node] if user_twitter_id not in already_annotated: append_user_id(user_twitter_id) counter += 1 if counter >= number_to_annotate: break return user_id_list
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '27']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'search'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '24']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'sort_map'},{'id': '8', 'type': 'dictionary', 'children': ['9', '12', '15', '18', '21']},{'id': '9', 'type': 'pair', 'children': ['10', '11']},{'id': '10', 'type': 'string', 'children': [], 'value': "'BoxSet'"},{'id': '11', 'type': 'integer', 'children': [], 'value': '0'},{'id': '12', 'type': 'pair', 'children': ['13', '14']},{'id': '13', 'type': 'string', 'children': [], 'value': "'Series'"},{'id': '14', 'type': 'integer', 'children': [], 'value': '1'},{'id': '15', 'type': 'pair', 'children': ['16', '17']},{'id': '16', 'type': 'string', 'children': [], 'value': "'Movie'"},{'id': '17', 'type': 'integer', 'children': [], 'value': '2'},{'id': '18', 'type': 'pair', 'children': ['19', '20']},{'id': '19', 'type': 'string', 'children': [], 'value': "'Audio'"},{'id': '20', 'type': 'integer', 'children': [], 'value': '3'},{'id': '21', 'type': 'pair', 'children': ['22', '23']},{'id': '22', 'type': 'string', 'children': [], 'value': "'Person'"},{'id': '23', 'type': 'integer', 'children': [], 'value': '4'},{'id': '24', 'type': 'default_parameter', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'strict_sort'},{'id': '26', 'type': 'False', 'children': []},{'id': '27', 'type': 'block', 'children': ['28', '30', '40', '58', '72', '84', '91', '112']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'string', 'children': [], 'value': "'''Sends a search request to emby, returns results\n |coro|\n Parameters\n ----------\n query : str\n the search string to send to emby\n sort_map : dict\n is a dict of strings to ints. Strings should be item types, and\n the ints are the priority of those types(for sorting).\n lower valued(0) will appear first.\n strict_sort : bool\n if True, then only item types in the keys of sortmap will be\n included in the results\n Returns\n -------\n list\n list of emby objects\n '''"},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'search_params'},{'id': '33', 'type': 'dictionary', 'children': ['34', '37']},{'id': '34', 'type': 'pair', 'children': ['35', '36']},{'id': '35', 'type': 'string', 'children': [], 'value': "'remote'"},{'id': '36', 'type': 'False', 'children': []},{'id': '37', 'type': 'pair', 'children': ['38', '39']},{'id': '38', 'type': 'string', 'children': [], 'value': "'searchTerm'"},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '40', 'type': 'if_statement', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'strict_sort'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '48']},{'id': '45', 'type': 'subscript', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'search_params'},{'id': '47', 'type': 'string', 'children': [], 'value': "'IncludeItemTypes'"},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'string', 'children': [], 'value': "','"},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'sort_map'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '57', 'type': 'argument_list', 'children': []},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '61', 'type': 'await', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '68']},{'id': '63', 'type': 'attribute', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'connector'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'getJson'},{'id': '68', 'type': 'argument_list', 'children': ['69', '70']},{'id': '69', 'type': 'string', 'children': [], 'value': "'/Search/Hints/'"},{'id': '70', 'type': 'dictionary_splat', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'search_params'},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '75', 'type': 'await', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'process'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'subscript', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '83', 'type': 'string', 'children': [], 'value': '"SearchHints"'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'm_size'},{'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': 'sort_map'},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '94', 'type': 'call', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '96', 'type': 'argument_list', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '98', 'type': 'keyword_argument', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '100', 'type': 'lambda', 'children': ['101', '103']},{'id': '101', 'type': 'lambda_parameters', 'children': ['102']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'sort_map'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '107', 'type': 'argument_list', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'm_size'},{'id': '112', 'type': 'return_statement', 'children': ['113']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'items'}
async def search(self, query, sort_map = {'BoxSet':0,'Series':1,'Movie':2,'Audio':3,'Person':4}, strict_sort = False): '''Sends a search request to emby, returns results |coro| Parameters ---------- query : str the search string to send to emby sort_map : dict is a dict of strings to ints. Strings should be item types, and the ints are the priority of those types(for sorting). lower valued(0) will appear first. strict_sort : bool if True, then only item types in the keys of sortmap will be included in the results Returns ------- list list of emby objects ''' search_params = { 'remote' : False, 'searchTerm' : query } if strict_sort: search_params['IncludeItemTypes'] = ','.join(sort_map.keys()) json = await self.connector.getJson('/Search/Hints/', **search_params) items = await self.process(json["SearchHints"]) m_size = len(sort_map) items = sorted(items, key = lambda x : sort_map.get(x.type, m_size)) return items
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'set_attribute_string'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '7', 'type': 'block', 'children': ['8']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'set_attribute'},{'id': '11', 'type': 'argument_list', 'children': ['12', '13', '14']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '14', 'type': 'call', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'bytes_'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'value'}
def set_attribute_string(target, name, value): set_attribute(target, name, np.bytes_(value))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '__calculate_edge_weights'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'dfs_data'},{'id': '5', 'type': 'block', 'children': ['6', '12', '16', '38']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '9', 'type': 'subscript', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'dfs_data'},{'id': '11', 'type': 'string', 'children': [], 'value': "'graph'"},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '15', 'type': 'dictionary', 'children': []},{'id': '16', 'type': 'for_statement', 'children': ['17', '18', '23']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'edge_id'},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'get_all_edge_ids'},{'id': '22', 'type': 'argument_list', 'children': []},{'id': '23', 'type': 'block', 'children': ['24', '32']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'edge_weight'},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': '__edge_weight'},{'id': '29', 'type': 'argument_list', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'edge_id'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'dfs_data'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '37']},{'id': '34', 'type': 'subscript', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'edge_id'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'edge_weight'},{'id': '38', 'type': 'return_statement', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'weights'}
def __calculate_edge_weights(dfs_data): graph = dfs_data['graph'] weights = {} for edge_id in graph.get_all_edge_ids(): edge_weight = __edge_weight(edge_id, dfs_data) weights[edge_id] = edge_weight return weights
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '__sort_adjacency_lists'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'dfs_data'},{'id': '5', 'type': 'block', 'children': ['6', '10', '16', '22', '28', '121']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'new_adjacency_lists'},{'id': '9', 'type': 'dictionary', 'children': []},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'adjacency_lists'},{'id': '13', 'type': 'subscript', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'dfs_data'},{'id': '15', 'type': 'string', 'children': [], 'value': "'adj'"},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'edge_weights'},{'id': '19', 'type': 'subscript', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'dfs_data'},{'id': '21', 'type': 'string', 'children': [], 'value': "'edge_weights'"},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'edge_lookup'},{'id': '25', 'type': 'subscript', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'dfs_data'},{'id': '27', 'type': 'string', 'children': [], 'value': "'edge_lookup'"},{'id': '28', 'type': 'for_statement', 'children': ['29', '32', '40']},{'id': '29', 'type': 'pattern_list', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'adj_list'},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'adjacency_lists'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '39', 'type': 'argument_list', 'children': []},{'id': '40', 'type': 'block', 'children': ['41', '45', '49', '86', '101', '115']},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'node_weight_lookup'},{'id': '44', 'type': 'dictionary', 'children': []},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'frond_lookup'},{'id': '48', 'type': 'dictionary', 'children': []},{'id': '49', 'type': 'for_statement', 'children': ['50', '51', '52']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'node_b'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'adj_list'},{'id': '52', 'type': 'block', 'children': ['53', '65', '73']},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'edge_id'},{'id': '56', 'type': 'call', 'children': ['57', '62']},{'id': '57', 'type': 'attribute', 'children': ['58', '61']},{'id': '58', 'type': 'subscript', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'dfs_data'},{'id': '60', 'type': 'string', 'children': [], 'value': "'graph'"},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'get_first_edge_id_by_node_ids'},{'id': '62', 'type': 'argument_list', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'node_b'},{'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': 'node_weight_lookup'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'node_b'},{'id': '70', 'type': 'subscript', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'edge_weights'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'edge_id'},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '78']},{'id': '75', 'type': 'subscript', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'frond_lookup'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'node_b'},{'id': '78', 'type': 'conditional_expression', 'children': ['79', '80', '85'], 'value': 'if'},{'id': '79', 'type': 'integer', 'children': [], 'value': '1'},{'id': '80', 'type': 'comparison_operator', 'children': ['81', '84'], 'value': '=='},{'id': '81', 'type': 'subscript', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'edge_lookup'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'edge_id'},{'id': '84', 'type': 'string', 'children': [], 'value': "'backedge'"},{'id': '85', 'type': 'integer', 'children': [], 'value': '2'},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'new_list'},{'id': '89', 'type': 'call', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '91', 'type': 'argument_list', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'adj_list'},{'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '95', 'type': 'lambda', 'children': ['96', '98']},{'id': '96', 'type': 'lambda_parameters', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '98', 'type': 'subscript', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'frond_lookup'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'n'},{'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': 'new_list'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'keyword_argument', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '109', 'type': 'lambda', 'children': ['110', '112']},{'id': '110', 'type': 'lambda_parameters', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '112', 'type': 'subscript', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'node_weight_lookup'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '120']},{'id': '117', 'type': 'subscript', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'new_adjacency_lists'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'new_list'},{'id': '121', 'type': 'return_statement', 'children': ['122']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'new_adjacency_lists'}
def __sort_adjacency_lists(dfs_data): new_adjacency_lists = {} adjacency_lists = dfs_data['adj'] edge_weights = dfs_data['edge_weights'] edge_lookup = dfs_data['edge_lookup'] for node_id, adj_list in list(adjacency_lists.items()): node_weight_lookup = {} frond_lookup = {} for node_b in adj_list: edge_id = dfs_data['graph'].get_first_edge_id_by_node_ids(node_id, node_b) node_weight_lookup[node_b] = edge_weights[edge_id] frond_lookup[node_b] = 1 if edge_lookup[edge_id] == 'backedge' else 2 new_list = sorted(adj_list, key=lambda n: frond_lookup[n]) new_list.sort(key=lambda n: node_weight_lookup[n]) new_adjacency_lists[node_id] = new_list return new_adjacency_lists
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '__edge_weight'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'edge_id'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'dfs_data'},{'id': '6', 'type': 'block', 'children': ['7', '13', '19', '28', '36', '44', '52', '60', '68']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '10', 'type': 'subscript', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'dfs_data'},{'id': '12', 'type': 'string', 'children': [], 'value': "'graph'"},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'edge_lookup'},{'id': '16', 'type': 'subscript', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'dfs_data'},{'id': '18', 'type': 'string', 'children': [], 'value': "'edge_lookup'"},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'edge'},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'get_edge'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'edge_id'},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '33']},{'id': '30', 'type': 'pattern_list', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '33', 'type': 'subscript', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'edge'},{'id': '35', 'type': 'string', 'children': [], 'value': "'vertices'"},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'd_u'},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'D'},{'id': '41', 'type': 'argument_list', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'dfs_data'},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'd_v'},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'D'},{'id': '49', 'type': 'argument_list', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'dfs_data'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'lp_1'},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'L1'},{'id': '57', 'type': 'argument_list', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'dfs_data'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'd_lp_1'},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'D'},{'id': '65', 'type': 'argument_list', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'lp_1'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'dfs_data'},{'id': '68', 'type': 'if_statement', 'children': ['69', '78', '83', '95', '109']},{'id': '69', 'type': 'boolean_operator', 'children': ['70', '75'], 'value': 'and'},{'id': '70', 'type': 'comparison_operator', 'children': ['71', '74'], 'value': '=='},{'id': '71', 'type': 'subscript', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'edge_lookup'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'edge_id'},{'id': '74', 'type': 'string', 'children': [], 'value': "'backedge'"},{'id': '75', 'type': 'comparison_operator', 'children': ['76', '77'], 'value': '<'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'd_v'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'd_u'},{'id': '78', 'type': 'block', 'children': ['79']},{'id': '79', 'type': 'return_statement', 'children': ['80']},{'id': '80', 'type': 'binary_operator', 'children': ['81', '82'], 'value': '*'},{'id': '81', 'type': 'integer', 'children': [], 'value': '2'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'd_v'},{'id': '83', 'type': 'elif_clause', 'children': ['84', '90']},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'is_type_I_branch'},{'id': '86', 'type': 'argument_list', 'children': ['87', '88', '89']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'dfs_data'},{'id': '90', 'type': 'block', 'children': ['91']},{'id': '91', 'type': 'return_statement', 'children': ['92']},{'id': '92', 'type': 'binary_operator', 'children': ['93', '94'], 'value': '*'},{'id': '93', 'type': 'integer', 'children': [], 'value': '2'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'd_lp_1'},{'id': '95', 'type': 'elif_clause', 'children': ['96', '102']},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'is_type_II_branch'},{'id': '98', 'type': 'argument_list', 'children': ['99', '100', '101']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'dfs_data'},{'id': '102', 'type': 'block', 'children': ['103']},{'id': '103', 'type': 'return_statement', 'children': ['104']},{'id': '104', 'type': 'binary_operator', 'children': ['105', '108'], 'value': '+'},{'id': '105', 'type': 'binary_operator', 'children': ['106', '107'], 'value': '*'},{'id': '106', 'type': 'integer', 'children': [], 'value': '2'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'd_lp_1'},{'id': '108', 'type': 'integer', 'children': [], 'value': '1'},{'id': '109', 'type': 'else_clause', 'children': ['110']},{'id': '110', 'type': 'block', 'children': ['111']},{'id': '111', 'type': 'return_statement', 'children': ['112']},{'id': '112', 'type': 'binary_operator', 'children': ['113', '120'], 'value': '+'},{'id': '113', 'type': 'binary_operator', 'children': ['114', '115'], 'value': '*'},{'id': '114', 'type': 'integer', 'children': [], 'value': '2'},{'id': '115', 'type': 'call', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'num_nodes'},{'id': '119', 'type': 'argument_list', 'children': []},{'id': '120', 'type': 'integer', 'children': [], 'value': '1'}
def __edge_weight(edge_id, dfs_data): graph = dfs_data['graph'] edge_lookup = dfs_data['edge_lookup'] edge = graph.get_edge(edge_id) u, v = edge['vertices'] d_u = D(u, dfs_data) d_v = D(v, dfs_data) lp_1 = L1(v, dfs_data) d_lp_1 = D(lp_1, dfs_data) if edge_lookup[edge_id] == 'backedge' and d_v < d_u: return 2*d_v elif is_type_I_branch(u, v, dfs_data): return 2*d_lp_1 elif is_type_II_branch(u, v, dfs_data): return 2*d_lp_1 + 1 else: return 2*graph.num_nodes() + 1
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'classify_segmented_recording'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'recording'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'result_format'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '11', '22']},{'id': '9', 'type': 'global_statement', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'single_symbol_classifier'},{'id': '11', 'type': 'if_statement', 'children': ['12', '15']},{'id': '12', 'type': 'comparison_operator', 'children': ['13', '14'], 'value': 'is'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'single_symbol_classifier'},{'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': 'single_symbol_classifier'},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'SingleClassificer'},{'id': '21', 'type': 'argument_list', 'children': []},{'id': '22', 'type': 'return_statement', 'children': ['23']},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'single_symbol_classifier'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'predict'},{'id': '27', 'type': 'argument_list', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'recording'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'result_format'}
def classify_segmented_recording(recording, result_format=None): global single_symbol_classifier if single_symbol_classifier is None: single_symbol_classifier = SingleClassificer() return single_symbol_classifier.predict(recording, result_format)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_by_formula_id'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'raw_datasets'},{'id': '5', 'type': 'block', 'children': ['6', '13', '32']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'by_formula_id'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '13', 'type': 'for_statement', 'children': ['14', '15', '16']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'raw_datasets'},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'call', 'children': ['19', '28']},{'id': '19', 'type': 'attribute', 'children': ['20', '27']},{'id': '20', 'type': 'subscript', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'by_formula_id'},{'id': '22', 'type': 'attribute', 'children': ['23', '26']},{'id': '23', 'type': 'subscript', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '25', 'type': 'string', 'children': [], 'value': "'handwriting'"},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'formula_id'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'subscript', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '31', 'type': 'string', 'children': [], 'value': "'handwriting'"},{'id': '32', 'type': 'return_statement', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'by_formula_id'}
def sort_by_formula_id(raw_datasets): by_formula_id = defaultdict(list) for el in raw_datasets: by_formula_id[el['handwriting'].formula_id].append(el['handwriting']) return by_formula_id
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_sorted_pointlist'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '14', '43', '60']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'pointlist'},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'get_pointlist'},{'id': '13', 'type': 'argument_list', 'children': []},{'id': '14', 'type': 'for_statement', 'children': ['15', '16', '23']},{'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': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'pointlist'},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '29']},{'id': '26', 'type': 'subscript', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'pointlist'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '31', 'type': 'argument_list', 'children': ['32', '35']},{'id': '32', 'type': 'subscript', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'pointlist'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '37', 'type': 'lambda', 'children': ['38', '40']},{'id': '38', 'type': 'lambda_parameters', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '40', 'type': 'subscript', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '42', 'type': 'string', 'children': [], 'value': "'time'"},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'pointlist'},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '48', 'type': 'argument_list', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'pointlist'},{'id': '50', 'type': 'keyword_argument', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '52', 'type': 'lambda', 'children': ['53', '55']},{'id': '53', 'type': 'lambda_parameters', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'stroke'},{'id': '55', 'type': 'subscript', 'children': ['56', '59']},{'id': '56', 'type': 'subscript', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'stroke'},{'id': '58', 'type': 'integer', 'children': [], 'value': '0'},{'id': '59', 'type': 'string', 'children': [], 'value': "'time'"},{'id': '60', 'type': 'return_statement', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'pointlist'}
def get_sorted_pointlist(self): pointlist = self.get_pointlist() for i in range(len(pointlist)): pointlist[i] = sorted(pointlist[i], key=lambda p: p['time']) pointlist = sorted(pointlist, key=lambda stroke: stroke[0]['time']) return pointlist
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_name'},{'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': 'use_alias'},{'id': '7', 'type': 'True', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '24', '41']},{'id': '9', 'type': 'if_statement', 'children': ['10', '13', '18']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'desc'},{'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': 'direction'},{'id': '17', 'type': 'string', 'children': [], 'value': "'DESC'"},{'id': '18', 'type': 'else_clause', 'children': ['19']},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '23', 'type': 'string', 'children': [], 'value': "'ASC'"},{'id': '24', 'type': 'if_statement', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'use_alias'},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'return_statement', 'children': ['28']},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'string', 'children': [], 'value': "'{0} {1}'"},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '32', 'type': 'argument_list', 'children': ['33', '40']},{'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': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'get_identifier'},{'id': '39', 'type': 'argument_list', 'children': []},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '41', 'type': 'return_statement', 'children': ['42']},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'string', 'children': [], 'value': "'{0} {1}'"},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '46', 'type': 'argument_list', 'children': ['47', '54']},{'id': '47', 'type': 'call', 'children': ['48', '53']},{'id': '48', 'type': 'attribute', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'get_select_sql'},{'id': '53', 'type': 'argument_list', 'children': []},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'direction'}
def get_name(self, use_alias=True): if self.desc: direction = 'DESC' else: direction = 'ASC' if use_alias: return '{0} {1}'.format(self.field.get_identifier(), direction) return '{0} {1}'.format(self.field.get_select_sql(), direction)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'order_by'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '35']},{'id': '15', 'type': 'expression_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': 'sorters'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'Sorter'},{'id': '25', 'type': 'argument_list', 'children': ['26', '29', '32']},{'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '29', 'type': 'keyword_argument', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '32', 'type': 'keyword_argument', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '35', 'type': 'return_statement', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}
def order_by(self, field=None, table=None, desc=False): self.sorters.append(Sorter( field=field, table=table, desc=desc )) return self
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_by_tag'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '6', 'type': 'block', 'children': ['7']},{'id': '7', 'type': 'return_statement', 'children': ['8']},{'id': '8', 'type': 'call', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'AmpalContainer'},{'id': '10', 'type': 'argument_list', 'children': ['11']},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '13', 'type': 'argument_list', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '15', 'type': 'keyword_argument', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '17', 'type': 'lambda', 'children': ['18', '20']},{'id': '18', 'type': 'lambda_parameters', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '20', 'type': 'subscript', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'tags'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'tag'}
def sort_by_tag(self, tag): return AmpalContainer(sorted(self, key=lambda x: x.tags[tag]))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'fit_heptad_register'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'crangles'},{'id': '5', 'type': 'block', 'children': ['6', '21', '45', '70', '79', '88', '92', '146']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'crangles'},{'id': '9', 'type': 'list_comprehension', 'children': ['10', '18']},{'id': '10', 'type': 'conditional_expression', 'children': ['11', '12', '15'], 'value': 'if'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '12', 'type': 'comparison_operator', 'children': ['13', '14'], 'value': '>'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '14', 'type': 'integer', 'children': [], 'value': '0'},{'id': '15', 'type': 'binary_operator', 'children': ['16', '17'], 'value': '+'},{'id': '16', 'type': 'integer', 'children': [], 'value': '360'},{'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': 'crangles'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'hept_p'},{'id': '24', 'type': 'list_comprehension', 'children': ['25', '39']},{'id': '25', 'type': 'binary_operator', 'children': ['26', '32'], 'value': '+'},{'id': '26', 'type': 'binary_operator', 'children': ['27', '28'], 'value': '*'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '28', 'type': '()', 'children': ['29']},{'id': '29', 'type': 'binary_operator', 'children': ['30', '31'], 'value': '/'},{'id': '30', 'type': 'float', 'children': [], 'value': '360.0'},{'id': '31', 'type': 'float', 'children': [], 'value': '7.0'},{'id': '32', 'type': '()', 'children': ['33']},{'id': '33', 'type': 'binary_operator', 'children': ['34', '38'], 'value': '/'},{'id': '34', 'type': '()', 'children': ['35']},{'id': '35', 'type': 'binary_operator', 'children': ['36', '37'], 'value': '/'},{'id': '36', 'type': 'float', 'children': [], 'value': '360.0'},{'id': '37', 'type': 'float', 'children': [], 'value': '7.0'},{'id': '38', 'type': 'float', 'children': [], 'value': '2.0'},{'id': '39', 'type': 'for_in_clause', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'integer', 'children': [], 'value': '7'},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'ideal_crangs'},{'id': '48', 'type': 'list', 'children': ['49', '52', '55', '58', '61', '64', '67'], 'value': '[\n hept_p[0],\n hept_p[2],\n hept_p[4],\n hept_p[6],\n hept_p[1],\n hept_p[3],\n hept_p[5]\n ]'},{'id': '49', 'type': 'subscript', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'hept_p'},{'id': '51', 'type': 'integer', 'children': [], 'value': '0'},{'id': '52', 'type': 'subscript', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'hept_p'},{'id': '54', 'type': 'integer', 'children': [], 'value': '2'},{'id': '55', 'type': 'subscript', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'hept_p'},{'id': '57', 'type': 'integer', 'children': [], 'value': '4'},{'id': '58', 'type': 'subscript', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'hept_p'},{'id': '60', 'type': 'integer', 'children': [], 'value': '6'},{'id': '61', 'type': 'subscript', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'hept_p'},{'id': '63', 'type': 'integer', 'children': [], 'value': '1'},{'id': '64', 'type': 'subscript', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'hept_p'},{'id': '66', 'type': 'integer', 'children': [], 'value': '3'},{'id': '67', 'type': 'subscript', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'hept_p'},{'id': '69', 'type': 'integer', 'children': [], 'value': '5'},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'full_hept'},{'id': '73', 'type': 'binary_operator', 'children': ['74', '78'], 'value': '//'},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'crangles'},{'id': '78', 'type': 'integer', 'children': [], 'value': '7'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'ideal_crang_list'},{'id': '82', 'type': 'binary_operator', 'children': ['83', '84'], 'value': '*'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'ideal_crangs'},{'id': '84', 'type': '()', 'children': ['85']},{'id': '85', 'type': 'binary_operator', 'children': ['86', '87'], 'value': '+'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'full_hept'},{'id': '87', 'type': 'integer', 'children': [], 'value': '2'},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'fitting'},{'id': '91', 'type': 'list', 'children': [], 'value': '[]'},{'id': '92', 'type': 'for_statement', 'children': ['93', '94', '98']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '94', 'type': 'call', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'integer', 'children': [], 'value': '7'},{'id': '98', 'type': 'block', 'children': ['99', '111', '126']},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'ang_pairs'},{'id': '102', 'type': 'call', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '104', 'type': 'argument_list', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'crangles'},{'id': '106', 'type': 'subscript', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'ideal_crang_list'},{'id': '108', 'type': 'slice', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '110', 'type': 'colon', 'children': []},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'ang_diffs'},{'id': '114', 'type': 'list_comprehension', 'children': ['115', '121']},{'id': '115', 'type': 'call', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '117', 'type': 'argument_list', 'children': ['118']},{'id': '118', 'type': 'binary_operator', 'children': ['119', '120'], 'value': '-'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '121', 'type': 'for_in_clause', 'children': ['122', '125']},{'id': '122', 'type': 'pattern_list', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'ang_pairs'},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'call', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'fitting'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'tuple', 'children': ['133', '134', '140']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '134', 'type': 'call', 'children': ['135', '138']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'mean'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'ang_diffs'},{'id': '140', 'type': 'call', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'std'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'ang_diffs'},{'id': '146', 'type': 'return_statement', 'children': ['147']},{'id': '147', 'type': 'call', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '149', 'type': 'argument_list', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'fitting'},{'id': '151', 'type': 'keyword_argument', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '153', 'type': 'lambda', 'children': ['154', '156']},{'id': '154', 'type': 'lambda_parameters', 'children': ['155']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '156', 'type': 'subscript', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '158', 'type': 'integer', 'children': [], 'value': '1'}
def fit_heptad_register(crangles): crangles = [x if x > 0 else 360 + x for x in crangles] hept_p = [x * (360.0 / 7.0) + ((360.0 / 7.0) / 2.0) for x in range(7)] ideal_crangs = [ hept_p[0], hept_p[2], hept_p[4], hept_p[6], hept_p[1], hept_p[3], hept_p[5] ] full_hept = len(crangles) // 7 ideal_crang_list = ideal_crangs * (full_hept + 2) fitting = [] for i in range(7): ang_pairs = zip(crangles, ideal_crang_list[i:]) ang_diffs = [abs(y - x) for x, y in ang_pairs] fitting.append((i, numpy.mean(ang_diffs), numpy.std(ang_diffs))) return sorted(fitting, key=lambda x: x[1])
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'simplify'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '13', '27', '37', '45', '53', '66', '70', '88', '100', '128', '146', '150', '376', '385', '397', '403', '413', '419']},{'id': '6', 'type': 'if_statement', 'children': ['7', '10']},{'id': '7', 'type': 'attribute', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'iscanonical'},{'id': '10', 'type': 'block', 'children': ['11']},{'id': '11', 'type': 'return_statement', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '16', 'type': 'list_comprehension', 'children': ['17', '22']},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'simplify'},{'id': '21', 'type': 'argument_list', 'children': []},{'id': '22', 'type': 'for_in_clause', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'expr'},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '33', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'list_splat', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'expr'},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'expr'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'literalize'},{'id': '44', 'type': 'argument_list', 'children': []},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'expr'},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'expr'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'flatten'},{'id': '52', 'type': 'argument_list', 'children': []},{'id': '53', 'type': 'if_statement', 'children': ['54', '61']},{'id': '54', 'type': 'comparison_operator', 'children': ['55', '58'], 'value': 'in'},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'annihilator'},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'expr'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '61', 'type': 'block', 'children': ['62']},{'id': '62', 'type': 'return_statement', 'children': ['63']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'annihilator'},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '69', 'type': 'list', 'children': [], 'value': '[]'},{'id': '70', 'type': 'for_statement', 'children': ['71', '72', '75']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'expr'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '75', 'type': 'block', 'children': ['76']},{'id': '76', 'type': 'if_statement', 'children': ['77', '80']},{'id': '77', 'type': 'comparison_operator', 'children': ['78', '79'], 'value': 'not'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'args'},{'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': 'args'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '88', 'type': 'if_statement', 'children': ['89', '95']},{'id': '89', 'type': 'comparison_operator', 'children': ['90', '94'], 'value': '=='},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '94', 'type': 'integer', 'children': [], 'value': '1'},{'id': '95', 'type': 'block', 'children': ['96']},{'id': '96', 'type': 'return_statement', 'children': ['97']},{'id': '97', 'type': 'subscript', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '99', 'type': 'integer', 'children': [], 'value': '0'},{'id': '100', 'type': 'if_statement', 'children': ['101', '106']},{'id': '101', 'type': 'comparison_operator', 'children': ['102', '105'], 'value': 'in'},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '106', 'type': 'block', 'children': ['107', '116']},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'call', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '116', 'type': 'if_statement', 'children': ['117', '123']},{'id': '117', 'type': 'comparison_operator', 'children': ['118', '122'], 'value': '=='},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '122', 'type': 'integer', 'children': [], 'value': '1'},{'id': '123', 'type': 'block', 'children': ['124']},{'id': '124', 'type': 'return_statement', 'children': ['125']},{'id': '125', 'type': 'subscript', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '127', 'type': 'integer', 'children': [], 'value': '0'},{'id': '128', 'type': 'for_statement', 'children': ['129', '130', '131']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '131', 'type': 'block', 'children': ['132']},{'id': '132', 'type': 'if_statement', 'children': ['133', '141']},{'id': '133', 'type': 'comparison_operator', 'children': ['134', '140'], 'value': 'in'},{'id': '134', 'type': 'call', 'children': ['135', '138']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'NOT'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '141', 'type': 'block', 'children': ['142']},{'id': '142', 'type': 'return_statement', 'children': ['143']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'annihilator'},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'assignment', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '149', 'type': 'integer', 'children': [], 'value': '0'},{'id': '150', 'type': 'while_statement', 'children': ['151', '159']},{'id': '151', 'type': 'comparison_operator', 'children': ['152', '153'], 'value': '<'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '153', 'type': 'binary_operator', 'children': ['154', '158'], 'value': '-'},{'id': '154', 'type': 'call', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '158', 'type': 'integer', 'children': [], 'value': '1'},{'id': '159', 'type': 'block', 'children': ['160', '166', '172', '187', '372']},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '163', 'type': 'binary_operator', 'children': ['164', '165'], 'value': '+'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '165', 'type': 'integer', 'children': [], 'value': '1'},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'ai'},{'id': '169', 'type': 'subscript', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '172', 'type': 'if_statement', 'children': ['173', '181']},{'id': '173', 'type': 'not_operator', 'children': ['174']},{'id': '174', 'type': 'call', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '176', 'type': 'argument_list', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'ai'},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'dual'},{'id': '181', 'type': 'block', 'children': ['182', '186']},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'augmented_assignment', 'children': ['184', '185'], 'value': '+='},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '185', 'type': 'integer', 'children': [], 'value': '1'},{'id': '186', 'type': 'continue_statement', 'children': []},{'id': '187', 'type': 'while_statement', 'children': ['188', '194']},{'id': '188', 'type': 'comparison_operator', 'children': ['189', '190'], 'value': '<'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '190', 'type': 'call', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '194', 'type': 'block', 'children': ['195', '201', '230', '234', '287', '368']},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'assignment', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'aj'},{'id': '198', 'type': 'subscript', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '201', 'type': 'if_statement', 'children': ['202', '224']},{'id': '202', 'type': 'boolean_operator', 'children': ['203', '211'], 'value': 'or'},{'id': '203', 'type': 'not_operator', 'children': ['204']},{'id': '204', 'type': 'call', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '206', 'type': 'argument_list', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'aj'},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'dual'},{'id': '211', 'type': 'comparison_operator', 'children': ['212', '218'], 'value': '!='},{'id': '212', 'type': 'call', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '214', 'type': 'argument_list', 'children': ['215']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'ai'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '218', 'type': 'call', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '220', 'type': 'argument_list', 'children': ['221']},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'aj'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '224', 'type': 'block', 'children': ['225', '229']},{'id': '225', 'type': 'expression_statement', 'children': ['226']},{'id': '226', 'type': 'augmented_assignment', 'children': ['227', '228'], 'value': '+='},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '228', 'type': 'integer', 'children': [], 'value': '1'},{'id': '229', 'type': 'continue_statement', 'children': []},{'id': '230', 'type': 'expression_statement', 'children': ['231']},{'id': '231', 'type': 'assignment', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'negated'},{'id': '233', 'type': 'None', 'children': []},{'id': '234', 'type': 'for_statement', 'children': ['235', '236', '239']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '236', 'type': 'attribute', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'ai'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '239', 'type': 'block', 'children': ['240']},{'id': '240', 'type': 'if_statement', 'children': ['241', '246', '248', '280']},{'id': '241', 'type': 'comparison_operator', 'children': ['242', '243'], 'value': 'in'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'aj'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '246', 'type': 'block', 'children': ['247']},{'id': '247', 'type': 'pass_statement', 'children': []},{'id': '248', 'type': 'elif_clause', 'children': ['249', '263']},{'id': '249', 'type': 'comparison_operator', 'children': ['250', '260'], 'value': 'in'},{'id': '250', 'type': 'call', 'children': ['251', '259']},{'id': '251', 'type': 'attribute', 'children': ['252', '258']},{'id': '252', 'type': 'call', 'children': ['253', '256']},{'id': '253', 'type': 'attribute', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'NOT'},{'id': '256', 'type': 'argument_list', 'children': ['257']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'cancel'},{'id': '259', 'type': 'argument_list', 'children': []},{'id': '260', 'type': 'attribute', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'aj'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '263', 'type': 'block', 'children': ['264']},{'id': '264', 'type': 'if_statement', 'children': ['265', '268', '273']},{'id': '265', 'type': 'comparison_operator', 'children': ['266', '267'], 'value': 'is'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'negated'},{'id': '267', 'type': 'None', 'children': []},{'id': '268', 'type': 'block', 'children': ['269']},{'id': '269', 'type': 'expression_statement', 'children': ['270']},{'id': '270', 'type': 'assignment', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'negated'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '273', 'type': 'else_clause', 'children': ['274']},{'id': '274', 'type': 'block', 'children': ['275', '279']},{'id': '275', 'type': 'expression_statement', 'children': ['276']},{'id': '276', 'type': 'assignment', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'negated'},{'id': '278', 'type': 'None', 'children': []},{'id': '279', 'type': 'break_statement', 'children': []},{'id': '280', 'type': 'else_clause', 'children': ['281']},{'id': '281', 'type': 'block', 'children': ['282', '286']},{'id': '282', 'type': 'expression_statement', 'children': ['283']},{'id': '283', 'type': 'assignment', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'negated'},{'id': '285', 'type': 'None', 'children': []},{'id': '286', 'type': 'break_statement', 'children': []},{'id': '287', 'type': 'if_statement', 'children': ['288', '291']},{'id': '288', 'type': 'comparison_operator', 'children': ['289', '290'], 'value': 'is'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'negated'},{'id': '290', 'type': 'None', 'children': []},{'id': '291', 'type': 'block', 'children': ['292', '296', '305', '312', '342']},{'id': '292', 'type': 'delete_statement', 'children': ['293']},{'id': '293', 'type': 'subscript', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '296', 'type': 'expression_statement', 'children': ['297']},{'id': '297', 'type': 'assignment', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'aiargs'},{'id': '299', 'type': 'call', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '301', 'type': 'argument_list', 'children': ['302']},{'id': '302', 'type': 'attribute', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'ai'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '305', 'type': 'expression_statement', 'children': ['306']},{'id': '306', 'type': 'call', 'children': ['307', '310']},{'id': '307', 'type': 'attribute', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'aiargs'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '310', 'type': 'argument_list', 'children': ['311']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'negated'},{'id': '312', 'type': 'if_statement', 'children': ['313', '319', '328']},{'id': '313', 'type': 'comparison_operator', 'children': ['314', '318'], 'value': '=='},{'id': '314', 'type': 'call', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '316', 'type': 'argument_list', 'children': ['317']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'aiargs'},{'id': '318', 'type': 'integer', 'children': [], 'value': '1'},{'id': '319', 'type': 'block', 'children': ['320']},{'id': '320', 'type': 'expression_statement', 'children': ['321']},{'id': '321', 'type': 'assignment', 'children': ['322', '325']},{'id': '322', 'type': 'subscript', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '325', 'type': 'subscript', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'aiargs'},{'id': '327', 'type': 'integer', 'children': [], 'value': '0'},{'id': '328', 'type': 'else_clause', 'children': ['329']},{'id': '329', 'type': 'block', 'children': ['330']},{'id': '330', 'type': 'expression_statement', 'children': ['331']},{'id': '331', 'type': 'assignment', 'children': ['332', '335']},{'id': '332', 'type': 'subscript', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '335', 'type': 'call', 'children': ['336', '339']},{'id': '336', 'type': 'attribute', 'children': ['337', '338']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'dual'},{'id': '339', 'type': 'argument_list', 'children': ['340']},{'id': '340', 'type': 'list_splat', 'children': ['341']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'aiargs'},{'id': '342', 'type': 'if_statement', 'children': ['343', '349', '354']},{'id': '343', 'type': 'comparison_operator', 'children': ['344', '348'], 'value': '=='},{'id': '344', 'type': 'call', 'children': ['345', '346']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '346', 'type': 'argument_list', 'children': ['347']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '348', 'type': 'integer', 'children': [], 'value': '1'},{'id': '349', 'type': 'block', 'children': ['350']},{'id': '350', 'type': 'return_statement', 'children': ['351']},{'id': '351', 'type': 'subscript', 'children': ['352', '353']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '353', 'type': 'integer', 'children': [], 'value': '0'},{'id': '354', 'type': 'else_clause', 'children': ['355']},{'id': '355', 'type': 'block', 'children': ['356']},{'id': '356', 'type': 'return_statement', 'children': ['357']},{'id': '357', 'type': 'call', 'children': ['358', '367']},{'id': '358', 'type': 'attribute', 'children': ['359', '366']},{'id': '359', 'type': 'call', 'children': ['360', '363']},{'id': '360', 'type': 'attribute', 'children': ['361', '362']},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '362', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '363', 'type': 'argument_list', 'children': ['364']},{'id': '364', 'type': 'list_splat', 'children': ['365']},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'simplify'},{'id': '367', 'type': 'argument_list', 'children': []},{'id': '368', 'type': 'expression_statement', 'children': ['369']},{'id': '369', 'type': 'augmented_assignment', 'children': ['370', '371'], 'value': '+='},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '371', 'type': 'integer', 'children': [], 'value': '1'},{'id': '372', 'type': 'expression_statement', 'children': ['373']},{'id': '373', 'type': 'augmented_assignment', 'children': ['374', '375'], 'value': '+='},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '375', 'type': 'integer', 'children': [], 'value': '1'},{'id': '376', 'type': 'expression_statement', 'children': ['377']},{'id': '377', 'type': 'assignment', 'children': ['378', '379']},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '379', 'type': 'call', 'children': ['380', '383']},{'id': '380', 'type': 'attribute', 'children': ['381', '382']},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'absorb'},{'id': '383', 'type': 'argument_list', 'children': ['384']},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '385', 'type': 'if_statement', 'children': ['386', '392']},{'id': '386', 'type': 'comparison_operator', 'children': ['387', '391'], 'value': '=='},{'id': '387', 'type': 'call', 'children': ['388', '389']},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '389', 'type': 'argument_list', 'children': ['390']},{'id': '390', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '391', 'type': 'integer', 'children': [], 'value': '1'},{'id': '392', 'type': 'block', 'children': ['393']},{'id': '393', 'type': 'return_statement', 'children': ['394']},{'id': '394', 'type': 'subscript', 'children': ['395', '396']},{'id': '395', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '396', 'type': 'integer', 'children': [], 'value': '0'},{'id': '397', 'type': 'expression_statement', 'children': ['398']},{'id': '398', 'type': 'call', 'children': ['399', '402']},{'id': '399', 'type': 'attribute', 'children': ['400', '401']},{'id': '400', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '401', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '402', 'type': 'argument_list', 'children': []},{'id': '403', 'type': 'expression_statement', 'children': ['404']},{'id': '404', 'type': 'assignment', 'children': ['405', '406']},{'id': '405', 'type': 'identifier', 'children': [], 'value': 'expr'},{'id': '406', 'type': 'call', 'children': ['407', '410']},{'id': '407', 'type': 'attribute', 'children': ['408', '409']},{'id': '408', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '409', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '410', 'type': 'argument_list', 'children': ['411']},{'id': '411', 'type': 'list_splat', 'children': ['412']},{'id': '412', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '413', 'type': 'expression_statement', 'children': ['414']},{'id': '414', 'type': 'assignment', 'children': ['415', '418']},{'id': '415', 'type': 'attribute', 'children': ['416', '417']},{'id': '416', 'type': 'identifier', 'children': [], 'value': 'expr'},{'id': '417', 'type': 'identifier', 'children': [], 'value': 'iscanonical'},{'id': '418', 'type': 'True', 'children': []},{'id': '419', 'type': 'return_statement', 'children': ['420']},{'id': '420', 'type': 'identifier', 'children': [], 'value': 'expr'}
def simplify(self): if self.iscanonical: return self args = [arg.simplify() for arg in self.args] expr = self.__class__(*args) expr = expr.literalize() expr = expr.flatten() if self.annihilator in expr.args: return self.annihilator args = [] for arg in expr.args: if arg not in args: args.append(arg) if len(args) == 1: return args[0] if self.identity in args: args.remove(self.identity) if len(args) == 1: return args[0] for arg in args: if self.NOT(arg) in args: return self.annihilator i = 0 while i < len(args) - 1: j = i + 1 ai = args[i] if not isinstance(ai, self.dual): i += 1 continue while j < len(args): aj = args[j] if not isinstance(aj, self.dual) or len(ai.args) != len(aj.args): j += 1 continue negated = None for arg in ai.args: if arg in aj.args: pass elif self.NOT(arg).cancel() in aj.args: if negated is None: negated = arg else: negated = None break else: negated = None break if negated is not None: del args[j] aiargs = list(ai.args) aiargs.remove(negated) if len(aiargs) == 1: args[i] = aiargs[0] else: args[i] = self.dual(*aiargs) if len(args) == 1: return args[0] else: return self.__class__(*args).simplify() j += 1 i += 1 args = self.absorb(args) if len(args) == 1: return args[0] args.sort() expr = self.__class__(*args) expr.iscanonical = True return expr
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_recordAndPrintHeadline'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'test'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'error_class'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'artifact'},{'id': '8', 'type': 'block', 'children': ['9', '13', '62', '83', '90', '104']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'is_error_class'},{'id': '12', 'type': 'False', 'children': []},{'id': '13', 'type': 'for_statement', 'children': ['14', '20', '27']},{'id': '14', 'type': 'pattern_list', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '16', 'type': 'tuple_pattern', 'children': ['17', '18', '19']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'storage'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'is_failure'},{'id': '20', 'type': 'call', 'children': ['21', '26']},{'id': '21', 'type': 'attribute', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'errorClasses'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '26', 'type': 'argument_list', 'children': []},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'if_statement', 'children': ['29', '39']},{'id': '29', 'type': 'boolean_operator', 'children': ['30', '34'], 'value': 'and'},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'isclass'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'error_class'},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'issubclass'},{'id': '36', 'type': 'argument_list', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'error_class'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '39', 'type': 'block', 'children': ['40', '49', '58']},{'id': '40', 'type': 'if_statement', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'is_failure'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'test'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'passed'},{'id': '48', 'type': 'False', 'children': []},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'storage'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'tuple', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'test'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'artifact'},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'is_error_class'},{'id': '61', 'type': 'True', 'children': []},{'id': '62', 'type': 'if_statement', 'children': ['63', '65']},{'id': '63', 'type': 'not_operator', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'is_error_class'},{'id': '65', 'type': 'block', 'children': ['66', '77']},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'call', 'children': ['68', '73']},{'id': '68', 'type': 'attribute', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'errors'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'tuple', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'test'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'artifact'},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'test'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'passed'},{'id': '82', 'type': 'False', 'children': []},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'is_any_failure'},{'id': '86', 'type': 'boolean_operator', 'children': ['87', '89'], 'value': 'or'},{'id': '87', 'type': 'not_operator', 'children': ['88']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'is_error_class'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'is_failure'},{'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': 'self'},{'id': '94', 'type': 'identifier', 'children': [], 'value': '_printHeadline'},{'id': '95', 'type': 'argument_list', 'children': ['96', '100', '101']},{'id': '96', 'type': 'conditional_expression', 'children': ['97', '98', '99'], 'value': 'if'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'is_error_class'},{'id': '99', 'type': 'string', 'children': [], 'value': "'ERROR'"},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'test'},{'id': '101', 'type': 'keyword_argument', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'is_failure'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'is_any_failure'},{'id': '104', 'type': 'return_statement', 'children': ['105']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'is_any_failure'}
def _recordAndPrintHeadline(self, test, error_class, artifact): is_error_class = False for cls, (storage, label, is_failure) in self.errorClasses.items(): if isclass(error_class) and issubclass(error_class, cls): if is_failure: test.passed = False storage.append((test, artifact)) is_error_class = True if not is_error_class: self.errors.append((test, artifact)) test.passed = False is_any_failure = not is_error_class or is_failure self._printHeadline(label if is_error_class else 'ERROR', test, is_failure=is_any_failure) return is_any_failure
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_decode_filename_to_unicode'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '5', 'type': 'block', 'children': ['6', '8', '19', '28']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'string', 'children': [], 'value': "'''Get bytestring filename and return unicode.\n First, try to decode from default file system encoding\n If that fails, use ``chardet`` module to guess encoding.\n As a last resort, try to decode as utf-8.\n If the argument already is unicode, return as is'''"},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '13', 'type': 'argument_list', 'children': ['14', '15']},{'id': '14', 'type': 'string', 'children': [], 'value': "'_decode_filename_to_unicode(%s)'"},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'repr'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '19', 'type': 'if_statement', 'children': ['20', '25']},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '22', 'type': 'argument_list', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'unicode'},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'return_statement', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '28', 'type': 'try_statement', 'children': ['29', '41']},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'return_statement', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'decode'},{'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': 'sys'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'getfilesystemencoding'},{'id': '40', 'type': 'argument_list', 'children': []},{'id': '41', 'type': 'except_clause', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'UnicodeDecodeError'},{'id': '43', 'type': 'block', 'children': ['44', '53', '62', '84', '93', '101', '114', '122']},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'charguess'},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'chardet'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'detect'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '58', 'type': 'argument_list', 'children': ['59', '60', '61']},{'id': '59', 'type': 'string', 'children': [], 'value': '"chardet filename: %r -> %r"'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'charguess'},{'id': '62', 'type': 'if_statement', 'children': ['63', '68']},{'id': '63', 'type': 'comparison_operator', 'children': ['64', '67'], 'value': 'is'},{'id': '64', 'type': 'subscript', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'charguess'},{'id': '66', 'type': 'string', 'children': [], 'value': "'encoding'"},{'id': '67', 'type': 'None', 'children': []},{'id': '68', 'type': 'block', 'children': ['69']},{'id': '69', 'type': 'try_statement', 'children': ['70', '80']},{'id': '70', 'type': 'block', 'children': ['71']},{'id': '71', 'type': 'return_statement', 'children': ['72']},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'subscript', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'charguess'},{'id': '79', 'type': 'string', 'children': [], 'value': "'encoding'"},{'id': '80', 'type': 'except_clause', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'UnicodeDecodeError'},{'id': '82', 'type': 'block', 'children': ['83']},{'id': '83', 'type': 'pass_statement', 'children': []},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '89', 'type': 'argument_list', 'children': ['90', '91', '92']},{'id': '90', 'type': 'string', 'children': [], 'value': "'Cannot understand decoding of this filename: %r (guessed %r, but was wrong)'"},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'charguess'},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '98', 'type': 'argument_list', 'children': ['99', '100']},{'id': '99', 'type': 'string', 'children': [], 'value': "'Trying utf-8 to decode %r'"},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '101', 'type': 'try_statement', 'children': ['102', '110']},{'id': '102', 'type': 'block', 'children': ['103']},{'id': '103', 'type': 'return_statement', 'children': ['104']},{'id': '104', 'type': 'call', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '110', 'type': 'except_clause', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'UnicodeDecodeError'},{'id': '112', 'type': 'block', 'children': ['113']},{'id': '113', 'type': 'pass_statement', 'children': []},{'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': 'log'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '119', 'type': 'argument_list', 'children': ['120', '121']},{'id': '120', 'type': 'string', 'children': [], 'value': "'Trying latin1 to decode %r'"},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '122', 'type': 'try_statement', 'children': ['123', '131']},{'id': '123', 'type': 'block', 'children': ['124']},{'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': 'f'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'string', 'children': [], 'value': "'latin1'"},{'id': '131', 'type': 'except_clause', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'UnicodeDecodeError'},{'id': '133', 'type': 'block', 'children': ['134', '142']},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '139', 'type': 'argument_list', 'children': ['140', '141']},{'id': '140', 'type': 'string', 'children': [], 'value': "'Exhausted all options. Decoding %r to safe ascii'"},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '142', 'type': 'return_statement', 'children': ['143']},{'id': '143', 'type': 'call', 'children': ['144', '147']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '147', 'type': 'argument_list', 'children': ['148', '149']},{'id': '148', 'type': 'string', 'children': [], 'value': "'ascii'"},{'id': '149', 'type': 'keyword_argument', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'errors'},{'id': '151', 'type': 'string', 'children': [], 'value': "'ignore'"}
def _decode_filename_to_unicode(f): '''Get bytestring filename and return unicode. First, try to decode from default file system encoding If that fails, use ``chardet`` module to guess encoding. As a last resort, try to decode as utf-8. If the argument already is unicode, return as is''' log.debug('_decode_filename_to_unicode(%s)', repr(f)) if isinstance(f, unicode): return f try: return f.decode(sys.getfilesystemencoding()) except UnicodeDecodeError: charguess = chardet.detect(f) log.debug("chardet filename: %r -> %r", f, charguess) if charguess['encoding'] is not None: try: return f.decode(charguess['encoding']) except UnicodeDecodeError: pass log.warning('Cannot understand decoding of this filename: %r (guessed %r, but was wrong)', f, charguess) log.debug('Trying utf-8 to decode %r', f) try: return f.decode('utf-8') except UnicodeDecodeError: pass log.debug('Trying latin1 to decode %r', f) try: return f.decode('latin1') except UnicodeDecodeError: log.warning('Exhausted all options. Decoding %r to safe ascii', f) return f.decode('ascii', errors='ignore')
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sortBy'},{'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': 'val'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9']},{'id': '9', 'type': 'if_statement', 'children': ['10', '13', '66']},{'id': '10', 'type': 'comparison_operator', 'children': ['11', '12'], 'value': 'is'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'if_statement', 'children': ['15', '23', '49']},{'id': '15', 'type': 'call', 'children': ['16', '22']},{'id': '16', 'type': 'attribute', 'children': ['17', '21']},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'isString'},{'id': '22', 'type': 'argument_list', 'children': []},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'return_statement', 'children': ['25']},{'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': '_wrap'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'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': 'obj'},{'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '38', 'type': 'lambda', 'children': ['39', '43']},{'id': '39', 'type': 'lambda_parameters', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '41', 'type': 'list_splat_pattern', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '49', 'type': 'else_clause', 'children': ['50']},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'return_statement', 'children': ['52']},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '55', 'type': 'identifier', 'children': [], 'value': '_wrap'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '59', 'type': 'argument_list', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '63', 'type': 'keyword_argument', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '66', 'type': 'else_clause', 'children': ['67']},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'return_statement', 'children': ['69']},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '72', 'type': 'identifier', 'children': [], 'value': '_wrap'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'obj'}
def sortBy(self, val=None): if val is not None: if _(val).isString(): return self._wrap(sorted(self.obj, key=lambda x, *args: x.get(val))) else: return self._wrap(sorted(self.obj, key=val)) else: return self._wrap(sorted(self.obj))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sortedIndex'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '8', 'type': 'lambda', 'children': ['9', '11']},{'id': '9', 'type': 'lambda_parameters', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '12', 'type': 'block', 'children': ['13', '19', '26', '30', '37', '73']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'low'},{'id': '29', 'type': 'integer', 'children': [], 'value': '0'},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'high'},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '37', 'type': 'while_statement', 'children': ['38', '41']},{'id': '38', 'type': 'comparison_operator', 'children': ['39', '40'], 'value': '<'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'low'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'high'},{'id': '41', 'type': 'block', 'children': ['42', '51']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'mid'},{'id': '45', 'type': 'binary_operator', 'children': ['46', '50'], 'value': '>>'},{'id': '46', 'type': '()', 'children': ['47']},{'id': '47', 'type': 'binary_operator', 'children': ['48', '49'], 'value': '+'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'low'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'high'},{'id': '50', 'type': 'integer', 'children': [], 'value': '1'},{'id': '51', 'type': 'if_statement', 'children': ['52', '60', '67']},{'id': '52', 'type': 'comparison_operator', 'children': ['53', '59'], 'value': '<'},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'subscript', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'mid'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'value'},{'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': 'low'},{'id': '64', 'type': 'binary_operator', 'children': ['65', '66'], 'value': '+'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'mid'},{'id': '66', 'type': 'integer', 'children': [], 'value': '1'},{'id': '67', 'type': 'else_clause', 'children': ['68']},{'id': '68', 'type': 'block', 'children': ['69']},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'high'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'mid'},{'id': '73', 'type': 'return_statement', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '77', 'type': 'identifier', 'children': [], 'value': '_wrap'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'low'}
def sortedIndex(self, obj, iterator=lambda x: x): array = self.obj value = iterator(obj) low = 0 high = len(array) while low < high: mid = (low + high) >> 1 if iterator(array[mid]) < value: low = mid + 1 else: high = mid return self._wrap(low)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'uniq'},{'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': 'isSorted'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '20', '26', '34', '40', '59', '116', '126']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'ns'},{'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': 'Namespace'},{'id': '19', 'type': 'argument_list', 'children': []},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '25', 'type': 'list', 'children': [], 'value': '[]'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'initial'},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '40', 'type': 'if_statement', 'children': ['41', '44']},{'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': 'is'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '43', 'type': 'None', 'children': []},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'initial'},{'id': '48', 'type': 'call', 'children': ['49', '57']},{'id': '49', 'type': 'attribute', 'children': ['50', '56']},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '59', 'type': 'function_definition', 'children': ['60', '61', '65']},{'id': '60', 'type': 'function_name', 'children': [], 'value': 'by'},{'id': '61', 'type': 'parameters', 'children': ['62', '63', '64']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'memo'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '65', 'type': 'block', 'children': ['66', '114']},{'id': '66', 'type': 'if_statement', 'children': ['67', '93']},{'id': '67', 'type': '()', 'children': ['68']},{'id': '68', 'type': 'conditional_expression', 'children': ['69', '84', '85'], 'value': 'if'},{'id': '69', 'type': '()', 'children': ['70']},{'id': '70', 'type': 'boolean_operator', 'children': ['71', '79'], 'value': 'or'},{'id': '71', 'type': 'comparison_operator', 'children': ['72', '78'], 'value': '!='},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'last'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'memo'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '79', 'type': 'not_operator', 'children': ['80']},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'memo'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'isSorted'},{'id': '85', 'type': 'not_operator', 'children': ['86']},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'include'},{'id': '90', 'type': 'argument_list', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'memo'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '93', 'type': 'block', 'children': ['94', '101']},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'call', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'memo'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'call', 'children': ['103', '108']},{'id': '103', 'type': 'attribute', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'subscript', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '114', 'type': 'return_statement', 'children': ['115']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'memo'},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '119', 'type': 'call', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'reduce'},{'id': '123', 'type': 'argument_list', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'initial'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'by'},{'id': '126', 'type': 'return_statement', 'children': ['127']},{'id': '127', 'type': 'call', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '130', 'type': 'identifier', 'children': [], 'value': '_wrap'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'ret'}
def uniq(self, isSorted=False, iterator=None): ns = self.Namespace() ns.results = [] ns.array = self.obj initial = self.obj if iterator is not None: initial = _(ns.array).map(iterator) def by(memo, value, index): if ((_.last(memo) != value or not len(memo)) if isSorted else not _.include(memo, value)): memo.append(value) ns.results.append(ns.array[index]) return memo ret = _.reduce(initial, by) return self._wrap(ret)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'functions'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '10', '42']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '9', 'type': 'list', 'children': [], 'value': '[]'},{'id': '10', 'type': 'for_statement', 'children': ['11', '14', '20']},{'id': '11', 'type': 'pattern_list', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'if_statement', 'children': ['22', '34']},{'id': '22', 'type': 'call', 'children': ['23', '33']},{'id': '23', 'type': 'attribute', 'children': ['24', '32']},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'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': 'obj'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'isCallable'},{'id': '33', 'type': 'argument_list', 'children': []},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '42', 'type': 'return_statement', 'children': ['43']},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '46', 'type': 'identifier', 'children': [], 'value': '_wrap'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'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': 'names'}
def functions(self): names = [] for i, k in enumerate(self.obj): if _(self.obj[k]).isCallable(): names.append(k) return self._wrap(sorted(names))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'createMSBWTFromBam'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'bamFNs'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'outputDir'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'numProcs'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'areUniform'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '9', 'type': 'block', 'children': ['10', '12', '19', '25', '31', '37', '43', '50', '60']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'string', 'children': [], 'value': "'''\n This function takes a fasta filename and creates the BWT using the technique from Cox and Bauer\n @param bamFNs - a list of BAM filenames to extract sequences from, READS MUST BE SORTED BY NAME\n @param outputDir - the directory for all of the bwt related data\n @param numProcs - the number of processes it's allowed to use\n @areUniform - true if all the sequences passed into the function are of equal length\n '''"},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'string', 'children': [], 'value': "'Saving sorted sequences...'"},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'seqFN'},{'id': '22', 'type': 'binary_operator', 'children': ['23', '24'], 'value': '+'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'outputDir'},{'id': '24', 'type': 'string', 'children': [], 'value': "'/seqs.npy'"},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'offsetFN'},{'id': '28', 'type': 'binary_operator', 'children': ['29', '30'], 'value': '+'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'outputDir'},{'id': '30', 'type': 'string', 'children': [], 'value': "'/offsets.npy'"},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'abtFN'},{'id': '34', 'type': 'binary_operator', 'children': ['35', '36'], 'value': '+'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'outputDir'},{'id': '36', 'type': 'string', 'children': [], 'value': "'/about.npy'"},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'bwtFN'},{'id': '40', 'type': 'binary_operator', 'children': ['41', '42'], 'value': '+'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'outputDir'},{'id': '42', 'type': 'string', 'children': [], 'value': "'/msbwt.npy'"},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'MSBWTGen'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'clearAuxiliaryData'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'outputDir'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'preprocessBams'},{'id': '53', 'type': 'argument_list', 'children': ['54', '55', '56', '57', '58', '59']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'bamFNs'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'seqFN'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'offsetFN'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'abtFN'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'areUniform'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'call', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'MSBWTGen'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'createFromSeqs'},{'id': '65', 'type': 'argument_list', 'children': ['66', '67', '68', '69', '70', '71']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'seqFN'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'offsetFN'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'bwtFN'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'numProcs'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'areUniform'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'logger'}
def createMSBWTFromBam(bamFNs, outputDir, numProcs, areUniform, logger): ''' This function takes a fasta filename and creates the BWT using the technique from Cox and Bauer @param bamFNs - a list of BAM filenames to extract sequences from, READS MUST BE SORTED BY NAME @param outputDir - the directory for all of the bwt related data @param numProcs - the number of processes it's allowed to use @areUniform - true if all the sequences passed into the function are of equal length ''' logger.info('Saving sorted sequences...') seqFN = outputDir+'/seqs.npy' offsetFN = outputDir+'/offsets.npy' abtFN = outputDir+'/about.npy' bwtFN = outputDir+'/msbwt.npy' MSBWTGen.clearAuxiliaryData(outputDir) preprocessBams(bamFNs, seqFN, offsetFN, abtFN, areUniform, logger) MSBWTGen.createFromSeqs(seqFN, offsetFN, bwtFN, numProcs, areUniform, logger)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'append_responder'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'matcher'},{'id': '6', 'type': 'list_splat_pattern', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '8', 'type': 'dictionary_splat_pattern', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '10', 'type': 'block', 'children': ['11']},{'id': '11', 'type': 'return_statement', 'children': ['12']},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '15', 'type': 'identifier', 'children': [], 'value': '_insert_responder'},{'id': '16', 'type': 'argument_list', 'children': ['17', '18', '19', '21']},{'id': '17', 'type': 'string', 'children': [], 'value': '"bottom"'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'matcher'},{'id': '19', 'type': 'list_splat', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '21', 'type': 'dictionary_splat', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'kwargs'}
def append_responder(self, matcher, *args, **kwargs): return self._insert_responder("bottom", matcher, *args, **kwargs)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'unique_list_dicts'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'dlist'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '6', 'type': 'block', 'children': ['7']},{'id': '7', 'type': 'return_statement', 'children': ['8']},{'id': '8', 'type': 'call', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '10', 'type': 'argument_list', 'children': ['11']},{'id': '11', 'type': 'call', 'children': ['12', '25']},{'id': '12', 'type': 'attribute', 'children': ['13', '24']},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '15', 'type': 'generator_expression', 'children': ['16', '21']},{'id': '16', 'type': 'tuple', 'children': ['17', '20']},{'id': '17', 'type': 'subscript', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '21', 'type': 'for_in_clause', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'dlist'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '25', 'type': 'argument_list', 'children': []}
def unique_list_dicts(dlist, key): return list(dict((val[key], val) for val in dlist).values())
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_bmu'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'activations'},{'id': '6', 'type': 'block', 'children': ['7', '19', '29']},{'id': '7', 'type': 'if_statement', 'children': ['8', '13']},{'id': '8', 'type': 'comparison_operator', 'children': ['9', '12'], 'value': '=='},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'argfunc'},{'id': '12', 'type': 'string', 'children': [], 'value': "'argmax'"},{'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': 'activations'},{'id': '17', 'type': 'unary_operator', 'children': ['18'], 'value': '-'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'activations'},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'activations'},{'id': '28', 'type': 'integer', 'children': [], 'value': '1'},{'id': '29', 'type': 'return_statement', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '34', 'type': 'argument_list', 'children': []}
def _get_bmu(self, activations): if self.argfunc == 'argmax': activations = -activations sort = np.argsort(activations, 1) return sort.argsort()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_versions'},{'id': '3', 'type': 'parameters', 'children': ['4', '7', '10']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'versions'},{'id': '6', 'type': 'tuple', 'children': []},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '9', 'type': 'False', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '12', 'type': 'string', 'children': [], 'value': "u'.'"},{'id': '13', 'type': 'block', 'children': ['14', '21', '25', '47', '54', '68', '232', '236', '246', '280', '287', '359', '369']},{'id': '14', 'type': 'if_statement', 'children': ['15', '18']},{'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': '=='},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'versions'},{'id': '17', 'type': 'list', 'children': [], 'value': '[]'},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'return_statement', 'children': ['20']},{'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': 'digits'},{'id': '24', 'type': 'string', 'children': [], 'value': "u'0123456789'"},{'id': '25', 'type': 'function_definition', 'children': ['26', '27', '29']},{'id': '26', 'type': 'function_name', 'children': [], 'value': 'toint'},{'id': '27', 'type': 'parameters', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '29', 'type': 'block', 'children': ['30', '45']},{'id': '30', 'type': 'try_statement', 'children': ['31', '39']},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '39', 'type': 'except_clause', 'children': ['40']},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '45', 'type': 'return_statement', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'versions'},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'versions'},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '60']},{'id': '56', 'type': 'pattern_list', 'children': ['57', '58', '59']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'new_versions'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'alpha'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'sizes'},{'id': '60', 'type': 'expression_list', 'children': ['61', '62', '65']},{'id': '61', 'type': 'list', 'children': [], 'value': '[]'},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '64', 'type': 'argument_list', 'children': []},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '67', 'type': 'argument_list', 'children': []},{'id': '68', 'type': 'for_statement', 'children': ['69', '70', '71']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'versions'},{'id': '71', 'type': 'block', 'children': ['72', '81', '85', '215', '225']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'temp'},{'id': '84', 'type': 'list', 'children': [], 'value': '[]'},{'id': '85', 'type': 'for_statement', 'children': ['86', '87', '88']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '88', 'type': 'block', 'children': ['89', '96', '211']},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'toint'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '96', 'type': 'if_statement', 'children': ['97', '103', '204']},{'id': '97', 'type': 'not_operator', 'children': ['98']},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '100', 'type': 'argument_list', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '103', 'type': 'block', 'children': ['104', '111', '125', '143', '161', '168', '175', '187']},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'middle'},{'id': '114', 'type': 'call', 'children': ['115', '123']},{'id': '115', 'type': 'attribute', 'children': ['116', '122']},{'id': '116', 'type': 'call', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'lstrip'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'digits'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'rstrip'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'digits'},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'tail'},{'id': '128', 'type': 'call', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'toint'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'call', 'children': ['132', '140']},{'id': '132', 'type': 'attribute', 'children': ['133', '139']},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'lstrip'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'digits'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '140', 'type': 'argument_list', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'middle'},{'id': '142', 'type': 'string', 'children': [], 'value': "u''"},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'head'},{'id': '146', 'type': 'call', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'toint'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'call', 'children': ['150', '158']},{'id': '150', 'type': 'attribute', 'children': ['151', '157']},{'id': '151', 'type': 'call', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'rstrip'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'digits'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '158', 'type': 'argument_list', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'middle'},{'id': '160', 'type': 'string', 'children': [], 'value': "u''"},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'middle'},{'id': '164', 'type': 'call', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'toint'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'middle'},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'assignment', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '171', 'type': 'list', 'children': ['172', '173', '174'], 'value': '[head, middle, tail]'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'head'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'middle'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'tail'},{'id': '175', 'type': 'while_statement', 'children': ['176', '179']},{'id': '176', 'type': 'comparison_operator', 'children': ['177', '178'], 'value': 'in'},{'id': '177', 'type': 'string', 'children': [], 'value': "u''"},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '179', 'type': 'block', 'children': ['180']},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'call', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '185', 'type': 'argument_list', 'children': ['186']},{'id': '186', 'type': 'string', 'children': [], 'value': "u''"},{'id': '187', 'type': 'for_statement', 'children': ['188', '189', '190']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '190', 'type': 'block', 'children': ['191']},{'id': '191', 'type': 'if_statement', 'children': ['192', '196']},{'id': '192', 'type': 'call', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'is_unicode'},{'id': '194', 'type': 'argument_list', 'children': ['195']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '196', 'type': 'block', 'children': ['197']},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'call', 'children': ['199', '202']},{'id': '199', 'type': 'attribute', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'alpha'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '202', 'type': 'argument_list', 'children': ['203']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '204', 'type': 'else_clause', 'children': ['205']},{'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': 'res'},{'id': '209', 'type': 'list', 'children': ['210'], 'value': '[x]'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'augmented_assignment', 'children': ['213', '214'], 'value': '+='},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'temp'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'call', 'children': ['217', '220']},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'sizes'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '220', 'type': 'argument_list', 'children': ['221']},{'id': '221', 'type': 'call', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '223', 'type': 'argument_list', 'children': ['224']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'temp'},{'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': 'new_versions'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '230', 'type': 'argument_list', 'children': ['231']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'temp'},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'assignment', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'replace_dic'},{'id': '235', 'type': 'dictionary', 'children': []},{'id': '236', 'type': 'expression_statement', 'children': ['237']},{'id': '237', 'type': 'assignment', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'alpha'},{'id': '239', 'type': 'call', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '241', 'type': 'argument_list', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'alpha'},{'id': '243', 'type': 'keyword_argument', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '245', 'type': 'True', 'children': []},{'id': '246', 'type': 'if_statement', 'children': ['247', '251']},{'id': '247', 'type': 'call', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '249', 'type': 'argument_list', 'children': ['250']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'alpha'},{'id': '251', 'type': 'block', 'children': ['252']},{'id': '252', 'type': 'expression_statement', 'children': ['253']},{'id': '253', 'type': 'assignment', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'replace_dic'},{'id': '255', 'type': 'call', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '257', 'type': 'argument_list', 'children': ['258']},{'id': '258', 'type': 'call', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '260', 'type': 'argument_list', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'alpha'},{'id': '262', 'type': 'call', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '264', 'type': 'argument_list', 'children': ['265']},{'id': '265', 'type': 'call', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '267', 'type': 'argument_list', 'children': ['268', '270', '278']},{'id': '268', 'type': 'unary_operator', 'children': ['269'], 'value': '-'},{'id': '269', 'type': 'integer', 'children': [], 'value': '1'},{'id': '270', 'type': 'unary_operator', 'children': ['271'], 'value': '-'},{'id': '271', 'type': '()', 'children': ['272']},{'id': '272', 'type': 'binary_operator', 'children': ['273', '277'], 'value': '+'},{'id': '273', 'type': 'call', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '275', 'type': 'argument_list', 'children': ['276']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'alpha'},{'id': '277', 'type': 'integer', 'children': [], 'value': '1'},{'id': '278', 'type': 'unary_operator', 'children': ['279'], 'value': '-'},{'id': '279', 'type': 'integer', 'children': [], 'value': '1'},{'id': '280', 'type': 'expression_statement', 'children': ['281']},{'id': '281', 'type': 'assignment', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'nmax'},{'id': '283', 'type': 'call', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '285', 'type': 'argument_list', 'children': ['286']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'sizes'},{'id': '287', 'type': 'for_statement', 'children': ['288', '289', '296']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '289', 'type': 'call', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '291', 'type': 'argument_list', 'children': ['292']},{'id': '292', 'type': 'call', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '294', 'type': 'argument_list', 'children': ['295']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'new_versions'},{'id': '296', 'type': 'block', 'children': ['297', '301', '330', '339', '346', '353']},{'id': '297', 'type': 'expression_statement', 'children': ['298']},{'id': '298', 'type': 'assignment', 'children': ['299', '300']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '300', 'type': 'list', 'children': [], 'value': '[]'},{'id': '301', 'type': 'for_statement', 'children': ['302', '303', '306']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '303', 'type': 'subscript', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'new_versions'},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '306', 'type': 'block', 'children': ['307']},{'id': '307', 'type': 'if_statement', 'children': ['308', '311', '321']},{'id': '308', 'type': 'comparison_operator', 'children': ['309', '310'], 'value': 'in'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'replace_dic'},{'id': '311', 'type': 'block', 'children': ['312']},{'id': '312', 'type': 'expression_statement', 'children': ['313']},{'id': '313', 'type': 'call', 'children': ['314', '317']},{'id': '314', 'type': 'attribute', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '317', 'type': 'argument_list', 'children': ['318']},{'id': '318', 'type': 'subscript', 'children': ['319', '320']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'replace_dic'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '321', 'type': 'else_clause', 'children': ['322']},{'id': '322', 'type': 'block', 'children': ['323']},{'id': '323', 'type': 'expression_statement', 'children': ['324']},{'id': '324', 'type': 'call', 'children': ['325', '328']},{'id': '325', 'type': 'attribute', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '328', 'type': 'argument_list', 'children': ['329']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '330', 'type': 'expression_statement', 'children': ['331']},{'id': '331', 'type': 'assignment', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'nzeros'},{'id': '333', 'type': 'binary_operator', 'children': ['334', '335'], 'value': '-'},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'nmax'},{'id': '335', 'type': 'call', 'children': ['336', '337']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '337', 'type': 'argument_list', 'children': ['338']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '339', 'type': 'expression_statement', 'children': ['340']},{'id': '340', 'type': 'augmented_assignment', 'children': ['341', '342'], 'value': '+='},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '342', 'type': 'binary_operator', 'children': ['343', '345'], 'value': '*'},{'id': '343', 'type': 'list', 'children': ['344'], 'value': '[0]'},{'id': '344', 'type': 'integer', 'children': [], 'value': '0'},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'nzeros'},{'id': '346', 'type': 'expression_statement', 'children': ['347']},{'id': '347', 'type': 'augmented_assignment', 'children': ['348', '349'], 'value': '+='},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '349', 'type': 'list', 'children': ['350'], 'value': '[versions[i]]'},{'id': '350', 'type': 'subscript', 'children': ['351', '352']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'versions'},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '353', 'type': 'expression_statement', 'children': ['354']},{'id': '354', 'type': 'assignment', 'children': ['355', '358']},{'id': '355', 'type': 'subscript', 'children': ['356', '357']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'new_versions'},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '359', 'type': 'expression_statement', 'children': ['360']},{'id': '360', 'type': 'assignment', 'children': ['361', '362']},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'new_versions'},{'id': '362', 'type': 'call', 'children': ['363', '364']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '364', 'type': 'argument_list', 'children': ['365', '366']},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'new_versions'},{'id': '366', 'type': 'keyword_argument', 'children': ['367', '368']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '369', 'type': 'return_statement', 'children': ['370']},{'id': '370', 'type': 'list_comprehension', 'children': ['371', '375']},{'id': '371', 'type': 'subscript', 'children': ['372', '373']},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '373', 'type': 'unary_operator', 'children': ['374'], 'value': '-'},{'id': '374', 'type': 'integer', 'children': [], 'value': '1'},{'id': '375', 'type': 'for_in_clause', 'children': ['376', '377']},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'new_versions'}
def sort_versions(versions=(), reverse=False, sep=u'.'): if versions == []: return [] digits = u'0123456789' def toint(x): try: n = int(x) except: n = x return n versions = list(versions) new_versions, alpha, sizes = [], set(), set() for item in versions: it = item.split(sep) temp = [] for i in it: x = toint(i) if not isinstance(x, int): x = u(x) middle = x.lstrip(digits).rstrip(digits) tail = toint(x.lstrip(digits).replace(middle, u'')) head = toint(x.rstrip(digits).replace(middle, u'')) middle = toint(middle) res = [head, middle, tail] while u'' in res: res.remove(u'') for r in res: if is_unicode(r): alpha.add(r) else: res = [x] temp += res sizes.add(len(temp)) new_versions.append(temp) replace_dic = {} alpha = sorted(alpha, reverse=True) if len(alpha): replace_dic = dict(zip(alpha, list(range(-1, -(len(alpha)+1), -1)))) nmax = max(sizes) for i in range(len(new_versions)): item = [] for z in new_versions[i]: if z in replace_dic: item.append(replace_dic[z]) else: item.append(z) nzeros = nmax - len(item) item += [0]*nzeros item += [versions[i]] new_versions[i] = item new_versions = sorted(new_versions, reverse=reverse) return [n[-1] for n in new_versions]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'make_qq_plot'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'kev'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'obs'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'mdl'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'unit'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'key_text'},{'id': '9', 'type': 'block', 'children': ['10', '15', '24', '33', '42', '51', '60', '74', '82', '95', '104', '129', '135', '141', '254', '266', '274']},{'id': '10', 'type': 'import_statement', 'children': ['11']},{'id': '11', 'type': 'aliased_import', 'children': ['12', '14']},{'id': '12', 'type': 'dotted_name', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'omega'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'om'},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'kev'},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'asarray'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'kev'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'obs'},{'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': 'obs'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'mdl'},{'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': 'asarray'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'mdl'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'c_obs'},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'cumsum'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'obs'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'c_mdl'},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'cumsum'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'mdl'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'mx'},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '65', 'type': 'argument_list', 'children': ['66', '70']},{'id': '66', 'type': 'subscript', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'c_obs'},{'id': '68', 'type': 'unary_operator', 'children': ['69'], 'value': '-'},{'id': '69', 'type': 'integer', 'children': [], 'value': '1'},{'id': '70', 'type': 'subscript', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'c_mdl'},{'id': '72', 'type': 'unary_operator', 'children': ['73'], 'value': '-'},{'id': '73', 'type': 'integer', 'children': [], 'value': '1'},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'om'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'RectPlot'},{'id': '81', 'type': 'argument_list', 'children': []},{'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': 'p'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'addXY'},{'id': '87', 'type': 'argument_list', 'children': ['88', '91', '94']},{'id': '88', 'type': 'list', 'children': ['89', '90'], 'value': '[0, mx]'},{'id': '89', 'type': 'integer', 'children': [], 'value': '0'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'mx'},{'id': '91', 'type': 'list', 'children': ['92', '93'], 'value': '[0, mx]'},{'id': '92', 'type': 'integer', 'children': [], 'value': '0'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'mx'},{'id': '94', 'type': 'string', 'children': [], 'value': "'1:1'"},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'addXY'},{'id': '100', 'type': 'argument_list', 'children': ['101', '102', '103']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'c_mdl'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'c_obs'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'key_text'},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'locs'},{'id': '107', 'type': 'binary_operator', 'children': ['108', '123'], 'value': '*'},{'id': '108', 'type': 'call', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'list', 'children': ['114', '115', '116', '117', '118', '119', '120', '121', '122'], 'value': '[0, 0.05, 0.08, 0.11, 0.17, 0.3, 0.4, 0.7, 1]'},{'id': '114', 'type': 'integer', 'children': [], 'value': '0'},{'id': '115', 'type': 'float', 'children': [], 'value': '0.05'},{'id': '116', 'type': 'float', 'children': [], 'value': '0.08'},{'id': '117', 'type': 'float', 'children': [], 'value': '0.11'},{'id': '118', 'type': 'float', 'children': [], 'value': '0.17'},{'id': '119', 'type': 'float', 'children': [], 'value': '0.3'},{'id': '120', 'type': 'float', 'children': [], 'value': '0.4'},{'id': '121', 'type': 'float', 'children': [], 'value': '0.7'},{'id': '122', 'type': 'integer', 'children': [], 'value': '1'},{'id': '123', 'type': '()', 'children': ['124']},{'id': '124', 'type': 'binary_operator', 'children': ['125', '128'], 'value': '-'},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'kev'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '128', 'type': 'integer', 'children': [], 'value': '2'},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'assignment', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'c0'},{'id': '132', 'type': 'binary_operator', 'children': ['133', '134'], 'value': '*'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'mx'},{'id': '134', 'type': 'float', 'children': [], 'value': '1.05'},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'assignment', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'c1'},{'id': '138', 'type': 'binary_operator', 'children': ['139', '140'], 'value': '*'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'mx'},{'id': '140', 'type': 'float', 'children': [], 'value': '1.1'},{'id': '141', 'type': 'for_statement', 'children': ['142', '143', '144']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'locs'},{'id': '144', 'type': 'block', 'children': ['145', '157', '163', '182', '201', '220', '238']},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'i0'},{'id': '148', 'type': 'call', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'int'},{'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': 'np'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'floor'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'frac'},{'id': '160', 'type': 'binary_operator', 'children': ['161', '162'], 'value': '-'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'i0'},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'kevval'},{'id': '166', 'type': 'binary_operator', 'children': ['167', '175'], 'value': '+'},{'id': '167', 'type': 'binary_operator', 'children': ['168', '172'], 'value': '*'},{'id': '168', 'type': '()', 'children': ['169']},{'id': '169', 'type': 'binary_operator', 'children': ['170', '171'], 'value': '-'},{'id': '170', 'type': 'integer', 'children': [], 'value': '1'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'frac'},{'id': '172', 'type': 'subscript', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'kev'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'i0'},{'id': '175', 'type': 'binary_operator', 'children': ['176', '177'], 'value': '*'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'frac'},{'id': '177', 'type': 'subscript', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'kev'},{'id': '179', 'type': 'binary_operator', 'children': ['180', '181'], 'value': '+'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'i0'},{'id': '181', 'type': 'integer', 'children': [], 'value': '1'},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'mdlval'},{'id': '185', 'type': 'binary_operator', 'children': ['186', '194'], 'value': '+'},{'id': '186', 'type': 'binary_operator', 'children': ['187', '191'], 'value': '*'},{'id': '187', 'type': '()', 'children': ['188']},{'id': '188', 'type': 'binary_operator', 'children': ['189', '190'], 'value': '-'},{'id': '189', 'type': 'integer', 'children': [], 'value': '1'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'frac'},{'id': '191', 'type': 'subscript', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'c_mdl'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'i0'},{'id': '194', 'type': 'binary_operator', 'children': ['195', '196'], 'value': '*'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'frac'},{'id': '196', 'type': 'subscript', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'c_mdl'},{'id': '198', 'type': 'binary_operator', 'children': ['199', '200'], 'value': '+'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'i0'},{'id': '200', 'type': 'integer', 'children': [], 'value': '1'},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'assignment', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'obsval'},{'id': '204', 'type': 'binary_operator', 'children': ['205', '213'], 'value': '+'},{'id': '205', 'type': 'binary_operator', 'children': ['206', '210'], 'value': '*'},{'id': '206', 'type': '()', 'children': ['207']},{'id': '207', 'type': 'binary_operator', 'children': ['208', '209'], 'value': '-'},{'id': '208', 'type': 'integer', 'children': [], 'value': '1'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'frac'},{'id': '210', 'type': 'subscript', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'c_obs'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'i0'},{'id': '213', 'type': 'binary_operator', 'children': ['214', '215'], 'value': '*'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'frac'},{'id': '215', 'type': 'subscript', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'c_obs'},{'id': '217', 'type': 'binary_operator', 'children': ['218', '219'], 'value': '+'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'i0'},{'id': '219', 'type': 'integer', 'children': [], 'value': '1'},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'call', 'children': ['222', '225']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'addXY'},{'id': '225', 'type': 'argument_list', 'children': ['226', '229', '232', '235']},{'id': '226', 'type': 'list', 'children': ['227', '228'], 'value': '[mdlval, mdlval]'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'mdlval'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'mdlval'},{'id': '229', 'type': 'list', 'children': ['230', '231'], 'value': '[c0, c1]'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'c0'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'c1'},{'id': '232', 'type': 'binary_operator', 'children': ['233', '234'], 'value': '%'},{'id': '233', 'type': 'string', 'children': [], 'value': "'%.2f keV'"},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'kevval'},{'id': '235', 'type': 'keyword_argument', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'dsn'},{'id': '237', 'type': 'integer', 'children': [], 'value': '2'},{'id': '238', 'type': 'expression_statement', 'children': ['239']},{'id': '239', 'type': 'call', 'children': ['240', '243']},{'id': '240', 'type': 'attribute', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'addXY'},{'id': '243', 'type': 'argument_list', 'children': ['244', '247', '250', '251']},{'id': '244', 'type': 'list', 'children': ['245', '246'], 'value': '[c0, c1]'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'c0'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'c1'},{'id': '247', 'type': 'list', 'children': ['248', '249'], 'value': '[obsval, obsval]'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'obsval'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'obsval'},{'id': '250', 'type': 'None', 'children': []},{'id': '251', 'type': 'keyword_argument', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'dsn'},{'id': '253', 'type': 'integer', 'children': [], 'value': '2'},{'id': '254', 'type': 'expression_statement', 'children': ['255']},{'id': '255', 'type': 'call', 'children': ['256', '259']},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'setLabels'},{'id': '259', 'type': 'argument_list', 'children': ['260', '263']},{'id': '260', 'type': 'binary_operator', 'children': ['261', '262'], 'value': '+'},{'id': '261', 'type': 'string', 'children': [], 'value': "'Cumulative model '"},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'unit'},{'id': '263', 'type': 'binary_operator', 'children': ['264', '265'], 'value': '+'},{'id': '264', 'type': 'string', 'children': [], 'value': "'Cumulative data '"},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'unit'},{'id': '266', 'type': 'expression_statement', 'children': ['267']},{'id': '267', 'type': 'assignment', 'children': ['268', '273']},{'id': '268', 'type': 'attribute', 'children': ['269', '272']},{'id': '269', 'type': 'attribute', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'defaultKeyOverlay'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'vAlign'},{'id': '273', 'type': 'float', 'children': [], 'value': '0.3'},{'id': '274', 'type': 'return_statement', 'children': ['275']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'p'}
def make_qq_plot(kev, obs, mdl, unit, key_text): import omega as om kev = np.asarray(kev) obs = np.asarray(obs) mdl = np.asarray(mdl) c_obs = np.cumsum(obs) c_mdl = np.cumsum(mdl) mx = max(c_obs[-1], c_mdl[-1]) p = om.RectPlot() p.addXY([0, mx], [0, mx], '1:1') p.addXY(c_mdl, c_obs, key_text) locs = np.array([0, 0.05, 0.08, 0.11, 0.17, 0.3, 0.4, 0.7, 1]) * (kev.size - 2) c0 = mx * 1.05 c1 = mx * 1.1 for loc in locs: i0 = int(np.floor(loc)) frac = loc - i0 kevval = (1 - frac) * kev[i0] + frac * kev[i0+1] mdlval = (1 - frac) * c_mdl[i0] + frac * c_mdl[i0+1] obsval = (1 - frac) * c_obs[i0] + frac * c_obs[i0+1] p.addXY([mdlval, mdlval], [c0, c1], '%.2f keV' % kevval, dsn=2) p.addXY([c0, c1], [obsval, obsval], None, dsn=2) p.setLabels('Cumulative model ' + unit, 'Cumulative data ' + unit) p.defaultKeyOverlay.vAlign = 0.3 return p
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_qr_factor_full'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '7', 'type': 'attribute', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '10', 'type': 'block', 'children': ['11', '19', '32', '43', '73', '82', '91', '152']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '16']},{'id': '13', 'type': 'pattern_list', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '26', '27']},{'id': '21', 'type': 'pattern_list', 'children': ['22', '23', '24', '25']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'packed'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'pmut'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'rdiag'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'acnorm'},{'id': '26', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': '_manual_qr_factor_packed'},{'id': '29', 'type': 'argument_list', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', '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': 'np'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'zeros'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'tuple', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '43', 'type': 'for_statement', 'children': ['44', '45', '49']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '49', 'type': 'block', 'children': ['50', '64']},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '58']},{'id': '52', 'type': 'subscript', 'children': ['53', '54', '55']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '55', 'type': 'slice', 'children': ['56', '57']},{'id': '56', 'type': 'colon', 'children': []},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '58', 'type': 'subscript', 'children': ['59', '60', '61']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'packed'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '61', 'type': 'slice', 'children': ['62', '63']},{'id': '62', 'type': 'colon', 'children': []},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '70']},{'id': '66', 'type': 'subscript', 'children': ['67', '68', '69']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '70', 'type': 'subscript', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'rdiag'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'q'},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'eye'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'v'},{'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': 'empty'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '91', 'type': 'for_statement', 'children': ['92', '93', '97']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '93', 'type': 'call', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '97', 'type': 'block', 'children': ['98', '107', '115', '142']},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '104']},{'id': '100', 'type': 'subscript', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '102', 'type': 'slice', 'children': ['103']},{'id': '103', 'type': 'colon', 'children': []},{'id': '104', 'type': 'subscript', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'packed'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '114']},{'id': '109', 'type': 'subscript', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '111', 'type': 'slice', 'children': ['112', '113']},{'id': '112', 'type': 'colon', 'children': []},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '114', 'type': 'integer', 'children': [], 'value': '0'},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'hhm'},{'id': '118', 'type': 'binary_operator', 'children': ['119', '125'], 'value': '-'},{'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': 'eye'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '125', 'type': 'binary_operator', 'children': ['126', '135'], 'value': '/'},{'id': '126', 'type': 'binary_operator', 'children': ['127', '128'], 'value': '*'},{'id': '127', 'type': 'integer', 'children': [], 'value': '2'},{'id': '128', 'type': 'call', 'children': ['129', '132']},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'outer'},{'id': '132', 'type': 'argument_list', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'dot'},{'id': '139', 'type': 'argument_list', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'q'},{'id': '145', 'type': 'call', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'dot'},{'id': '149', 'type': 'argument_list', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'hhm'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'q'},{'id': '152', 'type': 'return_statement', 'children': ['153']},{'id': '153', 'type': 'expression_list', 'children': ['154', '155', '156']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'q'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'pmut'}
def _qr_factor_full(a, dtype=np.float): n, m = a.shape packed, pmut, rdiag, acnorm = \ _manual_qr_factor_packed(a, dtype) r = np.zeros((n, m)) for i in range(n): r[i,:i] = packed[i,:i] r[i,i] = rdiag[i] q = np.eye(m) v = np.empty(m) for i in range(n): v[:] = packed[i] v[:i] = 0 hhm = np.eye(m) - 2 * np.outer(v, v) / np.dot(v, v) q = np.dot(hhm, q) return q, r, pmut
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_qrd_solve_full'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'ddiag'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '12', 'type': 'block', 'children': ['13', '23', '33', '43', '51', '55', '62', '69', '79', '91', '115']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'asarray'},{'id': '20', 'type': 'argument_list', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'b'},{'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': 'asarray'},{'id': '30', 'type': 'argument_list', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'ddiag'},{'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': 'asarray'},{'id': '40', 'type': 'argument_list', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'ddiag'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '48']},{'id': '45', 'type': 'pattern_list', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '51', 'type': 'assert_statement', 'children': ['52']},{'id': '52', 'type': 'comparison_operator', 'children': ['53', '54'], 'value': '>='},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '55', 'type': 'assert_statement', 'children': ['56']},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '60'], 'value': '=='},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '60', 'type': 'tuple', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '62', 'type': 'assert_statement', 'children': ['63']},{'id': '63', 'type': 'comparison_operator', 'children': ['64', '67'], 'value': '=='},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'ddiag'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '67', 'type': 'tuple', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '75']},{'id': '71', 'type': 'pattern_list', 'children': ['72', '73', '74']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'q'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'pmut'},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': '_qr_factor_full'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'bqt'},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'dot'},{'id': '86', 'type': 'argument_list', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'q'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '96']},{'id': '93', 'type': 'pattern_list', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': '_manual_qrd_solve'},{'id': '98', 'type': 'argument_list', 'children': ['99', '106', '107', '108', '109', '112']},{'id': '99', 'type': 'subscript', 'children': ['100', '101', '103']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '101', 'type': 'slice', 'children': ['102']},{'id': '102', 'type': 'colon', 'children': []},{'id': '103', 'type': 'slice', 'children': ['104', '105']},{'id': '104', 'type': 'colon', 'children': []},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'pmut'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'ddiag'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'bqt'},{'id': '109', 'type': 'keyword_argument', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '112', 'type': 'keyword_argument', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'build_s'},{'id': '114', 'type': 'True', 'children': []},{'id': '115', 'type': 'return_statement', 'children': ['116']},{'id': '116', 'type': 'expression_list', 'children': ['117', '118', '119']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'pmut'}
def _qrd_solve_full(a, b, ddiag, dtype=np.float): a = np.asarray(a, dtype) b = np.asarray(b, dtype) ddiag = np.asarray(ddiag, dtype) n, m = a.shape assert m >= n assert b.shape == (m, ) assert ddiag.shape == (n, ) q, r, pmut = _qr_factor_full(a) bqt = np.dot(b, q.T) x, s = _manual_qrd_solve(r[:,:n], pmut, ddiag, bqt, dtype=dtype, build_s=True) return x, s, pmut
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'concat'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'invises'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'outvis'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'timesort'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '20', '30', '47', '69', '81', '97', '103', '116', '148', '160', '182', '204', '213']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'tb'},{'id': '13', 'type': 'call', 'children': ['14', '19']},{'id': '14', 'type': 'attribute', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'util'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'tools'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '19', 'type': 'argument_list', 'children': []},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'ms'},{'id': '23', 'type': 'call', 'children': ['24', '29']},{'id': '24', 'type': 'attribute', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'util'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'tools'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'ms'},{'id': '29', 'type': 'argument_list', 'children': []},{'id': '30', 'type': 'if_statement', 'children': ['31', '39']},{'id': '31', 'type': 'call', 'children': ['32', '37']},{'id': '32', 'type': 'attribute', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'outvis'},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'raise_statement', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'binary_operator', 'children': ['45', '46'], 'value': '%'},{'id': '45', 'type': 'string', 'children': [], 'value': '\'output "%s" already exists\''},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'outvis'},{'id': '47', 'type': 'for_statement', 'children': ['48', '49', '50']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'invis'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'invises'},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'if_statement', 'children': ['52', '61']},{'id': '52', 'type': 'not_operator', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '59']},{'id': '54', 'type': 'attribute', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'isdir'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'invis'},{'id': '61', 'type': 'block', 'children': ['62']},{'id': '62', 'type': 'raise_statement', 'children': ['63']},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'binary_operator', 'children': ['67', '68'], 'value': '%'},{'id': '67', 'type': 'string', 'children': [], 'value': '\'input "%s" does not exist\''},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'invis'},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'tb'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'subscript', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'invises'},{'id': '80', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'tb'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '86', 'type': 'argument_list', 'children': ['87', '91', '94']},{'id': '87', 'type': 'call', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'outvis'},{'id': '91', 'type': 'keyword_argument', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'deep'},{'id': '93', 'type': 'True', 'children': []},{'id': '94', 'type': 'keyword_argument', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'valuecopy'},{'id': '96', 'type': 'True', 'children': []},{'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': 'tb'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '102', 'type': 'argument_list', 'children': []},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'call', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'ms'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '108', 'type': 'argument_list', 'children': ['109', '113']},{'id': '109', 'type': 'call', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'outvis'},{'id': '113', 'type': 'keyword_argument', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'nomodify'},{'id': '115', 'type': 'False', 'children': []},{'id': '116', 'type': 'for_statement', 'children': ['117', '118', '123']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'invis'},{'id': '118', 'type': 'subscript', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'invises'},{'id': '120', 'type': 'slice', 'children': ['121', '122']},{'id': '121', 'type': 'integer', 'children': [], 'value': '1'},{'id': '122', 'type': 'colon', 'children': []},{'id': '123', 'type': 'block', 'children': ['124']},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'call', 'children': ['126', '129']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'ms'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'concatenate'},{'id': '129', 'type': 'argument_list', 'children': ['130', '136', '142']},{'id': '130', 'type': 'keyword_argument', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'msfile'},{'id': '132', 'type': 'call', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'invis'},{'id': '136', 'type': 'keyword_argument', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'freqtol'},{'id': '138', 'type': 'call', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'concat_freqtol'},{'id': '142', 'type': 'keyword_argument', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'dirtol'},{'id': '144', 'type': 'call', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'concat_dirtol'},{'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': 'ms'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'writehistory'},{'id': '153', 'type': 'argument_list', 'children': ['154', '157']},{'id': '154', 'type': 'keyword_argument', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '156', 'type': 'string', 'children': [], 'value': "b'taskname=tasklib.concat'"},{'id': '157', 'type': 'keyword_argument', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'origin'},{'id': '159', 'type': 'string', 'children': [], 'value': "b'tasklib.concat'"},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'call', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'ms'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'writehistory'},{'id': '165', 'type': 'argument_list', 'children': ['166', '179']},{'id': '166', 'type': 'keyword_argument', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '168', 'type': 'call', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'binary_operator', 'children': ['172', '173'], 'value': '+'},{'id': '172', 'type': 'string', 'children': [], 'value': "'vis = '"},{'id': '173', 'type': 'call', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'string', 'children': [], 'value': "', '"},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '177', 'type': 'argument_list', 'children': ['178']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'invises'},{'id': '179', 'type': 'keyword_argument', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'origin'},{'id': '181', 'type': 'string', 'children': [], 'value': "b'tasklib.concat'"},{'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': 'ms'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'writehistory'},{'id': '187', 'type': 'argument_list', 'children': ['188', '201']},{'id': '188', 'type': 'keyword_argument', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '190', 'type': 'call', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'binary_operator', 'children': ['194', '195'], 'value': '+'},{'id': '194', 'type': 'string', 'children': [], 'value': "'timesort = '"},{'id': '195', 'type': 'subscript', 'children': ['196', '197']},{'id': '196', 'type': 'string', 'children': [], 'value': "'FT'"},{'id': '197', 'type': 'call', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '199', 'type': 'argument_list', 'children': ['200']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'timesort'},{'id': '201', 'type': 'keyword_argument', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'origin'},{'id': '203', 'type': 'string', 'children': [], 'value': "b'tasklib.concat'"},{'id': '204', 'type': 'if_statement', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'timesort'},{'id': '206', 'type': 'block', 'children': ['207']},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'call', 'children': ['209', '212']},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'ms'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'timesort'},{'id': '212', 'type': 'argument_list', 'children': []},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'call', 'children': ['215', '218']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'ms'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '218', 'type': 'argument_list', 'children': []}
def concat(invises, outvis, timesort=False): tb = util.tools.table() ms = util.tools.ms() if os.path.exists(outvis): raise RuntimeError('output "%s" already exists' % outvis) for invis in invises: if not os.path.isdir(invis): raise RuntimeError('input "%s" does not exist' % invis) tb.open(b(invises[0])) tb.copy(b(outvis), deep=True, valuecopy=True) tb.close() ms.open(b(outvis), nomodify=False) for invis in invises[1:]: ms.concatenate(msfile=b(invis), freqtol=b(concat_freqtol), dirtol=b(concat_dirtol)) ms.writehistory(message=b'taskname=tasklib.concat', origin=b'tasklib.concat') ms.writehistory(message=b('vis = ' + ', '.join(invises)), origin=b'tasklib.concat') ms.writehistory(message=b('timesort = ' + 'FT'[int(timesort)]), origin=b'tasklib.concat') if timesort: ms.timesort() ms.close()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_zones_of_account'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'account_name'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'q'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'dictionary_splat_pattern', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '11', 'type': 'block', 'children': ['12', '20', '28']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'uri'},{'id': '15', 'type': 'binary_operator', 'children': ['16', '19'], 'value': '+'},{'id': '16', 'type': 'binary_operator', 'children': ['17', '18'], 'value': '+'},{'id': '17', 'type': 'string', 'children': [], 'value': '"/v1/accounts/"'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'account_name'},{'id': '19', 'type': 'string', 'children': [], 'value': '"/zones"'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'build_params'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'q'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '28', 'type': 'return_statement', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '35']},{'id': '30', 'type': 'attribute', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'rest_api_connection'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '35', 'type': 'argument_list', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'uri'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'params'}
def get_zones_of_account(self, account_name, q=None, **kwargs): uri = "/v1/accounts/" + account_name + "/zones" params = build_params(q, kwargs) return self.rest_api_connection.get(uri, params)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_zones'},{'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': 'q'},{'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', '15', '23']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'uri'},{'id': '14', 'type': 'string', 'children': [], 'value': '"/v1/zones"'},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'build_params'},{'id': '20', 'type': 'argument_list', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'q'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '23', 'type': 'return_statement', 'children': ['24']},{'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': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'rest_api_connection'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '30', 'type': 'argument_list', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'uri'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'params'}
def get_zones(self, q=None, **kwargs): uri = "/v1/zones" params = build_params(q, kwargs) return self.rest_api_connection.get(uri, params)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_rrsets'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'zone_name'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'q'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'dictionary_splat_pattern', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '11', 'type': 'block', 'children': ['12', '20', '28']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'uri'},{'id': '15', 'type': 'binary_operator', 'children': ['16', '19'], 'value': '+'},{'id': '16', 'type': 'binary_operator', 'children': ['17', '18'], 'value': '+'},{'id': '17', 'type': 'string', 'children': [], 'value': '"/v1/zones/"'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'zone_name'},{'id': '19', 'type': 'string', 'children': [], 'value': '"/rrsets"'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'build_params'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'q'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '28', 'type': 'return_statement', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '35']},{'id': '30', 'type': 'attribute', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'rest_api_connection'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '35', 'type': 'argument_list', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'uri'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'params'}
def get_rrsets(self, zone_name, q=None, **kwargs): uri = "/v1/zones/" + zone_name + "/rrsets" params = build_params(q, kwargs) return self.rest_api_connection.get(uri, params)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'nested_tuple'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'container'},{'id': '5', 'type': 'block', 'children': ['6', '26', '49', '107']},{'id': '6', 'type': 'if_statement', 'children': ['7', '12']},{'id': '7', 'type': 'call', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '9', 'type': 'argument_list', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'container'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '12', 'type': 'block', 'children': ['13']},{'id': '13', 'type': 'return_statement', 'children': ['14']},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '19', 'type': 'argument_list', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'nested_tuple'},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'container'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '25', 'type': 'argument_list', 'children': []},{'id': '26', 'type': 'if_statement', 'children': ['27', '32']},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '29', 'type': 'argument_list', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'container'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'Mapping'},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'return_statement', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'sorted_if_possible'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '42', 'type': 'argument_list', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'nested_tuple'},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'container'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '48', 'type': 'argument_list', 'children': []},{'id': '49', 'type': 'if_statement', 'children': ['50', '58']},{'id': '50', 'type': 'not_operator', 'children': ['51']},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '53', 'type': 'argument_list', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'container'},{'id': '55', 'type': 'tuple', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'bytes'},{'id': '58', 'type': 'block', 'children': ['59', '75']},{'id': '59', 'type': 'if_statement', 'children': ['60', '65']},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '62', 'type': 'argument_list', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'container'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'Sequence'},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'return_statement', 'children': ['67']},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '72', 'type': 'argument_list', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'nested_tuple'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'container'},{'id': '75', 'type': 'if_statement', 'children': ['76', '94']},{'id': '76', 'type': '()', 'children': ['77']},{'id': '77', 'type': 'boolean_operator', 'children': ['78', '89'], 'value': 'and'},{'id': '78', 'type': 'boolean_operator', 'children': ['79', '84'], 'value': 'and'},{'id': '79', 'type': 'call', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '81', 'type': 'argument_list', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'container'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'Container'},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '86', 'type': 'argument_list', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'container'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'Iterable'},{'id': '89', 'type': 'call', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '91', 'type': 'argument_list', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'container'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'Sized'},{'id': '94', 'type': 'block', 'children': ['95']},{'id': '95', 'type': 'return_statement', 'children': ['96']},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'call', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'sorted_if_possible'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'call', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '104', 'type': 'argument_list', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'nested_tuple'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'container'},{'id': '107', 'type': 'return_statement', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'container'}
def nested_tuple(container): if isinstance(container, OrderedDict): return tuple(map(nested_tuple, container.items())) if isinstance(container, Mapping): return tuple(sorted_if_possible(map(nested_tuple, container.items()))) if not isinstance(container, (str, bytes)): if isinstance(container, Sequence): return tuple(map(nested_tuple, container)) if ( isinstance(container, Container) and isinstance(container, Iterable) and isinstance(container, Sized) ): return tuple(sorted_if_possible(map(nested_tuple, container))) return container
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_ranges_key'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'delta_indices'},{'id': '6', 'type': 'block', 'children': ['7', '13']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'index_symbol'},{'id': '13', 'type': 'if_statement', 'children': ['14', '17', '30']},{'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': 'in'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'delta_indices'},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'return_statement', 'children': ['19']},{'id': '19', 'type': 'tuple', 'children': ['20', '25']},{'id': '20', 'type': 'attribute', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'index_symbol'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'primed'},{'id': '25', 'type': 'attribute', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'index_symbol'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '30', 'type': 'else_clause', 'children': ['31']},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'return_statement', 'children': ['33']},{'id': '33', 'type': 'tuple', 'children': ['34', '35']},{'id': '34', 'type': 'integer', 'children': [], 'value': '0'},{'id': '35', 'type': 'string', 'children': [], 'value': "' '"}
def _ranges_key(r, delta_indices): idx = r.index_symbol if idx in delta_indices: return (r.index_symbol.primed, r.index_symbol.name) else: return (0, ' ')
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'plot'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'row_order'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'imshow_kwargs'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '14', 'type': 'True', 'children': []},{'id': '15', 'type': 'block', 'children': ['16', '26', '40', '54', '67', '76', '91', '101', '132', '147', '155', '172', '217', '224', '245', '254', '316', '328', '334']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'nrows'},{'id': '19', 'type': 'subscript', 'children': ['20', '25']},{'id': '20', 'type': 'attribute', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'diffed_array'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '25', 'type': 'integer', 'children': [], 'value': '0'},{'id': '26', 'type': 'if_statement', 'children': ['27', '30']},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': 'is'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'row_order'},{'id': '29', 'type': 'None', 'children': []},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'row_order'},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'arange'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'nrows'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'extent'},{'id': '43', 'type': 'tuple', 'children': ['44', '48', '52', '53']},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '52', 'type': 'integer', 'children': [], 'value': '0'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'nrows'},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'axes_info'},{'id': '57', 'type': 'call', 'children': ['58', '63']},{'id': '58', 'type': 'attribute', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'metaseq'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'plotutils'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'matrix_and_line_shell'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'keyword_argument', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '75']},{'id': '69', 'type': 'pattern_list', 'children': ['70', '71', '72', '73', '74']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'fig'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'matrix_ax'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'line_ax'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'strip_ax'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'cbar_ax'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'axes_info'},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': '_imshow_kwargs'},{'id': '79', 'type': 'call', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '81', 'type': 'argument_list', 'children': ['82', '85', '88']},{'id': '82', 'type': 'keyword_argument', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'aspect'},{'id': '84', 'type': 'string', 'children': [], 'value': "'auto'"},{'id': '85', 'type': 'keyword_argument', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'extent'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'extent'},{'id': '88', 'type': 'keyword_argument', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'interpolation'},{'id': '90', 'type': 'string', 'children': [], 'value': "'nearest'"},{'id': '91', 'type': 'if_statement', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'imshow_kwargs'},{'id': '93', 'type': 'block', 'children': ['94']},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'call', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': '_imshow_kwargs'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'imshow_kwargs'},{'id': '101', 'type': 'if_statement', 'children': ['102', '105']},{'id': '102', 'type': 'comparison_operator', 'children': ['103', '104'], 'value': 'not'},{'id': '103', 'type': 'string', 'children': [], 'value': "'cmap'"},{'id': '104', 'type': 'identifier', 'children': [], 'value': '_imshow_kwargs'},{'id': '105', 'type': 'block', 'children': ['106']},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '111']},{'id': '108', 'type': 'subscript', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': '_imshow_kwargs'},{'id': '110', 'type': 'string', 'children': [], 'value': "'cmap'"},{'id': '111', 'type': 'call', 'children': ['112', '117']},{'id': '112', 'type': 'attribute', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'metaseq'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'colormap_adjust'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'smart_colormap'},{'id': '117', 'type': 'argument_list', 'children': ['118', '125']},{'id': '118', 'type': 'call', 'children': ['119', '124']},{'id': '119', 'type': 'attribute', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'diffed_array'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '124', 'type': 'argument_list', 'children': []},{'id': '125', 'type': 'call', 'children': ['126', '131']},{'id': '126', 'type': 'attribute', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'diffed_array'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '131', 'type': 'argument_list', 'children': []},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'mappable'},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'matrix_ax'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'imshow'},{'id': '139', 'type': 'argument_list', 'children': ['140', '145']},{'id': '140', 'type': 'subscript', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'diffed_array'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'row_order'},{'id': '145', 'type': 'dictionary_splat', 'children': ['146']},{'id': '146', 'type': 'identifier', 'children': [], 'value': '_imshow_kwargs'},{'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': 'plt'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'colorbar'},{'id': '152', 'type': 'argument_list', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'mappable'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'cbar_ax'},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'call', 'children': ['157', '160']},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'line_ax'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'plot'},{'id': '160', 'type': 'argument_list', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '162', 'type': 'call', 'children': ['163', '168']},{'id': '163', 'type': 'attribute', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'diffed_array'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'mean'},{'id': '168', 'type': 'argument_list', 'children': ['169']},{'id': '169', 'type': 'keyword_argument', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '171', 'type': 'integer', 'children': [], 'value': '0'},{'id': '172', 'type': 'if_statement', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'strip_ax'},{'id': '174', 'type': 'block', 'children': ['175', '203', '211']},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'assignment', 'children': ['177', '179']},{'id': '177', 'type': 'pattern_list', 'children': ['178']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '179', 'type': 'call', 'children': ['180', '183']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'strip_ax'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'plot'},{'id': '183', 'type': 'argument_list', 'children': ['184', '191', '199']},{'id': '184', 'type': 'call', 'children': ['185', '188']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'zeros'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'tuple', 'children': ['190']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'nrows'},{'id': '191', 'type': 'binary_operator', 'children': ['192', '198'], 'value': '+'},{'id': '192', 'type': 'call', 'children': ['193', '196']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'arange'},{'id': '196', 'type': 'argument_list', 'children': ['197']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'nrows'},{'id': '198', 'type': 'float', 'children': [], 'value': '0.5'},{'id': '199', 'type': 'dictionary_splat', 'children': ['200']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '202', 'type': 'identifier', 'children': [], 'value': '_strip_kwargs'},{'id': '203', 'type': 'expression_statement', 'children': ['204']},{'id': '204', 'type': 'assignment', 'children': ['205', '208']},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'features'},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'features'},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'assignment', 'children': ['213', '216']},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'ind'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'row_order'},{'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': 'matrix_ax'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'string', 'children': [], 'value': "'tight'"},{'id': '224', 'type': 'if_statement', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'strip_ax'},{'id': '226', 'type': 'block', 'children': ['227', '236']},{'id': '227', 'type': 'expression_statement', 'children': ['228']},{'id': '228', 'type': 'call', 'children': ['229', '234']},{'id': '229', 'type': 'attribute', 'children': ['230', '233']},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'strip_ax'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'xaxis'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'set_visible'},{'id': '234', 'type': 'argument_list', 'children': ['235']},{'id': '235', 'type': 'False', 'children': []},{'id': '236', 'type': 'expression_statement', 'children': ['237']},{'id': '237', 'type': 'call', 'children': ['238', '243']},{'id': '238', 'type': 'attribute', 'children': ['239', '242']},{'id': '239', 'type': 'attribute', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'matrix_ax'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'yaxis'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'set_visible'},{'id': '243', 'type': 'argument_list', 'children': ['244']},{'id': '244', 'type': 'False', 'children': []},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'call', 'children': ['247', '252']},{'id': '247', 'type': 'attribute', 'children': ['248', '251']},{'id': '248', 'type': 'attribute', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'matrix_ax'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'xaxis'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'set_visible'},{'id': '252', 'type': 'argument_list', 'children': ['253']},{'id': '253', 'type': 'False', 'children': []},{'id': '254', 'type': 'if_statement', 'children': ['255', '258', '289']},{'id': '255', 'type': 'attribute', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '258', 'type': 'block', 'children': ['259']},{'id': '259', 'type': 'expression_statement', 'children': ['260']},{'id': '260', 'type': 'assignment', 'children': ['261', '264']},{'id': '261', 'type': 'attribute', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'minibrowser'},{'id': '264', 'type': 'call', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'GeneChipseqMiniBrowser'},{'id': '266', 'type': 'argument_list', 'children': ['267', '274', '279', '284']},{'id': '267', 'type': 'list', 'children': ['268', '271'], 'value': '[self.ip, self.control]'},{'id': '268', 'type': 'attribute', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'ip'},{'id': '271', 'type': 'attribute', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'control'},{'id': '274', 'type': 'keyword_argument', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '276', 'type': 'attribute', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '279', 'type': 'keyword_argument', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'plotting_kwargs'},{'id': '281', 'type': 'attribute', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'browser_plotting_kwargs'},{'id': '284', 'type': 'keyword_argument', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'local_coverage_kwargs'},{'id': '286', 'type': 'attribute', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'browser_local_coverage_kwargs'},{'id': '289', 'type': 'else_clause', 'children': ['290']},{'id': '290', 'type': 'block', 'children': ['291']},{'id': '291', 'type': 'expression_statement', 'children': ['292']},{'id': '292', 'type': 'assignment', 'children': ['293', '296']},{'id': '293', 'type': 'attribute', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'minibrowser'},{'id': '296', 'type': 'call', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'SignalChipseqMiniBrowser'},{'id': '298', 'type': 'argument_list', 'children': ['299', '306', '311']},{'id': '299', 'type': 'list', 'children': ['300', '303'], 'value': '[self.ip, self.control]'},{'id': '300', 'type': 'attribute', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'ip'},{'id': '303', 'type': 'attribute', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'control'},{'id': '306', 'type': 'keyword_argument', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'plotting_kwargs'},{'id': '308', 'type': 'attribute', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'browser_plotting_kwargs'},{'id': '311', 'type': 'keyword_argument', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'local_coverage_kwargs'},{'id': '313', 'type': 'attribute', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'browser_local_coverage_kwargs'},{'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': 'fig'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'canvas'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'mpl_connect'},{'id': '323', 'type': 'argument_list', 'children': ['324', '325']},{'id': '324', 'type': 'string', 'children': [], 'value': "'pick_event'"},{'id': '325', 'type': 'attribute', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'callback'},{'id': '328', 'type': 'expression_statement', 'children': ['329']},{'id': '329', 'type': 'assignment', 'children': ['330', '333']},{'id': '330', 'type': 'attribute', 'children': ['331', '332']},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'fig'},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'fig'},{'id': '334', 'type': 'expression_statement', 'children': ['335']},{'id': '335', 'type': 'assignment', 'children': ['336', '339']},{'id': '336', 'type': 'attribute', 'children': ['337', '338']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'axes'},{'id': '339', 'type': 'dictionary', 'children': ['340', '343', '346', '349']},{'id': '340', 'type': 'pair', 'children': ['341', '342']},{'id': '341', 'type': 'string', 'children': [], 'value': "'matrix_ax'"},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'matrix_ax'},{'id': '343', 'type': 'pair', 'children': ['344', '345']},{'id': '344', 'type': 'string', 'children': [], 'value': "'strip_ax'"},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'strip_ax'},{'id': '346', 'type': 'pair', 'children': ['347', '348']},{'id': '347', 'type': 'string', 'children': [], 'value': "'line_ax'"},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'line_ax'},{'id': '349', 'type': 'pair', 'children': ['350', '351']},{'id': '350', 'type': 'string', 'children': [], 'value': "'cbar_ax'"},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'cbar_ax'}
def plot(self, x, row_order=None, imshow_kwargs=None, strip=True): nrows = self.diffed_array.shape[0] if row_order is None: row_order = np.arange(nrows) extent = (min(x), max(x), 0, nrows) axes_info = metaseq.plotutils.matrix_and_line_shell(strip=strip) fig, matrix_ax, line_ax, strip_ax, cbar_ax = axes_info _imshow_kwargs = dict( aspect='auto', extent=extent, interpolation='nearest') if imshow_kwargs: _imshow_kwargs.update(imshow_kwargs) if 'cmap' not in _imshow_kwargs: _imshow_kwargs['cmap'] = metaseq.colormap_adjust.smart_colormap( self.diffed_array.min(), self.diffed_array.max() ) mappable = matrix_ax.imshow( self.diffed_array[row_order], **_imshow_kwargs) plt.colorbar(mappable, cbar_ax) line_ax.plot(x, self.diffed_array.mean(axis=0)) if strip_ax: line, = strip_ax.plot(np.zeros((nrows,)), np.arange(nrows) + 0.5, **self._strip_kwargs) line.features = self.features line.ind = row_order matrix_ax.axis('tight') if strip_ax: strip_ax.xaxis.set_visible(False) matrix_ax.yaxis.set_visible(False) matrix_ax.xaxis.set_visible(False) if self.db: self.minibrowser = GeneChipseqMiniBrowser( [self.ip, self.control], db=self.db, plotting_kwargs=self.browser_plotting_kwargs, local_coverage_kwargs=self.browser_local_coverage_kwargs) else: self.minibrowser = SignalChipseqMiniBrowser( [self.ip, self.control], plotting_kwargs=self.browser_plotting_kwargs, local_coverage_kwargs=self.browser_local_coverage_kwargs) fig.canvas.mpl_connect('pick_event', self.callback) self.fig = fig self.axes = { 'matrix_ax': matrix_ax, 'strip_ax': strip_ax, 'line_ax': line_ax, 'cbar_ax': cbar_ax }
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_restricted_growth_notation'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '5', 'type': 'block', 'children': ['6', '13', '20', '38', '45', '74']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'list_length'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '20', 'type': 'for_statement', 'children': ['21', '24', '28']},{'id': '21', 'type': 'tuple_pattern', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '36']},{'id': '31', 'type': 'attribute', 'children': ['32', '35']},{'id': '32', 'type': 'subscript', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'l2'},{'id': '41', 'type': 'binary_operator', 'children': ['42', '44'], 'value': '*'},{'id': '42', 'type': 'list', 'children': ['43'], 'value': '[None]'},{'id': '43', 'type': 'None', 'children': []},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'list_length'},{'id': '45', 'type': 'for_statement', 'children': ['46', '49', '63']},{'id': '46', 'type': 'tuple_pattern', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'index_list'},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '54', 'type': 'argument_list', 'children': ['55', '60']},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '59', 'type': 'argument_list', 'children': []},{'id': '60', 'type': 'keyword_argument', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'for_statement', 'children': ['65', '66', '67']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'index_list'},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '73']},{'id': '70', 'type': 'subscript', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'l2'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '74', 'type': 'return_statement', 'children': ['75']},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'l2'}
def _restricted_growth_notation(l): list_length = len(l) d = defaultdict(list) for (i, element) in enumerate(l): d[element].append(i) l2 = [None] * list_length for (name, index_list) in enumerate(sorted(d.values(), key=min)): for index in index_list: l2[index] = name return tuple(l2)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'insort_no_dup'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'lst'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '6', 'type': 'block', 'children': ['7', '10', '20']},{'id': '7', 'type': 'import_statement', 'children': ['8']},{'id': '8', 'type': 'dotted_name', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'bisect'},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'ix'},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'bisect'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'bisect_left'},{'id': '17', 'type': 'argument_list', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'lst'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '20', 'type': 'if_statement', 'children': ['21', '26']},{'id': '21', 'type': 'comparison_operator', 'children': ['22', '25'], 'value': '!='},{'id': '22', 'type': 'subscript', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'lst'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'ix'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '35']},{'id': '29', 'type': 'subscript', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'lst'},{'id': '31', 'type': 'slice', 'children': ['32', '33', '34']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'ix'},{'id': '33', 'type': 'colon', 'children': []},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'ix'},{'id': '35', 'type': 'list', 'children': ['36'], 'value': '[item]'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'item'}
def insort_no_dup(lst, item): import bisect ix = bisect.bisect_left(lst, item) if lst[ix] != item: lst[ix:ix] = [item]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'records'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6']},{'id': '6', 'type': 'return_statement', 'children': ['7']},{'id': '7', 'type': 'list_comprehension', 'children': ['8', '13']},{'id': '8', 'type': 'subscript', 'children': ['9', '12']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '11', 'type': 'identifier', 'children': [], 'value': '_records'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '13', 'type': 'for_in_clause', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '23', 'type': 'identifier', 'children': [], 'value': '_records'}
def records(self): return [self._records[i] for i in range(len(self._records))]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'score'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'phone_number'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'account_lifecycle_event'},{'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '9', 'type': 'block', 'children': ['10']},{'id': '10', 'type': 'return_statement', 'children': ['11']},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'post'},{'id': '15', 'type': 'argument_list', 'children': ['16', '24', '27']},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'SCORE_RESOURCE'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'phone_number'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'phone_number'},{'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'account_lifecycle_event'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'account_lifecycle_event'},{'id': '27', 'type': 'dictionary_splat', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'params'}
def score(self, phone_number, account_lifecycle_event, **params): return self.post(SCORE_RESOURCE.format(phone_number=phone_number), account_lifecycle_event=account_lifecycle_event, **params)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sorted_members'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '14', '26', '57', '83']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'members'},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '13', 'type': 'argument_list', 'children': []},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'required_names'},{'id': '17', 'type': 'call', 'children': ['18', '23']},{'id': '18', 'type': 'attribute', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '23', 'type': 'argument_list', 'children': ['24', '25']},{'id': '24', 'type': 'string', 'children': [], 'value': '"required"'},{'id': '25', 'type': 'tuple', 'children': []},{'id': '26', 'type': 'for_statement', 'children': ['27', '30', '37']},{'id': '27', 'type': 'pattern_list', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'shape'},{'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': 'self'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'members'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '36', 'type': 'argument_list', 'children': []},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '43']},{'id': '40', 'type': 'subscript', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'members'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'AbShapeMember'},{'id': '45', 'type': 'argument_list', 'children': ['46', '49', '52']},{'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'is_required'},{'id': '54', 'type': 'comparison_operator', 'children': ['55', '56'], 'value': 'in'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'required_names'},{'id': '57', 'type': 'if_statement', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'is_output_shape'},{'id': '61', 'type': 'block', 'children': ['62']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'yield', 'children': ['64']},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'AbShapeMember'},{'id': '66', 'type': 'argument_list', 'children': ['67', '70', '80']},{'id': '67', 'type': 'keyword_argument', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '69', 'type': 'string', 'children': [], 'value': '"ResponseMetadata"'},{'id': '70', 'type': 'keyword_argument', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '72', 'type': 'call', 'children': ['73', '78']},{'id': '73', 'type': 'attribute', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '76', 'type': 'identifier', 'children': [], 'value': '_shape_resolver'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'get_shape_by_name'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'string', 'children': [], 'value': '"ResponseMetadata"'},{'id': '80', 'type': 'keyword_argument', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'is_required'},{'id': '82', 'type': 'True', 'children': []},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'yield', 'children': ['85']},{'id': '85', 'type': 'call', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '87', 'type': 'argument_list', 'children': ['88', '93']},{'id': '88', 'type': 'call', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'members'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '92', 'type': 'argument_list', 'children': []},{'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '95', 'type': 'lambda', 'children': ['96', '98']},{'id': '96', 'type': 'lambda_parameters', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '98', 'type': 'not_operator', 'children': ['99']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'is_required'}
def sorted_members(self): members = collections.OrderedDict() required_names = self.metadata.get("required", ()) for name, shape in self.members.items(): members[name] = AbShapeMember(name=name, shape=shape, is_required=name in required_names) if self.is_output_shape: yield AbShapeMember( name="ResponseMetadata", shape=self._shape_resolver.get_shape_by_name("ResponseMetadata"), is_required=True, ) yield from sorted(members.values(), key=lambda m: not m.is_required)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'threshold_brier_score'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'observations'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'forecasts'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'issorted'},{'id': '9', 'type': 'False', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '12', 'type': 'unary_operator', 'children': ['13'], 'value': '-'},{'id': '13', 'type': 'integer', 'children': [], 'value': '1'},{'id': '14', 'type': 'block', 'children': ['15', '24', '33', '42', '56', '74', '97', '105', '117', '144', '162', '179', '188', '203']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'observations'},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'asarray'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'observations'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'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': 'threshold'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'forecasts'},{'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': 'asarray'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'forecasts'},{'id': '42', 'type': 'if_statement', 'children': ['43', '47']},{'id': '43', 'type': 'comparison_operator', 'children': ['44', '45'], 'value': '!='},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '45', 'type': 'unary_operator', 'children': ['46'], 'value': '-'},{'id': '46', 'type': 'integer', 'children': [], 'value': '1'},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'forecasts'},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'move_axis_to_end'},{'id': '53', 'type': 'argument_list', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'forecasts'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '56', 'type': 'if_statement', 'children': ['57', '64']},{'id': '57', 'type': 'comparison_operator', 'children': ['58', '61'], 'value': '=='},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'forecasts'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'observations'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'forecasts'},{'id': '68', 'type': 'subscript', 'children': ['69', '70', '71']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'forecasts'},{'id': '70', 'type': 'ellipsis', 'children': [], 'value': '...'},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'newaxis'},{'id': '74', 'type': 'if_statement', 'children': ['75', '87']},{'id': '75', 'type': 'comparison_operator', 'children': ['76', '79'], 'value': '!='},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'observations'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '79', 'type': 'subscript', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'forecasts'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '83', 'type': 'slice', 'children': ['84', '85']},{'id': '84', 'type': 'colon', 'children': []},{'id': '85', 'type': 'unary_operator', 'children': ['86'], 'value': '-'},{'id': '86', 'type': 'integer', 'children': [], 'value': '1'},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'raise_statement', 'children': ['89']},{'id': '89', 'type': 'call', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'binary_operator', 'children': ['93', '96'], 'value': '%'},{'id': '93', 'type': 'concatenated_string', 'children': ['94', '95']},{'id': '94', 'type': 'string', 'children': [], 'value': "'observations and forecasts must have matching '"},{'id': '95', 'type': 'string', 'children': [], 'value': "'shapes or matching shapes except along `axis=%s`'"},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'scalar_threshold'},{'id': '100', 'type': 'comparison_operator', 'children': ['101', '104'], 'value': '=='},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '104', 'type': 'integer', 'children': [], 'value': '0'},{'id': '105', 'type': 'if_statement', 'children': ['106', '111']},{'id': '106', 'type': 'comparison_operator', 'children': ['107', '110'], 'value': '>'},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '110', 'type': 'integer', 'children': [], 'value': '1'},{'id': '111', 'type': 'block', 'children': ['112']},{'id': '112', 'type': 'raise_statement', 'children': ['113']},{'id': '113', 'type': 'call', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'string', 'children': [], 'value': "'threshold must be scalar or 1-dimensional'"},{'id': '117', 'type': 'if_statement', 'children': ['118', '138']},{'id': '118', 'type': 'boolean_operator', 'children': ['119', '124'], 'value': 'and'},{'id': '119', 'type': 'comparison_operator', 'children': ['120', '123'], 'value': '=='},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '123', 'type': 'integer', 'children': [], 'value': '1'},{'id': '124', 'type': 'not_operator', 'children': ['125']},{'id': '125', 'type': 'call', 'children': ['126', '137']},{'id': '126', 'type': 'attribute', 'children': ['127', '136']},{'id': '127', 'type': '()', 'children': ['128']},{'id': '128', 'type': 'comparison_operator', 'children': ['129', '135'], 'value': '=='},{'id': '129', 'type': 'call', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '137', 'type': 'argument_list', 'children': []},{'id': '138', 'type': 'block', 'children': ['139']},{'id': '139', 'type': 'raise_statement', 'children': ['140']},{'id': '140', 'type': 'call', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'string', 'children': [], 'value': "'1D thresholds must be sorted'"},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '147', 'type': 'call', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'reshape'},{'id': '151', 'type': 'argument_list', 'children': ['152']},{'id': '152', 'type': 'binary_operator', 'children': ['153', '159'], 'value': '+'},{'id': '153', 'type': 'binary_operator', 'children': ['154', '156'], 'value': '*'},{'id': '154', 'type': 'tuple', 'children': ['155']},{'id': '155', 'type': 'integer', 'children': [], 'value': '1'},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'observations'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '159', 'type': 'tuple', 'children': ['160']},{'id': '160', 'type': 'unary_operator', 'children': ['161'], 'value': '-'},{'id': '161', 'type': 'integer', 'children': [], 'value': '1'},{'id': '162', 'type': 'if_statement', 'children': ['163', '165']},{'id': '163', 'type': 'not_operator', 'children': ['164']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'issorted'},{'id': '165', 'type': 'block', 'children': ['166']},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'forecasts'},{'id': '169', 'type': 'call', 'children': ['170', '173']},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '173', 'type': 'argument_list', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'forecasts'},{'id': '175', 'type': 'keyword_argument', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '177', 'type': 'unary_operator', 'children': ['178'], 'value': '-'},{'id': '178', 'type': 'integer', 'children': [], 'value': '1'},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'assignment', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '182', 'type': 'call', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': '_threshold_brier_score_core'},{'id': '184', 'type': 'argument_list', 'children': ['185', '186', '187']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'observations'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'forecasts'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '188', 'type': 'if_statement', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'scalar_threshold'},{'id': '190', 'type': 'block', 'children': ['191']},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '194', 'type': 'call', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'squeeze'},{'id': '198', 'type': 'argument_list', 'children': ['199']},{'id': '199', 'type': 'keyword_argument', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '201', 'type': 'unary_operator', 'children': ['202'], 'value': '-'},{'id': '202', 'type': 'integer', 'children': [], 'value': '1'},{'id': '203', 'type': 'return_statement', 'children': ['204']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'result'}
def threshold_brier_score(observations, forecasts, threshold, issorted=False, axis=-1): observations = np.asarray(observations) threshold = np.asarray(threshold) forecasts = np.asarray(forecasts) if axis != -1: forecasts = move_axis_to_end(forecasts, axis) if forecasts.shape == observations.shape: forecasts = forecasts[..., np.newaxis] if observations.shape != forecasts.shape[:-1]: raise ValueError('observations and forecasts must have matching ' 'shapes or matching shapes except along `axis=%s`' % axis) scalar_threshold = threshold.ndim == 0 if threshold.ndim > 1: raise ValueError('threshold must be scalar or 1-dimensional') if threshold.ndim == 1 and not (np.sort(threshold) == threshold).all(): raise ValueError('1D thresholds must be sorted') threshold = threshold.reshape((1,) * observations.ndim + (-1,)) if not issorted: forecasts = np.sort(forecasts, axis=-1) result = _threshold_brier_score_core(observations, forecasts, threshold) if scalar_threshold: result = result.squeeze(axis=-1) return result
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'run'},{'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': 'N'},{'id': '7', 'type': 'integer', 'children': [], 'value': '1'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'trace_sort'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '14', '21']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'string', 'children': [], 'value': "'''Run the sampler, store the history of visited points into\n the member variable ``self.samples`` and the importance weights\n into ``self.weights``.\n .. seealso::\n :py:class:`pypmc.tools.History`\n :param N:\n Integer; the number of samples to be drawn.\n :param trace_sort:\n Bool; if True, return an array containing the responsible\n component of ``self.proposal`` for each sample generated\n during this run.\n .. note::\n This option only works for proposals of type\n :py:class:`pypmc.density.mixture.MixtureDensity`\n .. note::\n If True, the samples will be ordered by the components.\n '''"},{'id': '14', 'type': 'if_statement', 'children': ['15', '18']},{'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': '=='},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '17', 'type': 'integer', 'children': [], 'value': '0'},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'return_statement', 'children': ['20']},{'id': '20', 'type': 'integer', 'children': [], 'value': '0'},{'id': '21', 'type': 'if_statement', 'children': ['22', '23', '48']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'trace_sort'},{'id': '23', 'type': 'block', 'children': ['24', '38', '46']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '29']},{'id': '26', 'type': 'pattern_list', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'this_samples'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'origin'},{'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': '_get_samples'},{'id': '33', 'type': 'argument_list', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'trace_sort'},{'id': '37', 'type': 'True', 'children': []},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '42', 'type': 'identifier', 'children': [], 'value': '_calculate_weights'},{'id': '43', 'type': 'argument_list', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'this_samples'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '46', 'type': 'return_statement', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'origin'},{'id': '48', 'type': 'else_clause', 'children': ['49']},{'id': '49', 'type': 'block', 'children': ['50', '62']},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'this_samples'},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '56', 'type': 'identifier', 'children': [], 'value': '_get_samples'},{'id': '57', 'type': 'argument_list', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '59', 'type': 'keyword_argument', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'trace_sort'},{'id': '61', 'type': 'False', 'children': []},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'call', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '66', 'type': 'identifier', 'children': [], 'value': '_calculate_weights'},{'id': '67', 'type': 'argument_list', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'this_samples'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'N'}
def run(self, N=1, trace_sort=False): '''Run the sampler, store the history of visited points into the member variable ``self.samples`` and the importance weights into ``self.weights``. .. seealso:: :py:class:`pypmc.tools.History` :param N: Integer; the number of samples to be drawn. :param trace_sort: Bool; if True, return an array containing the responsible component of ``self.proposal`` for each sample generated during this run. .. note:: This option only works for proposals of type :py:class:`pypmc.density.mixture.MixtureDensity` .. note:: If True, the samples will be ordered by the components. ''' if N == 0: return 0 if trace_sort: this_samples, origin = self._get_samples(N, trace_sort=True) self._calculate_weights(this_samples, N) return origin else: this_samples = self._get_samples(N, trace_sort=False) self._calculate_weights(this_samples, N)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_samples'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'trace_sort'},{'id': '7', 'type': 'block', 'children': ['8', '19']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'this_run'},{'id': '11', 'type': 'call', 'children': ['12', '17']},{'id': '12', 'type': 'attribute', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'samples'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '19', 'type': 'if_statement', 'children': ['20', '21', '51']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'trace_sort'},{'id': '21', 'type': 'block', 'children': ['22', '47']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '30']},{'id': '24', 'type': 'pattern_list', 'children': ['25', '29']},{'id': '25', 'type': 'subscript', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'this_run'},{'id': '27', 'type': 'slice', 'children': ['28']},{'id': '28', 'type': 'colon', 'children': []},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'origin'},{'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': 'self'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'proposal'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'propose'},{'id': '36', 'type': 'argument_list', 'children': ['37', '38', '41', '44']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'rng'},{'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'trace'},{'id': '43', 'type': 'True', 'children': []},{'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'shuffle'},{'id': '46', 'type': 'False', 'children': []},{'id': '47', 'type': 'return_statement', 'children': ['48']},{'id': '48', 'type': 'expression_list', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'this_run'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'origin'},{'id': '51', 'type': 'else_clause', 'children': ['52']},{'id': '52', 'type': 'block', 'children': ['53', '70']},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '59']},{'id': '55', 'type': 'subscript', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'this_run'},{'id': '57', 'type': 'slice', 'children': ['58']},{'id': '58', 'type': 'colon', 'children': []},{'id': '59', 'type': 'call', 'children': ['60', '65']},{'id': '60', 'type': 'attribute', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'proposal'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'propose'},{'id': '65', 'type': 'argument_list', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'rng'},{'id': '70', 'type': 'return_statement', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'this_run'}
def _get_samples(self, N, trace_sort): this_run = self.samples.append(N) if trace_sort: this_run[:], origin = self.proposal.propose(N, self.rng, trace=True, shuffle=False) return this_run, origin else: this_run[:] = self.proposal.propose(N, self.rng) return this_run
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'argsort_indices'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '7', 'type': 'unary_operator', 'children': ['8'], 'value': '-'},{'id': '8', 'type': 'integer', 'children': [], 'value': '1'},{'id': '9', 'type': 'block', 'children': ['10', '19', '43', '54']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'asarray'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'ind'},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'ix_'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'list_splat', 'children': ['31']},{'id': '31', 'type': 'list_comprehension', 'children': ['32', '38']},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'arange'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '38', 'type': 'for_in_clause', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '48']},{'id': '45', 'type': 'subscript', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'ind'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '54', 'type': 'return_statement', 'children': ['55']},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'ind'}
def argsort_indices(a, axis=-1): a = np.asarray(a) ind = list(np.ix_(*[np.arange(d) for d in a.shape])) ind[axis] = a.argsort(axis) return tuple(ind)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sorted'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'collection'},{'id': '5', 'type': 'block', 'children': ['6', '16', '40', '99']},{'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': 'collection'},{'id': '12', 'type': 'integer', 'children': [], 'value': '1'},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'return_statement', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'collection'},{'id': '16', 'type': 'if_statement', 'children': ['17', '22']},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '19', 'type': 'argument_list', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'collection'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'return_statement', 'children': ['24']},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '26', 'type': 'argument_list', 'children': ['27', '32']},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'collection'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '31', 'type': 'argument_list', 'children': []},{'id': '32', 'type': 'keyword_argument', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '34', 'type': 'lambda', 'children': ['35', '37']},{'id': '35', 'type': 'lambda_parameters', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '37', 'type': 'subscript', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '39', 'type': 'integer', 'children': [], 'value': '0'},{'id': '40', 'type': 'if_statement', 'children': ['41', '51', '61', '87']},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '43', 'type': 'argument_list', 'children': ['44', '50']},{'id': '44', 'type': 'subscript', 'children': ['45', '49']},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'collection'},{'id': '49', 'type': 'integer', 'children': [], 'value': '0'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'Operation'},{'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': 'key'},{'id': '55', 'type': 'lambda', 'children': ['56', '58']},{'id': '56', 'type': 'lambda_parameters', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'operation_id'},{'id': '61', 'type': 'elif_clause', 'children': ['62', '72']},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '64', 'type': 'argument_list', 'children': ['65', '71']},{'id': '65', 'type': 'subscript', 'children': ['66', '70']},{'id': '66', 'type': 'call', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'collection'},{'id': '70', 'type': 'integer', 'children': [], 'value': '0'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '76', 'type': 'lambda', 'children': ['77', '79']},{'id': '77', 'type': 'lambda_parameters', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '79', 'type': 'attribute', 'children': ['80', '86']},{'id': '80', 'type': 'call', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'SchemaObjects'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '87', 'type': 'else_clause', 'children': ['88']},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'raise_statement', 'children': ['90']},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'call', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'subscript', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'collection'},{'id': '98', 'type': 'integer', 'children': [], 'value': '0'},{'id': '99', 'type': 'return_statement', 'children': ['100']},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '102', 'type': 'argument_list', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'collection'},{'id': '104', 'type': 'keyword_argument', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'key'}
def sorted(collection): if len(collection) < 1: return collection if isinstance(collection, dict): return sorted(collection.items(), key=lambda x: x[0]) if isinstance(list(collection)[0], Operation): key = lambda x: x.operation_id elif isinstance(list(collection)[0], str): key = lambda x: SchemaObjects.get(x).name else: raise TypeError(type(collection[0])) return sorted(collection, key=key)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_schemas'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'schema_types'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '10', 'type': 'True', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '32', '50', '66']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '17', 'type': 'argument_list', 'children': ['18', '25']},{'id': '18', 'type': 'lambda', 'children': ['19', '21']},{'id': '19', 'type': 'lambda_parameters', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '21', 'type': 'not_operator', 'children': ['22']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'is_inline_array'},{'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': 'cls'},{'id': '29', 'type': 'identifier', 'children': [], 'value': '_schemas'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '31', 'type': 'argument_list', 'children': []},{'id': '32', 'type': 'if_statement', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'schema_types'},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '40', 'type': 'argument_list', 'children': ['41', '49']},{'id': '41', 'type': 'lambda', 'children': ['42', '44']},{'id': '42', 'type': 'lambda_parameters', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '44', 'type': 'comparison_operator', 'children': ['45', '48'], 'value': 'in'},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'schema_type'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'schema_types'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '50', 'type': 'if_statement', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'sort'},{'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': 'result'},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '58', 'type': 'argument_list', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '60', 'type': 'keyword_argument', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'attrgetter'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '66', 'type': 'return_statement', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'result'}
def get_schemas(cls, schema_types=None, sort=True): result = filter(lambda x: not x.is_inline_array, cls._schemas.values()) if schema_types: result = filter(lambda x: x.schema_type in schema_types, result) if sort: result = sorted(result, key=attrgetter('name')) return result
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'to_molden'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cartesian_list'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'sort_index'},{'id': '10', 'type': 'True', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'overwrite'},{'id': '13', 'type': 'True', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'float_format'},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'string', 'children': [], 'value': "'{:.6f}'"},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '19', 'type': 'block', 'children': ['20', '35', '64', '73', '92', '103', '118', '136', '147']},{'id': '20', 'type': 'if_statement', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'sort_index'},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'cartesian_list'},{'id': '26', 'type': 'list_comprehension', 'children': ['27', '32']},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'molecule'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'sort_index'},{'id': '31', 'type': 'argument_list', 'children': []},{'id': '32', 'type': 'for_in_clause', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'molecule'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'cartesian_list'},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'give_header'},{'id': '38', 'type': 'attribute', 'children': ['39', '63']},{'id': '39', 'type': '()', 'children': ['40']},{'id': '40', 'type': 'binary_operator', 'children': ['41', '62'], 'value': '+'},{'id': '41', 'type': 'binary_operator', 'children': ['42', '61'], 'value': '+'},{'id': '42', 'type': 'binary_operator', 'children': ['43', '60'], 'value': '+'},{'id': '43', 'type': 'binary_operator', 'children': ['44', '59'], 'value': '+'},{'id': '44', 'type': 'binary_operator', 'children': ['45', '58'], 'value': '+'},{'id': '45', 'type': 'binary_operator', 'children': ['46', '57'], 'value': '+'},{'id': '46', 'type': 'binary_operator', 'children': ['47', '50'], 'value': '+'},{'id': '47', 'type': 'binary_operator', 'children': ['48', '49'], 'value': '+'},{'id': '48', 'type': 'string', 'children': [], 'value': '"[MOLDEN FORMAT]\\n"'},{'id': '49', 'type': 'string', 'children': [], 'value': '"[N_GEO]\\n"'},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'cartesian_list'},{'id': '57', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '58', 'type': 'string', 'children': [], 'value': "'[GEOCONV]\\n'"},{'id': '59', 'type': 'string', 'children': [], 'value': "'energy\\n{energy}'"},{'id': '60', 'type': 'string', 'children': [], 'value': "'max-force\\n{max_force}'"},{'id': '61', 'type': 'string', 'children': [], 'value': "'rms-force\\n{rms_force}'"},{'id': '62', 'type': 'string', 'children': [], 'value': "'[GEOMETRIES] (XYZ)\\n'"},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '67', 'type': 'binary_operator', 'children': ['68', '72'], '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': 'identifier', 'children': [], 'value': 'cartesian_list'},{'id': '72', 'type': 'string', 'children': [], 'value': "'1\\n'"},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'energy'},{'id': '76', 'type': 'list_comprehension', 'children': ['77', '89']},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'call', 'children': ['81', '86']},{'id': '81', 'type': 'attribute', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '86', 'type': 'argument_list', 'children': ['87', '88']},{'id': '87', 'type': 'string', 'children': [], 'value': "'energy'"},{'id': '88', 'type': 'integer', 'children': [], 'value': '1'},{'id': '89', 'type': 'for_in_clause', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'cartesian_list'},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'energy'},{'id': '95', 'type': 'binary_operator', 'children': ['96', '102'], 'value': '+'},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'energy'},{'id': '102', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '106', 'type': 'call', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'give_header'},{'id': '108', 'type': 'argument_list', 'children': ['109', '112', '115']},{'id': '109', 'type': 'keyword_argument', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'energy'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'energy'},{'id': '112', 'type': 'keyword_argument', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'max_force'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '115', 'type': 'keyword_argument', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'rms_force'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'coordinates'},{'id': '121', 'type': 'list_comprehension', 'children': ['122', '133']},{'id': '122', 'type': 'call', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'to_xyz'},{'id': '126', 'type': 'argument_list', 'children': ['127', '130']},{'id': '127', 'type': 'keyword_argument', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'sort_index'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'sort_index'},{'id': '130', 'type': 'keyword_argument', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'float_format'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'float_format'},{'id': '133', 'type': 'for_in_clause', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'cartesian_list'},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '139', 'type': 'binary_operator', 'children': ['140', '141'], 'value': '+'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '141', 'type': 'call', 'children': ['142', '145']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '145', 'type': 'argument_list', 'children': ['146']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'coordinates'},{'id': '147', 'type': 'if_statement', 'children': ['148', '151', '199']},{'id': '148', 'type': 'comparison_operator', 'children': ['149', '150'], 'value': 'is'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '150', 'type': 'None', 'children': []},{'id': '151', 'type': 'block', 'children': ['152']},{'id': '152', 'type': 'if_statement', 'children': ['153', '154', '176']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'overwrite'},{'id': '154', 'type': 'block', 'children': ['155']},{'id': '155', 'type': 'with_statement', 'children': ['156', '168']},{'id': '156', 'type': 'with_clause', 'children': ['157']},{'id': '157', 'type': 'with_item', 'children': ['158']},{'id': '158', 'type': 'as_pattern', 'children': ['159', '166']},{'id': '159', 'type': 'call', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '161', 'type': 'argument_list', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '163', 'type': 'keyword_argument', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '165', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '166', 'type': 'as_pattern_target', 'children': ['167']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '168', 'type': 'block', 'children': ['169']},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'call', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '174', 'type': 'argument_list', 'children': ['175']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '176', 'type': 'else_clause', 'children': ['177']},{'id': '177', 'type': 'block', 'children': ['178']},{'id': '178', 'type': 'with_statement', 'children': ['179', '191']},{'id': '179', 'type': 'with_clause', 'children': ['180']},{'id': '180', 'type': 'with_item', 'children': ['181']},{'id': '181', 'type': 'as_pattern', 'children': ['182', '189']},{'id': '182', 'type': 'call', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '184', 'type': 'argument_list', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '186', 'type': 'keyword_argument', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '188', 'type': 'string', 'children': [], 'value': "'x'"},{'id': '189', 'type': 'as_pattern_target', 'children': ['190']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '191', 'type': 'block', 'children': ['192']},{'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': 'f'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '197', 'type': 'argument_list', 'children': ['198']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '199', 'type': 'else_clause', 'children': ['200']},{'id': '200', 'type': 'block', 'children': ['201']},{'id': '201', 'type': 'return_statement', 'children': ['202']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'output'}
def to_molden(cartesian_list, buf=None, sort_index=True, overwrite=True, float_format='{:.6f}'.format): if sort_index: cartesian_list = [molecule.sort_index() for molecule in cartesian_list] give_header = ("[MOLDEN FORMAT]\n" + "[N_GEO]\n" + str(len(cartesian_list)) + "\n" + '[GEOCONV]\n' + 'energy\n{energy}' + 'max-force\n{max_force}' + 'rms-force\n{rms_force}' + '[GEOMETRIES] (XYZ)\n').format values = len(cartesian_list) * '1\n' energy = [str(m.metadata.get('energy', 1)) for m in cartesian_list] energy = '\n'.join(energy) + '\n' header = give_header(energy=energy, max_force=values, rms_force=values) coordinates = [x.to_xyz(sort_index=sort_index, float_format=float_format) for x in cartesian_list] output = header + '\n'.join(coordinates) if buf is not None: if overwrite: with open(buf, mode='w') as f: f.write(output) else: with open(buf, mode='x') as f: f.write(output) else: return output
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_inertia'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '143', '152', '162', '172', '181', '190']},{'id': '6', 'type': 'function_definition', 'children': ['7', '8', '10']},{'id': '7', 'type': 'function_name', 'children': [], 'value': 'calculate_inertia_tensor'},{'id': '8', 'type': 'parameters', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'molecule'},{'id': '10', 'type': 'block', 'children': ['11', '23', '38', '102', '115', '124', '130', '138']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'masses'},{'id': '14', 'type': 'attribute', 'children': ['15', '22']},{'id': '15', 'type': 'subscript', 'children': ['16', '19', '21']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'molecule'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '19', 'type': 'slice', 'children': ['20']},{'id': '20', 'type': 'colon', 'children': []},{'id': '21', 'type': 'string', 'children': [], 'value': "'mass'"},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'pos'},{'id': '26', 'type': 'attribute', 'children': ['27', '37']},{'id': '27', 'type': 'subscript', 'children': ['28', '31', '33']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'molecule'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '31', 'type': 'slice', 'children': ['32']},{'id': '32', 'type': 'colon', 'children': []},{'id': '33', 'type': 'list', 'children': ['34', '35', '36'], 'value': "['x', 'y', 'z']"},{'id': '34', 'type': 'string', 'children': [], 'value': "'x'"},{'id': '35', 'type': 'string', 'children': [], 'value': "'y'"},{'id': '36', 'type': 'string', 'children': [], 'value': "'z'"},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'inertia'},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '45', 'type': 'argument_list', 'children': ['46', '99']},{'id': '46', 'type': 'binary_operator', 'children': ['47', '53'], 'value': '*'},{'id': '47', 'type': 'subscript', 'children': ['48', '49', '51', '52']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'masses'},{'id': '49', 'type': 'slice', 'children': ['50']},{'id': '50', 'type': 'colon', 'children': []},{'id': '51', 'type': 'None', 'children': []},{'id': '52', 'type': 'None', 'children': []},{'id': '53', 'type': '()', 'children': ['54']},{'id': '54', 'type': 'binary_operator', 'children': ['55', '84'], 'value': '-'},{'id': '55', 'type': 'binary_operator', 'children': ['56', '72'], 'value': '*'},{'id': '56', 'type': 'subscript', 'children': ['57', '68', '70', '71']},{'id': '57', 'type': 'call', 'children': ['58', '64']},{'id': '58', 'type': 'attribute', 'children': ['59', '63']},{'id': '59', 'type': '()', 'children': ['60']},{'id': '60', 'type': 'binary_operator', 'children': ['61', '62'], 'value': '**'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'pos'},{'id': '62', 'type': 'integer', 'children': [], 'value': '2'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '67', 'type': 'integer', 'children': [], 'value': '1'},{'id': '68', 'type': 'slice', 'children': ['69']},{'id': '69', 'type': 'colon', 'children': []},{'id': '70', 'type': 'None', 'children': []},{'id': '71', 'type': 'None', 'children': []},{'id': '72', 'type': 'subscript', 'children': ['73', '79', '80', '82']},{'id': '73', 'type': 'call', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'integer', 'children': [], 'value': '3'},{'id': '79', 'type': 'None', 'children': []},{'id': '80', 'type': 'slice', 'children': ['81']},{'id': '81', 'type': 'colon', 'children': []},{'id': '82', 'type': 'slice', 'children': ['83']},{'id': '83', 'type': 'colon', 'children': []},{'id': '84', 'type': 'binary_operator', 'children': ['85', '92'], 'value': '*'},{'id': '85', 'type': 'subscript', 'children': ['86', '87', '89', '91']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'pos'},{'id': '87', 'type': 'slice', 'children': ['88']},{'id': '88', 'type': 'colon', 'children': []},{'id': '89', 'type': 'slice', 'children': ['90']},{'id': '90', 'type': 'colon', 'children': []},{'id': '91', 'type': 'None', 'children': []},{'id': '92', 'type': 'subscript', 'children': ['93', '94', '96', '97']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'pos'},{'id': '94', 'type': 'slice', 'children': ['95']},{'id': '95', 'type': 'colon', 'children': []},{'id': '96', 'type': 'None', 'children': []},{'id': '97', 'type': 'slice', 'children': ['98']},{'id': '98', 'type': 'colon', 'children': []},{'id': '99', 'type': 'keyword_argument', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '101', 'type': 'integer', 'children': [], 'value': '0'},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '107']},{'id': '104', 'type': 'pattern_list', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'diag_inertia'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'eig_v'},{'id': '107', 'type': 'call', 'children': ['108', '113']},{'id': '108', 'type': 'attribute', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'linalg'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'eig'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'inertia'},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'sorted_index'},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'diag_inertia'},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'assignment', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'diag_inertia'},{'id': '127', 'type': 'subscript', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'diag_inertia'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'sorted_index'},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'eig_v'},{'id': '133', 'type': 'subscript', 'children': ['134', '135', '137']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'eig_v'},{'id': '135', 'type': 'slice', 'children': ['136']},{'id': '136', 'type': 'colon', 'children': []},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'sorted_index'},{'id': '138', 'type': 'return_statement', 'children': ['139']},{'id': '139', 'type': 'expression_list', 'children': ['140', '141', '142']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'inertia'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'eig_v'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'diag_inertia'},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'molecule'},{'id': '146', 'type': 'call', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'add_data'},{'id': '150', 'type': 'argument_list', 'children': ['151']},{'id': '151', 'type': 'string', 'children': [], 'value': "'mass'"},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'molecule'},{'id': '155', 'type': 'binary_operator', 'children': ['156', '157'], 'value': '-'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'molecule'},{'id': '157', 'type': 'call', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'molecule'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'get_barycenter'},{'id': '161', 'type': 'argument_list', 'children': []},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'assignment', 'children': ['164', '168']},{'id': '164', 'type': 'pattern_list', 'children': ['165', '166', '167']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'inertia'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'eig_v'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'diag_inertia'},{'id': '168', 'type': 'call', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'calculate_inertia_tensor'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'molecule'},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'assignment', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'eig_v'},{'id': '175', 'type': 'call', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'xyz_functions'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'orthonormalize_righthanded'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'eig_v'},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'assignment', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'molecule'},{'id': '184', 'type': 'call', 'children': ['185', '188']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'molecule'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'basistransform'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'eig_v'},{'id': '190', 'type': 'return_statement', 'children': ['191']},{'id': '191', 'type': 'dictionary', 'children': ['192', '195', '198', '201']},{'id': '192', 'type': 'pair', 'children': ['193', '194']},{'id': '193', 'type': 'string', 'children': [], 'value': "'transformed_Cartesian'"},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'molecule'},{'id': '195', 'type': 'pair', 'children': ['196', '197']},{'id': '196', 'type': 'string', 'children': [], 'value': "'eigenvectors'"},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'eig_v'},{'id': '198', 'type': 'pair', 'children': ['199', '200']},{'id': '199', 'type': 'string', 'children': [], 'value': "'diag_inertia_tensor'"},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'diag_inertia'},{'id': '201', 'type': 'pair', 'children': ['202', '203']},{'id': '202', 'type': 'string', 'children': [], 'value': "'inertia_tensor'"},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'inertia'}
def get_inertia(self): def calculate_inertia_tensor(molecule): masses = molecule.loc[:, 'mass'].values pos = molecule.loc[:, ['x', 'y', 'z']].values inertia = np.sum( masses[:, None, None] * ((pos**2).sum(axis=1)[:, None, None] * np.identity(3)[None, :, :] - pos[:, :, None] * pos[:, None, :]), axis=0) diag_inertia, eig_v = np.linalg.eig(inertia) sorted_index = np.argsort(diag_inertia) diag_inertia = diag_inertia[sorted_index] eig_v = eig_v[:, sorted_index] return inertia, eig_v, diag_inertia molecule = self.add_data('mass') molecule = molecule - molecule.get_barycenter() inertia, eig_v, diag_inertia = calculate_inertia_tensor(molecule) eig_v = xyz_functions.orthonormalize_righthanded(eig_v) molecule = molecule.basistransform(eig_v) return {'transformed_Cartesian': molecule, 'eigenvectors': eig_v, 'diag_inertia_tensor': diag_inertia, 'inertia_tensor': inertia}
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '25']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'to_xyz'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '22']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'sort_index'},{'id': '10', 'type': 'True', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '16', 'type': 'False', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'float_format'},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'string', 'children': [], 'value': "'{:.6f}'"},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '22', 'type': 'default_parameter', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'overwrite'},{'id': '24', 'type': 'True', 'children': []},{'id': '25', 'type': 'block', 'children': ['26', '69', '102', '125']},{'id': '26', 'type': 'if_statement', 'children': ['27', '28', '50']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'sort_index'},{'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': 'molecule_string'},{'id': '32', 'type': 'call', 'children': ['33', '40']},{'id': '33', 'type': 'attribute', 'children': ['34', '39']},{'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': 'sort_index'},{'id': '38', 'type': 'argument_list', 'children': []},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'to_string'},{'id': '40', 'type': 'argument_list', 'children': ['41', '44', '47']},{'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '47', 'type': 'keyword_argument', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'float_format'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'float_format'},{'id': '50', 'type': 'else_clause', 'children': ['51']},{'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': 'molecule_string'},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'to_string'},{'id': '59', 'type': 'argument_list', 'children': ['60', '63', '66']},{'id': '60', 'type': 'keyword_argument', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '63', 'type': 'keyword_argument', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '66', 'type': 'keyword_argument', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'float_format'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'float_format'},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'space'},{'id': '72', 'type': 'binary_operator', 'children': ['73', '74'], 'value': '*'},{'id': '73', 'type': 'string', 'children': [], 'value': "' '"},{'id': '74', 'type': '()', 'children': ['75']},{'id': '75', 'type': 'binary_operator', 'children': ['76', '93'], 'value': '-'},{'id': '76', 'type': 'call', 'children': ['77', '92']},{'id': '77', 'type': 'attribute', 'children': ['78', '91']},{'id': '78', 'type': 'call', 'children': ['79', '90']},{'id': '79', 'type': 'attribute', 'children': ['80', '89']},{'id': '80', 'type': 'attribute', 'children': ['81', '88']},{'id': '81', 'type': 'subscript', 'children': ['82', '85', '87']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '85', 'type': 'slice', 'children': ['86']},{'id': '86', 'type': 'colon', 'children': []},{'id': '87', 'type': 'string', 'children': [], 'value': "'atom'"},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '90', 'type': 'argument_list', 'children': []},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '92', 'type': 'argument_list', 'children': []},{'id': '93', 'type': 'call', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'subscript', 'children': ['97', '100', '101']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'iloc'},{'id': '100', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'output'},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'string', 'children': [], 'value': "'{n}\\n{message}\\n{alignment}{frame_string}'"},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '109', 'type': 'argument_list', 'children': ['110', '116', '119', '122']},{'id': '110', 'type': 'keyword_argument', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '116', 'type': 'keyword_argument', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'alignment'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'space'},{'id': '119', 'type': 'keyword_argument', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'frame_string'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'molecule_string'},{'id': '122', 'type': 'keyword_argument', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '124', 'type': 'string', 'children': [], 'value': "'Created by chemcoord http://chemcoord.readthedocs.io/'"},{'id': '125', 'type': 'if_statement', 'children': ['126', '129', '177']},{'id': '126', 'type': 'comparison_operator', 'children': ['127', '128'], 'value': 'is'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '128', 'type': 'None', 'children': []},{'id': '129', 'type': 'block', 'children': ['130']},{'id': '130', 'type': 'if_statement', 'children': ['131', '132', '154']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'overwrite'},{'id': '132', 'type': 'block', 'children': ['133']},{'id': '133', 'type': 'with_statement', 'children': ['134', '146']},{'id': '134', 'type': 'with_clause', 'children': ['135']},{'id': '135', 'type': 'with_item', 'children': ['136']},{'id': '136', 'type': 'as_pattern', 'children': ['137', '144']},{'id': '137', 'type': 'call', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '139', 'type': 'argument_list', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '141', 'type': 'keyword_argument', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '143', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '144', 'type': 'as_pattern_target', 'children': ['145']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'f'},{'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': 'f'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '154', 'type': 'else_clause', 'children': ['155']},{'id': '155', 'type': 'block', 'children': ['156']},{'id': '156', 'type': 'with_statement', 'children': ['157', '169']},{'id': '157', 'type': 'with_clause', 'children': ['158']},{'id': '158', 'type': 'with_item', 'children': ['159']},{'id': '159', 'type': 'as_pattern', 'children': ['160', '167']},{'id': '160', 'type': 'call', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '162', 'type': 'argument_list', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '164', 'type': 'keyword_argument', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '166', 'type': 'string', 'children': [], 'value': "'x'"},{'id': '167', 'type': 'as_pattern_target', 'children': ['168']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '169', 'type': 'block', 'children': ['170']},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'call', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '177', 'type': 'else_clause', 'children': ['178']},{'id': '178', 'type': 'block', 'children': ['179']},{'id': '179', 'type': 'return_statement', 'children': ['180']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'output'}
def to_xyz(self, buf=None, sort_index=True, index=False, header=False, float_format='{:.6f}'.format, overwrite=True): if sort_index: molecule_string = self.sort_index().to_string( header=header, index=index, float_format=float_format) else: molecule_string = self.to_string(header=header, index=index, float_format=float_format) space = ' ' * (self.loc[:, 'atom'].str.len().max() - len(self.iloc[0, 0])) output = '{n}\n{message}\n{alignment}{frame_string}'.format( n=len(self), alignment=space, frame_string=molecule_string, message='Created by chemcoord http://chemcoord.readthedocs.io/') if buf is not None: if overwrite: with open(buf, mode='w') as f: f.write(output) else: with open(buf, mode='x') as f: f.write(output) else: return output
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'priority'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '23']},{'id': '6', 'type': 'if_statement', 'children': ['7', '16']},{'id': '7', 'type': 'comparison_operator', 'children': ['8', '11'], 'value': '=='},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'compiled_type'},{'id': '11', 'type': 'attribute', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'const'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'COMPILED_TYPE'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'MARKER'},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'return_statement', 'children': ['18']},{'id': '18', 'type': 'attribute', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'compiled'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'priority'},{'id': '23', 'type': 'return_statement', 'children': ['24']},{'id': '24', 'type': 'subscript', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'const'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'compiled_type_priorities'},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'compiled_type'}
def priority(self): if self.compiled_type == const.COMPILED_TYPE.MARKER: return self.compiled.priority return const.compiled_type_priorities[self.compiled_type]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_schemas'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'schemas_list'},{'id': '6', 'type': 'block', 'children': ['7']},{'id': '7', 'type': 'return_statement', 'children': ['8']},{'id': '8', 'type': 'call', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '10', 'type': 'argument_list', 'children': ['11', '12', '39']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'schemas_list'},{'id': '12', 'type': 'keyword_argument', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '14', 'type': 'lambda', 'children': ['15', '17']},{'id': '15', 'type': 'lambda_parameters', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '17', 'type': 'tuple', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'priority'},{'id': '21', 'type': 'conditional_expression', 'children': ['22', '29', '38'], 'value': 'if'},{'id': '22', 'type': 'attribute', 'children': ['23', '28']},{'id': '23', 'type': 'attribute', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'compiled'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'key_schema'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'priority'},{'id': '29', 'type': 'comparison_operator', 'children': ['30', '33'], 'value': '=='},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'compiled_type'},{'id': '33', 'type': 'attribute', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'const'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'COMPILED_TYPE'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'MARKER'},{'id': '38', 'type': 'integer', 'children': [], 'value': '0'},{'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '41', 'type': 'True', 'children': []}
def sort_schemas(cls, schemas_list): return sorted(schemas_list, key=lambda x: ( x.priority, x.compiled.key_schema.priority if x.compiled_type == const.COMPILED_TYPE.MARKER else 0 ), reverse=True)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'patch_cursor'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'batch_size'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'skip'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'dictionary_splat_pattern', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '19', 'type': 'block', 'children': ['20', '35', '47', '59']},{'id': '20', 'type': 'if_statement', 'children': ['21', '27']},{'id': '21', 'type': 'comparison_operator', 'children': ['22', '26'], 'value': '=='},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'batch_size'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'batch_size'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'batch_size'},{'id': '35', 'type': 'if_statement', 'children': ['36', '39']},{'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': 'is'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '38', 'type': 'None', 'children': []},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '47', 'type': 'if_statement', 'children': ['48', '51']},{'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': 'is'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '50', 'type': 'None', 'children': []},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '59', 'type': 'if_statement', 'children': ['60', '63']},{'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': 'is'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'skip'},{'id': '62', 'type': 'None', 'children': []},{'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': 'cursor'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'skip'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'skip'}
def patch_cursor(cursor, batch_size=None, limit=None, skip=None, sort=None, **kwargs): if type(batch_size) == int: cursor.batch_size(batch_size) if limit is not None: cursor.limit(limit) if sort is not None: cursor.sort(sort) if skip is not None: cursor.skip(skip)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_interval'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'block', 'children': ['11', '13', '22']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'string', 'children': [], 'value': '\'\'\'\n Inserts an interval to the tree. \n Note that when inserting we do not maintain appropriate sorting of the "mid" data structure.\n This should be done after all intervals are inserted.\n \'\'\''},{'id': '13', 'type': 'if_statement', 'children': ['14', '20']},{'id': '14', 'type': 'comparison_operator', 'children': ['15', '19'], 'value': '<='},{'id': '15', 'type': '()', 'children': ['16']},{'id': '16', 'type': 'binary_operator', 'children': ['17', '18'], 'value': '-'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '19', 'type': 'integer', 'children': [], 'value': '0'},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'return_statement', 'children': []},{'id': '22', 'type': 'if_statement', 'children': ['23', '28', '38', '54']},{'id': '23', 'type': 'comparison_operator', 'children': ['24', '27'], 'value': 'is'},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'single_interval'},{'id': '27', 'type': 'None', 'children': []},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'single_interval'},{'id': '34', 'type': 'tuple', 'children': ['35', '36', '37']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '38', 'type': 'elif_clause', 'children': ['39', '44']},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '43'], 'value': '=='},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'single_interval'},{'id': '43', 'type': 'integer', 'children': [], 'value': '0'},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '49', 'type': 'identifier', 'children': [], 'value': '_add_interval'},{'id': '50', 'type': 'argument_list', 'children': ['51', '52', '53']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '54', 'type': 'else_clause', 'children': ['55']},{'id': '55', 'type': 'block', 'children': ['56', '66', '72']},{'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': 'self'},{'id': '60', 'type': 'identifier', 'children': [], 'value': '_add_interval'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'list_splat', 'children': ['63']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'single_interval'},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'single_interval'},{'id': '71', 'type': 'integer', 'children': [], 'value': '0'},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'call', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '76', 'type': 'identifier', 'children': [], 'value': '_add_interval'},{'id': '77', 'type': 'argument_list', 'children': ['78', '79', '80']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'data'}
def add_interval(self, start, end, data=None): ''' Inserts an interval to the tree. Note that when inserting we do not maintain appropriate sorting of the "mid" data structure. This should be done after all intervals are inserted. ''' if (end - start) <= 0: return if self.single_interval is None: self.single_interval = (start, end, data) elif self.single_interval == 0: self._add_interval(start, end, data) else: self._add_interval(*self.single_interval) self.single_interval = 0 self._add_interval(start, end, data)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'querydict'},{'id': '6', 'type': 'block', 'children': ['7', '49', '129']},{'id': '7', 'type': 'for_statement', 'children': ['8', '9', '14']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'querydict'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '13', 'type': 'argument_list', 'children': []},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'if_statement', 'children': ['16', '34']},{'id': '16', 'type': 'not_operator', 'children': ['17']},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'tuple', 'children': ['21', '26']},{'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': 'in'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'JSONAPIQueryDict'},{'id': '25', 'type': 'identifier', 'children': [], 'value': '_fields'},{'id': '26', 'type': 'call', 'children': ['27', '32']},{'id': '27', 'type': 'attribute', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'RE_FIELDS'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '34', 'type': 'block', 'children': ['35', '44']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'string', 'children': [], 'value': '"Query parameter {} is not known"'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'key'},{'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': 'identifier', 'children': [], 'value': 'msg'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'JSONAPIQueryDict'},{'id': '54', 'type': 'argument_list', 'children': ['55', '68', '76', '84', '97', '116']},{'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'distinct'},{'id': '57', 'type': 'call', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'prepare_values'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'querydict'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'getlist'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'string', 'children': [], 'value': "'distinct'"},{'id': '68', 'type': 'keyword_argument', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'parse_fields'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'querydict'},{'id': '76', 'type': 'keyword_argument', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '78', 'type': 'call', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'querydict'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'getlist'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'string', 'children': [], 'value': "'filter'"},{'id': '84', 'type': 'keyword_argument', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'include'},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'prepare_values'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'querydict'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'getlist'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'string', 'children': [], 'value': "'include'"},{'id': '97', 'type': 'keyword_argument', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '99', 'type': 'conditional_expression', 'children': ['100', '109', '115'], 'value': 'if'},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'int'},{'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': 'querydict'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'string', 'children': [], 'value': "'page'"},{'id': '109', 'type': 'call', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'querydict'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'string', 'children': [], 'value': "'page'"},{'id': '115', 'type': 'None', 'children': []},{'id': '116', 'type': 'keyword_argument', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'prepare_values'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'call', 'children': ['124', '127']},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'querydict'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'getlist'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'string', 'children': [], 'value': "'sort'"},{'id': '129', 'type': 'return_statement', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'result'}
def parse(cls, querydict): for key in querydict.keys(): if not any((key in JSONAPIQueryDict._fields, cls.RE_FIELDS.match(key))): msg = "Query parameter {} is not known".format(key) raise ValueError(msg) result = JSONAPIQueryDict( distinct=cls.prepare_values(querydict.getlist('distinct')), fields=cls.parse_fields(querydict), filter=querydict.getlist('filter'), include=cls.prepare_values(querydict.getlist('include')), page=int(querydict.get('page')) if querydict.get('page') else None, sort=cls.prepare_values(querydict.getlist('sort')) ) return result
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_pcca_connected_isa'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'evec'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'n_clusters'},{'id': '6', 'type': 'block', 'children': ['7', '15', '46', '73', '82', '91', '105', '114', '118', '132', '172', '181', '290', '303', '313']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '12']},{'id': '9', 'type': 'tuple_pattern', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'evec'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '15', 'type': 'if_statement', 'children': ['16', '19']},{'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': '>'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'n_clusters'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'raise_statement', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'binary_operator', 'children': ['25', '45'], 'value': '+'},{'id': '25', 'type': 'binary_operator', 'children': ['26', '41'], 'value': '+'},{'id': '26', 'type': 'binary_operator', 'children': ['27', '40'], 'value': '+'},{'id': '27', 'type': 'binary_operator', 'children': ['28', '36'], 'value': '+'},{'id': '28', 'type': 'binary_operator', 'children': ['29', '35'], 'value': '+'},{'id': '29', 'type': 'binary_operator', 'children': ['30', '31'], 'value': '+'},{'id': '30', 'type': 'string', 'children': [], 'value': '"Cannot cluster the ("'},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '35', 'type': 'string', 'children': [], 'value': '" x "'},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '40', 'type': 'string', 'children': [], 'value': '" eigenvector matrix to "'},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'n_clusters'},{'id': '45', 'type': 'string', 'children': [], 'value': '" clusters."'},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'diffs'},{'id': '49', 'type': 'call', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'binary_operator', 'children': ['55', '64'], 'value': '-'},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '59', 'type': 'argument_list', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'evec'},{'id': '61', 'type': 'keyword_argument', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '63', 'type': 'integer', 'children': [], 'value': '0'},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '68', 'type': 'argument_list', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'evec'},{'id': '70', 'type': 'keyword_argument', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '72', 'type': 'integer', 'children': [], 'value': '0'},{'id': '73', 'type': 'assert_statement', 'children': ['74', '79']},{'id': '74', 'type': 'comparison_operator', 'children': ['75', '78'], 'value': '<'},{'id': '75', 'type': 'subscript', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'diffs'},{'id': '77', 'type': 'integer', 'children': [], 'value': '0'},{'id': '78', 'type': 'float', 'children': [], 'value': '1e-6'},{'id': '79', 'type': 'concatenated_string', 'children': ['80', '81']},{'id': '80', 'type': 'string', 'children': [], 'value': '"First eigenvector is not constant. This indicates that the transition matrix "'},{'id': '81', 'type': 'string', 'children': [], 'value': '"is not connected or the eigenvectors are incorrectly sorted. Cannot do PCCA."'},{'id': '82', 'type': 'assert_statement', 'children': ['83', '88']},{'id': '83', 'type': 'comparison_operator', 'children': ['84', '87'], 'value': '>'},{'id': '84', 'type': 'subscript', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'diffs'},{'id': '86', 'type': 'integer', 'children': [], 'value': '1'},{'id': '87', 'type': 'float', 'children': [], 'value': '1e-6'},{'id': '88', 'type': 'concatenated_string', 'children': ['89', '90']},{'id': '89', 'type': 'string', 'children': [], 'value': '"An eigenvector after the first one is constant. "'},{'id': '90', 'type': 'string', 'children': [], 'value': '"Probably the eigenvectors are incorrectly sorted. Cannot do PCCA."'},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '94', 'type': 'subscript', 'children': ['95', '96', '98']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'evec'},{'id': '96', 'type': 'slice', 'children': ['97']},{'id': '97', 'type': 'colon', 'children': []},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'n_clusters'},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'ortho_sys'},{'id': '108', 'type': 'call', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'max_dist'},{'id': '117', 'type': 'float', 'children': [], 'value': '0.0'},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'ind'},{'id': '121', 'type': 'call', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'zeros'},{'id': '125', 'type': 'argument_list', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'n_clusters'},{'id': '127', 'type': 'keyword_argument', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'int32'},{'id': '132', 'type': 'for_statement', 'children': ['133', '136', '140']},{'id': '133', 'type': 'tuple_pattern', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '140', 'type': 'block', 'children': ['141']},{'id': '141', 'type': 'if_statement', 'children': ['142', '153']},{'id': '142', 'type': 'comparison_operator', 'children': ['143', '152'], 'value': '>'},{'id': '143', 'type': 'call', 'children': ['144', '149']},{'id': '144', 'type': 'attribute', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'linalg'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'norm'},{'id': '149', 'type': 'argument_list', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '151', 'type': 'integer', 'children': [], 'value': '2'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'max_dist'},{'id': '153', 'type': 'block', 'children': ['154', '166']},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'assignment', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'max_dist'},{'id': '157', 'type': 'call', 'children': ['158', '163']},{'id': '158', 'type': 'attribute', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'linalg'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'norm'},{'id': '163', 'type': 'argument_list', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '165', 'type': 'integer', 'children': [], 'value': '2'},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '171']},{'id': '168', 'type': 'subscript', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'ind'},{'id': '170', 'type': 'integer', 'children': [], 'value': '0'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'augmented_assignment', 'children': ['174', '175'], 'value': '-='},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'ortho_sys'},{'id': '175', 'type': 'subscript', 'children': ['176', '177', '180']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '177', 'type': 'subscript', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'ind'},{'id': '179', 'type': 'integer', 'children': [], 'value': '0'},{'id': '180', 'type': 'None', 'children': []},{'id': '181', 'type': 'for_statement', 'children': ['182', '183', '188']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '183', 'type': 'call', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '185', 'type': 'argument_list', 'children': ['186', '187']},{'id': '186', 'type': 'integer', 'children': [], 'value': '1'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'n_clusters'},{'id': '188', 'type': 'block', 'children': ['189', '193', '208', '274']},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'assignment', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'max_dist'},{'id': '192', 'type': 'float', 'children': [], 'value': '0.0'},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'assignment', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'temp'},{'id': '196', 'type': 'call', 'children': ['197', '200']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '200', 'type': 'argument_list', 'children': ['201']},{'id': '201', 'type': 'subscript', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'ortho_sys'},{'id': '203', 'type': 'subscript', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'ind'},{'id': '205', 'type': 'binary_operator', 'children': ['206', '207'], 'value': '-'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '207', 'type': 'integer', 'children': [], 'value': '1'},{'id': '208', 'type': 'for_statement', 'children': ['209', '212', '216']},{'id': '209', 'type': 'tuple_pattern', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '212', 'type': 'call', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '214', 'type': 'argument_list', 'children': ['215']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'ortho_sys'},{'id': '216', 'type': 'block', 'children': ['217', '238', '250']},{'id': '217', 'type': 'expression_statement', 'children': ['218']},{'id': '218', 'type': 'augmented_assignment', 'children': ['219', '220'], 'value': '-='},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '220', 'type': 'call', 'children': ['221', '224']},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'dot'},{'id': '224', 'type': 'argument_list', 'children': ['225', '237']},{'id': '225', 'type': 'call', 'children': ['226', '229']},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'dot'},{'id': '229', 'type': 'argument_list', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'temp'},{'id': '231', 'type': 'call', 'children': ['232', '235']},{'id': '232', 'type': 'attribute', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'transpose'},{'id': '235', 'type': 'argument_list', 'children': ['236']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'temp'},{'id': '238', 'type': 'expression_statement', 'children': ['239']},{'id': '239', 'type': 'assignment', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'distt'},{'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': 'np'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'linalg'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'norm'},{'id': '247', 'type': 'argument_list', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '249', 'type': 'integer', 'children': [], 'value': '2'},{'id': '250', 'type': 'if_statement', 'children': ['251', '263']},{'id': '251', 'type': 'boolean_operator', 'children': ['252', '255'], 'value': 'and'},{'id': '252', 'type': 'comparison_operator', 'children': ['253', '254'], 'value': '>'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'distt'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'max_dist'},{'id': '255', 'type': 'comparison_operator', 'children': ['256', '257'], 'value': 'not'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '257', 'type': 'subscript', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'ind'},{'id': '259', 'type': 'slice', 'children': ['260', '261', '262']},{'id': '260', 'type': 'integer', 'children': [], 'value': '0'},{'id': '261', 'type': 'colon', 'children': []},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '263', 'type': 'block', 'children': ['264', '268']},{'id': '264', 'type': 'expression_statement', 'children': ['265']},{'id': '265', 'type': 'assignment', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'max_dist'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'distt'},{'id': '268', 'type': 'expression_statement', 'children': ['269']},{'id': '269', 'type': 'assignment', 'children': ['270', '273']},{'id': '270', 'type': 'subscript', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'ind'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '274', 'type': 'expression_statement', 'children': ['275']},{'id': '275', 'type': 'augmented_assignment', 'children': ['276', '277'], 'value': '/='},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'ortho_sys'},{'id': '277', 'type': 'call', 'children': ['278', '283']},{'id': '278', 'type': 'attribute', 'children': ['279', '282']},{'id': '279', 'type': 'attribute', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'linalg'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'norm'},{'id': '283', 'type': 'argument_list', 'children': ['284', '289']},{'id': '284', 'type': 'subscript', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'ortho_sys'},{'id': '286', 'type': 'subscript', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'ind'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '289', 'type': 'integer', 'children': [], 'value': '2'},{'id': '290', 'type': 'expression_statement', 'children': ['291']},{'id': '291', 'type': 'assignment', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'rot_mat'},{'id': '293', 'type': 'call', 'children': ['294', '299']},{'id': '294', 'type': 'attribute', 'children': ['295', '298']},{'id': '295', 'type': 'attribute', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'linalg'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'inv'},{'id': '299', 'type': 'argument_list', 'children': ['300']},{'id': '300', 'type': 'subscript', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'ind'},{'id': '303', 'type': 'expression_statement', 'children': ['304']},{'id': '304', 'type': 'assignment', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'chi'},{'id': '306', 'type': 'call', 'children': ['307', '310']},{'id': '307', 'type': 'attribute', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'dot'},{'id': '310', 'type': 'argument_list', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'rot_mat'},{'id': '313', 'type': 'return_statement', 'children': ['314']},{'id': '314', 'type': 'tuple', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'chi'},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'rot_mat'}
def _pcca_connected_isa(evec, n_clusters): (n, m) = evec.shape if n_clusters > m: raise ValueError("Cannot cluster the (" + str(n) + " x " + str(m) + " eigenvector matrix to " + str(n_clusters) + " clusters.") diffs = np.abs(np.max(evec, axis=0) - np.min(evec, axis=0)) assert diffs[0] < 1e-6, "First eigenvector is not constant. This indicates that the transition matrix " \ "is not connected or the eigenvectors are incorrectly sorted. Cannot do PCCA." assert diffs[1] > 1e-6, "An eigenvector after the first one is constant. " \ "Probably the eigenvectors are incorrectly sorted. Cannot do PCCA." c = evec[:, list(range(n_clusters))] ortho_sys = np.copy(c) max_dist = 0.0 ind = np.zeros(n_clusters, dtype=np.int32) for (i, row) in enumerate(c): if np.linalg.norm(row, 2) > max_dist: max_dist = np.linalg.norm(row, 2) ind[0] = i ortho_sys -= c[ind[0], None] for k in range(1, n_clusters): max_dist = 0.0 temp = np.copy(ortho_sys[ind[k - 1]]) for (i, row) in enumerate(ortho_sys): row -= np.dot(np.dot(temp, np.transpose(row)), temp) distt = np.linalg.norm(row, 2) if distt > max_dist and i not in ind[0:k]: max_dist = distt ind[k] = i ortho_sys /= np.linalg.norm(ortho_sys[ind[k]], 2) rot_mat = np.linalg.inv(c[ind]) chi = np.dot(c, rot_mat) return (chi, rot_mat)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_opt_soft'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'eigvectors'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'rot_matrix'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'n_clusters'},{'id': '7', 'type': 'block', 'children': ['8', '18', '32', '40', '52', '119', '125', '140', '152', '160']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'eigvectors'},{'id': '11', 'type': 'subscript', 'children': ['12', '13', '15']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'eigvectors'},{'id': '13', 'type': 'slice', 'children': ['14']},{'id': '14', 'type': 'colon', 'children': []},{'id': '15', 'type': 'slice', 'children': ['16', '17']},{'id': '16', 'type': 'colon', 'children': []},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'n_clusters'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'rot_crop_matrix'},{'id': '21', 'type': 'subscript', 'children': ['22', '27', '29']},{'id': '22', 'type': 'subscript', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'rot_matrix'},{'id': '24', 'type': 'slice', 'children': ['25', '26']},{'id': '25', 'type': 'integer', 'children': [], 'value': '1'},{'id': '26', 'type': 'colon', 'children': []},{'id': '27', 'type': 'slice', 'children': ['28']},{'id': '28', 'type': 'colon', 'children': []},{'id': '29', 'type': 'slice', 'children': ['30', '31']},{'id': '30', 'type': 'integer', 'children': [], 'value': '1'},{'id': '31', 'type': 'colon', 'children': []},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '37']},{'id': '34', 'type': 'tuple_pattern', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'rot_crop_matrix'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'rot_crop_vec'},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'reshape'},{'id': '47', 'type': 'argument_list', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'rot_crop_matrix'},{'id': '49', 'type': 'binary_operator', 'children': ['50', '51'], 'value': '*'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '52', 'type': 'function_definition', 'children': ['53', '54', '57']},{'id': '53', 'type': 'function_name', 'children': [], 'value': 'susanna_func'},{'id': '54', 'type': 'parameters', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'rot_crop_vec'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'eigvectors'},{'id': '57', 'type': 'block', 'children': ['58', '70', '78', '82', '116']},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'rot_crop_matrix'},{'id': '61', 'type': 'call', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'reshape'},{'id': '65', 'type': 'argument_list', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'rot_crop_vec'},{'id': '67', 'type': 'tuple', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'rot_matrix'},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': '_fill_matrix'},{'id': '75', 'type': 'argument_list', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'rot_crop_matrix'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'eigvectors'},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '81', 'type': 'integer', 'children': [], 'value': '0'},{'id': '82', 'type': 'for_statement', 'children': ['83', '84', '89']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '86', 'type': 'argument_list', 'children': ['87', '88']},{'id': '87', 'type': 'integer', 'children': [], 'value': '0'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'n_clusters'},{'id': '89', 'type': 'block', 'children': ['90']},{'id': '90', 'type': 'for_statement', 'children': ['91', '92', '97']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '94', 'type': 'argument_list', 'children': ['95', '96']},{'id': '95', 'type': 'integer', 'children': [], 'value': '0'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'n_clusters'},{'id': '97', 'type': 'block', 'children': ['98']},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'augmented_assignment', 'children': ['100', '101'], 'value': '+='},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '101', 'type': 'binary_operator', 'children': ['102', '112'], 'value': '/'},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'power'},{'id': '106', 'type': 'argument_list', 'children': ['107', '111']},{'id': '107', 'type': 'subscript', 'children': ['108', '109', '110']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'rot_matrix'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '111', 'type': 'integer', 'children': [], 'value': '2'},{'id': '112', 'type': 'subscript', 'children': ['113', '114', '115']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'rot_matrix'},{'id': '114', 'type': 'integer', 'children': [], 'value': '0'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '116', 'type': 'return_statement', 'children': ['117']},{'id': '117', 'type': 'unary_operator', 'children': ['118'], 'value': '-'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '119', 'type': 'import_from_statement', 'children': ['120', '123']},{'id': '120', 'type': 'dotted_name', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'scipy'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'optimize'},{'id': '123', 'type': 'dotted_name', 'children': ['124']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'fmin'},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'rot_crop_vec_opt'},{'id': '128', 'type': 'call', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'fmin'},{'id': '130', 'type': 'argument_list', 'children': ['131', '132', '133', '137']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'susanna_func'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'rot_crop_vec'},{'id': '133', 'type': 'keyword_argument', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '135', 'type': 'tuple', 'children': ['136']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'eigvectors'},{'id': '137', 'type': 'keyword_argument', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'disp'},{'id': '139', 'type': 'False', 'children': []},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'assignment', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'rot_crop_matrix'},{'id': '143', 'type': 'call', 'children': ['144', '147']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'reshape'},{'id': '147', 'type': 'argument_list', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'rot_crop_vec_opt'},{'id': '149', 'type': 'tuple', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'rot_matrix'},{'id': '155', 'type': 'call', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': '_fill_matrix'},{'id': '157', 'type': 'argument_list', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'rot_crop_matrix'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'eigvectors'},{'id': '160', 'type': 'return_statement', 'children': ['161']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'rot_matrix'}
def _opt_soft(eigvectors, rot_matrix, n_clusters): eigvectors = eigvectors[:, :n_clusters] rot_crop_matrix = rot_matrix[1:][:, 1:] (x, y) = rot_crop_matrix.shape rot_crop_vec = np.reshape(rot_crop_matrix, x * y) def susanna_func(rot_crop_vec, eigvectors): rot_crop_matrix = np.reshape(rot_crop_vec, (x, y)) rot_matrix = _fill_matrix(rot_crop_matrix, eigvectors) result = 0 for i in range(0, n_clusters): for j in range(0, n_clusters): result += np.power(rot_matrix[j, i], 2) / rot_matrix[0, i] return -result from scipy.optimize import fmin rot_crop_vec_opt = fmin(susanna_func, rot_crop_vec, args=(eigvectors,), disp=False) rot_crop_matrix = np.reshape(rot_crop_vec_opt, (x, y)) rot_matrix = _fill_matrix(rot_crop_matrix, eigvectors) return rot_matrix
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'connected_sets'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'C'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'directed'},{'id': '7', 'type': 'True', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '11']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '11', 'type': 'if_statement', 'children': ['12', '16', '32']},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'isdense'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'C'},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'return_statement', 'children': ['18']},{'id': '18', 'type': 'call', 'children': ['19', '24']},{'id': '19', 'type': 'attribute', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'sparse'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'connectivity'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'connected_sets'},{'id': '24', 'type': 'argument_list', 'children': ['25', '29']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'csr_matrix'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'C'},{'id': '29', 'type': 'keyword_argument', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'directed'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'directed'},{'id': '32', 'type': 'else_clause', 'children': ['33']},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'return_statement', 'children': ['35']},{'id': '35', 'type': 'call', 'children': ['36', '41']},{'id': '36', 'type': 'attribute', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'sparse'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'connectivity'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'connected_sets'},{'id': '41', 'type': 'argument_list', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'C'},{'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'directed'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'directed'}
def connected_sets(C, directed=True): r if isdense(C): return sparse.connectivity.connected_sets(csr_matrix(C), directed=directed) else: return sparse.connectivity.connected_sets(C, directed=directed)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'zcount'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'score_start'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'score_end'},{'id': '8', 'type': 'block', 'children': ['9', '17', '25']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'score_start'},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'get_integer_or_emptystring'},{'id': '14', 'type': 'argument_list', 'children': ['15', '16']},{'id': '15', 'type': 'string', 'children': [], 'value': "'score_start'"},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'score_start'},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'score_end'},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'get_integer_or_emptystring'},{'id': '22', 'type': 'argument_list', 'children': ['23', '24']},{'id': '23', 'type': 'string', 'children': [], 'value': "'score_end'"},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'score_end'},{'id': '25', 'type': 'return_statement', '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': 'execute_command'},{'id': '30', 'type': 'argument_list', 'children': ['31', '32', '33', '34']},{'id': '31', 'type': 'string', 'children': [], 'value': "'zcount'"},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'score_start'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'score_end'}
def zcount(self, name, score_start, score_end): score_start = get_integer_or_emptystring('score_start', score_start) score_end = get_integer_or_emptystring('score_end', score_end) return self.execute_command('zcount', name, score_start, score_end)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'reload_index'},{'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': 'progress_cb'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'dummy_progress_cb'},{'id': '8', 'type': 'block', 'children': ['9', '19', '23', '45', '54']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'nb_results'},{'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': 'index'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'start_reload_index'},{'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': 'progress'},{'id': '22', 'type': 'integer', 'children': [], 'value': '0'},{'id': '23', 'type': 'while_statement', 'children': ['24', '31']},{'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': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'continue_reload_index'},{'id': '30', 'type': 'argument_list', 'children': []},{'id': '31', 'type': 'block', 'children': ['32', '41']},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'progress_cb'},{'id': '35', 'type': 'argument_list', 'children': ['36', '37', '38']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'progress'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'nb_results'},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'INDEX_STEP_LOADING'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'augmented_assignment', 'children': ['43', '44'], 'value': '+='},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'progress'},{'id': '44', 'type': 'integer', 'children': [], 'value': '1'},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'progress_cb'},{'id': '48', 'type': 'argument_list', 'children': ['49', '50', '51']},{'id': '49', 'type': 'integer', 'children': [], 'value': '1'},{'id': '50', 'type': 'integer', 'children': [], 'value': '1'},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'INDEX_STEP_LOADING'},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'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': 'self'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'end_reload_index'},{'id': '61', 'type': 'argument_list', 'children': []}
def reload_index(self, progress_cb=dummy_progress_cb): nb_results = self.index.start_reload_index() progress = 0 while self.index.continue_reload_index(): progress_cb(progress, nb_results, self.INDEX_STEP_LOADING) progress += 1 progress_cb(1, 1, self.INDEX_STEP_LOADING) self.index.end_reload_index()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '__doc_cmp'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '6', 'type': 'block', 'children': ['7', '15', '26']},{'id': '7', 'type': 'if_statement', 'children': ['8', '11']},{'id': '8', 'type': 'comparison_operator', 'children': ['9', '10'], 'value': 'is'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'return_statement', 'children': ['13']},{'id': '13', 'type': 'unary_operator', 'children': ['14'], 'value': '-'},{'id': '14', 'type': 'integer', 'children': [], 'value': '1'},{'id': '15', 'type': 'if_statement', 'children': ['16', '23']},{'id': '16', 'type': 'boolean_operator', 'children': ['17', '20'], 'value': 'and'},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'is_new'},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'is_new'},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'return_statement', 'children': ['25']},{'id': '25', 'type': 'integer', 'children': [], 'value': '0'},{'id': '26', 'type': 'if_statement', 'children': ['27', '34', '38', '49']},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '31'], 'value': '<'},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '30', 'type': 'identifier', 'children': [], 'value': '__docid'},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '33', 'type': 'identifier', 'children': [], 'value': '__docid'},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'return_statement', 'children': ['36']},{'id': '36', 'type': 'unary_operator', 'children': ['37'], 'value': '-'},{'id': '37', 'type': 'integer', 'children': [], 'value': '1'},{'id': '38', 'type': 'elif_clause', 'children': ['39', '46']},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '43'], 'value': '=='},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '42', 'type': 'identifier', 'children': [], 'value': '__docid'},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '45', 'type': 'identifier', 'children': [], 'value': '__docid'},{'id': '46', 'type': 'block', 'children': ['47']},{'id': '47', 'type': 'return_statement', 'children': ['48']},{'id': '48', 'type': 'integer', 'children': [], 'value': '0'},{'id': '49', 'type': 'else_clause', 'children': ['50']},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'return_statement', 'children': ['52']},{'id': '52', 'type': 'integer', 'children': [], 'value': '1'}
def __doc_cmp(self, other): if other is None: return -1 if self.is_new and other.is_new: return 0 if self.__docid < other.__docid: return -1 elif self.__docid == other.__docid: return 0 else: return 1
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '__label_cmp'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '6', 'type': 'block', 'children': ['7', '15', '28', '41', '60']},{'id': '7', 'type': 'if_statement', 'children': ['8', '11']},{'id': '8', 'type': 'comparison_operator', 'children': ['9', '10'], 'value': 'is'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'return_statement', 'children': ['13']},{'id': '13', 'type': 'unary_operator', 'children': ['14'], 'value': '-'},{'id': '14', 'type': 'integer', 'children': [], 'value': '1'},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'label_name'},{'id': '18', 'type': 'call', 'children': ['19', '27']},{'id': '19', 'type': 'attribute', 'children': ['20', '26']},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'strip_accents'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '27', 'type': 'argument_list', 'children': []},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'other_name'},{'id': '31', 'type': 'call', 'children': ['32', '40']},{'id': '32', 'type': 'attribute', 'children': ['33', '39']},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'strip_accents'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '40', 'type': 'argument_list', 'children': []},{'id': '41', 'type': 'if_statement', 'children': ['42', '45', '49', '56']},{'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': '<'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'label_name'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'other_name'},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'return_statement', 'children': ['47']},{'id': '47', 'type': 'unary_operator', 'children': ['48'], 'value': '-'},{'id': '48', 'type': 'integer', 'children': [], 'value': '1'},{'id': '49', 'type': 'elif_clause', 'children': ['50', '53']},{'id': '50', 'type': 'comparison_operator', 'children': ['51', '52'], 'value': '=='},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'label_name'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'other_name'},{'id': '53', 'type': 'block', 'children': ['54']},{'id': '54', 'type': 'return_statement', 'children': ['55']},{'id': '55', 'type': 'integer', 'children': [], 'value': '0'},{'id': '56', 'type': 'else_clause', 'children': ['57']},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'return_statement', 'children': ['59']},{'id': '59', 'type': 'integer', 'children': [], 'value': '1'},{'id': '60', 'type': 'if_statement', 'children': ['61', '72', '76', '91']},{'id': '61', 'type': 'comparison_operator', 'children': ['62', '67'], 'value': '<'},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'get_color_str'},{'id': '66', 'type': 'argument_list', 'children': []},{'id': '67', 'type': 'call', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'get_color_str'},{'id': '71', 'type': 'argument_list', 'children': []},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'return_statement', 'children': ['74']},{'id': '74', 'type': 'unary_operator', 'children': ['75'], 'value': '-'},{'id': '75', 'type': 'integer', 'children': [], 'value': '1'},{'id': '76', 'type': 'elif_clause', 'children': ['77', '88']},{'id': '77', 'type': 'comparison_operator', 'children': ['78', '83'], 'value': '=='},{'id': '78', 'type': 'call', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'get_color_str'},{'id': '82', 'type': 'argument_list', 'children': []},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'get_color_str'},{'id': '87', 'type': 'argument_list', 'children': []},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'return_statement', 'children': ['90']},{'id': '90', 'type': 'integer', 'children': [], 'value': '0'},{'id': '91', 'type': 'else_clause', 'children': ['92']},{'id': '92', 'type': 'block', 'children': ['93']},{'id': '93', 'type': 'return_statement', 'children': ['94']},{'id': '94', 'type': 'integer', 'children': [], 'value': '1'}
def __label_cmp(self, other): if other is None: return -1 label_name = strip_accents(self.name).lower() other_name = strip_accents(other.name).lower() if label_name < other_name: return -1 elif label_name == other_name: return 0 else: return 1 if self.get_color_str() < other.get_color_str(): return -1 elif self.get_color_str() == other.get_color_str(): return 0 else: return 1
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'stop_sequence'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6']},{'id': '6', 'type': 'return_statement', 'children': ['7']},{'id': '7', 'type': 'call', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '9', 'type': 'argument_list', 'children': ['10', '15']},{'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': 'stop_times'},{'id': '14', 'type': 'argument_list', 'children': []},{'id': '15', 'type': 'keyword_argument', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '17', 'type': 'lambda', 'children': ['18', '20']},{'id': '18', 'type': 'lambda_parameters', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'int'},{'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': 'x'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'string', 'children': [], 'value': "'stop_sequence'"}
def stop_sequence(self): return sorted( self.stop_times(), key=lambda x:int(x.get('stop_sequence')) )
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'near'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '12', '15']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'collection'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'latitude'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'longitude'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'index_id'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'distance'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'skip'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'block', 'children': ['19', '41']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '22', 'type': 'dictionary', 'children': ['23', '26', '29', '32', '35', '38']},{'id': '23', 'type': 'pair', 'children': ['24', '25']},{'id': '24', 'type': 'string', 'children': [], 'value': "'geo'"},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'index_id'},{'id': '26', 'type': 'pair', 'children': ['27', '28']},{'id': '27', 'type': 'string', 'children': [], 'value': "'latitude'"},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'latitude'},{'id': '29', 'type': 'pair', 'children': ['30', '31']},{'id': '30', 'type': 'string', 'children': [], 'value': "'longitude'"},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'longitude'},{'id': '32', 'type': 'pair', 'children': ['33', '34']},{'id': '33', 'type': 'string', 'children': [], 'value': "'distance'"},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'distance'},{'id': '35', 'type': 'pair', 'children': ['36', '37']},{'id': '36', 'type': 'string', 'children': [], 'value': "'skip'"},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'skip'},{'id': '38', 'type': 'pair', 'children': ['39', '40']},{'id': '39', 'type': 'string', 'children': [], 'value': "'limit'"},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '41', 'type': 'return_statement', 'children': ['42']},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '45', 'type': 'identifier', 'children': [], 'value': '_construct_query'},{'id': '46', 'type': 'argument_list', 'children': ['47', '50', '53', '56']},{'id': '47', 'type': 'keyword_argument', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '49', 'type': 'string', 'children': [], 'value': "'near'"},{'id': '50', 'type': 'keyword_argument', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'collection'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'collection'},{'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'multiple'},{'id': '55', 'type': 'True', 'children': []},{'id': '56', 'type': 'dictionary_splat', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'kwargs'}
def near(cls, collection, latitude, longitude, index_id, distance=None, skip=None, limit=None): kwargs = { 'geo': index_id, 'latitude': latitude, 'longitude': longitude, 'distance': distance, 'skip': skip, 'limit': limit, } return cls._construct_query(name='near', collection=collection, multiple=True, **kwargs)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'rank_targets'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'sample_frame'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'ref_targets'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'ref_sample'},{'id': '7', 'type': 'block', 'children': ['8', '17', '27', '42', '49', '56', '60', '64', '185', '194', '200', '206', '215']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'collect_expression'},{'id': '13', 'type': 'argument_list', 'children': ['14', '15', '16']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'sample_frame'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'ref_targets'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'ref_sample'},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'all_samples'},{'id': '20', 'type': 'call', 'children': ['21', '26']},{'id': '21', 'type': 'attribute', 'children': ['22', '25']},{'id': '22', 'type': 'subscript', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'sample_frame'},{'id': '24', 'type': 'string', 'children': [], 'value': "'Sample'"},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'unique'},{'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': 't'},{'id': '30', 'type': 'call', 'children': ['31', '41']},{'id': '31', 'type': 'attribute', 'children': ['32', '40']},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'groupby'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'list', 'children': ['38', '39'], 'value': "['Sample', 'Target']"},{'id': '38', 'type': 'string', 'children': [], 'value': "'Sample'"},{'id': '39', 'type': 'string', 'children': [], 'value': "'Target'"},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'mean'},{'id': '41', 'type': 'argument_list', 'children': []},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'logt'},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'log2'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'ref_targets'},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'ref_targets'},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'worst'},{'id': '59', 'type': 'list', 'children': [], 'value': '[]'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'worst_m'},{'id': '63', 'type': 'list', 'children': [], 'value': '[]'},{'id': '64', 'type': 'while_statement', 'children': ['65', '76']},{'id': '65', 'type': 'comparison_operator', 'children': ['66', '75'], 'value': '>'},{'id': '66', 'type': 'binary_operator', 'children': ['67', '71'], 'value': '-'},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'ref_targets'},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'worst'},{'id': '75', 'type': 'integer', 'children': [], 'value': '1'},{'id': '76', 'type': 'block', 'children': ['77', '81', '161', '173']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'M'},{'id': '80', 'type': 'list', 'children': [], 'value': '[]'},{'id': '81', 'type': 'for_statement', 'children': ['82', '83', '84']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'test_target'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'ref_targets'},{'id': '84', 'type': 'block', 'children': ['85', '91', '95', '136']},{'id': '85', 'type': 'if_statement', 'children': ['86', '89']},{'id': '86', 'type': 'comparison_operator', 'children': ['87', '88'], 'value': 'in'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'test_target'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'worst'},{'id': '89', 'type': 'block', 'children': ['90']},{'id': '90', 'type': 'continue_statement', 'children': []},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'Vs'},{'id': '94', 'type': 'list', 'children': [], 'value': '[]'},{'id': '95', 'type': 'for_statement', 'children': ['96', '97', '98']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'ref_target'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'ref_targets'},{'id': '98', 'type': 'block', 'children': ['99', '109', '125']},{'id': '99', 'type': 'if_statement', 'children': ['100', '107']},{'id': '100', 'type': 'boolean_operator', 'children': ['101', '104'], 'value': 'or'},{'id': '101', 'type': 'comparison_operator', 'children': ['102', '103'], 'value': '=='},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'ref_target'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'test_target'},{'id': '104', 'type': 'comparison_operator', 'children': ['105', '106'], 'value': 'in'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'ref_target'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'worst'},{'id': '107', 'type': 'block', 'children': ['108']},{'id': '108', 'type': 'continue_statement', 'children': []},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '112', 'type': 'subscript', 'children': ['113', '116', '124']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'logt'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'ix'},{'id': '116', 'type': 'call', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '118', 'type': 'argument_list', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'all_samples'},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'repeat'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'test_target'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'ref_target'},{'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': 'Vs'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'call', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'std'},{'id': '135', 'type': 'argument_list', 'children': []},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'call', 'children': ['138', '141']},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'M'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'tuple', 'children': ['143', '160']},{'id': '143', 'type': 'binary_operator', 'children': ['144', '148'], 'value': '/'},{'id': '144', 'type': 'call', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'Vs'},{'id': '148', 'type': '()', 'children': ['149']},{'id': '149', 'type': 'binary_operator', 'children': ['150', '159'], 'value': '-'},{'id': '150', 'type': 'binary_operator', 'children': ['151', '155'], 'value': '-'},{'id': '151', 'type': 'call', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'ref_targets'},{'id': '155', 'type': 'call', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'worst'},{'id': '159', 'type': 'integer', 'children': [], 'value': '1'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'test_target'},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'call', 'children': ['163', '166']},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'worst'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'subscript', 'children': ['168', '172']},{'id': '168', 'type': 'call', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'M'},{'id': '172', 'type': 'integer', 'children': [], 'value': '1'},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'call', 'children': ['175', '178']},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'worst_m'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '178', 'type': 'argument_list', 'children': ['179']},{'id': '179', 'type': 'subscript', 'children': ['180', '184']},{'id': '180', 'type': 'call', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '182', 'type': 'argument_list', 'children': ['183']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'M'},{'id': '184', 'type': 'integer', 'children': [], 'value': '0'},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'assignment', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'best'},{'id': '188', 'type': 'binary_operator', 'children': ['189', '190'], 'value': '-'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'ref_targets'},{'id': '190', 'type': 'call', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'worst'},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'call', 'children': ['196', '199']},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'worst'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '199', 'type': 'argument_list', 'children': []},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'call', 'children': ['202', '205']},{'id': '202', 'type': 'attribute', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'worst_m'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '205', 'type': 'argument_list', 'children': []},{'id': '206', 'type': 'expression_statement', 'children': ['207']},{'id': '207', 'type': 'assignment', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'worst_m'},{'id': '209', 'type': 'binary_operator', 'children': ['210', '214'], 'value': '+'},{'id': '210', 'type': 'list', 'children': ['211'], 'value': '[worst_m[0]]'},{'id': '211', 'type': 'subscript', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'worst_m'},{'id': '213', 'type': 'integer', 'children': [], 'value': '0'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'worst_m'},{'id': '215', 'type': 'return_statement', 'children': ['216']},{'id': '216', 'type': 'call', 'children': ['217', '220']},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'DataFrame'},{'id': '220', 'type': 'argument_list', 'children': ['221', '233']},{'id': '221', 'type': 'dictionary', 'children': ['222', '230']},{'id': '222', 'type': 'pair', 'children': ['223', '224']},{'id': '223', 'type': 'string', 'children': [], 'value': "'Target'"},{'id': '224', 'type': 'binary_operator', 'children': ['225', '229'], 'value': '+'},{'id': '225', 'type': 'call', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '227', 'type': 'argument_list', 'children': ['228']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'best'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'worst'},{'id': '230', 'type': 'pair', 'children': ['231', '232']},{'id': '231', 'type': 'string', 'children': [], 'value': "'M'"},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'worst_m'},{'id': '233', 'type': 'keyword_argument', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '235', 'type': 'list', 'children': ['236', '237'], 'value': "['Target', 'M']"},{'id': '236', 'type': 'string', 'children': [], 'value': "'Target'"},{'id': '237', 'type': 'string', 'children': [], 'value': "'M'"}
def rank_targets(sample_frame, ref_targets, ref_sample): table = collect_expression(sample_frame, ref_targets, ref_sample) all_samples = sample_frame['Sample'].unique() t = table.groupby(['Sample', 'Target']).mean() logt = log2(t) ref_targets = set(ref_targets) worst = [] worst_m = [] while len(ref_targets) - len(worst) > 1: M = [] for test_target in ref_targets: if test_target in worst: continue Vs = [] for ref_target in ref_targets: if ref_target == test_target or ref_target in worst: continue A = logt.ix[zip(all_samples, repeat(test_target)), ref_target] Vs.append(A.std()) M.append( (sum(Vs)/(len(ref_targets)-len(worst)-1), test_target) ) worst.append(max(M)[1]) worst_m.append(max(M)[0]) best = ref_targets - set(worst) worst.reverse() worst_m.reverse() worst_m = [worst_m[0]] + worst_m return pd.DataFrame({'Target': list(best) + worst, 'M': worst_m}, columns=['Target', 'M'])
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'natural_sort_key'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '5', 'type': 'block', 'children': ['6']},{'id': '6', 'type': 'return_statement', 'children': ['7']},{'id': '7', 'type': 'list_comprehension', 'children': ['8', '19']},{'id': '8', 'type': 'conditional_expression', 'children': ['9', '13', '18'], 'value': 'if'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'isdigit'},{'id': '17', 'type': 'argument_list', 'children': []},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '19', 'type': 'for_in_clause', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'INTEGER_RE'},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 's'}
def natural_sort_key(s): return [int(text) if text.isdigit() else text for text in re.split(INTEGER_RE, str(s))]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'relabel_nodes'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'mapping'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '8', 'type': 'True', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '39']},{'id': '10', 'type': 'if_statement', 'children': ['11', '17', '33']},{'id': '11', 'type': 'not_operator', 'children': ['12']},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '14', 'type': 'argument_list', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'mapping'},{'id': '16', 'type': 'string', 'children': [], 'value': '"__getitem__"'},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '23', 'type': 'generator_expression', 'children': ['24', '30']},{'id': '24', 'type': 'tuple', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'mapping'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '30', 'type': 'for_in_clause', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '33', 'type': 'else_clause', 'children': ['34']},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'mapping'},{'id': '39', 'type': 'if_statement', 'children': ['40', '41', '48']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '41', 'type': 'block', 'children': ['42']},{'id': '42', 'type': 'return_statement', 'children': ['43']},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': '_relabel_copy'},{'id': '45', 'type': 'argument_list', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '48', 'type': 'else_clause', 'children': ['49']},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'return_statement', 'children': ['51']},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': '_relabel_inplace'},{'id': '53', 'type': 'argument_list', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'm'}
def relabel_nodes(G, mapping, copy=True): if not hasattr(mapping, "__getitem__"): m = dict((n, mapping(n)) for n in G) else: m = mapping if copy: return _relabel_copy(G, m) else: return _relabel_inplace(G, m)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'convert_node_labels_to_integers'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'first_label'},{'id': '7', 'type': 'integer', 'children': [], 'value': '0'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'ordering'},{'id': '10', 'type': 'string', 'children': [], 'value': '"default"'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'label_attribute'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '25', '199', '207', '219', '247']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '18', 'type': 'binary_operator', 'children': ['19', '24'], 'value': '+'},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'number_of_nodes'},{'id': '23', 'type': 'argument_list', 'children': []},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'first_label'},{'id': '25', 'type': 'if_statement', 'children': ['26', '29', '49', '83', '131', '185']},{'id': '26', 'type': 'comparison_operator', 'children': ['27', '28'], 'value': '=='},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'ordering'},{'id': '28', 'type': 'string', 'children': [], 'value': '"default"'},{'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': 'mapping'},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '38', 'type': 'argument_list', 'children': ['39', '44']},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '43', 'type': 'argument_list', 'children': []},{'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': 'identifier', 'children': [], 'value': 'first_label'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '49', 'type': 'elif_clause', 'children': ['50', '53']},{'id': '50', 'type': 'comparison_operator', 'children': ['51', '52'], 'value': '=='},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'ordering'},{'id': '52', 'type': 'string', 'children': [], 'value': '"sorted"'},{'id': '53', 'type': 'block', 'children': ['54', '62', '68']},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'nlist'},{'id': '57', 'type': 'call', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '61', 'type': 'argument_list', 'children': []},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'call', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'nlist'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '67', 'type': 'argument_list', 'children': []},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'mapping'},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '76', 'type': 'argument_list', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'nlist'},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '80', 'type': 'argument_list', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'first_label'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '83', 'type': 'elif_clause', 'children': ['84', '87']},{'id': '84', 'type': 'comparison_operator', 'children': ['85', '86'], 'value': '=='},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'ordering'},{'id': '86', 'type': 'string', 'children': [], 'value': '"increasing degree"'},{'id': '87', 'type': 'block', 'children': ['88', '104', '110']},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'dv_pairs'},{'id': '91', 'type': 'list_comprehension', 'children': ['92', '95']},{'id': '92', 'type': 'tuple', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '95', 'type': 'for_in_clause', 'children': ['96', '99']},{'id': '96', 'type': 'tuple_pattern', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '99', 'type': 'call', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'degree_iter'},{'id': '103', 'type': 'argument_list', 'children': []},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'dv_pairs'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '109', 'type': 'argument_list', 'children': []},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'assignment', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'mapping'},{'id': '113', 'type': 'call', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'call', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '118', 'type': 'argument_list', 'children': ['119', '126']},{'id': '119', 'type': 'list_comprehension', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '121', 'type': 'for_in_clause', 'children': ['122', '125']},{'id': '122', 'type': 'pattern_list', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'dv_pairs'},{'id': '126', 'type': 'call', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '128', 'type': 'argument_list', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'first_label'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '131', 'type': 'elif_clause', 'children': ['132', '135']},{'id': '132', 'type': 'comparison_operator', 'children': ['133', '134'], 'value': '=='},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'ordering'},{'id': '134', 'type': 'string', 'children': [], 'value': '"decreasing degree"'},{'id': '135', 'type': 'block', 'children': ['136', '152', '158', '164']},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'dv_pairs'},{'id': '139', 'type': 'list_comprehension', 'children': ['140', '143']},{'id': '140', 'type': 'tuple', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '143', 'type': 'for_in_clause', 'children': ['144', '147']},{'id': '144', 'type': 'tuple_pattern', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '147', 'type': 'call', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'degree_iter'},{'id': '151', 'type': 'argument_list', 'children': []},{'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': 'dv_pairs'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '157', 'type': 'argument_list', 'children': []},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'call', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'dv_pairs'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '163', 'type': 'argument_list', 'children': []},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'assignment', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'mapping'},{'id': '167', 'type': 'call', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '169', 'type': 'argument_list', 'children': ['170']},{'id': '170', 'type': 'call', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '172', 'type': 'argument_list', 'children': ['173', '180']},{'id': '173', 'type': 'list_comprehension', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '175', 'type': 'for_in_clause', 'children': ['176', '179']},{'id': '176', 'type': 'pattern_list', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'dv_pairs'},{'id': '180', 'type': 'call', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '182', 'type': 'argument_list', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'first_label'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '185', 'type': 'else_clause', 'children': ['186']},{'id': '186', 'type': 'block', 'children': ['187']},{'id': '187', 'type': 'raise_statement', 'children': ['188']},{'id': '188', 'type': 'call', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'nx'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'NetworkXError'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'call', 'children': ['194', '197']},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'string', 'children': [], 'value': "'Unknown node ordering: {0}'"},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '197', 'type': 'argument_list', 'children': ['198']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'ordering'},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'assignment', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'H'},{'id': '202', 'type': 'call', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'relabel_nodes'},{'id': '204', 'type': 'argument_list', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'mapping'},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'assignment', 'children': ['209', '212']},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'H'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '212', 'type': 'binary_operator', 'children': ['213', '218'], 'value': '+'},{'id': '213', 'type': 'binary_operator', 'children': ['214', '215'], 'value': '+'},{'id': '214', 'type': 'string', 'children': [], 'value': '"("'},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '218', 'type': 'string', 'children': [], 'value': '")_with_int_labels"'},{'id': '219', 'type': 'if_statement', 'children': ['220', '223']},{'id': '220', 'type': 'comparison_operator', 'children': ['221', '222'], 'value': 'is'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'label_attribute'},{'id': '222', 'type': 'None', 'children': []},{'id': '223', 'type': 'block', 'children': ['224']},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'call', 'children': ['226', '229']},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'nx'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'set_node_attributes'},{'id': '229', 'type': 'argument_list', 'children': ['230', '231', '232']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'H'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'label_attribute'},{'id': '232', 'type': 'call', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '234', 'type': 'generator_expression', 'children': ['235', '238']},{'id': '235', 'type': 'tuple', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '238', 'type': 'for_in_clause', 'children': ['239', '242']},{'id': '239', 'type': 'pattern_list', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '242', 'type': 'call', 'children': ['243', '246']},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'mapping'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '246', 'type': 'argument_list', 'children': []},{'id': '247', 'type': 'return_statement', 'children': ['248']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'H'}
def convert_node_labels_to_integers(G, first_label=0, ordering="default", label_attribute=None): N = G.number_of_nodes() + first_label if ordering == "default": mapping = dict(zip(G.nodes(), range(first_label, N))) elif ordering == "sorted": nlist = G.nodes() nlist.sort() mapping = dict(zip(nlist, range(first_label, N))) elif ordering == "increasing degree": dv_pairs = [(d, n) for (n, d) in G.degree_iter()] dv_pairs.sort() mapping = dict(zip([n for d, n in dv_pairs], range(first_label, N))) elif ordering == "decreasing degree": dv_pairs = [(d, n) for (n, d) in G.degree_iter()] dv_pairs.sort() dv_pairs.reverse() mapping = dict(zip([n for d, n in dv_pairs], range(first_label, N))) else: raise nx.NetworkXError('Unknown node ordering: {0}'.format(ordering)) H = relabel_nodes(G, mapping) H.name = "(" + G.name + ")_with_int_labels" if label_attribute is not None: nx.set_node_attributes(H, label_attribute, dict((v, k) for k, v in mapping.items())) return H
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_token_ids'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '5', 'type': 'block', 'children': ['6', '22', '31']},{'id': '6', 'type': 'function_definition', 'children': ['7', '8', '10']},{'id': '7', 'type': 'function_name', 'children': [], 'value': 'tok2time'},{'id': '8', 'type': 'parameters', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'token_element'},{'id': '10', 'type': 'block', 'children': ['11', '13']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'string', 'children': [], 'value': "'''\n extracts the time (float) of a <tli> element\n (i.e. the absolute position of a token in the document)\n '''"},{'id': '13', 'type': 'return_statement', 'children': ['14']},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'subscript', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'token_element'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '21', 'type': 'string', 'children': [], 'value': "'time'"},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'timeline'},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'string', 'children': [], 'value': "'//common-timeline'"},{'id': '31', 'type': 'return_statement', 'children': ['32']},{'id': '32', 'type': 'generator_expression', 'children': ['33', '38']},{'id': '33', 'type': 'subscript', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'tok'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '37', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '38', 'type': 'for_in_clause', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'tok'},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '42', 'type': 'argument_list', 'children': ['43', '52']},{'id': '43', 'type': 'generator_expression', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'tli'},{'id': '45', 'type': 'for_in_clause', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'tli'},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'timeline'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'iterchildren'},{'id': '51', 'type': 'argument_list', 'children': []},{'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'tok2time'}
def get_token_ids(tree): def tok2time(token_element): ''' extracts the time (float) of a <tli> element (i.e. the absolute position of a token in the document) ''' return float(token_element.attrib['time']) timeline = tree.find('//common-timeline') return (tok.attrib['id'] for tok in sorted((tli for tli in timeline.iterchildren()), key=tok2time))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_span'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'docgraph'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '38', '42', '62', '103']},{'id': '10', 'type': 'if_statement', 'children': ['11', '21']},{'id': '11', 'type': 'boolean_operator', 'children': ['12', '15'], 'value': 'and'},{'id': '12', 'type': 'comparison_operator', 'children': ['13', '14'], 'value': 'is'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '14', 'type': 'True', 'children': []},{'id': '15', 'type': 'comparison_operator', 'children': ['16', '20'], 'value': 'is'},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'is_directed_acyclic_graph'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'docgraph'},{'id': '20', 'type': 'False', 'children': []},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'warnings'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'call', 'children': ['29', '35']},{'id': '29', 'type': 'attribute', 'children': ['30', '34']},{'id': '30', 'type': '()', 'children': ['31']},{'id': '31', 'type': 'concatenated_string', 'children': ['32', '33']},{'id': '32', 'type': 'string', 'children': [], 'value': '"Can\'t reliably extract span \'{0}\' from cyclical graph\'{1}\'."'},{'id': '33', 'type': 'string', 'children': [], 'value': '"Maximum recursion depth may be exceeded."'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '35', 'type': 'argument_list', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'docgraph'},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'span'},{'id': '41', 'type': 'list', 'children': [], 'value': '[]'},{'id': '42', 'type': 'if_statement', 'children': ['43', '54']},{'id': '43', 'type': 'comparison_operator', 'children': ['44', '49'], 'value': 'in'},{'id': '44', 'type': 'binary_operator', 'children': ['45', '48'], 'value': '+'},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'docgraph'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '48', 'type': 'string', 'children': [], 'value': "':token'"},{'id': '49', 'type': 'subscript', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'docgraph'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '54', 'type': 'block', 'children': ['55']},{'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': 'span'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '62', 'type': 'for_statement', 'children': ['63', '67', '76']},{'id': '63', 'type': 'pattern_list', 'children': ['64', '65', '66']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'src_id'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'target_id'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'edge_attribs'},{'id': '67', 'type': 'call', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'docgraph'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'out_edges_iter'},{'id': '71', 'type': 'argument_list', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '73', 'type': 'keyword_argument', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '75', 'type': 'True', 'children': []},{'id': '76', 'type': 'block', 'children': ['77', '83']},{'id': '77', 'type': 'if_statement', 'children': ['78', '81']},{'id': '78', 'type': 'comparison_operator', 'children': ['79', '80'], 'value': '=='},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'src_id'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'target_id'},{'id': '81', 'type': 'block', 'children': ['82']},{'id': '82', 'type': 'continue_statement', 'children': []},{'id': '83', 'type': 'if_statement', 'children': ['84', '91']},{'id': '84', 'type': 'comparison_operator', 'children': ['85', '88'], 'value': '!='},{'id': '85', 'type': 'subscript', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'edge_attribs'},{'id': '87', 'type': 'string', 'children': [], 'value': "'edge_type'"},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'EdgeTypes'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'pointing_relation'},{'id': '91', 'type': 'block', 'children': ['92']},{'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': 'span'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'get_span'},{'id': '100', 'type': 'argument_list', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'docgraph'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'target_id'},{'id': '103', 'type': 'return_statement', 'children': ['104']},{'id': '104', 'type': 'call', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '106', 'type': 'argument_list', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'span'},{'id': '108', 'type': 'keyword_argument', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'natural_sort_key'}
def get_span(docgraph, node_id, debug=False): if debug is True and is_directed_acyclic_graph(docgraph) is False: warnings.warn( ("Can't reliably extract span '{0}' from cyclical graph'{1}'." "Maximum recursion depth may be exceeded.").format(node_id, docgraph)) span = [] if docgraph.ns+':token' in docgraph.node[node_id]: span.append(node_id) for src_id, target_id, edge_attribs in docgraph.out_edges_iter(node_id, data=True): if src_id == target_id: continue if edge_attribs['edge_type'] != EdgeTypes.pointing_relation: span.extend(get_span(docgraph, target_id)) return sorted(span, key=natural_sort_key)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_terminals_and_nonterminals'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'sentence_graph'},{'id': '5', 'type': 'block', 'children': ['6', '12', '18', '52']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'terminals'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '11', 'type': 'argument_list', 'children': []},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'nonterminals'},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '17', 'type': 'argument_list', 'children': []},{'id': '18', 'type': 'for_statement', 'children': ['19', '20', '25']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'sentence_graph'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'nodes_iter'},{'id': '24', 'type': 'argument_list', 'children': []},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'if_statement', 'children': ['27', '35', '43']},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '34'], 'value': '>'},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'sentence_graph'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'out_degree'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '34', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'nonterminals'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '43', 'type': 'else_clause', 'children': ['44']},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'terminals'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '52', 'type': 'return_statement', 'children': ['53']},{'id': '53', 'type': 'expression_list', 'children': ['54', '64', '65']},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '56', 'type': 'argument_list', 'children': ['57', '61']},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'terminals'},{'id': '61', 'type': 'keyword_argument', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'natural_sort_key'},{'id': '64', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '67', 'type': 'argument_list', 'children': ['68', '72']},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'nonterminals'},{'id': '72', 'type': 'keyword_argument', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'natural_sort_key'}
def _get_terminals_and_nonterminals(sentence_graph): terminals = set() nonterminals = set() for node_id in sentence_graph.nodes_iter(): if sentence_graph.out_degree(node_id) > 0: nonterminals.add(node_id) else: terminals.add(node_id) return sorted(list(terminals), key=natural_sort_key), \ sorted(list(nonterminals), key=natural_sort_key)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'print_sorted_counter'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'counter'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'tab'},{'id': '7', 'type': 'integer', 'children': [], 'value': '1'},{'id': '8', 'type': 'block', 'children': ['9']},{'id': '9', 'type': 'for_statement', 'children': ['10', '13', '30']},{'id': '10', 'type': 'pattern_list', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '15', 'type': 'argument_list', 'children': ['16', '21', '27']},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'counter'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '20', 'type': 'argument_list', 'children': []},{'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'itemgetter'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'integer', 'children': [], 'value': '1'},{'id': '27', 'type': 'keyword_argument', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '29', 'type': 'True', 'children': []},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'print_statement', 'children': ['32']},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'string', 'children': [], 'value': '"{0}{1} - {2}"'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '36', 'type': 'argument_list', 'children': ['37', '40', '41']},{'id': '37', 'type': 'binary_operator', 'children': ['38', '39'], 'value': '*'},{'id': '38', 'type': 'string', 'children': [], 'value': "'\\t'"},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'tab'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'count'}
def print_sorted_counter(counter, tab=1): for key, count in sorted(counter.items(), key=itemgetter(1), reverse=True): print "{0}{1} - {2}".format('\t'*tab, key, count)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sorted_bfs_edges'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '20', '28', '36', '44', '68']},{'id': '9', 'type': 'if_statement', 'children': ['10', '13']},{'id': '10', 'type': 'comparison_operator', 'children': ['11', '12'], 'value': 'is'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'source'},{'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': 'source'},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'xpos'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'horizontal_positions'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'visited'},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'list', 'children': ['35'], 'value': '[source]'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'source_children'},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'get_child_nodes'},{'id': '41', 'type': 'argument_list', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'queue'},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'deque'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'list', 'children': ['51'], 'value': '[(source, iter(sorted(source_children,\n key=lambda x: xpos[x])))]'},{'id': '51', 'type': 'tuple', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '58', 'type': 'argument_list', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'source_children'},{'id': '60', 'type': 'keyword_argument', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '62', 'type': 'lambda', 'children': ['63', '65']},{'id': '63', 'type': 'lambda_parameters', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '65', 'type': 'subscript', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'xpos'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '68', 'type': 'while_statement', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'queue'},{'id': '70', 'type': 'block', 'children': ['71', '79']},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '76']},{'id': '73', 'type': 'pattern_list', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '76', 'type': 'subscript', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'queue'},{'id': '78', 'type': 'integer', 'children': [], 'value': '0'},{'id': '79', 'type': 'try_statement', 'children': ['80', '136']},{'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': 'child'},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'next'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '88', 'type': 'if_statement', 'children': ['89', '92']},{'id': '89', 'type': 'comparison_operator', 'children': ['90', '91'], 'value': 'not'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'visited'},{'id': '92', 'type': 'block', 'children': ['93', '98', '105', '113']},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'yield', 'children': ['95']},{'id': '95', 'type': 'expression_list', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'child'},{'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': 'visited'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'grandchildren'},{'id': '108', 'type': 'call', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'get_child_nodes'},{'id': '110', 'type': 'argument_list', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'call', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'queue'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'tuple', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '121', 'type': 'call', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'call', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '126', 'type': 'argument_list', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'grandchildren'},{'id': '128', 'type': 'keyword_argument', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '130', 'type': 'lambda', 'children': ['131', '133']},{'id': '131', 'type': 'lambda_parameters', 'children': ['132']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '133', 'type': 'subscript', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'xpos'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '136', 'type': 'except_clause', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'StopIteration'},{'id': '138', 'type': 'block', 'children': ['139']},{'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': 'queue'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'popleft'},{'id': '144', 'type': 'argument_list', 'children': []}
def sorted_bfs_edges(G, source=None): if source is None: source = G.root xpos = horizontal_positions(G, source) visited = set([source]) source_children = get_child_nodes(G, source) queue = deque([(source, iter(sorted(source_children, key=lambda x: xpos[x])))]) while queue: parent, children = queue[0] try: child = next(children) if child not in visited: yield parent, child visited.add(child) grandchildren = get_child_nodes(G, child) queue.append((child, iter(sorted(grandchildren, key=lambda x: xpos[x])))) except StopIteration: queue.popleft()