sequence
stringlengths 1.27k
35.1k
| code
stringlengths 75
8.58k
|
---|---|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'movefastq'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '13']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'call', 'children': ['8', '11']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'string', 'children': [], 'value': "'Moving FASTQ files'"}; {'id': '13', 'type': 'for_statement', 'children': ['14', '15', '22']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '15', 'type': 'attribute', 'children': ['16', '21']}; {'id': '16', 'type': 'attribute', 'children': ['17', '20']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'metadata'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'runmetadata'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'samples'}; {'id': '22', 'type': 'block', 'children': ['23', '39', '168', '334']}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'outputdir'}; {'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': 'os'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'join'}; {'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': 'path'}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'fastqfiles'}; {'id': '42', 'type': 'conditional_expression', 'children': ['43', '67', '68', '92', '93'], 'value': 'if'}; {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'glob'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}; {'id': '49', 'type': 'call', 'children': ['50', '55']}; {'id': '50', 'type': 'attribute', 'children': ['51', '54']}; {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '55', 'type': 'argument_list', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}; {'id': '61', 'type': 'string', 'children': [], 'value': "'{}_*.fastq*'"}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '67', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '68', 'type': 'call', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}; {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'glob'}; {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'call', 'children': ['75', '80']}; {'id': '75', 'type': 'attribute', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '80', 'type': 'argument_list', 'children': ['81', '84']}; {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '84', 'type': 'call', 'children': ['85', '88']}; {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'string', 'children': [], 'value': "'{}_*.fastq*'"}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}; {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '92', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '93', 'type': 'conditional_expression', 'children': ['94', '118', '119', '143', '144'], 'value': 'if'}; {'id': '94', 'type': 'call', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}; {'id': '97', 'type': 'call', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'glob'}; {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'call', 'children': ['101', '106']}; {'id': '101', 'type': 'attribute', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '106', 'type': 'argument_list', 'children': ['107', '110']}; {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '110', 'type': 'call', 'children': ['111', '114']}; {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'string', 'children': [], 'value': "'{}.fastq*'"}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '114', 'type': 'argument_list', 'children': ['115']}; {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '118', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '119', 'type': 'call', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '121', 'type': 'argument_list', 'children': ['122']}; {'id': '122', 'type': 'call', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'glob'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}; {'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': 'os'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '131', 'type': 'argument_list', 'children': ['132', '135']}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '135', 'type': 'call', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}; {'id': '137', 'type': 'string', 'children': [], 'value': "'{}.fastq*'"}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '143', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '144', 'type': 'call', 'children': ['145', '146']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '146', 'type': 'argument_list', 'children': ['147']}; {'id': '147', 'type': 'call', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'glob'}; {'id': '149', 'type': 'argument_list', 'children': ['150']}; {'id': '150', 'type': 'call', 'children': ['151', '156']}; {'id': '151', 'type': 'attribute', 'children': ['152', '155']}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '156', 'type': 'argument_list', 'children': ['157', '160']}; {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '160', 'type': 'call', 'children': ['161', '164']}; {'id': '161', 'type': 'attribute', 'children': ['162', '163']}; {'id': '162', 'type': 'string', 'children': [], 'value': "'{}*.fastq*'"}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}; {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '168', 'type': 'if_statement', 'children': ['169', '170', '279']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'fastqfiles'}; {'id': '170', 'type': 'block', 'children': ['171', '176', '230']}; {'id': '171', 'type': 'expression_statement', 'children': ['172']}; {'id': '172', 'type': 'call', 'children': ['173', '174']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'make_path'}; {'id': '174', 'type': 'argument_list', 'children': ['175']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'outputdir'}; {'id': '176', 'type': 'try_statement', 'children': ['177', '226']}; {'id': '177', 'type': 'block', 'children': ['178']}; {'id': '178', 'type': 'expression_statement', 'children': ['179']}; {'id': '179', 'type': 'call', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '181', 'type': 'argument_list', 'children': ['182']}; {'id': '182', 'type': 'call', 'children': ['183', '184']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'map'}; {'id': '184', 'type': 'argument_list', 'children': ['185', '225']}; {'id': '185', 'type': 'lambda', 'children': ['186', '188']}; {'id': '186', 'type': 'lambda_parameters', 'children': ['187']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '188', 'type': 'call', 'children': ['189', '192']}; {'id': '189', 'type': 'attribute', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'symlink'}; {'id': '192', 'type': 'argument_list', 'children': ['193', '209']}; {'id': '193', 'type': 'call', 'children': ['194', '199']}; {'id': '194', 'type': 'attribute', 'children': ['195', '198']}; {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '199', 'type': 'argument_list', 'children': ['200', '201']}; {'id': '200', 'type': 'string', 'children': [], 'value': "'..'"}; {'id': '201', 'type': 'call', 'children': ['202', '207']}; {'id': '202', 'type': 'attribute', 'children': ['203', '206']}; {'id': '203', 'type': 'attribute', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'basename'}; {'id': '207', 'type': 'argument_list', 'children': ['208']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '209', 'type': 'call', 'children': ['210', '215']}; {'id': '210', 'type': 'attribute', 'children': ['211', '214']}; {'id': '211', 'type': 'attribute', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '215', 'type': 'argument_list', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'outputdir'}; {'id': '217', 'type': 'call', 'children': ['218', '223']}; {'id': '218', 'type': 'attribute', 'children': ['219', '222']}; {'id': '219', 'type': 'attribute', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'basename'}; {'id': '223', 'type': 'argument_list', 'children': ['224']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'fastqfiles'}; {'id': '226', 'type': 'except_clause', 'children': ['227', '228']}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'OSError'}; {'id': '228', 'type': 'block', 'children': ['229']}; {'id': '229', 'type': 'pass_statement', 'children': []}; {'id': '230', 'type': 'expression_statement', 'children': ['231']}; {'id': '231', 'type': 'assignment', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'fastqfiles'}; {'id': '233', 'type': 'list_comprehension', 'children': ['234', '235', '259']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'fastq'}; {'id': '235', 'type': 'for_in_clause', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'fastq'}; {'id': '237', 'type': 'call', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '239', 'type': 'argument_list', 'children': ['240']}; {'id': '240', 'type': 'call', 'children': ['241', '242']}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'glob'}; {'id': '242', 'type': 'argument_list', 'children': ['243']}; {'id': '243', 'type': 'call', 'children': ['244', '249']}; {'id': '244', 'type': 'attribute', 'children': ['245', '248']}; {'id': '245', 'type': 'attribute', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '249', 'type': 'argument_list', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'outputdir'}; {'id': '251', 'type': 'call', 'children': ['252', '255']}; {'id': '252', 'type': 'attribute', 'children': ['253', '254']}; {'id': '253', 'type': 'string', 'children': [], 'value': "'{}*.fastq*'"}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '255', 'type': 'argument_list', 'children': ['256']}; {'id': '256', 'type': 'attribute', 'children': ['257', '258']}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '259', 'type': 'if_clause', 'children': ['260']}; {'id': '260', 'type': 'boolean_operator', 'children': ['261', '276'], 'value': 'and'}; {'id': '261', 'type': 'boolean_operator', 'children': ['262', '273'], 'value': 'and'}; {'id': '262', 'type': 'boolean_operator', 'children': ['263', '270'], 'value': 'and'}; {'id': '263', 'type': 'boolean_operator', 'children': ['264', '267'], 'value': 'and'}; {'id': '264', 'type': 'comparison_operator', 'children': ['265', '266'], 'value': 'not'}; {'id': '265', 'type': 'string', 'children': [], 'value': "'trimmed'"}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'fastq'}; {'id': '267', 'type': 'comparison_operator', 'children': ['268', '269'], 'value': 'not'}; {'id': '268', 'type': 'string', 'children': [], 'value': "'normalised'"}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'fastq'}; {'id': '270', 'type': 'comparison_operator', 'children': ['271', '272'], 'value': 'not'}; {'id': '271', 'type': 'string', 'children': [], 'value': "'corrected'"}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'fastq'}; {'id': '273', 'type': 'comparison_operator', 'children': ['274', '275'], 'value': 'not'}; {'id': '274', 'type': 'string', 'children': [], 'value': "'paired'"}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'fastq'}; {'id': '276', 'type': 'comparison_operator', 'children': ['277', '278'], 'value': 'not'}; {'id': '277', 'type': 'string', 'children': [], 'value': "'unpaired'"}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'fastq'}; {'id': '279', 'type': 'else_clause', 'children': ['280']}; {'id': '280', 'type': 'block', 'children': ['281']}; {'id': '281', 'type': 'if_statement', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'outputdir'}; {'id': '283', 'type': 'block', 'children': ['284']}; {'id': '284', 'type': 'expression_statement', 'children': ['285']}; {'id': '285', 'type': 'assignment', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'fastqfiles'}; {'id': '287', 'type': 'list_comprehension', 'children': ['288', '289', '314']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'fastq'}; {'id': '289', 'type': 'for_in_clause', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'fastq'}; {'id': '291', 'type': 'call', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '293', 'type': 'argument_list', 'children': ['294']}; {'id': '294', 'type': 'call', 'children': ['295', '296']}; {'id': '295', 'type': 'identifier', 'children': [], 'value': 'glob'}; {'id': '296', 'type': 'argument_list', 'children': ['297']}; {'id': '297', 'type': 'call', 'children': ['298', '303']}; {'id': '298', 'type': 'attribute', 'children': ['299', '302']}; {'id': '299', 'type': 'attribute', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '301', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '303', 'type': 'argument_list', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'outputdir'}; {'id': '305', 'type': 'call', 'children': ['306', '309']}; {'id': '306', 'type': 'attribute', 'children': ['307', '308']}; {'id': '307', 'type': 'string', 'children': [], 'value': "'{}*.fastq*'"}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '309', 'type': 'argument_list', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'outputdir'}; {'id': '311', 'type': 'attribute', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '313', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '314', 'type': 'if_clause', 'children': ['315']}; {'id': '315', 'type': 'boolean_operator', 'children': ['316', '331'], 'value': 'and'}; {'id': '316', 'type': 'boolean_operator', 'children': ['317', '328'], 'value': 'and'}; {'id': '317', 'type': 'boolean_operator', 'children': ['318', '325'], 'value': 'and'}; {'id': '318', 'type': 'boolean_operator', 'children': ['319', '322'], 'value': 'and'}; {'id': '319', 'type': 'comparison_operator', 'children': ['320', '321'], 'value': 'not'}; {'id': '320', 'type': 'string', 'children': [], 'value': "'trimmed'"}; {'id': '321', 'type': 'identifier', 'children': [], 'value': 'fastq'}; {'id': '322', 'type': 'comparison_operator', 'children': ['323', '324'], 'value': 'not'}; {'id': '323', 'type': 'string', 'children': [], 'value': "'normalised'"}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'fastq'}; {'id': '325', 'type': 'comparison_operator', 'children': ['326', '327'], 'value': 'not'}; {'id': '326', 'type': 'string', 'children': [], 'value': "'corrected'"}; {'id': '327', 'type': 'identifier', 'children': [], 'value': 'fastq'}; {'id': '328', 'type': 'comparison_operator', 'children': ['329', '330'], 'value': 'not'}; {'id': '329', 'type': 'string', 'children': [], 'value': "'paired'"}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'fastq'}; {'id': '331', 'type': 'comparison_operator', 'children': ['332', '333'], 'value': 'not'}; {'id': '332', 'type': 'string', 'children': [], 'value': "'unpaired'"}; {'id': '333', 'type': 'identifier', 'children': [], 'value': 'fastq'}; {'id': '334', 'type': 'expression_statement', 'children': ['335']}; {'id': '335', 'type': 'assignment', 'children': ['336', '341']}; {'id': '336', 'type': 'attribute', 'children': ['337', '340']}; {'id': '337', 'type': 'attribute', 'children': ['338', '339']}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '339', 'type': 'identifier', 'children': [], 'value': 'general'}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'fastqfiles'}; {'id': '341', 'type': 'identifier', 'children': [], 'value': 'fastqfiles'}
|
def movefastq(self):
logging.info('Moving FASTQ files')
for sample in self.metadata.runmetadata.samples:
outputdir = os.path.join(self.path, sample.name)
fastqfiles = sorted(glob(os.path.join(self.path, '{}_*.fastq*'.format(sample.name)))) \
if sorted(glob(os.path.join(self.path, '{}_*.fastq*'.format(sample.name)))) \
else sorted(glob(os.path.join(self.path, '{}.fastq*'.format(sample.name)))) \
if sorted(glob(os.path.join(self.path, '{}.fastq*'.format(sample.name)))) \
else sorted(glob(os.path.join(self.path, '{}*.fastq*'.format(sample.name))))
if fastqfiles:
make_path(outputdir)
try:
list(map(lambda x: os.symlink(os.path.join('..', os.path.basename(x)),
os.path.join(outputdir, os.path.basename(x))), fastqfiles))
except OSError:
pass
fastqfiles = [fastq for fastq in sorted(glob(os.path.join(outputdir, '{}*.fastq*'.format(sample.name))))
if 'trimmed' not in fastq and 'normalised' not in fastq and 'corrected' not in fastq
and 'paired' not in fastq and 'unpaired' not in fastq]
else:
if outputdir:
fastqfiles = [fastq for fastq in sorted(glob(os.path.join(
outputdir, '{}*.fastq*'.format(outputdir, sample.name))))
if 'trimmed' not in fastq and 'normalised' not in fastq and 'corrected' not in fastq
and 'paired' not in fastq and 'unpaired' not in fastq]
sample.general.fastqfiles = fastqfiles
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_raw_entity'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '7', 'type': 'type', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '9', 'type': 'type', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '11', 'type': 'block', 'children': ['12', '21', '35', '43', '51', '107', '119', '139', '156', '173', '190', '198', '209', '227', '249', '260', '266', '284', '345', '356']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'needed_in_entity'}; {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'list', 'children': ['19', '20'], 'value': "[\n 'label',\n 'type',\n ]"}; {'id': '19', 'type': 'string', 'children': [], 'value': "'label'"}; {'id': '20', 'type': 'string', 'children': [], 'value': "'type'"}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'options_in_entity'}; {'id': '24', 'type': 'call', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}; {'id': '27', 'type': 'list', 'children': ['28', '29', '30', '31', '32', '33', '34'], 'value': "[\n 'label',\n 'type',\n 'definition',\n 'comment',\n 'superclass',\n 'synonyms',\n 'existing_ids'\n ]"}; {'id': '28', 'type': 'string', 'children': [], 'value': "'label'"}; {'id': '29', 'type': 'string', 'children': [], 'value': "'type'"}; {'id': '30', 'type': 'string', 'children': [], 'value': "'definition'"}; {'id': '31', 'type': 'string', 'children': [], 'value': "'comment'"}; {'id': '32', 'type': 'string', 'children': [], 'value': "'superclass'"}; {'id': '33', 'type': 'string', 'children': [], 'value': "'synonyms'"}; {'id': '34', 'type': 'string', 'children': [], 'value': "'existing_ids'"}; {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'prime_entity_url'}; {'id': '38', 'type': 'binary_operator', 'children': ['39', '42'], 'value': '+'}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'base_url'}; {'id': '42', 'type': 'string', 'children': [], 'value': "'ilx/add'"}; {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'add_entity_url'}; {'id': '46', 'type': 'binary_operator', 'children': ['47', '50'], 'value': '+'}; {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'base_url'}; {'id': '50', 'type': 'string', 'children': [], 'value': "'term/add'"}; {'id': '51', 'type': 'if_statement', 'children': ['52', '61', '79']}; {'id': '52', 'type': 'comparison_operator', 'children': ['53', '60'], 'value': '!='}; {'id': '53', 'type': '()', 'children': ['54']}; {'id': '54', 'type': 'binary_operator', 'children': ['55', '59'], 'value': '&'}; {'id': '55', 'type': 'call', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'needed_in_entity'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'needed_in_entity'}; {'id': '61', 'type': 'block', 'children': ['62']}; {'id': '62', 'type': 'raise_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': 'MissingKeyError'}; {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'binary_operator', 'children': ['69', '70'], 'value': '+'}; {'id': '69', 'type': 'string', 'children': [], 'value': "'You need key(s): '"}; {'id': '70', 'type': 'call', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}; {'id': '73', 'type': 'binary_operator', 'children': ['74', '75'], 'value': '-'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'needed_in_entity'}; {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '79', 'type': 'elif_clause', 'children': ['80', '89']}; {'id': '80', 'type': 'comparison_operator', 'children': ['81', '88'], 'value': '!='}; {'id': '81', 'type': '()', 'children': ['82']}; {'id': '82', 'type': 'binary_operator', 'children': ['83', '87'], 'value': '|'}; {'id': '83', 'type': 'call', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'options_in_entity'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'options_in_entity'}; {'id': '89', 'type': 'block', 'children': ['90']}; {'id': '90', 'type': 'raise_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': 'IncorrectKeyError'}; {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'binary_operator', 'children': ['97', '98'], 'value': '+'}; {'id': '97', 'type': 'string', 'children': [], 'value': "'Unexpected key(s): '"}; {'id': '98', 'type': 'call', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}; {'id': '101', 'type': 'binary_operator', 'children': ['102', '106'], 'value': '-'}; {'id': '102', 'type': 'call', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'options_in_entity'}; {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'assignment', 'children': ['109', '112']}; {'id': '109', 'type': 'subscript', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '111', 'type': 'string', 'children': [], 'value': "'type'"}; {'id': '112', 'type': 'call', 'children': ['113', '118']}; {'id': '113', 'type': 'attribute', 'children': ['114', '117']}; {'id': '114', 'type': 'subscript', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '116', 'type': 'string', 'children': [], 'value': "'type'"}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '118', 'type': 'argument_list', 'children': []}; {'id': '119', 'type': 'if_statement', 'children': ['120', '131']}; {'id': '120', 'type': 'comparison_operator', 'children': ['121', '124'], 'value': 'not'}; {'id': '121', 'type': 'subscript', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '123', 'type': 'string', 'children': [], 'value': "'type'"}; {'id': '124', 'type': 'list', 'children': ['125', '126', '127', '128', '129', '130'], 'value': "['term', 'relationship', 'annotation', 'cde', 'fde', 'pde']"}; {'id': '125', 'type': 'string', 'children': [], 'value': "'term'"}; {'id': '126', 'type': 'string', 'children': [], 'value': "'relationship'"}; {'id': '127', 'type': 'string', 'children': [], 'value': "'annotation'"}; {'id': '128', 'type': 'string', 'children': [], 'value': "'cde'"}; {'id': '129', 'type': 'string', 'children': [], 'value': "'fde'"}; {'id': '130', 'type': 'string', 'children': [], 'value': "'pde'"}; {'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': 'TypeError'}; {'id': '135', 'type': 'argument_list', 'children': ['136']}; {'id': '136', 'type': 'binary_operator', 'children': ['137', '138'], 'value': '+'}; {'id': '137', 'type': 'string', 'children': [], 'value': "'Entity should be one of the following: '"}; {'id': '138', 'type': 'string', 'children': [], 'value': "'term, relationship, annotation, cde, fde, pde'"}; {'id': '139', 'type': 'if_statement', 'children': ['140', '146']}; {'id': '140', 'type': 'call', 'children': ['141', '144']}; {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}; {'id': '145', 'type': 'string', 'children': [], 'value': "'superclass'"}; {'id': '146', 'type': 'block', 'children': ['147']}; {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'assignment', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '150', 'type': 'call', 'children': ['151', '154']}; {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'process_superclass'}; {'id': '154', 'type': 'argument_list', 'children': ['155']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '156', 'type': 'if_statement', 'children': ['157', '163']}; {'id': '157', 'type': 'call', 'children': ['158', '161']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '161', 'type': 'argument_list', 'children': ['162']}; {'id': '162', 'type': 'string', 'children': [], 'value': "'synonyms'"}; {'id': '163', 'type': 'block', 'children': ['164']}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}; {'id': '165', 'type': 'assignment', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '167', 'type': 'call', 'children': ['168', '171']}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'process_synonyms'}; {'id': '171', 'type': 'argument_list', 'children': ['172']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '173', 'type': 'if_statement', 'children': ['174', '180']}; {'id': '174', 'type': 'call', 'children': ['175', '178']}; {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '178', 'type': 'argument_list', 'children': ['179']}; {'id': '179', 'type': 'string', 'children': [], 'value': "'existing_ids'"}; {'id': '180', 'type': 'block', 'children': ['181']}; {'id': '181', 'type': 'expression_statement', 'children': ['182']}; {'id': '182', 'type': 'assignment', 'children': ['183', '184']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '184', 'type': 'call', 'children': ['185', '188']}; {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'process_existing_ids'}; {'id': '188', 'type': 'argument_list', 'children': ['189']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '190', 'type': 'expression_statement', 'children': ['191']}; {'id': '191', 'type': 'assignment', 'children': ['192', '195']}; {'id': '192', 'type': 'subscript', 'children': ['193', '194']}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '194', 'type': 'string', 'children': [], 'value': "'uid'"}; {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'user_id'}; {'id': '198', 'type': 'expression_statement', 'children': ['199']}; {'id': '199', 'type': 'assignment', 'children': ['200', '203']}; {'id': '200', 'type': 'subscript', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '202', 'type': 'string', 'children': [], 'value': "'term'"}; {'id': '203', 'type': 'call', 'children': ['204', '207']}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '207', 'type': 'argument_list', 'children': ['208']}; {'id': '208', 'type': 'string', 'children': [], 'value': "'label'"}; {'id': '209', 'type': 'expression_statement', 'children': ['210']}; {'id': '210', 'type': 'assignment', 'children': ['211', '212']}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'ilx_data'}; {'id': '212', 'type': 'call', 'children': ['213', '216']}; {'id': '213', 'type': 'attribute', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'post'}; {'id': '216', 'type': 'argument_list', 'children': ['217', '220']}; {'id': '217', 'type': 'keyword_argument', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'prime_entity_url'}; {'id': '220', 'type': 'keyword_argument', 'children': ['221', '222']}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '222', 'type': 'call', 'children': ['223', '226']}; {'id': '223', 'type': 'attribute', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '226', 'type': 'argument_list', 'children': []}; {'id': '227', 'type': 'if_statement', 'children': ['228', '234', '241']}; {'id': '228', 'type': 'call', 'children': ['229', '232']}; {'id': '229', 'type': 'attribute', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'ilx_data'}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '232', 'type': 'argument_list', 'children': ['233']}; {'id': '233', 'type': 'string', 'children': [], 'value': "'ilx'"}; {'id': '234', 'type': 'block', 'children': ['235']}; {'id': '235', 'type': 'expression_statement', 'children': ['236']}; {'id': '236', 'type': 'assignment', 'children': ['237', '238']}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'ilx_id'}; {'id': '238', 'type': 'subscript', 'children': ['239', '240']}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'ilx_data'}; {'id': '240', 'type': 'string', 'children': [], 'value': "'ilx'"}; {'id': '241', 'type': 'else_clause', 'children': ['242']}; {'id': '242', 'type': 'block', 'children': ['243']}; {'id': '243', 'type': 'expression_statement', 'children': ['244']}; {'id': '244', 'type': 'assignment', 'children': ['245', '246']}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'ilx_id'}; {'id': '246', 'type': 'subscript', 'children': ['247', '248']}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'ilx_data'}; {'id': '248', 'type': 'string', 'children': [], 'value': "'fragment'"}; {'id': '249', 'type': 'expression_statement', 'children': ['250']}; {'id': '250', 'type': 'assignment', 'children': ['251', '254']}; {'id': '251', 'type': 'subscript', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '253', 'type': 'string', 'children': [], 'value': "'label'"}; {'id': '254', 'type': 'call', 'children': ['255', '258']}; {'id': '255', 'type': 'attribute', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '258', 'type': 'argument_list', 'children': ['259']}; {'id': '259', 'type': 'string', 'children': [], 'value': "'term'"}; {'id': '260', 'type': 'expression_statement', 'children': ['261']}; {'id': '261', 'type': 'assignment', 'children': ['262', '265']}; {'id': '262', 'type': 'subscript', 'children': ['263', '264']}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '264', 'type': 'string', 'children': [], 'value': "'ilx'"}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'ilx_id'}; {'id': '266', 'type': 'expression_statement', 'children': ['267']}; {'id': '267', 'type': 'assignment', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '269', 'type': 'call', 'children': ['270', '273']}; {'id': '270', 'type': 'attribute', 'children': ['271', '272']}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'post'}; {'id': '273', 'type': 'argument_list', 'children': ['274', '277']}; {'id': '274', 'type': 'keyword_argument', 'children': ['275', '276']}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'add_entity_url'}; {'id': '277', 'type': 'keyword_argument', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '279', 'type': 'call', 'children': ['280', '283']}; {'id': '280', 'type': 'attribute', 'children': ['281', '282']}; {'id': '281', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '283', 'type': 'argument_list', 'children': []}; {'id': '284', 'type': 'if_statement', 'children': ['285', '291']}; {'id': '285', 'type': 'call', 'children': ['286', '289']}; {'id': '286', 'type': 'attribute', 'children': ['287', '288']}; {'id': '287', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '289', 'type': 'argument_list', 'children': ['290']}; {'id': '290', 'type': 'string', 'children': [], 'value': "'errormsg'"}; {'id': '291', 'type': 'block', 'children': ['292', '338']}; {'id': '292', 'type': 'if_statement', 'children': ['293', '302']}; {'id': '293', 'type': 'comparison_operator', 'children': ['294', '295'], 'value': 'in'}; {'id': '294', 'type': 'string', 'children': [], 'value': "'already exists'"}; {'id': '295', 'type': 'call', 'children': ['296', '301']}; {'id': '296', 'type': 'attribute', 'children': ['297', '300']}; {'id': '297', 'type': 'subscript', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '299', 'type': 'string', 'children': [], 'value': "'errormsg'"}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '301', 'type': 'argument_list', 'children': []}; {'id': '302', 'type': 'block', 'children': ['303', '314', '331']}; {'id': '303', 'type': 'expression_statement', 'children': ['304']}; {'id': '304', 'type': 'assignment', 'children': ['305', '306']}; {'id': '305', 'type': 'identifier', 'children': [], 'value': 'prexisting_data'}; {'id': '306', 'type': 'call', 'children': ['307', '310']}; {'id': '307', 'type': 'attribute', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '309', 'type': 'identifier', 'children': [], 'value': 'check_scicrunch_for_label'}; {'id': '310', 'type': 'argument_list', 'children': ['311']}; {'id': '311', 'type': 'subscript', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '313', 'type': 'string', 'children': [], 'value': "'label'"}; {'id': '314', 'type': 'if_statement', 'children': ['315', '316']}; {'id': '315', 'type': 'identifier', 'children': [], 'value': 'prexisting_data'}; {'id': '316', 'type': 'block', 'children': ['317', '329']}; {'id': '317', 'type': 'expression_statement', 'children': ['318']}; {'id': '318', 'type': 'call', 'children': ['319', '320']}; {'id': '319', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '320', 'type': 'argument_list', 'children': ['321', '322', '325', '326']}; {'id': '321', 'type': 'string', 'children': [], 'value': "'You already added entity'"}; {'id': '322', 'type': 'subscript', 'children': ['323', '324']}; {'id': '323', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '324', 'type': 'string', 'children': [], 'value': "'label'"}; {'id': '325', 'type': 'string', 'children': [], 'value': "'with ILX ID:'"}; {'id': '326', 'type': 'subscript', 'children': ['327', '328']}; {'id': '327', 'type': 'identifier', 'children': [], 'value': 'prexisting_data'}; {'id': '328', 'type': 'string', 'children': [], 'value': "'ilx'"}; {'id': '329', 'type': 'return_statement', 'children': ['330']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'prexisting_data'}; {'id': '331', 'type': 'expression_statement', 'children': ['332']}; {'id': '332', 'type': 'call', 'children': ['333', '336']}; {'id': '333', 'type': 'attribute', 'children': ['334', '335']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '335', 'type': 'identifier', 'children': [], 'value': 'Error'}; {'id': '336', 'type': 'argument_list', 'children': ['337']}; {'id': '337', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '338', 'type': 'expression_statement', 'children': ['339']}; {'id': '339', 'type': 'call', 'children': ['340', '343']}; {'id': '340', 'type': 'attribute', 'children': ['341', '342']}; {'id': '341', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'Error'}; {'id': '343', 'type': 'argument_list', 'children': ['344']}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '345', 'type': 'expression_statement', 'children': ['346']}; {'id': '346', 'type': 'assignment', 'children': ['347', '348']}; {'id': '347', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '348', 'type': 'call', 'children': ['349', '352']}; {'id': '349', 'type': 'attribute', 'children': ['350', '351']}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '351', 'type': 'identifier', 'children': [], 'value': 'get_entity'}; {'id': '352', 'type': 'argument_list', 'children': ['353']}; {'id': '353', 'type': 'subscript', 'children': ['354', '355']}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '355', 'type': 'string', 'children': [], 'value': "'ilx'"}; {'id': '356', 'type': 'return_statement', 'children': ['357']}; {'id': '357', 'type': 'identifier', 'children': [], 'value': 'output'}
|
def add_raw_entity(self, entity: dict) -> dict:
needed_in_entity = set([
'label',
'type',
])
options_in_entity = set([
'label',
'type',
'definition',
'comment',
'superclass',
'synonyms',
'existing_ids'
])
prime_entity_url = self.base_url + 'ilx/add'
add_entity_url = self.base_url + 'term/add'
if (set(entity) & needed_in_entity) != needed_in_entity:
raise self.MissingKeyError(
'You need key(s): '+ str(needed_in_entity - set(entity)))
elif (set(entity) | options_in_entity) != options_in_entity:
raise self.IncorrectKeyError(
'Unexpected key(s): ' + str(set(entity) - options_in_entity))
entity['type'] = entity['type'].lower()
if entity['type'] not in ['term', 'relationship', 'annotation', 'cde', 'fde', 'pde']:
raise TypeError(
'Entity should be one of the following: ' +
'term, relationship, annotation, cde, fde, pde')
if entity.get('superclass'):
entity = self.process_superclass(entity)
if entity.get('synonyms'):
entity = self.process_synonyms(entity)
if entity.get('existing_ids'):
entity = self.process_existing_ids(entity)
entity['uid'] = self.user_id
entity['term'] = entity.pop('label')
ilx_data = self.post(
url = prime_entity_url,
data = entity.copy(),
)
if ilx_data.get('ilx'):
ilx_id = ilx_data['ilx']
else:
ilx_id = ilx_data['fragment']
entity['label'] = entity.pop('term')
entity['ilx'] = ilx_id
output = self.post(
url = add_entity_url,
data = entity.copy(),
)
if output.get('errormsg'):
if 'already exists' in output['errormsg'].lower():
prexisting_data = self.check_scicrunch_for_label(entity['label'])
if prexisting_data:
print(
'You already added entity', entity['label'],
'with ILX ID:', prexisting_data['ilx'])
return prexisting_data
self.Error(output)
self.Error(output)
output = self.get_entity(output['ilx'])
return output
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17', '19']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'delete_annotation'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '9', '13']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'term_ilx_id'}; {'id': '7', 'type': 'type', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '9', 'type': 'typed_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'annotation_type_ilx_id'}; {'id': '11', 'type': 'type', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '13', 'type': 'typed_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'annotation_value'}; {'id': '15', 'type': 'type', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '17', 'type': 'type', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '19', 'type': 'block', 'children': ['20', '29', '44', '53', '68', '79', '83', '137', '148', '163', '182', '196']}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}; {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'term_data'}; {'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': 'get_entity'}; {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'term_ilx_id'}; {'id': '29', 'type': 'if_statement', 'children': ['30', '34']}; {'id': '30', 'type': 'not_operator', 'children': ['31']}; {'id': '31', 'type': 'subscript', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'term_data'}; {'id': '33', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '34', 'type': 'block', 'children': ['35']}; {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'exit'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}; {'id': '39', 'type': 'binary_operator', 'children': ['40', '43'], 'value': '+'}; {'id': '40', 'type': 'binary_operator', 'children': ['41', '42'], 'value': '+'}; {'id': '41', 'type': 'string', 'children': [], 'value': "'term_ilx_id: '"}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'term_ilx_id'}; {'id': '43', 'type': 'string', 'children': [], 'value': "' does not exist'"}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}; {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'anno_data'}; {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'get_entity'}; {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'annotation_type_ilx_id'}; {'id': '53', 'type': 'if_statement', 'children': ['54', '58']}; {'id': '54', 'type': 'not_operator', 'children': ['55']}; {'id': '55', 'type': 'subscript', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'anno_data'}; {'id': '57', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '58', 'type': 'block', 'children': ['59']}; {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'call', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'exit'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}; {'id': '63', 'type': 'binary_operator', 'children': ['64', '67'], 'value': '+'}; {'id': '64', 'type': 'binary_operator', 'children': ['65', '66'], 'value': '+'}; {'id': '65', 'type': 'string', 'children': [], 'value': "'annotation_type_ilx_id: '"}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'annotation_type_ilx_id'}; {'id': '67', 'type': 'string', 'children': [], 'value': "' does not exist'"}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}; {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'entity_annotations'}; {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'get_annotation_via_tid'}; {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'subscript', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'term_data'}; {'id': '78', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'annotation_id'}; {'id': '82', 'type': 'string', 'children': [], 'value': "''"}; {'id': '83', 'type': 'for_statement', 'children': ['84', '85', '86']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'annotation'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'entity_annotations'}; {'id': '86', 'type': 'block', 'children': ['87']}; {'id': '87', 'type': 'if_statement', 'children': ['88', '101']}; {'id': '88', 'type': 'comparison_operator', 'children': ['89', '95'], 'value': '=='}; {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'subscript', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'annotation'}; {'id': '94', 'type': 'string', 'children': [], 'value': "'tid'"}; {'id': '95', 'type': 'call', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'subscript', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'term_data'}; {'id': '100', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '101', 'type': 'block', 'children': ['102']}; {'id': '102', 'type': 'if_statement', 'children': ['103', '116']}; {'id': '103', 'type': 'comparison_operator', 'children': ['104', '110'], 'value': '=='}; {'id': '104', 'type': 'call', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}; {'id': '107', 'type': 'subscript', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'annotation'}; {'id': '109', 'type': 'string', 'children': [], 'value': "'annotation_tid'"}; {'id': '110', 'type': 'call', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}; {'id': '113', 'type': 'subscript', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'anno_data'}; {'id': '115', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '116', 'type': 'block', 'children': ['117']}; {'id': '117', 'type': 'if_statement', 'children': ['118', '129']}; {'id': '118', 'type': 'comparison_operator', 'children': ['119', '125'], 'value': '=='}; {'id': '119', 'type': 'call', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '121', 'type': 'argument_list', 'children': ['122']}; {'id': '122', 'type': 'subscript', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'annotation'}; {'id': '124', 'type': 'string', 'children': [], 'value': "'value'"}; {'id': '125', 'type': 'call', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'annotation_value'}; {'id': '129', 'type': 'block', 'children': ['130', '136']}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}; {'id': '131', 'type': 'assignment', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'annotation_id'}; {'id': '133', 'type': 'subscript', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'annotation'}; {'id': '135', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '136', 'type': 'break_statement', 'children': []}; {'id': '137', 'type': 'if_statement', 'children': ['138', '140']}; {'id': '138', 'type': 'not_operator', 'children': ['139']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'annotation_id'}; {'id': '140', 'type': 'block', 'children': ['141', '146']}; {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'call', 'children': ['143', '144']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}; {'id': '145', 'type': 'string', 'children': [], 'value': "'''WARNING: Annotation you wanted to delete does not exist '''"}; {'id': '146', 'type': 'return_statement', 'children': ['147']}; {'id': '147', 'type': 'None', 'children': []}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}; {'id': '149', 'type': 'assignment', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '151', 'type': 'binary_operator', 'children': ['152', '155'], 'value': '+'}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'base_url'}; {'id': '155', 'type': 'call', 'children': ['156', '159']}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}; {'id': '157', 'type': 'string', 'children': [], 'value': "'term/edit-annotation/{annotation_id}'"}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '159', 'type': 'argument_list', 'children': ['160']}; {'id': '160', 'type': 'keyword_argument', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'annotation_id'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'annotation_id'}; {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'assignment', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '166', 'type': 'dictionary', 'children': ['167', '170', '173', '176', '179']}; {'id': '167', 'type': 'pair', 'children': ['168', '169']}; {'id': '168', 'type': 'string', 'children': [], 'value': "'tid'"}; {'id': '169', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '170', 'type': 'pair', 'children': ['171', '172']}; {'id': '171', 'type': 'string', 'children': [], 'value': "'annotation_tid'"}; {'id': '172', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '173', 'type': 'pair', 'children': ['174', '175']}; {'id': '174', 'type': 'string', 'children': [], 'value': "'value'"}; {'id': '175', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '176', 'type': 'pair', 'children': ['177', '178']}; {'id': '177', 'type': 'string', 'children': [], 'value': "'term_version'"}; {'id': '178', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '179', 'type': 'pair', 'children': ['180', '181']}; {'id': '180', 'type': 'string', 'children': [], 'value': "'annotation_term_version'"}; {'id': '181', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}; {'id': '183', 'type': 'assignment', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '185', 'type': 'call', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'post'}; {'id': '189', 'type': 'argument_list', 'children': ['190', '193']}; {'id': '190', 'type': 'keyword_argument', 'children': ['191', '192']}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '193', 'type': 'keyword_argument', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '196', 'type': 'return_statement', 'children': ['197']}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'output'}
|
def delete_annotation(
self,
term_ilx_id: str,
annotation_type_ilx_id: str,
annotation_value: str) -> dict:
term_data = self.get_entity(term_ilx_id)
if not term_data['id']:
exit(
'term_ilx_id: ' + term_ilx_id + ' does not exist'
)
anno_data = self.get_entity(annotation_type_ilx_id)
if not anno_data['id']:
exit(
'annotation_type_ilx_id: ' + annotation_type_ilx_id +
' does not exist'
)
entity_annotations = self.get_annotation_via_tid(term_data['id'])
annotation_id = ''
for annotation in entity_annotations:
if str(annotation['tid']) == str(term_data['id']):
if str(annotation['annotation_tid']) == str(anno_data['id']):
if str(annotation['value']) == str(annotation_value):
annotation_id = annotation['id']
break
if not annotation_id:
print('''WARNING: Annotation you wanted to delete does not exist ''')
return None
url = self.base_url + 'term/edit-annotation/{annotation_id}'.format(
annotation_id = annotation_id
)
data = {
'tid': ' ',
'annotation_tid': ' ',
'value': ' ',
'term_version': ' ',
'annotation_term_version': ' ',
}
output = self.post(
url = url,
data = data,
)
return output
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'configfilepopulator'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '18', '30', '88', '124', '140', '148', '320']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '11']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'forwardlength'}; {'id': '11', 'type': 'attribute', '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': 'metadata'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'forwardlength'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'assignment', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'reverselength'}; {'id': '23', 'type': 'attribute', 'children': ['24', '29']}; {'id': '24', 'type': 'attribute', 'children': ['25', '28']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'metadata'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'reverselength'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'cycles'}; {'id': '33', 'type': 'list', 'children': ['34', '42', '56', '70'], 'value': '[[1, self.forwardlength, self.runid],\n [self.forwardlength + 1, self.forwardlength + 8, self.runid],\n [self.forwardlength + 9, self.forwardlength + 16, self.runid],\n [self.forwardlength + 17, self.forwardlength + 16 + self.reverselength, self.runid]]'}; {'id': '34', 'type': 'list', 'children': ['35', '36', '39'], 'value': '[1, self.forwardlength, self.runid]'}; {'id': '35', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'forwardlength'}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'runid'}; {'id': '42', 'type': 'list', 'children': ['43', '48', '53'], 'value': '[self.forwardlength + 1, self.forwardlength + 8, self.runid]'}; {'id': '43', 'type': 'binary_operator', 'children': ['44', '47'], 'value': '+'}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'forwardlength'}; {'id': '47', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '48', 'type': 'binary_operator', 'children': ['49', '52'], 'value': '+'}; {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'forwardlength'}; {'id': '52', 'type': 'integer', 'children': [], 'value': '8'}; {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'runid'}; {'id': '56', 'type': 'list', 'children': ['57', '62', '67'], 'value': '[self.forwardlength + 9, self.forwardlength + 16, self.runid]'}; {'id': '57', 'type': 'binary_operator', 'children': ['58', '61'], 'value': '+'}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'forwardlength'}; {'id': '61', 'type': 'integer', 'children': [], 'value': '9'}; {'id': '62', 'type': 'binary_operator', 'children': ['63', '66'], 'value': '+'}; {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'forwardlength'}; {'id': '66', 'type': 'integer', 'children': [], 'value': '16'}; {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'runid'}; {'id': '70', 'type': 'list', 'children': ['71', '76', '85'], 'value': '[self.forwardlength + 17, self.forwardlength + 16 + self.reverselength, self.runid]'}; {'id': '71', 'type': 'binary_operator', 'children': ['72', '75'], 'value': '+'}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'forwardlength'}; {'id': '75', 'type': 'integer', 'children': [], 'value': '17'}; {'id': '76', 'type': 'binary_operator', 'children': ['77', '82'], 'value': '+'}; {'id': '77', 'type': 'binary_operator', 'children': ['78', '81'], 'value': '+'}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'forwardlength'}; {'id': '81', 'type': 'integer', 'children': [], 'value': '16'}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'reverselength'}; {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'runid'}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}; {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'parameters'}; {'id': '91', 'type': 'dictionary', 'children': ['92', '97', '110', '117']}; {'id': '92', 'type': 'pair', 'children': ['93', '94']}; {'id': '93', 'type': 'string', 'children': [], 'value': "'RunFolder'"}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'runid'}; {'id': '97', 'type': 'pair', 'children': ['98', '99']}; {'id': '98', 'type': 'string', 'children': [], 'value': "'RunFolderDate'"}; {'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': 'self'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'metadata'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '107', 'type': 'argument_list', 'children': ['108', '109']}; {'id': '108', 'type': 'string', 'children': [], 'value': '"-"'}; {'id': '109', 'type': 'string', 'children': [], 'value': '""'}; {'id': '110', 'type': 'pair', 'children': ['111', '112']}; {'id': '111', 'type': 'string', 'children': [], 'value': "'RunFolderId'"}; {'id': '112', 'type': 'attribute', 'children': ['113', '116']}; {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'metadata'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'runnumber'}; {'id': '117', 'type': 'pair', 'children': ['118', '119']}; {'id': '118', 'type': 'string', 'children': [], 'value': "'RunFlowcellId'"}; {'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': 'metadata'}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'flowcell'}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}; {'id': '125', 'type': 'assignment', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '127', 'type': 'call', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'ElementTree'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'parse'}; {'id': '131', 'type': 'argument_list', 'children': ['132']}; {'id': '132', 'type': 'call', 'children': ['133', '136']}; {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'string', 'children': [], 'value': '"{}/config.xml"'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '136', 'type': 'argument_list', 'children': ['137']}; {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'homepath'}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}; {'id': '141', 'type': 'assignment', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'configroot'}; {'id': '143', 'type': 'call', 'children': ['144', '147']}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'getroot'}; {'id': '147', 'type': 'argument_list', 'children': []}; {'id': '148', 'type': 'for_statement', 'children': ['149', '150', '151']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'run'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'configroot'}; {'id': '151', 'type': 'block', 'children': ['152']}; {'id': '152', 'type': 'for_statement', 'children': ['153', '154', '155']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'run'}; {'id': '155', 'type': 'block', 'children': ['156']}; {'id': '156', 'type': 'if_statement', 'children': ['157', '162', '198']}; {'id': '157', 'type': 'comparison_operator', 'children': ['158', '161'], 'value': '=='}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '161', 'type': 'string', 'children': [], 'value': "'Cycles'"}; {'id': '162', 'type': 'block', 'children': ['163']}; {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'assignment', 'children': ['165', '168']}; {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'attrib'}; {'id': '168', 'type': 'dictionary', 'children': ['169', '185', '195']}; {'id': '169', 'type': 'pair', 'children': ['170', '171']}; {'id': '170', 'type': 'string', 'children': [], 'value': "'Last'"}; {'id': '171', 'type': 'call', 'children': ['172', '175']}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}; {'id': '173', 'type': 'string', 'children': [], 'value': "'{}'"}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '175', 'type': 'argument_list', 'children': ['176']}; {'id': '176', 'type': 'binary_operator', 'children': ['177', '182'], 'value': '+'}; {'id': '177', 'type': 'binary_operator', 'children': ['178', '181'], 'value': '+'}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'forwardlength'}; {'id': '181', 'type': 'integer', 'children': [], 'value': '16'}; {'id': '182', 'type': 'attribute', 'children': ['183', '184']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'reverselength'}; {'id': '185', 'type': 'pair', 'children': ['186', '187']}; {'id': '186', 'type': 'string', 'children': [], 'value': "'Number'"}; {'id': '187', 'type': 'call', 'children': ['188', '191']}; {'id': '188', 'type': 'attribute', 'children': ['189', '190']}; {'id': '189', 'type': 'string', 'children': [], 'value': "'{}'"}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '191', 'type': 'argument_list', 'children': ['192']}; {'id': '192', 'type': 'attribute', 'children': ['193', '194']}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'totalreads'}; {'id': '195', 'type': 'pair', 'children': ['196', '197']}; {'id': '196', 'type': 'string', 'children': [], 'value': "'First'"}; {'id': '197', 'type': 'string', 'children': [], 'value': "'1'"}; {'id': '198', 'type': 'elif_clause', 'children': ['199', '204']}; {'id': '199', 'type': 'comparison_operator', 'children': ['200', '203'], 'value': '=='}; {'id': '200', 'type': 'attribute', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '203', 'type': 'string', 'children': [], 'value': "'RunParameters'"}; {'id': '204', 'type': 'block', 'children': ['205', '209']}; {'id': '205', 'type': 'expression_statement', 'children': ['206']}; {'id': '206', 'type': 'assignment', 'children': ['207', '208']}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'runparameters'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '209', 'type': 'for_statement', 'children': ['210', '211', '212']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'runparameter'}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'runparameters'}; {'id': '212', 'type': 'block', 'children': ['213', '255', '270', '289']}; {'id': '213', 'type': 'if_statement', 'children': ['214', '219']}; {'id': '214', 'type': 'comparison_operator', 'children': ['215', '216'], 'value': 'in'}; {'id': '215', 'type': 'string', 'children': [], 'value': "'Reads'"}; {'id': '216', 'type': 'attribute', 'children': ['217', '218']}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'runparameter'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '219', 'type': 'block', 'children': ['220']}; {'id': '220', 'type': 'for_statement', 'children': ['221', '224', '228']}; {'id': '221', 'type': 'pattern_list', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'indexcount'}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'reads'}; {'id': '224', 'type': 'call', 'children': ['225', '226']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '226', 'type': 'argument_list', 'children': ['227']}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'runparameter'}; {'id': '228', 'type': 'block', 'children': ['229', '242']}; {'id': '229', 'type': 'expression_statement', 'children': ['230']}; {'id': '230', 'type': 'assignment', 'children': ['231', '232']}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '232', 'type': 'binary_operator', 'children': ['233', '241'], 'value': '-'}; {'id': '233', 'type': 'call', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '235', 'type': 'argument_list', 'children': ['236']}; {'id': '236', 'type': 'subscript', 'children': ['237', '240']}; {'id': '237', 'type': 'attribute', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'runparameter'}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'attrib'}; {'id': '240', 'type': 'string', 'children': [], 'value': "'Index'"}; {'id': '241', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '242', 'type': 'expression_statement', 'children': ['243']}; {'id': '243', 'type': 'assignment', 'children': ['244', '247']}; {'id': '244', 'type': 'attribute', 'children': ['245', '246']}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'reads'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '247', 'type': 'call', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '249', 'type': 'argument_list', 'children': ['250']}; {'id': '250', 'type': 'subscript', 'children': ['251', '254']}; {'id': '251', 'type': 'subscript', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'cycles'}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'indexcount'}; {'id': '255', 'type': 'if_statement', 'children': ['256', '261']}; {'id': '256', 'type': 'comparison_operator', 'children': ['257', '260'], 'value': '=='}; {'id': '257', 'type': 'attribute', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'runparameter'}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '260', 'type': 'string', 'children': [], 'value': "'Instrument'"}; {'id': '261', 'type': 'block', 'children': ['262']}; {'id': '262', 'type': 'expression_statement', 'children': ['263']}; {'id': '263', 'type': 'assignment', 'children': ['264', '267']}; {'id': '264', 'type': 'attribute', 'children': ['265', '266']}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'runparameter'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '267', 'type': 'attribute', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'instrument'}; {'id': '270', 'type': 'for_statement', 'children': ['271', '272', '273']}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'parameter'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'parameters'}; {'id': '273', 'type': 'block', 'children': ['274']}; {'id': '274', 'type': 'if_statement', 'children': ['275', '280']}; {'id': '275', 'type': 'comparison_operator', 'children': ['276', '279'], 'value': '=='}; {'id': '276', 'type': 'attribute', 'children': ['277', '278']}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'runparameter'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '279', 'type': 'identifier', 'children': [], 'value': 'parameter'}; {'id': '280', 'type': 'block', 'children': ['281']}; {'id': '281', 'type': 'expression_statement', 'children': ['282']}; {'id': '282', 'type': 'assignment', 'children': ['283', '286']}; {'id': '283', 'type': 'attribute', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'runparameter'}; {'id': '285', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '286', 'type': 'subscript', 'children': ['287', '288']}; {'id': '287', 'type': 'identifier', 'children': [], 'value': 'parameters'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'parameter'}; {'id': '289', 'type': 'if_statement', 'children': ['290', '295']}; {'id': '290', 'type': 'comparison_operator', 'children': ['291', '292'], 'value': 'in'}; {'id': '291', 'type': 'string', 'children': [], 'value': "'Barcode'"}; {'id': '292', 'type': 'attribute', 'children': ['293', '294']}; {'id': '293', 'type': 'identifier', 'children': [], 'value': 'runparameter'}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '295', 'type': 'block', 'children': ['296']}; {'id': '296', 'type': 'for_statement', 'children': ['297', '300', '304']}; {'id': '297', 'type': 'pattern_list', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'cycle'}; {'id': '299', 'type': 'identifier', 'children': [], 'value': 'barcode'}; {'id': '300', 'type': 'call', 'children': ['301', '302']}; {'id': '301', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '302', 'type': 'argument_list', 'children': ['303']}; {'id': '303', 'type': 'identifier', 'children': [], 'value': 'runparameter'}; {'id': '304', 'type': 'block', 'children': ['305']}; {'id': '305', 'type': 'expression_statement', 'children': ['306']}; {'id': '306', 'type': 'assignment', 'children': ['307', '310']}; {'id': '307', 'type': 'attribute', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'barcode'}; {'id': '309', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '310', 'type': 'call', 'children': ['311', '312']}; {'id': '311', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '312', 'type': 'argument_list', 'children': ['313']}; {'id': '313', 'type': 'binary_operator', 'children': ['314', '319'], 'value': '+'}; {'id': '314', 'type': 'binary_operator', 'children': ['315', '318'], 'value': '+'}; {'id': '315', 'type': 'attribute', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '317', 'type': 'identifier', 'children': [], 'value': 'forwardlength'}; {'id': '318', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '319', 'type': 'identifier', 'children': [], 'value': 'cycle'}; {'id': '320', 'type': 'expression_statement', 'children': ['321']}; {'id': '321', 'type': 'call', 'children': ['322', '325']}; {'id': '322', 'type': 'attribute', 'children': ['323', '324']}; {'id': '323', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '325', 'type': 'argument_list', 'children': ['326']}; {'id': '326', 'type': 'call', 'children': ['327', '330']}; {'id': '327', 'type': 'attribute', 'children': ['328', '329']}; {'id': '328', 'type': 'string', 'children': [], 'value': "'{}Data/Intensities/BaseCalls/config.xml'"}; {'id': '329', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '330', 'type': 'argument_list', 'children': ['331']}; {'id': '331', 'type': 'attribute', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '333', 'type': 'identifier', 'children': [], 'value': 'miseqfolder'}
|
def configfilepopulator(self):
self.forwardlength = self.metadata.header.forwardlength
self.reverselength = self.metadata.header.reverselength
cycles = [[1, self.forwardlength, self.runid],
[self.forwardlength + 1, self.forwardlength + 8, self.runid],
[self.forwardlength + 9, self.forwardlength + 16, self.runid],
[self.forwardlength + 17, self.forwardlength + 16 + self.reverselength, self.runid]]
parameters = {'RunFolder': self.runid, 'RunFolderDate': self.metadata.date.replace("-", ""),
'RunFolderId': self.metadata.runnumber, 'RunFlowcellId': self.metadata.flowcell}
config = ElementTree.parse("{}/config.xml".format(self.homepath))
configroot = config.getroot()
for run in configroot:
for child in run:
if child.tag == 'Cycles':
child.attrib = {'Last': '{}'.format(self.forwardlength + 16 + self.reverselength),
'Number': '{}'.format(self.totalreads), 'First': '1'}
elif child.tag == 'RunParameters':
runparameters = child
for runparameter in runparameters:
if 'Reads' in runparameter.tag:
for indexcount, reads in enumerate(runparameter):
index = int(runparameter.attrib['Index']) - 1
reads.text = str(cycles[index][indexcount])
if runparameter.tag == 'Instrument':
runparameter.text = self.instrument
for parameter in parameters:
if runparameter.tag == parameter:
runparameter.text = parameters[parameter]
if 'Barcode' in runparameter.tag:
for cycle, barcode in enumerate(runparameter):
barcode.text = str(self.forwardlength + 1 + cycle)
config.write('{}Data/Intensities/BaseCalls/config.xml'.format(self.miseqfolder))
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_check_time_format'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '7', 'type': 'block', 'children': ['8']}; {'id': '8', 'type': 'for_statement', 'children': ['9', '12', '17']}; {'id': '9', 'type': 'pattern_list', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '12', 'type': 'call', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '17', 'type': 'block', 'children': ['18', '24', '72', '96']}; {'id': '18', 'type': 'if_statement', 'children': ['19', '22']}; {'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': '=='}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '21', 'type': 'string', 'children': [], 'value': '"*"'}; {'id': '22', 'type': 'block', 'children': ['23']}; {'id': '23', 'type': 'continue_statement', 'children': []}; {'id': '24', 'type': 'if_statement', 'children': ['25', '28']}; {'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': '=='}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '27', 'type': 'string', 'children': [], 'value': '"day_of_week"'}; {'id': '28', 'type': 'block', 'children': ['29']}; {'id': '29', 'type': 'if_statement', 'children': ['30', '35', '57']}; {'id': '30', 'type': 'call', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'string_types'}; {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'if_statement', 'children': ['37', '40']}; {'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': 'not'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'ORDER_WEEK'}; {'id': '40', 'type': 'block', 'children': ['41']}; {'id': '41', 'type': 'raise_statement', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'ParseError'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}; {'id': '45', 'type': 'binary_operator', 'children': ['46', '49'], 'value': '%'}; {'id': '46', 'type': 'concatenated_string', 'children': ['47', '48']}; {'id': '47', 'type': 'string', 'children': [], 'value': '"\'%s\' is not day of the week. "'}; {'id': '48', 'type': 'string', 'children': [], 'value': '"character is the only \'%s\'"'}; {'id': '49', 'type': 'tuple', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'string', 'children': [], 'value': "', '"}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'ORDER_WEEK'}; {'id': '57', 'type': 'elif_clause', 'children': ['58', '64']}; {'id': '58', 'type': 'not_operator', 'children': ['59']}; {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '61', 'type': 'argument_list', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '64', 'type': 'block', 'children': ['65']}; {'id': '65', 'type': 'raise_statement', 'children': ['66']}; {'id': '66', 'type': 'call', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}; {'id': '69', 'type': 'binary_operator', 'children': ['70', '71'], 'value': '%'}; {'id': '70', 'type': 'string', 'children': [], 'value': '"\'%s\' is not an int"'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '72', 'type': 'if_statement', 'children': ['73', '80']}; {'id': '73', 'type': 'comparison_operator', 'children': ['74', '75'], 'value': 'in'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '75', 'type': 'list', 'children': ['76', '77', '78', '79'], 'value': '["year", "month", "day", "num_of_week"]'}; {'id': '76', 'type': 'string', 'children': [], 'value': '"year"'}; {'id': '77', 'type': 'string', 'children': [], 'value': '"month"'}; {'id': '78', 'type': 'string', 'children': [], 'value': '"day"'}; {'id': '79', 'type': 'string', 'children': [], 'value': '"num_of_week"'}; {'id': '80', 'type': 'block', 'children': ['81']}; {'id': '81', 'type': 'if_statement', 'children': ['82', '88']}; {'id': '82', 'type': 'not_operator', 'children': ['83']}; {'id': '83', 'type': 'call', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '85', 'type': 'argument_list', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'int'}; {'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': 'binary_operator', 'children': ['94', '95'], 'value': '%'}; {'id': '94', 'type': 'string', 'children': [], 'value': '"\'%s\' is not an int"'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '96', 'type': 'if_statement', 'children': ['97', '102']}; {'id': '97', 'type': 'call', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '99', 'type': 'argument_list', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '102', 'type': 'block', 'children': ['103', '111']}; {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '108']}; {'id': '105', 'type': 'pattern_list', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '108', 'type': 'subscript', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'TIME_INFO'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '111', 'type': 'if_statement', 'children': ['112', '117']}; {'id': '112', 'type': 'not_operator', 'children': ['113']}; {'id': '113', 'type': 'comparison_operator', 'children': ['114', '115', '116'], 'value': '<='}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '117', 'type': 'block', 'children': ['118']}; {'id': '118', 'type': 'raise_statement', 'children': ['119']}; {'id': '119', 'type': 'call', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'PeriodRangeError'}; {'id': '121', 'type': 'argument_list', 'children': ['122']}; {'id': '122', 'type': 'binary_operator', 'children': ['123', '126'], 'value': '%'}; {'id': '123', 'type': 'concatenated_string', 'children': ['124', '125']}; {'id': '124', 'type': 'string', 'children': [], 'value': '"\'%d\' is outside the scope of the period "'}; {'id': '125', 'type': 'string', 'children': [], 'value': '"\'%s\' range: \'%d\' to \'%d\'"'}; {'id': '126', 'type': 'tuple', 'children': ['127', '128', '129', '130']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'end'}
|
def _check_time_format(self, labels, values):
for label, value in zip(labels, values):
if value == "*":
continue
if label == "day_of_week":
if isinstance(value, string_types):
if value not in ORDER_WEEK:
raise ParseError("'%s' is not day of the week. "
"character is the only '%s'" % (
value, ', '.join(ORDER_WEEK)))
elif not isinstance(value, int):
raise TypeError("'%s' is not an int" % value)
if label in ["year", "month", "day", "num_of_week"]:
if not isinstance(value, int):
raise TypeError("'%s' is not an int" % value)
if isinstance(value, int):
start, end = TIME_INFO[label]
if not start <= value <= end:
raise PeriodRangeError("'%d' is outside the scope of the period "
"'%s' range: '%d' to '%d'" % (
value, label, start, end))
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'readlength'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '13']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'call', 'children': ['8', '11']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'string', 'children': [], 'value': "'Estimating read lengths of FASTQ files'"}; {'id': '13', 'type': 'for_statement', 'children': ['14', '15', '18']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'samples'}; {'id': '18', 'type': 'block', 'children': ['19', '27', '35', '43', '51', '59', '67']}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '26']}; {'id': '21', 'type': 'attribute', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'run'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'Date'}; {'id': '26', 'type': 'string', 'children': [], 'value': "'NA'"}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '34']}; {'id': '29', 'type': 'attribute', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'run'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'InvestigatorName'}; {'id': '34', 'type': 'string', 'children': [], 'value': "'NA'"}; {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '42']}; {'id': '37', 'type': 'attribute', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'run'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'TotalClustersinRun'}; {'id': '42', 'type': 'string', 'children': [], 'value': "'NA'"}; {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '50']}; {'id': '45', 'type': 'attribute', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'run'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'NumberofClustersPF'}; {'id': '50', 'type': 'string', 'children': [], 'value': "'NA'"}; {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '58']}; {'id': '53', 'type': 'attribute', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'run'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'PercentOfClusters'}; {'id': '58', 'type': 'string', 'children': [], 'value': "'NA'"}; {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '66']}; {'id': '61', 'type': 'attribute', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'run'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'SampleProject'}; {'id': '66', 'type': 'string', 'children': [], 'value': "'NA'"}; {'id': '67', 'type': 'if_statement', 'children': ['68', '89']}; {'id': '68', 'type': 'boolean_operator', 'children': ['69', '79'], 'value': 'and'}; {'id': '69', 'type': 'not_operator', 'children': ['70']}; {'id': '70', 'type': 'call', 'children': ['71', '74']}; {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'GenObject'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'isattr'}; {'id': '74', 'type': 'argument_list', 'children': ['75', '78']}; {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'run'}; {'id': '78', 'type': 'string', 'children': [], 'value': "'forwardlength'"}; {'id': '79', 'type': 'not_operator', 'children': ['80']}; {'id': '80', 'type': 'call', 'children': ['81', '84']}; {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'GenObject'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'isattr'}; {'id': '84', 'type': 'argument_list', 'children': ['85', '88']}; {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'run'}; {'id': '88', 'type': 'string', 'children': [], 'value': "'reverselength'"}; {'id': '89', 'type': 'block', 'children': ['90', '98', '106', '116']}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}; {'id': '91', 'type': 'assignment', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '95', 'type': 'call', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'GenObject'}; {'id': '97', 'type': 'argument_list', 'children': []}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}; {'id': '99', 'type': 'assignment', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'commands'}; {'id': '103', 'type': 'call', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'GenObject'}; {'id': '105', 'type': 'argument_list', 'children': []}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}; {'id': '107', 'type': 'assignment', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'devnull'}; {'id': '109', 'type': 'call', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '111', 'type': 'argument_list', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'devnull'}; {'id': '115', 'type': 'string', 'children': [], 'value': "'wb'"}; {'id': '116', 'type': 'if_statement', 'children': ['117', '127']}; {'id': '117', 'type': 'comparison_operator', 'children': ['118', '126'], 'value': 'is'}; {'id': '118', 'type': 'call', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}; {'id': '121', 'type': 'attribute', 'children': ['122', '125']}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'general'}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'fastqfiles'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '127', 'type': 'block', 'children': ['128', '141', '156', '192', '214', '267']}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}; {'id': '129', 'type': 'assignment', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'forwardfastq'}; {'id': '131', 'type': 'subscript', 'children': ['132', '140']}; {'id': '132', 'type': 'call', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '134', 'type': 'argument_list', 'children': ['135']}; {'id': '135', 'type': 'attribute', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'general'}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'fastqfiles'}; {'id': '140', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '141', 'type': 'if_statement', 'children': ['142', '145', '150']}; {'id': '142', 'type': 'comparison_operator', 'children': ['143', '144'], 'value': 'in'}; {'id': '143', 'type': 'string', 'children': [], 'value': "'.gz'"}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'forwardfastq'}; {'id': '145', 'type': 'block', 'children': ['146']}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}; {'id': '147', 'type': 'assignment', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '149', 'type': 'string', 'children': [], 'value': "'zcat'"}; {'id': '150', 'type': 'else_clause', 'children': ['151']}; {'id': '151', 'type': 'block', 'children': ['152']}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}; {'id': '153', 'type': 'assignment', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '155', 'type': 'string', 'children': [], 'value': "'cat'"}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}; {'id': '157', 'type': 'assignment', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'forwardreads'}; {'id': '159', 'type': 'call', 'children': ['160', '191']}; {'id': '160', 'type': 'attribute', 'children': ['161', '190']}; {'id': '161', 'type': 'subscript', 'children': ['162', '189']}; {'id': '162', 'type': 'call', 'children': ['163', '188']}; {'id': '163', 'type': 'attribute', 'children': ['164', '187']}; {'id': '164', 'type': 'call', 'children': ['165', '168']}; {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'subprocess'}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'Popen'}; {'id': '168', 'type': 'argument_list', 'children': ['169', '176', '179', '184']}; {'id': '169', 'type': 'call', 'children': ['170', '173']}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}; {'id': '171', 'type': 'string', 'children': [], 'value': '"{} {} | head -n 1000"'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '173', 'type': 'argument_list', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'forwardfastq'}; {'id': '176', 'type': 'keyword_argument', 'children': ['177', '178']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'shell'}; {'id': '178', 'type': 'True', 'children': []}; {'id': '179', 'type': 'keyword_argument', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'stdout'}; {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'subprocess'}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'PIPE'}; {'id': '184', 'type': 'keyword_argument', 'children': ['185', '186']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'stderr'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'devnull'}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'communicate'}; {'id': '188', 'type': 'argument_list', 'children': []}; {'id': '189', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'rstrip'}; {'id': '191', 'type': 'argument_list', 'children': []}; {'id': '192', 'type': 'try_statement', 'children': ['193', '203']}; {'id': '193', 'type': 'block', 'children': ['194']}; {'id': '194', 'type': 'expression_statement', 'children': ['195']}; {'id': '195', 'type': 'assignment', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'forwardreads'}; {'id': '197', 'type': 'call', 'children': ['198', '201']}; {'id': '198', 'type': 'attribute', 'children': ['199', '200']}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'forwardreads'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'decode'}; {'id': '201', 'type': 'argument_list', 'children': ['202']}; {'id': '202', 'type': 'string', 'children': [], 'value': "'utf-8'"}; {'id': '203', 'type': 'except_clause', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'UnicodeDecodeError'}; {'id': '205', 'type': 'block', 'children': ['206']}; {'id': '206', 'type': 'expression_statement', 'children': ['207']}; {'id': '207', 'type': 'assignment', 'children': ['208', '213']}; {'id': '208', 'type': 'attribute', 'children': ['209', '212']}; {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'run'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'forwardlength'}; {'id': '213', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '214', 'type': 'try_statement', 'children': ['215', '254']}; {'id': '215', 'type': 'block', 'children': ['216', '246']}; {'id': '216', 'type': 'expression_statement', 'children': ['217']}; {'id': '217', 'type': 'assignment', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'forwardlength'}; {'id': '219', 'type': 'call', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '221', 'type': 'argument_list', 'children': ['222']}; {'id': '222', 'type': 'list_comprehension', 'children': ['223', '227', '240']}; {'id': '223', 'type': 'call', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '225', 'type': 'argument_list', 'children': ['226']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'sequence'}; {'id': '227', 'type': 'for_in_clause', 'children': ['228', '231']}; {'id': '228', 'type': 'pattern_list', 'children': ['229', '230']}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'iterator'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'sequence'}; {'id': '231', 'type': 'call', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '233', 'type': 'argument_list', 'children': ['234']}; {'id': '234', 'type': 'call', 'children': ['235', '238']}; {'id': '235', 'type': 'attribute', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'forwardreads'}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '238', 'type': 'argument_list', 'children': ['239']}; {'id': '239', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '240', 'type': 'if_clause', 'children': ['241']}; {'id': '241', 'type': 'comparison_operator', 'children': ['242', '245'], 'value': '=='}; {'id': '242', 'type': 'binary_operator', 'children': ['243', '244'], 'value': '%'}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'iterator'}; {'id': '244', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '245', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '246', 'type': 'expression_statement', 'children': ['247']}; {'id': '247', 'type': 'assignment', 'children': ['248', '253']}; {'id': '248', 'type': 'attribute', 'children': ['249', '252']}; {'id': '249', 'type': 'attribute', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'run'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'forwardlength'}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'forwardlength'}; {'id': '254', 'type': 'except_clause', 'children': ['255', '258']}; {'id': '255', 'type': 'tuple', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '258', 'type': 'block', 'children': ['259']}; {'id': '259', 'type': 'expression_statement', 'children': ['260']}; {'id': '260', 'type': 'assignment', 'children': ['261', '266']}; {'id': '261', 'type': 'attribute', 'children': ['262', '265']}; {'id': '262', 'type': 'attribute', 'children': ['263', '264']}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'run'}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'forwardlength'}; {'id': '266', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '267', 'type': 'if_statement', 'children': ['268', '278', '399']}; {'id': '268', 'type': 'comparison_operator', 'children': ['269', '277'], 'value': '=='}; {'id': '269', 'type': 'call', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '271', 'type': 'argument_list', 'children': ['272']}; {'id': '272', 'type': 'attribute', 'children': ['273', '276']}; {'id': '273', 'type': 'attribute', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'general'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'fastqfiles'}; {'id': '277', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '278', 'type': 'block', 'children': ['279', '292', '328', '350']}; {'id': '279', 'type': 'expression_statement', 'children': ['280']}; {'id': '280', 'type': 'assignment', 'children': ['281', '282']}; {'id': '281', 'type': 'identifier', 'children': [], 'value': 'reversefastq'}; {'id': '282', 'type': 'subscript', 'children': ['283', '291']}; {'id': '283', 'type': 'call', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '285', 'type': 'argument_list', 'children': ['286']}; {'id': '286', 'type': 'attribute', 'children': ['287', '290']}; {'id': '287', 'type': 'attribute', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'general'}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'fastqfiles'}; {'id': '291', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '292', 'type': 'expression_statement', 'children': ['293']}; {'id': '293', 'type': 'assignment', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'reversereads'}; {'id': '295', 'type': 'call', 'children': ['296', '327']}; {'id': '296', 'type': 'attribute', 'children': ['297', '326']}; {'id': '297', 'type': 'subscript', 'children': ['298', '325']}; {'id': '298', 'type': 'call', 'children': ['299', '324']}; {'id': '299', 'type': 'attribute', 'children': ['300', '323']}; {'id': '300', 'type': 'call', 'children': ['301', '304']}; {'id': '301', 'type': 'attribute', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'subprocess'}; {'id': '303', 'type': 'identifier', 'children': [], 'value': 'Popen'}; {'id': '304', 'type': 'argument_list', 'children': ['305', '312', '315', '320']}; {'id': '305', 'type': 'call', 'children': ['306', '309']}; {'id': '306', 'type': 'attribute', 'children': ['307', '308']}; {'id': '307', 'type': 'string', 'children': [], 'value': '"{} {} | head -n 1000"'}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '309', 'type': 'argument_list', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '311', 'type': 'identifier', 'children': [], 'value': 'reversefastq'}; {'id': '312', 'type': 'keyword_argument', 'children': ['313', '314']}; {'id': '313', 'type': 'identifier', 'children': [], 'value': 'shell'}; {'id': '314', 'type': 'True', 'children': []}; {'id': '315', 'type': 'keyword_argument', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'stdout'}; {'id': '317', 'type': 'attribute', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'subprocess'}; {'id': '319', 'type': 'identifier', 'children': [], 'value': 'PIPE'}; {'id': '320', 'type': 'keyword_argument', 'children': ['321', '322']}; {'id': '321', 'type': 'identifier', 'children': [], 'value': 'stderr'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'devnull'}; {'id': '323', 'type': 'identifier', 'children': [], 'value': 'communicate'}; {'id': '324', 'type': 'argument_list', 'children': []}; {'id': '325', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'rstrip'}; {'id': '327', 'type': 'argument_list', 'children': []}; {'id': '328', 'type': 'try_statement', 'children': ['329', '339']}; {'id': '329', 'type': 'block', 'children': ['330']}; {'id': '330', 'type': 'expression_statement', 'children': ['331']}; {'id': '331', 'type': 'assignment', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'reversereads'}; {'id': '333', 'type': 'call', 'children': ['334', '337']}; {'id': '334', 'type': 'attribute', 'children': ['335', '336']}; {'id': '335', 'type': 'identifier', 'children': [], 'value': 'reversereads'}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'decode'}; {'id': '337', 'type': 'argument_list', 'children': ['338']}; {'id': '338', 'type': 'string', 'children': [], 'value': "'utf-8'"}; {'id': '339', 'type': 'except_clause', 'children': ['340', '341']}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'UnicodeDecodeError'}; {'id': '341', 'type': 'block', 'children': ['342']}; {'id': '342', 'type': 'expression_statement', 'children': ['343']}; {'id': '343', 'type': 'assignment', 'children': ['344', '349']}; {'id': '344', 'type': 'attribute', 'children': ['345', '348']}; {'id': '345', 'type': 'attribute', 'children': ['346', '347']}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '347', 'type': 'identifier', 'children': [], 'value': 'run'}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'reverselength'}; {'id': '349', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '350', 'type': 'try_statement', 'children': ['351', '386']}; {'id': '351', 'type': 'block', 'children': ['352']}; {'id': '352', 'type': 'expression_statement', 'children': ['353']}; {'id': '353', 'type': 'assignment', 'children': ['354', '359']}; {'id': '354', 'type': 'attribute', 'children': ['355', '358']}; {'id': '355', 'type': 'attribute', 'children': ['356', '357']}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '357', 'type': 'identifier', 'children': [], 'value': 'run'}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'reverselength'}; {'id': '359', 'type': 'call', 'children': ['360', '361']}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '361', 'type': 'argument_list', 'children': ['362']}; {'id': '362', 'type': 'list_comprehension', 'children': ['363', '367', '380']}; {'id': '363', 'type': 'call', 'children': ['364', '365']}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '365', 'type': 'argument_list', 'children': ['366']}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'sequence'}; {'id': '367', 'type': 'for_in_clause', 'children': ['368', '371']}; {'id': '368', 'type': 'pattern_list', 'children': ['369', '370']}; {'id': '369', 'type': 'identifier', 'children': [], 'value': 'iterator'}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'sequence'}; {'id': '371', 'type': 'call', 'children': ['372', '373']}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '373', 'type': 'argument_list', 'children': ['374']}; {'id': '374', 'type': 'call', 'children': ['375', '378']}; {'id': '375', 'type': 'attribute', 'children': ['376', '377']}; {'id': '376', 'type': 'identifier', 'children': [], 'value': 'reversereads'}; {'id': '377', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '378', 'type': 'argument_list', 'children': ['379']}; {'id': '379', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '380', 'type': 'if_clause', 'children': ['381']}; {'id': '381', 'type': 'comparison_operator', 'children': ['382', '385'], 'value': '=='}; {'id': '382', 'type': 'binary_operator', 'children': ['383', '384'], 'value': '%'}; {'id': '383', 'type': 'identifier', 'children': [], 'value': 'iterator'}; {'id': '384', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '385', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '386', 'type': 'except_clause', 'children': ['387', '390']}; {'id': '387', 'type': 'tuple', 'children': ['388', '389']}; {'id': '388', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '389', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '390', 'type': 'block', 'children': ['391']}; {'id': '391', 'type': 'expression_statement', 'children': ['392']}; {'id': '392', 'type': 'assignment', 'children': ['393', '398']}; {'id': '393', 'type': 'attribute', 'children': ['394', '397']}; {'id': '394', 'type': 'attribute', 'children': ['395', '396']}; {'id': '395', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '396', 'type': 'identifier', 'children': [], 'value': 'run'}; {'id': '397', 'type': 'identifier', 'children': [], 'value': 'reverselength'}; {'id': '398', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '399', 'type': 'else_clause', 'children': ['400']}; {'id': '400', 'type': 'block', 'children': ['401']}; {'id': '401', 'type': 'expression_statement', 'children': ['402']}; {'id': '402', 'type': 'assignment', 'children': ['403', '408']}; {'id': '403', 'type': 'attribute', 'children': ['404', '407']}; {'id': '404', 'type': 'attribute', 'children': ['405', '406']}; {'id': '405', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '406', 'type': 'identifier', 'children': [], 'value': 'run'}; {'id': '407', 'type': 'identifier', 'children': [], 'value': 'reverselength'}; {'id': '408', 'type': 'integer', 'children': [], 'value': '0'}
|
def readlength(self):
logging.info('Estimating read lengths of FASTQ files')
for sample in self.samples:
sample.run.Date = 'NA'
sample.run.InvestigatorName = 'NA'
sample.run.TotalClustersinRun = 'NA'
sample.run.NumberofClustersPF = 'NA'
sample.run.PercentOfClusters = 'NA'
sample.run.SampleProject = 'NA'
if not GenObject.isattr(sample.run, 'forwardlength') and not GenObject.isattr(sample.run, 'reverselength'):
sample.header = GenObject()
sample.commands = GenObject()
devnull = open(os.devnull, 'wb')
if type(sample.general.fastqfiles) is list:
forwardfastq = sorted(sample.general.fastqfiles)[0]
if '.gz' in forwardfastq:
command = 'zcat'
else:
command = 'cat'
forwardreads = subprocess.Popen("{} {} | head -n 1000".format(command, forwardfastq),
shell=True,
stdout=subprocess.PIPE,
stderr=devnull).communicate()[0].rstrip()
try:
forwardreads = forwardreads.decode('utf-8')
except UnicodeDecodeError:
sample.run.forwardlength = 0
try:
forwardlength = max([len(sequence) for iterator, sequence in enumerate(forwardreads.split('\n'))
if iterator % 4 == 1])
sample.run.forwardlength = forwardlength
except (ValueError, TypeError):
sample.run.forwardlength = 0
if len(sample.general.fastqfiles) == 2:
reversefastq = sorted(sample.general.fastqfiles)[1]
reversereads = subprocess.Popen("{} {} | head -n 1000".format(command, reversefastq),
shell=True,
stdout=subprocess.PIPE,
stderr=devnull).communicate()[0].rstrip()
try:
reversereads = reversereads.decode('utf-8')
except UnicodeDecodeError:
sample.run.reverselength = 0
try:
sample.run.reverselength = max([len(sequence) for iterator, sequence in
enumerate(reversereads.split('\n')) if iterator % 4 == 1])
except (ValueError, TypeError):
sample.run.reverselength = 0
else:
sample.run.reverselength = 0
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'confirm'}; {'id': '3', 'type': 'parameters', 'children': ['4', '7', '10', '15', '18']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'prompt'}; {'id': '6', 'type': 'string', 'children': [], 'value': "'Really?'"}; {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'color'}; {'id': '9', 'type': 'string', 'children': [], 'value': "'warning'"}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'yes_values'}; {'id': '12', 'type': 'tuple', 'children': ['13', '14']}; {'id': '13', 'type': 'string', 'children': [], 'value': "'y'"}; {'id': '14', 'type': 'string', 'children': [], 'value': "'yes'"}; {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'abort_on_unconfirmed'}; {'id': '17', 'type': 'False', 'children': []}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'abort_options'}; {'id': '20', 'type': 'None', 'children': []}; {'id': '21', 'type': 'block', 'children': ['22', '34', '50', '65', '105', '125', '196']}; {'id': '22', 'type': 'if_statement', 'children': ['23', '28']}; {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '25', 'type': 'argument_list', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'yes_values'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'str'}; {'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': 'yes_values'}; {'id': '32', 'type': 'tuple', 'children': ['33']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'yes_values'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}; {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'prompt'}; {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'string', 'children': [], 'value': "'{prompt} [{yes_value}/N] '"}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '41', 'type': 'argument_list', 'children': ['42', '45']}; {'id': '42', 'type': 'keyword_argument', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'prompt'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'prompt'}; {'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'yes_value'}; {'id': '47', 'type': 'subscript', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'yes_values'}; {'id': '49', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '50', 'type': 'if_statement', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'color'}; {'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': 'prompt'}; {'id': '56', 'type': 'call', 'children': ['57', '60']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'printer'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'colorize'}; {'id': '60', 'type': 'argument_list', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'prompt'}; {'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'color'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'color'}; {'id': '65', 'type': 'try_statement', 'children': ['66', '74', '85']}; {'id': '66', 'type': 'block', 'children': ['67']}; {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'answer'}; {'id': '70', 'type': 'call', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'input'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'prompt'}; {'id': '74', 'type': 'except_clause', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'KeyboardInterrupt'}; {'id': '76', 'type': 'block', 'children': ['77', '81']}; {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '80', 'type': 'argument_list', 'children': []}; {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'confirmed'}; {'id': '84', 'type': 'False', 'children': []}; {'id': '85', 'type': 'else_clause', 'children': ['86']}; {'id': '86', 'type': 'block', 'children': ['87', '99']}; {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'answer'}; {'id': '90', 'type': 'call', 'children': ['91', '98']}; {'id': '91', 'type': 'attribute', 'children': ['92', '97']}; {'id': '92', 'type': 'call', 'children': ['93', '96']}; {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'answer'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '96', 'type': 'argument_list', 'children': []}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '98', 'type': 'argument_list', 'children': []}; {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'confirmed'}; {'id': '102', 'type': 'comparison_operator', 'children': ['103', '104'], 'value': 'in'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'answer'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'yes_values'}; {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'do_abort_on_unconfirmed'}; {'id': '108', 'type': 'boolean_operator', 'children': ['109', '111'], 'value': 'and'}; {'id': '109', 'type': 'not_operator', 'children': ['110']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'confirmed'}; {'id': '111', 'type': '()', 'children': ['112']}; {'id': '112', 'type': 'boolean_operator', 'children': ['113', '117'], 'value': 'or'}; {'id': '113', 'type': 'call', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'bool'}; {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'abort_on_unconfirmed'}; {'id': '117', 'type': '()', 'children': ['118']}; {'id': '118', 'type': 'boolean_operator', 'children': ['119', '122'], 'value': 'and'}; {'id': '119', 'type': 'comparison_operator', 'children': ['120', '121'], 'value': '=='}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'abort_on_unconfirmed'}; {'id': '121', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '122', 'type': 'comparison_operator', 'children': ['123', '124'], 'value': 'is'}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'abort_on_unconfirmed'}; {'id': '124', 'type': 'False', 'children': []}; {'id': '125', 'type': 'if_statement', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'do_abort_on_unconfirmed'}; {'id': '127', 'type': 'block', 'children': ['128', '137', '190']}; {'id': '128', 'type': 'if_statement', 'children': ['129', '132']}; {'id': '129', 'type': 'comparison_operator', 'children': ['130', '131'], 'value': 'is'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'abort_options'}; {'id': '131', 'type': 'None', 'children': []}; {'id': '132', 'type': 'block', 'children': ['133']}; {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'assignment', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'abort_options'}; {'id': '136', 'type': 'dictionary', 'children': []}; {'id': '137', 'type': 'if_statement', 'children': ['138', '141', '150', '165', '180']}; {'id': '138', 'type': 'comparison_operator', 'children': ['139', '140'], 'value': 'is'}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'abort_on_unconfirmed'}; {'id': '140', 'type': 'True', 'children': []}; {'id': '141', 'type': 'block', 'children': ['142']}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}; {'id': '143', 'type': 'call', 'children': ['144', '147']}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'abort_options'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'setdefault'}; {'id': '147', 'type': 'argument_list', 'children': ['148', '149']}; {'id': '148', 'type': 'string', 'children': [], 'value': "'return_code'"}; {'id': '149', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '150', 'type': 'elif_clause', 'children': ['151', '156']}; {'id': '151', 'type': 'call', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '153', 'type': 'argument_list', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'abort_on_unconfirmed'}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '156', 'type': 'block', 'children': ['157']}; {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'call', 'children': ['159', '162']}; {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'abort_options'}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'setdefault'}; {'id': '162', 'type': 'argument_list', 'children': ['163', '164']}; {'id': '163', 'type': 'string', 'children': [], 'value': "'return_code'"}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'abort_on_unconfirmed'}; {'id': '165', 'type': 'elif_clause', 'children': ['166', '171']}; {'id': '166', 'type': 'call', 'children': ['167', '168']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '168', 'type': 'argument_list', 'children': ['169', '170']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'abort_on_unconfirmed'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '171', 'type': 'block', 'children': ['172']}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}; {'id': '173', 'type': 'call', 'children': ['174', '177']}; {'id': '174', 'type': 'attribute', 'children': ['175', '176']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'abort_options'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'setdefault'}; {'id': '177', 'type': 'argument_list', 'children': ['178', '179']}; {'id': '178', 'type': 'string', 'children': [], 'value': "'message'"}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'abort_on_unconfirmed'}; {'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': 'abort_options'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'setdefault'}; {'id': '187', 'type': 'argument_list', 'children': ['188', '189']}; {'id': '188', 'type': 'string', 'children': [], 'value': "'return_code'"}; {'id': '189', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '190', 'type': 'expression_statement', 'children': ['191']}; {'id': '191', 'type': 'call', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'abort'}; {'id': '193', 'type': 'argument_list', 'children': ['194']}; {'id': '194', 'type': 'dictionary_splat', 'children': ['195']}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'abort_options'}; {'id': '196', 'type': 'return_statement', 'children': ['197']}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'confirmed'}
|
def confirm(prompt='Really?', color='warning', yes_values=('y', 'yes'),
abort_on_unconfirmed=False, abort_options=None):
if isinstance(yes_values, str):
yes_values = (yes_values,)
prompt = '{prompt} [{yes_value}/N] '.format(prompt=prompt, yes_value=yes_values[0])
if color:
prompt = printer.colorize(prompt, color=color)
try:
answer = input(prompt)
except KeyboardInterrupt:
print()
confirmed = False
else:
answer = answer.strip().lower()
confirmed = answer in yes_values
do_abort_on_unconfirmed = not confirmed and (
bool(abort_on_unconfirmed) or
(abort_on_unconfirmed == 0 and abort_on_unconfirmed is not False)
)
if do_abort_on_unconfirmed:
if abort_options is None:
abort_options = {}
if abort_on_unconfirmed is True:
abort_options.setdefault('return_code', 0)
elif isinstance(abort_on_unconfirmed, int):
abort_options.setdefault('return_code', abort_on_unconfirmed)
elif isinstance(abort_on_unconfirmed, str):
abort_options.setdefault('message', abort_on_unconfirmed)
else:
abort_options.setdefault('return_code', 0)
abort(**abort_options)
return confirmed
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'from_string'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'action_str'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '181']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '10', 'type': 'dictionary', 'children': []}; {'id': '11', 'type': 'try_statement', 'children': ['12', '22', '32']}; {'id': '12', 'type': 'block', 'children': ['13']}; {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'mod_obj'}; {'id': '16', 'type': 'call', 'children': ['17', '20']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'ast'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'parse'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'action_str'}; {'id': '22', 'type': 'except_clause', 'children': ['23', '29']}; {'id': '23', 'type': 'as_pattern', 'children': ['24', '27']}; {'id': '24', 'type': 'tuple', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'SyntaxError'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '27', 'type': 'as_pattern_target', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'raise_statement', 'children': ['31']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '32', 'type': 'else_clause', 'children': ['33']}; {'id': '33', 'type': 'block', 'children': ['34', '44']}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}; {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'call_obj'}; {'id': '37', 'type': 'attribute', 'children': ['38', '43']}; {'id': '38', 'type': 'subscript', 'children': ['39', '42']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'mod_obj'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'body'}; {'id': '42', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '44', 'type': 'if_statement', 'children': ['45', '52', '67', '174']}; {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '47', 'type': 'argument_list', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'call_obj'}; {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'ast'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'Attribute'}; {'id': '52', 'type': 'block', 'children': ['53', '61']}; {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '56', 'type': 'attribute', 'children': ['57', '60']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'call_obj'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'assignment', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'call_obj'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '67', 'type': 'elif_clause', 'children': ['68', '75']}; {'id': '68', 'type': 'call', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '70', 'type': 'argument_list', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'call_obj'}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'ast'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'Call'}; {'id': '75', 'type': 'block', 'children': ['76']}; {'id': '76', 'type': 'try_statement', 'children': ['77', '96', '104']}; {'id': '77', 'type': 'block', 'children': ['78', '88']}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}; {'id': '79', 'type': 'assignment', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '81', 'type': 'attribute', 'children': ['82', '87']}; {'id': '82', 'type': 'attribute', 'children': ['83', '86']}; {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'call_obj'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}; {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '91', 'type': 'attribute', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'call_obj'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '96', 'type': 'except_clause', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}; {'id': '98', 'type': 'block', 'children': ['99']}; {'id': '99', 'type': 'raise_statement', 'children': ['100']}; {'id': '100', 'type': 'call', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'UnsupportedActionError'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'action_str'}; {'id': '104', 'type': 'else_clause', 'children': ['105']}; {'id': '105', 'type': 'block', 'children': ['106']}; {'id': '106', 'type': 'for_statement', 'children': ['107', '108', '111']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'kwarg'}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'call_obj'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'keywords'}; {'id': '111', 'type': 'block', 'children': ['112']}; {'id': '112', 'type': 'if_statement', 'children': ['113', '122', '139', '166']}; {'id': '113', 'type': 'call', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '115', 'type': 'argument_list', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'kwarg'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'ast'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'Num'}; {'id': '122', 'type': 'block', 'children': ['123']}; {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'call', 'children': ['125', '128']}; {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '128', 'type': 'argument_list', 'children': ['129']}; {'id': '129', 'type': 'dictionary', 'children': ['130']}; {'id': '130', 'type': 'pair', 'children': ['131', '134']}; {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'kwarg'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'arg'}; {'id': '134', 'type': 'attribute', 'children': ['135', '138']}; {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'kwarg'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '139', 'type': 'elif_clause', 'children': ['140', '149']}; {'id': '140', 'type': 'call', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '142', 'type': 'argument_list', 'children': ['143', '146']}; {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'kwarg'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'ast'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'Str'}; {'id': '149', 'type': 'block', 'children': ['150']}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}; {'id': '151', 'type': 'call', 'children': ['152', '155']}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'dictionary', 'children': ['157']}; {'id': '157', 'type': 'pair', 'children': ['158', '161']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'kwarg'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'arg'}; {'id': '161', 'type': 'attribute', 'children': ['162', '165']}; {'id': '162', 'type': 'attribute', 'children': ['163', '164']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'kwarg'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '166', 'type': 'else_clause', 'children': ['167']}; {'id': '167', 'type': 'block', 'children': ['168']}; {'id': '168', 'type': 'raise_statement', 'children': ['169']}; {'id': '169', 'type': 'call', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'UnsupportedActionArgumentError'}; {'id': '171', 'type': 'argument_list', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'action_str'}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'kwarg'}; {'id': '174', 'type': 'else_clause', 'children': ['175']}; {'id': '175', 'type': 'block', 'children': ['176']}; {'id': '176', 'type': 'raise_statement', 'children': ['177']}; {'id': '177', 'type': 'call', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'UnsupportedActionError'}; {'id': '179', 'type': 'argument_list', 'children': ['180']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'action_str'}; {'id': '181', 'type': 'return_statement', 'children': ['182']}; {'id': '182', 'type': 'call', 'children': ['183', '184']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '184', 'type': 'argument_list', 'children': ['185', '186', '187']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'args'}
|
def from_string(cls, action_str):
args = {}
try:
mod_obj = ast.parse(action_str)
except (SyntaxError, ValueError) as e:
raise e
else:
call_obj = mod_obj.body[0].value
if isinstance(call_obj, ast.Attribute):
module = call_obj.value.id
func = call_obj.attr
elif isinstance(call_obj, ast.Call):
try:
module = call_obj.func.value.id
func = call_obj.func.attr
except AttributeError:
raise UnsupportedActionError(action_str)
else:
for kwarg in call_obj.keywords:
if isinstance(kwarg.value, ast.Num):
args.update({kwarg.arg: kwarg.value.n})
elif isinstance(kwarg.value, ast.Str):
args.update({kwarg.arg: kwarg.value.s})
else:
raise UnsupportedActionArgumentError(action_str,
kwarg)
else:
raise UnsupportedActionError(action_str)
return cls(module, func, args)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'epcrparsethreads'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '11', '53']}; {'id': '6', 'type': 'import_from_statement', 'children': ['7', '9']}; {'id': '7', 'type': 'dotted_name', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'Bio'}; {'id': '9', 'type': 'dotted_name', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'SeqIO'}; {'id': '11', 'type': 'for_statement', 'children': ['12', '13', '16']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'metadata'}; {'id': '16', 'type': 'block', 'children': ['17']}; {'id': '17', 'type': 'if_statement', 'children': ['18', '25']}; {'id': '18', 'type': 'comparison_operator', 'children': ['19', '24'], 'value': '!='}; {'id': '19', 'type': 'attribute', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'general'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'bestassemblyfile'}; {'id': '24', 'type': 'string', 'children': [], 'value': "'NA'"}; {'id': '25', 'type': 'block', 'children': ['26', '40', '47']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}; {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'threads'}; {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'Thread'}; {'id': '31', 'type': 'argument_list', 'children': ['32', '37']}; {'id': '32', 'type': 'keyword_argument', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'epcrparse'}; {'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '39', 'type': 'tuple', 'children': []}; {'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': 'threads'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'setDaemon'}; {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'True', 'children': []}; {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '52']}; {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'threads'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '52', 'type': 'argument_list', 'children': []}; {'id': '53', 'type': 'for_statement', 'children': ['54', '55', '58']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'metadata'}; {'id': '58', 'type': 'block', 'children': ['59']}; {'id': '59', 'type': 'if_statement', 'children': ['60', '67']}; {'id': '60', 'type': 'comparison_operator', 'children': ['61', '66'], 'value': '!='}; {'id': '61', 'type': 'attribute', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'general'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'bestassemblyfile'}; {'id': '66', 'type': 'string', 'children': [], 'value': "'NA'"}; {'id': '67', 'type': 'block', 'children': ['68']}; {'id': '68', 'type': 'if_statement', 'children': ['69', '78']}; {'id': '69', 'type': 'comparison_operator', 'children': ['70', '77'], 'value': '!='}; {'id': '70', 'type': 'attribute', 'children': ['71', '76']}; {'id': '71', 'type': 'subscript', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'analysistype'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'primers'}; {'id': '77', 'type': 'string', 'children': [], 'value': "'NA'"}; {'id': '78', 'type': 'block', 'children': ['79', '85', '97', '109', '136']}; {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'record'}; {'id': '82', 'type': 'call', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '84', 'type': 'argument_list', 'children': []}; {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '94']}; {'id': '87', 'type': 'attribute', 'children': ['88', '93']}; {'id': '88', 'type': 'subscript', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'analysistype'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'blastresults'}; {'id': '94', 'type': 'call', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '96', 'type': 'argument_list', 'children': []}; {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '106']}; {'id': '99', 'type': 'attribute', 'children': ['100', '105']}; {'id': '100', 'type': 'subscript', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'analysistype'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'rawblastresults'}; {'id': '106', 'type': 'call', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '108', 'type': 'argument_list', 'children': []}; {'id': '109', 'type': 'for_statement', 'children': ['110', '111', '122']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '111', 'type': 'call', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'SeqIO'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'parse'}; {'id': '115', 'type': 'argument_list', 'children': ['116', '121']}; {'id': '116', 'type': 'attribute', 'children': ['117', '120']}; {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'general'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'bestassemblyfile'}; {'id': '121', 'type': 'string', 'children': [], 'value': "'fasta'"}; {'id': '122', 'type': 'block', 'children': ['123']}; {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '130']}; {'id': '125', 'type': 'subscript', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'record'}; {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '130', 'type': 'call', 'children': ['131', '132']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}; {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '136', 'type': 'for_statement', 'children': ['137', '138', '145', '168']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '138', 'type': 'attribute', 'children': ['139', '144']}; {'id': '139', 'type': 'subscript', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'analysistype'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'epcrresults'}; {'id': '145', 'type': 'ERROR', 'children': ['146', '149', '161']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '149', 'type': 'ERROR', 'children': ['150']}; {'id': '150', 'type': 'call', 'children': ['151', '156']}; {'id': '151', 'type': 'attribute', 'children': ['152', '155']}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'epcrparsequeue'}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'put'}; {'id': '156', 'type': 'argument_list', 'children': ['157']}; {'id': '157', 'type': 'tuple', 'children': ['158', '159', '160']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'record'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '161', 'type': 'call', 'children': ['162', '167']}; {'id': '162', 'type': 'attribute', 'children': ['163', '166']}; {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'epcrparsequeue'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '167', 'type': 'argument_list', 'children': []}; {'id': '168', 'type': 'block', 'children': [], 'value': ''}
|
def epcrparsethreads(self):
from Bio import SeqIO
for sample in self.metadata:
if sample.general.bestassemblyfile != 'NA':
threads = Thread(target=self.epcrparse, args=())
threads.setDaemon(True)
threads.start()
for sample in self.metadata:
if sample.general.bestassemblyfile != 'NA':
if sample[self.analysistype].primers != 'NA':
record = dict()
sample[self.analysistype].blastresults = dict()
sample[self.analysistype].rawblastresults = dict()
for rec in SeqIO.parse(sample.general.bestassemblyfile, 'fasta'):
record[rec.id] = str(rec.seq)
for line in sample[self.analysistype].epcrresults:
if not line.startswith('
self.epcrparsequeue.put((sample, record, line))
self.epcrparsequeue.join()
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'trimquality'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '13', '392']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'call', 'children': ['8', '11']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'string', 'children': [], 'value': '"Trimming fastq files"'}; {'id': '13', 'type': 'with_statement', 'children': ['14', '25']}; {'id': '14', 'type': 'with_clause', 'children': ['15']}; {'id': '15', 'type': 'with_item', 'children': ['16']}; {'id': '16', 'type': 'as_pattern', 'children': ['17', '23']}; {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'progressbar'}; {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'metadata'}; {'id': '23', 'type': 'as_pattern_target', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'bar'}; {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'for_statement', 'children': ['27', '28', '29']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'bar'}; {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'if_statement', 'children': ['31', '41']}; {'id': '31', 'type': 'comparison_operator', 'children': ['32', '40'], 'value': 'is'}; {'id': '32', 'type': 'call', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}; {'id': '35', 'type': 'attribute', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'general'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'fastqfiles'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '41', 'type': 'block', 'children': ['42', '53', '61', '80', '99', '137', '146', '150', '315', '336', '357', '379']}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}; {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'fastqfiles'}; {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'attribute', 'children': ['49', '52']}; {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'general'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'fastqfiles'}; {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'outputdir'}; {'id': '56', 'type': 'attribute', 'children': ['57', '60']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'general'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'outputdirectory'}; {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'assignment', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'cleanforward'}; {'id': '64', 'type': 'call', 'children': ['65', '70']}; {'id': '65', 'type': 'attribute', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '70', 'type': 'argument_list', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'outputdir'}; {'id': '72', 'type': 'call', 'children': ['73', '76']}; {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'string', 'children': [], 'value': "'{}_R1_trimmed.fastq.gz'"}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}; {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}; {'id': '81', 'type': 'assignment', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'cleanreverse'}; {'id': '83', 'type': 'call', 'children': ['84', '89']}; {'id': '84', 'type': 'attribute', 'children': ['85', '88']}; {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '89', 'type': 'argument_list', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'outputdir'}; {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}; {'id': '93', 'type': 'string', 'children': [], 'value': "'{}_R2_trimmed.fastq.gz'"}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '99', 'type': 'try_statement', 'children': ['100', '123']}; {'id': '100', 'type': 'block', 'children': ['101']}; {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'lesser_length'}; {'id': '104', 'type': 'call', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '106', 'type': 'argument_list', 'children': ['107', '115']}; {'id': '107', 'type': 'call', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'attribute', 'children': ['111', '114']}; {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'run'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'forwardlength'}; {'id': '115', 'type': 'call', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'attribute', 'children': ['119', '122']}; {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'run'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'reverselength'}; {'id': '123', 'type': 'except_clause', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '125', 'type': 'block', 'children': ['126']}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}; {'id': '127', 'type': 'assignment', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'lesser_length'}; {'id': '129', 'type': 'call', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '131', 'type': 'argument_list', 'children': ['132']}; {'id': '132', 'type': 'attribute', 'children': ['133', '136']}; {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'run'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'forwardlength'}; {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'assignment', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'min_len'}; {'id': '140', 'type': 'conditional_expression', 'children': ['141', '142', '145'], 'value': 'if'}; {'id': '141', 'type': 'integer', 'children': [], 'value': '50'}; {'id': '142', 'type': 'comparison_operator', 'children': ['143', '144'], 'value': '>='}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'lesser_length'}; {'id': '144', 'type': 'integer', 'children': [], 'value': '50'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'lesser_length'}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}; {'id': '147', 'type': 'assignment', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'trim_left'}; {'id': '149', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '150', 'type': 'try_statement', 'children': ['151', '292']}; {'id': '151', 'type': 'block', 'children': ['152']}; {'id': '152', 'type': 'if_statement', 'children': ['153', '158', '226']}; {'id': '153', 'type': 'comparison_operator', 'children': ['154', '155'], 'value': 'in'}; {'id': '154', 'type': 'string', 'children': [], 'value': "'R2'"}; {'id': '155', 'type': 'subscript', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'fastqfiles'}; {'id': '157', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '158', 'type': 'block', 'children': ['159']}; {'id': '159', 'type': 'if_statement', 'children': ['160', '169', '206']}; {'id': '160', 'type': 'not_operator', 'children': ['161']}; {'id': '161', 'type': 'call', 'children': ['162', '167']}; {'id': '162', 'type': 'attribute', 'children': ['163', '166']}; {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'isfile'}; {'id': '167', 'type': 'argument_list', 'children': ['168']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'cleanreverse'}; {'id': '169', 'type': 'block', 'children': ['170']}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}; {'id': '171', 'type': 'assignment', 'children': ['172', '178']}; {'id': '172', 'type': 'pattern_list', 'children': ['173', '174', '175', '176', '177']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '174', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '176', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'bbdukcall'}; {'id': '178', 'type': 'call', 'children': ['179', '182']}; {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'bbtools'}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'bbduk_trim'}; {'id': '182', 'type': 'argument_list', 'children': ['183', '188', '191', '194', '197', '200', '203']}; {'id': '183', 'type': 'keyword_argument', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'forward_in'}; {'id': '185', 'type': 'subscript', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'fastqfiles'}; {'id': '187', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '188', 'type': 'keyword_argument', 'children': ['189', '190']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'reverse_in'}; {'id': '190', 'type': 'None', 'children': []}; {'id': '191', 'type': 'keyword_argument', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'forward_out'}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'cleanreverse'}; {'id': '194', 'type': 'keyword_argument', 'children': ['195', '196']}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'trimq'}; {'id': '196', 'type': 'integer', 'children': [], 'value': '10'}; {'id': '197', 'type': 'keyword_argument', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'minlength'}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'min_len'}; {'id': '200', 'type': 'keyword_argument', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'forcetrimleft'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'trim_left'}; {'id': '203', 'type': 'keyword_argument', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'returncmd'}; {'id': '205', 'type': 'True', 'children': []}; {'id': '206', 'type': 'else_clause', 'children': ['207']}; {'id': '207', 'type': 'block', 'children': ['208', '214', '220']}; {'id': '208', 'type': 'expression_statement', 'children': ['209']}; {'id': '209', 'type': 'assignment', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'bbdukcall'}; {'id': '211', 'type': 'call', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '213', 'type': 'argument_list', 'children': []}; {'id': '214', 'type': 'expression_statement', 'children': ['215']}; {'id': '215', 'type': 'assignment', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '217', 'type': 'call', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '219', 'type': 'argument_list', 'children': []}; {'id': '220', 'type': 'expression_statement', 'children': ['221']}; {'id': '221', 'type': 'assignment', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '223', 'type': 'call', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '225', 'type': 'argument_list', 'children': []}; {'id': '226', 'type': 'else_clause', 'children': ['227']}; {'id': '227', 'type': 'block', 'children': ['228']}; {'id': '228', 'type': 'if_statement', 'children': ['229', '238', '272']}; {'id': '229', 'type': 'not_operator', 'children': ['230']}; {'id': '230', 'type': 'call', 'children': ['231', '236']}; {'id': '231', 'type': 'attribute', 'children': ['232', '235']}; {'id': '232', 'type': 'attribute', 'children': ['233', '234']}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'isfile'}; {'id': '236', 'type': 'argument_list', 'children': ['237']}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'cleanforward'}; {'id': '238', 'type': 'block', 'children': ['239']}; {'id': '239', 'type': 'expression_statement', 'children': ['240']}; {'id': '240', 'type': 'assignment', 'children': ['241', '247']}; {'id': '241', 'type': 'pattern_list', 'children': ['242', '243', '244', '245', '246']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '243', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '245', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'bbdukcall'}; {'id': '247', 'type': 'call', 'children': ['248', '251']}; {'id': '248', 'type': 'attribute', 'children': ['249', '250']}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'bbtools'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'bbduk_trim'}; {'id': '251', 'type': 'argument_list', 'children': ['252', '257', '260', '263', '266', '269']}; {'id': '252', 'type': 'keyword_argument', 'children': ['253', '254']}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'forward_in'}; {'id': '254', 'type': 'subscript', 'children': ['255', '256']}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'fastqfiles'}; {'id': '256', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '257', 'type': 'keyword_argument', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'forward_out'}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'cleanforward'}; {'id': '260', 'type': 'keyword_argument', 'children': ['261', '262']}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'trimq'}; {'id': '262', 'type': 'integer', 'children': [], 'value': '10'}; {'id': '263', 'type': 'keyword_argument', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'minlength'}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'min_len'}; {'id': '266', 'type': 'keyword_argument', 'children': ['267', '268']}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'forcetrimleft'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'trim_left'}; {'id': '269', 'type': 'keyword_argument', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'returncmd'}; {'id': '271', 'type': 'True', 'children': []}; {'id': '272', 'type': 'else_clause', 'children': ['273']}; {'id': '273', 'type': 'block', 'children': ['274', '280', '286']}; {'id': '274', 'type': 'expression_statement', 'children': ['275']}; {'id': '275', 'type': 'assignment', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'bbdukcall'}; {'id': '277', 'type': 'call', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '279', 'type': 'argument_list', 'children': []}; {'id': '280', 'type': 'expression_statement', 'children': ['281']}; {'id': '281', 'type': 'assignment', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '283', 'type': 'call', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '285', 'type': 'argument_list', 'children': []}; {'id': '286', 'type': 'expression_statement', 'children': ['287']}; {'id': '287', 'type': 'assignment', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '289', 'type': 'call', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '291', 'type': 'argument_list', 'children': []}; {'id': '292', 'type': 'except_clause', 'children': ['293', '296']}; {'id': '293', 'type': 'tuple', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'IndexError'}; {'id': '295', 'type': 'identifier', 'children': [], 'value': 'CalledProcessError'}; {'id': '296', 'type': 'block', 'children': ['297', '303', '309']}; {'id': '297', 'type': 'expression_statement', 'children': ['298']}; {'id': '298', 'type': 'assignment', 'children': ['299', '300']}; {'id': '299', 'type': 'identifier', 'children': [], 'value': 'bbdukcall'}; {'id': '300', 'type': 'call', 'children': ['301', '302']}; {'id': '301', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '302', 'type': 'argument_list', 'children': []}; {'id': '303', 'type': 'expression_statement', 'children': ['304']}; {'id': '304', 'type': 'assignment', 'children': ['305', '306']}; {'id': '305', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '306', 'type': 'call', 'children': ['307', '308']}; {'id': '307', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '308', 'type': 'argument_list', 'children': []}; {'id': '309', 'type': 'expression_statement', 'children': ['310']}; {'id': '310', 'type': 'assignment', 'children': ['311', '312']}; {'id': '311', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '312', 'type': 'call', 'children': ['313', '314']}; {'id': '313', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '314', 'type': 'argument_list', 'children': []}; {'id': '315', 'type': 'expression_statement', 'children': ['316']}; {'id': '316', 'type': 'call', 'children': ['317', '318']}; {'id': '317', 'type': 'identifier', 'children': [], 'value': 'write_to_logfile'}; {'id': '318', 'type': 'argument_list', 'children': ['319', '320', '321', '324', '329', '334', '335']}; {'id': '319', 'type': 'identifier', 'children': [], 'value': 'bbdukcall'}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'bbdukcall'}; {'id': '321', 'type': 'attribute', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '323', 'type': 'identifier', 'children': [], 'value': 'logfile'}; {'id': '324', 'type': 'attribute', 'children': ['325', '328']}; {'id': '325', 'type': 'attribute', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '327', 'type': 'identifier', 'children': [], 'value': 'general'}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'logout'}; {'id': '329', 'type': 'attribute', 'children': ['330', '333']}; {'id': '330', 'type': 'attribute', 'children': ['331', '332']}; {'id': '331', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'general'}; {'id': '333', 'type': 'identifier', 'children': [], 'value': 'logerr'}; {'id': '334', 'type': 'None', 'children': []}; {'id': '335', 'type': 'None', 'children': []}; {'id': '336', 'type': 'expression_statement', 'children': ['337']}; {'id': '337', 'type': 'call', 'children': ['338', '339']}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'write_to_logfile'}; {'id': '339', 'type': 'argument_list', 'children': ['340', '341', '342', '345', '350', '355', '356']}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '341', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '342', 'type': 'attribute', 'children': ['343', '344']}; {'id': '343', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'logfile'}; {'id': '345', 'type': 'attribute', 'children': ['346', '349']}; {'id': '346', 'type': 'attribute', 'children': ['347', '348']}; {'id': '347', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'general'}; {'id': '349', 'type': 'identifier', 'children': [], 'value': 'logout'}; {'id': '350', 'type': 'attribute', 'children': ['351', '354']}; {'id': '351', 'type': 'attribute', 'children': ['352', '353']}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '353', 'type': 'identifier', 'children': [], 'value': 'general'}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'logerr'}; {'id': '355', 'type': 'None', 'children': []}; {'id': '356', 'type': 'None', 'children': []}; {'id': '357', 'type': 'expression_statement', 'children': ['358']}; {'id': '358', 'type': 'assignment', 'children': ['359', '360']}; {'id': '359', 'type': 'identifier', 'children': [], 'value': 'trimmedfastqfiles'}; {'id': '360', 'type': 'call', 'children': ['361', '362']}; {'id': '361', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '362', 'type': 'argument_list', 'children': ['363']}; {'id': '363', 'type': 'call', 'children': ['364', '365']}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'glob'}; {'id': '365', 'type': 'argument_list', 'children': ['366']}; {'id': '366', 'type': 'call', 'children': ['367', '372']}; {'id': '367', 'type': 'attribute', 'children': ['368', '371']}; {'id': '368', 'type': 'attribute', 'children': ['369', '370']}; {'id': '369', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '371', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '372', 'type': 'argument_list', 'children': ['373', '378']}; {'id': '373', 'type': 'attribute', 'children': ['374', '377']}; {'id': '374', 'type': 'attribute', 'children': ['375', '376']}; {'id': '375', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '376', 'type': 'identifier', 'children': [], 'value': 'general'}; {'id': '377', 'type': 'identifier', 'children': [], 'value': 'outputdirectory'}; {'id': '378', 'type': 'string', 'children': [], 'value': "'*trimmed.fastq.gz'"}; {'id': '379', 'type': 'expression_statement', 'children': ['380']}; {'id': '380', 'type': 'assignment', 'children': ['381', '386']}; {'id': '381', 'type': 'attribute', 'children': ['382', '385']}; {'id': '382', 'type': 'attribute', 'children': ['383', '384']}; {'id': '383', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'general'}; {'id': '385', 'type': 'identifier', 'children': [], 'value': 'trimmedfastqfiles'}; {'id': '386', 'type': 'conditional_expression', 'children': ['387', '388', '389'], 'value': 'if'}; {'id': '387', 'type': 'identifier', 'children': [], 'value': 'trimmedfastqfiles'}; {'id': '388', 'type': 'identifier', 'children': [], 'value': 'trimmedfastqfiles'}; {'id': '389', 'type': 'call', 'children': ['390', '391']}; {'id': '390', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '391', 'type': 'argument_list', 'children': []}; {'id': '392', 'type': 'expression_statement', 'children': ['393']}; {'id': '393', 'type': 'call', 'children': ['394', '397']}; {'id': '394', 'type': 'attribute', 'children': ['395', '396']}; {'id': '395', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '396', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '397', 'type': 'argument_list', 'children': ['398']}; {'id': '398', 'type': 'string', 'children': [], 'value': "'Fastq files trimmed'"}
|
def trimquality(self):
logging.info("Trimming fastq files")
with progressbar(self.metadata) as bar:
for sample in bar:
if type(sample.general.fastqfiles) is list:
fastqfiles = sorted(sample.general.fastqfiles)
outputdir = sample.general.outputdirectory
cleanforward = os.path.join(outputdir, '{}_R1_trimmed.fastq.gz'.format(sample.name))
cleanreverse = os.path.join(outputdir, '{}_R2_trimmed.fastq.gz'.format(sample.name))
try:
lesser_length = min(int(sample.run.forwardlength), int(sample.run.reverselength))
except ValueError:
lesser_length = int(sample.run.forwardlength)
min_len = 50 if lesser_length >= 50 else lesser_length
trim_left = 0
try:
if 'R2' in fastqfiles[0]:
if not os.path.isfile(cleanreverse):
out, \
err, \
bbdukcall = bbtools.bbduk_trim(forward_in=fastqfiles[0],
reverse_in=None,
forward_out=cleanreverse,
trimq=10,
minlength=min_len,
forcetrimleft=trim_left,
returncmd=True)
else:
bbdukcall = str()
out = str()
err = str()
else:
if not os.path.isfile(cleanforward):
out, \
err, \
bbdukcall = bbtools.bbduk_trim(forward_in=fastqfiles[0],
forward_out=cleanforward,
trimq=10,
minlength=min_len,
forcetrimleft=trim_left,
returncmd=True)
else:
bbdukcall = str()
out = str()
err = str()
except (IndexError, CalledProcessError):
bbdukcall = str()
out = str()
err = str()
write_to_logfile(bbdukcall, bbdukcall, self.logfile, sample.general.logout, sample.general.logerr,
None, None)
write_to_logfile(out, err, self.logfile, sample.general.logout, sample.general.logerr, None, None)
trimmedfastqfiles = sorted(glob(os.path.join(sample.general.outputdirectory, '*trimmed.fastq.gz')))
sample.general.trimmedfastqfiles = trimmedfastqfiles if trimmedfastqfiles else list()
logging.info('Fastq files trimmed')
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'contamination_finder'}; {'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': 'input_path'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'report_path'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'block', 'children': ['12', '19', '36', '59', '72', '84', '192', '210', '395']}; {'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': 'logging'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'string', 'children': [], 'value': "'Calculating contamination in reads'"}; {'id': '19', 'type': 'if_statement', 'children': ['20', '23', '28']}; {'id': '20', 'type': 'comparison_operator', 'children': ['21', '22'], 'value': 'is'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'input_path'}; {'id': '22', 'type': 'None', 'children': []}; {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}; {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'input_dir'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'input_path'}; {'id': '28', 'type': 'else_clause', 'children': ['29']}; {'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': 'input_dir'}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '36', 'type': 'if_statement', 'children': ['37', '40', '45']}; {'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': 'is'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'report_path'}; {'id': '39', 'type': 'None', 'children': []}; {'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': 'reportpath'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'report_path'}; {'id': '45', 'type': 'else_clause', 'children': ['46']}; {'id': '46', 'type': 'block', 'children': ['47']}; {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'reportpath'}; {'id': '50', 'type': 'call', 'children': ['51', '56']}; {'id': '51', 'type': 'attribute', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '56', 'type': 'argument_list', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'input_dir'}; {'id': '58', 'type': 'string', 'children': [], 'value': "'confindr'"}; {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'confindr_report'}; {'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': 'os'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '68', 'type': 'argument_list', 'children': ['69', '70', '71']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'input_dir'}; {'id': '70', 'type': 'string', 'children': [], 'value': "'confindr'"}; {'id': '71', 'type': 'string', 'children': [], 'value': "'confindr_report.csv'"}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}; {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'pipeline_report'}; {'id': '75', 'type': 'call', 'children': ['76', '81']}; {'id': '76', 'type': 'attribute', 'children': ['77', '80']}; {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '81', 'type': 'argument_list', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'reportpath'}; {'id': '83', 'type': 'string', 'children': [], 'value': "'confindr_report.csv'"}; {'id': '84', 'type': 'if_statement', 'children': ['85', '94']}; {'id': '85', 'type': 'not_operator', 'children': ['86']}; {'id': '86', 'type': 'call', 'children': ['87', '92']}; {'id': '87', 'type': 'attribute', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'isfile'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'confindr_report'}; {'id': '94', 'type': 'block', 'children': ['95', '108', '113', '150', '159', '172', '185']}; {'id': '95', 'type': 'try_statement', 'children': ['96', '104']}; {'id': '96', 'type': 'block', 'children': ['97']}; {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'call', 'children': ['99', '102']}; {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'shutil'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'rmtree'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'reportpath'}; {'id': '104', 'type': 'except_clause', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'IOError'}; {'id': '106', 'type': 'block', 'children': ['107']}; {'id': '107', 'type': 'pass_statement', 'children': []}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}; {'id': '109', 'type': 'call', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'make_path'}; {'id': '111', 'type': 'argument_list', 'children': ['112']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'reportpath'}; {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'systemcall'}; {'id': '116', 'type': 'call', 'children': ['117', '121']}; {'id': '117', 'type': 'attribute', 'children': ['118', '119', '120']}; {'id': '118', 'type': 'string', 'children': [], 'value': "'confindr.py -i {input_dir} -o {output_dir} -d {database_dir} -bf 0.05'"}; {'id': '119', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '121', 'type': 'argument_list', 'children': ['122', '125', '136']}; {'id': '122', 'type': 'keyword_argument', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'input_dir'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'input_dir'}; {'id': '125', 'type': 'keyword_argument', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'output_dir'}; {'id': '127', 'type': 'call', 'children': ['128', '133']}; {'id': '128', 'type': 'attribute', 'children': ['129', '132']}; {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '133', 'type': 'argument_list', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'input_dir'}; {'id': '135', 'type': 'string', 'children': [], 'value': "'confindr'"}; {'id': '136', 'type': 'keyword_argument', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'database_dir'}; {'id': '138', 'type': 'call', 'children': ['139', '144']}; {'id': '139', 'type': 'attribute', 'children': ['140', '143']}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '144', 'type': 'argument_list', 'children': ['145', '148', '149']}; {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'reffilepath'}; {'id': '148', 'type': 'string', 'children': [], 'value': "'ConFindr'"}; {'id': '149', 'type': 'string', 'children': [], 'value': "'databases'"}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}; {'id': '151', 'type': 'assignment', 'children': ['152', '155']}; {'id': '152', 'type': 'pattern_list', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '155', 'type': 'call', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'run_subprocess'}; {'id': '157', 'type': 'argument_list', 'children': ['158']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'systemcall'}; {'id': '159', 'type': 'expression_statement', 'children': ['160']}; {'id': '160', 'type': 'call', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'write_to_logfile'}; {'id': '162', 'type': 'argument_list', 'children': ['163', '164', '165', '168', '169', '170', '171']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'systemcall'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'systemcall'}; {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'logfile'}; {'id': '168', 'type': 'None', 'children': []}; {'id': '169', 'type': 'None', 'children': []}; {'id': '170', 'type': 'None', 'children': []}; {'id': '171', 'type': 'None', 'children': []}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}; {'id': '173', 'type': 'call', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'write_to_logfile'}; {'id': '175', 'type': 'argument_list', 'children': ['176', '177', '178', '181', '182', '183', '184']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'logfile'}; {'id': '181', 'type': 'None', 'children': []}; {'id': '182', 'type': 'None', 'children': []}; {'id': '183', 'type': 'None', 'children': []}; {'id': '184', 'type': 'None', 'children': []}; {'id': '185', 'type': 'expression_statement', 'children': ['186']}; {'id': '186', 'type': 'call', 'children': ['187', '190']}; {'id': '187', 'type': 'attribute', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '190', 'type': 'argument_list', 'children': ['191']}; {'id': '191', 'type': 'string', 'children': [], 'value': "'Contamination detection complete!'"}; {'id': '192', 'type': 'expression_statement', 'children': ['193']}; {'id': '193', 'type': 'assignment', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'confindr_results'}; {'id': '195', 'type': 'call', 'children': ['196', '209']}; {'id': '196', 'type': 'attribute', 'children': ['197', '208']}; {'id': '197', 'type': 'attribute', 'children': ['198', '207']}; {'id': '198', 'type': 'call', 'children': ['199', '202']}; {'id': '199', 'type': 'attribute', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'pandas'}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'read_csv'}; {'id': '202', 'type': 'argument_list', 'children': ['203', '204']}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'confindr_report'}; {'id': '204', 'type': 'keyword_argument', 'children': ['205', '206']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'index_col'}; {'id': '206', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'T'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'to_dict'}; {'id': '209', 'type': 'argument_list', 'children': []}; {'id': '210', 'type': 'for_statement', 'children': ['211', '212', '215']}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '212', 'type': 'attribute', 'children': ['213', '214']}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'metadata'}; {'id': '215', 'type': 'block', 'children': ['216', '224']}; {'id': '216', 'type': 'expression_statement', 'children': ['217']}; {'id': '217', 'type': 'assignment', 'children': ['218', '221']}; {'id': '218', 'type': 'attribute', 'children': ['219', '220']}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'confindr'}; {'id': '221', 'type': 'call', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'GenObject'}; {'id': '223', 'type': 'argument_list', 'children': []}; {'id': '224', 'type': 'for_statement', 'children': ['225', '226', '227']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'confindr_results'}; {'id': '227', 'type': 'block', 'children': ['228']}; {'id': '228', 'type': 'if_statement', 'children': ['229', '234']}; {'id': '229', 'type': 'comparison_operator', 'children': ['230', '233'], 'value': 'in'}; {'id': '230', 'type': 'attribute', 'children': ['231', '232']}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '234', 'type': 'block', 'children': ['235', '260', '272', '284', '322', '361']}; {'id': '235', 'type': 'expression_statement', 'children': ['236']}; {'id': '236', 'type': 'assignment', 'children': ['237', '242']}; {'id': '237', 'type': 'attribute', 'children': ['238', '241']}; {'id': '238', 'type': 'attribute', 'children': ['239', '240']}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'confindr'}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'genus'}; {'id': '242', 'type': 'conditional_expression', 'children': ['243', '248', '259'], 'value': 'if'}; {'id': '243', 'type': 'subscript', 'children': ['244', '247']}; {'id': '244', 'type': 'subscript', 'children': ['245', '246']}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'confindr_results'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '247', 'type': 'string', 'children': [], 'value': "'Genus'"}; {'id': '248', 'type': 'comparison_operator', 'children': ['249', '257', '258'], 'value': 'is'}; {'id': '249', 'type': 'call', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '251', 'type': 'argument_list', 'children': ['252']}; {'id': '252', 'type': 'subscript', 'children': ['253', '256']}; {'id': '253', 'type': 'subscript', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'confindr_results'}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '256', 'type': 'string', 'children': [], 'value': "'Genus'"}; {'id': '257', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '259', 'type': 'string', 'children': [], 'value': "'ND'"}; {'id': '260', 'type': 'expression_statement', 'children': ['261']}; {'id': '261', 'type': 'assignment', 'children': ['262', '267']}; {'id': '262', 'type': 'attribute', 'children': ['263', '266']}; {'id': '263', 'type': 'attribute', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'confindr'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'num_contaminated_snvs'}; {'id': '267', 'type': 'subscript', 'children': ['268', '271']}; {'id': '268', 'type': 'subscript', 'children': ['269', '270']}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'confindr_results'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '271', 'type': 'string', 'children': [], 'value': "'NumContamSNVs'"}; {'id': '272', 'type': 'expression_statement', 'children': ['273']}; {'id': '273', 'type': 'assignment', 'children': ['274', '279']}; {'id': '274', 'type': 'attribute', 'children': ['275', '278']}; {'id': '275', 'type': 'attribute', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'confindr'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'contam_status'}; {'id': '279', 'type': 'subscript', 'children': ['280', '283']}; {'id': '280', 'type': 'subscript', 'children': ['281', '282']}; {'id': '281', 'type': 'identifier', 'children': [], 'value': 'confindr_results'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '283', 'type': 'string', 'children': [], 'value': "'ContamStatus'"}; {'id': '284', 'type': 'try_statement', 'children': ['285', '311']}; {'id': '285', 'type': 'block', 'children': ['286']}; {'id': '286', 'type': 'expression_statement', 'children': ['287']}; {'id': '287', 'type': 'assignment', 'children': ['288', '293']}; {'id': '288', 'type': 'attribute', 'children': ['289', '292']}; {'id': '289', 'type': 'attribute', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '291', 'type': 'identifier', 'children': [], 'value': 'confindr'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'percent_contam'}; {'id': '293', 'type': 'conditional_expression', 'children': ['294', '299', '300', '310'], 'value': 'if'}; {'id': '294', 'type': 'subscript', 'children': ['295', '298']}; {'id': '295', 'type': 'subscript', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'confindr_results'}; {'id': '297', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '298', 'type': 'string', 'children': [], 'value': "'PercentContam'"}; {'id': '299', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '300', 'type': 'comparison_operator', 'children': ['301', '309'], 'value': '!='}; {'id': '301', 'type': 'call', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '303', 'type': 'argument_list', 'children': ['304']}; {'id': '304', 'type': 'subscript', 'children': ['305', '308']}; {'id': '305', 'type': 'subscript', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'confindr_results'}; {'id': '307', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '308', 'type': 'string', 'children': [], 'value': "'PercentContam'"}; {'id': '309', 'type': 'string', 'children': [], 'value': "'nan'"}; {'id': '310', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '311', 'type': 'except_clause', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '313', 'type': 'block', 'children': ['314']}; {'id': '314', 'type': 'expression_statement', 'children': ['315']}; {'id': '315', 'type': 'assignment', 'children': ['316', '321']}; {'id': '316', 'type': 'attribute', 'children': ['317', '320']}; {'id': '317', 'type': 'attribute', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '319', 'type': 'identifier', 'children': [], 'value': 'confindr'}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'percent_contam'}; {'id': '321', 'type': 'string', 'children': [], 'value': "'ND'"}; {'id': '322', 'type': 'try_statement', 'children': ['323', '350']}; {'id': '323', 'type': 'block', 'children': ['324']}; {'id': '324', 'type': 'expression_statement', 'children': ['325']}; {'id': '325', 'type': 'assignment', 'children': ['326', '331', '332']}; {'id': '326', 'type': 'attribute', 'children': ['327', '330']}; {'id': '327', 'type': 'attribute', 'children': ['328', '329']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '329', 'type': 'identifier', 'children': [], 'value': 'confindr'}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'percent_contam_std'}; {'id': '331', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '332', 'type': 'conditional_expression', 'children': ['333', '338', '339', '349'], 'value': 'if'}; {'id': '333', 'type': 'subscript', 'children': ['334', '337']}; {'id': '334', 'type': 'subscript', 'children': ['335', '336']}; {'id': '335', 'type': 'identifier', 'children': [], 'value': 'confindr_results'}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '337', 'type': 'string', 'children': [], 'value': "'PercentContamStandardDeviation'"}; {'id': '338', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '339', 'type': 'comparison_operator', 'children': ['340', '348'], 'value': '!='}; {'id': '340', 'type': 'call', 'children': ['341', '342']}; {'id': '341', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '342', 'type': 'argument_list', 'children': ['343']}; {'id': '343', 'type': 'subscript', 'children': ['344', '347']}; {'id': '344', 'type': 'subscript', 'children': ['345', '346']}; {'id': '345', 'type': 'identifier', 'children': [], 'value': 'confindr_results'}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '347', 'type': 'string', 'children': [], 'value': "'PercentContamStandardDeviation'"}; {'id': '348', 'type': 'string', 'children': [], 'value': "'nan'"}; {'id': '349', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '350', 'type': 'except_clause', 'children': ['351', '352']}; {'id': '351', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '352', 'type': 'block', 'children': ['353']}; {'id': '353', 'type': 'expression_statement', 'children': ['354']}; {'id': '354', 'type': 'assignment', 'children': ['355', '360']}; {'id': '355', 'type': 'attribute', 'children': ['356', '359']}; {'id': '356', 'type': 'attribute', 'children': ['357', '358']}; {'id': '357', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'confindr'}; {'id': '359', 'type': 'identifier', 'children': [], 'value': 'percent_contam_std'}; {'id': '360', 'type': 'string', 'children': [], 'value': "'ND'"}; {'id': '361', 'type': 'if_statement', 'children': ['362', '369', '378']}; {'id': '362', 'type': 'comparison_operator', 'children': ['363', '368'], 'value': 'is'}; {'id': '363', 'type': 'attribute', 'children': ['364', '367']}; {'id': '364', 'type': 'attribute', 'children': ['365', '366']}; {'id': '365', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'confindr'}; {'id': '367', 'type': 'identifier', 'children': [], 'value': 'contam_status'}; {'id': '368', 'type': 'True', 'children': []}; {'id': '369', 'type': 'block', 'children': ['370']}; {'id': '370', 'type': 'expression_statement', 'children': ['371']}; {'id': '371', 'type': 'assignment', 'children': ['372', '377']}; {'id': '372', 'type': 'attribute', 'children': ['373', '376']}; {'id': '373', 'type': 'attribute', 'children': ['374', '375']}; {'id': '374', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '375', 'type': 'identifier', 'children': [], 'value': 'confindr'}; {'id': '376', 'type': 'identifier', 'children': [], 'value': 'contam_status'}; {'id': '377', 'type': 'string', 'children': [], 'value': "'Contaminated'"}; {'id': '378', 'type': 'elif_clause', 'children': ['379', '386']}; {'id': '379', 'type': 'comparison_operator', 'children': ['380', '385'], 'value': 'is'}; {'id': '380', 'type': 'attribute', 'children': ['381', '384']}; {'id': '381', 'type': 'attribute', 'children': ['382', '383']}; {'id': '382', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '383', 'type': 'identifier', 'children': [], 'value': 'confindr'}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'contam_status'}; {'id': '385', 'type': 'False', 'children': []}; {'id': '386', 'type': 'block', 'children': ['387']}; {'id': '387', 'type': 'expression_statement', 'children': ['388']}; {'id': '388', 'type': 'assignment', 'children': ['389', '394']}; {'id': '389', 'type': 'attribute', 'children': ['390', '393']}; {'id': '390', 'type': 'attribute', 'children': ['391', '392']}; {'id': '391', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '392', 'type': 'identifier', 'children': [], 'value': 'confindr'}; {'id': '393', 'type': 'identifier', 'children': [], 'value': 'contam_status'}; {'id': '394', 'type': 'string', 'children': [], 'value': "'Clean'"}; {'id': '395', 'type': 'with_statement', 'children': ['396', '406']}; {'id': '396', 'type': 'with_clause', 'children': ['397']}; {'id': '397', 'type': 'with_item', 'children': ['398']}; {'id': '398', 'type': 'as_pattern', 'children': ['399', '404']}; {'id': '399', 'type': 'call', 'children': ['400', '401']}; {'id': '400', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '401', 'type': 'argument_list', 'children': ['402', '403']}; {'id': '402', 'type': 'identifier', 'children': [], 'value': 'pipeline_report'}; {'id': '403', 'type': 'string', 'children': [], 'value': "'w'"}; {'id': '404', 'type': 'as_pattern_target', 'children': ['405']}; {'id': '405', 'type': 'identifier', 'children': [], 'value': 'csv'}; {'id': '406', 'type': 'block', 'children': ['407', '411', '465']}; {'id': '407', 'type': 'expression_statement', 'children': ['408']}; {'id': '408', 'type': 'assignment', 'children': ['409', '410']}; {'id': '409', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '410', 'type': 'string', 'children': [], 'value': "'Strain,Genus,NumContamSNVs,ContamStatus,PercentContam,PercentContamSTD\\n'"}; {'id': '411', 'type': 'for_statement', 'children': ['412', '413', '416']}; {'id': '412', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '413', 'type': 'attribute', 'children': ['414', '415']}; {'id': '414', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '415', 'type': 'identifier', 'children': [], 'value': 'metadata'}; {'id': '416', 'type': 'block', 'children': ['417']}; {'id': '417', 'type': 'expression_statement', 'children': ['418']}; {'id': '418', 'type': 'augmented_assignment', 'children': ['419', '420'], 'value': '+='}; {'id': '419', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '420', 'type': 'call', 'children': ['421', '424']}; {'id': '421', 'type': 'attribute', 'children': ['422', '423']}; {'id': '422', 'type': 'string', 'children': [], 'value': "'{str},{genus},{numcontamsnv},{status},{pc},{pcs}\\n'"}; {'id': '423', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '424', 'type': 'argument_list', 'children': ['425', '430', '437', '444', '451', '458']}; {'id': '425', 'type': 'keyword_argument', 'children': ['426', '427']}; {'id': '426', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '427', 'type': 'attribute', 'children': ['428', '429']}; {'id': '428', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '429', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '430', 'type': 'keyword_argument', 'children': ['431', '432']}; {'id': '431', 'type': 'identifier', 'children': [], 'value': 'genus'}; {'id': '432', 'type': 'attribute', 'children': ['433', '436']}; {'id': '433', 'type': 'attribute', 'children': ['434', '435']}; {'id': '434', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '435', 'type': 'identifier', 'children': [], 'value': 'confindr'}; {'id': '436', 'type': 'identifier', 'children': [], 'value': 'genus'}; {'id': '437', 'type': 'keyword_argument', 'children': ['438', '439']}; {'id': '438', 'type': 'identifier', 'children': [], 'value': 'numcontamsnv'}; {'id': '439', 'type': 'attribute', 'children': ['440', '443']}; {'id': '440', 'type': 'attribute', 'children': ['441', '442']}; {'id': '441', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '442', 'type': 'identifier', 'children': [], 'value': 'confindr'}; {'id': '443', 'type': 'identifier', 'children': [], 'value': 'num_contaminated_snvs'}; {'id': '444', 'type': 'keyword_argument', 'children': ['445', '446']}; {'id': '445', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '446', 'type': 'attribute', 'children': ['447', '450']}; {'id': '447', 'type': 'attribute', 'children': ['448', '449']}; {'id': '448', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '449', 'type': 'identifier', 'children': [], 'value': 'confindr'}; {'id': '450', 'type': 'identifier', 'children': [], 'value': 'contam_status'}; {'id': '451', 'type': 'keyword_argument', 'children': ['452', '453']}; {'id': '452', 'type': 'identifier', 'children': [], 'value': 'pc'}; {'id': '453', 'type': 'attribute', 'children': ['454', '457']}; {'id': '454', 'type': 'attribute', 'children': ['455', '456']}; {'id': '455', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '456', 'type': 'identifier', 'children': [], 'value': 'confindr'}; {'id': '457', 'type': 'identifier', 'children': [], 'value': 'percent_contam'}; {'id': '458', 'type': 'keyword_argument', 'children': ['459', '460']}; {'id': '459', 'type': 'identifier', 'children': [], 'value': 'pcs'}; {'id': '460', 'type': 'attribute', 'children': ['461', '464']}; {'id': '461', 'type': 'attribute', 'children': ['462', '463']}; {'id': '462', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '463', 'type': 'identifier', 'children': [], 'value': 'confindr'}; {'id': '464', 'type': 'identifier', 'children': [], 'value': 'percent_contam_std'}; {'id': '465', 'type': 'expression_statement', 'children': ['466']}; {'id': '466', 'type': 'call', 'children': ['467', '470']}; {'id': '467', 'type': 'attribute', 'children': ['468', '469']}; {'id': '468', 'type': 'identifier', 'children': [], 'value': 'csv'}; {'id': '469', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '470', 'type': 'argument_list', 'children': ['471']}; {'id': '471', 'type': 'identifier', 'children': [], 'value': 'data'}
|
def contamination_finder(self, input_path=None, report_path=None):
logging.info('Calculating contamination in reads')
if input_path is not None:
input_dir = input_path
else:
input_dir = self.path
if report_path is not None:
reportpath = report_path
else:
reportpath = os.path.join(input_dir, 'confindr')
confindr_report = os.path.join(input_dir, 'confindr', 'confindr_report.csv')
pipeline_report = os.path.join(reportpath, 'confindr_report.csv')
if not os.path.isfile(confindr_report):
try:
shutil.rmtree(reportpath)
except IOError:
pass
make_path(reportpath)
systemcall = 'confindr.py -i {input_dir} -o {output_dir} -d {database_dir} -bf 0.05'\
.format(input_dir=input_dir,
output_dir=os.path.join(input_dir, 'confindr'),
database_dir=os.path.join(self.reffilepath, 'ConFindr', 'databases'))
out, err = run_subprocess(systemcall)
write_to_logfile(systemcall, systemcall, self.logfile, None, None, None, None)
write_to_logfile(out, err, self.logfile, None, None, None, None)
logging.info('Contamination detection complete!')
confindr_results = pandas.read_csv(confindr_report, index_col=0).T.to_dict()
for sample in self.metadata:
sample.confindr = GenObject()
for line in confindr_results:
if sample.name in line:
sample.confindr.genus = confindr_results[line]['Genus'] if type(confindr_results[line]['Genus']) \
is not float else 'ND'
sample.confindr.num_contaminated_snvs = confindr_results[line]['NumContamSNVs']
sample.confindr.contam_status = confindr_results[line]['ContamStatus']
try:
sample.confindr.percent_contam = confindr_results[line]['PercentContam'] if \
str(confindr_results[line]['PercentContam']) != 'nan' else 0
except KeyError:
sample.confindr.percent_contam = 'ND'
try:
sample.confindr.percent_contam_std = \
confindr_results[line]['PercentContamStandardDeviation'] if \
str(confindr_results[line]['PercentContamStandardDeviation']) != 'nan' else 0
except KeyError:
sample.confindr.percent_contam_std = 'ND'
if sample.confindr.contam_status is True:
sample.confindr.contam_status = 'Contaminated'
elif sample.confindr.contam_status is False:
sample.confindr.contam_status = 'Clean'
with open(pipeline_report, 'w') as csv:
data = 'Strain,Genus,NumContamSNVs,ContamStatus,PercentContam,PercentContamSTD\n'
for sample in self.metadata:
data += '{str},{genus},{numcontamsnv},{status},{pc},{pcs}\n'.format(
str=sample.name,
genus=sample.confindr.genus,
numcontamsnv=sample.confindr.num_contaminated_snvs,
status=sample.confindr.contam_status,
pc=sample.confindr.percent_contam,
pcs=sample.confindr.percent_contam_std
)
csv.write(data)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'subclass_genesis'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'genesisclass'}; {'id': '6', 'type': 'block', 'children': ['7', '454', '465']}; {'id': '7', 'type': 'class_definition', 'children': ['8', '9', '11']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'MayaGenesisWin'}; {'id': '9', 'type': 'argument_list', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'genesisclass'}; {'id': '11', 'type': 'block', 'children': ['12', '25', '46', '59', '80', '146', '187', '250', '312', '362']}; {'id': '12', 'type': 'function_definition', 'children': ['13', '14', '17']}; {'id': '13', 'type': 'function_name', 'children': [], 'value': 'open_shot'}; {'id': '14', 'type': 'parameters', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'taskfile'}; {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'return_statement', 'children': ['19']}; {'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': 'open_file'}; {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'taskfile'}; {'id': '25', 'type': 'function_definition', 'children': ['26', '27', '31']}; {'id': '26', 'type': 'function_name', 'children': [], 'value': 'save_shot'}; {'id': '27', 'type': 'parameters', 'children': ['28', '29', '30']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'jbfile'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'tf'}; {'id': '31', 'type': 'block', 'children': ['32', '39']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'update_scene_node'}; {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'tf'}; {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '44']}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'save_file'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'jbfile'}; {'id': '46', 'type': 'function_definition', 'children': ['47', '48', '51']}; {'id': '47', 'type': 'function_name', 'children': [], 'value': 'open_asset'}; {'id': '48', 'type': 'parameters', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'taskfile'}; {'id': '51', 'type': 'block', 'children': ['52']}; {'id': '52', 'type': 'return_statement', 'children': ['53']}; {'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': 'open_file'}; {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'taskfile'}; {'id': '59', 'type': 'function_definition', 'children': ['60', '61', '65']}; {'id': '60', 'type': 'function_name', 'children': [], 'value': 'save_asset'}; {'id': '61', 'type': 'parameters', 'children': ['62', '63', '64']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'jbfile'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'tf'}; {'id': '65', 'type': 'block', 'children': ['66', '73']}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}; {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'update_scene_node'}; {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'tf'}; {'id': '73', 'type': 'expression_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': 'save_file'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'jbfile'}; {'id': '80', 'type': 'function_definition', 'children': ['81', '82', '85']}; {'id': '81', 'type': 'function_name', 'children': [], 'value': 'save_file'}; {'id': '82', 'type': 'parameters', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'jbfile'}; {'id': '85', 'type': 'block', 'children': ['86', '94', '105', '109', '122', '131']}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}; {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'jbfile'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'get_fullpath'}; {'id': '93', 'type': 'argument_list', 'children': []}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}; {'id': '95', 'type': 'assignment', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '97', 'type': 'call', 'children': ['98', '103']}; {'id': '98', 'type': 'attribute', 'children': ['99', '102']}; {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'expanduser'}; {'id': '103', 'type': 'argument_list', 'children': ['104']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'typ'}; {'id': '108', 'type': 'string', 'children': [], 'value': "'mayaBinary'"}; {'id': '109', 'type': 'if_statement', 'children': ['110', '117']}; {'id': '110', 'type': 'comparison_operator', 'children': ['111', '116'], 'value': '=='}; {'id': '111', 'type': 'call', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'jbfile'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'get_ext'}; {'id': '115', 'type': 'argument_list', 'children': []}; {'id': '116', 'type': 'string', 'children': [], 'value': "'ma'"}; {'id': '117', 'type': 'block', 'children': ['118']}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}; {'id': '119', 'type': 'assignment', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'typ'}; {'id': '121', 'type': 'string', 'children': [], 'value': "'mayaAscii'"}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}; {'id': '123', 'type': 'call', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'cmds'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'keyword_argument', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'rename'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'call', 'children': ['133', '136']}; {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'cmds'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '136', 'type': 'argument_list', 'children': ['137', '140', '143']}; {'id': '137', 'type': 'keyword_argument', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'save'}; {'id': '139', 'type': 'True', 'children': []}; {'id': '140', 'type': 'keyword_argument', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'defaultExtensions'}; {'id': '142', 'type': 'False', 'children': []}; {'id': '143', 'type': 'keyword_argument', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'typ'}; {'id': '146', 'type': 'function_definition', 'children': ['147', '148', '151']}; {'id': '147', 'type': 'function_name', 'children': [], 'value': 'open_file'}; {'id': '148', 'type': 'parameters', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'taskfile'}; {'id': '151', 'type': 'block', 'children': ['152', '160', '167', '185']}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}; {'id': '153', 'type': 'assignment', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '155', 'type': 'call', 'children': ['156', '159']}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'check_modified'}; {'id': '159', 'type': 'argument_list', 'children': []}; {'id': '160', 'type': 'if_statement', 'children': ['161', '164']}; {'id': '161', 'type': 'comparison_operator', 'children': ['162', '163'], 'value': 'is'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '163', 'type': 'False', 'children': []}; {'id': '164', 'type': 'block', 'children': ['165']}; {'id': '165', 'type': 'return_statement', 'children': ['166']}; {'id': '166', 'type': 'False', 'children': []}; {'id': '167', 'type': 'expression_statement', 'children': ['168']}; {'id': '168', 'type': 'call', 'children': ['169', '172']}; {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'cmds'}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '172', 'type': 'argument_list', 'children': ['173', '176', '179', '182']}; {'id': '173', 'type': 'attribute', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'taskfile'}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '176', 'type': 'keyword_argument', 'children': ['177', '178']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '178', 'type': 'True', 'children': []}; {'id': '179', 'type': 'keyword_argument', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'force'}; {'id': '181', 'type': 'True', 'children': []}; {'id': '182', 'type': 'keyword_argument', 'children': ['183', '184']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'ignoreVersion'}; {'id': '184', 'type': 'True', 'children': []}; {'id': '185', 'type': 'return_statement', 'children': ['186']}; {'id': '186', 'type': 'True', 'children': []}; {'id': '187', 'type': 'function_definition', 'children': ['188', '189', '191']}; {'id': '188', 'type': 'function_name', 'children': [], 'value': 'get_current_file'}; {'id': '189', 'type': 'parameters', 'children': ['190']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '191', 'type': 'block', 'children': ['192', '200', '205', '216']}; {'id': '192', 'type': 'expression_statement', 'children': ['193']}; {'id': '193', 'type': 'assignment', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '195', 'type': 'call', 'children': ['196', '199']}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'jbscene'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'get_current_scene_node'}; {'id': '199', 'type': 'argument_list', 'children': []}; {'id': '200', 'type': 'if_statement', 'children': ['201', '203']}; {'id': '201', 'type': 'not_operator', 'children': ['202']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '203', 'type': 'block', 'children': ['204']}; {'id': '204', 'type': 'return_statement', 'children': []}; {'id': '205', 'type': 'expression_statement', 'children': ['206']}; {'id': '206', 'type': 'assignment', 'children': ['207', '208']}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'tfid'}; {'id': '208', 'type': 'call', 'children': ['209', '212']}; {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'cmds'}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'getAttr'}; {'id': '212', 'type': 'argument_list', 'children': ['213']}; {'id': '213', 'type': 'binary_operator', 'children': ['214', '215'], 'value': '%'}; {'id': '214', 'type': 'string', 'children': [], 'value': "'%s.taskfile_id'"}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '216', 'type': 'try_statement', 'children': ['217', '229']}; {'id': '217', 'type': 'block', 'children': ['218']}; {'id': '218', 'type': 'return_statement', 'children': ['219']}; {'id': '219', 'type': 'call', 'children': ['220', '225']}; {'id': '220', 'type': 'attribute', 'children': ['221', '224']}; {'id': '221', 'type': 'attribute', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'djadapter'}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'taskfiles'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '225', 'type': 'argument_list', 'children': ['226']}; {'id': '226', 'type': 'keyword_argument', 'children': ['227', '228']}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'tfid'}; {'id': '229', 'type': 'except_clause', 'children': ['230', '237']}; {'id': '230', 'type': 'attribute', 'children': ['231', '236']}; {'id': '231', 'type': 'attribute', 'children': ['232', '235']}; {'id': '232', 'type': 'attribute', 'children': ['233', '234']}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'djadapter'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'models'}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'TaskFile'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'DoesNotExist'}; {'id': '237', 'type': 'block', 'children': ['238', '249']}; {'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': 'log'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '243', 'type': 'argument_list', 'children': ['244']}; {'id': '244', 'type': 'binary_operator', 'children': ['245', '246'], 'value': '%'}; {'id': '245', 'type': 'string', 'children': [], 'value': '"No taskfile with id %s was found. Get current scene failed. Check your jb_sceneNode \\\'%s\\\'."'}; {'id': '246', 'type': 'tuple', 'children': ['247', '248']}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'tfid'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '249', 'type': 'return_statement', 'children': []}; {'id': '250', 'type': 'function_definition', 'children': ['251', '252', '254']}; {'id': '251', 'type': 'function_name', 'children': [], 'value': 'get_scene_node'}; {'id': '252', 'type': 'parameters', 'children': ['253']}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '254', 'type': 'block', 'children': ['255', '264', '279', '287', '310']}; {'id': '255', 'type': 'expression_statement', 'children': ['256']}; {'id': '256', 'type': 'assignment', 'children': ['257', '258']}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'scenenodes'}; {'id': '258', 'type': 'call', 'children': ['259', '262']}; {'id': '259', 'type': 'attribute', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'cmds'}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'ls'}; {'id': '262', 'type': 'argument_list', 'children': ['263']}; {'id': '263', 'type': 'string', 'children': [], 'value': "':jb_sceneNode*'"}; {'id': '264', 'type': 'if_statement', 'children': ['265', '271']}; {'id': '265', 'type': 'comparison_operator', 'children': ['266', '270'], 'value': '>'}; {'id': '266', 'type': 'call', 'children': ['267', '268']}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '268', 'type': 'argument_list', 'children': ['269']}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'scenenodes'}; {'id': '270', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '271', 'type': 'block', 'children': ['272']}; {'id': '272', 'type': 'expression_statement', 'children': ['273']}; {'id': '273', 'type': 'call', 'children': ['274', '277']}; {'id': '274', 'type': 'attribute', 'children': ['275', '276']}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'cmds'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'delete'}; {'id': '277', 'type': 'argument_list', 'children': ['278']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'scenenodes'}; {'id': '279', 'type': 'expression_statement', 'children': ['280']}; {'id': '280', 'type': 'assignment', 'children': ['281', '282']}; {'id': '281', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '282', 'type': 'call', 'children': ['283', '286']}; {'id': '283', 'type': 'attribute', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'jbscene'}; {'id': '285', 'type': 'identifier', 'children': [], 'value': 'get_current_scene_node'}; {'id': '286', 'type': 'argument_list', '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': 'node'}; {'id': '290', 'type': 'None', 'children': []}; {'id': '291', 'type': 'block', 'children': ['292', '301']}; {'id': '292', 'type': 'expression_statement', 'children': ['293']}; {'id': '293', 'type': 'call', 'children': ['294', '297']}; {'id': '294', 'type': 'attribute', 'children': ['295', '296']}; {'id': '295', 'type': 'identifier', 'children': [], 'value': 'cmds'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'namespace'}; {'id': '297', 'type': 'argument_list', 'children': ['298']}; {'id': '298', 'type': 'keyword_argument', 'children': ['299', '300']}; {'id': '299', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '300', 'type': 'string', 'children': [], 'value': "':'"}; {'id': '301', 'type': 'expression_statement', 'children': ['302']}; {'id': '302', 'type': 'assignment', 'children': ['303', '304']}; {'id': '303', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '304', 'type': 'call', 'children': ['305', '308']}; {'id': '305', 'type': 'attribute', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'cmds'}; {'id': '307', 'type': 'identifier', 'children': [], 'value': 'createNode'}; {'id': '308', 'type': 'argument_list', 'children': ['309']}; {'id': '309', 'type': 'string', 'children': [], 'value': "'jb_sceneNode'"}; {'id': '310', 'type': 'return_statement', 'children': ['311']}; {'id': '311', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '312', 'type': 'function_definition', 'children': ['313', '314', '317']}; {'id': '313', 'type': 'function_name', 'children': [], 'value': 'update_scene_node'}; {'id': '314', 'type': 'parameters', 'children': ['315', '316']}; {'id': '315', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'tf'}; {'id': '317', 'type': 'block', 'children': ['318', '326', '338', '350']}; {'id': '318', 'type': 'expression_statement', 'children': ['319']}; {'id': '319', 'type': 'assignment', 'children': ['320', '321']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '321', 'type': 'call', 'children': ['322', '325']}; {'id': '322', 'type': 'attribute', 'children': ['323', '324']}; {'id': '323', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'get_scene_node'}; {'id': '325', 'type': 'argument_list', 'children': []}; {'id': '326', 'type': 'expression_statement', 'children': ['327']}; {'id': '327', 'type': 'call', 'children': ['328', '331']}; {'id': '328', 'type': 'attribute', 'children': ['329', '330']}; {'id': '329', 'type': 'identifier', 'children': [], 'value': 'cmds'}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'setAttr'}; {'id': '331', 'type': 'argument_list', 'children': ['332', '335']}; {'id': '332', 'type': 'binary_operator', 'children': ['333', '334'], 'value': '%'}; {'id': '333', 'type': 'string', 'children': [], 'value': "'%s.taskfile_id'"}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '335', 'type': 'keyword_argument', 'children': ['336', '337']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'lock'}; {'id': '337', 'type': 'False', 'children': []}; {'id': '338', 'type': 'expression_statement', 'children': ['339']}; {'id': '339', 'type': 'call', 'children': ['340', '343']}; {'id': '340', 'type': 'attribute', 'children': ['341', '342']}; {'id': '341', 'type': 'identifier', 'children': [], 'value': 'cmds'}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'setAttr'}; {'id': '343', 'type': 'argument_list', 'children': ['344', '347']}; {'id': '344', 'type': 'binary_operator', 'children': ['345', '346'], 'value': '%'}; {'id': '345', 'type': 'string', 'children': [], 'value': "'%s.taskfile_id'"}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '347', 'type': 'attribute', 'children': ['348', '349']}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'tf'}; {'id': '349', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '350', 'type': 'expression_statement', 'children': ['351']}; {'id': '351', 'type': 'call', 'children': ['352', '355']}; {'id': '352', 'type': 'attribute', 'children': ['353', '354']}; {'id': '353', 'type': 'identifier', 'children': [], 'value': 'cmds'}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'setAttr'}; {'id': '355', 'type': 'argument_list', 'children': ['356', '359']}; {'id': '356', 'type': 'binary_operator', 'children': ['357', '358'], 'value': '%'}; {'id': '357', 'type': 'string', 'children': [], 'value': "'%s.taskfile_id'"}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '359', 'type': 'keyword_argument', 'children': ['360', '361']}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'lock'}; {'id': '361', 'type': 'True', 'children': []}; {'id': '362', 'type': 'function_definition', 'children': ['363', '364', '366']}; {'id': '363', 'type': 'function_name', 'children': [], 'value': 'check_modified'}; {'id': '364', 'type': 'parameters', 'children': ['365']}; {'id': '365', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '366', 'type': 'block', 'children': ['367', '383', '397', '428', '435', '452']}; {'id': '367', 'type': 'if_statement', 'children': ['368', '380']}; {'id': '368', 'type': 'not_operator', 'children': ['369']}; {'id': '369', 'type': 'call', 'children': ['370', '373']}; {'id': '370', 'type': 'attribute', 'children': ['371', '372']}; {'id': '371', 'type': 'identifier', 'children': [], 'value': 'cmds'}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '373', 'type': 'argument_list', 'children': ['374', '377']}; {'id': '374', 'type': 'keyword_argument', 'children': ['375', '376']}; {'id': '375', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '376', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '377', 'type': 'keyword_argument', 'children': ['378', '379']}; {'id': '378', 'type': 'identifier', 'children': [], 'value': 'modified'}; {'id': '379', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '380', 'type': 'block', 'children': ['381']}; {'id': '381', 'type': 'return_statement', 'children': ['382']}; {'id': '382', 'type': 'True', 'children': []}; {'id': '383', 'type': 'expression_statement', 'children': ['384']}; {'id': '384', 'type': 'assignment', 'children': ['385', '386']}; {'id': '385', 'type': 'identifier', 'children': [], 'value': 'curfile'}; {'id': '386', 'type': 'call', 'children': ['387', '390']}; {'id': '387', 'type': 'attribute', 'children': ['388', '389']}; {'id': '388', 'type': 'identifier', 'children': [], 'value': 'cmds'}; {'id': '389', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '390', 'type': 'argument_list', 'children': ['391', '394']}; {'id': '391', 'type': 'keyword_argument', 'children': ['392', '393']}; {'id': '392', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '393', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '394', 'type': 'keyword_argument', 'children': ['395', '396']}; {'id': '395', 'type': 'identifier', 'children': [], 'value': 'sceneName'}; {'id': '396', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '397', 'type': 'expression_statement', 'children': ['398']}; {'id': '398', 'type': 'assignment', 'children': ['399', '400']}; {'id': '399', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '400', 'type': 'call', 'children': ['401', '404']}; {'id': '401', 'type': 'attribute', 'children': ['402', '403']}; {'id': '402', 'type': 'identifier', 'children': [], 'value': 'cmds'}; {'id': '403', 'type': 'identifier', 'children': [], 'value': 'confirmDialog'}; {'id': '404', 'type': 'argument_list', 'children': ['405', '408', '413', '419', '422', '425']}; {'id': '405', 'type': 'keyword_argument', 'children': ['406', '407']}; {'id': '406', 'type': 'identifier', 'children': [], 'value': 'title'}; {'id': '407', 'type': 'string', 'children': [], 'value': "'Save Changes'"}; {'id': '408', 'type': 'keyword_argument', 'children': ['409', '410']}; {'id': '409', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '410', 'type': 'binary_operator', 'children': ['411', '412'], 'value': '%'}; {'id': '411', 'type': 'string', 'children': [], 'value': "'Save changes to %s?'"}; {'id': '412', 'type': 'identifier', 'children': [], 'value': 'curfile'}; {'id': '413', 'type': 'keyword_argument', 'children': ['414', '415']}; {'id': '414', 'type': 'identifier', 'children': [], 'value': 'button'}; {'id': '415', 'type': 'list', 'children': ['416', '417', '418'], 'value': "['Save', 'Don\\'t Save' ,'Cancel']"}; {'id': '416', 'type': 'string', 'children': [], 'value': "'Save'"}; {'id': '417', 'type': 'string', 'children': [], 'value': "'Don\\'t Save'"}; {'id': '418', 'type': 'string', 'children': [], 'value': "'Cancel'"}; {'id': '419', 'type': 'keyword_argument', 'children': ['420', '421']}; {'id': '420', 'type': 'identifier', 'children': [], 'value': 'defaultButton'}; {'id': '421', 'type': 'string', 'children': [], 'value': "'Save'"}; {'id': '422', 'type': 'keyword_argument', 'children': ['423', '424']}; {'id': '423', 'type': 'identifier', 'children': [], 'value': 'cancelButton'}; {'id': '424', 'type': 'string', 'children': [], 'value': "'Cancel'"}; {'id': '425', 'type': 'keyword_argument', 'children': ['426', '427']}; {'id': '426', 'type': 'identifier', 'children': [], 'value': 'dismissString'}; {'id': '427', 'type': 'string', 'children': [], 'value': "'Cancel'"}; {'id': '428', 'type': 'if_statement', 'children': ['429', '432']}; {'id': '429', 'type': 'comparison_operator', 'children': ['430', '431'], 'value': '=='}; {'id': '430', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '431', 'type': 'string', 'children': [], 'value': "'Cancel'"}; {'id': '432', 'type': 'block', 'children': ['433']}; {'id': '433', 'type': 'return_statement', 'children': ['434']}; {'id': '434', 'type': 'False', 'children': []}; {'id': '435', 'type': 'if_statement', 'children': ['436', '439']}; {'id': '436', 'type': 'comparison_operator', 'children': ['437', '438'], 'value': '=='}; {'id': '437', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '438', 'type': 'string', 'children': [], 'value': "'Save'"}; {'id': '439', 'type': 'block', 'children': ['440']}; {'id': '440', 'type': 'expression_statement', 'children': ['441']}; {'id': '441', 'type': 'call', 'children': ['442', '445']}; {'id': '442', 'type': 'attribute', 'children': ['443', '444']}; {'id': '443', 'type': 'identifier', 'children': [], 'value': 'cmds'}; {'id': '444', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '445', 'type': 'argument_list', 'children': ['446', '449']}; {'id': '446', 'type': 'keyword_argument', 'children': ['447', '448']}; {'id': '447', 'type': 'identifier', 'children': [], 'value': 'save'}; {'id': '448', 'type': 'True', 'children': []}; {'id': '449', 'type': 'keyword_argument', 'children': ['450', '451']}; {'id': '450', 'type': 'identifier', 'children': [], 'value': 'force'}; {'id': '451', 'type': 'True', 'children': []}; {'id': '452', 'type': 'return_statement', 'children': ['453']}; {'id': '453', 'type': 'True', 'children': []}; {'id': '454', 'type': 'expression_statement', 'children': ['455']}; {'id': '455', 'type': 'call', 'children': ['456', '459']}; {'id': '456', 'type': 'attribute', 'children': ['457', '458']}; {'id': '457', 'type': 'identifier', 'children': [], 'value': 'MayaGenesisWin'}; {'id': '458', 'type': 'identifier', 'children': [], 'value': 'set_filetype'}; {'id': '459', 'type': 'argument_list', 'children': ['460']}; {'id': '460', 'type': 'subscript', 'children': ['461', '464']}; {'id': '461', 'type': 'attribute', 'children': ['462', '463']}; {'id': '462', 'type': 'identifier', 'children': [], 'value': 'djadapter'}; {'id': '463', 'type': 'identifier', 'children': [], 'value': 'FILETYPES'}; {'id': '464', 'type': 'string', 'children': [], 'value': "'mayamainscene'"}; {'id': '465', 'type': 'return_statement', 'children': ['466']}; {'id': '466', 'type': 'identifier', 'children': [], 'value': 'MayaGenesisWin'}
|
def subclass_genesis(self, genesisclass):
class MayaGenesisWin(genesisclass):
def open_shot(self, taskfile):
return self.open_file(taskfile)
def save_shot(self, jbfile, tf):
self.update_scene_node(tf)
self.save_file(jbfile)
def open_asset(self, taskfile):
return self.open_file(taskfile)
def save_asset(self, jbfile, tf):
self.update_scene_node(tf)
self.save_file(jbfile)
def save_file(self, jbfile):
p = jbfile.get_fullpath()
p = os.path.expanduser(p)
typ = 'mayaBinary'
if jbfile.get_ext() == 'ma':
typ = 'mayaAscii'
cmds.file(rename = p)
cmds.file(save=True, defaultExtensions=False, type=typ)
def open_file(self, taskfile):
r = self.check_modified()
if r is False:
return False
cmds.file(taskfile.path, open=True, force=True, ignoreVersion=True)
return True
def get_current_file(self, ):
node = jbscene.get_current_scene_node()
if not node:
return
tfid = cmds.getAttr('%s.taskfile_id' % node)
try:
return djadapter.taskfiles.get(id=tfid)
except djadapter.models.TaskFile.DoesNotExist:
log.error("No taskfile with id %s was found. Get current scene failed. Check your jb_sceneNode \'%s\'." % (tfid, node))
return
def get_scene_node(self, ):
scenenodes = cmds.ls(':jb_sceneNode*')
if len(scenenodes) > 1:
cmds.delete(scenenodes)
node = jbscene.get_current_scene_node()
if node is None:
cmds.namespace(set=':')
node = cmds.createNode('jb_sceneNode')
return node
def update_scene_node(self, tf):
node = self.get_scene_node()
cmds.setAttr('%s.taskfile_id' % node, lock=False)
cmds.setAttr('%s.taskfile_id' % node, tf.id)
cmds.setAttr('%s.taskfile_id' % node, lock=True)
def check_modified(self, ):
if not cmds.file(q=1, modified=1):
return True
curfile = cmds.file(q=1, sceneName=1)
r = cmds.confirmDialog( title='Save Changes', message='Save changes to %s?' % curfile,
button=['Save', 'Don\'t Save' ,'Cancel'],
defaultButton='Save', cancelButton='Cancel',
dismissString='Cancel')
if r == 'Cancel':
return False
if r == 'Save':
cmds.file(save=True, force=True)
return True
MayaGenesisWin.set_filetype(djadapter.FILETYPES['mayamainscene'],)
return MayaGenesisWin
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '35', '37']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'override_options'}; {'id': '3', 'type': 'parameters', 'children': ['4', '8', '18', '30']}; {'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '6', 'type': 'type', 'children': ['7']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'DictLike'}; {'id': '8', 'type': 'typed_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'selected_options'}; {'id': '10', 'type': 'type', 'children': ['11']}; {'id': '11', 'type': 'generic_type', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'Tuple'}; {'id': '13', 'type': 'type_parameter', 'children': ['14', '16']}; {'id': '14', 'type': 'type', 'children': ['15']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'Any'}; {'id': '16', 'type': 'type', 'children': ['17']}; {'id': '17', 'type': 'ellipsis', 'children': [], 'value': '...'}; {'id': '18', 'type': 'typed_parameter', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'set_of_possible_options'}; {'id': '20', 'type': 'type', 'children': ['21']}; {'id': '21', 'type': 'generic_type', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'Tuple'}; {'id': '23', 'type': 'type_parameter', 'children': ['24', '28']}; {'id': '24', 'type': 'type', 'children': ['25']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'enum'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'Enum'}; {'id': '28', 'type': 'type', 'children': ['29']}; {'id': '29', 'type': 'ellipsis', 'children': [], 'value': '...'}; {'id': '30', 'type': 'typed_default_parameter', 'children': ['31', '32', '34']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'config_containing_override'}; {'id': '32', 'type': 'type', 'children': ['33']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'DictLike'}; {'id': '34', 'type': 'None', 'children': []}; {'id': '35', 'type': 'type', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'DictLike'}; {'id': '37', 'type': 'block', 'children': ['38', '47', '56', '65', '72', '232']}; {'id': '38', 'type': 'if_statement', 'children': ['39', '42']}; {'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': 'is'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'config_containing_override'}; {'id': '41', 'type': 'None', 'children': []}; {'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': 'config_containing_override'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'override_opts'}; {'id': '50', 'type': 'call', 'children': ['51', '54']}; {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'config_containing_override'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}; {'id': '55', 'type': 'string', 'children': [], 'value': '"override"'}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}; {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'override_dict'}; {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'determine_override_options'}; {'id': '61', 'type': 'argument_list', 'children': ['62', '63', '64']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'selected_options'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'override_opts'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'set_of_possible_options'}; {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'call', 'children': ['67', '70']}; {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}; {'id': '71', 'type': 'string', 'children': [], 'value': 'f"override_dict: {override_dict}"'}; {'id': '72', 'type': 'for_statement', 'children': ['73', '76', '81']}; {'id': '73', 'type': 'pattern_list', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '76', 'type': 'call', 'children': ['77', '80']}; {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'override_dict'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '80', 'type': 'argument_list', 'children': []}; {'id': '81', 'type': 'block', 'children': ['82']}; {'id': '82', 'type': 'if_statement', 'children': ['83', '86', '224']}; {'id': '83', 'type': 'comparison_operator', 'children': ['84', '85'], 'value': 'in'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '86', 'type': 'block', 'children': ['87']}; {'id': '87', 'type': 'try_statement', 'children': ['88', '215']}; {'id': '88', 'type': 'block', 'children': ['89', '95', '102']}; {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'attribute', 'children': ['91', '94']}; {'id': '91', 'type': 'subscript', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'anchor'}; {'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': 'logger'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}; {'id': '101', 'type': 'string', 'children': [], 'value': 'f"type: {type(config[k])}, k: {k}"'}; {'id': '102', 'type': 'if_statement', 'children': ['103', '110', '155', '183', '208']}; {'id': '103', 'type': 'call', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '105', 'type': 'argument_list', 'children': ['106', '109']}; {'id': '106', 'type': 'subscript', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '110', 'type': 'block', 'children': ['111', '118']}; {'id': '111', 'type': 'delete_statement', 'children': ['112']}; {'id': '112', 'type': 'subscript', 'children': ['113', '116']}; {'id': '113', 'type': 'subscript', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '116', 'type': 'slice', 'children': ['117']}; {'id': '117', 'type': 'colon', 'children': []}; {'id': '118', 'type': 'if_statement', 'children': ['119', '130', '142']}; {'id': '119', 'type': 'call', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '121', 'type': 'argument_list', 'children': ['122', '125']}; {'id': '122', 'type': 'subscript', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'override_dict'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '125', 'type': 'tuple', 'children': ['126', '127', '128', '129']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'bool'}; {'id': '130', 'type': 'block', 'children': ['131']}; {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'call', 'children': ['133', '138']}; {'id': '133', 'type': 'attribute', 'children': ['134', '137']}; {'id': '134', 'type': 'subscript', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '138', 'type': 'argument_list', 'children': ['139']}; {'id': '139', 'type': 'subscript', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'override_dict'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '142', 'type': 'else_clause', 'children': ['143']}; {'id': '143', 'type': 'block', 'children': ['144']}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}; {'id': '145', 'type': 'call', 'children': ['146', '151']}; {'id': '146', 'type': 'attribute', 'children': ['147', '150']}; {'id': '147', 'type': 'subscript', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '151', 'type': 'argument_list', 'children': ['152']}; {'id': '152', 'type': 'subscript', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'override_dict'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '155', 'type': 'elif_clause', 'children': ['156', '163']}; {'id': '156', 'type': 'call', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '158', 'type': 'argument_list', 'children': ['159', '162']}; {'id': '159', 'type': 'subscript', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '163', 'type': 'block', 'children': ['164', '172']}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}; {'id': '165', 'type': 'call', 'children': ['166', '171']}; {'id': '166', 'type': 'attribute', 'children': ['167', '170']}; {'id': '167', 'type': 'subscript', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'clear'}; {'id': '171', 'type': 'argument_list', 'children': []}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}; {'id': '173', 'type': 'call', 'children': ['174', '179']}; {'id': '174', 'type': 'attribute', 'children': ['175', '178']}; {'id': '175', 'type': 'subscript', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '179', 'type': 'argument_list', 'children': ['180']}; {'id': '180', 'type': 'subscript', 'children': ['181', '182']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'override_dict'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '183', 'type': 'elif_clause', 'children': ['184', '194']}; {'id': '184', 'type': 'call', 'children': ['185', '186']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '186', 'type': 'argument_list', 'children': ['187', '190']}; {'id': '187', 'type': 'subscript', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '190', 'type': 'tuple', 'children': ['191', '192', '193']}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'bool'}; {'id': '194', 'type': 'block', 'children': ['195', '202']}; {'id': '195', 'type': 'expression_statement', 'children': ['196']}; {'id': '196', 'type': 'call', 'children': ['197', '200']}; {'id': '197', 'type': 'attribute', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '200', 'type': 'argument_list', 'children': ['201']}; {'id': '201', 'type': 'string', 'children': [], 'value': '"Overwriting YAML anchor object. It is currently unclear how to reassign this value."'}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}; {'id': '203', 'type': 'assignment', 'children': ['204', '207']}; {'id': '204', 'type': 'subscript', 'children': ['205', '206']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '208', 'type': 'else_clause', 'children': ['209']}; {'id': '209', 'type': 'block', 'children': ['210']}; {'id': '210', 'type': 'raise_statement', 'children': ['211']}; {'id': '211', 'type': 'call', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '213', 'type': 'argument_list', 'children': ['214']}; {'id': '214', 'type': 'string', 'children': [], 'value': 'f"Object {k} (type {type(config[k])}) somehow has an anchor, but is something other than a list or dict. Attempting to assign directly to it."'}; {'id': '215', 'type': 'except_clause', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}; {'id': '217', 'type': 'block', 'children': ['218']}; {'id': '218', 'type': 'expression_statement', 'children': ['219']}; {'id': '219', 'type': 'assignment', 'children': ['220', '223']}; {'id': '220', 'type': 'subscript', 'children': ['221', '222']}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '224', 'type': 'else_clause', 'children': ['225']}; {'id': '225', 'type': 'block', 'children': ['226']}; {'id': '226', 'type': 'raise_statement', 'children': ['227']}; {'id': '227', 'type': 'call', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '229', 'type': 'argument_list', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '231', 'type': 'string', 'children': [], 'value': 'f"Trying to override key \\"{k}\\" that it is not in the config."'}; {'id': '232', 'type': 'return_statement', 'children': ['233']}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'config'}
|
def override_options(config: DictLike, selected_options: Tuple[Any, ...], set_of_possible_options: Tuple[enum.Enum, ...], config_containing_override: DictLike = None) -> DictLike:
if config_containing_override is None:
config_containing_override = config
override_opts = config_containing_override.pop("override")
override_dict = determine_override_options(selected_options, override_opts, set_of_possible_options)
logger.debug(f"override_dict: {override_dict}")
for k, v in override_dict.items():
if k in config:
try:
config[k].anchor
logger.debug(f"type: {type(config[k])}, k: {k}")
if isinstance(config[k], list):
del config[k][:]
if isinstance(override_dict[k], (str, int, float, bool)):
config[k].append(override_dict[k])
else:
config[k].extend(override_dict[k])
elif isinstance(config[k], dict):
config[k].clear()
config[k].update(override_dict[k])
elif isinstance(config[k], (int, float, bool)):
logger.debug("Overwriting YAML anchor object. It is currently unclear how to reassign this value.")
config[k] = v
else:
raise ValueError(f"Object {k} (type {type(config[k])}) somehow has an anchor, but is something other than a list or dict. Attempting to assign directly to it.")
except AttributeError:
config[k] = v
else:
raise KeyError(k, f"Trying to override key \"{k}\" that it is not in the config.")
return config
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '24', '36']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'determine_selection_of_iterable_values_from_config'}; {'id': '3', 'type': 'parameters', 'children': ['4', '8']}; {'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '6', 'type': 'type', 'children': ['7']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'DictLike'}; {'id': '8', 'type': 'typed_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'possible_iterables'}; {'id': '10', 'type': 'type', 'children': ['11']}; {'id': '11', 'type': 'generic_type', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'Mapping'}; {'id': '13', 'type': 'type_parameter', 'children': ['14', '16']}; {'id': '14', 'type': 'type', 'children': ['15']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '16', 'type': 'type', 'children': ['17']}; {'id': '17', 'type': 'generic_type', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'Type'}; {'id': '19', 'type': 'type_parameter', 'children': ['20']}; {'id': '20', 'type': 'type', 'children': ['21']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'enum'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'Enum'}; {'id': '24', 'type': 'type', 'children': ['25']}; {'id': '25', 'type': 'generic_type', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'Dict'}; {'id': '27', 'type': 'type_parameter', 'children': ['28', '30']}; {'id': '28', 'type': 'type', 'children': ['29']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '30', 'type': 'type', 'children': ['31']}; {'id': '31', 'type': 'generic_type', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'List'}; {'id': '33', 'type': 'type_parameter', 'children': ['34']}; {'id': '34', 'type': 'type', 'children': ['35']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'Any'}; {'id': '36', 'type': 'block', 'children': ['37', '41', '47', '160']}; {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'iterables'}; {'id': '40', 'type': 'dictionary', 'children': []}; {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'requested_iterables'}; {'id': '44', 'type': 'subscript', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '46', 'type': 'string', 'children': [], 'value': '"iterables"'}; {'id': '47', 'type': 'for_statement', 'children': ['48', '51', '56']}; {'id': '48', 'type': 'pattern_list', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'requested_iterables'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '55', 'type': 'argument_list', 'children': []}; {'id': '56', 'type': 'block', 'children': ['57', '68', '75', '85', '91', '107', '154']}; {'id': '57', 'type': 'if_statement', 'children': ['58', '61']}; {'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': 'not'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'possible_iterables'}; {'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': 'KeyError'}; {'id': '65', 'type': 'argument_list', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '67', 'type': 'string', 'children': [], 'value': 'f"Cannot find requested iterable in possible_iterables: {possible_iterables}"'}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}; {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'string', 'children': [], 'value': 'f"k: {k}, v: {v}"'}; {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78', '84']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'additional_iterable'}; {'id': '78', 'type': 'type', 'children': ['79']}; {'id': '79', 'type': 'generic_type', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'List'}; {'id': '81', 'type': 'type_parameter', 'children': ['82']}; {'id': '82', 'type': 'type', 'children': ['83']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'Any'}; {'id': '84', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'enum_values'}; {'id': '88', 'type': 'subscript', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'possible_iterables'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '91', 'type': 'if_statement', 'children': ['92', '97']}; {'id': '92', 'type': 'call', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '94', 'type': 'argument_list', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '97', 'type': 'block', 'children': ['98']}; {'id': '98', 'type': 'raise_statement', 'children': ['99']}; {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '101', 'type': 'argument_list', 'children': ['102', '106']}; {'id': '102', 'type': 'call', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '106', 'type': 'string', 'children': [], 'value': 'f"Passed string {v} when must be either bool or list"'}; {'id': '107', 'type': 'if_statement', 'children': ['108', '111', '113', '125']}; {'id': '108', 'type': 'comparison_operator', 'children': ['109', '110'], 'value': 'is'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '110', 'type': 'False', 'children': []}; {'id': '111', 'type': 'block', 'children': ['112']}; {'id': '112', 'type': 'continue_statement', 'children': []}; {'id': '113', 'type': 'elif_clause', 'children': ['114', '117']}; {'id': '114', 'type': 'comparison_operator', 'children': ['115', '116'], 'value': 'is'}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '116', 'type': 'True', 'children': []}; {'id': '117', 'type': 'block', 'children': ['118']}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}; {'id': '119', 'type': 'assignment', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'additional_iterable'}; {'id': '121', 'type': 'call', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '123', 'type': 'argument_list', 'children': ['124']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'enum_values'}; {'id': '125', 'type': 'else_clause', 'children': ['126']}; {'id': '126', 'type': 'block', 'children': ['127']}; {'id': '127', 'type': 'if_statement', 'children': ['128', '131', '139']}; {'id': '128', 'type': 'comparison_operator', 'children': ['129', '130'], 'value': 'is'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'enum_values'}; {'id': '130', 'type': 'None', 'children': []}; {'id': '131', 'type': 'block', 'children': ['132']}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}; {'id': '133', 'type': 'assignment', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'additional_iterable'}; {'id': '135', 'type': 'call', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '137', 'type': 'argument_list', 'children': ['138']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '139', 'type': 'else_clause', 'children': ['140']}; {'id': '140', 'type': 'block', 'children': ['141']}; {'id': '141', 'type': 'for_statement', 'children': ['142', '143', '144']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'el'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '144', 'type': 'block', 'children': ['145']}; {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'call', 'children': ['147', '150']}; {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'additional_iterable'}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '150', 'type': 'argument_list', 'children': ['151']}; {'id': '151', 'type': 'subscript', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'enum_values'}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'el'}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}; {'id': '155', 'type': 'assignment', 'children': ['156', '159']}; {'id': '156', 'type': 'subscript', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'iterables'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'additional_iterable'}; {'id': '160', 'type': 'return_statement', 'children': ['161']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'iterables'}
|
def determine_selection_of_iterable_values_from_config(config: DictLike, possible_iterables: Mapping[str, Type[enum.Enum]]) -> Dict[str, List[Any]]:
iterables = {}
requested_iterables = config["iterables"]
for k, v in requested_iterables.items():
if k not in possible_iterables:
raise KeyError(k, f"Cannot find requested iterable in possible_iterables: {possible_iterables}")
logger.debug(f"k: {k}, v: {v}")
additional_iterable: List[Any] = []
enum_values = possible_iterables[k]
if isinstance(v, str):
raise TypeError(type(v), f"Passed string {v} when must be either bool or list")
if v is False:
continue
elif v is True:
additional_iterable = list(enum_values)
else:
if enum_values is None:
additional_iterable = list(v)
else:
for el in v:
additional_iterable.append(enum_values[el])
iterables[k] = additional_iterable
return iterables
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18', '20']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'create_key_index_object'}; {'id': '3', 'type': 'parameters', 'children': ['4', '8']}; {'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'key_index_name'}; {'id': '6', 'type': 'type', 'children': ['7']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '8', 'type': 'typed_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'iterables'}; {'id': '10', 'type': 'type', 'children': ['11']}; {'id': '11', 'type': 'generic_type', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'Dict'}; {'id': '13', 'type': 'type_parameter', 'children': ['14', '16']}; {'id': '14', 'type': 'type', 'children': ['15']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '16', 'type': 'type', 'children': ['17']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'Any'}; {'id': '18', 'type': 'type', 'children': ['19']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'Any'}; {'id': '20', 'type': 'block', 'children': ['21', '49', '74', '87', '93']}; {'id': '21', 'type': 'for_statement', 'children': ['22', '25', '30']}; {'id': '22', 'type': 'pattern_list', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'iterable'}; {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'iterables'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '29', 'type': 'argument_list', 'children': []}; {'id': '30', 'type': 'block', 'children': ['31']}; {'id': '31', 'type': 'if_statement', 'children': ['32', '41']}; {'id': '32', 'type': 'comparison_operator', 'children': ['33', '37'], 'value': '=='}; {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'iter'}; {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'iterable'}; {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'iter'}; {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'iterable'}; {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'raise_statement', 'children': ['43']}; {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'concatenated_string', 'children': ['47', '48']}; {'id': '47', 'type': 'string', 'children': [], 'value': 'f"Iterable {name} is in iterator which can be exhausted. Please pass the iterable"'}; {'id': '48', 'type': 'string', 'children': [], 'value': 'f" in a container that can recreate the iterable. See the comments here for more info."'}; {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '52', 'type': 'list_comprehension', 'children': ['53', '65']}; {'id': '53', 'type': 'tuple', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '55', 'type': 'call', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'next'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}; {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'iter'}; {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'iterable'}; {'id': '65', 'type': 'for_in_clause', 'children': ['66', '69']}; {'id': '66', 'type': 'pattern_list', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'iterable'}; {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'iterables'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '73', 'type': 'argument_list', 'children': []}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}; {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'KeyIndex'}; {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'dataclasses'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'make_dataclass'}; {'id': '81', 'type': 'argument_list', 'children': ['82', '83', '84']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'key_index_name'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '84', 'type': 'keyword_argument', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'frozen'}; {'id': '86', 'type': 'True', 'children': []}; {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '92']}; {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'KeyIndex'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': '__iter__'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': '_key_index_iter'}; {'id': '93', 'type': 'return_statement', 'children': ['94']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'KeyIndex'}
|
def create_key_index_object(key_index_name: str, iterables: Dict[str, Any]) -> Any:
for name, iterable in iterables.items():
if iter(iterable) == iter(iterable):
raise TypeError(
f"Iterable {name} is in iterator which can be exhausted. Please pass the iterable"
f" in a container that can recreate the iterable. See the comments here for more info."
)
fields = [(name, type(next(iter(iterable)))) for name, iterable in iterables.items()]
KeyIndex = dataclasses.make_dataclass(
key_index_name,
fields,
frozen = True
)
KeyIndex.__iter__ = _key_index_iter
return KeyIndex
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '34', '50']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'create_objects_from_iterables'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '9', '19', '29']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '7', 'type': 'type', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '9', 'type': 'typed_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'iterables'}; {'id': '11', 'type': 'type', 'children': ['12']}; {'id': '12', 'type': 'generic_type', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'Dict'}; {'id': '14', 'type': 'type_parameter', 'children': ['15', '17']}; {'id': '15', 'type': 'type', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '17', 'type': 'type', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'Any'}; {'id': '19', 'type': 'typed_parameter', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'formatting_options'}; {'id': '21', 'type': 'type', 'children': ['22']}; {'id': '22', 'type': 'generic_type', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'Dict'}; {'id': '24', 'type': 'type_parameter', 'children': ['25', '27']}; {'id': '25', 'type': 'type', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '27', 'type': 'type', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'Any'}; {'id': '29', 'type': 'typed_default_parameter', 'children': ['30', '31', '33']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'key_index_name'}; {'id': '31', 'type': 'type', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '33', 'type': 'string', 'children': [], 'value': '"KeyIndex"'}; {'id': '34', 'type': 'type', 'children': ['35']}; {'id': '35', 'type': 'generic_type', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'Tuple'}; {'id': '37', 'type': 'type_parameter', 'children': ['38', '40', '48']}; {'id': '38', 'type': 'type', 'children': ['39']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'Any'}; {'id': '40', 'type': 'type', 'children': ['41']}; {'id': '41', 'type': 'generic_type', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'Dict'}; {'id': '43', 'type': 'type_parameter', 'children': ['44', '46']}; {'id': '44', 'type': 'type', 'children': ['45']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '46', 'type': 'type', 'children': ['47']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'Any'}; {'id': '48', 'type': 'type', 'children': ['49']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '50', 'type': 'block', 'children': ['51', '55', '62', '69', '81', '203', '213']}; {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'objects'}; {'id': '54', 'type': 'dictionary', 'children': []}; {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '58', 'type': 'call', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'iterables'}; {'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': 'logger'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'string', 'children': [], 'value': 'f"iterables: {iterables}"'}; {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'KeyIndex'}; {'id': '72', 'type': 'call', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'create_key_index_object'}; {'id': '74', 'type': 'argument_list', 'children': ['75', '78']}; {'id': '75', 'type': 'keyword_argument', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'key_index_name'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'key_index_name'}; {'id': '78', 'type': 'keyword_argument', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'iterables'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'iterables'}; {'id': '81', 'type': 'for_statement', 'children': ['82', '83', '94']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '83', 'type': 'call', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'itertools'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'product'}; {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'list_splat', 'children': ['89']}; {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'iterables'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '93', 'type': 'argument_list', 'children': []}; {'id': '94', 'type': 'block', 'children': ['95', '102', '107', '132', '141', '148', '156', '176', '182', '189']}; {'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': 'logger'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}; {'id': '101', 'type': 'string', 'children': [], 'value': 'f"Values: {values}"'}; {'id': '102', 'type': 'if_statement', 'children': ['103', '105']}; {'id': '103', 'type': 'not_operator', 'children': ['104']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '105', 'type': 'block', 'children': ['106']}; {'id': '106', 'type': 'continue_statement', 'children': []}; {'id': '107', 'type': 'for_statement', 'children': ['108', '111', '116']}; {'id': '108', 'type': 'pattern_list', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '111', 'type': 'call', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '113', 'type': 'argument_list', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '116', 'type': 'block', 'children': ['117', '123']}; {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'assignment', 'children': ['119', '122']}; {'id': '119', 'type': 'subscript', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '128']}; {'id': '125', 'type': 'subscript', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'formatting_options'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '128', 'type': 'call', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}; {'id': '133', 'type': 'assignment', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'object_args'}; {'id': '135', 'type': 'call', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'call', 'children': ['143', '146']}; {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '146', 'type': 'argument_list', 'children': ['147']}; {'id': '147', 'type': 'string', 'children': [], 'value': 'f"object_args pre format: {object_args}"'}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}; {'id': '149', 'type': 'assignment', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'object_args'}; {'id': '151', 'type': 'call', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'apply_formatting_dict'}; {'id': '153', 'type': 'argument_list', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'object_args'}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'formatting_options'}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}; {'id': '157', 'type': 'assignment', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'print_args'}; {'id': '159', 'type': 'dictionary_comprehension', 'children': ['160', '163', '172']}; {'id': '160', 'type': 'pair', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '163', 'type': 'for_in_clause', 'children': ['164', '167']}; {'id': '164', 'type': 'pattern_list', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '167', 'type': 'call', 'children': ['168', '171']}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'object_args'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '171', 'type': 'argument_list', 'children': []}; {'id': '172', 'type': 'if_clause', 'children': ['173']}; {'id': '173', 'type': 'comparison_operator', 'children': ['174', '175'], 'value': '!='}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '175', 'type': 'string', 'children': [], 'value': '"config"'}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}; {'id': '177', 'type': 'assignment', 'children': ['178', '181']}; {'id': '178', 'type': 'subscript', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'print_args'}; {'id': '180', 'type': 'string', 'children': [], 'value': '"config"'}; {'id': '181', 'type': 'string', 'children': [], 'value': '"..."'}; {'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': 'logger'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '187', 'type': 'argument_list', 'children': ['188']}; {'id': '188', 'type': 'string', 'children': [], 'value': 'f"Constructing obj \\"{obj}\\" with args: \\"{print_args}\\""'}; {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'assignment', 'children': ['191', '198']}; {'id': '191', 'type': 'subscript', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'objects'}; {'id': '193', 'type': 'call', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'KeyIndex'}; {'id': '195', 'type': 'argument_list', 'children': ['196']}; {'id': '196', 'type': 'list_splat', 'children': ['197']}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '198', 'type': 'call', 'children': ['199', '200']}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '200', 'type': 'argument_list', 'children': ['201']}; {'id': '201', 'type': 'dictionary_splat', 'children': ['202']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'object_args'}; {'id': '203', 'type': 'if_statement', 'children': ['204', '206']}; {'id': '204', 'type': 'not_operator', 'children': ['205']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'objects'}; {'id': '206', 'type': 'block', 'children': ['207']}; {'id': '207', 'type': 'raise_statement', 'children': ['208']}; {'id': '208', 'type': 'call', 'children': ['209', '210']}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '210', 'type': 'argument_list', 'children': ['211', '212']}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'iterables'}; {'id': '212', 'type': 'string', 'children': [], 'value': '"There appear to be no iterables to use in creating objects."'}; {'id': '213', 'type': 'return_statement', 'children': ['214']}; {'id': '214', 'type': 'tuple', 'children': ['215', '216', '217']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'KeyIndex'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'iterables'}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'objects'}
|
def create_objects_from_iterables(obj, args: dict, iterables: Dict[str, Any], formatting_options: Dict[str, Any], key_index_name: str = "KeyIndex") -> Tuple[Any, Dict[str, Any], dict]:
objects = {}
names = list(iterables)
logger.debug(f"iterables: {iterables}")
KeyIndex = create_key_index_object(
key_index_name = key_index_name,
iterables = iterables,
)
for values in itertools.product(*iterables.values()):
logger.debug(f"Values: {values}")
if not values:
continue
for name, val in zip(names, values):
args[name] = val
formatting_options[name] = str(val)
object_args = copy.copy(args)
logger.debug(f"object_args pre format: {object_args}")
object_args = apply_formatting_dict(object_args, formatting_options)
print_args = {k: v for k, v in object_args.items() if k != "config"}
print_args["config"] = "..."
logger.debug(f"Constructing obj \"{obj}\" with args: \"{print_args}\"")
objects[KeyIndex(*values)] = obj(**object_args)
if not objects:
raise ValueError(iterables, "There appear to be no iterables to use in creating objects.")
return (KeyIndex, iterables, objects)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '42', '58']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'iterate_with_selected_objects_in_order'}; {'id': '3', 'type': 'parameters', 'children': ['4', '14', '28']}; {'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'analysis_objects'}; {'id': '6', 'type': 'type', 'children': ['7']}; {'id': '7', 'type': 'generic_type', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'Mapping'}; {'id': '9', 'type': 'type_parameter', 'children': ['10', '12']}; {'id': '10', 'type': 'type', 'children': ['11']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'Any'}; {'id': '12', 'type': 'type', 'children': ['13']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'Any'}; {'id': '14', 'type': 'typed_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'analysis_iterables'}; {'id': '16', 'type': 'type', 'children': ['17']}; {'id': '17', 'type': 'generic_type', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'Dict'}; {'id': '19', 'type': 'type_parameter', 'children': ['20', '22']}; {'id': '20', 'type': 'type', 'children': ['21']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '22', 'type': 'type', 'children': ['23']}; {'id': '23', 'type': 'generic_type', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'Sequence'}; {'id': '25', 'type': 'type_parameter', 'children': ['26']}; {'id': '26', 'type': 'type', 'children': ['27']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'Any'}; {'id': '28', 'type': 'typed_parameter', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'selection'}; {'id': '30', 'type': 'type', 'children': ['31']}; {'id': '31', 'type': 'generic_type', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'Union'}; {'id': '33', 'type': 'type_parameter', 'children': ['34', '36']}; {'id': '34', 'type': 'type', 'children': ['35']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '36', 'type': 'type', 'children': ['37']}; {'id': '37', 'type': 'generic_type', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'Sequence'}; {'id': '39', 'type': 'type_parameter', 'children': ['40']}; {'id': '40', 'type': 'type', 'children': ['41']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '42', 'type': 'type', 'children': ['43']}; {'id': '43', 'type': 'generic_type', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'Iterator'}; {'id': '45', 'type': 'type_parameter', 'children': ['46']}; {'id': '46', 'type': 'type', 'children': ['47']}; {'id': '47', 'type': 'generic_type', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'List'}; {'id': '49', 'type': 'type_parameter', 'children': ['50']}; {'id': '50', 'type': 'type', 'children': ['51']}; {'id': '51', 'type': 'generic_type', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'Tuple'}; {'id': '53', 'type': 'type_parameter', 'children': ['54', '56']}; {'id': '54', 'type': 'type', 'children': ['55']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'Any'}; {'id': '56', 'type': 'type', 'children': ['57']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'Any'}; {'id': '58', 'type': 'block', 'children': ['59', '71', '78', '87', '91', '106', '113', '120', '140', '160', '167', '174']}; {'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': 'selection'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '65', 'type': 'block', 'children': ['66']}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}; {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'selection'}; {'id': '69', 'type': 'list', 'children': ['70'], 'value': '[selection]'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'selection'}; {'id': '71', 'type': 'assert_statement', 'children': ['72']}; {'id': '72', 'type': 'not_operator', 'children': ['73']}; {'id': '73', 'type': 'call', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '75', 'type': 'argument_list', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'selection'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}; {'id': '79', 'type': 'assignment', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'analysis_iterables'}; {'id': '81', 'type': 'call', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'analysis_iterables'}; {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'selected_iterators'}; {'id': '90', 'type': 'dictionary', 'children': []}; {'id': '91', 'type': 'for_statement', 'children': ['92', '93', '94']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'selection'}; {'id': '94', 'type': 'block', 'children': ['95']}; {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '100']}; {'id': '97', 'type': 'subscript', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'selected_iterators'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '100', 'type': 'call', 'children': ['101', '104']}; {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'analysis_iterables'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}; {'id': '107', 'type': 'call', 'children': ['108', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '111', 'type': 'argument_list', 'children': ['112']}; {'id': '112', 'type': 'string', 'children': [], 'value': 'f"Initial analysis_iterables: {analysis_iterables}"'}; {'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': 'logger'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}; {'id': '119', 'type': 'string', 'children': [], 'value': 'f"Initial selected_iterators: {selected_iterators}"'}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}; {'id': '121', 'type': 'assignment', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'selected_iterators'}; {'id': '123', 'type': 'list_comprehension', 'children': ['124', '131']}; {'id': '124', 'type': 'list_comprehension', 'children': ['125', '128']}; {'id': '125', 'type': 'tuple', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '128', 'type': 'for_in_clause', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '131', 'type': 'for_in_clause', 'children': ['132', '135']}; {'id': '132', 'type': 'pattern_list', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '135', 'type': 'call', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'selected_iterators'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '139', 'type': 'argument_list', 'children': []}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}; {'id': '141', 'type': 'assignment', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'analysis_iterables'}; {'id': '143', 'type': 'list_comprehension', 'children': ['144', '151']}; {'id': '144', 'type': 'list_comprehension', 'children': ['145', '148']}; {'id': '145', 'type': 'tuple', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '148', 'type': 'for_in_clause', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '151', 'type': 'for_in_clause', 'children': ['152', '155']}; {'id': '152', 'type': 'pattern_list', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '155', 'type': 'call', 'children': ['156', '159']}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'analysis_iterables'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '159', 'type': 'argument_list', 'children': []}; {'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': 'logger'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '165', 'type': 'argument_list', 'children': ['166']}; {'id': '166', 'type': 'string', 'children': [], 'value': 'f"Final analysis_iterables: {analysis_iterables}"'}; {'id': '167', 'type': 'expression_statement', 'children': ['168']}; {'id': '168', 'type': 'call', 'children': ['169', '172']}; {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '172', 'type': 'argument_list', 'children': ['173']}; {'id': '173', 'type': 'string', 'children': [], 'value': 'f"Final selected_iterators: {selected_iterators}"'}; {'id': '174', 'type': 'for_statement', 'children': ['175', '176', '183']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '176', 'type': 'call', 'children': ['177', '180']}; {'id': '177', 'type': 'attribute', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'itertools'}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'product'}; {'id': '180', 'type': 'argument_list', 'children': ['181']}; {'id': '181', 'type': 'list_splat', 'children': ['182']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'analysis_iterables'}; {'id': '183', 'type': 'block', 'children': ['184', '188', '262', '269']}; {'id': '184', 'type': 'expression_statement', 'children': ['185']}; {'id': '185', 'type': 'assignment', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'selected_analysis_objects'}; {'id': '187', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '188', 'type': 'for_statement', 'children': ['189', '190', '197']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'selected_values'}; {'id': '190', 'type': 'call', 'children': ['191', '194']}; {'id': '191', 'type': 'attribute', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'itertools'}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'product'}; {'id': '194', 'type': 'argument_list', 'children': ['195']}; {'id': '195', 'type': 'list_splat', 'children': ['196']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'selected_iterators'}; {'id': '197', 'type': 'block', 'children': ['198']}; {'id': '198', 'type': 'for_statement', 'children': ['199', '202', '207']}; {'id': '199', 'type': 'pattern_list', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'key_index'}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '202', 'type': 'call', 'children': ['203', '206']}; {'id': '203', 'type': 'attribute', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'analysis_objects'}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '206', 'type': 'argument_list', 'children': []}; {'id': '207', 'type': 'block', 'children': ['208', '226', '244', '250']}; {'id': '208', 'type': 'expression_statement', 'children': ['209']}; {'id': '209', 'type': 'assignment', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'selected_via_analysis_iterables'}; {'id': '211', 'type': 'call', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '213', 'type': 'generator_expression', 'children': ['214', '221']}; {'id': '214', 'type': 'comparison_operator', 'children': ['215', '220'], 'value': '=='}; {'id': '215', 'type': 'call', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '217', 'type': 'argument_list', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'key_index'}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '221', 'type': 'for_in_clause', 'children': ['222', '225']}; {'id': '222', 'type': 'pattern_list', 'children': ['223', '224']}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '226', 'type': 'expression_statement', 'children': ['227']}; {'id': '227', 'type': 'assignment', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'selected_via_selected_iterators'}; {'id': '229', 'type': 'call', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '231', 'type': 'generator_expression', 'children': ['232', '239']}; {'id': '232', 'type': 'comparison_operator', 'children': ['233', '238'], 'value': '=='}; {'id': '233', 'type': 'call', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '235', 'type': 'argument_list', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'key_index'}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '239', 'type': 'for_in_clause', 'children': ['240', '243']}; {'id': '240', 'type': 'pattern_list', 'children': ['241', '242']}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'selected_values'}; {'id': '244', 'type': 'expression_statement', 'children': ['245']}; {'id': '245', 'type': 'assignment', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'selected_obj'}; {'id': '247', 'type': 'boolean_operator', 'children': ['248', '249'], 'value': 'and'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'selected_via_analysis_iterables'}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'selected_via_selected_iterators'}; {'id': '250', 'type': 'if_statement', 'children': ['251', '252']}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'selected_obj'}; {'id': '252', 'type': 'block', 'children': ['253']}; {'id': '253', 'type': 'expression_statement', 'children': ['254']}; {'id': '254', 'type': 'call', 'children': ['255', '258']}; {'id': '255', 'type': 'attribute', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'selected_analysis_objects'}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '258', 'type': 'argument_list', 'children': ['259']}; {'id': '259', 'type': 'tuple', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'key_index'}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '262', 'type': 'expression_statement', 'children': ['263']}; {'id': '263', 'type': 'call', 'children': ['264', '267']}; {'id': '264', 'type': 'attribute', 'children': ['265', '266']}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '267', 'type': 'argument_list', 'children': ['268']}; {'id': '268', 'type': 'string', 'children': [], 'value': 'f"Yielding: {selected_analysis_objects}"'}; {'id': '269', 'type': 'expression_statement', 'children': ['270']}; {'id': '270', 'type': 'yield', 'children': ['271']}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'selected_analysis_objects'}
|
def iterate_with_selected_objects_in_order(analysis_objects: Mapping[Any, Any],
analysis_iterables: Dict[str, Sequence[Any]],
selection: Union[str, Sequence[str]]) -> Iterator[List[Tuple[Any, Any]]]:
if isinstance(selection, str):
selection = [selection]
assert not isinstance(selection, str)
analysis_iterables = copy.copy(analysis_iterables)
selected_iterators = {}
for s in selection:
selected_iterators[s] = analysis_iterables.pop(s)
logger.debug(f"Initial analysis_iterables: {analysis_iterables}")
logger.debug(f"Initial selected_iterators: {selected_iterators}")
selected_iterators = [[(k, v) for v in values] for k, values in selected_iterators.items()]
analysis_iterables = [[(k, v) for v in values] for k, values in analysis_iterables.items()]
logger.debug(f"Final analysis_iterables: {analysis_iterables}")
logger.debug(f"Final selected_iterators: {selected_iterators}")
for values in itertools.product(*analysis_iterables):
selected_analysis_objects = []
for selected_values in itertools.product(*selected_iterators):
for key_index, obj in analysis_objects.items():
selected_via_analysis_iterables = all(
getattr(key_index, k) == v for k, v in values
)
selected_via_selected_iterators = all(
getattr(key_index, k) == v for k, v in selected_values
)
selected_obj = selected_via_analysis_iterables and selected_via_selected_iterators
if selected_obj:
selected_analysis_objects.append((key_index, obj))
logger.debug(f"Yielding: {selected_analysis_objects}")
yield selected_analysis_objects
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'phenotypes_to_scored'}; {'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': 'phenotypes'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'overwrite'}; {'id': '10', 'type': 'False', 'children': []}; {'id': '11', 'type': 'block', 'children': ['12', '25', '48', '123', '131', '156']}; {'id': '12', 'type': 'if_statement', 'children': ['13', '19']}; {'id': '13', 'type': 'not_operator', 'children': ['14']}; {'id': '14', 'type': 'call', 'children': ['15', '18']}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'is_uniform'}; {'id': '18', 'type': 'argument_list', 'children': []}; {'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': 'string', 'children': [], 'value': '"inconsistent phenotypes"'}; {'id': '25', 'type': 'if_statement', 'children': ['26', '29', '36']}; {'id': '26', 'type': 'comparison_operator', 'children': ['27', '28'], 'value': 'is'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'phenotypes'}; {'id': '28', 'type': 'None', 'children': []}; {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'phenotypes'}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'phenotypes'}; {'id': '36', 'type': 'elif_clause', 'children': ['37', '42']}; {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '39', 'type': 'argument_list', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'phenotypes'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'str'}; {'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': 'phenotypes'}; {'id': '46', 'type': 'list', 'children': ['47'], 'value': '[phenotypes]'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'phenotypes'}; {'id': '48', 'type': 'function_definition', 'children': ['49', '50', '55']}; {'id': '49', 'type': 'function_name', 'children': [], 'value': '_post'}; {'id': '50', 'type': 'parameters', 'children': ['51', '52', '53', '54']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'binary'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'phenotype_label'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'phenotypes'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'overwrite'}; {'id': '55', 'type': 'block', 'children': ['56', '64', '96', '106', '121']}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}; {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'binary'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '63', 'type': 'argument_list', 'children': []}; {'id': '64', 'type': 'if_statement', 'children': ['65', '90']}; {'id': '65', 'type': 'boolean_operator', 'children': ['66', '87'], 'value': 'and'}; {'id': '66', 'type': 'comparison_operator', 'children': ['67', '86'], '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': 'binary_operator', 'children': ['71', '75'], 'value': '&'}; {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'phenotypes'}; {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}; {'id': '81', 'type': 'call', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'binary'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '85', 'type': 'argument_list', 'children': []}; {'id': '86', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '87', 'type': 'comparison_operator', 'children': ['88', '89'], 'value': '=='}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'overwrite'}; {'id': '89', 'type': 'False', 'children': []}; {'id': '90', 'type': 'block', 'children': ['91']}; {'id': '91', 'type': 'raise_statement', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}; {'id': '95', 'type': 'string', 'children': [], 'value': '"Error, phenotype already exists as a scored type"'}; {'id': '96', 'type': 'for_statement', 'children': ['97', '98', '99']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'phenotypes'}; {'id': '99', 'type': 'block', 'children': ['100']}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}; {'id': '101', 'type': 'assignment', 'children': ['102', '105']}; {'id': '102', 'type': 'subscript', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '105', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '106', 'type': 'if_statement', 'children': ['107', '114']}; {'id': '107', 'type': 'boolean_operator', 'children': ['108', '111'], 'value': 'and'}; {'id': '108', 'type': 'comparison_operator', 'children': ['109', '110'], 'value': '=='}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'phenotype_label'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'phenotype_label'}; {'id': '111', 'type': 'comparison_operator', 'children': ['112', '113'], 'value': 'in'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'phenotype_label'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'phenotypes'}; {'id': '114', 'type': 'block', 'children': ['115']}; {'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': 'd'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'phenotype_label'}; {'id': '120', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '121', 'type': 'return_statement', 'children': ['122']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '126', 'type': 'call', 'children': ['127', '130']}; {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '130', 'type': 'argument_list', 'children': []}; {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '136']}; {'id': '133', 'type': 'subscript', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '135', 'type': 'string', 'children': [], 'value': "'scored_calls'"}; {'id': '136', 'type': 'call', 'children': ['137', '140']}; {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'apply'}; {'id': '140', 'type': 'argument_list', 'children': ['141', '155']}; {'id': '141', 'type': 'lambda', 'children': ['142', '144']}; {'id': '142', 'type': 'lambda_parameters', 'children': ['143']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '144', 'type': 'call', 'children': ['145', '146']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': '_post'}; {'id': '146', 'type': 'argument_list', 'children': ['147', '150', '153', '154']}; {'id': '147', 'type': 'subscript', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '149', 'type': 'string', 'children': [], 'value': "'scored_calls'"}; {'id': '150', 'type': 'subscript', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '152', 'type': 'string', 'children': [], 'value': "'phenotype_label'"}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'phenotypes'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'overwrite'}; {'id': '155', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '156', 'type': 'return_statement', 'children': ['157']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'output'}
|
def phenotypes_to_scored(self,phenotypes=None,overwrite=False):
if not self.is_uniform(): raise ValueError("inconsistent phenotypes")
if phenotypes is None:
phenotypes = self.phenotypes
elif isinstance(phenotypes,str):
phenotypes = [phenotypes]
def _post(binary,phenotype_label,phenotypes,overwrite):
d = binary.copy()
if len(set(phenotypes)&set(list(binary.keys()))) > 0 and overwrite==False:
raise ValueError("Error, phenotype already exists as a scored type")
for label in phenotypes: d[label] = 0
if phenotype_label == phenotype_label and phenotype_label in phenotypes:
d[phenotype_label] = 1
return d
output = self.copy()
output['scored_calls'] = output.apply(lambda x:
_post(x['scored_calls'],x['phenotype_label'],phenotypes,overwrite)
,1)
return output
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'subset'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'logic'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '8', 'type': 'False', 'children': []}; {'id': '9', 'type': 'block', 'children': ['10', '16', '22', '30', '34', '40', '52', '66', '165', '174', '227', '235', '259', '268', '276']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}; {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'pnames'}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'phenotypes'}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'snames'}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'scored_names'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'data'}; {'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': 'copy'}; {'id': '29', 'type': 'argument_list', 'children': []}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '33', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}; {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'phenotypes'}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'logic'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'phenotypes'}; {'id': '40', 'type': 'if_statement', 'children': ['41', '47']}; {'id': '41', 'type': 'comparison_operator', 'children': ['42', '46'], 'value': '=='}; {'id': '42', 'type': 'call', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'phenotypes'}; {'id': '46', 'type': 'integer', 'children': [], 'value': '0'}; {'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': 'phenotypes'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'pnames'}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}; {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'removing'}; {'id': '55', 'type': 'binary_operator', 'children': ['56', '62'], 'value': '-'}; {'id': '56', 'type': 'call', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}; {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'phenotypes'}; {'id': '62', 'type': 'call', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'phenotypes'}; {'id': '66', 'type': 'for_statement', 'children': ['67', '68', '69']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'phenotypes'}; {'id': '69', 'type': 'block', 'children': ['70', '80', '106', '158']}; {'id': '70', 'type': 'if_statement', 'children': ['71', '74']}; {'id': '71', 'type': 'comparison_operator', 'children': ['72', '73'], 'value': 'not'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'pnames'}; {'id': '74', 'type': 'block', 'children': ['75']}; {'id': '75', 'type': 'raise_statement', 'children': ['76']}; {'id': '76', 'type': 'call', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}; {'id': '79', 'type': 'string', 'children': [], 'value': '"phenotype must exist in defined"'}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}; {'id': '81', 'type': 'assignment', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'temp'}; {'id': '83', 'type': 'call', 'children': ['84', '105']}; {'id': '84', 'type': 'attribute', 'children': ['85', '104']}; {'id': '85', 'type': 'subscript', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'loc'}; {'id': '89', 'type': 'call', 'children': ['90', '95']}; {'id': '90', 'type': 'attribute', 'children': ['91', '94']}; {'id': '91', 'type': 'subscript', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '93', 'type': 'string', 'children': [], 'value': "'phenotype_calls'"}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'apply'}; {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'lambda', 'children': ['97', '99']}; {'id': '97', 'type': 'lambda_parameters', 'children': ['98']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '99', 'type': 'comparison_operator', 'children': ['100', '103'], 'value': '=='}; {'id': '100', 'type': 'subscript', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '103', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '105', 'type': 'argument_list', 'children': []}; {'id': '106', 'type': 'if_statement', 'children': ['107', '121']}; {'id': '107', 'type': 'boolean_operator', 'children': ['108', '114'], 'value': 'and'}; {'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': 'removing'}; {'id': '113', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '114', 'type': 'comparison_operator', 'children': ['115', '120'], 'value': '>'}; {'id': '115', 'type': 'subscript', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'temp'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '119', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '120', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '121', 'type': 'block', 'children': ['122']}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}; {'id': '123', 'type': 'assignment', 'children': ['124', '127']}; {'id': '124', 'type': 'subscript', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'temp'}; {'id': '126', 'type': 'string', 'children': [], 'value': "'phenotype_calls'"}; {'id': '127', 'type': 'call', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'temp'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'apply'}; {'id': '131', 'type': 'argument_list', 'children': ['132', '157']}; {'id': '132', 'type': 'lambda', 'children': ['133', '135']}; {'id': '133', 'type': 'lambda_parameters', 'children': ['134']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '135', 'type': 'call', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '137', 'type': 'argument_list', 'children': ['138']}; {'id': '138', 'type': 'list_comprehension', 'children': ['139', '142', '153']}; {'id': '139', 'type': 'tuple', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '142', 'type': 'for_in_clause', 'children': ['143', '146']}; {'id': '143', 'type': 'pattern_list', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '146', 'type': 'call', 'children': ['147', '152']}; {'id': '147', 'type': 'attribute', 'children': ['148', '151']}; {'id': '148', 'type': 'subscript', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '150', 'type': 'string', 'children': [], 'value': "'phenotype_calls'"}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '152', 'type': 'argument_list', 'children': []}; {'id': '153', 'type': 'if_clause', 'children': ['154']}; {'id': '154', 'type': 'comparison_operator', 'children': ['155', '156'], 'value': 'not'}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'removing'}; {'id': '157', 'type': 'integer', 'children': [], 'value': '1'}; {'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': 'values'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '163', 'type': 'argument_list', 'children': ['164']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'temp'}; {'id': '165', 'type': 'expression_statement', 'children': ['166']}; {'id': '166', 'type': 'assignment', 'children': ['167', '168']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '168', 'type': 'call', 'children': ['169', '172']}; {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'pd'}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'concat'}; {'id': '172', 'type': 'argument_list', 'children': ['173']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '174', 'type': 'for_statement', 'children': ['175', '178', '185']}; {'id': '175', 'type': 'pattern_list', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '178', 'type': 'call', 'children': ['179', '184']}; {'id': '179', 'type': 'attribute', 'children': ['180', '183']}; {'id': '180', 'type': 'attribute', 'children': ['181', '182']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'logic'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'scored_calls'}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '184', 'type': 'argument_list', 'children': []}; {'id': '185', 'type': 'block', 'children': ['186', '196', '205']}; {'id': '186', 'type': 'if_statement', 'children': ['187', '190']}; {'id': '187', 'type': 'comparison_operator', 'children': ['188', '189'], 'value': 'not'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'snames'}; {'id': '190', 'type': 'block', 'children': ['191']}; {'id': '191', 'type': 'raise_statement', 'children': ['192']}; {'id': '192', 'type': 'call', 'children': ['193', '194']}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '194', 'type': 'argument_list', 'children': ['195']}; {'id': '195', 'type': 'string', 'children': [], 'value': '"Scored name must exist in defined"'}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}; {'id': '197', 'type': 'assignment', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'myfilter'}; {'id': '199', 'type': 'conditional_expression', 'children': ['200', '201', '204'], 'value': 'if'}; {'id': '200', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '201', 'type': 'comparison_operator', 'children': ['202', '203'], 'value': '=='}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '203', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '204', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '205', 'type': 'expression_statement', 'children': ['206']}; {'id': '206', 'type': 'assignment', 'children': ['207', '208']}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '208', 'type': 'subscript', 'children': ['209', '212']}; {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'loc'}; {'id': '212', 'type': 'call', 'children': ['213', '218']}; {'id': '213', 'type': 'attribute', 'children': ['214', '217']}; {'id': '214', 'type': 'subscript', 'children': ['215', '216']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '216', 'type': 'string', 'children': [], 'value': "'scored_calls'"}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'apply'}; {'id': '218', 'type': 'argument_list', 'children': ['219']}; {'id': '219', 'type': 'lambda', 'children': ['220', '222']}; {'id': '220', 'type': 'lambda_parameters', 'children': ['221']}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '222', 'type': 'comparison_operator', 'children': ['223', '226'], 'value': '=='}; {'id': '223', 'type': 'subscript', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'myfilter'}; {'id': '227', 'type': 'expression_statement', 'children': ['228']}; {'id': '228', 'type': 'assignment', 'children': ['229', '232']}; {'id': '229', 'type': 'attribute', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'microns_per_pixel'}; {'id': '232', 'type': 'attribute', 'children': ['233', '234']}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'microns_per_pixel'}; {'id': '235', 'type': 'if_statement', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '237', 'type': 'block', 'children': ['238']}; {'id': '238', 'type': 'expression_statement', 'children': ['239']}; {'id': '239', 'type': 'assignment', 'children': ['240', '243']}; {'id': '240', 'type': 'subscript', 'children': ['241', '242']}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '242', 'type': 'string', 'children': [], 'value': "'phenotype_calls'"}; {'id': '243', 'type': 'call', 'children': ['244', '249']}; {'id': '244', 'type': 'attribute', 'children': ['245', '248']}; {'id': '245', 'type': 'subscript', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '247', 'type': 'string', 'children': [], 'value': "'phenotype_calls'"}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'apply'}; {'id': '249', 'type': 'argument_list', 'children': ['250']}; {'id': '250', 'type': 'lambda', 'children': ['251', '253']}; {'id': '251', 'type': 'lambda_parameters', 'children': ['252']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '253', 'type': 'dictionary', 'children': ['254']}; {'id': '254', 'type': 'pair', 'children': ['255', '258']}; {'id': '255', 'type': 'attribute', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'logic'}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '258', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '259', 'type': 'expression_statement', 'children': ['260']}; {'id': '260', 'type': 'call', 'children': ['261', '264']}; {'id': '261', 'type': 'attribute', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'fill_phenotype_label'}; {'id': '264', 'type': 'argument_list', 'children': ['265']}; {'id': '265', 'type': 'keyword_argument', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'inplace'}; {'id': '267', 'type': 'True', 'children': []}; {'id': '268', 'type': 'expression_statement', 'children': ['269']}; {'id': '269', 'type': 'assignment', 'children': ['270', '273']}; {'id': '270', 'type': 'attribute', 'children': ['271', '272']}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'db'}; {'id': '273', 'type': 'attribute', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'db'}; {'id': '276', 'type': 'return_statement', 'children': ['277']}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'data'}
|
def subset(self,logic,update=False):
pnames = self.phenotypes
snames = self.scored_names
data = self.copy()
values = []
phenotypes = logic.phenotypes
if len(phenotypes)==0: phenotypes = pnames
removing = set(self.phenotypes)-set(phenotypes)
for k in phenotypes:
if k not in pnames: raise ValueError("phenotype must exist in defined")
temp = data.loc[data['phenotype_calls'].apply(lambda x: x[k]==1)].copy()
if len(removing) > 0 and temp.shape[0] > 0:
temp['phenotype_calls'] = temp.apply(lambda x:
dict([(k,v) for k,v in x['phenotype_calls'].items() if k not in removing])
,1)
values.append(temp)
data = pd.concat(values)
for k,v in logic.scored_calls.items():
if k not in snames: raise ValueError("Scored name must exist in defined")
myfilter = 0 if v == '-' else 1
data = data.loc[data['scored_calls'].apply(lambda x: x[k]==myfilter)]
data.microns_per_pixel = self.microns_per_pixel
if update:
data['phenotype_calls'] = data['phenotype_calls'].apply(lambda x: {logic.label:1})
data.fill_phenotype_label(inplace=True)
data.db = self.db
return data
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'collapse_phenotypes'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'input_phenotype_labels'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'output_phenotype_label'}; {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '9', 'type': 'True', 'children': []}; {'id': '10', 'type': 'block', 'children': ['11', '23', '37', '57', '65', '75', '148', '170', '207', '227']}; {'id': '11', 'type': 'if_statement', 'children': ['12', '17']}; {'id': '12', 'type': 'call', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'input_phenotype_labels'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'str'}; {'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': 'input_phenotype_labels'}; {'id': '21', 'type': 'list', 'children': ['22'], 'value': '[input_phenotype_labels]'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'input_phenotype_labels'}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'bad_phenotypes'}; {'id': '26', 'type': 'binary_operator', 'children': ['27', '31'], 'value': '-'}; {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'input_phenotype_labels'}; {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'phenotypes'}; {'id': '37', 'type': 'if_statement', 'children': ['38', '44']}; {'id': '38', 'type': 'comparison_operator', 'children': ['39', '43'], 'value': '>'}; {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'bad_phenotypes'}; {'id': '43', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '44', 'type': 'block', 'children': ['45']}; {'id': '45', 'type': 'raise_statement', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}; {'id': '49', 'type': 'binary_operator', 'children': ['50', '56'], 'value': '+'}; {'id': '50', 'type': 'binary_operator', 'children': ['51', '52'], 'value': '+'}; {'id': '51', 'type': 'string', 'children': [], 'value': '"Error phenotype(s) "'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'bad_phenotypes'}; {'id': '56', 'type': 'string', 'children': [], 'value': '" are not in the data."'}; {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '60', 'type': 'call', 'children': ['61', '64']}; {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '64', 'type': 'argument_list', 'children': []}; {'id': '65', 'type': 'if_statement', 'children': ['66', '72']}; {'id': '66', 'type': 'comparison_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': 'input_phenotype_labels'}; {'id': '71', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '72', 'type': 'block', 'children': ['73']}; {'id': '73', 'type': 'return_statement', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '75', 'type': 'function_definition', 'children': ['76', '77', '81']}; {'id': '76', 'type': 'function_name', 'children': [], 'value': '_swap_in'}; {'id': '77', 'type': 'parameters', 'children': ['78', '79', '80']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'inputs'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '81', 'type': 'block', 'children': ['82', '98', '108', '128']}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}; {'id': '83', 'type': 'assignment', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'overlap'}; {'id': '85', 'type': 'call', 'children': ['86', '96']}; {'id': '86', 'type': 'attribute', 'children': ['87', '95']}; {'id': '87', 'type': 'call', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'call', 'children': ['91', '94']}; {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '94', 'type': 'argument_list', 'children': []}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'intersection'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'inputs'}; {'id': '98', 'type': 'if_statement', 'children': ['99', '105']}; {'id': '99', 'type': 'comparison_operator', 'children': ['100', '104'], 'value': '=='}; {'id': '100', 'type': 'call', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'overlap'}; {'id': '104', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '105', 'type': 'block', 'children': ['106']}; {'id': '106', 'type': 'return_statement', 'children': ['107']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}; {'id': '109', 'type': 'assignment', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'keepers'}; {'id': '111', 'type': 'list_comprehension', 'children': ['112', '115', '124']}; {'id': '112', 'type': 'tuple', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '115', 'type': 'for_in_clause', 'children': ['116', '119']}; {'id': '116', 'type': 'pattern_list', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '119', 'type': 'call', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '123', 'type': 'argument_list', 'children': []}; {'id': '124', 'type': 'if_clause', 'children': ['125']}; {'id': '125', 'type': 'comparison_operator', 'children': ['126', '127'], 'value': 'not'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'inputs'}; {'id': '128', 'type': 'return_statement', 'children': ['129']}; {'id': '129', 'type': 'call', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '131', 'type': 'argument_list', 'children': ['132']}; {'id': '132', 'type': 'binary_operator', 'children': ['133', '134', '135'], 'value': '+'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'keepers'}; {'id': '134', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '135', 'type': 'list', 'children': ['136'], 'value': '[(output_phenotype_label,max([d[x] for x in overlap]))]'}; {'id': '136', 'type': 'tuple', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'output_phenotype_label'}; {'id': '138', 'type': 'call', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}; {'id': '141', 'type': 'list_comprehension', 'children': ['142', '145']}; {'id': '142', 'type': 'subscript', 'children': ['143', '144']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '145', 'type': 'for_in_clause', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'overlap'}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}; {'id': '149', 'type': 'assignment', 'children': ['150', '153']}; {'id': '150', 'type': 'subscript', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '152', 'type': 'string', 'children': [], 'value': "'phenotype_calls'"}; {'id': '153', 'type': 'call', 'children': ['154', '157']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'apply'}; {'id': '157', 'type': 'argument_list', 'children': ['158', '169']}; {'id': '158', 'type': 'lambda', 'children': ['159', '161']}; {'id': '159', 'type': 'lambda_parameters', 'children': ['160']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '161', 'type': 'call', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': '_swap_in'}; {'id': '163', 'type': 'argument_list', 'children': ['164', '167', '168']}; {'id': '164', 'type': 'subscript', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '166', 'type': 'string', 'children': [], 'value': "'phenotype_calls'"}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'input_phenotype_labels'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'output_phenotype_label'}; {'id': '169', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '170', 'type': 'function_definition', 'children': ['171', '172', '174']}; {'id': '171', 'type': 'function_name', 'children': [], 'value': '_set_label'}; {'id': '172', 'type': 'parameters', 'children': ['173']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '174', 'type': 'block', 'children': ['175', '193']}; {'id': '175', 'type': 'expression_statement', 'children': ['176']}; {'id': '176', 'type': 'assignment', 'children': ['177', '178']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'vals'}; {'id': '178', 'type': 'list_comprehension', 'children': ['179', '180', '189']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '180', 'type': 'for_in_clause', 'children': ['181', '184']}; {'id': '181', 'type': 'pattern_list', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '184', 'type': 'call', 'children': ['185', '188']}; {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '188', 'type': 'argument_list', 'children': []}; {'id': '189', 'type': 'if_clause', 'children': ['190']}; {'id': '190', 'type': 'comparison_operator', 'children': ['191', '192'], 'value': '=='}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '192', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '193', 'type': 'return_statement', 'children': ['194']}; {'id': '194', 'type': 'conditional_expression', 'children': ['195', '198', '204'], 'value': 'if'}; {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'nan'}; {'id': '198', 'type': 'comparison_operator', 'children': ['199', '203'], 'value': '=='}; {'id': '199', 'type': 'call', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '201', 'type': 'argument_list', 'children': ['202']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'vals'}; {'id': '203', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '204', 'type': 'subscript', 'children': ['205', '206']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'vals'}; {'id': '206', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '207', 'type': 'expression_statement', 'children': ['208']}; {'id': '208', 'type': 'assignment', 'children': ['209', '212']}; {'id': '209', 'type': 'subscript', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '211', 'type': 'string', 'children': [], 'value': "'phenotype_label'"}; {'id': '212', 'type': 'call', 'children': ['213', '216']}; {'id': '213', 'type': 'attribute', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'apply'}; {'id': '216', 'type': 'argument_list', 'children': ['217', '226']}; {'id': '217', 'type': 'lambda', 'children': ['218', '220']}; {'id': '218', 'type': 'lambda_parameters', 'children': ['219']}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '220', 'type': 'call', 'children': ['221', '222']}; {'id': '221', 'type': 'identifier', 'children': [], 'value': '_set_label'}; {'id': '222', 'type': 'argument_list', 'children': ['223']}; {'id': '223', 'type': 'subscript', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '225', 'type': 'string', 'children': [], 'value': "'phenotype_calls'"}; {'id': '226', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '227', 'type': 'return_statement', 'children': ['228']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'data'}
|
def collapse_phenotypes(self,input_phenotype_labels,output_phenotype_label,verbose=True):
if isinstance(input_phenotype_labels,str): input_phenotype_labels = [input_phenotype_labels]
bad_phenotypes = set(input_phenotype_labels)-set(self.phenotypes)
if len(bad_phenotypes) > 0: raise ValueError("Error phenotype(s) "+str(bad_phenotypes)+" are not in the data.")
data = self.copy()
if len(input_phenotype_labels) == 0: return data
def _swap_in(d,inputs,output):
overlap = set(d.keys()).intersection(inputs)
if len(overlap) == 0: return d
keepers = [(k,v) for k,v in d.items() if k not in inputs]
return dict(keepers+\
[(output_phenotype_label,max([d[x] for x in overlap]))])
data['phenotype_calls'] = data.apply(lambda x:
_swap_in(x['phenotype_calls'],input_phenotype_labels,output_phenotype_label)
,1)
def _set_label(d):
vals = [k for k,v in d.items() if v==1]
return np.nan if len(vals) == 0 else vals[0]
data['phenotype_label'] = data.apply(lambda x:
_set_label(x['phenotype_calls']),1)
return data
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'scored_to_phenotype'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'phenotypes'}; {'id': '6', 'type': 'block', 'children': ['7', '85', '93', '114', '145']}; {'id': '7', 'type': 'function_definition', 'children': ['8', '9', '12']}; {'id': '8', 'type': 'function_name', 'children': [], 'value': '_apply_score'}; {'id': '9', 'type': 'parameters', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'scored_calls'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'phenotypes'}; {'id': '12', 'type': 'block', 'children': ['13', '35', '48', '58', '67', '80']}; {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'present'}; {'id': '16', 'type': 'call', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}; {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'binary_operator', 'children': ['23', '27'], 'value': '&'}; {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'phenotypes'}; {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '34']}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'scored_calls'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '34', 'type': 'argument_list', 'children': []}; {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'total'}; {'id': '38', 'type': 'call', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}; {'id': '41', 'type': 'list_comprehension', 'children': ['42', '45']}; {'id': '42', 'type': 'subscript', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'scored_calls'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '45', 'type': 'for_in_clause', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'present'}; {'id': '48', 'type': 'if_statement', 'children': ['49', '52']}; {'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': '>'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'total'}; {'id': '51', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '52', 'type': 'block', 'children': ['53']}; {'id': '53', 'type': 'raise_statement', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}; {'id': '57', 'type': 'string', 'children': [], 'value': '"You cant extract phenotypes from scores if they are not mutually exclusive"'}; {'id': '58', 'type': 'if_statement', 'children': ['59', '62']}; {'id': '59', 'type': 'comparison_operator', 'children': ['60', '61'], 'value': '=='}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'total'}; {'id': '61', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '62', 'type': 'block', 'children': ['63']}; {'id': '63', 'type': 'return_statement', 'children': ['64']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'nan'}; {'id': '67', 'type': 'for_statement', 'children': ['68', '69', '70']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'present'}; {'id': '70', 'type': 'block', 'children': ['71']}; {'id': '71', 'type': 'if_statement', 'children': ['72', '77']}; {'id': '72', 'type': 'comparison_operator', 'children': ['73', '76'], 'value': '=='}; {'id': '73', 'type': 'subscript', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'scored_calls'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '76', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '77', 'type': 'block', 'children': ['78']}; {'id': '78', 'type': 'return_statement', 'children': ['79']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '80', 'type': 'raise_statement', 'children': ['81']}; {'id': '81', 'type': 'call', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'string', 'children': [], 'value': '"Should have hit an exit criteria already"'}; {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '88', 'type': 'call', 'children': ['89', '92']}; {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '92', 'type': 'argument_list', 'children': []}; {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '98']}; {'id': '95', 'type': 'subscript', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '97', 'type': 'string', 'children': [], 'value': "'phenotype_label'"}; {'id': '98', 'type': 'call', 'children': ['99', '102']}; {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'apply'}; {'id': '102', 'type': 'argument_list', 'children': ['103', '113']}; {'id': '103', 'type': 'lambda', 'children': ['104', '106']}; {'id': '104', 'type': 'lambda_parameters', 'children': ['105']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '106', 'type': 'call', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': '_apply_score'}; {'id': '108', 'type': 'argument_list', 'children': ['109', '112']}; {'id': '109', 'type': 'subscript', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '111', 'type': 'string', 'children': [], 'value': "'scored_calls'"}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'phenotypes'}; {'id': '113', 'type': 'integer', 'children': [], 'value': '1'}; {'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': 'output'}; {'id': '118', 'type': 'string', 'children': [], 'value': "'phenotype_calls'"}; {'id': '119', 'type': 'call', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'apply'}; {'id': '123', 'type': 'argument_list', 'children': ['124', '144']}; {'id': '124', 'type': 'lambda', 'children': ['125', '127']}; {'id': '125', 'type': 'lambda_parameters', 'children': ['126']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '127', 'type': 'call', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '129', 'type': 'argument_list', 'children': ['130']}; {'id': '130', 'type': 'list_comprehension', 'children': ['131', '141']}; {'id': '131', 'type': 'tuple', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '133', 'type': 'conditional_expression', 'children': ['134', '135', '140'], 'value': 'if'}; {'id': '134', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '135', 'type': 'comparison_operator', 'children': ['136', '139'], 'value': '=='}; {'id': '136', 'type': 'subscript', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '138', 'type': 'string', 'children': [], 'value': "'phenotype_label'"}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '140', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '141', 'type': 'for_in_clause', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'phenotypes'}; {'id': '144', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '145', 'type': 'return_statement', 'children': ['146']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'output'}
|
def scored_to_phenotype(self,phenotypes):
def _apply_score(scored_calls,phenotypes):
present = sorted(list(set(phenotypes)&set(scored_calls.keys())))
total = sum([scored_calls[x] for x in present])
if total > 1:
raise ValueError("You cant extract phenotypes from scores if they are not mutually exclusive")
if total == 0: return np.nan
for label in present:
if scored_calls[label] == 1: return label
raise ValueError("Should have hit an exit criteria already")
output = self.copy()
output['phenotype_label'] = output.apply(lambda x: _apply_score(x['scored_calls'],phenotypes),1)
output['phenotype_calls'] = output.apply(lambda x:
dict([(y,1 if x['phenotype_label']==y else 0) for y in phenotypes])
,1)
return output
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'spike_times'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'signal'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'threshold'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'fs'}; {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'absval'}; {'id': '9', 'type': 'True', 'children': []}; {'id': '10', 'type': 'block', 'children': ['11', '15', '27', '39', '56', '297']}; {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'times'}; {'id': '14', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '15', 'type': 'if_statement', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'absval'}; {'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': 'signal'}; {'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': 'abs'}; {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'signal'}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '31']}; {'id': '29', 'type': 'pattern_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'over'}; {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'where'}; {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': '>'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'signal'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'threshold'}; {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '43']}; {'id': '41', 'type': 'pattern_list', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'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': 'where'}; {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'comparison_operator', 'children': ['49', '55'], 'value': '>'}; {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'diff'}; {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'over'}; {'id': '55', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '56', 'type': 'if_statement', 'children': ['57', '63', '275']}; {'id': '57', 'type': 'comparison_operator', 'children': ['58', '62'], 'value': '>'}; {'id': '58', 'type': 'call', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'over'}; {'id': '62', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '63', 'type': 'block', 'children': ['64', '183']}; {'id': '64', 'type': 'if_statement', 'children': ['65', '71', '83']}; {'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': 'segments'}; {'id': '70', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '71', 'type': 'block', 'children': ['72']}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}; {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '75', 'type': 'list', 'children': ['76', '77'], 'value': '[0, len(over)-1]'}; {'id': '76', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '77', 'type': 'binary_operator', 'children': ['78', '82'], 'value': '-'}; {'id': '78', 'type': 'call', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'over'}; {'id': '82', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '83', 'type': 'else_clause', 'children': ['84']}; {'id': '84', 'type': 'block', 'children': ['85', '132']}; {'id': '85', 'type': 'if_statement', 'children': ['86', '91', '105']}; {'id': '86', 'type': 'comparison_operator', 'children': ['87', '90'], 'value': '!='}; {'id': '87', 'type': 'subscript', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '89', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '90', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '91', 'type': 'block', 'children': ['92']}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}; {'id': '93', 'type': 'assignment', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'insert'}; {'id': '99', 'type': 'argument_list', 'children': ['100', '101', '103']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '101', 'type': 'list', 'children': ['102'], 'value': '[0]'}; {'id': '102', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '103', 'type': 'list', 'children': ['104'], 'value': '[0]'}; {'id': '104', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '105', 'type': 'else_clause', 'children': ['106']}; {'id': '106', 'type': 'block', 'children': ['107', '121']}; {'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': 'times'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}; {'id': '113', 'type': 'binary_operator', 'children': ['114', '120'], 'value': '/'}; {'id': '114', 'type': 'call', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '116', 'type': 'argument_list', 'children': ['117']}; {'id': '117', 'type': 'subscript', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'over'}; {'id': '119', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'fs'}; {'id': '121', 'type': 'if_statement', 'children': ['122', '125']}; {'id': '122', 'type': 'comparison_operator', 'children': ['123', '124'], 'value': 'not'}; {'id': '123', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '125', 'type': 'block', 'children': ['126']}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}; {'id': '127', 'type': 'assignment', 'children': ['128', '131']}; {'id': '128', 'type': 'subscript', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '130', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '131', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '132', 'type': 'if_statement', 'children': ['133', '144', '166']}; {'id': '133', 'type': 'comparison_operator', 'children': ['134', '138'], 'value': '!='}; {'id': '134', 'type': 'subscript', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '136', 'type': 'unary_operator', 'children': ['137'], 'value': '-'}; {'id': '137', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '138', 'type': 'binary_operator', 'children': ['139', '143'], 'value': '-'}; {'id': '139', 'type': 'call', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'over'}; {'id': '143', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '144', 'type': 'block', 'children': ['145']}; {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'assignment', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '148', 'type': 'call', 'children': ['149', '152']}; {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'insert'}; {'id': '152', 'type': 'argument_list', 'children': ['153', '154', '159']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '154', 'type': 'list', 'children': ['155'], 'value': '[len(segments)]'}; {'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': 'segments'}; {'id': '159', 'type': 'list', 'children': ['160'], 'value': '[len(over)-1]'}; {'id': '160', 'type': 'binary_operator', 'children': ['161', '165'], 'value': '-'}; {'id': '161', 'type': 'call', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '163', 'type': 'argument_list', 'children': ['164']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'over'}; {'id': '165', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '166', 'type': 'else_clause', 'children': ['167']}; {'id': '167', 'type': 'block', 'children': ['168']}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}; {'id': '169', 'type': 'call', 'children': ['170', '173']}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'times'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'binary_operator', 'children': ['175', '182'], 'value': '/'}; {'id': '175', 'type': 'call', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '177', 'type': 'argument_list', 'children': ['178']}; {'id': '178', 'type': 'subscript', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'over'}; {'id': '180', 'type': 'unary_operator', 'children': ['181'], 'value': '-'}; {'id': '181', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'fs'}; {'id': '183', 'type': 'for_statement', 'children': ['184', '185', '193']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'iseg'}; {'id': '185', 'type': 'call', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '187', 'type': 'argument_list', 'children': ['188', '189']}; {'id': '188', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '189', 'type': 'call', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '191', 'type': 'argument_list', 'children': ['192']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '193', 'type': 'block', 'children': ['194', '263']}; {'id': '194', 'type': 'if_statement', 'children': ['195', '206', '215']}; {'id': '195', 'type': 'comparison_operator', 'children': ['196', '205'], 'value': '=='}; {'id': '196', 'type': 'binary_operator', 'children': ['197', '200'], 'value': '-'}; {'id': '197', 'type': 'subscript', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'iseg'}; {'id': '200', 'type': 'subscript', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '202', 'type': 'binary_operator', 'children': ['203', '204'], 'value': '-'}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'iseg'}; {'id': '204', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '205', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '206', 'type': 'block', 'children': ['207']}; {'id': '207', 'type': 'expression_statement', 'children': ['208']}; {'id': '208', 'type': 'assignment', 'children': ['209', '210']}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '210', 'type': 'subscript', 'children': ['211', '212']}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'over'}; {'id': '212', 'type': 'subscript', 'children': ['213', '214']}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'iseg'}; {'id': '215', 'type': 'else_clause', 'children': ['216']}; {'id': '216', 'type': 'block', 'children': ['217', '227']}; {'id': '217', 'type': 'expression_statement', 'children': ['218']}; {'id': '218', 'type': 'assignment', 'children': ['219', '222']}; {'id': '219', 'type': 'subscript', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '221', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '222', 'type': 'binary_operator', 'children': ['223', '226'], 'value': '-'}; {'id': '223', 'type': 'subscript', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '225', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '226', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '227', 'type': 'expression_statement', 'children': ['228']}; {'id': '228', 'type': 'assignment', 'children': ['229', '230']}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '230', 'type': 'binary_operator', 'children': ['231', '240'], 'value': '+'}; {'id': '231', 'type': 'subscript', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'over'}; {'id': '233', 'type': 'binary_operator', 'children': ['234', '239'], 'value': '+'}; {'id': '234', 'type': 'subscript', 'children': ['235', '236']}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '236', 'type': 'binary_operator', 'children': ['237', '238'], 'value': '-'}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'iseg'}; {'id': '238', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '239', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '240', 'type': 'call', 'children': ['241', '244']}; {'id': '241', 'type': 'attribute', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'argmax'}; {'id': '244', 'type': 'argument_list', 'children': ['245']}; {'id': '245', 'type': 'subscript', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'signal'}; {'id': '247', 'type': 'slice', 'children': ['248', '257', '258']}; {'id': '248', 'type': 'subscript', 'children': ['249', '250']}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'over'}; {'id': '250', 'type': 'binary_operator', 'children': ['251', '256'], 'value': '+'}; {'id': '251', 'type': 'subscript', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '253', 'type': 'binary_operator', 'children': ['254', '255'], 'value': '-'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'iseg'}; {'id': '255', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '256', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '257', 'type': 'colon', 'children': []}; {'id': '258', 'type': 'subscript', 'children': ['259', '260']}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'over'}; {'id': '260', 'type': 'subscript', 'children': ['261', '262']}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'iseg'}; {'id': '263', 'type': 'expression_statement', 'children': ['264']}; {'id': '264', 'type': 'call', 'children': ['265', '268']}; {'id': '265', 'type': 'attribute', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'times'}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '268', 'type': 'argument_list', 'children': ['269']}; {'id': '269', 'type': 'binary_operator', 'children': ['270', '274'], 'value': '/'}; {'id': '270', 'type': 'call', 'children': ['271', '272']}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '272', 'type': 'argument_list', 'children': ['273']}; {'id': '273', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'fs'}; {'id': '275', 'type': 'elif_clause', 'children': ['276', '282']}; {'id': '276', 'type': 'comparison_operator', 'children': ['277', '281'], 'value': '=='}; {'id': '277', 'type': 'call', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '279', 'type': 'argument_list', 'children': ['280']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'over'}; {'id': '281', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '282', 'type': 'block', 'children': ['283']}; {'id': '283', 'type': 'expression_statement', 'children': ['284']}; {'id': '284', 'type': 'call', 'children': ['285', '288']}; {'id': '285', 'type': 'attribute', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'times'}; {'id': '287', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '288', 'type': 'argument_list', 'children': ['289']}; {'id': '289', 'type': 'binary_operator', 'children': ['290', '296'], 'value': '/'}; {'id': '290', 'type': 'call', 'children': ['291', '292']}; {'id': '291', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '292', 'type': 'argument_list', 'children': ['293']}; {'id': '293', 'type': 'subscript', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'over'}; {'id': '295', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'fs'}; {'id': '297', 'type': 'if_statement', 'children': ['298', '304', '310']}; {'id': '298', 'type': 'comparison_operator', 'children': ['299', '303'], 'value': '>'}; {'id': '299', 'type': 'call', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '301', 'type': 'argument_list', 'children': ['302']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'times'}; {'id': '303', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '304', 'type': 'block', 'children': ['305']}; {'id': '305', 'type': 'return_statement', 'children': ['306']}; {'id': '306', 'type': 'call', 'children': ['307', '308']}; {'id': '307', 'type': 'identifier', 'children': [], 'value': 'refractory'}; {'id': '308', 'type': 'argument_list', 'children': ['309']}; {'id': '309', 'type': 'identifier', 'children': [], 'value': 'times'}; {'id': '310', 'type': 'else_clause', 'children': ['311']}; {'id': '311', 'type': 'block', 'children': ['312']}; {'id': '312', 'type': 'return_statement', 'children': ['313']}; {'id': '313', 'type': 'identifier', 'children': [], 'value': 'times'}
|
def spike_times(signal, threshold, fs, absval=True):
times = []
if absval:
signal = np.abs(signal)
over, = np.where(signal>threshold)
segments, = np.where(np.diff(over) > 1)
if len(over) > 1:
if len(segments) == 0:
segments = [0, len(over)-1]
else:
if segments[0] != 0:
segments = np.insert(segments, [0], [0])
else:
times.append(float(over[0])/fs)
if 1 not in segments:
segments[0] = 1
if segments[-1] != len(over)-1:
segments = np.insert(segments, [len(segments)], [len(over)-1])
else:
times.append(float(over[-1])/fs)
for iseg in range(1,len(segments)):
if segments[iseg] - segments[iseg-1] == 1:
idx = over[segments[iseg]]
else:
segments[0] = segments[0]-1
idx = over[segments[iseg-1]+1] + np.argmax(signal[over[segments[iseg-1]+1]:over[segments[iseg]]])
times.append(float(idx)/fs)
elif len(over) == 1:
times.append(float(over[0])/fs)
if len(times)>0:
return refractory(times)
else:
return times
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'bin_spikes'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'spike_times'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'binsz'}; {'id': '6', 'type': 'block', 'children': ['7', '23', '51']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'bins'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'empty'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '20']}; {'id': '15', 'type': 'tuple', 'children': ['16']}; {'id': '16', 'type': 'call', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'spike_times'}; {'id': '20', 'type': 'keyword_argument', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '23', 'type': 'for_statement', 'children': ['24', '27', '31']}; {'id': '24', 'type': 'pattern_list', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'stime'}; {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'spike_times'}; {'id': '31', 'type': 'block', 'children': ['32']}; {'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': 'bins'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'floor'}; {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '46']}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'around'}; {'id': '46', 'type': 'argument_list', 'children': ['47', '50']}; {'id': '47', 'type': 'binary_operator', 'children': ['48', '49'], 'value': '/'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'stime'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'binsz'}; {'id': '50', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '51', 'type': 'return_statement', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'bins'}
|
def bin_spikes(spike_times, binsz):
bins = np.empty((len(spike_times),), dtype=int)
for i, stime in enumerate(spike_times):
bins[i] = np.floor(np.around(stime/binsz, 5))
return bins
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'corewriter'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '14', '243', '288']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'call', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'printtime'}; {'id': '9', 'type': 'argument_list', 'children': ['10', '11']}; {'id': '10', 'type': 'string', 'children': [], 'value': "'Creating core allele files'"}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '14', 'type': 'for_statement', 'children': ['15', '16', '22']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'gene'}; {'id': '16', 'type': 'call', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'genesequence'}; {'id': '22', 'type': 'block', 'children': ['23', '32', '51']}; {'id': '23', 'type': 'expression_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': 'geneset'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'gene'}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'genefile'}; {'id': '35', 'type': 'call', 'children': ['36', '41']}; {'id': '36', 'type': 'attribute', 'children': ['37', '40']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '41', 'type': 'argument_list', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'coregenelocation'}; {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'string', 'children': [], 'value': "'{}.fasta'"}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'gene'}; {'id': '51', 'type': 'if_statement', 'children': ['52', '61', '176']}; {'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': 'isfile'}; {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'genefile'}; {'id': '61', 'type': 'block', 'children': ['62']}; {'id': '62', 'type': 'with_statement', 'children': ['63', '73']}; {'id': '63', 'type': 'with_clause', 'children': ['64']}; {'id': '64', 'type': 'with_item', 'children': ['65']}; {'id': '65', 'type': 'as_pattern', 'children': ['66', '71']}; {'id': '66', 'type': 'call', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '68', 'type': 'argument_list', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'genefile'}; {'id': '70', 'type': 'string', 'children': [], 'value': "'w'"}; {'id': '71', 'type': 'as_pattern_target', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'core'}; {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'for_statement', 'children': ['75', '78', '86']}; {'id': '75', 'type': 'pattern_list', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'sequence'}; {'id': '78', 'type': 'call', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}; {'id': '81', 'type': 'subscript', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'genesequence'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'gene'}; {'id': '86', 'type': 'block', 'children': ['87', '99', '115', '124']}; {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'definitionline'}; {'id': '90', 'type': 'call', 'children': ['91', '94']}; {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'string', 'children': [], 'value': "'{}-{}'"}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '94', 'type': 'argument_list', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'gene'}; {'id': '96', 'type': 'binary_operator', 'children': ['97', '98'], 'value': '+'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '98', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'fasta'}; {'id': '102', 'type': 'call', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'SeqRecord'}; {'id': '104', 'type': 'argument_list', 'children': ['105', '109', '112']}; {'id': '105', 'type': 'call', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'Seq'}; {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'sequence'}; {'id': '109', 'type': 'keyword_argument', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'description'}; {'id': '111', 'type': 'string', 'children': [], 'value': "''"}; {'id': '112', 'type': 'keyword_argument', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'definitionline'}; {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'call', 'children': ['117', '120']}; {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'SeqIO'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '120', 'type': 'argument_list', 'children': ['121', '122', '123']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'fasta'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'core'}; {'id': '123', 'type': 'string', 'children': [], 'value': "'fasta'"}; {'id': '124', 'type': 'for_statement', 'children': ['125', '126', '131']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'strain'}; {'id': '126', 'type': 'subscript', 'children': ['127', '130']}; {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'coresequence'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'sequence'}; {'id': '131', 'type': 'block', 'children': ['132']}; {'id': '132', 'type': 'try_statement', 'children': ['133', '155']}; {'id': '133', 'type': 'block', 'children': ['134']}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}; {'id': '135', 'type': 'call', 'children': ['136', '148']}; {'id': '136', 'type': 'attribute', 'children': ['137', '147']}; {'id': '137', 'type': 'subscript', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'corealleles'}; {'id': '141', 'type': 'subscript', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'strain'}; {'id': '143', 'type': 'slice', 'children': ['144', '145']}; {'id': '144', 'type': 'colon', 'children': []}; {'id': '145', 'type': 'unary_operator', 'children': ['146'], 'value': '-'}; {'id': '146', 'type': 'integer', 'children': [], 'value': '6'}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '148', 'type': 'argument_list', 'children': ['149']}; {'id': '149', 'type': 'dictionary', 'children': ['150']}; {'id': '150', 'type': 'pair', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'gene'}; {'id': '152', 'type': 'binary_operator', 'children': ['153', '154'], 'value': '+'}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '154', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '155', 'type': 'except_clause', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '157', 'type': 'block', 'children': ['158']}; {'id': '158', 'type': 'expression_statement', 'children': ['159']}; {'id': '159', 'type': 'assignment', 'children': ['160', '170']}; {'id': '160', 'type': 'subscript', 'children': ['161', '164']}; {'id': '161', 'type': 'attribute', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'corealleles'}; {'id': '164', 'type': 'subscript', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'strain'}; {'id': '166', 'type': 'slice', 'children': ['167', '168']}; {'id': '167', 'type': 'colon', 'children': []}; {'id': '168', 'type': 'unary_operator', 'children': ['169'], 'value': '-'}; {'id': '169', 'type': 'integer', 'children': [], 'value': '6'}; {'id': '170', 'type': 'dictionary', 'children': ['171']}; {'id': '171', 'type': 'pair', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'gene'}; {'id': '173', 'type': 'binary_operator', 'children': ['174', '175'], 'value': '+'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '175', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '176', 'type': 'else_clause', 'children': ['177']}; {'id': '177', 'type': 'block', 'children': ['178']}; {'id': '178', 'type': 'for_statement', 'children': ['179', '182', '190']}; {'id': '179', 'type': 'pattern_list', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'sequence'}; {'id': '182', 'type': 'call', 'children': ['183', '184']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '184', 'type': 'argument_list', 'children': ['185']}; {'id': '185', 'type': 'subscript', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'genesequence'}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'gene'}; {'id': '190', 'type': 'block', 'children': ['191']}; {'id': '191', 'type': 'for_statement', 'children': ['192', '193', '198']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'strain'}; {'id': '193', 'type': 'subscript', 'children': ['194', '197']}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'coresequence'}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'sequence'}; {'id': '198', 'type': 'block', 'children': ['199']}; {'id': '199', 'type': 'try_statement', 'children': ['200', '222']}; {'id': '200', 'type': 'block', 'children': ['201']}; {'id': '201', 'type': 'expression_statement', 'children': ['202']}; {'id': '202', 'type': 'call', 'children': ['203', '215']}; {'id': '203', 'type': 'attribute', 'children': ['204', '214']}; {'id': '204', 'type': 'subscript', 'children': ['205', '208']}; {'id': '205', 'type': 'attribute', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'corealleles'}; {'id': '208', 'type': 'subscript', 'children': ['209', '210']}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'strain'}; {'id': '210', 'type': 'slice', 'children': ['211', '212']}; {'id': '211', 'type': 'colon', 'children': []}; {'id': '212', 'type': 'unary_operator', 'children': ['213'], 'value': '-'}; {'id': '213', 'type': 'integer', 'children': [], 'value': '6'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '215', 'type': 'argument_list', 'children': ['216']}; {'id': '216', 'type': 'dictionary', 'children': ['217']}; {'id': '217', 'type': 'pair', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'gene'}; {'id': '219', 'type': 'binary_operator', 'children': ['220', '221'], 'value': '+'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '221', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '222', 'type': 'except_clause', 'children': ['223', '224']}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '224', 'type': 'block', 'children': ['225']}; {'id': '225', 'type': 'expression_statement', 'children': ['226']}; {'id': '226', 'type': 'assignment', 'children': ['227', '237']}; {'id': '227', 'type': 'subscript', 'children': ['228', '231']}; {'id': '228', 'type': 'attribute', 'children': ['229', '230']}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'corealleles'}; {'id': '231', 'type': 'subscript', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'strain'}; {'id': '233', 'type': 'slice', 'children': ['234', '235']}; {'id': '234', 'type': 'colon', 'children': []}; {'id': '235', 'type': 'unary_operator', 'children': ['236'], 'value': '-'}; {'id': '236', 'type': 'integer', 'children': [], 'value': '6'}; {'id': '237', 'type': 'dictionary', 'children': ['238']}; {'id': '238', 'type': 'pair', 'children': ['239', '240']}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'gene'}; {'id': '240', 'type': 'binary_operator', 'children': ['241', '242'], 'value': '+'}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '242', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '243', 'type': 'if_statement', 'children': ['244', '263']}; {'id': '244', 'type': 'not_operator', 'children': ['245']}; {'id': '245', 'type': 'call', 'children': ['246', '251']}; {'id': '246', 'type': 'attribute', 'children': ['247', '250']}; {'id': '247', 'type': 'attribute', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'isfile'}; {'id': '251', 'type': 'argument_list', 'children': ['252']}; {'id': '252', 'type': 'call', 'children': ['253', '258']}; {'id': '253', 'type': 'attribute', 'children': ['254', '257']}; {'id': '254', 'type': 'attribute', 'children': ['255', '256']}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '258', 'type': 'argument_list', 'children': ['259', '262']}; {'id': '259', 'type': 'attribute', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'coregenelocation'}; {'id': '262', 'type': 'string', 'children': [], 'value': "'core_combined.fasta'"}; {'id': '263', 'type': 'block', 'children': ['264', '281']}; {'id': '264', 'type': 'expression_statement', 'children': ['265']}; {'id': '265', 'type': 'assignment', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'fastafiles'}; {'id': '267', 'type': 'call', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'glob'}; {'id': '269', 'type': 'argument_list', 'children': ['270']}; {'id': '270', 'type': 'call', 'children': ['271', '276']}; {'id': '271', 'type': 'attribute', 'children': ['272', '275']}; {'id': '272', 'type': 'attribute', 'children': ['273', '274']}; {'id': '273', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '276', 'type': 'argument_list', 'children': ['277', '280']}; {'id': '277', 'type': 'attribute', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '279', 'type': 'identifier', 'children': [], 'value': 'coregenelocation'}; {'id': '280', 'type': 'string', 'children': [], 'value': "'*.fasta'"}; {'id': '281', 'type': 'expression_statement', 'children': ['282']}; {'id': '282', 'type': 'call', 'children': ['283', '286']}; {'id': '283', 'type': 'attribute', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '285', 'type': 'identifier', 'children': [], 'value': 'combinealleles'}; {'id': '286', 'type': 'argument_list', 'children': ['287']}; {'id': '287', 'type': 'identifier', 'children': [], 'value': 'fastafiles'}; {'id': '288', 'type': 'expression_statement', 'children': ['289']}; {'id': '289', 'type': 'call', 'children': ['290', '293']}; {'id': '290', 'type': 'attribute', 'children': ['291', '292']}; {'id': '291', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'profiler'}; {'id': '293', 'type': 'argument_list', 'children': []}
|
def corewriter(self):
printtime('Creating core allele files', self.start)
for gene in sorted(self.genesequence):
self.geneset.add(gene)
genefile = os.path.join(self.coregenelocation, '{}.fasta'.format(gene))
if not os.path.isfile(genefile):
with open(genefile, 'w') as core:
for count, sequence in enumerate(self.genesequence[gene]):
definitionline = '{}-{}'.format(gene, count + 1)
fasta = SeqRecord(Seq(sequence),
description='',
id=definitionline)
SeqIO.write(fasta, core, 'fasta')
for strain in self.coresequence[sequence]:
try:
self.corealleles[strain[:-6]].update({gene: count + 1})
except KeyError:
self.corealleles[strain[:-6]] = {gene: count + 1}
else:
for count, sequence in enumerate(self.genesequence[gene]):
for strain in self.coresequence[sequence]:
try:
self.corealleles[strain[:-6]].update({gene: count + 1})
except KeyError:
self.corealleles[strain[:-6]] = {gene: count + 1}
if not os.path.isfile(os.path.join(self.coregenelocation, 'core_combined.fasta')):
fastafiles = glob(os.path.join(self.coregenelocation, '*.fasta'))
self.combinealleles(fastafiles)
self.profiler()
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'profiler'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '14', '43', '62', '66', '148', '184']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'call', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'printtime'}; {'id': '9', 'type': 'argument_list', 'children': ['10', '11']}; {'id': '10', 'type': 'string', 'children': [], 'value': "'Calculating core profiles'"}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '14', 'type': 'for_statement', 'children': ['15', '16', '19']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'strain'}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'corealleles'}; {'id': '19', 'type': 'block', 'children': ['20']}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}; {'id': '21', 'type': 'call', 'children': ['22', '27']}; {'id': '22', 'type': 'attribute', 'children': ['23', '26']}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'coreset'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'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']}; {'id': '34', 'type': 'call', 'children': ['35', '42']}; {'id': '35', 'type': 'attribute', 'children': ['36', '41']}; {'id': '36', 'type': 'subscript', 'children': ['37', '40']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'corealleles'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'strain'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '42', 'type': 'argument_list', 'children': []}; {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '46', 'type': 'call', 'children': ['47', '50']}; {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'string', 'children': [], 'value': "'ST,{}\\n'"}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}; {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'string', 'children': [], 'value': "','"}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'join'}; {'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']}; {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'geneset'}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}; {'id': '63', 'type': 'assignment', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '65', 'type': 'string', 'children': [], 'value': "''"}; {'id': '66', 'type': 'for_statement', 'children': ['67', '70', '79']}; {'id': '67', 'type': 'pattern_list', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'core'}; {'id': '70', 'type': 'call', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}; {'id': '73', 'type': 'call', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'coreset'}; {'id': '79', 'type': 'block', 'children': ['80', '84', '93', '126', '144']}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}; {'id': '81', 'type': 'augmented_assignment', 'children': ['82', '83'], 'value': '+='}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '83', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}; {'id': '85', 'type': 'augmented_assignment', 'children': ['86', '87'], 'value': '+='}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}; {'id': '89', 'type': 'string', 'children': [], 'value': "'{}'"}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '93', 'type': 'for_statement', 'children': ['94', '95', '98']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'strain'}; {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'corealleles'}; {'id': '98', 'type': 'block', 'children': ['99']}; {'id': '99', 'type': 'if_statement', 'children': ['100', '117']}; {'id': '100', 'type': 'comparison_operator', 'children': ['101', '116'], 'value': '=='}; {'id': '101', 'type': 'call', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '103', 'type': 'argument_list', 'children': ['104']}; {'id': '104', 'type': 'call', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}; {'id': '107', 'type': 'call', 'children': ['108', '115']}; {'id': '108', 'type': 'attribute', 'children': ['109', '114']}; {'id': '109', 'type': 'subscript', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'corealleles'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'strain'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '115', 'type': 'argument_list', 'children': []}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'core'}; {'id': '117', 'type': 'block', 'children': ['118']}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}; {'id': '119', 'type': 'assignment', 'children': ['120', '125']}; {'id': '120', 'type': 'subscript', 'children': ['121', '124']}; {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'profiles'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'strain'}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '126', 'type': 'for_statement', 'children': ['127', '128', '132']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'gene'}; {'id': '128', 'type': 'call', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'core'}; {'id': '132', 'type': 'block', 'children': ['133']}; {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'augmented_assignment', 'children': ['135', '136'], 'value': '+='}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '136', 'type': 'call', 'children': ['137', '140']}; {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'string', 'children': [], 'value': "',{}'"}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}; {'id': '141', 'type': 'subscript', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'gene'}; {'id': '143', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}; {'id': '145', 'type': 'augmented_assignment', 'children': ['146', '147'], 'value': '+='}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '147', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '148', 'type': 'with_statement', 'children': ['149', '169']}; {'id': '149', 'type': 'with_clause', 'children': ['150']}; {'id': '150', 'type': 'with_item', 'children': ['151']}; {'id': '151', 'type': 'as_pattern', 'children': ['152', '167']}; {'id': '152', 'type': 'call', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '154', 'type': 'argument_list', 'children': ['155', '166']}; {'id': '155', 'type': 'call', 'children': ['156', '161']}; {'id': '156', 'type': 'attribute', 'children': ['157', '160']}; {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '161', 'type': 'argument_list', 'children': ['162', '165']}; {'id': '162', 'type': 'attribute', 'children': ['163', '164']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'profilelocation'}; {'id': '165', 'type': 'string', 'children': [], 'value': "'profile.txt'"}; {'id': '166', 'type': 'string', 'children': [], 'value': "'w'"}; {'id': '167', 'type': 'as_pattern_target', 'children': ['168']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'profile'}; {'id': '169', 'type': 'block', 'children': ['170', '177']}; {'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': 'profile'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '175', 'type': 'argument_list', 'children': ['176']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '177', 'type': 'expression_statement', 'children': ['178']}; {'id': '178', 'type': 'call', 'children': ['179', '182']}; {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'profile'}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '182', 'type': 'argument_list', 'children': ['183']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '184', 'type': 'expression_statement', 'children': ['185']}; {'id': '185', 'type': 'call', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'linker'}; {'id': '189', 'type': 'argument_list', 'children': []}
|
def profiler(self):
printtime('Calculating core profiles', self.start)
for strain in self.corealleles:
self.coreset.add(tuple(sorted(self.corealleles[strain].items())))
header = 'ST,{}\n'.format(','.join(sorted(self.geneset)))
data = ''
for count, core in sorted(enumerate(self.coreset)):
count += 1
data += '{}'.format(count)
for strain in self.corealleles:
if tuple(sorted(self.corealleles[strain].items())) == core:
self.profiles[strain] = count
for gene in sorted(core):
data += ',{}'.format(gene[1])
data += '\n'
with open(os.path.join(self.profilelocation, 'profile.txt'), 'w') as profile:
profile.write(header)
profile.write(data)
self.linker()
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '23']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'row2dict'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'depth'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'exclude'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'exclude_pk'}; {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'exclude_underscore'}; {'id': '16', 'type': 'None', 'children': []}; {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'only'}; {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'fk_suffix'}; {'id': '22', 'type': 'None', 'children': []}; {'id': '23', 'type': 'block', 'children': ['24', '31', '42', '64', '78', '92', '106', '120', '134', '192', '306']}; {'id': '24', 'type': 'if_statement', 'children': ['25', '28']}; {'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': '=='}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'depth'}; {'id': '27', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '28', 'type': 'block', 'children': ['29']}; {'id': '29', 'type': 'return_statement', 'children': ['30']}; {'id': '30', 'type': 'None', 'children': []}; {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '36']}; {'id': '33', 'type': 'pattern_list', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'mapper'}; {'id': '36', 'type': 'expression_list', 'children': ['37', '38']}; {'id': '37', 'type': 'dictionary', 'children': []}; {'id': '38', 'type': 'call', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'get_mapper'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '42', 'type': 'if_statement', 'children': ['43', '46', '58']}; {'id': '43', 'type': 'comparison_operator', 'children': ['44', '45'], 'value': 'is'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'depth'}; {'id': '45', 'type': 'None', 'children': []}; {'id': '46', 'type': 'block', 'children': ['47']}; {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'depth'}; {'id': '50', 'type': 'binary_operator', 'children': ['51', '57'], 'value': '-'}; {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '53', 'type': 'argument_list', 'children': ['54', '55', '56']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'ATTR_DEPTH'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_DEPTH'}; {'id': '57', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '58', 'type': 'else_clause', 'children': ['59']}; {'id': '59', 'type': 'block', 'children': ['60']}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}; {'id': '61', 'type': 'augmented_assignment', 'children': ['62', '63'], 'value': '-='}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'depth'}; {'id': '63', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '64', 'type': 'if_statement', 'children': ['65', '68']}; {'id': '65', 'type': 'comparison_operator', 'children': ['66', '67'], 'value': 'is'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'exclude'}; {'id': '67', 'type': 'None', 'children': []}; {'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': 'exclude'}; {'id': '72', 'type': 'call', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '74', 'type': 'argument_list', 'children': ['75', '76', '77']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'ATTR_EXCLUDE'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_EXCLUDE'}; {'id': '78', 'type': 'if_statement', 'children': ['79', '82']}; {'id': '79', 'type': 'comparison_operator', 'children': ['80', '81'], 'value': 'is'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'exclude_pk'}; {'id': '81', 'type': 'None', 'children': []}; {'id': '82', 'type': 'block', 'children': ['83']}; {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'exclude_pk'}; {'id': '86', 'type': 'call', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '88', 'type': 'argument_list', 'children': ['89', '90', '91']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'ATTR_EXCLUDE_PK'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_EXCLUDE_PK'}; {'id': '92', 'type': 'if_statement', 'children': ['93', '96']}; {'id': '93', 'type': 'comparison_operator', 'children': ['94', '95'], 'value': 'is'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'exclude_underscore'}; {'id': '95', 'type': 'None', 'children': []}; {'id': '96', 'type': 'block', 'children': ['97']}; {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'exclude_underscore'}; {'id': '100', 'type': 'call', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '102', 'type': 'argument_list', 'children': ['103', '104', '105']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'ATTR_EXCLUDE_UNDERSCORE'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_EXCLUDE_UNDERSCORE'}; {'id': '106', 'type': 'if_statement', 'children': ['107', '110']}; {'id': '107', 'type': 'comparison_operator', 'children': ['108', '109'], 'value': 'is'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'only'}; {'id': '109', 'type': 'None', 'children': []}; {'id': '110', 'type': 'block', 'children': ['111']}; {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'only'}; {'id': '114', 'type': 'call', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '116', 'type': 'argument_list', 'children': ['117', '118', '119']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'ATTR_ONLY'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_ONLY'}; {'id': '120', 'type': 'if_statement', 'children': ['121', '124']}; {'id': '121', 'type': 'comparison_operator', 'children': ['122', '123'], 'value': 'is'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'fk_suffix'}; {'id': '123', 'type': 'None', 'children': []}; {'id': '124', 'type': 'block', 'children': ['125']}; {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'assignment', 'children': ['127', '128']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'fk_suffix'}; {'id': '128', 'type': 'call', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '130', 'type': 'argument_list', 'children': ['131', '132', '133']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'ATTR_FK_SUFFIX'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_FK_SUFFIX'}; {'id': '134', 'type': 'for_statement', 'children': ['135', '136', '151']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '136', 'type': 'binary_operator', 'children': ['137', '144'], 'value': '+'}; {'id': '137', 'type': 'call', 'children': ['138', '143']}; {'id': '138', 'type': 'attribute', 'children': ['139', '142']}; {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'mapper'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '143', 'type': 'argument_list', 'children': []}; {'id': '144', 'type': 'call', 'children': ['145', '150']}; {'id': '145', 'type': 'attribute', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'mapper'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'synonyms'}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '150', 'type': 'argument_list', 'children': []}; {'id': '151', 'type': 'block', 'children': ['152', '182']}; {'id': '152', 'type': 'if_statement', 'children': ['153', '180']}; {'id': '153', 'type': 'boolean_operator', 'children': ['154', '174', '175'], 'value': 'or'}; {'id': '154', 'type': 'boolean_operator', 'children': ['155', '168', '169'], 'value': 'or'}; {'id': '155', 'type': 'boolean_operator', 'children': ['156', '159', '160'], 'value': 'or'}; {'id': '156', 'type': 'comparison_operator', 'children': ['157', '158'], 'value': 'in'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'exclude'}; {'id': '159', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '160', 'type': 'call', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'check_exclude_pk'}; {'id': '162', 'type': 'argument_list', 'children': ['163', '164', '165']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'exclude_pk'}; {'id': '165', 'type': 'keyword_argument', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'fk_suffix'}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'fk_suffix'}; {'id': '168', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '169', 'type': 'call', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'check_exclude_underscore'}; {'id': '171', 'type': 'argument_list', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'exclude_underscore'}; {'id': '174', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '175', 'type': 'call', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'check_only'}; {'id': '177', 'type': 'argument_list', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'only'}; {'id': '180', 'type': 'block', 'children': ['181']}; {'id': '181', 'type': 'continue_statement', 'children': []}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}; {'id': '183', 'type': 'assignment', 'children': ['184', '187']}; {'id': '184', 'type': 'subscript', 'children': ['185', '186']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '187', 'type': 'call', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '189', 'type': 'argument_list', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '192', 'type': 'for_statement', 'children': ['193', '194', '201']}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '194', 'type': 'call', 'children': ['195', '200']}; {'id': '195', 'type': 'attribute', 'children': ['196', '199']}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'mapper'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'relationships'}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '200', 'type': 'argument_list', 'children': []}; {'id': '201', 'type': 'block', 'children': ['202', '214', '222', '233', '243', '267']}; {'id': '202', 'type': 'if_statement', 'children': ['203', '212']}; {'id': '203', 'type': 'boolean_operator', 'children': ['204', '207'], 'value': 'or'}; {'id': '204', 'type': 'comparison_operator', 'children': ['205', '206'], 'value': 'in'}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'exclude'}; {'id': '207', 'type': 'call', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'check_only'}; {'id': '209', 'type': 'argument_list', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'only'}; {'id': '212', 'type': 'block', 'children': ['213']}; {'id': '213', 'type': 'continue_statement', 'children': []}; {'id': '214', 'type': 'expression_statement', 'children': ['215']}; {'id': '215', 'type': 'assignment', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '217', 'type': 'call', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '219', 'type': 'argument_list', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '222', 'type': 'expression_statement', 'children': ['223']}; {'id': '223', 'type': 'assignment', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'backref'}; {'id': '225', 'type': 'call', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'get_backref'}; {'id': '227', 'type': 'argument_list', 'children': ['228']}; {'id': '228', 'type': 'subscript', 'children': ['229', '232']}; {'id': '229', 'type': 'attribute', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'mapper'}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'relationships'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '233', 'type': 'if_statement', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'backref'}; {'id': '235', 'type': 'block', 'children': ['236']}; {'id': '236', 'type': 'expression_statement', 'children': ['237']}; {'id': '237', 'type': 'call', 'children': ['238', '241']}; {'id': '238', 'type': 'attribute', 'children': ['239', '240']}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'exclude'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '241', 'type': 'argument_list', 'children': ['242']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'backref'}; {'id': '243', 'type': 'expression_statement', 'children': ['244']}; {'id': '244', 'type': 'assignment', 'children': ['245', '246']}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '246', 'type': 'call', 'children': ['247', '248']}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '248', 'type': 'argument_list', 'children': ['249', '252', '255', '258', '261', '264']}; {'id': '249', 'type': 'keyword_argument', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'depth'}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'depth'}; {'id': '252', 'type': 'keyword_argument', 'children': ['253', '254']}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'exclude'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'exclude'}; {'id': '255', 'type': 'keyword_argument', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'exclude_pk'}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'exclude_pk'}; {'id': '258', 'type': 'keyword_argument', 'children': ['259', '260']}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'exclude_underscore'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'exclude_underscore'}; {'id': '261', 'type': 'keyword_argument', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'only'}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'only'}; {'id': '264', 'type': 'keyword_argument', 'children': ['265', '266']}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'fk_suffix'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'fk_suffix'}; {'id': '267', 'type': 'if_statement', 'children': ['268', '275', '293']}; {'id': '268', 'type': 'call', 'children': ['269', '270']}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '270', 'type': 'argument_list', 'children': ['271', '272']}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '272', 'type': 'attribute', 'children': ['273', '274']}; {'id': '273', 'type': 'identifier', 'children': [], 'value': 'collections'}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'InstrumentedList'}; {'id': '275', 'type': 'block', 'children': ['276']}; {'id': '276', 'type': 'expression_statement', 'children': ['277']}; {'id': '277', 'type': 'assignment', 'children': ['278', '281']}; {'id': '278', 'type': 'subscript', 'children': ['279', '280']}; {'id': '279', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '281', 'type': 'list_comprehension', 'children': ['282', '288', '291']}; {'id': '282', 'type': 'call', 'children': ['283', '284']}; {'id': '283', 'type': 'identifier', 'children': [], 'value': 'row2dict'}; {'id': '284', 'type': 'argument_list', 'children': ['285', '286']}; {'id': '285', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '286', 'type': 'dictionary_splat', 'children': ['287']}; {'id': '287', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '288', 'type': 'for_in_clause', 'children': ['289', '290']}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '291', 'type': 'if_clause', 'children': ['292']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'depth'}; {'id': '293', 'type': 'else_clause', 'children': ['294']}; {'id': '294', 'type': 'block', 'children': ['295']}; {'id': '295', 'type': 'expression_statement', 'children': ['296']}; {'id': '296', 'type': 'assignment', 'children': ['297', '300']}; {'id': '297', 'type': 'subscript', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '299', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '300', 'type': 'call', 'children': ['301', '302']}; {'id': '301', 'type': 'identifier', 'children': [], 'value': 'row2dict'}; {'id': '302', 'type': 'argument_list', 'children': ['303', '304']}; {'id': '303', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '304', 'type': 'dictionary_splat', 'children': ['305']}; {'id': '305', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '306', 'type': 'return_statement', 'children': ['307']}; {'id': '307', 'type': 'identifier', 'children': [], 'value': 'd'}
|
def row2dict(row, depth=None, exclude=None, exclude_pk=None,
exclude_underscore=None, only=None, fk_suffix=None):
if depth == 0:
return None
d, mapper = {}, get_mapper(row)
if depth is None:
depth = getattr(row, ATTR_DEPTH, DEFAULT_DEPTH) - 1
else:
depth -= 1
if exclude is None:
exclude = getattr(row, ATTR_EXCLUDE, DEFAULT_EXCLUDE)
if exclude_pk is None:
exclude_pk = getattr(row, ATTR_EXCLUDE_PK, DEFAULT_EXCLUDE_PK)
if exclude_underscore is None:
exclude_underscore = getattr(row, ATTR_EXCLUDE_UNDERSCORE,
DEFAULT_EXCLUDE_UNDERSCORE)
if only is None:
only = getattr(row, ATTR_ONLY, DEFAULT_ONLY)
if fk_suffix is None:
fk_suffix = getattr(row, ATTR_FK_SUFFIX, DEFAULT_FK_SUFFIX)
for c in mapper.columns.keys() + mapper.synonyms.keys():
if c in exclude or \
check_exclude_pk(c, exclude_pk, fk_suffix=fk_suffix) or \
check_exclude_underscore(c, exclude_underscore) or \
check_only(c, only):
continue
d[c] = getattr(row, c)
for r in mapper.relationships.keys():
if r in exclude or check_only(r, only):
continue
attr = getattr(row, r)
backref = get_backref(mapper.relationships[r])
if backref:
exclude.add(backref)
kwargs = dict(depth=depth, exclude=exclude, exclude_pk=exclude_pk,
exclude_underscore=exclude_underscore, only=only,
fk_suffix=fk_suffix)
if isinstance(attr, collections.InstrumentedList):
d[r] = [row2dict(i, **kwargs) for i in attr if depth]
else:
d[r] = row2dict(attr, **kwargs)
return d
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '24']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'dict2row'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'rel'}; {'id': '8', 'type': 'None', 'children': []}; {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'exclude'}; {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'exclude_pk'}; {'id': '14', 'type': 'None', 'children': []}; {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'exclude_underscore'}; {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'only'}; {'id': '20', 'type': 'None', 'children': []}; {'id': '21', 'type': 'default_parameter', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'fk_suffix'}; {'id': '23', 'type': 'None', 'children': []}; {'id': '24', 'type': 'block', 'children': ['25', '45', '51', '58', '72', '86', '100', '114', '128', '142', '203', '350']}; {'id': '25', 'type': 'if_statement', 'children': ['26', '32']}; {'id': '26', 'type': 'not_operator', 'children': ['27']}; {'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': 'd'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '32', 'type': 'block', 'children': ['33']}; {'id': '33', 'type': 'raise_statement', 'children': ['34']}; {'id': '34', 'type': 'call', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}; {'id': '37', 'type': 'binary_operator', 'children': ['38', '39'], 'value': '%'}; {'id': '38', 'type': 'string', 'children': [], 'value': "'Source must be instance of dict, got %s instead'"}; {'id': '39', 'type': 'attribute', 'children': ['40', '44']}; {'id': '40', 'type': 'call', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '48', 'type': 'call', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'model'}; {'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': 'mapper'}; {'id': '54', 'type': 'call', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'get_mapper'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '58', 'type': 'if_statement', 'children': ['59', '62']}; {'id': '59', 'type': 'comparison_operator', 'children': ['60', '61'], 'value': 'is'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'rel'}; {'id': '61', 'type': 'None', 'children': []}; {'id': '62', 'type': 'block', 'children': ['63']}; {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'rel'}; {'id': '66', 'type': 'call', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '68', 'type': 'argument_list', 'children': ['69', '70', '71']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'ATTR_REL'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_REL'}; {'id': '72', 'type': 'if_statement', 'children': ['73', '76']}; {'id': '73', 'type': 'comparison_operator', 'children': ['74', '75'], 'value': 'is'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'exclude'}; {'id': '75', 'type': 'None', 'children': []}; {'id': '76', 'type': 'block', 'children': ['77']}; {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'exclude'}; {'id': '80', 'type': 'call', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '82', 'type': 'argument_list', 'children': ['83', '84', '85']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'ATTR_EXCLUDE'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_EXCLUDE'}; {'id': '86', 'type': 'if_statement', 'children': ['87', '90']}; {'id': '87', 'type': 'comparison_operator', 'children': ['88', '89'], 'value': 'is'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'exclude_pk'}; {'id': '89', 'type': 'None', 'children': []}; {'id': '90', 'type': 'block', 'children': ['91']}; {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'exclude_pk'}; {'id': '94', 'type': 'call', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '96', 'type': 'argument_list', 'children': ['97', '98', '99']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'ATTR_EXCLUDE_PK'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_EXCLUDE_PK'}; {'id': '100', 'type': 'if_statement', 'children': ['101', '104']}; {'id': '101', 'type': 'comparison_operator', 'children': ['102', '103'], 'value': 'is'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'exclude_underscore'}; {'id': '103', 'type': 'None', 'children': []}; {'id': '104', 'type': 'block', 'children': ['105']}; {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'exclude_underscore'}; {'id': '108', 'type': 'call', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '110', 'type': 'argument_list', 'children': ['111', '112', '113']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'ATTR_EXCLUDE_UNDERSCORE'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_EXCLUDE_UNDERSCORE'}; {'id': '114', 'type': 'if_statement', 'children': ['115', '118']}; {'id': '115', 'type': 'comparison_operator', 'children': ['116', '117'], 'value': 'is'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'only'}; {'id': '117', 'type': 'None', 'children': []}; {'id': '118', 'type': 'block', 'children': ['119']}; {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'only'}; {'id': '122', 'type': 'call', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '124', 'type': 'argument_list', 'children': ['125', '126', '127']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'ATTR_ONLY'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_ONLY'}; {'id': '128', 'type': 'if_statement', 'children': ['129', '132']}; {'id': '129', 'type': 'comparison_operator', 'children': ['130', '131'], 'value': 'is'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'fk_suffix'}; {'id': '131', 'type': 'None', 'children': []}; {'id': '132', 'type': 'block', 'children': ['133']}; {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'assignment', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'fk_suffix'}; {'id': '136', 'type': 'call', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '138', 'type': 'argument_list', 'children': ['139', '140', '141']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'ATTR_FK_SUFFIX'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_FK_SUFFIX'}; {'id': '142', 'type': 'for_statement', 'children': ['143', '144', '159']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '144', 'type': 'binary_operator', 'children': ['145', '152'], 'value': '+'}; {'id': '145', 'type': 'call', 'children': ['146', '151']}; {'id': '146', 'type': 'attribute', 'children': ['147', '150']}; {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'mapper'}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '151', 'type': 'argument_list', 'children': []}; {'id': '152', 'type': 'call', 'children': ['153', '158']}; {'id': '153', 'type': 'attribute', 'children': ['154', '157']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'mapper'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'synonyms'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '158', 'type': 'argument_list', 'children': []}; {'id': '159', 'type': 'block', 'children': ['160', '194']}; {'id': '160', 'type': 'if_statement', 'children': ['161', '192']}; {'id': '161', 'type': 'boolean_operator', 'children': ['162', '186', '187'], 'value': 'or'}; {'id': '162', 'type': 'boolean_operator', 'children': ['163', '180', '181'], 'value': 'or'}; {'id': '163', 'type': 'boolean_operator', 'children': ['164', '171', '172'], 'value': 'or'}; {'id': '164', 'type': 'boolean_operator', 'children': ['165', '168'], 'value': 'or'}; {'id': '165', 'type': 'comparison_operator', 'children': ['166', '167'], 'value': 'not'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '168', 'type': 'comparison_operator', 'children': ['169', '170'], 'value': 'in'}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'exclude'}; {'id': '171', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '172', 'type': 'call', 'children': ['173', '174']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'check_exclude_pk'}; {'id': '174', 'type': 'argument_list', 'children': ['175', '176', '177']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'exclude_pk'}; {'id': '177', 'type': 'keyword_argument', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'fk_suffix'}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'fk_suffix'}; {'id': '180', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '181', 'type': 'call', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'check_exclude_underscore'}; {'id': '183', 'type': 'argument_list', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'exclude_underscore'}; {'id': '186', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '187', 'type': 'call', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'check_only'}; {'id': '189', 'type': 'argument_list', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'only'}; {'id': '192', 'type': 'block', 'children': ['193']}; {'id': '193', 'type': 'continue_statement', 'children': []}; {'id': '194', 'type': 'expression_statement', 'children': ['195']}; {'id': '195', 'type': 'call', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'setattr'}; {'id': '197', 'type': 'argument_list', 'children': ['198', '199', '200']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '200', 'type': 'subscript', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '203', 'type': 'for_statement', 'children': ['204', '205', '212']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '205', 'type': 'call', 'children': ['206', '211']}; {'id': '206', 'type': 'attribute', 'children': ['207', '210']}; {'id': '207', 'type': 'attribute', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'mapper'}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'relationships'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '211', 'type': 'argument_list', 'children': []}; {'id': '212', 'type': 'block', 'children': ['213', '229', '253']}; {'id': '213', 'type': 'if_statement', 'children': ['214', '227']}; {'id': '214', 'type': 'boolean_operator', 'children': ['215', '222'], 'value': 'or'}; {'id': '215', 'type': 'boolean_operator', 'children': ['216', '219'], 'value': 'or'}; {'id': '216', 'type': 'comparison_operator', 'children': ['217', '218'], 'value': 'not'}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '219', 'type': 'comparison_operator', 'children': ['220', '221'], 'value': 'not'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'rel'}; {'id': '222', 'type': 'call', 'children': ['223', '224']}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'check_only'}; {'id': '224', 'type': 'argument_list', 'children': ['225', '226']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'only'}; {'id': '227', 'type': 'block', 'children': ['228']}; {'id': '228', 'type': 'continue_statement', 'children': []}; {'id': '229', 'type': 'expression_statement', 'children': ['230']}; {'id': '230', 'type': 'assignment', 'children': ['231', '232']}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '232', 'type': 'call', 'children': ['233', '234']}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '234', 'type': 'argument_list', 'children': ['235', '238', '241', '244', '247', '250']}; {'id': '235', 'type': 'keyword_argument', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'rel'}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'rel'}; {'id': '238', 'type': 'keyword_argument', 'children': ['239', '240']}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'exclude'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'exclude'}; {'id': '241', 'type': 'keyword_argument', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'exclude_pk'}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'exclude_pk'}; {'id': '244', 'type': 'keyword_argument', 'children': ['245', '246']}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'exclude_underscore'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'exclude_underscore'}; {'id': '247', 'type': 'keyword_argument', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'only'}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'only'}; {'id': '250', 'type': 'keyword_argument', 'children': ['251', '252']}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'fk_suffix'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'fk_suffix'}; {'id': '253', 'type': 'if_statement', 'children': ['254', '261', '298']}; {'id': '254', 'type': 'call', 'children': ['255', '256']}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '256', 'type': 'argument_list', 'children': ['257', '260']}; {'id': '257', 'type': 'subscript', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '261', 'type': 'block', 'children': ['262', '273']}; {'id': '262', 'type': 'expression_statement', 'children': ['263']}; {'id': '263', 'type': 'call', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'setattr'}; {'id': '265', 'type': 'argument_list', 'children': ['266', '267', '268']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '268', 'type': 'call', 'children': ['269', '272']}; {'id': '269', 'type': 'attribute', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'collections'}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'InstrumentedList'}; {'id': '272', 'type': 'argument_list', 'children': []}; {'id': '273', 'type': 'for_statement', 'children': ['274', '275', '278']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '275', 'type': 'subscript', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '278', 'type': 'block', 'children': ['279']}; {'id': '279', 'type': 'expression_statement', 'children': ['280']}; {'id': '280', 'type': 'call', 'children': ['281', '288']}; {'id': '281', 'type': 'attribute', 'children': ['282', '287']}; {'id': '282', 'type': 'call', 'children': ['283', '284']}; {'id': '283', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '284', 'type': 'argument_list', 'children': ['285', '286']}; {'id': '285', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '287', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '288', 'type': 'argument_list', 'children': ['289']}; {'id': '289', 'type': 'call', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'dict2row'}; {'id': '291', 'type': 'argument_list', 'children': ['292', '293', '296']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '293', 'type': 'subscript', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'rel'}; {'id': '295', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '296', 'type': 'dictionary_splat', 'children': ['297']}; {'id': '297', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '298', 'type': 'else_clause', 'children': ['299']}; {'id': '299', 'type': 'block', 'children': ['300', '333']}; {'id': '300', 'type': 'if_statement', 'children': ['301', '303']}; {'id': '301', 'type': 'not_operator', 'children': ['302']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'exclude_pk'}; {'id': '303', 'type': 'block', 'children': ['304', '324']}; {'id': '304', 'type': 'expression_statement', 'children': ['305']}; {'id': '305', 'type': 'assignment', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'rpk'}; {'id': '307', 'type': 'conditional_expression', 'children': ['308', '316', '323'], 'value': 'if'}; {'id': '308', 'type': 'call', 'children': ['309', '314']}; {'id': '309', 'type': 'attribute', 'children': ['310', '313']}; {'id': '310', 'type': 'subscript', 'children': ['311', '312']}; {'id': '311', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '313', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '314', 'type': 'argument_list', 'children': ['315']}; {'id': '315', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '316', 'type': 'call', 'children': ['317', '318']}; {'id': '317', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '318', 'type': 'argument_list', 'children': ['319', '322']}; {'id': '319', 'type': 'subscript', 'children': ['320', '321']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '321', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '323', 'type': 'None', 'children': []}; {'id': '324', 'type': 'expression_statement', 'children': ['325']}; {'id': '325', 'type': 'call', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'setattr'}; {'id': '327', 'type': 'argument_list', 'children': ['328', '329', '332']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '329', 'type': 'binary_operator', 'children': ['330', '331'], 'value': '+'}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '331', 'type': 'identifier', 'children': [], 'value': 'fk_suffix'}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'rpk'}; {'id': '333', 'type': 'expression_statement', 'children': ['334']}; {'id': '334', 'type': 'call', 'children': ['335', '336']}; {'id': '335', 'type': 'identifier', 'children': [], 'value': 'setattr'}; {'id': '336', 'type': 'argument_list', 'children': ['337', '338', '339']}; {'id': '337', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '339', 'type': 'call', 'children': ['340', '341']}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'dict2row'}; {'id': '341', 'type': 'argument_list', 'children': ['342', '345', '348']}; {'id': '342', 'type': 'subscript', 'children': ['343', '344']}; {'id': '343', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '345', 'type': 'subscript', 'children': ['346', '347']}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'rel'}; {'id': '347', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '348', 'type': 'dictionary_splat', 'children': ['349']}; {'id': '349', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '350', 'type': 'return_statement', 'children': ['351']}; {'id': '351', 'type': 'identifier', 'children': [], 'value': 'row'}
|
def dict2row(d, model, rel=None, exclude=None, exclude_pk=None,
exclude_underscore=None, only=None, fk_suffix=None):
if not isinstance(d, dict):
raise TypeError('Source must be instance of dict, got %s instead' %
type(d).__name__)
row = model()
mapper = get_mapper(row)
if rel is None:
rel = getattr(row, ATTR_REL, DEFAULT_REL)
if exclude is None:
exclude = getattr(row, ATTR_EXCLUDE, DEFAULT_EXCLUDE)
if exclude_pk is None:
exclude_pk = getattr(row, ATTR_EXCLUDE_PK, DEFAULT_EXCLUDE_PK)
if exclude_underscore is None:
exclude_underscore = getattr(row, ATTR_EXCLUDE_UNDERSCORE,
DEFAULT_EXCLUDE_UNDERSCORE)
if only is None:
only = getattr(row, ATTR_ONLY, DEFAULT_ONLY)
if fk_suffix is None:
fk_suffix = getattr(row, ATTR_FK_SUFFIX, DEFAULT_FK_SUFFIX)
for c in mapper.columns.keys() + mapper.synonyms.keys():
if c not in d or c in exclude or \
check_exclude_pk(c, exclude_pk, fk_suffix=fk_suffix) or \
check_exclude_underscore(c, exclude_underscore) or \
check_only(c, only):
continue
setattr(row, c, d[c])
for r in mapper.relationships.keys():
if r not in d or r not in rel or check_only(r, only):
continue
kwargs = dict(rel=rel, exclude=exclude, exclude_pk=exclude_pk,
exclude_underscore=exclude_underscore, only=only,
fk_suffix=fk_suffix)
if isinstance(d[r], list):
setattr(row, r, collections.InstrumentedList())
for i in d[r]:
getattr(row, r).append(dict2row(i, rel[r], **kwargs))
else:
if not exclude_pk:
rpk = d[r].get('id') if isinstance(d[r], dict) else None
setattr(row, r + fk_suffix, rpk)
setattr(row, r, dict2row(d[r], rel[r], **kwargs))
return row
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '74', '76']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'remote'}; {'id': '3', 'type': 'parameters', 'children': ['4', '13', '14', '17', '20', '23', '26', '29', '32', '42', '45', '55', '65', '68', '71']}; {'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '6', 'type': 'type', 'children': ['7']}; {'id': '7', 'type': 'call', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'arg'}; {'id': '9', 'type': 'argument_list', 'children': ['10']}; {'id': '10', 'type': 'keyword_argument', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'container'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'host'}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '16', 'type': 'None', 'children': []}; {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'port'}; {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'sudo'}; {'id': '22', 'type': 'False', 'children': []}; {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'run_as'}; {'id': '25', 'type': 'None', 'children': []}; {'id': '26', 'type': 'default_parameter', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'shell'}; {'id': '28', 'type': 'string', 'children': [], 'value': "'/bin/sh'"}; {'id': '29', 'type': 'default_parameter', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'cd'}; {'id': '31', 'type': 'None', 'children': []}; {'id': '32', 'type': 'typed_default_parameter', 'children': ['33', '34', '41']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'environ'}; {'id': '34', 'type': 'type', 'children': ['35']}; {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'arg'}; {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'container'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '41', 'type': 'None', 'children': []}; {'id': '42', 'type': 'default_parameter', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'paths'}; {'id': '44', 'type': 'tuple', 'children': []}; {'id': '45', 'type': 'typed_default_parameter', 'children': ['46', '47', '54']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'stdout'}; {'id': '47', 'type': 'type', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'arg'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}; {'id': '51', 'type': 'keyword_argument', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'StreamOptions'}; {'id': '54', 'type': 'None', 'children': []}; {'id': '55', 'type': 'typed_default_parameter', 'children': ['56', '57', '64']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'stderr'}; {'id': '57', 'type': 'type', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'arg'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}; {'id': '61', 'type': 'keyword_argument', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'StreamOptions'}; {'id': '64', 'type': 'None', 'children': []}; {'id': '65', 'type': 'default_parameter', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'echo'}; {'id': '67', 'type': 'False', 'children': []}; {'id': '68', 'type': 'default_parameter', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'raise_on_error'}; {'id': '70', 'type': 'True', 'children': []}; {'id': '71', 'type': 'default_parameter', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'dry_run'}; {'id': '73', 'type': 'False', 'children': []}; {'id': '74', 'type': 'type', 'children': ['75']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'Result'}; {'id': '76', 'type': 'block', 'children': ['77', '95', '100', '115', '129', '143', '147', '173', '182', '186', '203', '229', '251', '258', '267', '278', '287', '294', '303', '311']}; {'id': '77', 'type': 'if_statement', 'children': ['78', '84']}; {'id': '78', 'type': 'not_operator', 'children': ['79']}; {'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': 'cmd'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '84', 'type': 'block', 'children': ['85']}; {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '88', 'type': 'call', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'flatten_args'}; {'id': '90', 'type': 'argument_list', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '92', 'type': 'keyword_argument', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '94', 'type': 'True', 'children': []}; {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'ssh_options'}; {'id': '98', 'type': 'list', 'children': ['99'], 'value': "['-q']"}; {'id': '99', 'type': 'string', 'children': [], 'value': "'-q'"}; {'id': '100', 'type': 'if_statement', 'children': ['101', '107']}; {'id': '101', 'type': 'call', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'isatty'}; {'id': '103', 'type': 'argument_list', 'children': ['104']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'stdin'}; {'id': '107', 'type': 'block', 'children': ['108']}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}; {'id': '109', 'type': 'call', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'ssh_options'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'string', 'children': [], 'value': "'-t'"}; {'id': '115', 'type': 'if_statement', 'children': ['116', '119']}; {'id': '116', 'type': 'comparison_operator', 'children': ['117', '118'], 'value': 'is'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'port'}; {'id': '118', 'type': 'None', 'children': []}; {'id': '119', 'type': 'block', 'children': ['120']}; {'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': 'ssh_options'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '125', 'type': 'argument_list', 'children': ['126']}; {'id': '126', 'type': 'tuple', 'children': ['127', '128']}; {'id': '127', 'type': 'string', 'children': [], 'value': "'-p'"}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'port'}; {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'assignment', 'children': ['131', '132']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'ssh_connection_str'}; {'id': '132', 'type': 'conditional_expression', 'children': ['133', '141', '142'], 'value': 'if'}; {'id': '133', 'type': 'call', 'children': ['134', '137']}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}; {'id': '135', 'type': 'string', 'children': [], 'value': "'{user}@{host}'"}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'format_map'}; {'id': '137', 'type': 'argument_list', 'children': ['138']}; {'id': '138', 'type': 'call', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'locals'}; {'id': '140', 'type': 'argument_list', 'children': []}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'host'}; {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'assignment', 'children': ['145', '146']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'remote_cmd'}; {'id': '146', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '147', 'type': 'if_statement', 'children': ['148', '149', '159']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'sudo'}; {'id': '149', 'type': 'block', 'children': ['150']}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}; {'id': '151', 'type': 'call', 'children': ['152', '155']}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'remote_cmd'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'tuple', 'children': ['157', '158']}; {'id': '157', 'type': 'string', 'children': [], 'value': "'sudo'"}; {'id': '158', 'type': 'string', 'children': [], 'value': "'-H'"}; {'id': '159', 'type': 'elif_clause', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'run_as'}; {'id': '161', 'type': 'block', 'children': ['162']}; {'id': '162', 'type': 'expression_statement', 'children': ['163']}; {'id': '163', 'type': 'call', 'children': ['164', '167']}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'remote_cmd'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '167', 'type': 'argument_list', 'children': ['168']}; {'id': '168', 'type': 'tuple', 'children': ['169', '170', '171', '172']}; {'id': '169', 'type': 'string', 'children': [], 'value': "'sudo'"}; {'id': '170', 'type': 'string', 'children': [], 'value': "'-H'"}; {'id': '171', 'type': 'string', 'children': [], 'value': "'-u'"}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'run_as'}; {'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': 'remote_cmd'}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '178', 'type': 'argument_list', 'children': ['179']}; {'id': '179', 'type': 'tuple', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'shell'}; {'id': '181', 'type': 'string', 'children': [], 'value': "'-c'"}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}; {'id': '183', 'type': 'assignment', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'inner_cmd'}; {'id': '185', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '186', 'type': 'if_statement', 'children': ['187', '188']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'cd'}; {'id': '188', 'type': 'block', 'children': ['189']}; {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'call', 'children': ['191', '194']}; {'id': '191', 'type': 'attribute', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'inner_cmd'}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '194', 'type': 'argument_list', 'children': ['195']}; {'id': '195', 'type': 'call', 'children': ['196', '199']}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}; {'id': '197', 'type': 'string', 'children': [], 'value': "'cd {cd}'"}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'format_map'}; {'id': '199', 'type': 'argument_list', 'children': ['200']}; {'id': '200', 'type': 'call', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'locals'}; {'id': '202', 'type': 'argument_list', 'children': []}; {'id': '203', 'type': 'if_statement', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'environ'}; {'id': '205', 'type': 'block', 'children': ['206']}; {'id': '206', 'type': 'expression_statement', 'children': ['207']}; {'id': '207', 'type': 'call', 'children': ['208', '211']}; {'id': '208', 'type': 'attribute', 'children': ['209', '210']}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'inner_cmd'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '211', 'type': 'generator_expression', 'children': ['212', '220']}; {'id': '212', 'type': 'call', 'children': ['213', '216']}; {'id': '213', 'type': 'attribute', 'children': ['214', '215']}; {'id': '214', 'type': 'string', 'children': [], 'value': '\'export {k}="{v}"\''}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'format_map'}; {'id': '216', 'type': 'argument_list', 'children': ['217']}; {'id': '217', 'type': 'call', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'locals'}; {'id': '219', 'type': 'argument_list', 'children': []}; {'id': '220', 'type': 'for_in_clause', 'children': ['221', '224']}; {'id': '221', 'type': 'pattern_list', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '224', 'type': 'call', 'children': ['225', '228']}; {'id': '225', 'type': 'attribute', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'environ'}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '228', 'type': 'argument_list', 'children': []}; {'id': '229', 'type': 'if_statement', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'paths'}; {'id': '231', 'type': 'block', 'children': ['232']}; {'id': '232', 'type': 'expression_statement', 'children': ['233']}; {'id': '233', 'type': 'call', 'children': ['234', '237']}; {'id': '234', 'type': 'attribute', 'children': ['235', '236']}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'inner_cmd'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '237', 'type': 'argument_list', 'children': ['238']}; {'id': '238', 'type': 'call', 'children': ['239', '242']}; {'id': '239', 'type': 'attribute', 'children': ['240', '241']}; {'id': '240', 'type': 'string', 'children': [], 'value': '\'export PATH="{path}:$PATH"\''}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '242', 'type': 'argument_list', 'children': ['243']}; {'id': '243', 'type': 'keyword_argument', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '245', 'type': 'call', 'children': ['246', '249']}; {'id': '246', 'type': 'attribute', 'children': ['247', '248']}; {'id': '247', 'type': 'string', 'children': [], 'value': "':'"}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '249', 'type': 'argument_list', 'children': ['250']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'paths'}; {'id': '251', 'type': 'expression_statement', 'children': ['252']}; {'id': '252', 'type': 'call', 'children': ['253', '256']}; {'id': '253', 'type': 'attribute', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'inner_cmd'}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '256', 'type': 'argument_list', 'children': ['257']}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '258', 'type': 'expression_statement', 'children': ['259']}; {'id': '259', 'type': 'assignment', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'inner_cmd'}; {'id': '261', 'type': 'call', 'children': ['262', '265']}; {'id': '262', 'type': 'attribute', 'children': ['263', '264']}; {'id': '263', 'type': 'string', 'children': [], 'value': "' &&\\n '"}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '265', 'type': 'argument_list', 'children': ['266']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'inner_cmd'}; {'id': '267', 'type': 'expression_statement', 'children': ['268']}; {'id': '268', 'type': 'assignment', 'children': ['269', '270']}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'inner_cmd'}; {'id': '270', 'type': 'call', 'children': ['271', '274']}; {'id': '271', 'type': 'attribute', 'children': ['272', '273']}; {'id': '272', 'type': 'string', 'children': [], 'value': "'\\n {inner_cmd}\\n'"}; {'id': '273', 'type': 'identifier', 'children': [], 'value': 'format_map'}; {'id': '274', 'type': 'argument_list', 'children': ['275']}; {'id': '275', 'type': 'call', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'locals'}; {'id': '277', 'type': 'argument_list', 'children': []}; {'id': '278', 'type': 'expression_statement', 'children': ['279']}; {'id': '279', 'type': 'assignment', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'inner_cmd'}; {'id': '281', 'type': 'call', 'children': ['282', '285']}; {'id': '282', 'type': 'attribute', 'children': ['283', '284']}; {'id': '283', 'type': 'identifier', 'children': [], 'value': 'shlex'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'quote'}; {'id': '285', 'type': 'argument_list', 'children': ['286']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'inner_cmd'}; {'id': '287', 'type': 'expression_statement', 'children': ['288']}; {'id': '288', 'type': 'call', 'children': ['289', '292']}; {'id': '289', 'type': 'attribute', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'remote_cmd'}; {'id': '291', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '292', 'type': 'argument_list', 'children': ['293']}; {'id': '293', 'type': 'identifier', 'children': [], 'value': 'inner_cmd'}; {'id': '294', 'type': 'expression_statement', 'children': ['295']}; {'id': '295', 'type': 'assignment', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'remote_cmd'}; {'id': '297', 'type': 'call', 'children': ['298', '301']}; {'id': '298', 'type': 'attribute', 'children': ['299', '300']}; {'id': '299', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '301', 'type': 'argument_list', 'children': ['302']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'remote_cmd'}; {'id': '303', 'type': 'expression_statement', 'children': ['304']}; {'id': '304', 'type': 'assignment', 'children': ['305', '306']}; {'id': '305', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '306', 'type': 'tuple', 'children': ['307', '308', '309', '310']}; {'id': '307', 'type': 'string', 'children': [], 'value': "'ssh'"}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'ssh_options'}; {'id': '309', 'type': 'identifier', 'children': [], 'value': 'ssh_connection_str'}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'remote_cmd'}; {'id': '311', 'type': 'return_statement', 'children': ['312']}; {'id': '312', 'type': 'call', 'children': ['313', '314']}; {'id': '313', 'type': 'identifier', 'children': [], 'value': 'local'}; {'id': '314', 'type': 'argument_list', 'children': ['315', '316', '319', '322', '325', '328']}; {'id': '315', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '316', 'type': 'keyword_argument', 'children': ['317', '318']}; {'id': '317', 'type': 'identifier', 'children': [], 'value': 'stdout'}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'stdout'}; {'id': '319', 'type': 'keyword_argument', 'children': ['320', '321']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'stderr'}; {'id': '321', 'type': 'identifier', 'children': [], 'value': 'stderr'}; {'id': '322', 'type': 'keyword_argument', 'children': ['323', '324']}; {'id': '323', 'type': 'identifier', 'children': [], 'value': 'echo'}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'echo'}; {'id': '325', 'type': 'keyword_argument', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'raise_on_error'}; {'id': '327', 'type': 'identifier', 'children': [], 'value': 'raise_on_error'}; {'id': '328', 'type': 'keyword_argument', 'children': ['329', '330']}; {'id': '329', 'type': 'identifier', 'children': [], 'value': 'dry_run'}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'dry_run'}
|
def remote(cmd: arg(container=list),
host,
user=None,
port=None,
sudo=False,
run_as=None,
shell='/bin/sh',
cd=None,
environ: arg(container=dict) = None,
paths=(),
stdout: arg(type=StreamOptions) = None,
stderr: arg(type=StreamOptions) = None,
echo=False,
raise_on_error=True,
dry_run=False,
) -> Result:
if not isinstance(cmd, str):
cmd = flatten_args(cmd, join=True)
ssh_options = ['-q']
if isatty(sys.stdin):
ssh_options.append('-t')
if port is not None:
ssh_options.extend(('-p', port))
ssh_connection_str = '{user}@{host}'.format_map(locals()) if user else host
remote_cmd = []
if sudo:
remote_cmd.extend(('sudo', '-H'))
elif run_as:
remote_cmd.extend(('sudo', '-H', '-u', run_as))
remote_cmd.extend((shell, '-c'))
inner_cmd = []
if cd:
inner_cmd.append('cd {cd}'.format_map(locals()))
if environ:
inner_cmd.extend('export {k}="{v}"'.format_map(locals()) for k, v in environ.items())
if paths:
inner_cmd.append('export PATH="{path}:$PATH"'.format(path=':'.join(paths)))
inner_cmd.append(cmd)
inner_cmd = ' &&\n '.join(inner_cmd)
inner_cmd = '\n {inner_cmd}\n'.format_map(locals())
inner_cmd = shlex.quote(inner_cmd)
remote_cmd.append(inner_cmd)
remote_cmd = ' '.join(remote_cmd)
args = ('ssh', ssh_options, ssh_connection_str, remote_cmd)
return local(
args, stdout=stdout, stderr=stderr, echo=echo, raise_on_error=raise_on_error,
dry_run=dry_run)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '69', '71']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sync'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16', '22', '25', '28', '31', '34', '37', '40', '43', '53', '63', '66']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'destination'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'host'}; {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'sudo'}; {'id': '12', 'type': 'False', 'children': []}; {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'run_as'}; {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'default_parameter', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'options'}; {'id': '18', 'type': 'tuple', 'children': ['19', '20', '21']}; {'id': '19', 'type': 'string', 'children': [], 'value': "'-rltvz'"}; {'id': '20', 'type': 'string', 'children': [], 'value': "'--no-perms'"}; {'id': '21', 'type': 'string', 'children': [], 'value': "'--no-group'"}; {'id': '22', 'type': 'default_parameter', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'excludes'}; {'id': '24', 'type': 'tuple', 'children': []}; {'id': '25', 'type': 'default_parameter', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'exclude_from'}; {'id': '27', 'type': 'None', 'children': []}; {'id': '28', 'type': 'default_parameter', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'delete'}; {'id': '30', 'type': 'False', 'children': []}; {'id': '31', 'type': 'default_parameter', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'dry_run'}; {'id': '33', 'type': 'False', 'children': []}; {'id': '34', 'type': 'default_parameter', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '36', 'type': 'string', 'children': [], 'value': "'u=rwX,g=rwX,o='"}; {'id': '37', 'type': 'default_parameter', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'quiet'}; {'id': '39', 'type': 'True', 'children': []}; {'id': '40', 'type': 'default_parameter', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'pull'}; {'id': '42', 'type': 'False', 'children': []}; {'id': '43', 'type': 'typed_default_parameter', 'children': ['44', '45', '52']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'stdout'}; {'id': '45', 'type': 'type', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'arg'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}; {'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'StreamOptions'}; {'id': '52', 'type': 'None', 'children': []}; {'id': '53', 'type': 'typed_default_parameter', 'children': ['54', '55', '62']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'stderr'}; {'id': '55', 'type': 'type', 'children': ['56']}; {'id': '56', 'type': 'call', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'arg'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}; {'id': '59', 'type': 'keyword_argument', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'StreamOptions'}; {'id': '62', 'type': 'None', 'children': []}; {'id': '63', 'type': 'default_parameter', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'echo'}; {'id': '65', 'type': 'False', 'children': []}; {'id': '66', 'type': 'default_parameter', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'raise_on_error'}; {'id': '68', 'type': 'True', 'children': []}; {'id': '69', 'type': 'type', 'children': ['70']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'Result'}; {'id': '71', 'type': 'block', 'children': ['72', '82', '92', '106', '111', '142', '169', '211']}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}; {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'abs_path'}; {'id': '77', 'type': 'argument_list', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '79', 'type': 'keyword_argument', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'keep_slash'}; {'id': '81', 'type': 'True', 'children': []}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}; {'id': '83', 'type': 'assignment', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'destination'}; {'id': '85', 'type': 'call', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'abs_path'}; {'id': '87', 'type': 'argument_list', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'destination'}; {'id': '89', 'type': 'keyword_argument', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'keep_slash'}; {'id': '91', 'type': 'True', 'children': []}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}; {'id': '93', 'type': 'assignment', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'connection_str'}; {'id': '95', 'type': 'conditional_expression', 'children': ['96', '104', '105'], 'value': 'if'}; {'id': '96', 'type': 'call', 'children': ['97', '100']}; {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'string', 'children': [], 'value': "'{user}@{host}'"}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'format_map'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}; {'id': '101', 'type': 'call', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'locals'}; {'id': '103', 'type': 'argument_list', 'children': []}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'host'}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}; {'id': '107', 'type': 'assignment', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'push'}; {'id': '109', 'type': 'not_operator', 'children': ['110']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'pull'}; {'id': '111', 'type': 'if_statement', 'children': ['112', '113', '120', '136']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'sudo'}; {'id': '113', 'type': 'block', 'children': ['114']}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}; {'id': '115', 'type': 'assignment', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'rsync_path'}; {'id': '117', 'type': 'tuple', 'children': ['118', '119']}; {'id': '118', 'type': 'string', 'children': [], 'value': "'--rsync-path'"}; {'id': '119', 'type': 'string', 'children': [], 'value': "'sudo rsync'"}; {'id': '120', 'type': 'elif_clause', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'run_as'}; {'id': '122', 'type': 'block', 'children': ['123']}; {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'rsync_path'}; {'id': '126', 'type': 'tuple', 'children': ['127', '128']}; {'id': '127', 'type': 'string', 'children': [], 'value': "'--rsync-path'"}; {'id': '128', 'type': 'call', 'children': ['129', '132']}; {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'string', 'children': [], 'value': "'sudo -u {run_as} rsync'"}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'format_map'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}; {'id': '133', 'type': 'call', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'locals'}; {'id': '135', 'type': 'argument_list', 'children': []}; {'id': '136', 'type': 'else_clause', 'children': ['137']}; {'id': '137', 'type': 'block', 'children': ['138']}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}; {'id': '139', 'type': 'assignment', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'rsync_path'}; {'id': '141', 'type': 'None', 'children': []}; {'id': '142', 'type': 'if_statement', 'children': ['143', '144', '156']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'push'}; {'id': '144', 'type': 'block', 'children': ['145']}; {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'assignment', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'destination'}; {'id': '148', 'type': 'call', 'children': ['149', '152']}; {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'string', 'children': [], 'value': "'{connection_str}:{destination}'"}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'format_map'}; {'id': '152', 'type': 'argument_list', 'children': ['153']}; {'id': '153', 'type': 'call', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'locals'}; {'id': '155', 'type': 'argument_list', 'children': []}; {'id': '156', 'type': 'else_clause', 'children': ['157']}; {'id': '157', 'type': 'block', 'children': ['158']}; {'id': '158', 'type': 'expression_statement', 'children': ['159']}; {'id': '159', 'type': 'assignment', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '161', 'type': 'call', 'children': ['162', '165']}; {'id': '162', 'type': 'attribute', 'children': ['163', '164']}; {'id': '163', 'type': 'string', 'children': [], 'value': "'{connection_str}:{source}'"}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'format_map'}; {'id': '165', 'type': 'argument_list', 'children': ['166']}; {'id': '166', 'type': 'call', 'children': ['167', '168']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'locals'}; {'id': '168', 'type': 'argument_list', 'children': []}; {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'assignment', 'children': ['171', '172']}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '172', 'type': 'tuple', 'children': ['173', '174', '175', '176', '182', '191', '197', '201', '205', '209', '210']}; {'id': '173', 'type': 'string', 'children': [], 'value': "'rsync'"}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'rsync_path'}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'options'}; {'id': '176', 'type': 'conditional_expression', 'children': ['177', '180', '181'], 'value': 'if'}; {'id': '177', 'type': 'tuple', 'children': ['178', '179']}; {'id': '178', 'type': 'string', 'children': [], 'value': "'--chmod'"}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '181', 'type': 'None', 'children': []}; {'id': '182', 'type': 'call', 'children': ['183', '184']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '184', 'type': 'generator_expression', 'children': ['185', '188']}; {'id': '185', 'type': 'tuple', 'children': ['186', '187']}; {'id': '186', 'type': 'string', 'children': [], 'value': "'--exclude'"}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'exclude'}; {'id': '188', 'type': 'for_in_clause', 'children': ['189', '190']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'exclude'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'excludes'}; {'id': '191', 'type': 'conditional_expression', 'children': ['192', '195', '196'], 'value': 'if'}; {'id': '192', 'type': 'tuple', 'children': ['193', '194']}; {'id': '193', 'type': 'string', 'children': [], 'value': "'--exclude-from'"}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'exclude_from'}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'exclude_from'}; {'id': '196', 'type': 'None', 'children': []}; {'id': '197', 'type': 'conditional_expression', 'children': ['198', '199', '200'], 'value': 'if'}; {'id': '198', 'type': 'string', 'children': [], 'value': "'--delete'"}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'delete'}; {'id': '200', 'type': 'None', 'children': []}; {'id': '201', 'type': 'conditional_expression', 'children': ['202', '203', '204'], 'value': 'if'}; {'id': '202', 'type': 'string', 'children': [], 'value': "'--dry-run'"}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'dry_run'}; {'id': '204', 'type': 'None', 'children': []}; {'id': '205', 'type': 'conditional_expression', 'children': ['206', '207', '208'], 'value': 'if'}; {'id': '206', 'type': 'string', 'children': [], 'value': "'--quiet'"}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'quiet'}; {'id': '208', 'type': 'None', 'children': []}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'destination'}; {'id': '211', 'type': 'return_statement', 'children': ['212']}; {'id': '212', 'type': 'call', 'children': ['213', '214']}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'local'}; {'id': '214', 'type': 'argument_list', 'children': ['215', '216', '219', '222', '225']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '216', 'type': 'keyword_argument', 'children': ['217', '218']}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'stdout'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'stdout'}; {'id': '219', 'type': 'keyword_argument', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'stderr'}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'stderr'}; {'id': '222', 'type': 'keyword_argument', 'children': ['223', '224']}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'echo'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'echo'}; {'id': '225', 'type': 'keyword_argument', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'raise_on_error'}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'raise_on_error'}
|
def sync(source,
destination,
host,
user=None,
sudo=False,
run_as=None,
options=('-rltvz', '--no-perms', '--no-group'),
excludes=(),
exclude_from=None,
delete=False,
dry_run=False,
mode='u=rwX,g=rwX,o=',
quiet=True,
pull=False,
stdout: arg(type=StreamOptions) = None,
stderr: arg(type=StreamOptions) = None,
echo=False,
raise_on_error=True,
) -> Result:
source = abs_path(source, keep_slash=True)
destination = abs_path(destination, keep_slash=True)
connection_str = '{user}@{host}'.format_map(locals()) if user else host
push = not pull
if sudo:
rsync_path = ('--rsync-path', 'sudo rsync')
elif run_as:
rsync_path = ('--rsync-path', 'sudo -u {run_as} rsync'.format_map(locals()))
else:
rsync_path = None
if push:
destination = '{connection_str}:{destination}'.format_map(locals())
else:
source = '{connection_str}:{source}'.format_map(locals())
args = (
'rsync',
rsync_path,
options,
('--chmod', mode) if mode else None,
tuple(('--exclude', exclude) for exclude in excludes),
('--exclude-from', exclude_from) if exclude_from else None,
'--delete' if delete else None,
'--dry-run' if dry_run else None,
'--quiet' if quiet else None,
source,
destination,
)
return local(args, stdout=stdout, stderr=stderr, echo=echo, raise_on_error=raise_on_error)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '22', '24']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_determine_outliers_for_moving_average'}; {'id': '3', 'type': 'parameters', 'children': ['4', '10', '14', '18']}; {'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'moving_average'}; {'id': '6', 'type': 'type', 'children': ['7']}; {'id': '7', 'type': 'attribute', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'ndarray'}; {'id': '10', 'type': 'typed_parameter', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'moving_average_threshold'}; {'id': '12', 'type': 'type', 'children': ['13']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '14', 'type': 'typed_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'number_of_values_to_search_ahead'}; {'id': '16', 'type': 'type', 'children': ['17']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '18', 'type': 'typed_parameter', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'limit_of_number_of_values_below_threshold'}; {'id': '20', 'type': 'type', 'children': ['21']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '22', 'type': 'type', 'children': ['23']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '24', 'type': 'block', 'children': ['25', '31', '35', '62', '66', '71', '138']}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'below_threshold'}; {'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': '<'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'moving_average'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'moving_average_threshold'}; {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'values_to_check'}; {'id': '34', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '35', 'type': 'for_statement', 'children': ['36', '37', '41']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'limit_of_number_of_values_below_threshold'}; {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}; {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'values_to_check'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'subscript', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'below_threshold'}; {'id': '50', 'type': 'slice', 'children': ['51', '52', '53']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '52', 'type': 'colon', 'children': []}; {'id': '53', 'type': 'boolean_operator', 'children': ['54', '61'], 'value': 'or'}; {'id': '54', 'type': 'unary_operator', 'children': ['55'], 'value': '-'}; {'id': '55', 'type': '()', 'children': ['56']}; {'id': '56', 'type': 'binary_operator', 'children': ['57', '60'], 'value': '-'}; {'id': '57', 'type': 'binary_operator', 'children': ['58', '59'], 'value': '-'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'limit_of_number_of_values_below_threshold'}; {'id': '59', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '61', 'type': 'None', 'children': []}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}; {'id': '63', 'type': 'assignment', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'found_at_least_one_bin_above_threshold'}; {'id': '65', 'type': 'False', 'children': []}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}; {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'cut_index'}; {'id': '69', 'type': 'unary_operator', 'children': ['70'], 'value': '-'}; {'id': '70', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '71', 'type': 'for_statement', 'children': ['72', '75', '83']}; {'id': '72', 'type': 'pattern_list', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}; {'id': '81', 'type': 'list_splat', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'values_to_check'}; {'id': '83', 'type': 'block', 'children': ['84', '90', '99', '109']}; {'id': '84', 'type': 'if_statement', 'children': ['85', '88']}; {'id': '85', 'type': 'comparison_operator', 'children': ['86', '87'], 'value': '=='}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '87', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '88', 'type': 'block', 'children': ['89']}; {'id': '89', 'type': 'continue_statement', 'children': []}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}; {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'above_threshold'}; {'id': '93', 'type': 'list_comprehension', 'children': ['94', '96']}; {'id': '94', 'type': 'not_operator', 'children': ['95']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '96', 'type': 'for_in_clause', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '99', 'type': 'if_statement', 'children': ['100', '104']}; {'id': '100', 'type': 'call', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'any'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'above_threshold'}; {'id': '104', 'type': 'block', 'children': ['105']}; {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'found_at_least_one_bin_above_threshold'}; {'id': '108', 'type': 'True', 'children': []}; {'id': '109', 'type': 'if_statement', 'children': ['110', '121']}; {'id': '110', 'type': 'boolean_operator', 'children': ['111', '112'], 'value': 'and'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'found_at_least_one_bin_above_threshold'}; {'id': '112', 'type': 'call', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '114', 'type': 'argument_list', 'children': ['115']}; {'id': '115', 'type': 'call', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'invert'}; {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'above_threshold'}; {'id': '121', 'type': 'block', 'children': ['122', '129', '137']}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}; {'id': '123', 'type': 'call', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'string', 'children': [], 'value': 'f"i at found cut_index: {i} with moving_average: {moving_average[i]}"'}; {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'assignment', 'children': ['131', '132']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'cut_index'}; {'id': '132', 'type': 'binary_operator', 'children': ['133', '134'], 'value': '+'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '134', 'type': 'binary_operator', 'children': ['135', '136'], 'value': '//'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'limit_of_number_of_values_below_threshold'}; {'id': '136', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '137', 'type': 'break_statement', 'children': []}; {'id': '138', 'type': 'return_statement', 'children': ['139']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'cut_index'}
|
def _determine_outliers_for_moving_average(moving_average: np.ndarray,
moving_average_threshold: float,
number_of_values_to_search_ahead: int,
limit_of_number_of_values_below_threshold: int) -> int:
below_threshold = moving_average < moving_average_threshold
values_to_check = []
for i in range(limit_of_number_of_values_below_threshold):
values_to_check.append(
below_threshold[i:-(limit_of_number_of_values_below_threshold - 1 - i) or None]
)
found_at_least_one_bin_above_threshold = False
cut_index = -1
for i, values in enumerate(zip(*values_to_check)):
if i == 0:
continue
above_threshold = [not value for value in values]
if any(above_threshold):
found_at_least_one_bin_above_threshold = True
if found_at_least_one_bin_above_threshold and all(np.invert(above_threshold)):
logger.debug(f"i at found cut_index: {i} with moving_average: {moving_average[i]}")
cut_index = i + limit_of_number_of_values_below_threshold // 2
break
return cut_index
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'make_dynamic_class'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'typename'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'field_names'}; {'id': '6', 'type': 'block', 'children': ['7', '28', '36', '44', '65', '71', '77', '83', '100', '106', '120', '156']}; {'id': '7', 'type': 'if_statement', 'children': ['8', '13']}; {'id': '8', 'type': 'call', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '10', 'type': 'argument_list', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'field_names'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'basestring'}; {'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': 'field_names'}; {'id': '17', 'type': 'call', 'children': ['18', '27']}; {'id': '18', 'type': 'attribute', 'children': ['19', '26']}; {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'field_names'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '23', 'type': 'argument_list', 'children': ['24', '25']}; {'id': '24', 'type': 'string', 'children': [], 'value': '","'}; {'id': '25', 'type': 'string', 'children': [], 'value': '" "'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'split'}; {'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': 'field_names'}; {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'map'}; {'id': '33', 'type': 'argument_list', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'field_names'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}; {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'safe_fields_names'}; {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'map'}; {'id': '41', 'type': 'argument_list', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': '_encode_property_name'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'field_names'}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}; {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '49', 'type': 'generator_expression', 'children': ['50', '56']}; {'id': '50', 'type': 'tuple', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'safe_name'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': '_property'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '56', 'type': 'for_in_clause', 'children': ['57', '60']}; {'id': '57', 'type': 'pattern_list', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'safe_name'}; {'id': '60', 'type': 'call', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '62', 'type': 'argument_list', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'field_names'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'safe_fields_names'}; {'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': 'attr'}; {'id': '69', 'type': 'string', 'children': [], 'value': "'__doc__'"}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'typename'}; {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '76']}; {'id': '73', 'type': 'subscript', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '75', 'type': 'string', 'children': [], 'value': "'__identifier__'"}; {'id': '76', 'type': 'string', 'children': [], 'value': '"dolphin"'}; {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '82']}; {'id': '79', 'type': 'subscript', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '81', 'type': 'string', 'children': [], 'value': "'__init__'"}; {'id': '82', 'type': 'identifier', 'children': [], 'value': '_dynamic__init'}; {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '88']}; {'id': '85', 'type': 'subscript', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '87', 'type': 'string', 'children': [], 'value': "'__getitem__'"}; {'id': '88', 'type': 'lambda', 'children': ['89', '92']}; {'id': '89', 'type': 'lambda_parameters', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '92', 'type': 'call', 'children': ['93', '98']}; {'id': '93', 'type': 'attribute', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': '__dict__'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}; {'id': '101', 'type': 'assignment', 'children': ['102', '105']}; {'id': '102', 'type': 'subscript', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '104', 'type': 'string', 'children': [], 'value': "'__setitem__'"}; {'id': '105', 'type': 'identifier', 'children': [], 'value': '_dynamic__setitem'}; {'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': 'attr'}; {'id': '110', 'type': 'string', 'children': [], 'value': "'__iter__'"}; {'id': '111', 'type': 'lambda', 'children': ['112', '114']}; {'id': '112', 'type': 'lambda_parameters', 'children': ['113']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '114', 'type': 'call', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'iter'}; {'id': '116', 'type': 'argument_list', 'children': ['117']}; {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': '__dict__'}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}; {'id': '121', 'type': 'assignment', 'children': ['122', '125']}; {'id': '122', 'type': 'subscript', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '124', 'type': 'string', 'children': [], 'value': "'__repr__'"}; {'id': '125', 'type': 'lambda', 'children': ['126', '128']}; {'id': '126', 'type': 'lambda_parameters', 'children': ['127']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '128', 'type': 'binary_operator', 'children': ['129', '130'], 'value': '%'}; {'id': '129', 'type': 'string', 'children': [], 'value': '"{%s}"'}; {'id': '130', 'type': '()', 'children': ['131']}; {'id': '131', 'type': 'call', 'children': ['132', '135']}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}; {'id': '133', 'type': 'string', 'children': [], 'value': "', '"}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '135', 'type': 'argument_list', 'children': ['136']}; {'id': '136', 'type': 'list_comprehension', 'children': ['137', '144']}; {'id': '137', 'type': 'binary_operator', 'children': ['138', '139'], 'value': '%'}; {'id': '138', 'type': 'string', 'children': [], 'value': '"%s=%r"'}; {'id': '139', 'type': 'tuple', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '141', 'type': 'subscript', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '144', 'type': 'for_in_clause', 'children': ['145', '146']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '146', 'type': 'call', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '148', 'type': 'argument_list', 'children': ['149']}; {'id': '149', 'type': 'call', 'children': ['150', '155']}; {'id': '150', 'type': 'attribute', 'children': ['151', '154']}; {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '153', 'type': 'identifier', 'children': [], 'value': '__dict__'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '155', 'type': 'argument_list', 'children': []}; {'id': '156', 'type': 'return_statement', 'children': ['157']}; {'id': '157', 'type': 'call', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '159', 'type': 'argument_list', 'children': ['160', '161', '163']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'typename'}; {'id': '161', 'type': 'tuple', 'children': ['162']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'object'}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'attr'}
|
def make_dynamic_class(typename, field_names):
if isinstance(field_names, basestring):
field_names = field_names.replace(",", " ").split()
field_names = map(str, field_names)
safe_fields_names = map(_encode_property_name, field_names)
attr = dict((safe_name, _property(name)) for name, safe_name in zip(field_names, safe_fields_names))
attr['__doc__'] = typename
attr['__identifier__'] = "dolphin"
attr['__init__'] = _dynamic__init
attr['__getitem__'] = lambda self, key: self.__dict__.get(key)
attr['__setitem__'] = _dynamic__setitem
attr['__iter__'] = lambda self: iter(self.__dict__)
attr['__repr__'] = lambda self: "{%s}" % (', '.join([
"%s=%r" % (key, self[key]) for key in
sorted(self.__dict__.keys())
]))
return type(typename, (object,), attr)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'verifyInputs'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '6', 'type': 'block', 'children': ['7', '34', '431']}; {'id': '7', 'type': 'if_statement', 'children': ['8', '16']}; {'id': '8', 'type': 'comparison_operator', 'children': ['9', '15'], 'value': '<'}; {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '_aichans'}; {'id': '15', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '16', 'type': 'block', 'children': ['17', '21', '32']}; {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'failmsg'}; {'id': '20', 'type': 'string', 'children': [], 'value': '"Must have at least one input channel selected"'}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'call', 'children': ['23', '28']}; {'id': '23', 'type': 'attribute', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'QtGui'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'QMessageBox'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '30', '31']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'string', 'children': [], 'value': '"Invalid Setting"'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'failmsg'}; {'id': '32', 'type': 'return_statement', 'children': ['33']}; {'id': '33', 'type': 'False', 'children': []}; {'id': '34', 'type': 'if_statement', 'children': ['35', '38', '69']}; {'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': '=='}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '37', 'type': 'string', 'children': [], 'value': "'chart'"}; {'id': '38', 'type': 'block', 'children': ['39']}; {'id': '39', 'type': 'if_statement', 'children': ['40', '55']}; {'id': '40', 'type': 'comparison_operator', 'children': ['41', '54'], 'value': '>'}; {'id': '41', 'type': 'binary_operator', 'children': ['42', '51'], 'value': '*'}; {'id': '42', 'type': 'call', 'children': ['43', '50']}; {'id': '43', 'type': 'attribute', 'children': ['44', '49']}; {'id': '44', 'type': 'attribute', 'children': ['45', '48']}; {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'ui'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'aifsSpnbx'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '50', 'type': 'argument_list', 'children': []}; {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'fscale'}; {'id': '54', 'type': 'integer', 'children': [], 'value': '100000'}; {'id': '55', 'type': 'block', 'children': ['56', '67']}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}; {'id': '57', 'type': 'call', 'children': ['58', '63']}; {'id': '58', 'type': 'attribute', 'children': ['59', '62']}; {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'QtGui'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'QMessageBox'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '63', 'type': 'argument_list', 'children': ['64', '65', '66']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '65', 'type': 'string', 'children': [], 'value': '"Invalid Input"'}; {'id': '66', 'type': 'string', 'children': [], 'value': '"Recording samplerate cannot exceed 100kHz for chart acquisition"'}; {'id': '67', 'type': 'return_statement', 'children': ['68']}; {'id': '68', 'type': 'False', 'children': []}; {'id': '69', 'type': 'elif_clause', 'children': ['70', '73']}; {'id': '70', 'type': 'comparison_operator', 'children': ['71', '72'], 'value': 'is'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '72', 'type': 'None', 'children': []}; {'id': '73', 'type': 'block', 'children': ['74', '398']}; {'id': '74', 'type': 'if_statement', 'children': ['75', '90', '138', '201']}; {'id': '75', 'type': 'comparison_operator', 'children': ['76', '89'], 'value': '=='}; {'id': '76', 'type': 'call', 'children': ['77', '88']}; {'id': '77', 'type': 'attribute', 'children': ['78', '87']}; {'id': '78', 'type': 'call', 'children': ['79', '86']}; {'id': '79', 'type': 'attribute', 'children': ['80', '85']}; {'id': '80', 'type': 'attribute', 'children': ['81', '84']}; {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'ui'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'tabGroup'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'currentWidget'}; {'id': '86', 'type': 'argument_list', 'children': []}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'objectName'}; {'id': '88', 'type': 'argument_list', 'children': []}; {'id': '89', 'type': 'string', 'children': [], 'value': "'tabExplore'"}; {'id': '90', 'type': 'block', 'children': ['91', '101', '122']}; {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '100']}; {'id': '93', 'type': 'attribute', 'children': ['94', '99']}; {'id': '94', 'type': 'attribute', 'children': ['95', '98']}; {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'ui'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'exploreStimEditor'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'saveToObject'}; {'id': '100', 'type': 'argument_list', 'children': []}; {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'failmsg'}; {'id': '104', 'type': 'call', 'children': ['105', '112']}; {'id': '105', 'type': 'attribute', 'children': ['106', '111']}; {'id': '106', 'type': 'attribute', 'children': ['107', '110']}; {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'ui'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'exploreStimEditor'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'verify'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}; {'id': '113', 'type': 'call', 'children': ['114', '121']}; {'id': '114', 'type': 'attribute', 'children': ['115', '120']}; {'id': '115', 'type': 'attribute', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'ui'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'windowszSpnbx'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '121', 'type': 'argument_list', 'children': []}; {'id': '122', 'type': 'if_statement', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'failmsg'}; {'id': '124', 'type': 'block', 'children': ['125', '136']}; {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'call', 'children': ['127', '132']}; {'id': '127', 'type': 'attribute', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'QtGui'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'QMessageBox'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '132', 'type': 'argument_list', 'children': ['133', '134', '135']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '134', 'type': 'string', 'children': [], 'value': '"Invalid Input"'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'failmsg'}; {'id': '136', 'type': 'return_statement', 'children': ['137']}; {'id': '137', 'type': 'False', 'children': []}; {'id': '138', 'type': 'elif_clause', 'children': ['139', '154']}; {'id': '139', 'type': 'comparison_operator', 'children': ['140', '153'], 'value': '=='}; {'id': '140', 'type': 'call', 'children': ['141', '152']}; {'id': '141', 'type': 'attribute', 'children': ['142', '151']}; {'id': '142', 'type': 'call', 'children': ['143', '150']}; {'id': '143', 'type': 'attribute', 'children': ['144', '149']}; {'id': '144', 'type': 'attribute', 'children': ['145', '148']}; {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'ui'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'tabGroup'}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'currentWidget'}; {'id': '150', 'type': 'argument_list', 'children': []}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'objectName'}; {'id': '152', 'type': 'argument_list', 'children': []}; {'id': '153', 'type': 'string', 'children': [], 'value': "'tabProtocol'"}; {'id': '154', 'type': 'block', 'children': ['155', '165', '185']}; {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'assignment', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'protocol_model'}; {'id': '158', 'type': 'call', 'children': ['159', '164']}; {'id': '159', 'type': 'attribute', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'acqmodel'}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'protocol_model'}; {'id': '164', 'type': 'argument_list', 'children': []}; {'id': '165', 'type': 'expression_statement', 'children': ['166']}; {'id': '166', 'type': 'assignment', 'children': ['167', '168']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'failure'}; {'id': '168', 'type': 'call', 'children': ['169', '172']}; {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'protocol_model'}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'verify'}; {'id': '172', 'type': 'argument_list', 'children': ['173']}; {'id': '173', 'type': 'call', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '175', 'type': 'argument_list', 'children': ['176']}; {'id': '176', 'type': 'call', 'children': ['177', '184']}; {'id': '177', 'type': 'attribute', 'children': ['178', '183']}; {'id': '178', 'type': 'attribute', 'children': ['179', '182']}; {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'ui'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'windowszSpnbx'}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '184', 'type': 'argument_list', 'children': []}; {'id': '185', 'type': 'if_statement', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'failure'}; {'id': '187', 'type': 'block', 'children': ['188', '199']}; {'id': '188', 'type': 'expression_statement', 'children': ['189']}; {'id': '189', 'type': 'call', 'children': ['190', '195']}; {'id': '190', 'type': 'attribute', 'children': ['191', '194']}; {'id': '191', 'type': 'attribute', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'QtGui'}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'QMessageBox'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '195', 'type': 'argument_list', 'children': ['196', '197', '198']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '197', 'type': 'string', 'children': [], 'value': '"Invalid Input"'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'failure'}; {'id': '199', 'type': 'return_statement', 'children': ['200']}; {'id': '200', 'type': 'False', 'children': []}; {'id': '201', 'type': 'elif_clause', 'children': ['202', '217']}; {'id': '202', 'type': 'comparison_operator', 'children': ['203', '216'], 'value': '=='}; {'id': '203', 'type': 'call', 'children': ['204', '215']}; {'id': '204', 'type': 'attribute', 'children': ['205', '214']}; {'id': '205', 'type': 'call', 'children': ['206', '213']}; {'id': '206', 'type': 'attribute', 'children': ['207', '212']}; {'id': '207', 'type': 'attribute', 'children': ['208', '211']}; {'id': '208', 'type': 'attribute', 'children': ['209', '210']}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'ui'}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'tabGroup'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'currentWidget'}; {'id': '213', 'type': 'argument_list', 'children': []}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'objectName'}; {'id': '215', 'type': 'argument_list', 'children': []}; {'id': '216', 'type': 'string', 'children': [], 'value': "'tabCalibrate'"}; {'id': '217', 'type': 'block', 'children': ['218', '255', '317', '337', '353', '372']}; {'id': '218', 'type': 'if_statement', 'children': ['219', '227']}; {'id': '219', 'type': 'comparison_operator', 'children': ['220', '226'], 'value': '>'}; {'id': '220', 'type': 'call', 'children': ['221', '222']}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '222', 'type': 'argument_list', 'children': ['223']}; {'id': '223', 'type': 'attribute', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '225', 'type': 'identifier', 'children': [], 'value': '_aichans'}; {'id': '226', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '227', 'type': 'block', 'children': ['228', '242', '253']}; {'id': '228', 'type': 'expression_statement', 'children': ['229']}; {'id': '229', 'type': 'assignment', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'failmsg'}; {'id': '231', 'type': 'call', 'children': ['232', '235']}; {'id': '232', 'type': 'attribute', 'children': ['233', '234']}; {'id': '233', 'type': 'string', 'children': [], 'value': '"Speaker calibration only supported for single channel, currently {} channels selected; select 1 input channel."'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '235', 'type': 'argument_list', 'children': ['236']}; {'id': '236', 'type': 'call', 'children': ['237', '238']}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '238', 'type': 'argument_list', 'children': ['239']}; {'id': '239', 'type': 'attribute', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '241', 'type': 'identifier', 'children': [], 'value': '_aichans'}; {'id': '242', 'type': 'expression_statement', 'children': ['243']}; {'id': '243', 'type': 'call', 'children': ['244', '249']}; {'id': '244', 'type': 'attribute', 'children': ['245', '248']}; {'id': '245', 'type': 'attribute', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'QtGui'}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'QMessageBox'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '249', 'type': 'argument_list', 'children': ['250', '251', '252']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '251', 'type': 'string', 'children': [], 'value': '"Invalid Setting"'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'failmsg'}; {'id': '253', 'type': 'return_statement', 'children': ['254']}; {'id': '254', 'type': 'False', 'children': []}; {'id': '255', 'type': 'if_statement', 'children': ['256', '282', '304']}; {'id': '256', 'type': 'boolean_operator', 'children': ['257', '270'], 'value': 'or'}; {'id': '257', 'type': 'call', 'children': ['258', '269']}; {'id': '258', 'type': 'attribute', 'children': ['259', '268']}; {'id': '259', 'type': 'attribute', 'children': ['260', '267']}; {'id': '260', 'type': 'attribute', 'children': ['261', '266']}; {'id': '261', 'type': 'attribute', 'children': ['262', '265']}; {'id': '262', 'type': 'attribute', 'children': ['263', '264']}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'ui'}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'calibrationWidget'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'ui'}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'savecalCkbx'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'isChecked'}; {'id': '269', 'type': 'argument_list', 'children': []}; {'id': '270', 'type': 'not_operator', 'children': ['271']}; {'id': '271', 'type': 'comparison_operator', 'children': ['272', '281'], 'value': '=='}; {'id': '272', 'type': 'call', 'children': ['273', '280']}; {'id': '273', 'type': 'attribute', 'children': ['274', '279']}; {'id': '274', 'type': 'attribute', 'children': ['275', '278']}; {'id': '275', 'type': 'attribute', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'ui'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'calibrationWidget'}; {'id': '279', 'type': 'identifier', 'children': [], 'value': 'currentSelection'}; {'id': '280', 'type': 'argument_list', 'children': []}; {'id': '281', 'type': 'string', 'children': [], 'value': "'Tone Curve'"}; {'id': '282', 'type': 'block', 'children': ['283', '294']}; {'id': '283', 'type': 'expression_statement', 'children': ['284']}; {'id': '284', 'type': 'assignment', 'children': ['285', '286']}; {'id': '285', 'type': 'identifier', 'children': [], 'value': 'calibration_stimulus'}; {'id': '286', 'type': 'call', 'children': ['287', '292']}; {'id': '287', 'type': 'attribute', 'children': ['288', '291']}; {'id': '288', 'type': 'attribute', 'children': ['289', '290']}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'acqmodel'}; {'id': '291', 'type': 'identifier', 'children': [], 'value': 'calibration_stimulus'}; {'id': '292', 'type': 'argument_list', 'children': ['293']}; {'id': '293', 'type': 'string', 'children': [], 'value': "'noise'"}; {'id': '294', 'type': 'expression_statement', 'children': ['295']}; {'id': '295', 'type': 'call', 'children': ['296', '303']}; {'id': '296', 'type': 'attribute', 'children': ['297', '302']}; {'id': '297', 'type': 'attribute', 'children': ['298', '301']}; {'id': '298', 'type': 'attribute', 'children': ['299', '300']}; {'id': '299', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'ui'}; {'id': '301', 'type': 'identifier', 'children': [], 'value': 'calibrationWidget'}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'saveToObject'}; {'id': '303', 'type': 'argument_list', 'children': []}; {'id': '304', 'type': 'else_clause', 'children': ['305']}; {'id': '305', 'type': 'block', 'children': ['306']}; {'id': '306', 'type': 'expression_statement', 'children': ['307']}; {'id': '307', 'type': 'assignment', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'calibration_stimulus'}; {'id': '309', 'type': 'call', 'children': ['310', '315']}; {'id': '310', 'type': 'attribute', 'children': ['311', '314']}; {'id': '311', 'type': 'attribute', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '313', 'type': 'identifier', 'children': [], 'value': 'acqmodel'}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'calibration_stimulus'}; {'id': '315', 'type': 'argument_list', 'children': ['316']}; {'id': '316', 'type': 'string', 'children': [], 'value': "'tone'"}; {'id': '317', 'type': 'expression_statement', 'children': ['318']}; {'id': '318', 'type': 'assignment', 'children': ['319', '320']}; {'id': '319', 'type': 'identifier', 'children': [], 'value': 'failmsg'}; {'id': '320', 'type': 'call', 'children': ['321', '324']}; {'id': '321', 'type': 'attribute', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'calibration_stimulus'}; {'id': '323', 'type': 'identifier', 'children': [], 'value': 'verify'}; {'id': '324', 'type': 'argument_list', 'children': ['325']}; {'id': '325', 'type': 'call', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '327', 'type': 'argument_list', 'children': ['328']}; {'id': '328', 'type': 'call', 'children': ['329', '336']}; {'id': '329', 'type': 'attribute', 'children': ['330', '335']}; {'id': '330', 'type': 'attribute', 'children': ['331', '334']}; {'id': '331', 'type': 'attribute', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '333', 'type': 'identifier', 'children': [], 'value': 'ui'}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'windowszSpnbx'}; {'id': '335', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '336', 'type': 'argument_list', 'children': []}; {'id': '337', 'type': 'if_statement', 'children': ['338', '339']}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'failmsg'}; {'id': '339', 'type': 'block', 'children': ['340', '351']}; {'id': '340', 'type': 'expression_statement', 'children': ['341']}; {'id': '341', 'type': 'call', 'children': ['342', '347']}; {'id': '342', 'type': 'attribute', 'children': ['343', '346']}; {'id': '343', 'type': 'attribute', 'children': ['344', '345']}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'QtGui'}; {'id': '345', 'type': 'identifier', 'children': [], 'value': 'QMessageBox'}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '347', 'type': 'argument_list', 'children': ['348', '349', '350']}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '349', 'type': 'string', 'children': [], 'value': '"Invalid Input"'}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'failmsg'}; {'id': '351', 'type': 'return_statement', 'children': ['352']}; {'id': '352', 'type': 'False', 'children': []}; {'id': '353', 'type': 'expression_statement', 'children': ['354']}; {'id': '354', 'type': 'assignment', 'children': ['355', '356']}; {'id': '355', 'type': 'identifier', 'children': [], 'value': 'failmsg'}; {'id': '356', 'type': 'call', 'children': ['357', '360']}; {'id': '357', 'type': 'attribute', 'children': ['358', '359']}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'calibration_stimulus'}; {'id': '359', 'type': 'identifier', 'children': [], 'value': 'verifyExpanded'}; {'id': '360', 'type': 'argument_list', 'children': ['361']}; {'id': '361', 'type': 'keyword_argument', 'children': ['362', '363']}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'samplerate'}; {'id': '363', 'type': 'call', 'children': ['364', '371']}; {'id': '364', 'type': 'attribute', 'children': ['365', '370']}; {'id': '365', 'type': 'attribute', 'children': ['366', '369']}; {'id': '366', 'type': 'attribute', 'children': ['367', '368']}; {'id': '367', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'ui'}; {'id': '369', 'type': 'identifier', 'children': [], 'value': 'aifsSpnbx'}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '371', 'type': 'argument_list', 'children': []}; {'id': '372', 'type': 'if_statement', 'children': ['373', '374']}; {'id': '373', 'type': 'identifier', 'children': [], 'value': 'failmsg'}; {'id': '374', 'type': 'block', 'children': ['375', '385', '396']}; {'id': '375', 'type': 'expression_statement', 'children': ['376']}; {'id': '376', 'type': 'assignment', 'children': ['377', '378']}; {'id': '377', 'type': 'identifier', 'children': [], 'value': 'failmsg'}; {'id': '378', 'type': 'call', 'children': ['379', '382']}; {'id': '379', 'type': 'attribute', 'children': ['380', '381']}; {'id': '380', 'type': 'identifier', 'children': [], 'value': 'failmsg'}; {'id': '381', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '382', 'type': 'argument_list', 'children': ['383', '384']}; {'id': '383', 'type': 'string', 'children': [], 'value': "'Generation'"}; {'id': '384', 'type': 'string', 'children': [], 'value': "'Recording'"}; {'id': '385', 'type': 'expression_statement', 'children': ['386']}; {'id': '386', 'type': 'call', 'children': ['387', '392']}; {'id': '387', 'type': 'attribute', 'children': ['388', '391']}; {'id': '388', 'type': 'attribute', 'children': ['389', '390']}; {'id': '389', 'type': 'identifier', 'children': [], 'value': 'QtGui'}; {'id': '390', 'type': 'identifier', 'children': [], 'value': 'QMessageBox'}; {'id': '391', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '392', 'type': 'argument_list', 'children': ['393', '394', '395']}; {'id': '393', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '394', 'type': 'string', 'children': [], 'value': '"Invalid Input"'}; {'id': '395', 'type': 'identifier', 'children': [], 'value': 'failmsg'}; {'id': '396', 'type': 'return_statement', 'children': ['397']}; {'id': '397', 'type': 'False', 'children': []}; {'id': '398', 'type': 'if_statement', 'children': ['399', '413']}; {'id': '399', 'type': 'boolean_operator', 'children': ['400', '405'], 'value': 'and'}; {'id': '400', 'type': 'subscript', 'children': ['401', '404']}; {'id': '401', 'type': 'attribute', 'children': ['402', '403']}; {'id': '402', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '403', 'type': 'identifier', 'children': [], 'value': 'advanced_options'}; {'id': '404', 'type': 'string', 'children': [], 'value': "'use_attenuator'"}; {'id': '405', 'type': 'not_operator', 'children': ['406']}; {'id': '406', 'type': 'call', 'children': ['407', '412']}; {'id': '407', 'type': 'attribute', 'children': ['408', '411']}; {'id': '408', 'type': 'attribute', 'children': ['409', '410']}; {'id': '409', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '410', 'type': 'identifier', 'children': [], 'value': 'acqmodel'}; {'id': '411', 'type': 'identifier', 'children': [], 'value': 'attenuator_connection'}; {'id': '412', 'type': 'argument_list', 'children': []}; {'id': '413', 'type': 'block', 'children': ['414', '418', '429']}; {'id': '414', 'type': 'expression_statement', 'children': ['415']}; {'id': '415', 'type': 'assignment', 'children': ['416', '417']}; {'id': '416', 'type': 'identifier', 'children': [], 'value': 'failmsg'}; {'id': '417', 'type': 'string', 'children': [], 'value': '"Error Connection to attenuator, make sure it it turned on and connected, and try again"'}; {'id': '418', 'type': 'expression_statement', 'children': ['419']}; {'id': '419', 'type': 'call', 'children': ['420', '425']}; {'id': '420', 'type': 'attribute', 'children': ['421', '424']}; {'id': '421', 'type': 'attribute', 'children': ['422', '423']}; {'id': '422', 'type': 'identifier', 'children': [], 'value': 'QtGui'}; {'id': '423', 'type': 'identifier', 'children': [], 'value': 'QMessageBox'}; {'id': '424', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '425', 'type': 'argument_list', 'children': ['426', '427', '428']}; {'id': '426', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '427', 'type': 'string', 'children': [], 'value': '"Connection Error"'}; {'id': '428', 'type': 'identifier', 'children': [], 'value': 'failmsg'}; {'id': '429', 'type': 'return_statement', 'children': ['430']}; {'id': '430', 'type': 'False', 'children': []}; {'id': '431', 'type': 'return_statement', 'children': ['432']}; {'id': '432', 'type': 'True', 'children': []}
|
def verifyInputs(self, mode):
if len(self._aichans) < 1:
failmsg = "Must have at least one input channel selected"
QtGui.QMessageBox.warning(self, "Invalid Setting", failmsg)
return False
if mode == 'chart':
if self.ui.aifsSpnbx.value()*self.fscale > 100000:
QtGui.QMessageBox.warning(self, "Invalid Input", "Recording samplerate cannot exceed 100kHz for chart acquisition")
return False
elif mode is not None:
if self.ui.tabGroup.currentWidget().objectName() == 'tabExplore':
self.ui.exploreStimEditor.saveToObject()
failmsg = self.ui.exploreStimEditor.verify(self.ui.windowszSpnbx.value())
if failmsg:
QtGui.QMessageBox.warning(self, "Invalid Input", failmsg)
return False
elif self.ui.tabGroup.currentWidget().objectName() == 'tabProtocol':
protocol_model = self.acqmodel.protocol_model()
failure = protocol_model.verify(float(self.ui.windowszSpnbx.value()))
if failure:
QtGui.QMessageBox.warning(self, "Invalid Input", failure)
return False
elif self.ui.tabGroup.currentWidget().objectName() == 'tabCalibrate':
if len(self._aichans) > 1:
failmsg = "Speaker calibration only supported for single channel, currently {} channels selected; select 1 input channel.".format(len(self._aichans))
QtGui.QMessageBox.warning(self, "Invalid Setting", failmsg)
return False
if self.ui.calibrationWidget.ui.savecalCkbx.isChecked() or not self.ui.calibrationWidget.currentSelection() == 'Tone Curve':
calibration_stimulus = self.acqmodel.calibration_stimulus('noise')
self.ui.calibrationWidget.saveToObject()
else:
calibration_stimulus = self.acqmodel.calibration_stimulus('tone')
failmsg = calibration_stimulus.verify(float(self.ui.windowszSpnbx.value()))
if failmsg:
QtGui.QMessageBox.warning(self, "Invalid Input", failmsg)
return False
failmsg = calibration_stimulus.verifyExpanded(samplerate=self.ui.aifsSpnbx.value())
if failmsg:
failmsg = failmsg.replace('Generation', 'Recording')
QtGui.QMessageBox.warning(self, "Invalid Input", failmsg)
return False
if self.advanced_options['use_attenuator'] and not self.acqmodel.attenuator_connection():
failmsg = "Error Connection to attenuator, make sure it it turned on and connected, and try again"
QtGui.QMessageBox.warning(self, "Connection Error", failmsg)
return False
return True
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'complete'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'command_line'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'current_token'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'position'}; {'id': '7', 'type': 'typed_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'shell'}; {'id': '9', 'type': 'type', 'children': ['10']}; {'id': '10', 'type': 'call', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'arg'}; {'id': '12', 'type': 'argument_list', 'children': ['13']}; {'id': '13', 'type': 'keyword_argument', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'choices'}; {'id': '15', 'type': 'tuple', 'children': ['16', '17']}; {'id': '16', 'type': 'string', 'children': [], 'value': "'bash'"}; {'id': '17', 'type': 'string', 'children': [], 'value': "'fish'"}; {'id': '18', 'type': 'block', 'children': ['19', '26', '39', '55', '64', '73', '79', '86', '104', '114']}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'position'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'position'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}; {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'tokens'}; {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'shlex'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'subscript', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'command_line'}; {'id': '36', 'type': 'slice', 'children': ['37', '38']}; {'id': '37', 'type': 'colon', 'children': []}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'position'}; {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '45']}; {'id': '41', 'type': 'pattern_list', 'children': ['42', '43', '44']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'all_argv'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'run_argv'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'command_argv'}; {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'run'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'partition_argv'}; {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'subscript', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'tokens'}; {'id': '52', 'type': 'slice', 'children': ['53', '54']}; {'id': '53', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '54', 'type': 'colon', 'children': []}; {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'run_args'}; {'id': '58', 'type': 'call', 'children': ['59', '62']}; {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'run'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'parse_args'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'run_argv'}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}; {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'run_args'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'string', 'children': [], 'value': "'commands_module'"}; {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '76', 'type': 'boolean_operator', 'children': ['77', '78'], 'value': 'or'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_COMMANDS_MODULE'}; {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '82', 'type': 'call', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'normalize_path'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '86', 'type': 'try_statement', 'children': ['87', '97']}; {'id': '87', 'type': 'block', 'children': ['88']}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}; {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'collection'}; {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'Collection'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'load_from_module'}; {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '97', 'type': 'except_clause', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '99', 'type': 'block', 'children': ['100']}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}; {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'collection'}; {'id': '103', 'type': 'dictionary', 'children': []}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}; {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'found_command'}; {'id': '107', 'type': 'boolean_operator', 'children': ['108', '113'], 'value': 'or'}; {'id': '108', 'type': 'call', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'find_command'}; {'id': '110', 'type': 'argument_list', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'collection'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'tokens'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'run'}; {'id': '114', 'type': 'if_statement', 'children': ['115', '116', '210']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'current_token'}; {'id': '116', 'type': 'block', 'children': ['117']}; {'id': '117', 'type': 'if_statement', 'children': ['118', '124', '138']}; {'id': '118', 'type': 'call', 'children': ['119', '122']}; {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'current_token'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}; {'id': '123', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '124', 'type': 'block', 'children': ['125']}; {'id': '125', 'type': 'if_statement', 'children': ['126', '131']}; {'id': '126', 'type': 'comparison_operator', 'children': ['127', '128'], 'value': 'not'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'current_token'}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'found_command'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'option_map'}; {'id': '131', 'type': 'block', 'children': ['132']}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}; {'id': '133', 'type': 'call', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'print_command_options'}; {'id': '135', 'type': 'argument_list', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'found_command'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'current_token'}; {'id': '138', 'type': 'else_clause', 'children': ['139']}; {'id': '139', 'type': 'block', 'children': ['140', '146', '157', '168', '179']}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}; {'id': '141', 'type': 'call', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'print_commands'}; {'id': '143', 'type': 'argument_list', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'collection'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'shell'}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}; {'id': '147', 'type': 'assignment', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '149', 'type': 'call', 'children': ['150', '155']}; {'id': '150', 'type': 'attribute', 'children': ['151', '154']}; {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'expanduser'}; {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'current_token'}; {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'assignment', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '160', 'type': 'call', 'children': ['161', '166']}; {'id': '161', 'type': 'attribute', 'children': ['162', '165']}; {'id': '162', 'type': 'attribute', 'children': ['163', '164']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'expandvars'}; {'id': '166', 'type': 'argument_list', 'children': ['167']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}; {'id': '169', 'type': 'assignment', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'paths'}; {'id': '171', 'type': 'call', 'children': ['172', '175']}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'glob'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'glob'}; {'id': '175', 'type': 'argument_list', 'children': ['176']}; {'id': '176', 'type': 'binary_operator', 'children': ['177', '178'], 'value': '%'}; {'id': '177', 'type': 'string', 'children': [], 'value': "'%s*'"}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '179', 'type': 'if_statement', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'paths'}; {'id': '181', 'type': 'block', 'children': ['182']}; {'id': '182', 'type': 'for_statement', 'children': ['183', '184', '185']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'paths'}; {'id': '185', 'type': 'block', 'children': ['186']}; {'id': '186', 'type': 'if_statement', 'children': ['187', '195', '203']}; {'id': '187', 'type': 'call', 'children': ['188', '193']}; {'id': '188', 'type': 'attribute', 'children': ['189', '192']}; {'id': '189', 'type': 'attribute', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'isdir'}; {'id': '193', 'type': 'argument_list', 'children': ['194']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '195', 'type': 'block', 'children': ['196']}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}; {'id': '197', 'type': 'call', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '199', 'type': 'argument_list', 'children': ['200']}; {'id': '200', 'type': 'binary_operator', 'children': ['201', '202'], 'value': '%'}; {'id': '201', 'type': 'string', 'children': [], 'value': "'%s/'"}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '203', 'type': 'else_clause', 'children': ['204']}; {'id': '204', 'type': 'block', 'children': ['205']}; {'id': '205', 'type': 'expression_statement', 'children': ['206']}; {'id': '206', 'type': 'call', 'children': ['207', '208']}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '208', 'type': 'argument_list', 'children': ['209']}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '210', 'type': 'else_clause', 'children': ['211']}; {'id': '211', 'type': 'block', 'children': ['212', '226']}; {'id': '212', 'type': 'expression_statement', 'children': ['213']}; {'id': '213', 'type': 'assignment', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'option'}; {'id': '215', 'type': 'call', 'children': ['216', '221']}; {'id': '216', 'type': 'attribute', 'children': ['217', '220']}; {'id': '217', 'type': 'attribute', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'found_command'}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'option_map'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '221', 'type': 'argument_list', 'children': ['222']}; {'id': '222', 'type': 'subscript', 'children': ['223', '224']}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'tokens'}; {'id': '224', 'type': 'unary_operator', 'children': ['225'], 'value': '-'}; {'id': '225', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '226', 'type': 'if_statement', 'children': ['227', '232', '283']}; {'id': '227', 'type': 'boolean_operator', 'children': ['228', '229'], 'value': 'and'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'option'}; {'id': '229', 'type': 'attribute', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'option'}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'takes_value'}; {'id': '232', 'type': 'block', 'children': ['233']}; {'id': '233', 'type': 'if_statement', 'children': ['234', '237', '249']}; {'id': '234', 'type': 'attribute', 'children': ['235', '236']}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'option'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'choices'}; {'id': '237', 'type': 'block', 'children': ['238']}; {'id': '238', 'type': 'for_statement', 'children': ['239', '240', '243']}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'choice'}; {'id': '240', 'type': 'attribute', 'children': ['241', '242']}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'option'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'choices'}; {'id': '243', 'type': 'block', 'children': ['244']}; {'id': '244', 'type': 'expression_statement', 'children': ['245']}; {'id': '245', 'type': 'call', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '247', 'type': 'argument_list', 'children': ['248']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'choice'}; {'id': '249', 'type': 'else_clause', 'children': ['250']}; {'id': '250', 'type': 'block', 'children': ['251']}; {'id': '251', 'type': 'for_statement', 'children': ['252', '253', '258']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '253', 'type': 'call', 'children': ['254', '257']}; {'id': '254', 'type': 'attribute', 'children': ['255', '256']}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'listdir'}; {'id': '257', 'type': 'argument_list', 'children': []}; {'id': '258', 'type': 'block', 'children': ['259']}; {'id': '259', 'type': 'if_statement', 'children': ['260', '268', '276']}; {'id': '260', 'type': 'call', 'children': ['261', '266']}; {'id': '261', 'type': 'attribute', 'children': ['262', '265']}; {'id': '262', 'type': 'attribute', 'children': ['263', '264']}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'isdir'}; {'id': '266', 'type': 'argument_list', 'children': ['267']}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '268', 'type': 'block', 'children': ['269']}; {'id': '269', 'type': 'expression_statement', 'children': ['270']}; {'id': '270', 'type': 'call', 'children': ['271', '272']}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '272', 'type': 'argument_list', 'children': ['273']}; {'id': '273', 'type': 'binary_operator', 'children': ['274', '275'], 'value': '%'}; {'id': '274', 'type': 'string', 'children': [], 'value': "'%s/'"}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '276', 'type': 'else_clause', 'children': ['277']}; {'id': '277', 'type': 'block', 'children': ['278']}; {'id': '278', 'type': 'expression_statement', 'children': ['279']}; {'id': '279', 'type': 'call', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '281', 'type': 'argument_list', 'children': ['282']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '283', 'type': 'else_clause', 'children': ['284']}; {'id': '284', 'type': 'block', 'children': ['285', '290']}; {'id': '285', 'type': 'expression_statement', 'children': ['286']}; {'id': '286', 'type': 'call', 'children': ['287', '288']}; {'id': '287', 'type': 'identifier', 'children': [], 'value': 'print_command_options'}; {'id': '288', 'type': 'argument_list', 'children': ['289']}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'found_command'}; {'id': '290', 'type': 'expression_statement', 'children': ['291']}; {'id': '291', 'type': 'call', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'print_commands'}; {'id': '293', 'type': 'argument_list', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'collection'}; {'id': '295', 'type': 'identifier', 'children': [], 'value': 'shell'}
|
def complete(command_line,
current_token,
position,
shell: arg(choices=('bash', 'fish'))):
position = int(position)
tokens = shlex.split(command_line[:position])
all_argv, run_argv, command_argv = run.partition_argv(tokens[1:])
run_args = run.parse_args(run_argv)
module = run_args.get('commands_module')
module = module or DEFAULT_COMMANDS_MODULE
module = normalize_path(module)
try:
collection = Collection.load_from_module(module)
except Exception:
collection = {}
found_command = find_command(collection, tokens) or run
if current_token:
if current_token.startswith('-'):
if current_token not in found_command.option_map:
print_command_options(found_command, current_token)
else:
print_commands(collection, shell)
path = os.path.expanduser(current_token)
path = os.path.expandvars(path)
paths = glob.glob('%s*' % path)
if paths:
for entry in paths:
if os.path.isdir(entry):
print('%s/' % entry)
else:
print(entry)
else:
option = found_command.option_map.get(tokens[-1])
if option and option.takes_value:
if option.choices:
for choice in option.choices:
print(choice)
else:
for entry in os.listdir():
if os.path.isdir(entry):
print('%s/' % entry)
else:
print(entry)
else:
print_command_options(found_command)
print_commands(collection, shell)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'export'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'keywords'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '8', 'type': 'block', 'children': ['9', '19', '27', '31', '197']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'call', 'children': ['11', '14']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}; {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'string', 'children': [], 'value': "'Export Mode'"}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'database'}; {'id': '22', 'type': 'subscript', 'children': ['23', '26']}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '26', 'type': 'string', 'children': [], 'value': "'sense'"}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'none'}; {'id': '30', 'type': 'True', 'children': []}; {'id': '31', 'type': 'if_statement', 'children': ['32', '33', '104', '154']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '33', 'type': 'block', 'children': ['34', '40', '48', '93', '100']}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}; {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'exports'}; {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'}; {'id': '39', 'type': 'argument_list', 'children': []}; {'id': '40', 'type': 'import_from_statement', 'children': ['41', '46']}; {'id': '41', 'type': 'relative_import', 'children': ['42', '43']}; {'id': '42', 'type': 'import_prefix', 'children': []}; {'id': '43', 'type': 'dotted_name', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'executables'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'pe'}; {'id': '46', 'type': 'dotted_name', 'children': ['47']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'PE'}; {'id': '48', 'type': 'for_statement', 'children': ['49', '50', '51']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'keywords'}; {'id': '51', 'type': 'block', 'children': ['52', '64']}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}; {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '55', 'type': 'subscript', 'children': ['56', '63']}; {'id': '56', 'type': 'call', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'split_ext'}; {'id': '58', 'type': 'argument_list', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '60', 'type': 'keyword_argument', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'basename'}; {'id': '62', 'type': 'True', 'children': []}; {'id': '63', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '64', 'type': 'with_statement', 'children': ['65', '75']}; {'id': '65', 'type': 'with_clause', 'children': ['66']}; {'id': '66', 'type': 'with_item', 'children': ['67']}; {'id': '67', 'type': 'as_pattern', 'children': ['68', '73']}; {'id': '68', 'type': 'call', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '70', 'type': 'argument_list', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '72', 'type': 'string', 'children': [], 'value': "'rb'"}; {'id': '73', 'type': 'as_pattern_target', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'stream'}; {'id': '75', 'type': 'block', 'children': ['76']}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}; {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'exports'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'dictionary', 'children': ['83']}; {'id': '83', 'type': 'pair', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '85', 'type': 'call', 'children': ['86', '92']}; {'id': '86', 'type': 'attribute', 'children': ['87', '91']}; {'id': '87', 'type': 'call', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'PE'}; {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'stream'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'get_export_table'}; {'id': '92', 'type': 'argument_list', 'children': []}; {'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': 'database'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'make_export'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'exports'}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}; {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'none'}; {'id': '103', 'type': 'False', 'children': []}; {'id': '104', 'type': 'elif_clause', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '106', 'type': 'block', 'children': ['107']}; {'id': '107', 'type': 'for_statement', 'children': ['108', '109', '110']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'module_name'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'keywords'}; {'id': '110', 'type': 'block', 'children': ['111', '120']}; {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'funcs'}; {'id': '114', 'type': 'call', 'children': ['115', '118']}; {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'database'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'query_module_funcs'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'module_name'}; {'id': '120', 'type': 'if_statement', 'children': ['121', '122', '141']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'funcs'}; {'id': '122', 'type': 'block', 'children': ['123', '127']}; {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'none'}; {'id': '126', 'type': 'False', 'children': []}; {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'call', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}; {'id': '131', 'type': 'call', 'children': ['132', '135']}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}; {'id': '133', 'type': 'string', 'children': [], 'value': "', '"}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '135', 'type': 'argument_list', 'children': ['136']}; {'id': '136', 'type': 'call', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'map'}; {'id': '138', 'type': 'argument_list', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'funcs'}; {'id': '141', 'type': 'else_clause', 'children': ['142']}; {'id': '142', 'type': 'block', 'children': ['143']}; {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'call', 'children': ['145', '148']}; {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '148', 'type': 'argument_list', 'children': ['149', '153']}; {'id': '149', 'type': 'call', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '151', 'type': 'argument_list', 'children': ['152']}; {'id': '152', 'type': 'string', 'children': [], 'value': "'No function for module: %s'"}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'module_name'}; {'id': '154', 'type': 'else_clause', 'children': ['155']}; {'id': '155', 'type': 'block', 'children': ['156']}; {'id': '156', 'type': 'for_statement', 'children': ['157', '158', '159']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'func_name'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'keywords'}; {'id': '159', 'type': 'block', 'children': ['160', '169']}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}; {'id': '161', 'type': 'assignment', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'module_name'}; {'id': '163', 'type': 'call', 'children': ['164', '167']}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'database'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'query_func_module'}; {'id': '167', 'type': 'argument_list', 'children': ['168']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'func_name'}; {'id': '169', 'type': 'if_statement', 'children': ['170', '171', '184']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'module_name'}; {'id': '171', 'type': 'block', 'children': ['172', '176']}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}; {'id': '173', 'type': 'assignment', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'none'}; {'id': '175', 'type': 'False', 'children': []}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}; {'id': '177', 'type': 'call', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '179', 'type': 'argument_list', 'children': ['180']}; {'id': '180', 'type': 'call', 'children': ['181', '182']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'repr'}; {'id': '182', 'type': 'argument_list', 'children': ['183']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'module_name'}; {'id': '184', 'type': 'else_clause', 'children': ['185']}; {'id': '185', 'type': 'block', 'children': ['186']}; {'id': '186', 'type': 'expression_statement', 'children': ['187']}; {'id': '187', 'type': 'call', 'children': ['188', '191']}; {'id': '188', 'type': 'attribute', 'children': ['189', '190']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '191', 'type': 'argument_list', 'children': ['192', '196']}; {'id': '192', 'type': 'call', 'children': ['193', '194']}; {'id': '193', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '194', 'type': 'argument_list', 'children': ['195']}; {'id': '195', 'type': 'string', 'children': [], 'value': "'No module for function: %s'"}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'func_name'}; {'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': 'sys'}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'exit'}; {'id': '202', 'type': 'argument_list', 'children': ['203']}; {'id': '203', 'type': 'conditional_expression', 'children': ['204', '205', '206'], 'value': 'if'}; {'id': '204', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'none'}; {'id': '206', 'type': 'integer', 'children': [], 'value': '0'}
|
def export(context, keywords, module, update):
logging.info(_('Export Mode'))
database = context.obj['sense']
none = True
if update:
exports = OrderedDict()
from .executables.pe import PE
for filename in keywords:
module = split_ext(filename, basename=True)[0]
with open(filename, 'rb') as stream:
exports.update(
{module: PE(stream).get_export_table()})
database.make_export(exports)
none = False
elif module:
for module_name in keywords:
funcs = database.query_module_funcs(module_name)
if funcs:
none = False
print(', '.join(map(str, funcs)))
else:
logging.warning(_('No function for module: %s'),
module_name)
else:
for func_name in keywords:
module_name = database.query_func_module(func_name)
if module_name:
none = False
print(repr(module_name))
else:
logging.warning(_('No module for function: %s'),
func_name)
sys.exit(1 if none else 0)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_source'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'source_type'}; {'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '8', 'type': 'block', 'children': ['9', '27', '53']}; {'id': '9', 'type': 'if_statement', 'children': ['10', '15']}; {'id': '10', 'type': 'comparison_operator', 'children': ['11', '12'], 'value': 'not'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'source_type'}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'yapconf'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'ALL_SUPPORTED_SOURCES'}; {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'raise_statement', 'children': ['17']}; {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'YapconfSourceError'}; {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'binary_operator', 'children': ['21', '22'], 'value': '%'}; {'id': '21', 'type': 'string', 'children': [], 'value': "'Invalid source type %s. Supported types are %s.'"}; {'id': '22', 'type': 'tuple', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'source_type'}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'yapconf'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'ALL_SUPPORTED_SOURCES'}; {'id': '27', 'type': 'if_statement', 'children': ['28', '33']}; {'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': 'not'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'source_type'}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'yapconf'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'SUPPORTED_SOURCES'}; {'id': '33', 'type': 'block', 'children': ['34']}; {'id': '34', 'type': 'raise_statement', 'children': ['35']}; {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'YapconfSourceError'}; {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'binary_operator', 'children': ['39', '44'], 'value': '%'}; {'id': '39', 'type': 'concatenated_string', 'children': ['40', '41', '42', '43']}; {'id': '40', 'type': 'string', 'children': [], 'value': '\'Unsupported source type "%s". If you want to use this type, you \''}; {'id': '41', 'type': 'string', 'children': [], 'value': "'will need to install the correct client for it (try `pip install '"}; {'id': '42', 'type': 'string', 'children': [], 'value': "'yapconf[%s]. Currently supported types are %s. All supported '"}; {'id': '43', 'type': 'string', 'children': [], 'value': "'types are %s'"}; {'id': '44', 'type': 'tuple', 'children': ['45', '46', '47', '50']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'source_type'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'source_type'}; {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'yapconf'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'SUPPORTED_SOURCES'}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'yapconf'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'ALL_SUPPORTED_SOURCES'}; {'id': '53', 'type': 'if_statement', 'children': ['54', '57', '71', '83', '117', '127', '150', '206']}; {'id': '54', 'type': 'comparison_operator', 'children': ['55', '56'], 'value': '=='}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'source_type'}; {'id': '56', 'type': 'string', 'children': [], 'value': "'dict'"}; {'id': '57', 'type': 'block', 'children': ['58']}; {'id': '58', 'type': 'return_statement', 'children': ['59']}; {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'DictConfigSource'}; {'id': '61', 'type': 'argument_list', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '63', 'type': 'keyword_argument', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '65', 'type': 'call', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'string', 'children': [], 'value': "'data'"}; {'id': '71', 'type': 'elif_clause', 'children': ['72', '75']}; {'id': '72', 'type': 'comparison_operator', 'children': ['73', '74'], 'value': '=='}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'source_type'}; {'id': '74', 'type': 'string', 'children': [], 'value': "'json'"}; {'id': '75', 'type': 'block', 'children': ['76']}; {'id': '76', 'type': 'return_statement', 'children': ['77']}; {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'JsonConfigSource'}; {'id': '79', 'type': 'argument_list', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '81', 'type': 'dictionary_splat', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '83', 'type': 'elif_clause', 'children': ['84', '87']}; {'id': '84', 'type': 'comparison_operator', 'children': ['85', '86'], 'value': '=='}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'source_type'}; {'id': '86', 'type': 'string', 'children': [], 'value': "'yaml'"}; {'id': '87', 'type': 'block', 'children': ['88', '97', '109']}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}; {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'string', 'children': [], 'value': "'filename'"}; {'id': '97', 'type': 'if_statement', 'children': ['98', '101']}; {'id': '98', 'type': 'comparison_operator', 'children': ['99', '100'], 'value': 'in'}; {'id': '99', 'type': 'string', 'children': [], 'value': "'filename'"}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '101', 'type': 'block', 'children': ['102']}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}; {'id': '103', 'type': 'call', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'string', 'children': [], 'value': "'filename'"}; {'id': '109', 'type': 'return_statement', 'children': ['110']}; {'id': '110', 'type': 'call', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'YamlConfigSource'}; {'id': '112', 'type': 'argument_list', 'children': ['113', '114', '115']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '115', 'type': 'dictionary_splat', 'children': ['116']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '117', 'type': 'elif_clause', 'children': ['118', '121']}; {'id': '118', 'type': 'comparison_operator', 'children': ['119', '120'], 'value': '=='}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'source_type'}; {'id': '120', 'type': 'string', 'children': [], 'value': "'environment'"}; {'id': '121', 'type': 'block', 'children': ['122']}; {'id': '122', 'type': 'return_statement', 'children': ['123']}; {'id': '123', 'type': 'call', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'EnvironmentConfigSource'}; {'id': '125', 'type': 'argument_list', 'children': ['126']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '127', 'type': 'elif_clause', 'children': ['128', '131']}; {'id': '128', 'type': 'comparison_operator', 'children': ['129', '130'], 'value': '=='}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'source_type'}; {'id': '130', 'type': 'string', 'children': [], 'value': "'etcd'"}; {'id': '131', 'type': 'block', 'children': ['132']}; {'id': '132', 'type': 'return_statement', 'children': ['133']}; {'id': '133', 'type': 'call', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'EtcdConfigSource'}; {'id': '135', 'type': 'argument_list', 'children': ['136', '137', '143']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '137', 'type': 'call', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'string', 'children': [], 'value': "'client'"}; {'id': '143', 'type': 'call', 'children': ['144', '147']}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '147', 'type': 'argument_list', 'children': ['148', '149']}; {'id': '148', 'type': 'string', 'children': [], 'value': "'key'"}; {'id': '149', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '150', 'type': 'elif_clause', 'children': ['151', '154']}; {'id': '151', 'type': 'comparison_operator', 'children': ['152', '153'], 'value': '=='}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'source_type'}; {'id': '153', 'type': 'string', 'children': [], 'value': "'kubernetes'"}; {'id': '154', 'type': 'block', 'children': ['155', '164', '176', '185', '197']}; {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'assignment', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '158', 'type': 'call', 'children': ['159', '162']}; {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '162', 'type': 'argument_list', 'children': ['163']}; {'id': '163', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '164', 'type': 'if_statement', 'children': ['165', '168']}; {'id': '165', 'type': 'comparison_operator', 'children': ['166', '167'], 'value': 'in'}; {'id': '166', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'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': 'kwargs'}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '174', 'type': 'argument_list', 'children': ['175']}; {'id': '175', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}; {'id': '177', 'type': 'assignment', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'client'}; {'id': '179', 'type': 'call', 'children': ['180', '183']}; {'id': '180', 'type': 'attribute', 'children': ['181', '182']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '183', 'type': 'argument_list', 'children': ['184']}; {'id': '184', 'type': 'string', 'children': [], 'value': "'client'"}; {'id': '185', 'type': 'if_statement', 'children': ['186', '189']}; {'id': '186', 'type': 'comparison_operator', 'children': ['187', '188'], 'value': 'in'}; {'id': '187', 'type': 'string', 'children': [], 'value': "'client'"}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '189', 'type': 'block', 'children': ['190']}; {'id': '190', 'type': 'expression_statement', 'children': ['191']}; {'id': '191', 'type': 'call', 'children': ['192', '195']}; {'id': '192', 'type': 'attribute', 'children': ['193', '194']}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '195', 'type': 'argument_list', 'children': ['196']}; {'id': '196', 'type': 'string', 'children': [], 'value': "'client'"}; {'id': '197', 'type': 'return_statement', 'children': ['198']}; {'id': '198', 'type': 'call', 'children': ['199', '200']}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'KubernetesConfigSource'}; {'id': '200', 'type': 'argument_list', 'children': ['201', '202', '203', '204']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'client'}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '204', 'type': 'dictionary_splat', 'children': ['205']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '206', 'type': 'else_clause', 'children': ['207']}; {'id': '207', 'type': 'block', 'children': ['208']}; {'id': '208', 'type': 'raise_statement', 'children': ['209']}; {'id': '209', 'type': 'call', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'NotImplementedError'}; {'id': '211', 'type': 'argument_list', 'children': ['212']}; {'id': '212', 'type': 'binary_operator', 'children': ['213', '214'], 'value': '%'}; {'id': '213', 'type': 'string', 'children': [], 'value': "'No implementation for source type %s'"}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'source_type'}
|
def get_source(label, source_type, **kwargs):
if source_type not in yapconf.ALL_SUPPORTED_SOURCES:
raise YapconfSourceError(
'Invalid source type %s. Supported types are %s.' %
(source_type, yapconf.ALL_SUPPORTED_SOURCES)
)
if source_type not in yapconf.SUPPORTED_SOURCES:
raise YapconfSourceError(
'Unsupported source type "%s". If you want to use this type, you '
'will need to install the correct client for it (try `pip install '
'yapconf[%s]. Currently supported types are %s. All supported '
'types are %s' %
(source_type, source_type, yapconf.SUPPORTED_SOURCES,
yapconf.ALL_SUPPORTED_SOURCES)
)
if source_type == 'dict':
return DictConfigSource(label, data=kwargs.get('data'))
elif source_type == 'json':
return JsonConfigSource(label, **kwargs)
elif source_type == 'yaml':
filename = kwargs.get('filename')
if 'filename' in kwargs:
kwargs.pop('filename')
return YamlConfigSource(label, filename, **kwargs)
elif source_type == 'environment':
return EnvironmentConfigSource(label)
elif source_type == 'etcd':
return EtcdConfigSource(
label, kwargs.get('client'), kwargs.get('key', '/')
)
elif source_type == 'kubernetes':
name = kwargs.get('name')
if 'name' in kwargs:
kwargs.pop('name')
client = kwargs.get('client')
if 'client' in kwargs:
kwargs.pop('client')
return KubernetesConfigSource(label, client, name, **kwargs)
else:
raise NotImplementedError(
'No implementation for source type %s' % source_type
)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '37', '39']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_project_observable'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '9', '13', '24', '35']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'input_key'}; {'id': '7', 'type': 'type', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '9', 'type': 'typed_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'input_observable'}; {'id': '11', 'type': 'type', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'Any'}; {'id': '13', 'type': 'typed_default_parameter', 'children': ['14', '15', '23']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'get_hist_args'}; {'id': '15', 'type': 'type', 'children': ['16']}; {'id': '16', 'type': 'generic_type', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'Dict'}; {'id': '18', 'type': 'type_parameter', 'children': ['19', '21']}; {'id': '19', 'type': 'type', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '21', 'type': 'type', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'Any'}; {'id': '23', 'type': 'None', 'children': []}; {'id': '24', 'type': 'typed_default_parameter', 'children': ['25', '26', '34']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'projection_name_args'}; {'id': '26', 'type': 'type', 'children': ['27']}; {'id': '27', 'type': 'generic_type', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'Dict'}; {'id': '29', 'type': 'type_parameter', 'children': ['30', '32']}; {'id': '30', 'type': 'type', 'children': ['31']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '32', 'type': 'type', 'children': ['33']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'Any'}; {'id': '34', 'type': 'None', 'children': []}; {'id': '35', 'type': 'dictionary_splat_pattern', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '37', 'type': 'type', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'Hist'}; {'id': '39', 'type': 'block', 'children': ['40', '54', '68', '78', '88', '97', '104', '120', '130', '137', '157', '173', '199', '210', '214', '276', '288', '294', '309', '316', '323']}; {'id': '40', 'type': 'if_statement', 'children': ['41', '44']}; {'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': 'is'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'get_hist_args'}; {'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': 'get_hist_args'}; {'id': '48', 'type': 'call', 'children': ['49', '52']}; {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'deepcopy'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '54', 'type': 'if_statement', 'children': ['55', '58']}; {'id': '55', 'type': 'comparison_operator', 'children': ['56', '57'], 'value': 'is'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'projection_name_args'}; {'id': '57', 'type': 'None', 'children': []}; {'id': '58', 'type': 'block', 'children': ['59']}; {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'projection_name_args'}; {'id': '62', 'type': 'call', 'children': ['63', '66']}; {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'deepcopy'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}; {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'get_hist_args'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'dictionary', 'children': ['75']}; {'id': '75', 'type': 'pair', 'children': ['76', '77']}; {'id': '76', 'type': 'string', 'children': [], 'value': '"observable"'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'input_observable'}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}; {'id': '79', 'type': 'assignment', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'hist'}; {'id': '81', 'type': 'call', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'get_hist'}; {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'dictionary_splat', 'children': ['87']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'get_hist_args'}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}; {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'projection_name_args'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'projection_information'}; {'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': 'projection_name_args'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'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': 'projection_name_args'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'dictionary', 'children': ['111', '114', '117']}; {'id': '111', 'type': 'pair', 'children': ['112', '113']}; {'id': '112', 'type': 'string', 'children': [], 'value': '"input_key"'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'input_key'}; {'id': '114', 'type': 'pair', 'children': ['115', '116']}; {'id': '115', 'type': 'string', 'children': [], 'value': '"input_observable"'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'input_observable'}; {'id': '117', 'type': 'pair', 'children': ['118', '119']}; {'id': '118', 'type': 'string', 'children': [], 'value': '"input_hist"'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'hist'}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}; {'id': '121', 'type': 'assignment', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'projection_name'}; {'id': '123', 'type': 'call', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'projection_name'}; {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'dictionary_splat', 'children': ['129']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'projection_name_args'}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}; {'id': '131', 'type': 'call', 'children': ['132', '135']}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '135', 'type': 'argument_list', 'children': ['136']}; {'id': '136', 'type': 'string', 'children': [], 'value': 'f"hist: {hist}"'}; {'id': '137', 'type': 'for_statement', 'children': ['138', '139', '142']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'additional_axis_cuts'}; {'id': '142', 'type': 'block', 'children': ['143', '150']}; {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'call', 'children': ['145', '148']}; {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '148', 'type': 'argument_list', 'children': ['149']}; {'id': '149', 'type': 'string', 'children': [], 'value': 'f"Apply additional axis hist range: {axis.name}"'}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}; {'id': '151', 'type': 'call', 'children': ['152', '155']}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'apply_range_set'}; {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'hist'}; {'id': '157', 'type': 'if_statement', 'children': ['158', '163']}; {'id': '158', 'type': 'comparison_operator', 'children': ['159', '162'], 'value': '=='}; {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'projection_dependent_cut_axes'}; {'id': '162', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '163', 'type': 'block', 'children': ['164']}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}; {'id': '165', 'type': 'call', 'children': ['166', '171']}; {'id': '166', 'type': 'attribute', 'children': ['167', '170']}; {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'projection_dependent_cut_axes'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '171', 'type': 'argument_list', 'children': ['172']}; {'id': '172', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '173', 'type': 'expression_statement', 'children': ['174']}; {'id': '174', 'type': 'assignment', 'children': ['175', '176']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'duplicated_axes'}; {'id': '176', 'type': 'list_comprehension', 'children': ['177', '178', '183', '188', '191']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'PDCA'}; {'id': '178', 'type': 'for_in_clause', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'PA'}; {'id': '180', 'type': 'attribute', 'children': ['181', '182']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'projection_axes'}; {'id': '183', 'type': 'for_in_clause', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'PDCA_group'}; {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'projection_dependent_cut_axes'}; {'id': '188', 'type': 'for_in_clause', 'children': ['189', '190']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'PDCA'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'PDCA_group'}; {'id': '191', 'type': 'if_clause', 'children': ['192']}; {'id': '192', 'type': 'comparison_operator', 'children': ['193', '196'], 'value': '=='}; {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'PDCA'}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'axis_type'}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'PA'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'axis_type'}; {'id': '199', 'type': 'if_statement', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'duplicated_axes'}; {'id': '201', 'type': 'block', 'children': ['202']}; {'id': '202', 'type': 'raise_statement', 'children': ['203']}; {'id': '203', 'type': 'call', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '205', 'type': 'argument_list', 'children': ['206']}; {'id': '206', 'type': 'concatenated_string', 'children': ['207', '208', '209']}; {'id': '207', 'type': 'string', 'children': [], 'value': 'f"Axis {duplicated_axes} is in the projection axes and the projection dependent cut axes."'}; {'id': '208', 'type': 'string', 'children': [], 'value': '" This configuration is not allowed, as the range in the PDCA will be overwritten by the projection axes!"'}; {'id': '209', 'type': 'string', 'children': [], 'value': '" Please revise your configuration."'}; {'id': '210', 'type': 'expression_statement', 'children': ['211']}; {'id': '211', 'type': 'assignment', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'hists'}; {'id': '213', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '214', 'type': 'for_statement', 'children': ['215', '218', '224']}; {'id': '215', 'type': 'pattern_list', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'axes'}; {'id': '218', 'type': 'call', 'children': ['219', '220']}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '220', 'type': 'argument_list', 'children': ['221']}; {'id': '221', 'type': 'attribute', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'projection_dependent_cut_axes'}; {'id': '224', 'type': 'block', 'children': ['225', '243', '252', '259', '266']}; {'id': '225', 'type': 'for_statement', 'children': ['226', '227', '228']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'axes'}; {'id': '228', 'type': 'block', 'children': ['229', '236']}; {'id': '229', 'type': 'expression_statement', 'children': ['230']}; {'id': '230', 'type': 'call', 'children': ['231', '234']}; {'id': '231', 'type': 'attribute', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '234', 'type': 'argument_list', 'children': ['235']}; {'id': '235', 'type': 'string', 'children': [], 'value': 'f"Apply projection dependent hist range: {axis.name}"'}; {'id': '236', 'type': 'expression_statement', 'children': ['237']}; {'id': '237', 'type': 'call', 'children': ['238', '241']}; {'id': '238', 'type': 'attribute', 'children': ['239', '240']}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'apply_range_set'}; {'id': '241', 'type': 'argument_list', 'children': ['242']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'hist'}; {'id': '243', 'type': 'expression_statement', 'children': ['244']}; {'id': '244', 'type': 'assignment', 'children': ['245', '246']}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'projected_hist'}; {'id': '246', 'type': 'call', 'children': ['247', '250']}; {'id': '247', 'type': 'attribute', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'call_projection_function'}; {'id': '250', 'type': 'argument_list', 'children': ['251']}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'hist'}; {'id': '252', 'type': 'expression_statement', 'children': ['253']}; {'id': '253', 'type': 'call', 'children': ['254', '257']}; {'id': '254', 'type': 'attribute', 'children': ['255', '256']}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'projected_hist'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'SetName'}; {'id': '257', 'type': 'argument_list', 'children': ['258']}; {'id': '258', 'type': 'string', 'children': [], 'value': 'f"{projection_name}_{i}"'}; {'id': '259', 'type': 'expression_statement', 'children': ['260']}; {'id': '260', 'type': 'call', 'children': ['261', '264']}; {'id': '261', 'type': 'attribute', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'hists'}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '264', 'type': 'argument_list', 'children': ['265']}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'projected_hist'}; {'id': '266', 'type': 'expression_statement', 'children': ['267']}; {'id': '267', 'type': 'call', 'children': ['268', '271']}; {'id': '268', 'type': 'attribute', 'children': ['269', '270']}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'cleanup_cuts'}; {'id': '271', 'type': 'argument_list', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'hist'}; {'id': '273', 'type': 'keyword_argument', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'cut_axes'}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'axes'}; {'id': '276', 'type': 'expression_statement', 'children': ['277']}; {'id': '277', 'type': 'call', 'children': ['278', '281']}; {'id': '278', 'type': 'attribute', 'children': ['279', '280']}; {'id': '279', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'cleanup_cuts'}; {'id': '281', 'type': 'argument_list', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'hist'}; {'id': '283', 'type': 'keyword_argument', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'cut_axes'}; {'id': '285', 'type': 'attribute', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '287', 'type': 'identifier', 'children': [], 'value': 'additional_axis_cuts'}; {'id': '288', 'type': 'expression_statement', 'children': ['289']}; {'id': '289', 'type': 'assignment', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'output_hist'}; {'id': '291', 'type': 'subscript', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'hists'}; {'id': '293', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '294', 'type': 'for_statement', 'children': ['295', '296', '301']}; {'id': '295', 'type': 'identifier', 'children': [], 'value': 'temp_hist'}; {'id': '296', 'type': 'subscript', 'children': ['297', '298']}; {'id': '297', 'type': 'identifier', 'children': [], 'value': 'hists'}; {'id': '298', 'type': 'slice', 'children': ['299', '300']}; {'id': '299', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '300', 'type': 'colon', 'children': []}; {'id': '301', 'type': 'block', 'children': ['302']}; {'id': '302', 'type': 'expression_statement', 'children': ['303']}; {'id': '303', 'type': 'call', 'children': ['304', '307']}; {'id': '304', 'type': 'attribute', 'children': ['305', '306']}; {'id': '305', 'type': 'identifier', 'children': [], 'value': 'output_hist'}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'Add'}; {'id': '307', 'type': 'argument_list', 'children': ['308']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'temp_hist'}; {'id': '309', 'type': 'expression_statement', 'children': ['310']}; {'id': '310', 'type': 'call', 'children': ['311', '314']}; {'id': '311', 'type': 'attribute', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'output_hist'}; {'id': '313', 'type': 'identifier', 'children': [], 'value': 'SetName'}; {'id': '314', 'type': 'argument_list', 'children': ['315']}; {'id': '315', 'type': 'identifier', 'children': [], 'value': 'projection_name'}; {'id': '316', 'type': 'expression_statement', 'children': ['317']}; {'id': '317', 'type': 'call', 'children': ['318', '321']}; {'id': '318', 'type': 'attribute', 'children': ['319', '320']}; {'id': '319', 'type': 'identifier', 'children': [], 'value': 'output_hist'}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'SetDirectory'}; {'id': '321', 'type': 'argument_list', 'children': ['322']}; {'id': '322', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '323', 'type': 'return_statement', 'children': ['324']}; {'id': '324', 'type': 'expression_list', 'children': ['325', '326', '327']}; {'id': '325', 'type': 'identifier', 'children': [], 'value': 'output_hist'}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'projection_name'}; {'id': '327', 'type': 'identifier', 'children': [], 'value': 'projection_name_args'}
|
def _project_observable(self, input_key: str,
input_observable: Any,
get_hist_args: Dict[str, Any] = None,
projection_name_args: Dict[str, Any] = None,
**kwargs) -> Hist:
if get_hist_args is None:
get_hist_args = copy.deepcopy(kwargs)
if projection_name_args is None:
projection_name_args = copy.deepcopy(kwargs)
get_hist_args.update({"observable": input_observable})
hist = self.get_hist(**get_hist_args)
projection_name_args.update(self.projection_information)
projection_name_args.update(kwargs)
projection_name_args.update({
"input_key": input_key,
"input_observable": input_observable,
"input_hist": hist
})
projection_name = self.projection_name(**projection_name_args)
logger.debug(f"hist: {hist}")
for axis in self.additional_axis_cuts:
logger.debug(f"Apply additional axis hist range: {axis.name}")
axis.apply_range_set(hist)
if self.projection_dependent_cut_axes == []:
self.projection_dependent_cut_axes.append([])
duplicated_axes = [
PDCA
for PA in self.projection_axes
for PDCA_group in self.projection_dependent_cut_axes
for PDCA in PDCA_group
if PDCA.axis_type == PA.axis_type
]
if duplicated_axes:
raise ValueError(
f"Axis {duplicated_axes} is in the projection axes and the projection dependent cut axes."
" This configuration is not allowed, as the range in the PDCA will be overwritten by the projection axes!"
" Please revise your configuration."
)
hists = []
for i, axes in enumerate(self.projection_dependent_cut_axes):
for axis in axes:
logger.debug(f"Apply projection dependent hist range: {axis.name}")
axis.apply_range_set(hist)
projected_hist = self.call_projection_function(hist)
projected_hist.SetName(f"{projection_name}_{i}")
hists.append(projected_hist)
self.cleanup_cuts(hist, cut_axes = axes)
self.cleanup_cuts(hist, cut_axes = self.additional_axis_cuts)
output_hist = hists[0]
for temp_hist in hists[1:]:
output_hist.Add(temp_hist)
output_hist.SetName(projection_name)
output_hist.SetDirectory(0)
return output_hist, projection_name, projection_name_args
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'getrruleset'}; {'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': 'addRDate'}; {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '13', '469']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'rruleset'}; {'id': '12', 'type': 'None', 'children': []}; {'id': '13', 'type': 'for_statement', 'children': ['14', '15', '16']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'DATESANDRULES'}; {'id': '16', 'type': 'block', 'children': ['17', '21']}; {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'addfunc'}; {'id': '20', 'type': 'None', 'children': []}; {'id': '21', 'type': 'for_statement', 'children': ['22', '23', '32']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'line'}; {'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': 'self'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'contents'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '29', 'type': 'argument_list', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '31', 'type': 'tuple', 'children': []}; {'id': '32', 'type': 'block', 'children': ['33', '46', '59']}; {'id': '33', 'type': 'if_statement', 'children': ['34', '37']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': 'is'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'rruleset'}; {'id': '36', 'type': 'None', 'children': []}; {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}; {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'rruleset'}; {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'rrule'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'rruleset'}; {'id': '45', 'type': 'argument_list', 'children': []}; {'id': '46', 'type': 'if_statement', 'children': ['47', '50']}; {'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': 'is'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'addfunc'}; {'id': '49', 'type': 'None', 'children': []}; {'id': '50', 'type': 'block', 'children': ['51']}; {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'addfunc'}; {'id': '54', 'type': 'call', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '56', 'type': 'argument_list', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'rruleset'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '59', 'type': 'if_statement', 'children': ['60', '63', '127']}; {'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': 'in'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'DATENAMES'}; {'id': '63', 'type': 'block', 'children': ['64']}; {'id': '64', 'type': 'if_statement', 'children': ['65', '77', '86', '124']}; {'id': '65', 'type': 'comparison_operator', 'children': ['66', '74'], 'value': '=='}; {'id': '66', 'type': 'call', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}; {'id': '69', 'type': 'subscript', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '73', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '77', 'type': 'block', 'children': ['78']}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}; {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'map'}; {'id': '81', 'type': 'argument_list', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'addfunc'}; {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '86', 'type': 'elif_clause', 'children': ['87', '99']}; {'id': '87', 'type': 'comparison_operator', 'children': ['88', '96'], 'value': '=='}; {'id': '88', 'type': 'call', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}; {'id': '91', 'type': 'subscript', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '95', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '99', 'type': 'block', 'children': ['100']}; {'id': '100', 'type': 'for_statement', 'children': ['101', '102', '105']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'dt'}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '105', 'type': 'block', 'children': ['106']}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}; {'id': '107', 'type': 'call', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'addfunc'}; {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'call', 'children': ['111', '114']}; {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '114', 'type': 'argument_list', 'children': ['115', '118', '121']}; {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'dt'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'year'}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'dt'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'month'}; {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'dt'}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'day'}; {'id': '124', 'type': 'else_clause', 'children': ['125']}; {'id': '125', 'type': 'block', 'children': ['126']}; {'id': '126', 'type': 'pass_statement', 'children': []}; {'id': '127', 'type': 'elif_clause', 'children': ['128', '131']}; {'id': '128', 'type': 'comparison_operator', 'children': ['129', '130'], 'value': 'in'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'RULENAMES'}; {'id': '131', 'type': 'block', 'children': ['132', '185', '200', '212', '218', '363', '368']}; {'id': '132', 'type': 'try_statement', 'children': ['133', '142']}; {'id': '133', 'type': 'block', 'children': ['134']}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}; {'id': '135', 'type': 'assignment', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'dtstart'}; {'id': '137', 'type': 'attribute', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'dtstart'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '142', 'type': 'except_clause', 'children': ['143', '146']}; {'id': '143', 'type': 'tuple', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '146', 'type': 'block', 'children': ['147']}; {'id': '147', 'type': 'try_statement', 'children': ['148', '173']}; {'id': '148', 'type': 'block', 'children': ['149']}; {'id': '149', 'type': 'if_statement', 'children': ['150', '155', '164']}; {'id': '150', 'type': 'comparison_operator', 'children': ['151', '154'], 'value': '=='}; {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '154', 'type': 'string', 'children': [], 'value': '"VTODO"'}; {'id': '155', 'type': 'block', 'children': ['156']}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}; {'id': '157', 'type': 'assignment', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'dtstart'}; {'id': '159', 'type': 'attribute', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'due'}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '164', 'type': 'else_clause', 'children': ['165']}; {'id': '165', 'type': 'block', 'children': ['166', '171']}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}; {'id': '167', 'type': 'call', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '169', 'type': 'argument_list', 'children': ['170']}; {'id': '170', 'type': 'string', 'children': [], 'value': "'failed to get dtstart with VTODO'"}; {'id': '171', 'type': 'return_statement', 'children': ['172']}; {'id': '172', 'type': 'None', 'children': []}; {'id': '173', 'type': 'except_clause', 'children': ['174', '177']}; {'id': '174', 'type': 'tuple', 'children': ['175', '176']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '177', 'type': 'block', 'children': ['178', '183']}; {'id': '178', 'type': 'expression_statement', 'children': ['179']}; {'id': '179', 'type': 'call', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '181', 'type': 'argument_list', 'children': ['182']}; {'id': '182', 'type': 'string', 'children': [], 'value': "'failed to find DUE at all.'"}; {'id': '183', 'type': 'return_statement', 'children': ['184']}; {'id': '184', 'type': 'None', 'children': []}; {'id': '185', 'type': 'expression_statement', 'children': ['186']}; {'id': '186', 'type': 'assignment', 'children': ['187', '188']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '188', 'type': 'call', 'children': ['189', '197']}; {'id': '189', 'type': 'attribute', 'children': ['190', '196']}; {'id': '190', 'type': 'call', 'children': ['191', '192']}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'str_'}; {'id': '192', 'type': 'argument_list', 'children': ['193']}; {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '197', 'type': 'argument_list', 'children': ['198', '199']}; {'id': '198', 'type': 'string', 'children': [], 'value': "'\\\\'"}; {'id': '199', 'type': 'string', 'children': [], 'value': "''"}; {'id': '200', 'type': 'expression_statement', 'children': ['201']}; {'id': '201', 'type': 'assignment', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'rule'}; {'id': '203', 'type': 'call', 'children': ['204', '207']}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'rrule'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'rrulestr'}; {'id': '207', 'type': 'argument_list', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '209', 'type': 'keyword_argument', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'dtstart'}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'dtstart'}; {'id': '212', 'type': 'expression_statement', 'children': ['213']}; {'id': '213', 'type': 'assignment', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'until'}; {'id': '215', 'type': 'attribute', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'rule'}; {'id': '217', 'type': 'identifier', 'children': [], 'value': '_until'}; {'id': '218', 'type': 'if_statement', 'children': ['219', '240']}; {'id': '219', 'type': 'boolean_operator', 'children': ['220', '231', '232'], 'value': 'and'}; {'id': '220', 'type': 'boolean_operator', 'children': ['221', '224'], 'value': 'and'}; {'id': '221', 'type': 'comparison_operator', 'children': ['222', '223'], 'value': 'is'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'until'}; {'id': '223', 'type': 'None', 'children': []}; {'id': '224', 'type': 'call', 'children': ['225', '226']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '226', 'type': 'argument_list', 'children': ['227', '228']}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'dtstart'}; {'id': '228', 'type': 'attribute', 'children': ['229', '230']}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '231', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '232', 'type': '()', 'children': ['233']}; {'id': '233', 'type': 'comparison_operator', 'children': ['234', '237'], 'value': '!='}; {'id': '234', 'type': 'attribute', 'children': ['235', '236']}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'until'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'tzinfo'}; {'id': '237', 'type': 'attribute', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'dtstart'}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'tzinfo'}; {'id': '240', 'type': 'block', 'children': ['241', '267', '301', '321', '339', '357']}; {'id': '241', 'type': 'expression_statement', 'children': ['242']}; {'id': '242', 'type': 'assignment', 'children': ['243', '244']}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'vals'}; {'id': '244', 'type': 'call', 'children': ['245', '246']}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '246', 'type': 'generator_expression', 'children': ['247', '253']}; {'id': '247', 'type': 'call', 'children': ['248', '251']}; {'id': '248', 'type': 'attribute', 'children': ['249', '250']}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'pair'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '251', 'type': 'argument_list', 'children': ['252']}; {'id': '252', 'type': 'string', 'children': [], 'value': "'='"}; {'id': '253', 'type': 'for_in_clause', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'pair'}; {'id': '255', 'type': 'call', 'children': ['256', '265']}; {'id': '256', 'type': 'attribute', 'children': ['257', '264']}; {'id': '257', 'type': 'call', 'children': ['258', '263']}; {'id': '258', 'type': 'attribute', 'children': ['259', '262']}; {'id': '259', 'type': 'attribute', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'upper'}; {'id': '263', 'type': 'argument_list', 'children': []}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '265', 'type': 'argument_list', 'children': ['266']}; {'id': '266', 'type': 'string', 'children': [], 'value': "';'"}; {'id': '267', 'type': 'if_statement', 'children': ['268', '280']}; {'id': '268', 'type': 'comparison_operator', 'children': ['269', '279'], 'value': '=='}; {'id': '269', 'type': 'call', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '271', 'type': 'argument_list', 'children': ['272']}; {'id': '272', 'type': 'call', 'children': ['273', '276']}; {'id': '273', 'type': 'attribute', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'vals'}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '276', 'type': 'argument_list', 'children': ['277', '278']}; {'id': '277', 'type': 'string', 'children': [], 'value': "'UNTIL'"}; {'id': '278', 'type': 'string', 'children': [], 'value': "''"}; {'id': '279', 'type': 'integer', 'children': [], 'value': '8'}; {'id': '280', 'type': 'block', 'children': ['281']}; {'id': '281', 'type': 'expression_statement', 'children': ['282']}; {'id': '282', 'type': 'assignment', 'children': ['283', '284']}; {'id': '283', 'type': 'identifier', 'children': [], 'value': 'until'}; {'id': '284', 'type': 'call', 'children': ['285', '290']}; {'id': '285', 'type': 'attribute', 'children': ['286', '289']}; {'id': '286', 'type': 'attribute', 'children': ['287', '288']}; {'id': '287', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'combine'}; {'id': '290', 'type': 'argument_list', 'children': ['291', '296']}; {'id': '291', 'type': 'call', 'children': ['292', '295']}; {'id': '292', 'type': 'attribute', 'children': ['293', '294']}; {'id': '293', 'type': 'identifier', 'children': [], 'value': 'until'}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '295', 'type': 'argument_list', 'children': []}; {'id': '296', 'type': 'call', 'children': ['297', '300']}; {'id': '297', 'type': 'attribute', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'dtstart'}; {'id': '299', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '300', 'type': 'argument_list', 'children': []}; {'id': '301', 'type': 'if_statement', 'children': ['302', '307']}; {'id': '302', 'type': 'comparison_operator', 'children': ['303', '306'], 'value': 'is'}; {'id': '303', 'type': 'attribute', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'until'}; {'id': '305', 'type': 'identifier', 'children': [], 'value': 'tzinfo'}; {'id': '306', 'type': 'None', 'children': []}; {'id': '307', 'type': 'block', 'children': ['308']}; {'id': '308', 'type': 'expression_statement', 'children': ['309']}; {'id': '309', 'type': 'assignment', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'until'}; {'id': '311', 'type': 'call', 'children': ['312', '315']}; {'id': '312', 'type': 'attribute', 'children': ['313', '314']}; {'id': '313', 'type': 'identifier', 'children': [], 'value': 'until'}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '315', 'type': 'argument_list', 'children': ['316']}; {'id': '316', 'type': 'keyword_argument', 'children': ['317', '318']}; {'id': '317', 'type': 'identifier', 'children': [], 'value': 'tzinfo'}; {'id': '318', 'type': 'attribute', 'children': ['319', '320']}; {'id': '319', 'type': 'identifier', 'children': [], 'value': 'dtstart'}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'tzinfo'}; {'id': '321', 'type': 'if_statement', 'children': ['322', '327']}; {'id': '322', 'type': 'comparison_operator', 'children': ['323', '326'], 'value': 'is'}; {'id': '323', 'type': 'attribute', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'dtstart'}; {'id': '325', 'type': 'identifier', 'children': [], 'value': 'tzinfo'}; {'id': '326', 'type': 'None', 'children': []}; {'id': '327', 'type': 'block', 'children': ['328']}; {'id': '328', 'type': 'expression_statement', 'children': ['329']}; {'id': '329', 'type': 'assignment', 'children': ['330', '331']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'until'}; {'id': '331', 'type': 'call', 'children': ['332', '335']}; {'id': '332', 'type': 'attribute', 'children': ['333', '334']}; {'id': '333', 'type': 'identifier', 'children': [], 'value': 'until'}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'astimezone'}; {'id': '335', 'type': 'argument_list', 'children': ['336']}; {'id': '336', 'type': 'attribute', 'children': ['337', '338']}; {'id': '337', 'type': 'identifier', 'children': [], 'value': 'dtstart'}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'tzinfo'}; {'id': '339', 'type': 'if_statement', 'children': ['340', '345']}; {'id': '340', 'type': 'comparison_operator', 'children': ['341', '344'], 'value': 'is'}; {'id': '341', 'type': 'attribute', 'children': ['342', '343']}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'dtstart'}; {'id': '343', 'type': 'identifier', 'children': [], 'value': 'tzinfo'}; {'id': '344', 'type': 'None', 'children': []}; {'id': '345', 'type': 'block', 'children': ['346']}; {'id': '346', 'type': 'expression_statement', 'children': ['347']}; {'id': '347', 'type': 'assignment', 'children': ['348', '349']}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'until'}; {'id': '349', 'type': 'call', 'children': ['350', '353']}; {'id': '350', 'type': 'attribute', 'children': ['351', '352']}; {'id': '351', 'type': 'identifier', 'children': [], 'value': 'until'}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '353', 'type': 'argument_list', 'children': ['354']}; {'id': '354', 'type': 'keyword_argument', 'children': ['355', '356']}; {'id': '355', 'type': 'identifier', 'children': [], 'value': 'tzinfo'}; {'id': '356', 'type': 'None', 'children': []}; {'id': '357', 'type': 'expression_statement', 'children': ['358']}; {'id': '358', 'type': 'assignment', 'children': ['359', '362']}; {'id': '359', 'type': 'attribute', 'children': ['360', '361']}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'rule'}; {'id': '361', 'type': 'identifier', 'children': [], 'value': '_until'}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'until'}; {'id': '363', 'type': 'expression_statement', 'children': ['364']}; {'id': '364', 'type': 'call', 'children': ['365', '366']}; {'id': '365', 'type': 'identifier', 'children': [], 'value': 'addfunc'}; {'id': '366', 'type': 'argument_list', 'children': ['367']}; {'id': '367', 'type': 'identifier', 'children': [], 'value': 'rule'}; {'id': '368', 'type': 'if_statement', 'children': ['369', '374']}; {'id': '369', 'type': 'boolean_operator', 'children': ['370', '373'], 'value': 'and'}; {'id': '370', 'type': 'comparison_operator', 'children': ['371', '372'], 'value': '=='}; {'id': '371', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '372', 'type': 'string', 'children': [], 'value': "'rrule'"}; {'id': '373', 'type': 'identifier', 'children': [], 'value': 'addRDate'}; {'id': '374', 'type': 'block', 'children': ['375', '444']}; {'id': '375', 'type': 'try_statement', 'children': ['376', '437']}; {'id': '376', 'type': 'block', 'children': ['377', '408']}; {'id': '377', 'type': 'if_statement', 'children': ['378', '386', '402']}; {'id': '378', 'type': 'not_operator', 'children': ['379']}; {'id': '379', 'type': 'call', 'children': ['380', '381']}; {'id': '380', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '381', 'type': 'argument_list', 'children': ['382', '383']}; {'id': '382', 'type': 'identifier', 'children': [], 'value': 'dtstart'}; {'id': '383', 'type': 'attribute', 'children': ['384', '385']}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '385', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '386', 'type': 'block', 'children': ['387']}; {'id': '387', 'type': 'expression_statement', 'children': ['388']}; {'id': '388', 'type': 'assignment', 'children': ['389', '390']}; {'id': '389', 'type': 'identifier', 'children': [], 'value': 'adddtstart'}; {'id': '390', 'type': 'call', 'children': ['391', '396']}; {'id': '391', 'type': 'attribute', 'children': ['392', '395']}; {'id': '392', 'type': 'attribute', 'children': ['393', '394']}; {'id': '393', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '394', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '395', 'type': 'identifier', 'children': [], 'value': 'fromordinal'}; {'id': '396', 'type': 'argument_list', 'children': ['397']}; {'id': '397', 'type': 'call', 'children': ['398', '401']}; {'id': '398', 'type': 'attribute', 'children': ['399', '400']}; {'id': '399', 'type': 'identifier', 'children': [], 'value': 'dtstart'}; {'id': '400', 'type': 'identifier', 'children': [], 'value': 'toordinal'}; {'id': '401', 'type': 'argument_list', 'children': []}; {'id': '402', 'type': 'else_clause', 'children': ['403']}; {'id': '403', 'type': 'block', 'children': ['404']}; {'id': '404', 'type': 'expression_statement', 'children': ['405']}; {'id': '405', 'type': 'assignment', 'children': ['406', '407']}; {'id': '406', 'type': 'identifier', 'children': [], 'value': 'adddtstart'}; {'id': '407', 'type': 'identifier', 'children': [], 'value': 'dtstart'}; {'id': '408', 'type': 'if_statement', 'children': ['409', '419', '431']}; {'id': '409', 'type': 'comparison_operator', 'children': ['410', '418'], 'value': '!='}; {'id': '410', 'type': 'subscript', 'children': ['411', '417']}; {'id': '411', 'type': 'subscript', 'children': ['412', '415']}; {'id': '412', 'type': 'attribute', 'children': ['413', '414']}; {'id': '413', 'type': 'identifier', 'children': [], 'value': 'rruleset'}; {'id': '414', 'type': 'identifier', 'children': [], 'value': '_rrule'}; {'id': '415', 'type': 'unary_operator', 'children': ['416'], 'value': '-'}; {'id': '416', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '417', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '418', 'type': 'identifier', 'children': [], 'value': 'adddtstart'}; {'id': '419', 'type': 'block', 'children': ['420', '427']}; {'id': '420', 'type': 'expression_statement', 'children': ['421']}; {'id': '421', 'type': 'call', 'children': ['422', '425']}; {'id': '422', 'type': 'attribute', 'children': ['423', '424']}; {'id': '423', 'type': 'identifier', 'children': [], 'value': 'rruleset'}; {'id': '424', 'type': 'identifier', 'children': [], 'value': 'rdate'}; {'id': '425', 'type': 'argument_list', 'children': ['426']}; {'id': '426', 'type': 'identifier', 'children': [], 'value': 'adddtstart'}; {'id': '427', 'type': 'expression_statement', 'children': ['428']}; {'id': '428', 'type': 'assignment', 'children': ['429', '430']}; {'id': '429', 'type': 'identifier', 'children': [], 'value': 'added'}; {'id': '430', 'type': 'True', 'children': []}; {'id': '431', 'type': 'else_clause', 'children': ['432']}; {'id': '432', 'type': 'block', 'children': ['433']}; {'id': '433', 'type': 'expression_statement', 'children': ['434']}; {'id': '434', 'type': 'assignment', 'children': ['435', '436']}; {'id': '435', 'type': 'identifier', 'children': [], 'value': 'added'}; {'id': '436', 'type': 'False', 'children': []}; {'id': '437', 'type': 'except_clause', 'children': ['438', '439']}; {'id': '438', 'type': 'identifier', 'children': [], 'value': 'IndexError'}; {'id': '439', 'type': 'block', 'children': ['440']}; {'id': '440', 'type': 'expression_statement', 'children': ['441']}; {'id': '441', 'type': 'assignment', 'children': ['442', '443']}; {'id': '442', 'type': 'identifier', 'children': [], 'value': 'added'}; {'id': '443', 'type': 'False', 'children': []}; {'id': '444', 'type': 'if_statement', 'children': ['445', '457']}; {'id': '445', 'type': 'boolean_operator', 'children': ['446', '447'], 'value': 'and'}; {'id': '446', 'type': 'identifier', 'children': [], 'value': 'added'}; {'id': '447', 'type': 'comparison_operator', 'children': ['448', '456'], 'value': 'is'}; {'id': '448', 'type': 'attribute', 'children': ['449', '455']}; {'id': '449', 'type': 'subscript', 'children': ['450', '453']}; {'id': '450', 'type': 'attribute', 'children': ['451', '452']}; {'id': '451', 'type': 'identifier', 'children': [], 'value': 'rruleset'}; {'id': '452', 'type': 'identifier', 'children': [], 'value': '_rrule'}; {'id': '453', 'type': 'unary_operator', 'children': ['454'], 'value': '-'}; {'id': '454', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '455', 'type': 'identifier', 'children': [], 'value': '_count'}; {'id': '456', 'type': 'None', 'children': []}; {'id': '457', 'type': 'block', 'children': ['458']}; {'id': '458', 'type': 'expression_statement', 'children': ['459']}; {'id': '459', 'type': 'augmented_assignment', 'children': ['460', '468'], 'value': '-='}; {'id': '460', 'type': 'attribute', 'children': ['461', '467']}; {'id': '461', 'type': 'subscript', 'children': ['462', '465']}; {'id': '462', 'type': 'attribute', 'children': ['463', '464']}; {'id': '463', 'type': 'identifier', 'children': [], 'value': 'rruleset'}; {'id': '464', 'type': 'identifier', 'children': [], 'value': '_rrule'}; {'id': '465', 'type': 'unary_operator', 'children': ['466'], 'value': '-'}; {'id': '466', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '467', 'type': 'identifier', 'children': [], 'value': '_count'}; {'id': '468', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '469', 'type': 'return_statement', 'children': ['470']}; {'id': '470', 'type': 'identifier', 'children': [], 'value': 'rruleset'}
|
def getrruleset(self, addRDate=False):
rruleset = None
for name in DATESANDRULES:
addfunc = None
for line in self.contents.get(name, ()):
if rruleset is None:
rruleset = rrule.rruleset()
if addfunc is None:
addfunc = getattr(rruleset, name)
if name in DATENAMES:
if type(line.value[0]) == datetime.datetime:
map(addfunc, line.value)
elif type(line.value[0]) == datetime.date:
for dt in line.value:
addfunc(datetime.datetime(dt.year, dt.month, dt.day))
else:
pass
elif name in RULENAMES:
try:
dtstart = self.dtstart.value
except (AttributeError, KeyError):
try:
if self.name == "VTODO":
dtstart = self.due.value
else:
print('failed to get dtstart with VTODO')
return None
except (AttributeError, KeyError):
print('failed to find DUE at all.')
return None
value = str_(line.value).replace('\\', '')
rule = rrule.rrulestr(value, dtstart=dtstart)
until = rule._until
if until is not None and isinstance(dtstart, datetime.datetime) and \
(until.tzinfo != dtstart.tzinfo):
vals = dict(pair.split('=') for pair in
line.value.upper().split(';'))
if len(vals.get('UNTIL', '')) == 8:
until = datetime.datetime.combine(until.date(), dtstart.time())
if until.tzinfo is None:
until = until.replace(tzinfo=dtstart.tzinfo)
if dtstart.tzinfo is not None:
until = until.astimezone(dtstart.tzinfo)
if dtstart.tzinfo is None:
until = until.replace(tzinfo=None)
rule._until = until
addfunc(rule)
if name == 'rrule' and addRDate:
try:
if not isinstance(dtstart, datetime.datetime):
adddtstart = datetime.datetime.fromordinal(dtstart.toordinal())
else:
adddtstart = dtstart
if rruleset._rrule[-1][0] != adddtstart:
rruleset.rdate(adddtstart)
added = True
else:
added = False
except IndexError:
added = False
if added and rruleset._rrule[-1]._count is not None:
rruleset._rrule[-1]._count -= 1
return rruleset
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_processed_parameter_group_histogram'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'merge_time'}; {'id': '16', 'type': 'integer', 'children': [], 'value': '20'}; {'id': '17', 'type': 'block', 'children': ['18', '22', '33', '47', '61', '77']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '21', 'type': 'dictionary', 'children': []}; {'id': '22', 'type': 'if_statement', 'children': ['23', '26']}; {'id': '23', 'type': 'comparison_operator', 'children': ['24', '25'], 'value': 'is'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '25', 'type': 'None', 'children': []}; {'id': '26', 'type': 'block', 'children': ['27']}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '32']}; {'id': '29', 'type': 'subscript', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '31', 'type': 'string', 'children': [], 'value': "'group'"}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '33', 'type': 'if_statement', 'children': ['34', '37']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': 'is'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '36', 'type': 'None', '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': 'params'}; {'id': '42', 'type': 'string', 'children': [], 'value': "'start'"}; {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'to_isostring'}; {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '47', 'type': 'if_statement', 'children': ['48', '51']}; {'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': 'is'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '50', 'type': 'None', 'children': []}; {'id': '51', 'type': 'block', 'children': ['52']}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}; {'id': '53', 'type': 'assignment', 'children': ['54', '57']}; {'id': '54', 'type': 'subscript', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '56', 'type': 'string', 'children': [], 'value': "'stop'"}; {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'to_isostring'}; {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '61', 'type': 'if_statement', 'children': ['62', '65']}; {'id': '62', 'type': 'comparison_operator', 'children': ['63', '64'], 'value': 'is'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'merge_time'}; {'id': '64', 'type': 'None', 'children': []}; {'id': '65', 'type': 'block', 'children': ['66']}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}; {'id': '67', 'type': 'assignment', 'children': ['68', '71']}; {'id': '68', 'type': 'subscript', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '70', 'type': 'string', 'children': [], 'value': "'mergeTime'"}; {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'binary_operator', 'children': ['75', '76'], 'value': '*'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'merge_time'}; {'id': '76', 'type': 'integer', 'children': [], 'value': '1000'}; {'id': '77', 'type': 'return_statement', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '82']}; {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'pagination'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'Iterator'}; {'id': '82', 'type': 'argument_list', 'children': ['83', '88', '98', '101', '106', '109']}; {'id': '83', 'type': 'keyword_argument', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'client'}; {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': '_client'}; {'id': '88', 'type': 'keyword_argument', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '90', 'type': 'call', 'children': ['91', '94']}; {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'string', 'children': [], 'value': "'/archive/{}/parameter-index'"}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}; {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': '_instance'}; {'id': '98', 'type': 'keyword_argument', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '101', 'type': 'keyword_argument', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'response_class'}; {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'archive_pb2'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'IndexResponse'}; {'id': '106', 'type': 'keyword_argument', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'items_key'}; {'id': '108', 'type': 'string', 'children': [], 'value': "'group'"}; {'id': '109', 'type': 'keyword_argument', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'item_mapper'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'IndexGroup'}
|
def list_processed_parameter_group_histogram(self, group=None, start=None, stop=None, merge_time=20):
params = {}
if group is not None:
params['group'] = group
if start is not None:
params['start'] = to_isostring(start)
if stop is not None:
params['stop'] = to_isostring(stop)
if merge_time is not None:
params['mergeTime'] = int(merge_time * 1000)
return pagination.Iterator(
client=self._client,
path='/archive/{}/parameter-index'.format(self._instance),
params=params,
response_class=archive_pb2.IndexResponse,
items_key='group',
item_mapper=IndexGroup,
)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_completeness_index'}; {'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': 'start'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'block', 'children': ['12', '16', '30', '44']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '15', 'type': 'dictionary', 'children': []}; {'id': '16', 'type': 'if_statement', 'children': ['17', '20']}; {'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': 'is'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'block', 'children': ['21']}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '26']}; {'id': '23', 'type': 'subscript', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '25', 'type': 'string', 'children': [], 'value': "'start'"}; {'id': '26', 'type': 'call', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'to_isostring'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '30', 'type': 'if_statement', 'children': ['31', '34']}; {'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': 'is'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '33', 'type': 'None', 'children': []}; {'id': '34', 'type': 'block', 'children': ['35']}; {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '40']}; {'id': '37', 'type': 'subscript', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '39', 'type': 'string', 'children': [], 'value': "'stop'"}; {'id': '40', 'type': 'call', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'to_isostring'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '44', 'type': 'return_statement', 'children': ['45']}; {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'pagination'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'Iterator'}; {'id': '49', 'type': 'argument_list', 'children': ['50', '55', '65', '68', '73', '76']}; {'id': '50', 'type': 'keyword_argument', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'client'}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': '_client'}; {'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}; {'id': '59', 'type': 'string', 'children': [], 'value': "'/archive/{}/completeness-index'"}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': '_instance'}; {'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '68', 'type': 'keyword_argument', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'response_class'}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'archive_pb2'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'IndexResponse'}; {'id': '73', 'type': 'keyword_argument', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'items_key'}; {'id': '75', 'type': 'string', 'children': [], 'value': "'group'"}; {'id': '76', 'type': 'keyword_argument', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'item_mapper'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'IndexGroup'}
|
def list_completeness_index(self, start=None, stop=None):
params = {}
if start is not None:
params['start'] = to_isostring(start)
if stop is not None:
params['stop'] = to_isostring(stop)
return pagination.Iterator(
client=self._client,
path='/archive/{}/completeness-index'.format(self._instance),
params=params,
response_class=archive_pb2.IndexResponse,
items_key='group',
item_mapper=IndexGroup,
)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_packets'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'page_size'}; {'id': '16', 'type': 'integer', 'children': [], 'value': '500'}; {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'descending'}; {'id': '19', 'type': 'False', 'children': []}; {'id': '20', 'type': 'block', 'children': ['21', '31', '42', '53', '67', '81']}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '24', 'type': 'dictionary', 'children': ['25']}; {'id': '25', 'type': 'pair', 'children': ['26', '27']}; {'id': '26', 'type': 'string', 'children': [], 'value': "'order'"}; {'id': '27', 'type': 'conditional_expression', 'children': ['28', '29', '30'], 'value': 'if'}; {'id': '28', 'type': 'string', 'children': [], 'value': "'desc'"}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'descending'}; {'id': '30', 'type': 'string', 'children': [], 'value': "'asc'"}; {'id': '31', 'type': 'if_statement', 'children': ['32', '35']}; {'id': '32', 'type': 'comparison_operator', 'children': ['33', '34'], 'value': 'is'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '34', 'type': 'None', 'children': []}; {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}; {'id': '37', 'type': 'assignment', 'children': ['38', '41']}; {'id': '38', 'type': 'subscript', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '40', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '42', 'type': 'if_statement', 'children': ['43', '46']}; {'id': '43', 'type': 'comparison_operator', 'children': ['44', '45'], 'value': 'is'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'page_size'}; {'id': '45', 'type': 'None', 'children': []}; {'id': '46', 'type': 'block', 'children': ['47']}; {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '52']}; {'id': '49', 'type': 'subscript', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '51', 'type': 'string', 'children': [], 'value': "'limit'"}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'page_size'}; {'id': '53', 'type': 'if_statement', 'children': ['54', '57']}; {'id': '54', 'type': 'comparison_operator', 'children': ['55', '56'], 'value': 'is'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '56', 'type': 'None', 'children': []}; {'id': '57', 'type': 'block', 'children': ['58']}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}; {'id': '59', 'type': 'assignment', 'children': ['60', '63']}; {'id': '60', 'type': 'subscript', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '62', 'type': 'string', 'children': [], 'value': "'start'"}; {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'to_isostring'}; {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '67', 'type': 'if_statement', 'children': ['68', '71']}; {'id': '68', 'type': 'comparison_operator', 'children': ['69', '70'], 'value': 'is'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '70', 'type': 'None', 'children': []}; {'id': '71', 'type': 'block', 'children': ['72']}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}; {'id': '73', 'type': 'assignment', 'children': ['74', '77']}; {'id': '74', 'type': 'subscript', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '76', 'type': 'string', 'children': [], 'value': "'stop'"}; {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'to_isostring'}; {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '81', 'type': 'return_statement', 'children': ['82']}; {'id': '82', 'type': 'call', 'children': ['83', '86']}; {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'pagination'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'Iterator'}; {'id': '86', 'type': 'argument_list', 'children': ['87', '92', '102', '105', '110', '113']}; {'id': '87', 'type': 'keyword_argument', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'client'}; {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': '_client'}; {'id': '92', 'type': 'keyword_argument', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '94', 'type': 'call', 'children': ['95', '98']}; {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'string', 'children': [], 'value': "'/archive/{}/packets'"}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}; {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': '_instance'}; {'id': '102', 'type': 'keyword_argument', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '105', 'type': 'keyword_argument', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'response_class'}; {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'rest_pb2'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'ListPacketsResponse'}; {'id': '110', 'type': 'keyword_argument', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'items_key'}; {'id': '112', 'type': 'string', 'children': [], 'value': "'packet'"}; {'id': '113', 'type': 'keyword_argument', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'item_mapper'}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'Packet'}
|
def list_packets(self, name=None, start=None, stop=None, page_size=500, descending=False):
params = {
'order': 'desc' if descending else 'asc',
}
if name is not None:
params['name'] = name
if page_size is not None:
params['limit'] = page_size
if start is not None:
params['start'] = to_isostring(start)
if stop is not None:
params['stop'] = to_isostring(stop)
return pagination.Iterator(
client=self._client,
path='/archive/{}/packets'.format(self._instance),
params=params,
response_class=rest_pb2.ListPacketsResponse,
items_key='packet',
item_mapper=Packet,
)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '26']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_events'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'severity'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'text_filter'}; {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '16', 'type': 'None', 'children': []}; {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'page_size'}; {'id': '22', 'type': 'integer', 'children': [], 'value': '500'}; {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'descending'}; {'id': '25', 'type': 'False', 'children': []}; {'id': '26', 'type': 'block', 'children': ['27', '37', '48', '59', '70', '84', '98', '109']}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '30', 'type': 'dictionary', 'children': ['31']}; {'id': '31', 'type': 'pair', 'children': ['32', '33']}; {'id': '32', 'type': 'string', 'children': [], 'value': "'order'"}; {'id': '33', 'type': 'conditional_expression', 'children': ['34', '35', '36'], 'value': 'if'}; {'id': '34', 'type': 'string', 'children': [], 'value': "'desc'"}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'descending'}; {'id': '36', 'type': 'string', 'children': [], 'value': "'asc'"}; {'id': '37', 'type': 'if_statement', 'children': ['38', '41']}; {'id': '38', 'type': 'comparison_operator', 'children': ['39', '40'], 'value': 'is'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '40', 'type': 'None', 'children': []}; {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}; {'id': '43', 'type': 'assignment', 'children': ['44', '47']}; {'id': '44', 'type': 'subscript', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '46', 'type': 'string', 'children': [], 'value': "'source'"}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '48', 'type': 'if_statement', 'children': ['49', '52']}; {'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': 'is'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'page_size'}; {'id': '51', 'type': 'None', 'children': []}; {'id': '52', 'type': 'block', 'children': ['53']}; {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '58']}; {'id': '55', 'type': 'subscript', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '57', 'type': 'string', 'children': [], 'value': "'limit'"}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'page_size'}; {'id': '59', 'type': 'if_statement', 'children': ['60', '63']}; {'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': 'is'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'severity'}; {'id': '62', 'type': 'None', 'children': []}; {'id': '63', 'type': 'block', 'children': ['64']}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}; {'id': '65', 'type': 'assignment', 'children': ['66', '69']}; {'id': '66', 'type': 'subscript', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '68', 'type': 'string', 'children': [], 'value': "'severity'"}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'severity'}; {'id': '70', 'type': 'if_statement', 'children': ['71', '74']}; {'id': '71', 'type': 'comparison_operator', 'children': ['72', '73'], 'value': 'is'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '73', 'type': 'None', 'children': []}; {'id': '74', 'type': 'block', 'children': ['75']}; {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '80']}; {'id': '77', 'type': 'subscript', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '79', 'type': 'string', 'children': [], 'value': "'start'"}; {'id': '80', 'type': 'call', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'to_isostring'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '84', 'type': 'if_statement', 'children': ['85', '88']}; {'id': '85', 'type': 'comparison_operator', 'children': ['86', '87'], 'value': 'is'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '87', 'type': 'None', 'children': []}; {'id': '88', 'type': 'block', 'children': ['89']}; {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'assignment', 'children': ['91', '94']}; {'id': '91', 'type': 'subscript', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '93', 'type': 'string', 'children': [], 'value': "'stop'"}; {'id': '94', 'type': 'call', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'to_isostring'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '98', 'type': 'if_statement', 'children': ['99', '102']}; {'id': '99', 'type': 'comparison_operator', 'children': ['100', '101'], 'value': 'is'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'text_filter'}; {'id': '101', 'type': 'None', 'children': []}; {'id': '102', 'type': 'block', 'children': ['103']}; {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '108']}; {'id': '105', 'type': 'subscript', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '107', 'type': 'string', 'children': [], 'value': "'q'"}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'text_filter'}; {'id': '109', 'type': 'return_statement', 'children': ['110']}; {'id': '110', 'type': 'call', 'children': ['111', '114']}; {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'pagination'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'Iterator'}; {'id': '114', 'type': 'argument_list', 'children': ['115', '120', '130', '133', '138', '141']}; {'id': '115', 'type': 'keyword_argument', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'client'}; {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': '_client'}; {'id': '120', 'type': 'keyword_argument', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '122', 'type': 'call', 'children': ['123', '126']}; {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'string', 'children': [], 'value': "'/archive/{}/events'"}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}; {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': '_instance'}; {'id': '130', 'type': 'keyword_argument', 'children': ['131', '132']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '133', 'type': 'keyword_argument', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'response_class'}; {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'rest_pb2'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'ListEventsResponse'}; {'id': '138', 'type': 'keyword_argument', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'items_key'}; {'id': '140', 'type': 'string', 'children': [], 'value': "'event'"}; {'id': '141', 'type': 'keyword_argument', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'item_mapper'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'Event'}
|
def list_events(self, source=None, severity=None, text_filter=None,
start=None, stop=None, page_size=500, descending=False):
params = {
'order': 'desc' if descending else 'asc',
}
if source is not None:
params['source'] = source
if page_size is not None:
params['limit'] = page_size
if severity is not None:
params['severity'] = severity
if start is not None:
params['start'] = to_isostring(start)
if stop is not None:
params['stop'] = to_isostring(stop)
if text_filter is not None:
params['q'] = text_filter
return pagination.Iterator(
client=self._client,
path='/archive/{}/events'.format(self._instance),
params=params,
response_class=rest_pb2.ListEventsResponse,
items_key='event',
item_mapper=Event,
)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_parameter_ranges'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'parameter'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '8', 'type': 'None', 'children': []}; {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'min_gap'}; {'id': '14', 'type': 'None', 'children': []}; {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'max_gap'}; {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'parameter_cache'}; {'id': '20', 'type': 'string', 'children': [], 'value': "'realtime'"}; {'id': '21', 'type': 'block', 'children': ['22', '34', '38', '52', '66', '82', '98', '115', '131', '139', '148', '156']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'string', 'children': [], 'value': "'/archive/{}/parameters{}/ranges'"}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '29', 'type': 'argument_list', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': '_instance'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'parameter'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}; {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '37', 'type': 'dictionary', 'children': []}; {'id': '38', 'type': 'if_statement', 'children': ['39', '42']}; {'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': 'is'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '41', 'type': 'None', 'children': []}; {'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': 'params'}; {'id': '47', 'type': 'string', 'children': [], 'value': "'start'"}; {'id': '48', 'type': 'call', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'to_isostring'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '52', 'type': 'if_statement', 'children': ['53', '56']}; {'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': 'is'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '55', 'type': 'None', 'children': []}; {'id': '56', 'type': 'block', 'children': ['57']}; {'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': "'stop'"}; {'id': '62', 'type': 'call', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'to_isostring'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '66', 'type': 'if_statement', 'children': ['67', '70']}; {'id': '67', 'type': 'comparison_operator', 'children': ['68', '69'], 'value': 'is'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'min_gap'}; {'id': '69', 'type': 'None', 'children': []}; {'id': '70', 'type': 'block', 'children': ['71']}; {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '76']}; {'id': '73', 'type': 'subscript', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '75', 'type': 'string', 'children': [], 'value': "'minGap'"}; {'id': '76', 'type': 'call', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}; {'id': '79', 'type': 'binary_operator', 'children': ['80', '81'], 'value': '*'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'min_gap'}; {'id': '81', 'type': 'integer', 'children': [], 'value': '1000'}; {'id': '82', 'type': 'if_statement', 'children': ['83', '86']}; {'id': '83', 'type': 'comparison_operator', 'children': ['84', '85'], 'value': 'is'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'max_gap'}; {'id': '85', 'type': 'None', 'children': []}; {'id': '86', 'type': 'block', 'children': ['87']}; {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '92']}; {'id': '89', 'type': 'subscript', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '91', 'type': 'string', 'children': [], 'value': "'maxGap'"}; {'id': '92', 'type': 'call', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}; {'id': '95', 'type': 'binary_operator', 'children': ['96', '97'], 'value': '*'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'max_gap'}; {'id': '97', 'type': 'integer', 'children': [], 'value': '1000'}; {'id': '98', 'type': 'if_statement', 'children': ['99', '100', '107']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'parameter_cache'}; {'id': '100', 'type': 'block', 'children': ['101']}; {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '106']}; {'id': '103', 'type': 'subscript', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '105', 'type': 'string', 'children': [], 'value': "'processor'"}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'parameter_cache'}; {'id': '107', 'type': 'else_clause', 'children': ['108']}; {'id': '108', 'type': 'block', 'children': ['109']}; {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'assignment', 'children': ['111', '114']}; {'id': '111', 'type': 'subscript', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '113', 'type': 'string', 'children': [], 'value': "'norealtime'"}; {'id': '114', 'type': 'True', 'children': []}; {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'response'}; {'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': '_client'}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'get_proto'}; {'id': '124', 'type': 'argument_list', 'children': ['125', '128']}; {'id': '125', 'type': 'keyword_argument', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '128', 'type': 'keyword_argument', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '134', 'type': 'call', 'children': ['135', '138']}; {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'pvalue_pb2'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'Ranges'}; {'id': '138', 'type': 'argument_list', 'children': []}; {'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': 'message'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'ParseFromString'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}; {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'content'}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}; {'id': '149', 'type': 'assignment', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'ranges'}; {'id': '151', 'type': 'call', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '153', 'type': 'argument_list', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '155', 'type': 'string', 'children': [], 'value': "'range'"}; {'id': '156', 'type': 'return_statement', 'children': ['157']}; {'id': '157', 'type': 'list_comprehension', 'children': ['158', '162']}; {'id': '158', 'type': 'call', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'ParameterRange'}; {'id': '160', 'type': 'argument_list', 'children': ['161']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '162', 'type': 'for_in_clause', 'children': ['163', '164']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'ranges'}
|
def list_parameter_ranges(self, parameter, start=None, stop=None,
min_gap=None, max_gap=None,
parameter_cache='realtime'):
path = '/archive/{}/parameters{}/ranges'.format(
self._instance, parameter)
params = {}
if start is not None:
params['start'] = to_isostring(start)
if stop is not None:
params['stop'] = to_isostring(stop)
if min_gap is not None:
params['minGap'] = int(min_gap * 1000)
if max_gap is not None:
params['maxGap'] = int(max_gap * 1000)
if parameter_cache:
params['processor'] = parameter_cache
else:
params['norealtime'] = True
response = self._client.get_proto(path=path, params=params)
message = pvalue_pb2.Ranges()
message.ParseFromString(response.content)
ranges = getattr(message, 'range')
return [ParameterRange(r) for r in ranges]
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'copy_file'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'destination'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'unique'}; {'id': '8', 'type': 'False', 'children': []}; {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '11', 'type': 'False', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'case_sensitive'}; {'id': '14', 'type': 'True', 'children': []}; {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'create_path'}; {'id': '17', 'type': 'False', 'children': []}; {'id': '18', 'type': 'block', 'children': ['19']}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'call', 'children': ['21', '24']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': '_File'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '26', '27', '28', '29', '30']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'destination'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'unique'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'case_sensitive'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'create_path'}
|
def copy_file(source, destination, unique=False, sort=False, case_sensitive=True, create_path=False):
_File.copy(source, destination, unique, sort, case_sensitive, create_path)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'tree'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'formatter'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'postfix'}; {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': '_depth'}; {'id': '16', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '17', 'type': 'block', 'children': ['18', '22', '33', '37', '41']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'current'}; {'id': '21', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '32']}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '32', 'type': 'argument_list', 'children': []}; {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'tee_joint'}; {'id': '36', 'type': 'string', 'children': [], 'value': "'\\xe2\\x94\\x9c\\xe2\\x94\\x80\\xe2\\x94\\x80'"}; {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'elbow_joint'}; {'id': '40', 'type': 'string', 'children': [], 'value': "'\\xe2\\x94\\x94\\xe2\\x94\\x80\\xe2\\x94\\x80'"}; {'id': '41', 'type': 'for_statement', 'children': ['42', '45', '50']}; {'id': '42', 'type': 'pattern_list', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'iteritems'}; {'id': '49', 'type': 'argument_list', 'children': []}; {'id': '50', 'type': 'block', 'children': ['51', '55', '65', '75', '85', '94', '113']}; {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'augmented_assignment', 'children': ['53', '54'], 'value': '+='}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'current'}; {'id': '54', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '58', 'type': 'conditional_expression', 'children': ['59', '63', '64'], 'value': 'if'}; {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'formatter'}; {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'formatter'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'pre'}; {'id': '68', 'type': 'conditional_expression', 'children': ['69', '73', '74'], 'value': 'if'}; {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '74', 'type': 'string', 'children': [], 'value': "''"}; {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'post'}; {'id': '78', 'type': 'conditional_expression', 'children': ['79', '83', '84'], 'value': 'if'}; {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'postfix'}; {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'postfix'}; {'id': '84', 'type': 'string', 'children': [], 'value': "''"}; {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'space'}; {'id': '88', 'type': 'conditional_expression', 'children': ['89', '90', '93'], 'value': 'if'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'elbow_joint'}; {'id': '90', 'type': 'comparison_operator', 'children': ['91', '92'], 'value': '=='}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'current'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'tee_joint'}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}; {'id': '95', 'type': 'yield', 'children': ['96']}; {'id': '96', 'type': 'call', 'children': ['97', '100']}; {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'string', 'children': [], 'value': "' {space} {prefix}{key}{postfix}'"}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '100', 'type': 'argument_list', 'children': ['101', '104', '107', '110']}; {'id': '101', 'type': 'keyword_argument', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'space'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'space'}; {'id': '104', 'type': 'keyword_argument', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '107', 'type': 'keyword_argument', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'pre'}; {'id': '110', 'type': 'keyword_argument', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'postfix'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'post'}; {'id': '113', 'type': 'if_statement', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '115', 'type': 'block', 'children': ['116']}; {'id': '116', 'type': 'for_statement', 'children': ['117', '118', '136']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '118', 'type': 'call', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '120', 'type': 'argument_list', 'children': ['121', '122', '125', '128', '131']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '122', 'type': 'keyword_argument', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'formatter'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'formatter'}; {'id': '125', 'type': 'keyword_argument', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '128', 'type': 'keyword_argument', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'postfix'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'postfix'}; {'id': '131', 'type': 'keyword_argument', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': '_depth'}; {'id': '133', 'type': 'binary_operator', 'children': ['134', '135'], 'value': '+'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': '_depth'}; {'id': '135', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '136', 'type': 'block', 'children': ['137']}; {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'yield', 'children': ['139']}; {'id': '139', 'type': 'binary_operator', 'children': ['140', '147'], 'value': '+'}; {'id': '140', 'type': '()', 'children': ['141']}; {'id': '141', 'type': 'conditional_expression', 'children': ['142', '143', '146'], 'value': 'if'}; {'id': '142', 'type': 'string', 'children': [], 'value': "' | '"}; {'id': '143', 'type': 'comparison_operator', 'children': ['144', '145'], 'value': '!='}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'current'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '146', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'e'}
|
def tree(node, formatter=None, prefix=None, postfix=None, _depth=1):
current = 0
length = len(node.keys())
tee_joint = '\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80'
elbow_joint = '\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80'
for key, value in node.iteritems():
current += 1
k = formatter(key) if formatter else key
pre = prefix(key) if prefix else ''
post = postfix(key) if postfix else ''
space = elbow_joint if current == length else tee_joint
yield ' {space} {prefix}{key}{postfix}'.format(space=space, key=k, prefix=pre, postfix=post)
if value:
for e in tree(value, formatter=formatter, prefix=prefix, postfix=postfix, _depth=_depth + 1):
yield (' | ' if current != length else ' ') + e
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'run'}; {'id': '3', 'type': 'parameters', 'children': []}; {'id': '4', 'type': 'block', 'children': ['5', '11', '20', '26', '35', '44', '81', '87', '99', '136', '148', '163', '175', '177', '195', '206', '220', '224', '240', '290', '314', '346', '350', '384', '388', '404', '429']}; {'id': '5', 'type': 'expression_statement', 'children': ['6']}; {'id': '6', 'type': 'assignment', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '8', 'type': 'call', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'parse_args'}; {'id': '10', 'type': 'argument_list', 'children': []}; {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'call', 'children': ['13', '16']}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'codetools'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'setup_logging'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}; {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'git_tag'}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}; {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'git_email'}; {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'codetools'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'lookup_email'}; {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'git_user'}; {'id': '38', 'type': 'call', 'children': ['39', '42']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'codetools'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'lookup_user'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '44', 'type': 'if_statement', 'children': ['45', '49']}; {'id': '45', 'type': 'not_operator', 'children': ['46']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'manifest_only'}; {'id': '49', 'type': 'block', 'children': ['50', '56', '69']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}; {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'eups_tag'}; {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'eups_tag'}; {'id': '56', 'type': 'if_statement', 'children': ['57', '59']}; {'id': '57', 'type': 'not_operator', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'eups_tag'}; {'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': 'eups_tag'}; {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'eups'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'git_tag2eups_tag'}; {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'git_tag'}; {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'call', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}; {'id': '73', 'type': 'call', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}; {'id': '75', 'type': 'string', 'children': [], 'value': '"using eups tag: {eups_tag}"'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'keyword_argument', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'eups_tag'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'eups_tag'}; {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'manifest'}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'manifest'}; {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'call', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}; {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}; {'id': '93', 'type': 'string', 'children': [], 'value': '"using manifest: {manifest}"'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'keyword_argument', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'manifest'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'manifest'}; {'id': '99', 'type': 'if_statement', 'children': ['100', '104', '121']}; {'id': '100', 'type': 'not_operator', 'children': ['101']}; {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'manifest_only'}; {'id': '104', 'type': 'block', 'children': ['105']}; {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'message_template'}; {'id': '108', 'type': 'call', 'children': ['109', '114']}; {'id': '109', 'type': 'attribute', 'children': ['110', '113']}; {'id': '110', 'type': 'concatenated_string', 'children': ['111', '112']}; {'id': '111', 'type': 'string', 'children': [], 'value': '"Version {{git_tag}}"'}; {'id': '112', 'type': 'string', 'children': [], 'value': '" release from {eups_tag}/{manifest}"'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '114', 'type': 'argument_list', 'children': ['115', '118']}; {'id': '115', 'type': 'keyword_argument', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'eups_tag'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'eups_tag'}; {'id': '118', 'type': 'keyword_argument', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'manifest'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'manifest'}; {'id': '121', 'type': 'else_clause', 'children': ['122']}; {'id': '122', 'type': 'block', 'children': ['123']}; {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'message_template'}; {'id': '126', 'type': 'call', 'children': ['127', '132']}; {'id': '127', 'type': 'attribute', 'children': ['128', '131']}; {'id': '128', 'type': 'concatenated_string', 'children': ['129', '130']}; {'id': '129', 'type': 'string', 'children': [], 'value': '"Version {{git_tag}}"'}; {'id': '130', 'type': 'string', 'children': [], 'value': '" release from manifest {manifest}"'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}; {'id': '133', 'type': 'keyword_argument', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'manifest'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'manifest'}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}; {'id': '137', 'type': 'call', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'call', 'children': ['141', '144']}; {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'string', 'children': [], 'value': '"using tag message: {msg}"'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}; {'id': '145', 'type': 'keyword_argument', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'message_template'}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}; {'id': '149', 'type': 'assignment', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'tagger'}; {'id': '151', 'type': 'call', 'children': ['152', '155']}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'github'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'InputGitAuthor'}; {'id': '155', 'type': 'argument_list', 'children': ['156', '157', '158']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'git_user'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'git_email'}; {'id': '158', 'type': 'call', 'children': ['159', '162']}; {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'codetools'}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'current_timestamp'}; {'id': '162', 'type': 'argument_list', 'children': []}; {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'call', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '166', 'type': 'argument_list', 'children': ['167']}; {'id': '167', 'type': 'call', 'children': ['168', '171']}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}; {'id': '169', 'type': 'string', 'children': [], 'value': '"using taggger: {tagger}"'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '171', 'type': 'argument_list', 'children': ['172']}; {'id': '172', 'type': 'keyword_argument', 'children': ['173', '174']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'tagger'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'tagger'}; {'id': '175', 'type': 'global_statement', 'children': ['176']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '177', 'type': 'expression_statement', 'children': ['178']}; {'id': '178', 'type': 'assignment', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '180', 'type': 'call', 'children': ['181', '184']}; {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'pygithub'}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'login_github'}; {'id': '184', 'type': 'argument_list', 'children': ['185', '190']}; {'id': '185', 'type': 'keyword_argument', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'token_path'}; {'id': '187', 'type': 'attribute', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'token_path'}; {'id': '190', 'type': 'keyword_argument', 'children': ['191', '192']}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '192', 'type': 'attribute', 'children': ['193', '194']}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '195', 'type': 'expression_statement', 'children': ['196']}; {'id': '196', 'type': 'assignment', 'children': ['197', '198']}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'org'}; {'id': '198', 'type': 'call', 'children': ['199', '202']}; {'id': '199', 'type': 'attribute', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'get_organization'}; {'id': '202', 'type': 'argument_list', 'children': ['203']}; {'id': '203', 'type': 'attribute', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'org'}; {'id': '206', 'type': 'expression_statement', 'children': ['207']}; {'id': '207', 'type': 'call', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '209', 'type': 'argument_list', 'children': ['210']}; {'id': '210', 'type': 'call', 'children': ['211', '214']}; {'id': '211', 'type': 'attribute', 'children': ['212', '213']}; {'id': '212', 'type': 'string', 'children': [], 'value': '"tagging repos in org: {org}"'}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '214', 'type': 'argument_list', 'children': ['215']}; {'id': '215', 'type': 'keyword_argument', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'org'}; {'id': '217', 'type': 'attribute', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'org'}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'login'}; {'id': '220', 'type': 'expression_statement', 'children': ['221']}; {'id': '221', 'type': 'assignment', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'problems'}; {'id': '223', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '224', 'type': 'expression_statement', 'children': ['225']}; {'id': '225', 'type': 'assignment', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'manifest_products'}; {'id': '227', 'type': 'attribute', 'children': ['228', '239']}; {'id': '228', 'type': 'call', 'children': ['229', '232']}; {'id': '229', 'type': 'attribute', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'versiondb'}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'Manifest'}; {'id': '232', 'type': 'argument_list', 'children': ['233', '234']}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'manifest'}; {'id': '234', 'type': 'keyword_argument', 'children': ['235', '236']}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'base_url'}; {'id': '236', 'type': 'attribute', 'children': ['237', '238']}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'versiondb_base_url'}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'products'}; {'id': '240', 'type': 'if_statement', 'children': ['241', '245', '284']}; {'id': '241', 'type': 'not_operator', 'children': ['242']}; {'id': '242', 'type': 'attribute', 'children': ['243', '244']}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'manifest_only'}; {'id': '245', 'type': 'block', 'children': ['246', '262', '280']}; {'id': '246', 'type': 'expression_statement', 'children': ['247']}; {'id': '247', 'type': 'assignment', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'eups_products'}; {'id': '249', 'type': 'attribute', 'children': ['250', '261']}; {'id': '250', 'type': 'call', 'children': ['251', '254']}; {'id': '251', 'type': 'attribute', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'eups'}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'EupsTag'}; {'id': '254', 'type': 'argument_list', 'children': ['255', '256']}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'eups_tag'}; {'id': '256', 'type': 'keyword_argument', 'children': ['257', '258']}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'base_url'}; {'id': '258', 'type': 'attribute', 'children': ['259', '260']}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'eupstag_base_url'}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'products'}; {'id': '262', 'type': 'expression_statement', 'children': ['263']}; {'id': '263', 'type': 'assignment', 'children': ['264', '267']}; {'id': '264', 'type': 'pattern_list', 'children': ['265', '266']}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'products'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '267', 'type': 'call', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'cross_reference_products'}; {'id': '269', 'type': 'argument_list', 'children': ['270', '271', '272', '277']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'eups_products'}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'manifest_products'}; {'id': '272', 'type': 'keyword_argument', 'children': ['273', '274']}; {'id': '273', 'type': 'identifier', 'children': [], 'value': 'ignore_manifest_versions'}; {'id': '274', 'type': 'attribute', 'children': ['275', '276']}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'ignore_manifest_versions'}; {'id': '277', 'type': 'keyword_argument', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'fail_fast'}; {'id': '279', 'type': 'False', 'children': []}; {'id': '280', 'type': 'expression_statement', 'children': ['281']}; {'id': '281', 'type': 'augmented_assignment', 'children': ['282', '283'], 'value': '+='}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'problems'}; {'id': '283', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '284', 'type': 'else_clause', 'children': ['285']}; {'id': '285', 'type': 'block', 'children': ['286']}; {'id': '286', 'type': 'expression_statement', 'children': ['287']}; {'id': '287', 'type': 'assignment', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'products'}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'manifest_products'}; {'id': '290', 'type': 'if_statement', 'children': ['291', '294']}; {'id': '291', 'type': 'attribute', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '293', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '294', 'type': 'block', 'children': ['295']}; {'id': '295', 'type': 'expression_statement', 'children': ['296']}; {'id': '296', 'type': 'assignment', 'children': ['297', '298']}; {'id': '297', 'type': 'identifier', 'children': [], 'value': 'products'}; {'id': '298', 'type': 'call', 'children': ['299', '300']}; {'id': '299', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '300', 'type': 'argument_list', 'children': ['301']}; {'id': '301', 'type': 'call', 'children': ['302', '305']}; {'id': '302', 'type': 'attribute', 'children': ['303', '304']}; {'id': '303', 'type': 'identifier', 'children': [], 'value': 'itertools'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'islice'}; {'id': '305', 'type': 'argument_list', 'children': ['306', '311']}; {'id': '306', 'type': 'call', 'children': ['307', '310']}; {'id': '307', 'type': 'attribute', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'products'}; {'id': '309', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '310', 'type': 'argument_list', 'children': []}; {'id': '311', 'type': 'attribute', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '313', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '314', 'type': 'expression_statement', 'children': ['315']}; {'id': '315', 'type': 'assignment', 'children': ['316', '319']}; {'id': '316', 'type': 'pattern_list', 'children': ['317', '318']}; {'id': '317', 'type': 'identifier', 'children': [], 'value': 'products'}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '319', 'type': 'call', 'children': ['320', '321']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'get_repo_for_products'}; {'id': '321', 'type': 'argument_list', 'children': ['322', '325', '328', '333', '338', '343']}; {'id': '322', 'type': 'keyword_argument', 'children': ['323', '324']}; {'id': '323', 'type': 'identifier', 'children': [], 'value': 'org'}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'org'}; {'id': '325', 'type': 'keyword_argument', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'products'}; {'id': '327', 'type': 'identifier', 'children': [], 'value': 'products'}; {'id': '328', 'type': 'keyword_argument', 'children': ['329', '330']}; {'id': '329', 'type': 'identifier', 'children': [], 'value': 'allow_teams'}; {'id': '330', 'type': 'attribute', 'children': ['331', '332']}; {'id': '331', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'allow_team'}; {'id': '333', 'type': 'keyword_argument', 'children': ['334', '335']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'ext_teams'}; {'id': '335', 'type': 'attribute', 'children': ['336', '337']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '337', 'type': 'identifier', 'children': [], 'value': 'external_team'}; {'id': '338', 'type': 'keyword_argument', 'children': ['339', '340']}; {'id': '339', 'type': 'identifier', 'children': [], 'value': 'deny_teams'}; {'id': '340', 'type': 'attribute', 'children': ['341', '342']}; {'id': '341', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'deny_team'}; {'id': '343', 'type': 'keyword_argument', 'children': ['344', '345']}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'fail_fast'}; {'id': '345', 'type': 'False', 'children': []}; {'id': '346', 'type': 'expression_statement', 'children': ['347']}; {'id': '347', 'type': 'augmented_assignment', 'children': ['348', '349'], 'value': '+='}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'problems'}; {'id': '349', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '350', 'type': 'expression_statement', 'children': ['351']}; {'id': '351', 'type': 'assignment', 'children': ['352', '355']}; {'id': '352', 'type': 'pattern_list', 'children': ['353', '354']}; {'id': '353', 'type': 'identifier', 'children': [], 'value': 'products_to_tag'}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '355', 'type': 'call', 'children': ['356', '357']}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'check_product_tags'}; {'id': '357', 'type': 'argument_list', 'children': ['358', '359', '360', '363', '366', '371', '374', '379']}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'products'}; {'id': '359', 'type': 'identifier', 'children': [], 'value': 'git_tag'}; {'id': '360', 'type': 'keyword_argument', 'children': ['361', '362']}; {'id': '361', 'type': 'identifier', 'children': [], 'value': 'tag_message_template'}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'message_template'}; {'id': '363', 'type': 'keyword_argument', 'children': ['364', '365']}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'tagger'}; {'id': '365', 'type': 'identifier', 'children': [], 'value': 'tagger'}; {'id': '366', 'type': 'keyword_argument', 'children': ['367', '368']}; {'id': '367', 'type': 'identifier', 'children': [], 'value': 'force_tag'}; {'id': '368', 'type': 'attribute', 'children': ['369', '370']}; {'id': '369', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'force_tag'}; {'id': '371', 'type': 'keyword_argument', 'children': ['372', '373']}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'fail_fast'}; {'id': '373', 'type': 'False', 'children': []}; {'id': '374', 'type': 'keyword_argument', 'children': ['375', '376']}; {'id': '375', 'type': 'identifier', 'children': [], 'value': 'ignore_git_message'}; {'id': '376', 'type': 'attribute', 'children': ['377', '378']}; {'id': '377', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '378', 'type': 'identifier', 'children': [], 'value': 'ignore_git_message'}; {'id': '379', 'type': 'keyword_argument', 'children': ['380', '381']}; {'id': '380', 'type': 'identifier', 'children': [], 'value': 'ignore_git_tagger'}; {'id': '381', 'type': 'attribute', 'children': ['382', '383']}; {'id': '382', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '383', 'type': 'identifier', 'children': [], 'value': 'ignore_git_tagger'}; {'id': '384', 'type': 'expression_statement', 'children': ['385']}; {'id': '385', 'type': 'augmented_assignment', 'children': ['386', '387'], 'value': '+='}; {'id': '386', 'type': 'identifier', 'children': [], 'value': 'problems'}; {'id': '387', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '388', 'type': 'if_statement', 'children': ['389', '392']}; {'id': '389', 'type': 'attribute', 'children': ['390', '391']}; {'id': '390', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '391', 'type': 'identifier', 'children': [], 'value': 'verify'}; {'id': '392', 'type': 'block', 'children': ['393', '400']}; {'id': '393', 'type': 'expression_statement', 'children': ['394']}; {'id': '394', 'type': 'assignment', 'children': ['395', '396']}; {'id': '395', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '396', 'type': 'call', 'children': ['397', '398']}; {'id': '397', 'type': 'identifier', 'children': [], 'value': 'identify_products_missing_tags'}; {'id': '398', 'type': 'argument_list', 'children': ['399']}; {'id': '399', 'type': 'identifier', 'children': [], 'value': 'products_to_tag'}; {'id': '400', 'type': 'expression_statement', 'children': ['401']}; {'id': '401', 'type': 'augmented_assignment', 'children': ['402', '403'], 'value': '+='}; {'id': '402', 'type': 'identifier', 'children': [], 'value': 'problems'}; {'id': '403', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '404', 'type': 'if_statement', 'children': ['405', '406']}; {'id': '405', 'type': 'identifier', 'children': [], 'value': 'problems'}; {'id': '406', 'type': 'block', 'children': ['407', '421']}; {'id': '407', 'type': 'expression_statement', 'children': ['408']}; {'id': '408', 'type': 'assignment', 'children': ['409', '410']}; {'id': '409', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '410', 'type': 'call', 'children': ['411', '414']}; {'id': '411', 'type': 'attribute', 'children': ['412', '413']}; {'id': '412', 'type': 'string', 'children': [], 'value': '"{n} pre-flight error(s)"'}; {'id': '413', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '414', 'type': 'argument_list', 'children': ['415']}; {'id': '415', 'type': 'keyword_argument', 'children': ['416', '417']}; {'id': '416', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '417', 'type': 'call', 'children': ['418', '419']}; {'id': '418', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '419', 'type': 'argument_list', 'children': ['420']}; {'id': '420', 'type': 'identifier', 'children': [], 'value': 'problems'}; {'id': '421', 'type': 'raise_statement', 'children': ['422']}; {'id': '422', 'type': 'call', 'children': ['423', '426']}; {'id': '423', 'type': 'attribute', 'children': ['424', '425']}; {'id': '424', 'type': 'identifier', 'children': [], 'value': 'codetools'}; {'id': '425', 'type': 'identifier', 'children': [], 'value': 'DogpileError'}; {'id': '426', 'type': 'argument_list', 'children': ['427', '428']}; {'id': '427', 'type': 'identifier', 'children': [], 'value': 'problems'}; {'id': '428', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '429', 'type': 'expression_statement', 'children': ['430']}; {'id': '430', 'type': 'call', 'children': ['431', '432']}; {'id': '431', 'type': 'identifier', 'children': [], 'value': 'tag_products'}; {'id': '432', 'type': 'argument_list', 'children': ['433', '434', '439']}; {'id': '433', 'type': 'identifier', 'children': [], 'value': 'products_to_tag'}; {'id': '434', 'type': 'keyword_argument', 'children': ['435', '436']}; {'id': '435', 'type': 'identifier', 'children': [], 'value': 'fail_fast'}; {'id': '436', 'type': 'attribute', 'children': ['437', '438']}; {'id': '437', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '438', 'type': 'identifier', 'children': [], 'value': 'fail_fast'}; {'id': '439', 'type': 'keyword_argument', 'children': ['440', '441']}; {'id': '440', 'type': 'identifier', 'children': [], 'value': 'dry_run'}; {'id': '441', 'type': 'attribute', 'children': ['442', '443']}; {'id': '442', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '443', 'type': 'identifier', 'children': [], 'value': 'dry_run'}
|
def run():
args = parse_args()
codetools.setup_logging(args.debug)
git_tag = args.tag
git_email = codetools.lookup_email(args)
git_user = codetools.lookup_user(args)
if not args.manifest_only:
eups_tag = args.eups_tag
if not eups_tag:
eups_tag = eups.git_tag2eups_tag(git_tag)
debug("using eups tag: {eups_tag}".format(eups_tag=eups_tag))
manifest = args.manifest
debug("using manifest: {manifest}".format(manifest=manifest))
if not args.manifest_only:
message_template = "Version {{git_tag}}"\
" release from {eups_tag}/{manifest}".format(
eups_tag=eups_tag,
manifest=manifest,
)
else:
message_template = "Version {{git_tag}}"\
" release from manifest {manifest}".format(
manifest=manifest,
)
debug("using tag message: {msg}".format(msg=message_template))
tagger = github.InputGitAuthor(
git_user,
git_email,
codetools.current_timestamp(),
)
debug("using taggger: {tagger}".format(tagger=tagger))
global g
g = pygithub.login_github(token_path=args.token_path, token=args.token)
org = g.get_organization(args.org)
info("tagging repos in org: {org}".format(org=org.login))
problems = []
manifest_products = versiondb.Manifest(
manifest,
base_url=args.versiondb_base_url).products
if not args.manifest_only:
eups_products = eups.EupsTag(
eups_tag,
base_url=args.eupstag_base_url).products
products, err = cross_reference_products(
eups_products,
manifest_products,
ignore_manifest_versions=args.ignore_manifest_versions,
fail_fast=False,
)
problems += err
else:
products = manifest_products
if args.limit:
products = dict(itertools.islice(products.items(), args.limit))
products, err = get_repo_for_products(
org=org,
products=products,
allow_teams=args.allow_team,
ext_teams=args.external_team,
deny_teams=args.deny_team,
fail_fast=False,
)
problems += err
products_to_tag, err = check_product_tags(
products,
git_tag,
tag_message_template=message_template,
tagger=tagger,
force_tag=args.force_tag,
fail_fast=False,
ignore_git_message=args.ignore_git_message,
ignore_git_tagger=args.ignore_git_tagger,
)
problems += err
if args.verify:
err = identify_products_missing_tags(products_to_tag)
problems += err
if problems:
msg = "{n} pre-flight error(s)".format(n=len(problems))
raise codetools.DogpileError(problems, msg)
tag_products(
products_to_tag,
fail_fast=args.fail_fast,
dry_run=args.dry_run,
)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'filter_seq'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '5', 'type': 'block', 'children': ['6', '8', '15', '26', '38', '44', '55', '66', '77', '88', '117', '131', '144']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'string', 'children': [], 'value': "'''Examines unreserved sequences to see if they are prone to mutation. This\n currently ignores solely-power-of-2 guides with b > 3'''"}; {'id': '8', 'type': 'if_statement', 'children': ['9', '12']}; {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '12', 'type': 'block', 'children': ['13']}; {'id': '13', 'type': 'return_statement', 'children': ['14']}; {'id': '14', 'type': 'None', 'children': []}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '18', 'type': 'call', 'children': ['19', '22']}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'nt'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'Factors'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'factors'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}; {'id': '27', 'type': 'assignment', 'children': ['28', '32']}; {'id': '28', 'type': 'pattern_list', 'children': ['29', '30', '31']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'guide'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '32', 'type': 'call', 'children': ['33', '36']}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'aq'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'canonical_form'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}; {'id': '39', 'type': 'assignment', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'guide'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'guide'}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}; {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'aq'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'get_class'}; {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'guide'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'guide'}; {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'num_larges'}; {'id': '58', 'type': 'call', 'children': ['59', '64']}; {'id': '59', 'type': 'attribute', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'factors'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}; {'id': '65', 'type': 'string', 'children': [], 'value': "'P'"}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}; {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'upper_bound_tau'}; {'id': '69', 'type': 'binary_operator', 'children': ['70', '73'], 'value': '-'}; {'id': '70', 'type': 'binary_operator', 'children': ['71', '72'], 'value': '-'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'num_larges'}; {'id': '73', 'type': 'call', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '77', 'type': 'if_statement', 'children': ['78', '85']}; {'id': '78', 'type': 'boolean_operator', 'children': ['79', '82'], 'value': 'or'}; {'id': '79', 'type': 'comparison_operator', 'children': ['80', '81'], 'value': '<'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '81', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '82', 'type': 'comparison_operator', 'children': ['83', '84'], 'value': '<'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'upper_bound_tau'}; {'id': '84', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '85', 'type': 'block', 'children': ['86']}; {'id': '86', 'type': 'return_statement', 'children': ['87']}; {'id': '87', 'type': 'None', 'children': []}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}; {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'nt'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'Factors'}; {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'dictionary_comprehension', 'children': ['97', '100', '109']}; {'id': '97', 'type': 'pair', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '100', 'type': 'for_in_clause', 'children': ['101', '104']}; {'id': '101', 'type': 'pattern_list', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '104', 'type': 'call', 'children': ['105', '108']}; {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'guide'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '108', 'type': 'argument_list', 'children': []}; {'id': '109', 'type': 'if_clause', 'children': ['110']}; {'id': '110', 'type': 'boolean_operator', 'children': ['111', '114'], 'value': 'and'}; {'id': '111', 'type': 'comparison_operator', 'children': ['112', '113'], 'value': '!='}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '113', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '114', 'type': 'comparison_operator', 'children': ['115', '116'], 'value': '>'}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '116', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '117', 'type': 'if_statement', 'children': ['118', '128']}; {'id': '118', 'type': 'boolean_operator', 'children': ['119', '125'], 'value': 'and'}; {'id': '119', 'type': 'comparison_operator', 'children': ['120', '124'], 'value': '=='}; {'id': '120', 'type': 'call', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '124', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '125', 'type': 'comparison_operator', 'children': ['126', '127'], 'value': '>'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '127', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '128', 'type': 'block', 'children': ['129']}; {'id': '129', 'type': 'return_statement', 'children': ['130']}; {'id': '130', 'type': 'None', 'children': []}; {'id': '131', 'type': 'if_statement', 'children': ['132', '141']}; {'id': '132', 'type': 'not_operator', 'children': ['133']}; {'id': '133', 'type': 'call', 'children': ['134', '137']}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'aq'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'is_driver'}; {'id': '137', 'type': 'argument_list', 'children': ['138']}; {'id': '138', 'type': 'keyword_argument', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'guide'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'guide'}; {'id': '141', 'type': 'block', 'children': ['142']}; {'id': '142', 'type': 'return_statement', 'children': ['143']}; {'id': '143', 'type': 'None', 'children': []}; {'id': '144', 'type': 'return_statement', 'children': ['145']}; {'id': '145', 'type': 'expression_list', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'guide'}
|
def filter_seq(seq):
'''Examines unreserved sequences to see if they are prone to mutation. This
currently ignores solely-power-of-2 guides with b > 3'''
if seq.res:
return None
n = nt.Factors(seq.factors)
guide, s, t = aq.canonical_form(n)
seq.guide = guide
cls = aq.get_class(guide=guide)
num_larges = seq.factors.count('P')
upper_bound_tau = cls - num_larges - len(t)
if cls < 2 or upper_bound_tau < 2:
return None
v = nt.Factors({p: a for p, a in guide.items() if p != 2 and a > 0})
if int(v) == 1 and cls > 3:
return None
if not aq.is_driver(guide=guide):
return None
return n, guide
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_data'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'filenames'}; {'id': '6', 'type': 'block', 'children': ['7', '56', '119', '170', '211', '352']}; {'id': '7', 'type': 'function_definition', 'children': ['8', '9', '11']}; {'id': '8', 'type': 'function_name', 'children': [], 'value': '_parse_table'}; {'id': '9', 'type': 'parameters', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '11', 'type': 'block', 'children': ['12', '24', '47']}; {'id': '12', 'type': 'function_definition', 'children': ['13', '14', '16']}; {'id': '13', 'type': 'function_name', 'children': [], 'value': '_parse_line'}; {'id': '14', 'type': 'parameters', 'children': ['15']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '16', 'type': 'block', 'children': ['17']}; {'id': '17', 'type': 'return_statement', 'children': ['18']}; {'id': '18', 'type': 'call', 'children': ['19', '22']}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}; {'id': '23', 'type': 'string', 'children': [], 'value': "'\\t'"}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}; {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'lines'}; {'id': '27', 'type': 'generator_expression', 'children': ['28', '32', '39']}; {'id': '28', 'type': 'call', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': '_parse_line'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'one'}; {'id': '32', 'type': 'for_in_clause', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'one'}; {'id': '34', 'type': 'call', 'children': ['35', '38']}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'splitlines'}; {'id': '38', 'type': 'argument_list', 'children': []}; {'id': '39', 'type': 'if_clause', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '44']}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '46']}; {'id': '45', 'type': 'string', 'children': [], 'value': "r'^\\d'"}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'one'}; {'id': '47', 'type': 'return_statement', 'children': ['48']}; {'id': '48', 'type': 'generator_expression', 'children': ['49', '53']}; {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'remove_false'}; {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'one'}; {'id': '53', 'type': 'for_in_clause', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'one'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'lines'}; {'id': '56', 'type': 'function_definition', 'children': ['57', '58', '60']}; {'id': '57', 'type': 'function_name', 'children': [], 'value': '_parse_decl'}; {'id': '58', 'type': 'parameters', 'children': ['59']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'decl'}; {'id': '60', 'type': 'block', 'children': ['61', '68', '74', '95', '101', '114']}; {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'assignment', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '64', 'type': 'call', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}; {'id': '67', 'type': 'string', 'children': [], 'value': "'SYSCALL_DEFINE'"}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}; {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'argc'}; {'id': '71', 'type': 'subscript', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'decl'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}; {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'rest'}; {'id': '77', 'type': 'call', 'children': ['78', '93']}; {'id': '78', 'type': 'attribute', 'children': ['79', '92']}; {'id': '79', 'type': 'subscript', 'children': ['80', '87']}; {'id': '80', 'type': 'subscript', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'decl'}; {'id': '82', 'type': 'slice', 'children': ['83', '86']}; {'id': '83', 'type': 'binary_operator', 'children': ['84', '85'], 'value': '+'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '85', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '86', 'type': 'colon', 'children': []}; {'id': '87', 'type': 'slice', 'children': ['88', '89', '90']}; {'id': '88', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '89', 'type': 'colon', 'children': []}; {'id': '90', 'type': 'unary_operator', 'children': ['91'], 'value': '-'}; {'id': '91', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'string', 'children': [], 'value': "','"}; {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '98', 'type': 'subscript', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'rest'}; {'id': '100', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '104', 'type': 'call', 'children': ['105', '108']}; {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'string', 'children': [], 'value': "','"}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}; {'id': '109', 'type': 'subscript', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'rest'}; {'id': '111', 'type': 'slice', 'children': ['112', '113']}; {'id': '112', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '113', 'type': 'colon', 'children': []}; {'id': '114', 'type': 'return_statement', 'children': ['115']}; {'id': '115', 'type': 'expression_list', 'children': ['116', '117', '118']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'argc'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '119', 'type': 'function_definition', 'children': ['120', '121', '123']}; {'id': '120', 'type': 'function_name', 'children': [], 'value': '_parse_line'}; {'id': '121', 'type': 'parameters', 'children': ['122']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '123', 'type': 'block', 'children': ['124', '133', '145', '153', '163']}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}; {'id': '125', 'type': 'assignment', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '127', 'type': 'call', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'find'}; {'id': '131', 'type': 'argument_list', 'children': ['132']}; {'id': '132', 'type': 'string', 'children': [], 'value': "':'"}; {'id': '133', 'type': 'if_statement', 'children': ['134', '138']}; {'id': '134', 'type': 'comparison_operator', 'children': ['135', '136'], 'value': '=='}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '136', 'type': 'unary_operator', 'children': ['137'], 'value': '-'}; {'id': '137', 'type': 'integer', 'children': [], 'value': '1'}; {'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': 'RuntimeError'}; {'id': '142', 'type': 'argument_list', 'children': ['143', '144']}; {'id': '143', 'type': 'string', 'children': [], 'value': "'This is unexpected: %s'"}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'assignment', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '148', 'type': 'subscript', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '150', 'type': 'slice', 'children': ['151', '152']}; {'id': '151', 'type': 'colon', 'children': []}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '153', 'type': 'expression_statement', 'children': ['154']}; {'id': '154', 'type': 'assignment', 'children': ['155', '156']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'decl'}; {'id': '156', 'type': 'subscript', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '158', 'type': 'slice', 'children': ['159', '162']}; {'id': '159', 'type': 'binary_operator', 'children': ['160', '161'], 'value': '+'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '161', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '162', 'type': 'colon', 'children': []}; {'id': '163', 'type': 'return_statement', 'children': ['164']}; {'id': '164', 'type': 'expression_list', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '166', 'type': 'call', 'children': ['167', '168']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': '_parse_decl'}; {'id': '168', 'type': 'argument_list', 'children': ['169']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'decl'}; {'id': '170', 'type': 'function_definition', 'children': ['171', '172', '174']}; {'id': '171', 'type': 'function_name', 'children': [], 'value': '_split_into_lines'}; {'id': '172', 'type': 'parameters', 'children': ['173']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'grep_output'}; {'id': '174', 'type': 'block', 'children': ['175', '185', '201']}; {'id': '175', 'type': 'expression_statement', 'children': ['176']}; {'id': '176', 'type': 'assignment', 'children': ['177', '178']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'lines'}; {'id': '178', 'type': 'call', 'children': ['179', '182']}; {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'grep_output'}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '182', 'type': 'argument_list', 'children': ['183', '184']}; {'id': '183', 'type': 'string', 'children': [], 'value': "'\\n\\n'"}; {'id': '184', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '185', 'type': 'expression_statement', 'children': ['186']}; {'id': '186', 'type': 'assignment', 'children': ['187', '188']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'lines'}; {'id': '188', 'type': 'call', 'children': ['189', '198']}; {'id': '189', 'type': 'attribute', 'children': ['190', '197']}; {'id': '190', 'type': 'call', 'children': ['191', '194']}; {'id': '191', 'type': 'attribute', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'lines'}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '194', 'type': 'argument_list', 'children': ['195', '196']}; {'id': '195', 'type': 'string', 'children': [], 'value': "'\\n\\t'"}; {'id': '196', 'type': 'string', 'children': [], 'value': "''"}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '198', 'type': 'argument_list', 'children': ['199', '200']}; {'id': '199', 'type': 'string', 'children': [], 'value': "'\\t'"}; {'id': '200', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '201', 'type': 'return_statement', 'children': ['202']}; {'id': '202', 'type': 'call', 'children': ['203', '210']}; {'id': '203', 'type': 'attribute', 'children': ['204', '209']}; {'id': '204', 'type': 'call', 'children': ['205', '208']}; {'id': '205', 'type': 'attribute', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'lines'}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '208', 'type': 'argument_list', 'children': []}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'splitlines'}; {'id': '210', 'type': 'argument_list', 'children': []}; {'id': '211', 'type': 'for_statement', 'children': ['212', '213', '214']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'one'}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'filenames'}; {'id': '214', 'type': 'block', 'children': ['215']}; {'id': '215', 'type': 'if_statement', 'children': ['216', '224', '300']}; {'id': '216', 'type': 'call', 'children': ['217', '222']}; {'id': '217', 'type': 'attribute', 'children': ['218', '221']}; {'id': '218', 'type': 'attribute', 'children': ['219', '220']}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'one'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'endswith'}; {'id': '222', 'type': 'argument_list', 'children': ['223']}; {'id': '223', 'type': 'string', 'children': [], 'value': "'.tbl'"}; {'id': '224', 'type': 'block', 'children': ['225']}; {'id': '225', 'type': 'for_statement', 'children': ['226', '227', '235']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '227', 'type': 'call', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': '_parse_table'}; {'id': '229', 'type': 'argument_list', 'children': ['230']}; {'id': '230', 'type': 'call', 'children': ['231', '234']}; {'id': '231', 'type': 'attribute', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'one'}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '234', 'type': 'argument_list', 'children': []}; {'id': '235', 'type': 'block', 'children': ['236', '243', '264']}; {'id': '236', 'type': 'expression_statement', 'children': ['237']}; {'id': '237', 'type': 'assignment', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '239', 'type': 'call', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '241', 'type': 'argument_list', 'children': ['242']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '243', 'type': 'if_statement', 'children': ['244', '250']}; {'id': '244', 'type': 'comparison_operator', 'children': ['245', '249'], 'value': '!='}; {'id': '245', 'type': 'call', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '247', 'type': 'argument_list', 'children': ['248']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '249', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '250', 'type': 'block', 'children': ['251']}; {'id': '251', 'type': 'expression_statement', 'children': ['252']}; {'id': '252', 'type': 'augmented_assignment', 'children': ['253', '254'], 'value': '+='}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '254', 'type': 'binary_operator', 'children': ['255', '257'], 'value': '*'}; {'id': '255', 'type': 'list', 'children': ['256'], 'value': "['']"}; {'id': '256', 'type': 'string', 'children': [], 'value': "''"}; {'id': '257', 'type': '()', 'children': ['258']}; {'id': '258', 'type': 'binary_operator', 'children': ['259', '260'], 'value': '-'}; {'id': '259', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '260', 'type': 'call', 'children': ['261', '262']}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '262', 'type': 'argument_list', 'children': ['263']}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '264', 'type': 'expression_statement', 'children': ['265']}; {'id': '265', 'type': 'call', 'children': ['266', '271']}; {'id': '266', 'type': 'attribute', 'children': ['267', '270']}; {'id': '267', 'type': 'attribute', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'session'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '271', 'type': 'argument_list', 'children': ['272']}; {'id': '272', 'type': 'call', 'children': ['273', '274']}; {'id': '273', 'type': 'identifier', 'children': [], 'value': 'Item'}; {'id': '274', 'type': 'argument_list', 'children': ['275', '280', '285', '290', '295']}; {'id': '275', 'type': 'keyword_argument', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '277', 'type': 'subscript', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '279', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '280', 'type': 'keyword_argument', 'children': ['281', '282']}; {'id': '281', 'type': 'identifier', 'children': [], 'value': 'abi'}; {'id': '282', 'type': 'subscript', 'children': ['283', '284']}; {'id': '283', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '284', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '285', 'type': 'keyword_argument', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'number'}; {'id': '287', 'type': 'subscript', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '289', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '290', 'type': 'keyword_argument', 'children': ['291', '292']}; {'id': '291', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '292', 'type': 'subscript', 'children': ['293', '294']}; {'id': '293', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '294', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '295', 'type': 'keyword_argument', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'compat'}; {'id': '297', 'type': 'subscript', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '299', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '300', 'type': 'else_clause', 'children': ['301']}; {'id': '301', 'type': 'block', 'children': ['302']}; {'id': '302', 'type': 'for_statement', 'children': ['303', '304', '312']}; {'id': '303', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '304', 'type': 'call', 'children': ['305', '306']}; {'id': '305', 'type': 'identifier', 'children': [], 'value': '_split_into_lines'}; {'id': '306', 'type': 'argument_list', 'children': ['307']}; {'id': '307', 'type': 'call', 'children': ['308', '311']}; {'id': '308', 'type': 'attribute', 'children': ['309', '310']}; {'id': '309', 'type': 'identifier', 'children': [], 'value': 'one'}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '311', 'type': 'argument_list', 'children': []}; {'id': '312', 'type': 'block', 'children': ['313', '323']}; {'id': '313', 'type': 'expression_statement', 'children': ['314']}; {'id': '314', 'type': 'assignment', 'children': ['315', '318']}; {'id': '315', 'type': 'pattern_list', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '317', 'type': 'identifier', 'children': [], 'value': 'rest'}; {'id': '318', 'type': '()', 'children': ['319']}; {'id': '319', 'type': 'call', 'children': ['320', '321']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': '_parse_line'}; {'id': '321', 'type': 'argument_list', 'children': ['322']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '323', 'type': 'expression_statement', 'children': ['324']}; {'id': '324', 'type': 'call', 'children': ['325', '330']}; {'id': '325', 'type': 'attribute', 'children': ['326', '329']}; {'id': '326', 'type': 'attribute', 'children': ['327', '328']}; {'id': '327', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'session'}; {'id': '329', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '330', 'type': 'argument_list', 'children': ['331']}; {'id': '331', 'type': 'call', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'Decl'}; {'id': '333', 'type': 'argument_list', 'children': ['334', '339', '342', '347']}; {'id': '334', 'type': 'keyword_argument', 'children': ['335', '336']}; {'id': '335', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '336', 'type': 'subscript', 'children': ['337', '338']}; {'id': '337', 'type': 'identifier', 'children': [], 'value': 'rest'}; {'id': '338', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '339', 'type': 'keyword_argument', 'children': ['340', '341']}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '341', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '342', 'type': 'keyword_argument', 'children': ['343', '344']}; {'id': '343', 'type': 'identifier', 'children': [], 'value': 'argc'}; {'id': '344', 'type': 'subscript', 'children': ['345', '346']}; {'id': '345', 'type': 'identifier', 'children': [], 'value': 'rest'}; {'id': '346', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '347', 'type': 'keyword_argument', 'children': ['348', '349']}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '349', 'type': 'subscript', 'children': ['350', '351']}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'rest'}; {'id': '351', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '352', 'type': 'expression_statement', 'children': ['353']}; {'id': '353', 'type': 'call', 'children': ['354', '359']}; {'id': '354', 'type': 'attribute', 'children': ['355', '358']}; {'id': '355', 'type': 'attribute', 'children': ['356', '357']}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '357', 'type': 'identifier', 'children': [], 'value': 'session'}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'commit'}; {'id': '359', 'type': 'argument_list', 'children': []}
|
def add_data(self, filenames):
def _parse_table(table):
def _parse_line(line):
return line.split('\t')
lines = (_parse_line(one) for one in table.splitlines()
if re.match(r'^\d', one))
return (remove_false(one) for one in lines)
def _parse_decl(decl):
index = len('SYSCALL_DEFINE')
argc = decl[index]
rest = decl[index + 1:][1:-1].split(',')
name = rest[0]
args = ','.join(rest[1:])
return name, argc, args
def _parse_line(line):
index = line.find(':')
if index == -1:
raise RuntimeError('This is unexpected: %s', line)
filename = line[:index]
decl = line[index + 1:]
return filename, _parse_decl(decl)
def _split_into_lines(grep_output):
lines = grep_output.replace('\n\n', '\n')
lines = lines.replace('\n\t', '').replace('\t', ' ')
return lines.strip().splitlines()
for one in filenames:
if one.name.endswith('.tbl'):
for item in _parse_table(one.read()):
args = list(item)
if len(args) != 5:
args += [''] * (5 - len(args))
self.session.add(
Item(name=args[2], abi=args[1],
number=args[0], entry=args[3],
compat=args[4]))
else:
for line in _split_into_lines(one.read()):
filename, rest = (_parse_line(line))
self.session.add(
Decl(name=rest[0], filename=filename,
argc=rest[1], args=rest[2]))
self.session.commit()
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'check_tags'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'repos'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'tags'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'ignore_existing'}; {'id': '8', 'type': 'False', 'children': []}; {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'fail_fast'}; {'id': '11', 'type': 'False', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13', '28', '44', '59', '77', '81', '85', '89', '201', '232']}; {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'call', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}; {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'string', 'children': [], 'value': '"looking for {n} tag(s):"'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'keyword_argument', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '24', 'type': 'call', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'tags'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}; {'id': '29', 'type': 'list_comprehension', 'children': ['30', '41']}; {'id': '30', 'type': 'call', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}; {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'string', 'children': [], 'value': '" {t}"'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '41', 'type': 'for_in_clause', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'tags'}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}; {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '52']}; {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'string', 'children': [], 'value': '"in {n} repo(s):"'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}; {'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '55', 'type': 'call', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'repos'}; {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'list_comprehension', 'children': ['61', '74']}; {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'call', 'children': ['65', '68']}; {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'string', 'children': [], 'value': '" {r}"'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}; {'id': '69', 'type': 'keyword_argument', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'full_name'}; {'id': '74', 'type': 'for_in_clause', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'repos'}; {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'present_tags'}; {'id': '80', 'type': 'dictionary', 'children': []}; {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'absent_tags'}; {'id': '84', 'type': 'dictionary', 'children': []}; {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'problems'}; {'id': '88', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '89', 'type': 'for_statement', 'children': ['90', '91', '92']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'repos'}; {'id': '92', 'type': 'block', 'children': ['93', '101', '172', '184']}; {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'has_tags'}; {'id': '96', 'type': 'call', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'find_tags_in_repo'}; {'id': '98', 'type': 'argument_list', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'tags'}; {'id': '101', 'type': 'if_statement', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'has_tags'}; {'id': '103', 'type': 'block', 'children': ['104', '151']}; {'id': '104', 'type': 'if_statement', 'children': ['105', '107']}; {'id': '105', 'type': 'not_operator', 'children': ['106']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'ignore_existing'}; {'id': '107', 'type': 'block', 'children': ['108', '134', '139', '146']}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}; {'id': '109', 'type': 'assignment', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'yikes'}; {'id': '111', 'type': 'call', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'GitTagExistsError'}; {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'call', 'children': ['115', '118']}; {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'string', 'children': [], 'value': '"tag(s) {tag} already exists in repos {r}"'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '118', 'type': 'argument_list', 'children': ['119', '129']}; {'id': '119', 'type': 'keyword_argument', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '121', 'type': 'call', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '123', 'type': 'argument_list', 'children': ['124']}; {'id': '124', 'type': 'call', 'children': ['125', '128']}; {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'has_tags'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '128', 'type': 'argument_list', 'children': []}; {'id': '129', 'type': 'keyword_argument', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'full_name'}; {'id': '134', 'type': 'if_statement', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'fail_fast'}; {'id': '136', 'type': 'block', 'children': ['137']}; {'id': '137', 'type': 'raise_statement', 'children': ['138']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'yikes'}; {'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': 'problems'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'yikes'}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}; {'id': '147', 'type': 'call', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '149', 'type': 'argument_list', 'children': ['150']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'yikes'}; {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'assignment', 'children': ['153', '158']}; {'id': '153', 'type': 'subscript', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'present_tags'}; {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'full_name'}; {'id': '158', 'type': 'dictionary', 'children': ['159', '162']}; {'id': '159', 'type': 'pair', 'children': ['160', '161']}; {'id': '160', 'type': 'string', 'children': [], 'value': "'repo'"}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '162', 'type': 'pair', 'children': ['163', '164']}; {'id': '163', 'type': 'string', 'children': [], 'value': "'tags'"}; {'id': '164', 'type': 'call', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '166', 'type': 'argument_list', 'children': ['167']}; {'id': '167', 'type': 'call', 'children': ['168', '171']}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'has_tags'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '171', 'type': 'argument_list', 'children': []}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}; {'id': '173', 'type': 'assignment', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'missing_tags'}; {'id': '175', 'type': 'list_comprehension', 'children': ['176', '177', '180']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '177', 'type': 'for_in_clause', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'tags'}; {'id': '180', 'type': 'if_clause', 'children': ['181']}; {'id': '181', 'type': 'comparison_operator', 'children': ['182', '183'], 'value': 'not'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'has_tags'}; {'id': '184', 'type': 'if_statement', 'children': ['185', '186']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'missing_tags'}; {'id': '186', 'type': 'block', 'children': ['187']}; {'id': '187', 'type': 'expression_statement', 'children': ['188']}; {'id': '188', 'type': 'assignment', 'children': ['189', '194']}; {'id': '189', 'type': 'subscript', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'absent_tags'}; {'id': '191', 'type': 'attribute', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'full_name'}; {'id': '194', 'type': 'dictionary', 'children': ['195', '198']}; {'id': '195', 'type': 'pair', 'children': ['196', '197']}; {'id': '196', 'type': 'string', 'children': [], 'value': "'repo'"}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '198', 'type': 'pair', 'children': ['199', '200']}; {'id': '199', 'type': 'string', 'children': [], 'value': "'need_tags'"}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'missing_tags'}; {'id': '201', 'type': 'expression_statement', 'children': ['202']}; {'id': '202', 'type': 'call', 'children': ['203', '204']}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '204', 'type': 'argument_list', 'children': ['205']}; {'id': '205', 'type': 'call', 'children': ['206', '213']}; {'id': '206', 'type': 'attribute', 'children': ['207', '212']}; {'id': '207', 'type': 'call', 'children': ['208', '211']}; {'id': '208', 'type': 'attribute', 'children': ['209', '210']}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'textwrap'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'dedent'}; {'id': '211', 'type': 'argument_list', 'children': []}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '213', 'type': 'argument_list', 'children': ['214', '220', '226']}; {'id': '214', 'type': 'keyword_argument', 'children': ['215', '216']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'n_with'}; {'id': '216', 'type': 'call', 'children': ['217', '218']}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '218', 'type': 'argument_list', 'children': ['219']}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'present_tags'}; {'id': '220', 'type': 'keyword_argument', 'children': ['221', '222']}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'n_none'}; {'id': '222', 'type': 'call', 'children': ['223', '224']}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '224', 'type': 'argument_list', 'children': ['225']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'absent_tags'}; {'id': '226', 'type': 'keyword_argument', 'children': ['227', '228']}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '228', 'type': 'call', 'children': ['229', '230']}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '230', 'type': 'argument_list', 'children': ['231']}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'problems'}; {'id': '232', 'type': 'return_statement', 'children': ['233']}; {'id': '233', 'type': 'expression_list', 'children': ['234', '235', '236']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'present_tags'}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'absent_tags'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'problems'}
|
def check_tags(repos, tags, ignore_existing=False, fail_fast=False):
debug("looking for {n} tag(s):".format(n=len(tags)))
[debug(" {t}".format(t=t)) for t in tags]
debug("in {n} repo(s):".format(n=len(repos)))
[debug(" {r}".format(r=r.full_name)) for r in repos]
present_tags = {}
absent_tags = {}
problems = []
for r in repos:
has_tags = find_tags_in_repo(r, tags)
if has_tags:
if not ignore_existing:
yikes = GitTagExistsError(
"tag(s) {tag} already exists in repos {r}".format(
tag=list(has_tags.keys()),
r=r.full_name
))
if fail_fast:
raise yikes
problems.append(yikes)
error(yikes)
present_tags[r.full_name] = {
'repo': r,
'tags': list(has_tags.values()),
}
missing_tags = [x for x in tags if x not in has_tags]
if missing_tags:
absent_tags[r.full_name] = {
'repo': r,
'need_tags': missing_tags,
}
debug(textwrap.dedent(
).format(
n_with=len(present_tags),
n_none=len(absent_tags),
errors=len(problems),
))
return present_tags, absent_tags, problems
|
{'id': '0', 'type': 'module', 'children': ['1', '42', '44', '46', '48', '50', '52', '54', '56', '58', '61', '82']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8', '37', '39']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'getmlsthelper'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'referencefilepath'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'organism'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '8', 'type': 'ERROR', 'children': ['9', '36']}; {'id': '9', 'type': 'ERROR', 'children': ['10', '16', '22', '31', '32', '33', '35']}; {'id': '10', 'type': 'import_from_statement', 'children': ['11', '14']}; {'id': '11', 'type': 'dotted_name', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'accessoryFunctions'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'accessoryFunctions'}; {'id': '14', 'type': 'dotted_name', 'children': ['15']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'GenObject'}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'organismset'}; {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '21', 'type': 'argument_list', 'children': []}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'organism'}; {'id': '25', 'type': 'conditional_expression', 'children': ['26', '27', '30'], 'value': 'if'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'organism'}; {'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': '!='}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'organism'}; {'id': '29', 'type': 'string', 'children': [], 'value': "'Shigella'"}; {'id': '30', 'type': 'string', 'children': [], 'value': "'Escherichia'"}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'organismdictionary'}; {'id': '32', 'type': 'string', 'children': [], 'value': "'Escherichia'"}; {'id': '33', 'type': 'ERROR', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'Escherichia'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'coli'}; {'id': '36', 'type': 'string', 'children': [], 'value': "'Shigella'"}; {'id': '37', 'type': 'ERROR', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'Escherichia'}; {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'coli'}; {'id': '42', 'type': 'ERROR', 'children': ['43']}; {'id': '43', 'type': 'string', 'children': [], 'value': "'Vibrio'"}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}; {'id': '45', 'type': 'string', 'children': [], 'value': "'Vibrio parahaemolyticus'"}; {'id': '46', 'type': 'ERROR', 'children': ['47']}; {'id': '47', 'type': 'string', 'children': [], 'value': "'Campylobacter'"}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}; {'id': '49', 'type': 'string', 'children': [], 'value': "'Campylobacter jejuni'"}; {'id': '50', 'type': 'ERROR', 'children': ['51']}; {'id': '51', 'type': 'string', 'children': [], 'value': "'Listeria'"}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}; {'id': '53', 'type': 'string', 'children': [], 'value': "'Listeria monocytogenes'"}; {'id': '54', 'type': 'ERROR', 'children': ['55']}; {'id': '55', 'type': 'string', 'children': [], 'value': "'Bacillus'"}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}; {'id': '57', 'type': 'string', 'children': [], 'value': "'Bacillus cereus'"}; {'id': '58', 'type': 'ERROR', 'children': ['59', '60']}; {'id': '59', 'type': 'string', 'children': [], 'value': "'Klebsiella'"}; {'id': '60', 'type': 'string', 'children': [], 'value': "'Klebsiella pneumoniae'"}; {'id': '61', 'type': 'try_statement', 'children': ['62', '72']}; {'id': '62', 'type': 'block', 'children': ['63']}; {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'call', 'children': ['65', '68']}; {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'organismset'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}; {'id': '69', 'type': 'subscript', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'organismdictionary'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'organism'}; {'id': '72', 'type': 'except_clause', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '74', 'type': 'block', 'children': ['75']}; {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'call', 'children': ['77', '80']}; {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'organismset'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'organism'}; {'id': '82', 'type': 'for_statement', 'children': ['83', '84', '85', '384']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'scheme'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'organismset'}; {'id': '85', 'type': 'ERROR', 'children': ['86']}; {'id': '86', 'type': 'block', 'children': ['87', '100', '132', '142', '152', '284', '338', '382']}; {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'organismpath'}; {'id': '90', 'type': 'call', 'children': ['91', '96']}; {'id': '91', 'type': 'attribute', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '96', 'type': 'argument_list', 'children': ['97', '98', '99']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'referencefilepath'}; {'id': '98', 'type': 'string', 'children': [], 'value': "'MLST'"}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'organism'}; {'id': '100', 'type': 'try_statement', 'children': ['101', '125']}; {'id': '101', 'type': 'block', 'children': ['102']}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}; {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'lastfolder'}; {'id': '105', 'type': 'call', 'children': ['106', '123']}; {'id': '106', 'type': 'attribute', 'children': ['107', '122']}; {'id': '107', 'type': 'subscript', 'children': ['108', '120']}; {'id': '108', 'type': 'call', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}; {'id': '111', 'type': 'call', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'glob'}; {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'call', 'children': ['115', '118']}; {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'string', 'children': [], 'value': "'{}/*/'"}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'organismpath'}; {'id': '120', 'type': 'unary_operator', 'children': ['121'], 'value': '-'}; {'id': '121', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'rstrip'}; {'id': '123', 'type': 'argument_list', 'children': ['124']}; {'id': '124', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '125', 'type': 'except_clause', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'IndexError'}; {'id': '127', 'type': 'block', 'children': ['128']}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}; {'id': '129', 'type': 'assignment', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'lastfolder'}; {'id': '131', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}; {'id': '133', 'type': 'assignment', 'children': ['134', '138']}; {'id': '134', 'type': 'pattern_list', 'children': ['135', '136', '137']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'delta'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'foldersize'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'd1'}; {'id': '138', 'type': 'call', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'schemedate'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'lastfolder'}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}; {'id': '143', 'type': 'assignment', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'newfolder'}; {'id': '145', 'type': 'call', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}; {'id': '147', 'type': 'string', 'children': [], 'value': "'{}/{}'"}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '149', 'type': 'argument_list', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'organismpath'}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'd1'}; {'id': '152', 'type': 'if_statement', 'children': ['153', '154', '278']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '154', 'type': 'block', 'children': ['155']}; {'id': '155', 'type': 'if_statement', 'children': ['156', '165', '272']}; {'id': '156', 'type': 'boolean_operator', 'children': ['157', '162'], 'value': 'or'}; {'id': '157', 'type': 'comparison_operator', 'children': ['158', '161'], 'value': '>'}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'delta'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'days'}; {'id': '161', 'type': 'integer', 'children': [], 'value': '7'}; {'id': '162', 'type': 'comparison_operator', 'children': ['163', '164'], 'value': '<'}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'foldersize'}; {'id': '164', 'type': 'integer', 'children': [], 'value': '100'}; {'id': '165', 'type': 'block', 'children': ['166', '177', '183', '189', '195', '201', '207', '214', '221', '251']}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}; {'id': '167', 'type': 'call', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'printtime'}; {'id': '169', 'type': 'argument_list', 'children': ['170', '176']}; {'id': '170', 'type': 'call', 'children': ['171', '174']}; {'id': '171', 'type': 'attribute', 'children': ['172', '173']}; {'id': '172', 'type': 'string', 'children': [], 'value': "'Downloading {} MLST scheme from pubmlst.org'"}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '174', 'type': 'argument_list', 'children': ['175']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'organism'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '177', 'type': 'expression_statement', 'children': ['178']}; {'id': '178', 'type': 'assignment', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'getmlstargs'}; {'id': '180', 'type': 'call', 'children': ['181', '182']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'GenObject'}; {'id': '182', 'type': 'argument_list', 'children': []}; {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'assignment', 'children': ['185', '188']}; {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'getmlstargs'}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'species'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'scheme'}; {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'assignment', 'children': ['191', '194']}; {'id': '191', 'type': 'attribute', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'getmlstargs'}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'repository_url'}; {'id': '194', 'type': 'string', 'children': [], 'value': "'http://pubmlst.org/data/dbases.xml'"}; {'id': '195', 'type': 'expression_statement', 'children': ['196']}; {'id': '196', 'type': 'assignment', 'children': ['197', '200']}; {'id': '197', 'type': 'attribute', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'getmlstargs'}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'force_scheme_name'}; {'id': '200', 'type': 'False', 'children': []}; {'id': '201', 'type': 'expression_statement', 'children': ['202']}; {'id': '202', 'type': 'assignment', 'children': ['203', '206']}; {'id': '203', 'type': 'attribute', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'getmlstargs'}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'newfolder'}; {'id': '207', 'type': 'expression_statement', 'children': ['208']}; {'id': '208', 'type': 'call', 'children': ['209', '210']}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'make_path'}; {'id': '210', 'type': 'argument_list', 'children': ['211']}; {'id': '211', 'type': 'attribute', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'getmlstargs'}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '214', 'type': 'expression_statement', 'children': ['215']}; {'id': '215', 'type': 'call', 'children': ['216', '219']}; {'id': '216', 'type': 'attribute', 'children': ['217', '218']}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'getmlst'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'main'}; {'id': '219', 'type': 'argument_list', 'children': ['220']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'getmlstargs'}; {'id': '221', 'type': 'try_statement', 'children': ['222', '244']}; {'id': '222', 'type': 'block', 'children': ['223']}; {'id': '223', 'type': 'expression_statement', 'children': ['224']}; {'id': '224', 'type': 'assignment', 'children': ['225', '226']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'profilestart'}; {'id': '226', 'type': 'call', 'children': ['227', '243']}; {'id': '227', 'type': 'attribute', 'children': ['228', '242']}; {'id': '228', 'type': 'call', 'children': ['229', '230']}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '230', 'type': 'argument_list', 'children': ['231']}; {'id': '231', 'type': 'subscript', 'children': ['232', '241']}; {'id': '232', 'type': 'call', 'children': ['233', '234']}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'glob'}; {'id': '234', 'type': 'argument_list', 'children': ['235']}; {'id': '235', 'type': 'call', 'children': ['236', '239']}; {'id': '236', 'type': 'attribute', 'children': ['237', '238']}; {'id': '237', 'type': 'string', 'children': [], 'value': "'{}/*.txt'"}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '239', 'type': 'argument_list', 'children': ['240']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'newfolder'}; {'id': '241', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'readline'}; {'id': '243', 'type': 'argument_list', 'children': []}; {'id': '244', 'type': 'except_clause', 'children': ['245', '246']}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'IndexError'}; {'id': '246', 'type': 'block', 'children': ['247']}; {'id': '247', 'type': 'expression_statement', 'children': ['248']}; {'id': '248', 'type': 'assignment', 'children': ['249', '250']}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'profilestart'}; {'id': '250', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '251', 'type': 'if_statement', 'children': ['252', '260']}; {'id': '252', 'type': 'boolean_operator', 'children': ['253', '255'], 'value': 'or'}; {'id': '253', 'type': 'not_operator', 'children': ['254']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'profilestart'}; {'id': '255', 'type': 'comparison_operator', 'children': ['256', '259'], 'value': '=='}; {'id': '256', 'type': 'subscript', 'children': ['257', '258']}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'profilestart'}; {'id': '258', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '259', 'type': 'string', 'children': [], 'value': "'<'"}; {'id': '260', 'type': 'block', 'children': ['261', '268']}; {'id': '261', 'type': 'expression_statement', 'children': ['262']}; {'id': '262', 'type': 'call', 'children': ['263', '266']}; {'id': '263', 'type': 'attribute', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'shutil'}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'rmtree'}; {'id': '266', 'type': 'argument_list', 'children': ['267']}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'newfolder'}; {'id': '268', 'type': 'expression_statement', 'children': ['269']}; {'id': '269', 'type': 'assignment', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'newfolder'}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'lastfolder'}; {'id': '272', 'type': 'else_clause', 'children': ['273']}; {'id': '273', 'type': 'block', 'children': ['274']}; {'id': '274', 'type': 'expression_statement', 'children': ['275']}; {'id': '275', 'type': 'assignment', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'newfolder'}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'lastfolder'}; {'id': '278', 'type': 'else_clause', 'children': ['279']}; {'id': '279', 'type': 'block', 'children': ['280']}; {'id': '280', 'type': 'expression_statement', 'children': ['281']}; {'id': '281', 'type': 'assignment', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'newfolder'}; {'id': '283', 'type': 'identifier', 'children': [], 'value': 'lastfolder'}; {'id': '284', 'type': 'try_statement', 'children': ['285', '329']}; {'id': '285', 'type': 'block', 'children': ['286']}; {'id': '286', 'type': 'expression_statement', 'children': ['287']}; {'id': '287', 'type': 'assignment', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'newfoldersize'}; {'id': '289', 'type': 'call', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '291', 'type': 'generator_expression', 'children': ['292', '306', '314']}; {'id': '292', 'type': 'call', 'children': ['293', '298']}; {'id': '293', 'type': 'attribute', 'children': ['294', '297']}; {'id': '294', 'type': 'attribute', 'children': ['295', '296']}; {'id': '295', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '297', 'type': 'identifier', 'children': [], 'value': 'getsize'}; {'id': '298', 'type': 'argument_list', 'children': ['299']}; {'id': '299', 'type': 'call', 'children': ['300', '303']}; {'id': '300', 'type': 'attribute', 'children': ['301', '302']}; {'id': '301', 'type': 'string', 'children': [], 'value': "'{}/{}'"}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '303', 'type': 'argument_list', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'newfolder'}; {'id': '305', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '306', 'type': 'for_in_clause', 'children': ['307', '308']}; {'id': '307', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '308', 'type': 'call', 'children': ['309', '312']}; {'id': '309', 'type': 'attribute', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '311', 'type': 'identifier', 'children': [], 'value': 'listdir'}; {'id': '312', 'type': 'argument_list', 'children': ['313']}; {'id': '313', 'type': 'identifier', 'children': [], 'value': 'newfolder'}; {'id': '314', 'type': 'if_clause', 'children': ['315']}; {'id': '315', 'type': 'call', 'children': ['316', '321']}; {'id': '316', 'type': 'attribute', 'children': ['317', '320']}; {'id': '317', 'type': 'attribute', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '319', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'isfile'}; {'id': '321', 'type': 'argument_list', 'children': ['322']}; {'id': '322', 'type': 'call', 'children': ['323', '326']}; {'id': '323', 'type': 'attribute', 'children': ['324', '325']}; {'id': '324', 'type': 'string', 'children': [], 'value': "'{}/{}'"}; {'id': '325', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '326', 'type': 'argument_list', 'children': ['327', '328']}; {'id': '327', 'type': 'identifier', 'children': [], 'value': 'newfolder'}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '329', 'type': 'except_clause', 'children': ['330', '333']}; {'id': '330', 'type': 'tuple', 'children': ['331', '332']}; {'id': '331', 'type': 'identifier', 'children': [], 'value': 'OSError'}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '333', 'type': 'block', 'children': ['334']}; {'id': '334', 'type': 'expression_statement', 'children': ['335']}; {'id': '335', 'type': 'assignment', 'children': ['336', '337']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'newfoldersize'}; {'id': '337', 'type': 'integer', 'children': [], 'value': '100'}; {'id': '338', 'type': 'if_statement', 'children': ['339', '342']}; {'id': '339', 'type': 'comparison_operator', 'children': ['340', '341'], 'value': '<'}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'newfoldersize'}; {'id': '341', 'type': 'integer', 'children': [], 'value': '100'}; {'id': '342', 'type': 'block', 'children': ['343', '350']}; {'id': '343', 'type': 'expression_statement', 'children': ['344']}; {'id': '344', 'type': 'call', 'children': ['345', '348']}; {'id': '345', 'type': 'attribute', 'children': ['346', '347']}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'shutil'}; {'id': '347', 'type': 'identifier', 'children': [], 'value': 'rmtree'}; {'id': '348', 'type': 'argument_list', 'children': ['349']}; {'id': '349', 'type': 'identifier', 'children': [], 'value': 'newfolder'}; {'id': '350', 'type': 'try_statement', 'children': ['351', '375']}; {'id': '351', 'type': 'block', 'children': ['352']}; {'id': '352', 'type': 'expression_statement', 'children': ['353']}; {'id': '353', 'type': 'assignment', 'children': ['354', '355']}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'newfolder'}; {'id': '355', 'type': 'call', 'children': ['356', '373']}; {'id': '356', 'type': 'attribute', 'children': ['357', '372']}; {'id': '357', 'type': 'subscript', 'children': ['358', '370']}; {'id': '358', 'type': 'call', 'children': ['359', '360']}; {'id': '359', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '360', 'type': 'argument_list', 'children': ['361']}; {'id': '361', 'type': 'call', 'children': ['362', '363']}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'glob'}; {'id': '363', 'type': 'argument_list', 'children': ['364']}; {'id': '364', 'type': 'call', 'children': ['365', '368']}; {'id': '365', 'type': 'attribute', 'children': ['366', '367']}; {'id': '366', 'type': 'string', 'children': [], 'value': "'{}/*/'"}; {'id': '367', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '368', 'type': 'argument_list', 'children': ['369']}; {'id': '369', 'type': 'identifier', 'children': [], 'value': 'organismpath'}; {'id': '370', 'type': 'unary_operator', 'children': ['371'], 'value': '-'}; {'id': '371', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'rstrip'}; {'id': '373', 'type': 'argument_list', 'children': ['374']}; {'id': '374', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '375', 'type': 'except_clause', 'children': ['376', '377']}; {'id': '376', 'type': 'identifier', 'children': [], 'value': 'IndexError'}; {'id': '377', 'type': 'block', 'children': ['378']}; {'id': '378', 'type': 'expression_statement', 'children': ['379']}; {'id': '379', 'type': 'assignment', 'children': ['380', '381']}; {'id': '380', 'type': 'identifier', 'children': [], 'value': 'newfolder'}; {'id': '381', 'type': 'identifier', 'children': [], 'value': 'organismpath'}; {'id': '382', 'type': 'return_statement', 'children': ['383']}; {'id': '383', 'type': 'identifier', 'children': [], 'value': 'newfolder'}; {'id': '384', 'type': 'block', 'children': [], 'value': ''}
|
def getmlsthelper(referencefilepath, start, organism, update):
from accessoryFunctions.accessoryFunctions import GenObject
organismset = set()
organism = organism if organism != 'Shigella' else 'Escherichia'
organismdictionary = {'Escherichia': 'Escherichia coli
'Shigella': 'Escherichia coli
'Vibrio': 'Vibrio parahaemolyticus',
'Campylobacter': 'Campylobacter jejuni',
'Listeria': 'Listeria monocytogenes',
'Bacillus': 'Bacillus cereus',
'Klebsiella': 'Klebsiella pneumoniae'}
try:
organismset.add(organismdictionary[organism])
except KeyError:
organismset.add(organism)
for scheme in organismset:
organismpath = os.path.join(referencefilepath, 'MLST', organism)
try:
lastfolder = sorted(glob('{}/*/'.format(organismpath)))[-1].rstrip('/')
except IndexError:
lastfolder = []
delta, foldersize, d1 = schemedate(lastfolder)
newfolder = '{}/{}'.format(organismpath, d1)
if update:
if delta.days > 7 or foldersize < 100:
printtime('Downloading {} MLST scheme from pubmlst.org'.format(organism), start)
getmlstargs = GenObject()
getmlstargs.species = scheme
getmlstargs.repository_url = 'http://pubmlst.org/data/dbases.xml'
getmlstargs.force_scheme_name = False
getmlstargs.path = newfolder
make_path(getmlstargs.path)
getmlst.main(getmlstargs)
try:
profilestart = open(glob('{}/*.txt'.format(newfolder))[0]).readline()
except IndexError:
profilestart = []
if not profilestart or profilestart[0] == '<':
shutil.rmtree(newfolder)
newfolder = lastfolder
else:
newfolder = lastfolder
else:
newfolder = lastfolder
try:
newfoldersize = sum(os.path.getsize('{}/{}'.format(newfolder, f)) for f in os.listdir(newfolder)
if os.path.isfile('{}/{}'.format(newfolder, f)))
except (OSError, TypeError):
newfoldersize = 100
if newfoldersize < 100:
shutil.rmtree(newfolder)
try:
newfolder = sorted(glob('{}/*/'.format(organismpath)))[-1].rstrip('/')
except IndexError:
newfolder = organismpath
return newfolder
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'set'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '7', 'type': 'block', 'children': ['8', '16', '32', '56', '115', '131', '139', '152', '165', '178', '191', '204', '217', '230', '245', '258', '271', '284', '297', '310']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'call', 'children': ['10', '15']}; {'id': '10', 'type': 'attribute', 'children': ['11', '14']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'player_lock'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'acquire'}; {'id': '15', 'type': 'argument_list', 'children': []}; {'id': '16', 'type': 'if_statement', 'children': ['17', '20']}; {'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': 'in'}; {'id': '18', 'type': 'string', 'children': [], 'value': "'acqtime'"}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '20', 'type': 'block', 'children': ['21']}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'call', 'children': ['23', '28']}; {'id': '23', 'type': 'attribute', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'player'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'set_aidur'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}; {'id': '29', 'type': 'subscript', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '31', 'type': 'string', 'children': [], 'value': "'acqtime'"}; {'id': '32', 'type': 'if_statement', 'children': ['33', '36']}; {'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': 'in'}; {'id': '34', 'type': 'string', 'children': [], 'value': "'aifs'"}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '36', 'type': 'block', 'children': ['37', '48']}; {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'call', 'children': ['39', '44']}; {'id': '39', 'type': 'attribute', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'player'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'set_aifs'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}; {'id': '45', 'type': 'subscript', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '47', 'type': 'string', 'children': [], 'value': "'aifs'"}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}; {'id': '49', 'type': 'assignment', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'aifs'}; {'id': '53', 'type': 'subscript', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '55', 'type': 'string', 'children': [], 'value': "'aifs'"}; {'id': '56', 'type': 'if_statement', 'children': ['57', '64']}; {'id': '57', 'type': 'boolean_operator', 'children': ['58', '61'], 'value': 'or'}; {'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': 'in'}; {'id': '59', 'type': 'string', 'children': [], 'value': "'aifs'"}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': 'in'}; {'id': '62', 'type': 'string', 'children': [], 'value': "'acqtime'"}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '64', 'type': 'block', 'children': ['65', '81', '102']}; {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '68', 'type': 'call', 'children': ['69', '72']}; {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '72', 'type': 'argument_list', 'children': ['73', '74']}; {'id': '73', 'type': 'string', 'children': [], 'value': "'acqtime'"}; {'id': '74', 'type': 'call', 'children': ['75', '80']}; {'id': '75', 'type': 'attribute', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'player'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'get_aidur'}; {'id': '80', 'type': 'argument_list', 'children': []}; {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'npoints'}; {'id': '84', 'type': 'binary_operator', 'children': ['85', '86'], 'value': '*'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '86', 'type': 'call', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}; {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '93', 'type': 'argument_list', 'children': ['94', '95']}; {'id': '94', 'type': 'string', 'children': [], 'value': "'aifs'"}; {'id': '95', 'type': 'call', 'children': ['96', '101']}; {'id': '96', 'type': 'attribute', 'children': ['97', '100']}; {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'player'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'get_aifs'}; {'id': '101', 'type': 'argument_list', 'children': []}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}; {'id': '103', 'type': 'assignment', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'aitimes'}; {'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': 'linspace'}; {'id': '111', 'type': 'argument_list', 'children': ['112', '113', '114']}; {'id': '112', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'npoints'}; {'id': '115', 'type': 'if_statement', 'children': ['116', '119']}; {'id': '116', 'type': 'comparison_operator', 'children': ['117', '118'], 'value': 'in'}; {'id': '117', 'type': 'string', 'children': [], 'value': "'trigger'"}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '119', 'type': 'block', 'children': ['120']}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}; {'id': '121', 'type': 'call', 'children': ['122', '127']}; {'id': '122', 'type': 'attribute', 'children': ['123', '126']}; {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'player'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'set_trigger'}; {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'subscript', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '130', 'type': 'string', 'children': [], 'value': "'trigger'"}; {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'call', 'children': ['133', '138']}; {'id': '133', 'type': 'attribute', 'children': ['134', '137']}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'player_lock'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'release'}; {'id': '138', 'type': 'argument_list', 'children': []}; {'id': '139', 'type': 'if_statement', 'children': ['140', '143']}; {'id': '140', 'type': 'comparison_operator', 'children': ['141', '142'], 'value': 'in'}; {'id': '141', 'type': 'string', 'children': [], 'value': "'aochan'"}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '143', 'type': 'block', 'children': ['144']}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}; {'id': '145', 'type': 'assignment', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'aochan'}; {'id': '149', 'type': 'subscript', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '151', 'type': 'string', 'children': [], 'value': "'aochan'"}; {'id': '152', 'type': 'if_statement', 'children': ['153', '156']}; {'id': '153', 'type': 'comparison_operator', 'children': ['154', '155'], 'value': 'in'}; {'id': '154', 'type': 'string', 'children': [], 'value': "'aichan'"}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '156', 'type': 'block', 'children': ['157']}; {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'assignment', 'children': ['159', '162']}; {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'aichan'}; {'id': '162', 'type': 'subscript', 'children': ['163', '164']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '164', 'type': 'string', 'children': [], 'value': "'aichan'"}; {'id': '165', 'type': 'if_statement', 'children': ['166', '169']}; {'id': '166', 'type': 'comparison_operator', 'children': ['167', '168'], 'value': 'in'}; {'id': '167', 'type': 'string', 'children': [], 'value': "'binsz'"}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '169', 'type': 'block', 'children': ['170']}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}; {'id': '171', 'type': 'assignment', 'children': ['172', '175']}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'binsz'}; {'id': '175', 'type': 'subscript', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '177', 'type': 'string', 'children': [], 'value': "'binsz'"}; {'id': '178', 'type': 'if_statement', 'children': ['179', '182']}; {'id': '179', 'type': 'comparison_operator', 'children': ['180', '181'], 'value': 'in'}; {'id': '180', 'type': 'string', 'children': [], 'value': "'save'"}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '182', 'type': 'block', 'children': ['183']}; {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'assignment', 'children': ['185', '188']}; {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'save_data'}; {'id': '188', 'type': 'subscript', 'children': ['189', '190']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '190', 'type': 'string', 'children': [], 'value': "'save'"}; {'id': '191', 'type': 'if_statement', 'children': ['192', '195']}; {'id': '192', 'type': 'comparison_operator', 'children': ['193', '194'], 'value': 'in'}; {'id': '193', 'type': 'string', 'children': [], 'value': "'caldb'"}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '195', 'type': 'block', 'children': ['196']}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}; {'id': '197', 'type': 'assignment', 'children': ['198', '201']}; {'id': '198', 'type': 'attribute', 'children': ['199', '200']}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'caldb'}; {'id': '201', 'type': 'subscript', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '203', 'type': 'string', 'children': [], 'value': "'caldb'"}; {'id': '204', 'type': 'if_statement', 'children': ['205', '208']}; {'id': '205', 'type': 'comparison_operator', 'children': ['206', '207'], 'value': 'in'}; {'id': '206', 'type': 'string', 'children': [], 'value': "'calv'"}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '208', 'type': 'block', 'children': ['209']}; {'id': '209', 'type': 'expression_statement', 'children': ['210']}; {'id': '210', 'type': 'assignment', 'children': ['211', '214']}; {'id': '211', 'type': 'attribute', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'calv'}; {'id': '214', 'type': 'subscript', 'children': ['215', '216']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '216', 'type': 'string', 'children': [], 'value': "'calv'"}; {'id': '217', 'type': 'if_statement', 'children': ['218', '221']}; {'id': '218', 'type': 'comparison_operator', 'children': ['219', '220'], 'value': 'in'}; {'id': '219', 'type': 'string', 'children': [], 'value': "'calf'"}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '221', 'type': 'block', 'children': ['222']}; {'id': '222', 'type': 'expression_statement', 'children': ['223']}; {'id': '223', 'type': 'assignment', 'children': ['224', '227']}; {'id': '224', 'type': 'attribute', 'children': ['225', '226']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'calf'}; {'id': '227', 'type': 'subscript', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '229', 'type': 'string', 'children': [], 'value': "'calf'"}; {'id': '230', 'type': 'if_statement', 'children': ['231', '238']}; {'id': '231', 'type': 'boolean_operator', 'children': ['232', '235'], 'value': 'or'}; {'id': '232', 'type': 'comparison_operator', 'children': ['233', '234'], 'value': 'in'}; {'id': '233', 'type': 'string', 'children': [], 'value': "'caldb'"}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '235', 'type': 'comparison_operator', 'children': ['236', '237'], 'value': 'in'}; {'id': '236', 'type': 'string', 'children': [], 'value': "'calv'"}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '238', 'type': 'block', 'children': ['239']}; {'id': '239', 'type': 'expression_statement', 'children': ['240']}; {'id': '240', 'type': 'call', 'children': ['241', '244']}; {'id': '241', 'type': 'attribute', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'update_reference_voltage'}; {'id': '244', 'type': 'argument_list', 'children': []}; {'id': '245', 'type': 'if_statement', 'children': ['246', '249']}; {'id': '246', 'type': 'comparison_operator', 'children': ['247', '248'], 'value': 'in'}; {'id': '247', 'type': 'string', 'children': [], 'value': "'datafile'"}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '249', 'type': 'block', 'children': ['250']}; {'id': '250', 'type': 'expression_statement', 'children': ['251']}; {'id': '251', 'type': 'assignment', 'children': ['252', '255']}; {'id': '252', 'type': 'attribute', 'children': ['253', '254']}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'datafile'}; {'id': '255', 'type': 'subscript', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '257', 'type': 'string', 'children': [], 'value': "'datafile'"}; {'id': '258', 'type': 'if_statement', 'children': ['259', '262']}; {'id': '259', 'type': 'comparison_operator', 'children': ['260', '261'], 'value': 'in'}; {'id': '260', 'type': 'string', 'children': [], 'value': "'reprate'"}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '262', 'type': 'block', 'children': ['263']}; {'id': '263', 'type': 'expression_statement', 'children': ['264']}; {'id': '264', 'type': 'assignment', 'children': ['265', '268']}; {'id': '265', 'type': 'attribute', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'reprate'}; {'id': '268', 'type': 'subscript', 'children': ['269', '270']}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '270', 'type': 'string', 'children': [], 'value': "'reprate'"}; {'id': '271', 'type': 'if_statement', 'children': ['272', '275']}; {'id': '272', 'type': 'comparison_operator', 'children': ['273', '274'], 'value': 'in'}; {'id': '273', 'type': 'string', 'children': [], 'value': "'save'"}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '275', 'type': 'block', 'children': ['276']}; {'id': '276', 'type': 'expression_statement', 'children': ['277']}; {'id': '277', 'type': 'assignment', 'children': ['278', '281']}; {'id': '278', 'type': 'attribute', 'children': ['279', '280']}; {'id': '279', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'save_data'}; {'id': '281', 'type': 'subscript', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '283', 'type': 'string', 'children': [], 'value': "'save'"}; {'id': '284', 'type': 'if_statement', 'children': ['285', '288']}; {'id': '285', 'type': 'comparison_operator', 'children': ['286', '287'], 'value': 'in'}; {'id': '286', 'type': 'string', 'children': [], 'value': "'average'"}; {'id': '287', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '288', 'type': 'block', 'children': ['289']}; {'id': '289', 'type': 'expression_statement', 'children': ['290']}; {'id': '290', 'type': 'assignment', 'children': ['291', '294']}; {'id': '291', 'type': 'attribute', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '293', 'type': 'identifier', 'children': [], 'value': 'average'}; {'id': '294', 'type': 'subscript', 'children': ['295', '296']}; {'id': '295', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '296', 'type': 'string', 'children': [], 'value': "'average'"}; {'id': '297', 'type': 'if_statement', 'children': ['298', '301']}; {'id': '298', 'type': 'comparison_operator', 'children': ['299', '300'], 'value': 'in'}; {'id': '299', 'type': 'string', 'children': [], 'value': "'reject'"}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '301', 'type': 'block', 'children': ['302']}; {'id': '302', 'type': 'expression_statement', 'children': ['303']}; {'id': '303', 'type': 'assignment', 'children': ['304', '307']}; {'id': '304', 'type': 'attribute', 'children': ['305', '306']}; {'id': '305', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'reject'}; {'id': '307', 'type': 'subscript', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '309', 'type': 'string', 'children': [], 'value': "'reject'"}; {'id': '310', 'type': 'if_statement', 'children': ['311', '314']}; {'id': '311', 'type': 'comparison_operator', 'children': ['312', '313'], 'value': 'in'}; {'id': '312', 'type': 'string', 'children': [], 'value': "'rejectrate'"}; {'id': '313', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '314', 'type': 'block', 'children': ['315']}; {'id': '315', 'type': 'expression_statement', 'children': ['316']}; {'id': '316', 'type': 'assignment', 'children': ['317', '320']}; {'id': '317', 'type': 'attribute', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '319', 'type': 'identifier', 'children': [], 'value': 'rejectrate'}; {'id': '320', 'type': 'subscript', 'children': ['321', '322']}; {'id': '321', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '322', 'type': 'string', 'children': [], 'value': "'rejectrate'"}
|
def set(self, **kwargs):
self.player_lock.acquire()
if 'acqtime' in kwargs:
self.player.set_aidur(kwargs['acqtime'])
if 'aifs' in kwargs:
self.player.set_aifs(kwargs['aifs'])
self.aifs = kwargs['aifs']
if 'aifs' in kwargs or 'acqtime' in kwargs:
t = kwargs.get('acqtime', self.player.get_aidur())
npoints = t*float(kwargs.get('aifs', self.player.get_aifs()))
self.aitimes = np.linspace(0, t, npoints)
if 'trigger' in kwargs:
self.player.set_trigger(kwargs['trigger'])
self.player_lock.release()
if 'aochan' in kwargs:
self.aochan = kwargs['aochan']
if 'aichan' in kwargs:
self.aichan = kwargs['aichan']
if 'binsz' in kwargs:
self.binsz = kwargs['binsz']
if 'save' in kwargs:
self.save_data = kwargs['save']
if 'caldb' in kwargs:
self.caldb = kwargs['caldb']
if 'calv' in kwargs:
self.calv = kwargs['calv']
if 'calf' in kwargs:
self.calf = kwargs['calf']
if 'caldb' in kwargs or 'calv' in kwargs:
self.update_reference_voltage()
if 'datafile' in kwargs:
self.datafile = kwargs['datafile']
if 'reprate' in kwargs:
self.reprate = kwargs['reprate']
if 'save' in kwargs:
self.save_data = kwargs['save']
if 'average' in kwargs:
self.average = kwargs['average']
if 'reject' in kwargs:
self.reject = kwargs['reject']
if 'rejectrate' in kwargs:
self.rejectrate = kwargs['rejectrate']
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'readlist'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '14', '50', '67', '75']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'call', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'printtime'}; {'id': '9', 'type': 'argument_list', 'children': ['10', '11']}; {'id': '10', 'type': 'string', 'children': [], 'value': "'Sorting reads'"}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '14', 'type': 'for_statement', 'children': ['15', '16', '22']}; {'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': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'cpus'}; {'id': '22', 'type': 'block', 'children': ['23', '37', '44']}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'threads'}; {'id': '26', 'type': 'call', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'Thread'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '34']}; {'id': '29', 'type': 'keyword_argument', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'listread'}; {'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '36', 'type': 'tuple', 'children': []}; {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'call', 'children': ['39', '42']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'threads'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'setDaemon'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}; {'id': '43', 'type': 'True', 'children': []}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}; {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'threads'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '49', 'type': 'argument_list', 'children': []}; {'id': '50', 'type': 'for_statement', 'children': ['51', '52', '57']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '52', 'type': 'attribute', 'children': ['53', '56']}; {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'runmetadata'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'samples'}; {'id': '57', 'type': 'block', 'children': ['58']}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}; {'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': 'listqueue'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'put'}; {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '74']}; {'id': '69', 'type': 'attribute', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'listqueue'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '74', 'type': 'argument_list', 'children': []}; {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'call', 'children': ['77', '80']}; {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'fastqfilter'}; {'id': '80', 'type': 'argument_list', 'children': []}
|
def readlist(self):
printtime('Sorting reads', self.start)
for i in range(self.cpus):
threads = Thread(target=self.listread, args=())
threads.setDaemon(True)
threads.start()
for sample in self.runmetadata.samples:
self.listqueue.put(sample)
self.listqueue.join()
self.fastqfilter()
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'has_change_permission'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'lang'}; {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'block', 'children': ['11', '18', '27', '72', '80', '106']}; {'id': '11', 'type': 'if_statement', 'children': ['12', '15']}; {'id': '12', 'type': 'comparison_operator', 'children': ['13', '14'], 'value': '!='}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '14', 'type': 'string', 'children': [], 'value': "'POST'"}; {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'return_statement', 'children': ['17']}; {'id': '17', 'type': 'True', 'children': []}; {'id': '18', 'type': 'if_statement', 'children': ['19', '24']}; {'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': 'change_page'}; {'id': '23', 'type': 'argument_list', 'children': []}; {'id': '24', 'type': 'block', 'children': ['25']}; {'id': '25', 'type': 'return_statement', 'children': ['26']}; {'id': '26', 'type': 'True', 'children': []}; {'id': '27', 'type': 'if_statement', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'lang'}; {'id': '29', 'type': 'block', 'children': ['30', '49', '54', '64']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'perm'}; {'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': 'user'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'has_perm'}; {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'binary_operator', 'children': ['41', '42'], 'value': '%'}; {'id': '41', 'type': 'string', 'children': [], 'value': "'pages.can_manage_%s'"}; {'id': '42', 'type': 'call', 'children': ['43', '46']}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'lang'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '46', 'type': 'argument_list', 'children': ['47', '48']}; {'id': '47', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '48', 'type': 'string', 'children': [], 'value': "'_'"}; {'id': '49', 'type': 'if_statement', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'perm'}; {'id': '51', 'type': 'block', 'children': ['52']}; {'id': '52', 'type': 'return_statement', 'children': ['53']}; {'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': 'perm_func'}; {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '59', 'type': 'argument_list', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '61', 'type': 'binary_operator', 'children': ['62', '63'], 'value': '%'}; {'id': '62', 'type': 'string', 'children': [], 'value': "'manage (%s)_page'"}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'lang'}; {'id': '64', 'type': 'if_statement', 'children': ['65', '69']}; {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'perm_func'}; {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '69', 'type': 'block', 'children': ['70']}; {'id': '70', 'type': 'return_statement', 'children': ['71']}; {'id': '71', 'type': 'True', 'children': []}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}; {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'perm_func'}; {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '77', 'type': 'argument_list', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '79', 'type': 'string', 'children': [], 'value': "'manage hierarchy_page'"}; {'id': '80', 'type': 'if_statement', 'children': ['81', '85', '88']}; {'id': '81', 'type': 'call', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'perm_func'}; {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '85', 'type': 'block', 'children': ['86']}; {'id': '86', 'type': 'return_statement', 'children': ['87']}; {'id': '87', 'type': 'True', 'children': []}; {'id': '88', 'type': 'else_clause', 'children': ['89']}; {'id': '89', 'type': 'block', 'children': ['90']}; {'id': '90', 'type': 'for_statement', 'children': ['91', '92', '97']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'ancestor'}; {'id': '92', 'type': 'call', 'children': ['93', '96']}; {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'get_ancestors'}; {'id': '96', 'type': 'argument_list', 'children': []}; {'id': '97', 'type': 'block', 'children': ['98']}; {'id': '98', 'type': 'if_statement', 'children': ['99', '103']}; {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'perm_func'}; {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'ancestor'}; {'id': '103', 'type': 'block', 'children': ['104']}; {'id': '104', 'type': 'return_statement', 'children': ['105']}; {'id': '105', 'type': 'True', 'children': []}; {'id': '106', 'type': 'return_statement', 'children': ['107']}; {'id': '107', 'type': 'False', 'children': []}
|
def has_change_permission(self, page, lang, method=None):
if method != 'POST':
return True
if self.change_page():
return True
if lang:
perm = self.user.has_perm(
'pages.can_manage_%s' % lang.replace('-', '_')
)
if perm:
return True
perm_func = getattr(self, 'manage (%s)_page' % lang)
if perm_func(page):
return True
perm_func = getattr(self, 'manage hierarchy_page')
if perm_func(page):
return True
else:
for ancestor in page.get_ancestors():
if perm_func(ancestor):
return True
return False
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'args'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '12', '18', '29', '35', '41', '47', '53', '59', '70', '76', '107', '326', '332', '363', '418']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'parameters'}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'}; {'id': '17', 'type': 'argument_list', 'children': []}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'assignment', 'children': ['20', '23']}; {'id': '20', 'type': 'subscript', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '22', 'type': 'string', 'children': [], 'value': "'help'"}; {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'HelpArg'}; {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'normalize_name'}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'normalize_name'}; {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'get_arg_config'}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'get_arg_config'}; {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'get_short_option'}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'get_short_option_for_arg'}; {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'get_long_option'}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'get_long_option_for_arg'}; {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'get_inverse_option'}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'get_inverse_option_for_arg'}; {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '62', 'type': 'set_comprehension', 'children': ['63', '67']}; {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'normalize_name'}; {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '67', 'type': 'for_in_clause', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}; {'id': '71', 'type': 'assignment', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'used_short_options'}; {'id': '73', 'type': 'call', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '75', 'type': 'argument_list', 'children': []}; {'id': '76', 'type': 'for_statement', 'children': ['77', '78', '83']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '78', 'type': 'call', 'children': ['79', '82']}; {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '82', 'type': 'argument_list', 'children': []}; {'id': '83', 'type': 'block', 'children': ['84', '91', '97']}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}; {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'annotation'}; {'id': '87', 'type': 'call', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'get_arg_config'}; {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'short_option'}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'annotation'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'short_option'}; {'id': '97', 'type': 'if_statement', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'short_option'}; {'id': '99', 'type': 'block', 'children': ['100']}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}; {'id': '101', 'type': 'call', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'used_short_options'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'short_option'}; {'id': '107', 'type': 'for_statement', 'children': ['108', '111', '116']}; {'id': '108', 'type': 'pattern_list', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '111', 'type': 'call', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '115', 'type': 'argument_list', 'children': []}; {'id': '116', 'type': 'block', 'children': ['117', '124', '150', '154', '161', '167', '173', '179', '185', '191', '197', '203', '209', '215', '221', '227', '276']}; {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'assignment', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '120', 'type': 'call', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'normalize_name'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}; {'id': '125', 'type': 'assignment', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'skip'}; {'id': '127', 'type': '()', 'children': ['128']}; {'id': '128', 'type': 'boolean_operator', 'children': ['129', '143'], 'value': 'or'}; {'id': '129', 'type': 'boolean_operator', 'children': ['130', '136'], 'value': 'or'}; {'id': '130', 'type': 'call', 'children': ['131', '134']}; {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '134', 'type': 'argument_list', 'children': ['135']}; {'id': '135', 'type': 'string', 'children': [], 'value': "'_'"}; {'id': '136', 'type': 'comparison_operator', 'children': ['137', '140'], 'value': 'is'}; {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'kind'}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'VAR_KEYWORD'}; {'id': '143', 'type': 'comparison_operator', 'children': ['144', '147'], 'value': 'is'}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'kind'}; {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'KEYWORD_ONLY'}; {'id': '150', 'type': 'if_statement', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'skip'}; {'id': '152', 'type': 'block', 'children': ['153']}; {'id': '153', 'type': 'continue_statement', 'children': []}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}; {'id': '155', 'type': 'assignment', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'annotation'}; {'id': '157', 'type': 'call', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'get_arg_config'}; {'id': '159', 'type': 'argument_list', 'children': ['160']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'assignment', 'children': ['163', '164']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'container'}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'annotation'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'container'}; {'id': '167', 'type': 'expression_statement', 'children': ['168']}; {'id': '168', 'type': 'assignment', 'children': ['169', '170']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'annotation'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '173', 'type': 'expression_statement', 'children': ['174']}; {'id': '174', 'type': 'assignment', 'children': ['175', '176']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'choices'}; {'id': '176', 'type': 'attribute', 'children': ['177', '178']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'annotation'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'choices'}; {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'assignment', 'children': ['181', '182']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'help'}; {'id': '182', 'type': 'attribute', 'children': ['183', '184']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'annotation'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'help'}; {'id': '185', 'type': 'expression_statement', 'children': ['186']}; {'id': '186', 'type': 'assignment', 'children': ['187', '188']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'inverse_help'}; {'id': '188', 'type': 'attribute', 'children': ['189', '190']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'annotation'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'inverse_help'}; {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'assignment', 'children': ['193', '194']}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'short_option'}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'annotation'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'short_option'}; {'id': '197', 'type': 'expression_statement', 'children': ['198']}; {'id': '198', 'type': 'assignment', 'children': ['199', '200']}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'long_option'}; {'id': '200', 'type': 'attribute', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'annotation'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'long_option'}; {'id': '203', 'type': 'expression_statement', 'children': ['204']}; {'id': '204', 'type': 'assignment', 'children': ['205', '206']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'inverse_option'}; {'id': '206', 'type': 'attribute', 'children': ['207', '208']}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'annotation'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'inverse_option'}; {'id': '209', 'type': 'expression_statement', 'children': ['210']}; {'id': '210', 'type': 'assignment', 'children': ['211', '212']}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '212', 'type': 'attribute', 'children': ['213', '214']}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'annotation'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '215', 'type': 'expression_statement', 'children': ['216']}; {'id': '216', 'type': 'assignment', 'children': ['217', '218']}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'nargs'}; {'id': '218', 'type': 'attribute', 'children': ['219', '220']}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'annotation'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'nargs'}; {'id': '221', 'type': 'expression_statement', 'children': ['222']}; {'id': '222', 'type': 'assignment', 'children': ['223', '224']}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '224', 'type': 'attribute', 'children': ['225', '226']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '227', 'type': 'if_statement', 'children': ['228', '233']}; {'id': '228', 'type': 'comparison_operator', 'children': ['229', '230'], 'value': 'is'}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '230', 'type': 'attribute', 'children': ['231', '232']}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'empty'}; {'id': '233', 'type': 'block', 'children': ['234', '254', '265']}; {'id': '234', 'type': 'if_statement', 'children': ['235', '237']}; {'id': '235', 'type': 'not_operator', 'children': ['236']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'short_option'}; {'id': '237', 'type': 'block', 'children': ['238', '247']}; {'id': '238', 'type': 'expression_statement', 'children': ['239']}; {'id': '239', 'type': 'assignment', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'short_option'}; {'id': '241', 'type': 'call', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'get_short_option'}; {'id': '243', 'type': 'argument_list', 'children': ['244', '245', '246']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'used_short_options'}; {'id': '247', 'type': 'expression_statement', 'children': ['248']}; {'id': '248', 'type': 'call', 'children': ['249', '252']}; {'id': '249', 'type': 'attribute', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'used_short_options'}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '252', 'type': 'argument_list', 'children': ['253']}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'short_option'}; {'id': '254', 'type': 'if_statement', 'children': ['255', '257']}; {'id': '255', 'type': 'not_operator', 'children': ['256']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'long_option'}; {'id': '257', 'type': 'block', 'children': ['258']}; {'id': '258', 'type': 'expression_statement', 'children': ['259']}; {'id': '259', 'type': 'assignment', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'long_option'}; {'id': '261', 'type': 'call', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'get_long_option'}; {'id': '263', 'type': 'argument_list', 'children': ['264']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '265', 'type': 'if_statement', 'children': ['266', '268']}; {'id': '266', 'type': 'not_operator', 'children': ['267']}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'inverse_option'}; {'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': 'inverse_option'}; {'id': '272', 'type': 'call', 'children': ['273', '274']}; {'id': '273', 'type': 'identifier', 'children': [], 'value': 'get_inverse_option'}; {'id': '274', 'type': 'argument_list', 'children': ['275']}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'long_option'}; {'id': '276', 'type': 'expression_statement', 'children': ['277']}; {'id': '277', 'type': 'assignment', 'children': ['278', '281']}; {'id': '278', 'type': 'subscript', 'children': ['279', '280']}; {'id': '279', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '281', 'type': 'call', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'Arg'}; {'id': '283', 'type': 'argument_list', 'children': ['284', '287', '290', '293', '296', '299', '302', '305', '308', '311', '314', '317', '320', '323']}; {'id': '284', 'type': 'keyword_argument', 'children': ['285', '286']}; {'id': '285', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '287', 'type': 'keyword_argument', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'parameter'}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '290', 'type': 'keyword_argument', 'children': ['291', '292']}; {'id': '291', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '293', 'type': 'keyword_argument', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'container'}; {'id': '295', 'type': 'identifier', 'children': [], 'value': 'container'}; {'id': '296', 'type': 'keyword_argument', 'children': ['297', '298']}; {'id': '297', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '299', 'type': 'keyword_argument', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '301', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '302', 'type': 'keyword_argument', 'children': ['303', '304']}; {'id': '303', 'type': 'identifier', 'children': [], 'value': 'choices'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'choices'}; {'id': '305', 'type': 'keyword_argument', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'help'}; {'id': '307', 'type': 'identifier', 'children': [], 'value': 'help'}; {'id': '308', 'type': 'keyword_argument', 'children': ['309', '310']}; {'id': '309', 'type': 'identifier', 'children': [], 'value': 'inverse_help'}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'inverse_help'}; {'id': '311', 'type': 'keyword_argument', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'short_option'}; {'id': '313', 'type': 'identifier', 'children': [], 'value': 'short_option'}; {'id': '314', 'type': 'keyword_argument', 'children': ['315', '316']}; {'id': '315', 'type': 'identifier', 'children': [], 'value': 'long_option'}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'long_option'}; {'id': '317', 'type': 'keyword_argument', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'inverse_option'}; {'id': '319', 'type': 'identifier', 'children': [], 'value': 'inverse_option'}; {'id': '320', 'type': 'keyword_argument', 'children': ['321', '322']}; {'id': '321', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '323', 'type': 'keyword_argument', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'nargs'}; {'id': '325', 'type': 'identifier', 'children': [], 'value': 'nargs'}; {'id': '326', 'type': 'expression_statement', 'children': ['327']}; {'id': '327', 'type': 'assignment', 'children': ['328', '329']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'option_map'}; {'id': '329', 'type': 'call', 'children': ['330', '331']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'}; {'id': '331', 'type': 'argument_list', 'children': []}; {'id': '332', 'type': 'for_statement', 'children': ['333', '334', '339']}; {'id': '333', 'type': 'identifier', 'children': [], 'value': 'arg'}; {'id': '334', 'type': 'call', 'children': ['335', '338']}; {'id': '335', 'type': 'attribute', 'children': ['336', '337']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '337', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '338', 'type': 'argument_list', 'children': []}; {'id': '339', 'type': 'block', 'children': ['340']}; {'id': '340', 'type': 'for_statement', 'children': ['341', '342', '345']}; {'id': '341', 'type': 'identifier', 'children': [], 'value': 'option'}; {'id': '342', 'type': 'attribute', 'children': ['343', '344']}; {'id': '343', 'type': 'identifier', 'children': [], 'value': 'arg'}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'options'}; {'id': '345', 'type': 'block', 'children': ['346', '354']}; {'id': '346', 'type': 'expression_statement', 'children': ['347']}; {'id': '347', 'type': 'call', 'children': ['348', '351']}; {'id': '348', 'type': 'attribute', 'children': ['349', '350']}; {'id': '349', 'type': 'identifier', 'children': [], 'value': 'option_map'}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'setdefault'}; {'id': '351', 'type': 'argument_list', 'children': ['352', '353']}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'option'}; {'id': '353', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '354', 'type': 'expression_statement', 'children': ['355']}; {'id': '355', 'type': 'call', 'children': ['356', '361']}; {'id': '356', 'type': 'attribute', 'children': ['357', '360']}; {'id': '357', 'type': 'subscript', 'children': ['358', '359']}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'option_map'}; {'id': '359', 'type': 'identifier', 'children': [], 'value': 'option'}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '361', 'type': 'argument_list', 'children': ['362']}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'arg'}; {'id': '363', 'type': 'for_statement', 'children': ['364', '367', '372']}; {'id': '364', 'type': 'pattern_list', 'children': ['365', '366']}; {'id': '365', 'type': 'identifier', 'children': [], 'value': 'option'}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'option_args'}; {'id': '367', 'type': 'call', 'children': ['368', '371']}; {'id': '368', 'type': 'attribute', 'children': ['369', '370']}; {'id': '369', 'type': 'identifier', 'children': [], 'value': 'option_map'}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '371', 'type': 'argument_list', 'children': []}; {'id': '372', 'type': 'block', 'children': ['373']}; {'id': '373', 'type': 'if_statement', 'children': ['374', '380']}; {'id': '374', 'type': 'comparison_operator', 'children': ['375', '379'], 'value': '>'}; {'id': '375', 'type': 'call', 'children': ['376', '377']}; {'id': '376', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '377', 'type': 'argument_list', 'children': ['378']}; {'id': '378', 'type': 'identifier', 'children': [], 'value': 'option_args'}; {'id': '379', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '380', 'type': 'block', 'children': ['381', '397', '402', '413']}; {'id': '381', 'type': 'expression_statement', 'children': ['382']}; {'id': '382', 'type': 'assignment', 'children': ['383', '384']}; {'id': '383', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '384', 'type': 'call', 'children': ['385', '388']}; {'id': '385', 'type': 'attribute', 'children': ['386', '387']}; {'id': '386', 'type': 'string', 'children': [], 'value': "', '"}; {'id': '387', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '388', 'type': 'generator_expression', 'children': ['389', '394']}; {'id': '389', 'type': 'attribute', 'children': ['390', '393']}; {'id': '390', 'type': 'attribute', 'children': ['391', '392']}; {'id': '391', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '392', 'type': 'identifier', 'children': [], 'value': 'parameter'}; {'id': '393', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '394', 'type': 'for_in_clause', 'children': ['395', '396']}; {'id': '395', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '396', 'type': 'identifier', 'children': [], 'value': 'option_args'}; {'id': '397', 'type': 'expression_statement', 'children': ['398']}; {'id': '398', 'type': 'assignment', 'children': ['399', '400']}; {'id': '399', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '400', 'type': '()', 'children': ['401']}; {'id': '401', 'type': 'string', 'children': [], 'value': "'Option {option} of command {self.name} maps to multiple parameters: {names}'"}; {'id': '402', 'type': 'expression_statement', 'children': ['403']}; {'id': '403', 'type': 'assignment', 'children': ['404', '405']}; {'id': '404', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '405', 'type': 'call', 'children': ['406', '409']}; {'id': '406', 'type': 'attribute', 'children': ['407', '408']}; {'id': '407', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '408', 'type': 'identifier', 'children': [], 'value': 'format_map'}; {'id': '409', 'type': 'argument_list', 'children': ['410']}; {'id': '410', 'type': 'call', 'children': ['411', '412']}; {'id': '411', 'type': 'identifier', 'children': [], 'value': 'locals'}; {'id': '412', 'type': 'argument_list', 'children': []}; {'id': '413', 'type': 'raise_statement', 'children': ['414']}; {'id': '414', 'type': 'call', 'children': ['415', '416']}; {'id': '415', 'type': 'identifier', 'children': [], 'value': 'CommandError'}; {'id': '416', 'type': 'argument_list', 'children': ['417']}; {'id': '417', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '418', 'type': 'return_statement', 'children': ['419']}; {'id': '419', 'type': 'identifier', 'children': [], 'value': 'args'}
|
def args(self):
params = self.parameters
args = OrderedDict()
args['help'] = HelpArg(command=self)
normalize_name = self.normalize_name
get_arg_config = self.get_arg_config
get_short_option = self.get_short_option_for_arg
get_long_option = self.get_long_option_for_arg
get_inverse_option = self.get_inverse_option_for_arg
names = {normalize_name(name) for name in params}
used_short_options = set()
for param in params.values():
annotation = get_arg_config(param)
short_option = annotation.short_option
if short_option:
used_short_options.add(short_option)
for name, param in params.items():
name = normalize_name(name)
skip = (
name.startswith('_') or
param.kind is param.VAR_KEYWORD or
param.kind is param.KEYWORD_ONLY)
if skip:
continue
annotation = get_arg_config(param)
container = annotation.container
type = annotation.type
choices = annotation.choices
help = annotation.help
inverse_help = annotation.inverse_help
short_option = annotation.short_option
long_option = annotation.long_option
inverse_option = annotation.inverse_option
action = annotation.action
nargs = annotation.nargs
default = param.default
if default is not param.empty:
if not short_option:
short_option = get_short_option(name, names, used_short_options)
used_short_options.add(short_option)
if not long_option:
long_option = get_long_option(name)
if not inverse_option:
inverse_option = get_inverse_option(long_option)
args[name] = Arg(
command=self,
parameter=param,
name=name,
container=container,
type=type,
default=default,
choices=choices,
help=help,
inverse_help=inverse_help,
short_option=short_option,
long_option=long_option,
inverse_option=inverse_option,
action=action,
nargs=nargs,
)
option_map = OrderedDict()
for arg in args.values():
for option in arg.options:
option_map.setdefault(option, [])
option_map[option].append(arg)
for option, option_args in option_map.items():
if len(option_args) > 1:
names = ', '.join(a.parameter.name for a in option_args)
message = (
'Option {option} of command {self.name} maps to multiple parameters: {names}')
message = message.format_map(locals())
raise CommandError(message)
return args
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'epcr_threads'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'formattedprimers'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'ampliconsize'}; {'id': '8', 'type': 'integer', 'children': [], 'value': '10000'}; {'id': '9', 'type': 'block', 'children': ['10', '52', '59', '294']}; {'id': '10', 'type': 'for_statement', 'children': ['11', '12', '15']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'metadata'}; {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'if_statement', 'children': ['17', '24']}; {'id': '17', 'type': 'comparison_operator', 'children': ['18', '23'], 'value': '!='}; {'id': '18', 'type': 'attribute', 'children': ['19', '22']}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'general'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'bestassemblyfile'}; {'id': '23', 'type': 'string', 'children': [], 'value': "'NA'"}; {'id': '24', 'type': 'block', 'children': ['25', '39', '46']}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'threads'}; {'id': '28', 'type': 'call', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'Thread'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '36']}; {'id': '31', 'type': 'keyword_argument', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'epcr'}; {'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '38', 'type': 'tuple', 'children': []}; {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '44']}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'threads'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'setDaemon'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}; {'id': '45', 'type': 'True', 'children': []}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}; {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'threads'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '51', 'type': 'argument_list', 'children': []}; {'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': 'logging'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'string', 'children': [], 'value': "'Running ePCR analyses'"}; {'id': '59', 'type': 'for_statement', 'children': ['60', '61', '64']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'metadata'}; {'id': '64', 'type': 'block', 'children': ['65']}; {'id': '65', 'type': 'if_statement', 'children': ['66', '73']}; {'id': '66', 'type': 'comparison_operator', 'children': ['67', '72'], 'value': '!='}; {'id': '67', 'type': 'attribute', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'general'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'bestassemblyfile'}; {'id': '72', 'type': 'string', 'children': [], 'value': "'NA'"}; {'id': '73', 'type': 'block', 'children': ['74', '85', '95', '119', '130', '150', '187', '217', '266', '283']}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}; {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'setattr'}; {'id': '77', 'type': 'argument_list', 'children': ['78', '79', '82']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'analysistype'}; {'id': '82', 'type': 'call', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'GenObject'}; {'id': '84', 'type': 'argument_list', 'children': []}; {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '94']}; {'id': '87', 'type': 'attribute', 'children': ['88', '93']}; {'id': '88', 'type': 'subscript', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'analysistype'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'primers'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'formattedprimers'}; {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '104']}; {'id': '97', 'type': 'attribute', 'children': ['98', '103']}; {'id': '98', 'type': 'subscript', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'analysistype'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'reportdir'}; {'id': '104', 'type': 'call', 'children': ['105', '110']}; {'id': '105', 'type': 'attribute', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '110', 'type': 'argument_list', 'children': ['111', '116']}; {'id': '111', 'type': 'attribute', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'general'}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'outputdirectory'}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'analysistype'}; {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'call', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'make_path'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}; {'id': '123', 'type': 'attribute', 'children': ['124', '129']}; {'id': '124', 'type': 'subscript', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'analysistype'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'reportdir'}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}; {'id': '131', 'type': 'assignment', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'outfile'}; {'id': '133', 'type': 'call', 'children': ['134', '139']}; {'id': '134', 'type': 'attribute', 'children': ['135', '138']}; {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '139', 'type': 'argument_list', 'children': ['140', '147']}; {'id': '140', 'type': 'attribute', 'children': ['141', '146']}; {'id': '141', 'type': 'subscript', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'analysistype'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'reportdir'}; {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}; {'id': '151', 'type': 'assignment', 'children': ['152', '157']}; {'id': '152', 'type': 'attribute', 'children': ['153', '156']}; {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'commands'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'famap'}; {'id': '157', 'type': 'call', 'children': ['158', '162']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160', '161']}; {'id': '159', 'type': 'string', 'children': [], 'value': "'{famap} -b {outfile}.famap {fasta}'"}; {'id': '160', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '162', 'type': 'argument_list', 'children': ['163', '177', '180']}; {'id': '163', 'type': 'keyword_argument', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'famap'}; {'id': '165', 'type': 'call', 'children': ['166', '171']}; {'id': '166', 'type': 'attribute', 'children': ['167', '170']}; {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '171', 'type': 'argument_list', 'children': ['172', '175', '176']}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'homepath'}; {'id': '175', 'type': 'string', 'children': [], 'value': "'ePCR'"}; {'id': '176', 'type': 'string', 'children': [], 'value': "'famap'"}; {'id': '177', 'type': 'keyword_argument', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'outfile'}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'outfile'}; {'id': '180', 'type': 'keyword_argument', 'children': ['181', '182']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'fasta'}; {'id': '182', 'type': 'attribute', 'children': ['183', '186']}; {'id': '183', 'type': 'attribute', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'general'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'bestassemblyfile'}; {'id': '187', 'type': 'expression_statement', 'children': ['188']}; {'id': '188', 'type': 'assignment', 'children': ['189', '194']}; {'id': '189', 'type': 'attribute', 'children': ['190', '193']}; {'id': '190', 'type': 'attribute', 'children': ['191', '192']}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'commands'}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'fahash'}; {'id': '194', 'type': 'call', 'children': ['195', '199']}; {'id': '195', 'type': 'attribute', 'children': ['196', '197', '198']}; {'id': '196', 'type': 'string', 'children': [], 'value': "'{fahash} -b {outfile}.hash {outfile}.famap'"}; {'id': '197', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '199', 'type': 'argument_list', 'children': ['200', '214']}; {'id': '200', 'type': 'keyword_argument', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'fahash'}; {'id': '202', 'type': 'call', 'children': ['203', '208']}; {'id': '203', 'type': 'attribute', 'children': ['204', '207']}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '208', 'type': 'argument_list', 'children': ['209', '212', '213']}; {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'homepath'}; {'id': '212', 'type': 'string', 'children': [], 'value': "'ePCR'"}; {'id': '213', 'type': 'string', 'children': [], 'value': "'fahash'"}; {'id': '214', 'type': 'keyword_argument', 'children': ['215', '216']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'outfile'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'outfile'}; {'id': '217', 'type': 'expression_statement', 'children': ['218']}; {'id': '218', 'type': 'assignment', 'children': ['219', '224']}; {'id': '219', 'type': 'attribute', 'children': ['220', '223']}; {'id': '220', 'type': 'attribute', 'children': ['221', '222']}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'commands'}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'epcr'}; {'id': '224', 'type': 'call', 'children': ['225', '231']}; {'id': '225', 'type': 'attribute', 'children': ['226', '229', '230']}; {'id': '226', 'type': 'concatenated_string', 'children': ['227', '228']}; {'id': '227', 'type': 'string', 'children': [], 'value': "'{rePCR} -S {outfile}.hash -r + -d 1-{ampsize} -n {mismatches} -g 0 -G -q '"}; {'id': '228', 'type': 'string', 'children': [], 'value': "'-o {outfile}.txt {primers}'"}; {'id': '229', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '231', 'type': 'argument_list', 'children': ['232', '246', '249', '252', '257']}; {'id': '232', 'type': 'keyword_argument', 'children': ['233', '234']}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'rePCR'}; {'id': '234', 'type': 'call', 'children': ['235', '240']}; {'id': '235', 'type': 'attribute', 'children': ['236', '239']}; {'id': '236', 'type': 'attribute', 'children': ['237', '238']}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '240', 'type': 'argument_list', 'children': ['241', '244', '245']}; {'id': '241', 'type': 'attribute', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'homepath'}; {'id': '244', 'type': 'string', 'children': [], 'value': "'ePCR'"}; {'id': '245', 'type': 'string', 'children': [], 'value': "'re-PCR'"}; {'id': '246', 'type': 'keyword_argument', 'children': ['247', '248']}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'outfile'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'outfile'}; {'id': '249', 'type': 'keyword_argument', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'ampsize'}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'ampliconsize'}; {'id': '252', 'type': 'keyword_argument', 'children': ['253', '254']}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'mismatches'}; {'id': '254', 'type': 'attribute', 'children': ['255', '256']}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'mismatches'}; {'id': '257', 'type': 'keyword_argument', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'primers'}; {'id': '259', 'type': 'attribute', 'children': ['260', '265']}; {'id': '260', 'type': 'subscript', 'children': ['261', '262']}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '262', 'type': 'attribute', 'children': ['263', '264']}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'analysistype'}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'primers'}; {'id': '266', 'type': 'expression_statement', 'children': ['267']}; {'id': '267', 'type': 'assignment', 'children': ['268', '275']}; {'id': '268', 'type': 'attribute', 'children': ['269', '274']}; {'id': '269', 'type': 'subscript', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '271', 'type': 'attribute', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '273', 'type': 'identifier', 'children': [], 'value': 'analysistype'}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'resultsfile'}; {'id': '275', 'type': 'call', 'children': ['276', '279']}; {'id': '276', 'type': 'attribute', 'children': ['277', '278']}; {'id': '277', 'type': 'string', 'children': [], 'value': "'{of}.txt'"}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '279', 'type': 'argument_list', 'children': ['280']}; {'id': '280', 'type': 'keyword_argument', 'children': ['281', '282']}; {'id': '281', 'type': 'identifier', 'children': [], 'value': 'of'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'outfile'}; {'id': '283', 'type': 'expression_statement', 'children': ['284']}; {'id': '284', 'type': 'call', 'children': ['285', '290']}; {'id': '285', 'type': 'attribute', 'children': ['286', '289']}; {'id': '286', 'type': 'attribute', 'children': ['287', '288']}; {'id': '287', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'epcrqueue'}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'put'}; {'id': '290', 'type': 'argument_list', 'children': ['291']}; {'id': '291', 'type': 'tuple', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '293', 'type': 'identifier', 'children': [], 'value': 'outfile'}; {'id': '294', 'type': 'expression_statement', 'children': ['295']}; {'id': '295', 'type': 'call', 'children': ['296', '301']}; {'id': '296', 'type': 'attribute', 'children': ['297', '300']}; {'id': '297', 'type': 'attribute', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '299', 'type': 'identifier', 'children': [], 'value': 'epcrqueue'}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '301', 'type': 'argument_list', 'children': []}
|
def epcr_threads(self, formattedprimers, ampliconsize=10000):
for sample in self.metadata:
if sample.general.bestassemblyfile != 'NA':
threads = Thread(target=self.epcr, args=())
threads.setDaemon(True)
threads.start()
logging.info('Running ePCR analyses')
for sample in self.metadata:
if sample.general.bestassemblyfile != 'NA':
setattr(sample, self.analysistype, GenObject())
sample[self.analysistype].primers = formattedprimers
sample[self.analysistype].reportdir = os.path.join(sample.general.outputdirectory,
self.analysistype)
make_path(sample[self.analysistype].reportdir)
outfile = os.path.join(sample[self.analysistype].reportdir, sample.name)
sample.commands.famap = '{famap} -b {outfile}.famap {fasta}'\
.format(famap=os.path.join(self.homepath, 'ePCR', 'famap'),
outfile=outfile,
fasta=sample.general.bestassemblyfile)
sample.commands.fahash = '{fahash} -b {outfile}.hash {outfile}.famap'\
.format(fahash=os.path.join(self.homepath, 'ePCR', 'fahash'),
outfile=outfile)
sample.commands.epcr = \
'{rePCR} -S {outfile}.hash -r + -d 1-{ampsize} -n {mismatches} -g 0 -G -q ' \
'-o {outfile}.txt {primers}'\
.format(rePCR=os.path.join(self.homepath, 'ePCR', 're-PCR'),
outfile=outfile,
ampsize=ampliconsize,
mismatches=self.mismatches,
primers=sample[self.analysistype].primers)
sample[self.analysistype].resultsfile = '{of}.txt'.format(of=outfile)
self.epcrqueue.put((sample, outfile))
self.epcrqueue.join()
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'aggregate'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'for_statement', 'children': ['7', '8', '11']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'report'}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'reportset'}; {'id': '11', 'type': 'block', 'children': ['12', '32', '41', '45']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'printtime'}; {'id': '15', 'type': 'argument_list', 'children': ['16', '29']}; {'id': '16', 'type': 'call', 'children': ['17', '20']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'string', 'children': [], 'value': "'Processing {}'"}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}; {'id': '21', 'type': 'subscript', 'children': ['22', '28']}; {'id': '22', 'type': 'call', 'children': ['23', '26']}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'report'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}; {'id': '27', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '28', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '35', 'type': 'conditional_expression', 'children': ['36', '37', '40'], 'value': 'if'}; {'id': '36', 'type': 'string', 'children': [], 'value': "''"}; {'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': '!='}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'report'}; {'id': '39', 'type': 'string', 'children': [], 'value': "'mlst.csv'"}; {'id': '40', 'type': 'string', 'children': [], 'value': "'Strain,Genus,SequenceType,Matches,1,2,3,4,5,6,7\\n'"}; {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '44', 'type': 'string', 'children': [], 'value': "''"}; {'id': '45', 'type': 'with_statement', 'children': ['46', '66']}; {'id': '46', 'type': 'with_clause', 'children': ['47']}; {'id': '47', 'type': 'with_item', 'children': ['48']}; {'id': '48', 'type': 'as_pattern', 'children': ['49', '64']}; {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '51', 'type': 'argument_list', 'children': ['52', '63']}; {'id': '52', 'type': 'call', 'children': ['53', '58']}; {'id': '53', 'type': 'attribute', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '58', 'type': 'argument_list', 'children': ['59', '62']}; {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'reportpath'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'report'}; {'id': '63', 'type': 'string', 'children': [], 'value': "'w'"}; {'id': '64', 'type': 'as_pattern_target', 'children': ['65']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'aggregate'}; {'id': '66', 'type': 'block', 'children': ['67', '159', '166']}; {'id': '67', 'type': 'for_statement', 'children': ['68', '69', '74']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '69', 'type': 'attribute', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'runmetadata'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'samples'}; {'id': '74', 'type': 'block', 'children': ['75']}; {'id': '75', 'type': 'try_statement', 'children': ['76', '155']}; {'id': '76', 'type': 'block', 'children': ['77']}; {'id': '77', 'type': 'with_statement', 'children': ['78', '100']}; {'id': '78', 'type': 'with_clause', 'children': ['79']}; {'id': '79', 'type': 'with_item', 'children': ['80']}; {'id': '80', 'type': 'as_pattern', 'children': ['81', '98']}; {'id': '81', 'type': 'call', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '83', 'type': 'argument_list', 'children': ['84', '97']}; {'id': '84', 'type': 'call', 'children': ['85', '90']}; {'id': '85', 'type': 'attribute', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '90', 'type': 'argument_list', 'children': ['91', '96']}; {'id': '91', 'type': 'attribute', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'general'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'reportpath'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'report'}; {'id': '97', 'type': 'string', 'children': [], 'value': "'r'"}; {'id': '98', 'type': 'as_pattern_target', 'children': ['99']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'runreport'}; {'id': '100', 'type': 'block', 'children': ['101']}; {'id': '101', 'type': 'if_statement', 'children': ['102', '104', '113']}; {'id': '102', 'type': 'not_operator', 'children': ['103']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '104', 'type': 'block', 'children': ['105']}; {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '108', 'type': 'call', 'children': ['109', '112']}; {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'runreport'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'readline'}; {'id': '112', 'type': 'argument_list', 'children': []}; {'id': '113', 'type': 'else_clause', 'children': ['114']}; {'id': '114', 'type': 'block', 'children': ['115']}; {'id': '115', 'type': 'for_statement', 'children': ['116', '117', '118']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'runreport'}; {'id': '118', 'type': 'block', 'children': ['119', '132']}; {'id': '119', 'type': 'if_statement', 'children': ['120', '127']}; {'id': '120', 'type': 'not_operator', 'children': ['121']}; {'id': '121', 'type': 'call', 'children': ['122', '125']}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'endswith'}; {'id': '125', 'type': 'argument_list', 'children': ['126']}; {'id': '126', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '127', 'type': 'block', 'children': ['128']}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}; {'id': '129', 'type': 'augmented_assignment', 'children': ['130', '131'], 'value': '+='}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '131', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '132', 'type': 'if_statement', 'children': ['133', '150']}; {'id': '133', 'type': 'comparison_operator', 'children': ['134', '142'], 'value': '!='}; {'id': '134', 'type': 'subscript', 'children': ['135', '141']}; {'id': '135', 'type': 'call', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'string', 'children': [], 'value': "','"}; {'id': '141', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '142', 'type': 'subscript', 'children': ['143', '149']}; {'id': '143', 'type': 'call', 'children': ['144', '147']}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'string', 'children': [], 'value': "','"}; {'id': '149', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '150', 'type': 'block', 'children': ['151']}; {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'augmented_assignment', 'children': ['153', '154'], 'value': '+='}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '155', 'type': 'except_clause', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'IOError'}; {'id': '157', 'type': 'block', 'children': ['158']}; {'id': '158', 'type': 'pass_statement', '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': 'aggregate'}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}; {'id': '167', 'type': 'call', 'children': ['168', '171']}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'aggregate'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '171', 'type': 'argument_list', 'children': ['172']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'data'}
|
def aggregate(self):
for report in self.reportset:
printtime('Processing {}'.format(report.split('.')[0]), self.start)
header = '' if report != 'mlst.csv' else 'Strain,Genus,SequenceType,Matches,1,2,3,4,5,6,7\n'
data = ''
with open(os.path.join(self.reportpath, report), 'w') as aggregate:
for sample in self.runmetadata.samples:
try:
with open(os.path.join(sample.general.reportpath, report), 'r') as runreport:
if not header:
header = runreport.readline()
else:
for row in runreport:
if not row.endswith('\n'):
row += '\n'
if row.split(',')[0] != header.split(',')[0]:
data += row
except IOError:
pass
aggregate.write(header)
aggregate.write(data)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_parse_sequences'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'ilines'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'expect_qlen'}; {'id': '6', 'type': 'block', 'children': ['7']}; {'id': '7', 'type': 'while_statement', 'children': ['8', '9']}; {'id': '8', 'type': 'True', 'children': []}; {'id': '9', 'type': 'block', 'children': ['10', '17', '33', '57', '74', '101', '116', '127', '138', '174', '210']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}; {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'first'}; {'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': 'ilines'}; {'id': '17', 'type': 'if_statement', 'children': ['18', '31']}; {'id': '18', 'type': 'boolean_operator', 'children': ['19', '25'], 'value': 'and'}; {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'first'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'string', 'children': [], 'value': "'_'"}; {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'first'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'endswith'}; {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'string', 'children': [], 'value': "'].'"}; {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'break_statement', 'children': []}; {'id': '33', 'type': 'try_statement', 'children': ['34', '45']}; {'id': '34', 'type': 'block', 'children': ['35']}; {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '41']}; {'id': '37', 'type': 'pattern_list', 'children': ['38', '39', '40']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'this_len'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'query_len'}; {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': '_parse_seq_preheader'}; {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'first'}; {'id': '45', 'type': 'except_clause', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '47', 'type': 'block', 'children': ['48', '56']}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}; {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'warn'}; {'id': '53', 'type': 'argument_list', 'children': ['54', '55']}; {'id': '54', 'type': 'string', 'children': [], 'value': "'Unparseable line (SKIPPING):\\n%s'"}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'first'}; {'id': '56', 'type': 'continue_statement', 'children': []}; {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '67']}; {'id': '59', 'type': 'tuple_pattern', 'children': ['60', '61', '62', '63', '64', '65', '66']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'rec_id'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'dbxrefs'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'headlen'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'taillen'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'phylum'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'taxchar'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'description'}; {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': '_parse_seq_header'}; {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'call', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'next'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'ilines'}; {'id': '74', 'type': 'try_statement', 'children': ['75', '89']}; {'id': '75', 'type': 'block', 'children': ['76']}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}; {'id': '77', 'type': 'assignment', 'children': ['78', '82']}; {'id': '78', 'type': 'pattern_list', 'children': ['79', '80', '81']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'headseq'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'molseq'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'tailseq'}; {'id': '82', 'type': 'call', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': '_parse_seq_body'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}; {'id': '85', 'type': 'call', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'next'}; {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'ilines'}; {'id': '89', 'type': 'except_clause', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '91', 'type': 'block', 'children': ['92', '100']}; {'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': 'logging'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'warn'}; {'id': '97', 'type': 'argument_list', 'children': ['98', '99']}; {'id': '98', 'type': 'string', 'children': [], 'value': "'Unparseable sequence: %s -- SKIPPING'"}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'rec_id'}; {'id': '100', 'type': 'continue_statement', 'children': []}; {'id': '101', 'type': 'if_statement', 'children': ['102', '105']}; {'id': '102', 'type': 'comparison_operator', 'children': ['103', '104'], 'value': '!='}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'expect_qlen'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'query_len'}; {'id': '105', 'type': 'block', 'children': ['106']}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}; {'id': '107', 'type': 'call', 'children': ['108', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'warn'}; {'id': '111', 'type': 'argument_list', 'children': ['112', '113', '114', '115']}; {'id': '112', 'type': 'string', 'children': [], 'value': '"Query length in %s given as %d; expected %d"'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'rec_id'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'query_len'}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'expect_qlen'}; {'id': '116', 'type': 'if_statement', 'children': ['117', '122']}; {'id': '117', 'type': 'boolean_operator', 'children': ['118', '120'], 'value': 'and'}; {'id': '118', 'type': 'not_operator', 'children': ['119']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'headseq'}; {'id': '120', 'type': 'not_operator', 'children': ['121']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'headlen'}; {'id': '122', 'type': 'block', 'children': ['123']}; {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'headlen'}; {'id': '126', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '127', 'type': 'if_statement', 'children': ['128', '133']}; {'id': '128', 'type': 'boolean_operator', 'children': ['129', '131'], 'value': 'and'}; {'id': '129', 'type': 'not_operator', 'children': ['130']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'tailseq'}; {'id': '131', 'type': 'not_operator', 'children': ['132']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'taillen'}; {'id': '133', 'type': 'block', 'children': ['134']}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}; {'id': '135', 'type': 'assignment', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'taillen'}; {'id': '137', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '138', 'type': 'if_statement', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'headseq'}; {'id': '140', 'type': 'block', 'children': ['141']}; {'id': '141', 'type': 'if_statement', 'children': ['142', '145', '153']}; {'id': '142', 'type': 'comparison_operator', 'children': ['143', '144'], 'value': 'is'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'headlen'}; {'id': '144', 'type': 'None', 'children': []}; {'id': '145', 'type': 'block', 'children': ['146']}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}; {'id': '147', 'type': 'assignment', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'headlen'}; {'id': '149', 'type': 'call', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '151', 'type': 'argument_list', 'children': ['152']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'headseq'}; {'id': '153', 'type': 'elif_clause', 'children': ['154', '160']}; {'id': '154', 'type': 'comparison_operator', 'children': ['155', '156'], 'value': '!='}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'headlen'}; {'id': '156', 'type': 'call', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '158', 'type': 'argument_list', 'children': ['159']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'headseq'}; {'id': '160', 'type': 'block', 'children': ['161']}; {'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': 'logging'}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'warn'}; {'id': '166', 'type': 'argument_list', 'children': ['167', '168', '169', '170']}; {'id': '167', 'type': 'string', 'children': [], 'value': '"Conflicting head flank lengths in %s: %d, %d"'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'rec_id'}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'headlen'}; {'id': '170', 'type': 'call', 'children': ['171', '172']}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '172', 'type': 'argument_list', 'children': ['173']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'headseq'}; {'id': '174', 'type': 'if_statement', 'children': ['175', '176']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'tailseq'}; {'id': '176', 'type': 'block', 'children': ['177']}; {'id': '177', 'type': 'if_statement', 'children': ['178', '181', '189']}; {'id': '178', 'type': 'comparison_operator', 'children': ['179', '180'], 'value': 'is'}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'taillen'}; {'id': '180', 'type': 'None', 'children': []}; {'id': '181', 'type': 'block', 'children': ['182']}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}; {'id': '183', 'type': 'assignment', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'taillen'}; {'id': '185', 'type': 'call', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '187', 'type': 'argument_list', 'children': ['188']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'tailseq'}; {'id': '189', 'type': 'elif_clause', 'children': ['190', '196']}; {'id': '190', 'type': 'comparison_operator', 'children': ['191', '192'], 'value': '!='}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'taillen'}; {'id': '192', 'type': 'call', 'children': ['193', '194']}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '194', 'type': 'argument_list', 'children': ['195']}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'tailseq'}; {'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': 'logging'}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'warn'}; {'id': '202', 'type': 'argument_list', 'children': ['203', '204', '205', '206']}; {'id': '203', 'type': 'string', 'children': [], 'value': '"Conflicting tail flank lengths in %s: %d, %d"'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'rec_id'}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'taillen'}; {'id': '206', 'type': 'call', 'children': ['207', '208']}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '208', 'type': 'argument_list', 'children': ['209']}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'tailseq'}; {'id': '210', 'type': 'expression_statement', 'children': ['211']}; {'id': '211', 'type': 'yield', 'children': ['212']}; {'id': '212', 'type': 'dictionary', 'children': ['213', '216', '219', '222', '225', '228', '231', '234', '237', '240', '243', '246']}; {'id': '213', 'type': 'pair', 'children': ['214', '215']}; {'id': '214', 'type': 'string', 'children': [], 'value': "'index'"}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '216', 'type': 'pair', 'children': ['217', '218']}; {'id': '217', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'rec_id'}; {'id': '219', 'type': 'pair', 'children': ['220', '221']}; {'id': '220', 'type': 'string', 'children': [], 'value': "'description'"}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'description'}; {'id': '222', 'type': 'pair', 'children': ['223', '224']}; {'id': '223', 'type': 'string', 'children': [], 'value': "'dbxrefs'"}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'dbxrefs'}; {'id': '225', 'type': 'pair', 'children': ['226', '227']}; {'id': '226', 'type': 'string', 'children': [], 'value': "'phylum'"}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'phylum'}; {'id': '228', 'type': 'pair', 'children': ['229', '230']}; {'id': '229', 'type': 'string', 'children': [], 'value': "'taxchar'"}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'taxchar'}; {'id': '231', 'type': 'pair', 'children': ['232', '233']}; {'id': '232', 'type': 'string', 'children': [], 'value': "'head_len'"}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'headlen'}; {'id': '234', 'type': 'pair', 'children': ['235', '236']}; {'id': '235', 'type': 'string', 'children': [], 'value': "'tail_len'"}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'taillen'}; {'id': '237', 'type': 'pair', 'children': ['238', '239']}; {'id': '238', 'type': 'string', 'children': [], 'value': "'head_seq'"}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'headseq'}; {'id': '240', 'type': 'pair', 'children': ['241', '242']}; {'id': '241', 'type': 'string', 'children': [], 'value': "'tail_seq'"}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'tailseq'}; {'id': '243', 'type': 'pair', 'children': ['244', '245']}; {'id': '244', 'type': 'string', 'children': [], 'value': "'length'"}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'this_len'}; {'id': '246', 'type': 'pair', 'children': ['247', '248']}; {'id': '247', 'type': 'string', 'children': [], 'value': "'seq'"}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'molseq'}
|
def _parse_sequences(ilines, expect_qlen):
while True:
first = next(ilines)
if first.startswith('_') and first.endswith('].'):
break
try:
index, this_len, query_len = _parse_seq_preheader(first)
except ValueError:
logging.warn('Unparseable line (SKIPPING):\n%s', first)
continue
(rec_id, dbxrefs, headlen, taillen, phylum, taxchar, description
) = _parse_seq_header(next(ilines))
try:
headseq, molseq, tailseq = _parse_seq_body(next(ilines))
except ValueError:
logging.warn('Unparseable sequence: %s -- SKIPPING', rec_id)
continue
if expect_qlen != query_len:
logging.warn("Query length in %s given as %d; expected %d",
rec_id, query_len, expect_qlen)
if not headseq and not headlen:
headlen = 0
if not tailseq and not taillen:
taillen = 0
if headseq:
if headlen is None:
headlen = len(headseq)
elif headlen != len(headseq):
logging.warn("Conflicting head flank lengths in %s: %d, %d",
rec_id, headlen, len(headseq))
if tailseq:
if taillen is None:
taillen = len(tailseq)
elif taillen != len(tailseq):
logging.warn("Conflicting tail flank lengths in %s: %d, %d",
rec_id, taillen, len(tailseq))
yield {'index': index,
'id': rec_id,
'description': description,
'dbxrefs': dbxrefs,
'phylum': phylum,
'taxchar': taxchar,
'head_len': headlen,
'tail_len': taillen,
'head_seq': headseq,
'tail_seq': tailseq,
'length': this_len,
'seq': molseq,
}
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'realign_seqs'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'block'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'gap_char'}; {'id': '7', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'align_indels'}; {'id': '10', 'type': 'False', 'children': []}; {'id': '11', 'type': 'block', 'children': ['12', '27', '34', '38', '89']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'all_chars'}; {'id': '15', 'type': 'list_comprehension', 'children': ['16', '22']}; {'id': '16', 'type': 'call', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}; {'id': '19', 'type': 'subscript', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'sq'}; {'id': '21', 'type': 'string', 'children': [], 'value': "'seq'"}; {'id': '22', 'type': 'for_in_clause', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'sq'}; {'id': '24', 'type': 'subscript', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'block'}; {'id': '26', 'type': 'string', 'children': [], 'value': "'sequences'"}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'nrows'}; {'id': '30', 'type': 'call', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'all_chars'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}; {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '37', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '38', 'type': 'while_statement', 'children': ['39', '47']}; {'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': '<'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'subscript', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'all_chars'}; {'id': '46', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '47', 'type': 'block', 'children': ['48', '65', '85']}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}; {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'rows_need_gaps'}; {'id': '51', 'type': 'list_comprehension', 'children': ['52', '53', '56']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '53', 'type': 'for_in_clause', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'all_chars'}; {'id': '56', 'type': 'if_clause', 'children': ['57']}; {'id': '57', 'type': 'not_operator', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '64']}; {'id': '59', 'type': 'attribute', 'children': ['60', '63']}; {'id': '60', 'type': 'subscript', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'islower'}; {'id': '64', 'type': 'argument_list', 'children': []}; {'id': '65', 'type': 'if_statement', 'children': ['66', '72']}; {'id': '66', 'type': 'comparison_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': 'rows_need_gaps'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'nrows'}; {'id': '72', 'type': 'block', 'children': ['73']}; {'id': '73', 'type': 'for_statement', 'children': ['74', '75', '76']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'rows_need_gaps'}; {'id': '76', 'type': 'block', 'children': ['77']}; {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '82']}; {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'insert'}; {'id': '82', 'type': 'argument_list', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'gap_char'}; {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'augmented_assignment', 'children': ['87', '88'], 'value': '+='}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '88', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '89', 'type': 'return_statement', 'children': ['90']}; {'id': '90', 'type': 'list_comprehension', 'children': ['91', '97']}; {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}; {'id': '93', 'type': 'string', 'children': [], 'value': "''"}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '97', 'type': 'for_in_clause', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'all_chars'}
|
def realign_seqs(block, gap_char='.', align_indels=False):
all_chars = [list(sq['seq']) for sq in block['sequences']]
nrows = len(all_chars)
i = 0
while i < len(all_chars[0]):
rows_need_gaps = [r for r in all_chars if not r[i].islower()]
if len(rows_need_gaps) != nrows:
for row in rows_need_gaps:
row.insert(i, gap_char)
i += 1
return [''.join(row) for row in all_chars]
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'collapse_to_consensus'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'seqrecords'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'strict'}; {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'do_iron'}; {'id': '10', 'type': 'True', 'children': []}; {'id': '11', 'type': 'block', 'children': ['12', '16', '24', '63', '72', '79', '112', '199', '211', '224', '230', '365']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '15', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '19', 'type': 'attribute', 'children': ['20', '23']}; {'id': '20', 'type': 'subscript', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'seqrecords'}; {'id': '22', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '24', 'type': 'if_statement', 'children': ['25', '30']}; {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '27', 'type': 'argument_list', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'seqrecords'}; {'id': '29', 'type': 'string', 'children': [], 'value': "'_records'"}; {'id': '30', 'type': 'block', 'children': ['31', '44', '57']}; {'id': '31', 'type': 'if_statement', 'children': ['32', '37']}; {'id': '32', 'type': 'call', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'seqrecords'}; {'id': '36', 'type': 'string', 'children': [], 'value': "'level'"}; {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}; {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'seqrecords'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '44', 'type': 'if_statement', 'children': ['45', '50']}; {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '47', 'type': 'argument_list', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'seqrecords'}; {'id': '49', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '50', 'type': 'block', 'children': ['51']}; {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'seqrecords'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'seqrecords'}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'seqrecords'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': '_records'}; {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'consensus'}; {'id': '66', 'type': 'call', 'children': ['67', '70']}; {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'seqrecords'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}; {'id': '71', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}; {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'cons_length'}; {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'consensus'}; {'id': '79', 'type': 'for_statement', 'children': ['80', '83', '87']}; {'id': '80', 'type': 'pattern_list', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '83', 'type': 'call', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'seqrecords'}; {'id': '87', 'type': 'block', 'children': ['88']}; {'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': 's'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'cons_length'}; {'id': '95', 'type': 'block', 'children': ['96']}; {'id': '96', 'type': 'raise_statement', 'children': ['97']}; {'id': '97', 'type': 'call', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '99', 'type': 'argument_list', 'children': ['100', '101']}; {'id': '100', 'type': 'ERROR', 'children': []}; {'id': '101', 'type': 'binary_operator', 'children': ['102', '103'], 'value': '%'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'Sequence'}; {'id': '103', 'type': 'tuple', 'children': ['104', '107', '111']}; {'id': '104', 'type': 'binary_operator', 'children': ['105', '106'], 'value': '+'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '106', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '107', 'type': 'call', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'cons_length'}; {'id': '112', 'type': 'if_statement', 'children': ['113', '121', '182']}; {'id': '113', 'type': 'comparison_operator', 'children': ['114', '115'], 'value': 'in'}; {'id': '114', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '115', 'type': 'call', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'consensus'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '121', 'type': 'block', 'children': ['122']}; {'id': '122', 'type': 'if_statement', 'children': ['123', '131', '165']}; {'id': '123', 'type': 'comparison_operator', 'children': ['124', '125'], 'value': 'in'}; {'id': '124', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '125', 'type': 'call', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'consensus'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '131', 'type': 'block', 'children': ['132', '140', '149']}; {'id': '132', 'type': 'if_statement', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'strict'}; {'id': '134', 'type': 'block', 'children': ['135']}; {'id': '135', 'type': 'raise_statement', 'children': ['136']}; {'id': '136', 'type': 'call', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '138', 'type': 'argument_list', 'children': ['139']}; {'id': '139', 'type': 'string', 'children': [], 'value': '"Consensus contains \'-\' gap characters"'}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}; {'id': '141', 'type': 'call', 'children': ['142', '145']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'warn'}; {'id': '145', 'type': 'argument_list', 'children': ['146']}; {'id': '146', 'type': 'concatenated_string', 'children': ['147', '148']}; {'id': '147', 'type': 'string', 'children': [], 'value': '"Consensus sequence contains both \'.\' and \'-\' gap "'}; {'id': '148', 'type': 'string', 'children': [], 'value': '"characters -- is it really the consensus?"'}; {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'assignment', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'aligned_cols'}; {'id': '152', 'type': 'list_comprehension', 'children': ['153', '157']}; {'id': '153', 'type': '()', 'children': ['154']}; {'id': '154', 'type': 'comparison_operator', 'children': ['155', '156'], 'value': 'not'}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '156', 'type': 'string', 'children': [], 'value': "'.-'"}; {'id': '157', 'type': 'for_in_clause', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '159', 'type': 'call', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '161', 'type': 'argument_list', 'children': ['162']}; {'id': '162', 'type': 'attribute', 'children': ['163', '164']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'consensus'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '165', 'type': 'else_clause', 'children': ['166']}; {'id': '166', 'type': 'block', 'children': ['167']}; {'id': '167', 'type': 'expression_statement', 'children': ['168']}; {'id': '168', 'type': 'assignment', 'children': ['169', '170']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'aligned_cols'}; {'id': '170', 'type': 'list_comprehension', 'children': ['171', '174']}; {'id': '171', 'type': 'comparison_operator', 'children': ['172', '173'], 'value': '!='}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '173', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '174', 'type': 'for_in_clause', 'children': ['175', '176']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '176', 'type': 'call', 'children': ['177', '178']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '178', 'type': 'argument_list', 'children': ['179']}; {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'consensus'}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '182', 'type': 'else_clause', 'children': ['183']}; {'id': '183', 'type': 'block', 'children': ['184']}; {'id': '184', 'type': 'expression_statement', 'children': ['185']}; {'id': '185', 'type': 'assignment', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'aligned_cols'}; {'id': '187', 'type': 'list_comprehension', 'children': ['188', '191']}; {'id': '188', 'type': 'comparison_operator', 'children': ['189', '190'], 'value': '!='}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '190', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '191', 'type': 'for_in_clause', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '193', 'type': 'call', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '195', 'type': 'argument_list', 'children': ['196']}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'consensus'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'assignment', 'children': ['201', '204']}; {'id': '201', 'type': 'attribute', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'consensus'}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '204', 'type': 'call', 'children': ['205', '206']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'replace_asterisks'}; {'id': '206', 'type': 'argument_list', 'children': ['207', '210']}; {'id': '207', 'type': 'attribute', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'consensus'}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '210', 'type': 'string', 'children': [], 'value': "'consensus'"}; {'id': '211', 'type': 'expression_statement', 'children': ['212']}; {'id': '212', 'type': 'assignment', 'children': ['213', '214']}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'block'}; {'id': '214', 'type': 'call', 'children': ['215', '216']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'consensus2block'}; {'id': '216', 'type': 'argument_list', 'children': ['217', '218', '221']}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'consensus'}; {'id': '218', 'type': 'keyword_argument', 'children': ['219', '220']}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '221', 'type': 'keyword_argument', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '224', 'type': 'expression_statement', 'children': ['225']}; {'id': '225', 'type': 'assignment', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'qlen'}; {'id': '227', 'type': 'subscript', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'block'}; {'id': '229', 'type': 'string', 'children': [], 'value': "'query_length'"}; {'id': '230', 'type': 'for_statement', 'children': ['231', '234', '248']}; {'id': '231', 'type': 'pattern_list', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '234', 'type': 'call', 'children': ['235', '236']}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '236', 'type': 'argument_list', 'children': ['237', '247']}; {'id': '237', 'type': 'call', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'xrange'}; {'id': '239', 'type': 'argument_list', 'children': ['240', '241']}; {'id': '240', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '241', 'type': 'binary_operator', 'children': ['242', '246'], 'value': '+'}; {'id': '242', 'type': 'call', 'children': ['243', '244']}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '244', 'type': 'argument_list', 'children': ['245']}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'seqrecords'}; {'id': '246', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'seqrecords'}; {'id': '248', 'type': 'block', 'children': ['249', '253', '257', '326', '337', '351']}; {'id': '249', 'type': 'expression_statement', 'children': ['250']}; {'id': '250', 'type': 'assignment', 'children': ['251', '252']}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'new_mol_seq'}; {'id': '252', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '253', 'type': 'expression_statement', 'children': ['254']}; {'id': '254', 'type': 'assignment', 'children': ['255', '256']}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'is_beginning'}; {'id': '256', 'type': 'True', 'children': []}; {'id': '257', 'type': 'for_statement', 'children': ['258', '261', '272']}; {'id': '258', 'type': 'pattern_list', 'children': ['259', '260']}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'aligned_col'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'char'}; {'id': '261', 'type': 'call', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '263', 'type': 'argument_list', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'aligned_cols'}; {'id': '265', 'type': 'call', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'replace_asterisks'}; {'id': '267', 'type': 'argument_list', 'children': ['268', '271']}; {'id': '268', 'type': 'attribute', 'children': ['269', '270']}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '272', 'type': 'block', 'children': ['273']}; {'id': '273', 'type': 'if_statement', 'children': ['274', '275', '305']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'aligned_col'}; {'id': '275', 'type': 'block', 'children': ['276', '280']}; {'id': '276', 'type': 'expression_statement', 'children': ['277']}; {'id': '277', 'type': 'assignment', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'is_beginning'}; {'id': '279', 'type': 'False', 'children': []}; {'id': '280', 'type': 'if_statement', 'children': ['281', '284', '292']}; {'id': '281', 'type': 'comparison_operator', 'children': ['282', '283'], 'value': 'in'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'char'}; {'id': '283', 'type': 'string', 'children': [], 'value': "'-.'"}; {'id': '284', 'type': 'block', 'children': ['285']}; {'id': '285', 'type': 'expression_statement', 'children': ['286']}; {'id': '286', 'type': 'call', 'children': ['287', '290']}; {'id': '287', 'type': 'attribute', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'new_mol_seq'}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '290', 'type': 'argument_list', 'children': ['291']}; {'id': '291', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '292', 'type': 'else_clause', 'children': ['293']}; {'id': '293', 'type': 'block', 'children': ['294']}; {'id': '294', 'type': 'expression_statement', 'children': ['295']}; {'id': '295', 'type': 'call', 'children': ['296', '299']}; {'id': '296', 'type': 'attribute', 'children': ['297', '298']}; {'id': '297', 'type': 'identifier', 'children': [], 'value': 'new_mol_seq'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '299', 'type': 'argument_list', 'children': ['300']}; {'id': '300', 'type': 'call', 'children': ['301', '304']}; {'id': '301', 'type': 'attribute', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'char'}; {'id': '303', 'type': 'identifier', 'children': [], 'value': 'upper'}; {'id': '304', 'type': 'argument_list', 'children': []}; {'id': '305', 'type': 'else_clause', 'children': ['306']}; {'id': '306', 'type': 'block', 'children': ['307']}; {'id': '307', 'type': 'if_statement', 'children': ['308', '314']}; {'id': '308', 'type': 'boolean_operator', 'children': ['309', '312'], 'value': 'and'}; {'id': '309', 'type': 'comparison_operator', 'children': ['310', '311'], 'value': 'not'}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'char'}; {'id': '311', 'type': 'string', 'children': [], 'value': "'-.'"}; {'id': '312', 'type': 'not_operator', 'children': ['313']}; {'id': '313', 'type': 'identifier', 'children': [], 'value': 'is_beginning'}; {'id': '314', 'type': 'block', 'children': ['315']}; {'id': '315', 'type': 'expression_statement', 'children': ['316']}; {'id': '316', 'type': 'call', 'children': ['317', '320']}; {'id': '317', 'type': 'attribute', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'new_mol_seq'}; {'id': '319', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '320', 'type': 'argument_list', 'children': ['321']}; {'id': '321', 'type': 'call', 'children': ['322', '325']}; {'id': '322', 'type': 'attribute', 'children': ['323', '324']}; {'id': '323', 'type': 'identifier', 'children': [], 'value': 'char'}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '325', 'type': 'argument_list', 'children': []}; {'id': '326', 'type': 'expression_statement', 'children': ['327']}; {'id': '327', 'type': 'assignment', 'children': ['328', '331']}; {'id': '328', 'type': 'attribute', 'children': ['329', '330']}; {'id': '329', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '331', 'type': 'call', 'children': ['332', '335']}; {'id': '332', 'type': 'attribute', 'children': ['333', '334']}; {'id': '333', 'type': 'string', 'children': [], 'value': "''"}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '335', 'type': 'argument_list', 'children': ['336']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'new_mol_seq'}; {'id': '337', 'type': 'if_statement', 'children': ['338', '339']}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'do_iron'}; {'id': '339', 'type': 'block', 'children': ['340']}; {'id': '340', 'type': 'expression_statement', 'children': ['341']}; {'id': '341', 'type': 'assignment', 'children': ['342', '345']}; {'id': '342', 'type': 'attribute', 'children': ['343', '344']}; {'id': '343', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '345', 'type': 'call', 'children': ['346', '347']}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'iron'}; {'id': '347', 'type': 'argument_list', 'children': ['348']}; {'id': '348', 'type': 'attribute', 'children': ['349', '350']}; {'id': '349', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '351', 'type': 'expression_statement', 'children': ['352']}; {'id': '352', 'type': 'call', 'children': ['353', '358']}; {'id': '353', 'type': 'attribute', 'children': ['354', '357']}; {'id': '354', 'type': 'subscript', 'children': ['355', '356']}; {'id': '355', 'type': 'identifier', 'children': [], 'value': 'block'}; {'id': '356', 'type': 'string', 'children': [], 'value': "'sequences'"}; {'id': '357', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '358', 'type': 'argument_list', 'children': ['359']}; {'id': '359', 'type': 'call', 'children': ['360', '361']}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'seqrecord2sequence'}; {'id': '361', 'type': 'argument_list', 'children': ['362', '363', '364']}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '363', 'type': 'identifier', 'children': [], 'value': 'qlen'}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '365', 'type': 'return_statement', 'children': ['366']}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'block'}
|
def collapse_to_consensus(seqrecords, strict=False, do_iron=True):
level = 0
name = seqrecords[0].id
if hasattr(seqrecords, '_records'):
if hasattr(seqrecords, 'level'):
level = seqrecords.level
if hasattr(seqrecords, 'name'):
name = seqrecords.name
seqrecords = seqrecords._records
consensus = seqrecords.pop(0)
cons_length = len(consensus)
for i, s in enumerate(seqrecords):
if len(s) != cons_length:
raise ValueError(
"Sequence
% (i+2, len(s), cons_length))
if '.' in str(consensus.seq):
if '-' in str(consensus.seq):
if strict:
raise ValueError("Consensus contains '-' gap characters")
logging.warn("Consensus sequence contains both '.' and '-' gap "
"characters -- is it really the consensus?")
aligned_cols = [(c not in '.-') for c in str(consensus.seq)]
else:
aligned_cols = [c != '.' for c in str(consensus.seq)]
else:
aligned_cols = [c != '-' for c in str(consensus.seq)]
consensus.seq = replace_asterisks(consensus.seq, 'consensus')
block = consensus2block(consensus, level=level, name=name)
qlen = block['query_length']
for index, rec in zip(xrange(2, len(seqrecords)+2), seqrecords):
new_mol_seq = []
is_beginning = True
for aligned_col, char in zip(aligned_cols,
replace_asterisks(rec.seq, index)):
if aligned_col:
is_beginning = False
if char in '-.':
new_mol_seq.append('-')
else:
new_mol_seq.append(char.upper())
else:
if char not in '-.' and not is_beginning:
new_mol_seq.append(char.lower())
rec.seq = ''.join(new_mol_seq)
if do_iron:
rec.seq = iron(rec.seq)
block['sequences'].append(seqrecord2sequence(rec, qlen, index))
return block
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'iron'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'sequence'}; {'id': '5', 'type': 'block', 'children': ['6', '15', '19', '389']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'r_indel'}; {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'compile'}; {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'string', 'children': [], 'value': "r'(-[a-y]|[a-y]-)'"}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'orig_sequence'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'sequence'}; {'id': '19', 'type': 'while_statement', 'children': ['20', '26']}; {'id': '20', 'type': 'call', 'children': ['21', '24']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'r_indel'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'search'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'sequence'}; {'id': '26', 'type': 'block', 'children': ['27', '31', '35', '39', '43', '47', '326', '336', '348', '357']}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'in_insert'}; {'id': '30', 'type': 'False', 'children': []}; {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'in_gap'}; {'id': '34', 'type': 'False', 'children': []}; {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'seen_gaps'}; {'id': '38', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'inserts'}; {'id': '42', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'outchars'}; {'id': '46', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '47', 'type': 'for_statement', 'children': ['48', '49', '50']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'char'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'sequence'}; {'id': '50', 'type': 'block', 'children': ['51']}; {'id': '51', 'type': 'if_statement', 'children': ['52', '53', '162', '263']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'in_insert'}; {'id': '53', 'type': 'block', 'children': ['54']}; {'id': '54', 'type': 'if_statement', 'children': ['55', '60', '68', '110']}; {'id': '55', 'type': 'call', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'char'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'islower'}; {'id': '59', 'type': 'argument_list', 'children': []}; {'id': '60', 'type': 'block', 'children': ['61']}; {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'call', 'children': ['63', '66']}; {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'inserts'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'char'}; {'id': '68', 'type': 'elif_clause', 'children': ['69', '74']}; {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'char'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'isupper'}; {'id': '73', 'type': 'argument_list', 'children': []}; {'id': '74', 'type': 'block', 'children': ['75', '79', '86', '90', '99', '103']}; {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'in_insert'}; {'id': '78', 'type': 'False', 'children': []}; {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'call', 'children': ['81', '84']}; {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'outchars'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'inserts'}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}; {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'inserts'}; {'id': '89', 'type': 'list', 'children': [], 'value': '[]'}; {'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': 'outchars'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'binary_operator', 'children': ['97', '98'], 'value': '*'}; {'id': '97', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'seen_gaps'}; {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'seen_gaps'}; {'id': '102', 'type': 'integer', 'children': [], 'value': '0'}; {'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': 'outchars'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'char'}; {'id': '110', 'type': 'else_clause', 'children': ['111']}; {'id': '111', 'type': 'block', 'children': ['112', '116']}; {'id': '112', 'type': 'assert_statement', 'children': ['113']}; {'id': '113', 'type': 'comparison_operator', 'children': ['114', '115'], 'value': '=='}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'char'}; {'id': '115', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '116', 'type': 'if_statement', 'children': ['117', '119', '132']}; {'id': '117', 'type': 'not_operator', 'children': ['118']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'inserts'}; {'id': '119', 'type': 'block', 'children': ['120', '124', '128']}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}; {'id': '121', 'type': 'assignment', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'in_insert'}; {'id': '123', 'type': 'False', 'children': []}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}; {'id': '125', 'type': 'assignment', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'in_gap'}; {'id': '127', 'type': 'True', 'children': []}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}; {'id': '129', 'type': 'augmented_assignment', 'children': ['130', '131'], 'value': '+='}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'seen_gaps'}; {'id': '131', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '132', 'type': 'else_clause', 'children': ['133']}; {'id': '133', 'type': 'block', 'children': ['134', '150']}; {'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': 'outchars'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'call', 'children': ['141', '149']}; {'id': '141', 'type': 'attribute', 'children': ['142', '148']}; {'id': '142', 'type': 'call', 'children': ['143', '146']}; {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'inserts'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '146', 'type': 'argument_list', 'children': ['147']}; {'id': '147', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'upper'}; {'id': '149', 'type': 'argument_list', 'children': []}; {'id': '150', 'type': 'if_statement', 'children': ['151', '153']}; {'id': '151', 'type': 'not_operator', 'children': ['152']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'inserts'}; {'id': '153', 'type': 'block', 'children': ['154', '158']}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}; {'id': '155', 'type': 'assignment', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'in_insert'}; {'id': '157', 'type': 'False', 'children': []}; {'id': '158', 'type': 'expression_statement', 'children': ['159']}; {'id': '159', 'type': 'assignment', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'in_gap'}; {'id': '161', 'type': 'True', 'children': []}; {'id': '162', 'type': 'elif_clause', 'children': ['163', '164']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'in_gap'}; {'id': '164', 'type': 'block', 'children': ['165']}; {'id': '165', 'type': 'if_statement', 'children': ['166', '171', '208', '253']}; {'id': '166', 'type': 'call', 'children': ['167', '170']}; {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'char'}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'islower'}; {'id': '170', 'type': 'argument_list', 'children': []}; {'id': '171', 'type': 'block', 'children': ['172', '176', '180', '203']}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}; {'id': '173', 'type': 'assignment', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'in_insert'}; {'id': '175', 'type': 'True', 'children': []}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}; {'id': '177', 'type': 'assignment', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'in_gap'}; {'id': '179', 'type': 'False', 'children': []}; {'id': '180', 'type': 'if_statement', 'children': ['181', '182']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'inserts'}; {'id': '182', 'type': 'block', 'children': ['183', '190', '199']}; {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'call', 'children': ['185', '188']}; {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'outchars'}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '188', 'type': 'argument_list', 'children': ['189']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'inserts'}; {'id': '190', 'type': 'expression_statement', 'children': ['191']}; {'id': '191', 'type': 'call', 'children': ['192', '195']}; {'id': '192', 'type': 'attribute', 'children': ['193', '194']}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'outchars'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '195', 'type': 'argument_list', 'children': ['196']}; {'id': '196', 'type': 'binary_operator', 'children': ['197', '198'], 'value': '*'}; {'id': '197', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'seen_gaps'}; {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'assignment', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'seen_gaps'}; {'id': '202', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '203', 'type': 'expression_statement', 'children': ['204']}; {'id': '204', 'type': 'assignment', 'children': ['205', '206']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'inserts'}; {'id': '206', 'type': 'list', 'children': ['207'], 'value': '[char]'}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'char'}; {'id': '208', 'type': 'elif_clause', 'children': ['209', '214']}; {'id': '209', 'type': 'call', 'children': ['210', '213']}; {'id': '210', 'type': 'attribute', 'children': ['211', '212']}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'char'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'isupper'}; {'id': '213', 'type': 'argument_list', 'children': []}; {'id': '214', 'type': 'block', 'children': ['215', '219', '233', '242', '246']}; {'id': '215', 'type': 'expression_statement', 'children': ['216']}; {'id': '216', 'type': 'assignment', 'children': ['217', '218']}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'in_gap'}; {'id': '218', 'type': 'False', 'children': []}; {'id': '219', 'type': 'if_statement', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'inserts'}; {'id': '221', 'type': 'block', 'children': ['222', '229']}; {'id': '222', 'type': 'expression_statement', 'children': ['223']}; {'id': '223', 'type': 'call', 'children': ['224', '227']}; {'id': '224', 'type': 'attribute', 'children': ['225', '226']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'outchars'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '227', 'type': 'argument_list', 'children': ['228']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'inserts'}; {'id': '229', 'type': 'expression_statement', 'children': ['230']}; {'id': '230', 'type': 'assignment', 'children': ['231', '232']}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'inserts'}; {'id': '232', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '233', 'type': 'expression_statement', 'children': ['234']}; {'id': '234', 'type': 'call', 'children': ['235', '238']}; {'id': '235', 'type': 'attribute', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'outchars'}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '238', 'type': 'argument_list', 'children': ['239']}; {'id': '239', 'type': 'binary_operator', 'children': ['240', '241'], 'value': '*'}; {'id': '240', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'seen_gaps'}; {'id': '242', 'type': 'expression_statement', 'children': ['243']}; {'id': '243', 'type': 'assignment', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'seen_gaps'}; {'id': '245', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '246', 'type': 'expression_statement', 'children': ['247']}; {'id': '247', 'type': 'call', 'children': ['248', '251']}; {'id': '248', 'type': 'attribute', 'children': ['249', '250']}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'outchars'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '251', 'type': 'argument_list', 'children': ['252']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'char'}; {'id': '253', 'type': 'else_clause', 'children': ['254']}; {'id': '254', 'type': 'block', 'children': ['255', '259']}; {'id': '255', 'type': 'assert_statement', 'children': ['256']}; {'id': '256', 'type': 'comparison_operator', 'children': ['257', '258'], 'value': '=='}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'char'}; {'id': '258', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '259', 'type': 'expression_statement', 'children': ['260']}; {'id': '260', 'type': 'augmented_assignment', 'children': ['261', '262'], 'value': '+='}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'seen_gaps'}; {'id': '262', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '263', 'type': 'else_clause', 'children': ['264']}; {'id': '264', 'type': 'block', 'children': ['265', '280']}; {'id': '265', 'type': 'assert_statement', 'children': ['266', '271']}; {'id': '266', 'type': 'boolean_operator', 'children': ['267', '269'], 'value': 'and'}; {'id': '267', 'type': 'not_operator', 'children': ['268']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'inserts'}; {'id': '269', 'type': 'not_operator', 'children': ['270']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'seen_gaps'}; {'id': '271', 'type': '()', 'children': ['272']}; {'id': '272', 'type': 'binary_operator', 'children': ['273', '274'], 'value': '%'}; {'id': '273', 'type': 'string', 'children': [], 'value': '"Inserts: %s, gaps: %s, seq: %s, in_ins=%s, in_gap=%s"'}; {'id': '274', 'type': 'tuple', 'children': ['275', '276', '277', '278', '279']}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'inserts'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'seen_gaps'}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'sequence'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'in_insert'}; {'id': '279', 'type': 'identifier', 'children': [], 'value': 'in_gap'}; {'id': '280', 'type': 'if_statement', 'children': ['281', '286', '294', '312']}; {'id': '281', 'type': 'call', 'children': ['282', '285']}; {'id': '282', 'type': 'attribute', 'children': ['283', '284']}; {'id': '283', 'type': 'identifier', 'children': [], 'value': 'char'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'isupper'}; {'id': '285', 'type': 'argument_list', 'children': []}; {'id': '286', 'type': 'block', 'children': ['287']}; {'id': '287', 'type': 'expression_statement', 'children': ['288']}; {'id': '288', 'type': 'call', 'children': ['289', '292']}; {'id': '289', 'type': 'attribute', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'outchars'}; {'id': '291', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '292', 'type': 'argument_list', 'children': ['293']}; {'id': '293', 'type': 'identifier', 'children': [], 'value': 'char'}; {'id': '294', 'type': 'elif_clause', 'children': ['295', '300']}; {'id': '295', 'type': 'call', 'children': ['296', '299']}; {'id': '296', 'type': 'attribute', 'children': ['297', '298']}; {'id': '297', 'type': 'identifier', 'children': [], 'value': 'char'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'islower'}; {'id': '299', 'type': 'argument_list', 'children': []}; {'id': '300', 'type': 'block', 'children': ['301', '308']}; {'id': '301', 'type': 'expression_statement', 'children': ['302']}; {'id': '302', 'type': 'call', 'children': ['303', '306']}; {'id': '303', 'type': 'attribute', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'inserts'}; {'id': '305', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '306', 'type': 'argument_list', 'children': ['307']}; {'id': '307', 'type': 'identifier', 'children': [], 'value': 'char'}; {'id': '308', 'type': 'expression_statement', 'children': ['309']}; {'id': '309', 'type': 'assignment', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'in_insert'}; {'id': '311', 'type': 'True', 'children': []}; {'id': '312', 'type': 'else_clause', 'children': ['313']}; {'id': '313', 'type': 'block', 'children': ['314', '318', '322']}; {'id': '314', 'type': 'assert_statement', 'children': ['315']}; {'id': '315', 'type': 'comparison_operator', 'children': ['316', '317'], 'value': '=='}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'char'}; {'id': '317', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '318', 'type': 'expression_statement', 'children': ['319']}; {'id': '319', 'type': 'augmented_assignment', 'children': ['320', '321'], 'value': '+='}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'seen_gaps'}; {'id': '321', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '322', 'type': 'expression_statement', 'children': ['323']}; {'id': '323', 'type': 'assignment', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'in_gap'}; {'id': '325', 'type': 'True', 'children': []}; {'id': '326', 'type': 'if_statement', 'children': ['327', '328']}; {'id': '327', 'type': 'identifier', 'children': [], 'value': 'inserts'}; {'id': '328', 'type': 'block', 'children': ['329']}; {'id': '329', 'type': 'expression_statement', 'children': ['330']}; {'id': '330', 'type': 'call', 'children': ['331', '334']}; {'id': '331', 'type': 'attribute', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'outchars'}; {'id': '333', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '334', 'type': 'argument_list', 'children': ['335']}; {'id': '335', 'type': 'identifier', 'children': [], 'value': 'inserts'}; {'id': '336', 'type': 'if_statement', 'children': ['337', '338']}; {'id': '337', 'type': 'identifier', 'children': [], 'value': 'seen_gaps'}; {'id': '338', 'type': 'block', 'children': ['339']}; {'id': '339', 'type': 'expression_statement', 'children': ['340']}; {'id': '340', 'type': 'call', 'children': ['341', '344']}; {'id': '341', 'type': 'attribute', 'children': ['342', '343']}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'outchars'}; {'id': '343', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '344', 'type': 'argument_list', 'children': ['345']}; {'id': '345', 'type': 'binary_operator', 'children': ['346', '347'], 'value': '*'}; {'id': '346', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '347', 'type': 'identifier', 'children': [], 'value': 'seen_gaps'}; {'id': '348', 'type': 'expression_statement', 'children': ['349']}; {'id': '349', 'type': 'assignment', 'children': ['350', '351']}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'sequence'}; {'id': '351', 'type': 'call', 'children': ['352', '355']}; {'id': '352', 'type': 'attribute', 'children': ['353', '354']}; {'id': '353', 'type': 'string', 'children': [], 'value': "''"}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '355', 'type': 'argument_list', 'children': ['356']}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'outchars'}; {'id': '357', 'type': 'assert_statement', 'children': ['358', '382']}; {'id': '358', 'type': '()', 'children': ['359']}; {'id': '359', 'type': 'comparison_operator', 'children': ['360', '371'], 'value': '=='}; {'id': '360', 'type': 'call', 'children': ['361', '370']}; {'id': '361', 'type': 'attribute', 'children': ['362', '369']}; {'id': '362', 'type': 'call', 'children': ['363', '366']}; {'id': '363', 'type': 'attribute', 'children': ['364', '365']}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'sequence'}; {'id': '365', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '366', 'type': 'argument_list', 'children': ['367', '368']}; {'id': '367', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '368', 'type': 'string', 'children': [], 'value': "''"}; {'id': '369', 'type': 'identifier', 'children': [], 'value': 'upper'}; {'id': '370', 'type': 'argument_list', 'children': []}; {'id': '371', 'type': 'call', 'children': ['372', '381']}; {'id': '372', 'type': 'attribute', 'children': ['373', '380']}; {'id': '373', 'type': 'call', 'children': ['374', '377']}; {'id': '374', 'type': 'attribute', 'children': ['375', '376']}; {'id': '375', 'type': 'identifier', 'children': [], 'value': 'orig_sequence'}; {'id': '376', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '377', 'type': 'argument_list', 'children': ['378', '379']}; {'id': '378', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '379', 'type': 'string', 'children': [], 'value': "''"}; {'id': '380', 'type': 'identifier', 'children': [], 'value': 'upper'}; {'id': '381', 'type': 'argument_list', 'children': []}; {'id': '382', 'type': 'binary_operator', 'children': ['383', '388'], 'value': '+'}; {'id': '383', 'type': 'binary_operator', 'children': ['384', '387'], 'value': '+'}; {'id': '384', 'type': 'binary_operator', 'children': ['385', '386'], 'value': '+'}; {'id': '385', 'type': 'string', 'children': [], 'value': "'\\nOrig: '"}; {'id': '386', 'type': 'identifier', 'children': [], 'value': 'orig_sequence'}; {'id': '387', 'type': 'string', 'children': [], 'value': "'\\nIron: '"}; {'id': '388', 'type': 'identifier', 'children': [], 'value': 'sequence'}; {'id': '389', 'type': 'return_statement', 'children': ['390']}; {'id': '390', 'type': 'identifier', 'children': [], 'value': 'sequence'}
|
def iron(sequence):
r_indel = re.compile(r'(-[a-y]|[a-y]-)')
orig_sequence = sequence
while r_indel.search(sequence):
in_insert = False
in_gap = False
seen_gaps = 0
inserts = []
outchars = []
for char in sequence:
if in_insert:
if char.islower():
inserts.append(char)
elif char.isupper():
in_insert = False
outchars.extend(inserts)
inserts = []
outchars.append('-' * seen_gaps)
seen_gaps = 0
outchars.append(char)
else:
assert char == '-'
if not inserts:
in_insert = False
in_gap = True
seen_gaps += 1
else:
outchars.append(inserts.pop(0).upper())
if not inserts:
in_insert = False
in_gap = True
elif in_gap:
if char.islower():
in_insert = True
in_gap = False
if inserts:
outchars.extend(inserts)
outchars.append('-' * seen_gaps)
seen_gaps = 0
inserts = [char]
elif char.isupper():
in_gap = False
if inserts:
outchars.extend(inserts)
inserts = []
outchars.append('-' * seen_gaps)
seen_gaps = 0
outchars.append(char)
else:
assert char == '-'
seen_gaps += 1
else:
assert not inserts and not seen_gaps, (
"Inserts: %s, gaps: %s, seq: %s, in_ins=%s, in_gap=%s"
% (inserts, seen_gaps, sequence, in_insert, in_gap))
if char.isupper():
outchars.append(char)
elif char.islower():
inserts.append(char)
in_insert = True
else:
assert char == '-'
seen_gaps += 1
in_gap = True
if inserts:
outchars.extend(inserts)
if seen_gaps:
outchars.append('-' * seen_gaps)
sequence = ''.join(outchars)
assert (sequence.replace('-', '').upper()
==
orig_sequence.replace('-', '').upper()), \
'\nOrig: ' + orig_sequence + \
'\nIron: ' + sequence
return sequence
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'collect_reponames'}; {'id': '3', 'type': 'parameters', 'children': []}; {'id': '4', 'type': 'block', 'children': ['5', '9', '146', '216']}; {'id': '5', 'type': 'expression_statement', 'children': ['6']}; {'id': '6', 'type': 'assignment', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'reponames'}; {'id': '8', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '9', 'type': 'try_statement', 'children': ['10', '136', '140']}; {'id': '10', 'type': 'block', 'children': ['11', '40', '44', '99']}; {'id': '11', 'type': 'with_statement', 'children': ['12', '23']}; {'id': '12', 'type': 'with_clause', 'children': ['13']}; {'id': '13', 'type': 'with_item', 'children': ['14']}; {'id': '14', 'type': 'as_pattern', 'children': ['15', '21']}; {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'devnull'}; {'id': '21', 'type': 'as_pattern_target', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'devnull'}; {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}; {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'remote_data'}; {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'subprocess'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'check_output'}; {'id': '31', 'type': 'argument_list', 'children': ['32', '37']}; {'id': '32', 'type': 'list', 'children': ['33', '34', '35', '36'], 'value': '["git","remote","-v","show"]'}; {'id': '33', 'type': 'string', 'children': [], 'value': '"git"'}; {'id': '34', 'type': 'string', 'children': [], 'value': '"remote"'}; {'id': '35', 'type': 'string', 'children': [], 'value': '"-v"'}; {'id': '36', 'type': 'string', 'children': [], 'value': '"show"'}; {'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'stderr'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'devnull'}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}; {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'branches'}; {'id': '43', 'type': 'dictionary', 'children': []}; {'id': '44', 'type': 'for_statement', 'children': ['45', '46', '57']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '46', 'type': 'call', 'children': ['47', '55']}; {'id': '47', 'type': 'attribute', 'children': ['48', '54']}; {'id': '48', 'type': 'call', 'children': ['49', '52']}; {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'remote_data'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'decode'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}; {'id': '53', 'type': 'string', 'children': [], 'value': "'utf-8'"}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'string', 'children': [], 'value': '"\\n"'}; {'id': '57', 'type': 'block', 'children': ['58', '68', '77']}; {'id': '58', 'type': 'if_statement', 'children': ['59', '66']}; {'id': '59', 'type': 'comparison_operator', 'children': ['60', '65'], 'value': '=='}; {'id': '60', 'type': 'call', 'children': ['61', '64']}; {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '64', 'type': 'argument_list', 'children': []}; {'id': '65', 'type': 'string', 'children': [], 'value': '""'}; {'id': '66', 'type': 'block', 'children': ['67']}; {'id': '67', 'type': 'continue_statement', 'children': []}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}; {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'remote_match'}; {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 're_mote'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '77', 'type': 'if_statement', 'children': ['78', '82']}; {'id': '78', 'type': 'not_operator', 'children': ['79']}; {'id': '79', 'type': 'comparison_operator', 'children': ['80', '81'], 'value': 'is'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'remote_match'}; {'id': '81', 'type': 'None', 'children': []}; {'id': '82', 'type': 'block', 'children': ['83']}; {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '93']}; {'id': '85', 'type': 'subscript', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'branches'}; {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'remote_match'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '93', 'type': 'call', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'remote_match'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '99', 'type': 'if_statement', 'children': ['100', '106']}; {'id': '100', 'type': 'comparison_operator', 'children': ['101', '105'], 'value': '>'}; {'id': '101', 'type': 'call', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '103', 'type': 'argument_list', 'children': ['104']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'branches'}; {'id': '105', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '106', 'type': 'block', 'children': ['107']}; {'id': '107', 'type': 'if_statement', 'children': ['108', '111', '121']}; {'id': '108', 'type': 'comparison_operator', 'children': ['109', '110'], 'value': 'in'}; {'id': '109', 'type': 'string', 'children': [], 'value': '"origin"'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'branches'}; {'id': '111', 'type': 'block', 'children': ['112']}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}; {'id': '113', 'type': 'call', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'reponames'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'subscript', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'branches'}; {'id': '120', 'type': 'string', 'children': [], 'value': '"origin"'}; {'id': '121', 'type': 'else_clause', 'children': ['122']}; {'id': '122', 'type': 'block', 'children': ['123']}; {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'call', 'children': ['125', '128']}; {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'reponames'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '128', 'type': 'argument_list', 'children': ['129']}; {'id': '129', 'type': 'subscript', 'children': ['130', '135']}; {'id': '130', 'type': 'call', 'children': ['131', '134']}; {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'branches'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '134', 'type': 'argument_list', 'children': []}; {'id': '135', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '136', 'type': 'except_clause', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'OSError'}; {'id': '138', 'type': 'block', 'children': ['139']}; {'id': '139', 'type': 'pass_statement', 'children': []}; {'id': '140', 'type': 'except_clause', 'children': ['141', '144']}; {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'subprocess'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'CalledProcessError'}; {'id': '144', 'type': 'block', 'children': ['145']}; {'id': '145', 'type': 'pass_statement', 'children': []}; {'id': '146', 'type': 'for_statement', 'children': ['147', '148', '154']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'fname'}; {'id': '148', 'type': 'call', 'children': ['149', '152']}; {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'glob'}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'iglob'}; {'id': '152', 'type': 'argument_list', 'children': ['153']}; {'id': '153', 'type': 'string', 'children': [], 'value': '"*.html"'}; {'id': '154', 'type': 'block', 'children': ['155', '164', '170', '178', '188', '206']}; {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'assignment', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'fid'}; {'id': '158', 'type': 'call', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '160', 'type': 'argument_list', 'children': ['161', '162', '163']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'fname'}; {'id': '162', 'type': 'string', 'children': [], 'value': '"r"'}; {'id': '163', 'type': 'string', 'children': [], 'value': '"utf8"'}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}; {'id': '165', 'type': 'call', 'children': ['166', '169']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'fid'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'readline'}; {'id': '169', 'type': 'argument_list', 'children': []}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}; {'id': '171', 'type': 'assignment', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '173', 'type': 'call', 'children': ['174', '177']}; {'id': '174', 'type': 'attribute', 'children': ['175', '176']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'fid'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'readline'}; {'id': '177', 'type': 'argument_list', 'children': []}; {'id': '178', 'type': 'expression_statement', 'children': ['179']}; {'id': '179', 'type': 'assignment', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '181', 'type': 'call', 'children': ['182', '185']}; {'id': '182', 'type': 'attribute', 'children': ['183', '184']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '185', 'type': 'argument_list', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'repo_marker_re'}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '188', 'type': 'if_statement', 'children': ['189', '193']}; {'id': '189', 'type': 'not_operator', 'children': ['190']}; {'id': '190', 'type': 'comparison_operator', 'children': ['191', '192'], 'value': 'is'}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '192', 'type': 'None', 'children': []}; {'id': '193', 'type': 'block', 'children': ['194']}; {'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': 'reponames'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '199', 'type': 'argument_list', 'children': ['200']}; {'id': '200', 'type': 'call', 'children': ['201', '204']}; {'id': '201', 'type': 'attribute', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '204', 'type': 'argument_list', 'children': ['205']}; {'id': '205', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '206', 'type': 'expression_statement', 'children': ['207']}; {'id': '207', 'type': 'assignment', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'reponames'}; {'id': '209', 'type': 'call', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '211', 'type': 'argument_list', 'children': ['212']}; {'id': '212', 'type': 'call', 'children': ['213', '214']}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '214', 'type': 'argument_list', 'children': ['215']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'reponames'}; {'id': '216', 'type': 'return_statement', 'children': ['217']}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'reponames'}
|
def collect_reponames():
reponames = []
try:
with open(os.devnull) as devnull:
remote_data = subprocess.check_output(["git","remote","-v","show"],stderr=devnull)
branches = {}
for line in remote_data.decode('utf-8').split("\n"):
if line.strip() == "":
continue
remote_match = re_mote.match(line)
if not remote_match is None:
branches[remote_match.group(1)] = remote_match.group(5)
if len(branches) > 0:
if "origin" in branches:
reponames.append(branches["origin"])
else:
reponames.append(branches.values()[0])
except OSError:
pass
except subprocess.CalledProcessError:
pass
for fname in glob.iglob("*.html"):
fid = open(fname,"r","utf8")
fid.readline()
line = fid.readline()
match = re.match(repo_marker_re,line)
if not match is None:
reponames.append(match.group(1))
reponames = list(set(reponames))
return reponames
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'build_markdown_table'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'headers'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'rows'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'row_keys'}; {'id': '8', 'type': 'None', 'children': []}; {'id': '9', 'type': 'block', 'children': ['10', '18', '34', '49', '65']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}; {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'row_maxes'}; {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '_find_row_maxes'}; {'id': '15', 'type': 'argument_list', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'headers'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'rows'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'row_keys'}; {'id': '21', 'type': 'boolean_operator', 'children': ['22', '23'], 'value': 'or'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'row_keys'}; {'id': '23', 'type': 'list_comprehension', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '25', 'type': 'for_in_clause', 'children': ['26', '29']}; {'id': '26', 'type': 'pattern_list', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'headers'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '33', 'type': 'argument_list', 'children': []}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}; {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '37', 'type': 'list', 'children': ['38', '44'], 'value': '[\n _build_row(headers, row_maxes, row_keys),\n _build_separator(row_maxes, row_keys)\n ]'}; {'id': '38', 'type': 'call', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': '_build_row'}; {'id': '40', 'type': 'argument_list', 'children': ['41', '42', '43']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'headers'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'row_maxes'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'row_keys'}; {'id': '44', 'type': 'call', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': '_build_separator'}; {'id': '46', 'type': 'argument_list', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'row_maxes'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'row_keys'}; {'id': '49', 'type': 'for_statement', 'children': ['50', '51', '52']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'rows'}; {'id': '52', 'type': 'block', 'children': ['53']}; {'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': 'table'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}; {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': '_build_row'}; {'id': '61', 'type': 'argument_list', 'children': ['62', '63', '64']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'row_maxes'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'row_keys'}; {'id': '65', 'type': 'return_statement', 'children': ['66']}; {'id': '66', 'type': 'binary_operator', 'children': ['67', '73'], 'value': '+'}; {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}; {'id': '69', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '73', 'type': 'string', 'children': [], 'value': "'\\n'"}
|
def build_markdown_table(headers, rows, row_keys=None):
row_maxes = _find_row_maxes(headers, rows)
row_keys = row_keys or [key for key, value in headers.items()]
table = [
_build_row(headers, row_maxes, row_keys),
_build_separator(row_maxes, row_keys)
]
for row in rows:
table.append(_build_row(row, row_maxes, row_keys))
return '\n'.join(table) + '\n'
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'create_publication_assistant'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '7', 'type': 'block', 'children': ['8', '10', '16', '23', '33', '59', '85', '95', '147', '153']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'string', 'children': [], 'value': "'''\n Create an assistant for a dataset that allows to make PID\n requests for the dataset and all of its files.\n :param drs_id: Mandatory. The dataset id of the dataset\n to be published.\n :param version_number: Mandatory. The version number of the\n dataset to be published.\n :param is_replica: Mandatory. Flag to indicate whether the\n dataset is a replica.\n .. note:: If the replica flag is set to False, the publication\n may still be considered a replica by the consuming servlet,\n namely if the dataset was already published at a different\n host. For this, please refer to the consumer documentation.\n :return: A publication assistant which provides all necessary\n methods to publish a dataset and its files.\n '''"}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}; {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'logdebug'}; {'id': '13', 'type': 'argument_list', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'LOGGER'}; {'id': '15', 'type': 'string', 'children': [], 'value': "'Creating publication assistant..'"}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'mandatory_args'}; {'id': '19', 'type': 'list', 'children': ['20', '21', '22'], 'value': "['drs_id', 'version_number', 'is_replica']"}; {'id': '20', 'type': 'string', 'children': [], 'value': "'drs_id'"}; {'id': '21', 'type': 'string', 'children': [], 'value': "'version_number'"}; {'id': '22', 'type': 'string', 'children': [], 'value': "'is_replica'"}; {'id': '23', 'type': 'expression_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': 'esgfpid'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'check_presence_of_mandatory_args'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'mandatory_args'}; {'id': '33', 'type': 'if_statement', 'children': ['34', '39']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '38'], 'value': 'is'}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': '__thredds_service_path'}; {'id': '38', 'type': 'None', 'children': []}; {'id': '39', 'type': 'block', 'children': ['40', '44', '50']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}; {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '43', 'type': 'string', 'children': [], 'value': "'No thredds_service_path given (but it is mandatory for publication)'"}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}; {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'logwarn'}; {'id': '47', 'type': 'argument_list', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'LOGGER'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '50', 'type': 'raise_statement', 'children': ['51']}; {'id': '51', 'type': 'call', 'children': ['52', '57']}; {'id': '52', 'type': 'attribute', 'children': ['53', '56']}; {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'esgfpid'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'exceptions'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'ArgumentError'}; {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '59', 'type': 'if_statement', 'children': ['60', '65']}; {'id': '60', 'type': 'comparison_operator', 'children': ['61', '64'], 'value': 'is'}; {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': '__data_node'}; {'id': '64', 'type': 'None', 'children': []}; {'id': '65', 'type': 'block', 'children': ['66', '70', '76']}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}; {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '69', 'type': 'string', 'children': [], 'value': "'No data_node given (but it is mandatory for publication)'"}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}; {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'logwarn'}; {'id': '73', 'type': 'argument_list', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'LOGGER'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '76', 'type': 'raise_statement', 'children': ['77']}; {'id': '77', 'type': 'call', 'children': ['78', '83']}; {'id': '78', 'type': 'attribute', 'children': ['79', '82']}; {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'esgfpid'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'exceptions'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'ArgumentError'}; {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '85', 'type': 'if_statement', 'children': ['86', '93']}; {'id': '86', 'type': 'call', 'children': ['87', '92']}; {'id': '87', 'type': 'attribute', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': '__coupler'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'is_solr_switched_off'}; {'id': '92', 'type': 'argument_list', 'children': []}; {'id': '93', 'type': 'block', 'children': ['94']}; {'id': '94', 'type': 'pass_statement', 'children': []}; {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'assistant'}; {'id': '98', 'type': 'call', 'children': ['99', '106']}; {'id': '99', 'type': 'attribute', 'children': ['100', '105']}; {'id': '100', 'type': 'attribute', 'children': ['101', '104']}; {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'esgfpid'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'assistant'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'publish'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'DatasetPublicationAssistant'}; {'id': '106', 'type': 'argument_list', 'children': ['107', '112', '117', '122', '127', '132', '137', '142']}; {'id': '107', 'type': 'keyword_argument', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'drs_id'}; {'id': '109', 'type': 'subscript', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '111', 'type': 'string', 'children': [], 'value': "'drs_id'"}; {'id': '112', 'type': 'keyword_argument', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'version_number'}; {'id': '114', 'type': 'subscript', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '116', 'type': 'string', 'children': [], 'value': "'version_number'"}; {'id': '117', 'type': 'keyword_argument', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'thredds_service_path'}; {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': '__thredds_service_path'}; {'id': '122', 'type': 'keyword_argument', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'data_node'}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': '__data_node'}; {'id': '127', 'type': 'keyword_argument', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '132', 'type': 'keyword_argument', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'coupler'}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': '__coupler'}; {'id': '137', 'type': 'keyword_argument', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'is_replica'}; {'id': '139', 'type': 'subscript', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '141', 'type': 'string', 'children': [], 'value': "'is_replica'"}; {'id': '142', 'type': 'keyword_argument', 'children': ['143', '144']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'consumer_solr_url'}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': '__consumer_solr_url'}; {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'call', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'logdebug'}; {'id': '150', 'type': 'argument_list', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'LOGGER'}; {'id': '152', 'type': 'string', 'children': [], 'value': "'Creating publication assistant.. done'"}; {'id': '153', 'type': 'return_statement', 'children': ['154']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'assistant'}
|
def create_publication_assistant(self, **args):
'''
Create an assistant for a dataset that allows to make PID
requests for the dataset and all of its files.
:param drs_id: Mandatory. The dataset id of the dataset
to be published.
:param version_number: Mandatory. The version number of the
dataset to be published.
:param is_replica: Mandatory. Flag to indicate whether the
dataset is a replica.
.. note:: If the replica flag is set to False, the publication
may still be considered a replica by the consuming servlet,
namely if the dataset was already published at a different
host. For this, please refer to the consumer documentation.
:return: A publication assistant which provides all necessary
methods to publish a dataset and its files.
'''
logdebug(LOGGER, 'Creating publication assistant..')
mandatory_args = ['drs_id', 'version_number', 'is_replica']
esgfpid.utils.check_presence_of_mandatory_args(args, mandatory_args)
if self.__thredds_service_path is None:
msg = 'No thredds_service_path given (but it is mandatory for publication)'
logwarn(LOGGER, msg)
raise esgfpid.exceptions.ArgumentError(msg)
if self.__data_node is None:
msg = 'No data_node given (but it is mandatory for publication)'
logwarn(LOGGER, msg)
raise esgfpid.exceptions.ArgumentError(msg)
if self.__coupler.is_solr_switched_off():
pass
assistant = esgfpid.assistant.publish.DatasetPublicationAssistant(
drs_id=args['drs_id'],
version_number=args['version_number'],
thredds_service_path=self.__thredds_service_path,
data_node=self.__data_node,
prefix=self.prefix,
coupler=self.__coupler,
is_replica=args['is_replica'],
consumer_solr_url=self.__consumer_solr_url
)
logdebug(LOGGER, 'Creating publication assistant.. done')
return assistant
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'replace_source'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'modules'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '9', 'type': 'block', 'children': ['10', '14', '102', '115', '126', '135', '139', '196', '207', '219', '232', '242', '250', '272', '276', '289', '302', '314']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}; {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'needs_windll'}; {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'function_definition', 'children': ['15', '16', '20']}; {'id': '15', 'type': 'function_name', 'children': [], 'value': '_func_replacer'}; {'id': '16', 'type': 'parameters', 'children': ['17', '18', '19']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'modules'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'windll'}; {'id': '20', 'type': 'block', 'children': ['21', '30', '39', '50', '100']}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'matched'}; {'id': '24', 'type': 'call', 'children': ['25', '28']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}; {'id': '29', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '30', 'type': 'if_statement', 'children': ['31', '36']}; {'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': 'in'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'matched'}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'BLACKLIST'}; {'id': '36', 'type': 'block', 'children': ['37']}; {'id': '37', 'type': 'return_statement', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'matched'}; {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '42', 'type': 'call', 'children': ['43', '48']}; {'id': '43', 'type': 'attribute', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'database'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'query_func_module'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'matched'}; {'id': '50', 'type': 'if_statement', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '52', 'type': 'block', 'children': ['53', '80', '92']}; {'id': '53', 'type': 'try_statement', 'children': ['54', '66']}; {'id': '54', 'type': 'block', 'children': ['55']}; {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'augmented_assignment', 'children': ['57', '62'], 'value': '+='}; {'id': '57', 'type': 'subscript', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'modules'}; {'id': '59', 'type': 'subscript', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '61', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '62', 'type': 'list', 'children': ['63'], 'value': '[module[1]]'}; {'id': '63', 'type': 'subscript', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '65', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '66', 'type': 'except_clause', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '68', 'type': 'block', 'children': ['69']}; {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '76']}; {'id': '71', 'type': 'subscript', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'modules'}; {'id': '73', 'type': 'subscript', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '75', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '76', 'type': 'list', 'children': ['77'], 'value': '[module[1]]'}; {'id': '77', 'type': 'subscript', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '79', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '80', 'type': 'if_statement', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'windll'}; {'id': '82', 'type': 'block', 'children': ['83']}; {'id': '83', 'type': 'return_statement', 'children': ['84']}; {'id': '84', 'type': 'call', 'children': ['85', '88']}; {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'string', 'children': [], 'value': "'{}->{}.{}'"}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '88', 'type': 'argument_list', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'windll'}; {'id': '90', 'type': 'list_splat', 'children': ['91']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '92', 'type': 'return_statement', 'children': ['93']}; {'id': '93', 'type': 'call', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}; {'id': '95', 'type': 'string', 'children': [], 'value': "'{}->{}'"}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'list_splat', 'children': ['99']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '100', 'type': 'return_statement', 'children': ['101']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'matched'}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}; {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'replacer'}; {'id': '105', 'type': 'call', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'partial'}; {'id': '107', 'type': 'argument_list', 'children': ['108', '109', '112']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': '_func_replacer'}; {'id': '109', 'type': 'keyword_argument', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'modules'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'modules'}; {'id': '112', 'type': 'keyword_argument', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'windll'}; {'id': '114', 'type': 'string', 'children': [], 'value': "'windll'"}; {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'replaced'}; {'id': '118', 'type': 'call', 'children': ['119', '122']}; {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'sub'}; {'id': '122', 'type': 'argument_list', 'children': ['123', '124', '125']}; {'id': '123', 'type': 'string', 'children': [], 'value': "r'[_\\w][_\\w\\d]*(?=\\s*\\()'"}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'replacer'}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '126', 'type': 'if_statement', 'children': ['127', '130']}; {'id': '127', 'type': 'comparison_operator', 'children': ['128', '129'], 'value': '!='}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'replaced'}; {'id': '130', 'type': 'block', 'children': ['131']}; {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'needs_windll'}; {'id': '134', 'type': 'True', 'children': []}; {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'assignment', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'str_table'}; {'id': '138', 'type': 'dictionary', 'children': []}; {'id': '139', 'type': 'function_definition', 'children': ['140', '141', '143']}; {'id': '140', 'type': 'function_name', 'children': [], 'value': '_string_replacer'}; {'id': '141', 'type': 'parameters', 'children': ['142']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '143', 'type': 'block', 'children': ['144', '158', '188']}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}; {'id': '145', 'type': 'assignment', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'matched'}; {'id': '147', 'type': 'subscript', 'children': ['148', '153']}; {'id': '148', 'type': 'call', 'children': ['149', '152']}; {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '152', 'type': 'argument_list', 'children': []}; {'id': '153', 'type': 'slice', 'children': ['154', '155', '156']}; {'id': '154', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '155', 'type': 'colon', 'children': []}; {'id': '156', 'type': 'unary_operator', 'children': ['157'], 'value': '-'}; {'id': '157', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '158', 'type': 'try_statement', 'children': ['159', '166']}; {'id': '159', 'type': 'block', 'children': ['160']}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}; {'id': '161', 'type': 'assignment', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'number'}; {'id': '163', 'type': 'subscript', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'str_table'}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'matched'}; {'id': '166', 'type': 'except_clause', 'children': ['167', '168']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '168', 'type': 'block', 'children': ['169', '178']}; {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'assignment', 'children': ['171', '172']}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'number'}; {'id': '172', 'type': 'binary_operator', 'children': ['173', '177'], 'value': '+'}; {'id': '173', 'type': 'call', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '175', 'type': 'argument_list', 'children': ['176']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'str_table'}; {'id': '177', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '178', 'type': 'expression_statement', 'children': ['179']}; {'id': '179', 'type': 'call', 'children': ['180', '183']}; {'id': '180', 'type': 'attribute', 'children': ['181', '182']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'str_table'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '183', 'type': 'argument_list', 'children': ['184']}; {'id': '184', 'type': 'dictionary', 'children': ['185']}; {'id': '185', 'type': 'pair', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'matched'}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'number'}; {'id': '188', 'type': 'return_statement', 'children': ['189']}; {'id': '189', 'type': 'call', 'children': ['190', '193']}; {'id': '190', 'type': 'attribute', 'children': ['191', '192']}; {'id': '191', 'type': 'string', 'children': [], 'value': "'{}{}'"}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '193', 'type': 'argument_list', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'number'}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}; {'id': '197', 'type': 'assignment', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'replaced'}; {'id': '199', 'type': 'call', 'children': ['200', '203']}; {'id': '200', 'type': 'attribute', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'sub'}; {'id': '203', 'type': 'argument_list', 'children': ['204', '205', '206']}; {'id': '204', 'type': 'string', 'children': [], 'value': 'r\'".+?"\''}; {'id': '205', 'type': 'identifier', 'children': [], 'value': '_string_replacer'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'replaced'}; {'id': '207', 'type': 'expression_statement', 'children': ['208']}; {'id': '208', 'type': 'assignment', 'children': ['209', '212']}; {'id': '209', 'type': 'pattern_list', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'strings'}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'relocs'}; {'id': '212', 'type': 'call', 'children': ['213', '216']}; {'id': '213', 'type': 'attribute', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'build_strings'}; {'id': '216', 'type': 'argument_list', 'children': ['217', '218']}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'str_table'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '219', 'type': 'expression_statement', 'children': ['220']}; {'id': '220', 'type': 'assignment', 'children': ['221', '222']}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'strings'}; {'id': '222', 'type': 'call', 'children': ['223', '231']}; {'id': '223', 'type': 'attribute', 'children': ['224', '230']}; {'id': '224', 'type': 'call', 'children': ['225', '228']}; {'id': '225', 'type': 'attribute', 'children': ['226', '227']}; {'id': '226', 'type': 'string', 'children': [], 'value': "''"}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '228', 'type': 'argument_list', 'children': ['229']}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'strings'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '231', 'type': 'argument_list', 'children': []}; {'id': '232', 'type': 'expression_statement', 'children': ['233']}; {'id': '233', 'type': 'assignment', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'windll32'}; {'id': '235', 'type': 'call', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'reloc_var'}; {'id': '237', 'type': 'argument_list', 'children': ['238', '239', '240', '241']}; {'id': '238', 'type': 'string', 'children': [], 'value': "'windll'"}; {'id': '239', 'type': 'string', 'children': [], 'value': "'reloc_delta'"}; {'id': '240', 'type': 'True', 'children': []}; {'id': '241', 'type': 'string', 'children': [], 'value': "'windll_t'"}; {'id': '242', 'type': 'if_statement', 'children': ['243', '244']}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'needs_windll'}; {'id': '244', 'type': 'block', 'children': ['245']}; {'id': '245', 'type': 'expression_statement', 'children': ['246']}; {'id': '246', 'type': 'augmented_assignment', 'children': ['247', '248'], 'value': '+='}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'relocs'}; {'id': '248', 'type': 'list', 'children': ['249'], 'value': '[windll32]'}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'windll32'}; {'id': '250', 'type': 'if_statement', 'children': ['251', '252']}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'strings'}; {'id': '252', 'type': 'block', 'children': ['253', '259']}; {'id': '253', 'type': 'expression_statement', 'children': ['254']}; {'id': '254', 'type': 'assignment', 'children': ['255', '256']}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'strings'}; {'id': '256', 'type': 'binary_operator', 'children': ['257', '258'], 'value': '+'}; {'id': '257', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'strings'}; {'id': '259', 'type': 'if_statement', 'children': ['260', '262']}; {'id': '260', 'type': 'not_operator', 'children': ['261']}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'needs_windll'}; {'id': '262', 'type': 'block', 'children': ['263', '268']}; {'id': '263', 'type': 'expression_statement', 'children': ['264']}; {'id': '264', 'type': 'augmented_assignment', 'children': ['265', '266'], 'value': '+='}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'relocs'}; {'id': '266', 'type': 'list', 'children': ['267'], 'value': '[windll32]'}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'windll32'}; {'id': '268', 'type': 'expression_statement', 'children': ['269']}; {'id': '269', 'type': 'assignment', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'needs_windll'}; {'id': '271', 'type': 'True', 'children': []}; {'id': '272', 'type': 'expression_statement', 'children': ['273']}; {'id': '273', 'type': 'assignment', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'windll64'}; {'id': '275', 'type': 'string', 'children': [], 'value': "''"}; {'id': '276', 'type': 'if_statement', 'children': ['277', '278']}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'needs_windll'}; {'id': '278', 'type': 'block', 'children': ['279']}; {'id': '279', 'type': 'expression_statement', 'children': ['280']}; {'id': '280', 'type': 'assignment', 'children': ['281', '282']}; {'id': '281', 'type': 'identifier', 'children': [], 'value': 'windll64'}; {'id': '282', 'type': 'call', 'children': ['283', '286']}; {'id': '283', 'type': 'attribute', 'children': ['284', '285']}; {'id': '284', 'type': 'string', 'children': [], 'value': "'{0} *{1} = &_{1};\\n'"}; {'id': '285', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '286', 'type': 'argument_list', 'children': ['287', '288']}; {'id': '287', 'type': 'string', 'children': [], 'value': "'windll_t'"}; {'id': '288', 'type': 'string', 'children': [], 'value': "'windll'"}; {'id': '289', 'type': 'expression_statement', 'children': ['290']}; {'id': '290', 'type': 'assignment', 'children': ['291', '292']}; {'id': '291', 'type': 'identifier', 'children': [], 'value': 'relocs'}; {'id': '292', 'type': 'call', 'children': ['293', '294']}; {'id': '293', 'type': 'identifier', 'children': [], 'value': 'reloc_both'}; {'id': '294', 'type': 'argument_list', 'children': ['295', '301']}; {'id': '295', 'type': 'call', 'children': ['296', '299']}; {'id': '296', 'type': 'attribute', 'children': ['297', '298']}; {'id': '297', 'type': 'string', 'children': [], 'value': "''"}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '299', 'type': 'argument_list', 'children': ['300']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'relocs'}; {'id': '301', 'type': 'identifier', 'children': [], 'value': 'windll64'}; {'id': '302', 'type': 'if_statement', 'children': ['303', '307']}; {'id': '303', 'type': 'comparison_operator', 'children': ['304', '305'], 'value': 'in'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '305', 'type': 'list', 'children': ['306'], 'value': "['main']"}; {'id': '306', 'type': 'string', 'children': [], 'value': "'main'"}; {'id': '307', 'type': 'block', 'children': ['308']}; {'id': '308', 'type': 'expression_statement', 'children': ['309']}; {'id': '309', 'type': 'assignment', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'replaced'}; {'id': '311', 'type': 'binary_operator', 'children': ['312', '313'], 'value': '+'}; {'id': '312', 'type': 'string', 'children': [], 'value': "'\\ninit();'"}; {'id': '313', 'type': 'identifier', 'children': [], 'value': 'replaced'}; {'id': '314', 'type': 'return_statement', 'children': ['315']}; {'id': '315', 'type': 'binary_operator', 'children': ['316', '319'], 'value': '+'}; {'id': '316', 'type': 'binary_operator', 'children': ['317', '318'], 'value': '+'}; {'id': '317', 'type': 'identifier', 'children': [], 'value': 'strings'}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'relocs'}; {'id': '319', 'type': 'identifier', 'children': [], 'value': 'replaced'}
|
def replace_source(self, source, name, modules, prefix):
needs_windll = False
def _func_replacer(match, modules, windll):
matched = match.group(0)
if matched in self.BLACKLIST:
return matched
module = self.database.query_func_module(matched)
if module:
try:
modules[module[0]] += [module[1]]
except KeyError:
modules[module[0]] = [module[1]]
if windll:
return '{}->{}.{}'.format(windll, *module)
return '{}->{}'.format(*module)
return matched
replacer = partial(
_func_replacer, modules=modules, windll='windll')
replaced = re.sub(r'[_\w][_\w\d]*(?=\s*\()',
replacer, source)
if source != replaced:
needs_windll = True
str_table = {}
def _string_replacer(match):
matched = match.group()[1:-1]
try:
number = str_table[matched]
except KeyError:
number = len(str_table) + 1
str_table.update({matched: number})
return '{}{}'.format(prefix, number)
replaced = re.sub(r'".+?"', _string_replacer, replaced)
strings, relocs = self.build_strings(str_table, prefix)
strings = ''.join(strings).strip()
windll32 = reloc_var('windll', 'reloc_delta', True,
'windll_t')
if needs_windll:
relocs += [windll32]
if strings:
strings = '\n' + strings
if not needs_windll:
relocs += [windll32]
needs_windll = True
windll64 = ''
if needs_windll:
windll64 = '{0} *{1} = &_{1};\n'.format('windll_t',
'windll')
relocs = reloc_both(''.join(relocs), windll64)
if name in ['main']:
replaced = '\ninit();' + replaced
return strings + relocs + replaced
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_item'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'iterable'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'number'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '8', 'type': 'False', 'children': []}; {'id': '9', 'type': 'block', 'children': ['10']}; {'id': '10', 'type': 'return_statement', 'children': ['11']}; {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '13', 'type': 'argument_list', 'children': ['14', '15', '21']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'iterable'}; {'id': '15', 'type': 'keyword_argument', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'itemgetter'}; {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'number'}; {'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'reverse'}
|
def sort_item(iterable, number, reverse=False):
return sorted(iterable, key=itemgetter(number), reverse=reverse)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_equivalent_positions'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'block'}; {'id': '5', 'type': 'block', 'children': ['6', '16', '26', '40', '46', '52', '83', '98', '102', '106', '128', '148', '265']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'consensus'}; {'id': '9', 'type': 'subscript', 'children': ['10', '15']}; {'id': '10', 'type': 'subscript', 'children': ['11', '14']}; {'id': '11', 'type': 'subscript', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'block'}; {'id': '13', 'type': 'string', 'children': [], 'value': "'sequences'"}; {'id': '14', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '15', 'type': 'string', 'children': [], 'value': "'seq'"}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'rest'}; {'id': '19', 'type': 'subscript', 'children': ['20', '23']}; {'id': '20', 'type': 'subscript', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'block'}; {'id': '22', 'type': 'string', 'children': [], 'value': "'sequences'"}; {'id': '23', 'type': 'slice', 'children': ['24', '25']}; {'id': '24', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '25', 'type': 'colon', 'children': []}; {'id': '26', 'type': 'if_statement', 'children': ['27', '34']}; {'id': '27', 'type': 'boolean_operator', 'children': ['28', '31'], 'value': 'or'}; {'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': 'in'}; {'id': '29', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'consensus'}; {'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': 'in'}; {'id': '32', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'consensus'}; {'id': '34', 'type': 'block', 'children': ['35']}; {'id': '35', 'type': 'raise_statement', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}; {'id': '39', 'type': 'string', 'children': [], 'value': '"First sequence (consensus?) contains gaps"'}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}; {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'seen'}; {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '45', 'type': 'argument_list', 'children': []}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}; {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'dupes'}; {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '51', 'type': 'argument_list', 'children': []}; {'id': '52', 'type': 'for_statement', 'children': ['53', '54', '55']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'rest'}; {'id': '55', 'type': 'block', 'children': ['56']}; {'id': '56', 'type': 'if_statement', 'children': ['57', '62', '72']}; {'id': '57', 'type': 'comparison_operator', 'children': ['58', '61'], 'value': 'in'}; {'id': '58', 'type': 'subscript', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '60', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'seen'}; {'id': '62', 'type': 'block', 'children': ['63']}; {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'call', 'children': ['65', '68']}; {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'dupes'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}; {'id': '69', 'type': 'subscript', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '71', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '72', 'type': 'else_clause', 'children': ['73']}; {'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': 'seen'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'subscript', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '82', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '83', 'type': 'if_statement', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'dupes'}; {'id': '85', 'type': 'block', 'children': ['86']}; {'id': '86', 'type': 'raise_statement', 'children': ['87']}; {'id': '87', 'type': 'call', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'binary_operator', 'children': ['91', '92'], 'value': '+'}; {'id': '91', 'type': 'string', 'children': [], 'value': '"Duplicate sequences:\\n"'}; {'id': '92', 'type': 'call', 'children': ['93', '96']}; {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'dupes'}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}; {'id': '99', 'type': 'assignment', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'curr_shift'}; {'id': '101', 'type': 'dictionary', 'children': []}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}; {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'curr_resn'}; {'id': '105', 'type': 'dictionary', 'children': []}; {'id': '106', 'type': 'for_statement', 'children': ['107', '108', '109']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'rest'}; {'id': '109', 'type': 'block', 'children': ['110', '118']}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}; {'id': '111', 'type': 'assignment', 'children': ['112', '117']}; {'id': '112', 'type': 'subscript', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'curr_shift'}; {'id': '114', 'type': 'subscript', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '116', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '117', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}; {'id': '119', 'type': 'assignment', 'children': ['120', '125']}; {'id': '120', 'type': 'subscript', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'curr_resn'}; {'id': '122', 'type': 'subscript', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '124', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '125', 'type': 'subscript', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '127', 'type': 'string', 'children': [], 'value': "'head_len'"}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}; {'id': '129', 'type': 'assignment', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'equivalencies'}; {'id': '131', 'type': 'call', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '133', 'type': 'generator_expression', 'children': ['134', '139']}; {'id': '134', 'type': 'tuple', 'children': ['135', '138']}; {'id': '135', 'type': 'binary_operator', 'children': ['136', '137'], 'value': '+'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '137', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '138', 'type': 'dictionary', 'children': []}; {'id': '139', 'type': 'for_in_clause', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '141', 'type': 'call', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'xrange'}; {'id': '143', 'type': 'argument_list', 'children': ['144']}; {'id': '144', 'type': 'call', 'children': ['145', '146']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '146', 'type': 'argument_list', 'children': ['147']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'consensus'}; {'id': '148', 'type': 'for_statement', 'children': ['149', '152', '156']}; {'id': '149', 'type': 'pattern_list', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'char'}; {'id': '152', 'type': 'call', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '154', 'type': 'argument_list', 'children': ['155']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'consensus'}; {'id': '156', 'type': 'block', 'children': ['157', '163']}; {'id': '157', 'type': 'assert_statement', 'children': ['158']}; {'id': '158', 'type': 'call', 'children': ['159', '162']}; {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'char'}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'isupper'}; {'id': '162', 'type': 'argument_list', 'children': []}; {'id': '163', 'type': 'for_statement', 'children': ['164', '165', '166']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'rest'}; {'id': '166', 'type': 'block', 'children': ['167', '173', '181', '253']}; {'id': '167', 'type': 'expression_statement', 'children': ['168']}; {'id': '168', 'type': 'assignment', 'children': ['169', '170']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'rid'}; {'id': '170', 'type': 'subscript', 'children': ['171', '172']}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '172', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '173', 'type': 'expression_statement', 'children': ['174']}; {'id': '174', 'type': 'assignment', 'children': ['175', '176']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'strposn'}; {'id': '176', 'type': 'binary_operator', 'children': ['177', '178'], 'value': '+'}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '178', 'type': 'subscript', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'curr_shift'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'rid'}; {'id': '181', 'type': 'if_statement', 'children': ['182', '191', '198', '242']}; {'id': '182', 'type': 'call', 'children': ['183', '190']}; {'id': '183', 'type': 'attribute', 'children': ['184', '189']}; {'id': '184', 'type': 'subscript', 'children': ['185', '188']}; {'id': '185', 'type': 'subscript', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '187', 'type': 'string', 'children': [], 'value': "'seq'"}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'strposn'}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'isupper'}; {'id': '190', 'type': 'argument_list', 'children': []}; {'id': '191', 'type': 'block', 'children': ['192']}; {'id': '192', 'type': 'expression_statement', 'children': ['193']}; {'id': '193', 'type': 'augmented_assignment', 'children': ['194', '197'], 'value': '+='}; {'id': '194', 'type': 'subscript', 'children': ['195', '196']}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'curr_resn'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'rid'}; {'id': '197', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '198', 'type': 'elif_clause', 'children': ['199', '208']}; {'id': '199', 'type': 'call', 'children': ['200', '207']}; {'id': '200', 'type': 'attribute', 'children': ['201', '206']}; {'id': '201', 'type': 'subscript', 'children': ['202', '205']}; {'id': '202', 'type': 'subscript', 'children': ['203', '204']}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '204', 'type': 'string', 'children': [], 'value': "'seq'"}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'strposn'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'islower'}; {'id': '207', 'type': 'argument_list', 'children': []}; {'id': '208', 'type': 'block', 'children': ['209', '236']}; {'id': '209', 'type': 'while_statement', 'children': ['210', '219']}; {'id': '210', 'type': 'call', 'children': ['211', '218']}; {'id': '211', 'type': 'attribute', 'children': ['212', '217']}; {'id': '212', 'type': 'subscript', 'children': ['213', '216']}; {'id': '213', 'type': 'subscript', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '215', 'type': 'string', 'children': [], 'value': "'seq'"}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'strposn'}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'islower'}; {'id': '218', 'type': 'argument_list', 'children': []}; {'id': '219', 'type': 'block', 'children': ['220', '226', '232']}; {'id': '220', 'type': 'expression_statement', 'children': ['221']}; {'id': '221', 'type': 'augmented_assignment', 'children': ['222', '225'], 'value': '+='}; {'id': '222', 'type': 'subscript', 'children': ['223', '224']}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'curr_shift'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'rid'}; {'id': '225', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '226', 'type': 'expression_statement', 'children': ['227']}; {'id': '227', 'type': 'augmented_assignment', 'children': ['228', '231'], 'value': '+='}; {'id': '228', 'type': 'subscript', 'children': ['229', '230']}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'curr_resn'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'rid'}; {'id': '231', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '232', 'type': 'expression_statement', 'children': ['233']}; {'id': '233', 'type': 'augmented_assignment', 'children': ['234', '235'], 'value': '+='}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'strposn'}; {'id': '235', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '236', 'type': 'expression_statement', 'children': ['237']}; {'id': '237', 'type': 'augmented_assignment', 'children': ['238', '241'], 'value': '+='}; {'id': '238', 'type': 'subscript', 'children': ['239', '240']}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'curr_resn'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'rid'}; {'id': '241', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '242', 'type': 'else_clause', 'children': ['243']}; {'id': '243', 'type': 'block', 'children': ['244', '252']}; {'id': '244', 'type': 'assert_statement', 'children': ['245']}; {'id': '245', 'type': 'comparison_operator', 'children': ['246', '251'], 'value': 'in'}; {'id': '246', 'type': 'subscript', 'children': ['247', '250']}; {'id': '247', 'type': 'subscript', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '249', 'type': 'string', 'children': [], 'value': "'seq'"}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'strposn'}; {'id': '251', 'type': 'string', 'children': [], 'value': "'.-'"}; {'id': '252', 'type': 'continue_statement', 'children': []}; {'id': '253', 'type': 'expression_statement', 'children': ['254']}; {'id': '254', 'type': 'assignment', 'children': ['255', '262']}; {'id': '255', 'type': 'subscript', 'children': ['256', '261']}; {'id': '256', 'type': 'subscript', 'children': ['257', '258']}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'equivalencies'}; {'id': '258', 'type': 'binary_operator', 'children': ['259', '260'], 'value': '+'}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '260', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'rid'}; {'id': '262', 'type': 'subscript', 'children': ['263', '264']}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'curr_resn'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'rid'}; {'id': '265', 'type': 'return_statement', 'children': ['266']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'equivalencies'}
|
def get_equivalent_positions(block):
consensus = block['sequences'][0]['seq']
rest = block['sequences'][1:]
if '-' in consensus or '.' in consensus:
raise ValueError("First sequence (consensus?) contains gaps")
seen = set()
dupes = set()
for rec in rest:
if rec['id'] in seen:
dupes.add(rec['id'])
else:
seen.add(rec['id'])
if dupes:
raise ValueError("Duplicate sequences:\n" + '\n'.join(dupes))
curr_shift = {}
curr_resn = {}
for rec in rest:
curr_shift[rec['id']] = 0
curr_resn[rec['id']] = rec['head_len']
equivalencies = dict((i+1, {}) for i in xrange(len(consensus)))
for i, char in enumerate(consensus):
assert char.isupper()
for rec in rest:
rid = rec['id']
strposn = i + curr_shift[rid]
if rec['seq'][strposn].isupper():
curr_resn[rid] += 1
elif rec['seq'][strposn].islower():
while rec['seq'][strposn].islower():
curr_shift[rid] += 1
curr_resn[rid] += 1
strposn += 1
curr_resn[rid] += 1
else:
assert rec['seq'][strposn] in '.-'
continue
equivalencies[i+1][rid] = curr_resn[rid]
return equivalencies
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'remove_path_segments'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'removes'}; {'id': '6', 'type': 'block', 'children': ['7', '20', '33', '142']}; {'id': '7', 'type': 'if_statement', 'children': ['8', '12']}; {'id': '8', 'type': 'comparison_operator', 'children': ['9', '10'], 'value': '=='}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '10', 'type': 'list', 'children': ['11'], 'value': "['']"}; {'id': '11', 'type': 'string', 'children': [], 'value': "''"}; {'id': '12', 'type': 'block', 'children': ['13']}; {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'call', 'children': ['15', '18']}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}; {'id': '19', 'type': 'string', 'children': [], 'value': "''"}; {'id': '20', 'type': 'if_statement', 'children': ['21', '25']}; {'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': '=='}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'removes'}; {'id': '23', 'type': 'list', 'children': ['24'], 'value': "['']"}; {'id': '24', 'type': 'string', 'children': [], 'value': "''"}; {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}; {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'removes'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'string', 'children': [], 'value': "''"}; {'id': '33', 'type': 'if_statement', 'children': ['34', '37', '42', '57']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': '=='}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'removes'}; {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}; {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '41', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '42', 'type': 'elif_clause', 'children': ['43', '52']}; {'id': '43', 'type': 'comparison_operator', 'children': ['44', '48'], 'value': '>'}; {'id': '44', 'type': 'call', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'removes'}; {'id': '48', 'type': 'call', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'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': 'ret'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '57', 'type': 'else_clause', 'children': ['58']}; {'id': '58', 'type': 'block', 'children': ['59', '66', '87']}; {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'removes2'}; {'id': '62', 'type': 'call', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'removes'}; {'id': '66', 'type': 'if_statement', 'children': ['67', '79']}; {'id': '67', 'type': 'boolean_operator', 'children': ['68', '74'], 'value': 'and'}; {'id': '68', 'type': 'comparison_operator', 'children': ['69', '73'], 'value': '>'}; {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'removes'}; {'id': '73', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '74', 'type': 'comparison_operator', 'children': ['75', '78'], 'value': '=='}; {'id': '75', 'type': 'subscript', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'removes'}; {'id': '77', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '78', 'type': 'string', 'children': [], 'value': "''"}; {'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': 'removes2'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '87', 'type': 'if_statement', 'children': ['88', '103', '136']}; {'id': '88', 'type': 'boolean_operator', 'children': ['89', '90'], 'value': 'and'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'removes2'}; {'id': '90', 'type': 'comparison_operator', 'children': ['91', '92'], 'value': '=='}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'removes2'}; {'id': '92', 'type': 'subscript', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '94', 'type': 'slice', 'children': ['95', '102']}; {'id': '95', 'type': 'binary_operator', 'children': ['96', '98'], 'value': '*'}; {'id': '96', 'type': 'unary_operator', 'children': ['97'], 'value': '-'}; {'id': '97', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '98', 'type': 'call', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'removes2'}; {'id': '102', 'type': 'colon', 'children': []}; {'id': '103', 'type': 'block', 'children': ['104', '120']}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}; {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '107', 'type': 'subscript', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '109', 'type': 'slice', 'children': ['110', '111']}; {'id': '110', 'type': 'colon', 'children': []}; {'id': '111', 'type': 'binary_operator', 'children': ['112', '116'], 'value': '-'}; {'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': 'segments'}; {'id': '116', 'type': 'call', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'removes2'}; {'id': '120', 'type': 'if_statement', 'children': ['121', '128']}; {'id': '121', 'type': 'boolean_operator', 'children': ['122', '127'], 'value': 'and'}; {'id': '122', 'type': 'comparison_operator', 'children': ['123', '126'], 'value': '!='}; {'id': '123', 'type': 'subscript', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'removes'}; {'id': '125', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '126', 'type': 'string', 'children': [], 'value': "''"}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '128', 'type': 'block', 'children': ['129']}; {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'call', 'children': ['131', '134']}; {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '134', 'type': 'argument_list', 'children': ['135']}; {'id': '135', 'type': 'string', 'children': [], 'value': "''"}; {'id': '136', 'type': 'else_clause', 'children': ['137']}; {'id': '137', 'type': 'block', 'children': ['138']}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}; {'id': '139', 'type': 'assignment', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '142', 'type': 'return_statement', 'children': ['143']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'ret'}
|
def remove_path_segments(segments, removes):
if segments == ['']:
segments.append('')
if removes == ['']:
removes.append('')
if segments == removes:
ret = []
elif len(removes) > len(segments):
ret = segments
else:
removes2 = list(removes)
if len(removes) > 1 and removes[0] == '':
removes2.pop(0)
if removes2 and removes2 == segments[-1 * len(removes2):]:
ret = segments[:len(segments) - len(removes2)]
if removes[0] != '' and ret:
ret.append('')
else:
ret = segments
return ret
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'error'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'template'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'default_params'}; {'id': '8', 'type': 'dictionary', 'children': []}; {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'cause'}; {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'stack_depth'}; {'id': '14', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '15', 'type': 'dictionary_splat_pattern', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'more_params'}; {'id': '17', 'type': 'block', 'children': ['18', '44', '66', '78', '82', '162', '173', '191', '214']}; {'id': '18', 'type': 'if_statement', 'children': ['19', '24']}; {'id': '19', 'type': 'not_operator', 'children': ['20']}; {'id': '20', 'type': 'call', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'is_text'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'template'}; {'id': '24', 'type': 'block', 'children': ['25', '37']}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'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': 'sys'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'stderr'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}; {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'string', 'children': [], 'value': '"Log.error was expecting a unicode template"'}; {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'call', 'children': ['39', '42']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'Log'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}; {'id': '43', 'type': 'string', 'children': [], 'value': '"Log.error was expecting a unicode template"'}; {'id': '44', 'type': 'if_statement', 'children': ['45', '57']}; {'id': '45', 'type': 'boolean_operator', 'children': ['46', '47'], 'value': 'and'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'default_params'}; {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '49', 'type': 'argument_list', 'children': ['50', '56']}; {'id': '50', 'type': 'subscript', 'children': ['51', '55']}; {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'listwrap'}; {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'default_params'}; {'id': '55', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'BaseException'}; {'id': '57', 'type': 'block', 'children': ['58', '62']}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}; {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'cause'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'default_params'}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}; {'id': '63', 'type': 'assignment', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'default_params'}; {'id': '65', 'type': 'dictionary', 'children': []}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}; {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'Data'}; {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'call', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '74', 'type': 'argument_list', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'default_params'}; {'id': '76', 'type': 'dictionary_splat', 'children': ['77']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'more_params'}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}; {'id': '79', 'type': 'assignment', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'add_to_trace'}; {'id': '81', 'type': 'False', 'children': []}; {'id': '82', 'type': 'if_statement', 'children': ['83', '86', '91', '130', '149']}; {'id': '83', 'type': 'comparison_operator', 'children': ['84', '85'], 'value': '=='}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'cause'}; {'id': '85', 'type': 'None', 'children': []}; {'id': '86', 'type': 'block', 'children': ['87']}; {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'causes'}; {'id': '90', 'type': 'None', 'children': []}; {'id': '91', 'type': 'elif_clause', 'children': ['92', '96']}; {'id': '92', 'type': 'call', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'is_list'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'cause'}; {'id': '96', 'type': 'block', 'children': ['97', '101', '123']}; {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'causes'}; {'id': '100', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '101', 'type': 'for_statement', 'children': ['102', '103', '107']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '103', 'type': 'call', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'listwrap'}; {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'cause'}; {'id': '107', 'type': 'block', 'children': ['108']}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}; {'id': '109', 'type': 'call', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'causes'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'call', 'children': ['115', '118']}; {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'Except'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'wrap'}; {'id': '118', 'type': 'argument_list', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '120', 'type': 'keyword_argument', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'stack_depth'}; {'id': '122', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'causes'}; {'id': '126', 'type': 'call', 'children': ['127', '128']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'FlatList'}; {'id': '128', 'type': 'argument_list', 'children': ['129']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'causes'}; {'id': '130', 'type': 'elif_clause', 'children': ['131', '136']}; {'id': '131', 'type': 'call', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '133', 'type': 'argument_list', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'cause'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'BaseException'}; {'id': '136', 'type': 'block', 'children': ['137']}; {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'assignment', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'causes'}; {'id': '140', 'type': 'call', 'children': ['141', '144']}; {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'Except'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'wrap'}; {'id': '144', 'type': 'argument_list', 'children': ['145', '146']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'cause'}; {'id': '146', 'type': 'keyword_argument', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'stack_depth'}; {'id': '148', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '149', 'type': 'else_clause', 'children': ['150']}; {'id': '150', 'type': 'block', 'children': ['151', '155']}; {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'assignment', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'causes'}; {'id': '154', 'type': 'None', 'children': []}; {'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': 'Log'}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '160', 'type': 'argument_list', 'children': ['161']}; {'id': '161', 'type': 'string', 'children': [], 'value': '"can only accept Exception, or list of exceptions"'}; {'id': '162', 'type': 'expression_statement', 'children': ['163']}; {'id': '163', 'type': 'assignment', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'trace'}; {'id': '165', 'type': 'call', 'children': ['166', '169']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'exceptions'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'extract_stack'}; {'id': '169', 'type': 'argument_list', 'children': ['170']}; {'id': '170', 'type': 'binary_operator', 'children': ['171', '172'], 'value': '+'}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'stack_depth'}; {'id': '172', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '173', 'type': 'if_statement', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'add_to_trace'}; {'id': '175', 'type': 'block', 'children': ['176']}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}; {'id': '177', 'type': 'call', 'children': ['178', '185']}; {'id': '178', 'type': 'attribute', 'children': ['179', '184']}; {'id': '179', 'type': 'attribute', 'children': ['180', '183']}; {'id': '180', 'type': 'subscript', 'children': ['181', '182']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'cause'}; {'id': '182', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'trace'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '185', 'type': 'argument_list', 'children': ['186']}; {'id': '186', 'type': 'subscript', 'children': ['187', '188']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'trace'}; {'id': '188', 'type': 'slice', 'children': ['189', '190']}; {'id': '189', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '190', 'type': 'colon', 'children': []}; {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'assignment', 'children': ['193', '194']}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '194', 'type': 'call', 'children': ['195', '196']}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'Except'}; {'id': '196', 'type': 'argument_list', 'children': ['197', '202', '205', '208', '211']}; {'id': '197', 'type': 'keyword_argument', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '199', 'type': 'attribute', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'exceptions'}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'ERROR'}; {'id': '202', 'type': 'keyword_argument', 'children': ['203', '204']}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'template'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'template'}; {'id': '205', 'type': 'keyword_argument', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '208', 'type': 'keyword_argument', 'children': ['209', '210']}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'cause'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'causes'}; {'id': '211', 'type': 'keyword_argument', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'trace'}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'trace'}; {'id': '214', 'type': 'expression_statement', 'children': ['215']}; {'id': '215', 'type': 'call', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'raise_from_none'}; {'id': '217', 'type': 'argument_list', 'children': ['218']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'e'}
|
def error(
cls,
template,
default_params={},
cause=None,
stack_depth=0,
**more_params
):
if not is_text(template):
sys.stderr.write(str("Log.error was expecting a unicode template"))
Log.error("Log.error was expecting a unicode template")
if default_params and isinstance(listwrap(default_params)[0], BaseException):
cause = default_params
default_params = {}
params = Data(dict(default_params, **more_params))
add_to_trace = False
if cause == None:
causes = None
elif is_list(cause):
causes = []
for c in listwrap(cause):
causes.append(Except.wrap(c, stack_depth=1))
causes = FlatList(causes)
elif isinstance(cause, BaseException):
causes = Except.wrap(cause, stack_depth=1)
else:
causes = None
Log.error("can only accept Exception, or list of exceptions")
trace = exceptions.extract_stack(stack_depth + 1)
if add_to_trace:
cause[0].trace.extend(trace[1:])
e = Except(context=exceptions.ERROR, template=template, params=params, cause=causes, trace=trace)
raise_from_none(e)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'summary_reporter'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '13']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'call', 'children': ['8', '11']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'string', 'children': [], 'value': "'Creating MOB-recon summary report'"}; {'id': '13', 'type': 'with_statement', 'children': ['14', '34']}; {'id': '14', 'type': 'with_clause', 'children': ['15']}; {'id': '15', 'type': 'with_item', 'children': ['16']}; {'id': '16', 'type': 'as_pattern', 'children': ['17', '32']}; {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '19', 'type': 'argument_list', 'children': ['20', '31']}; {'id': '20', 'type': 'call', 'children': ['21', '26']}; {'id': '21', 'type': 'attribute', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '26', 'type': 'argument_list', 'children': ['27', '30']}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'reportpath'}; {'id': '30', 'type': 'string', 'children': [], 'value': "'mob_recon_summary.csv'"}; {'id': '31', 'type': 'string', 'children': [], 'value': "'w'"}; {'id': '32', 'type': 'as_pattern_target', 'children': ['33']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'summary'}; {'id': '34', 'type': 'block', 'children': ['35', '41', '188']}; {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '38', 'type': 'concatenated_string', 'children': ['39', '40']}; {'id': '39', 'type': 'string', 'children': [], 'value': "'Strain,Location,Contig,Incompatibility,IncompatibilityAccession,RelaxaseType,'"}; {'id': '40', 'type': 'string', 'children': [], 'value': "'MashNearestNeighbor,MashNeighborDistance\\n'"}; {'id': '41', 'type': 'for_statement', 'children': ['42', '43', '46']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'metadata'}; {'id': '46', 'type': 'block', 'children': ['47', '59']}; {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '56']}; {'id': '49', 'type': 'attribute', 'children': ['50', '55']}; {'id': '50', 'type': 'subscript', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'analysistype'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'pipelineresults'}; {'id': '56', 'type': 'call', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '58', 'type': 'argument_list', 'children': []}; {'id': '59', 'type': 'for_statement', 'children': ['60', '63', '74']}; {'id': '60', 'type': 'pattern_list', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'primarykey'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '63', 'type': 'call', 'children': ['64', '73']}; {'id': '64', 'type': 'attribute', 'children': ['65', '72']}; {'id': '65', 'type': 'attribute', 'children': ['66', '71']}; {'id': '66', 'type': 'subscript', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'analysistype'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'report_dict'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '73', 'type': 'argument_list', 'children': []}; {'id': '74', 'type': 'block', 'children': ['75']}; {'id': '75', 'type': 'if_statement', 'children': ['76', '81']}; {'id': '76', 'type': 'comparison_operator', 'children': ['77', '80'], 'value': '!='}; {'id': '77', 'type': 'subscript', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '79', 'type': 'string', 'children': [], 'value': "'cluster_id'"}; {'id': '80', 'type': 'string', 'children': [], 'value': "'chromosome'"}; {'id': '81', 'type': 'block', 'children': ['82', '142', '146']}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}; {'id': '83', 'type': 'augmented_assignment', 'children': ['84', '85'], 'value': '+='}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '85', 'type': 'call', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}; {'id': '87', 'type': 'string', 'children': [], 'value': "','"}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '89', 'type': 'generator_expression', 'children': ['90', '108']}; {'id': '90', 'type': 'conditional_expression', 'children': ['91', '101', '107'], 'value': 'if'}; {'id': '91', 'type': 'call', 'children': ['92', '98']}; {'id': '92', 'type': 'attribute', 'children': ['93', '97']}; {'id': '93', 'type': 'call', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '98', 'type': 'argument_list', 'children': ['99', '100']}; {'id': '99', 'type': 'string', 'children': [], 'value': "','"}; {'id': '100', 'type': 'string', 'children': [], 'value': "';'"}; {'id': '101', 'type': 'comparison_operator', 'children': ['102', '106'], 'value': '!='}; {'id': '102', 'type': 'call', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '106', 'type': 'string', 'children': [], 'value': "'nan'"}; {'id': '107', 'type': 'string', 'children': [], 'value': "'ND'"}; {'id': '108', 'type': 'for_in_clause', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '110', 'type': 'list', 'children': ['111', '114', '117', '127', '130', '133', '136', '139'], 'value': "[\n sample.name,\n results['cluster_id'],\n results['contig_id'].split('|')[1],\n results['rep_type'],\n results['rep_type_accession'],\n results['relaxase_type'],\n results['mash_nearest_neighbor'],\n results['mash_neighbor_distance']]"}; {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '114', 'type': 'subscript', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '116', 'type': 'string', 'children': [], 'value': "'cluster_id'"}; {'id': '117', 'type': 'subscript', 'children': ['118', '126']}; {'id': '118', 'type': 'call', 'children': ['119', '124']}; {'id': '119', 'type': 'attribute', 'children': ['120', '123']}; {'id': '120', 'type': 'subscript', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '122', 'type': 'string', 'children': [], 'value': "'contig_id'"}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}; {'id': '125', 'type': 'string', 'children': [], 'value': "'|'"}; {'id': '126', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '127', 'type': 'subscript', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '129', 'type': 'string', 'children': [], 'value': "'rep_type'"}; {'id': '130', 'type': 'subscript', 'children': ['131', '132']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '132', 'type': 'string', 'children': [], 'value': "'rep_type_accession'"}; {'id': '133', 'type': 'subscript', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '135', 'type': 'string', 'children': [], 'value': "'relaxase_type'"}; {'id': '136', 'type': 'subscript', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '138', 'type': 'string', 'children': [], 'value': "'mash_nearest_neighbor'"}; {'id': '139', 'type': 'subscript', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '141', 'type': 'string', 'children': [], 'value': "'mash_neighbor_distance'"}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}; {'id': '143', 'type': 'augmented_assignment', 'children': ['144', '145'], 'value': '+='}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '145', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}; {'id': '147', 'type': 'assignment', 'children': ['148', '159']}; {'id': '148', 'type': 'subscript', 'children': ['149', '156']}; {'id': '149', 'type': 'attribute', 'children': ['150', '155']}; {'id': '150', 'type': 'subscript', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'analysistype'}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'pipelineresults'}; {'id': '156', 'type': 'subscript', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '158', 'type': 'string', 'children': [], 'value': "'cluster_id'"}; {'id': '159', 'type': 'call', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}; {'id': '161', 'type': 'string', 'children': [], 'value': "';'"}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '163', 'type': 'generator_expression', 'children': ['164', '182']}; {'id': '164', 'type': 'conditional_expression', 'children': ['165', '175', '181'], 'value': 'if'}; {'id': '165', 'type': 'call', 'children': ['166', '172']}; {'id': '166', 'type': 'attribute', 'children': ['167', '171']}; {'id': '167', 'type': 'call', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '169', 'type': 'argument_list', 'children': ['170']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '172', 'type': 'argument_list', 'children': ['173', '174']}; {'id': '173', 'type': 'string', 'children': [], 'value': "','"}; {'id': '174', 'type': 'string', 'children': [], 'value': "';'"}; {'id': '175', 'type': 'comparison_operator', 'children': ['176', '180'], 'value': '!='}; {'id': '176', 'type': 'call', 'children': ['177', '178']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '178', 'type': 'argument_list', 'children': ['179']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '180', 'type': 'string', 'children': [], 'value': "'nan'"}; {'id': '181', 'type': 'string', 'children': [], 'value': "'ND'"}; {'id': '182', 'type': 'for_in_clause', 'children': ['183', '184']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '184', 'type': 'list', 'children': ['185'], 'value': "[\n results['rep_type']]"}; {'id': '185', 'type': 'subscript', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '187', 'type': 'string', 'children': [], 'value': "'rep_type'"}; {'id': '188', 'type': 'expression_statement', 'children': ['189']}; {'id': '189', 'type': 'call', 'children': ['190', '193']}; {'id': '190', 'type': 'attribute', 'children': ['191', '192']}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'summary'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '193', 'type': 'argument_list', 'children': ['194']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'data'}
|
def summary_reporter(self):
logging.info('Creating MOB-recon summary report')
with open(os.path.join(self.reportpath, 'mob_recon_summary.csv'), 'w') as summary:
data = 'Strain,Location,Contig,Incompatibility,IncompatibilityAccession,RelaxaseType,' \
'MashNearestNeighbor,MashNeighborDistance\n'
for sample in self.metadata:
sample[self.analysistype].pipelineresults = dict()
for primarykey, results in sample[self.analysistype].report_dict.items():
if results['cluster_id'] != 'chromosome':
data += ','.join(str(result).replace(',', ';') if str(result) != 'nan' else 'ND'
for result in [
sample.name,
results['cluster_id'],
results['contig_id'].split('|')[1],
results['rep_type'],
results['rep_type_accession'],
results['relaxase_type'],
results['mash_nearest_neighbor'],
results['mash_neighbor_distance']]
)
data += '\n'
sample[self.analysistype].pipelineresults[results['cluster_id']] = \
';'.join(str(result).replace(',', ';') if str(result) != 'nan' else 'ND'
for result in [
results['rep_type']]
)
summary.write(data)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'amrsummary'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '13']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'call', 'children': ['8', '11']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'string', 'children': [], 'value': "'Creating AMR summary table from ResFinder and MOB-recon outputs'"}; {'id': '13', 'type': 'with_statement', 'children': ['14', '34']}; {'id': '14', 'type': 'with_clause', 'children': ['15']}; {'id': '15', 'type': 'with_item', 'children': ['16']}; {'id': '16', 'type': 'as_pattern', 'children': ['17', '32']}; {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '19', 'type': 'argument_list', 'children': ['20', '31']}; {'id': '20', 'type': 'call', 'children': ['21', '26']}; {'id': '21', 'type': 'attribute', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '26', 'type': 'argument_list', 'children': ['27', '30']}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'reportpath'}; {'id': '30', 'type': 'string', 'children': [], 'value': "'amr_summary.csv'"}; {'id': '31', 'type': 'string', 'children': [], 'value': "'w'"}; {'id': '32', 'type': 'as_pattern_target', 'children': ['33']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'amr'}; {'id': '34', 'type': 'block', 'children': ['35', '39', '306']}; {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '38', 'type': 'string', 'children': [], 'value': "'Strain,Gene,Allele,Resistance,PercentIdentity,Contig,Location,PlasmidIncompatibilitySets\\n'"}; {'id': '39', 'type': 'for_statement', 'children': ['40', '41', '44']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'metadata'}; {'id': '44', 'type': 'block', 'children': ['45', '51', '135']}; {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'inc_dict'}; {'id': '48', 'type': 'call', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '50', 'type': 'argument_list', 'children': []}; {'id': '51', 'type': 'for_statement', 'children': ['52', '55', '66']}; {'id': '52', 'type': 'pattern_list', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'primarykey'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '55', 'type': 'call', 'children': ['56', '65']}; {'id': '56', 'type': 'attribute', 'children': ['57', '64']}; {'id': '57', 'type': 'attribute', 'children': ['58', '63']}; {'id': '58', 'type': 'subscript', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'analysistype'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'report_dict'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '65', 'type': 'argument_list', 'children': []}; {'id': '66', 'type': 'block', 'children': ['67']}; {'id': '67', 'type': 'try_statement', 'children': ['68', '131']}; {'id': '68', 'type': 'block', 'children': ['69', '75', '100']}; {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'inc'}; {'id': '72', 'type': 'subscript', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '74', 'type': 'string', 'children': [], 'value': "'cluster_id'"}; {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'rep'}; {'id': '78', 'type': 'conditional_expression', 'children': ['79', '91', '99'], 'value': 'if'}; {'id': '79', 'type': 'call', 'children': ['80', '88']}; {'id': '80', 'type': 'attribute', 'children': ['81', '87']}; {'id': '81', 'type': 'call', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'subscript', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '86', 'type': 'string', 'children': [], 'value': "'rep_type'"}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '88', 'type': 'argument_list', 'children': ['89', '90']}; {'id': '89', 'type': 'string', 'children': [], 'value': "','"}; {'id': '90', 'type': 'string', 'children': [], 'value': "';'"}; {'id': '91', 'type': 'comparison_operator', 'children': ['92', '98'], 'value': '!='}; {'id': '92', 'type': 'call', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}; {'id': '95', 'type': 'subscript', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '97', 'type': 'string', 'children': [], 'value': "'rep_type'"}; {'id': '98', 'type': 'string', 'children': [], 'value': "'nan'"}; {'id': '99', 'type': 'string', 'children': [], 'value': "'ND'"}; {'id': '100', 'type': 'try_statement', 'children': ['101', '111']}; {'id': '101', 'type': 'block', 'children': ['102']}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}; {'id': '103', 'type': 'call', 'children': ['104', '109']}; {'id': '104', 'type': 'attribute', 'children': ['105', '108']}; {'id': '105', 'type': 'subscript', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'inc_dict'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'inc'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'rep'}; {'id': '111', 'type': 'except_clause', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '113', 'type': 'block', 'children': ['114', '122']}; {'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': 'inc_dict'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'inc'}; {'id': '119', 'type': 'call', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '121', 'type': 'argument_list', 'children': []}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}; {'id': '123', 'type': 'call', 'children': ['124', '129']}; {'id': '124', 'type': 'attribute', 'children': ['125', '128']}; {'id': '125', 'type': 'subscript', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'inc_dict'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'inc'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '129', 'type': 'argument_list', 'children': ['130']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'rep'}; {'id': '131', 'type': 'except_clause', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '133', 'type': 'block', 'children': ['134']}; {'id': '134', 'type': 'pass_statement', 'children': []}; {'id': '135', 'type': 'for_statement', 'children': ['136', '139', '150']}; {'id': '136', 'type': 'pattern_list', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'primarykey'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '139', 'type': 'call', 'children': ['140', '149']}; {'id': '140', 'type': 'attribute', 'children': ['141', '148']}; {'id': '141', 'type': 'attribute', 'children': ['142', '147']}; {'id': '142', 'type': 'subscript', 'children': ['143', '144']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'analysistype'}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'report_dict'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '149', 'type': 'argument_list', 'children': []}; {'id': '150', 'type': 'block', 'children': ['151']}; {'id': '151', 'type': 'try_statement', 'children': ['152', '302']}; {'id': '152', 'type': 'block', 'children': ['153', '166', '192']}; {'id': '153', 'type': 'expression_statement', 'children': ['154']}; {'id': '154', 'type': 'assignment', 'children': ['155', '156']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'contig'}; {'id': '156', 'type': 'subscript', 'children': ['157', '165']}; {'id': '157', 'type': 'call', 'children': ['158', '163']}; {'id': '158', 'type': 'attribute', 'children': ['159', '162']}; {'id': '159', 'type': 'subscript', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '161', 'type': 'string', 'children': [], 'value': "'contig_id'"}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '163', 'type': 'argument_list', 'children': ['164']}; {'id': '164', 'type': 'string', 'children': [], 'value': "'|'"}; {'id': '165', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '166', 'type': 'if_statement', 'children': ['167', '180']}; {'id': '167', 'type': 'call', 'children': ['168', '178']}; {'id': '168', 'type': 'attribute', 'children': ['169', '177']}; {'id': '169', 'type': 'subscript', 'children': ['170', '176']}; {'id': '170', 'type': 'call', 'children': ['171', '174']}; {'id': '171', 'type': 'attribute', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'contig'}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '174', 'type': 'argument_list', 'children': ['175']}; {'id': '175', 'type': 'string', 'children': [], 'value': "'_'"}; {'id': '176', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '178', 'type': 'argument_list', 'children': ['179']}; {'id': '179', 'type': 'string', 'children': [], 'value': "'length'"}; {'id': '180', 'type': 'block', 'children': ['181']}; {'id': '181', 'type': 'expression_statement', 'children': ['182']}; {'id': '182', 'type': 'assignment', 'children': ['183', '184']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'contig'}; {'id': '184', 'type': 'subscript', 'children': ['185', '191']}; {'id': '185', 'type': 'call', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'contig'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '189', 'type': 'argument_list', 'children': ['190']}; {'id': '190', 'type': 'string', 'children': [], 'value': "'_'"}; {'id': '191', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '192', 'type': 'for_statement', 'children': ['193', '194', '199']}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'amr_result'}; {'id': '194', 'type': 'attribute', 'children': ['195', '198']}; {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'resfinder_assembled'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'sampledata'}; {'id': '199', 'type': 'block', 'children': ['200']}; {'id': '200', 'type': 'if_statement', 'children': ['201', '210']}; {'id': '201', 'type': 'comparison_operator', 'children': ['202', '203'], 'value': '=='}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'contig'}; {'id': '203', 'type': 'call', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '205', 'type': 'argument_list', 'children': ['206']}; {'id': '206', 'type': 'subscript', 'children': ['207', '208']}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'amr_result'}; {'id': '208', 'type': 'unary_operator', 'children': ['209'], 'value': '-'}; {'id': '209', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '210', 'type': 'block', 'children': ['211', '224']}; {'id': '211', 'type': 'expression_statement', 'children': ['212']}; {'id': '212', 'type': 'augmented_assignment', 'children': ['213', '214'], 'value': '+='}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '214', 'type': 'call', 'children': ['215', '218']}; {'id': '215', 'type': 'attribute', 'children': ['216', '217']}; {'id': '216', 'type': 'string', 'children': [], 'value': "'{sn},'"}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '218', 'type': 'argument_list', 'children': ['219']}; {'id': '219', 'type': 'keyword_argument', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'sn'}; {'id': '221', 'type': 'attribute', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '224', 'type': 'expression_statement', 'children': ['225']}; {'id': '225', 'type': 'augmented_assignment', 'children': ['226', '227'], 'value': '+='}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '227', 'type': 'call', 'children': ['228', '232']}; {'id': '228', 'type': 'attribute', 'children': ['229', '230', '231']}; {'id': '229', 'type': 'string', 'children': [], 'value': "'{amr},{mob}\\n'"}; {'id': '230', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '232', 'type': 'argument_list', 'children': ['233', '260']}; {'id': '233', 'type': 'keyword_argument', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'amr'}; {'id': '235', 'type': 'call', 'children': ['236', '239']}; {'id': '236', 'type': 'attribute', 'children': ['237', '238']}; {'id': '237', 'type': 'string', 'children': [], 'value': "','"}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '239', 'type': 'generator_expression', 'children': ['240', '252']}; {'id': '240', 'type': 'conditional_expression', 'children': ['241', '245', '251'], 'value': 'if'}; {'id': '241', 'type': 'call', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '243', 'type': 'argument_list', 'children': ['244']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '245', 'type': 'comparison_operator', 'children': ['246', '250'], 'value': '!='}; {'id': '246', 'type': 'call', 'children': ['247', '248']}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '248', 'type': 'argument_list', 'children': ['249']}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '250', 'type': 'string', 'children': [], 'value': "'nan'"}; {'id': '251', 'type': 'string', 'children': [], 'value': "'ND'"}; {'id': '252', 'type': 'for_in_clause', 'children': ['253', '254']}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '254', 'type': 'subscript', 'children': ['255', '256']}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'amr_result'}; {'id': '256', 'type': 'slice', 'children': ['257', '258', '259']}; {'id': '257', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '258', 'type': 'colon', 'children': []}; {'id': '259', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '260', 'type': 'keyword_argument', 'children': ['261', '262']}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'mob'}; {'id': '262', 'type': 'call', 'children': ['263', '266']}; {'id': '263', 'type': 'attribute', 'children': ['264', '265']}; {'id': '264', 'type': 'string', 'children': [], 'value': "','"}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '266', 'type': 'generator_expression', 'children': ['267', '279']}; {'id': '267', 'type': 'conditional_expression', 'children': ['268', '272', '278'], 'value': 'if'}; {'id': '268', 'type': 'call', 'children': ['269', '270']}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '270', 'type': 'argument_list', 'children': ['271']}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '272', 'type': 'comparison_operator', 'children': ['273', '277'], 'value': '!='}; {'id': '273', 'type': 'call', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '275', 'type': 'argument_list', 'children': ['276']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '277', 'type': 'string', 'children': [], 'value': "'nan'"}; {'id': '278', 'type': 'string', 'children': [], 'value': "'ND'"}; {'id': '279', 'type': 'for_in_clause', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '281', 'type': 'list', 'children': ['282', '283', '286'], 'value': "[contig, results['cluster_id'],\n ';'.join(sorted(inc_dict[str(results['cluster_id'])]))\n ]"}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'contig'}; {'id': '283', 'type': 'subscript', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '285', 'type': 'string', 'children': [], 'value': "'cluster_id'"}; {'id': '286', 'type': 'call', 'children': ['287', '290']}; {'id': '287', 'type': 'attribute', 'children': ['288', '289']}; {'id': '288', 'type': 'string', 'children': [], 'value': "';'"}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '290', 'type': 'argument_list', 'children': ['291']}; {'id': '291', 'type': 'call', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '293', 'type': 'argument_list', 'children': ['294']}; {'id': '294', 'type': 'subscript', 'children': ['295', '296']}; {'id': '295', 'type': 'identifier', 'children': [], 'value': 'inc_dict'}; {'id': '296', 'type': 'call', 'children': ['297', '298']}; {'id': '297', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '298', 'type': 'argument_list', 'children': ['299']}; {'id': '299', 'type': 'subscript', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '301', 'type': 'string', 'children': [], 'value': "'cluster_id'"}; {'id': '302', 'type': 'except_clause', 'children': ['303', '304']}; {'id': '303', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '304', 'type': 'block', 'children': ['305']}; {'id': '305', 'type': 'pass_statement', 'children': []}; {'id': '306', 'type': 'expression_statement', 'children': ['307']}; {'id': '307', 'type': 'call', 'children': ['308', '311']}; {'id': '308', 'type': 'attribute', 'children': ['309', '310']}; {'id': '309', 'type': 'identifier', 'children': [], 'value': 'amr'}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '311', 'type': 'argument_list', 'children': ['312']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'data'}
|
def amrsummary(self):
logging.info('Creating AMR summary table from ResFinder and MOB-recon outputs')
with open(os.path.join(self.reportpath, 'amr_summary.csv'), 'w') as amr:
data = 'Strain,Gene,Allele,Resistance,PercentIdentity,Contig,Location,PlasmidIncompatibilitySets\n'
for sample in self.metadata:
inc_dict = dict()
for primarykey, results in sample[self.analysistype].report_dict.items():
try:
inc = results['cluster_id']
rep = str(results['rep_type']).replace(',', ';') if str(results['rep_type']) != 'nan' else 'ND'
try:
inc_dict[inc].add(rep)
except KeyError:
inc_dict[inc] = set()
inc_dict[inc].add(rep)
except KeyError:
pass
for primarykey, results in sample[self.analysistype].report_dict.items():
try:
contig = results['contig_id'].split('|')[1]
if contig.split('_')[1].startswith('length'):
contig = contig.split('_')[0]
for amr_result in sample.resfinder_assembled.sampledata:
if contig == str(amr_result[-1]):
data += '{sn},'.format(sn=sample.name)
data += '{amr},{mob}\n'\
.format(amr=','.join(str(res) if str(res) != 'nan' else 'ND' for res in
amr_result[0:4]),
mob=','.join(str(res) if str(res) != 'nan' else 'ND' for res in
[contig, results['cluster_id'],
';'.join(sorted(inc_dict[str(results['cluster_id'])]))
]
)
)
except KeyError:
pass
amr.write(data)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'geneseekrsummary'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '13']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'call', 'children': ['8', '11']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'string', 'children': [], 'value': "'Creating predicted plasmid-borne gene summary table'"}; {'id': '13', 'type': 'with_statement', 'children': ['14', '34']}; {'id': '14', 'type': 'with_clause', 'children': ['15']}; {'id': '15', 'type': 'with_item', 'children': ['16']}; {'id': '16', 'type': 'as_pattern', 'children': ['17', '32']}; {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '19', 'type': 'argument_list', 'children': ['20', '31']}; {'id': '20', 'type': 'call', 'children': ['21', '26']}; {'id': '21', 'type': 'attribute', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '26', 'type': 'argument_list', 'children': ['27', '30']}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'reportpath'}; {'id': '30', 'type': 'string', 'children': [], 'value': "'plasmid_borne_summary.csv'"}; {'id': '31', 'type': 'string', 'children': [], 'value': "'w'"}; {'id': '32', 'type': 'as_pattern_target', 'children': ['33']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'pbs'}; {'id': '34', 'type': 'block', 'children': ['35', '39', '314']}; {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '38', 'type': 'string', 'children': [], 'value': "'Strain,Gene,PercentIdentity,Contig,Location,PlasmidIncompatibilitySets\\n'"}; {'id': '39', 'type': 'for_statement', 'children': ['40', '41', '44']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'metadata'}; {'id': '44', 'type': 'block', 'children': ['45', '49', '55', '139', '297']}; {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'result_bool'}; {'id': '48', 'type': 'False', 'children': []}; {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'inc_dict'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '54', 'type': 'argument_list', 'children': []}; {'id': '55', 'type': 'for_statement', 'children': ['56', '59', '70']}; {'id': '56', 'type': 'pattern_list', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'primarykey'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '59', 'type': 'call', 'children': ['60', '69']}; {'id': '60', 'type': 'attribute', 'children': ['61', '68']}; {'id': '61', 'type': 'attribute', 'children': ['62', '67']}; {'id': '62', 'type': 'subscript', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'analysistype'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'report_dict'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '69', 'type': 'argument_list', 'children': []}; {'id': '70', 'type': 'block', 'children': ['71']}; {'id': '71', 'type': 'try_statement', 'children': ['72', '135']}; {'id': '72', 'type': 'block', 'children': ['73', '79', '104']}; {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'inc'}; {'id': '76', 'type': 'subscript', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '78', 'type': 'string', 'children': [], 'value': "'cluster_id'"}; {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'rep'}; {'id': '82', 'type': 'conditional_expression', 'children': ['83', '95', '103'], 'value': 'if'}; {'id': '83', 'type': 'call', 'children': ['84', '92']}; {'id': '84', 'type': 'attribute', 'children': ['85', '91']}; {'id': '85', 'type': 'call', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'subscript', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '90', 'type': 'string', 'children': [], 'value': "'rep_type'"}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '92', 'type': 'argument_list', 'children': ['93', '94']}; {'id': '93', 'type': 'string', 'children': [], 'value': "','"}; {'id': '94', 'type': 'string', 'children': [], 'value': "';'"}; {'id': '95', 'type': 'comparison_operator', 'children': ['96', '102'], 'value': '!='}; {'id': '96', 'type': 'call', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}; {'id': '99', 'type': 'subscript', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '101', 'type': 'string', 'children': [], 'value': "'rep_type'"}; {'id': '102', 'type': 'string', 'children': [], 'value': "'nan'"}; {'id': '103', 'type': 'string', 'children': [], 'value': "'ND'"}; {'id': '104', 'type': 'try_statement', 'children': ['105', '115']}; {'id': '105', 'type': 'block', 'children': ['106']}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}; {'id': '107', 'type': 'call', 'children': ['108', '113']}; {'id': '108', 'type': 'attribute', 'children': ['109', '112']}; {'id': '109', 'type': 'subscript', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'inc_dict'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'inc'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'rep'}; {'id': '115', 'type': 'except_clause', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '117', 'type': 'block', 'children': ['118', '126']}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}; {'id': '119', 'type': 'assignment', 'children': ['120', '123']}; {'id': '120', 'type': 'subscript', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'inc_dict'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'inc'}; {'id': '123', 'type': 'call', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '125', 'type': 'argument_list', 'children': []}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}; {'id': '127', 'type': 'call', 'children': ['128', '133']}; {'id': '128', 'type': 'attribute', 'children': ['129', '132']}; {'id': '129', 'type': 'subscript', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'inc_dict'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'inc'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '133', 'type': 'argument_list', 'children': ['134']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'rep'}; {'id': '135', 'type': 'except_clause', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '137', 'type': 'block', 'children': ['138']}; {'id': '138', 'type': 'pass_statement', 'children': []}; {'id': '139', 'type': 'for_statement', 'children': ['140', '143', '154']}; {'id': '140', 'type': 'pattern_list', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'primarykey'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '143', 'type': 'call', 'children': ['144', '153']}; {'id': '144', 'type': 'attribute', 'children': ['145', '152']}; {'id': '145', 'type': 'attribute', 'children': ['146', '151']}; {'id': '146', 'type': 'subscript', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'analysistype'}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'report_dict'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '153', 'type': 'argument_list', 'children': []}; {'id': '154', 'type': 'block', 'children': ['155']}; {'id': '155', 'type': 'try_statement', 'children': ['156', '293']}; {'id': '156', 'type': 'block', 'children': ['157', '170', '196']}; {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'assignment', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'contig'}; {'id': '160', 'type': 'subscript', 'children': ['161', '169']}; {'id': '161', 'type': 'call', 'children': ['162', '167']}; {'id': '162', 'type': 'attribute', 'children': ['163', '166']}; {'id': '163', 'type': 'subscript', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '165', 'type': 'string', 'children': [], 'value': "'contig_id'"}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '167', 'type': 'argument_list', 'children': ['168']}; {'id': '168', 'type': 'string', 'children': [], 'value': "'|'"}; {'id': '169', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '170', 'type': 'if_statement', 'children': ['171', '184']}; {'id': '171', 'type': 'call', 'children': ['172', '182']}; {'id': '172', 'type': 'attribute', 'children': ['173', '181']}; {'id': '173', 'type': 'subscript', 'children': ['174', '180']}; {'id': '174', 'type': 'call', 'children': ['175', '178']}; {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'contig'}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '178', 'type': 'argument_list', 'children': ['179']}; {'id': '179', 'type': 'string', 'children': [], 'value': "'_'"}; {'id': '180', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '182', 'type': 'argument_list', 'children': ['183']}; {'id': '183', 'type': 'string', 'children': [], 'value': "'length'"}; {'id': '184', 'type': 'block', 'children': ['185']}; {'id': '185', 'type': 'expression_statement', 'children': ['186']}; {'id': '186', 'type': 'assignment', 'children': ['187', '188']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'contig'}; {'id': '188', 'type': 'subscript', 'children': ['189', '195']}; {'id': '189', 'type': 'call', 'children': ['190', '193']}; {'id': '190', 'type': 'attribute', 'children': ['191', '192']}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'contig'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '193', 'type': 'argument_list', 'children': ['194']}; {'id': '194', 'type': 'string', 'children': [], 'value': "'_'"}; {'id': '195', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '196', 'type': 'for_statement', 'children': ['197', '200', '209']}; {'id': '197', 'type': 'pattern_list', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'gene'}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'result_dict'}; {'id': '200', 'type': 'call', 'children': ['201', '208']}; {'id': '201', 'type': 'attribute', 'children': ['202', '207']}; {'id': '202', 'type': 'attribute', 'children': ['203', '206']}; {'id': '203', 'type': 'attribute', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'geneseekr_results'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'sampledata'}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '208', 'type': 'argument_list', 'children': []}; {'id': '209', 'type': 'block', 'children': ['210']}; {'id': '210', 'type': 'if_statement', 'children': ['211', '216']}; {'id': '211', 'type': 'comparison_operator', 'children': ['212', '213'], 'value': '=='}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'contig'}; {'id': '213', 'type': 'subscript', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'result_dict'}; {'id': '215', 'type': 'string', 'children': [], 'value': "'query_id'"}; {'id': '216', 'type': 'block', 'children': ['217', '223']}; {'id': '217', 'type': 'expression_statement', 'children': ['218']}; {'id': '218', 'type': 'assignment', 'children': ['219', '220']}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'percent_identity'}; {'id': '220', 'type': 'subscript', 'children': ['221', '222']}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'result_dict'}; {'id': '222', 'type': 'string', 'children': [], 'value': "'PercentIdentity'"}; {'id': '223', 'type': 'if_statement', 'children': ['224', '234']}; {'id': '224', 'type': 'comparison_operator', 'children': ['225', '231'], 'value': '>='}; {'id': '225', 'type': 'call', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '227', 'type': 'argument_list', 'children': ['228']}; {'id': '228', 'type': 'subscript', 'children': ['229', '230']}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'result_dict'}; {'id': '230', 'type': 'string', 'children': [], 'value': "'PercentIdentity'"}; {'id': '231', 'type': 'attribute', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'cutoff'}; {'id': '234', 'type': 'block', 'children': ['235', '239', '252']}; {'id': '235', 'type': 'expression_statement', 'children': ['236']}; {'id': '236', 'type': 'assignment', 'children': ['237', '238']}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'result_bool'}; {'id': '238', 'type': 'True', 'children': []}; {'id': '239', 'type': 'expression_statement', 'children': ['240']}; {'id': '240', 'type': 'augmented_assignment', 'children': ['241', '242'], 'value': '+='}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '242', 'type': 'call', 'children': ['243', '246']}; {'id': '243', 'type': 'attribute', 'children': ['244', '245']}; {'id': '244', 'type': 'string', 'children': [], 'value': "'{sn},'"}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '246', 'type': 'argument_list', 'children': ['247']}; {'id': '247', 'type': 'keyword_argument', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'sn'}; {'id': '249', 'type': 'attribute', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '252', 'type': 'expression_statement', 'children': ['253']}; {'id': '253', 'type': 'augmented_assignment', 'children': ['254', '255'], 'value': '+='}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '255', 'type': 'call', 'children': ['256', '260']}; {'id': '256', 'type': 'attribute', 'children': ['257', '258', '259']}; {'id': '257', 'type': 'string', 'children': [], 'value': "'{gene},{pi},{contig},{cid},{inc}\\n'"}; {'id': '258', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '260', 'type': 'argument_list', 'children': ['261', '264', '267', '270', '275']}; {'id': '261', 'type': 'keyword_argument', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'gene'}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'gene'}; {'id': '264', 'type': 'keyword_argument', 'children': ['265', '266']}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'pi'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'percent_identity'}; {'id': '267', 'type': 'keyword_argument', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'contig'}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'contig'}; {'id': '270', 'type': 'keyword_argument', 'children': ['271', '272']}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'cid'}; {'id': '272', 'type': 'subscript', 'children': ['273', '274']}; {'id': '273', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '274', 'type': 'string', 'children': [], 'value': "'cluster_id'"}; {'id': '275', 'type': 'keyword_argument', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'inc'}; {'id': '277', 'type': 'call', 'children': ['278', '281']}; {'id': '278', 'type': 'attribute', 'children': ['279', '280']}; {'id': '279', 'type': 'string', 'children': [], 'value': "';'"}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '281', 'type': 'argument_list', 'children': ['282']}; {'id': '282', 'type': 'call', 'children': ['283', '284']}; {'id': '283', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '284', 'type': 'argument_list', 'children': ['285']}; {'id': '285', 'type': 'subscript', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'inc_dict'}; {'id': '287', 'type': 'call', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '289', 'type': 'argument_list', 'children': ['290']}; {'id': '290', 'type': 'subscript', 'children': ['291', '292']}; {'id': '291', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '292', 'type': 'string', 'children': [], 'value': "'cluster_id'"}; {'id': '293', 'type': 'except_clause', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '295', 'type': 'block', 'children': ['296']}; {'id': '296', 'type': 'pass_statement', 'children': []}; {'id': '297', 'type': 'if_statement', 'children': ['298', '300']}; {'id': '298', 'type': 'not_operator', 'children': ['299']}; {'id': '299', 'type': 'identifier', 'children': [], 'value': 'result_bool'}; {'id': '300', 'type': 'block', 'children': ['301']}; {'id': '301', 'type': 'expression_statement', 'children': ['302']}; {'id': '302', 'type': 'augmented_assignment', 'children': ['303', '304'], 'value': '+='}; {'id': '303', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '304', 'type': 'call', 'children': ['305', '308']}; {'id': '305', 'type': 'attribute', 'children': ['306', '307']}; {'id': '306', 'type': 'string', 'children': [], 'value': "'{sn}\\n'"}; {'id': '307', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '308', 'type': 'argument_list', 'children': ['309']}; {'id': '309', 'type': 'keyword_argument', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'sn'}; {'id': '311', 'type': 'attribute', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '313', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '314', 'type': 'expression_statement', 'children': ['315']}; {'id': '315', 'type': 'call', 'children': ['316', '319']}; {'id': '316', 'type': 'attribute', 'children': ['317', '318']}; {'id': '317', 'type': 'identifier', 'children': [], 'value': 'pbs'}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '319', 'type': 'argument_list', 'children': ['320']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'data'}
|
def geneseekrsummary(self):
logging.info('Creating predicted plasmid-borne gene summary table')
with open(os.path.join(self.reportpath, 'plasmid_borne_summary.csv'), 'w') as pbs:
data = 'Strain,Gene,PercentIdentity,Contig,Location,PlasmidIncompatibilitySets\n'
for sample in self.metadata:
result_bool = False
inc_dict = dict()
for primarykey, results in sample[self.analysistype].report_dict.items():
try:
inc = results['cluster_id']
rep = str(results['rep_type']).replace(',', ';') if str(results['rep_type']) != 'nan' else 'ND'
try:
inc_dict[inc].add(rep)
except KeyError:
inc_dict[inc] = set()
inc_dict[inc].add(rep)
except KeyError:
pass
for primarykey, results in sample[self.analysistype].report_dict.items():
try:
contig = results['contig_id'].split('|')[1]
if contig.split('_')[1].startswith('length'):
contig = contig.split('_')[0]
for gene, result_dict in sample.geneseekr_results.sampledata.items():
if contig == result_dict['query_id']:
percent_identity = result_dict['PercentIdentity']
if float(result_dict['PercentIdentity']) >= self.cutoff:
result_bool = True
data += '{sn},'.format(sn=sample.name)
data += '{gene},{pi},{contig},{cid},{inc}\n'\
.format(gene=gene,
pi=percent_identity,
contig=contig,
cid=results['cluster_id'],
inc=';'.join(sorted(inc_dict[str(results['cluster_id'])])))
except KeyError:
pass
if not result_bool:
data += '{sn}\n'.format(sn=sample.name)
pbs.write(data)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'filterunique'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'for_statement', 'children': ['7', '8', '11']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'metadata'}; {'id': '11', 'type': 'block', 'children': ['12', '24', '30', '36', '278']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'assignment', 'children': ['14', '21']}; {'id': '14', 'type': 'attribute', 'children': ['15', '20']}; {'id': '15', 'type': 'subscript', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'analysistype'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'blastresults'}; {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '23', 'type': 'argument_list', 'children': []}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}; {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'resultdict'}; {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '29', 'type': 'argument_list', 'children': []}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'rowdict'}; {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '35', 'type': 'argument_list', 'children': []}; {'id': '36', 'type': 'try_statement', 'children': ['37', '274']}; {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'for_statement', 'children': ['39', '40', '47']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'contig'}; {'id': '40', 'type': 'attribute', 'children': ['41', '46']}; {'id': '41', 'type': 'subscript', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'analysistype'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'queryranges'}; {'id': '47', 'type': 'block', 'children': ['48']}; {'id': '48', 'type': 'for_statement', 'children': ['49', '50', '59']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'location'}; {'id': '50', 'type': 'subscript', 'children': ['51', '58']}; {'id': '51', 'type': 'attribute', 'children': ['52', '57']}; {'id': '52', 'type': 'subscript', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'analysistype'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'queryranges'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'contig'}; {'id': '59', 'type': 'block', 'children': ['60']}; {'id': '60', 'type': 'for_statement', 'children': ['61', '62', '71']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '62', 'type': 'subscript', 'children': ['63', '70']}; {'id': '63', 'type': 'attribute', 'children': ['64', '69']}; {'id': '64', 'type': 'subscript', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'analysistype'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'contig'}; {'id': '71', 'type': 'block', 'children': ['72', '78', '84', '90', '96', '112', '123']}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}; {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'contig'}; {'id': '75', 'type': 'subscript', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '77', 'type': 'string', 'children': [], 'value': "'query_id'"}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}; {'id': '79', 'type': 'assignment', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'high'}; {'id': '81', 'type': 'subscript', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '83', 'type': 'string', 'children': [], 'value': "'high'"}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}; {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'low'}; {'id': '87', 'type': 'subscript', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '89', 'type': 'string', 'children': [], 'value': "'low'"}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}; {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'percentidentity'}; {'id': '93', 'type': 'subscript', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '95', 'type': 'string', 'children': [], 'value': "'percentidentity'"}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}; {'id': '97', 'type': 'assignment', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'locstr'}; {'id': '99', 'type': 'call', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}; {'id': '101', 'type': 'string', 'children': [], 'value': "','"}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '103', 'type': 'argument_list', 'children': ['104']}; {'id': '104', 'type': 'list_comprehension', 'children': ['105', '109']}; {'id': '105', 'type': 'call', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '109', 'type': 'for_in_clause', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'location'}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}; {'id': '113', 'type': 'assignment', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'loc'}; {'id': '115', 'type': 'call', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'call', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '120', 'type': 'argument_list', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'low'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'high'}; {'id': '123', 'type': 'if_statement', 'children': ['124', '141']}; {'id': '124', 'type': 'call', 'children': ['125', '128']}; {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'loc'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'intersection'}; {'id': '128', 'type': 'argument_list', 'children': ['129']}; {'id': '129', 'type': 'call', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '131', 'type': 'argument_list', 'children': ['132']}; {'id': '132', 'type': 'call', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '134', 'type': 'argument_list', 'children': ['135', '138']}; {'id': '135', 'type': 'subscript', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'location'}; {'id': '137', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '138', 'type': 'subscript', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'location'}; {'id': '140', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '141', 'type': 'block', 'children': ['142']}; {'id': '142', 'type': 'try_statement', 'children': ['143', '166']}; {'id': '143', 'type': 'block', 'children': ['144', '155']}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}; {'id': '145', 'type': 'call', 'children': ['146', '153']}; {'id': '146', 'type': 'attribute', 'children': ['147', '152']}; {'id': '147', 'type': 'subscript', 'children': ['148', '151']}; {'id': '148', 'type': 'subscript', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'resultdict'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'contig'}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'locstr'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '153', 'type': 'argument_list', 'children': ['154']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'percentidentity'}; {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'call', 'children': ['157', '164']}; {'id': '157', 'type': 'attribute', 'children': ['158', '163']}; {'id': '158', 'type': 'subscript', 'children': ['159', '162']}; {'id': '159', 'type': 'subscript', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'rowdict'}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'contig'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'locstr'}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '166', 'type': 'except_clause', 'children': ['167', '168']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '168', 'type': 'block', 'children': ['169']}; {'id': '169', 'type': 'try_statement', 'children': ['170', '213']}; {'id': '170', 'type': 'block', 'children': ['171', '181', '192', '202']}; {'id': '171', 'type': 'expression_statement', 'children': ['172']}; {'id': '172', 'type': 'assignment', 'children': ['173', '178']}; {'id': '173', 'type': 'subscript', 'children': ['174', '177']}; {'id': '174', 'type': 'subscript', 'children': ['175', '176']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'resultdict'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'contig'}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'locstr'}; {'id': '178', 'type': 'call', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '180', 'type': 'argument_list', 'children': []}; {'id': '181', 'type': 'expression_statement', 'children': ['182']}; {'id': '182', 'type': 'call', 'children': ['183', '190']}; {'id': '183', 'type': 'attribute', 'children': ['184', '189']}; {'id': '184', 'type': 'subscript', 'children': ['185', '188']}; {'id': '185', 'type': 'subscript', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'resultdict'}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'contig'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'locstr'}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '190', 'type': 'argument_list', 'children': ['191']}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'percentidentity'}; {'id': '192', 'type': 'expression_statement', 'children': ['193']}; {'id': '193', 'type': 'assignment', 'children': ['194', '199']}; {'id': '194', 'type': 'subscript', 'children': ['195', '198']}; {'id': '195', 'type': 'subscript', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'rowdict'}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'contig'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'locstr'}; {'id': '199', 'type': 'call', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '201', 'type': 'argument_list', 'children': []}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}; {'id': '203', 'type': 'call', 'children': ['204', '211']}; {'id': '204', 'type': 'attribute', 'children': ['205', '210']}; {'id': '205', 'type': 'subscript', 'children': ['206', '209']}; {'id': '206', 'type': 'subscript', 'children': ['207', '208']}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'rowdict'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'contig'}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'locstr'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '211', 'type': 'argument_list', 'children': ['212']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '213', 'type': 'except_clause', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '215', 'type': 'block', 'children': ['216', '224', '234', '245', '253', '263']}; {'id': '216', 'type': 'expression_statement', 'children': ['217']}; {'id': '217', 'type': 'assignment', 'children': ['218', '221']}; {'id': '218', 'type': 'subscript', 'children': ['219', '220']}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'resultdict'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'contig'}; {'id': '221', 'type': 'call', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '223', 'type': 'argument_list', 'children': []}; {'id': '224', 'type': 'expression_statement', 'children': ['225']}; {'id': '225', 'type': 'assignment', 'children': ['226', '231']}; {'id': '226', 'type': 'subscript', 'children': ['227', '230']}; {'id': '227', 'type': 'subscript', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'resultdict'}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'contig'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'locstr'}; {'id': '231', 'type': 'call', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '233', 'type': 'argument_list', 'children': []}; {'id': '234', 'type': 'expression_statement', 'children': ['235']}; {'id': '235', 'type': 'call', 'children': ['236', '243']}; {'id': '236', 'type': 'attribute', 'children': ['237', '242']}; {'id': '237', 'type': 'subscript', 'children': ['238', '241']}; {'id': '238', 'type': 'subscript', 'children': ['239', '240']}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'resultdict'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'contig'}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'locstr'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '243', 'type': 'argument_list', 'children': ['244']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'percentidentity'}; {'id': '245', 'type': 'expression_statement', 'children': ['246']}; {'id': '246', 'type': 'assignment', 'children': ['247', '250']}; {'id': '247', 'type': 'subscript', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'rowdict'}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'contig'}; {'id': '250', 'type': 'call', 'children': ['251', '252']}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '252', 'type': 'argument_list', 'children': []}; {'id': '253', 'type': 'expression_statement', 'children': ['254']}; {'id': '254', 'type': 'assignment', 'children': ['255', '260']}; {'id': '255', 'type': 'subscript', 'children': ['256', '259']}; {'id': '256', 'type': 'subscript', 'children': ['257', '258']}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'rowdict'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'contig'}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'locstr'}; {'id': '260', 'type': 'call', 'children': ['261', '262']}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '262', 'type': 'argument_list', 'children': []}; {'id': '263', 'type': 'expression_statement', 'children': ['264']}; {'id': '264', 'type': 'call', 'children': ['265', '272']}; {'id': '265', 'type': 'attribute', 'children': ['266', '271']}; {'id': '266', 'type': 'subscript', 'children': ['267', '270']}; {'id': '267', 'type': 'subscript', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'rowdict'}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'contig'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'locstr'}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '272', 'type': 'argument_list', 'children': ['273']}; {'id': '273', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '274', 'type': 'except_clause', 'children': ['275', '276']}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '276', 'type': 'block', 'children': ['277']}; {'id': '277', 'type': 'pass_statement', 'children': []}; {'id': '278', 'type': 'for_statement', 'children': ['279', '280', '281']}; {'id': '279', 'type': 'identifier', 'children': [], 'value': 'contig'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'resultdict'}; {'id': '281', 'type': 'block', 'children': ['282', '288']}; {'id': '282', 'type': 'expression_statement', 'children': ['283']}; {'id': '283', 'type': 'assignment', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'genes'}; {'id': '285', 'type': 'call', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '287', 'type': 'argument_list', 'children': []}; {'id': '288', 'type': 'for_statement', 'children': ['289', '290', '293']}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'location'}; {'id': '290', 'type': 'subscript', 'children': ['291', '292']}; {'id': '291', 'type': 'identifier', 'children': [], 'value': 'resultdict'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'contig'}; {'id': '293', 'type': 'block', 'children': ['294', '298']}; {'id': '294', 'type': 'expression_statement', 'children': ['295']}; {'id': '295', 'type': 'assignment', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'multiple'}; {'id': '297', 'type': 'False', 'children': []}; {'id': '298', 'type': 'for_statement', 'children': ['299', '300', '305']}; {'id': '299', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '300', 'type': 'subscript', 'children': ['301', '304']}; {'id': '301', 'type': 'subscript', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'rowdict'}; {'id': '303', 'type': 'identifier', 'children': [], 'value': 'contig'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'location'}; {'id': '305', 'type': 'block', 'children': ['306']}; {'id': '306', 'type': 'if_statement', 'children': ['307', '329']}; {'id': '307', 'type': 'boolean_operator', 'children': ['308', '323', '324'], 'value': 'and'}; {'id': '308', 'type': 'boolean_operator', 'children': ['309', '321'], 'value': 'and'}; {'id': '309', 'type': 'comparison_operator', 'children': ['310', '313'], 'value': '=='}; {'id': '310', 'type': 'subscript', 'children': ['311', '312']}; {'id': '311', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '312', 'type': 'string', 'children': [], 'value': "'percentidentity'"}; {'id': '313', 'type': 'call', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '315', 'type': 'argument_list', 'children': ['316']}; {'id': '316', 'type': 'subscript', 'children': ['317', '320']}; {'id': '317', 'type': 'subscript', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'resultdict'}; {'id': '319', 'type': 'identifier', 'children': [], 'value': 'contig'}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'location'}; {'id': '321', 'type': 'not_operator', 'children': ['322']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'multiple'}; {'id': '323', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '324', 'type': 'comparison_operator', 'children': ['325', '328'], 'value': 'not'}; {'id': '325', 'type': 'subscript', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '327', 'type': 'string', 'children': [], 'value': "'subject_id'"}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'genes'}; {'id': '329', 'type': 'block', 'children': ['330', '343', '352']}; {'id': '330', 'type': 'expression_statement', 'children': ['331']}; {'id': '331', 'type': 'call', 'children': ['332', '341']}; {'id': '332', 'type': 'attribute', 'children': ['333', '340']}; {'id': '333', 'type': 'attribute', 'children': ['334', '339']}; {'id': '334', 'type': 'subscript', 'children': ['335', '336']}; {'id': '335', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '336', 'type': 'attribute', 'children': ['337', '338']}; {'id': '337', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'analysistype'}; {'id': '339', 'type': 'identifier', 'children': [], 'value': 'blastresults'}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '341', 'type': 'argument_list', 'children': ['342']}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '343', 'type': 'expression_statement', 'children': ['344']}; {'id': '344', 'type': 'call', 'children': ['345', '348']}; {'id': '345', 'type': 'attribute', 'children': ['346', '347']}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'genes'}; {'id': '347', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '348', 'type': 'argument_list', 'children': ['349']}; {'id': '349', 'type': 'subscript', 'children': ['350', '351']}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '351', 'type': 'string', 'children': [], 'value': "'subject_id'"}; {'id': '352', 'type': 'expression_statement', 'children': ['353']}; {'id': '353', 'type': 'assignment', 'children': ['354', '355']}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'multiple'}; {'id': '355', 'type': 'True', 'children': []}
|
def filterunique(self):
for sample in self.metadata:
sample[self.analysistype].blastresults = list()
resultdict = dict()
rowdict = dict()
try:
for contig in sample[self.analysistype].queryranges:
for location in sample[self.analysistype].queryranges[contig]:
for row in sample[self.analysistype].results[contig]:
contig = row['query_id']
high = row['high']
low = row['low']
percentidentity = row['percentidentity']
locstr = ','.join([str(x) for x in location])
loc = set(range(low, high))
if loc.intersection(set(range(location[0], location[1]))):
try:
resultdict[contig][locstr].append(percentidentity)
rowdict[contig][locstr].append(row)
except KeyError:
try:
resultdict[contig][locstr] = list()
resultdict[contig][locstr].append(percentidentity)
rowdict[contig][locstr] = list()
rowdict[contig][locstr].append(row)
except KeyError:
resultdict[contig] = dict()
resultdict[contig][locstr] = list()
resultdict[contig][locstr].append(percentidentity)
rowdict[contig] = dict()
rowdict[contig][locstr] = list()
rowdict[contig][locstr].append(row)
except KeyError:
pass
for contig in resultdict:
genes = list()
for location in resultdict[contig]:
multiple = False
for row in rowdict[contig][location]:
if row['percentidentity'] == max(resultdict[contig][location]) and not multiple \
and row['subject_id'] not in genes:
sample[self.analysistype].blastresults.append(row)
genes.append(row['subject_id'])
multiple = True
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'makedbthreads'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '38', '77', '164']}; {'id': '6', 'type': 'for_statement', 'children': ['7', '8', '11']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'metadata'}; {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'if_statement', 'children': ['13', '22']}; {'id': '13', 'type': 'comparison_operator', 'children': ['14', '21'], 'value': '!='}; {'id': '14', 'type': 'attribute', 'children': ['15', '20']}; {'id': '15', 'type': 'subscript', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'analysistype'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'combinedtargets'}; {'id': '21', 'type': 'string', 'children': [], 'value': "'NA'"}; {'id': '22', 'type': 'block', 'children': ['23']}; {'id': '23', 'type': 'expression_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': 'targetfolders'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}; {'id': '31', 'type': 'attribute', 'children': ['32', '37']}; {'id': '32', 'type': 'subscript', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'analysistype'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'targetpath'}; {'id': '38', 'type': 'for_statement', 'children': ['39', '40', '49']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '40', 'type': 'call', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}; {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'targetfolders'}; {'id': '49', 'type': 'block', 'children': ['50', '64', '71']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}; {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'threads'}; {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'Thread'}; {'id': '55', 'type': 'argument_list', 'children': ['56', '61']}; {'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'makeblastdb'}; {'id': '61', 'type': 'keyword_argument', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '63', 'type': 'tuple', 'children': []}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}; {'id': '65', 'type': 'call', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'threads'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'setDaemon'}; {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'True', 'children': []}; {'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': 'threads'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '76', 'type': 'argument_list', 'children': []}; {'id': '77', 'type': 'for_statement', 'children': ['78', '79', '82']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'targetdir'}; {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'targetfolders'}; {'id': '82', 'type': 'block', 'children': ['83', '100', '130']}; {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '88']}; {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'targetfiles'}; {'id': '88', 'type': 'call', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'glob'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}; {'id': '91', 'type': 'call', 'children': ['92', '97']}; {'id': '92', 'type': 'attribute', 'children': ['93', '96']}; {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '97', 'type': 'argument_list', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'targetdir'}; {'id': '99', 'type': 'string', 'children': [], 'value': "'*.fasta'"}; {'id': '100', 'type': 'try_statement', 'children': ['101', '110']}; {'id': '101', 'type': 'block', 'children': ['102']}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}; {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '105', 'type': 'subscript', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'targetfiles'}; {'id': '109', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '110', 'type': 'except_clause', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'IndexError'}; {'id': '112', 'type': 'block', 'children': ['113']}; {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '118']}; {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'targetfiles'}; {'id': '118', 'type': 'call', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'glob'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}; {'id': '121', 'type': 'call', 'children': ['122', '127']}; {'id': '122', 'type': 'attribute', 'children': ['123', '126']}; {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '127', 'type': 'argument_list', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'targetdir'}; {'id': '129', 'type': 'string', 'children': [], 'value': "'*.fasta'"}; {'id': '130', 'type': 'for_statement', 'children': ['131', '132', '135']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'targetfile'}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'targetfiles'}; {'id': '135', 'type': 'block', 'children': ['136', '155']}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}; {'id': '137', 'type': 'assignment', 'children': ['138', '143']}; {'id': '138', 'type': 'subscript', 'children': ['139', '142']}; {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'records'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'targetfile'}; {'id': '143', 'type': 'call', 'children': ['144', '147']}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'SeqIO'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'to_dict'}; {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'call', 'children': ['149', '152']}; {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'SeqIO'}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'parse'}; {'id': '152', 'type': 'argument_list', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'targetfile'}; {'id': '154', 'type': 'string', 'children': [], 'value': "'fasta'"}; {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'call', 'children': ['157', '162']}; {'id': '157', 'type': 'attribute', 'children': ['158', '161']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'dqueue'}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'put'}; {'id': '162', 'type': 'argument_list', 'children': ['163']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'targetfile'}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}; {'id': '165', 'type': 'call', 'children': ['166', '171']}; {'id': '166', 'type': 'attribute', 'children': ['167', '170']}; {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'dqueue'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '171', 'type': 'argument_list', 'children': []}
|
def makedbthreads(self):
for sample in self.metadata:
if sample[self.analysistype].combinedtargets != 'NA':
self.targetfolders.add(sample[self.analysistype].targetpath)
for i in range(len(self.targetfolders)):
threads = Thread(target=self.makeblastdb, args=())
threads.setDaemon(True)
threads.start()
for targetdir in self.targetfolders:
self.targetfiles = glob(os.path.join(targetdir, '*.fasta'))
try:
_ = self.targetfiles[0]
except IndexError:
self.targetfiles = glob(os.path.join(targetdir, '*.fasta'))
for targetfile in self.targetfiles:
self.records[targetfile] = SeqIO.to_dict(SeqIO.parse(targetfile, 'fasta'))
self.dqueue.put(targetfile)
self.dqueue.join()
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'cowbat'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '13', '49', '85', '116', '152', '188', '229', '265', '307', '349', '391', '433', '469']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'call', 'children': ['8', '11']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'string', 'children': [], 'value': "'Beginning COWBAT database downloads'"}; {'id': '13', 'type': 'if_statement', 'children': ['14', '37']}; {'id': '14', 'type': 'boolean_operator', 'children': ['15', '18'], 'value': 'or'}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'overwrite'}; {'id': '18', 'type': 'not_operator', 'children': ['19']}; {'id': '19', 'type': 'call', 'children': ['20', '25']}; {'id': '20', 'type': 'attribute', 'children': ['21', '24']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'isdir'}; {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'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': 'os'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'join'}; {'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': 'databasepath'}; {'id': '36', 'type': 'string', 'children': [], 'value': "'genesippr'"}; {'id': '37', 'type': 'block', 'children': ['38']}; {'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': 'sipprverse_targets'}; {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'databasepath'}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'databasepath'}; {'id': '49', 'type': 'if_statement', 'children': ['50', '73']}; {'id': '50', 'type': 'boolean_operator', 'children': ['51', '54'], 'value': 'or'}; {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'overwrite'}; {'id': '54', 'type': 'not_operator', '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': 'os'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'isdir'}; {'id': '61', 'type': 'argument_list', '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': 'os'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '68', 'type': 'argument_list', 'children': ['69', '72']}; {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'databasepath'}; {'id': '72', 'type': 'string', 'children': [], 'value': "'coregenome'"}; {'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': 'self'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'cowbat_targets'}; {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'keyword_argument', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'databasepath'}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'databasepath'}; {'id': '85', 'type': 'if_statement', 'children': ['86', '109']}; {'id': '86', 'type': 'boolean_operator', 'children': ['87', '90'], 'value': 'or'}; {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'overwrite'}; {'id': '90', 'type': 'not_operator', 'children': ['91']}; {'id': '91', 'type': 'call', 'children': ['92', '97']}; {'id': '92', 'type': 'attribute', 'children': ['93', '96']}; {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'isdir'}; {'id': '97', 'type': 'argument_list', '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': 'os'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '104', 'type': 'argument_list', 'children': ['105', '108']}; {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'databasepath'}; {'id': '108', 'type': 'string', 'children': [], 'value': "'ConFindr'"}; {'id': '109', 'type': 'block', 'children': ['110']}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}; {'id': '111', 'type': 'call', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'confindr_targets'}; {'id': '115', 'type': 'argument_list', 'children': []}; {'id': '116', 'type': 'if_statement', 'children': ['117', '140']}; {'id': '117', 'type': 'boolean_operator', 'children': ['118', '121'], 'value': 'or'}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'overwrite'}; {'id': '121', 'type': 'not_operator', 'children': ['122']}; {'id': '122', 'type': 'call', 'children': ['123', '128']}; {'id': '123', 'type': 'attribute', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'isdir'}; {'id': '128', 'type': 'argument_list', 'children': ['129']}; {'id': '129', 'type': 'call', 'children': ['130', '135']}; {'id': '130', 'type': 'attribute', 'children': ['131', '134']}; {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '135', 'type': 'argument_list', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'databasepath'}; {'id': '139', 'type': 'string', 'children': [], 'value': "'mash'"}; {'id': '140', 'type': 'block', 'children': ['141']}; {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'call', 'children': ['143', '146']}; {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'mash'}; {'id': '146', 'type': 'argument_list', 'children': ['147']}; {'id': '147', 'type': 'keyword_argument', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'databasepath'}; {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'databasepath'}; {'id': '152', 'type': 'if_statement', 'children': ['153', '176']}; {'id': '153', 'type': 'boolean_operator', 'children': ['154', '157'], 'value': 'or'}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'overwrite'}; {'id': '157', 'type': 'not_operator', 'children': ['158']}; {'id': '158', 'type': 'call', 'children': ['159', '164']}; {'id': '159', 'type': 'attribute', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'isdir'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}; {'id': '165', 'type': 'call', 'children': ['166', '171']}; {'id': '166', 'type': 'attribute', 'children': ['167', '170']}; {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '171', 'type': 'argument_list', 'children': ['172', '175']}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'databasepath'}; {'id': '175', 'type': 'string', 'children': [], 'value': "'MLST'"}; {'id': '176', 'type': 'block', 'children': ['177']}; {'id': '177', 'type': 'expression_statement', 'children': ['178']}; {'id': '178', 'type': 'call', 'children': ['179', '182']}; {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'mlst'}; {'id': '182', 'type': 'argument_list', 'children': ['183']}; {'id': '183', 'type': 'keyword_argument', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'databasepath'}; {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'databasepath'}; {'id': '188', 'type': 'if_statement', 'children': ['189', '212']}; {'id': '189', 'type': 'boolean_operator', 'children': ['190', '193'], 'value': 'or'}; {'id': '190', 'type': 'attribute', 'children': ['191', '192']}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'overwrite'}; {'id': '193', 'type': 'not_operator', 'children': ['194']}; {'id': '194', 'type': 'call', 'children': ['195', '200']}; {'id': '195', 'type': 'attribute', 'children': ['196', '199']}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'isdir'}; {'id': '200', 'type': 'argument_list', 'children': ['201']}; {'id': '201', 'type': 'call', 'children': ['202', '207']}; {'id': '202', 'type': 'attribute', 'children': ['203', '206']}; {'id': '203', 'type': 'attribute', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '207', 'type': 'argument_list', 'children': ['208', '211']}; {'id': '208', 'type': 'attribute', 'children': ['209', '210']}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'databasepath'}; {'id': '211', 'type': 'string', 'children': [], 'value': "'rMLST'"}; {'id': '212', 'type': 'block', 'children': ['213']}; {'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': 'self'}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'rmlst'}; {'id': '218', 'type': 'argument_list', 'children': ['219', '224']}; {'id': '219', 'type': 'keyword_argument', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'databasepath'}; {'id': '221', 'type': 'attribute', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'databasepath'}; {'id': '224', 'type': 'keyword_argument', 'children': ['225', '226']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'credentials'}; {'id': '226', 'type': 'attribute', 'children': ['227', '228']}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'credentials'}; {'id': '229', 'type': 'if_statement', 'children': ['230', '253']}; {'id': '230', 'type': 'boolean_operator', 'children': ['231', '234'], 'value': 'or'}; {'id': '231', 'type': 'attribute', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'overwrite'}; {'id': '234', 'type': 'not_operator', 'children': ['235']}; {'id': '235', 'type': 'call', 'children': ['236', '241']}; {'id': '236', 'type': 'attribute', 'children': ['237', '240']}; {'id': '237', 'type': 'attribute', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'isdir'}; {'id': '241', 'type': 'argument_list', 'children': ['242']}; {'id': '242', 'type': 'call', 'children': ['243', '248']}; {'id': '243', 'type': 'attribute', 'children': ['244', '247']}; {'id': '244', 'type': 'attribute', 'children': ['245', '246']}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '248', 'type': 'argument_list', 'children': ['249', '252']}; {'id': '249', 'type': 'attribute', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'databasepath'}; {'id': '252', 'type': 'string', 'children': [], 'value': "'univec'"}; {'id': '253', 'type': 'block', 'children': ['254']}; {'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': 'self'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'univec'}; {'id': '259', 'type': 'argument_list', 'children': ['260']}; {'id': '260', 'type': 'keyword_argument', 'children': ['261', '262']}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'databasepath'}; {'id': '262', 'type': 'attribute', 'children': ['263', '264']}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'databasepath'}; {'id': '265', 'type': 'if_statement', 'children': ['266', '289']}; {'id': '266', 'type': 'boolean_operator', 'children': ['267', '270'], 'value': 'or'}; {'id': '267', 'type': 'attribute', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'overwrite'}; {'id': '270', 'type': 'not_operator', 'children': ['271']}; {'id': '271', 'type': 'call', 'children': ['272', '277']}; {'id': '272', 'type': 'attribute', 'children': ['273', '276']}; {'id': '273', 'type': 'attribute', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'isdir'}; {'id': '277', 'type': 'argument_list', 'children': ['278']}; {'id': '278', 'type': 'call', 'children': ['279', '284']}; {'id': '279', 'type': 'attribute', 'children': ['280', '283']}; {'id': '280', 'type': 'attribute', 'children': ['281', '282']}; {'id': '281', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '283', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '284', 'type': 'argument_list', 'children': ['285', '288']}; {'id': '285', 'type': 'attribute', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '287', 'type': 'identifier', 'children': [], 'value': 'databasepath'}; {'id': '288', 'type': 'string', 'children': [], 'value': "'resfinder'"}; {'id': '289', 'type': 'block', 'children': ['290']}; {'id': '290', 'type': 'expression_statement', 'children': ['291']}; {'id': '291', 'type': 'call', 'children': ['292', '295']}; {'id': '292', 'type': 'attribute', 'children': ['293', '294']}; {'id': '293', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'cge_db_downloader'}; {'id': '295', 'type': 'argument_list', 'children': ['296', '301', '304']}; {'id': '296', 'type': 'keyword_argument', 'children': ['297', '298']}; {'id': '297', 'type': 'identifier', 'children': [], 'value': 'databasepath'}; {'id': '298', 'type': 'attribute', 'children': ['299', '300']}; {'id': '299', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'databasepath'}; {'id': '301', 'type': 'keyword_argument', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'analysistype'}; {'id': '303', 'type': 'string', 'children': [], 'value': "'resfinder'"}; {'id': '304', 'type': 'keyword_argument', 'children': ['305', '306']}; {'id': '305', 'type': 'identifier', 'children': [], 'value': 'dbname'}; {'id': '306', 'type': 'string', 'children': [], 'value': "'resfinder_db'"}; {'id': '307', 'type': 'if_statement', 'children': ['308', '331']}; {'id': '308', 'type': 'boolean_operator', 'children': ['309', '312'], 'value': 'or'}; {'id': '309', 'type': 'attribute', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '311', 'type': 'identifier', 'children': [], 'value': 'overwrite'}; {'id': '312', 'type': 'not_operator', 'children': ['313']}; {'id': '313', 'type': 'call', 'children': ['314', '319']}; {'id': '314', 'type': 'attribute', 'children': ['315', '318']}; {'id': '315', 'type': 'attribute', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '317', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'isdir'}; {'id': '319', 'type': 'argument_list', 'children': ['320']}; {'id': '320', 'type': 'call', 'children': ['321', '326']}; {'id': '321', 'type': 'attribute', 'children': ['322', '325']}; {'id': '322', 'type': 'attribute', 'children': ['323', '324']}; {'id': '323', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '325', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '326', 'type': 'argument_list', 'children': ['327', '330']}; {'id': '327', 'type': 'attribute', 'children': ['328', '329']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '329', 'type': 'identifier', 'children': [], 'value': 'databasepath'}; {'id': '330', 'type': 'string', 'children': [], 'value': "'virulence'"}; {'id': '331', 'type': 'block', 'children': ['332']}; {'id': '332', 'type': 'expression_statement', 'children': ['333']}; {'id': '333', 'type': 'call', 'children': ['334', '337']}; {'id': '334', 'type': 'attribute', 'children': ['335', '336']}; {'id': '335', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'cge_db_downloader'}; {'id': '337', 'type': 'argument_list', 'children': ['338', '343', '346']}; {'id': '338', 'type': 'keyword_argument', 'children': ['339', '340']}; {'id': '339', 'type': 'identifier', 'children': [], 'value': 'databasepath'}; {'id': '340', 'type': 'attribute', 'children': ['341', '342']}; {'id': '341', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'databasepath'}; {'id': '343', 'type': 'keyword_argument', 'children': ['344', '345']}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'analysistype'}; {'id': '345', 'type': 'string', 'children': [], 'value': "'virulence'"}; {'id': '346', 'type': 'keyword_argument', 'children': ['347', '348']}; {'id': '347', 'type': 'identifier', 'children': [], 'value': 'dbname'}; {'id': '348', 'type': 'string', 'children': [], 'value': "'virulencefinder_db'"}; {'id': '349', 'type': 'if_statement', 'children': ['350', '373']}; {'id': '350', 'type': 'boolean_operator', 'children': ['351', '354'], 'value': 'or'}; {'id': '351', 'type': 'attribute', 'children': ['352', '353']}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '353', 'type': 'identifier', 'children': [], 'value': 'overwrite'}; {'id': '354', 'type': 'not_operator', 'children': ['355']}; {'id': '355', 'type': 'call', 'children': ['356', '361']}; {'id': '356', 'type': 'attribute', 'children': ['357', '360']}; {'id': '357', 'type': 'attribute', 'children': ['358', '359']}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '359', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'isdir'}; {'id': '361', 'type': 'argument_list', 'children': ['362']}; {'id': '362', 'type': 'call', 'children': ['363', '368']}; {'id': '363', 'type': 'attribute', 'children': ['364', '367']}; {'id': '364', 'type': 'attribute', 'children': ['365', '366']}; {'id': '365', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '367', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '368', 'type': 'argument_list', 'children': ['369', '372']}; {'id': '369', 'type': 'attribute', 'children': ['370', '371']}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '371', 'type': 'identifier', 'children': [], 'value': 'databasepath'}; {'id': '372', 'type': 'string', 'children': [], 'value': "'serosippr'"}; {'id': '373', 'type': 'block', 'children': ['374']}; {'id': '374', 'type': 'expression_statement', 'children': ['375']}; {'id': '375', 'type': 'call', 'children': ['376', '379']}; {'id': '376', 'type': 'attribute', 'children': ['377', '378']}; {'id': '377', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '378', 'type': 'identifier', 'children': [], 'value': 'cge_db_downloader'}; {'id': '379', 'type': 'argument_list', 'children': ['380', '385', '388']}; {'id': '380', 'type': 'keyword_argument', 'children': ['381', '382']}; {'id': '381', 'type': 'identifier', 'children': [], 'value': 'databasepath'}; {'id': '382', 'type': 'attribute', 'children': ['383', '384']}; {'id': '383', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'databasepath'}; {'id': '385', 'type': 'keyword_argument', 'children': ['386', '387']}; {'id': '386', 'type': 'identifier', 'children': [], 'value': 'analysistype'}; {'id': '387', 'type': 'string', 'children': [], 'value': "'serosippr'"}; {'id': '388', 'type': 'keyword_argument', 'children': ['389', '390']}; {'id': '389', 'type': 'identifier', 'children': [], 'value': 'dbname'}; {'id': '390', 'type': 'string', 'children': [], 'value': "'serotypefinder_db'"}; {'id': '391', 'type': 'if_statement', 'children': ['392', '415']}; {'id': '392', 'type': 'boolean_operator', 'children': ['393', '396'], 'value': 'or'}; {'id': '393', 'type': 'attribute', 'children': ['394', '395']}; {'id': '394', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '395', 'type': 'identifier', 'children': [], 'value': 'overwrite'}; {'id': '396', 'type': 'not_operator', 'children': ['397']}; {'id': '397', 'type': 'call', 'children': ['398', '403']}; {'id': '398', 'type': 'attribute', 'children': ['399', '402']}; {'id': '399', 'type': 'attribute', 'children': ['400', '401']}; {'id': '400', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '401', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '402', 'type': 'identifier', 'children': [], 'value': 'isdir'}; {'id': '403', 'type': 'argument_list', 'children': ['404']}; {'id': '404', 'type': 'call', 'children': ['405', '410']}; {'id': '405', 'type': 'attribute', 'children': ['406', '409']}; {'id': '406', 'type': 'attribute', 'children': ['407', '408']}; {'id': '407', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '408', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '409', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '410', 'type': 'argument_list', 'children': ['411', '414']}; {'id': '411', 'type': 'attribute', 'children': ['412', '413']}; {'id': '412', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '413', 'type': 'identifier', 'children': [], 'value': 'databasepath'}; {'id': '414', 'type': 'string', 'children': [], 'value': "'pointfinder'"}; {'id': '415', 'type': 'block', 'children': ['416']}; {'id': '416', 'type': 'expression_statement', 'children': ['417']}; {'id': '417', 'type': 'call', 'children': ['418', '421']}; {'id': '418', 'type': 'attribute', 'children': ['419', '420']}; {'id': '419', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '420', 'type': 'identifier', 'children': [], 'value': 'cge_db_downloader'}; {'id': '421', 'type': 'argument_list', 'children': ['422', '427', '430']}; {'id': '422', 'type': 'keyword_argument', 'children': ['423', '424']}; {'id': '423', 'type': 'identifier', 'children': [], 'value': 'databasepath'}; {'id': '424', 'type': 'attribute', 'children': ['425', '426']}; {'id': '425', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '426', 'type': 'identifier', 'children': [], 'value': 'databasepath'}; {'id': '427', 'type': 'keyword_argument', 'children': ['428', '429']}; {'id': '428', 'type': 'identifier', 'children': [], 'value': 'analysistype'}; {'id': '429', 'type': 'string', 'children': [], 'value': "'pointfinder'"}; {'id': '430', 'type': 'keyword_argument', 'children': ['431', '432']}; {'id': '431', 'type': 'identifier', 'children': [], 'value': 'dbname'}; {'id': '432', 'type': 'string', 'children': [], 'value': "'pointfinder_db'"}; {'id': '433', 'type': 'if_statement', 'children': ['434', '457']}; {'id': '434', 'type': 'boolean_operator', 'children': ['435', '438'], 'value': 'or'}; {'id': '435', 'type': 'attribute', 'children': ['436', '437']}; {'id': '436', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '437', 'type': 'identifier', 'children': [], 'value': 'overwrite'}; {'id': '438', 'type': 'not_operator', 'children': ['439']}; {'id': '439', 'type': 'call', 'children': ['440', '445']}; {'id': '440', 'type': 'attribute', 'children': ['441', '444']}; {'id': '441', 'type': 'attribute', 'children': ['442', '443']}; {'id': '442', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '443', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '444', 'type': 'identifier', 'children': [], 'value': 'isdir'}; {'id': '445', 'type': 'argument_list', 'children': ['446']}; {'id': '446', 'type': 'call', 'children': ['447', '452']}; {'id': '447', 'type': 'attribute', 'children': ['448', '451']}; {'id': '448', 'type': 'attribute', 'children': ['449', '450']}; {'id': '449', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '450', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '451', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '452', 'type': 'argument_list', 'children': ['453', '456']}; {'id': '453', 'type': 'attribute', 'children': ['454', '455']}; {'id': '454', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '455', 'type': 'identifier', 'children': [], 'value': 'databasepath'}; {'id': '456', 'type': 'string', 'children': [], 'value': "'clark'"}; {'id': '457', 'type': 'block', 'children': ['458']}; {'id': '458', 'type': 'expression_statement', 'children': ['459']}; {'id': '459', 'type': 'call', 'children': ['460', '463']}; {'id': '460', 'type': 'attribute', 'children': ['461', '462']}; {'id': '461', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '462', 'type': 'identifier', 'children': [], 'value': 'clark'}; {'id': '463', 'type': 'argument_list', 'children': ['464']}; {'id': '464', 'type': 'keyword_argument', 'children': ['465', '466']}; {'id': '465', 'type': 'identifier', 'children': [], 'value': 'databasepath'}; {'id': '466', 'type': 'attribute', 'children': ['467', '468']}; {'id': '467', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '468', 'type': 'identifier', 'children': [], 'value': 'databasepath'}; {'id': '469', 'type': 'if_statement', 'children': ['470', '493']}; {'id': '470', 'type': 'boolean_operator', 'children': ['471', '474'], 'value': 'or'}; {'id': '471', 'type': 'attribute', 'children': ['472', '473']}; {'id': '472', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '473', 'type': 'identifier', 'children': [], 'value': 'overwrite'}; {'id': '474', 'type': 'not_operator', 'children': ['475']}; {'id': '475', 'type': 'call', 'children': ['476', '481']}; {'id': '476', 'type': 'attribute', 'children': ['477', '480']}; {'id': '477', 'type': 'attribute', 'children': ['478', '479']}; {'id': '478', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '479', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '480', 'type': 'identifier', 'children': [], 'value': 'isdir'}; {'id': '481', 'type': 'argument_list', 'children': ['482']}; {'id': '482', 'type': 'call', 'children': ['483', '488']}; {'id': '483', 'type': 'attribute', 'children': ['484', '487']}; {'id': '484', 'type': 'attribute', 'children': ['485', '486']}; {'id': '485', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '486', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '487', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '488', 'type': 'argument_list', 'children': ['489', '492']}; {'id': '489', 'type': 'attribute', 'children': ['490', '491']}; {'id': '490', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '491', 'type': 'identifier', 'children': [], 'value': 'databasepath'}; {'id': '492', 'type': 'string', 'children': [], 'value': "'mob_suite'"}; {'id': '493', 'type': 'block', 'children': ['494']}; {'id': '494', 'type': 'expression_statement', 'children': ['495']}; {'id': '495', 'type': 'call', 'children': ['496', '499']}; {'id': '496', 'type': 'attribute', 'children': ['497', '498']}; {'id': '497', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '498', 'type': 'identifier', 'children': [], 'value': 'mob_suite_targets'}; {'id': '499', 'type': 'argument_list', 'children': []}
|
def cowbat(self):
logging.info('Beginning COWBAT database downloads')
if self.overwrite or not os.path.isdir(os.path.join(self.databasepath, 'genesippr')):
self.sipprverse_targets(databasepath=self.databasepath)
if self.overwrite or not os.path.isdir(os.path.join(self.databasepath, 'coregenome')):
self.cowbat_targets(databasepath=self.databasepath)
if self.overwrite or not os.path.isdir(os.path.join(self.databasepath, 'ConFindr')):
self.confindr_targets()
if self.overwrite or not os.path.isdir(os.path.join(self.databasepath, 'mash')):
self.mash(databasepath=self.databasepath)
if self.overwrite or not os.path.isdir(os.path.join(self.databasepath, 'MLST')):
self.mlst(databasepath=self.databasepath)
if self.overwrite or not os.path.isdir(os.path.join(self.databasepath, 'rMLST')):
self.rmlst(databasepath=self.databasepath,
credentials=self.credentials)
if self.overwrite or not os.path.isdir(os.path.join(self.databasepath, 'univec')):
self.univec(databasepath=self.databasepath)
if self.overwrite or not os.path.isdir(os.path.join(self.databasepath, 'resfinder')):
self.cge_db_downloader(databasepath=self.databasepath,
analysistype='resfinder',
dbname='resfinder_db')
if self.overwrite or not os.path.isdir(os.path.join(self.databasepath, 'virulence')):
self.cge_db_downloader(databasepath=self.databasepath,
analysistype='virulence',
dbname='virulencefinder_db')
if self.overwrite or not os.path.isdir(os.path.join(self.databasepath, 'serosippr')):
self.cge_db_downloader(databasepath=self.databasepath,
analysistype='serosippr',
dbname='serotypefinder_db')
if self.overwrite or not os.path.isdir(os.path.join(self.databasepath, 'pointfinder')):
self.cge_db_downloader(databasepath=self.databasepath,
analysistype='pointfinder',
dbname='pointfinder_db')
if self.overwrite or not os.path.isdir(os.path.join(self.databasepath, 'clark')):
self.clark(databasepath=self.databasepath)
if self.overwrite or not os.path.isdir(os.path.join(self.databasepath, 'mob_suite')):
self.mob_suite_targets()
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'setCalibration'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'dbBoostArray'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'frequencies'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'frange'}; {'id': '8', 'type': 'block', 'children': ['9']}; {'id': '9', 'type': 'if_statement', 'children': ['10', '17', '189']}; {'id': '10', 'type': 'boolean_operator', 'children': ['11', '14'], 'value': 'and'}; {'id': '11', 'type': 'comparison_operator', 'children': ['12', '13'], 'value': 'is'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'dbBoostArray'}; {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': 'is'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'frequencies'}; {'id': '16', 'type': 'None', 'children': []}; {'id': '17', 'type': 'block', 'children': ['18', '27', '44', '60', '76', '84', '144', '150', '171', '177', '183']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'getLogger'}; {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'string', 'children': [], 'value': "'main'"}; {'id': '27', 'type': 'if_statement', 'children': ['28', '35']}; {'id': '28', 'type': 'comparison_operator', 'children': ['29', '32'], 'value': '!='}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'dbBoostArray'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'frequencies'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '35', 'type': 'block', 'children': ['36', '43']}; {'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': 'logger'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'string', 'children': [], 'value': '"ERROR: calibration array and frequency array must have same dimensions"'}; {'id': '43', 'type': 'return_statement', 'children': []}; {'id': '44', 'type': 'if_statement', 'children': ['45', '48']}; {'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': 'is'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'frange'}; {'id': '47', 'type': 'None', 'children': []}; {'id': '48', 'type': 'block', 'children': ['49']}; {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'frange'}; {'id': '52', 'type': 'tuple', 'children': ['53', '56']}; {'id': '53', 'type': 'subscript', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'frequencies'}; {'id': '55', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '56', 'type': 'subscript', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'frequencies'}; {'id': '58', 'type': 'unary_operator', 'children': ['59'], 'value': '-'}; {'id': '59', 'type': 'integer', 'children': [], 'value': '1'}; {'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': 'logger'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'call', 'children': ['67', '70']}; {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'string', 'children': [], 'value': "'setting calibration with samplerate {}'"}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}; {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'samplerate'}; {'id': '75', 'type': 'argument_list', 'children': []}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}; {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'fs'}; {'id': '79', 'type': 'call', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'samplerate'}; {'id': '83', 'type': 'argument_list', 'children': []}; {'id': '84', 'type': 'if_statement', 'children': ['85', '90', '108']}; {'id': '85', 'type': 'comparison_operator', 'children': ['86', '87'], 'value': 'in'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'fs'}; {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'StimulusModel'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'kernelCache'}; {'id': '90', 'type': 'block', 'children': ['91', '98']}; {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '96']}; {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}; {'id': '97', 'type': 'string', 'children': [], 'value': "'---->using cached filter'"}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}; {'id': '99', 'type': 'assignment', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'impulseResponse'}; {'id': '103', 'type': 'subscript', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'StimulusModel'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'kernelCache'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'fs'}; {'id': '108', 'type': 'else_clause', 'children': ['109']}; {'id': '109', 'type': 'block', 'children': ['110', '122', '134']}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}; {'id': '111', 'type': 'call', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'call', 'children': ['117', '120']}; {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'string', 'children': [], 'value': "'---->calculating new filter for fs {}'"}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'fs'}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}; {'id': '123', 'type': 'assignment', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'impulseResponse'}; {'id': '127', 'type': 'call', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'impulse_response'}; {'id': '129', 'type': 'argument_list', 'children': ['130', '131', '132', '133']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'fs'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'dbBoostArray'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'frequencies'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'frange'}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}; {'id': '135', 'type': 'assignment', 'children': ['136', '141']}; {'id': '136', 'type': 'subscript', 'children': ['137', '140']}; {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'StimulusModel'}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'kernelCache'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'fs'}; {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'impulseResponse'}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}; {'id': '145', 'type': 'assignment', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': '_calibration_fs'}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'fs'}; {'id': '150', 'type': 'if_statement', 'children': ['151', '156']}; {'id': '151', 'type': 'comparison_operator', 'children': ['152', '153'], 'value': 'not'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_SAMPLERATE'}; {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'StimulusModel'}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'kernelCache'}; {'id': '156', 'type': 'block', 'children': ['157']}; {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'assignment', 'children': ['159', '164']}; {'id': '159', 'type': 'subscript', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'StimulusModel'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'kernelCache'}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_SAMPLERATE'}; {'id': '164', 'type': 'call', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'impulse_response'}; {'id': '166', 'type': 'argument_list', 'children': ['167', '168', '169', '170']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_SAMPLERATE'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'dbBoostArray'}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'frequencies'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'frange'}; {'id': '171', 'type': 'expression_statement', 'children': ['172']}; {'id': '172', 'type': 'assignment', 'children': ['173', '176']}; {'id': '173', 'type': 'attribute', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '175', 'type': 'identifier', 'children': [], 'value': '_attenuationVector'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'dbBoostArray'}; {'id': '177', 'type': 'expression_statement', 'children': ['178']}; {'id': '178', 'type': 'assignment', 'children': ['179', '182']}; {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '181', 'type': 'identifier', 'children': [], 'value': '_calFrequencies'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'frequencies'}; {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'assignment', 'children': ['185', '188']}; {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '187', 'type': 'identifier', 'children': [], 'value': '_calFrange'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'frange'}; {'id': '189', 'type': 'else_clause', 'children': ['190']}; {'id': '190', 'type': 'block', 'children': ['191']}; {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'assignment', 'children': ['193', '196']}; {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'impulseResponse'}; {'id': '196', 'type': 'None', 'children': []}
|
def setCalibration(self, dbBoostArray, frequencies, frange):
if dbBoostArray is not None and frequencies is not None:
logger = logging.getLogger('main')
if dbBoostArray.shape != frequencies.shape:
logger.error("ERROR: calibration array and frequency array must have same dimensions")
return
if frange is None:
frange = (frequencies[0], frequencies[-1])
logger.debug('setting calibration with samplerate {}'.format(self.samplerate()))
fs = self.samplerate()
if fs in StimulusModel.kernelCache:
logger.debug('---->using cached filter')
self.impulseResponse = StimulusModel.kernelCache[fs]
else:
logger.debug('---->calculating new filter for fs {}'.format(fs))
self.impulseResponse = impulse_response(fs, dbBoostArray, frequencies, frange)
StimulusModel.kernelCache[fs] = self.impulseResponse
self._calibration_fs = fs
if DEFAULT_SAMPLERATE not in StimulusModel.kernelCache:
StimulusModel.kernelCache[DEFAULT_SAMPLERATE] = impulse_response(DEFAULT_SAMPLERATE, dbBoostArray, frequencies, frange)
self._attenuationVector = dbBoostArray
self._calFrequencies = frequencies
self._calFrange = frange
else:
self.impulseResponse = None
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'expandFunction'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '8', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '9', 'type': 'block', 'children': ['10', '20', '28', '32', '45', '66', '70', '117', '121', '187', '216']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}; {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'params'}; {'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': '_autoParams'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'allData'}; {'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': 'steps'}; {'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': 'autoParamRanges'}; {'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': 'ntraces'}; {'id': '31', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '32', 'type': 'for_statement', 'children': ['33', '34', '35']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'steps'}; {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}; {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'ntraces'}; {'id': '39', 'type': 'binary_operator', 'children': ['40', '41'], 'value': '*'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'ntraces'}; {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'varylist'}; {'id': '48', 'type': 'list_comprehension', 'children': ['49', '60']}; {'id': '49', 'type': 'list_comprehension', 'children': ['50', '51']}; {'id': '50', 'type': 'None', 'children': []}; {'id': '51', 'type': 'for_in_clause', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'call', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '60', 'type': 'for_in_clause', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '62', 'type': 'call', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'ntraces'}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}; {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '69', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '70', 'type': 'for_statement', 'children': ['71', '74', '78']}; {'id': '71', 'type': 'pattern_list', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'iset'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'step_set'}; {'id': '74', 'type': 'call', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'steps'}; {'id': '78', 'type': 'block', 'children': ['79', '108']}; {'id': '79', 'type': 'for_statement', 'children': ['80', '81', '85']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'itrace'}; {'id': '81', 'type': 'call', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'ntraces'}; {'id': '85', 'type': 'block', 'children': ['86', '98']}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}; {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '89', 'type': 'binary_operator', 'children': ['90', '94'], 'value': '%'}; {'id': '90', 'type': '()', 'children': ['91']}; {'id': '91', 'type': 'binary_operator', 'children': ['92', '93'], 'value': '/'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'itrace'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '94', 'type': 'call', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'step_set'}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}; {'id': '99', 'type': 'assignment', 'children': ['100', '105']}; {'id': '100', 'type': 'subscript', 'children': ['101', '104']}; {'id': '101', 'type': 'subscript', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'varylist'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'itrace'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'iset'}; {'id': '105', 'type': 'subscript', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'step_set'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}; {'id': '109', 'type': 'assignment', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '111', 'type': 'binary_operator', 'children': ['112', '113'], 'value': '*'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '113', 'type': 'call', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'step_set'}; {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'assignment', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'stim_list'}; {'id': '120', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '121', 'type': 'for_statement', 'children': ['122', '123', '127']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'itrace'}; {'id': '123', 'type': 'call', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '125', 'type': 'argument_list', 'children': ['126']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'ntraces'}; {'id': '127', 'type': 'block', 'children': ['128', '176']}; {'id': '128', 'type': 'for_statement', 'children': ['129', '132', '136']}; {'id': '129', 'type': 'pattern_list', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'ip'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '132', 'type': 'call', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '134', 'type': 'argument_list', 'children': ['135']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '136', 'type': 'block', 'children': ['137']}; {'id': '137', 'type': 'for_statement', 'children': ['138', '139', '142']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'component'}; {'id': '139', 'type': 'subscript', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '141', 'type': 'string', 'children': [], 'value': "'selection'"}; {'id': '142', 'type': 'block', 'children': ['143', '152', '162']}; {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'assignment', 'children': ['145', '146']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'index'}; {'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': 'indexByComponent'}; {'id': '150', 'type': 'argument_list', 'children': ['151']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'component'}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}; {'id': '153', 'type': 'assignment', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'component'}; {'id': '155', 'type': 'call', 'children': ['156', '159']}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'component'}; {'id': '159', 'type': 'argument_list', 'children': ['160']}; {'id': '160', 'type': 'list_splat', 'children': ['161']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '162', 'type': 'expression_statement', 'children': ['163']}; {'id': '163', 'type': 'call', 'children': ['164', '167']}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'component'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '167', 'type': 'argument_list', 'children': ['168', '171']}; {'id': '168', 'type': 'subscript', 'children': ['169', '170']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '170', 'type': 'string', 'children': [], 'value': "'parameter'"}; {'id': '171', 'type': 'subscript', 'children': ['172', '175']}; {'id': '172', 'type': 'subscript', 'children': ['173', '174']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'varylist'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'itrace'}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'ip'}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}; {'id': '177', 'type': 'call', 'children': ['178', '181']}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'stim_list'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '181', 'type': 'argument_list', 'children': ['182']}; {'id': '182', 'type': 'call', 'children': ['183', '184']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '184', 'type': 'argument_list', 'children': ['185']}; {'id': '185', 'type': 'list_splat', 'children': ['186']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '187', 'type': 'for_statement', 'children': ['188', '191', '195']}; {'id': '188', 'type': 'pattern_list', 'children': ['189', '190']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'ip'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '191', 'type': 'call', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '193', 'type': 'argument_list', 'children': ['194']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '195', 'type': 'block', 'children': ['196']}; {'id': '196', 'type': 'for_statement', 'children': ['197', '198', '201']}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'component'}; {'id': '198', 'type': 'subscript', 'children': ['199', '200']}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '200', 'type': 'string', 'children': [], 'value': "'selection'"}; {'id': '201', 'type': 'block', 'children': ['202']}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}; {'id': '203', 'type': 'call', 'children': ['204', '207']}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'component'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '207', 'type': 'argument_list', 'children': ['208', '211']}; {'id': '208', 'type': 'subscript', 'children': ['209', '210']}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '210', 'type': 'string', 'children': [], 'value': "'parameter'"}; {'id': '211', 'type': 'subscript', 'children': ['212', '215']}; {'id': '212', 'type': 'subscript', 'children': ['213', '214']}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'varylist'}; {'id': '214', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'ip'}; {'id': '216', 'type': 'return_statement', 'children': ['217']}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'stim_list'}
|
def expandFunction(self, func, args=[]):
params = self._autoParams.allData()
steps = self.autoParamRanges()
ntraces = 1
for p in steps:
ntraces = ntraces*len(p)
varylist = [[None for x in range(len(params))] for y in range(ntraces)]
x = 1
for iset, step_set in enumerate(steps):
for itrace in range(ntraces):
idx = (itrace / x) % len(step_set)
varylist[itrace][iset] = step_set[idx]
x = x*len(step_set)
stim_list = []
for itrace in range(ntraces):
for ip, param in enumerate(params):
for component in param['selection']:
index = self.indexByComponent(component)
component = self.component(*index)
component.set(param['parameter'], varylist[itrace][ip])
stim_list.append(func(*args))
for ip, param in enumerate(params):
for component in param['selection']:
component.set(param['parameter'], varylist[0][ip])
return stim_list
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'signal'}; {'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': 'force_fs'}; {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '16', '33', '37', '57', '61', '122', '135', '145', '161', '182', '194', '252', '259', '263', '271', '283', '430']}; {'id': '9', 'type': 'assert_statement', 'children': ['10', '15']}; {'id': '10', 'type': 'comparison_operator', 'children': ['11', '12'], 'value': 'not'}; {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'voltage_limits'}; {'id': '15', 'type': 'string', 'children': [], 'value': "'Max voltage level not set'"}; {'id': '16', 'type': 'if_statement', 'children': ['17', '18', '23']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'force_fs'}; {'id': '18', 'type': 'block', 'children': ['19']}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'samplerate'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'force_fs'}; {'id': '23', 'type': 'else_clause', 'children': ['24']}; {'id': '24', 'type': 'block', 'children': ['25']}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'samplerate'}; {'id': '28', 'type': 'call', 'children': ['29', '32']}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'samplerate'}; {'id': '32', 'type': 'argument_list', 'children': []}; {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'track_signals'}; {'id': '36', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'max_db'}; {'id': '40', 'type': 'call', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}; {'id': '43', 'type': 'list_comprehension', 'children': ['44', '49', '54']}; {'id': '44', 'type': 'call', 'children': ['45', '48']}; {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'comp'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'intensity'}; {'id': '48', 'type': 'argument_list', 'children': []}; {'id': '49', 'type': 'for_in_clause', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': '_segments'}; {'id': '54', 'type': 'for_in_clause', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'comp'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'atten'}; {'id': '60', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '61', 'type': 'for_statement', 'children': ['62', '63', '66']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'track'}; {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': '_segments'}; {'id': '66', 'type': 'block', 'children': ['67', '71', '102']}; {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'track_list'}; {'id': '70', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '71', 'type': 'for_statement', 'children': ['72', '73', '74']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'component'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'track'}; {'id': '74', 'type': 'block', 'children': ['75']}; {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'call', 'children': ['77', '80']}; {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'track_list'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}; {'id': '81', 'type': 'call', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'component'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'signal'}; {'id': '85', 'type': 'argument_list', 'children': ['86', '89', '92', '97']}; {'id': '86', 'type': 'keyword_argument', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'fs'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'samplerate'}; {'id': '89', 'type': 'keyword_argument', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'atten'}; {'id': '91', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '92', 'type': 'keyword_argument', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'caldb'}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'caldb'}; {'id': '97', 'type': 'keyword_argument', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'calv'}; {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'calv'}; {'id': '102', 'type': 'if_statement', 'children': ['103', '109']}; {'id': '103', 'type': 'comparison_operator', 'children': ['104', '108'], 'value': '>'}; {'id': '104', 'type': 'call', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'track_list'}; {'id': '108', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '109', 'type': 'block', 'children': ['110']}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}; {'id': '111', 'type': 'call', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'track_signals'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'call', 'children': ['117', '120']}; {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'hstack'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'track_list'}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}; {'id': '123', 'type': 'assignment', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'full_len'}; {'id': '125', 'type': 'call', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'call', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '130', 'type': 'argument_list', 'children': ['131', '132']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'track_signals'}; {'id': '132', 'type': 'keyword_argument', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'assignment', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'total_signal'}; {'id': '138', 'type': 'call', 'children': ['139', '142']}; {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '142', 'type': 'argument_list', 'children': ['143']}; {'id': '143', 'type': 'tuple', 'children': ['144']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'full_len'}; {'id': '145', 'type': 'for_statement', 'children': ['146', '147', '148']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'track'}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'track_signals'}; {'id': '148', 'type': 'block', 'children': ['149']}; {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'augmented_assignment', 'children': ['151', '160'], 'value': '+='}; {'id': '151', 'type': 'subscript', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'total_signal'}; {'id': '153', 'type': 'slice', 'children': ['154', '155', '156']}; {'id': '154', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '155', 'type': 'colon', 'children': []}; {'id': '156', 'type': 'call', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '158', 'type': 'argument_list', 'children': ['159']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'track'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'track'}; {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'assignment', 'children': ['163', '164']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'component_names'}; {'id': '164', 'type': 'call', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '166', 'type': 'argument_list', 'children': ['167']}; {'id': '167', 'type': 'call', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '169', 'type': 'argument_list', 'children': ['170']}; {'id': '170', 'type': 'list_comprehension', 'children': ['171', '174', '179']}; {'id': '171', 'type': 'attribute', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'comp'}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '174', 'type': 'for_in_clause', 'children': ['175', '176']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'track'}; {'id': '176', 'type': 'attribute', 'children': ['177', '178']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': '_segments'}; {'id': '179', 'type': 'for_in_clause', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'comp'}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'track'}; {'id': '182', 'type': 'if_statement', 'children': ['183', '186']}; {'id': '183', 'type': 'comparison_operator', 'children': ['184', '185'], 'value': 'in'}; {'id': '184', 'type': 'string', 'children': [], 'value': "'silence'"}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'component_names'}; {'id': '186', 'type': 'block', 'children': ['187']}; {'id': '187', 'type': 'expression_statement', 'children': ['188']}; {'id': '188', 'type': 'call', 'children': ['189', '192']}; {'id': '189', 'type': 'attribute', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'component_names'}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'remove'}; {'id': '192', 'type': 'argument_list', 'children': ['193']}; {'id': '193', 'type': 'string', 'children': [], 'value': "'silence'"}; {'id': '194', 'type': 'if_statement', 'children': ['195', '215', '238']}; {'id': '195', 'type': 'boolean_operator', 'children': ['196', '202'], 'value': 'or'}; {'id': '196', 'type': 'comparison_operator', 'children': ['197', '201'], 'value': '>'}; {'id': '197', 'type': 'call', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '199', 'type': 'argument_list', 'children': ['200']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'component_names'}; {'id': '201', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '202', 'type': '()', 'children': ['203']}; {'id': '203', 'type': 'boolean_operator', 'children': ['204', '210'], 'value': 'and'}; {'id': '204', 'type': 'comparison_operator', 'children': ['205', '209'], 'value': '=='}; {'id': '205', 'type': 'call', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '207', 'type': 'argument_list', 'children': ['208']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'component_names'}; {'id': '209', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '210', 'type': 'comparison_operator', 'children': ['211', '214'], 'value': '!='}; {'id': '211', 'type': 'subscript', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'component_names'}; {'id': '213', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '214', 'type': 'string', 'children': [], 'value': '"Square Wave"'}; {'id': '215', 'type': 'block', 'children': ['216', '226', '234']}; {'id': '216', 'type': 'expression_statement', 'children': ['217']}; {'id': '217', 'type': 'assignment', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'total_signal'}; {'id': '219', 'type': 'call', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'convolve_filter'}; {'id': '221', 'type': 'argument_list', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'total_signal'}; {'id': '223', 'type': 'attribute', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'impulseResponse'}; {'id': '226', 'type': 'expression_statement', 'children': ['227']}; {'id': '227', 'type': 'assignment', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'maxv'}; {'id': '229', 'type': 'subscript', 'children': ['230', '233']}; {'id': '230', 'type': 'attribute', 'children': ['231', '232']}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'voltage_limits'}; {'id': '233', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '234', 'type': 'expression_statement', 'children': ['235']}; {'id': '235', 'type': 'assignment', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'to_speaker'}; {'id': '237', 'type': 'True', 'children': []}; {'id': '238', 'type': 'else_clause', 'children': ['239']}; {'id': '239', 'type': 'block', 'children': ['240', '248']}; {'id': '240', 'type': 'expression_statement', 'children': ['241']}; {'id': '241', 'type': 'assignment', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'maxv'}; {'id': '243', 'type': 'subscript', 'children': ['244', '247']}; {'id': '244', 'type': 'attribute', 'children': ['245', '246']}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'voltage_limits'}; {'id': '247', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '248', 'type': 'expression_statement', 'children': ['249']}; {'id': '249', 'type': 'assignment', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'to_speaker'}; {'id': '251', 'type': 'False', 'children': []}; {'id': '252', 'type': 'expression_statement', 'children': ['253']}; {'id': '253', 'type': 'assignment', 'children': ['254', '258']}; {'id': '254', 'type': 'subscript', 'children': ['255', '256']}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'total_signal'}; {'id': '256', 'type': 'unary_operator', 'children': ['257'], 'value': '-'}; {'id': '257', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '258', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '259', 'type': 'expression_statement', 'children': ['260']}; {'id': '260', 'type': 'assignment', 'children': ['261', '262']}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'undesired_attenuation'}; {'id': '262', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '263', 'type': 'expression_statement', 'children': ['264']}; {'id': '264', 'type': 'assignment', 'children': ['265', '266']}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'minv'}; {'id': '266', 'type': 'subscript', 'children': ['267', '270']}; {'id': '267', 'type': 'attribute', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'voltage_limits'}; {'id': '270', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '271', 'type': 'expression_statement', 'children': ['272']}; {'id': '272', 'type': 'assignment', 'children': ['273', '274']}; {'id': '273', 'type': 'identifier', 'children': [], 'value': 'sig_max'}; {'id': '274', 'type': 'call', 'children': ['275', '278']}; {'id': '275', 'type': 'attribute', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '278', 'type': 'argument_list', 'children': ['279']}; {'id': '279', 'type': 'call', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'abs'}; {'id': '281', 'type': 'argument_list', 'children': ['282']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'total_signal'}; {'id': '283', 'type': 'if_statement', 'children': ['284', '287', '356']}; {'id': '284', 'type': 'comparison_operator', 'children': ['285', '286'], 'value': '>'}; {'id': '285', 'type': 'identifier', 'children': [], 'value': 'sig_max'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'maxv'}; {'id': '287', 'type': 'block', 'children': ['288', '297', '310']}; {'id': '288', 'type': 'expression_statement', 'children': ['289']}; {'id': '289', 'type': 'assignment', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'total_signal'}; {'id': '291', 'type': 'binary_operator', 'children': ['292', '296'], 'value': '*'}; {'id': '292', 'type': '()', 'children': ['293']}; {'id': '293', 'type': 'binary_operator', 'children': ['294', '295'], 'value': '/'}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'total_signal'}; {'id': '295', 'type': 'identifier', 'children': [], 'value': 'sig_max'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'maxv'}; {'id': '297', 'type': 'expression_statement', 'children': ['298']}; {'id': '298', 'type': 'assignment', 'children': ['299', '300']}; {'id': '299', 'type': 'identifier', 'children': [], 'value': 'attenuated'}; {'id': '300', 'type': 'binary_operator', 'children': ['301', '302'], 'value': '*'}; {'id': '301', 'type': 'integer', 'children': [], 'value': '20'}; {'id': '302', 'type': 'call', 'children': ['303', '306']}; {'id': '303', 'type': 'attribute', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '305', 'type': 'identifier', 'children': [], 'value': 'log10'}; {'id': '306', 'type': 'argument_list', 'children': ['307']}; {'id': '307', 'type': 'binary_operator', 'children': ['308', '309'], 'value': '/'}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'sig_max'}; {'id': '309', 'type': 'identifier', 'children': [], 'value': 'maxv'}; {'id': '310', 'type': 'if_statement', 'children': ['311', '314', '321']}; {'id': '311', 'type': 'comparison_operator', 'children': ['312', '313'], 'value': '<='}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'attenuated'}; {'id': '313', 'type': 'identifier', 'children': [], 'value': 'atten'}; {'id': '314', 'type': 'block', 'children': ['315']}; {'id': '315', 'type': 'expression_statement', 'children': ['316']}; {'id': '316', 'type': 'assignment', 'children': ['317', '318']}; {'id': '317', 'type': 'identifier', 'children': [], 'value': 'atten'}; {'id': '318', 'type': 'binary_operator', 'children': ['319', '320'], 'value': '-'}; {'id': '319', 'type': 'identifier', 'children': [], 'value': 'atten'}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'attenuated'}; {'id': '321', 'type': 'else_clause', 'children': ['322']}; {'id': '322', 'type': 'block', 'children': ['323', '329', '333', '342']}; {'id': '323', 'type': 'expression_statement', 'children': ['324']}; {'id': '324', 'type': 'assignment', 'children': ['325', '326']}; {'id': '325', 'type': 'identifier', 'children': [], 'value': 'undesired_attenuation'}; {'id': '326', 'type': 'binary_operator', 'children': ['327', '328'], 'value': '-'}; {'id': '327', 'type': 'identifier', 'children': [], 'value': 'attenuated'}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'atten'}; {'id': '329', 'type': 'expression_statement', 'children': ['330']}; {'id': '330', 'type': 'assignment', 'children': ['331', '332']}; {'id': '331', 'type': 'identifier', 'children': [], 'value': 'atten'}; {'id': '332', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '333', 'type': 'expression_statement', 'children': ['334']}; {'id': '334', 'type': 'assignment', 'children': ['335', '336']}; {'id': '335', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '336', 'type': 'call', 'children': ['337', '340']}; {'id': '337', 'type': 'attribute', 'children': ['338', '339']}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '339', 'type': 'identifier', 'children': [], 'value': 'getLogger'}; {'id': '340', 'type': 'argument_list', 'children': ['341']}; {'id': '341', 'type': 'string', 'children': [], 'value': "'main'"}; {'id': '342', 'type': 'expression_statement', 'children': ['343']}; {'id': '343', 'type': 'call', 'children': ['344', '347']}; {'id': '344', 'type': 'attribute', 'children': ['345', '346']}; {'id': '345', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '347', 'type': 'argument_list', 'children': ['348']}; {'id': '348', 'type': 'call', 'children': ['349', '352']}; {'id': '349', 'type': 'attribute', 'children': ['350', '351']}; {'id': '350', 'type': 'string', 'children': [], 'value': '"STIMULUS AMPLTIUDE {:.2f}V EXCEEDS MAXIMUM({}V), RESCALING. \\\n UNDESIRED ATTENUATION {:.2f}dB"'}; {'id': '351', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '352', 'type': 'argument_list', 'children': ['353', '354', '355']}; {'id': '353', 'type': 'identifier', 'children': [], 'value': 'sig_max'}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'maxv'}; {'id': '355', 'type': 'identifier', 'children': [], 'value': 'undesired_attenuation'}; {'id': '356', 'type': 'elif_clause', 'children': ['357', '366']}; {'id': '357', 'type': 'boolean_operator', 'children': ['358', '365'], 'value': 'and'}; {'id': '358', 'type': 'boolean_operator', 'children': ['359', '362'], 'value': 'and'}; {'id': '359', 'type': 'comparison_operator', 'children': ['360', '361'], 'value': '<'}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'sig_max'}; {'id': '361', 'type': 'identifier', 'children': [], 'value': 'minv'}; {'id': '362', 'type': 'comparison_operator', 'children': ['363', '364'], 'value': '!='}; {'id': '363', 'type': 'identifier', 'children': [], 'value': 'sig_max'}; {'id': '364', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '365', 'type': 'identifier', 'children': [], 'value': 'to_speaker'}; {'id': '366', 'type': 'block', 'children': ['367', '385', '394', '412', '426']}; {'id': '367', 'type': 'expression_statement', 'children': ['368']}; {'id': '368', 'type': 'assignment', 'children': ['369', '370']}; {'id': '369', 'type': 'identifier', 'children': [], 'value': 'before_rms'}; {'id': '370', 'type': 'call', 'children': ['371', '374']}; {'id': '371', 'type': 'attribute', 'children': ['372', '373']}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '373', 'type': 'identifier', 'children': [], 'value': 'sqrt'}; {'id': '374', 'type': 'argument_list', 'children': ['375']}; {'id': '375', 'type': 'call', 'children': ['376', '379']}; {'id': '376', 'type': 'attribute', 'children': ['377', '378']}; {'id': '377', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '378', 'type': 'identifier', 'children': [], 'value': 'mean'}; {'id': '379', 'type': 'argument_list', 'children': ['380']}; {'id': '380', 'type': 'call', 'children': ['381', '382']}; {'id': '381', 'type': 'identifier', 'children': [], 'value': 'pow'}; {'id': '382', 'type': 'argument_list', 'children': ['383', '384']}; {'id': '383', 'type': 'identifier', 'children': [], 'value': 'total_signal'}; {'id': '384', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '385', 'type': 'expression_statement', 'children': ['386']}; {'id': '386', 'type': 'assignment', 'children': ['387', '388']}; {'id': '387', 'type': 'identifier', 'children': [], 'value': 'total_signal'}; {'id': '388', 'type': 'binary_operator', 'children': ['389', '393'], 'value': '*'}; {'id': '389', 'type': '()', 'children': ['390']}; {'id': '390', 'type': 'binary_operator', 'children': ['391', '392'], 'value': '/'}; {'id': '391', 'type': 'identifier', 'children': [], 'value': 'total_signal'}; {'id': '392', 'type': 'identifier', 'children': [], 'value': 'sig_max'}; {'id': '393', 'type': 'identifier', 'children': [], 'value': 'minv'}; {'id': '394', 'type': 'expression_statement', 'children': ['395']}; {'id': '395', 'type': 'assignment', 'children': ['396', '397']}; {'id': '396', 'type': 'identifier', 'children': [], 'value': 'after_rms'}; {'id': '397', 'type': 'call', 'children': ['398', '401']}; {'id': '398', 'type': 'attribute', 'children': ['399', '400']}; {'id': '399', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '400', 'type': 'identifier', 'children': [], 'value': 'sqrt'}; {'id': '401', 'type': 'argument_list', 'children': ['402']}; {'id': '402', 'type': 'call', 'children': ['403', '406']}; {'id': '403', 'type': 'attribute', 'children': ['404', '405']}; {'id': '404', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '405', 'type': 'identifier', 'children': [], 'value': 'mean'}; {'id': '406', 'type': 'argument_list', 'children': ['407']}; {'id': '407', 'type': 'call', 'children': ['408', '409']}; {'id': '408', 'type': 'identifier', 'children': [], 'value': 'pow'}; {'id': '409', 'type': 'argument_list', 'children': ['410', '411']}; {'id': '410', 'type': 'identifier', 'children': [], 'value': 'total_signal'}; {'id': '411', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '412', 'type': 'expression_statement', 'children': ['413']}; {'id': '413', 'type': 'assignment', 'children': ['414', '415']}; {'id': '414', 'type': 'identifier', 'children': [], 'value': 'attenuated'}; {'id': '415', 'type': 'binary_operator', 'children': ['416', '418'], 'value': '*'}; {'id': '416', 'type': 'unary_operator', 'children': ['417'], 'value': '-'}; {'id': '417', 'type': 'integer', 'children': [], 'value': '20'}; {'id': '418', 'type': 'call', 'children': ['419', '422']}; {'id': '419', 'type': 'attribute', 'children': ['420', '421']}; {'id': '420', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '421', 'type': 'identifier', 'children': [], 'value': 'log10'}; {'id': '422', 'type': 'argument_list', 'children': ['423']}; {'id': '423', 'type': 'binary_operator', 'children': ['424', '425'], 'value': '/'}; {'id': '424', 'type': 'identifier', 'children': [], 'value': 'before_rms'}; {'id': '425', 'type': 'identifier', 'children': [], 'value': 'after_rms'}; {'id': '426', 'type': 'expression_statement', 'children': ['427']}; {'id': '427', 'type': 'augmented_assignment', 'children': ['428', '429'], 'value': '+='}; {'id': '428', 'type': 'identifier', 'children': [], 'value': 'atten'}; {'id': '429', 'type': 'identifier', 'children': [], 'value': 'attenuated'}; {'id': '430', 'type': 'return_statement', 'children': ['431']}; {'id': '431', 'type': 'expression_list', 'children': ['432', '433', '434']}; {'id': '432', 'type': 'identifier', 'children': [], 'value': 'total_signal'}; {'id': '433', 'type': 'identifier', 'children': [], 'value': 'atten'}; {'id': '434', 'type': 'identifier', 'children': [], 'value': 'undesired_attenuation'}
|
def signal(self, force_fs=False):
assert None not in self.voltage_limits, 'Max voltage level not set'
if force_fs:
samplerate = force_fs
else:
samplerate = self.samplerate()
track_signals = []
max_db = max([comp.intensity() for t in self._segments for comp in t])
atten = 0
for track in self._segments:
track_list = []
for component in track:
track_list.append(component.signal(fs=samplerate,
atten=0,
caldb=self.caldb,
calv=self.calv))
if len(track_list) > 0:
track_signals.append(np.hstack(track_list))
full_len = len(max(track_signals, key=len))
total_signal = np.zeros((full_len,))
for track in track_signals:
total_signal[0:len(track)] += track
component_names = list(set([comp.name for track in self._segments for comp in track]))
if 'silence' in component_names:
component_names.remove('silence')
if len(component_names) > 1 or (len(component_names) == 1 and component_names[0] != "Square Wave"):
total_signal = convolve_filter(total_signal, self.impulseResponse)
maxv = self.voltage_limits[0]
to_speaker = True
else:
maxv = self.voltage_limits[1]
to_speaker = False
total_signal[-1] = 0
undesired_attenuation = 0
minv = self.voltage_limits[2]
sig_max = np.max(abs(total_signal))
if sig_max > maxv:
total_signal = (total_signal/sig_max)*maxv
attenuated = 20 * np.log10(sig_max/maxv)
if attenuated <= atten:
atten = atten - attenuated
else:
undesired_attenuation = attenuated - atten
atten = 0
logger = logging.getLogger('main')
logger.warning("STIMULUS AMPLTIUDE {:.2f}V EXCEEDS MAXIMUM({}V), RESCALING. \
UNDESIRED ATTENUATION {:.2f}dB".format(sig_max, maxv, undesired_attenuation))
elif sig_max < minv and sig_max !=0 and to_speaker:
before_rms = np.sqrt(np.mean(pow(total_signal,2)))
total_signal = (total_signal/sig_max)*minv
after_rms = np.sqrt(np.mean(pow(total_signal,2)))
attenuated = -20 * np.log10(before_rms/after_rms)
atten += attenuated
return total_signal, atten, undesired_attenuation
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'verify'}; {'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': 'windowSize'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '20', '30', '35', '46', '78', '91', '96', '111', '120']}; {'id': '9', 'type': 'if_statement', 'children': ['10', '17']}; {'id': '10', 'type': 'comparison_operator', 'children': ['11', '16'], 'value': 'is'}; {'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': 'samplerate'}; {'id': '15', 'type': 'argument_list', 'children': []}; {'id': '16', 'type': 'None', 'children': []}; {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'return_statement', 'children': ['19']}; {'id': '19', 'type': 'string', 'children': [], 'value': '"Multiple recording files with conflicting samplerates"'}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}; {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'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': 'self'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': '_autoParams'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'verify'}; {'id': '29', 'type': 'argument_list', 'children': []}; {'id': '30', 'type': 'if_statement', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '32', 'type': 'block', 'children': ['33']}; {'id': '33', 'type': 'return_statement', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '35', 'type': 'if_statement', 'children': ['36', '43']}; {'id': '36', 'type': 'comparison_operator', 'children': ['37', '42'], 'value': '=='}; {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'traceCount'}; {'id': '41', 'type': 'argument_list', 'children': []}; {'id': '42', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '43', 'type': 'block', 'children': ['44']}; {'id': '44', 'type': 'return_statement', 'children': ['45']}; {'id': '45', 'type': 'string', 'children': [], 'value': '"Test is empty"'}; {'id': '46', 'type': 'if_statement', 'children': ['47', '50']}; {'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': 'is'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'windowSize'}; {'id': '49', 'type': 'None', 'children': []}; {'id': '50', 'type': 'block', 'children': ['51', '62']}; {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'durations'}; {'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': 'expandFunction'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}; {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'duration'}; {'id': '62', 'type': 'if_statement', 'children': ['63', '75']}; {'id': '63', 'type': 'boolean_operator', 'children': ['64', '69'], 'value': 'or'}; {'id': '64', 'type': 'comparison_operator', 'children': ['65', '68'], 'value': '>'}; {'id': '65', 'type': 'subscript', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'durations'}; {'id': '67', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'windowSize'}; {'id': '69', 'type': 'comparison_operator', 'children': ['70', '74'], 'value': '>'}; {'id': '70', 'type': 'subscript', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'durations'}; {'id': '72', 'type': 'unary_operator', 'children': ['73'], 'value': '-'}; {'id': '73', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'windowSize'}; {'id': '75', 'type': 'block', 'children': ['76']}; {'id': '76', 'type': 'return_statement', 'children': ['77']}; {'id': '77', 'type': 'string', 'children': [], 'value': '"Stimulus duration exceeds window duration"'}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}; {'id': '79', 'type': 'assignment', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '81', 'type': 'call', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'verifyExpanded'}; {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'call', 'children': ['87', '90']}; {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'samplerate'}; {'id': '90', 'type': 'argument_list', 'children': []}; {'id': '91', 'type': 'if_statement', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '93', 'type': 'block', 'children': ['94']}; {'id': '94', 'type': 'return_statement', 'children': ['95']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '96', 'type': 'if_statement', 'children': ['97', '108']}; {'id': '97', 'type': 'boolean_operator', 'children': ['98', '103'], 'value': 'or'}; {'id': '98', 'type': 'comparison_operator', 'children': ['99', '102'], 'value': 'is'}; {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'caldb'}; {'id': '102', 'type': 'None', 'children': []}; {'id': '103', 'type': 'comparison_operator', 'children': ['104', '107'], 'value': 'is'}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'calv'}; {'id': '107', 'type': 'None', 'children': []}; {'id': '108', 'type': 'block', 'children': ['109']}; {'id': '109', 'type': 'return_statement', 'children': ['110']}; {'id': '110', 'type': 'string', 'children': [], 'value': '"Test reference voltage not set"'}; {'id': '111', 'type': 'if_statement', 'children': ['112', '117']}; {'id': '112', 'type': 'comparison_operator', 'children': ['113', '114'], 'value': 'in'}; {'id': '113', 'type': 'None', 'children': []}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'voltage_limits'}; {'id': '117', 'type': 'block', 'children': ['118']}; {'id': '118', 'type': 'return_statement', 'children': ['119']}; {'id': '119', 'type': 'string', 'children': [], 'value': '"Device voltage limits not set"'}; {'id': '120', 'type': 'return_statement', 'children': ['121']}; {'id': '121', 'type': 'integer', 'children': [], 'value': '0'}
|
def verify(self, windowSize=None):
if self.samplerate() is None:
return "Multiple recording files with conflicting samplerates"
msg = self._autoParams.verify()
if msg:
return msg
if self.traceCount() == 0:
return "Test is empty"
if windowSize is not None:
durations = self.expandFunction(self.duration)
if durations[0] > windowSize or durations[-1] > windowSize:
return "Stimulus duration exceeds window duration"
msg = self.verifyExpanded(self.samplerate())
if msg:
return msg
if self.caldb is None or self.calv is None:
return "Test reference voltage not set"
if None in self.voltage_limits:
return "Device voltage limits not set"
return 0
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'getLogicalLines'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'fp'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'allowQP'}; {'id': '7', 'type': 'True', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'findBegin'}; {'id': '10', 'type': 'False', 'children': []}; {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'if_statement', 'children': ['13', '15', '69']}; {'id': '13', 'type': 'not_operator', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'allowQP'}; {'id': '15', 'type': 'block', 'children': ['16', '26', '30']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'fp'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'unary_operator', 'children': ['25'], 'value': '-'}; {'id': '25', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}; {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'lineNumber'}; {'id': '29', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '30', 'type': 'for_statement', 'children': ['31', '32', '38']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '32', 'type': 'call', 'children': ['33', '36']}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'logical_lines_re'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'finditer'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '38', 'type': 'block', 'children': ['39', '55', '65']}; {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '44']}; {'id': '41', 'type': 'pattern_list', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '44', 'type': 'call', 'children': ['45', '48']}; {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'wrap_re'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'subn'}; {'id': '48', 'type': 'argument_list', 'children': ['49', '50']}; {'id': '49', 'type': 'string', 'children': [], 'value': "''"}; {'id': '50', 'type': 'call', 'children': ['51', '54']}; {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '54', 'type': 'argument_list', 'children': []}; {'id': '55', 'type': 'if_statement', 'children': ['56', '59']}; {'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': '!='}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '58', 'type': 'string', 'children': [], 'value': "''"}; {'id': '59', 'type': 'block', 'children': ['60']}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}; {'id': '61', 'type': 'yield', 'children': ['62']}; {'id': '62', 'type': 'expression_list', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'lineNumber'}; {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'augmented_assignment', 'children': ['67', '68'], 'value': '+='}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'lineNumber'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '69', 'type': 'else_clause', 'children': ['70']}; {'id': '70', 'type': 'block', 'children': ['71', '75', '81', '87', '91', '95', '293']}; {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'quotedPrintable'}; {'id': '74', 'type': 'False', 'children': []}; {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'newbuffer'}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'StringIO'}; {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'logicalLine'}; {'id': '84', 'type': 'call', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'newbuffer'}; {'id': '86', 'type': 'argument_list', 'children': []}; {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'lineNumber'}; {'id': '90', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'lineStartNumber'}; {'id': '94', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '95', 'type': 'while_statement', 'children': ['96', '97']}; {'id': '96', 'type': 'True', 'children': []}; {'id': '97', 'type': 'block', 'children': ['98', '106', '127', '169', '260', '268']}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}; {'id': '99', 'type': 'assignment', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '101', 'type': 'call', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'fp'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'readline'}; {'id': '105', 'type': 'argument_list', 'children': []}; {'id': '106', 'type': 'if_statement', 'children': ['107', '110', '112']}; {'id': '107', 'type': 'comparison_operator', 'children': ['108', '109'], 'value': '=='}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '109', 'type': 'string', 'children': [], 'value': "''"}; {'id': '110', 'type': 'block', 'children': ['111']}; {'id': '111', 'type': 'break_statement', 'children': []}; {'id': '112', 'type': 'else_clause', 'children': ['113']}; {'id': '113', 'type': 'block', 'children': ['114', '123']}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}; {'id': '115', 'type': 'assignment', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '117', 'type': 'call', 'children': ['118', '121']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'rstrip'}; {'id': '121', 'type': 'argument_list', 'children': ['122']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'CRLF'}; {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'augmented_assignment', 'children': ['125', '126'], 'value': '+='}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'lineNumber'}; {'id': '126', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '127', 'type': 'if_statement', 'children': ['128', '135']}; {'id': '128', 'type': 'comparison_operator', 'children': ['129', '134'], 'value': '=='}; {'id': '129', 'type': 'call', 'children': ['130', '133']}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'rstrip'}; {'id': '133', 'type': 'argument_list', 'children': []}; {'id': '134', 'type': 'string', 'children': [], 'value': "''"}; {'id': '135', 'type': 'block', 'children': ['136', '154', '158', '164', '168']}; {'id': '136', 'type': 'if_statement', 'children': ['137', '144']}; {'id': '137', 'type': 'comparison_operator', 'children': ['138', '143'], 'value': '>'}; {'id': '138', 'type': 'call', 'children': ['139', '142']}; {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'logicalLine'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'tell'}; {'id': '142', 'type': 'argument_list', 'children': []}; {'id': '143', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '144', 'type': 'block', 'children': ['145']}; {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'yield', 'children': ['147']}; {'id': '147', 'type': 'expression_list', 'children': ['148', '153']}; {'id': '148', 'type': 'call', 'children': ['149', '152']}; {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'logicalLine'}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'getvalue'}; {'id': '152', 'type': 'argument_list', 'children': []}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'lineStartNumber'}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}; {'id': '155', 'type': 'assignment', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'lineStartNumber'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'lineNumber'}; {'id': '158', 'type': 'expression_statement', 'children': ['159']}; {'id': '159', 'type': 'assignment', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'logicalLine'}; {'id': '161', 'type': 'call', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'newbuffer'}; {'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': 'quotedPrintable'}; {'id': '167', 'type': 'False', 'children': []}; {'id': '168', 'type': 'continue_statement', 'children': []}; {'id': '169', 'type': 'if_statement', 'children': ['170', '173', '192', '210', '245']}; {'id': '170', 'type': 'boolean_operator', 'children': ['171', '172'], 'value': 'and'}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'quotedPrintable'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'allowQP'}; {'id': '173', 'type': 'block', 'children': ['174', '181', '188']}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}; {'id': '175', 'type': 'call', 'children': ['176', '179']}; {'id': '176', 'type': 'attribute', 'children': ['177', '178']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'logicalLine'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '179', 'type': 'argument_list', 'children': ['180']}; {'id': '180', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '181', 'type': 'expression_statement', 'children': ['182']}; {'id': '182', 'type': 'call', 'children': ['183', '186']}; {'id': '183', 'type': 'attribute', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'logicalLine'}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '186', 'type': 'argument_list', 'children': ['187']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '188', 'type': 'expression_statement', 'children': ['189']}; {'id': '189', 'type': 'assignment', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'quotedPrintable'}; {'id': '191', 'type': 'False', 'children': []}; {'id': '192', 'type': 'elif_clause', 'children': ['193', '198']}; {'id': '193', 'type': 'comparison_operator', 'children': ['194', '197'], 'value': 'in'}; {'id': '194', 'type': 'subscript', 'children': ['195', '196']}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '196', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'SPACEORTAB'}; {'id': '198', 'type': 'block', 'children': ['199']}; {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'call', 'children': ['201', '204']}; {'id': '201', 'type': 'attribute', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'logicalLine'}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '204', 'type': 'argument_list', 'children': ['205']}; {'id': '205', 'type': 'subscript', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '207', 'type': 'slice', 'children': ['208', '209']}; {'id': '208', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '209', 'type': 'colon', 'children': []}; {'id': '210', 'type': 'elif_clause', 'children': ['211', '218']}; {'id': '211', 'type': 'comparison_operator', 'children': ['212', '217'], 'value': '>'}; {'id': '212', 'type': 'call', 'children': ['213', '216']}; {'id': '213', 'type': 'attribute', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'logicalLine'}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'tell'}; {'id': '216', 'type': 'argument_list', 'children': []}; {'id': '217', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '218', 'type': 'block', 'children': ['219', '228', '232', '238']}; {'id': '219', 'type': 'expression_statement', 'children': ['220']}; {'id': '220', 'type': 'yield', 'children': ['221']}; {'id': '221', 'type': 'expression_list', 'children': ['222', '227']}; {'id': '222', 'type': 'call', 'children': ['223', '226']}; {'id': '223', 'type': 'attribute', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'logicalLine'}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'getvalue'}; {'id': '226', 'type': 'argument_list', 'children': []}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'lineStartNumber'}; {'id': '228', 'type': 'expression_statement', 'children': ['229']}; {'id': '229', 'type': 'assignment', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'lineStartNumber'}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'lineNumber'}; {'id': '232', 'type': 'expression_statement', 'children': ['233']}; {'id': '233', 'type': 'assignment', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'logicalLine'}; {'id': '235', 'type': 'call', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'newbuffer'}; {'id': '237', 'type': 'argument_list', 'children': []}; {'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': 'logicalLine'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '243', 'type': 'argument_list', 'children': ['244']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '245', 'type': 'else_clause', 'children': ['246']}; {'id': '246', 'type': 'block', 'children': ['247', '253']}; {'id': '247', 'type': 'expression_statement', 'children': ['248']}; {'id': '248', 'type': 'assignment', 'children': ['249', '250']}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'logicalLine'}; {'id': '250', 'type': 'call', 'children': ['251', '252']}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'newbuffer'}; {'id': '252', 'type': 'argument_list', 'children': []}; {'id': '253', 'type': 'expression_statement', 'children': ['254']}; {'id': '254', 'type': 'call', 'children': ['255', '258']}; {'id': '255', 'type': 'attribute', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'logicalLine'}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '258', 'type': 'argument_list', 'children': ['259']}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '260', 'type': 'expression_statement', 'children': ['261']}; {'id': '261', 'type': 'assignment', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '263', 'type': 'call', 'children': ['264', '267']}; {'id': '264', 'type': 'attribute', 'children': ['265', '266']}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'logicalLine'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'getvalue'}; {'id': '267', 'type': 'argument_list', 'children': []}; {'id': '268', 'type': 'if_statement', 'children': ['269', '288']}; {'id': '269', 'type': 'boolean_operator', 'children': ['270', '276'], 'value': 'and'}; {'id': '270', 'type': 'comparison_operator', 'children': ['271', '275'], 'value': '=='}; {'id': '271', 'type': 'subscript', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '273', 'type': 'unary_operator', 'children': ['274'], 'value': '-'}; {'id': '274', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '275', 'type': 'string', 'children': [], 'value': "'='"}; {'id': '276', 'type': 'comparison_operator', 'children': ['277', '287'], 'value': '>='}; {'id': '277', 'type': 'call', 'children': ['278', '285']}; {'id': '278', 'type': 'attribute', 'children': ['279', '284']}; {'id': '279', 'type': 'call', 'children': ['280', '283']}; {'id': '280', 'type': 'attribute', 'children': ['281', '282']}; {'id': '281', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '283', 'type': 'argument_list', 'children': []}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'find'}; {'id': '285', 'type': 'argument_list', 'children': ['286']}; {'id': '286', 'type': 'string', 'children': [], 'value': "'quoted-printable'"}; {'id': '287', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '288', 'type': 'block', 'children': ['289']}; {'id': '289', 'type': 'expression_statement', 'children': ['290']}; {'id': '290', 'type': 'assignment', 'children': ['291', '292']}; {'id': '291', 'type': 'identifier', 'children': [], 'value': 'quotedPrintable'}; {'id': '292', 'type': 'True', 'children': []}; {'id': '293', 'type': 'if_statement', 'children': ['294', '301']}; {'id': '294', 'type': 'comparison_operator', 'children': ['295', '300'], 'value': '>'}; {'id': '295', 'type': 'call', 'children': ['296', '299']}; {'id': '296', 'type': 'attribute', 'children': ['297', '298']}; {'id': '297', 'type': 'identifier', 'children': [], 'value': 'logicalLine'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'tell'}; {'id': '299', 'type': 'argument_list', 'children': []}; {'id': '300', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '301', 'type': 'block', 'children': ['302']}; {'id': '302', 'type': 'expression_statement', 'children': ['303']}; {'id': '303', 'type': 'yield', 'children': ['304']}; {'id': '304', 'type': 'expression_list', 'children': ['305', '310']}; {'id': '305', 'type': 'call', 'children': ['306', '309']}; {'id': '306', 'type': 'attribute', 'children': ['307', '308']}; {'id': '307', 'type': 'identifier', 'children': [], 'value': 'logicalLine'}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'getvalue'}; {'id': '309', 'type': 'argument_list', 'children': []}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'lineStartNumber'}
|
def getLogicalLines(fp, allowQP=True, findBegin=False):
if not allowQP:
val = fp.read(-1)
lineNumber = 1
for match in logical_lines_re.finditer(val):
line, n = wrap_re.subn('', match.group())
if line != '':
yield line, lineNumber
lineNumber += n
else:
quotedPrintable = False
newbuffer = six.StringIO
logicalLine = newbuffer()
lineNumber = 0
lineStartNumber = 0
while True:
line = fp.readline()
if line == '':
break
else:
line = line.rstrip(CRLF)
lineNumber += 1
if line.rstrip() == '':
if logicalLine.tell() > 0:
yield logicalLine.getvalue(), lineStartNumber
lineStartNumber = lineNumber
logicalLine = newbuffer()
quotedPrintable = False
continue
if quotedPrintable and allowQP:
logicalLine.write('\n')
logicalLine.write(line)
quotedPrintable = False
elif line[0] in SPACEORTAB:
logicalLine.write(line[1:])
elif logicalLine.tell() > 0:
yield logicalLine.getvalue(), lineStartNumber
lineStartNumber = lineNumber
logicalLine = newbuffer()
logicalLine.write(line)
else:
logicalLine = newbuffer()
logicalLine.write(line)
val = logicalLine.getvalue()
if val[-1]=='=' and val.lower().find('quoted-printable') >= 0:
quotedPrintable=True
if logicalLine.tell() > 0:
yield logicalLine.getvalue(), lineStartNumber
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_bind_model'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '51', '69', '79', '85', '89', '178']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '16']}; {'id': '7', 'type': 'comparison_operator', 'children': ['8', '15'], 'value': '!='}; {'id': '8', 'type': 'attribute', 'children': ['9', '14']}; {'id': '9', 'type': 'subscript', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'groups'}; {'id': '13', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '15', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '16', 'type': 'block', 'children': ['17', '35']}; {'id': '17', 'type': 'expression_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': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}; {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'string', 'children': [], 'value': '"Got invalid first group: {0}"'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'subscript', 'children': ['31', '34']}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'groups'}; {'id': '34', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '35', 'type': 'raise_statement', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}; {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}; {'id': '41', 'type': 'string', 'children': [], 'value': '"Invalid group tree: first group must have level of 0 (got {0})"'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'attribute', 'children': ['45', '50']}; {'id': '45', 'type': 'subscript', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'groups'}; {'id': '49', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '51', 'type': 'class_definition', 'children': ['52', '53', '55']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'Stack'}; {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '55', 'type': 'block', 'children': ['56']}; {'id': '56', 'type': 'function_definition', 'children': ['57', '58', '61']}; {'id': '57', 'type': 'function_name', 'children': [], 'value': 'push'}; {'id': '58', 'type': 'parameters', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'el'}; {'id': '61', 'type': 'block', 'children': ['62']}; {'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': 'append'}; {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'el'}; {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'parent_stack'}; {'id': '72', 'type': 'call', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'Stack'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}; {'id': '75', 'type': 'list', 'children': ['76'], 'value': '[self.root]'}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'current_parent'}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'prev_group'}; {'id': '88', 'type': 'None', 'children': []}; {'id': '89', 'type': 'for_statement', 'children': ['90', '91', '94']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'groups'}; {'id': '94', 'type': 'block', 'children': ['95', '101', '159', '165', '174']}; {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '100']}; {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'db'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '101', 'type': 'if_statement', 'children': ['102', '105']}; {'id': '102', 'type': 'comparison_operator', 'children': ['103', '104'], 'value': 'is'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'prev_group'}; {'id': '104', 'type': 'None', 'children': []}; {'id': '105', 'type': 'block', 'children': ['106']}; {'id': '106', 'type': 'if_statement', 'children': ['107', '114', '126']}; {'id': '107', 'type': 'comparison_operator', 'children': ['108', '111'], 'value': '>'}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'prev_group'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '114', 'type': 'block', 'children': ['115', '119']}; {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'current_parent'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'prev_group'}; {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'call', 'children': ['121', '124']}; {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'parent_stack'}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'push'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'current_parent'}; {'id': '126', 'type': 'elif_clause', 'children': ['127', '134']}; {'id': '127', 'type': 'comparison_operator', 'children': ['128', '131'], 'value': '<'}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'prev_group'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '134', 'type': 'block', 'children': ['135', '152']}; {'id': '135', 'type': 'while_statement', 'children': ['136', '143']}; {'id': '136', 'type': 'comparison_operator', 'children': ['137', '140'], 'value': '<='}; {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'current_parent'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '143', 'type': 'block', 'children': ['144']}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}; {'id': '145', 'type': 'assignment', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'current_parent'}; {'id': '147', 'type': 'call', 'children': ['148', '151']}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'parent_stack'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'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': 'parent_stack'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'push'}; {'id': '157', 'type': 'argument_list', 'children': ['158']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'current_parent'}; {'id': '159', 'type': 'expression_statement', 'children': ['160']}; {'id': '160', 'type': 'assignment', 'children': ['161', '164']}; {'id': '161', 'type': 'attribute', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'current_parent'}; {'id': '165', 'type': 'expression_statement', 'children': ['166']}; {'id': '166', 'type': 'call', 'children': ['167', '172']}; {'id': '167', 'type': 'attribute', 'children': ['168', '171']}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'current_parent'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'children'}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '172', 'type': 'argument_list', 'children': ['173']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}; {'id': '175', 'type': 'assignment', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'prev_group'}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '178', 'type': 'for_statement', 'children': ['179', '180', '183']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '180', 'type': 'attribute', 'children': ['181', '182']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'entries'}; {'id': '183', 'type': 'block', 'children': ['184']}; {'id': '184', 'type': 'for_statement', 'children': ['185', '186', '189', '215']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'groups'}; {'id': '189', 'type': 'block', 'children': ['190']}; {'id': '190', 'type': 'if_statement', 'children': ['191', '198']}; {'id': '191', 'type': 'comparison_operator', 'children': ['192', '195'], 'value': '=='}; {'id': '192', 'type': 'attribute', 'children': ['193', '194']}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'group_id'}; {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '198', 'type': 'block', 'children': ['199', '208', '214']}; {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'call', 'children': ['201', '206']}; {'id': '201', 'type': 'attribute', 'children': ['202', '205']}; {'id': '202', 'type': 'attribute', 'children': ['203', '204']}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'entries'}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '206', 'type': 'argument_list', 'children': ['207']}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '208', 'type': 'expression_statement', 'children': ['209']}; {'id': '209', 'type': 'assignment', 'children': ['210', '213']}; {'id': '210', 'type': 'attribute', 'children': ['211', '212']}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '214', 'type': 'break_statement', 'children': []}; {'id': '215', 'type': 'else_clause', 'children': ['216']}; {'id': '216', 'type': 'block', 'children': ['217']}; {'id': '217', 'type': 'raise_statement', 'children': ['218']}; {'id': '218', 'type': 'call', 'children': ['219', '220']}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'NotImplementedError'}; {'id': '220', 'type': 'argument_list', 'children': ['221']}; {'id': '221', 'type': 'string', 'children': [], 'value': '"Orphaned entries not (yet) supported."'}
|
def _bind_model(self):
if self.groups[0].level != 0:
self.log.info("Got invalid first group: {0}".format(self.groups[0]))
raise ValueError("Invalid group tree: first group must have level of 0 (got {0})".format(self.groups[0].level))
class Stack(list):
def push(self, el):
self.append(el)
parent_stack = Stack([self.root])
current_parent = self.root
prev_group = None
for g in self.groups:
g.db = self
if prev_group is not None:
if g.level > prev_group.level:
current_parent = prev_group
parent_stack.push(current_parent)
elif g.level < prev_group.level:
while g.level <= current_parent.level:
current_parent = parent_stack.pop()
parent_stack.push(current_parent)
g.parent = current_parent
current_parent.children.append(g)
prev_group = g
for entry in self.entries:
for group in self.groups:
if entry.group_id == group.id:
group.entries.append(entry)
entry.group = group
break
else:
raise NotImplementedError("Orphaned entries not (yet) supported.")
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'bowtie'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '42', '460']}; {'id': '6', 'type': 'for_statement', 'children': ['7', '8', '14']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '8', 'type': 'call', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '10', 'type': 'argument_list', 'children': ['11']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'cpus'}; {'id': '14', 'type': 'block', 'children': ['15', '29', '36']}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'threads'}; {'id': '18', 'type': 'call', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'Thread'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '26']}; {'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'align'}; {'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '28', 'type': 'tuple', 'children': []}; {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '34']}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'threads'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'setDaemon'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}; {'id': '35', 'type': 'True', 'children': []}; {'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': 'threads'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '41', 'type': 'argument_list', 'children': []}; {'id': '42', 'type': 'with_statement', 'children': ['43', '54']}; {'id': '43', 'type': 'with_clause', 'children': ['44']}; {'id': '44', 'type': 'with_item', 'children': ['45']}; {'id': '45', 'type': 'as_pattern', 'children': ['46', '52']}; {'id': '46', 'type': 'call', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'progressbar'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}; {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'metadata'}; {'id': '52', 'type': 'as_pattern_target', 'children': ['53']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'bar'}; {'id': '54', 'type': 'block', 'children': ['55']}; {'id': '55', 'type': 'for_statement', 'children': ['56', '57', '58']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'bar'}; {'id': '58', 'type': 'block', 'children': ['59', '67', '73']}; {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '64']}; {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'mapping'}; {'id': '64', 'type': 'call', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'GenObject'}; {'id': '66', 'type': 'argument_list', 'children': []}; {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'sagen'}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'general'}; {'id': '73', 'type': 'if_statement', 'children': ['74', '79', '434']}; {'id': '74', 'type': 'comparison_operator', 'children': ['75', '78'], 'value': '!='}; {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'sagen'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'bestassemblyfile'}; {'id': '78', 'type': 'string', 'children': [], 'value': '"NA"'}; {'id': '79', 'type': 'block', 'children': ['80', '96', '103', '126', '141', '147', '165', '181', '193', '212', '229', '248', '371', '392', '403', '414']}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}; {'id': '81', 'type': 'assignment', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'sagen'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'QualimapResults'}; {'id': '85', 'type': 'call', 'children': ['86', '91']}; {'id': '86', 'type': 'attribute', 'children': ['87', '90']}; {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '91', 'type': 'argument_list', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'sagen'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'outputdirectory'}; {'id': '95', 'type': 'string', 'children': [], 'value': "'qualimap_results'"}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}; {'id': '97', 'type': 'call', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'make_path'}; {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'sagen'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'QualimapResults'}; {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '108']}; {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'sagen'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'sortedbam'}; {'id': '108', 'type': 'call', 'children': ['109', '114']}; {'id': '109', 'type': 'attribute', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '114', 'type': 'argument_list', 'children': ['115', '118']}; {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'sagen'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'QualimapResults'}; {'id': '118', 'type': 'call', 'children': ['119', '122']}; {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'string', 'children': [], 'value': "'{}_sorted.bam'"}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}; {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}; {'id': '127', 'type': 'assignment', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'filenoext'}; {'id': '129', 'type': 'subscript', 'children': ['130', '140']}; {'id': '130', 'type': 'call', 'children': ['131', '136']}; {'id': '131', 'type': 'attribute', 'children': ['132', '135']}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'splitext'}; {'id': '136', 'type': 'argument_list', 'children': ['137']}; {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'sagen'}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'filteredfile'}; {'id': '140', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'assignment', 'children': ['143', '146']}; {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'sagen'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'filenoext'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'filenoext'}; {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'assignment', 'children': ['149', '152']}; {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'sagen'}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'bowtie2results'}; {'id': '152', 'type': 'call', 'children': ['153', '158']}; {'id': '153', 'type': 'attribute', 'children': ['154', '157']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '158', 'type': 'argument_list', 'children': ['159', '162']}; {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'sagen'}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'QualimapResults'}; {'id': '162', 'type': 'attribute', 'children': ['163', '164']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '165', 'type': 'expression_statement', 'children': ['166']}; {'id': '166', 'type': 'assignment', 'children': ['167', '168']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'bowtie2build'}; {'id': '168', 'type': 'call', 'children': ['169', '170']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'Bowtie2BuildCommandLine'}; {'id': '170', 'type': 'argument_list', 'children': ['171', '176']}; {'id': '171', 'type': 'keyword_argument', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'reference'}; {'id': '173', 'type': 'attribute', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'sagen'}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'bestassemblyfile'}; {'id': '176', 'type': 'keyword_argument', 'children': ['177', '178']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'bt2'}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'sagen'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'bowtie2results'}; {'id': '181', 'type': 'expression_statement', 'children': ['182']}; {'id': '182', 'type': 'assignment', 'children': ['183', '188']}; {'id': '183', 'type': 'attribute', 'children': ['184', '187']}; {'id': '184', 'type': 'attribute', 'children': ['185', '186']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'mapping'}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'BamFile'}; {'id': '188', 'type': 'binary_operator', 'children': ['189', '192'], 'value': '+'}; {'id': '189', 'type': 'attribute', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'sagen'}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'bowtie2results'}; {'id': '192', 'type': 'string', 'children': [], 'value': '"_sorted.bam"'}; {'id': '193', 'type': 'expression_statement', 'children': ['194']}; {'id': '194', 'type': 'assignment', 'children': ['195', '196']}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'samsort'}; {'id': '196', 'type': 'call', 'children': ['197', '198']}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'SamtoolsSortCommandline'}; {'id': '198', 'type': 'argument_list', 'children': ['199', '206', '209']}; {'id': '199', 'type': 'keyword_argument', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'input'}; {'id': '201', 'type': 'attribute', 'children': ['202', '205']}; {'id': '202', 'type': 'attribute', 'children': ['203', '204']}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'mapping'}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'BamFile'}; {'id': '206', 'type': 'keyword_argument', 'children': ['207', '208']}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '208', 'type': 'True', 'children': []}; {'id': '209', 'type': 'keyword_argument', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'out_prefix'}; {'id': '211', 'type': 'string', 'children': [], 'value': '"-"'}; {'id': '212', 'type': 'expression_statement', 'children': ['213']}; {'id': '213', 'type': 'assignment', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'samtools'}; {'id': '215', 'type': 'list', 'children': ['216', '228'], 'value': '[SamtoolsViewCommandline(b=True, S=True, input_file="-"), samsort]'}; {'id': '216', 'type': 'call', 'children': ['217', '218']}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'SamtoolsViewCommandline'}; {'id': '218', 'type': 'argument_list', 'children': ['219', '222', '225']}; {'id': '219', 'type': 'keyword_argument', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '221', 'type': 'True', 'children': []}; {'id': '222', 'type': 'keyword_argument', 'children': ['223', '224']}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'S'}; {'id': '224', 'type': 'True', 'children': []}; {'id': '225', 'type': 'keyword_argument', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'input_file'}; {'id': '227', 'type': 'string', 'children': [], 'value': '"-"'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'samsort'}; {'id': '229', 'type': 'expression_statement', 'children': ['230']}; {'id': '230', 'type': 'assignment', 'children': ['231', '232']}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'indict'}; {'id': '232', 'type': 'dictionary', 'children': ['233', '236', '239', '242', '245']}; {'id': '233', 'type': 'pair', 'children': ['234', '235']}; {'id': '234', 'type': 'string', 'children': [], 'value': "'D'"}; {'id': '235', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '236', 'type': 'pair', 'children': ['237', '238']}; {'id': '237', 'type': 'string', 'children': [], 'value': "'R'"}; {'id': '238', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '239', 'type': 'pair', 'children': ['240', '241']}; {'id': '240', 'type': 'string', 'children': [], 'value': "'num_mismatches'"}; {'id': '241', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '242', 'type': 'pair', 'children': ['243', '244']}; {'id': '243', 'type': 'string', 'children': [], 'value': "'seed_length'"}; {'id': '244', 'type': 'integer', 'children': [], 'value': '22'}; {'id': '245', 'type': 'pair', 'children': ['246', '247']}; {'id': '246', 'type': 'string', 'children': [], 'value': "'i_func'"}; {'id': '247', 'type': 'string', 'children': [], 'value': '"S,0,2.50"'}; {'id': '248', 'type': 'try_statement', 'children': ['249', '313']}; {'id': '249', 'type': 'block', 'children': ['250', '258']}; {'id': '250', 'type': 'expression_statement', 'children': ['251']}; {'id': '251', 'type': 'assignment', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '253', 'type': 'attribute', 'children': ['254', '257']}; {'id': '254', 'type': 'attribute', 'children': ['255', '256']}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'general'}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'mergedreads'}; {'id': '258', 'type': 'if_statement', 'children': ['259', '269', '295']}; {'id': '259', 'type': 'comparison_operator', 'children': ['260', '268'], 'value': '=='}; {'id': '260', 'type': 'call', 'children': ['261', '262']}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '262', 'type': 'argument_list', 'children': ['263']}; {'id': '263', 'type': 'attribute', 'children': ['264', '267']}; {'id': '264', 'type': 'attribute', 'children': ['265', '266']}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'general'}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'trimmedcorrectedfastqfiles'}; {'id': '268', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '269', 'type': 'block', 'children': ['270']}; {'id': '270', 'type': 'expression_statement', 'children': ['271']}; {'id': '271', 'type': 'call', 'children': ['272', '275']}; {'id': '272', 'type': 'attribute', 'children': ['273', '274']}; {'id': '273', 'type': 'identifier', 'children': [], 'value': 'indict'}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '275', 'type': 'argument_list', 'children': ['276']}; {'id': '276', 'type': 'dictionary', 'children': ['277', '286']}; {'id': '277', 'type': 'pair', 'children': ['278', '279']}; {'id': '278', 'type': 'string', 'children': [], 'value': "'m1'"}; {'id': '279', 'type': 'subscript', 'children': ['280', '285']}; {'id': '280', 'type': 'attribute', 'children': ['281', '284']}; {'id': '281', 'type': 'attribute', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '283', 'type': 'identifier', 'children': [], 'value': 'general'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'trimmedcorrectedfastqfiles'}; {'id': '285', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '286', 'type': 'pair', 'children': ['287', '288']}; {'id': '287', 'type': 'string', 'children': [], 'value': "'m2'"}; {'id': '288', 'type': 'subscript', 'children': ['289', '294']}; {'id': '289', 'type': 'attribute', 'children': ['290', '293']}; {'id': '290', 'type': 'attribute', 'children': ['291', '292']}; {'id': '291', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'general'}; {'id': '293', 'type': 'identifier', 'children': [], 'value': 'trimmedcorrectedfastqfiles'}; {'id': '294', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '295', 'type': 'else_clause', 'children': ['296']}; {'id': '296', 'type': 'block', 'children': ['297']}; {'id': '297', 'type': 'expression_statement', 'children': ['298']}; {'id': '298', 'type': 'call', 'children': ['299', '302']}; {'id': '299', 'type': 'attribute', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'indict'}; {'id': '301', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '302', 'type': 'argument_list', 'children': ['303']}; {'id': '303', 'type': 'dictionary', 'children': ['304']}; {'id': '304', 'type': 'pair', 'children': ['305', '306']}; {'id': '305', 'type': 'string', 'children': [], 'value': "'U'"}; {'id': '306', 'type': 'subscript', 'children': ['307', '312']}; {'id': '307', 'type': 'attribute', 'children': ['308', '311']}; {'id': '308', 'type': 'attribute', 'children': ['309', '310']}; {'id': '309', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'general'}; {'id': '311', 'type': 'identifier', 'children': [], 'value': 'trimmedcorrectedfastqfiles'}; {'id': '312', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '313', 'type': 'except_clause', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}; {'id': '315', 'type': 'block', 'children': ['316']}; {'id': '316', 'type': 'if_statement', 'children': ['317', '327', '353']}; {'id': '317', 'type': 'comparison_operator', 'children': ['318', '326'], 'value': '=='}; {'id': '318', 'type': 'call', 'children': ['319', '320']}; {'id': '319', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '320', 'type': 'argument_list', 'children': ['321']}; {'id': '321', 'type': 'attribute', 'children': ['322', '325']}; {'id': '322', 'type': 'attribute', 'children': ['323', '324']}; {'id': '323', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'general'}; {'id': '325', 'type': 'identifier', 'children': [], 'value': 'assemblyfastq'}; {'id': '326', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '327', 'type': 'block', 'children': ['328']}; {'id': '328', 'type': 'expression_statement', 'children': ['329']}; {'id': '329', 'type': 'call', 'children': ['330', '333']}; {'id': '330', 'type': 'attribute', 'children': ['331', '332']}; {'id': '331', 'type': 'identifier', 'children': [], 'value': 'indict'}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '333', 'type': 'argument_list', 'children': ['334']}; {'id': '334', 'type': 'dictionary', 'children': ['335', '344']}; {'id': '335', 'type': 'pair', 'children': ['336', '337']}; {'id': '336', 'type': 'string', 'children': [], 'value': "'m1'"}; {'id': '337', 'type': 'subscript', 'children': ['338', '343']}; {'id': '338', 'type': 'attribute', 'children': ['339', '342']}; {'id': '339', 'type': 'attribute', 'children': ['340', '341']}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '341', 'type': 'identifier', 'children': [], 'value': 'general'}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'assemblyfastq'}; {'id': '343', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '344', 'type': 'pair', 'children': ['345', '346']}; {'id': '345', 'type': 'string', 'children': [], 'value': "'m2'"}; {'id': '346', 'type': 'subscript', 'children': ['347', '352']}; {'id': '347', 'type': 'attribute', 'children': ['348', '351']}; {'id': '348', 'type': 'attribute', 'children': ['349', '350']}; {'id': '349', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'general'}; {'id': '351', 'type': 'identifier', 'children': [], 'value': 'assemblyfastq'}; {'id': '352', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '353', 'type': 'else_clause', 'children': ['354']}; {'id': '354', 'type': 'block', 'children': ['355']}; {'id': '355', 'type': 'expression_statement', 'children': ['356']}; {'id': '356', 'type': 'call', 'children': ['357', '360']}; {'id': '357', 'type': 'attribute', 'children': ['358', '359']}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'indict'}; {'id': '359', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '360', 'type': 'argument_list', 'children': ['361']}; {'id': '361', 'type': 'dictionary', 'children': ['362']}; {'id': '362', 'type': 'pair', 'children': ['363', '364']}; {'id': '363', 'type': 'string', 'children': [], 'value': "'U'"}; {'id': '364', 'type': 'subscript', 'children': ['365', '370']}; {'id': '365', 'type': 'attribute', 'children': ['366', '369']}; {'id': '366', 'type': 'attribute', 'children': ['367', '368']}; {'id': '367', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'general'}; {'id': '369', 'type': 'identifier', 'children': [], 'value': 'assemblyfastq'}; {'id': '370', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '371', 'type': 'expression_statement', 'children': ['372']}; {'id': '372', 'type': 'assignment', 'children': ['373', '374']}; {'id': '373', 'type': 'identifier', 'children': [], 'value': 'bowtie2align'}; {'id': '374', 'type': 'call', 'children': ['375', '376']}; {'id': '375', 'type': 'identifier', 'children': [], 'value': 'Bowtie2CommandLine'}; {'id': '376', 'type': 'argument_list', 'children': ['377', '382', '387', '390']}; {'id': '377', 'type': 'keyword_argument', 'children': ['378', '379']}; {'id': '378', 'type': 'identifier', 'children': [], 'value': 'bt2'}; {'id': '379', 'type': 'attribute', 'children': ['380', '381']}; {'id': '380', 'type': 'identifier', 'children': [], 'value': 'sagen'}; {'id': '381', 'type': 'identifier', 'children': [], 'value': 'bowtie2results'}; {'id': '382', 'type': 'keyword_argument', 'children': ['383', '384']}; {'id': '383', 'type': 'identifier', 'children': [], 'value': 'threads'}; {'id': '384', 'type': 'attribute', 'children': ['385', '386']}; {'id': '385', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '386', 'type': 'identifier', 'children': [], 'value': 'threads'}; {'id': '387', 'type': 'keyword_argument', 'children': ['388', '389']}; {'id': '388', 'type': 'identifier', 'children': [], 'value': 'samtools'}; {'id': '389', 'type': 'identifier', 'children': [], 'value': 'samtools'}; {'id': '390', 'type': 'dictionary_splat', 'children': ['391']}; {'id': '391', 'type': 'identifier', 'children': [], 'value': 'indict'}; {'id': '392', 'type': 'expression_statement', 'children': ['393']}; {'id': '393', 'type': 'assignment', 'children': ['394', '399']}; {'id': '394', 'type': 'attribute', 'children': ['395', '398']}; {'id': '395', 'type': 'attribute', 'children': ['396', '397']}; {'id': '396', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '397', 'type': 'identifier', 'children': [], 'value': 'commands'}; {'id': '398', 'type': 'identifier', 'children': [], 'value': 'bowtie2align'}; {'id': '399', 'type': 'call', 'children': ['400', '401']}; {'id': '400', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '401', 'type': 'argument_list', 'children': ['402']}; {'id': '402', 'type': 'identifier', 'children': [], 'value': 'bowtie2align'}; {'id': '403', 'type': 'expression_statement', 'children': ['404']}; {'id': '404', 'type': 'assignment', 'children': ['405', '410']}; {'id': '405', 'type': 'attribute', 'children': ['406', '409']}; {'id': '406', 'type': 'attribute', 'children': ['407', '408']}; {'id': '407', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '408', 'type': 'identifier', 'children': [], 'value': 'commands'}; {'id': '409', 'type': 'identifier', 'children': [], 'value': 'bowtie2build'}; {'id': '410', 'type': 'call', 'children': ['411', '412']}; {'id': '411', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '412', 'type': 'argument_list', 'children': ['413']}; {'id': '413', 'type': 'identifier', 'children': [], 'value': 'bowtie2build'}; {'id': '414', 'type': 'expression_statement', 'children': ['415']}; {'id': '415', 'type': 'call', 'children': ['416', '421']}; {'id': '416', 'type': 'attribute', 'children': ['417', '420']}; {'id': '417', 'type': 'attribute', 'children': ['418', '419']}; {'id': '418', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '419', 'type': 'identifier', 'children': [], 'value': 'bowqueue'}; {'id': '420', 'type': 'identifier', 'children': [], 'value': 'put'}; {'id': '421', 'type': 'argument_list', 'children': ['422']}; {'id': '422', 'type': 'tuple', 'children': ['423', '424', '429']}; {'id': '423', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '424', 'type': 'attribute', 'children': ['425', '428']}; {'id': '425', 'type': 'attribute', 'children': ['426', '427']}; {'id': '426', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '427', 'type': 'identifier', 'children': [], 'value': 'commands'}; {'id': '428', 'type': 'identifier', 'children': [], 'value': 'bowtie2build'}; {'id': '429', 'type': 'attribute', 'children': ['430', '433']}; {'id': '430', 'type': 'attribute', 'children': ['431', '432']}; {'id': '431', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '432', 'type': 'identifier', 'children': [], 'value': 'commands'}; {'id': '433', 'type': 'identifier', 'children': [], 'value': 'bowtie2align'}; {'id': '434', 'type': 'else_clause', 'children': ['435']}; {'id': '435', 'type': 'block', 'children': ['436', '444', '452']}; {'id': '436', 'type': 'expression_statement', 'children': ['437']}; {'id': '437', 'type': 'assignment', 'children': ['438', '443']}; {'id': '438', 'type': 'attribute', 'children': ['439', '442']}; {'id': '439', 'type': 'attribute', 'children': ['440', '441']}; {'id': '440', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '441', 'type': 'identifier', 'children': [], 'value': 'commands'}; {'id': '442', 'type': 'identifier', 'children': [], 'value': 'samtools'}; {'id': '443', 'type': 'string', 'children': [], 'value': '"NA"'}; {'id': '444', 'type': 'expression_statement', 'children': ['445']}; {'id': '445', 'type': 'assignment', 'children': ['446', '451']}; {'id': '446', 'type': 'attribute', 'children': ['447', '450']}; {'id': '447', 'type': 'attribute', 'children': ['448', '449']}; {'id': '448', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '449', 'type': 'identifier', 'children': [], 'value': 'mapping'}; {'id': '450', 'type': 'identifier', 'children': [], 'value': 'MeanInsertSize'}; {'id': '451', 'type': 'string', 'children': [], 'value': "'NA'"}; {'id': '452', 'type': 'expression_statement', 'children': ['453']}; {'id': '453', 'type': 'assignment', 'children': ['454', '459']}; {'id': '454', 'type': 'attribute', 'children': ['455', '458']}; {'id': '455', 'type': 'attribute', 'children': ['456', '457']}; {'id': '456', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '457', 'type': 'identifier', 'children': [], 'value': 'mapping'}; {'id': '458', 'type': 'identifier', 'children': [], 'value': 'MeanCoveragedata'}; {'id': '459', 'type': 'string', 'children': [], 'value': "'NA'"}; {'id': '460', 'type': 'expression_statement', 'children': ['461']}; {'id': '461', 'type': 'call', 'children': ['462', '467']}; {'id': '462', 'type': 'attribute', 'children': ['463', '466']}; {'id': '463', 'type': 'attribute', 'children': ['464', '465']}; {'id': '464', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '465', 'type': 'identifier', 'children': [], 'value': 'bowqueue'}; {'id': '466', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '467', 'type': 'argument_list', 'children': []}
|
def bowtie(self):
for i in range(self.cpus):
threads = Thread(target=self.align, args=())
threads.setDaemon(True)
threads.start()
with progressbar(self.metadata) as bar:
for sample in bar:
sample.mapping = GenObject()
sagen = sample.general
if sagen.bestassemblyfile != "NA":
sagen.QualimapResults = os.path.join(sagen.outputdirectory, 'qualimap_results')
make_path(sagen.QualimapResults)
sagen.sortedbam = os.path.join(sagen.QualimapResults, '{}_sorted.bam'.format(sample.name))
filenoext = os.path.splitext(sagen.filteredfile)[0]
sagen.filenoext = filenoext
sagen.bowtie2results = os.path.join(sagen.QualimapResults, sample.name)
bowtie2build = Bowtie2BuildCommandLine(reference=sagen.bestassemblyfile,
bt2=sagen.bowtie2results)
sample.mapping.BamFile = sagen.bowtie2results + "_sorted.bam"
samsort = SamtoolsSortCommandline(input=sample.mapping.BamFile,
o=True,
out_prefix="-")
samtools = [SamtoolsViewCommandline(b=True, S=True, input_file="-"), samsort]
indict = {'D': 5, 'R': 1, 'num_mismatches': 0, 'seed_length': 22, 'i_func': "S,0,2.50"}
try:
_ = sample.general.mergedreads
if len(sample.general.trimmedcorrectedfastqfiles) == 2:
indict.update({'m1': sample.general.trimmedcorrectedfastqfiles[0],
'm2': sample.general.trimmedcorrectedfastqfiles[1]})
else:
indict.update({'U': sample.general.trimmedcorrectedfastqfiles[0]})
except AttributeError:
if len(sample.general.assemblyfastq) == 2:
indict.update({'m1': sample.general.assemblyfastq[0],
'm2': sample.general.assemblyfastq[1]})
else:
indict.update({'U': sample.general.assemblyfastq[0]})
bowtie2align = Bowtie2CommandLine(bt2=sagen.bowtie2results,
threads=self.threads,
samtools=samtools,
**indict)
sample.commands.bowtie2align = str(bowtie2align)
sample.commands.bowtie2build = str(bowtie2build)
self.bowqueue.put((sample, sample.commands.bowtie2build, sample.commands.bowtie2align))
else:
sample.commands.samtools = "NA"
sample.mapping.MeanInsertSize = 'NA'
sample.mapping.MeanCoveragedata = 'NA'
self.bowqueue.join()
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'validate_pages_json_data'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'preferred_lang'}; {'id': '6', 'type': 'block', 'children': ['7', '14', '18', '36', '52', '61', '83', '89', '370']}; {'id': '7', 'type': 'import_from_statement', 'children': ['8', '12']}; {'id': '8', 'type': 'relative_import', 'children': ['9', '10']}; {'id': '9', 'type': 'import_prefix', 'children': []}; {'id': '10', 'type': 'dotted_name', 'children': ['11']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'models'}; {'id': '12', 'type': 'dotted_name', 'children': ['13']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'Page'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '17', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'seen_complete_slugs'}; {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '23', 'type': 'generator_expression', 'children': ['24', '31']}; {'id': '24', 'type': 'tuple', 'children': ['25', '28']}; {'id': '25', 'type': 'subscript', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'lang'}; {'id': '27', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '28', 'type': 'call', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '30', 'type': 'argument_list', 'children': []}; {'id': '31', 'type': 'for_in_clause', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'lang'}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'settings'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'PAGE_LANGUAGES'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}; {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'valid_templates'}; {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '41', 'type': 'generator_expression', 'children': ['42', '45']}; {'id': '42', 'type': 'subscript', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '44', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '45', 'type': 'for_in_clause', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'settings'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'get_page_templates'}; {'id': '51', 'type': 'argument_list', 'children': []}; {'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': 'valid_templates'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'settings'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'PAGE_DEFAULT_TEMPLATE'}; {'id': '61', 'type': 'if_statement', 'children': ['62', '67']}; {'id': '62', 'type': 'comparison_operator', 'children': ['63', '66'], 'value': '!='}; {'id': '63', 'type': 'subscript', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'JSON_PAGE_EXPORT_NAME'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'JSON_PAGE_EXPORT_VERSION'}; {'id': '67', 'type': 'block', 'children': ['68']}; {'id': '68', 'type': 'return_statement', 'children': ['69']}; {'id': '69', 'type': 'expression_list', 'children': ['70', '82']}; {'id': '70', 'type': 'list', 'children': ['71'], 'value': "[_('Unsupported file version: %s') % repr(\n d[JSON_PAGE_EXPORT_NAME])]"}; {'id': '71', 'type': 'binary_operator', 'children': ['72', '76'], 'value': '%'}; {'id': '72', 'type': 'call', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}; {'id': '75', 'type': 'string', 'children': [], 'value': "'Unsupported file version: %s'"}; {'id': '76', 'type': 'call', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'repr'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}; {'id': '79', 'type': 'subscript', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'JSON_PAGE_EXPORT_NAME'}; {'id': '82', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'pages'}; {'id': '86', 'type': 'subscript', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '88', 'type': 'string', 'children': [], 'value': "'pages'"}; {'id': '89', 'type': 'for_statement', 'children': ['90', '91', '92']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'pages'}; {'id': '92', 'type': 'block', 'children': ['93', '105', '109', '213', '239', '258', '282', '295', '308', '333', '346']}; {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'slug'}; {'id': '96', 'type': 'call', 'children': ['97', '102']}; {'id': '97', 'type': 'attribute', 'children': ['98', '101']}; {'id': '98', 'type': 'subscript', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '100', 'type': 'string', 'children': [], 'value': "'complete_slug'"}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '102', 'type': 'argument_list', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'preferred_lang'}; {'id': '104', 'type': 'None', 'children': []}; {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'seen_parent'}; {'id': '108', 'type': 'False', 'children': []}; {'id': '109', 'type': 'for_statement', 'children': ['110', '113', '120']}; {'id': '110', 'type': 'pattern_list', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'lang'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '113', 'type': 'call', 'children': ['114', '119']}; {'id': '114', 'type': 'attribute', 'children': ['115', '118']}; {'id': '115', 'type': 'subscript', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '117', 'type': 'string', 'children': [], 'value': "'complete_slug'"}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '119', 'type': 'argument_list', 'children': []}; {'id': '120', 'type': 'block', 'children': ['121', '127', '136', '145', '205']}; {'id': '121', 'type': 'if_statement', 'children': ['122', '125']}; {'id': '122', 'type': 'comparison_operator', 'children': ['123', '124'], 'value': 'not'}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'lang'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'seen_complete_slugs'}; {'id': '125', 'type': 'block', 'children': ['126']}; {'id': '126', 'type': 'continue_statement', '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': 'seen_complete_slugs'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'lang'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '134', 'type': 'argument_list', 'children': ['135']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '136', 'type': 'if_statement', 'children': ['137', '140']}; {'id': '137', 'type': 'comparison_operator', 'children': ['138', '139'], 'value': 'not'}; {'id': '138', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '140', 'type': 'block', 'children': ['141']}; {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'assignment', 'children': ['143', '144']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'seen_parent'}; {'id': '144', 'type': 'True', 'children': []}; {'id': '145', 'type': 'if_statement', 'children': ['146', '148']}; {'id': '146', 'type': 'not_operator', 'children': ['147']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'seen_parent'}; {'id': '148', 'type': 'block', 'children': ['149', '161']}; {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'assignment', 'children': ['151', '154']}; {'id': '151', 'type': 'pattern_list', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'parent_slug'}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'ignore'}; {'id': '154', 'type': 'call', 'children': ['155', '158']}; {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'rsplit'}; {'id': '158', 'type': 'argument_list', 'children': ['159', '160']}; {'id': '159', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '160', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '161', 'type': 'if_statement', 'children': ['162', '167', '172']}; {'id': '162', 'type': 'comparison_operator', 'children': ['163', '164'], 'value': 'in'}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'parent_slug'}; {'id': '164', 'type': 'subscript', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'seen_complete_slugs'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'lang'}; {'id': '167', 'type': 'block', 'children': ['168']}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}; {'id': '169', 'type': 'assignment', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'seen_parent'}; {'id': '171', 'type': 'True', 'children': []}; {'id': '172', 'type': 'else_clause', 'children': ['173']}; {'id': '173', 'type': 'block', 'children': ['174', '189']}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}; {'id': '175', 'type': 'assignment', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '177', 'type': 'call', 'children': ['178', '183']}; {'id': '178', 'type': 'attribute', 'children': ['179', '182']}; {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'Page'}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'objects'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'from_path'}; {'id': '183', 'type': 'argument_list', 'children': ['184', '185', '186']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'parent_slug'}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'lang'}; {'id': '186', 'type': 'keyword_argument', 'children': ['187', '188']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'exclude_drafts'}; {'id': '188', 'type': 'False', 'children': []}; {'id': '189', 'type': 'if_statement', 'children': ['190', '200']}; {'id': '190', 'type': 'boolean_operator', 'children': ['191', '192'], 'value': 'and'}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '192', 'type': 'comparison_operator', 'children': ['193', '199'], 'value': '=='}; {'id': '193', 'type': 'call', 'children': ['194', '197']}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'get_complete_slug'}; {'id': '197', 'type': 'argument_list', 'children': ['198']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'lang'}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'parent_slug'}; {'id': '200', 'type': 'block', 'children': ['201']}; {'id': '201', 'type': 'expression_statement', 'children': ['202']}; {'id': '202', 'type': 'assignment', 'children': ['203', '204']}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'seen_parent'}; {'id': '204', 'type': 'True', 'children': []}; {'id': '205', 'type': 'if_statement', 'children': ['206', '208']}; {'id': '206', 'type': 'not_operator', 'children': ['207']}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'slug'}; {'id': '208', 'type': 'block', 'children': ['209']}; {'id': '209', 'type': 'expression_statement', 'children': ['210']}; {'id': '210', 'type': 'assignment', 'children': ['211', '212']}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'slug'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '213', 'type': 'if_statement', 'children': ['214', '216']}; {'id': '214', 'type': 'not_operator', 'children': ['215']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'slug'}; {'id': '216', 'type': 'block', 'children': ['217', '238']}; {'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': 'errors'}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '222', 'type': 'argument_list', 'children': ['223']}; {'id': '223', 'type': 'binary_operator', 'children': ['224', '228'], 'value': '%'}; {'id': '224', 'type': 'call', 'children': ['225', '226']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '226', 'type': 'argument_list', 'children': ['227']}; {'id': '227', 'type': 'string', 'children': [], 'value': '"%s has no common language with this site"'}; {'id': '228', 'type': 'tuple', 'children': ['229']}; {'id': '229', 'type': 'subscript', 'children': ['230', '237']}; {'id': '230', 'type': 'call', 'children': ['231', '236']}; {'id': '231', 'type': 'attribute', 'children': ['232', '235']}; {'id': '232', 'type': 'subscript', 'children': ['233', '234']}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '234', 'type': 'string', 'children': [], 'value': "'complete_slug'"}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '236', 'type': 'argument_list', 'children': []}; {'id': '237', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '238', 'type': 'continue_statement', 'children': []}; {'id': '239', 'type': 'if_statement', 'children': ['240', '242']}; {'id': '240', 'type': 'not_operator', 'children': ['241']}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'seen_parent'}; {'id': '242', 'type': 'block', 'children': ['243']}; {'id': '243', 'type': 'expression_statement', 'children': ['244']}; {'id': '244', 'type': 'call', 'children': ['245', '248']}; {'id': '245', 'type': 'attribute', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '248', 'type': 'argument_list', 'children': ['249']}; {'id': '249', 'type': 'binary_operator', 'children': ['250', '256'], 'value': '%'}; {'id': '250', 'type': 'call', 'children': ['251', '252']}; {'id': '251', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '252', 'type': 'argument_list', 'children': ['253']}; {'id': '253', 'type': 'concatenated_string', 'children': ['254', '255']}; {'id': '254', 'type': 'string', 'children': [], 'value': '"%s did not include its parent page and a matching"'}; {'id': '255', 'type': 'string', 'children': [], 'value': '" one was not found on this site"'}; {'id': '256', 'type': 'tuple', 'children': ['257']}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'slug'}; {'id': '258', 'type': 'if_statement', 'children': ['259', '264']}; {'id': '259', 'type': 'comparison_operator', 'children': ['260', '263'], 'value': 'not'}; {'id': '260', 'type': 'subscript', 'children': ['261', '262']}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '262', 'type': 'string', 'children': [], 'value': "'template'"}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'valid_templates'}; {'id': '264', 'type': 'block', 'children': ['265', '281']}; {'id': '265', 'type': 'expression_statement', 'children': ['266']}; {'id': '266', 'type': 'call', 'children': ['267', '270']}; {'id': '267', 'type': 'attribute', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '270', 'type': 'argument_list', 'children': ['271']}; {'id': '271', 'type': 'binary_operator', 'children': ['272', '276'], 'value': '%'}; {'id': '272', 'type': 'call', 'children': ['273', '274']}; {'id': '273', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '274', 'type': 'argument_list', 'children': ['275']}; {'id': '275', 'type': 'string', 'children': [], 'value': '"%s uses a template not found on this site: %s"'}; {'id': '276', 'type': 'tuple', 'children': ['277', '278']}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'slug'}; {'id': '278', 'type': 'subscript', 'children': ['279', '280']}; {'id': '279', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '280', 'type': 'string', 'children': [], 'value': "'template'"}; {'id': '281', 'type': 'continue_statement', 'children': []}; {'id': '282', 'type': 'expression_statement', 'children': ['283']}; {'id': '283', 'type': 'assignment', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'import_fields'}; {'id': '285', 'type': 'call', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '287', 'type': 'argument_list', 'children': ['288']}; {'id': '288', 'type': 'call', 'children': ['289', '294']}; {'id': '289', 'type': 'attribute', 'children': ['290', '293']}; {'id': '290', 'type': 'subscript', 'children': ['291', '292']}; {'id': '291', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '292', 'type': 'string', 'children': [], 'value': "'content'"}; {'id': '293', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '294', 'type': 'argument_list', 'children': []}; {'id': '295', 'type': 'expression_statement', 'children': ['296']}; {'id': '296', 'type': 'augmented_assignment', 'children': ['297', '298'], 'value': '|='}; {'id': '297', 'type': 'identifier', 'children': [], 'value': 'import_fields'}; {'id': '298', 'type': 'call', 'children': ['299', '300']}; {'id': '299', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '300', 'type': 'argument_list', 'children': ['301']}; {'id': '301', 'type': 'tuple', 'children': ['302', '303', '304', '305', '306', '307']}; {'id': '302', 'type': 'string', 'children': [], 'value': "'meta_title'"}; {'id': '303', 'type': 'string', 'children': [], 'value': "'meta_description'"}; {'id': '304', 'type': 'string', 'children': [], 'value': "'meta_keywords'"}; {'id': '305', 'type': 'string', 'children': [], 'value': "'meta_author'"}; {'id': '306', 'type': 'string', 'children': [], 'value': "'fb_page_type'"}; {'id': '307', 'type': 'string', 'children': [], 'value': "'fb_image'"}; {'id': '308', 'type': 'expression_statement', 'children': ['309']}; {'id': '309', 'type': 'assignment', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'template_fields'}; {'id': '311', 'type': 'call', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '313', 'type': 'generator_expression', 'children': ['314', '317', '325']}; {'id': '314', 'type': 'attribute', 'children': ['315', '316']}; {'id': '315', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '317', 'type': 'for_in_clause', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '319', 'type': 'call', 'children': ['320', '321']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'get_placeholders'}; {'id': '321', 'type': 'argument_list', 'children': ['322']}; {'id': '322', 'type': 'subscript', 'children': ['323', '324']}; {'id': '323', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '324', 'type': 'string', 'children': [], 'value': "'template'"}; {'id': '325', 'type': 'if_clause', 'children': ['326']}; {'id': '326', 'type': 'comparison_operator', 'children': ['327', '330'], 'value': 'not'}; {'id': '327', 'type': 'attribute', 'children': ['328', '329']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '329', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '330', 'type': 'tuple', 'children': ['331', '332']}; {'id': '331', 'type': 'string', 'children': [], 'value': "'title'"}; {'id': '332', 'type': 'string', 'children': [], 'value': "'slug'"}; {'id': '333', 'type': 'expression_statement', 'children': ['334']}; {'id': '334', 'type': 'augmented_assignment', 'children': ['335', '336'], 'value': '|='}; {'id': '335', 'type': 'identifier', 'children': [], 'value': 'template_fields'}; {'id': '336', 'type': 'call', 'children': ['337', '338']}; {'id': '337', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '338', 'type': 'argument_list', 'children': ['339']}; {'id': '339', 'type': 'tuple', 'children': ['340', '341', '342', '343', '344', '345']}; {'id': '340', 'type': 'string', 'children': [], 'value': "'meta_title'"}; {'id': '341', 'type': 'string', 'children': [], 'value': "'meta_description'"}; {'id': '342', 'type': 'string', 'children': [], 'value': "'meta_keywords'"}; {'id': '343', 'type': 'string', 'children': [], 'value': "'meta_author'"}; {'id': '344', 'type': 'string', 'children': [], 'value': "'fb_page_type'"}; {'id': '345', 'type': 'string', 'children': [], 'value': "'fb_image'"}; {'id': '346', 'type': 'if_statement', 'children': ['347', '350']}; {'id': '347', 'type': 'comparison_operator', 'children': ['348', '349'], 'value': '!='}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'template_fields'}; {'id': '349', 'type': 'identifier', 'children': [], 'value': 'import_fields'}; {'id': '350', 'type': 'block', 'children': ['351', '369']}; {'id': '351', 'type': 'expression_statement', 'children': ['352']}; {'id': '352', 'type': 'call', 'children': ['353', '356']}; {'id': '353', 'type': 'attribute', 'children': ['354', '355']}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '355', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '356', 'type': 'argument_list', 'children': ['357']}; {'id': '357', 'type': 'binary_operator', 'children': ['358', '364'], 'value': '%'}; {'id': '358', 'type': 'call', 'children': ['359', '360']}; {'id': '359', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '360', 'type': 'argument_list', 'children': ['361']}; {'id': '361', 'type': 'concatenated_string', 'children': ['362', '363']}; {'id': '362', 'type': 'string', 'children': [], 'value': '"%s template contents are different than our "'}; {'id': '363', 'type': 'string', 'children': [], 'value': '"template: %s"'}; {'id': '364', 'type': 'tuple', 'children': ['365', '366']}; {'id': '365', 'type': 'identifier', 'children': [], 'value': 'slug'}; {'id': '366', 'type': 'subscript', 'children': ['367', '368']}; {'id': '367', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '368', 'type': 'string', 'children': [], 'value': "'template'"}; {'id': '369', 'type': 'continue_statement', 'children': []}; {'id': '370', 'type': 'return_statement', 'children': ['371']}; {'id': '371', 'type': 'identifier', 'children': [], 'value': 'errors'}
|
def validate_pages_json_data(d, preferred_lang):
from .models import Page
errors = []
seen_complete_slugs = dict(
(lang[0], set()) for lang in settings.PAGE_LANGUAGES)
valid_templates = set(t[0] for t in settings.get_page_templates())
valid_templates.add(settings.PAGE_DEFAULT_TEMPLATE)
if d[JSON_PAGE_EXPORT_NAME] != JSON_PAGE_EXPORT_VERSION:
return [_('Unsupported file version: %s') % repr(
d[JSON_PAGE_EXPORT_NAME])], []
pages = d['pages']
for p in pages:
slug = p['complete_slug'].get(preferred_lang, None)
seen_parent = False
for lang, s in p['complete_slug'].items():
if lang not in seen_complete_slugs:
continue
seen_complete_slugs[lang].add(s)
if '/' not in s:
seen_parent = True
if not seen_parent:
parent_slug, ignore = s.rsplit('/', 1)
if parent_slug in seen_complete_slugs[lang]:
seen_parent = True
else:
parent = Page.objects.from_path(parent_slug, lang,
exclude_drafts=False)
if parent and parent.get_complete_slug(lang) == parent_slug:
seen_parent = True
if not slug:
slug = s
if not slug:
errors.append(_("%s has no common language with this site")
% (p['complete_slug'].values()[0],))
continue
if not seen_parent:
errors.append(_("%s did not include its parent page and a matching"
" one was not found on this site") % (slug,))
if p['template'] not in valid_templates:
errors.append(_("%s uses a template not found on this site: %s")
% (slug, p['template']))
continue
import_fields = set(p['content'].keys())
import_fields |= set(('meta_title', 'meta_description', 'meta_keywords', 'meta_author', 'fb_page_type', 'fb_image'))
template_fields = set(p.name for p in get_placeholders(p['template']) if
p.name not in ('title', 'slug'))
template_fields |= set(('meta_title', 'meta_description', 'meta_keywords', 'meta_author', 'fb_page_type', 'fb_image'))
if template_fields != import_fields:
errors.append(_("%s template contents are different than our "
"template: %s") % (slug, p['template']))
continue
return errors
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'import_po_files'}; {'id': '3', 'type': 'parameters', 'children': ['4', '7']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '6', 'type': 'string', 'children': [], 'value': "'poexport'"}; {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'stdout'}; {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'block', 'children': ['11', '14', '22', '28', '32', '36', '58', '72', '85', '255', '265']}; {'id': '11', 'type': 'import_statement', 'children': ['12']}; {'id': '12', 'type': 'dotted_name', 'children': ['13']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'polib'}; {'id': '14', 'type': 'import_from_statement', 'children': ['15', '18', '20']}; {'id': '15', 'type': 'dotted_name', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'basic_cms'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'models'}; {'id': '18', 'type': 'dotted_name', 'children': ['19']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'Page'}; {'id': '20', 'type': 'dotted_name', 'children': ['21']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'Content'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'source_language'}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'settings'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'PAGE_DEFAULT_LANGUAGE'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}; {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'source_list'}; {'id': '31', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'pages_to_invalidate'}; {'id': '35', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '36', 'type': 'for_statement', 'children': ['37', '38', '45']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '38', 'type': 'call', 'children': ['39', '44']}; {'id': '39', 'type': 'attribute', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'Page'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'objects'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'published'}; {'id': '44', 'type': 'argument_list', 'children': []}; {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}; {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'source_list'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'call', 'children': ['53', '56']}; {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'content_by_language'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'source_language'}; {'id': '58', 'type': 'if_statement', 'children': ['59', '62']}; {'id': '59', 'type': 'comparison_operator', 'children': ['60', '61'], 'value': 'is'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'stdout'}; {'id': '61', 'type': 'None', 'children': []}; {'id': '62', 'type': 'block', 'children': ['63', '66']}; {'id': '63', 'type': 'import_statement', 'children': ['64']}; {'id': '64', 'type': 'dotted_name', 'children': ['65']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}; {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'stdout'}; {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'stdout'}; {'id': '72', 'type': 'if_statement', 'children': ['73', '80']}; {'id': '73', 'type': 'not_operator', 'children': ['74']}; {'id': '74', 'type': 'call', 'children': ['75', '78']}; {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'endswith'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}; {'id': '79', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '80', 'type': 'block', 'children': ['81']}; {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'augmented_assignment', 'children': ['83', '84'], 'value': '+='}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '84', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '85', 'type': 'for_statement', 'children': ['86', '87', '90']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'lang'}; {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'settings'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'PAGE_LANGUAGES'}; {'id': '90', 'type': 'block', 'children': ['91']}; {'id': '91', 'type': 'if_statement', 'children': ['92', '99']}; {'id': '92', 'type': 'comparison_operator', 'children': ['93', '96'], 'value': '!='}; {'id': '93', 'type': 'subscript', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'lang'}; {'id': '95', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'settings'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'PAGE_DEFAULT_LANGUAGE'}; {'id': '99', 'type': 'block', 'children': ['100', '111', '121', '130']}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}; {'id': '101', 'type': 'call', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'stdout'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'binary_operator', 'children': ['107', '108'], 'value': '%'}; {'id': '107', 'type': 'string', 'children': [], 'value': '"Update language %s.\\n"'}; {'id': '108', 'type': 'subscript', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'lang'}; {'id': '110', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'po_path'}; {'id': '114', 'type': 'binary_operator', 'children': ['115', '120'], 'value': '+'}; {'id': '115', 'type': 'binary_operator', 'children': ['116', '117'], 'value': '+'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '117', 'type': 'subscript', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'lang'}; {'id': '119', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '120', 'type': 'string', 'children': [], 'value': "'.po'"}; {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'assignment', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'po'}; {'id': '124', 'type': 'call', 'children': ['125', '128']}; {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'polib'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'pofile'}; {'id': '128', 'type': 'argument_list', 'children': ['129']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'po_path'}; {'id': '130', 'type': 'for_statement', 'children': ['131', '132', '133']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'po'}; {'id': '133', 'type': 'block', 'children': ['134', '152', '165', '181', '194', '209']}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}; {'id': '135', 'type': 'assignment', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'meta_data'}; {'id': '137', 'type': 'call', 'children': ['138', '150']}; {'id': '138', 'type': 'attribute', 'children': ['139', '149']}; {'id': '139', 'type': 'subscript', 'children': ['140', '148']}; {'id': '140', 'type': 'call', 'children': ['141', '146']}; {'id': '141', 'type': 'attribute', 'children': ['142', '145']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'tcomment'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '146', 'type': 'argument_list', 'children': ['147']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'do_not_msg'}; {'id': '148', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '150', 'type': 'argument_list', 'children': ['151']}; {'id': '151', 'type': 'string', 'children': [], 'value': '"\\n"'}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}; {'id': '153', 'type': 'assignment', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'placeholder_name'}; {'id': '155', 'type': 'subscript', 'children': ['156', '164']}; {'id': '156', 'type': 'call', 'children': ['157', '162']}; {'id': '157', 'type': 'attribute', 'children': ['158', '161']}; {'id': '158', 'type': 'subscript', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'meta_data'}; {'id': '160', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '162', 'type': 'argument_list', 'children': ['163']}; {'id': '163', 'type': 'string', 'children': [], 'value': "'='"}; {'id': '164', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '165', 'type': 'expression_statement', 'children': ['166']}; {'id': '166', 'type': 'assignment', 'children': ['167', '168']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'page_id'}; {'id': '168', 'type': 'call', 'children': ['169', '170']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '170', 'type': 'argument_list', 'children': ['171']}; {'id': '171', 'type': 'subscript', 'children': ['172', '180']}; {'id': '172', 'type': 'call', 'children': ['173', '178']}; {'id': '173', 'type': 'attribute', 'children': ['174', '177']}; {'id': '174', 'type': 'subscript', 'children': ['175', '176']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'meta_data'}; {'id': '176', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '178', 'type': 'argument_list', 'children': ['179']}; {'id': '179', 'type': 'string', 'children': [], 'value': "'='"}; {'id': '180', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '181', 'type': 'expression_statement', 'children': ['182']}; {'id': '182', 'type': 'assignment', 'children': ['183', '184']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '184', 'type': 'call', 'children': ['185', '190']}; {'id': '185', 'type': 'attribute', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'Page'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'objects'}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '190', 'type': 'argument_list', 'children': ['191']}; {'id': '191', 'type': 'keyword_argument', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'page_id'}; {'id': '194', 'type': 'expression_statement', 'children': ['195']}; {'id': '195', 'type': 'assignment', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'current_content'}; {'id': '197', 'type': 'call', 'children': ['198', '203']}; {'id': '198', 'type': 'attribute', 'children': ['199', '202']}; {'id': '199', 'type': 'attribute', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'Content'}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'objects'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'get_content'}; {'id': '203', 'type': 'argument_list', 'children': ['204', '205', '208']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '205', 'type': 'subscript', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'lang'}; {'id': '207', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'placeholder_name'}; {'id': '209', 'type': 'if_statement', 'children': ['210', '215']}; {'id': '210', 'type': 'comparison_operator', 'children': ['211', '212'], 'value': '!='}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'current_content'}; {'id': '212', 'type': 'attribute', 'children': ['213', '214']}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'msgstr'}; {'id': '215', 'type': 'block', 'children': ['216', '227', '243']}; {'id': '216', 'type': 'expression_statement', 'children': ['217']}; {'id': '217', 'type': 'call', 'children': ['218', '221']}; {'id': '218', 'type': 'attribute', 'children': ['219', '220']}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'stdout'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '221', 'type': 'argument_list', 'children': ['222']}; {'id': '222', 'type': 'binary_operator', 'children': ['223', '224'], 'value': '%'}; {'id': '223', 'type': 'string', 'children': [], 'value': '"Update page %d placeholder %s.\\n"'}; {'id': '224', 'type': 'tuple', 'children': ['225', '226']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'page_id'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'placeholder_name'}; {'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': 'Content'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'objects'}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'create_content_if_changed'}; {'id': '234', 'type': 'argument_list', 'children': ['235', '236', '239', '240']}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '236', 'type': 'subscript', 'children': ['237', '238']}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'lang'}; {'id': '238', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'placeholder_name'}; {'id': '240', 'type': 'attribute', 'children': ['241', '242']}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'msgstr'}; {'id': '243', 'type': 'if_statement', 'children': ['244', '247']}; {'id': '244', 'type': 'comparison_operator', 'children': ['245', '246'], 'value': 'not'}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'pages_to_invalidate'}; {'id': '247', 'type': 'block', 'children': ['248']}; {'id': '248', 'type': 'expression_statement', 'children': ['249']}; {'id': '249', 'type': 'call', 'children': ['250', '253']}; {'id': '250', 'type': 'attribute', 'children': ['251', '252']}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'pages_to_invalidate'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '253', 'type': 'argument_list', 'children': ['254']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '255', 'type': 'for_statement', 'children': ['256', '257', '258']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'pages_to_invalidate'}; {'id': '258', 'type': 'block', 'children': ['259']}; {'id': '259', 'type': 'expression_statement', 'children': ['260']}; {'id': '260', 'type': 'call', 'children': ['261', '264']}; {'id': '261', 'type': 'attribute', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'invalidate'}; {'id': '264', 'type': 'argument_list', 'children': []}; {'id': '265', 'type': 'expression_statement', 'children': ['266']}; {'id': '266', 'type': 'call', 'children': ['267', '270']}; {'id': '267', 'type': 'attribute', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'stdout'}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '270', 'type': 'argument_list', 'children': ['271']}; {'id': '271', 'type': 'binary_operator', 'children': ['272', '273'], 'value': '%'}; {'id': '272', 'type': 'string', 'children': [], 'value': '"Import finished from %s.\\n"'}; {'id': '273', 'type': 'identifier', 'children': [], 'value': 'path'}
|
def import_po_files(path='poexport', stdout=None):
import polib
from basic_cms.models import Page, Content
source_language = settings.PAGE_DEFAULT_LANGUAGE
source_list = []
pages_to_invalidate = []
for page in Page.objects.published():
source_list.extend(page.content_by_language(source_language))
if stdout is None:
import sys
stdout = sys.stdout
if not path.endswith('/'):
path += '/'
for lang in settings.PAGE_LANGUAGES:
if lang[0] != settings.PAGE_DEFAULT_LANGUAGE:
stdout.write("Update language %s.\n" % lang[0])
po_path = path + lang[0] + '.po'
po = polib.pofile(po_path)
for entry in po:
meta_data = entry.tcomment.split(do_not_msg)[1].split("\n")
placeholder_name = meta_data[1].split('=')[1]
page_id = int(meta_data[2].split('=')[1])
page = Page.objects.get(id=page_id)
current_content = Content.objects.get_content(page, lang[0],
placeholder_name)
if current_content != entry.msgstr:
stdout.write("Update page %d placeholder %s.\n" % (page_id,
placeholder_name))
Content.objects.create_content_if_changed(
page, lang[0], placeholder_name, entry.msgstr)
if page not in pages_to_invalidate:
pages_to_invalidate.append(page)
for page in pages_to_invalidate:
page.invalidate()
stdout.write("Import finished from %s.\n" % path)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_scene_suggestions'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'current'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '29', '45']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '10', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '11', 'type': 'if_statement', 'children': ['12', '21']}; {'id': '12', 'type': 'call', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'current'}; {'id': '16', 'type': 'attribute', 'children': ['17', '20']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'djadapter'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'models'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'Asset'}; {'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': 'l'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'current'}; {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '34']}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}; {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'call', 'children': ['39', '44']}; {'id': '39', 'type': 'attribute', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'current'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'assets'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '44', 'type': 'argument_list', 'children': []}; {'id': '45', 'type': 'return_statement', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'l'}
|
def get_scene_suggestions(self, current):
l = []
if isinstance(current, djadapter.models.Asset):
l.append(current)
l.extend(list(current.assets.all()))
return l
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'assert_variable_type'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'variable'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'expected_type'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'raise_exception'}; {'id': '8', 'type': 'True', 'children': []}; {'id': '9', 'type': 'block', 'children': ['10', '23', '45', '63', '125']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '17']}; {'id': '11', 'type': 'not_operator', 'children': ['12']}; {'id': '12', 'type': 'call', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'expected_type'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'expected_type'}; {'id': '21', 'type': 'list', 'children': ['22'], 'value': '[expected_type]'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'expected_type'}; {'id': '23', 'type': 'for_statement', 'children': ['24', '25', '26']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'expected_type'}; {'id': '26', 'type': 'block', 'children': ['27']}; {'id': '27', 'type': 'if_statement', 'children': ['28', '34']}; {'id': '28', 'type': 'not_operator', 'children': ['29']}; {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '31', 'type': 'argument_list', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '34', 'type': 'block', 'children': ['35']}; {'id': '35', 'type': 'raise_statement', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}; {'id': '39', 'type': 'binary_operator', 'children': ['40', '41'], 'value': '%'}; {'id': '40', 'type': 'string', 'children': [], 'value': '\'expected_type argument "%s" is not a type\''}; {'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': 't'}; {'id': '45', 'type': 'if_statement', 'children': ['46', '52']}; {'id': '46', 'type': 'not_operator', 'children': ['47']}; {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '49', 'type': 'argument_list', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'raise_exception'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'bool'}; {'id': '52', 'type': 'block', 'children': ['53']}; {'id': '53', 'type': 'raise_statement', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}; {'id': '57', 'type': 'binary_operator', 'children': ['58', '59'], 'value': '%'}; {'id': '58', 'type': 'string', 'children': [], 'value': '\'raise_exception argument "%s" is not a bool\''}; {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'raise_exception'}; {'id': '63', 'type': 'if_statement', 'children': ['64', '80']}; {'id': '64', 'type': 'not_operator', 'children': ['65']}; {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'list_comprehension', 'children': ['69', '71', '74']}; {'id': '69', 'type': '()', 'children': ['70']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '71', 'type': 'for_in_clause', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'expected_type'}; {'id': '74', 'type': 'if_clause', 'children': ['75']}; {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '77', 'type': 'argument_list', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'variable'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '80', 'type': 'block', 'children': ['81', '111']}; {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'error_message'}; {'id': '84', 'type': 'binary_operator', 'children': ['85', '86'], 'value': '%'}; {'id': '85', 'type': 'string', 'children': [], 'value': '\'"%s" is not an instance of type %s. It is of type %s\''}; {'id': '86', 'type': 'tuple', 'children': ['87', '91', '104']}; {'id': '87', 'type': 'call', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'variable'}; {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}; {'id': '93', 'type': 'string', 'children': [], 'value': "' or '"}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'list_comprehension', 'children': ['97', '101']}; {'id': '97', 'type': 'call', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '101', 'type': 'for_in_clause', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'expected_type'}; {'id': '104', 'type': 'call', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}; {'id': '107', 'type': 'call', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'variable'}; {'id': '111', 'type': 'if_statement', 'children': ['112', '113', '119']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'raise_exception'}; {'id': '113', 'type': 'block', 'children': ['114']}; {'id': '114', 'type': 'raise_statement', 'children': ['115']}; {'id': '115', 'type': 'call', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'error_message'}; {'id': '119', 'type': 'else_clause', 'children': ['120']}; {'id': '120', 'type': 'block', 'children': ['121']}; {'id': '121', 'type': 'return_statement', 'children': ['122']}; {'id': '122', 'type': 'expression_list', 'children': ['123', '124']}; {'id': '123', 'type': 'False', 'children': []}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'error_message'}; {'id': '125', 'type': 'return_statement', 'children': ['126']}; {'id': '126', 'type': 'expression_list', 'children': ['127', '128']}; {'id': '127', 'type': 'True', 'children': []}; {'id': '128', 'type': 'None', 'children': []}
|
def assert_variable_type(variable, expected_type, raise_exception=True):
if not isinstance(expected_type, list):
expected_type = [expected_type]
for t in expected_type:
if not isinstance(t, type):
raise ValueError('expected_type argument "%s" is not a type' %str(t))
if not isinstance(raise_exception, bool):
raise ValueError('raise_exception argument "%s" is not a bool' %str(raise_exception))
if not len([(t) for t in expected_type if isinstance(variable, t)]):
error_message = '"%s" is not an instance of type %s. It is of type %s' %(str(variable),' or '.join([str(t) for t in expected_type]), str(type(variable)))
if raise_exception:
raise ValueError(error_message)
else:
return False, error_message
return True, None
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'run'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'while_statement', 'children': ['7', '15']}; {'id': '7', 'type': 'not_operator', 'children': ['8']}; {'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': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'stopped'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'isSet'}; {'id': '14', 'type': 'argument_list', 'children': []}; {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'try_statement', 'children': ['17', '158']}; {'id': '17', 'type': 'block', 'children': ['18', '31', '53', '71', '82', '108', '120', '131']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '21', 'type': 'boolean_operator', 'children': ['22', '30'], 'value': 'or'}; {'id': '22', 'type': 'boolean_operator', 'children': ['23', '29'], 'value': 'and'}; {'id': '23', 'type': '()', 'children': ['24']}; {'id': '24', 'type': 'comparison_operator', 'children': ['25', '28'], 'value': '!='}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': '_state'}; {'id': '28', 'type': 'string', 'children': [], 'value': "'idle'"}; {'id': '29', 'type': 'float', 'children': [], 'value': '0.2'}; {'id': '30', 'type': 'None', 'children': []}; {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '37']}; {'id': '33', 'type': 'pattern_list', 'children': ['34', '35', '36']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'rdlist'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'select'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'select'}; {'id': '41', 'type': 'argument_list', 'children': ['42', '50', '51', '52']}; {'id': '42', 'type': 'list', 'children': ['43'], 'value': '[self._socket.fileno()]'}; {'id': '43', 'type': 'call', 'children': ['44', '49']}; {'id': '44', 'type': 'attribute', 'children': ['45', '48']}; {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': '_socket'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'fileno'}; {'id': '49', 'type': 'argument_list', 'children': []}; {'id': '50', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '51', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '53', 'type': 'if_statement', 'children': ['54', '56']}; {'id': '54', 'type': 'not_operator', 'children': ['55']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'rdlist'}; {'id': '56', 'type': 'block', 'children': ['57', '70']}; {'id': '57', 'type': 'if_statement', 'children': ['58', '63']}; {'id': '58', 'type': 'comparison_operator', 'children': ['59', '62'], 'value': '!='}; {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': '_state'}; {'id': '62', 'type': 'string', 'children': [], 'value': "'idle'"}; {'id': '63', 'type': 'block', 'children': ['64']}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}; {'id': '65', 'type': 'assignment', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': '_state'}; {'id': '69', 'type': 'string', 'children': [], 'value': "'idle'"}; {'id': '70', 'type': 'continue_statement', 'children': []}; {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '74', 'type': 'call', 'children': ['75', '80']}; {'id': '75', 'type': 'attribute', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': '_socket'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'recv'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}; {'id': '81', 'type': 'integer', 'children': [], 'value': '1024'}; {'id': '82', 'type': 'if_statement', 'children': ['83', '85']}; {'id': '83', 'type': 'not_operator', 'children': ['84']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '85', 'type': 'block', 'children': ['86', '107']}; {'id': '86', 'type': 'try_statement', 'children': ['87', '101']}; {'id': '87', 'type': 'block', 'children': ['88']}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}; {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'fstat'}; {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'call', 'children': ['95', '100']}; {'id': '95', 'type': 'attribute', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'recv'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': '_socket'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'fileno'}; {'id': '100', 'type': 'argument_list', 'children': []}; {'id': '101', 'type': 'except_clause', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'socket'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '105', 'type': 'block', 'children': ['106']}; {'id': '106', 'type': 'break_statement', 'children': []}; {'id': '107', 'type': 'continue_statement', 'children': []}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}; {'id': '109', 'type': 'assignment', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '111', 'type': 'call', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'mangleIR'}; {'id': '115', 'type': 'argument_list', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '117', 'type': 'keyword_argument', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'ignore_errors'}; {'id': '119', 'type': 'True', 'children': []}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}; {'id': '121', 'type': 'assignment', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'codeName'}; {'id': '123', 'type': 'call', 'children': ['124', '129']}; {'id': '124', 'type': 'attribute', 'children': ['125', '128']}; {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'codeMap'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '129', 'type': 'argument_list', 'children': ['130']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '131', 'type': 'if_statement', 'children': ['132', '140']}; {'id': '132', 'type': 'boolean_operator', 'children': ['133', '134'], 'value': 'and'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'codeName'}; {'id': '134', 'type': '()', 'children': ['135']}; {'id': '135', 'type': 'comparison_operator', 'children': ['136', '139'], 'value': '!='}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': '_state'}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'codeName'}; {'id': '140', 'type': 'block', 'children': ['141', '147']}; {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'assignment', 'children': ['143', '146']}; {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': '_state'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'codeName'}; {'id': '147', 'type': 'for_statement', 'children': ['148', '149', '152']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'callback'}; {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '151', 'type': 'identifier', 'children': [], 'value': '_callbacks'}; {'id': '152', 'type': 'block', 'children': ['153']}; {'id': '153', 'type': 'expression_statement', 'children': ['154']}; {'id': '154', 'type': 'call', 'children': ['155', '156']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'callback'}; {'id': '156', 'type': 'argument_list', 'children': ['157']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'codeName'}; {'id': '158', 'type': 'except_clause', 'children': ['159']}; {'id': '159', 'type': 'block', 'children': ['160']}; {'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': 'time'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'sleep'}; {'id': '165', 'type': 'argument_list', 'children': ['166']}; {'id': '166', 'type': 'float', 'children': [], 'value': '0.1'}
|
def run(self):
while not self.stopped.isSet():
try:
timeout = (self._state != 'idle') and 0.2 or None
rdlist, _, _ = select.select([self._socket.fileno()], [], [], timeout)
if not rdlist:
if self._state != 'idle':
self._state = 'idle'
continue
data = self._socket.recv(1024)
if not data:
try:
os.fstat(recv._socket.fileno())
except socket.error:
break
continue
code = utils.mangleIR(data, ignore_errors=True)
codeName = self.codeMap.get(code)
if codeName and (self._state != codeName):
self._state = codeName
for callback in self._callbacks:
callback(codeName)
except:
time.sleep(0.1)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_inc'}; {'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': 'native'}; {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '67', '167', '256', '267']}; {'id': '9', 'type': 'if_statement', 'children': ['10', '15']}; {'id': '10', 'type': 'comparison_operator', 'children': ['11', '14'], 'value': '=='}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'sdk_version'}; {'id': '14', 'type': 'string', 'children': [], 'value': "'v7.0A'"}; {'id': '15', 'type': 'block', 'children': ['16', '30', '54', '65']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'include'}; {'id': '19', 'type': 'call', 'children': ['20', '25']}; {'id': '20', 'type': 'attribute', 'children': ['21', '24']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '25', 'type': 'argument_list', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'sdk_dir'}; {'id': '29', 'type': 'string', 'children': [], 'value': "'include'"}; {'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': 'isdir'}; {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'include'}; {'id': '39', 'type': 'block', 'children': ['40', '51']}; {'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': 'logging'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '45', 'type': 'argument_list', 'children': ['46', '50']}; {'id': '46', 'type': 'call', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}; {'id': '49', 'type': 'string', 'children': [], 'value': "'using include: %s'"}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'include'}; {'id': '51', 'type': 'return_statement', 'children': ['52']}; {'id': '52', 'type': 'list', 'children': ['53'], 'value': '[include]'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'include'}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}; {'id': '55', 'type': 'call', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '59', 'type': 'argument_list', 'children': ['60', '64']}; {'id': '60', 'type': 'call', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}; {'id': '63', 'type': 'string', 'children': [], 'value': "'include not found: %s'"}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'include'}; {'id': '65', 'type': 'return_statement', 'children': ['66']}; {'id': '66', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '67', 'type': 'if_statement', 'children': ['68', '73']}; {'id': '68', 'type': 'comparison_operator', 'children': ['69', '72'], 'value': '=='}; {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'sdk_version'}; {'id': '72', 'type': 'string', 'children': [], 'value': "'v8.1'"}; {'id': '73', 'type': 'block', 'children': ['74', '78', '105', '165']}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}; {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'dirs'}; {'id': '77', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '78', 'type': 'if_statement', 'children': ['79', '80', '96']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'native'}; {'id': '80', 'type': 'block', 'children': ['81']}; {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'parts'}; {'id': '84', 'type': 'list', 'children': ['85', '86', '95'], 'value': "['km', os.path.join('km', 'crt'), 'shared']"}; {'id': '85', 'type': 'string', 'children': [], 'value': "'km'"}; {'id': '86', 'type': 'call', 'children': ['87', '92']}; {'id': '87', 'type': 'attribute', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '92', 'type': 'argument_list', 'children': ['93', '94']}; {'id': '93', 'type': 'string', 'children': [], 'value': "'km'"}; {'id': '94', 'type': 'string', 'children': [], 'value': "'crt'"}; {'id': '95', 'type': 'string', 'children': [], 'value': "'shared'"}; {'id': '96', 'type': 'else_clause', 'children': ['97']}; {'id': '97', 'type': 'block', 'children': ['98']}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}; {'id': '99', 'type': 'assignment', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'parts'}; {'id': '101', 'type': 'list', 'children': ['102', '103', '104'], 'value': "['um', 'winrt', 'shared']"}; {'id': '102', 'type': 'string', 'children': [], 'value': "'um'"}; {'id': '103', 'type': 'string', 'children': [], 'value': "'winrt'"}; {'id': '104', 'type': 'string', 'children': [], 'value': "'shared'"}; {'id': '105', 'type': 'for_statement', 'children': ['106', '107', '108']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'part'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'parts'}; {'id': '108', 'type': 'block', 'children': ['109', '124']}; {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'assignment', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'include'}; {'id': '112', 'type': 'call', 'children': ['113', '118']}; {'id': '113', 'type': 'attribute', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '118', 'type': 'argument_list', 'children': ['119', '122', '123']}; {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'sdk_dir'}; {'id': '122', 'type': 'string', 'children': [], 'value': "'include'"}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'part'}; {'id': '124', 'type': 'if_statement', 'children': ['125', '133', '152']}; {'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': 'os'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'isdir'}; {'id': '131', 'type': 'argument_list', 'children': ['132']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'include'}; {'id': '133', 'type': 'block', 'children': ['134', '145']}; {'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': 'logging'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '139', 'type': 'argument_list', 'children': ['140', '144']}; {'id': '140', 'type': 'call', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '142', 'type': 'argument_list', 'children': ['143']}; {'id': '143', 'type': 'string', 'children': [], 'value': "'using include: %s'"}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'include'}; {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'call', 'children': ['147', '150']}; {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'dirs'}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '150', 'type': 'argument_list', 'children': ['151']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'include'}; {'id': '152', 'type': 'else_clause', 'children': ['153']}; {'id': '153', 'type': 'block', 'children': ['154']}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}; {'id': '155', 'type': 'call', 'children': ['156', '159']}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '159', 'type': 'argument_list', 'children': ['160', '164']}; {'id': '160', 'type': 'call', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '162', 'type': 'argument_list', 'children': ['163']}; {'id': '163', 'type': 'string', 'children': [], 'value': "'inc not found: %s'"}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'include'}; {'id': '165', 'type': 'return_statement', 'children': ['166']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'dirs'}; {'id': '167', 'type': 'if_statement', 'children': ['168', '173']}; {'id': '168', 'type': 'comparison_operator', 'children': ['169', '172'], 'value': '=='}; {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'sdk_version'}; {'id': '172', 'type': 'string', 'children': [], 'value': "'v10.0'"}; {'id': '173', 'type': 'block', 'children': ['174', '178', '190', '254']}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}; {'id': '175', 'type': 'assignment', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'dirs'}; {'id': '177', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '178', 'type': 'expression_statement', 'children': ['179']}; {'id': '179', 'type': 'assignment', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'extra'}; {'id': '181', 'type': 'call', 'children': ['182', '187']}; {'id': '182', 'type': 'attribute', 'children': ['183', '186']}; {'id': '183', 'type': 'attribute', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '187', 'type': 'argument_list', 'children': ['188', '189']}; {'id': '188', 'type': 'string', 'children': [], 'value': "'include'"}; {'id': '189', 'type': 'string', 'children': [], 'value': "'10.0.10240.0'"}; {'id': '190', 'type': 'for_statement', 'children': ['191', '192', '197']}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '192', 'type': 'list', 'children': ['193', '194', '195', '196'], 'value': "['um', 'ucrt', 'shared', 'winrt']"}; {'id': '193', 'type': 'string', 'children': [], 'value': "'um'"}; {'id': '194', 'type': 'string', 'children': [], 'value': "'ucrt'"}; {'id': '195', 'type': 'string', 'children': [], 'value': "'shared'"}; {'id': '196', 'type': 'string', 'children': [], 'value': "'winrt'"}; {'id': '197', 'type': 'block', 'children': ['198', '213']}; {'id': '198', 'type': 'expression_statement', 'children': ['199']}; {'id': '199', 'type': 'assignment', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'include'}; {'id': '201', 'type': 'call', 'children': ['202', '207']}; {'id': '202', 'type': 'attribute', 'children': ['203', '206']}; {'id': '203', 'type': 'attribute', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '207', 'type': 'argument_list', 'children': ['208', '211', '212']}; {'id': '208', 'type': 'attribute', 'children': ['209', '210']}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'sdk_dir'}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'extra'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '213', 'type': 'if_statement', 'children': ['214', '222', '241']}; {'id': '214', 'type': 'call', 'children': ['215', '220']}; {'id': '215', 'type': 'attribute', 'children': ['216', '219']}; {'id': '216', 'type': 'attribute', 'children': ['217', '218']}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'isdir'}; {'id': '220', 'type': 'argument_list', 'children': ['221']}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'include'}; {'id': '222', 'type': 'block', 'children': ['223', '234']}; {'id': '223', 'type': 'expression_statement', 'children': ['224']}; {'id': '224', 'type': 'call', 'children': ['225', '228']}; {'id': '225', 'type': 'attribute', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '228', 'type': 'argument_list', 'children': ['229', '233']}; {'id': '229', 'type': 'call', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '231', 'type': 'argument_list', 'children': ['232']}; {'id': '232', 'type': 'string', 'children': [], 'value': "'using include: %s'"}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'include'}; {'id': '234', 'type': 'expression_statement', 'children': ['235']}; {'id': '235', 'type': 'call', 'children': ['236', '239']}; {'id': '236', 'type': 'attribute', 'children': ['237', '238']}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'dirs'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '239', 'type': 'argument_list', 'children': ['240']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'include'}; {'id': '241', 'type': 'else_clause', 'children': ['242']}; {'id': '242', 'type': 'block', 'children': ['243']}; {'id': '243', 'type': 'expression_statement', 'children': ['244']}; {'id': '244', 'type': 'call', 'children': ['245', '248']}; {'id': '245', 'type': 'attribute', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '248', 'type': 'argument_list', 'children': ['249', '253']}; {'id': '249', 'type': 'call', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '251', 'type': 'argument_list', 'children': ['252']}; {'id': '252', 'type': 'string', 'children': [], 'value': "'inc not found: %s'"}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'include'}; {'id': '254', 'type': 'return_statement', 'children': ['255']}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'dirs'}; {'id': '256', 'type': 'expression_statement', 'children': ['257']}; {'id': '257', 'type': 'assignment', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '259', 'type': 'call', 'children': ['260', '263']}; {'id': '260', 'type': 'attribute', 'children': ['261', '262']}; {'id': '261', 'type': 'string', 'children': [], 'value': "'unknown sdk version: {}'"}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '263', 'type': 'argument_list', 'children': ['264']}; {'id': '264', 'type': 'attribute', 'children': ['265', '266']}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'sdk_version'}; {'id': '267', 'type': 'raise_statement', 'children': ['268']}; {'id': '268', 'type': 'call', 'children': ['269', '270']}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'}; {'id': '270', 'type': 'argument_list', 'children': ['271']}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'message'}
|
def get_inc(self, native=False):
if self.sdk_version == 'v7.0A':
include = os.path.join(self.sdk_dir, 'include')
if os.path.isdir(include):
logging.info(_('using include: %s'), include)
return [include]
logging.debug(_('include not found: %s'), include)
return []
if self.sdk_version == 'v8.1':
dirs = []
if native:
parts = ['km', os.path.join('km', 'crt'), 'shared']
else:
parts = ['um', 'winrt', 'shared']
for part in parts:
include = os.path.join(self.sdk_dir, 'include', part)
if os.path.isdir(include):
logging.info(_('using include: %s'), include)
dirs.append(include)
else:
logging.debug(_('inc not found: %s'), include)
return dirs
if self.sdk_version == 'v10.0':
dirs = []
extra = os.path.join('include', '10.0.10240.0')
for mode in ['um', 'ucrt', 'shared', 'winrt']:
include = os.path.join(self.sdk_dir, extra, mode)
if os.path.isdir(include):
logging.info(_('using include: %s'), include)
dirs.append(include)
else:
logging.debug(_('inc not found: %s'), include)
return dirs
message = 'unknown sdk version: {}'.format(self.sdk_version)
raise RuntimeError(message)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_lib'}; {'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': 'arch'}; {'id': '7', 'type': 'string', 'children': [], 'value': "'x86'"}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'native'}; {'id': '10', 'type': 'False', 'children': []}; {'id': '11', 'type': 'block', 'children': ['12', '80', '169', '257', '268']}; {'id': '12', 'type': 'if_statement', 'children': ['13', '18']}; {'id': '13', 'type': 'comparison_operator', 'children': ['14', '17'], 'value': '=='}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'sdk_version'}; {'id': '17', 'type': 'string', 'children': [], 'value': "'v7.0A'"}; {'id': '18', 'type': 'block', 'children': ['19', '28', '43', '67', '78']}; {'id': '19', 'type': 'if_statement', 'children': ['20', '23']}; {'id': '20', 'type': 'comparison_operator', 'children': ['21', '22'], 'value': '=='}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'arch'}; {'id': '22', 'type': 'string', 'children': [], 'value': "'x86'"}; {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}; {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'arch'}; {'id': '27', 'type': 'string', 'children': [], 'value': "''"}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}; {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'lib'}; {'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', '41', '42']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'sdk_dir'}; {'id': '41', 'type': 'string', 'children': [], 'value': "'lib'"}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'arch'}; {'id': '43', 'type': 'if_statement', 'children': ['44', '52']}; {'id': '44', 'type': 'call', 'children': ['45', '50']}; {'id': '45', 'type': 'attribute', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'isdir'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'lib'}; {'id': '52', 'type': 'block', 'children': ['53', '64']}; {'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': 'logging'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '58', 'type': 'argument_list', 'children': ['59', '63']}; {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'string', 'children': [], 'value': "'using lib: %s'"}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'lib'}; {'id': '64', 'type': 'return_statement', 'children': ['65']}; {'id': '65', 'type': 'list', 'children': ['66'], 'value': '[lib]'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'lib'}; {'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': 'logging'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '72', 'type': 'argument_list', 'children': ['73', '77']}; {'id': '73', 'type': 'call', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'string', 'children': [], 'value': "'lib not found: %s'"}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'lib'}; {'id': '78', 'type': 'return_statement', 'children': ['79']}; {'id': '79', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '80', 'type': 'if_statement', 'children': ['81', '86']}; {'id': '81', 'type': 'comparison_operator', 'children': ['82', '85'], 'value': '=='}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'sdk_version'}; {'id': '85', 'type': 'string', 'children': [], 'value': "'v8.1'"}; {'id': '86', 'type': 'block', 'children': ['87', '116', '132', '156', '167']}; {'id': '87', 'type': 'if_statement', 'children': ['88', '89', '102']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'native'}; {'id': '89', 'type': 'block', 'children': ['90']}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}; {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'extra'}; {'id': '93', 'type': 'call', 'children': ['94', '99']}; {'id': '94', 'type': 'attribute', 'children': ['95', '98']}; {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '99', 'type': 'argument_list', 'children': ['100', '101']}; {'id': '100', 'type': 'string', 'children': [], 'value': "'winv6.3'"}; {'id': '101', 'type': 'string', 'children': [], 'value': "'km'"}; {'id': '102', 'type': 'else_clause', 'children': ['103']}; {'id': '103', 'type': 'block', 'children': ['104']}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}; {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'extra'}; {'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': 'os'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '113', 'type': 'argument_list', 'children': ['114', '115']}; {'id': '114', 'type': 'string', 'children': [], 'value': "'winv6.3'"}; {'id': '115', 'type': 'string', 'children': [], 'value': "'um'"}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}; {'id': '117', 'type': 'assignment', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'lib'}; {'id': '119', 'type': 'call', 'children': ['120', '125']}; {'id': '120', 'type': 'attribute', 'children': ['121', '124']}; {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '125', 'type': 'argument_list', 'children': ['126', '129', '130', '131']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'sdk_dir'}; {'id': '129', 'type': 'string', 'children': [], 'value': "'lib'"}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'extra'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'arch'}; {'id': '132', 'type': 'if_statement', 'children': ['133', '141']}; {'id': '133', 'type': 'call', 'children': ['134', '139']}; {'id': '134', 'type': 'attribute', 'children': ['135', '138']}; {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'isdir'}; {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'lib'}; {'id': '141', 'type': 'block', 'children': ['142', '153']}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}; {'id': '143', 'type': 'call', 'children': ['144', '147']}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '147', 'type': 'argument_list', 'children': ['148', '152']}; {'id': '148', 'type': 'call', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '150', 'type': 'argument_list', 'children': ['151']}; {'id': '151', 'type': 'string', 'children': [], 'value': "'using lib: %s'"}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'lib'}; {'id': '153', 'type': 'return_statement', 'children': ['154']}; {'id': '154', 'type': 'list', 'children': ['155'], 'value': '[lib]'}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'lib'}; {'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': 'logging'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '161', 'type': 'argument_list', 'children': ['162', '166']}; {'id': '162', 'type': 'call', 'children': ['163', '164']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}; {'id': '165', 'type': 'string', 'children': [], 'value': "'lib not found: %s'"}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'lib'}; {'id': '167', 'type': 'return_statement', 'children': ['168']}; {'id': '168', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '169', 'type': 'if_statement', 'children': ['170', '175']}; {'id': '170', 'type': 'comparison_operator', 'children': ['171', '174'], 'value': '=='}; {'id': '171', 'type': 'attribute', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'sdk_version'}; {'id': '174', 'type': 'string', 'children': [], 'value': "'v10.0'"}; {'id': '175', 'type': 'block', 'children': ['176', '180', '192', '255']}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}; {'id': '177', 'type': 'assignment', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'dirs'}; {'id': '179', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '180', 'type': 'expression_statement', 'children': ['181']}; {'id': '181', 'type': 'assignment', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'extra'}; {'id': '183', 'type': 'call', 'children': ['184', '189']}; {'id': '184', 'type': 'attribute', 'children': ['185', '188']}; {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '189', 'type': 'argument_list', 'children': ['190', '191']}; {'id': '190', 'type': 'string', 'children': [], 'value': "'lib'"}; {'id': '191', 'type': 'string', 'children': [], 'value': "'10.0.10240.0'"}; {'id': '192', 'type': 'for_statement', 'children': ['193', '194', '197']}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '194', 'type': 'list', 'children': ['195', '196'], 'value': "['um', 'ucrt']"}; {'id': '195', 'type': 'string', 'children': [], 'value': "'um'"}; {'id': '196', 'type': 'string', 'children': [], 'value': "'ucrt'"}; {'id': '197', 'type': 'block', 'children': ['198', '214']}; {'id': '198', 'type': 'expression_statement', 'children': ['199']}; {'id': '199', 'type': 'assignment', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'lib'}; {'id': '201', 'type': 'call', 'children': ['202', '207']}; {'id': '202', 'type': 'attribute', 'children': ['203', '206']}; {'id': '203', 'type': 'attribute', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '207', 'type': 'argument_list', 'children': ['208', '211', '212', '213']}; {'id': '208', 'type': 'attribute', 'children': ['209', '210']}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'sdk_dir'}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'extra'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'arch'}; {'id': '214', 'type': 'if_statement', 'children': ['215', '223', '242']}; {'id': '215', 'type': 'call', 'children': ['216', '221']}; {'id': '216', 'type': 'attribute', 'children': ['217', '220']}; {'id': '217', 'type': 'attribute', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'isdir'}; {'id': '221', 'type': 'argument_list', 'children': ['222']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'lib'}; {'id': '223', 'type': 'block', 'children': ['224', '235']}; {'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': 'logging'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '229', 'type': 'argument_list', 'children': ['230', '234']}; {'id': '230', 'type': 'call', 'children': ['231', '232']}; {'id': '231', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '232', 'type': 'argument_list', 'children': ['233']}; {'id': '233', 'type': 'string', 'children': [], 'value': "'using lib: %s'"}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'lib'}; {'id': '235', 'type': 'expression_statement', 'children': ['236']}; {'id': '236', 'type': 'call', 'children': ['237', '240']}; {'id': '237', 'type': 'attribute', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'dirs'}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '240', 'type': 'argument_list', 'children': ['241']}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'lib'}; {'id': '242', 'type': 'else_clause', 'children': ['243']}; {'id': '243', 'type': 'block', 'children': ['244']}; {'id': '244', 'type': 'expression_statement', 'children': ['245']}; {'id': '245', 'type': 'call', 'children': ['246', '249']}; {'id': '246', 'type': 'attribute', 'children': ['247', '248']}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '249', 'type': 'argument_list', 'children': ['250', '254']}; {'id': '250', 'type': 'call', 'children': ['251', '252']}; {'id': '251', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '252', 'type': 'argument_list', 'children': ['253']}; {'id': '253', 'type': 'string', 'children': [], 'value': "'lib not found: %s'"}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'lib'}; {'id': '255', 'type': 'return_statement', 'children': ['256']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'dirs'}; {'id': '257', 'type': 'expression_statement', 'children': ['258']}; {'id': '258', 'type': 'assignment', 'children': ['259', '260']}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '260', 'type': 'call', 'children': ['261', '264']}; {'id': '261', 'type': 'attribute', 'children': ['262', '263']}; {'id': '262', 'type': 'string', 'children': [], 'value': "'unknown sdk version: {}'"}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '264', 'type': 'argument_list', 'children': ['265']}; {'id': '265', 'type': 'attribute', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'sdk_version'}; {'id': '268', 'type': 'raise_statement', 'children': ['269']}; {'id': '269', 'type': 'call', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'}; {'id': '271', 'type': 'argument_list', 'children': ['272']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'message'}
|
def get_lib(self, arch='x86', native=False):
if self.sdk_version == 'v7.0A':
if arch == 'x86':
arch = ''
lib = os.path.join(self.sdk_dir, 'lib', arch)
if os.path.isdir(lib):
logging.info(_('using lib: %s'), lib)
return [lib]
logging.debug(_('lib not found: %s'), lib)
return []
if self.sdk_version == 'v8.1':
if native:
extra = os.path.join('winv6.3', 'km')
else:
extra = os.path.join('winv6.3', 'um')
lib = os.path.join(self.sdk_dir, 'lib', extra, arch)
if os.path.isdir(lib):
logging.info(_('using lib: %s'), lib)
return [lib]
logging.debug(_('lib not found: %s'), lib)
return []
if self.sdk_version == 'v10.0':
dirs = []
extra = os.path.join('lib', '10.0.10240.0')
for mode in ['um', 'ucrt']:
lib = os.path.join(self.sdk_dir, extra, mode, arch)
if os.path.isdir(lib):
logging.info(_('using lib: %s'), lib)
dirs.append(lib)
else:
logging.debug(_('lib not found: %s'), lib)
return dirs
message = 'unknown sdk version: {}'.format(self.sdk_version)
raise RuntimeError(message)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'interrogate'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'platformIdentifier'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'configuration'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'libraries'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'libOverrides'}; {'id': '10', 'type': 'dictionary', 'children': []}; {'id': '11', 'type': 'block', 'children': ['12', '27', '33', '331', '348', '359']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'libModules'}; {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'list_comprehension', 'children': ['19', '20', '23']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'lib'}; {'id': '20', 'type': 'for_in_clause', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'lib'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'libraries'}; {'id': '23', 'type': 'if_clause', 'children': ['24']}; {'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': 'not'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'lib'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'libOverrides'}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'details'}; {'id': '30', 'type': 'call', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'ThirdPartyLibraryDetails'}; {'id': '32', 'type': 'argument_list', 'children': []}; {'id': '33', 'type': 'if_statement', 'children': ['34', '40']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '39'], 'value': '>'}; {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'libModules'}; {'id': '39', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '40', 'type': 'block', 'children': ['41', '51', '65', '75', '91', '113', '199', '210', '214', '249', '255', '269', '275', '306']}; {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'modules'}; {'id': '44', 'type': 'call', 'children': ['45', '48']}; {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': '_getThirdPartyLibs'}; {'id': '48', 'type': 'argument_list', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'platformIdentifier'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'configuration'}; {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'modules'}; {'id': '54', 'type': 'list_comprehension', 'children': ['55', '56', '59']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '56', 'type': 'for_in_clause', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'modules'}; {'id': '59', 'type': 'if_clause', 'children': ['60']}; {'id': '60', 'type': 'comparison_operator', 'children': ['61', '64'], 'value': 'in'}; {'id': '61', 'type': 'subscript', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '63', 'type': 'string', 'children': [], 'value': "'Name'"}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'libModules'}; {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '68', 'type': 'list_comprehension', 'children': ['69', '72']}; {'id': '69', 'type': 'subscript', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '71', 'type': 'string', 'children': [], 'value': "'Name'"}; {'id': '72', 'type': 'for_in_clause', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'modules'}; {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'unsupported'}; {'id': '78', 'type': 'list_comprehension', 'children': ['79', '84', '87']}; {'id': '79', 'type': 'binary_operator', 'children': ['80', '83'], 'value': '+'}; {'id': '80', 'type': 'binary_operator', 'children': ['81', '82'], 'value': '+'}; {'id': '81', 'type': 'string', 'children': [], 'value': '\'"\''}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '83', 'type': 'string', 'children': [], 'value': '\'"\''}; {'id': '84', 'type': 'for_in_clause', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'libModules'}; {'id': '87', 'type': 'if_clause', 'children': ['88']}; {'id': '88', 'type': 'comparison_operator', 'children': ['89', '90'], 'value': 'not'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '91', 'type': 'if_statement', 'children': ['92', '98']}; {'id': '92', 'type': 'comparison_operator', 'children': ['93', '97'], 'value': '>'}; {'id': '93', 'type': 'call', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'unsupported'}; {'id': '97', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '98', 'type': 'block', 'children': ['99']}; {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'call', 'children': ['101', '104']}; {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'Utility'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'printStderr'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}; {'id': '105', 'type': 'binary_operator', 'children': ['106', '107'], 'value': '+'}; {'id': '106', 'type': 'string', 'children': [], 'value': "'Warning: unsupported libraries '"}; {'id': '107', 'type': 'call', 'children': ['108', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}; {'id': '109', 'type': 'string', 'children': [], 'value': "','"}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '111', 'type': 'argument_list', 'children': ['112']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'unsupported'}; {'id': '113', 'type': 'for_statement', 'children': ['114', '115', '116']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'modules'}; {'id': '116', 'type': 'block', 'children': ['117']}; {'id': '117', 'type': 'if_statement', 'children': ['118', '135']}; {'id': '118', 'type': 'boolean_operator', 'children': ['119', '127'], 'value': 'and'}; {'id': '119', 'type': 'comparison_operator', 'children': ['120', '126'], 'value': '>'}; {'id': '120', 'type': 'call', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}; {'id': '123', 'type': 'subscript', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '125', 'type': 'string', 'children': [], 'value': "'PublicAdditionalLibraries'"}; {'id': '126', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '127', 'type': 'comparison_operator', 'children': ['128', '134'], 'value': '>'}; {'id': '128', 'type': 'call', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}; {'id': '131', 'type': 'subscript', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '133', 'type': 'string', 'children': [], 'value': "'PublicLibraryPaths'"}; {'id': '134', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '135', 'type': 'block', 'children': ['136', '150', '169', '193']}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}; {'id': '137', 'type': 'assignment', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'libPath'}; {'id': '139', 'type': 'subscript', 'children': ['140', '149']}; {'id': '140', 'type': '()', 'children': ['141']}; {'id': '141', 'type': 'call', 'children': ['142', '145']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': '_absolutePaths'}; {'id': '145', 'type': 'argument_list', 'children': ['146']}; {'id': '146', 'type': 'subscript', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '148', 'type': 'string', 'children': [], 'value': "'PublicLibraryPaths'"}; {'id': '149', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}; {'id': '151', 'type': 'assignment', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'libs'}; {'id': '153', 'type': 'call', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'list_comprehension', 'children': ['157', '164']}; {'id': '157', 'type': 'call', 'children': ['158', '161']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'lib'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '161', 'type': 'argument_list', 'children': ['162', '163']}; {'id': '162', 'type': 'string', 'children': [], 'value': "'\\\\'"}; {'id': '163', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '164', 'type': 'for_in_clause', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'lib'}; {'id': '166', 'type': 'subscript', 'children': ['167', '168']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '168', 'type': 'string', 'children': [], 'value': "'PublicAdditionalLibraries'"}; {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'assignment', 'children': ['171', '172']}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'libs'}; {'id': '172', 'type': 'call', 'children': ['173', '174']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '174', 'type': 'argument_list', 'children': ['175']}; {'id': '175', 'type': 'list_comprehension', 'children': ['176', '190']}; {'id': '176', 'type': 'conditional_expression', 'children': ['177', '186', '189'], 'value': 'if'}; {'id': '177', 'type': 'call', 'children': ['178', '183']}; {'id': '178', 'type': 'attribute', 'children': ['179', '182']}; {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '183', 'type': 'argument_list', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'libPath'}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'lib'}; {'id': '186', 'type': 'comparison_operator', 'children': ['187', '188'], 'value': 'not'}; {'id': '187', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'lib'}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'lib'}; {'id': '190', 'type': 'for_in_clause', 'children': ['191', '192']}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'lib'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'libs'}; {'id': '193', 'type': 'expression_statement', 'children': ['194']}; {'id': '194', 'type': 'assignment', 'children': ['195', '198']}; {'id': '195', 'type': 'subscript', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '197', 'type': 'string', 'children': [], 'value': "'PublicAdditionalLibraries'"}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'libs'}; {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'assignment', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '202', 'type': 'list', 'children': ['203', '204', '205', '206', '207', '208', '209'], 'value': "[\n\t\t\t\t'Directory',\n\t\t\t\t'PublicAdditionalLibraries',\n\t\t\t\t'PublicLibraryPaths',\n\t\t\t\t'PublicSystemIncludePaths',\n\t\t\t\t'PublicIncludePaths',\n\t\t\t\t'PrivateIncludePaths',\n\t\t\t\t'PublicDefinitions'\n\t\t\t]"}; {'id': '203', 'type': 'string', 'children': [], 'value': "'Directory'"}; {'id': '204', 'type': 'string', 'children': [], 'value': "'PublicAdditionalLibraries'"}; {'id': '205', 'type': 'string', 'children': [], 'value': "'PublicLibraryPaths'"}; {'id': '206', 'type': 'string', 'children': [], 'value': "'PublicSystemIncludePaths'"}; {'id': '207', 'type': 'string', 'children': [], 'value': "'PublicIncludePaths'"}; {'id': '208', 'type': 'string', 'children': [], 'value': "'PrivateIncludePaths'"}; {'id': '209', 'type': 'string', 'children': [], 'value': "'PublicDefinitions'"}; {'id': '210', 'type': 'expression_statement', 'children': ['211']}; {'id': '211', 'type': 'assignment', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'flattened'}; {'id': '213', 'type': 'dictionary', 'children': []}; {'id': '214', 'type': 'for_statement', 'children': ['215', '216', '217']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '217', 'type': 'block', 'children': ['218', '236']}; {'id': '218', 'type': 'expression_statement', 'children': ['219']}; {'id': '219', 'type': 'assignment', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'transform'}; {'id': '221', 'type': 'conditional_expression', 'children': ['222', '232', '235'], 'value': 'if'}; {'id': '222', 'type': '()', 'children': ['223']}; {'id': '223', 'type': 'lambda', 'children': ['224', '226']}; {'id': '224', 'type': 'lambda_parameters', 'children': ['225']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '226', 'type': 'call', 'children': ['227', '230']}; {'id': '227', 'type': 'attribute', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '229', 'type': 'identifier', 'children': [], 'value': '_absolutePaths'}; {'id': '230', 'type': 'argument_list', 'children': ['231']}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '232', 'type': 'comparison_operator', 'children': ['233', '234'], 'value': '!='}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '234', 'type': 'string', 'children': [], 'value': "'Definitions'"}; {'id': '235', 'type': 'None', 'children': []}; {'id': '236', 'type': 'expression_statement', 'children': ['237']}; {'id': '237', 'type': 'assignment', 'children': ['238', '241']}; {'id': '238', 'type': 'subscript', 'children': ['239', '240']}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'flattened'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '241', 'type': 'call', 'children': ['242', '245']}; {'id': '242', 'type': 'attribute', 'children': ['243', '244']}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': '_flatten'}; {'id': '245', 'type': 'argument_list', 'children': ['246', '247', '248']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'modules'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'transform'}; {'id': '249', 'type': 'expression_statement', 'children': ['250']}; {'id': '250', 'type': 'assignment', 'children': ['251', '252']}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'libraryDirectories'}; {'id': '252', 'type': 'subscript', 'children': ['253', '254']}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'flattened'}; {'id': '254', 'type': 'string', 'children': [], 'value': "'PublicLibraryPaths'"}; {'id': '255', 'type': 'expression_statement', 'children': ['256']}; {'id': '256', 'type': 'assignment', 'children': ['257', '258']}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'headerDirectories'}; {'id': '258', 'type': 'binary_operator', 'children': ['259', '266'], 'value': '+'}; {'id': '259', 'type': 'binary_operator', 'children': ['260', '263'], 'value': '+'}; {'id': '260', 'type': 'subscript', 'children': ['261', '262']}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'flattened'}; {'id': '262', 'type': 'string', 'children': [], 'value': "'PublicSystemIncludePaths'"}; {'id': '263', 'type': 'subscript', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'flattened'}; {'id': '265', 'type': 'string', 'children': [], 'value': "'PublicIncludePaths'"}; {'id': '266', 'type': 'subscript', 'children': ['267', '268']}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'flattened'}; {'id': '268', 'type': 'string', 'children': [], 'value': "'PrivateIncludePaths'"}; {'id': '269', 'type': 'expression_statement', 'children': ['270']}; {'id': '270', 'type': 'assignment', 'children': ['271', '272']}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'modulePaths'}; {'id': '272', 'type': 'subscript', 'children': ['273', '274']}; {'id': '273', 'type': 'identifier', 'children': [], 'value': 'flattened'}; {'id': '274', 'type': 'string', 'children': [], 'value': "'Directory'"}; {'id': '275', 'type': 'expression_statement', 'children': ['276']}; {'id': '276', 'type': 'assignment', 'children': ['277', '278']}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'prefixDirectories'}; {'id': '278', 'type': 'call', 'children': ['279', '280']}; {'id': '279', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '280', 'type': 'argument_list', 'children': ['281']}; {'id': '281', 'type': 'call', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '283', 'type': 'argument_list', 'children': ['284']}; {'id': '284', 'type': 'binary_operator', 'children': ['285', '292'], 'value': '+'}; {'id': '285', 'type': 'binary_operator', 'children': ['286', '291'], 'value': '+'}; {'id': '286', 'type': 'binary_operator', 'children': ['287', '290'], 'value': '+'}; {'id': '287', 'type': 'subscript', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'flattened'}; {'id': '289', 'type': 'string', 'children': [], 'value': "'Directory'"}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'headerDirectories'}; {'id': '291', 'type': 'identifier', 'children': [], 'value': 'libraryDirectories'}; {'id': '292', 'type': 'list_comprehension', 'children': ['293', '301']}; {'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': 'os'}; {'id': '297', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'dirname'}; {'id': '299', 'type': 'argument_list', 'children': ['300']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '301', 'type': 'for_in_clause', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '303', 'type': 'binary_operator', 'children': ['304', '305'], 'value': '+'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'headerDirectories'}; {'id': '305', 'type': 'identifier', 'children': [], 'value': 'libraryDirectories'}; {'id': '306', 'type': 'expression_statement', 'children': ['307']}; {'id': '307', 'type': 'assignment', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'details'}; {'id': '309', 'type': 'call', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'ThirdPartyLibraryDetails'}; {'id': '311', 'type': 'argument_list', 'children': ['312', '315', '318', '321', '326']}; {'id': '312', 'type': 'keyword_argument', 'children': ['313', '314']}; {'id': '313', 'type': 'identifier', 'children': [], 'value': 'prefixDirs'}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'prefixDirectories'}; {'id': '315', 'type': 'keyword_argument', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'includeDirs'}; {'id': '317', 'type': 'identifier', 'children': [], 'value': 'headerDirectories'}; {'id': '318', 'type': 'keyword_argument', 'children': ['319', '320']}; {'id': '319', 'type': 'identifier', 'children': [], 'value': 'linkDirs'}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'libraryDirectories'}; {'id': '321', 'type': 'keyword_argument', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'definitions'}; {'id': '323', 'type': 'subscript', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'flattened'}; {'id': '325', 'type': 'string', 'children': [], 'value': "'PublicDefinitions'"}; {'id': '326', 'type': 'keyword_argument', 'children': ['327', '328']}; {'id': '327', 'type': 'identifier', 'children': [], 'value': 'libs'}; {'id': '328', 'type': 'subscript', 'children': ['329', '330']}; {'id': '329', 'type': 'identifier', 'children': [], 'value': 'flattened'}; {'id': '330', 'type': 'string', 'children': [], 'value': "'PublicAdditionalLibraries'"}; {'id': '331', 'type': 'expression_statement', 'children': ['332']}; {'id': '332', 'type': 'assignment', 'children': ['333', '334']}; {'id': '333', 'type': 'identifier', 'children': [], 'value': 'overridesToApply'}; {'id': '334', 'type': 'call', 'children': ['335', '336']}; {'id': '335', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '336', 'type': 'argument_list', 'children': ['337']}; {'id': '337', 'type': 'list_comprehension', 'children': ['338', '341', '344']}; {'id': '338', 'type': 'subscript', 'children': ['339', '340']}; {'id': '339', 'type': 'identifier', 'children': [], 'value': 'libOverrides'}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'lib'}; {'id': '341', 'type': 'for_in_clause', 'children': ['342', '343']}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'lib'}; {'id': '343', 'type': 'identifier', 'children': [], 'value': 'libraries'}; {'id': '344', 'type': 'if_clause', 'children': ['345']}; {'id': '345', 'type': 'comparison_operator', 'children': ['346', '347'], 'value': 'in'}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'lib'}; {'id': '347', 'type': 'identifier', 'children': [], 'value': 'libOverrides'}; {'id': '348', 'type': 'for_statement', 'children': ['349', '350', '351']}; {'id': '349', 'type': 'identifier', 'children': [], 'value': 'override'}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'overridesToApply'}; {'id': '351', 'type': 'block', 'children': ['352']}; {'id': '352', 'type': 'expression_statement', 'children': ['353']}; {'id': '353', 'type': 'call', 'children': ['354', '357']}; {'id': '354', 'type': 'attribute', 'children': ['355', '356']}; {'id': '355', 'type': 'identifier', 'children': [], 'value': 'details'}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'merge'}; {'id': '357', 'type': 'argument_list', 'children': ['358']}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'override'}; {'id': '359', 'type': 'return_statement', 'children': ['360']}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'details'}
|
def interrogate(self, platformIdentifier, configuration, libraries, libOverrides = {}):
libModules = list([lib for lib in libraries if lib not in libOverrides])
details = ThirdPartyLibraryDetails()
if len(libModules) > 0:
modules = self._getThirdPartyLibs(platformIdentifier, configuration)
modules = [m for m in modules if m['Name'] in libModules]
names = [m['Name'] for m in modules]
unsupported = ['"' + m + '"' for m in libModules if m not in names]
if len(unsupported) > 0:
Utility.printStderr('Warning: unsupported libraries ' + ','.join(unsupported))
for module in modules:
if len(module['PublicAdditionalLibraries']) > 0 and len(module['PublicLibraryPaths']) > 0:
libPath = (self._absolutePaths(module['PublicLibraryPaths']))[0]
libs = list([lib.replace('\\', '/') for lib in module['PublicAdditionalLibraries']])
libs = list([os.path.join(libPath, lib) if '/' not in lib else lib for lib in libs])
module['PublicAdditionalLibraries'] = libs
fields = [
'Directory',
'PublicAdditionalLibraries',
'PublicLibraryPaths',
'PublicSystemIncludePaths',
'PublicIncludePaths',
'PrivateIncludePaths',
'PublicDefinitions'
]
flattened = {}
for field in fields:
transform = (lambda l: self._absolutePaths(l)) if field != 'Definitions' else None
flattened[field] = self._flatten(field, modules, transform)
libraryDirectories = flattened['PublicLibraryPaths']
headerDirectories = flattened['PublicSystemIncludePaths'] + flattened['PublicIncludePaths'] + flattened['PrivateIncludePaths']
modulePaths = flattened['Directory']
prefixDirectories = list(set(flattened['Directory'] + headerDirectories + libraryDirectories + [os.path.dirname(p) for p in headerDirectories + libraryDirectories]))
details = ThirdPartyLibraryDetails(
prefixDirs = prefixDirectories,
includeDirs = headerDirectories,
linkDirs = libraryDirectories,
definitions = flattened['PublicDefinitions'],
libs = flattened['PublicAdditionalLibraries']
)
overridesToApply = list([libOverrides[lib] for lib in libraries if lib in libOverrides])
for override in overridesToApply:
details.merge(override)
return details
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_getThirdPartyLibs'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'platformIdentifier'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'configuration'}; {'id': '7', 'type': 'block', 'children': ['8', '20', '27', '35', '47', '63', '69', '92', '105', '154', '168', '182', '198', '215', '227', '238']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'cachedList'}; {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'CachedDataManager'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'getCachedDataKey'}; {'id': '15', 'type': 'argument_list', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'engineVersionHash'}; {'id': '19', 'type': 'string', 'children': [], 'value': "'ThirdPartyLibraries'"}; {'id': '20', 'type': 'if_statement', 'children': ['21', '24']}; {'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': '!='}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'cachedList'}; {'id': '23', 'type': 'None', 'children': []}; {'id': '24', 'type': 'block', 'children': ['25']}; {'id': '25', 'type': 'return_statement', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'cachedList'}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'tempDir'}; {'id': '30', 'type': 'call', 'children': ['31', '34']}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'tempfile'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'mkdtemp'}; {'id': '34', 'type': 'argument_list', 'children': []}; {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'jsonFile'}; {'id': '38', 'type': 'call', 'children': ['39', '44']}; {'id': '39', 'type': 'attribute', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'tempDir'}; {'id': '46', 'type': 'string', 'children': [], 'value': "'ubt_output.json'"}; {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'sentinelFile'}; {'id': '50', 'type': 'call', 'children': ['51', '56']}; {'id': '51', 'type': 'attribute', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '56', 'type': 'argument_list', 'children': ['57', '60', '61', '62']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'engineRoot'}; {'id': '60', 'type': 'string', 'children': [], 'value': "'Engine'"}; {'id': '61', 'type': 'string', 'children': [], 'value': "'Build'"}; {'id': '62', 'type': 'string', 'children': [], 'value': "'InstalledBuild.txt'"}; {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'sentinelBackup'}; {'id': '66', 'type': 'binary_operator', 'children': ['67', '68'], 'value': '+'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'sentinelFile'}; {'id': '68', 'type': 'string', 'children': [], 'value': "'.bak'"}; {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'renameSentinel'}; {'id': '72', 'type': 'boolean_operator', 'children': ['73', '81'], 'value': 'and'}; {'id': '73', 'type': 'call', 'children': ['74', '79']}; {'id': '74', 'type': 'attribute', 'children': ['75', '78']}; {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'exists'}; {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'sentinelFile'}; {'id': '81', 'type': 'comparison_operator', 'children': ['82', '91'], 'value': '=='}; {'id': '82', 'type': 'call', 'children': ['83', '88']}; {'id': '83', 'type': 'attribute', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'environ'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '88', 'type': 'argument_list', 'children': ['89', '90']}; {'id': '89', 'type': 'string', 'children': [], 'value': "'UE4CLI_SENTINEL_RENAME'"}; {'id': '90', 'type': 'string', 'children': [], 'value': "'0'"}; {'id': '91', 'type': 'string', 'children': [], 'value': "'1'"}; {'id': '92', 'type': 'if_statement', 'children': ['93', '96']}; {'id': '93', 'type': 'comparison_operator', 'children': ['94', '95'], 'value': '=='}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'renameSentinel'}; {'id': '95', 'type': 'True', 'children': []}; {'id': '96', 'type': 'block', 'children': ['97']}; {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'call', 'children': ['99', '102']}; {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'shutil'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'move'}; {'id': '102', 'type': 'argument_list', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'sentinelFile'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'sentinelBackup'}; {'id': '105', 'type': 'try_statement', 'children': ['106', '139']}; {'id': '106', 'type': 'block', 'children': ['107', '129']}; {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'assignment', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '110', 'type': 'conditional_expression', 'children': ['111', '116', '123'], 'value': 'if'}; {'id': '111', 'type': 'list', 'children': ['112', '113'], 'value': "['-Mode=JsonExport', '-OutputFile=' +jsonFile ]"}; {'id': '112', 'type': 'string', 'children': [], 'value': "'-Mode=JsonExport'"}; {'id': '113', 'type': 'binary_operator', 'children': ['114', '115'], 'value': '+'}; {'id': '114', 'type': 'string', 'children': [], 'value': "'-OutputFile='"}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'jsonFile'}; {'id': '116', 'type': 'comparison_operator', 'children': ['117', '122'], 'value': '>='}; {'id': '117', 'type': 'subscript', 'children': ['118', '121']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'engineVersion'}; {'id': '121', 'type': 'string', 'children': [], 'value': "'MinorVersion'"}; {'id': '122', 'type': 'integer', 'children': [], 'value': '22'}; {'id': '123', 'type': 'list', 'children': ['124', '125', '128'], 'value': "['-gather', '-jsonexport=' + jsonFile, '-SkipBuild']"}; {'id': '124', 'type': 'string', 'children': [], 'value': "'-gather'"}; {'id': '125', 'type': 'binary_operator', 'children': ['126', '127'], 'value': '+'}; {'id': '126', 'type': 'string', 'children': [], 'value': "'-jsonexport='"}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'jsonFile'}; {'id': '128', 'type': 'string', 'children': [], 'value': "'-SkipBuild'"}; {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'call', 'children': ['131', '134']}; {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'runUBTFunc'}; {'id': '134', 'type': 'argument_list', 'children': ['135', '136', '137', '138']}; {'id': '135', 'type': 'string', 'children': [], 'value': "'UE4Editor'"}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'platformIdentifier'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'configuration'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '139', 'type': 'finally_clause', 'children': ['140']}; {'id': '140', 'type': 'block', 'children': ['141']}; {'id': '141', 'type': 'if_statement', 'children': ['142', '145']}; {'id': '142', 'type': 'comparison_operator', 'children': ['143', '144'], 'value': '=='}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'renameSentinel'}; {'id': '144', 'type': 'True', 'children': []}; {'id': '145', 'type': 'block', 'children': ['146']}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}; {'id': '147', 'type': 'call', 'children': ['148', '151']}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'shutil'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'move'}; {'id': '151', 'type': 'argument_list', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'sentinelBackup'}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'sentinelFile'}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}; {'id': '155', 'type': 'assignment', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '157', 'type': 'call', 'children': ['158', '161']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'loads'}; {'id': '161', 'type': 'argument_list', 'children': ['162']}; {'id': '162', 'type': 'call', 'children': ['163', '166']}; {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'Utility'}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'readFile'}; {'id': '166', 'type': 'argument_list', 'children': ['167']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'jsonFile'}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}; {'id': '169', 'type': 'assignment', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'modules'}; {'id': '171', 'type': 'list_comprehension', 'children': ['172', '177']}; {'id': '172', 'type': 'subscript', 'children': ['173', '176']}; {'id': '173', 'type': 'subscript', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '175', 'type': 'string', 'children': [], 'value': "'Modules'"}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '177', 'type': 'for_in_clause', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '179', 'type': 'subscript', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '181', 'type': 'string', 'children': [], 'value': "'Modules'"}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}; {'id': '183', 'type': 'assignment', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'thirdPartyRoot'}; {'id': '185', 'type': 'call', 'children': ['186', '191']}; {'id': '186', 'type': 'attribute', 'children': ['187', '190']}; {'id': '187', 'type': 'attribute', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '191', 'type': 'argument_list', 'children': ['192', '195', '196', '197']}; {'id': '192', 'type': 'attribute', 'children': ['193', '194']}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'engineRoot'}; {'id': '195', 'type': 'string', 'children': [], 'value': "'Engine'"}; {'id': '196', 'type': 'string', 'children': [], 'value': "'Source'"}; {'id': '197', 'type': 'string', 'children': [], 'value': "'ThirdParty'"}; {'id': '198', 'type': 'expression_statement', 'children': ['199']}; {'id': '199', 'type': 'assignment', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'thirdparty'}; {'id': '201', 'type': 'call', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '203', 'type': 'argument_list', 'children': ['204']}; {'id': '204', 'type': 'list_comprehension', 'children': ['205', '206', '209']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '206', 'type': 'for_in_clause', 'children': ['207', '208']}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'modules'}; {'id': '209', 'type': 'if_clause', 'children': ['210']}; {'id': '210', 'type': 'comparison_operator', 'children': ['211', '212'], 'value': 'in'}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'thirdPartyRoot'}; {'id': '212', 'type': 'subscript', 'children': ['213', '214']}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '214', 'type': 'string', 'children': [], 'value': "'Directory'"}; {'id': '215', 'type': 'try_statement', 'children': ['216', '224']}; {'id': '216', 'type': 'block', 'children': ['217']}; {'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': 'shutil'}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'rmtree'}; {'id': '222', 'type': 'argument_list', 'children': ['223']}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'tempDir'}; {'id': '224', 'type': 'except_clause', 'children': ['225']}; {'id': '225', 'type': 'block', 'children': ['226']}; {'id': '226', 'type': 'pass_statement', 'children': []}; {'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': 'CachedDataManager'}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'setCachedDataKey'}; {'id': '232', 'type': 'argument_list', 'children': ['233', '236', '237']}; {'id': '233', 'type': 'attribute', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'engineVersionHash'}; {'id': '236', 'type': 'string', 'children': [], 'value': "'ThirdPartyLibraries'"}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'thirdparty'}; {'id': '238', 'type': 'return_statement', 'children': ['239']}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'thirdparty'}
|
def _getThirdPartyLibs(self, platformIdentifier, configuration):
cachedList = CachedDataManager.getCachedDataKey(self.engineVersionHash, 'ThirdPartyLibraries')
if cachedList != None:
return cachedList
tempDir = tempfile.mkdtemp()
jsonFile = os.path.join(tempDir, 'ubt_output.json')
sentinelFile = os.path.join(self.engineRoot, 'Engine', 'Build', 'InstalledBuild.txt')
sentinelBackup = sentinelFile + '.bak'
renameSentinel = os.path.exists(sentinelFile) and os.environ.get('UE4CLI_SENTINEL_RENAME', '0') == '1'
if renameSentinel == True:
shutil.move(sentinelFile, sentinelBackup)
try:
args = ['-Mode=JsonExport', '-OutputFile=' +jsonFile ] if self.engineVersion['MinorVersion'] >= 22 else ['-gather', '-jsonexport=' + jsonFile, '-SkipBuild']
self.runUBTFunc('UE4Editor', platformIdentifier, configuration, args)
finally:
if renameSentinel == True:
shutil.move(sentinelBackup, sentinelFile)
result = json.loads(Utility.readFile(jsonFile))
modules = [result['Modules'][key] for key in result['Modules']]
thirdPartyRoot = os.path.join(self.engineRoot, 'Engine', 'Source', 'ThirdParty')
thirdparty = list([m for m in modules if thirdPartyRoot in m['Directory']])
try:
shutil.rmtree(tempDir)
except:
pass
CachedDataManager.setCachedDataKey(self.engineVersionHash, 'ThirdPartyLibraries', thirdparty)
return thirdparty
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '57']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_vt'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24', '27', '30', '33', '36', '39', '42', '45', '48', '51', '54']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'vt_id'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '8', 'type': 'None', 'children': []}; {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'vt_params'}; {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'vt_refs'}; {'id': '14', 'type': 'None', 'children': []}; {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'custom'}; {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'vt_creation_time'}; {'id': '20', 'type': 'None', 'children': []}; {'id': '21', 'type': 'default_parameter', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'vt_modification_time'}; {'id': '23', 'type': 'None', 'children': []}; {'id': '24', 'type': 'default_parameter', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'vt_dependencies'}; {'id': '26', 'type': 'None', 'children': []}; {'id': '27', 'type': 'default_parameter', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'summary'}; {'id': '29', 'type': 'None', 'children': []}; {'id': '30', 'type': 'default_parameter', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'impact'}; {'id': '32', 'type': 'None', 'children': []}; {'id': '33', 'type': 'default_parameter', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'affected'}; {'id': '35', 'type': 'None', 'children': []}; {'id': '36', 'type': 'default_parameter', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'insight'}; {'id': '38', 'type': 'None', 'children': []}; {'id': '39', 'type': 'default_parameter', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'solution'}; {'id': '41', 'type': 'None', 'children': []}; {'id': '42', 'type': 'default_parameter', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'solution_t'}; {'id': '44', 'type': 'None', 'children': []}; {'id': '45', 'type': 'default_parameter', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'detection'}; {'id': '47', 'type': 'None', 'children': []}; {'id': '48', 'type': 'default_parameter', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'qod_t'}; {'id': '50', 'type': 'None', 'children': []}; {'id': '51', 'type': 'default_parameter', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'qod_v'}; {'id': '53', 'type': 'None', 'children': []}; {'id': '54', 'type': 'default_parameter', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'severities'}; {'id': '56', 'type': 'None', 'children': []}; {'id': '57', 'type': 'block', 'children': ['58', '65', '80', '90', '99', '110', '125', '140', '155', '170', '185', '200', '215', '230', '245', '260', '290', '305', '335', '350']}; {'id': '58', 'type': 'if_statement', 'children': ['59', '61']}; {'id': '59', 'type': 'not_operator', 'children': ['60']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'vt_id'}; {'id': '61', 'type': 'block', 'children': ['62']}; {'id': '62', 'type': 'return_statement', 'children': ['63']}; {'id': '63', 'type': 'unary_operator', 'children': ['64'], 'value': '-'}; {'id': '64', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '65', 'type': 'if_statement', 'children': ['66', '76']}; {'id': '66', 'type': 'comparison_operator', 'children': ['67', '75'], 'value': 'is'}; {'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': 'vt_id_pattern'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'fullmatch'}; {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'vt_id'}; {'id': '75', 'type': 'None', 'children': []}; {'id': '76', 'type': 'block', 'children': ['77']}; {'id': '77', 'type': 'return_statement', 'children': ['78']}; {'id': '78', 'type': 'unary_operator', 'children': ['79'], 'value': '-'}; {'id': '79', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '80', 'type': 'if_statement', 'children': ['81', '86']}; {'id': '81', 'type': 'comparison_operator', 'children': ['82', '83'], 'value': 'in'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'vt_id'}; {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'vts'}; {'id': '86', 'type': 'block', 'children': ['87']}; {'id': '87', 'type': 'return_statement', 'children': ['88']}; {'id': '88', 'type': 'unary_operator', 'children': ['89'], 'value': '-'}; {'id': '89', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '90', 'type': 'if_statement', 'children': ['91', '94']}; {'id': '91', 'type': 'comparison_operator', 'children': ['92', '93'], 'value': 'is'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '93', 'type': 'None', 'children': []}; {'id': '94', 'type': 'block', 'children': ['95']}; {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '98', 'type': 'string', 'children': [], 'value': "''"}; {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '106']}; {'id': '101', 'type': 'subscript', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'vts'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'vt_id'}; {'id': '106', 'type': 'dictionary', 'children': ['107']}; {'id': '107', 'type': 'pair', 'children': ['108', '109']}; {'id': '108', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '110', 'type': 'if_statement', 'children': ['111', '114']}; {'id': '111', 'type': 'comparison_operator', 'children': ['112', '113'], 'value': 'is'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'custom'}; {'id': '113', 'type': 'None', 'children': []}; {'id': '114', 'type': 'block', 'children': ['115']}; {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '124']}; {'id': '117', 'type': 'subscript', 'children': ['118', '123']}; {'id': '118', 'type': 'subscript', 'children': ['119', '122']}; {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'vts'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'vt_id'}; {'id': '123', 'type': 'string', 'children': [], 'value': '"custom"'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'custom'}; {'id': '125', 'type': 'if_statement', 'children': ['126', '129']}; {'id': '126', 'type': 'comparison_operator', 'children': ['127', '128'], 'value': 'is'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'vt_params'}; {'id': '128', 'type': 'None', 'children': []}; {'id': '129', 'type': 'block', 'children': ['130']}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}; {'id': '131', 'type': 'assignment', 'children': ['132', '139']}; {'id': '132', 'type': 'subscript', 'children': ['133', '138']}; {'id': '133', 'type': 'subscript', 'children': ['134', '137']}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'vts'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'vt_id'}; {'id': '138', 'type': 'string', 'children': [], 'value': '"vt_params"'}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'vt_params'}; {'id': '140', 'type': 'if_statement', 'children': ['141', '144']}; {'id': '141', 'type': 'comparison_operator', 'children': ['142', '143'], 'value': 'is'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'vt_refs'}; {'id': '143', 'type': 'None', 'children': []}; {'id': '144', 'type': 'block', 'children': ['145']}; {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'assignment', 'children': ['147', '154']}; {'id': '147', 'type': 'subscript', 'children': ['148', '153']}; {'id': '148', 'type': 'subscript', 'children': ['149', '152']}; {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'vts'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'vt_id'}; {'id': '153', 'type': 'string', 'children': [], 'value': '"vt_refs"'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'vt_refs'}; {'id': '155', 'type': 'if_statement', 'children': ['156', '159']}; {'id': '156', 'type': 'comparison_operator', 'children': ['157', '158'], 'value': 'is'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'vt_dependencies'}; {'id': '158', 'type': 'None', 'children': []}; {'id': '159', 'type': 'block', 'children': ['160']}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}; {'id': '161', 'type': 'assignment', 'children': ['162', '169']}; {'id': '162', 'type': 'subscript', 'children': ['163', '168']}; {'id': '163', 'type': 'subscript', 'children': ['164', '167']}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'vts'}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'vt_id'}; {'id': '168', 'type': 'string', 'children': [], 'value': '"vt_dependencies"'}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'vt_dependencies'}; {'id': '170', 'type': 'if_statement', 'children': ['171', '174']}; {'id': '171', 'type': 'comparison_operator', 'children': ['172', '173'], 'value': 'is'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'vt_creation_time'}; {'id': '173', 'type': 'None', 'children': []}; {'id': '174', 'type': 'block', 'children': ['175']}; {'id': '175', 'type': 'expression_statement', 'children': ['176']}; {'id': '176', 'type': 'assignment', 'children': ['177', '184']}; {'id': '177', 'type': 'subscript', 'children': ['178', '183']}; {'id': '178', 'type': 'subscript', 'children': ['179', '182']}; {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'vts'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'vt_id'}; {'id': '183', 'type': 'string', 'children': [], 'value': '"creation_time"'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'vt_creation_time'}; {'id': '185', 'type': 'if_statement', 'children': ['186', '189']}; {'id': '186', 'type': 'comparison_operator', 'children': ['187', '188'], 'value': 'is'}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'vt_modification_time'}; {'id': '188', 'type': 'None', 'children': []}; {'id': '189', 'type': 'block', 'children': ['190']}; {'id': '190', 'type': 'expression_statement', 'children': ['191']}; {'id': '191', 'type': 'assignment', 'children': ['192', '199']}; {'id': '192', 'type': 'subscript', 'children': ['193', '198']}; {'id': '193', 'type': 'subscript', 'children': ['194', '197']}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'vts'}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'vt_id'}; {'id': '198', 'type': 'string', 'children': [], 'value': '"modification_time"'}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'vt_modification_time'}; {'id': '200', 'type': 'if_statement', 'children': ['201', '204']}; {'id': '201', 'type': 'comparison_operator', 'children': ['202', '203'], 'value': 'is'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'summary'}; {'id': '203', 'type': 'None', 'children': []}; {'id': '204', 'type': 'block', 'children': ['205']}; {'id': '205', 'type': 'expression_statement', 'children': ['206']}; {'id': '206', 'type': 'assignment', 'children': ['207', '214']}; {'id': '207', 'type': 'subscript', 'children': ['208', '213']}; {'id': '208', 'type': 'subscript', 'children': ['209', '212']}; {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'vts'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'vt_id'}; {'id': '213', 'type': 'string', 'children': [], 'value': '"summary"'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'summary'}; {'id': '215', 'type': 'if_statement', 'children': ['216', '219']}; {'id': '216', 'type': 'comparison_operator', 'children': ['217', '218'], 'value': 'is'}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'impact'}; {'id': '218', 'type': 'None', 'children': []}; {'id': '219', 'type': 'block', 'children': ['220']}; {'id': '220', 'type': 'expression_statement', 'children': ['221']}; {'id': '221', 'type': 'assignment', 'children': ['222', '229']}; {'id': '222', 'type': 'subscript', 'children': ['223', '228']}; {'id': '223', 'type': 'subscript', 'children': ['224', '227']}; {'id': '224', 'type': 'attribute', 'children': ['225', '226']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'vts'}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'vt_id'}; {'id': '228', 'type': 'string', 'children': [], 'value': '"impact"'}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'impact'}; {'id': '230', 'type': 'if_statement', 'children': ['231', '234']}; {'id': '231', 'type': 'comparison_operator', 'children': ['232', '233'], 'value': 'is'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'affected'}; {'id': '233', 'type': 'None', 'children': []}; {'id': '234', 'type': 'block', 'children': ['235']}; {'id': '235', 'type': 'expression_statement', 'children': ['236']}; {'id': '236', 'type': 'assignment', 'children': ['237', '244']}; {'id': '237', 'type': 'subscript', 'children': ['238', '243']}; {'id': '238', 'type': 'subscript', 'children': ['239', '242']}; {'id': '239', 'type': 'attribute', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'vts'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'vt_id'}; {'id': '243', 'type': 'string', 'children': [], 'value': '"affected"'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'affected'}; {'id': '245', 'type': 'if_statement', 'children': ['246', '249']}; {'id': '246', 'type': 'comparison_operator', 'children': ['247', '248'], 'value': 'is'}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'insight'}; {'id': '248', 'type': 'None', 'children': []}; {'id': '249', 'type': 'block', 'children': ['250']}; {'id': '250', 'type': 'expression_statement', 'children': ['251']}; {'id': '251', 'type': 'assignment', 'children': ['252', '259']}; {'id': '252', 'type': 'subscript', 'children': ['253', '258']}; {'id': '253', 'type': 'subscript', 'children': ['254', '257']}; {'id': '254', 'type': 'attribute', 'children': ['255', '256']}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'vts'}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'vt_id'}; {'id': '258', 'type': 'string', 'children': [], 'value': '"insight"'}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'insight'}; {'id': '260', 'type': 'if_statement', 'children': ['261', '264']}; {'id': '261', 'type': 'comparison_operator', 'children': ['262', '263'], 'value': 'is'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'solution'}; {'id': '263', 'type': 'None', 'children': []}; {'id': '264', 'type': 'block', 'children': ['265', '275']}; {'id': '265', 'type': 'expression_statement', 'children': ['266']}; {'id': '266', 'type': 'assignment', 'children': ['267', '274']}; {'id': '267', 'type': 'subscript', 'children': ['268', '273']}; {'id': '268', 'type': 'subscript', 'children': ['269', '272']}; {'id': '269', 'type': 'attribute', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'vts'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'vt_id'}; {'id': '273', 'type': 'string', 'children': [], 'value': '"solution"'}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'solution'}; {'id': '275', 'type': 'if_statement', 'children': ['276', '279']}; {'id': '276', 'type': 'comparison_operator', 'children': ['277', '278'], 'value': 'is'}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'solution_t'}; {'id': '278', 'type': 'None', 'children': []}; {'id': '279', 'type': 'block', 'children': ['280']}; {'id': '280', 'type': 'expression_statement', 'children': ['281']}; {'id': '281', 'type': 'assignment', 'children': ['282', '289']}; {'id': '282', 'type': 'subscript', 'children': ['283', '288']}; {'id': '283', 'type': 'subscript', 'children': ['284', '287']}; {'id': '284', 'type': 'attribute', 'children': ['285', '286']}; {'id': '285', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'vts'}; {'id': '287', 'type': 'identifier', 'children': [], 'value': 'vt_id'}; {'id': '288', 'type': 'string', 'children': [], 'value': '"solution_type"'}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'solution_t'}; {'id': '290', 'type': 'if_statement', 'children': ['291', '294']}; {'id': '291', 'type': 'comparison_operator', 'children': ['292', '293'], 'value': 'is'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'detection'}; {'id': '293', 'type': 'None', 'children': []}; {'id': '294', 'type': 'block', 'children': ['295']}; {'id': '295', 'type': 'expression_statement', 'children': ['296']}; {'id': '296', 'type': 'assignment', 'children': ['297', '304']}; {'id': '297', 'type': 'subscript', 'children': ['298', '303']}; {'id': '298', 'type': 'subscript', 'children': ['299', '302']}; {'id': '299', 'type': 'attribute', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '301', 'type': 'identifier', 'children': [], 'value': 'vts'}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'vt_id'}; {'id': '303', 'type': 'string', 'children': [], 'value': '"detection"'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'detection'}; {'id': '305', 'type': 'if_statement', 'children': ['306', '309', '320']}; {'id': '306', 'type': 'comparison_operator', 'children': ['307', '308'], 'value': 'is'}; {'id': '307', 'type': 'identifier', 'children': [], 'value': 'qod_t'}; {'id': '308', 'type': 'None', 'children': []}; {'id': '309', 'type': 'block', 'children': ['310']}; {'id': '310', 'type': 'expression_statement', 'children': ['311']}; {'id': '311', 'type': 'assignment', 'children': ['312', '319']}; {'id': '312', 'type': 'subscript', 'children': ['313', '318']}; {'id': '313', 'type': 'subscript', 'children': ['314', '317']}; {'id': '314', 'type': 'attribute', 'children': ['315', '316']}; {'id': '315', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'vts'}; {'id': '317', 'type': 'identifier', 'children': [], 'value': 'vt_id'}; {'id': '318', 'type': 'string', 'children': [], 'value': '"qod_type"'}; {'id': '319', 'type': 'identifier', 'children': [], 'value': 'qod_t'}; {'id': '320', 'type': 'elif_clause', 'children': ['321', '324']}; {'id': '321', 'type': 'comparison_operator', 'children': ['322', '323'], 'value': 'is'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'qod_v'}; {'id': '323', 'type': 'None', 'children': []}; {'id': '324', 'type': 'block', 'children': ['325']}; {'id': '325', 'type': 'expression_statement', 'children': ['326']}; {'id': '326', 'type': 'assignment', 'children': ['327', '334']}; {'id': '327', 'type': 'subscript', 'children': ['328', '333']}; {'id': '328', 'type': 'subscript', 'children': ['329', '332']}; {'id': '329', 'type': 'attribute', 'children': ['330', '331']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '331', 'type': 'identifier', 'children': [], 'value': 'vts'}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'vt_id'}; {'id': '333', 'type': 'string', 'children': [], 'value': '"qod"'}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'qod_v'}; {'id': '335', 'type': 'if_statement', 'children': ['336', '339']}; {'id': '336', 'type': 'comparison_operator', 'children': ['337', '338'], 'value': 'is'}; {'id': '337', 'type': 'identifier', 'children': [], 'value': 'severities'}; {'id': '338', 'type': 'None', 'children': []}; {'id': '339', 'type': 'block', 'children': ['340']}; {'id': '340', 'type': 'expression_statement', 'children': ['341']}; {'id': '341', 'type': 'assignment', 'children': ['342', '349']}; {'id': '342', 'type': 'subscript', 'children': ['343', '348']}; {'id': '343', 'type': 'subscript', 'children': ['344', '347']}; {'id': '344', 'type': 'attribute', 'children': ['345', '346']}; {'id': '345', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'vts'}; {'id': '347', 'type': 'identifier', 'children': [], 'value': 'vt_id'}; {'id': '348', 'type': 'string', 'children': [], 'value': '"severities"'}; {'id': '349', 'type': 'identifier', 'children': [], 'value': 'severities'}; {'id': '350', 'type': 'return_statement', 'children': ['351']}; {'id': '351', 'type': 'call', 'children': ['352', '353']}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '353', 'type': 'argument_list', 'children': ['354']}; {'id': '354', 'type': 'attribute', 'children': ['355', '356']}; {'id': '355', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'vts'}
|
def add_vt(self, vt_id, name=None, vt_params=None, vt_refs=None,
custom=None, vt_creation_time=None, vt_modification_time=None,
vt_dependencies=None, summary=None, impact=None, affected=None,
insight=None, solution=None, solution_t=None, detection=None,
qod_t=None, qod_v=None, severities=None):
if not vt_id:
return -2
if self.vt_id_pattern.fullmatch(vt_id) is None:
return -2
if vt_id in self.vts:
return -1
if name is None:
name = ''
self.vts[vt_id] = {'name': name}
if custom is not None:
self.vts[vt_id]["custom"] = custom
if vt_params is not None:
self.vts[vt_id]["vt_params"] = vt_params
if vt_refs is not None:
self.vts[vt_id]["vt_refs"] = vt_refs
if vt_dependencies is not None:
self.vts[vt_id]["vt_dependencies"] = vt_dependencies
if vt_creation_time is not None:
self.vts[vt_id]["creation_time"] = vt_creation_time
if vt_modification_time is not None:
self.vts[vt_id]["modification_time"] = vt_modification_time
if summary is not None:
self.vts[vt_id]["summary"] = summary
if impact is not None:
self.vts[vt_id]["impact"] = impact
if affected is not None:
self.vts[vt_id]["affected"] = affected
if insight is not None:
self.vts[vt_id]["insight"] = insight
if solution is not None:
self.vts[vt_id]["solution"] = solution
if solution_t is not None:
self.vts[vt_id]["solution_type"] = solution_t
if detection is not None:
self.vts[vt_id]["detection"] = detection
if qod_t is not None:
self.vts[vt_id]["qod_type"] = qod_t
elif qod_v is not None:
self.vts[vt_id]["qod"] = qod_v
if severities is not None:
self.vts[vt_id]["severities"] = severities
return len(self.vts)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_preprocess_scan_params'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'xml_params'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '27', '74', '201']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '10', 'type': 'dictionary', 'children': []}; {'id': '11', 'type': 'for_statement', 'children': ['12', '13', '14']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'xml_params'}; {'id': '14', 'type': 'block', 'children': ['15']}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '22']}; {'id': '17', 'type': 'subscript', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '22', 'type': 'boolean_operator', 'children': ['23', '26'], 'value': 'or'}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '26', 'type': 'string', 'children': [], 'value': "''"}; {'id': '27', 'type': 'for_statement', 'children': ['28', '29', '32']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'scanner_params'}; {'id': '32', 'type': 'block', 'children': ['33']}; {'id': '33', 'type': 'if_statement', 'children': ['34', '37']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': 'not'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '37', 'type': 'block', 'children': ['38', '49']}; {'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': 'params'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'key'}; {'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': 'get_scanner_param_default'}; {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '49', 'type': 'if_statement', 'children': ['50', '58']}; {'id': '50', 'type': 'comparison_operator', 'children': ['51', '57'], 'value': '=='}; {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'get_scanner_param_type'}; {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '57', 'type': 'string', 'children': [], 'value': "'selection'"}; {'id': '58', 'type': 'block', 'children': ['59']}; {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '64']}; {'id': '61', 'type': 'subscript', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '64', 'type': 'subscript', 'children': ['65', '73']}; {'id': '65', 'type': 'call', 'children': ['66', '71']}; {'id': '66', 'type': 'attribute', 'children': ['67', '70']}; {'id': '67', 'type': 'subscript', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'string', 'children': [], 'value': "'|'"}; {'id': '73', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '74', 'type': 'for_statement', 'children': ['75', '76', '77']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '77', 'type': 'block', 'children': ['78', '87', '92', '123', '179']}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}; {'id': '79', 'type': 'assignment', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'param_type'}; {'id': '81', 'type': 'call', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'get_scanner_param_type'}; {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '87', 'type': 'if_statement', 'children': ['88', '90']}; {'id': '88', 'type': 'not_operator', 'children': ['89']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'param_type'}; {'id': '90', 'type': 'block', 'children': ['91']}; {'id': '91', 'type': 'continue_statement', 'children': []}; {'id': '92', 'type': 'if_statement', 'children': ['93', '98']}; {'id': '93', 'type': 'comparison_operator', 'children': ['94', '95'], 'value': 'in'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'param_type'}; {'id': '95', 'type': 'list', 'children': ['96', '97'], 'value': "['integer', 'boolean']"}; {'id': '96', 'type': 'string', 'children': [], 'value': "'integer'"}; {'id': '97', 'type': 'string', 'children': [], 'value': "'boolean'"}; {'id': '98', 'type': 'block', 'children': ['99']}; {'id': '99', 'type': 'try_statement', 'children': ['100', '112']}; {'id': '100', 'type': 'block', 'children': ['101']}; {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '106']}; {'id': '103', 'type': 'subscript', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '106', 'type': 'call', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}; {'id': '109', 'type': 'subscript', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '112', 'type': 'except_clause', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '114', 'type': 'block', 'children': ['115']}; {'id': '115', 'type': 'raise_statement', 'children': ['116']}; {'id': '116', 'type': 'call', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'OSPDError'}; {'id': '118', 'type': 'argument_list', 'children': ['119', '122']}; {'id': '119', 'type': 'binary_operator', 'children': ['120', '121'], 'value': '%'}; {'id': '120', 'type': 'string', 'children': [], 'value': "'Invalid %s value'"}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '122', 'type': 'string', 'children': [], 'value': "'start_scan'"}; {'id': '123', 'type': 'if_statement', 'children': ['124', '127', '145']}; {'id': '124', 'type': 'comparison_operator', 'children': ['125', '126'], 'value': '=='}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'param_type'}; {'id': '126', 'type': 'string', 'children': [], 'value': "'boolean'"}; {'id': '127', 'type': 'block', 'children': ['128']}; {'id': '128', 'type': 'if_statement', 'children': ['129', '136']}; {'id': '129', 'type': 'comparison_operator', 'children': ['130', '133'], 'value': 'not'}; {'id': '130', 'type': 'subscript', 'children': ['131', '132']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '133', 'type': 'list', 'children': ['134', '135'], 'value': '[0, 1]'}; {'id': '134', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '135', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '136', 'type': 'block', 'children': ['137']}; {'id': '137', 'type': 'raise_statement', 'children': ['138']}; {'id': '138', 'type': 'call', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'OSPDError'}; {'id': '140', 'type': 'argument_list', 'children': ['141', '144']}; {'id': '141', 'type': 'binary_operator', 'children': ['142', '143'], 'value': '%'}; {'id': '142', 'type': 'string', 'children': [], 'value': "'Invalid %s value'"}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '144', 'type': 'string', 'children': [], 'value': "'start_scan'"}; {'id': '145', 'type': 'elif_clause', 'children': ['146', '149']}; {'id': '146', 'type': 'comparison_operator', 'children': ['147', '148'], 'value': '=='}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'param_type'}; {'id': '148', 'type': 'string', 'children': [], 'value': "'selection'"}; {'id': '149', 'type': 'block', 'children': ['150', '164']}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}; {'id': '151', 'type': 'assignment', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'selection'}; {'id': '153', 'type': 'call', 'children': ['154', '162']}; {'id': '154', 'type': 'attribute', 'children': ['155', '161']}; {'id': '155', 'type': 'call', 'children': ['156', '159']}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'get_scanner_param_default'}; {'id': '159', 'type': 'argument_list', 'children': ['160']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '162', 'type': 'argument_list', 'children': ['163']}; {'id': '163', 'type': 'string', 'children': [], 'value': "'|'"}; {'id': '164', 'type': 'if_statement', 'children': ['165', '170']}; {'id': '165', 'type': 'comparison_operator', 'children': ['166', '169'], 'value': 'not'}; {'id': '166', 'type': 'subscript', 'children': ['167', '168']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'selection'}; {'id': '170', 'type': 'block', 'children': ['171']}; {'id': '171', 'type': 'raise_statement', 'children': ['172']}; {'id': '172', 'type': 'call', 'children': ['173', '174']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'OSPDError'}; {'id': '174', 'type': 'argument_list', 'children': ['175', '178']}; {'id': '175', 'type': 'binary_operator', 'children': ['176', '177'], 'value': '%'}; {'id': '176', 'type': 'string', 'children': [], 'value': "'Invalid %s value'"}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '178', 'type': 'string', 'children': [], 'value': "'start_scan'"}; {'id': '179', 'type': 'if_statement', 'children': ['180', '192']}; {'id': '180', 'type': 'boolean_operator', 'children': ['181', '187'], 'value': 'and'}; {'id': '181', 'type': 'call', 'children': ['182', '185']}; {'id': '182', 'type': 'attribute', 'children': ['183', '184']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'get_scanner_param_mandatory'}; {'id': '185', 'type': 'argument_list', 'children': ['186']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '187', 'type': 'comparison_operator', 'children': ['188', '191'], 'value': '=='}; {'id': '188', 'type': 'subscript', 'children': ['189', '190']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '191', 'type': 'string', 'children': [], 'value': "''"}; {'id': '192', 'type': 'block', 'children': ['193']}; {'id': '193', 'type': 'raise_statement', 'children': ['194']}; {'id': '194', 'type': 'call', 'children': ['195', '196']}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'OSPDError'}; {'id': '196', 'type': 'argument_list', 'children': ['197', '200']}; {'id': '197', 'type': 'binary_operator', 'children': ['198', '199'], 'value': '%'}; {'id': '198', 'type': 'string', 'children': [], 'value': "'Mandatory %s value is missing'"}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '200', 'type': 'string', 'children': [], 'value': "'start_scan'"}; {'id': '201', 'type': 'return_statement', 'children': ['202']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'params'}
|
def _preprocess_scan_params(self, xml_params):
params = {}
for param in xml_params:
params[param.tag] = param.text or ''
for key in self.scanner_params:
if key not in params:
params[key] = self.get_scanner_param_default(key)
if self.get_scanner_param_type(key) == 'selection':
params[key] = params[key].split('|')[0]
for key in params:
param_type = self.get_scanner_param_type(key)
if not param_type:
continue
if param_type in ['integer', 'boolean']:
try:
params[key] = int(params[key])
except ValueError:
raise OSPDError('Invalid %s value' % key, 'start_scan')
if param_type == 'boolean':
if params[key] not in [0, 1]:
raise OSPDError('Invalid %s value' % key, 'start_scan')
elif param_type == 'selection':
selection = self.get_scanner_param_default(key).split('|')
if params[key] not in selection:
raise OSPDError('Invalid %s value' % key, 'start_scan')
if self.get_scanner_param_mandatory(key) and params[key] == '':
raise OSPDError('Mandatory %s value is missing' % key,
'start_scan')
return params
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'start_scan'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'scan_id'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'targets'}; {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'parallel'}; {'id': '9', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '10', 'type': 'block', 'children': ['11', '17', '21', '29', '33', '47', '171', '211']}; {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'call', 'children': ['13', '16']}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'setsid'}; {'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': 'multiscan_proc'}; {'id': '20', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'call', 'children': ['23', '26']}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '26', 'type': 'argument_list', 'children': ['27', '28']}; {'id': '27', 'type': 'string', 'children': [], 'value': '"%s: Scan started."'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'scan_id'}; {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'target_list'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'targets'}; {'id': '33', 'type': 'if_statement', 'children': ['34', '40']}; {'id': '34', 'type': 'boolean_operator', 'children': ['35', '38'], 'value': 'or'}; {'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': 'is'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'target_list'}; {'id': '37', 'type': 'None', 'children': []}; {'id': '38', 'type': 'not_operator', 'children': ['39']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'target_list'}; {'id': '40', 'type': 'block', 'children': ['41']}; {'id': '41', 'type': 'raise_statement', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'OSPDError'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '46']}; {'id': '45', 'type': 'string', 'children': [], 'value': "'Erroneous targets list'"}; {'id': '46', 'type': 'string', 'children': [], 'value': "'start_scan'"}; {'id': '47', 'type': 'for_statement', 'children': ['48', '51', '55']}; {'id': '48', 'type': 'pattern_list', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'target_list'}; {'id': '55', 'type': 'block', 'children': ['56', '98', '111', '124', '144', '155', '161']}; {'id': '56', 'type': 'while_statement', 'children': ['57', '63']}; {'id': '57', 'type': 'comparison_operator', 'children': ['58', '62'], 'value': '>='}; {'id': '58', 'type': 'call', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'multiscan_proc'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'parallel'}; {'id': '63', 'type': 'block', 'children': ['64', '73', '81', '91']}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}; {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'progress'}; {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'calculate_progress'}; {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'scan_id'}; {'id': '73', 'type': 'expression_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': 'set_scan_progress'}; {'id': '78', 'type': 'argument_list', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'scan_id'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'progress'}; {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'multiscan_proc'}; {'id': '84', 'type': 'call', 'children': ['85', '88']}; {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'check_pending_target'}; {'id': '88', 'type': 'argument_list', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'scan_id'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'multiscan_proc'}; {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '96']}; {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'sleep'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}; {'id': '97', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '98', 'type': 'if_statement', 'children': ['99', '109']}; {'id': '99', 'type': 'comparison_operator', 'children': ['100', '106'], 'value': '=='}; {'id': '100', 'type': 'call', 'children': ['101', '104']}; {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'get_scan_status'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'scan_id'}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'ScanStatus'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'STOPPED'}; {'id': '109', 'type': 'block', 'children': ['110']}; {'id': '110', 'type': 'return_statement', 'children': []}; {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'call', 'children': ['113', '116']}; {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '116', 'type': 'argument_list', 'children': ['117', '118', '121']}; {'id': '117', 'type': 'string', 'children': [], 'value': '"%s: Host scan started on ports %s."'}; {'id': '118', 'type': 'subscript', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '120', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '121', 'type': 'subscript', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '123', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}; {'id': '125', 'type': 'assignment', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'scan_process'}; {'id': '127', 'type': 'call', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'multiprocessing'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'Process'}; {'id': '131', 'type': 'argument_list', 'children': ['132', '137']}; {'id': '132', 'type': 'keyword_argument', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'parallel_scan'}; {'id': '137', 'type': 'keyword_argument', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '139', 'type': 'tuple', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'scan_id'}; {'id': '141', 'type': 'subscript', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '143', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}; {'id': '145', 'type': 'call', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'multiscan_proc'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '149', 'type': 'argument_list', 'children': ['150']}; {'id': '150', 'type': 'tuple', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'scan_process'}; {'id': '152', 'type': 'subscript', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '154', 'type': 'integer', 'children': [], 'value': '0'}; {'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': 'scan_process'}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '160', 'type': 'argument_list', 'children': []}; {'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': 'self'}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'set_scan_status'}; {'id': '166', 'type': 'argument_list', 'children': ['167', '168']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'scan_id'}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'ScanStatus'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'RUNNING'}; {'id': '171', 'type': 'while_statement', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'multiscan_proc'}; {'id': '173', 'type': 'block', 'children': ['174', '184', '204']}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}; {'id': '175', 'type': 'assignment', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'multiscan_proc'}; {'id': '177', 'type': 'call', 'children': ['178', '181']}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'check_pending_target'}; {'id': '181', 'type': 'argument_list', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'scan_id'}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'multiscan_proc'}; {'id': '184', 'type': 'if_statement', 'children': ['185', '186']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'multiscan_proc'}; {'id': '186', 'type': 'block', 'children': ['187', '196']}; {'id': '187', 'type': 'expression_statement', 'children': ['188']}; {'id': '188', 'type': 'assignment', 'children': ['189', '190']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'progress'}; {'id': '190', 'type': 'call', 'children': ['191', '194']}; {'id': '191', 'type': 'attribute', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'calculate_progress'}; {'id': '194', 'type': 'argument_list', 'children': ['195']}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'scan_id'}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}; {'id': '197', 'type': 'call', 'children': ['198', '201']}; {'id': '198', 'type': 'attribute', 'children': ['199', '200']}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'set_scan_progress'}; {'id': '201', 'type': 'argument_list', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'scan_id'}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'progress'}; {'id': '204', 'type': 'expression_statement', 'children': ['205']}; {'id': '205', 'type': 'call', 'children': ['206', '209']}; {'id': '206', 'type': 'attribute', 'children': ['207', '208']}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'sleep'}; {'id': '209', 'type': 'argument_list', 'children': ['210']}; {'id': '210', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '211', 'type': 'if_statement', 'children': ['212', '222']}; {'id': '212', 'type': 'comparison_operator', 'children': ['213', '219'], 'value': '!='}; {'id': '213', 'type': 'call', 'children': ['214', '217']}; {'id': '214', 'type': 'attribute', 'children': ['215', '216']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'get_scan_status'}; {'id': '217', 'type': 'argument_list', 'children': ['218']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'scan_id'}; {'id': '219', 'type': 'attribute', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'ScanStatus'}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'STOPPED'}; {'id': '222', 'type': 'block', 'children': ['223']}; {'id': '223', 'type': 'expression_statement', 'children': ['224']}; {'id': '224', 'type': 'call', 'children': ['225', '228']}; {'id': '225', 'type': 'attribute', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'finish_scan'}; {'id': '228', 'type': 'argument_list', 'children': ['229']}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'scan_id'}
|
def start_scan(self, scan_id, targets, parallel=1):
os.setsid()
multiscan_proc = []
logger.info("%s: Scan started.", scan_id)
target_list = targets
if target_list is None or not target_list:
raise OSPDError('Erroneous targets list', 'start_scan')
for index, target in enumerate(target_list):
while len(multiscan_proc) >= parallel:
progress = self.calculate_progress(scan_id)
self.set_scan_progress(scan_id, progress)
multiscan_proc = self.check_pending_target(scan_id,
multiscan_proc)
time.sleep(1)
if self.get_scan_status(scan_id) == ScanStatus.STOPPED:
return
logger.info("%s: Host scan started on ports %s.", target[0], target[1])
scan_process = multiprocessing.Process(target=self.parallel_scan,
args=(scan_id, target[0]))
multiscan_proc.append((scan_process, target[0]))
scan_process.start()
self.set_scan_status(scan_id, ScanStatus.RUNNING)
while multiscan_proc:
multiscan_proc = self.check_pending_target(scan_id, multiscan_proc)
if multiscan_proc:
progress = self.calculate_progress(scan_id)
self.set_scan_progress(scan_id, progress)
time.sleep(1)
if self.get_scan_status(scan_id) != ScanStatus.STOPPED:
self.finish_scan(scan_id)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'ports_as_list'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'port_str'}; {'id': '5', 'type': 'block', 'children': ['6', '21', '38', '44', '50', '60', '69', '78', '103', '128', '135', '139', '143', '248', '293', '338']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '9']}; {'id': '7', 'type': 'not_operator', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'port_str'}; {'id': '9', 'type': 'block', 'children': ['10', '17']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}; {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'LOGGER'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'string', 'children': [], 'value': '"Invalid port value"'}; {'id': '17', 'type': 'return_statement', 'children': ['18']}; {'id': '18', 'type': 'list', 'children': ['19', '20'], 'value': '[None, None]'}; {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'None', 'children': []}; {'id': '21', 'type': 'if_statement', 'children': ['22', '26']}; {'id': '22', 'type': 'call', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'ports_str_check_failed'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'port_str'}; {'id': '26', 'type': 'block', 'children': ['27', '34']}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '32']}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'LOGGER'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}; {'id': '33', 'type': 'string', 'children': [], 'value': '"{0}: Port list malformed."'}; {'id': '34', 'type': 'return_statement', 'children': ['35']}; {'id': '35', 'type': 'list', 'children': ['36', '37'], 'value': '[None, None]'}; {'id': '36', 'type': 'None', 'children': []}; {'id': '37', 'type': 'None', 'children': []}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}; {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'tcp_list'}; {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '43', 'type': 'argument_list', 'children': []}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}; {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'udp_list'}; {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '49', 'type': 'argument_list', 'children': []}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}; {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'ports'}; {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'port_str'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '57', 'type': 'argument_list', 'children': ['58', '59']}; {'id': '58', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '59', 'type': 'string', 'children': [], 'value': "''"}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}; {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'b_tcp'}; {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'ports'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'find'}; {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'string', 'children': [], 'value': '"T"'}; {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'b_udp'}; {'id': '72', 'type': 'call', 'children': ['73', '76']}; {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'ports'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'find'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}; {'id': '77', 'type': 'string', 'children': [], 'value': '"U"'}; {'id': '78', 'type': 'if_statement', 'children': ['79', '86']}; {'id': '79', 'type': 'comparison_operator', 'children': ['80', '85'], 'value': '=='}; {'id': '80', 'type': 'subscript', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'ports'}; {'id': '82', 'type': 'binary_operator', 'children': ['83', '84'], 'value': '-'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'b_tcp'}; {'id': '84', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '85', 'type': 'string', 'children': [], 'value': "','"}; {'id': '86', 'type': 'block', 'children': ['87']}; {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'ports'}; {'id': '90', 'type': 'binary_operator', 'children': ['91', '98'], 'value': '+'}; {'id': '91', 'type': 'subscript', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'ports'}; {'id': '93', 'type': 'slice', 'children': ['94', '95']}; {'id': '94', 'type': 'colon', 'children': []}; {'id': '95', 'type': 'binary_operator', 'children': ['96', '97'], 'value': '-'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'b_tcp'}; {'id': '97', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '98', 'type': 'subscript', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'ports'}; {'id': '100', 'type': 'slice', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'b_tcp'}; {'id': '102', 'type': 'colon', 'children': []}; {'id': '103', 'type': 'if_statement', 'children': ['104', '111']}; {'id': '104', 'type': 'comparison_operator', 'children': ['105', '110'], 'value': '=='}; {'id': '105', 'type': 'subscript', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'ports'}; {'id': '107', 'type': 'binary_operator', 'children': ['108', '109'], 'value': '-'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'b_udp'}; {'id': '109', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '110', 'type': 'string', 'children': [], 'value': "','"}; {'id': '111', 'type': 'block', 'children': ['112']}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}; {'id': '113', 'type': 'assignment', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'ports'}; {'id': '115', 'type': 'binary_operator', 'children': ['116', '123'], 'value': '+'}; {'id': '116', 'type': 'subscript', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'ports'}; {'id': '118', 'type': 'slice', 'children': ['119', '120']}; {'id': '119', 'type': 'colon', 'children': []}; {'id': '120', 'type': 'binary_operator', 'children': ['121', '122'], 'value': '-'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'b_udp'}; {'id': '122', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '123', 'type': 'subscript', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'ports'}; {'id': '125', 'type': 'slice', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'b_udp'}; {'id': '127', 'type': 'colon', 'children': []}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}; {'id': '129', 'type': 'assignment', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'ports'}; {'id': '131', 'type': 'call', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'port_str_arrange'}; {'id': '133', 'type': 'argument_list', 'children': ['134']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'ports'}; {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'assignment', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'tports'}; {'id': '138', 'type': 'string', 'children': [], 'value': "''"}; {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'assignment', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'uports'}; {'id': '142', 'type': 'string', 'children': [], 'value': "''"}; {'id': '143', 'type': 'if_statement', 'children': ['144', '153', '190', '216', '242']}; {'id': '144', 'type': 'boolean_operator', 'children': ['145', '149'], 'value': 'and'}; {'id': '145', 'type': 'comparison_operator', 'children': ['146', '147'], 'value': '!='}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'b_udp'}; {'id': '147', 'type': 'unary_operator', 'children': ['148'], 'value': '-'}; {'id': '148', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '149', 'type': 'comparison_operator', 'children': ['150', '151'], 'value': '!='}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'b_tcp'}; {'id': '151', 'type': 'unary_operator', 'children': ['152'], 'value': '-'}; {'id': '152', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '153', 'type': 'block', 'children': ['154', '175']}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}; {'id': '155', 'type': 'assignment', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'tports'}; {'id': '157', 'type': 'subscript', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'ports'}; {'id': '159', 'type': 'slice', 'children': ['160', '168', '169']}; {'id': '160', 'type': 'binary_operator', 'children': ['161', '167'], 'value': '+'}; {'id': '161', 'type': 'call', 'children': ['162', '165']}; {'id': '162', 'type': 'attribute', 'children': ['163', '164']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'ports'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '165', 'type': 'argument_list', 'children': ['166']}; {'id': '166', 'type': 'string', 'children': [], 'value': "'T:'"}; {'id': '167', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '168', 'type': 'colon', 'children': []}; {'id': '169', 'type': 'call', 'children': ['170', '173']}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'ports'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'string', 'children': [], 'value': "'U:'"}; {'id': '175', 'type': 'expression_statement', 'children': ['176']}; {'id': '176', 'type': 'assignment', 'children': ['177', '178']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'uports'}; {'id': '178', 'type': 'subscript', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'ports'}; {'id': '180', 'type': 'slice', 'children': ['181', '189']}; {'id': '181', 'type': 'binary_operator', 'children': ['182', '188'], 'value': '+'}; {'id': '182', 'type': 'call', 'children': ['183', '186']}; {'id': '183', 'type': 'attribute', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'ports'}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '186', 'type': 'argument_list', 'children': ['187']}; {'id': '187', 'type': 'string', 'children': [], 'value': "'U:'"}; {'id': '188', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '189', 'type': 'colon', 'children': []}; {'id': '190', 'type': 'elif_clause', 'children': ['191', '200']}; {'id': '191', 'type': 'boolean_operator', 'children': ['192', '196'], 'value': 'and'}; {'id': '192', 'type': 'comparison_operator', 'children': ['193', '194'], 'value': '=='}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'b_tcp'}; {'id': '194', 'type': 'unary_operator', 'children': ['195'], 'value': '-'}; {'id': '195', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '196', 'type': 'comparison_operator', 'children': ['197', '198'], 'value': '!='}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'b_udp'}; {'id': '198', 'type': 'unary_operator', 'children': ['199'], 'value': '-'}; {'id': '199', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '200', 'type': 'block', 'children': ['201']}; {'id': '201', 'type': 'expression_statement', 'children': ['202']}; {'id': '202', 'type': 'assignment', 'children': ['203', '204']}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'uports'}; {'id': '204', 'type': 'subscript', 'children': ['205', '206']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'ports'}; {'id': '206', 'type': 'slice', 'children': ['207', '215']}; {'id': '207', 'type': 'binary_operator', 'children': ['208', '214'], 'value': '+'}; {'id': '208', 'type': 'call', 'children': ['209', '212']}; {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'ports'}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '212', 'type': 'argument_list', 'children': ['213']}; {'id': '213', 'type': 'string', 'children': [], 'value': "'U:'"}; {'id': '214', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '215', 'type': 'colon', 'children': []}; {'id': '216', 'type': 'elif_clause', 'children': ['217', '226']}; {'id': '217', 'type': 'boolean_operator', 'children': ['218', '222'], 'value': 'and'}; {'id': '218', 'type': 'comparison_operator', 'children': ['219', '220'], 'value': '=='}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'b_udp'}; {'id': '220', 'type': 'unary_operator', 'children': ['221'], 'value': '-'}; {'id': '221', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '222', 'type': 'comparison_operator', 'children': ['223', '224'], 'value': '!='}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'b_tcp'}; {'id': '224', 'type': 'unary_operator', 'children': ['225'], 'value': '-'}; {'id': '225', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '226', 'type': 'block', 'children': ['227']}; {'id': '227', 'type': 'expression_statement', 'children': ['228']}; {'id': '228', 'type': 'assignment', 'children': ['229', '230']}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'tports'}; {'id': '230', 'type': 'subscript', 'children': ['231', '232']}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'ports'}; {'id': '232', 'type': 'slice', 'children': ['233', '241']}; {'id': '233', 'type': 'binary_operator', 'children': ['234', '240'], 'value': '+'}; {'id': '234', 'type': 'call', 'children': ['235', '238']}; {'id': '235', 'type': 'attribute', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'ports'}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '238', 'type': 'argument_list', 'children': ['239']}; {'id': '239', 'type': 'string', 'children': [], 'value': "'T:'"}; {'id': '240', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '241', 'type': 'colon', 'children': []}; {'id': '242', 'type': 'else_clause', 'children': ['243']}; {'id': '243', 'type': 'block', 'children': ['244']}; {'id': '244', 'type': 'expression_statement', 'children': ['245']}; {'id': '245', 'type': 'assignment', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'tports'}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'ports'}; {'id': '248', 'type': 'if_statement', 'children': ['249', '250']}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'tports'}; {'id': '250', 'type': 'block', 'children': ['251', '287']}; {'id': '251', 'type': 'for_statement', 'children': ['252', '253', '259']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'port'}; {'id': '253', 'type': 'call', 'children': ['254', '257']}; {'id': '254', 'type': 'attribute', 'children': ['255', '256']}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'tports'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '257', 'type': 'argument_list', 'children': ['258']}; {'id': '258', 'type': 'string', 'children': [], 'value': "','"}; {'id': '259', 'type': 'block', 'children': ['260']}; {'id': '260', 'type': 'if_statement', 'children': ['261', '264', '275']}; {'id': '261', 'type': 'comparison_operator', 'children': ['262', '263'], 'value': 'in'}; {'id': '262', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'port'}; {'id': '264', 'type': 'block', 'children': ['265']}; {'id': '265', 'type': 'expression_statement', 'children': ['266']}; {'id': '266', 'type': 'call', 'children': ['267', '270']}; {'id': '267', 'type': 'attribute', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'tcp_list'}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '270', 'type': 'argument_list', 'children': ['271']}; {'id': '271', 'type': 'call', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'port_range_expand'}; {'id': '273', 'type': 'argument_list', 'children': ['274']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'port'}; {'id': '275', 'type': 'else_clause', 'children': ['276']}; {'id': '276', 'type': 'block', 'children': ['277']}; {'id': '277', 'type': 'expression_statement', 'children': ['278']}; {'id': '278', 'type': 'call', 'children': ['279', '282']}; {'id': '279', 'type': 'attribute', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'tcp_list'}; {'id': '281', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '282', 'type': 'argument_list', 'children': ['283']}; {'id': '283', 'type': 'call', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '285', 'type': 'argument_list', 'children': ['286']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'port'}; {'id': '287', 'type': 'expression_statement', 'children': ['288']}; {'id': '288', 'type': 'call', 'children': ['289', '292']}; {'id': '289', 'type': 'attribute', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'tcp_list'}; {'id': '291', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '292', 'type': 'argument_list', 'children': []}; {'id': '293', 'type': 'if_statement', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'uports'}; {'id': '295', 'type': 'block', 'children': ['296', '332']}; {'id': '296', 'type': 'for_statement', 'children': ['297', '298', '304']}; {'id': '297', 'type': 'identifier', 'children': [], 'value': 'port'}; {'id': '298', 'type': 'call', 'children': ['299', '302']}; {'id': '299', 'type': 'attribute', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'uports'}; {'id': '301', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '302', 'type': 'argument_list', 'children': ['303']}; {'id': '303', 'type': 'string', 'children': [], 'value': "','"}; {'id': '304', 'type': 'block', 'children': ['305']}; {'id': '305', 'type': 'if_statement', 'children': ['306', '309', '320']}; {'id': '306', 'type': 'comparison_operator', 'children': ['307', '308'], 'value': 'in'}; {'id': '307', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'port'}; {'id': '309', 'type': 'block', 'children': ['310']}; {'id': '310', 'type': 'expression_statement', 'children': ['311']}; {'id': '311', 'type': 'call', 'children': ['312', '315']}; {'id': '312', 'type': 'attribute', 'children': ['313', '314']}; {'id': '313', 'type': 'identifier', 'children': [], 'value': 'udp_list'}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '315', 'type': 'argument_list', 'children': ['316']}; {'id': '316', 'type': 'call', 'children': ['317', '318']}; {'id': '317', 'type': 'identifier', 'children': [], 'value': 'port_range_expand'}; {'id': '318', 'type': 'argument_list', 'children': ['319']}; {'id': '319', 'type': 'identifier', 'children': [], 'value': 'port'}; {'id': '320', 'type': 'else_clause', 'children': ['321']}; {'id': '321', 'type': 'block', 'children': ['322']}; {'id': '322', 'type': 'expression_statement', 'children': ['323']}; {'id': '323', 'type': 'call', 'children': ['324', '327']}; {'id': '324', 'type': 'attribute', 'children': ['325', '326']}; {'id': '325', 'type': 'identifier', 'children': [], 'value': 'udp_list'}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '327', 'type': 'argument_list', 'children': ['328']}; {'id': '328', 'type': 'call', 'children': ['329', '330']}; {'id': '329', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '330', 'type': 'argument_list', 'children': ['331']}; {'id': '331', 'type': 'identifier', 'children': [], 'value': 'port'}; {'id': '332', 'type': 'expression_statement', 'children': ['333']}; {'id': '333', 'type': 'call', 'children': ['334', '337']}; {'id': '334', 'type': 'attribute', 'children': ['335', '336']}; {'id': '335', 'type': 'identifier', 'children': [], 'value': 'udp_list'}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '337', 'type': 'argument_list', 'children': []}; {'id': '338', 'type': 'return_statement', 'children': ['339']}; {'id': '339', 'type': 'tuple', 'children': ['340', '341']}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'tcp_list'}; {'id': '341', 'type': 'identifier', 'children': [], 'value': 'udp_list'}
|
def ports_as_list(port_str):
if not port_str:
LOGGER.info("Invalid port value")
return [None, None]
if ports_str_check_failed(port_str):
LOGGER.info("{0}: Port list malformed.")
return [None, None]
tcp_list = list()
udp_list = list()
ports = port_str.replace(' ', '')
b_tcp = ports.find("T")
b_udp = ports.find("U")
if ports[b_tcp - 1] == ',':
ports = ports[:b_tcp - 1] + ports[b_tcp:]
if ports[b_udp - 1] == ',':
ports = ports[:b_udp - 1] + ports[b_udp:]
ports = port_str_arrange(ports)
tports = ''
uports = ''
if b_udp != -1 and b_tcp != -1:
tports = ports[ports.index('T:') + 2:ports.index('U:')]
uports = ports[ports.index('U:') + 2:]
elif b_tcp == -1 and b_udp != -1:
uports = ports[ports.index('U:') + 2:]
elif b_udp == -1 and b_tcp != -1:
tports = ports[ports.index('T:') + 2:]
else:
tports = ports
if tports:
for port in tports.split(','):
if '-' in port:
tcp_list.extend(port_range_expand(port))
else:
tcp_list.append(int(port))
tcp_list.sort()
if uports:
for port in uports.split(','):
if '-' in port:
udp_list.extend(port_range_expand(port))
else:
udp_list.append(int(port))
udp_list.sort()
return (tcp_list, udp_list)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'create_args_parser'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'description'}; {'id': '5', 'type': 'block', 'children': ['6', '17', '45', '174', '209', '236', '258', '277', '288', '307', '326', '344', '361', '374', '388', '401']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'parser'}; {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'argparse'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'ArgumentParser'}; {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'keyword_argument', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'description'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'description'}; {'id': '17', 'type': 'function_definition', 'children': ['18', '19', '21']}; {'id': '18', 'type': 'function_name', 'children': [], 'value': 'network_port'}; {'id': '19', 'type': 'parameters', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'string'}; {'id': '21', 'type': 'block', 'children': ['22', '29', '43']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'string'}; {'id': '29', 'type': 'if_statement', 'children': ['30', '35']}; {'id': '30', 'type': 'not_operator', 'children': ['31']}; {'id': '31', 'type': 'comparison_operator', 'children': ['32', '33', '34'], 'value': '<'}; {'id': '32', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '34', 'type': 'integer', 'children': [], 'value': '65535'}; {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'raise_statement', 'children': ['37']}; {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'argparse'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'ArgumentTypeError'}; {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'string', 'children': [], 'value': "'port must be in ]0,65535] interval'"}; {'id': '43', 'type': 'return_statement', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '45', 'type': 'function_definition', 'children': ['46', '47', '49']}; {'id': '46', 'type': 'function_name', 'children': [], 'value': 'cacert_file'}; {'id': '47', 'type': 'parameters', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'cacert'}; {'id': '49', 'type': 'block', 'children': ['50', '78', '134', '153', '172']}; {'id': '50', 'type': 'try_statement', 'children': ['51', '63', '68']}; {'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': 'context'}; {'id': '55', 'type': 'call', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'ssl'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'create_default_context'}; {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'keyword_argument', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'cafile'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'cacert'}; {'id': '63', 'type': 'except_clause', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}; {'id': '65', 'type': 'block', 'children': ['66']}; {'id': '66', 'type': 'return_statement', 'children': ['67']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'cacert'}; {'id': '68', 'type': 'except_clause', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'IOError'}; {'id': '70', 'type': 'block', 'children': ['71']}; {'id': '71', 'type': 'raise_statement', 'children': ['72']}; {'id': '72', 'type': 'call', 'children': ['73', '76']}; {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'argparse'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'ArgumentTypeError'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}; {'id': '77', 'type': 'string', 'children': [], 'value': "'CA Certificate not found'"}; {'id': '78', 'type': 'try_statement', 'children': ['79', '122']}; {'id': '79', 'type': 'block', 'children': ['80', '92', '101', '113']}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}; {'id': '81', 'type': 'assignment', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'not_after'}; {'id': '83', 'type': 'subscript', 'children': ['84', '91']}; {'id': '84', 'type': 'subscript', 'children': ['85', '90']}; {'id': '85', 'type': 'call', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'get_ca_certs'}; {'id': '89', 'type': 'argument_list', 'children': []}; {'id': '90', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '91', 'type': 'string', 'children': [], 'value': "'notAfter'"}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}; {'id': '93', 'type': 'assignment', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'not_after'}; {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'ssl'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'cert_time_to_seconds'}; {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'not_after'}; {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'not_before'}; {'id': '104', 'type': 'subscript', 'children': ['105', '112']}; {'id': '105', 'type': 'subscript', 'children': ['106', '111']}; {'id': '106', 'type': 'call', 'children': ['107', '110']}; {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'get_ca_certs'}; {'id': '110', 'type': 'argument_list', 'children': []}; {'id': '111', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '112', 'type': 'string', 'children': [], 'value': "'notBefore'"}; {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'not_before'}; {'id': '116', 'type': 'call', 'children': ['117', '120']}; {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'ssl'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'cert_time_to_seconds'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'not_before'}; {'id': '122', 'type': 'except_clause', 'children': ['123', '126']}; {'id': '123', 'type': 'tuple', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'IndexError'}; {'id': '126', 'type': 'block', 'children': ['127']}; {'id': '127', 'type': 'raise_statement', 'children': ['128']}; {'id': '128', 'type': 'call', 'children': ['129', '132']}; {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'argparse'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'ArgumentTypeError'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}; {'id': '133', 'type': 'string', 'children': [], 'value': "'CA Certificate is erroneous'"}; {'id': '134', 'type': 'if_statement', 'children': ['135', '145']}; {'id': '135', 'type': 'comparison_operator', 'children': ['136', '137'], 'value': '<'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'not_after'}; {'id': '137', 'type': 'call', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'call', 'children': ['141', '144']}; {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '144', 'type': 'argument_list', 'children': []}; {'id': '145', 'type': 'block', 'children': ['146']}; {'id': '146', 'type': 'raise_statement', 'children': ['147']}; {'id': '147', 'type': 'call', 'children': ['148', '151']}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'argparse'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'ArgumentTypeError'}; {'id': '151', 'type': 'argument_list', 'children': ['152']}; {'id': '152', 'type': 'string', 'children': [], 'value': "'CA Certificate expired'"}; {'id': '153', 'type': 'if_statement', 'children': ['154', '164']}; {'id': '154', 'type': 'comparison_operator', 'children': ['155', '156'], 'value': '>'}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'not_before'}; {'id': '156', 'type': 'call', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '158', 'type': 'argument_list', 'children': ['159']}; {'id': '159', 'type': 'call', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '163', 'type': 'argument_list', 'children': []}; {'id': '164', 'type': 'block', 'children': ['165']}; {'id': '165', 'type': 'raise_statement', 'children': ['166']}; {'id': '166', 'type': 'call', 'children': ['167', '170']}; {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'argparse'}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'ArgumentTypeError'}; {'id': '170', 'type': 'argument_list', 'children': ['171']}; {'id': '171', 'type': 'string', 'children': [], 'value': "'CA Certificate not active yet'"}; {'id': '172', 'type': 'return_statement', 'children': ['173']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'cacert'}; {'id': '174', 'type': 'function_definition', 'children': ['175', '176', '178']}; {'id': '175', 'type': 'function_name', 'children': [], 'value': 'log_level'}; {'id': '176', 'type': 'parameters', 'children': ['177']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'string'}; {'id': '178', 'type': 'block', 'children': ['179', '192', '207']}; {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'assignment', 'children': ['181', '182']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '182', 'type': 'call', 'children': ['183', '184']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '184', 'type': 'argument_list', 'children': ['185', '186', '191']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '186', 'type': 'call', 'children': ['187', '190']}; {'id': '187', 'type': 'attribute', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'string'}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'upper'}; {'id': '190', 'type': 'argument_list', 'children': []}; {'id': '191', 'type': 'None', 'children': []}; {'id': '192', 'type': 'if_statement', 'children': ['193', '199']}; {'id': '193', 'type': 'not_operator', 'children': ['194']}; {'id': '194', 'type': 'call', 'children': ['195', '196']}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '196', 'type': 'argument_list', 'children': ['197', '198']}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '199', 'type': 'block', 'children': ['200']}; {'id': '200', 'type': 'raise_statement', 'children': ['201']}; {'id': '201', 'type': 'call', 'children': ['202', '205']}; {'id': '202', 'type': 'attribute', 'children': ['203', '204']}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'argparse'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'ArgumentTypeError'}; {'id': '205', 'type': 'argument_list', 'children': ['206']}; {'id': '206', 'type': 'string', 'children': [], 'value': "'log level must be one of {debug,info,warning,error,critical}'"}; {'id': '207', 'type': 'return_statement', 'children': ['208']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '209', 'type': 'function_definition', 'children': ['210', '211', '213']}; {'id': '210', 'type': 'function_name', 'children': [], 'value': 'filename'}; {'id': '211', 'type': 'parameters', 'children': ['212']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'string'}; {'id': '213', 'type': 'block', 'children': ['214', '234']}; {'id': '214', 'type': 'if_statement', 'children': ['215', '224']}; {'id': '215', 'type': 'not_operator', 'children': ['216']}; {'id': '216', 'type': 'call', 'children': ['217', '222']}; {'id': '217', 'type': 'attribute', 'children': ['218', '221']}; {'id': '218', 'type': 'attribute', 'children': ['219', '220']}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'isfile'}; {'id': '222', 'type': 'argument_list', 'children': ['223']}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'string'}; {'id': '224', 'type': 'block', 'children': ['225']}; {'id': '225', 'type': 'raise_statement', 'children': ['226']}; {'id': '226', 'type': 'call', 'children': ['227', '230']}; {'id': '227', 'type': 'attribute', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'argparse'}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'ArgumentTypeError'}; {'id': '230', 'type': 'argument_list', 'children': ['231']}; {'id': '231', 'type': 'binary_operator', 'children': ['232', '233'], 'value': '%'}; {'id': '232', 'type': 'string', 'children': [], 'value': "'%s is not a valid file path'"}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'string'}; {'id': '234', 'type': 'return_statement', 'children': ['235']}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'string'}; {'id': '236', 'type': 'expression_statement', 'children': ['237']}; {'id': '237', 'type': 'call', 'children': ['238', '241']}; {'id': '238', 'type': 'attribute', 'children': ['239', '240']}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'parser'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'add_argument'}; {'id': '241', 'type': 'argument_list', 'children': ['242', '243', '244', '247', '250']}; {'id': '242', 'type': 'string', 'children': [], 'value': "'-p'"}; {'id': '243', 'type': 'string', 'children': [], 'value': "'--port'"}; {'id': '244', 'type': 'keyword_argument', 'children': ['245', '246']}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'PORT'}; {'id': '247', 'type': 'keyword_argument', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'network_port'}; {'id': '250', 'type': 'keyword_argument', 'children': ['251', '252']}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'help'}; {'id': '252', 'type': 'call', 'children': ['253', '256']}; {'id': '253', 'type': 'attribute', 'children': ['254', '255']}; {'id': '254', 'type': 'string', 'children': [], 'value': "'TCP Port to listen on. Default: {0}'"}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '256', 'type': 'argument_list', 'children': ['257']}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'PORT'}; {'id': '258', 'type': 'expression_statement', 'children': ['259']}; {'id': '259', 'type': 'call', 'children': ['260', '263']}; {'id': '260', 'type': 'attribute', 'children': ['261', '262']}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'parser'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'add_argument'}; {'id': '263', 'type': 'argument_list', 'children': ['264', '265', '266', '269']}; {'id': '264', 'type': 'string', 'children': [], 'value': "'-b'"}; {'id': '265', 'type': 'string', 'children': [], 'value': "'--bind-address'"}; {'id': '266', 'type': 'keyword_argument', 'children': ['267', '268']}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'ADDRESS'}; {'id': '269', 'type': 'keyword_argument', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'help'}; {'id': '271', 'type': 'call', 'children': ['272', '275']}; {'id': '272', 'type': 'attribute', 'children': ['273', '274']}; {'id': '273', 'type': 'string', 'children': [], 'value': "'Address to listen on. Default: {0}'"}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '275', 'type': 'argument_list', 'children': ['276']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'ADDRESS'}; {'id': '277', 'type': 'expression_statement', 'children': ['278']}; {'id': '278', 'type': 'call', 'children': ['279', '282']}; {'id': '279', 'type': 'attribute', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'parser'}; {'id': '281', 'type': 'identifier', 'children': [], 'value': 'add_argument'}; {'id': '282', 'type': 'argument_list', 'children': ['283', '284', '285']}; {'id': '283', 'type': 'string', 'children': [], 'value': "'-u'"}; {'id': '284', 'type': 'string', 'children': [], 'value': "'--unix-socket'"}; {'id': '285', 'type': 'keyword_argument', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'help'}; {'id': '287', 'type': 'string', 'children': [], 'value': "'Unix file socket to listen on.'"}; {'id': '288', 'type': 'expression_statement', 'children': ['289']}; {'id': '289', 'type': 'call', 'children': ['290', '293']}; {'id': '290', 'type': 'attribute', 'children': ['291', '292']}; {'id': '291', 'type': 'identifier', 'children': [], 'value': 'parser'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'add_argument'}; {'id': '293', 'type': 'argument_list', 'children': ['294', '295', '296', '299']}; {'id': '294', 'type': 'string', 'children': [], 'value': "'-k'"}; {'id': '295', 'type': 'string', 'children': [], 'value': "'--key-file'"}; {'id': '296', 'type': 'keyword_argument', 'children': ['297', '298']}; {'id': '297', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '299', 'type': 'keyword_argument', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'help'}; {'id': '301', 'type': 'call', 'children': ['302', '305']}; {'id': '302', 'type': 'attribute', 'children': ['303', '304']}; {'id': '303', 'type': 'string', 'children': [], 'value': "'Server key file. Default: {0}'"}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '305', 'type': 'argument_list', 'children': ['306']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'KEY_FILE'}; {'id': '307', 'type': 'expression_statement', 'children': ['308']}; {'id': '308', 'type': 'call', 'children': ['309', '312']}; {'id': '309', 'type': 'attribute', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'parser'}; {'id': '311', 'type': 'identifier', 'children': [], 'value': 'add_argument'}; {'id': '312', 'type': 'argument_list', 'children': ['313', '314', '315', '318']}; {'id': '313', 'type': 'string', 'children': [], 'value': "'-c'"}; {'id': '314', 'type': 'string', 'children': [], 'value': "'--cert-file'"}; {'id': '315', 'type': 'keyword_argument', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '317', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '318', 'type': 'keyword_argument', 'children': ['319', '320']}; {'id': '319', 'type': 'identifier', 'children': [], 'value': 'help'}; {'id': '320', 'type': 'call', 'children': ['321', '324']}; {'id': '321', 'type': 'attribute', 'children': ['322', '323']}; {'id': '322', 'type': 'string', 'children': [], 'value': "'Server cert file. Default: {0}'"}; {'id': '323', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '324', 'type': 'argument_list', 'children': ['325']}; {'id': '325', 'type': 'identifier', 'children': [], 'value': 'CERT_FILE'}; {'id': '326', 'type': 'expression_statement', 'children': ['327']}; {'id': '327', 'type': 'call', 'children': ['328', '331']}; {'id': '328', 'type': 'attribute', 'children': ['329', '330']}; {'id': '329', 'type': 'identifier', 'children': [], 'value': 'parser'}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'add_argument'}; {'id': '331', 'type': 'argument_list', 'children': ['332', '333', '336']}; {'id': '332', 'type': 'string', 'children': [], 'value': "'--ca-file'"}; {'id': '333', 'type': 'keyword_argument', 'children': ['334', '335']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '335', 'type': 'identifier', 'children': [], 'value': 'cacert_file'}; {'id': '336', 'type': 'keyword_argument', 'children': ['337', '338']}; {'id': '337', 'type': 'identifier', 'children': [], 'value': 'help'}; {'id': '338', 'type': 'call', 'children': ['339', '342']}; {'id': '339', 'type': 'attribute', 'children': ['340', '341']}; {'id': '340', 'type': 'string', 'children': [], 'value': "'CA cert file. Default: {0}'"}; {'id': '341', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '342', 'type': 'argument_list', 'children': ['343']}; {'id': '343', 'type': 'identifier', 'children': [], 'value': 'CA_FILE'}; {'id': '344', 'type': 'expression_statement', 'children': ['345']}; {'id': '345', 'type': 'call', 'children': ['346', '349']}; {'id': '346', 'type': 'attribute', 'children': ['347', '348']}; {'id': '347', 'type': 'identifier', 'children': [], 'value': 'parser'}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'add_argument'}; {'id': '349', 'type': 'argument_list', 'children': ['350', '351', '352', '355', '358']}; {'id': '350', 'type': 'string', 'children': [], 'value': "'-L'"}; {'id': '351', 'type': 'string', 'children': [], 'value': "'--log-level'"}; {'id': '352', 'type': 'keyword_argument', 'children': ['353', '354']}; {'id': '353', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '354', 'type': 'string', 'children': [], 'value': "'warning'"}; {'id': '355', 'type': 'keyword_argument', 'children': ['356', '357']}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '357', 'type': 'identifier', 'children': [], 'value': 'log_level'}; {'id': '358', 'type': 'keyword_argument', 'children': ['359', '360']}; {'id': '359', 'type': 'identifier', 'children': [], 'value': 'help'}; {'id': '360', 'type': 'string', 'children': [], 'value': "'Wished level of logging. Default: WARNING'"}; {'id': '361', 'type': 'expression_statement', 'children': ['362']}; {'id': '362', 'type': 'call', 'children': ['363', '366']}; {'id': '363', 'type': 'attribute', 'children': ['364', '365']}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'parser'}; {'id': '365', 'type': 'identifier', 'children': [], 'value': 'add_argument'}; {'id': '366', 'type': 'argument_list', 'children': ['367', '368', '371']}; {'id': '367', 'type': 'string', 'children': [], 'value': "'--foreground'"}; {'id': '368', 'type': 'keyword_argument', 'children': ['369', '370']}; {'id': '369', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '370', 'type': 'string', 'children': [], 'value': "'store_true'"}; {'id': '371', 'type': 'keyword_argument', 'children': ['372', '373']}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'help'}; {'id': '373', 'type': 'string', 'children': [], 'value': "'Run in foreground and logs all messages to console.'"}; {'id': '374', 'type': 'expression_statement', 'children': ['375']}; {'id': '375', 'type': 'call', 'children': ['376', '379']}; {'id': '376', 'type': 'attribute', 'children': ['377', '378']}; {'id': '377', 'type': 'identifier', 'children': [], 'value': 'parser'}; {'id': '378', 'type': 'identifier', 'children': [], 'value': 'add_argument'}; {'id': '379', 'type': 'argument_list', 'children': ['380', '381', '382', '385']}; {'id': '380', 'type': 'string', 'children': [], 'value': "'-l'"}; {'id': '381', 'type': 'string', 'children': [], 'value': "'--log-file'"}; {'id': '382', 'type': 'keyword_argument', 'children': ['383', '384']}; {'id': '383', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '385', 'type': 'keyword_argument', 'children': ['386', '387']}; {'id': '386', 'type': 'identifier', 'children': [], 'value': 'help'}; {'id': '387', 'type': 'string', 'children': [], 'value': "'Path to the logging file.'"}; {'id': '388', 'type': 'expression_statement', 'children': ['389']}; {'id': '389', 'type': 'call', 'children': ['390', '393']}; {'id': '390', 'type': 'attribute', 'children': ['391', '392']}; {'id': '391', 'type': 'identifier', 'children': [], 'value': 'parser'}; {'id': '392', 'type': 'identifier', 'children': [], 'value': 'add_argument'}; {'id': '393', 'type': 'argument_list', 'children': ['394', '395', '398']}; {'id': '394', 'type': 'string', 'children': [], 'value': "'--version'"}; {'id': '395', 'type': 'keyword_argument', 'children': ['396', '397']}; {'id': '396', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '397', 'type': 'string', 'children': [], 'value': "'store_true'"}; {'id': '398', 'type': 'keyword_argument', 'children': ['399', '400']}; {'id': '399', 'type': 'identifier', 'children': [], 'value': 'help'}; {'id': '400', 'type': 'string', 'children': [], 'value': "'Print version then exit.'"}; {'id': '401', 'type': 'return_statement', 'children': ['402']}; {'id': '402', 'type': 'identifier', 'children': [], 'value': 'parser'}
|
def create_args_parser(description):
parser = argparse.ArgumentParser(description=description)
def network_port(string):
value = int(string)
if not 0 < value <= 65535:
raise argparse.ArgumentTypeError(
'port must be in ]0,65535] interval')
return value
def cacert_file(cacert):
try:
context = ssl.create_default_context(cafile=cacert)
except AttributeError:
return cacert
except IOError:
raise argparse.ArgumentTypeError('CA Certificate not found')
try:
not_after = context.get_ca_certs()[0]['notAfter']
not_after = ssl.cert_time_to_seconds(not_after)
not_before = context.get_ca_certs()[0]['notBefore']
not_before = ssl.cert_time_to_seconds(not_before)
except (KeyError, IndexError):
raise argparse.ArgumentTypeError('CA Certificate is erroneous')
if not_after < int(time.time()):
raise argparse.ArgumentTypeError('CA Certificate expired')
if not_before > int(time.time()):
raise argparse.ArgumentTypeError('CA Certificate not active yet')
return cacert
def log_level(string):
value = getattr(logging, string.upper(), None)
if not isinstance(value, int):
raise argparse.ArgumentTypeError(
'log level must be one of {debug,info,warning,error,critical}')
return value
def filename(string):
if not os.path.isfile(string):
raise argparse.ArgumentTypeError(
'%s is not a valid file path' % string)
return string
parser.add_argument('-p', '--port', default=PORT, type=network_port,
help='TCP Port to listen on. Default: {0}'.format(PORT))
parser.add_argument('-b', '--bind-address', default=ADDRESS,
help='Address to listen on. Default: {0}'
.format(ADDRESS))
parser.add_argument('-u', '--unix-socket',
help='Unix file socket to listen on.')
parser.add_argument('-k', '--key-file', type=filename,
help='Server key file. Default: {0}'.format(KEY_FILE))
parser.add_argument('-c', '--cert-file', type=filename,
help='Server cert file. Default: {0}'.format(CERT_FILE))
parser.add_argument('--ca-file', type=cacert_file,
help='CA cert file. Default: {0}'.format(CA_FILE))
parser.add_argument('-L', '--log-level', default='warning', type=log_level,
help='Wished level of logging. Default: WARNING')
parser.add_argument('--foreground', action='store_true',
help='Run in foreground and logs all messages to console.')
parser.add_argument('-l', '--log-file', type=filename,
help='Path to the logging file.')
parser.add_argument('--version', action='store_true',
help='Print version then exit.')
return parser
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_handle_func'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'rule'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'done'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'block', 'children': ['12', '18', '23', '27', '113']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'rule'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '18', 'type': 'if_statement', 'children': ['19', '21']}; {'id': '19', 'type': 'not_operator', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'return_statement', 'children': []}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'found_method'}; {'id': '26', 'type': 'False', 'children': []}; {'id': '27', 'type': 'for_statement', 'children': ['28', '29', '32']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'extension'}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'loaded_extensions'}; {'id': '32', 'type': 'block', 'children': ['33', '42']}; {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '36', 'type': 'call', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '38', 'type': 'argument_list', 'children': ['39', '40', '41']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'extension'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '41', 'type': 'None', 'children': []}; {'id': '42', 'type': 'if_statement', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '44', 'type': 'block', 'children': ['45', '49', '58', '98', '112']}; {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'found_method'}; {'id': '48', 'type': 'True', 'children': []}; {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '54', 'type': 'argument_list', 'children': ['55', '56', '57']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'rule'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '58', 'type': 'if_statement', 'children': ['59', '66']}; {'id': '59', 'type': 'boolean_operator', 'children': ['60', '63'], 'value': 'and'}; {'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': 'is'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '62', 'type': 'True', 'children': []}; {'id': '63', 'type': 'comparison_operator', 'children': ['64', '65'], 'value': 'is'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '65', 'type': 'None', 'children': []}; {'id': '66', 'type': 'block', 'children': ['67', '76']}; {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '70', 'type': 'binary_operator', 'children': ['71', '72'], 'value': '%'}; {'id': '71', 'type': 'string', 'children': [], 'value': "'%s. Path: {path}'"}; {'id': '72', 'type': 'call', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'unicode'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}; {'id': '77', 'type': 'call', 'children': ['78', '83']}; {'id': '78', 'type': 'attribute', 'children': ['79', '82']}; {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'call', 'children': ['85', '88']}; {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'SchemaError'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'SchemaErrorEntry'}; {'id': '88', 'type': 'argument_list', 'children': ['89', '92', '95']}; {'id': '89', 'type': 'keyword_argument', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '92', 'type': 'keyword_argument', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '95', 'type': 'keyword_argument', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '97', 'type': 'None', 'children': []}; {'id': '98', 'type': 'if_statement', 'children': ['99', '101']}; {'id': '99', 'type': 'not_operator', 'children': ['100']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '101', 'type': 'block', 'children': ['102']}; {'id': '102', 'type': 'raise_statement', 'children': ['103']}; {'id': '103', 'type': 'call', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'CoreError'}; {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'call', 'children': ['107', '110']}; {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'string', 'children': [], 'value': 'u"Error when running extension function : {0}"'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '112', 'type': 'break_statement', 'children': []}; {'id': '113', 'type': 'if_statement', 'children': ['114', '116']}; {'id': '114', 'type': 'not_operator', 'children': ['115']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'found_method'}; {'id': '116', 'type': 'block', 'children': ['117']}; {'id': '117', 'type': 'raise_statement', 'children': ['118']}; {'id': '118', 'type': 'call', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'CoreError'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}; {'id': '121', 'type': 'call', 'children': ['122', '125']}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}; {'id': '123', 'type': 'string', 'children': [], 'value': 'u"Did not find method \'{0}\' in any loaded extension file"'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '125', 'type': 'argument_list', 'children': ['126']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'func'}
|
def _handle_func(self, value, rule, path, done=None):
func = rule.func
if not func:
return
found_method = False
for extension in self.loaded_extensions:
method = getattr(extension, func, None)
if method:
found_method = True
ret = method(value, rule, path)
if ret is not True and ret is not None:
msg = '%s. Path: {path}' % unicode(ret)
self.errors.append(SchemaError.SchemaErrorEntry(
msg=msg,
path=path,
value=None))
if not ret:
raise CoreError(u"Error when running extension function : {0}".format(func))
break
if not found_method:
raise CoreError(u"Did not find method '{0}' in any loaded extension file".format(func))
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_validate_range'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'max_'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'min_'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'max_ex'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'min_ex'}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '12', 'type': 'block', 'children': ['13', '33', '46', '94', '142', '190']}; {'id': '13', 'type': 'if_statement', 'children': ['14', '27']}; {'id': '14', 'type': 'boolean_operator', 'children': ['15', '21'], 'value': 'and'}; {'id': '15', 'type': 'not_operator', 'children': ['16']}; {'id': '16', 'type': 'call', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '18', 'type': 'argument_list', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '21', 'type': 'not_operator', 'children': ['22']}; {'id': '22', 'type': 'call', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'raise_statement', 'children': ['29']}; {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'CoreError'}; {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'string', 'children': [], 'value': '"Value must be a integer type"'}; {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'call', 'children': ['35', '38']}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '38', 'type': 'argument_list', 'children': ['39', '40', '41', '42', '43', '44', '45']}; {'id': '39', 'type': 'string', 'children': [], 'value': 'u"Validate range : %s : %s : %s : %s : %s : %s"'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'max_'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'min_'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'max_ex'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'min_ex'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '46', 'type': 'if_statement', 'children': ['47', '54']}; {'id': '47', 'type': 'boolean_operator', 'children': ['48', '51'], 'value': 'and'}; {'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': 'is'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'max_'}; {'id': '50', 'type': 'None', 'children': []}; {'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': '<'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'max_'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '54', 'type': 'block', 'children': ['55']}; {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'call', 'children': ['57', '62']}; {'id': '57', 'type': 'attribute', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}; {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'SchemaError'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'SchemaErrorEntry'}; {'id': '67', 'type': 'argument_list', 'children': ['68', '71', '74', '88', '91']}; {'id': '68', 'type': 'keyword_argument', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '70', 'type': 'string', 'children': [], 'value': 'u"Type \'{prefix}\' has size of \'{value}\', greater than max limit \'{max_}\'. Path: \'{path}\'"'}; {'id': '71', 'type': 'keyword_argument', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '74', 'type': 'keyword_argument', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '76', 'type': 'conditional_expression', 'children': ['77', '81', '87'], 'value': 'if'}; {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'nativestr'}; {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '81', 'type': 'call', 'children': ['82', '85']}; {'id': '82', 'type': 'subscript', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'tt'}; {'id': '84', 'type': 'string', 'children': [], 'value': "'str'"}; {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '88', 'type': 'keyword_argument', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '91', 'type': 'keyword_argument', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'max_'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'max_'}; {'id': '94', 'type': 'if_statement', 'children': ['95', '102']}; {'id': '95', 'type': 'boolean_operator', 'children': ['96', '99'], 'value': 'and'}; {'id': '96', 'type': 'comparison_operator', 'children': ['97', '98'], 'value': 'is'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'min_'}; {'id': '98', 'type': 'None', 'children': []}; {'id': '99', 'type': 'comparison_operator', 'children': ['100', '101'], 'value': '>'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'min_'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '102', 'type': 'block', 'children': ['103']}; {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'call', 'children': ['105', '110']}; {'id': '105', 'type': 'attribute', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}; {'id': '111', 'type': 'call', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'SchemaError'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'SchemaErrorEntry'}; {'id': '115', 'type': 'argument_list', 'children': ['116', '119', '122', '136', '139']}; {'id': '116', 'type': 'keyword_argument', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '118', 'type': 'string', 'children': [], 'value': 'u"Type \'{prefix}\' has size of \'{value}\', less than min limit \'{min_}\'. Path: \'{path}\'"'}; {'id': '119', 'type': 'keyword_argument', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '122', 'type': 'keyword_argument', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '124', 'type': 'conditional_expression', 'children': ['125', '129', '135'], 'value': 'if'}; {'id': '125', 'type': 'call', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'nativestr'}; {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '129', 'type': 'call', 'children': ['130', '133']}; {'id': '130', 'type': 'subscript', 'children': ['131', '132']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'tt'}; {'id': '132', 'type': 'string', 'children': [], 'value': "'str'"}; {'id': '133', 'type': 'argument_list', 'children': ['134']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '136', 'type': 'keyword_argument', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '139', 'type': 'keyword_argument', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'min_'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'min_'}; {'id': '142', 'type': 'if_statement', 'children': ['143', '150']}; {'id': '143', 'type': 'boolean_operator', 'children': ['144', '147'], 'value': 'and'}; {'id': '144', 'type': 'comparison_operator', 'children': ['145', '146'], 'value': 'is'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'max_ex'}; {'id': '146', 'type': 'None', 'children': []}; {'id': '147', 'type': 'comparison_operator', 'children': ['148', '149'], 'value': '<='}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'max_ex'}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '150', 'type': 'block', 'children': ['151']}; {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'call', 'children': ['153', '158']}; {'id': '153', 'type': 'attribute', 'children': ['154', '157']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '158', 'type': 'argument_list', 'children': ['159']}; {'id': '159', 'type': 'call', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'SchemaError'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'SchemaErrorEntry'}; {'id': '163', 'type': 'argument_list', 'children': ['164', '167', '170', '184', '187']}; {'id': '164', 'type': 'keyword_argument', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '166', 'type': 'string', 'children': [], 'value': 'u"Type \'{prefix}\' has size of \'{value}\', greater than or equals to max limit(exclusive) \'{max_ex}\'. Path: \'{path}\'"'}; {'id': '167', 'type': 'keyword_argument', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '170', 'type': 'keyword_argument', 'children': ['171', '172']}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '172', 'type': 'conditional_expression', 'children': ['173', '177', '183'], 'value': 'if'}; {'id': '173', 'type': 'call', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'nativestr'}; {'id': '175', 'type': 'argument_list', 'children': ['176']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '177', 'type': 'call', 'children': ['178', '181']}; {'id': '178', 'type': 'subscript', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'tt'}; {'id': '180', 'type': 'string', 'children': [], 'value': "'str'"}; {'id': '181', 'type': 'argument_list', 'children': ['182']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '184', 'type': 'keyword_argument', 'children': ['185', '186']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '187', 'type': 'keyword_argument', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'max_ex'}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'max_ex'}; {'id': '190', 'type': 'if_statement', 'children': ['191', '198']}; {'id': '191', 'type': 'boolean_operator', 'children': ['192', '195'], 'value': 'and'}; {'id': '192', 'type': 'comparison_operator', 'children': ['193', '194'], 'value': 'is'}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'min_ex'}; {'id': '194', 'type': 'None', 'children': []}; {'id': '195', 'type': 'comparison_operator', 'children': ['196', '197'], 'value': '>='}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'min_ex'}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '198', 'type': 'block', 'children': ['199']}; {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'call', 'children': ['201', '206']}; {'id': '201', 'type': 'attribute', 'children': ['202', '205']}; {'id': '202', 'type': 'attribute', 'children': ['203', '204']}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '206', 'type': 'argument_list', 'children': ['207']}; {'id': '207', 'type': 'call', 'children': ['208', '211']}; {'id': '208', 'type': 'attribute', 'children': ['209', '210']}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'SchemaError'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'SchemaErrorEntry'}; {'id': '211', 'type': 'argument_list', 'children': ['212', '215', '218', '232', '235']}; {'id': '212', 'type': 'keyword_argument', 'children': ['213', '214']}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '214', 'type': 'string', 'children': [], 'value': 'u"Type \'{prefix}\' has size of \'{value}\', less than or equals to min limit(exclusive) \'{min_ex}\'. Path: \'{path}\'"'}; {'id': '215', 'type': 'keyword_argument', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '218', 'type': 'keyword_argument', 'children': ['219', '220']}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '220', 'type': 'conditional_expression', 'children': ['221', '225', '231'], 'value': 'if'}; {'id': '221', 'type': 'call', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'nativestr'}; {'id': '223', 'type': 'argument_list', 'children': ['224']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '225', 'type': 'call', 'children': ['226', '229']}; {'id': '226', 'type': 'subscript', 'children': ['227', '228']}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'tt'}; {'id': '228', 'type': 'string', 'children': [], 'value': "'str'"}; {'id': '229', 'type': 'argument_list', 'children': ['230']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '232', 'type': 'keyword_argument', 'children': ['233', '234']}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '235', 'type': 'keyword_argument', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'min_ex'}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'min_ex'}
|
def _validate_range(self, max_, min_, max_ex, min_ex, value, path, prefix):
if not isinstance(value, int) and not isinstance(value, float):
raise CoreError("Value must be a integer type")
log.debug(
u"Validate range : %s : %s : %s : %s : %s : %s",
max_,
min_,
max_ex,
min_ex,
value,
path,
)
if max_ is not None and max_ < value:
self.errors.append(SchemaError.SchemaErrorEntry(
msg=u"Type '{prefix}' has size of '{value}', greater than max limit '{max_}'. Path: '{path}'",
path=path,
value=nativestr(value) if tt['str'](value) else value,
prefix=prefix,
max_=max_))
if min_ is not None and min_ > value:
self.errors.append(SchemaError.SchemaErrorEntry(
msg=u"Type '{prefix}' has size of '{value}', less than min limit '{min_}'. Path: '{path}'",
path=path,
value=nativestr(value) if tt['str'](value) else value,
prefix=prefix,
min_=min_))
if max_ex is not None and max_ex <= value:
self.errors.append(SchemaError.SchemaErrorEntry(
msg=u"Type '{prefix}' has size of '{value}', greater than or equals to max limit(exclusive) '{max_ex}'. Path: '{path}'",
path=path,
value=nativestr(value) if tt['str'](value) else value,
prefix=prefix,
max_ex=max_ex))
if min_ex is not None and min_ex >= value:
self.errors.append(SchemaError.SchemaErrorEntry(
msg=u"Type '{prefix}' has size of '{value}', less than or equals to min limit(exclusive) '{min_ex}'. Path: '{path}'",
path=path,
value=nativestr(value) if tt['str'](value) else value,
prefix=prefix,
min_ex=min_ex))
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '23']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'tsses'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'db'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'merge_overlapping'}; {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'attrs'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'attrs_sep'}; {'id': '13', 'type': 'string', 'children': [], 'value': '":"'}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'merge_kwargs'}; {'id': '16', 'type': 'None', 'children': []}; {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'as_bed6'}; {'id': '19', 'type': 'False', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'bedtools_227_or_later'}; {'id': '22', 'type': 'True', 'children': []}; {'id': '23', 'type': 'block', 'children': ['24', '36', '73', '108', '120', '188', '203', '227', '306', '384']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}; {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': '_override'}; {'id': '27', 'type': 'call', 'children': ['28', '33']}; {'id': '28', 'type': 'attribute', 'children': ['29', '32']}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'environ'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '33', 'type': 'argument_list', 'children': ['34', '35']}; {'id': '34', 'type': 'string', 'children': [], 'value': "'GFFUTILS_USES_BEDTOOLS_227_OR_LATER'"}; {'id': '35', 'type': 'None', 'children': []}; {'id': '36', 'type': 'if_statement', 'children': ['37', '40']}; {'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': 'is'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': '_override'}; {'id': '39', 'type': 'None', 'children': []}; {'id': '40', 'type': 'block', 'children': ['41']}; {'id': '41', 'type': 'if_statement', 'children': ['42', '45', '50', '59']}; {'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': '=='}; {'id': '43', 'type': 'identifier', 'children': [], 'value': '_override'}; {'id': '44', 'type': 'string', 'children': [], 'value': "'true'"}; {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}; {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'bedtools_227_or_later'}; {'id': '49', 'type': 'True', 'children': []}; {'id': '50', 'type': 'elif_clause', 'children': ['51', '54']}; {'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': '=='}; {'id': '52', 'type': 'identifier', 'children': [], 'value': '_override'}; {'id': '53', 'type': 'string', 'children': [], 'value': "'false'"}; {'id': '54', 'type': 'block', 'children': ['55']}; {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'bedtools_227_or_later'}; {'id': '58', 'type': 'False', 'children': []}; {'id': '59', 'type': 'else_clause', 'children': ['60']}; {'id': '60', 'type': 'block', 'children': ['61']}; {'id': '61', 'type': 'raise_statement', 'children': ['62']}; {'id': '62', 'type': 'call', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}; {'id': '65', 'type': 'call', 'children': ['66', '71']}; {'id': '66', 'type': 'attribute', 'children': ['67', '70']}; {'id': '67', 'type': 'concatenated_string', 'children': ['68', '69']}; {'id': '68', 'type': 'string', 'children': [], 'value': '"Unknown value for GFFUTILS_USES_BEDTOOLS_227_OR_LATER "'}; {'id': '69', 'type': 'string', 'children': [], 'value': '"environment variable: {0}"'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': '_override'}; {'id': '73', 'type': 'if_statement', 'children': ['74', '75', '91']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'bedtools_227_or_later'}; {'id': '75', 'type': 'block', 'children': ['76']}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}; {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': '_merge_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': 'o'}; {'id': '84', 'type': 'string', 'children': [], 'value': "'distinct'"}; {'id': '85', 'type': 'keyword_argument', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '87', 'type': 'True', 'children': []}; {'id': '88', 'type': 'keyword_argument', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '90', 'type': 'string', 'children': [], 'value': "'4,5,6'"}; {'id': '91', 'type': 'else_clause', 'children': ['92']}; {'id': '92', 'type': 'block', 'children': ['93']}; {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': '_merge_kwargs'}; {'id': '96', 'type': 'call', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '98', 'type': 'argument_list', 'children': ['99', '102', '105']}; {'id': '99', 'type': 'keyword_argument', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '101', 'type': 'string', 'children': [], 'value': "'distinct'"}; {'id': '102', 'type': 'keyword_argument', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '104', 'type': 'True', 'children': []}; {'id': '105', 'type': 'keyword_argument', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '107', 'type': 'string', 'children': [], 'value': "'4'"}; {'id': '108', 'type': 'if_statement', 'children': ['109', '112']}; {'id': '109', 'type': 'comparison_operator', 'children': ['110', '111'], 'value': 'is'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'merge_kwargs'}; {'id': '111', 'type': 'None', 'children': []}; {'id': '112', 'type': 'block', 'children': ['113']}; {'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': '_merge_kwargs'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'merge_kwargs'}; {'id': '120', 'type': 'function_definition', 'children': ['121', '122', '123']}; {'id': '121', 'type': 'function_name', 'children': [], 'value': 'gen'}; {'id': '122', 'type': 'parameters', 'children': []}; {'id': '123', 'type': 'block', 'children': ['124']}; {'id': '124', 'type': 'for_statement', 'children': ['125', '126', '132']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'gene'}; {'id': '126', 'type': 'call', 'children': ['127', '130']}; {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'db'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'features_of_type'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}; {'id': '131', 'type': 'string', 'children': [], 'value': "'gene'"}; {'id': '132', 'type': 'block', 'children': ['133']}; {'id': '133', 'type': 'for_statement', 'children': ['134', '135', '144']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'transcript'}; {'id': '135', 'type': 'call', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'db'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'children'}; {'id': '139', 'type': 'argument_list', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'gene'}; {'id': '141', 'type': 'keyword_argument', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '143', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '144', 'type': 'block', 'children': ['145', '170', '180']}; {'id': '145', 'type': 'if_statement', 'children': ['146', '151', '160']}; {'id': '146', 'type': 'comparison_operator', 'children': ['147', '150'], 'value': '=='}; {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'transcript'}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'strand'}; {'id': '150', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '151', 'type': 'block', 'children': ['152']}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}; {'id': '153', 'type': 'assignment', 'children': ['154', '157']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'transcript'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'transcript'}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '160', 'type': 'else_clause', 'children': ['161']}; {'id': '161', 'type': 'block', 'children': ['162']}; {'id': '162', 'type': 'expression_statement', 'children': ['163']}; {'id': '163', 'type': 'assignment', 'children': ['164', '167']}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'transcript'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'transcript'}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}; {'id': '171', 'type': 'assignment', 'children': ['172', '175']}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'transcript'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'featuretype'}; {'id': '175', 'type': 'binary_operator', 'children': ['176', '179'], 'value': '+'}; {'id': '176', 'type': 'attribute', 'children': ['177', '178']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'transcript'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'featuretype'}; {'id': '179', 'type': 'string', 'children': [], 'value': "'_TSS'"}; {'id': '180', 'type': 'expression_statement', 'children': ['181']}; {'id': '181', 'type': 'yield', 'children': ['182']}; {'id': '182', 'type': 'call', 'children': ['183', '186']}; {'id': '183', 'type': 'attribute', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'helpers'}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'asinterval'}; {'id': '186', 'type': 'argument_list', 'children': ['187']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'transcript'}; {'id': '188', 'type': 'expression_statement', 'children': ['189']}; {'id': '189', 'type': 'assignment', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '191', 'type': 'call', 'children': ['192', '202']}; {'id': '192', 'type': 'attribute', 'children': ['193', '201']}; {'id': '193', 'type': 'call', 'children': ['194', '197']}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'pybedtools'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'BedTool'}; {'id': '197', 'type': 'argument_list', 'children': ['198']}; {'id': '198', 'type': 'call', 'children': ['199', '200']}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'gen'}; {'id': '200', 'type': 'argument_list', 'children': []}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '202', 'type': 'argument_list', 'children': []}; {'id': '203', 'type': 'if_statement', 'children': ['204', '207']}; {'id': '204', 'type': 'comparison_operator', 'children': ['205', '206'], 'value': 'is'}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'attrs'}; {'id': '206', 'type': 'None', 'children': []}; {'id': '207', 'type': 'block', 'children': ['208']}; {'id': '208', 'type': 'if_statement', 'children': ['209', '216', '221']}; {'id': '209', 'type': 'comparison_operator', 'children': ['210', '215'], 'value': '=='}; {'id': '210', 'type': 'subscript', 'children': ['211', '214']}; {'id': '211', 'type': 'attribute', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'db'}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'dialect'}; {'id': '214', 'type': 'string', 'children': [], 'value': "'fmt'"}; {'id': '215', 'type': 'string', 'children': [], 'value': "'gtf'"}; {'id': '216', 'type': 'block', 'children': ['217']}; {'id': '217', 'type': 'expression_statement', 'children': ['218']}; {'id': '218', 'type': 'assignment', 'children': ['219', '220']}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'attrs'}; {'id': '220', 'type': 'string', 'children': [], 'value': "'gene_id'"}; {'id': '221', 'type': 'else_clause', 'children': ['222']}; {'id': '222', 'type': 'block', 'children': ['223']}; {'id': '223', 'type': 'expression_statement', 'children': ['224']}; {'id': '224', 'type': 'assignment', 'children': ['225', '226']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'attrs'}; {'id': '226', 'type': 'string', 'children': [], 'value': "'ID'"}; {'id': '227', 'type': 'if_statement', 'children': ['228', '231']}; {'id': '228', 'type': 'boolean_operator', 'children': ['229', '230'], 'value': 'or'}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'merge_overlapping'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'as_bed6'}; {'id': '231', 'type': 'block', 'children': ['232', '246', '293']}; {'id': '232', 'type': 'if_statement', 'children': ['233', '240']}; {'id': '233', 'type': 'call', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '235', 'type': 'argument_list', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'attrs'}; {'id': '237', 'type': 'attribute', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'string_types'}; {'id': '240', 'type': 'block', 'children': ['241']}; {'id': '241', 'type': 'expression_statement', 'children': ['242']}; {'id': '242', 'type': 'assignment', 'children': ['243', '244']}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'attrs'}; {'id': '244', 'type': 'list', 'children': ['245'], 'value': '[attrs]'}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'attrs'}; {'id': '246', 'type': 'function_definition', 'children': ['247', '248', '250']}; {'id': '247', 'type': 'function_name', 'children': [], 'value': 'to_bed'}; {'id': '248', 'type': 'parameters', 'children': ['249']}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '250', 'type': 'block', 'children': ['251', '268']}; {'id': '251', 'type': 'expression_statement', 'children': ['252']}; {'id': '252', 'type': 'assignment', 'children': ['253', '254']}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '254', 'type': 'call', 'children': ['255', '258']}; {'id': '255', 'type': 'attribute', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'attrs_sep'}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '258', 'type': 'argument_list', 'children': ['259']}; {'id': '259', 'type': 'list_comprehension', 'children': ['260', '265']}; {'id': '260', 'type': 'subscript', 'children': ['261', '264']}; {'id': '261', 'type': 'attribute', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'attrs'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '265', 'type': 'for_in_clause', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'attrs'}; {'id': '268', 'type': 'return_statement', 'children': ['269']}; {'id': '269', 'type': 'call', 'children': ['270', '273']}; {'id': '270', 'type': 'attribute', 'children': ['271', '272']}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'pybedtools'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'Interval'}; {'id': '273', 'type': 'argument_list', 'children': ['274', '277', '280', '283', '284', '290']}; {'id': '274', 'type': 'attribute', 'children': ['275', '276']}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'chrom'}; {'id': '277', 'type': 'attribute', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '279', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '280', 'type': 'attribute', 'children': ['281', '282']}; {'id': '281', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '283', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '284', 'type': 'call', 'children': ['285', '286']}; {'id': '285', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '286', 'type': 'argument_list', 'children': ['287']}; {'id': '287', 'type': 'attribute', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'score'}; {'id': '290', 'type': 'attribute', 'children': ['291', '292']}; {'id': '291', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'strand'}; {'id': '293', 'type': 'expression_statement', 'children': ['294']}; {'id': '294', 'type': 'assignment', 'children': ['295', '296']}; {'id': '295', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '296', 'type': 'call', 'children': ['297', '305']}; {'id': '297', 'type': 'attribute', 'children': ['298', '304']}; {'id': '298', 'type': 'call', 'children': ['299', '302']}; {'id': '299', 'type': 'attribute', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '301', 'type': 'identifier', 'children': [], 'value': 'each'}; {'id': '302', 'type': 'argument_list', 'children': ['303']}; {'id': '303', 'type': 'identifier', 'children': [], 'value': 'to_bed'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'saveas'}; {'id': '305', 'type': 'argument_list', 'children': []}; {'id': '306', 'type': 'if_statement', 'children': ['307', '308']}; {'id': '307', 'type': 'identifier', 'children': [], 'value': 'merge_overlapping'}; {'id': '308', 'type': 'block', 'children': ['309']}; {'id': '309', 'type': 'if_statement', 'children': ['310', '311', '322']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'bedtools_227_or_later'}; {'id': '311', 'type': 'block', 'children': ['312']}; {'id': '312', 'type': 'expression_statement', 'children': ['313']}; {'id': '313', 'type': 'assignment', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '315', 'type': 'call', 'children': ['316', '319']}; {'id': '316', 'type': 'attribute', 'children': ['317', '318']}; {'id': '317', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'merge'}; {'id': '319', 'type': 'argument_list', 'children': ['320']}; {'id': '320', 'type': 'dictionary_splat', 'children': ['321']}; {'id': '321', 'type': 'identifier', 'children': [], 'value': '_merge_kwargs'}; {'id': '322', 'type': 'else_clause', 'children': ['323']}; {'id': '323', 'type': 'block', 'children': ['324', '361']}; {'id': '324', 'type': 'function_definition', 'children': ['325', '326', '328']}; {'id': '325', 'type': 'function_name', 'children': [], 'value': 'fix_merge'}; {'id': '326', 'type': 'parameters', 'children': ['327']}; {'id': '327', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '328', 'type': 'block', 'children': ['329', '339']}; {'id': '329', 'type': 'expression_statement', 'children': ['330']}; {'id': '330', 'type': 'assignment', 'children': ['331', '332']}; {'id': '331', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '332', 'type': 'call', 'children': ['333', '336']}; {'id': '333', 'type': 'attribute', 'children': ['334', '335']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'featurefuncs'}; {'id': '335', 'type': 'identifier', 'children': [], 'value': 'extend_fields'}; {'id': '336', 'type': 'argument_list', 'children': ['337', '338']}; {'id': '337', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '338', 'type': 'integer', 'children': [], 'value': '6'}; {'id': '339', 'type': 'return_statement', 'children': ['340']}; {'id': '340', 'type': 'call', 'children': ['341', '344']}; {'id': '341', 'type': 'attribute', 'children': ['342', '343']}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'pybedtools'}; {'id': '343', 'type': 'identifier', 'children': [], 'value': 'Interval'}; {'id': '344', 'type': 'argument_list', 'children': ['345', '348', '351', '354', '357', '358']}; {'id': '345', 'type': 'attribute', 'children': ['346', '347']}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '347', 'type': 'identifier', 'children': [], 'value': 'chrom'}; {'id': '348', 'type': 'attribute', 'children': ['349', '350']}; {'id': '349', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '351', 'type': 'attribute', 'children': ['352', '353']}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '353', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '354', 'type': 'subscript', 'children': ['355', '356']}; {'id': '355', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '356', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '357', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '358', 'type': 'subscript', 'children': ['359', '360']}; {'id': '359', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '360', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '361', 'type': 'expression_statement', 'children': ['362']}; {'id': '362', 'type': 'assignment', 'children': ['363', '364']}; {'id': '363', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '364', 'type': 'call', 'children': ['365', '383']}; {'id': '365', 'type': 'attribute', 'children': ['366', '382']}; {'id': '366', 'type': 'call', 'children': ['367', '380']}; {'id': '367', 'type': 'attribute', 'children': ['368', '379']}; {'id': '368', 'type': 'call', 'children': ['369', '378']}; {'id': '369', 'type': 'attribute', 'children': ['370', '377']}; {'id': '370', 'type': 'call', 'children': ['371', '374']}; {'id': '371', 'type': 'attribute', 'children': ['372', '373']}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '373', 'type': 'identifier', 'children': [], 'value': 'merge'}; {'id': '374', 'type': 'argument_list', 'children': ['375']}; {'id': '375', 'type': 'dictionary_splat', 'children': ['376']}; {'id': '376', 'type': 'identifier', 'children': [], 'value': '_merge_kwargs'}; {'id': '377', 'type': 'identifier', 'children': [], 'value': 'saveas'}; {'id': '378', 'type': 'argument_list', 'children': []}; {'id': '379', 'type': 'identifier', 'children': [], 'value': 'each'}; {'id': '380', 'type': 'argument_list', 'children': ['381']}; {'id': '381', 'type': 'identifier', 'children': [], 'value': 'fix_merge'}; {'id': '382', 'type': 'identifier', 'children': [], 'value': 'saveas'}; {'id': '383', 'type': 'argument_list', 'children': []}; {'id': '384', 'type': 'return_statement', 'children': ['385']}; {'id': '385', 'type': 'identifier', 'children': [], 'value': 'x'}
|
def tsses(db, merge_overlapping=False, attrs=None, attrs_sep=":",
merge_kwargs=None, as_bed6=False, bedtools_227_or_later=True):
_override = os.environ.get('GFFUTILS_USES_BEDTOOLS_227_OR_LATER', None)
if _override is not None:
if _override == 'true':
bedtools_227_or_later = True
elif _override == 'false':
bedtools_227_or_later = False
else:
raise ValueError(
"Unknown value for GFFUTILS_USES_BEDTOOLS_227_OR_LATER "
"environment variable: {0}".format(_override))
if bedtools_227_or_later:
_merge_kwargs = dict(o='distinct', s=True, c='4,5,6')
else:
_merge_kwargs = dict(o='distinct', s=True, c='4')
if merge_kwargs is not None:
_merge_kwargs.update(merge_kwargs)
def gen():
for gene in db.features_of_type('gene'):
for transcript in db.children(gene, level=1):
if transcript.strand == '-':
transcript.start = transcript.stop
else:
transcript.stop = transcript.start
transcript.featuretype = transcript.featuretype + '_TSS'
yield helpers.asinterval(transcript)
x = pybedtools.BedTool(gen()).sort()
if attrs is None:
if db.dialect['fmt'] == 'gtf':
attrs = 'gene_id'
else:
attrs = 'ID'
if merge_overlapping or as_bed6:
if isinstance(attrs, six.string_types):
attrs = [attrs]
def to_bed(f):
name = attrs_sep.join([f.attrs[i] for i in attrs])
return pybedtools.Interval(
f.chrom,
f.start,
f.stop,
name,
str(f.score),
f.strand)
x = x.each(to_bed).saveas()
if merge_overlapping:
if bedtools_227_or_later:
x = x.merge(**_merge_kwargs)
else:
def fix_merge(f):
f = featurefuncs.extend_fields(f, 6)
return pybedtools.Interval(
f.chrom,
f.start,
f.stop,
f[4],
'.',
f[3])
x = x.merge(**_merge_kwargs).saveas().each(fix_merge).saveas()
return x
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'interfeatures'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'features'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'new_featuretype'}; {'id': '8', 'type': 'None', 'children': []}; {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'merge_attributes'}; {'id': '11', 'type': 'True', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'dialect'}; {'id': '14', 'type': 'None', 'children': []}; {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'attribute_func'}; {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'update_attributes'}; {'id': '20', 'type': 'None', 'children': []}; {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'for_statement', 'children': ['23', '26', '30']}; {'id': '23', 'type': 'pattern_list', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '26', 'type': 'call', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'features'}; {'id': '30', 'type': 'block', 'children': ['31', '47', '53', '70', '91', '105', '109', '115', '119', '123', '146', '156', '169', '173', '209', '229', '238']}; {'id': '31', 'type': 'if_statement', 'children': ['32', '35']}; {'id': '32', 'type': 'comparison_operator', 'children': ['33', '34'], 'value': '=='}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '34', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '35', 'type': 'block', 'children': ['36', '42', '46']}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}; {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'interfeature_start'}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}; {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'last_feature'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '46', 'type': 'continue_statement', 'children': []}; {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'interfeature_stop'}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '53', 'type': 'if_statement', 'children': ['54', '57']}; {'id': '54', 'type': 'comparison_operator', 'children': ['55', '56'], 'value': 'is'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'new_featuretype'}; {'id': '56', 'type': 'None', 'children': []}; {'id': '57', 'type': 'block', 'children': ['58']}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}; {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'new_featuretype'}; {'id': '61', 'type': 'binary_operator', 'children': ['62', '63'], 'value': '%'}; {'id': '62', 'type': 'string', 'children': [], 'value': "'inter_%s_%s'"}; {'id': '63', 'type': 'tuple', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'last_feature'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'featuretype'}; {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'featuretype'}; {'id': '70', 'type': 'if_statement', 'children': ['71', '78', '83']}; {'id': '71', 'type': 'comparison_operator', 'children': ['72', '75'], 'value': '!='}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'last_feature'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'strand'}; {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'strand'}; {'id': '78', 'type': 'block', 'children': ['79']}; {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'new_strand'}; {'id': '82', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '83', 'type': 'else_clause', 'children': ['84']}; {'id': '84', 'type': 'block', 'children': ['85']}; {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'new_strand'}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'strand'}; {'id': '91', 'type': 'if_statement', 'children': ['92', '99']}; {'id': '92', 'type': 'comparison_operator', 'children': ['93', '96'], 'value': '!='}; {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'last_feature'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'chrom'}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'chrom'}; {'id': '99', 'type': 'block', 'children': ['100', '104']}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}; {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'last_feature'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '104', 'type': 'continue_statement', 'children': []}; {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'strand'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'new_strand'}; {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'assignment', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'chrom'}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'last_feature'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'chrom'}; {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'augmented_assignment', 'children': ['117', '118'], 'value': '+='}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'interfeature_start'}; {'id': '118', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'augmented_assignment', 'children': ['121', '122'], 'value': '-='}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'interfeature_stop'}; {'id': '122', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '123', 'type': 'if_statement', 'children': ['124', '125', '140']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'merge_attributes'}; {'id': '125', 'type': 'block', 'children': ['126']}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}; {'id': '127', 'type': 'assignment', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'new_attributes'}; {'id': '129', 'type': 'call', 'children': ['130', '133']}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'helpers'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'merge_attributes'}; {'id': '133', 'type': 'argument_list', 'children': ['134', '137']}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'last_feature'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'attributes'}; {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'attributes'}; {'id': '140', 'type': 'else_clause', 'children': ['141']}; {'id': '141', 'type': 'block', 'children': ['142']}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}; {'id': '143', 'type': 'assignment', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'new_attributes'}; {'id': '145', 'type': 'dictionary', 'children': []}; {'id': '146', 'type': 'if_statement', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'update_attributes'}; {'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': 'new_attributes'}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '154', 'type': 'argument_list', 'children': ['155']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'update_attributes'}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}; {'id': '157', 'type': 'assignment', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'new_bin'}; {'id': '159', 'type': 'call', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'bins'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'bins'}; {'id': '163', 'type': 'argument_list', 'children': ['164', '165', '166']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'interfeature_start'}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'interfeature_stop'}; {'id': '166', 'type': 'keyword_argument', 'children': ['167', '168']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'one'}; {'id': '168', 'type': 'True', 'children': []}; {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'assignment', 'children': ['171', '172']}; {'id': '171', 'type': 'identifier', 'children': [], 'value': '_id'}; {'id': '172', 'type': 'None', 'children': []}; {'id': '173', 'type': 'expression_statement', 'children': ['174']}; {'id': '174', 'type': 'assignment', 'children': ['175', '176']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '176', 'type': 'call', 'children': ['177', '178']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '178', 'type': 'argument_list', 'children': ['179', '182', '185', '188', '191', '194', '197', '200', '203', '206']}; {'id': '179', 'type': 'keyword_argument', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'seqid'}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'chrom'}; {'id': '182', 'type': 'keyword_argument', 'children': ['183', '184']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '184', 'type': 'string', 'children': [], 'value': "'gffutils_derived'"}; {'id': '185', 'type': 'keyword_argument', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'featuretype'}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'new_featuretype'}; {'id': '188', 'type': 'keyword_argument', 'children': ['189', '190']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'interfeature_start'}; {'id': '191', 'type': 'keyword_argument', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'interfeature_stop'}; {'id': '194', 'type': 'keyword_argument', 'children': ['195', '196']}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'score'}; {'id': '196', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '197', 'type': 'keyword_argument', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'strand'}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'strand'}; {'id': '200', 'type': 'keyword_argument', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'frame'}; {'id': '202', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '203', 'type': 'keyword_argument', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'attributes'}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'new_attributes'}; {'id': '206', 'type': 'keyword_argument', 'children': ['207', '208']}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'bin'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'new_bin'}; {'id': '209', 'type': 'if_statement', 'children': ['210', '213']}; {'id': '210', 'type': 'comparison_operator', 'children': ['211', '212'], 'value': 'is'}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'dialect'}; {'id': '212', 'type': 'None', 'children': []}; {'id': '213', 'type': 'block', 'children': ['214']}; {'id': '214', 'type': 'try_statement', 'children': ['215', '222']}; {'id': '215', 'type': 'block', 'children': ['216']}; {'id': '216', 'type': 'expression_statement', 'children': ['217']}; {'id': '217', 'type': 'assignment', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'dialect'}; {'id': '219', 'type': 'attribute', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'dialect'}; {'id': '222', 'type': 'except_clause', 'children': ['223', '224']}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}; {'id': '224', 'type': 'block', 'children': ['225']}; {'id': '225', 'type': 'expression_statement', 'children': ['226']}; {'id': '226', 'type': 'assignment', 'children': ['227', '228']}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'dialect'}; {'id': '228', 'type': 'None', 'children': []}; {'id': '229', 'type': 'expression_statement', 'children': ['230']}; {'id': '230', 'type': 'yield', 'children': ['231']}; {'id': '231', 'type': 'call', 'children': ['232', '235']}; {'id': '232', 'type': 'attribute', 'children': ['233', '234']}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': '_feature_returner'}; {'id': '235', 'type': 'argument_list', 'children': ['236']}; {'id': '236', 'type': 'dictionary_splat', 'children': ['237']}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '238', 'type': 'expression_statement', 'children': ['239']}; {'id': '239', 'type': 'assignment', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'interfeature_start'}; {'id': '241', 'type': 'attribute', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'stop'}
|
def interfeatures(self, features, new_featuretype=None,
merge_attributes=True, dialect=None,
attribute_func=None, update_attributes=None):
for i, f in enumerate(features):
if i == 0:
interfeature_start = f.stop
last_feature = f
continue
interfeature_stop = f.start
if new_featuretype is None:
new_featuretype = 'inter_%s_%s' % (
last_feature.featuretype, f.featuretype)
if last_feature.strand != f.strand:
new_strand = '.'
else:
new_strand = f.strand
if last_feature.chrom != f.chrom:
last_feature = f
continue
strand = new_strand
chrom = last_feature.chrom
interfeature_start += 1
interfeature_stop -= 1
if merge_attributes:
new_attributes = helpers.merge_attributes(
last_feature.attributes, f.attributes)
else:
new_attributes = {}
if update_attributes:
new_attributes.update(update_attributes)
new_bin = bins.bins(
interfeature_start, interfeature_stop, one=True)
_id = None
fields = dict(
seqid=chrom,
source='gffutils_derived',
featuretype=new_featuretype,
start=interfeature_start,
end=interfeature_stop,
score='.',
strand=strand,
frame='.',
attributes=new_attributes,
bin=new_bin)
if dialect is None:
try:
dialect = self.dialect
except AttributeError:
dialect = None
yield self._feature_returner(**fields)
interfeature_start = f.stop
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'update'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'make_backup'}; {'id': '8', 'type': 'True', 'children': []}; {'id': '9', 'type': 'dictionary_splat_pattern', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '11', 'type': 'block', 'children': ['12', '17', '22', '50', '54', '77', '88', '184', '191', '197', '203']}; {'id': '12', 'type': 'import_from_statement', 'children': ['13', '15']}; {'id': '13', 'type': 'dotted_name', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'gffutils'}; {'id': '15', 'type': 'dotted_name', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'create'}; {'id': '17', 'type': 'import_from_statement', 'children': ['18', '20']}; {'id': '18', 'type': 'dotted_name', 'children': ['19']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'gffutils'}; {'id': '20', 'type': 'dotted_name', 'children': ['21']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'iterators'}; {'id': '22', 'type': 'if_statement', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'make_backup'}; {'id': '24', 'type': 'block', 'children': ['25']}; {'id': '25', 'type': 'if_statement', 'children': ['26', '35']}; {'id': '26', 'type': 'call', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '32']}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'dbfn'}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'string_types'}; {'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': 'shutil'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'copy2'}; {'id': '41', 'type': 'argument_list', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'dbfn'}; {'id': '45', 'type': 'binary_operator', 'children': ['46', '49'], 'value': '+'}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'dbfn'}; {'id': '49', 'type': 'string', 'children': [], 'value': "'.bak'"}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}; {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': '_iterator_kwargs'}; {'id': '53', 'type': 'dictionary', 'children': []}; {'id': '54', 'type': 'for_statement', 'children': ['55', '58', '63']}; {'id': '55', 'type': 'pattern_list', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '58', 'type': 'call', 'children': ['59', '62']}; {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '62', 'type': 'argument_list', 'children': []}; {'id': '63', 'type': 'block', 'children': ['64']}; {'id': '64', 'type': 'if_statement', 'children': ['65', '70']}; {'id': '65', 'type': 'comparison_operator', 'children': ['66', '67'], 'value': 'in'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'constants'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': '_iterator_kwargs'}; {'id': '70', 'type': 'block', 'children': ['71']}; {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '76']}; {'id': '73', 'type': 'subscript', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': '_iterator_kwargs'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '80', 'type': 'call', 'children': ['81', '84']}; {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'iterators'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'DataIterator'}; {'id': '84', 'type': 'argument_list', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '86', 'type': 'dictionary_splat', 'children': ['87']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': '_iterator_kwargs'}; {'id': '88', 'type': 'if_statement', 'children': ['89', '96', '137', '180']}; {'id': '89', 'type': 'comparison_operator', 'children': ['90', '95'], 'value': '=='}; {'id': '90', 'type': 'subscript', 'children': ['91', '94']}; {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'dialect'}; {'id': '94', 'type': 'string', 'children': [], 'value': "'fmt'"}; {'id': '95', 'type': 'string', 'children': [], 'value': "'gtf'"}; {'id': '96', 'type': 'block', 'children': ['97', '114']}; {'id': '97', 'type': 'if_statement', 'children': ['98', '101']}; {'id': '98', 'type': 'comparison_operator', 'children': ['99', '100'], 'value': 'not'}; {'id': '99', 'type': 'string', 'children': [], 'value': "'id_spec'"}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '101', 'type': 'block', 'children': ['102']}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}; {'id': '103', 'type': 'assignment', 'children': ['104', '107']}; {'id': '104', 'type': 'subscript', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '106', 'type': 'string', 'children': [], 'value': "'id_spec'"}; {'id': '107', 'type': 'dictionary', 'children': ['108', '111']}; {'id': '108', 'type': 'pair', 'children': ['109', '110']}; {'id': '109', 'type': 'string', 'children': [], 'value': "'gene'"}; {'id': '110', 'type': 'string', 'children': [], 'value': "'gene_id'"}; {'id': '111', 'type': 'pair', 'children': ['112', '113']}; {'id': '112', 'type': 'string', 'children': [], 'value': "'transcript'"}; {'id': '113', 'type': 'string', 'children': [], 'value': "'transcript_id'"}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}; {'id': '115', 'type': 'assignment', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'db'}; {'id': '117', 'type': 'call', 'children': ['118', '121']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'create'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': '_GTFDBCreator'}; {'id': '121', 'type': 'argument_list', 'children': ['122', '125', '130', '135']}; {'id': '122', 'type': 'keyword_argument', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '125', 'type': 'keyword_argument', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'dbfn'}; {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'dbfn'}; {'id': '130', 'type': 'keyword_argument', 'children': ['131', '132']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'dialect'}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'dialect'}; {'id': '135', 'type': 'dictionary_splat', 'children': ['136']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '137', 'type': 'elif_clause', 'children': ['138', '145']}; {'id': '138', 'type': 'comparison_operator', 'children': ['139', '144'], 'value': '=='}; {'id': '139', 'type': 'subscript', 'children': ['140', '143']}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'dialect'}; {'id': '143', 'type': 'string', 'children': [], 'value': "'fmt'"}; {'id': '144', 'type': 'string', 'children': [], 'value': "'gff3'"}; {'id': '145', 'type': 'block', 'children': ['146', '157']}; {'id': '146', 'type': 'if_statement', 'children': ['147', '150']}; {'id': '147', 'type': 'comparison_operator', 'children': ['148', '149'], 'value': 'not'}; {'id': '148', 'type': 'string', 'children': [], 'value': "'id_spec'"}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '150', 'type': 'block', 'children': ['151']}; {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'assignment', 'children': ['153', '156']}; {'id': '153', 'type': 'subscript', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '155', 'type': 'string', 'children': [], 'value': "'id_spec'"}; {'id': '156', 'type': 'string', 'children': [], 'value': "'ID'"}; {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'assignment', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'db'}; {'id': '160', 'type': 'call', 'children': ['161', '164']}; {'id': '161', 'type': 'attribute', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'create'}; {'id': '163', 'type': 'identifier', 'children': [], 'value': '_GFFDBCreator'}; {'id': '164', 'type': 'argument_list', 'children': ['165', '168', '173', '178']}; {'id': '165', 'type': 'keyword_argument', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '168', 'type': 'keyword_argument', 'children': ['169', '170']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'dbfn'}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'dbfn'}; {'id': '173', 'type': 'keyword_argument', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'dialect'}; {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'dialect'}; {'id': '178', 'type': 'dictionary_splat', 'children': ['179']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '180', 'type': 'else_clause', 'children': ['181']}; {'id': '181', 'type': 'block', 'children': ['182']}; {'id': '182', 'type': 'raise_statement', 'children': ['183']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '184', 'type': 'expression_statement', 'children': ['185']}; {'id': '185', 'type': 'call', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'db'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': '_populate_from_lines'}; {'id': '189', 'type': 'argument_list', 'children': ['190']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'call', 'children': ['193', '196']}; {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'db'}; {'id': '195', 'type': 'identifier', 'children': [], 'value': '_update_relations'}; {'id': '196', 'type': 'argument_list', 'children': []}; {'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': 'db'}; {'id': '201', 'type': 'identifier', 'children': [], 'value': '_finalize'}; {'id': '202', 'type': 'argument_list', 'children': []}; {'id': '203', 'type': 'return_statement', 'children': ['204']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'db'}
|
def update(self, data, make_backup=True, **kwargs):
from gffutils import create
from gffutils import iterators
if make_backup:
if isinstance(self.dbfn, six.string_types):
shutil.copy2(self.dbfn, self.dbfn + '.bak')
_iterator_kwargs = {}
for k, v in kwargs.items():
if k in constants._iterator_kwargs:
_iterator_kwargs[k] = v
data = iterators.DataIterator(data, **_iterator_kwargs)
if self.dialect['fmt'] == 'gtf':
if 'id_spec' not in kwargs:
kwargs['id_spec'] = {
'gene': 'gene_id', 'transcript': 'transcript_id'}
db = create._GTFDBCreator(
data=data, dbfn=self.dbfn, dialect=self.dialect, **kwargs)
elif self.dialect['fmt'] == 'gff3':
if 'id_spec' not in kwargs:
kwargs['id_spec'] = 'ID'
db = create._GFFDBCreator(
data=data, dbfn=self.dbfn, dialect=self.dialect, **kwargs)
else:
raise ValueError
db._populate_from_lines(data)
db._update_relations()
db._finalize()
return db
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'create_introns'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'exon_featuretype'}; {'id': '7', 'type': 'string', 'children': [], 'value': "'exon'"}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'grandparent_featuretype'}; {'id': '10', 'type': 'string', 'children': [], 'value': "'gene'"}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'parent_featuretype'}; {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'new_featuretype'}; {'id': '16', 'type': 'string', 'children': [], 'value': "'intron'"}; {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'merge_attributes'}; {'id': '19', 'type': 'True', 'children': []}; {'id': '20', 'type': 'block', 'children': ['21', '43', '93']}; {'id': '21', 'type': 'if_statement', 'children': ['22', '35']}; {'id': '22', 'type': 'boolean_operator', 'children': ['23', '27'], 'value': 'or'}; {'id': '23', 'type': '()', 'children': ['24']}; {'id': '24', 'type': 'boolean_operator', 'children': ['25', '26'], 'value': 'and'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'grandparent_featuretype'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'parent_featuretype'}; {'id': '27', 'type': '()', 'children': ['28']}; {'id': '28', 'type': 'boolean_operator', 'children': ['29', '32'], 'value': 'and'}; {'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': 'is'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'grandparent_featuretype'}; {'id': '31', 'type': 'None', 'children': []}; {'id': '32', 'type': 'comparison_operator', 'children': ['33', '34'], 'value': 'is'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'parent_featuretype'}; {'id': '34', 'type': 'None', 'children': []}; {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'raise_statement', 'children': ['37']}; {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'concatenated_string', 'children': ['41', '42']}; {'id': '41', 'type': 'string', 'children': [], 'value': '"exactly one of `grandparent_featuretype` or "'}; {'id': '42', 'type': 'string', 'children': [], 'value': '"`parent_featuretype` should be provided"'}; {'id': '43', 'type': 'if_statement', 'children': ['44', '45', '74']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'grandparent_featuretype'}; {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'function_definition', 'children': ['47', '48', '49']}; {'id': '47', 'type': 'function_name', 'children': [], 'value': 'child_gen'}; {'id': '48', 'type': 'parameters', 'children': []}; {'id': '49', 'type': 'block', 'children': ['50']}; {'id': '50', 'type': 'for_statement', 'children': ['51', '52', '58']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'gene'}; {'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': 'features_of_type'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'grandparent_featuretype'}; {'id': '58', 'type': 'block', 'children': ['59']}; {'id': '59', 'type': 'for_statement', 'children': ['60', '61', '70']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'children'}; {'id': '65', 'type': 'argument_list', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'gene'}; {'id': '67', 'type': 'keyword_argument', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '69', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '70', 'type': 'block', 'children': ['71']}; {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'yield', 'children': ['73']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '74', 'type': 'elif_clause', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'parent_featuretype'}; {'id': '76', 'type': 'block', 'children': ['77']}; {'id': '77', 'type': 'function_definition', 'children': ['78', '79', '80']}; {'id': '78', 'type': 'function_name', 'children': [], 'value': 'child_gen'}; {'id': '79', 'type': 'parameters', 'children': []}; {'id': '80', 'type': 'block', 'children': ['81']}; {'id': '81', 'type': 'for_statement', 'children': ['82', '83', '89']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '83', 'type': 'call', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'features_of_type'}; {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'parent_featuretype'}; {'id': '89', 'type': 'block', 'children': ['90']}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}; {'id': '91', 'type': 'yield', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '93', 'type': 'for_statement', 'children': ['94', '95', '98']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '95', 'type': 'call', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'child_gen'}; {'id': '97', 'type': 'argument_list', 'children': []}; {'id': '98', 'type': 'block', 'children': ['99', '117']}; {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'exons'}; {'id': '102', 'type': 'call', 'children': ['103', '106']}; {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'children'}; {'id': '106', 'type': 'argument_list', 'children': ['107', '108', '111', '114']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '108', 'type': 'keyword_argument', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '110', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '111', 'type': 'keyword_argument', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'featuretype'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'exon_featuretype'}; {'id': '114', 'type': 'keyword_argument', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'order_by'}; {'id': '116', 'type': 'string', 'children': [], 'value': "'start'"}; {'id': '117', 'type': 'for_statement', 'children': ['118', '119', '136']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'intron'}; {'id': '119', 'type': 'call', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'interfeatures'}; {'id': '123', 'type': 'argument_list', 'children': ['124', '125', '128', '131']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'exons'}; {'id': '125', 'type': 'keyword_argument', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'new_featuretype'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'new_featuretype'}; {'id': '128', 'type': 'keyword_argument', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'merge_attributes'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'merge_attributes'}; {'id': '131', 'type': 'keyword_argument', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'dialect'}; {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'dialect'}; {'id': '136', 'type': 'block', 'children': ['137']}; {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'yield', 'children': ['139']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'intron'}
|
def create_introns(self, exon_featuretype='exon',
grandparent_featuretype='gene', parent_featuretype=None,
new_featuretype='intron', merge_attributes=True):
if (grandparent_featuretype and parent_featuretype) or (
grandparent_featuretype is None and parent_featuretype is None
):
raise ValueError("exactly one of `grandparent_featuretype` or "
"`parent_featuretype` should be provided")
if grandparent_featuretype:
def child_gen():
for gene in self.features_of_type(grandparent_featuretype):
for child in self.children(gene, level=1):
yield child
elif parent_featuretype:
def child_gen():
for child in self.features_of_type(parent_featuretype):
yield child
for child in child_gen():
exons = self.children(child, level=1, featuretype=exon_featuretype,
order_by='start')
for intron in self.interfeatures(
exons, new_featuretype=new_featuretype,
merge_attributes=merge_attributes, dialect=self.dialect
):
yield intron
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.