sequence
stringlengths 1.25k
34.6k
| code
stringlengths 75
8.58k
|
---|---|
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '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 |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'merge'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'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': 'ignore_strand'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '17', '27', '70', '80', '98', '104', '112', '120', '213', '227', '264']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'features'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'features'},{'id': '17', 'type': 'if_statement', 'children': ['18', '24']},{'id': '18', 'type': 'comparison_operator', 'children': ['19', '23'], 'value': '=='},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'features'},{'id': '23', 'type': 'integer', 'children': [], 'value': '0'},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'raise_statement', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'StopIteration'},{'id': '27', 'type': 'if_statement', 'children': ['28', '29', '34']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'ignore_strand'},{'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': 'strand'},{'id': '33', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '34', 'type': 'else_clause', 'children': ['35']},{'id': '35', 'type': 'block', 'children': ['36', '46', '64']},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'strands'},{'id': '39', 'type': 'list_comprehension', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'strand'},{'id': '43', 'type': 'for_in_clause', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'features'},{'id': '46', 'type': 'if_statement', 'children': ['47', '56']},{'id': '47', 'type': 'comparison_operator', 'children': ['48', '55'], 'value': '>'},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'strands'},{'id': '55', 'type': 'integer', 'children': [], 'value': '1'},{'id': '56', 'type': 'block', 'children': ['57']},{'id': '57', 'type': 'raise_statement', 'children': ['58']},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'concatenated_string', 'children': ['62', '63']},{'id': '62', 'type': 'string', 'children': [], 'value': "'Specify ignore_strand=True to force merging '"},{'id': '63', 'type': 'string', 'children': [], 'value': "'of multiple strands'"},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'strand'},{'id': '67', 'type': 'subscript', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'strands'},{'id': '69', 'type': 'integer', 'children': [], 'value': '0'},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'chroms'},{'id': '73', 'type': 'list_comprehension', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '77', 'type': 'for_in_clause', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'features'},{'id': '80', 'type': 'if_statement', 'children': ['81', '90']},{'id': '81', 'type': 'comparison_operator', 'children': ['82', '89'], 'value': '>'},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'call', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'chroms'},{'id': '89', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'NotImplementedError'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'concatenated_string', 'children': ['96', '97']},{'id': '96', 'type': 'string', 'children': [], 'value': "'Merging multiple chromosomes not '"},{'id': '97', 'type': 'string', 'children': [], 'value': "'implemented'"},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '101', 'type': 'subscript', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'chroms'},{'id': '103', 'type': 'integer', 'children': [], 'value': '0'},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'current_merged_start'},{'id': '107', 'type': 'attribute', 'children': ['108', '111']},{'id': '108', 'type': 'subscript', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'features'},{'id': '110', 'type': 'integer', 'children': [], 'value': '0'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'current_merged_stop'},{'id': '115', 'type': 'attribute', 'children': ['116', '119']},{'id': '116', 'type': 'subscript', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'features'},{'id': '118', 'type': 'integer', 'children': [], 'value': '0'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '120', 'type': 'for_statement', 'children': ['121', '122', '127']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '122', 'type': 'subscript', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'features'},{'id': '124', 'type': 'slice', 'children': ['125', '126']},{'id': '125', 'type': 'integer', 'children': [], 'value': '1'},{'id': '126', 'type': 'colon', 'children': []},{'id': '127', 'type': 'block', 'children': ['128']},{'id': '128', 'type': 'if_statement', 'children': ['129', '136', '153']},{'id': '129', 'type': 'comparison_operator', 'children': ['130', '133'], 'value': '<='},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '133', 'type': 'binary_operator', 'children': ['134', '135'], 'value': '+'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'current_merged_stop'},{'id': '135', 'type': 'integer', 'children': [], 'value': '1'},{'id': '136', 'type': 'block', 'children': ['137']},{'id': '137', 'type': 'if_statement', 'children': ['138', '143', '150']},{'id': '138', 'type': 'comparison_operator', 'children': ['139', '142'], 'value': '>='},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'current_merged_stop'},{'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_merged_stop'},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '150', 'type': 'else_clause', 'children': ['151']},{'id': '151', 'type': 'block', 'children': ['152']},{'id': '152', 'type': 'continue_statement', 'children': []},{'id': '153', 'type': 'else_clause', 'children': ['154']},{'id': '154', 'type': 'block', 'children': ['155', '192', '201', '207']},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'merged_feature'},{'id': '158', 'type': 'call', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '160', 'type': 'argument_list', 'children': ['161', '166', '169', '174', '177', '180', '183', '186', '189']},{'id': '161', 'type': 'keyword_argument', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'seqid'},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '166', 'type': 'keyword_argument', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '168', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '169', 'type': 'keyword_argument', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'featuretype'},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'featuretype'},{'id': '174', 'type': 'keyword_argument', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'current_merged_start'},{'id': '177', 'type': 'keyword_argument', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'current_merged_stop'},{'id': '180', 'type': 'keyword_argument', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '182', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '183', 'type': 'keyword_argument', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'strand'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'strand'},{'id': '186', 'type': 'keyword_argument', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'frame'},{'id': '188', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '189', 'type': 'keyword_argument', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '191', 'type': 'string', 'children': [], 'value': "''"},{'id': '192', 'type': 'expression_statement', 'children': ['193']},{'id': '193', 'type': 'yield', 'children': ['194']},{'id': '194', 'type': 'call', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '197', 'type': 'identifier', 'children': [], 'value': '_feature_returner'},{'id': '198', 'type': 'argument_list', 'children': ['199']},{'id': '199', 'type': 'dictionary_splat', 'children': ['200']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'merged_feature'},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'assignment', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'current_merged_start'},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'assignment', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'current_merged_stop'},{'id': '210', 'type': 'attribute', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '213', 'type': 'if_statement', 'children': ['214', '220']},{'id': '214', 'type': 'comparison_operator', 'children': ['215', '219'], 'value': '=='},{'id': '215', 'type': 'call', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '217', 'type': 'argument_list', 'children': ['218']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'features'},{'id': '219', 'type': 'integer', 'children': [], 'value': '1'},{'id': '220', 'type': 'block', 'children': ['221']},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'assignment', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '224', 'type': 'subscript', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'features'},{'id': '226', 'type': 'integer', 'children': [], 'value': '0'},{'id': '227', 'type': 'expression_statement', 'children': ['228']},{'id': '228', 'type': 'assignment', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'merged_feature'},{'id': '230', 'type': 'call', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '232', 'type': 'argument_list', 'children': ['233', '238', '241', '246', '249', '252', '255', '258', '261']},{'id': '233', 'type': 'keyword_argument', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'seqid'},{'id': '235', 'type': 'attribute', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '238', 'type': 'keyword_argument', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '240', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '241', 'type': 'keyword_argument', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'featuretype'},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'featuretype'},{'id': '246', 'type': 'keyword_argument', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'current_merged_start'},{'id': '249', 'type': 'keyword_argument', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'current_merged_stop'},{'id': '252', 'type': 'keyword_argument', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '254', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '255', 'type': 'keyword_argument', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'strand'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'strand'},{'id': '258', 'type': 'keyword_argument', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'frame'},{'id': '260', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '261', 'type': 'keyword_argument', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '263', 'type': 'string', 'children': [], 'value': "''"},{'id': '264', 'type': 'expression_statement', 'children': ['265']},{'id': '265', 'type': 'yield', 'children': ['266']},{'id': '266', 'type': 'call', 'children': ['267', '270']},{'id': '267', 'type': 'attribute', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '269', 'type': 'identifier', 'children': [], 'value': '_feature_returner'},{'id': '270', 'type': 'argument_list', 'children': ['271']},{'id': '271', 'type': 'dictionary_splat', 'children': ['272']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'merged_feature'} | def merge(self, features, ignore_strand=False):
features = list(features)
if len(features) == 0:
raise StopIteration
if ignore_strand:
strand = '.'
else:
strands = [i.strand for i in features]
if len(set(strands)) > 1:
raise ValueError('Specify ignore_strand=True to force merging '
'of multiple strands')
strand = strands[0]
chroms = [i.chrom for i in features]
if len(set(chroms)) > 1:
raise NotImplementedError('Merging multiple chromosomes not '
'implemented')
chrom = chroms[0]
current_merged_start = features[0].start
current_merged_stop = features[0].stop
for feature in features[1:]:
if feature.start <= current_merged_stop + 1:
if feature.stop >= current_merged_stop:
current_merged_stop = feature.stop
else:
continue
else:
merged_feature = dict(
seqid=feature.chrom,
source='.',
featuretype=feature.featuretype,
start=current_merged_start,
end=current_merged_stop,
score='.',
strand=strand,
frame='.',
attributes='')
yield self._feature_returner(**merged_feature)
current_merged_start = feature.start
current_merged_stop = feature.stop
if len(features) == 1:
feature = features[0]
merged_feature = dict(
seqid=feature.chrom,
source='.',
featuretype=feature.featuretype,
start=current_merged_start,
end=current_merged_stop,
score='.',
strand=strand,
frame='.',
attributes='')
yield self._feature_returner(**merged_feature) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '23']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'bed12'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '10', '14', '17', '20']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'block_featuretype'},{'id': '8', 'type': 'list', 'children': ['9'], 'value': "['exon']"},{'id': '9', 'type': 'string', 'children': [], 'value': "'exon'"},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'thick_featuretype'},{'id': '12', 'type': 'list', 'children': ['13'], 'value': "['CDS']"},{'id': '13', 'type': 'string', 'children': [], 'value': "'CDS'"},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'thin_featuretype'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'name_field'},{'id': '19', 'type': 'string', 'children': [], 'value': "'ID'"},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'block', 'children': ['24', '36', '54', '67', '73', '81', '90', '108', '126', '135', '149', '155', '163', '169', '175', '181', '198', '204', '210', '219', '225', '229', '236', '247', '261', '323', '385', '399', '408', '442']},{'id': '24', 'type': 'if_statement', 'children': ['25', '28']},{'id': '25', 'type': 'boolean_operator', 'children': ['26', '27'], 'value': 'and'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'thick_featuretype'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'thin_featuretype'},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'raise_statement', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'concatenated_string', 'children': ['34', '35']},{'id': '34', 'type': 'string', 'children': [], 'value': '"Can only specify one of `thick_featuertype` or "'},{'id': '35', 'type': 'string', 'children': [], 'value': '"`thin_featuretype`"'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'exons'},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'list'},{'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': 'self'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '46', 'type': 'argument_list', 'children': ['47', '48', '51']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '48', 'type': 'keyword_argument', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'featuretype'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'block_featuretype'},{'id': '51', 'type': 'keyword_argument', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '53', 'type': 'string', 'children': [], 'value': "'start'"},{'id': '54', 'type': 'if_statement', 'children': ['55', '61']},{'id': '55', 'type': 'comparison_operator', 'children': ['56', '60'], 'value': '=='},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'exons'},{'id': '60', 'type': 'integer', 'children': [], 'value': '0'},{'id': '61', 'type': 'block', 'children': ['62']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'exons'},{'id': '65', 'type': 'list', 'children': ['66'], 'value': '[feature]'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '70', 'type': 'subscript', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'first'},{'id': '76', 'type': 'attribute', 'children': ['77', '80']},{'id': '77', 'type': 'subscript', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'exons'},{'id': '79', 'type': 'integer', 'children': [], 'value': '0'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'last'},{'id': '84', 'type': 'attribute', 'children': ['85', '89']},{'id': '85', 'type': 'subscript', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'exons'},{'id': '87', 'type': 'unary_operator', 'children': ['88'], 'value': '-'},{'id': '88', 'type': 'integer', 'children': [], 'value': '1'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '90', 'type': 'if_statement', 'children': ['91', '96']},{'id': '91', 'type': 'comparison_operator', 'children': ['92', '93'], 'value': '!='},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'first'},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '96', 'type': 'block', 'children': ['97']},{'id': '97', 'type': 'raise_statement', 'children': ['98']},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'binary_operator', 'children': ['102', '103'], 'value': '%'},{'id': '102', 'type': 'string', 'children': [], 'value': '"Start of first exon (%s) does not match start of feature (%s)"'},{'id': '103', 'type': 'tuple', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'first'},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '108', 'type': 'if_statement', 'children': ['109', '114']},{'id': '109', 'type': 'comparison_operator', 'children': ['110', '111'], 'value': '!='},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'last'},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'stop'},{'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': 'ValueError'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'binary_operator', 'children': ['120', '121'], 'value': '%'},{'id': '120', 'type': 'string', 'children': [], 'value': '"End of last exon (%s) does not match end of feature (%s)"'},{'id': '121', 'type': 'tuple', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'last'},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '126', 'type': 'if_statement', 'children': ['127', '130']},{'id': '127', 'type': 'comparison_operator', 'children': ['128', '129'], 'value': 'is'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '129', 'type': 'None', 'children': []},{'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': 'color'},{'id': '134', 'type': 'string', 'children': [], 'value': "'0,0,0'"},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'assignment', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '138', 'type': 'call', 'children': ['139', '148']},{'id': '139', 'type': 'attribute', 'children': ['140', '147']},{'id': '140', 'type': 'call', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '144', 'type': 'argument_list', 'children': ['145', '146']},{'id': '145', 'type': 'string', 'children': [], 'value': "' '"},{'id': '146', 'type': 'string', 'children': [], 'value': "''"},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '148', 'type': 'argument_list', 'children': []},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'chromStart'},{'id': '158', 'type': 'binary_operator', 'children': ['159', '162'], 'value': '-'},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '162', 'type': 'integer', 'children': [], 'value': '1'},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'chromEnd'},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'assignment', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'orig'},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'constants'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'always_return_list'},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'assignment', 'children': ['177', '180']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'constants'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'always_return_list'},{'id': '180', 'type': 'True', 'children': []},{'id': '181', 'type': 'try_statement', 'children': ['182', '191']},{'id': '182', 'type': 'block', 'children': ['183']},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'assignment', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '186', 'type': 'subscript', 'children': ['187', '190']},{'id': '187', 'type': 'subscript', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'name_field'},{'id': '190', 'type': 'integer', 'children': [], 'value': '0'},{'id': '191', 'type': 'except_clause', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'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': 'name'},{'id': '197', 'type': 'string', 'children': [], 'value': '"."'},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'constants'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'always_return_list'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'orig'},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'assignment', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '210', 'type': 'if_statement', 'children': ['211', '214']},{'id': '211', 'type': 'comparison_operator', 'children': ['212', '213'], 'value': '=='},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '213', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '214', 'type': 'block', 'children': ['215']},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'assignment', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '218', 'type': 'string', 'children': [], 'value': "'0'"},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'assignment', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'strand'},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'strand'},{'id': '225', 'type': 'expression_statement', 'children': ['226']},{'id': '226', 'type': 'assignment', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'itemRgb'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '229', 'type': 'expression_statement', 'children': ['230']},{'id': '230', 'type': 'assignment', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'blockCount'},{'id': '232', 'type': 'call', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '234', 'type': 'argument_list', 'children': ['235']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'exons'},{'id': '236', 'type': 'expression_statement', 'children': ['237']},{'id': '237', 'type': 'assignment', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'blockSizes'},{'id': '239', 'type': 'list_comprehension', 'children': ['240', '244']},{'id': '240', 'type': 'call', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '242', 'type': 'argument_list', 'children': ['243']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '244', 'type': 'for_in_clause', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'exons'},{'id': '247', 'type': 'expression_statement', 'children': ['248']},{'id': '248', 'type': 'assignment', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'blockStarts'},{'id': '250', 'type': 'list_comprehension', 'children': ['251', '258']},{'id': '251', 'type': 'binary_operator', 'children': ['252', '257'], 'value': '-'},{'id': '252', 'type': 'binary_operator', 'children': ['253', '256'], 'value': '-'},{'id': '253', 'type': 'attribute', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '256', 'type': 'integer', 'children': [], 'value': '1'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'chromStart'},{'id': '258', 'type': 'for_in_clause', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'exons'},{'id': '261', 'type': 'if_statement', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'thick_featuretype'},{'id': '263', 'type': 'block', 'children': ['264', '282']},{'id': '264', 'type': 'expression_statement', 'children': ['265']},{'id': '265', 'type': 'assignment', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'thick'},{'id': '267', 'type': 'call', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '269', 'type': 'argument_list', 'children': ['270']},{'id': '270', 'type': 'call', 'children': ['271', '274']},{'id': '271', 'type': 'attribute', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '274', 'type': 'argument_list', 'children': ['275', '276', '279']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '276', 'type': 'keyword_argument', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'featuretype'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'thick_featuretype'},{'id': '279', 'type': 'keyword_argument', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '281', 'type': 'string', 'children': [], 'value': "'start'"},{'id': '282', 'type': 'if_statement', 'children': ['283', '289', '302']},{'id': '283', 'type': 'comparison_operator', 'children': ['284', '288'], 'value': '=='},{'id': '284', 'type': 'call', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '286', 'type': 'argument_list', 'children': ['287']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'thick'},{'id': '288', 'type': 'integer', 'children': [], 'value': '0'},{'id': '289', 'type': 'block', 'children': ['290', '296']},{'id': '290', 'type': 'expression_statement', 'children': ['291']},{'id': '291', 'type': 'assignment', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'thickStart'},{'id': '293', 'type': 'attribute', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '296', 'type': 'expression_statement', 'children': ['297']},{'id': '297', 'type': 'assignment', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'thickEnd'},{'id': '299', 'type': 'attribute', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '302', 'type': 'else_clause', 'children': ['303']},{'id': '303', 'type': 'block', 'children': ['304', '314']},{'id': '304', 'type': 'expression_statement', 'children': ['305']},{'id': '305', 'type': 'assignment', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'thickStart'},{'id': '307', 'type': 'binary_operator', 'children': ['308', '313'], 'value': '-'},{'id': '308', 'type': 'attribute', 'children': ['309', '312']},{'id': '309', 'type': 'subscript', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'thick'},{'id': '311', 'type': 'integer', 'children': [], 'value': '0'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '313', 'type': 'integer', 'children': [], 'value': '1'},{'id': '314', 'type': 'expression_statement', 'children': ['315']},{'id': '315', 'type': 'assignment', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'thickEnd'},{'id': '317', 'type': 'attribute', 'children': ['318', '322']},{'id': '318', 'type': 'subscript', 'children': ['319', '320']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'thick'},{'id': '320', 'type': 'unary_operator', 'children': ['321'], 'value': '-'},{'id': '321', 'type': 'integer', 'children': [], 'value': '1'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '323', 'type': 'if_statement', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'thin_featuretype'},{'id': '325', 'type': 'block', 'children': ['326', '344']},{'id': '326', 'type': 'expression_statement', 'children': ['327']},{'id': '327', 'type': 'assignment', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'thin'},{'id': '329', 'type': 'call', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '331', 'type': 'argument_list', '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': 'children'},{'id': '336', 'type': 'argument_list', 'children': ['337', '338', '341']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '338', 'type': 'keyword_argument', 'children': ['339', '340']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'featuretype'},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'thin_featuretype'},{'id': '341', 'type': 'keyword_argument', 'children': ['342', '343']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '343', 'type': 'string', 'children': [], 'value': "'start'"},{'id': '344', 'type': 'if_statement', 'children': ['345', '351', '364']},{'id': '345', 'type': 'comparison_operator', 'children': ['346', '350'], 'value': '=='},{'id': '346', 'type': 'call', 'children': ['347', '348']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '348', 'type': 'argument_list', 'children': ['349']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'thin'},{'id': '350', 'type': 'integer', 'children': [], 'value': '0'},{'id': '351', 'type': 'block', 'children': ['352', '358']},{'id': '352', 'type': 'expression_statement', 'children': ['353']},{'id': '353', 'type': 'assignment', 'children': ['354', '355']},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'thickStart'},{'id': '355', 'type': 'attribute', 'children': ['356', '357']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '358', 'type': 'expression_statement', 'children': ['359']},{'id': '359', 'type': 'assignment', 'children': ['360', '361']},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'thickEnd'},{'id': '361', 'type': 'attribute', 'children': ['362', '363']},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '364', 'type': 'else_clause', 'children': ['365']},{'id': '365', 'type': 'block', 'children': ['366', '374']},{'id': '366', 'type': 'expression_statement', 'children': ['367']},{'id': '367', 'type': 'assignment', 'children': ['368', '369']},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'thickStart'},{'id': '369', 'type': 'attribute', 'children': ['370', '373']},{'id': '370', 'type': 'subscript', 'children': ['371', '372']},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'thin'},{'id': '372', 'type': 'integer', 'children': [], 'value': '0'},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '374', 'type': 'expression_statement', 'children': ['375']},{'id': '375', 'type': 'assignment', 'children': ['376', '377']},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'thickEnd'},{'id': '377', 'type': 'binary_operator', 'children': ['378', '384'], 'value': '-'},{'id': '378', 'type': 'attribute', 'children': ['379', '383']},{'id': '379', 'type': 'subscript', 'children': ['380', '381']},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'thin'},{'id': '381', 'type': 'unary_operator', 'children': ['382'], 'value': '-'},{'id': '382', 'type': 'integer', 'children': [], 'value': '1'},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '384', 'type': 'integer', 'children': [], 'value': '1'},{'id': '385', 'type': 'expression_statement', 'children': ['386']},{'id': '386', 'type': 'assignment', 'children': ['387', '388']},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'tst'},{'id': '388', 'type': 'binary_operator', 'children': ['389', '395'], 'value': '+'},{'id': '389', 'type': 'binary_operator', 'children': ['390', '391'], 'value': '+'},{'id': '390', 'type': 'identifier', 'children': [], 'value': 'chromStart'},{'id': '391', 'type': 'subscript', 'children': ['392', '393']},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'blockStarts'},{'id': '393', 'type': 'unary_operator', 'children': ['394'], 'value': '-'},{'id': '394', 'type': 'integer', 'children': [], 'value': '1'},{'id': '395', 'type': 'subscript', 'children': ['396', '397']},{'id': '396', 'type': 'identifier', 'children': [], 'value': 'blockSizes'},{'id': '397', 'type': 'unary_operator', 'children': ['398'], 'value': '-'},{'id': '398', 'type': 'integer', 'children': [], 'value': '1'},{'id': '399', 'type': 'assert_statement', 'children': ['400', '403']},{'id': '400', 'type': 'comparison_operator', 'children': ['401', '402'], 'value': '=='},{'id': '401', 'type': 'identifier', 'children': [], 'value': 'tst'},{'id': '402', 'type': 'identifier', 'children': [], 'value': 'chromEnd'},{'id': '403', 'type': 'binary_operator', 'children': ['404', '405'], 'value': '%'},{'id': '404', 'type': 'string', 'children': [], 'value': '"tst=%s; chromEnd=%s"'},{'id': '405', 'type': 'tuple', 'children': ['406', '407']},{'id': '406', 'type': 'identifier', 'children': [], 'value': 'tst'},{'id': '407', 'type': 'identifier', 'children': [], 'value': 'chromEnd'},{'id': '408', 'type': 'expression_statement', 'children': ['409']},{'id': '409', 'type': 'assignment', 'children': ['410', '411']},{'id': '410', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '411', 'type': 'list', 'children': ['412', '413', '414', '415', '416', '417', '418', '419', '420', '421', '422', '432'], 'value': "[\n chrom,\n chromStart,\n chromEnd,\n name,\n score,\n strand,\n thickStart,\n thickEnd,\n itemRgb,\n blockCount,\n ','.join(map(str, blockSizes)),\n ','.join(map(str, blockStarts))]"},{'id': '412', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '413', 'type': 'identifier', 'children': [], 'value': 'chromStart'},{'id': '414', 'type': 'identifier', 'children': [], 'value': 'chromEnd'},{'id': '415', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '416', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '417', 'type': 'identifier', 'children': [], 'value': 'strand'},{'id': '418', 'type': 'identifier', 'children': [], 'value': 'thickStart'},{'id': '419', 'type': 'identifier', 'children': [], 'value': 'thickEnd'},{'id': '420', 'type': 'identifier', 'children': [], 'value': 'itemRgb'},{'id': '421', 'type': 'identifier', 'children': [], 'value': 'blockCount'},{'id': '422', 'type': 'call', 'children': ['423', '426']},{'id': '423', 'type': 'attribute', 'children': ['424', '425']},{'id': '424', 'type': 'string', 'children': [], 'value': "','"},{'id': '425', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '426', 'type': 'argument_list', 'children': ['427']},{'id': '427', 'type': 'call', 'children': ['428', '429']},{'id': '428', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '429', 'type': 'argument_list', 'children': ['430', '431']},{'id': '430', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '431', 'type': 'identifier', 'children': [], 'value': 'blockSizes'},{'id': '432', 'type': 'call', 'children': ['433', '436']},{'id': '433', 'type': 'attribute', 'children': ['434', '435']},{'id': '434', 'type': 'string', 'children': [], 'value': "','"},{'id': '435', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '436', 'type': 'argument_list', 'children': ['437']},{'id': '437', 'type': 'call', 'children': ['438', '439']},{'id': '438', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '439', 'type': 'argument_list', 'children': ['440', '441']},{'id': '440', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '441', 'type': 'identifier', 'children': [], 'value': 'blockStarts'},{'id': '442', 'type': 'return_statement', 'children': ['443']},{'id': '443', 'type': 'call', 'children': ['444', '447']},{'id': '444', 'type': 'attribute', 'children': ['445', '446']},{'id': '445', 'type': 'string', 'children': [], 'value': "'\\t'"},{'id': '446', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '447', 'type': 'argument_list', 'children': ['448']},{'id': '448', 'type': 'call', 'children': ['449', '450']},{'id': '449', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '450', 'type': 'argument_list', 'children': ['451', '452']},{'id': '451', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '452', 'type': 'identifier', 'children': [], 'value': 'fields'} | def bed12(self, feature, block_featuretype=['exon'],
thick_featuretype=['CDS'], thin_featuretype=None,
name_field='ID', color=None):
if thick_featuretype and thin_featuretype:
raise ValueError("Can only specify one of `thick_featuertype` or "
"`thin_featuretype`")
exons = list(self.children(feature, featuretype=block_featuretype,
order_by='start'))
if len(exons) == 0:
exons = [feature]
feature = self[feature]
first = exons[0].start
last = exons[-1].stop
if first != feature.start:
raise ValueError(
"Start of first exon (%s) does not match start of feature (%s)"
% (first, feature.start))
if last != feature.stop:
raise ValueError(
"End of last exon (%s) does not match end of feature (%s)"
% (last, feature.stop))
if color is None:
color = '0,0,0'
color = color.replace(' ', '').strip()
chrom = feature.chrom
chromStart = feature.start - 1
chromEnd = feature.stop
orig = constants.always_return_list
constants.always_return_list = True
try:
name = feature[name_field][0]
except KeyError:
name = "."
constants.always_return_list = orig
score = feature.score
if score == '.':
score = '0'
strand = feature.strand
itemRgb = color
blockCount = len(exons)
blockSizes = [len(i) for i in exons]
blockStarts = [i.start - 1 - chromStart for i in exons]
if thick_featuretype:
thick = list(self.children(feature, featuretype=thick_featuretype,
order_by='start'))
if len(thick) == 0:
thickStart = feature.start
thickEnd = feature.stop
else:
thickStart = thick[0].start - 1
thickEnd = thick[-1].stop
if thin_featuretype:
thin = list(self.children(feature, featuretype=thin_featuretype,
order_by='start'))
if len(thin) == 0:
thickStart = feature.start
thickEnd = feature.stop
else:
thickStart = thin[0].stop
thickEnd = thin[-1].start - 1
tst = chromStart + blockStarts[-1] + blockSizes[-1]
assert tst == chromEnd, "tst=%s; chromEnd=%s" % (tst, chromEnd)
fields = [
chrom,
chromStart,
chromEnd,
name,
score,
strand,
thickStart,
thickEnd,
itemRgb,
blockCount,
','.join(map(str, blockSizes)),
','.join(map(str, blockStarts))]
return '\t'.join(map(str, fields)) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'inspect'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '12', '15']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'look_for'},{'id': '7', 'type': 'list', 'children': ['8', '9', '10', '11'], 'value': "['featuretype', 'chrom', 'attribute_keys',\n 'feature_count']"},{'id': '8', 'type': 'string', 'children': [], 'value': "'featuretype'"},{'id': '9', 'type': 'string', 'children': [], 'value': "'chrom'"},{'id': '10', 'type': 'string', 'children': [], 'value': "'attribute_keys'"},{'id': '11', 'type': 'string', 'children': [], 'value': "'feature_count'"},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '17', 'type': 'True', 'children': []},{'id': '18', 'type': 'block', 'children': ['19', '23', '27', '53', '59', '68', '72', '146', '150', '169', '175']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '22', 'type': 'dictionary', 'children': []},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'obj_attrs'},{'id': '26', 'type': 'list', 'children': [], 'value': '[]'},{'id': '27', 'type': 'for_statement', 'children': ['28', '29', '30']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'look_for'},{'id': '30', 'type': 'block', 'children': ['31', '45']},{'id': '31', 'type': 'if_statement', 'children': ['32', '37']},{'id': '32', 'type': 'comparison_operator', 'children': ['33', '34'], 'value': 'not'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '34', 'type': 'list', 'children': ['35', '36'], 'value': "['attribute_keys', 'feature_count']"},{'id': '35', 'type': 'string', 'children': [], 'value': "'attribute_keys'"},{'id': '36', 'type': 'string', 'children': [], 'value': "'feature_count'"},{'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': 'obj_attrs'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '50']},{'id': '47', 'type': 'subscript', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'Counter'},{'id': '52', 'type': 'argument_list', 'children': []},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'attr_keys'},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': 'in'},{'id': '57', 'type': 'string', 'children': [], 'value': "'attribute_keys'"},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'look_for'},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'iterators'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'DataIterator'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'feature_count'},{'id': '71', 'type': 'integer', 'children': [], 'value': '0'},{'id': '72', 'type': 'for_statement', 'children': ['73', '74', '75']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '75', 'type': 'block', 'children': ['76', '98', '116', '134', '138']},{'id': '76', 'type': 'if_statement', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '78', 'type': 'block', 'children': ['79', '90']},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'call', 'children': ['81', '86']},{'id': '81', 'type': 'attribute', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'binary_operator', 'children': ['88', '89'], 'value': '%'},{'id': '88', 'type': 'string', 'children': [], 'value': "'\\r%s features inspected'"},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'feature_count'},{'id': '90', 'type': 'expression_statement', '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': 'sys'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'flush'},{'id': '97', 'type': 'argument_list', 'children': []},{'id': '98', 'type': 'for_statement', 'children': ['99', '100', '101']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'obj_attr'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'obj_attrs'},{'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': 'results'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'obj_attr'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'list', 'children': ['111'], 'value': '[getattr(f, obj_attr)]'},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '113', 'type': 'argument_list', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'obj_attr'},{'id': '116', 'type': 'if_statement', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'attr_keys'},{'id': '118', 'type': 'block', 'children': ['119']},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'call', 'children': ['121', '126']},{'id': '121', 'type': 'attribute', 'children': ['122', '125']},{'id': '122', 'type': 'subscript', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '124', 'type': 'string', 'children': [], 'value': "'attribute_keys'"},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'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': 'f'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '133', 'type': 'argument_list', 'children': []},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'augmented_assignment', 'children': ['136', '137'], 'value': '+='},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'feature_count'},{'id': '137', 'type': 'integer', 'children': [], 'value': '1'},{'id': '138', 'type': 'if_statement', 'children': ['139', '144']},{'id': '139', 'type': 'boolean_operator', 'children': ['140', '141'], 'value': 'and'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '141', 'type': 'comparison_operator', 'children': ['142', '143'], 'value': '=='},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'feature_count'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '144', 'type': 'block', 'children': ['145']},{'id': '145', 'type': 'break_statement', 'children': []},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'assignment', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'new_results'},{'id': '149', 'type': 'dictionary', 'children': []},{'id': '150', 'type': 'for_statement', 'children': ['151', '154', '159']},{'id': '151', 'type': 'pattern_list', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '154', 'type': 'call', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '158', 'type': 'argument_list', 'children': []},{'id': '159', 'type': 'block', 'children': ['160']},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '165']},{'id': '162', 'type': 'subscript', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'new_results'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '165', 'type': 'call', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '167', 'type': 'argument_list', 'children': ['168']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'assignment', 'children': ['171', '174']},{'id': '171', 'type': 'subscript', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'new_results'},{'id': '173', 'type': 'string', 'children': [], 'value': "'feature_count'"},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'feature_count'},{'id': '175', 'type': 'return_statement', 'children': ['176']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'new_results'} | def inspect(data, look_for=['featuretype', 'chrom', 'attribute_keys',
'feature_count'], limit=None, verbose=True):
results = {}
obj_attrs = []
for i in look_for:
if i not in ['attribute_keys', 'feature_count']:
obj_attrs.append(i)
results[i] = Counter()
attr_keys = 'attribute_keys' in look_for
d = iterators.DataIterator(data)
feature_count = 0
for f in d:
if verbose:
sys.stderr.write('\r%s features inspected' % feature_count)
sys.stderr.flush()
for obj_attr in obj_attrs:
results[obj_attr].update([getattr(f, obj_attr)])
if attr_keys:
results['attribute_keys'].update(f.attributes.keys())
feature_count += 1
if limit and feature_count == limit:
break
new_results = {}
for k, v in results.items():
new_results[k] = dict(v)
new_results['feature_count'] = feature_count
return new_results |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'feature_from_line'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'dialect'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'strict'},{'id': '10', 'type': 'True', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'keep_order'},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '125', '140', '154', '170', '176', '186', '192', '201']},{'id': '15', 'type': 'if_statement', 'children': ['16', '18', '109']},{'id': '16', 'type': 'not_operator', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'strict'},{'id': '18', 'type': 'block', 'children': ['19', '28', '32', '59', '67', '73']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'splitlines'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'False', 'children': []},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': '_lines'},{'id': '31', 'type': 'list', 'children': [], 'value': '[]'},{'id': '32', 'type': 'for_statement', 'children': ['33', '34', '35']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '35', 'type': 'block', 'children': ['36', '44']},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '43', 'type': 'argument_list', 'children': []},{'id': '44', 'type': 'if_statement', 'children': ['45', '51']},{'id': '45', 'type': 'comparison_operator', 'children': ['46', '50'], 'value': '>'},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '50', 'type': 'integer', 'children': [], 'value': '0'},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': '_lines'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '59', 'type': 'assert_statement', 'children': ['60', '66']},{'id': '60', 'type': 'comparison_operator', 'children': ['61', '65'], 'value': '=='},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': '_lines'},{'id': '65', 'type': 'integer', 'children': [], 'value': '1'},{'id': '66', 'type': 'identifier', 'children': [], 'value': '_lines'},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '70', 'type': 'subscript', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': '_lines'},{'id': '72', 'type': 'integer', 'children': [], 'value': '0'},{'id': '73', 'type': 'if_statement', 'children': ['74', '77', '92']},{'id': '74', 'type': 'comparison_operator', 'children': ['75', '76'], 'value': 'in'},{'id': '75', 'type': 'string', 'children': [], 'value': "'\\t'"},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '77', 'type': 'block', 'children': ['78']},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '81', 'type': 'call', 'children': ['82', '90']},{'id': '82', 'type': 'attribute', 'children': ['83', '89']},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'rstrip'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'string', 'children': [], 'value': "'\\n\\r'"},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'string', 'children': [], 'value': "'\\t'"},{'id': '92', 'type': 'else_clause', 'children': ['93']},{'id': '93', 'type': 'block', 'children': ['94']},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '97', 'type': 'call', 'children': ['98', '106']},{'id': '98', 'type': 'attribute', 'children': ['99', '105']},{'id': '99', 'type': 'call', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'rstrip'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'string', 'children': [], 'value': "'\\n\\r'"},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '106', 'type': 'argument_list', 'children': ['107', '108']},{'id': '107', 'type': 'None', 'children': []},{'id': '108', 'type': 'integer', 'children': [], 'value': '8'},{'id': '109', 'type': 'else_clause', 'children': ['110']},{'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': 'fields'},{'id': '114', 'type': 'call', 'children': ['115', '123']},{'id': '115', 'type': 'attribute', 'children': ['116', '122']},{'id': '116', 'type': 'call', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'rstrip'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'string', 'children': [], 'value': "'\\n\\r'"},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'string', 'children': [], 'value': "'\\t'"},{'id': '125', 'type': 'try_statement', 'children': ['126', '133']},{'id': '126', 'type': 'block', 'children': ['127']},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'attr_string'},{'id': '130', 'type': 'subscript', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '132', 'type': 'integer', 'children': [], 'value': '8'},{'id': '133', 'type': 'except_clause', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'IndexError'},{'id': '135', 'type': 'block', 'children': ['136']},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'attr_string'},{'id': '139', 'type': 'string', 'children': [], 'value': '""'},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'assignment', 'children': ['142', '145']},{'id': '142', 'type': 'pattern_list', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'attrs'},{'id': '144', 'type': 'identifier', 'children': [], 'value': '_dialect'},{'id': '145', 'type': 'call', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '148', 'type': 'identifier', 'children': [], 'value': '_split_keyvals'},{'id': '149', 'type': 'argument_list', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'attr_string'},{'id': '151', 'type': 'keyword_argument', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'dialect'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'dialect'},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'assignment', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'call', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'call', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '165', 'type': 'argument_list', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'constants'},{'id': '168', 'type': 'identifier', 'children': [], 'value': '_gffkeys'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'assignment', 'children': ['172', '175']},{'id': '172', 'type': 'subscript', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '174', 'type': 'string', 'children': [], 'value': "'attributes'"},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'attrs'},{'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': 'd'},{'id': '180', 'type': 'string', 'children': [], 'value': "'extra'"},{'id': '181', 'type': 'subscript', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '183', 'type': 'slice', 'children': ['184', '185']},{'id': '184', 'type': 'integer', 'children': [], 'value': '9'},{'id': '185', 'type': 'colon', 'children': []},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '191']},{'id': '188', 'type': 'subscript', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '190', 'type': 'string', 'children': [], 'value': "'keep_order'"},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'keep_order'},{'id': '192', 'type': 'if_statement', 'children': ['193', '196']},{'id': '193', 'type': 'comparison_operator', 'children': ['194', '195'], 'value': 'is'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'dialect'},{'id': '195', 'type': 'None', 'children': []},{'id': '196', 'type': 'block', 'children': ['197']},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'assignment', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'dialect'},{'id': '200', 'type': 'identifier', 'children': [], 'value': '_dialect'},{'id': '201', 'type': 'return_statement', 'children': ['202']},{'id': '202', 'type': 'call', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'Feature'},{'id': '204', 'type': 'argument_list', 'children': ['205', '208']},{'id': '205', 'type': 'keyword_argument', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'dialect'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'dialect'},{'id': '208', 'type': 'dictionary_splat', 'children': ['209']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'd'} | def feature_from_line(line, dialect=None, strict=True, keep_order=False):
if not strict:
lines = line.splitlines(False)
_lines = []
for i in lines:
i = i.strip()
if len(i) > 0:
_lines.append(i)
assert len(_lines) == 1, _lines
line = _lines[0]
if '\t' in line:
fields = line.rstrip('\n\r').split('\t')
else:
fields = line.rstrip('\n\r').split(None, 8)
else:
fields = line.rstrip('\n\r').split('\t')
try:
attr_string = fields[8]
except IndexError:
attr_string = ""
attrs, _dialect = parser._split_keyvals(attr_string, dialect=dialect)
d = dict(list(zip(constants._gffkeys, fields)))
d['attributes'] = attrs
d['extra'] = fields[9:]
d['keep_order'] = keep_order
if dialect is None:
dialect = _dialect
return Feature(dialect=dialect, **d) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_reconstruct'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'keyvals'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'dialect'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'keep_order'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'sort_attribute_values'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '21', '27', '31', '92', '157', '180', '192', '284', '295', '304']},{'id': '13', 'type': 'if_statement', 'children': ['14', '16']},{'id': '14', 'type': 'not_operator', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'dialect'},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'raise_statement', 'children': ['18']},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'AttributeStringError'},{'id': '20', 'type': 'argument_list', 'children': []},{'id': '21', 'type': 'if_statement', 'children': ['22', '24']},{'id': '22', 'type': 'not_operator', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'keyvals'},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'return_statement', 'children': ['26']},{'id': '26', 'type': 'string', 'children': [], 'value': '""'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '30', 'type': 'list', 'children': [], 'value': '[]'},{'id': '31', 'type': 'if_statement', 'children': ['32', '41', '46']},{'id': '32', 'type': 'boolean_operator', 'children': ['33', '36'], 'value': 'or'},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'constants'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'ignore_url_escape_characters'},{'id': '36', 'type': 'comparison_operator', 'children': ['37', '40'], 'value': '!='},{'id': '37', 'type': 'subscript', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'dialect'},{'id': '39', 'type': 'string', 'children': [], 'value': "'fmt'"},{'id': '40', 'type': 'string', 'children': [], 'value': "'gff3'"},{'id': '41', 'type': 'block', 'children': ['42']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'keyvals'},{'id': '46', 'type': 'else_clause', 'children': ['47']},{'id': '47', 'type': 'block', 'children': ['48', '52']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '51', 'type': 'dictionary', 'children': []},{'id': '52', 'type': 'for_statement', 'children': ['53', '56', '61']},{'id': '53', 'type': 'pattern_list', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'keyvals'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '60', 'type': 'argument_list', 'children': []},{'id': '61', 'type': 'block', 'children': ['62', '68']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '67']},{'id': '64', 'type': 'subscript', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '67', 'type': 'list', 'children': [], 'value': '[]'},{'id': '68', 'type': 'for_statement', 'children': ['69', '70', '71']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '71', 'type': 'block', 'children': ['72']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'call', 'children': ['74', '79']},{'id': '74', 'type': 'attribute', 'children': ['75', '78']},{'id': '75', 'type': 'subscript', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'call', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'string', 'children': [], 'value': "''"},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'list_comprehension', 'children': ['86', '89']},{'id': '86', 'type': 'subscript', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'quoter'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '89', 'type': 'for_in_clause', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '92', 'type': 'if_statement', 'children': ['93', '96', '144']},{'id': '93', 'type': 'subscript', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'dialect'},{'id': '95', 'type': 'string', 'children': [], 'value': "'repeated keys'"},{'id': '96', 'type': 'block', 'children': ['97', '101']},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '100', 'type': 'list', 'children': [], 'value': '[]'},{'id': '101', 'type': 'for_statement', 'children': ['102', '105', '110']},{'id': '102', 'type': 'pattern_list', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '109', 'type': 'argument_list', 'children': []},{'id': '110', 'type': 'block', 'children': ['111']},{'id': '111', 'type': 'if_statement', 'children': ['112', '118', '133']},{'id': '112', 'type': 'comparison_operator', 'children': ['113', '117'], 'value': '>'},{'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': 'val'},{'id': '117', 'type': 'integer', 'children': [], 'value': '1'},{'id': '118', 'type': 'block', 'children': ['119']},{'id': '119', 'type': 'for_statement', 'children': ['120', '121', '122']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'val'},{'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': 'items'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'tuple', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '131', 'type': 'list', 'children': ['132'], 'value': '[v]'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '133', 'type': 'else_clause', 'children': ['134']},{'id': '134', 'type': 'block', 'children': ['135']},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'call', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'tuple', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '144', 'type': 'else_clause', 'children': ['145']},{'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': 'items'},{'id': '149', 'type': 'call', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '151', 'type': 'argument_list', 'children': ['152']},{'id': '152', 'type': 'call', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '156', 'type': 'argument_list', 'children': []},{'id': '157', 'type': 'function_definition', 'children': ['158', '159', '161']},{'id': '158', 'type': 'function_name', 'children': [], 'value': 'sort_key'},{'id': '159', 'type': 'parameters', 'children': ['160']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '161', 'type': 'block', 'children': ['162']},{'id': '162', 'type': 'try_statement', 'children': ['163', '175']},{'id': '163', 'type': 'block', 'children': ['164']},{'id': '164', 'type': 'return_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': 'dialect'},{'id': '169', 'type': 'string', 'children': [], 'value': "'order'"},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'subscript', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '174', 'type': 'integer', 'children': [], 'value': '0'},{'id': '175', 'type': 'except_clause', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '177', 'type': 'block', 'children': ['178']},{'id': '178', 'type': 'return_statement', 'children': ['179']},{'id': '179', 'type': 'float', 'children': [], 'value': '1e6'},{'id': '180', 'type': 'if_statement', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'keep_order'},{'id': '182', 'type': 'block', 'children': ['183']},{'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': 'items'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'keyword_argument', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '192', 'type': 'for_statement', 'children': ['193', '196', '197']},{'id': '193', 'type': 'pattern_list', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '197', 'type': 'block', 'children': ['198', '277']},{'id': '198', 'type': 'if_statement', 'children': ['199', '200', '249']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '200', 'type': 'block', 'children': ['201', '211', '222']},{'id': '201', 'type': 'if_statement', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'sort_attribute_values'},{'id': '203', 'type': 'block', 'children': ['204']},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'assignment', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '207', 'type': 'call', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '209', 'type': 'argument_list', 'children': ['210']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'assignment', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'val_str'},{'id': '214', 'type': 'call', 'children': ['215', '220']},{'id': '215', 'type': 'attribute', 'children': ['216', '219']},{'id': '216', 'type': 'subscript', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'dialect'},{'id': '218', 'type': 'string', 'children': [], 'value': "'multival separator'"},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '220', 'type': 'argument_list', 'children': ['221']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '222', 'type': 'if_statement', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'val_str'},{'id': '224', 'type': 'block', 'children': ['225', '236']},{'id': '225', 'type': 'if_statement', 'children': ['226', '229']},{'id': '226', 'type': 'subscript', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'dialect'},{'id': '228', 'type': 'string', 'children': [], 'value': "'quoted GFF2 values'"},{'id': '229', 'type': 'block', 'children': ['230']},{'id': '230', 'type': 'expression_statement', 'children': ['231']},{'id': '231', 'type': 'assignment', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'val_str'},{'id': '233', 'type': 'binary_operator', 'children': ['234', '235'], 'value': '%'},{'id': '234', 'type': 'string', 'children': [], 'value': '\'"%s"\''},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'val_str'},{'id': '236', 'type': 'expression_statement', 'children': ['237']},{'id': '237', 'type': 'assignment', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'part'},{'id': '239', 'type': 'call', 'children': ['240', '245']},{'id': '240', 'type': 'attribute', 'children': ['241', '244']},{'id': '241', 'type': 'subscript', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'dialect'},{'id': '243', 'type': 'string', 'children': [], 'value': "'keyval separator'"},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '245', 'type': 'argument_list', 'children': ['246']},{'id': '246', 'type': 'list', 'children': ['247', '248'], 'value': '[key, val_str]'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'val_str'},{'id': '249', 'type': 'else_clause', 'children': ['250']},{'id': '250', 'type': 'block', 'children': ['251']},{'id': '251', 'type': 'if_statement', 'children': ['252', '257', '271']},{'id': '252', 'type': 'comparison_operator', 'children': ['253', '256'], 'value': '=='},{'id': '253', 'type': 'subscript', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'dialect'},{'id': '255', 'type': 'string', 'children': [], 'value': "'fmt'"},{'id': '256', 'type': 'string', 'children': [], 'value': "'gtf'"},{'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': 'part'},{'id': '261', 'type': 'call', 'children': ['262', '267']},{'id': '262', 'type': 'attribute', 'children': ['263', '266']},{'id': '263', 'type': 'subscript', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'dialect'},{'id': '265', 'type': 'string', 'children': [], 'value': "'keyval separator'"},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '267', 'type': 'argument_list', 'children': ['268']},{'id': '268', 'type': 'list', 'children': ['269', '270'], 'value': '[key, \'""\']'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '270', 'type': 'string', 'children': [], 'value': '\'""\''},{'id': '271', 'type': 'else_clause', 'children': ['272']},{'id': '272', 'type': 'block', 'children': ['273']},{'id': '273', 'type': 'expression_statement', 'children': ['274']},{'id': '274', 'type': 'assignment', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'part'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'key'},{'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': 'parts'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '282', 'type': 'argument_list', 'children': ['283']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'part'},{'id': '284', 'type': 'expression_statement', 'children': ['285']},{'id': '285', 'type': 'assignment', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'parts_str'},{'id': '287', 'type': 'call', 'children': ['288', '293']},{'id': '288', 'type': 'attribute', 'children': ['289', '292']},{'id': '289', 'type': 'subscript', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'dialect'},{'id': '291', 'type': 'string', 'children': [], 'value': "'field separator'"},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '293', 'type': 'argument_list', 'children': ['294']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '295', 'type': 'if_statement', 'children': ['296', '299']},{'id': '296', 'type': 'subscript', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'dialect'},{'id': '298', 'type': 'string', 'children': [], 'value': "'trailing semicolon'"},{'id': '299', 'type': 'block', 'children': ['300']},{'id': '300', 'type': 'expression_statement', 'children': ['301']},{'id': '301', 'type': 'augmented_assignment', 'children': ['302', '303'], 'value': '+='},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'parts_str'},{'id': '303', 'type': 'string', 'children': [], 'value': "';'"},{'id': '304', 'type': 'return_statement', 'children': ['305']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'parts_str'} | def _reconstruct(keyvals, dialect, keep_order=False,
sort_attribute_values=False):
if not dialect:
raise AttributeStringError()
if not keyvals:
return ""
parts = []
if constants.ignore_url_escape_characters or dialect['fmt'] != 'gff3':
attributes = keyvals
else:
attributes = {}
for k, v in keyvals.items():
attributes[k] = []
for i in v:
attributes[k].append(''.join([quoter[j] for j in i]))
if dialect['repeated keys']:
items = []
for key, val in attributes.items():
if len(val) > 1:
for v in val:
items.append((key, [v]))
else:
items.append((key, val))
else:
items = list(attributes.items())
def sort_key(x):
try:
return dialect['order'].index(x[0])
except ValueError:
return 1e6
if keep_order:
items.sort(key=sort_key)
for key, val in items:
if val:
if sort_attribute_values:
val = sorted(val)
val_str = dialect['multival separator'].join(val)
if val_str:
if dialect['quoted GFF2 values']:
val_str = '"%s"' % val_str
part = dialect['keyval separator'].join([key, val_str])
else:
if dialect['fmt'] == 'gtf':
part = dialect['keyval separator'].join([key, '""'])
else:
part = key
parts.append(part)
parts_str = dialect['field separator'].join(parts)
if dialect['trailing semicolon']:
parts_str += ';'
return parts_str |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '78']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'create_db'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24', '27', '30', '33', '36', '39', '42', '45', '50', '53', '58', '61', '64', '67', '70', '73', '76']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'dbfn'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'id_spec'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'force'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '14', 'type': 'False', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'checklines'},{'id': '17', 'type': 'integer', 'children': [], 'value': '10'},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'merge_strategy'},{'id': '20', 'type': 'string', 'children': [], 'value': "'error'"},{'id': '21', 'type': 'default_parameter', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'transform'},{'id': '23', 'type': 'None', 'children': []},{'id': '24', 'type': 'default_parameter', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'gtf_transcript_key'},{'id': '26', 'type': 'string', 'children': [], 'value': "'transcript_id'"},{'id': '27', 'type': 'default_parameter', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'gtf_gene_key'},{'id': '29', 'type': 'string', 'children': [], 'value': "'gene_id'"},{'id': '30', 'type': 'default_parameter', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'gtf_subfeature'},{'id': '32', 'type': 'string', 'children': [], 'value': "'exon'"},{'id': '33', 'type': 'default_parameter', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'force_gff'},{'id': '35', 'type': 'False', 'children': []},{'id': '36', 'type': 'default_parameter', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'force_dialect_check'},{'id': '38', 'type': 'False', 'children': []},{'id': '39', 'type': 'default_parameter', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'from_string'},{'id': '41', 'type': 'False', 'children': []},{'id': '42', 'type': 'default_parameter', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'keep_order'},{'id': '44', 'type': 'False', 'children': []},{'id': '45', 'type': 'default_parameter', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'text_factory'},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'sqlite3'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'OptimizedUnicode'},{'id': '50', 'type': 'default_parameter', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'force_merge_fields'},{'id': '52', 'type': 'None', 'children': []},{'id': '53', 'type': 'default_parameter', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'pragmas'},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'constants'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'default_pragmas'},{'id': '58', 'type': 'default_parameter', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'sort_attribute_values'},{'id': '60', 'type': 'False', 'children': []},{'id': '61', 'type': 'default_parameter', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'dialect'},{'id': '63', 'type': 'None', 'children': []},{'id': '64', 'type': 'default_parameter', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': '_keep_tempfiles'},{'id': '66', 'type': 'False', 'children': []},{'id': '67', 'type': 'default_parameter', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'infer_gene_extent'},{'id': '69', 'type': 'True', 'children': []},{'id': '70', 'type': 'default_parameter', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'disable_infer_genes'},{'id': '72', 'type': 'False', 'children': []},{'id': '73', 'type': 'default_parameter', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'disable_infer_transcripts'},{'id': '75', 'type': 'False', 'children': []},{'id': '76', 'type': 'dictionary_splat_pattern', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '78', 'type': 'block', 'children': ['79', '85', '90', '106', '116', '124', '135', '143', '151', '157', '227', '235', '241', '249', '255', '306']},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': '_locals'},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'locals'},{'id': '84', 'type': 'argument_list', 'children': []},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'deprecation_handler'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '93', 'type': 'call', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '95', 'type': 'generator_expression', 'children': ['96', '101']},{'id': '96', 'type': 'tuple', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '98', 'type': 'subscript', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': '_locals'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '101', 'type': 'for_in_clause', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'constants'},{'id': '105', 'type': 'identifier', 'children': [], 'value': '_iterator_kwargs'},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '109', 'type': 'call', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'iterators'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'DataIterator'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'dictionary_splat', 'children': ['115']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'call', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'dictionary_splat', 'children': ['123']},{'id': '123', 'type': 'identifier', 'children': [], 'value': '_locals'},{'id': '124', 'type': 'if_statement', 'children': ['125', '128']},{'id': '125', 'type': 'comparison_operator', 'children': ['126', '127'], 'value': 'is'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'dialect'},{'id': '127', 'type': 'None', 'children': []},{'id': '128', 'type': 'block', 'children': ['129']},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'assignment', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'dialect'},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'dialect'},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'assignment', 'children': ['137', '140']},{'id': '137', 'type': 'subscript', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '139', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '142', 'type': 'identifier', 'children': [], 'value': '_iter'},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '148']},{'id': '145', 'type': 'subscript', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '147', 'type': 'string', 'children': [], 'value': "'directives'"},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'directives'},{'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': "'checklines'"},{'id': '156', 'type': 'integer', 'children': [], 'value': '0'},{'id': '157', 'type': 'if_statement', 'children': ['158', '166', '186']},{'id': '158', 'type': 'boolean_operator', 'children': ['159', '160'], 'value': 'or'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'force_gff'},{'id': '160', 'type': '()', 'children': ['161']},{'id': '161', 'type': 'comparison_operator', 'children': ['162', '165'], 'value': '=='},{'id': '162', 'type': 'subscript', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'dialect'},{'id': '164', 'type': 'string', 'children': [], 'value': "'fmt'"},{'id': '165', 'type': 'string', 'children': [], 'value': "'gff3'"},{'id': '166', 'type': 'block', 'children': ['167', '171', '177']},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'assignment', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '170', 'type': 'identifier', 'children': [], 'value': '_GFFDBCreator'},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'assignment', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'id_spec'},{'id': '174', 'type': 'boolean_operator', 'children': ['175', '176'], 'value': 'or'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'id_spec'},{'id': '176', 'type': 'string', 'children': [], 'value': "'ID'"},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'add_kwargs'},{'id': '180', 'type': 'call', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '182', 'type': 'argument_list', 'children': ['183']},{'id': '183', 'type': 'keyword_argument', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'id_spec'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'id_spec'},{'id': '186', 'type': 'elif_clause', 'children': ['187', '192']},{'id': '187', 'type': 'comparison_operator', 'children': ['188', '191'], 'value': '=='},{'id': '188', 'type': 'subscript', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'dialect'},{'id': '190', 'type': 'string', 'children': [], 'value': "'fmt'"},{'id': '191', 'type': 'string', 'children': [], 'value': "'gtf'"},{'id': '192', 'type': 'block', 'children': ['193', '197', '209']},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'assignment', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '196', 'type': 'identifier', 'children': [], 'value': '_GTFDBCreator'},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'assignment', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'id_spec'},{'id': '200', 'type': 'boolean_operator', 'children': ['201', '202'], 'value': 'or'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'id_spec'},{'id': '202', 'type': 'dictionary', 'children': ['203', '206']},{'id': '203', 'type': 'pair', 'children': ['204', '205']},{'id': '204', 'type': 'string', 'children': [], 'value': "'gene'"},{'id': '205', 'type': 'string', 'children': [], 'value': "'gene_id'"},{'id': '206', 'type': 'pair', 'children': ['207', '208']},{'id': '207', 'type': 'string', 'children': [], 'value': "'transcript'"},{'id': '208', 'type': 'string', 'children': [], 'value': "'transcript_id'"},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'assignment', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'add_kwargs'},{'id': '212', 'type': 'call', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '214', 'type': 'argument_list', 'children': ['215', '218', '221', '224']},{'id': '215', 'type': 'keyword_argument', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'transcript_key'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'gtf_transcript_key'},{'id': '218', 'type': 'keyword_argument', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'gene_key'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'gtf_gene_key'},{'id': '221', 'type': 'keyword_argument', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'subfeature'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'gtf_subfeature'},{'id': '224', 'type': 'keyword_argument', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'id_spec'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'id_spec'},{'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': 'kwargs'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '232', 'type': 'argument_list', 'children': ['233']},{'id': '233', 'type': 'dictionary_splat', 'children': ['234']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'add_kwargs'},{'id': '235', 'type': 'expression_statement', 'children': ['236']},{'id': '236', 'type': 'assignment', 'children': ['237', '240']},{'id': '237', 'type': 'subscript', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '239', 'type': 'string', 'children': [], 'value': "'dialect'"},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'dialect'},{'id': '241', 'type': 'expression_statement', 'children': ['242']},{'id': '242', 'type': 'assignment', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '244', 'type': 'call', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '246', 'type': 'argument_list', 'children': ['247']},{'id': '247', 'type': 'dictionary_splat', 'children': ['248']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '249', 'type': 'expression_statement', 'children': ['250']},{'id': '250', 'type': 'call', 'children': ['251', '254']},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'create'},{'id': '254', 'type': 'argument_list', 'children': []},{'id': '255', 'type': 'if_statement', 'children': ['256', '259', '283']},{'id': '256', 'type': 'comparison_operator', 'children': ['257', '258'], 'value': '=='},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'dbfn'},{'id': '258', 'type': 'string', 'children': [], 'value': "':memory:'"},{'id': '259', 'type': 'block', 'children': ['260']},{'id': '260', 'type': 'expression_statement', 'children': ['261']},{'id': '261', 'type': 'assignment', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '263', 'type': 'call', 'children': ['264', '267']},{'id': '264', 'type': 'attribute', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'interface'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'FeatureDB'},{'id': '267', 'type': 'argument_list', 'children': ['268', '271', '274', '277', '280']},{'id': '268', 'type': 'attribute', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'conn'},{'id': '271', 'type': 'keyword_argument', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'keep_order'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'keep_order'},{'id': '274', 'type': 'keyword_argument', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'pragmas'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'pragmas'},{'id': '277', 'type': 'keyword_argument', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'sort_attribute_values'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'sort_attribute_values'},{'id': '280', 'type': 'keyword_argument', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'text_factory'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'text_factory'},{'id': '283', 'type': 'else_clause', 'children': ['284']},{'id': '284', 'type': 'block', 'children': ['285']},{'id': '285', 'type': 'expression_statement', 'children': ['286']},{'id': '286', 'type': 'assignment', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '288', 'type': 'call', 'children': ['289', '292']},{'id': '289', 'type': 'attribute', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'interface'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'FeatureDB'},{'id': '292', 'type': 'argument_list', 'children': ['293', '294', '297', '300', '303']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '294', 'type': 'keyword_argument', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'keep_order'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'keep_order'},{'id': '297', 'type': 'keyword_argument', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'pragmas'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'pragmas'},{'id': '300', 'type': 'keyword_argument', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'sort_attribute_values'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'sort_attribute_values'},{'id': '303', 'type': 'keyword_argument', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'text_factory'},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'text_factory'},{'id': '306', 'type': 'return_statement', 'children': ['307']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'db'} | def create_db(data, dbfn, id_spec=None, force=False, verbose=False,
checklines=10, merge_strategy='error', transform=None,
gtf_transcript_key='transcript_id', gtf_gene_key='gene_id',
gtf_subfeature='exon', force_gff=False,
force_dialect_check=False, from_string=False, keep_order=False,
text_factory=sqlite3.OptimizedUnicode, force_merge_fields=None,
pragmas=constants.default_pragmas, sort_attribute_values=False,
dialect=None, _keep_tempfiles=False, infer_gene_extent=True,
disable_infer_genes=False, disable_infer_transcripts=False,
**kwargs):
_locals = locals()
deprecation_handler(kwargs)
kwargs = dict((i, _locals[i]) for i in constants._iterator_kwargs)
iterator = iterators.DataIterator(**kwargs)
kwargs.update(**_locals)
if dialect is None:
dialect = iterator.dialect
kwargs['data'] = iterator._iter
kwargs['directives'] = iterator.directives
kwargs['checklines'] = 0
if force_gff or (dialect['fmt'] == 'gff3'):
cls = _GFFDBCreator
id_spec = id_spec or 'ID'
add_kwargs = dict(
id_spec=id_spec,
)
elif dialect['fmt'] == 'gtf':
cls = _GTFDBCreator
id_spec = id_spec or {'gene': 'gene_id', 'transcript': 'transcript_id'}
add_kwargs = dict(
transcript_key=gtf_transcript_key,
gene_key=gtf_gene_key,
subfeature=gtf_subfeature,
id_spec=id_spec,
)
kwargs.update(**add_kwargs)
kwargs['dialect'] = dialect
c = cls(**kwargs)
c.create()
if dbfn == ':memory:':
db = interface.FeatureDB(c.conn,
keep_order=keep_order,
pragmas=pragmas,
sort_attribute_values=sort_attribute_values,
text_factory=text_factory)
else:
db = interface.FeatureDB(c,
keep_order=keep_order,
pragmas=pragmas,
sort_attribute_values=sort_attribute_values,
text_factory=text_factory)
return db |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_id_handler'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '6', 'type': 'block', 'children': ['7', '96', '194']},{'id': '7', 'type': 'if_statement', 'children': ['8', '17', '25', '41', '88']},{'id': '8', 'type': 'call', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '10', 'type': 'argument_list', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'id_spec'},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'string_types'},{'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': 'id_key'},{'id': '21', 'type': 'list', 'children': ['22'], 'value': '[self.id_spec]'},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'id_spec'},{'id': '25', 'type': 'elif_clause', 'children': ['26', '33']},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'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': 'id_spec'},{'id': '32', 'type': 'string', 'children': [], 'value': "'__call__'"},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'id_key'},{'id': '37', 'type': 'list', 'children': ['38'], 'value': '[self.id_spec]'},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'id_spec'},{'id': '41', 'type': 'elif_clause', 'children': ['42', '49']},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '44', 'type': 'argument_list', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'id_spec'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'try_statement', 'children': ['51', '76']},{'id': '51', 'type': 'block', 'children': ['52', '62']},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'id_key'},{'id': '55', 'type': 'subscript', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'id_spec'},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'featuretype'},{'id': '62', 'type': 'if_statement', 'children': ['63', '70']},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '65', 'type': 'argument_list', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'id_key'},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'string_types'},{'id': '70', 'type': 'block', 'children': ['71']},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'id_key'},{'id': '74', 'type': 'list', 'children': ['75'], 'value': '[id_key]'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'id_key'},{'id': '76', 'type': 'except_clause', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '78', 'type': 'block', 'children': ['79']},{'id': '79', 'type': 'return_statement', 'children': ['80']},{'id': '80', 'type': 'call', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '83', 'type': 'identifier', 'children': [], 'value': '_increment_featuretype_autoid'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'featuretype'},{'id': '88', 'type': 'else_clause', 'children': ['89']},{'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': 'id_key'},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'id_spec'},{'id': '96', 'type': 'for_statement', 'children': ['97', '98', '99']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'id_key'},{'id': '99', 'type': 'block', 'children': ['100']},{'id': '100', 'type': 'if_statement', 'children': ['101', '106', '138']},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '103', 'type': 'argument_list', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '105', 'type': 'string', 'children': [], 'value': "'__call__'"},{'id': '106', 'type': 'block', 'children': ['107', '114']},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': '_id'},{'id': '110', 'type': 'call', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '114', 'type': 'if_statement', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': '_id'},{'id': '116', 'type': 'block', 'children': ['117', '136']},{'id': '117', 'type': 'if_statement', 'children': ['118', '124']},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': '_id'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'string', 'children': [], 'value': "'autoincrement:'"},{'id': '124', 'type': 'block', 'children': ['125']},{'id': '125', 'type': 'return_statement', 'children': ['126']},{'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': '_increment_featuretype_autoid'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'subscript', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': '_id'},{'id': '133', 'type': 'slice', 'children': ['134', '135']},{'id': '134', 'type': 'integer', 'children': [], 'value': '14'},{'id': '135', 'type': 'colon', 'children': []},{'id': '136', 'type': 'return_statement', 'children': ['137']},{'id': '137', 'type': 'identifier', 'children': [], 'value': '_id'},{'id': '138', 'type': 'else_clause', 'children': ['139']},{'id': '139', 'type': 'block', 'children': ['140']},{'id': '140', 'type': 'if_statement', 'children': ['141', '163', '176']},{'id': '141', 'type': 'boolean_operator', 'children': ['142', '156'], 'value': 'and'},{'id': '142', 'type': 'boolean_operator', 'children': ['143', '150'], 'value': 'and'},{'id': '143', 'type': '()', 'children': ['144']},{'id': '144', 'type': 'comparison_operator', 'children': ['145', '149'], 'value': '>'},{'id': '145', 'type': 'call', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '149', 'type': 'integer', 'children': [], 'value': '3'},{'id': '150', 'type': '()', 'children': ['151']},{'id': '151', 'type': 'comparison_operator', 'children': ['152', '155'], 'value': '=='},{'id': '152', 'type': 'subscript', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '154', 'type': 'integer', 'children': [], 'value': '0'},{'id': '155', 'type': 'string', 'children': [], 'value': "':'"},{'id': '156', 'type': '()', 'children': ['157']},{'id': '157', 'type': 'comparison_operator', 'children': ['158', '162'], 'value': '=='},{'id': '158', 'type': 'subscript', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '160', 'type': 'unary_operator', 'children': ['161'], 'value': '-'},{'id': '161', 'type': 'integer', 'children': [], 'value': '1'},{'id': '162', 'type': 'string', 'children': [], 'value': "':'"},{'id': '163', 'type': 'block', 'children': ['164']},{'id': '164', 'type': 'return_statement', 'children': ['165']},{'id': '165', 'type': 'call', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '167', 'type': 'argument_list', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '169', 'type': 'subscript', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '171', 'type': 'slice', 'children': ['172', '173', '174']},{'id': '172', 'type': 'integer', 'children': [], 'value': '1'},{'id': '173', 'type': 'colon', 'children': []},{'id': '174', 'type': 'unary_operator', 'children': ['175'], 'value': '-'},{'id': '175', 'type': 'integer', 'children': [], 'value': '1'},{'id': '176', 'type': 'else_clause', 'children': ['177']},{'id': '177', 'type': 'block', 'children': ['178']},{'id': '178', 'type': 'try_statement', 'children': ['179', '188']},{'id': '179', 'type': 'block', 'children': ['180']},{'id': '180', 'type': 'return_statement', 'children': ['181']},{'id': '181', 'type': 'subscript', 'children': ['182', '187']},{'id': '182', 'type': 'subscript', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '187', 'type': 'integer', 'children': [], 'value': '0'},{'id': '188', 'type': 'except_clause', 'children': ['189', '192']},{'id': '189', 'type': 'tuple', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'IndexError'},{'id': '192', 'type': 'block', 'children': ['193']},{'id': '193', 'type': 'pass_statement', 'children': []},{'id': '194', 'type': 'return_statement', 'children': ['195']},{'id': '195', 'type': 'call', 'children': ['196', '199']},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '198', 'type': 'identifier', 'children': [], 'value': '_increment_featuretype_autoid'},{'id': '199', 'type': 'argument_list', 'children': ['200']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'featuretype'} | def _id_handler(self, f):
if isinstance(self.id_spec, six.string_types):
id_key = [self.id_spec]
elif hasattr(self.id_spec, '__call__'):
id_key = [self.id_spec]
elif isinstance(self.id_spec, dict):
try:
id_key = self.id_spec[f.featuretype]
if isinstance(id_key, six.string_types):
id_key = [id_key]
except KeyError:
return self._increment_featuretype_autoid(f.featuretype)
else:
id_key = self.id_spec
for k in id_key:
if hasattr(k, '__call__'):
_id = k(f)
if _id:
if _id.startswith('autoincrement:'):
return self._increment_featuretype_autoid(_id[14:])
return _id
else:
if (len(k) > 3) and (k[0] == ':') and (k[-1] == ':'):
return getattr(f, k[1:-1])
else:
try:
return f.attributes[k][0]
except (KeyError, IndexError):
pass
return self._increment_featuretype_autoid(f.featuretype) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'browser'},{'id': '3', 'type': 'parameters', 'children': ['4', '7', '10']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'tags'},{'id': '6', 'type': 'None', 'children': []},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'proxy'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'other_caps'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'block', 'children': ['14', '26', '162', '180']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'browser_name'},{'id': '17', 'type': 'call', 'children': ['18', '23']},{'id': '18', 'type': 'attribute', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'environ'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '23', 'type': 'argument_list', 'children': ['24', '25']},{'id': '24', 'type': 'string', 'children': [], 'value': "'SELENIUM_BROWSER'"},{'id': '25', 'type': 'string', 'children': [], 'value': "'firefox'"},{'id': '26', 'type': 'function_definition', 'children': ['27', '28', '29']},{'id': '27', 'type': 'function_name', 'children': [], 'value': 'browser_check_func'},{'id': '28', 'type': 'parameters', 'children': []},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'try_statement', 'children': ['31', '132']},{'id': '31', 'type': 'block', 'children': ['32', '78', '90', '122']},{'id': '32', 'type': 'if_statement', 'children': ['33', '37', '49', '66']},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': '_use_remote_browser'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'SAUCE_ENV_VARS'},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '44']},{'id': '40', 'type': 'pattern_list', 'children': ['41', '42', '43']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'browser_class'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'browser_args'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'browser_kwargs'},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': '_remote_browser_class'},{'id': '46', 'type': 'argument_list', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'SAUCE_ENV_VARS'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'tags'},{'id': '49', 'type': 'elif_clause', 'children': ['50', '54']},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': '_use_remote_browser'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'REMOTE_ENV_VARS'},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '61']},{'id': '57', 'type': 'pattern_list', 'children': ['58', '59', '60']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'browser_class'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'browser_args'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'browser_kwargs'},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': '_remote_browser_class'},{'id': '63', 'type': 'argument_list', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'REMOTE_ENV_VARS'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'tags'},{'id': '66', 'type': 'else_clause', 'children': ['67']},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '74']},{'id': '70', 'type': 'pattern_list', 'children': ['71', '72', '73']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'browser_class'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'browser_args'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'browser_kwargs'},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': '_local_browser_class'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'browser_name'},{'id': '78', 'type': 'if_statement', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'proxy'},{'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': 'browser_kwargs'},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': '_proxy_kwargs'},{'id': '86', 'type': 'argument_list', 'children': ['87', '88', '89']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'browser_name'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'proxy'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'browser_kwargs'},{'id': '90', 'type': 'if_statement', 'children': ['91', '96']},{'id': '91', 'type': 'comparison_operator', 'children': ['92', '93'], 'value': '=='},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'browser_class'},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'webdriver'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'Remote'},{'id': '96', 'type': 'block', 'children': ['97', '103', '116']},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'desired_caps'},{'id': '100', 'type': 'boolean_operator', 'children': ['101', '102'], 'value': 'or'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'other_caps'},{'id': '102', 'type': 'dictionary', 'children': []},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'call', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'desired_caps'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'call', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'browser_kwargs'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '113', 'type': 'argument_list', 'children': ['114', '115']},{'id': '114', 'type': 'string', 'children': [], 'value': "'desired_capabilities'"},{'id': '115', 'type': 'dictionary', 'children': []},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '121']},{'id': '118', 'type': 'subscript', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'browser_kwargs'},{'id': '120', 'type': 'string', 'children': [], 'value': "'desired_capabilities'"},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'desired_caps'},{'id': '122', 'type': 'return_statement', 'children': ['123']},{'id': '123', 'type': 'expression_list', 'children': ['124', '125']},{'id': '124', 'type': 'True', 'children': []},{'id': '125', 'type': 'call', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'browser_class'},{'id': '127', 'type': 'argument_list', 'children': ['128', '130']},{'id': '128', 'type': 'list_splat', 'children': ['129']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'browser_args'},{'id': '130', 'type': 'dictionary_splat', 'children': ['131']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'browser_kwargs'},{'id': '132', 'type': 'except_clause', 'children': ['133', '141']},{'id': '133', 'type': 'as_pattern', 'children': ['134', '139']},{'id': '134', 'type': 'tuple', 'children': ['135', '138']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'socket'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'WebDriverException'},{'id': '139', 'type': 'as_pattern_target', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '141', 'type': 'block', 'children': ['142', '149', '158']},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '145', 'type': 'call', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'err'},{'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': 'LOGGER'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'binary_operator', 'children': ['156', '157'], 'value': '+'},{'id': '156', 'type': 'string', 'children': [], 'value': "'Failed to instantiate browser: '"},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '158', 'type': 'return_statement', 'children': ['159']},{'id': '159', 'type': 'expression_list', 'children': ['160', '161']},{'id': '160', 'type': 'False', 'children': []},{'id': '161', 'type': 'None', 'children': []},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'assignment', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'browser_instance'},{'id': '165', 'type': 'call', 'children': ['166', '179']},{'id': '166', 'type': 'attribute', 'children': ['167', '178']},{'id': '167', 'type': 'call', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'Promise'},{'id': '169', 'type': 'argument_list', 'children': ['170', '171', '172', '175']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'browser_check_func'},{'id': '171', 'type': 'string', 'children': [], 'value': '"Browser is instantiated successfully."'},{'id': '172', 'type': 'keyword_argument', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'try_limit'},{'id': '174', 'type': 'integer', 'children': [], 'value': '3'},{'id': '175', 'type': 'keyword_argument', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '177', 'type': 'integer', 'children': [], 'value': '95'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'fulfill'},{'id': '179', 'type': 'argument_list', 'children': []},{'id': '180', 'type': 'return_statement', 'children': ['181']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'browser_instance'} | def browser(tags=None, proxy=None, other_caps=None):
browser_name = os.environ.get('SELENIUM_BROWSER', 'firefox')
def browser_check_func():
try:
if _use_remote_browser(SAUCE_ENV_VARS):
browser_class, browser_args, browser_kwargs = _remote_browser_class(
SAUCE_ENV_VARS, tags)
elif _use_remote_browser(REMOTE_ENV_VARS):
browser_class, browser_args, browser_kwargs = _remote_browser_class(
REMOTE_ENV_VARS, tags)
else:
browser_class, browser_args, browser_kwargs = _local_browser_class(
browser_name)
if proxy:
browser_kwargs = _proxy_kwargs(browser_name, proxy, browser_kwargs)
if browser_class == webdriver.Remote:
desired_caps = other_caps or {}
desired_caps.update(browser_kwargs.get('desired_capabilities', {}))
browser_kwargs['desired_capabilities'] = desired_caps
return True, browser_class(*browser_args, **browser_kwargs)
except (socket.error, WebDriverException) as err:
msg = str(err)
LOGGER.debug('Failed to instantiate browser: ' + msg)
return False, None
browser_instance = Promise(
browser_check_func, "Browser is instantiated successfully.", try_limit=3, timeout=95).fulfill()
return browser_instance |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_local_browser_class'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'browser_name'},{'id': '5', 'type': 'block', 'children': ['6', '14', '23', '41']},{'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': 'LOGGER'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '11', 'type': 'argument_list', 'children': ['12', '13']},{'id': '12', 'type': 'string', 'children': [], 'value': 'u"Using local browser: %s [Default is firefox]"'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'browser_name'},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'browser_class'},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'BROWSERS'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'browser_name'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'headless'},{'id': '26', 'type': 'comparison_operator', 'children': ['27', '40'], 'value': '=='},{'id': '27', 'type': 'call', 'children': ['28', '39']},{'id': '28', 'type': 'attribute', 'children': ['29', '38']},{'id': '29', 'type': 'call', 'children': ['30', '35']},{'id': '30', 'type': 'attribute', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'environ'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '35', 'type': 'argument_list', 'children': ['36', '37']},{'id': '36', 'type': 'string', 'children': [], 'value': "'BOKCHOY_HEADLESS'"},{'id': '37', 'type': 'string', 'children': [], 'value': "'false'"},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '39', 'type': 'argument_list', 'children': []},{'id': '40', 'type': 'string', 'children': [], 'value': "'true'"},{'id': '41', 'type': 'if_statement', 'children': ['42', '45', '73']},{'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': 'is'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'browser_class'},{'id': '44', 'type': 'None', 'children': []},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'raise_statement', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'BrowserConfigError'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'string', 'children': [], 'value': 'u"Invalid browser name {name}. Options are: {options}"'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '54', 'type': 'argument_list', 'children': ['55', '58']},{'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'browser_name'},{'id': '58', 'type': 'keyword_argument', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'string', 'children': [], 'value': '", "'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'BROWSERS'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '72', 'type': 'argument_list', 'children': []},{'id': '73', 'type': 'else_clause', 'children': ['74']},{'id': '74', 'type': 'block', 'children': ['75', '288']},{'id': '75', 'type': 'if_statement', 'children': ['76', '79', '233', '278']},{'id': '76', 'type': 'comparison_operator', 'children': ['77', '78'], 'value': '=='},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'browser_name'},{'id': '78', 'type': 'string', 'children': [], 'value': "'firefox'"},{'id': '79', 'type': 'block', 'children': ['80', '96', '113', '119', '127', '136', '140', '152', '163', '174']},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'log_path'},{'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', '95']},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'getcwd'},{'id': '94', 'type': 'argument_list', 'children': []},{'id': '95', 'type': 'string', 'children': [], 'value': "'geckodriver.log'"},{'id': '96', 'type': 'if_statement', 'children': ['97', '105']},{'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': 'exists'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'log_path'},{'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': 'os'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'log_path'},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'firefox_options'},{'id': '116', 'type': 'call', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'FirefoxOptions'},{'id': '118', 'type': 'argument_list', 'children': []},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '126']},{'id': '121', 'type': 'attribute', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'firefox_options'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '126', 'type': 'string', 'children': [], 'value': "'trace'"},{'id': '127', 'type': 'if_statement', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'headless'},{'id': '129', 'type': 'block', 'children': ['130']},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'firefox_options'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'headless'},{'id': '135', 'type': 'True', 'children': []},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'browser_args'},{'id': '139', 'type': 'list', 'children': [], 'value': '[]'},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'assignment', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'browser_kwargs'},{'id': '143', 'type': 'dictionary', 'children': ['144', '149']},{'id': '144', 'type': 'pair', 'children': ['145', '146']},{'id': '145', 'type': 'string', 'children': [], 'value': "'firefox_profile'"},{'id': '146', 'type': 'call', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': '_firefox_profile'},{'id': '148', 'type': 'argument_list', 'children': []},{'id': '149', 'type': 'pair', 'children': ['150', '151']},{'id': '150', 'type': 'string', 'children': [], 'value': "'options'"},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'firefox_options'},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'firefox_path'},{'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': 'environ'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'string', 'children': [], 'value': "'SELENIUM_FIREFOX_PATH'"},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'firefox_log'},{'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': 'os'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'environ'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'string', 'children': [], 'value': "'SELENIUM_FIREFOX_LOG'"},{'id': '174', 'type': 'if_statement', 'children': ['175', '178', '197', '215']},{'id': '175', 'type': 'boolean_operator', 'children': ['176', '177'], 'value': 'and'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'firefox_path'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'firefox_log'},{'id': '178', 'type': 'block', 'children': ['179']},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'call', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'browser_kwargs'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'dictionary', 'children': ['186']},{'id': '186', 'type': 'pair', 'children': ['187', '188']},{'id': '187', 'type': 'string', 'children': [], 'value': "'firefox_binary'"},{'id': '188', 'type': 'call', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'FirefoxBinary'},{'id': '190', 'type': 'argument_list', 'children': ['191', '194']},{'id': '191', 'type': 'keyword_argument', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'firefox_path'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'firefox_path'},{'id': '194', 'type': 'keyword_argument', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'log_file'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'firefox_log'},{'id': '197', 'type': 'elif_clause', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'firefox_path'},{'id': '199', 'type': 'block', 'children': ['200']},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'call', 'children': ['202', '205']},{'id': '202', 'type': 'attribute', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'browser_kwargs'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '205', 'type': 'argument_list', 'children': ['206']},{'id': '206', 'type': 'dictionary', 'children': ['207']},{'id': '207', 'type': 'pair', 'children': ['208', '209']},{'id': '208', 'type': 'string', 'children': [], 'value': "'firefox_binary'"},{'id': '209', 'type': 'call', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'FirefoxBinary'},{'id': '211', 'type': 'argument_list', 'children': ['212']},{'id': '212', 'type': 'keyword_argument', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'firefox_path'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'firefox_path'},{'id': '215', 'type': 'elif_clause', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'firefox_log'},{'id': '217', 'type': 'block', 'children': ['218']},{'id': '218', 'type': 'expression_statement', 'children': ['219']},{'id': '219', 'type': 'call', 'children': ['220', '223']},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'browser_kwargs'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '223', 'type': 'argument_list', 'children': ['224']},{'id': '224', 'type': 'dictionary', 'children': ['225']},{'id': '225', 'type': 'pair', 'children': ['226', '227']},{'id': '226', 'type': 'string', 'children': [], 'value': "'firefox_binary'"},{'id': '227', 'type': 'call', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'FirefoxBinary'},{'id': '229', 'type': 'argument_list', 'children': ['230']},{'id': '230', 'type': 'keyword_argument', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'log_file'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'firefox_log'},{'id': '233', 'type': 'elif_clause', 'children': ['234', '237']},{'id': '234', 'type': 'comparison_operator', 'children': ['235', '236'], 'value': '=='},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'browser_name'},{'id': '236', 'type': 'string', 'children': [], 'value': "'chrome'"},{'id': '237', 'type': 'block', 'children': ['238', '244', '253', '260', '267', '271']},{'id': '238', 'type': 'expression_statement', 'children': ['239']},{'id': '239', 'type': 'assignment', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'chrome_options'},{'id': '241', 'type': 'call', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'ChromeOptions'},{'id': '243', 'type': 'argument_list', 'children': []},{'id': '244', 'type': 'if_statement', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'headless'},{'id': '246', 'type': 'block', 'children': ['247']},{'id': '247', 'type': 'expression_statement', 'children': ['248']},{'id': '248', 'type': 'assignment', 'children': ['249', '252']},{'id': '249', 'type': 'attribute', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'chrome_options'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'headless'},{'id': '252', 'type': 'True', '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': 'chrome_options'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '258', 'type': 'argument_list', 'children': ['259']},{'id': '259', 'type': 'string', 'children': [], 'value': "'--use-fake-device-for-media-stream'"},{'id': '260', 'type': 'expression_statement', 'children': ['261']},{'id': '261', 'type': 'call', 'children': ['262', '265']},{'id': '262', 'type': 'attribute', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'chrome_options'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '265', 'type': 'argument_list', 'children': ['266']},{'id': '266', 'type': 'string', 'children': [], 'value': "'--use-fake-ui-for-media-stream'"},{'id': '267', 'type': 'expression_statement', 'children': ['268']},{'id': '268', 'type': 'assignment', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'browser_args'},{'id': '270', 'type': 'list', 'children': [], 'value': '[]'},{'id': '271', 'type': 'expression_statement', 'children': ['272']},{'id': '272', 'type': 'assignment', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'browser_kwargs'},{'id': '274', 'type': 'dictionary', 'children': ['275']},{'id': '275', 'type': 'pair', 'children': ['276', '277']},{'id': '276', 'type': 'string', 'children': [], 'value': "'options'"},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'chrome_options'},{'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', '285']},{'id': '282', 'type': 'pattern_list', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'browser_args'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'browser_kwargs'},{'id': '285', 'type': 'expression_list', 'children': ['286', '287']},{'id': '286', 'type': 'list', 'children': [], 'value': '[]'},{'id': '287', 'type': 'dictionary', 'children': []},{'id': '288', 'type': 'return_statement', 'children': ['289']},{'id': '289', 'type': 'expression_list', 'children': ['290', '291', '292']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'browser_class'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'browser_args'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'browser_kwargs'} | def _local_browser_class(browser_name):
LOGGER.info(u"Using local browser: %s [Default is firefox]", browser_name)
browser_class = BROWSERS.get(browser_name)
headless = os.environ.get('BOKCHOY_HEADLESS', 'false').lower() == 'true'
if browser_class is None:
raise BrowserConfigError(
u"Invalid browser name {name}. Options are: {options}".format(
name=browser_name, options=", ".join(list(BROWSERS.keys()))))
else:
if browser_name == 'firefox':
log_path = os.path.join(os.getcwd(), 'geckodriver.log')
if os.path.exists(log_path):
os.remove(log_path)
firefox_options = FirefoxOptions()
firefox_options.log.level = 'trace'
if headless:
firefox_options.headless = True
browser_args = []
browser_kwargs = {
'firefox_profile': _firefox_profile(),
'options': firefox_options,
}
firefox_path = os.environ.get('SELENIUM_FIREFOX_PATH')
firefox_log = os.environ.get('SELENIUM_FIREFOX_LOG')
if firefox_path and firefox_log:
browser_kwargs.update({
'firefox_binary': FirefoxBinary(
firefox_path=firefox_path, log_file=firefox_log)
})
elif firefox_path:
browser_kwargs.update({
'firefox_binary': FirefoxBinary(firefox_path=firefox_path)
})
elif firefox_log:
browser_kwargs.update({
'firefox_binary': FirefoxBinary(log_file=firefox_log)
})
elif browser_name == 'chrome':
chrome_options = ChromeOptions()
if headless:
chrome_options.headless = True
chrome_options.add_argument('--use-fake-device-for-media-stream')
chrome_options.add_argument('--use-fake-ui-for-media-stream')
browser_args = []
browser_kwargs = {
'options': chrome_options,
}
else:
browser_args, browser_kwargs = [], {}
return browser_class, browser_args, browser_kwargs |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'filter'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'filter_fn'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'dictionary_splat_pattern', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '13', 'type': 'block', 'children': ['14', '26', '39', '86', '95', '123']},{'id': '14', 'type': 'if_statement', 'children': ['15', '20']},{'id': '15', 'type': 'boolean_operator', 'children': ['16', '19'], 'value': 'and'},{'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'is'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'filter_fn'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'raise_statement', 'children': ['22']},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'string', 'children': [], 'value': "'Must supply either a filter_fn or attribute filter parameters to filter(), but not both.'"},{'id': '26', 'type': 'if_statement', 'children': ['27', '33']},{'id': '27', 'type': 'boolean_operator', 'children': ['28', '31'], 'value': 'and'},{'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': 'is'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'filter_fn'},{'id': '30', 'type': 'None', 'children': []},{'id': '31', 'type': 'not_operator', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'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': 'TypeError'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'string', 'children': [], 'value': "'Must supply one of filter_fn or one or more attribute filter parameters to filter().'"},{'id': '39', 'type': 'if_statement', 'children': ['40', '43']},{'id': '40', 'type': 'comparison_operator', 'children': ['41', '42'], 'value': 'is'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '42', 'type': 'None', 'children': []},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'if_statement', 'children': ['45', '48', '58']},{'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': 'is'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'filter_fn'},{'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': 'desc'},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '54', 'type': 'argument_list', 'children': ['55', '56', '57']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'filter_fn'},{'id': '56', 'type': 'string', 'children': [], 'value': "'__name__'"},{'id': '57', 'type': 'string', 'children': [], 'value': "''"},{'id': '58', 'type': 'elif_clause', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'string', 'children': [], 'value': 'u", "'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'list_comprehension', 'children': ['70', '77']},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'string', 'children': [], 'value': 'u"{}={!r}"'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '74', 'type': 'argument_list', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '77', 'type': 'for_in_clause', 'children': ['78', '81']},{'id': '78', 'type': 'pattern_list', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '85', 'type': 'argument_list', 'children': []},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '89', 'type': 'call', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'string', 'children': [], 'value': 'u"filter({})"'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '95', 'type': 'if_statement', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '97', 'type': 'block', 'children': ['98']},{'id': '98', 'type': 'function_definition', 'children': ['99', '100', '102']},{'id': '99', 'type': 'function_name', 'children': [], 'value': 'filter_fn'},{'id': '100', 'type': 'parameters', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '102', 'type': 'block', 'children': ['103']},{'id': '103', 'type': 'return_statement', 'children': ['104']},{'id': '104', 'type': 'call', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '106', 'type': 'generator_expression', 'children': ['107', '114']},{'id': '107', 'type': 'comparison_operator', 'children': ['108', '113'], 'value': '=='},{'id': '108', 'type': 'call', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '110', 'type': 'argument_list', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'filter_key'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'filter_value'},{'id': '114', 'type': 'for_in_clause', 'children': ['115', '118']},{'id': '115', 'type': 'pattern_list', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'filter_key'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'filter_value'},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '122', 'type': 'argument_list', 'children': []},{'id': '123', 'type': 'return_statement', 'children': ['124']},{'id': '124', 'type': 'call', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'transform'},{'id': '128', 'type': 'argument_list', 'children': ['129', '142']},{'id': '129', 'type': 'lambda', 'children': ['130', '132']},{'id': '130', 'type': 'lambda_parameters', 'children': ['131']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'xs'},{'id': '132', 'type': 'generator_expression', 'children': ['133', '134', '137']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '134', 'type': 'for_in_clause', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'xs'},{'id': '137', 'type': 'if_clause', 'children': ['138']},{'id': '138', 'type': 'call', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'filter_fn'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '142', 'type': 'keyword_argument', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'desc'} | def filter(self, filter_fn=None, desc=None, **kwargs):
if filter_fn is not None and kwargs:
raise TypeError('Must supply either a filter_fn or attribute filter parameters to filter(), but not both.')
if filter_fn is None and not kwargs:
raise TypeError('Must supply one of filter_fn or one or more attribute filter parameters to filter().')
if desc is None:
if filter_fn is not None:
desc = getattr(filter_fn, '__name__', '')
elif kwargs:
desc = u", ".join([u"{}={!r}".format(key, value) for key, value in kwargs.items()])
desc = u"filter({})".format(desc)
if kwargs:
def filter_fn(elem):
return all(
getattr(elem, filter_key) == filter_value
for filter_key, filter_value
in kwargs.items()
)
return self.transform(lambda xs: (x for x in xs if filter_fn(x)), desc=desc) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'order_by_on_list'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'order_field'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'is_desc'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '29', '51']},{'id': '10', 'type': 'if_statement', 'children': ['11', '15']},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'callable'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'order_field'},{'id': '15', 'type': 'block', 'children': ['16', '28']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '21', 'type': 'argument_list', 'children': ['22', '25']},{'id': '22', 'type': 'keyword_argument', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'order_field'},{'id': '25', 'type': 'keyword_argument', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'is_desc'},{'id': '28', 'type': 'return_statement', 'children': []},{'id': '29', 'type': 'function_definition', 'children': ['30', '31', '33']},{'id': '30', 'type': 'function_name', 'children': [], 'value': 'order_key'},{'id': '31', 'type': 'parameters', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '33', 'type': 'block', 'children': ['34', '42', '49']},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'getattr_path'},{'id': '39', 'type': 'argument_list', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'order_field'},{'id': '42', 'type': 'if_statement', 'children': ['43', '46']},{'id': '43', 'type': 'comparison_operator', 'children': ['44', '45'], 'value': 'is'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '45', 'type': 'None', 'children': []},{'id': '46', 'type': 'block', 'children': ['47']},{'id': '47', 'type': 'return_statement', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'MIN'},{'id': '49', 'type': 'return_statement', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '56', 'type': 'argument_list', 'children': ['57', '60']},{'id': '57', 'type': 'keyword_argument', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'order_key'},{'id': '60', 'type': 'keyword_argument', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'is_desc'} | def order_by_on_list(objects, order_field, is_desc=False):
if callable(order_field):
objects.sort(key=order_field, reverse=is_desc)
return
def order_key(x):
v = getattr_path(x, order_field)
if v is None:
return MIN
return v
objects.sort(key=order_key, reverse=is_desc) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '41']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'render_table'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24', '27', '30', '33']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'links'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '14', 'type': 'string', 'children': [], 'value': "'tri_table/list.html'"},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'blank_on_empty'},{'id': '17', 'type': 'False', 'children': []},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'paginate_by'},{'id': '20', 'type': 'integer', 'children': [], 'value': '40'},{'id': '21', 'type': 'default_parameter', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '23', 'type': 'None', 'children': []},{'id': '24', 'type': 'default_parameter', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'paginator'},{'id': '26', 'type': 'None', 'children': []},{'id': '27', 'type': 'default_parameter', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'show_hits'},{'id': '29', 'type': 'False', 'children': []},{'id': '30', 'type': 'default_parameter', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'hit_label'},{'id': '32', 'type': 'string', 'children': [], 'value': "'Items'"},{'id': '33', 'type': 'default_parameter', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'post_bulk_edit'},{'id': '35', 'type': 'lambda', 'children': ['36', '40']},{'id': '36', 'type': 'lambda_parameters', 'children': ['37', '38', '39']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'queryset'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'updates'},{'id': '40', 'type': 'None', 'children': []},{'id': '41', 'type': 'block', 'children': ['42', '50', '63', '70', '76', '90', '95', '103', '111', '119', '213', '246', '256', '287']},{'id': '42', 'type': 'if_statement', 'children': ['43', '45']},{'id': '43', 'type': 'not_operator', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'context'},{'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': 'context'},{'id': '49', 'type': 'dictionary', 'children': []},{'id': '50', 'type': 'if_statement', 'children': ['51', '56']},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '53', 'type': 'argument_list', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'Namespace'},{'id': '56', 'type': 'block', 'children': ['57']},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '62', 'type': 'argument_list', 'children': []},{'id': '63', 'type': 'assert_statement', 'children': ['64', '69']},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '66', 'type': 'argument_list', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'Table'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '81']},{'id': '78', 'type': 'pattern_list', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'should_return'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'dispatch_result'},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'handle_dispatch'},{'id': '83', 'type': 'argument_list', 'children': ['84', '87']},{'id': '84', 'type': 'keyword_argument', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '87', 'type': 'keyword_argument', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '90', 'type': 'if_statement', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'should_return'},{'id': '92', 'type': 'block', 'children': ['93']},{'id': '93', 'type': 'return_statement', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'dispatch_result'},{'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': 'context'},{'id': '99', 'type': 'string', 'children': [], 'value': "'bulk_form'"},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'bulk_form'},{'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': 'context'},{'id': '107', 'type': 'string', 'children': [], 'value': "'query_form'"},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'query_form'},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '116']},{'id': '113', 'type': 'subscript', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '115', 'type': 'string', 'children': [], 'value': "'tri_query_error'"},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'query_error'},{'id': '119', 'type': 'if_statement', 'children': ['120', '129']},{'id': '120', 'type': 'boolean_operator', 'children': ['121', '124'], 'value': 'and'},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'bulk_form'},{'id': '124', 'type': 'comparison_operator', 'children': ['125', '128'], 'value': '=='},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '128', 'type': 'string', 'children': [], 'value': "'POST'"},{'id': '129', 'type': 'block', 'children': ['130']},{'id': '130', 'type': 'if_statement', 'children': ['131', '138']},{'id': '131', 'type': 'call', 'children': ['132', '137']},{'id': '132', 'type': 'attribute', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'bulk_form'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'is_valid'},{'id': '137', 'type': 'argument_list', 'children': []},{'id': '138', 'type': 'block', 'children': ['139', '147', '183', '191', '204']},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'assignment', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'queryset'},{'id': '142', 'type': 'call', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'bulk_queryset'},{'id': '146', 'type': 'argument_list', 'children': []},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'assignment', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'updates'},{'id': '150', 'type': 'dictionary_comprehension', 'children': ['151', '158', '165']},{'id': '151', 'type': 'pair', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '158', 'type': 'for_in_clause', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '160', 'type': 'attribute', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'bulk_form'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '165', 'type': 'if_clause', 'children': ['166']},{'id': '166', 'type': 'boolean_operator', 'children': ['167', '178'], 'value': 'and'},{'id': '167', 'type': 'boolean_operator', 'children': ['168', '173'], 'value': 'and'},{'id': '168', 'type': 'comparison_operator', 'children': ['169', '172'], 'value': 'is'},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '172', 'type': 'None', 'children': []},{'id': '173', 'type': 'comparison_operator', 'children': ['174', '177'], 'value': '!='},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '177', 'type': 'string', 'children': [], 'value': "''"},{'id': '178', 'type': 'comparison_operator', 'children': ['179', '182'], 'value': 'is'},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '182', 'type': 'None', 'children': []},{'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': 'queryset'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'dictionary_splat', 'children': ['190']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'updates'},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'call', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'post_bulk_edit'},{'id': '194', 'type': 'argument_list', 'children': ['195', '198', '201']},{'id': '195', 'type': 'keyword_argument', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '198', 'type': 'keyword_argument', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'queryset'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'queryset'},{'id': '201', 'type': 'keyword_argument', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'updates'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'updates'},{'id': '204', 'type': 'return_statement', 'children': ['205']},{'id': '205', 'type': 'call', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'HttpResponseRedirect'},{'id': '207', 'type': 'argument_list', 'children': ['208']},{'id': '208', 'type': 'subscript', 'children': ['209', '212']},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'META'},{'id': '212', 'type': 'string', 'children': [], 'value': "'HTTP_REFERER'"},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'assignment', 'children': ['215', '218']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '218', 'type': 'call', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'table_context'},{'id': '220', 'type': 'argument_list', 'children': ['221', '222', '225', '228', '231', '234', '237', '240', '243']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '222', 'type': 'keyword_argument', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '225', 'type': 'keyword_argument', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'links'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'links'},{'id': '228', 'type': 'keyword_argument', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'paginate_by'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'paginate_by'},{'id': '231', 'type': 'keyword_argument', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '234', 'type': 'keyword_argument', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'extra_context'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '237', 'type': 'keyword_argument', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'paginator'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'paginator'},{'id': '240', 'type': 'keyword_argument', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'show_hits'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'show_hits'},{'id': '243', 'type': 'keyword_argument', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'hit_label'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'hit_label'},{'id': '246', 'type': 'if_statement', 'children': ['247', '253']},{'id': '247', 'type': 'boolean_operator', 'children': ['248', '252'], 'value': 'and'},{'id': '248', 'type': 'not_operator', 'children': ['249']},{'id': '249', 'type': 'attribute', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'blank_on_empty'},{'id': '253', 'type': 'block', 'children': ['254']},{'id': '254', 'type': 'return_statement', 'children': ['255']},{'id': '255', 'type': 'string', 'children': [], 'value': "''"},{'id': '256', 'type': 'if_statement', 'children': ['257', '269']},{'id': '257', 'type': 'boolean_operator', 'children': ['258', '261'], 'value': 'and'},{'id': '258', 'type': 'attribute', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'query_form'},{'id': '261', 'type': 'not_operator', 'children': ['262']},{'id': '262', 'type': 'call', 'children': ['263', '268']},{'id': '263', 'type': 'attribute', 'children': ['264', '267']},{'id': '264', 'type': 'attribute', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'query_form'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'is_valid'},{'id': '268', 'type': 'argument_list', 'children': []},{'id': '269', 'type': 'block', 'children': ['270', '276']},{'id': '270', 'type': 'expression_statement', 'children': ['271']},{'id': '271', 'type': 'assignment', 'children': ['272', '275']},{'id': '272', 'type': 'attribute', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '275', 'type': 'None', 'children': []},{'id': '276', 'type': 'expression_statement', 'children': ['277']},{'id': '277', 'type': 'assignment', 'children': ['278', '283']},{'id': '278', 'type': 'subscript', 'children': ['279', '282']},{'id': '279', 'type': 'attribute', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '282', 'type': 'string', 'children': [], 'value': "'invalid_form_message'"},{'id': '283', 'type': 'call', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'mark_safe'},{'id': '285', 'type': 'argument_list', 'children': ['286']},{'id': '286', 'type': 'string', 'children': [], 'value': '\'<i class="fa fa-meh-o fa-5x" aria-hidden="true"></i>\''},{'id': '287', 'type': 'return_statement', 'children': ['288']},{'id': '288', 'type': 'call', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'render_template'},{'id': '290', 'type': 'argument_list', 'children': ['291', '292', '293']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '293', 'type': 'attribute', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'context'} | def render_table(request,
table,
links=None,
context=None,
template='tri_table/list.html',
blank_on_empty=False,
paginate_by=40,
page=None,
paginator=None,
show_hits=False,
hit_label='Items',
post_bulk_edit=lambda table, queryset, updates: None):
if not context:
context = {}
if isinstance(table, Namespace):
table = table()
assert isinstance(table, Table), table
table.request = request
should_return, dispatch_result = handle_dispatch(request=request, obj=table)
if should_return:
return dispatch_result
context['bulk_form'] = table.bulk_form
context['query_form'] = table.query_form
context['tri_query_error'] = table.query_error
if table.bulk_form and request.method == 'POST':
if table.bulk_form.is_valid():
queryset = table.bulk_queryset()
updates = {
field.name: field.value
for field in table.bulk_form.fields
if field.value is not None and field.value != '' and field.attr is not None
}
queryset.update(**updates)
post_bulk_edit(table=table, queryset=queryset, updates=updates)
return HttpResponseRedirect(request.META['HTTP_REFERER'])
table.context = table_context(
request,
table=table,
links=links,
paginate_by=paginate_by,
page=page,
extra_context=context,
paginator=paginator,
show_hits=show_hits,
hit_label=hit_label,
)
if not table.data and blank_on_empty:
return ''
if table.query_form and not table.query_form.is_valid():
table.data = None
table.context['invalid_form_message'] = mark_safe('<i class="fa fa-meh-o fa-5x" aria-hidden="true"></i>')
return render_template(request, template, table.context) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '22']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'create_network'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16', '19']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'net_view_name'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'cidr'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'nameservers'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'members'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'gateway_ip'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'dhcp_trel_ip'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'default_parameter', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'network_extattrs'},{'id': '21', 'type': 'None', 'children': []},{'id': '22', 'type': 'block', 'children': ['23', '34', '38', '63', '85', '110']},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'ipv4'},{'id': '26', 'type': 'comparison_operator', 'children': ['27', '33'], 'value': '=='},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'ib_utils'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'determine_ip_version'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'cidr'},{'id': '33', 'type': 'integer', 'children': [], 'value': '4'},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '37', 'type': 'list', 'children': [], 'value': '[]'},{'id': '38', 'type': 'if_statement', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'nameservers'},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'DhcpOption'},{'id': '51', 'type': 'argument_list', 'children': ['52', '55']},{'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '54', 'type': 'string', 'children': [], 'value': "'domain-name-servers'"},{'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '57', 'type': 'call', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'string', 'children': [], 'value': '","'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'nameservers'},{'id': '63', 'type': 'if_statement', 'children': ['64', '67']},{'id': '64', 'type': 'boolean_operator', 'children': ['65', '66'], 'value': 'and'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'ipv4'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'gateway_ip'},{'id': '67', 'type': 'block', 'children': ['68']},{'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': 'options'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'DhcpOption'},{'id': '78', 'type': 'argument_list', 'children': ['79', '82']},{'id': '79', 'type': 'keyword_argument', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '81', 'type': 'string', 'children': [], 'value': "'routers'"},{'id': '82', 'type': 'keyword_argument', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'gateway_ip'},{'id': '85', 'type': 'if_statement', 'children': ['86', '89']},{'id': '86', 'type': 'boolean_operator', 'children': ['87', '88'], 'value': 'and'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'ipv4'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'dhcp_trel_ip'},{'id': '89', 'type': 'block', 'children': ['90']},{'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': 'options'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'DhcpOption'},{'id': '100', 'type': 'argument_list', 'children': ['101', '104', '107']},{'id': '101', 'type': 'keyword_argument', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '103', 'type': 'string', 'children': [], 'value': "'dhcp-server-identifier'"},{'id': '104', 'type': 'keyword_argument', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'num'},{'id': '106', 'type': 'integer', 'children': [], 'value': '54'},{'id': '107', 'type': 'keyword_argument', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'dhcp_trel_ip'},{'id': '110', 'type': 'return_statement', 'children': ['111']},{'id': '111', 'type': 'call', 'children': ['112', '117']},{'id': '112', 'type': 'attribute', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'Network'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'create'},{'id': '117', 'type': 'argument_list', 'children': ['118', '121', '124', '127', '130', '133', '136']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'connector'},{'id': '121', 'type': 'keyword_argument', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'network_view'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'net_view_name'},{'id': '124', 'type': 'keyword_argument', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'cidr'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'cidr'},{'id': '127', 'type': 'keyword_argument', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'members'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'members'},{'id': '130', 'type': 'keyword_argument', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '133', 'type': 'keyword_argument', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'extattrs'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'network_extattrs'},{'id': '136', 'type': 'keyword_argument', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'check_if_exists'},{'id': '138', 'type': 'False', 'children': []} | def create_network(self, net_view_name, cidr, nameservers=None,
members=None, gateway_ip=None, dhcp_trel_ip=None,
network_extattrs=None):
ipv4 = ib_utils.determine_ip_version(cidr) == 4
options = []
if nameservers:
options.append(obj.DhcpOption(name='domain-name-servers',
value=",".join(nameservers)))
if ipv4 and gateway_ip:
options.append(obj.DhcpOption(name='routers',
value=gateway_ip))
if ipv4 and dhcp_trel_ip:
options.append(obj.DhcpOption(name='dhcp-server-identifier',
num=54,
value=dhcp_trel_ip))
return obj.Network.create(self.connector,
network_view=net_view_name,
cidr=cidr,
members=members,
options=options,
extattrs=network_extattrs,
check_if_exists=False) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_run_pass'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '173']},{'id': '6', 'type': 'while_statement', 'children': ['7', '8']},{'id': '7', 'type': 'True', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '43', '52', '101', '111', '142', '152']},{'id': '9', 'type': 'try_statement', 'children': ['10', '22']},{'id': '10', 'type': 'block', 'children': ['11']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '14', 'type': 'call', 'children': ['15', '20']},{'id': '15', 'type': 'attribute', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '18', 'type': 'identifier', 'children': [], 'value': '_file'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'integer', 'children': [], 'value': '4096'},{'id': '22', 'type': 'except_clause', 'children': ['23', '24', '25']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'IOError'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'if_statement', 'children': ['27', '34']},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '31'], 'value': '=='},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'errno'},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'errno'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'ESTALE'},{'id': '34', 'type': 'block', 'children': ['35', '41']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'active'},{'id': '40', 'type': 'False', 'children': []},{'id': '41', 'type': 'return_statement', 'children': ['42']},{'id': '42', 'type': 'False', 'children': []},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '49', 'type': 'identifier', 'children': [], 'value': '_buffer_extract'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '52', 'type': 'if_statement', 'children': ['53', '55']},{'id': '53', 'type': 'not_operator', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '55', 'type': 'block', 'children': ['56', '100']},{'id': '56', 'type': 'if_statement', 'children': ['57', '72']},{'id': '57', 'type': 'boolean_operator', 'children': ['58', '61'], 'value': 'and'},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '60', 'type': 'identifier', 'children': [], 'value': '_current_event'},{'id': '61', 'type': 'comparison_operator', 'children': ['62', '71'], 'value': '>'},{'id': '62', 'type': 'binary_operator', 'children': ['63', '68'], 'value': '-'},{'id': '63', 'type': 'call', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '67', 'type': 'argument_list', 'children': []},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '70', 'type': 'identifier', 'children': [], 'value': '_last_activity'},{'id': '71', 'type': 'integer', 'children': [], 'value': '1'},{'id': '72', 'type': 'block', 'children': ['73', '84', '92']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '83', 'type': 'identifier', 'children': [], 'value': '_current_event'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'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': 'self'},{'id': '89', 'type': 'identifier', 'children': [], 'value': '_current_event'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'clear'},{'id': '91', 'type': 'argument_list', 'children': []},{'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': 'self'},{'id': '96', 'type': 'identifier', 'children': [], 'value': '_callback_wrapper'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'list', 'children': ['99'], 'value': '[event]'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '100', 'type': 'break_statement', 'children': []},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '105', 'type': 'identifier', 'children': [], 'value': '_last_activity'},{'id': '106', 'type': 'call', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '110', 'type': 'argument_list', 'children': []},{'id': '111', 'type': 'if_statement', 'children': ['112', '119', '136']},{'id': '112', 'type': 'boolean_operator', 'children': ['113', '116'], 'value': 'or'},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '115', 'type': 'identifier', 'children': [], 'value': '_multiline_regex_after'},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '118', 'type': 'identifier', 'children': [], 'value': '_multiline_regex_before'},{'id': '119', 'type': 'block', 'children': ['120']},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'events'},{'id': '123', 'type': 'call', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'multiline_merge'},{'id': '125', 'type': 'argument_list', 'children': ['126', '127', '130', '133']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '129', 'type': 'identifier', 'children': [], 'value': '_current_event'},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '132', 'type': 'identifier', 'children': [], 'value': '_multiline_regex_after'},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '135', 'type': 'identifier', 'children': [], 'value': '_multiline_regex_before'},{'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': 'events'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '142', 'type': 'if_statement', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'events'},{'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': 'self'},{'id': '149', 'type': 'identifier', 'children': [], 'value': '_callback_wrapper'},{'id': '150', 'type': 'argument_list', 'children': ['151']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'events'},{'id': '152', 'type': 'if_statement', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '155', 'type': 'identifier', 'children': [], 'value': '_sincedb_path'},{'id': '156', 'type': 'block', 'children': ['157', '164']},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'current_line_count'},{'id': '160', 'type': 'call', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'lines'},{'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': 'self'},{'id': '168', 'type': 'identifier', 'children': [], 'value': '_sincedb_update_position'},{'id': '169', 'type': 'argument_list', 'children': ['170']},{'id': '170', 'type': 'keyword_argument', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'current_line_count'},{'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': 'self'},{'id': '177', 'type': 'identifier', 'children': [], 'value': '_sincedb_update_position'},{'id': '178', 'type': 'argument_list', 'children': []} | def _run_pass(self):
while True:
try:
data = self._file.read(4096)
except IOError, e:
if e.errno == errno.ESTALE:
self.active = False
return False
lines = self._buffer_extract(data)
if not lines:
if self._current_event and time.time() - self._last_activity > 1:
event = '\n'.join(self._current_event)
self._current_event.clear()
self._callback_wrapper([event])
break
self._last_activity = time.time()
if self._multiline_regex_after or self._multiline_regex_before:
events = multiline_merge(
lines,
self._current_event,
self._multiline_regex_after,
self._multiline_regex_before)
else:
events = lines
if events:
self._callback_wrapper(events)
if self._sincedb_path:
current_line_count = len(lines)
self._sincedb_update_position(lines=current_line_count)
self._sincedb_update_position() |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'update_files'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '29', '42', '46', '50', '171', '236', '252']},{'id': '6', 'type': 'if_statement', 'children': ['7', '27']},{'id': '7', 'type': 'boolean_operator', 'children': ['8', '11'], 'value': 'and'},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '10', 'type': 'identifier', 'children': [], 'value': '_update_time'},{'id': '11', 'type': 'comparison_operator', 'children': ['12', '24'], 'value': '<'},{'id': '12', 'type': 'binary_operator', 'children': ['13', '21'], 'value': '-'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '20', 'type': 'argument_list', 'children': []},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '23', 'type': 'identifier', 'children': [], 'value': '_update_time'},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': '_discover_interval'},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'return_statement', 'children': []},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '33', 'type': 'identifier', 'children': [], 'value': '_update_time'},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '41', 'type': 'argument_list', 'children': []},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'possible_files'},{'id': '45', 'type': 'list', 'children': [], 'value': '[]'},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '49', 'type': 'list', 'children': [], 'value': '[]'},{'id': '50', 'type': 'if_statement', 'children': ['51', '64', '133']},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '63'], 'value': '>'},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'call', 'children': ['56', '61']},{'id': '56', 'type': 'attribute', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '59', 'type': 'identifier', 'children': [], 'value': '_beaver_config'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'string', 'children': [], 'value': "'globs'"},{'id': '63', 'type': 'integer', 'children': [], 'value': '0'},{'id': '64', 'type': 'block', 'children': ['65', '71']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'extend_files'},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '71', 'type': 'for_statement', 'children': ['72', '75', '87']},{'id': '72', 'type': 'pattern_list', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'exclude'},{'id': '75', 'type': 'call', 'children': ['76', '86']},{'id': '76', 'type': 'attribute', 'children': ['77', '85']},{'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': '_beaver_config'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'string', 'children': [], 'value': "'globs'"},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '86', 'type': 'argument_list', 'children': []},{'id': '87', 'type': 'block', 'children': ['88', '107', '112', '122']},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'globbed'},{'id': '91', 'type': 'list_comprehension', 'children': ['92', '100']},{'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': 'os'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'realpath'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '100', 'type': 'for_in_clause', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '102', 'type': 'call', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'eglob'},{'id': '104', 'type': 'argument_list', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'exclude'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'call', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'extend_files'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'globbed'},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'call', 'children': ['114', '119']},{'id': '114', 'type': 'attribute', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '117', 'type': 'identifier', 'children': [], 'value': '_beaver_config'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'addglob'},{'id': '119', 'type': 'argument_list', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'globbed'},{'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': 'self'},{'id': '126', 'type': 'identifier', 'children': [], 'value': '_callback'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'tuple', 'children': ['129', '130']},{'id': '129', 'type': 'string', 'children': [], 'value': '"addglob"'},{'id': '130', 'type': 'tuple', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'globbed'},{'id': '133', 'type': 'else_clause', 'children': ['134']},{'id': '134', 'type': 'block', 'children': ['135', '141']},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'assignment', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'append_files'},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '141', 'type': 'for_statement', 'children': ['142', '143', '148']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '143', 'type': 'call', 'children': ['144', '147']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'listdir'},{'id': '147', 'type': 'argument_list', 'children': []},{'id': '148', 'type': 'block', 'children': ['149']},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'call', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'append_files'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'call', 'children': ['154', '159']},{'id': '154', 'type': 'attribute', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'realpath'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'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': 'join'},{'id': '166', 'type': 'argument_list', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '169', 'type': 'identifier', 'children': [], 'value': '_folder'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '171', 'type': 'for_statement', 'children': ['172', '173', '174']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'absname'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '174', 'type': 'block', 'children': ['175']},{'id': '175', 'type': 'try_statement', 'children': ['176', '186', '200']},{'id': '176', 'type': 'block', 'children': ['177']},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '180', 'type': 'call', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'stat'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'absname'},{'id': '186', 'type': 'except_clause', 'children': ['187', '188', '189']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'EnvironmentError'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'err'},{'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': 'err'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'errno'},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'errno'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'ENOENT'},{'id': '198', 'type': 'block', 'children': ['199']},{'id': '199', 'type': 'raise_statement', 'children': []},{'id': '200', 'type': 'else_clause', 'children': ['201']},{'id': '201', 'type': 'block', 'children': ['202', '214', '220', '229']},{'id': '202', 'type': 'if_statement', 'children': ['203', '212']},{'id': '203', 'type': 'not_operator', 'children': ['204']},{'id': '204', 'type': 'call', 'children': ['205', '208']},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'stat'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'S_ISREG'},{'id': '208', 'type': 'argument_list', 'children': ['209']},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'st_mode'},{'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': 'append_possible_files'},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'possible_files'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'assignment', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'fid'},{'id': '223', 'type': 'call', 'children': ['224', '227']},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'get_file_id'},{'id': '227', 'type': 'argument_list', 'children': ['228']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '229', 'type': 'expression_statement', 'children': ['230']},{'id': '230', 'type': 'call', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'append_possible_files'},{'id': '232', 'type': 'argument_list', 'children': ['233']},{'id': '233', 'type': 'tuple', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'fid'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'absname'},{'id': '236', 'type': 'expression_statement', 'children': ['237']},{'id': '237', 'type': 'assignment', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'new_files'},{'id': '239', 'type': 'list_comprehension', 'children': ['240', '241', '246']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'fname'},{'id': '241', 'type': 'for_in_clause', 'children': ['242', '245']},{'id': '242', 'type': 'pattern_list', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'fid'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'fname'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'possible_files'},{'id': '246', 'type': 'if_clause', 'children': ['247']},{'id': '247', 'type': 'comparison_operator', 'children': ['248', '249'], 'value': 'not'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'fid'},{'id': '249', 'type': 'attribute', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '251', 'type': 'identifier', 'children': [], 'value': '_tails'},{'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': 'self'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'watch'},{'id': '257', 'type': 'argument_list', 'children': ['258']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'new_files'} | def update_files(self):
if self._update_time and int(time.time()) - self._update_time < self._discover_interval:
return
self._update_time = int(time.time())
possible_files = []
files = []
if len(self._beaver_config.get('globs')) > 0:
extend_files = files.extend
for name, exclude in self._beaver_config.get('globs').items():
globbed = [os.path.realpath(filename) for filename in eglob(name, exclude)]
extend_files(globbed)
self._beaver_config.addglob(name, globbed)
self._callback(("addglob", (name, globbed)))
else:
append_files = files.append
for name in self.listdir():
append_files(os.path.realpath(os.path.join(self._folder, name)))
for absname in files:
try:
st = os.stat(absname)
except EnvironmentError, err:
if err.errno != errno.ENOENT:
raise
else:
if not stat.S_ISREG(st.st_mode):
continue
append_possible_files = possible_files.append
fid = self.get_file_id(st)
append_possible_files((fid, absname))
new_files = [fname for fid, fname in possible_files if fid not in self._tails]
self.watch(new_files) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '29']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'gctx_file_path'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'convert_neg_666'},{'id': '7', 'type': 'True', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'rid'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'cid'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'ridx'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'cidx'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'row_meta_only'},{'id': '22', 'type': 'False', 'children': []},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'col_meta_only'},{'id': '25', 'type': 'False', 'children': []},{'id': '26', 'type': 'default_parameter', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'make_multiindex'},{'id': '28', 'type': 'False', 'children': []},{'id': '29', 'type': 'block', 'children': ['30', '41', '78', '90', '100']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'full_path'},{'id': '33', 'type': 'call', 'children': ['34', '39']},{'id': '34', 'type': 'attribute', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'expanduser'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'gctx_file_path'},{'id': '41', 'type': 'if_statement', 'children': ['42', '51']},{'id': '42', 'type': 'not_operator', 'children': ['43']},{'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': 'os'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'full_path'},{'id': '51', 'type': 'block', 'children': ['52', '56', '68']},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'err_msg'},{'id': '55', 'type': 'string', 'children': [], 'value': '"The given path to the gctx file cannot be found. full_path: {}"'},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'call', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'err_msg'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'full_path'},{'id': '68', 'type': 'raise_statement', 'children': ['69']},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'err_msg'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'full_path'},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'call', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'string', 'children': [], 'value': '"Reading GCTX: {}"'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'full_path'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'gctx_file'},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'h5py'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'File'},{'id': '97', 'type': 'argument_list', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'full_path'},{'id': '99', 'type': 'string', 'children': [], 'value': '"r"'},{'id': '100', 'type': 'if_statement', 'children': ['101', '102', '148', '196']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'row_meta_only'},{'id': '102', 'type': 'block', 'children': ['103', '109', '118', '132', '138', '146']},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'row_dset'},{'id': '106', 'type': 'subscript', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'gctx_file'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'row_meta_group_node'},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'row_meta'},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'parse_metadata_df'},{'id': '114', 'type': 'argument_list', 'children': ['115', '116', '117']},{'id': '115', 'type': 'string', 'children': [], 'value': '"row"'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'row_dset'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'convert_neg_666'},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '123']},{'id': '120', 'type': 'tuple_pattern', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'sorted_ridx'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'sorted_cidx'},{'id': '123', 'type': 'call', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'check_and_order_id_inputs'},{'id': '125', 'type': 'argument_list', 'children': ['126', '127', '128', '129', '130', '131']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'rid'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'ridx'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'cid'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'cidx'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'row_meta'},{'id': '131', 'type': 'None', 'children': []},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'gctx_file'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '137', 'type': 'argument_list', 'children': []},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'assignment', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'row_meta'},{'id': '141', 'type': 'subscript', 'children': ['142', '145']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'row_meta'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'iloc'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'sorted_ridx'},{'id': '146', 'type': 'return_statement', 'children': ['147']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'row_meta'},{'id': '148', 'type': 'elif_clause', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'col_meta_only'},{'id': '150', 'type': 'block', 'children': ['151', '157', '166', '180', '186', '194']},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'col_dset'},{'id': '154', 'type': 'subscript', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'gctx_file'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'col_meta_group_node'},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'col_meta'},{'id': '160', 'type': 'call', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'parse_metadata_df'},{'id': '162', 'type': 'argument_list', 'children': ['163', '164', '165']},{'id': '163', 'type': 'string', 'children': [], 'value': '"col"'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'col_dset'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'convert_neg_666'},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '171']},{'id': '168', 'type': 'tuple_pattern', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'sorted_ridx'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'sorted_cidx'},{'id': '171', 'type': 'call', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'check_and_order_id_inputs'},{'id': '173', 'type': 'argument_list', 'children': ['174', '175', '176', '177', '178', '179']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'rid'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'ridx'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'cid'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'cidx'},{'id': '178', 'type': 'None', 'children': []},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'col_meta'},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'call', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'gctx_file'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '185', 'type': 'argument_list', 'children': []},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'col_meta'},{'id': '189', 'type': 'subscript', 'children': ['190', '193']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'col_meta'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'iloc'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'sorted_cidx'},{'id': '194', 'type': 'return_statement', 'children': ['195']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'col_meta'},{'id': '196', 'type': 'else_clause', 'children': ['197']},{'id': '197', 'type': 'block', 'children': ['198', '204', '213', '219', '228', '242', '248', '259', '267', '275', '283', '299', '305', '331']},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'row_dset'},{'id': '201', 'type': 'subscript', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'gctx_file'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'row_meta_group_node'},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'assignment', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'row_meta'},{'id': '207', 'type': 'call', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'parse_metadata_df'},{'id': '209', 'type': 'argument_list', 'children': ['210', '211', '212']},{'id': '210', 'type': 'string', 'children': [], 'value': '"row"'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'row_dset'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'convert_neg_666'},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'assignment', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'col_dset'},{'id': '216', 'type': 'subscript', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'gctx_file'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'col_meta_group_node'},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'assignment', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'col_meta'},{'id': '222', 'type': 'call', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'parse_metadata_df'},{'id': '224', 'type': 'argument_list', 'children': ['225', '226', '227']},{'id': '225', 'type': 'string', 'children': [], 'value': '"col"'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'col_dset'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'convert_neg_666'},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'assignment', 'children': ['230', '233']},{'id': '230', 'type': 'tuple_pattern', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'sorted_ridx'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'sorted_cidx'},{'id': '233', 'type': 'call', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'check_and_order_id_inputs'},{'id': '235', 'type': 'argument_list', 'children': ['236', '237', '238', '239', '240', '241']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'rid'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'ridx'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'cid'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'cidx'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'row_meta'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'col_meta'},{'id': '242', 'type': 'expression_statement', 'children': ['243']},{'id': '243', 'type': 'assignment', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'data_dset'},{'id': '245', 'type': 'subscript', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'gctx_file'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'data_node'},{'id': '248', 'type': 'expression_statement', 'children': ['249']},{'id': '249', 'type': 'assignment', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'data_df'},{'id': '251', 'type': 'call', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'parse_data_df'},{'id': '253', 'type': 'argument_list', 'children': ['254', '255', '256', '257', '258']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'data_dset'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'sorted_ridx'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'sorted_cidx'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'row_meta'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'col_meta'},{'id': '259', 'type': 'expression_statement', 'children': ['260']},{'id': '260', 'type': 'assignment', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'row_meta'},{'id': '262', 'type': 'subscript', 'children': ['263', '266']},{'id': '263', 'type': 'attribute', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'row_meta'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'iloc'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'sorted_ridx'},{'id': '267', 'type': 'expression_statement', 'children': ['268']},{'id': '268', 'type': 'assignment', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'col_meta'},{'id': '270', 'type': 'subscript', 'children': ['271', '274']},{'id': '271', 'type': 'attribute', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'col_meta'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'iloc'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'sorted_cidx'},{'id': '275', 'type': 'expression_statement', 'children': ['276']},{'id': '276', 'type': 'assignment', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'my_version'},{'id': '278', 'type': 'subscript', 'children': ['279', '282']},{'id': '279', 'type': 'attribute', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'gctx_file'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'attrs'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'version_node'},{'id': '283', 'type': 'if_statement', 'children': ['284', '292']},{'id': '284', 'type': 'comparison_operator', 'children': ['285', '289'], 'value': '=='},{'id': '285', 'type': 'call', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '287', 'type': 'argument_list', 'children': ['288']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'my_version'},{'id': '289', 'type': 'attribute', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'ndarray'},{'id': '292', 'type': 'block', 'children': ['293']},{'id': '293', 'type': 'expression_statement', 'children': ['294']},{'id': '294', 'type': 'assignment', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'my_version'},{'id': '296', 'type': 'subscript', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'my_version'},{'id': '298', 'type': 'integer', 'children': [], 'value': '0'},{'id': '299', 'type': 'expression_statement', 'children': ['300']},{'id': '300', 'type': 'call', 'children': ['301', '304']},{'id': '301', 'type': 'attribute', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'gctx_file'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '304', 'type': 'argument_list', 'children': []},{'id': '305', 'type': 'expression_statement', 'children': ['306']},{'id': '306', 'type': 'assignment', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'my_gctoo'},{'id': '308', 'type': 'call', 'children': ['309', '312']},{'id': '309', 'type': 'attribute', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'GCToo'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'GCToo'},{'id': '312', 'type': 'argument_list', 'children': ['313', '316', '319', '322', '325', '328']},{'id': '313', 'type': 'keyword_argument', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'data_df'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'data_df'},{'id': '316', 'type': 'keyword_argument', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'row_metadata_df'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'row_meta'},{'id': '319', 'type': 'keyword_argument', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'col_metadata_df'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'col_meta'},{'id': '322', 'type': 'keyword_argument', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'src'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'full_path'},{'id': '325', 'type': 'keyword_argument', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'my_version'},{'id': '328', 'type': 'keyword_argument', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'make_multiindex'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'make_multiindex'},{'id': '331', 'type': 'return_statement', 'children': ['332']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'my_gctoo'} | def parse(gctx_file_path, convert_neg_666=True, rid=None, cid=None,
ridx=None, cidx=None, row_meta_only=False, col_meta_only=False, make_multiindex=False):
full_path = os.path.expanduser(gctx_file_path)
if not os.path.exists(full_path):
err_msg = "The given path to the gctx file cannot be found. full_path: {}"
logger.error(err_msg.format(full_path))
raise Exception(err_msg.format(full_path))
logger.info("Reading GCTX: {}".format(full_path))
gctx_file = h5py.File(full_path, "r")
if row_meta_only:
row_dset = gctx_file[row_meta_group_node]
row_meta = parse_metadata_df("row", row_dset, convert_neg_666)
(sorted_ridx, sorted_cidx) = check_and_order_id_inputs(rid, ridx, cid, cidx, row_meta, None)
gctx_file.close()
row_meta = row_meta.iloc[sorted_ridx]
return row_meta
elif col_meta_only:
col_dset = gctx_file[col_meta_group_node]
col_meta = parse_metadata_df("col", col_dset, convert_neg_666)
(sorted_ridx, sorted_cidx) = check_and_order_id_inputs(rid, ridx, cid, cidx, None, col_meta)
gctx_file.close()
col_meta = col_meta.iloc[sorted_cidx]
return col_meta
else:
row_dset = gctx_file[row_meta_group_node]
row_meta = parse_metadata_df("row", row_dset, convert_neg_666)
col_dset = gctx_file[col_meta_group_node]
col_meta = parse_metadata_df("col", col_dset, convert_neg_666)
(sorted_ridx, sorted_cidx) = check_and_order_id_inputs(rid, ridx, cid, cidx, row_meta, col_meta)
data_dset = gctx_file[data_node]
data_df = parse_data_df(data_dset, sorted_ridx, sorted_cidx, row_meta, col_meta)
row_meta = row_meta.iloc[sorted_ridx]
col_meta = col_meta.iloc[sorted_cidx]
my_version = gctx_file.attrs[version_node]
if type(my_version) == np.ndarray:
my_version = my_version[0]
gctx_file.close()
my_gctoo = GCToo.GCToo(data_df=data_df, row_metadata_df=row_meta, col_metadata_df=col_meta,
src=full_path, version=my_version, make_multiindex=make_multiindex)
return my_gctoo |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'multi_index_df_to_component_dfs'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'multi_index_df'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'rid'},{'id': '7', 'type': 'string', 'children': [], 'value': '"rid"'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'cid'},{'id': '10', 'type': 'string', 'children': [], 'value': '"cid"'},{'id': '11', 'type': 'block', 'children': ['12', '26', '40', '128', '216', '249', '282', '315']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'rids'},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '17', 'type': 'argument_list', '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': 'multi_index_df'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'get_level_values'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'rid'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'cids'},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'call', 'children': ['33', '38']},{'id': '33', 'type': 'attribute', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'multi_index_df'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'get_level_values'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'cid'},{'id': '40', 'type': 'if_statement', 'children': ['41', '50', '118']},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '43', 'type': 'argument_list', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'multi_index_df'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'MultiIndex'},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'if_statement', 'children': ['52', '62', '108']},{'id': '52', 'type': 'comparison_operator', 'children': ['53', '61'], 'value': '>'},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'attribute', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'multi_index_df'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '61', 'type': 'integer', 'children': [], 'value': '1'},{'id': '62', 'type': 'block', 'children': ['63', '74', '83']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'mi_df_index'},{'id': '66', 'type': 'call', 'children': ['67', '72']},{'id': '67', 'type': 'attribute', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'multi_index_df'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'droplevel'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'rid'},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'rhds'},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'mi_df_index'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'row_metadata'},{'id': '86', 'type': 'attribute', 'children': ['87', '107']},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'list_comprehension', 'children': ['93', '101']},{'id': '93', 'type': 'attribute', 'children': ['94', '100']},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'mi_df_index'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'get_level_values'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '101', 'type': 'for_in_clause', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '103', 'type': 'call', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'rhds'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '108', 'type': 'else_clause', 'children': ['109']},{'id': '109', 'type': 'block', 'children': ['110', '114']},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'assignment', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'rhds'},{'id': '113', 'type': 'list', 'children': [], 'value': '[]'},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'row_metadata'},{'id': '117', 'type': 'list', 'children': [], 'value': '[]'},{'id': '118', 'type': 'else_clause', 'children': ['119']},{'id': '119', 'type': 'block', 'children': ['120', '124']},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'rhds'},{'id': '123', 'type': 'list', 'children': [], 'value': '[]'},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'assignment', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'row_metadata'},{'id': '127', 'type': 'list', 'children': [], 'value': '[]'},{'id': '128', 'type': 'if_statement', 'children': ['129', '138', '206']},{'id': '129', 'type': 'call', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '131', 'type': 'argument_list', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'multi_index_df'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'MultiIndex'},{'id': '138', 'type': 'block', 'children': ['139']},{'id': '139', 'type': 'if_statement', 'children': ['140', '150', '196']},{'id': '140', 'type': 'comparison_operator', 'children': ['141', '149'], 'value': '>'},{'id': '141', 'type': 'call', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'attribute', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'multi_index_df'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '149', 'type': 'integer', 'children': [], 'value': '1'},{'id': '150', 'type': 'block', 'children': ['151', '162', '171']},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'mi_df_columns'},{'id': '154', 'type': 'call', 'children': ['155', '160']},{'id': '155', 'type': 'attribute', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'multi_index_df'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'droplevel'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'cid'},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'assignment', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'chds'},{'id': '165', 'type': 'call', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '167', 'type': 'argument_list', 'children': ['168']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'mi_df_columns'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'assignment', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'col_metadata'},{'id': '174', 'type': 'attribute', 'children': ['175', '195']},{'id': '175', 'type': 'call', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'list_comprehension', 'children': ['181', '189']},{'id': '181', 'type': 'attribute', 'children': ['182', '188']},{'id': '182', 'type': 'call', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'mi_df_columns'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'get_level_values'},{'id': '186', 'type': 'argument_list', 'children': ['187']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '189', 'type': 'for_in_clause', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '191', 'type': 'call', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '193', 'type': 'argument_list', 'children': ['194']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'chds'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '196', 'type': 'else_clause', 'children': ['197']},{'id': '197', 'type': 'block', 'children': ['198', '202']},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'chds'},{'id': '201', 'type': 'list', 'children': [], 'value': '[]'},{'id': '202', 'type': 'expression_statement', 'children': ['203']},{'id': '203', 'type': 'assignment', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'col_metadata'},{'id': '205', 'type': 'list', 'children': [], 'value': '[]'},{'id': '206', 'type': 'else_clause', 'children': ['207']},{'id': '207', 'type': 'block', 'children': ['208', '212']},{'id': '208', 'type': 'expression_statement', 'children': ['209']},{'id': '209', 'type': 'assignment', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'chds'},{'id': '211', 'type': 'list', 'children': [], 'value': '[]'},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'assignment', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'col_metadata'},{'id': '215', 'type': 'list', 'children': [], 'value': '[]'},{'id': '216', 'type': 'expression_statement', 'children': ['217']},{'id': '217', 'type': 'assignment', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'row_metadata_df'},{'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': 'pd'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'DataFrame'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'from_records'},{'id': '225', 'type': 'argument_list', 'children': ['226', '227', '238']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'row_metadata'},{'id': '227', 'type': 'keyword_argument', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '229', 'type': 'call', 'children': ['230', '233']},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'Index'},{'id': '233', 'type': 'argument_list', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'rids'},{'id': '235', 'type': 'keyword_argument', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '237', 'type': 'string', 'children': [], 'value': '"rid"'},{'id': '238', 'type': 'keyword_argument', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '240', 'type': 'call', 'children': ['241', '244']},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'Index'},{'id': '244', 'type': 'argument_list', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'rhds'},{'id': '246', 'type': 'keyword_argument', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '248', 'type': 'string', 'children': [], 'value': '"rhd"'},{'id': '249', 'type': 'expression_statement', 'children': ['250']},{'id': '250', 'type': 'assignment', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'col_metadata_df'},{'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': 'pd'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'DataFrame'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'from_records'},{'id': '258', 'type': 'argument_list', 'children': ['259', '260', '271']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'col_metadata'},{'id': '260', 'type': 'keyword_argument', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '262', 'type': 'call', 'children': ['263', '266']},{'id': '263', 'type': 'attribute', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'Index'},{'id': '266', 'type': 'argument_list', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'cids'},{'id': '268', 'type': 'keyword_argument', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '270', 'type': 'string', 'children': [], 'value': '"cid"'},{'id': '271', 'type': 'keyword_argument', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '273', 'type': 'call', 'children': ['274', '277']},{'id': '274', 'type': 'attribute', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'Index'},{'id': '277', 'type': 'argument_list', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'chds'},{'id': '279', 'type': 'keyword_argument', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '281', 'type': 'string', 'children': [], 'value': '"chd"'},{'id': '282', 'type': 'expression_statement', 'children': ['283']},{'id': '283', 'type': 'assignment', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'data_df'},{'id': '285', 'type': 'call', 'children': ['286', '289']},{'id': '286', 'type': 'attribute', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'DataFrame'},{'id': '289', 'type': 'argument_list', 'children': ['290', '293', '304']},{'id': '290', 'type': 'attribute', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'multi_index_df'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '293', 'type': 'keyword_argument', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '295', 'type': 'call', 'children': ['296', '299']},{'id': '296', 'type': 'attribute', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'Index'},{'id': '299', 'type': 'argument_list', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'rids'},{'id': '301', 'type': 'keyword_argument', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '303', 'type': 'string', 'children': [], 'value': '"rid"'},{'id': '304', 'type': 'keyword_argument', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '306', 'type': 'call', 'children': ['307', '310']},{'id': '307', 'type': 'attribute', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'Index'},{'id': '310', 'type': 'argument_list', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'cids'},{'id': '312', 'type': 'keyword_argument', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '314', 'type': 'string', 'children': [], 'value': '"cid"'},{'id': '315', 'type': 'return_statement', 'children': ['316']},{'id': '316', 'type': 'expression_list', 'children': ['317', '318', '319']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'data_df'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'row_metadata_df'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'col_metadata_df'} | def multi_index_df_to_component_dfs(multi_index_df, rid="rid", cid="cid"):
rids = list(multi_index_df.index.get_level_values(rid))
cids = list(multi_index_df.columns.get_level_values(cid))
if isinstance(multi_index_df.index, pd.MultiIndex):
if len(multi_index_df.index.names) > 1:
mi_df_index = multi_index_df.index.droplevel(rid)
rhds = list(mi_df_index.names)
row_metadata = np.array([mi_df_index.get_level_values(level).values for level in list(rhds)]).T
else:
rhds = []
row_metadata = []
else:
rhds = []
row_metadata = []
if isinstance(multi_index_df.columns, pd.MultiIndex):
if len(multi_index_df.columns.names) > 1:
mi_df_columns = multi_index_df.columns.droplevel(cid)
chds = list(mi_df_columns.names)
col_metadata = np.array([mi_df_columns.get_level_values(level).values for level in list(chds)]).T
else:
chds = []
col_metadata = []
else:
chds = []
col_metadata = []
row_metadata_df = pd.DataFrame.from_records(row_metadata, index=pd.Index(rids, name="rid"), columns=pd.Index(rhds, name="rhd"))
col_metadata_df = pd.DataFrame.from_records(col_metadata, index=pd.Index(cids, name="cid"), columns=pd.Index(chds, name="chd"))
data_df = pd.DataFrame(multi_index_df.values, index=pd.Index(rids, name="rid"), columns=pd.Index(cids, name="cid"))
return data_df, row_metadata_df, col_metadata_df |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '29']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'file_path'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'convert_neg_666'},{'id': '7', 'type': 'True', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'rid'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'cid'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'ridx'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'cidx'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'row_meta_only'},{'id': '22', 'type': 'False', 'children': []},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'col_meta_only'},{'id': '25', 'type': 'False', 'children': []},{'id': '26', 'type': 'default_parameter', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'make_multiindex'},{'id': '28', 'type': 'False', 'children': []},{'id': '29', 'type': 'block', 'children': ['30', '130']},{'id': '30', 'type': 'if_statement', 'children': ['31', '37', '71', '112']},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'file_path'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'string', 'children': [], 'value': '".gct"'},{'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': 'out'},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'parse_gct'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'parse'},{'id': '45', 'type': 'argument_list', 'children': ['46', '47', '50', '53', '56', '59', '62', '65', '68']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'file_path'},{'id': '47', 'type': 'keyword_argument', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'convert_neg_666'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'convert_neg_666'},{'id': '50', 'type': 'keyword_argument', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'rid'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'rid'},{'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'cid'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'cid'},{'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'ridx'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'ridx'},{'id': '59', 'type': 'keyword_argument', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'cidx'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'cidx'},{'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'row_meta_only'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'row_meta_only'},{'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'col_meta_only'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'col_meta_only'},{'id': '68', 'type': 'keyword_argument', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'make_multiindex'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'make_multiindex'},{'id': '71', 'type': 'elif_clause', 'children': ['72', '78']},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'file_path'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'string', 'children': [], 'value': '".gctx"'},{'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': 'out'},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'parse_gctx'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'parse'},{'id': '86', 'type': 'argument_list', 'children': ['87', '88', '91', '94', '97', '100', '103', '106', '109']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'file_path'},{'id': '88', 'type': 'keyword_argument', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'convert_neg_666'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'convert_neg_666'},{'id': '91', 'type': 'keyword_argument', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'rid'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'rid'},{'id': '94', 'type': 'keyword_argument', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'cid'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'cid'},{'id': '97', 'type': 'keyword_argument', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'ridx'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'ridx'},{'id': '100', 'type': 'keyword_argument', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'cidx'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'cidx'},{'id': '103', 'type': 'keyword_argument', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'row_meta_only'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'row_meta_only'},{'id': '106', 'type': 'keyword_argument', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'col_meta_only'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'col_meta_only'},{'id': '109', 'type': 'keyword_argument', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'make_multiindex'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'make_multiindex'},{'id': '112', 'type': 'else_clause', 'children': ['113']},{'id': '113', 'type': 'block', 'children': ['114', '118', '125']},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'err_msg'},{'id': '117', 'type': 'string', 'children': [], 'value': '"File to parse must be .gct or .gctx!"'},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'call', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'err_msg'},{'id': '125', 'type': 'raise_statement', 'children': ['126']},{'id': '126', 'type': 'call', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'err_msg'},{'id': '130', 'type': 'return_statement', 'children': ['131']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'out'} | def parse(file_path, convert_neg_666=True, rid=None, cid=None, ridx=None, cidx=None,
row_meta_only=False, col_meta_only=False, make_multiindex=False):
if file_path.endswith(".gct"):
out = parse_gct.parse(file_path, convert_neg_666=convert_neg_666,
rid=rid, cid=cid, ridx=ridx, cidx=cidx,
row_meta_only=row_meta_only, col_meta_only=col_meta_only,
make_multiindex=make_multiindex)
elif file_path.endswith(".gctx"):
out = parse_gctx.parse(file_path, convert_neg_666=convert_neg_666,
rid=rid, cid=cid, ridx=ridx, cidx=cidx,
row_meta_only=row_meta_only, col_meta_only=col_meta_only,
make_multiindex=make_multiindex)
else:
err_msg = "File to parse must be .gct or .gctx!"
logger.error(err_msg)
raise Exception(err_msg)
return out |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'assemble_concatenated_meta'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'concated_meta_dfs'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'remove_all_metadata_fields'},{'id': '6', 'type': 'block', 'children': ['7', '29', '41', '49', '61', '76', '80', '98']},{'id': '7', 'type': 'if_statement', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'remove_all_metadata_fields'},{'id': '9', 'type': 'block', 'children': ['10']},{'id': '10', 'type': 'for_statement', 'children': ['11', '12', '13']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'concated_meta_dfs'},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'drop'},{'id': '19', 'type': 'argument_list', 'children': ['20', '23', '26']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '23', 'type': 'keyword_argument', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '25', 'type': 'integer', 'children': [], 'value': '1'},{'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'inplace'},{'id': '28', 'type': 'True', 'children': []},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'all_concated_meta_df'},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'concat'},{'id': '36', 'type': 'argument_list', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'concated_meta_dfs'},{'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '40', 'type': 'integer', 'children': [], 'value': '0'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'n_rows'},{'id': '44', 'type': 'subscript', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'all_concated_meta_df'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '48', 'type': 'integer', 'children': [], 'value': '0'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'string', 'children': [], 'value': '"all_concated_meta_df.shape[0]: {}"'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'n_rows'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'n_rows_cumulative'},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'list_comprehension', 'children': ['68', '73']},{'id': '68', 'type': 'subscript', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '72', 'type': 'integer', 'children': [], 'value': '0'},{'id': '73', 'type': 'for_in_clause', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'concated_meta_dfs'},{'id': '76', 'type': 'assert_statement', 'children': ['77']},{'id': '77', 'type': 'comparison_operator', 'children': ['78', '79'], 'value': '=='},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'n_rows'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'n_rows_cumulative'},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'all_concated_meta_df_sorted'},{'id': '83', 'type': 'call', 'children': ['84', '94']},{'id': '84', 'type': 'attribute', 'children': ['85', '93']},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'all_concated_meta_df'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'sort_index'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'keyword_argument', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '92', 'type': 'integer', 'children': [], 'value': '0'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'sort_index'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'keyword_argument', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '97', 'type': 'integer', 'children': [], 'value': '1'},{'id': '98', 'type': 'return_statement', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'all_concated_meta_df_sorted'} | def assemble_concatenated_meta(concated_meta_dfs, remove_all_metadata_fields):
if remove_all_metadata_fields:
for df in concated_meta_dfs:
df.drop(df.columns, axis=1, inplace=True)
all_concated_meta_df = pd.concat(concated_meta_dfs, axis=0)
n_rows = all_concated_meta_df.shape[0]
logger.debug("all_concated_meta_df.shape[0]: {}".format(n_rows))
n_rows_cumulative = sum([df.shape[0] for df in concated_meta_dfs])
assert n_rows == n_rows_cumulative
all_concated_meta_df_sorted = all_concated_meta_df.sort_index(axis=0).sort_index(axis=1)
return all_concated_meta_df_sorted |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'assemble_data'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'data_dfs'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'concat_direction'},{'id': '6', 'type': 'block', 'children': ['7', '119', '137']},{'id': '7', 'type': 'if_statement', 'children': ['8', '11', '63']},{'id': '8', 'type': 'comparison_operator', 'children': ['9', '10'], 'value': '=='},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'concat_direction'},{'id': '10', 'type': 'string', 'children': [], 'value': '"horiz"'},{'id': '11', 'type': 'block', 'children': ['12', '24', '32', '44', '59']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'all_data_df'},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'concat'},{'id': '19', 'type': 'argument_list', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'data_dfs'},{'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '23', 'type': 'integer', 'children': [], 'value': '1'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'n_cols'},{'id': '27', 'type': 'subscript', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'all_data_df'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '31', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'logger'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'string', 'children': [], 'value': '"all_data_df.shape[1]: {}"'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'n_cols'},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'n_cols_cumulative'},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'list_comprehension', 'children': ['51', '56']},{'id': '51', 'type': 'subscript', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '55', 'type': 'integer', 'children': [], 'value': '1'},{'id': '56', 'type': 'for_in_clause', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'data_dfs'},{'id': '59', 'type': 'assert_statement', 'children': ['60']},{'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': '=='},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'n_cols'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'n_cols_cumulative'},{'id': '63', 'type': 'elif_clause', 'children': ['64', '67']},{'id': '64', 'type': 'comparison_operator', 'children': ['65', '66'], 'value': '=='},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'concat_direction'},{'id': '66', 'type': 'string', 'children': [], 'value': '"vert"'},{'id': '67', 'type': 'block', 'children': ['68', '80', '88', '100', '115']},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'all_data_df'},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'concat'},{'id': '75', 'type': 'argument_list', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'data_dfs'},{'id': '77', 'type': 'keyword_argument', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '79', 'type': 'integer', 'children': [], 'value': '0'},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'n_rows'},{'id': '83', 'type': 'subscript', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'all_data_df'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '87', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'logger'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'string', 'children': [], 'value': '"all_data_df.shape[0]: {}"'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'n_rows'},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'n_rows_cumulative'},{'id': '103', 'type': 'call', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'list_comprehension', 'children': ['107', '112']},{'id': '107', 'type': 'subscript', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '111', 'type': 'integer', 'children': [], 'value': '0'},{'id': '112', 'type': 'for_in_clause', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'data_dfs'},{'id': '115', 'type': 'assert_statement', 'children': ['116']},{'id': '116', 'type': 'comparison_operator', 'children': ['117', '118'], 'value': '=='},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'n_rows'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'n_rows_cumulative'},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'all_data_df_sorted'},{'id': '122', 'type': 'call', 'children': ['123', '133']},{'id': '123', 'type': 'attribute', 'children': ['124', '132']},{'id': '124', 'type': 'call', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'all_data_df'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'sort_index'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'keyword_argument', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '131', 'type': 'integer', 'children': [], 'value': '0'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'sort_index'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'keyword_argument', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '136', 'type': 'integer', 'children': [], 'value': '1'},{'id': '137', 'type': 'return_statement', 'children': ['138']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'all_data_df_sorted'} | def assemble_data(data_dfs, concat_direction):
if concat_direction == "horiz":
all_data_df = pd.concat(data_dfs, axis=1)
n_cols = all_data_df.shape[1]
logger.debug("all_data_df.shape[1]: {}".format(n_cols))
n_cols_cumulative = sum([df.shape[1] for df in data_dfs])
assert n_cols == n_cols_cumulative
elif concat_direction == "vert":
all_data_df = pd.concat(data_dfs, axis=0)
n_rows = all_data_df.shape[0]
logger.debug("all_data_df.shape[0]: {}".format(n_rows))
n_rows_cumulative = sum([df.shape[0] for df in data_dfs])
assert n_rows == n_rows_cumulative
all_data_df_sorted = all_data_df.sort_index(axis=0).sort_index(axis=1)
return all_data_df_sorted |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_rows_to_keep'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'gctoo'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'rid'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'row_bool'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'ridx'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'exclude_rid'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'block', 'children': ['18', '217', '234']},{'id': '18', 'type': 'if_statement', 'children': ['19', '22', '81', '130', '205']},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': 'is'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'rid'},{'id': '21', 'type': 'None', 'children': []},{'id': '22', 'type': 'block', 'children': ['23', '36', '52', '64']},{'id': '23', 'type': 'assert_statement', 'children': ['24', '30']},{'id': '24', 'type': 'comparison_operator', 'children': ['25', '29'], 'value': '=='},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'rid'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'string', 'children': [], 'value': '"rid must be a list. rid: {}"'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'rid'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'rows_to_keep'},{'id': '39', 'type': 'list_comprehension', 'children': ['40', '41', '48']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'gctoo_row'},{'id': '41', 'type': 'for_in_clause', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'gctoo_row'},{'id': '43', 'type': 'attribute', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'gctoo'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'data_df'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '48', 'type': 'if_clause', 'children': ['49']},{'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': 'in'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'gctoo_row'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'rid'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'num_missing_rids'},{'id': '55', 'type': 'binary_operator', 'children': ['56', '60'], 'value': '-'},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'rid'},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'rows_to_keep'},{'id': '64', 'type': 'if_statement', 'children': ['65', '68']},{'id': '65', 'type': 'comparison_operator', 'children': ['66', '67'], 'value': '!='},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'num_missing_rids'},{'id': '67', 'type': 'integer', 'children': [], 'value': '0'},{'id': '68', 'type': 'block', 'children': ['69']},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'string', 'children': [], 'value': '"{} rids were not found in the GCT."'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'num_missing_rids'},{'id': '81', 'type': 'elif_clause', 'children': ['82', '85']},{'id': '82', 'type': 'comparison_operator', 'children': ['83', '84'], 'value': 'is'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'row_bool'},{'id': '84', 'type': 'None', 'children': []},{'id': '85', 'type': 'block', 'children': ['86', '118']},{'id': '86', 'type': 'assert_statement', 'children': ['87', '99']},{'id': '87', 'type': 'comparison_operator', 'children': ['88', '92'], 'value': '=='},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'row_bool'},{'id': '92', 'type': 'subscript', 'children': ['93', '98']},{'id': '93', 'type': 'attribute', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'gctoo'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'data_df'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '98', 'type': 'integer', 'children': [], 'value': '0'},{'id': '99', 'type': '()', 'children': ['100']},{'id': '100', 'type': 'binary_operator', 'children': ['101', '102'], 'value': '+'},{'id': '101', 'type': 'string', 'children': [], 'value': '"row_bool must have length equal to gctoo.data_df.shape[0]. "'},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'string', 'children': [], 'value': '"len(row_bool): {}, gctoo.data_df.shape[0]: {}"'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '106', 'type': 'argument_list', 'children': ['107', '111']},{'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': 'row_bool'},{'id': '111', 'type': 'subscript', 'children': ['112', '117']},{'id': '112', 'type': 'attribute', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'gctoo'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'data_df'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '117', 'type': 'integer', 'children': [], 'value': '0'},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'rows_to_keep'},{'id': '121', 'type': 'attribute', 'children': ['122', '129']},{'id': '122', 'type': 'subscript', 'children': ['123', '128']},{'id': '123', 'type': 'attribute', 'children': ['124', '127']},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'gctoo'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'data_df'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'row_bool'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '130', 'type': 'elif_clause', 'children': ['131', '134']},{'id': '131', 'type': 'comparison_operator', 'children': ['132', '133'], 'value': 'is'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'ridx'},{'id': '133', 'type': 'None', 'children': []},{'id': '134', 'type': 'block', 'children': ['135', '161', '193']},{'id': '135', 'type': 'assert_statement', 'children': ['136', '144']},{'id': '136', 'type': 'comparison_operator', 'children': ['137', '143'], 'value': 'is'},{'id': '137', 'type': 'call', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'subscript', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'ridx'},{'id': '142', 'type': 'integer', 'children': [], 'value': '0'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '144', 'type': 'call', 'children': ['145', '151']},{'id': '145', 'type': 'attribute', 'children': ['146', '150']},{'id': '146', 'type': '()', 'children': ['147']},{'id': '147', 'type': 'binary_operator', 'children': ['148', '149'], 'value': '+'},{'id': '148', 'type': 'string', 'children': [], 'value': '"ridx must be a list of integers. ridx[0]: {}, "'},{'id': '149', 'type': 'string', 'children': [], 'value': '"type(ridx[0]): {}"'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '151', 'type': 'argument_list', 'children': ['152', '155']},{'id': '152', 'type': 'subscript', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'ridx'},{'id': '154', 'type': 'integer', 'children': [], 'value': '0'},{'id': '155', 'type': 'call', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'subscript', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'ridx'},{'id': '160', 'type': 'integer', 'children': [], 'value': '0'},{'id': '161', 'type': 'assert_statement', 'children': ['162', '174']},{'id': '162', 'type': 'comparison_operator', 'children': ['163', '167'], 'value': '<='},{'id': '163', 'type': 'call', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'ridx'},{'id': '167', 'type': 'subscript', 'children': ['168', '173']},{'id': '168', 'type': 'attribute', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'gctoo'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'data_df'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '173', 'type': 'integer', 'children': [], 'value': '0'},{'id': '174', 'type': 'call', 'children': ['175', '181']},{'id': '175', 'type': 'attribute', 'children': ['176', '180']},{'id': '176', 'type': '()', 'children': ['177']},{'id': '177', 'type': 'binary_operator', 'children': ['178', '179'], 'value': '+'},{'id': '178', 'type': 'string', 'children': [], 'value': '"ridx contains an integer larger than the number of rows in "'},{'id': '179', 'type': 'string', 'children': [], 'value': '"the GCToo. max(ridx): {}, gctoo.data_df.shape[0]: {}"'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '181', 'type': 'argument_list', 'children': ['182', '186']},{'id': '182', 'type': 'call', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'ridx'},{'id': '186', 'type': 'subscript', 'children': ['187', '192']},{'id': '187', 'type': 'attribute', 'children': ['188', '191']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'gctoo'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'data_df'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '192', 'type': 'integer', 'children': [], 'value': '0'},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'assignment', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'rows_to_keep'},{'id': '196', 'type': 'attribute', 'children': ['197', '204']},{'id': '197', 'type': 'subscript', 'children': ['198', '203']},{'id': '198', 'type': 'attribute', 'children': ['199', '202']},{'id': '199', 'type': 'attribute', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'gctoo'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'data_df'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'ridx'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '205', 'type': 'else_clause', 'children': ['206']},{'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': 'rows_to_keep'},{'id': '210', 'type': 'attribute', 'children': ['211', '216']},{'id': '211', 'type': 'attribute', 'children': ['212', '215']},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'gctoo'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'data_df'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '217', 'type': 'if_statement', 'children': ['218', '221']},{'id': '218', 'type': 'comparison_operator', 'children': ['219', '220'], 'value': 'is'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'exclude_rid'},{'id': '220', 'type': 'None', 'children': []},{'id': '221', 'type': 'block', 'children': ['222']},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'assignment', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'rows_to_keep'},{'id': '225', 'type': 'list_comprehension', 'children': ['226', '227', '230']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'row_to_keep'},{'id': '227', 'type': 'for_in_clause', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'row_to_keep'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'rows_to_keep'},{'id': '230', 'type': 'if_clause', 'children': ['231']},{'id': '231', 'type': 'comparison_operator', 'children': ['232', '233'], 'value': 'not'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'row_to_keep'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'exclude_rid'},{'id': '234', 'type': 'return_statement', 'children': ['235']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'rows_to_keep'} | def get_rows_to_keep(gctoo, rid=None, row_bool=None, ridx=None, exclude_rid=None):
if rid is not None:
assert type(rid) == list, "rid must be a list. rid: {}".format(rid)
rows_to_keep = [gctoo_row for gctoo_row in gctoo.data_df.index if gctoo_row in rid]
num_missing_rids = len(rid) - len(rows_to_keep)
if num_missing_rids != 0:
logger.info("{} rids were not found in the GCT.".format(num_missing_rids))
elif row_bool is not None:
assert len(row_bool) == gctoo.data_df.shape[0], (
"row_bool must have length equal to gctoo.data_df.shape[0]. " +
"len(row_bool): {}, gctoo.data_df.shape[0]: {}".format(
len(row_bool), gctoo.data_df.shape[0]))
rows_to_keep = gctoo.data_df.index[row_bool].values
elif ridx is not None:
assert type(ridx[0]) is int, (
"ridx must be a list of integers. ridx[0]: {}, " +
"type(ridx[0]): {}").format(ridx[0], type(ridx[0]))
assert max(ridx) <= gctoo.data_df.shape[0], (
"ridx contains an integer larger than the number of rows in " +
"the GCToo. max(ridx): {}, gctoo.data_df.shape[0]: {}").format(
max(ridx), gctoo.data_df.shape[0])
rows_to_keep = gctoo.data_df.index[ridx].values
else:
rows_to_keep = gctoo.data_df.index.values
if exclude_rid is not None:
rows_to_keep = [row_to_keep for row_to_keep in rows_to_keep if row_to_keep not in exclude_rid]
return rows_to_keep |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_cols_to_keep'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'gctoo'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'cid'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'col_bool'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'cidx'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'exclude_cid'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'block', 'children': ['18', '217', '234']},{'id': '18', 'type': 'if_statement', 'children': ['19', '22', '81', '130', '205']},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': 'is'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'cid'},{'id': '21', 'type': 'None', 'children': []},{'id': '22', 'type': 'block', 'children': ['23', '36', '52', '64']},{'id': '23', 'type': 'assert_statement', 'children': ['24', '30']},{'id': '24', 'type': 'comparison_operator', 'children': ['25', '29'], 'value': '=='},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'cid'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'string', 'children': [], 'value': '"cid must be a list. cid: {}"'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'cid'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'cols_to_keep'},{'id': '39', 'type': 'list_comprehension', 'children': ['40', '41', '48']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'gctoo_col'},{'id': '41', 'type': 'for_in_clause', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'gctoo_col'},{'id': '43', 'type': 'attribute', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'gctoo'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'data_df'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '48', 'type': 'if_clause', 'children': ['49']},{'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': 'in'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'gctoo_col'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'cid'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'num_missing_cids'},{'id': '55', 'type': 'binary_operator', 'children': ['56', '60'], 'value': '-'},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'cid'},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'cols_to_keep'},{'id': '64', 'type': 'if_statement', 'children': ['65', '68']},{'id': '65', 'type': 'comparison_operator', 'children': ['66', '67'], 'value': '!='},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'num_missing_cids'},{'id': '67', 'type': 'integer', 'children': [], 'value': '0'},{'id': '68', 'type': 'block', 'children': ['69']},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'string', 'children': [], 'value': '"{} cids were not found in the GCT."'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'num_missing_cids'},{'id': '81', 'type': 'elif_clause', 'children': ['82', '85']},{'id': '82', 'type': 'comparison_operator', 'children': ['83', '84'], 'value': 'is'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'col_bool'},{'id': '84', 'type': 'None', 'children': []},{'id': '85', 'type': 'block', 'children': ['86', '118']},{'id': '86', 'type': 'assert_statement', 'children': ['87', '99']},{'id': '87', 'type': 'comparison_operator', 'children': ['88', '92'], 'value': '=='},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'col_bool'},{'id': '92', 'type': 'subscript', 'children': ['93', '98']},{'id': '93', 'type': 'attribute', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'gctoo'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'data_df'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '98', 'type': 'integer', 'children': [], 'value': '1'},{'id': '99', 'type': '()', 'children': ['100']},{'id': '100', 'type': 'binary_operator', 'children': ['101', '102'], 'value': '+'},{'id': '101', 'type': 'string', 'children': [], 'value': '"col_bool must have length equal to gctoo.data_df.shape[1]. "'},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'string', 'children': [], 'value': '"len(col_bool): {}, gctoo.data_df.shape[1]: {}"'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '106', 'type': 'argument_list', 'children': ['107', '111']},{'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': 'col_bool'},{'id': '111', 'type': 'subscript', 'children': ['112', '117']},{'id': '112', 'type': 'attribute', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'gctoo'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'data_df'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '117', 'type': 'integer', 'children': [], 'value': '1'},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'cols_to_keep'},{'id': '121', 'type': 'attribute', 'children': ['122', '129']},{'id': '122', 'type': 'subscript', 'children': ['123', '128']},{'id': '123', 'type': 'attribute', 'children': ['124', '127']},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'gctoo'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'data_df'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'col_bool'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '130', 'type': 'elif_clause', 'children': ['131', '134']},{'id': '131', 'type': 'comparison_operator', 'children': ['132', '133'], 'value': 'is'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'cidx'},{'id': '133', 'type': 'None', 'children': []},{'id': '134', 'type': 'block', 'children': ['135', '161', '193']},{'id': '135', 'type': 'assert_statement', 'children': ['136', '144']},{'id': '136', 'type': 'comparison_operator', 'children': ['137', '143'], 'value': 'is'},{'id': '137', 'type': 'call', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'subscript', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'cidx'},{'id': '142', 'type': 'integer', 'children': [], 'value': '0'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '144', 'type': 'call', 'children': ['145', '151']},{'id': '145', 'type': 'attribute', 'children': ['146', '150']},{'id': '146', 'type': '()', 'children': ['147']},{'id': '147', 'type': 'binary_operator', 'children': ['148', '149'], 'value': '+'},{'id': '148', 'type': 'string', 'children': [], 'value': '"cidx must be a list of integers. cidx[0]: {}, "'},{'id': '149', 'type': 'string', 'children': [], 'value': '"type(cidx[0]): {}"'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '151', 'type': 'argument_list', 'children': ['152', '155']},{'id': '152', 'type': 'subscript', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'cidx'},{'id': '154', 'type': 'integer', 'children': [], 'value': '0'},{'id': '155', 'type': 'call', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'subscript', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'cidx'},{'id': '160', 'type': 'integer', 'children': [], 'value': '0'},{'id': '161', 'type': 'assert_statement', 'children': ['162', '174']},{'id': '162', 'type': 'comparison_operator', 'children': ['163', '167'], 'value': '<='},{'id': '163', 'type': 'call', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'cidx'},{'id': '167', 'type': 'subscript', 'children': ['168', '173']},{'id': '168', 'type': 'attribute', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'gctoo'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'data_df'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '173', 'type': 'integer', 'children': [], 'value': '1'},{'id': '174', 'type': 'call', 'children': ['175', '181']},{'id': '175', 'type': 'attribute', 'children': ['176', '180']},{'id': '176', 'type': '()', 'children': ['177']},{'id': '177', 'type': 'binary_operator', 'children': ['178', '179'], 'value': '+'},{'id': '178', 'type': 'string', 'children': [], 'value': '"cidx contains an integer larger than the number of columns in "'},{'id': '179', 'type': 'string', 'children': [], 'value': '"the GCToo. max(cidx): {}, gctoo.data_df.shape[1]: {}"'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '181', 'type': 'argument_list', 'children': ['182', '186']},{'id': '182', 'type': 'call', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'cidx'},{'id': '186', 'type': 'subscript', 'children': ['187', '192']},{'id': '187', 'type': 'attribute', 'children': ['188', '191']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'gctoo'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'data_df'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '192', 'type': 'integer', 'children': [], 'value': '1'},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'assignment', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'cols_to_keep'},{'id': '196', 'type': 'attribute', 'children': ['197', '204']},{'id': '197', 'type': 'subscript', 'children': ['198', '203']},{'id': '198', 'type': 'attribute', 'children': ['199', '202']},{'id': '199', 'type': 'attribute', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'gctoo'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'data_df'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'cidx'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '205', 'type': 'else_clause', 'children': ['206']},{'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': 'cols_to_keep'},{'id': '210', 'type': 'attribute', 'children': ['211', '216']},{'id': '211', 'type': 'attribute', 'children': ['212', '215']},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'gctoo'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'data_df'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '217', 'type': 'if_statement', 'children': ['218', '221']},{'id': '218', 'type': 'comparison_operator', 'children': ['219', '220'], 'value': 'is'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'exclude_cid'},{'id': '220', 'type': 'None', 'children': []},{'id': '221', 'type': 'block', 'children': ['222']},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'assignment', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'cols_to_keep'},{'id': '225', 'type': 'list_comprehension', 'children': ['226', '227', '230']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'col_to_keep'},{'id': '227', 'type': 'for_in_clause', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'col_to_keep'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'cols_to_keep'},{'id': '230', 'type': 'if_clause', 'children': ['231']},{'id': '231', 'type': 'comparison_operator', 'children': ['232', '233'], 'value': 'not'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'col_to_keep'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'exclude_cid'},{'id': '234', 'type': 'return_statement', 'children': ['235']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'cols_to_keep'} | def get_cols_to_keep(gctoo, cid=None, col_bool=None, cidx=None, exclude_cid=None):
if cid is not None:
assert type(cid) == list, "cid must be a list. cid: {}".format(cid)
cols_to_keep = [gctoo_col for gctoo_col in gctoo.data_df.columns if gctoo_col in cid]
num_missing_cids = len(cid) - len(cols_to_keep)
if num_missing_cids != 0:
logger.info("{} cids were not found in the GCT.".format(num_missing_cids))
elif col_bool is not None:
assert len(col_bool) == gctoo.data_df.shape[1], (
"col_bool must have length equal to gctoo.data_df.shape[1]. " +
"len(col_bool): {}, gctoo.data_df.shape[1]: {}".format(
len(col_bool), gctoo.data_df.shape[1]))
cols_to_keep = gctoo.data_df.columns[col_bool].values
elif cidx is not None:
assert type(cidx[0]) is int, (
"cidx must be a list of integers. cidx[0]: {}, " +
"type(cidx[0]): {}").format(cidx[0], type(cidx[0]))
assert max(cidx) <= gctoo.data_df.shape[1], (
"cidx contains an integer larger than the number of columns in " +
"the GCToo. max(cidx): {}, gctoo.data_df.shape[1]: {}").format(
max(cidx), gctoo.data_df.shape[1])
cols_to_keep = gctoo.data_df.columns[cidx].values
else:
cols_to_keep = gctoo.data_df.columns.values
if exclude_cid is not None:
cols_to_keep = [col_to_keep for col_to_keep in cols_to_keep if col_to_keep not in exclude_cid]
return cols_to_keep |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'finish'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'queue_name'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'task_id'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'owner'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '9', 'type': 'False', 'children': []},{'id': '10', 'type': 'block', 'children': ['11', '20', '49', '71', '83', '92', '104']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': '_get_task_with_policy'},{'id': '16', 'type': 'argument_list', 'children': ['17', '18', '19']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'queue_name'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'task_id'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'owner'},{'id': '20', 'type': 'if_statement', 'children': ['21', '29']},{'id': '21', 'type': 'not_operator', 'children': ['22']},{'id': '22', 'type': 'comparison_operator', 'children': ['23', '26'], 'value': '=='},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'WorkQueue'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'LIVE'},{'id': '29', 'type': 'block', 'children': ['30', '47']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '35', 'type': 'argument_list', 'children': ['36', '39', '42', '43', '44']},{'id': '36', 'type': 'concatenated_string', 'children': ['37', '38']},{'id': '37', 'type': 'string', 'children': [], 'value': "'Finishing already dead task. queue=%r, task_id=%r, '"},{'id': '38', 'type': 'string', 'children': [], 'value': "'owner=%r, status=%r'"},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'queue_name'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'task_id'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'owner'},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '47', 'type': 'return_statement', 'children': ['48']},{'id': '48', 'type': 'False', 'children': []},{'id': '49', 'type': 'if_statement', 'children': ['50', '52', '61']},{'id': '50', 'type': 'not_operator', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '52', 'type': 'block', 'children': ['53']},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'WorkQueue'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'DONE'},{'id': '61', 'type': 'else_clause', 'children': ['62']},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'WorkQueue'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'ERROR'},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'finished'},{'id': '76', 'type': 'call', 'children': ['77', '82']},{'id': '77', 'type': 'attribute', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'utcnow'},{'id': '82', 'type': 'argument_list', 'children': []},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'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': 'db'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'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': 'signals'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'task_updated'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '99', 'type': 'argument_list', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '101', 'type': 'keyword_argument', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '104', 'type': 'return_statement', 'children': ['105']},{'id': '105', 'type': 'True', 'children': []} | def finish(queue_name, task_id, owner, error=False):
task = _get_task_with_policy(queue_name, task_id, owner)
if not task.status == WorkQueue.LIVE:
logging.warning('Finishing already dead task. queue=%r, task_id=%r, '
'owner=%r, status=%r',
task.queue_name, task_id, owner, task.status)
return False
if not error:
task.status = WorkQueue.DONE
else:
task.status = WorkQueue.ERROR
task.finished = datetime.datetime.utcnow()
db.session.add(task)
signals.task_updated.send(app, task=task)
return True |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'send_ready_for_review'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'build_id'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'release_name'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'release_number'},{'id': '7', 'type': 'block', 'children': ['8', '21', '40', '49', '63', '86', '98', '117', '121', '152', '175', '185', '191', '210']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'build'},{'id': '11', 'type': 'call', 'children': ['12', '19']},{'id': '12', 'type': 'attribute', 'children': ['13', '18']},{'id': '13', 'type': 'attribute', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'Build'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'build_id'},{'id': '21', 'type': 'if_statement', 'children': ['22', '26']},{'id': '22', 'type': 'not_operator', 'children': ['23']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'build'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'send_email'},{'id': '26', 'type': 'block', 'children': ['27', '39']},{'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': 'logging'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '32', 'type': 'argument_list', 'children': ['33', '36']},{'id': '33', 'type': 'concatenated_string', 'children': ['34', '35']},{'id': '34', 'type': 'string', 'children': [], 'value': "'Not sending ready for review email because build does not have '"},{'id': '35', 'type': 'string', 'children': [], 'value': "'email enabled. build_id=%r'"},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'build'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '39', 'type': 'return_statement', 'children': []},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'ops'},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'operations'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'BuildOps'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'build_id'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '56']},{'id': '51', 'type': 'pattern_list', 'children': ['52', '53', '54', '55']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'release'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'run_list'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'stats_dict'},{'id': '55', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'ops'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'get_release'},{'id': '60', 'type': 'argument_list', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'release_name'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'release_number'},{'id': '63', 'type': 'if_statement', 'children': ['64', '66']},{'id': '64', 'type': 'not_operator', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'run_list'},{'id': '66', 'type': 'block', 'children': ['67', '85']},{'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', '76', '79', '82']},{'id': '73', 'type': 'concatenated_string', 'children': ['74', '75']},{'id': '74', 'type': 'string', 'children': [], 'value': "'Not sending ready for review email because there are '"},{'id': '75', 'type': 'string', 'children': [], 'value': "' no runs. build_id=%r, release_name=%r, release_number=%d'"},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'build'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'release'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'release'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '85', 'type': 'return_statement', 'children': []},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '89', 'type': 'binary_operator', 'children': ['90', '91'], 'value': '%'},{'id': '90', 'type': 'string', 'children': [], 'value': "'%s: %s - Ready for review'"},{'id': '91', 'type': 'tuple', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'build'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'release'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'email_body'},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'render_template'},{'id': '103', 'type': 'argument_list', 'children': ['104', '105', '108', '111', '114']},{'id': '104', 'type': 'string', 'children': [], 'value': "'email_ready_for_review.html'"},{'id': '105', 'type': 'keyword_argument', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'build'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'build'},{'id': '108', 'type': 'keyword_argument', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'release'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'release'},{'id': '111', 'type': 'keyword_argument', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'run_list'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'run_list'},{'id': '114', 'type': 'keyword_argument', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'stats_dict'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'stats_dict'},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'recipients'},{'id': '120', 'type': 'list', 'children': [], 'value': '[]'},{'id': '121', 'type': 'if_statement', 'children': ['122', '125', '135']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'build'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'email_alias'},{'id': '125', 'type': 'block', 'children': ['126']},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'call', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'recipients'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'build'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'email_alias'},{'id': '135', 'type': 'else_clause', 'children': ['136']},{'id': '136', 'type': 'block', 'children': ['137']},{'id': '137', 'type': 'for_statement', 'children': ['138', '139', '142']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'build'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'owners'},{'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': 'recipients'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'email_address'},{'id': '152', 'type': 'if_statement', 'children': ['153', '155']},{'id': '153', 'type': 'not_operator', 'children': ['154']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'recipients'},{'id': '155', 'type': 'block', 'children': ['156', '174']},{'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', '165', '168', '171']},{'id': '162', 'type': 'concatenated_string', 'children': ['163', '164']},{'id': '163', 'type': 'string', 'children': [], 'value': "'Not sending ready for review email because there are no '"},{'id': '164', 'type': 'string', 'children': [], 'value': "'recipients. build_id=%r, release_name=%r, release_number=%d'"},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'build'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'release'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'release'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '174', 'type': 'return_statement', 'children': []},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'assignment', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '178', 'type': 'call', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'Message'},{'id': '180', 'type': 'argument_list', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '182', 'type': 'keyword_argument', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'recipients'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'recipients'},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'assignment', 'children': ['187', '190']},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'html'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'email_body'},{'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': 'logging'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '196', 'type': 'argument_list', 'children': ['197', '200', '203', '206', '209']},{'id': '197', 'type': 'concatenated_string', 'children': ['198', '199']},{'id': '198', 'type': 'string', 'children': [], 'value': "'Sending ready for review email for build_id=%r, '"},{'id': '199', 'type': 'string', 'children': [], 'value': "'release_name=%r, release_number=%d to %r'"},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'build'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'release'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'release'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'recipients'},{'id': '210', 'type': 'return_statement', 'children': ['211']},{'id': '211', 'type': 'call', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'render_or_send'},{'id': '213', 'type': 'argument_list', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'send_ready_for_review'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'message'} | def send_ready_for_review(build_id, release_name, release_number):
build = models.Build.query.get(build_id)
if not build.send_email:
logging.debug(
'Not sending ready for review email because build does not have '
'email enabled. build_id=%r', build.id)
return
ops = operations.BuildOps(build_id)
release, run_list, stats_dict, _ = ops.get_release(
release_name, release_number)
if not run_list:
logging.debug(
'Not sending ready for review email because there are '
' no runs. build_id=%r, release_name=%r, release_number=%d',
build.id, release.name, release.number)
return
title = '%s: %s - Ready for review' % (build.name, release.name)
email_body = render_template(
'email_ready_for_review.html',
build=build,
release=release,
run_list=run_list,
stats_dict=stats_dict)
recipients = []
if build.email_alias:
recipients.append(build.email_alias)
else:
for user in build.owners:
recipients.append(user.email_address)
if not recipients:
logging.debug(
'Not sending ready for review email because there are no '
'recipients. build_id=%r, release_name=%r, release_number=%d',
build.id, release.name, release.number)
return
message = Message(title, recipients=recipients)
message.html = email_body
logging.info('Sending ready for review email for build_id=%r, '
'release_name=%r, release_number=%d to %r',
build.id, release.name, release.number, recipients)
return render_or_send(send_ready_for_review, message) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'claim_invitations'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '5', 'type': 'block', 'children': ['6', '20', '33']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'invitation_user_id'},{'id': '9', 'type': 'binary_operator', 'children': ['10', '11'], 'value': '%'},{'id': '10', 'type': 'string', 'children': [], 'value': "'%s:%s'"},{'id': '11', 'type': 'tuple', 'children': ['12', '17']},{'id': '12', 'type': 'attribute', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'User'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'EMAIL_INVITATION'},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'email_address'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'invitation_user'},{'id': '23', 'type': 'call', 'children': ['24', '31']},{'id': '24', 'type': 'attribute', 'children': ['25', '30']},{'id': '25', 'type': 'attribute', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'User'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'invitation_user_id'},{'id': '33', 'type': 'if_statement', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'invitation_user'},{'id': '35', 'type': 'block', 'children': ['36', '45', '50', '59', '72', '149', '158', '166']},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'invited_build_list'},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'invitation_user'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'builds'},{'id': '45', 'type': 'if_statement', 'children': ['46', '48']},{'id': '46', 'type': 'not_operator', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'invited_build_list'},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'return_statement', 'children': []},{'id': '50', 'type': 'expression_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': 'db'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '64', 'type': 'argument_list', 'children': ['65', '66', '70', '71']},{'id': '65', 'type': 'string', 'children': [], 'value': "'Found %d build admin invitations for id=%r, user=%r'"},{'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': 'invited_build_list'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'invitation_user_id'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '72', 'type': 'for_statement', 'children': ['73', '74', '75']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'build'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'invited_build_list'},{'id': '75', 'type': 'block', 'children': ['76', '85', '140']},{'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': 'build'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'owners'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'invitation_user'},{'id': '85', 'type': 'if_statement', 'children': ['86', '95', '123']},{'id': '86', 'type': 'not_operator', 'children': ['87']},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'build'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'is_owned_by'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '95', 'type': 'block', 'children': ['96', '105', '115']},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'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': 'build'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'owners'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'call', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '110', 'type': 'argument_list', 'children': ['111', '112']},{'id': '111', 'type': 'string', 'children': [], 'value': "'Claiming invitation for build_id=%r'"},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'build'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'call', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'save_admin_log'},{'id': '118', 'type': 'argument_list', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'build'},{'id': '120', 'type': 'keyword_argument', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'invite_accepted'},{'id': '122', 'type': 'True', 'children': []},{'id': '123', 'type': 'else_clause', 'children': ['124']},{'id': '124', 'type': 'block', 'children': ['125']},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'call', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '130', 'type': 'argument_list', 'children': ['131', '134', '137']},{'id': '131', 'type': 'concatenated_string', 'children': ['132', '133']},{'id': '132', 'type': 'string', 'children': [], 'value': "'User already owner of build. '"},{'id': '133', 'type': 'string', 'children': [], 'value': "'id=%r, build_id=%r'"},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'build'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'call', 'children': ['142', '147']},{'id': '142', 'type': 'attribute', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'build'},{'id': '149', 'type': 'expression_statement', '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': 'db'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'delete'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'invitation_user'},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'call', 'children': ['160', '165']},{'id': '160', 'type': 'attribute', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'commit'},{'id': '165', 'type': 'argument_list', 'children': []},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'call', 'children': ['168', '173']},{'id': '168', 'type': 'attribute', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '173', 'type': 'argument_list', 'children': ['174']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'current_user'} | def claim_invitations(user):
invitation_user_id = '%s:%s' % (
models.User.EMAIL_INVITATION, user.email_address)
invitation_user = models.User.query.get(invitation_user_id)
if invitation_user:
invited_build_list = list(invitation_user.builds)
if not invited_build_list:
return
db.session.add(user)
logging.debug('Found %d build admin invitations for id=%r, user=%r',
len(invited_build_list), invitation_user_id, user)
for build in invited_build_list:
build.owners.remove(invitation_user)
if not build.is_owned_by(user.id):
build.owners.append(user)
logging.debug('Claiming invitation for build_id=%r', build.id)
save_admin_log(build, invite_accepted=True)
else:
logging.debug('User already owner of build. '
'id=%r, build_id=%r', user.id, build.id)
db.session.add(build)
db.session.delete(invitation_user)
db.session.commit()
db.session.add(current_user) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_check_release_done_processing'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'release'},{'id': '5', 'type': 'block', 'children': ['6', '37', '54', '95', '113', '119', '125', '131', '150', '160', '169']},{'id': '6', 'type': 'if_statement', 'children': ['7', '16']},{'id': '7', 'type': 'comparison_operator', 'children': ['8', '11'], 'value': '!='},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'release'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '11', 'type': 'attribute', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'Release'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'PROCESSING'},{'id': '16', 'type': 'block', 'children': ['17', '35']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '22', 'type': 'argument_list', 'children': ['23', '26', '29', '32']},{'id': '23', 'type': 'concatenated_string', 'children': ['24', '25']},{'id': '24', 'type': 'string', 'children': [], 'value': "'Release not in processing state yet: build_id=%r, '"},{'id': '25', 'type': 'string', 'children': [], 'value': "'name=%r, number=%d'"},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'release'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'build_id'},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'release'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'release'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '35', 'type': 'return_statement', 'children': ['36']},{'id': '36', 'type': 'False', 'children': []},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '40', 'type': 'call', 'children': ['41', '48']},{'id': '41', 'type': 'attribute', 'children': ['42', '47']},{'id': '42', 'type': 'attribute', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'Run'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'filter_by'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'release_id'},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'release'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '54', 'type': 'for_statement', 'children': ['55', '56', '57']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'run'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '57', 'type': 'block', 'children': ['58', '71', '83']},{'id': '58', 'type': 'if_statement', 'children': ['59', '68']},{'id': '59', 'type': 'comparison_operator', 'children': ['60', '63'], 'value': '=='},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'run'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '63', 'type': 'attribute', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'Run'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'NEEDS_DIFF'},{'id': '68', 'type': 'block', 'children': ['69']},{'id': '69', 'type': 'return_statement', 'children': ['70']},{'id': '70', 'type': 'False', 'children': []},{'id': '71', 'type': 'if_statement', 'children': ['72', '80']},{'id': '72', 'type': 'boolean_operator', 'children': ['73', '76'], 'value': 'and'},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'run'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'ref_config'},{'id': '76', 'type': 'not_operator', 'children': ['77']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'run'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'ref_image'},{'id': '80', 'type': 'block', 'children': ['81']},{'id': '81', 'type': 'return_statement', 'children': ['82']},{'id': '82', 'type': 'False', 'children': []},{'id': '83', 'type': 'if_statement', 'children': ['84', '92']},{'id': '84', 'type': 'boolean_operator', 'children': ['85', '88'], 'value': 'and'},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'run'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '88', 'type': 'not_operator', 'children': ['89']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'run'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '92', 'type': 'block', 'children': ['93']},{'id': '93', 'type': 'return_statement', 'children': ['94']},{'id': '94', 'type': 'False', 'children': []},{'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': 'logging'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '100', 'type': 'argument_list', 'children': ['101', '104', '107', '110']},{'id': '101', 'type': 'concatenated_string', 'children': ['102', '103']},{'id': '102', 'type': 'string', 'children': [], 'value': "'Release done processing, now reviewing: build_id=%r, '"},{'id': '103', 'type': 'string', 'children': [], 'value': "'name=%r, number=%d'"},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'release'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'build_id'},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'release'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'release'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'build_id'},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'release'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'build_id'},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'release_name'},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'release'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'release_number'},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'release'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '131', 'type': 'decorated_definition', 'children': ['132', '136']},{'id': '132', 'type': 'decorator', 'children': ['133']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'after_this_request'},{'id': '136', 'type': 'function_definition', 'children': ['137', '138', '140']},{'id': '137', 'type': 'function_name', 'children': [], 'value': 'send_notification_email'},{'id': '138', 'type': 'parameters', 'children': ['139']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'response'},{'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': 'emails'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'send_ready_for_review'},{'id': '146', 'type': 'argument_list', 'children': ['147', '148', '149']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'build_id'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'release_name'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'release_number'},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'release'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '155', 'type': 'attribute', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'Release'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'REVIEWING'},{'id': '160', 'type': 'expression_statement', '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': 'db'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '167', 'type': 'argument_list', 'children': ['168']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'release'},{'id': '169', 'type': 'return_statement', 'children': ['170']},{'id': '170', 'type': 'True', 'children': []} | def _check_release_done_processing(release):
if release.status != models.Release.PROCESSING:
logging.info('Release not in processing state yet: build_id=%r, '
'name=%r, number=%d', release.build_id, release.name,
release.number)
return False
query = models.Run.query.filter_by(release_id=release.id)
for run in query:
if run.status == models.Run.NEEDS_DIFF:
return False
if run.ref_config and not run.ref_image:
return False
if run.config and not run.image:
return False
logging.info('Release done processing, now reviewing: build_id=%r, '
'name=%r, number=%d', release.build_id, release.name,
release.number)
build_id = release.build_id
release_name = release.name
release_number = release.number
@utils.after_this_request
def send_notification_email(response):
emails.send_ready_for_review(build_id, release_name, release_number)
release.status = models.Release.REVIEWING
db.session.add(release)
return True |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'download'},{'id': '3', 'type': 'parameters', 'children': []},{'id': '4', 'type': 'block', 'children': ['5', '37', '51', '68', '81', '98', '112', '129', '146', '164', '187', '202', '229']},{'id': '5', 'type': 'try_statement', 'children': ['6', '16']},{'id': '6', 'type': 'block', 'children': ['7']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'build'},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'auth'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'can_user_access_build'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'string', 'children': [], 'value': "'build_id'"},{'id': '16', 'type': 'except_clause', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'HTTPException'},{'id': '18', 'type': 'block', 'children': ['19', '26']},{'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': 'logging'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'string', 'children': [], 'value': "'User access to artifact failed. Trying API key.'"},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '31']},{'id': '28', 'type': 'pattern_list', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'build'},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'auth'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'can_api_key_access_build'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'string', 'children': [], 'value': "'build_id'"},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'sha1sum'},{'id': '40', 'type': 'call', 'children': ['41', '46']},{'id': '41', 'type': 'attribute', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '46', 'type': 'argument_list', 'children': ['47', '48']},{'id': '47', 'type': 'string', 'children': [], 'value': "'sha1sum'"},{'id': '48', 'type': 'keyword_argument', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '51', 'type': 'if_statement', 'children': ['52', '54']},{'id': '52', 'type': 'not_operator', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'sha1sum'},{'id': '54', 'type': 'block', 'children': ['55', '63']},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '60', 'type': 'argument_list', 'children': ['61', '62']},{'id': '61', 'type': 'string', 'children': [], 'value': "'Artifact sha1sum=%r not supplied'"},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'sha1sum'},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'abort'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'integer', 'children': [], 'value': '404'},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'artifact'},{'id': '71', 'type': 'call', 'children': ['72', '79']},{'id': '72', 'type': 'attribute', 'children': ['73', '78']},{'id': '73', 'type': 'attribute', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'Artifact'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'sha1sum'},{'id': '81', 'type': 'if_statement', 'children': ['82', '84']},{'id': '82', 'type': 'not_operator', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'artifact'},{'id': '84', 'type': 'block', 'children': ['85', '93']},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '90', 'type': 'argument_list', 'children': ['91', '92']},{'id': '91', 'type': 'string', 'children': [], 'value': "'Artifact sha1sum=%r does not exist'"},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'sha1sum'},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'call', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'abort'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'integer', 'children': [], 'value': '404'},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'build_id'},{'id': '101', 'type': 'call', 'children': ['102', '107']},{'id': '102', 'type': 'attribute', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '107', 'type': 'argument_list', 'children': ['108', '109']},{'id': '108', 'type': 'string', 'children': [], 'value': "'build_id'"},{'id': '109', 'type': 'keyword_argument', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '112', 'type': 'if_statement', 'children': ['113', '115']},{'id': '113', 'type': 'not_operator', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'build_id'},{'id': '115', 'type': 'block', 'children': ['116', '124']},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'call', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '121', 'type': 'argument_list', 'children': ['122', '123']},{'id': '122', 'type': 'string', 'children': [], 'value': "'build_id missing for artifact sha1sum=%r'"},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'sha1sum'},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'call', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'abort'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'integer', 'children': [], 'value': '404'},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'assignment', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'is_owned'},{'id': '132', 'type': 'call', 'children': ['133', '145']},{'id': '133', 'type': 'attribute', 'children': ['134', '144']},{'id': '134', 'type': 'call', 'children': ['135', '140']},{'id': '135', 'type': 'attribute', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'artifact'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'owners'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'filter_by'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'keyword_argument', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'build_id'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'first'},{'id': '145', 'type': 'argument_list', 'children': []},{'id': '146', 'type': 'if_statement', 'children': ['147', '149']},{'id': '147', 'type': 'not_operator', 'children': ['148']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'is_owned'},{'id': '149', 'type': 'block', 'children': ['150', '159']},{'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': 'logging'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '155', 'type': 'argument_list', 'children': ['156', '157', '158']},{'id': '156', 'type': 'string', 'children': [], 'value': "'build_id=%r not owner of artifact sha1sum=%r'"},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'build_id'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'sha1sum'},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'call', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'abort'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'integer', 'children': [], 'value': '403'},{'id': '164', 'type': 'decorated_definition', 'children': ['165', '169']},{'id': '165', 'type': 'decorator', 'children': ['166']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'after_this_request'},{'id': '169', 'type': 'function_definition', 'children': ['170', '171', '173']},{'id': '170', 'type': 'function_name', 'children': [], 'value': 'no_session'},{'id': '171', 'type': 'parameters', 'children': ['172']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '173', 'type': 'block', 'children': ['174']},{'id': '174', 'type': 'if_statement', 'children': ['175', '180']},{'id': '175', 'type': 'comparison_operator', 'children': ['176', '177'], 'value': 'in'},{'id': '176', 'type': 'string', 'children': [], 'value': "'Set-Cookie'"},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '180', 'type': 'block', 'children': ['181']},{'id': '181', 'type': 'delete_statement', 'children': ['182']},{'id': '182', 'type': 'subscript', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '186', 'type': 'string', 'children': [], 'value': "'Set-Cookie'"},{'id': '187', 'type': 'if_statement', 'children': ['188', '194']},{'id': '188', 'type': 'not_operator', 'children': ['189']},{'id': '189', 'type': 'call', 'children': ['190', '193']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'is_production'},{'id': '193', 'type': 'argument_list', 'children': []},{'id': '194', 'type': 'block', 'children': ['195']},{'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': 'time'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'sleep'},{'id': '200', 'type': 'argument_list', 'children': ['201']},{'id': '201', 'type': 'float', 'children': [], 'value': '1.5'},{'id': '202', 'type': 'if_statement', 'children': ['203', '215']},{'id': '203', 'type': 'boolean_operator', 'children': ['204', '207'], 'value': 'and'},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'if_none_match'},{'id': '207', 'type': 'call', 'children': ['208', '213']},{'id': '208', 'type': 'attribute', 'children': ['209', '212']},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'if_none_match'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'contains'},{'id': '213', 'type': 'argument_list', 'children': ['214']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'sha1sum'},{'id': '215', 'type': 'block', 'children': ['216', '227']},{'id': '216', 'type': 'expression_statement', 'children': ['217']},{'id': '217', 'type': 'assignment', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '219', 'type': 'call', 'children': ['220', '223']},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'flask'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'Response'},{'id': '223', 'type': 'argument_list', 'children': ['224']},{'id': '224', 'type': 'keyword_argument', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '226', 'type': 'integer', 'children': [], 'value': '304'},{'id': '227', 'type': 'return_statement', 'children': ['228']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '229', 'type': 'return_statement', 'children': ['230']},{'id': '230', 'type': 'call', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': '_get_artifact_response'},{'id': '232', 'type': 'argument_list', 'children': ['233']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'artifact'} | def download():
try:
build = auth.can_user_access_build('build_id')
except HTTPException:
logging.debug('User access to artifact failed. Trying API key.')
_, build = auth.can_api_key_access_build('build_id')
sha1sum = request.args.get('sha1sum', type=str)
if not sha1sum:
logging.debug('Artifact sha1sum=%r not supplied', sha1sum)
abort(404)
artifact = models.Artifact.query.get(sha1sum)
if not artifact:
logging.debug('Artifact sha1sum=%r does not exist', sha1sum)
abort(404)
build_id = request.args.get('build_id', type=int)
if not build_id:
logging.debug('build_id missing for artifact sha1sum=%r', sha1sum)
abort(404)
is_owned = artifact.owners.filter_by(id=build_id).first()
if not is_owned:
logging.debug('build_id=%r not owner of artifact sha1sum=%r',
build_id, sha1sum)
abort(403)
@utils.after_this_request
def no_session(response):
if 'Set-Cookie' in response.headers:
del response.headers['Set-Cookie']
if not utils.is_production():
time.sleep(1.5)
if request.if_none_match and request.if_none_match.contains(sha1sum):
response = flask.Response(status=304)
return response
return _get_artifact_response(artifact) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_run'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'run'},{'id': '5', 'type': 'block', 'children': ['6', '23']},{'id': '6', 'type': 'if_statement', 'children': ['7', '16']},{'id': '7', 'type': 'comparison_operator', 'children': ['8', '11'], 'value': 'in'},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'run'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '11', 'type': 'attribute', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'Run'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'DIFF_NEEDED_STATES'},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'return_statement', 'children': ['18']},{'id': '18', 'type': 'tuple', 'children': ['19', '20']},{'id': '19', 'type': 'integer', 'children': [], 'value': '0'},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'run'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '23', 'type': 'return_statement', 'children': ['24']},{'id': '24', 'type': 'tuple', 'children': ['25', '26']},{'id': '25', 'type': 'integer', 'children': [], 'value': '1'},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'run'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'name'} | def sort_run(run):
if run.status in models.Run.DIFF_NEEDED_STATES:
return (0, run.name)
return (1, run.name) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'required_properties'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'additional_properties'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'ignore_optional_property_errors'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '45', '49', '138', '153']},{'id': '15', 'type': 'if_statement', 'children': ['16', '23']},{'id': '16', 'type': 'not_operator', 'children': ['17']},{'id': '17', 'type': '()', 'children': ['18']},{'id': '18', 'type': 'comparison_operator', 'children': ['19', '20', '21', '22'], 'value': 'is'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'required_properties'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'additional_properties'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'ignore_optional_property_errors'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'with_statement', 'children': ['25', '39']},{'id': '25', 'type': 'with_clause', 'children': ['26']},{'id': '26', 'type': 'with_item', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'parsing'},{'id': '29', 'type': 'argument_list', 'children': ['30', '33', '36']},{'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'required_properties'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'required_properties'},{'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'additional_properties'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'additional_properties'},{'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'ignore_optional_property_errors'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'ignore_optional_property_errors'},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'return_statement', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'parse'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'validator'},{'id': '48', 'type': 'None', 'children': []},{'id': '49', 'type': 'if_statement', 'children': ['50', '55', '60', '80']},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '52', 'type': 'argument_list', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'Validator'},{'id': '55', 'type': 'block', 'children': ['56']},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'validator'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '60', 'type': 'elif_clause', 'children': ['61', '73']},{'id': '61', 'type': 'boolean_operator', 'children': ['62', '68'], 'value': 'and'},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'inspect'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'isclass'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'issubclass'},{'id': '70', 'type': 'argument_list', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'Validator'},{'id': '73', 'type': 'block', 'children': ['74']},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'validator'},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '79', 'type': 'argument_list', 'children': []},{'id': '80', 'type': 'else_clause', 'children': ['81']},{'id': '81', 'type': 'block', 'children': ['82']},{'id': '82', 'type': 'try_statement', 'children': ['83', '90', '112']},{'id': '83', 'type': 'block', 'children': ['84']},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'validator'},{'id': '87', 'type': 'subscript', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': '_NAMED_VALIDATORS'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '90', 'type': 'except_clause', 'children': ['91', '94']},{'id': '91', 'type': 'tuple', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '94', 'type': 'block', 'children': ['95']},{'id': '95', 'type': 'for_statement', 'children': ['96', '97', '98']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'factory'},{'id': '97', 'type': 'identifier', 'children': [], 'value': '_VALIDATOR_FACTORIES'},{'id': '98', 'type': 'block', 'children': ['99', '106']},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'validator'},{'id': '102', 'type': 'call', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'factory'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '106', 'type': 'if_statement', 'children': ['107', '110']},{'id': '107', 'type': 'comparison_operator', 'children': ['108', '109'], 'value': 'is'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'validator'},{'id': '109', 'type': 'None', 'children': []},{'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']},{'id': '114', 'type': 'if_statement', 'children': ['115', '127']},{'id': '115', 'type': 'boolean_operator', 'children': ['116', '122'], 'value': 'and'},{'id': '116', 'type': 'call', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'inspect'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'isclass'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'validator'},{'id': '122', 'type': 'call', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'issubclass'},{'id': '124', 'type': 'argument_list', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'validator'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'Validator'},{'id': '127', 'type': 'block', 'children': ['128']},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'assignment', 'children': ['130', '133']},{'id': '130', 'type': 'subscript', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': '_NAMED_VALIDATORS'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '133', 'type': 'assignment', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'validator'},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'validator'},{'id': '137', 'type': 'argument_list', 'children': []},{'id': '138', 'type': 'if_statement', 'children': ['139', '145']},{'id': '139', 'type': 'not_operator', 'children': ['140']},{'id': '140', 'type': 'call', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '142', 'type': 'argument_list', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'validator'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'Validator'},{'id': '145', 'type': 'block', 'children': ['146']},{'id': '146', 'type': 'raise_statement', 'children': ['147']},{'id': '147', 'type': 'call', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'SchemaError'},{'id': '149', 'type': 'argument_list', 'children': ['150']},{'id': '150', 'type': 'binary_operator', 'children': ['151', '152'], 'value': '%'},{'id': '151', 'type': 'string', 'children': [], 'value': '"%r cannot be parsed as a Validator"'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '153', 'type': 'return_statement', 'children': ['154']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'validator'} | def parse(obj, required_properties=None, additional_properties=None,
ignore_optional_property_errors=None):
if not (required_properties is
additional_properties is
ignore_optional_property_errors is None):
with parsing(required_properties=required_properties,
additional_properties=additional_properties,
ignore_optional_property_errors=ignore_optional_property_errors):
return parse(obj)
validator = None
if isinstance(obj, Validator):
validator = obj
elif inspect.isclass(obj) and issubclass(obj, Validator):
validator = obj()
else:
try:
validator = _NAMED_VALIDATORS[obj]
except (KeyError, TypeError):
for factory in _VALIDATOR_FACTORIES:
validator = factory(obj)
if validator is not None:
break
else:
if inspect.isclass(validator) and issubclass(validator, Validator):
_NAMED_VALIDATORS[obj] = validator = validator()
if not isinstance(validator, Validator):
raise SchemaError("%r cannot be parsed as a Validator" % obj)
return validator |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'adapts'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'dictionary_splat_pattern', 'children': ['5']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'schemas'},{'id': '6', 'type': 'block', 'children': ['7', '16', '143']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'validate'},{'id': '10', 'type': 'attribute', 'children': ['11', '15']},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'parse'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'schemas'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'validate'},{'id': '16', 'type': 'decorated_definition', 'children': ['17', '19']},{'id': '17', 'type': 'decorator', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'decorator'},{'id': '19', 'type': 'function_definition', 'children': ['20', '21', '27']},{'id': '20', 'type': 'function_name', 'children': [], 'value': 'adapting'},{'id': '21', 'type': 'parameters', 'children': ['22', '23', '25']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '23', 'type': 'list_splat_pattern', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '25', 'type': 'dictionary_splat_pattern', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '27', 'type': 'block', 'children': ['28', '47', '56', '72', '84', '96', '116', '128', '135']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'adapted'},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'validate'},{'id': '33', 'type': 'argument_list', 'children': ['34', '44']},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'inspect'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'getcallargs'},{'id': '38', 'type': 'argument_list', 'children': ['39', '40', '42']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '40', 'type': 'list_splat', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '42', 'type': 'dictionary_splat', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'adapt'},{'id': '46', 'type': 'True', 'children': []},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'argspec'},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'inspect'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'getargspec'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '56', 'type': 'if_statement', 'children': ['57', '65']},{'id': '57', 'type': 'comparison_operator', 'children': ['58', '61', '64'], 'value': 'is'},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'argspec'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'varargs'},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'argspec'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '64', 'type': 'None', 'children': []},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'return_statement', 'children': ['67']},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'dictionary_splat', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'adapted'},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'adapted_varargs'},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'adapted'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '79', 'type': 'argument_list', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'argspec'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'varargs'},{'id': '83', 'type': 'tuple', 'children': []},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'adapted_keywords'},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'adapted'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '91', 'type': 'argument_list', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'argspec'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '95', 'type': 'dictionary', 'children': []},{'id': '96', 'type': 'if_statement', 'children': ['97', '99']},{'id': '97', 'type': 'not_operator', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'adapted_varargs'},{'id': '99', 'type': 'block', 'children': ['100', '110']},{'id': '100', 'type': 'if_statement', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'adapted_keywords'},{'id': '102', 'type': 'block', 'children': ['103']},{'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': 'adapted'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'adapted_keywords'},{'id': '110', 'type': 'return_statement', 'children': ['111']},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'dictionary_splat', 'children': ['115']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'adapted'},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'adapted_posargs'},{'id': '119', 'type': 'list_comprehension', 'children': ['120', '123']},{'id': '120', 'type': 'subscript', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'adapted'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '123', 'type': 'for_in_clause', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'argspec'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'call', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'adapted_posargs'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'adapted_varargs'},{'id': '135', 'type': 'return_statement', 'children': ['136']},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '138', 'type': 'argument_list', 'children': ['139', '141']},{'id': '139', 'type': 'list_splat', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'adapted_posargs'},{'id': '141', 'type': 'dictionary_splat', 'children': ['142']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'adapted_keywords'},{'id': '143', 'type': 'return_statement', 'children': ['144']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'adapting'} | def adapts(**schemas):
validate = parse(schemas).validate
@decorator
def adapting(func, *args, **kwargs):
adapted = validate(inspect.getcallargs(func, *args, **kwargs), adapt=True)
argspec = inspect.getargspec(func)
if argspec.varargs is argspec.keywords is None:
return func(**adapted)
adapted_varargs = adapted.pop(argspec.varargs, ())
adapted_keywords = adapted.pop(argspec.keywords, {})
if not adapted_varargs:
if adapted_keywords:
adapted.update(adapted_keywords)
return func(**adapted)
adapted_posargs = [adapted[arg] for arg in argspec.args]
adapted_posargs.extend(adapted_varargs)
return func(*adapted_posargs, **adapted_keywords)
return adapting |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '27']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'download'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '17', '21', '24']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'bundle_uuid'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'replica'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '9', 'type': 'string', 'children': [], 'value': '""'},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'download_dir'},{'id': '12', 'type': 'string', 'children': [], 'value': '""'},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'metadata_files'},{'id': '15', 'type': 'tuple', 'children': ['16']},{'id': '16', 'type': 'string', 'children': [], 'value': "'*'"},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'data_files'},{'id': '19', 'type': 'tuple', 'children': ['20']},{'id': '20', 'type': 'string', 'children': [], 'value': "'*'"},{'id': '21', 'type': 'default_parameter', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'num_retries'},{'id': '23', 'type': 'integer', 'children': [], 'value': '10'},{'id': '24', 'type': 'default_parameter', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'min_delay_seconds'},{'id': '26', 'type': 'float', 'children': [], 'value': '0.25'},{'id': '27', 'type': 'block', 'children': ['28', '32', '132']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'errors'},{'id': '31', 'type': 'integer', 'children': [], 'value': '0'},{'id': '32', 'type': 'with_statement', 'children': ['33', '48']},{'id': '33', 'type': 'with_clause', 'children': ['34']},{'id': '34', 'type': 'with_item', 'children': ['35']},{'id': '35', 'type': 'as_pattern', 'children': ['36', '46']},{'id': '36', 'type': 'call', 'children': ['37', '42']},{'id': '37', 'type': 'attribute', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'concurrent'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'futures'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'ThreadPoolExecutor'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'threads'},{'id': '46', 'type': 'as_pattern_target', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'executor'},{'id': '48', 'type': 'block', 'children': ['49', '78']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'futures_to_dss_file'},{'id': '52', 'type': 'dictionary_comprehension', 'children': ['53', '61']},{'id': '53', 'type': 'pair', 'children': ['54', '60']},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'executor'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'submit'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'dss_file'},{'id': '61', 'type': 'for_in_clause', 'children': ['62', '65']},{'id': '62', 'type': 'pattern_list', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'dss_file'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '68', 'type': 'identifier', 'children': [], 'value': '_download_tasks'},{'id': '69', 'type': 'argument_list', 'children': ['70', '71', '72', '73', '74', '75', '76', '77']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'bundle_uuid'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'replica'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'download_dir'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'metadata_files'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'data_files'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'num_retries'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'min_delay_seconds'},{'id': '78', 'type': 'for_statement', 'children': ['79', '80', '88']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'future'},{'id': '80', 'type': 'call', 'children': ['81', '86']},{'id': '81', 'type': 'attribute', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'concurrent'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'futures'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'as_completed'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'futures_to_dss_file'},{'id': '88', 'type': 'block', 'children': ['89', '95']},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'dss_file'},{'id': '92', 'type': 'subscript', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'futures_to_dss_file'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'future'},{'id': '95', 'type': 'try_statement', 'children': ['96', '103']},{'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': 'future'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '102', 'type': 'argument_list', 'children': []},{'id': '103', 'type': 'except_clause', 'children': ['104', '108']},{'id': '104', 'type': 'as_pattern', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '106', 'type': 'as_pattern_target', 'children': ['107']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '108', 'type': 'block', 'children': ['109', '113']},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'augmented_assignment', 'children': ['111', '112'], 'value': '+='},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'errors'},{'id': '112', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'warning'},{'id': '118', 'type': 'argument_list', 'children': ['119', '120', '123', '126', '129']},{'id': '119', 'type': 'string', 'children': [], 'value': "'Failed to download file %s version %s from replica %s'"},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'dss_file'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'dss_file'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'dss_file'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'replica'},{'id': '129', 'type': 'keyword_argument', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'exc_info'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '132', 'type': 'if_statement', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'errors'},{'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': 'RuntimeError'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'string', 'children': [], 'value': "'{} file(s) failed to download'"},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'errors'} | def download(self, bundle_uuid, replica, version="", download_dir="",
metadata_files=('*',), data_files=('*',),
num_retries=10, min_delay_seconds=0.25):
errors = 0
with concurrent.futures.ThreadPoolExecutor(self.threads) as executor:
futures_to_dss_file = {executor.submit(task): dss_file
for dss_file, task in self._download_tasks(bundle_uuid,
replica,
version,
download_dir,
metadata_files,
data_files,
num_retries,
min_delay_seconds)}
for future in concurrent.futures.as_completed(futures_to_dss_file):
dss_file = futures_to_dss_file[future]
try:
future.result()
except Exception as e:
errors += 1
logger.warning('Failed to download file %s version %s from replica %s',
dss_file.uuid, dss_file.version, dss_file.replica, exc_info=e)
if errors:
raise RuntimeError('{} file(s) failed to download'.format(errors)) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_do_download_file'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'dss_file'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'fh'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'num_retries'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'min_delay_seconds'},{'id': '9', 'type': 'block', 'children': ['10', '18', '22', '26', '383']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'hasher'},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'hashlib'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'sha256'},{'id': '17', 'type': 'argument_list', 'children': []},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'delay'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'min_delay_seconds'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'retries_left'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'num_retries'},{'id': '26', 'type': 'while_statement', 'children': ['27', '28']},{'id': '27', 'type': 'True', 'children': []},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'try_statement', 'children': ['30', '340']},{'id': '30', 'type': 'block', 'children': ['31', '77']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '34', 'type': 'call', 'children': ['35', '40']},{'id': '35', 'type': 'attribute', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'get_file'},{'id': '39', 'type': 'identifier', 'children': [], 'value': '_request'},{'id': '40', 'type': 'argument_list', 'children': ['41', '59', '62']},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '43', 'type': 'argument_list', 'children': ['44', '49', '54']},{'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'dss_file'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'dss_file'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '54', 'type': 'keyword_argument', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'replica'},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'dss_file'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'replica'},{'id': '59', 'type': 'keyword_argument', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '61', 'type': 'True', 'children': []},{'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '64', 'type': 'dictionary', 'children': ['65']},{'id': '65', 'type': 'pair', 'children': ['66', '67']},{'id': '66', 'type': 'string', 'children': [], 'value': "'Range'"},{'id': '67', 'type': 'call', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'string', 'children': [], 'value': '"bytes={}-"'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'fh'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'tell'},{'id': '76', 'type': 'argument_list', 'children': []},{'id': '77', 'type': 'try_statement', 'children': ['78', '332']},{'id': '78', 'type': 'block', 'children': ['79', '116', '127', '131', '143', '183', '187', '191', '281', '331']},{'id': '79', 'type': 'if_statement', 'children': ['80', '84']},{'id': '80', 'type': 'not_operator', 'children': ['81']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'ok'},{'id': '84', 'type': 'block', 'children': ['85', '100', '115']},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '90', 'type': 'argument_list', 'children': ['91', '92']},{'id': '91', 'type': 'string', 'children': [], 'value': '"%s"'},{'id': '92', 'type': 'call', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'string', 'children': [], 'value': '"File {}: GET FAILED."'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'dss_file'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'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': 'logger'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '105', 'type': 'argument_list', 'children': ['106', '107']},{'id': '106', 'type': 'string', 'children': [], 'value': '"%s"'},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'string', 'children': [], 'value': '"Response: {}"'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '115', 'type': 'break_statement', 'children': []},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'consume_bytes'},{'id': '119', 'type': 'call', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'call', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'fh'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'tell'},{'id': '126', 'type': 'argument_list', 'children': []},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'server_start'},{'id': '130', 'type': 'integer', 'children': [], 'value': '0'},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'content_range_header'},{'id': '134', 'type': 'call', 'children': ['135', '140']},{'id': '135', 'type': 'attribute', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '140', 'type': 'argument_list', 'children': ['141', '142']},{'id': '141', 'type': 'string', 'children': [], 'value': "'Content-Range'"},{'id': '142', 'type': 'None', 'children': []},{'id': '143', 'type': 'if_statement', 'children': ['144', '147']},{'id': '144', 'type': 'comparison_operator', 'children': ['145', '146'], 'value': 'is'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'content_range_header'},{'id': '146', 'type': 'None', 'children': []},{'id': '147', 'type': 'block', 'children': ['148', '157', '166']},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'cre'},{'id': '151', 'type': 'call', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'compile'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'string', 'children': [], 'value': '"bytes (\\d+)-(\\d+)"'},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'mo'},{'id': '160', 'type': 'call', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'cre'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'content_range_header'},{'id': '166', 'type': 'if_statement', 'children': ['167', '170']},{'id': '167', 'type': 'comparison_operator', 'children': ['168', '169'], 'value': 'is'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'mo'},{'id': '169', 'type': 'None', 'children': []},{'id': '170', 'type': 'block', 'children': ['171']},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'assignment', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'server_start'},{'id': '174', 'type': 'call', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'call', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'mo'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'integer', 'children': [], 'value': '1'},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'augmented_assignment', 'children': ['185', '186'], 'value': '-='},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'consume_bytes'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'server_start'},{'id': '187', 'type': 'assert_statement', 'children': ['188']},{'id': '188', 'type': 'comparison_operator', 'children': ['189', '190'], 'value': '>='},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'consume_bytes'},{'id': '190', 'type': 'integer', 'children': [], 'value': '0'},{'id': '191', 'type': 'if_statement', 'children': ['192', '199', '216']},{'id': '192', 'type': 'boolean_operator', 'children': ['193', '196'], 'value': 'and'},{'id': '193', 'type': 'comparison_operator', 'children': ['194', '195'], 'value': '>'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'server_start'},{'id': '195', 'type': 'integer', 'children': [], 'value': '0'},{'id': '196', 'type': 'comparison_operator', 'children': ['197', '198'], 'value': '=='},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'consume_bytes'},{'id': '198', 'type': 'integer', 'children': [], 'value': '0'},{'id': '199', 'type': 'block', 'children': ['200']},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'call', 'children': ['202', '205']},{'id': '202', 'type': 'attribute', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '205', 'type': 'argument_list', 'children': ['206', '207']},{'id': '206', 'type': 'string', 'children': [], 'value': '"%s"'},{'id': '207', 'type': 'call', 'children': ['208', '211']},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'string', 'children': [], 'value': '"File {}: Resuming at {}."'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '211', 'type': 'argument_list', 'children': ['212', '215']},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'dss_file'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'server_start'},{'id': '216', 'type': 'elif_clause', 'children': ['217', '220']},{'id': '217', 'type': 'comparison_operator', 'children': ['218', '219'], 'value': '>'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'consume_bytes'},{'id': '219', 'type': 'integer', 'children': [], 'value': '0'},{'id': '220', 'type': 'block', 'children': ['221', '238']},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'call', 'children': ['223', '226']},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '226', 'type': 'argument_list', 'children': ['227', '228']},{'id': '227', 'type': 'string', 'children': [], 'value': '"%s"'},{'id': '228', 'type': 'call', 'children': ['229', '232']},{'id': '229', 'type': 'attribute', 'children': ['230', '231']},{'id': '230', 'type': 'string', 'children': [], 'value': '"File {}: Resuming at {}. Dropping {} bytes to match"'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '232', 'type': 'argument_list', 'children': ['233', '236', '237']},{'id': '233', 'type': 'attribute', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'dss_file'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'server_start'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'consume_bytes'},{'id': '238', 'type': 'while_statement', 'children': ['239', '242']},{'id': '239', 'type': 'comparison_operator', 'children': ['240', '241'], 'value': '>'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'consume_bytes'},{'id': '241', 'type': 'integer', 'children': [], 'value': '0'},{'id': '242', 'type': 'block', 'children': ['243', '253', '264', '271']},{'id': '243', 'type': 'expression_statement', 'children': ['244']},{'id': '244', 'type': 'assignment', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'bytes_to_read'},{'id': '246', 'type': 'call', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '248', 'type': 'argument_list', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'consume_bytes'},{'id': '250', 'type': 'binary_operator', 'children': ['251', '252'], 'value': '*'},{'id': '251', 'type': 'integer', 'children': [], 'value': '1024'},{'id': '252', 'type': 'integer', 'children': [], 'value': '1024'},{'id': '253', 'type': 'expression_statement', 'children': ['254']},{'id': '254', 'type': 'assignment', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '256', 'type': 'call', 'children': ['257', '260']},{'id': '257', 'type': 'attribute', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'iter_content'},{'id': '260', 'type': 'argument_list', 'children': ['261']},{'id': '261', 'type': 'keyword_argument', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'chunk_size'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'bytes_to_read'},{'id': '264', 'type': 'expression_statement', 'children': ['265']},{'id': '265', 'type': 'assignment', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'chunk'},{'id': '267', 'type': 'call', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'next'},{'id': '269', 'type': 'argument_list', 'children': ['270']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '271', 'type': 'if_statement', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'chunk'},{'id': '273', 'type': 'block', 'children': ['274']},{'id': '274', 'type': 'expression_statement', 'children': ['275']},{'id': '275', 'type': 'augmented_assignment', 'children': ['276', '277'], 'value': '-='},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'consume_bytes'},{'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': 'chunk'},{'id': '281', 'type': 'for_statement', 'children': ['282', '283', '293']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'chunk'},{'id': '283', 'type': 'call', 'children': ['284', '287']},{'id': '284', 'type': 'attribute', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'iter_content'},{'id': '287', 'type': 'argument_list', 'children': ['288']},{'id': '288', 'type': 'keyword_argument', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'chunk_size'},{'id': '290', 'type': 'binary_operator', 'children': ['291', '292'], 'value': '*'},{'id': '291', 'type': 'integer', 'children': [], 'value': '1024'},{'id': '292', 'type': 'integer', 'children': [], 'value': '1024'},{'id': '293', 'type': 'block', 'children': ['294']},{'id': '294', 'type': 'if_statement', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'chunk'},{'id': '296', 'type': 'block', 'children': ['297', '304', '311', '321']},{'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': 'fh'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '302', 'type': 'argument_list', 'children': ['303']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'chunk'},{'id': '304', 'type': 'expression_statement', 'children': ['305']},{'id': '305', 'type': 'call', 'children': ['306', '309']},{'id': '306', 'type': 'attribute', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'hasher'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '309', 'type': 'argument_list', 'children': ['310']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'chunk'},{'id': '311', 'type': 'expression_statement', 'children': ['312']},{'id': '312', 'type': 'assignment', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'retries_left'},{'id': '314', 'type': 'call', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '316', 'type': 'argument_list', 'children': ['317', '320']},{'id': '317', 'type': 'binary_operator', 'children': ['318', '319'], 'value': '+'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'retries_left'},{'id': '319', 'type': 'integer', 'children': [], 'value': '1'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'num_retries'},{'id': '321', 'type': 'expression_statement', 'children': ['322']},{'id': '322', 'type': 'assignment', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'delay'},{'id': '324', 'type': 'call', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '326', 'type': 'argument_list', 'children': ['327', '330']},{'id': '327', 'type': 'binary_operator', 'children': ['328', '329'], 'value': '/'},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'delay'},{'id': '329', 'type': 'integer', 'children': [], 'value': '2'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'min_delay_seconds'},{'id': '331', 'type': 'break_statement', 'children': []},{'id': '332', 'type': 'finally_clause', 'children': ['333']},{'id': '333', 'type': 'block', 'children': ['334']},{'id': '334', 'type': 'expression_statement', 'children': ['335']},{'id': '335', 'type': 'call', 'children': ['336', '339']},{'id': '336', 'type': 'attribute', 'children': ['337', '338']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '339', 'type': 'argument_list', 'children': []},{'id': '340', 'type': 'except_clause', 'children': ['341', '345']},{'id': '341', 'type': 'tuple', 'children': ['342', '343', '344']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'ChunkedEncodingError'},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'ConnectionError'},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'ReadTimeout'},{'id': '345', 'type': 'block', 'children': ['346', '382']},{'id': '346', 'type': 'if_statement', 'children': ['347', '350']},{'id': '347', 'type': 'comparison_operator', 'children': ['348', '349'], 'value': '>'},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'retries_left'},{'id': '349', 'type': 'integer', 'children': [], 'value': '0'},{'id': '350', 'type': 'block', 'children': ['351', '366', '373', '377', '381']},{'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': 'logger'},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '356', 'type': 'argument_list', 'children': ['357', '358']},{'id': '357', 'type': 'string', 'children': [], 'value': '"%s"'},{'id': '358', 'type': 'call', 'children': ['359', '362']},{'id': '359', 'type': 'attribute', 'children': ['360', '361']},{'id': '360', 'type': 'string', 'children': [], 'value': '"File {}: GET FAILED. Attempting to resume."'},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '362', 'type': 'argument_list', 'children': ['363']},{'id': '363', 'type': 'attribute', 'children': ['364', '365']},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'dss_file'},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '366', 'type': 'expression_statement', 'children': ['367']},{'id': '367', 'type': 'call', 'children': ['368', '371']},{'id': '368', 'type': 'attribute', 'children': ['369', '370']},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'sleep'},{'id': '371', 'type': 'argument_list', 'children': ['372']},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'delay'},{'id': '373', 'type': 'expression_statement', 'children': ['374']},{'id': '374', 'type': 'augmented_assignment', 'children': ['375', '376'], 'value': '*='},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'delay'},{'id': '376', 'type': 'integer', 'children': [], 'value': '2'},{'id': '377', 'type': 'expression_statement', 'children': ['378']},{'id': '378', 'type': 'augmented_assignment', 'children': ['379', '380'], 'value': '-='},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'retries_left'},{'id': '380', 'type': 'integer', 'children': [], 'value': '1'},{'id': '381', 'type': 'continue_statement', 'children': []},{'id': '382', 'type': 'raise_statement', 'children': []},{'id': '383', 'type': 'return_statement', 'children': ['384']},{'id': '384', 'type': 'call', 'children': ['385', '388']},{'id': '385', 'type': 'attribute', 'children': ['386', '387']},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'hasher'},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'hexdigest'},{'id': '388', 'type': 'argument_list', 'children': []} | def _do_download_file(self, dss_file, fh, num_retries, min_delay_seconds):
hasher = hashlib.sha256()
delay = min_delay_seconds
retries_left = num_retries
while True:
try:
response = self.get_file._request(
dict(uuid=dss_file.uuid, version=dss_file.version, replica=dss_file.replica),
stream=True,
headers={
'Range': "bytes={}-".format(fh.tell())
},
)
try:
if not response.ok:
logger.error("%s", "File {}: GET FAILED.".format(dss_file.uuid))
logger.error("%s", "Response: {}".format(response.text))
break
consume_bytes = int(fh.tell())
server_start = 0
content_range_header = response.headers.get('Content-Range', None)
if content_range_header is not None:
cre = re.compile("bytes (\d+)-(\d+)")
mo = cre.search(content_range_header)
if mo is not None:
server_start = int(mo.group(1))
consume_bytes -= server_start
assert consume_bytes >= 0
if server_start > 0 and consume_bytes == 0:
logger.info("%s", "File {}: Resuming at {}.".format(
dss_file.uuid, server_start))
elif consume_bytes > 0:
logger.info("%s", "File {}: Resuming at {}. Dropping {} bytes to match".format(
dss_file.uuid, server_start, consume_bytes))
while consume_bytes > 0:
bytes_to_read = min(consume_bytes, 1024*1024)
content = response.iter_content(chunk_size=bytes_to_read)
chunk = next(content)
if chunk:
consume_bytes -= len(chunk)
for chunk in response.iter_content(chunk_size=1024*1024):
if chunk:
fh.write(chunk)
hasher.update(chunk)
retries_left = min(retries_left + 1, num_retries)
delay = max(delay / 2, min_delay_seconds)
break
finally:
response.close()
except (ChunkedEncodingError, ConnectionError, ReadTimeout):
if retries_left > 0:
logger.info("%s", "File {}: GET FAILED. Attempting to resume.".format(dss_file.uuid))
time.sleep(delay)
delay *= 2
retries_left -= 1
continue
raise
return hasher.hexdigest() |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'output'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '188']},{'id': '10', 'type': 'if_statement', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '12', 'type': 'block', 'children': ['13', '25', '34', '38', '42', '54', '157']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '16', 'type': 'call', 'children': ['17', '24']},{'id': '17', 'type': 'attribute', 'children': ['18', '23']},{'id': '18', 'type': 'attribute', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'cli'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'get_size'},{'id': '24', 'type': 'argument_list', 'children': []},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'margin'},{'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': 'get_output_margin'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'fits'},{'id': '37', 'type': 'True', 'children': []},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '41', 'type': 'list', 'children': [], 'value': '[]'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'output_via_pager'},{'id': '45', 'type': 'boolean_operator', 'children': ['46', '49'], 'value': 'and'},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'explicit_pager'},{'id': '49', 'type': 'call', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'special'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'is_pager_enabled'},{'id': '53', 'type': 'argument_list', 'children': []},{'id': '54', 'type': 'for_statement', 'children': ['55', '58', '63']},{'id': '55', 'type': 'pattern_list', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '60', 'type': 'argument_list', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '62', 'type': 'integer', 'children': [], 'value': '1'},{'id': '63', 'type': 'block', 'children': ['64', '71', '78']},{'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': 'special'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'write_tee'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'line'},{'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': 'special'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'write_once'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '78', 'type': 'if_statement', 'children': ['79', '82', '148']},{'id': '79', 'type': 'boolean_operator', 'children': ['80', '81'], 'value': 'or'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'fits'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'output_via_pager'},{'id': '82', 'type': 'block', 'children': ['83', '90']},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'call', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '90', 'type': 'if_statement', 'children': ['91', '108']},{'id': '91', 'type': 'boolean_operator', 'children': ['92', '100'], 'value': 'or'},{'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': 'line'},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '100', 'type': 'comparison_operator', 'children': ['101', '102'], 'value': '>'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '102', 'type': '()', 'children': ['103']},{'id': '103', 'type': 'binary_operator', 'children': ['104', '107'], 'value': '-'},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'rows'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'margin'},{'id': '108', 'type': 'block', 'children': ['109', '113', '129']},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'fits'},{'id': '112', 'type': 'False', 'children': []},{'id': '113', 'type': 'if_statement', 'children': ['114', '124']},{'id': '114', 'type': 'boolean_operator', 'children': ['115', '119'], 'value': 'and'},{'id': '115', 'type': 'not_operator', 'children': ['116']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'explicit_pager'},{'id': '119', 'type': 'call', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'special'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'is_pager_enabled'},{'id': '123', 'type': 'argument_list', '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': 'output_via_pager'},{'id': '128', 'type': 'True', 'children': []},{'id': '129', 'type': 'if_statement', 'children': ['130', '132']},{'id': '130', 'type': 'not_operator', 'children': ['131']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'output_via_pager'},{'id': '132', 'type': 'block', 'children': ['133', '144']},{'id': '133', 'type': 'for_statement', 'children': ['134', '135', '136']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '136', 'type': 'block', 'children': ['137']},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'click'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'secho'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '147', 'type': 'list', 'children': [], 'value': '[]'},{'id': '148', 'type': 'else_clause', 'children': ['149']},{'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': 'click'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'secho'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '157', 'type': 'if_statement', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '159', 'type': 'block', 'children': ['160']},{'id': '160', 'type': 'if_statement', 'children': ['161', '162', '175']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'output_via_pager'},{'id': '162', 'type': 'block', 'children': ['163']},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'call', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'click'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'echo_via_pager'},{'id': '168', 'type': 'argument_list', 'children': ['169']},{'id': '169', 'type': 'call', 'children': ['170', '173']},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '173', 'type': 'argument_list', 'children': ['174']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '175', 'type': 'else_clause', 'children': ['176']},{'id': '176', 'type': 'block', 'children': ['177']},{'id': '177', 'type': 'for_statement', 'children': ['178', '179', '180']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '180', 'type': 'block', 'children': ['181']},{'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': 'click'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'secho'},{'id': '186', 'type': 'argument_list', 'children': ['187']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '188', 'type': 'if_statement', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '190', 'type': 'block', 'children': ['191']},{'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': 'click'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'secho'},{'id': '196', 'type': 'argument_list', 'children': ['197']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'status'} | def output(self, output, status=None):
if output:
size = self.cli.output.get_size()
margin = self.get_output_margin(status)
fits = True
buf = []
output_via_pager = self.explicit_pager and special.is_pager_enabled()
for i, line in enumerate(output, 1):
special.write_tee(line)
special.write_once(line)
if fits or output_via_pager:
buf.append(line)
if len(line) > size.columns or i > (size.rows - margin):
fits = False
if not self.explicit_pager and special.is_pager_enabled():
output_via_pager = True
if not output_via_pager:
for line in buf:
click.secho(line)
buf = []
else:
click.secho(line)
if buf:
if output_via_pager:
click.echo_via_pager("\n".join(buf))
else:
for line in buf:
click.secho(line)
if status:
click.secho(status) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_matches'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'collection'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'start_only'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'fuzzy'},{'id': '11', 'type': 'True', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'casing'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'block', 'children': ['16', '26', '34', '38', '159', '180', '202']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'last'},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'last_word'},{'id': '21', 'type': 'argument_list', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '23', 'type': 'keyword_argument', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'include'},{'id': '25', 'type': 'string', 'children': [], 'value': "'most_punctuations'"},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'last'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'lower'},{'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': 'completions'},{'id': '37', 'type': 'list', 'children': [], 'value': '[]'},{'id': '38', 'type': 'if_statement', 'children': ['39', '40', '107']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'fuzzy'},{'id': '40', 'type': 'block', 'children': ['41', '54', '63']},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'regex'},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'string', 'children': [], 'value': "'.*?'"},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '51', 'type': 'argument_list', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'escape'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'pat'},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'compile'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'binary_operator', 'children': ['61', '62'], 'value': '%'},{'id': '61', 'type': 'string', 'children': [], 'value': "'(%s)'"},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'regex'},{'id': '63', 'type': 'for_statement', 'children': ['64', '65', '69']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'collection'},{'id': '69', 'type': 'block', 'children': ['70', '83']},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '73', 'type': 'call', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'pat'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'call', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '82', 'type': 'argument_list', 'children': []},{'id': '83', 'type': 'if_statement', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '85', 'type': 'block', 'children': ['86']},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'completions'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'tuple', 'children': ['93', '101', '106']},{'id': '93', 'type': 'call', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '100', 'type': 'argument_list', 'children': []},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '105', 'type': 'argument_list', 'children': []},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '107', 'type': 'else_clause', 'children': ['108']},{'id': '108', 'type': 'block', 'children': ['109', '119']},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'match_end_limit'},{'id': '112', 'type': 'conditional_expression', 'children': ['113', '117', '118'], 'value': 'if'},{'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': 'text'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'start_only'},{'id': '118', 'type': 'None', 'children': []},{'id': '119', 'type': 'for_statement', 'children': ['120', '121', '125']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '121', 'type': 'call', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'collection'},{'id': '125', 'type': 'block', 'children': ['126', '141']},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'match_point'},{'id': '129', 'type': 'call', 'children': ['130', '137']},{'id': '130', 'type': 'attribute', 'children': ['131', '136']},{'id': '131', 'type': 'call', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '135', 'type': 'argument_list', 'children': []},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '137', 'type': 'argument_list', 'children': ['138', '139', '140']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '139', 'type': 'integer', 'children': [], 'value': '0'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'match_end_limit'},{'id': '141', 'type': 'if_statement', 'children': ['142', '145']},{'id': '142', 'type': 'comparison_operator', 'children': ['143', '144'], 'value': '>='},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'match_point'},{'id': '144', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'completions'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '151', 'type': 'argument_list', 'children': ['152']},{'id': '152', 'type': 'tuple', 'children': ['153', '157', '158']},{'id': '153', 'type': 'call', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'match_point'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '159', 'type': 'if_statement', 'children': ['160', '163']},{'id': '160', 'type': 'comparison_operator', 'children': ['161', '162'], 'value': '=='},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'casing'},{'id': '162', 'type': 'string', 'children': [], 'value': "'auto'"},{'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': 'casing'},{'id': '167', 'type': 'conditional_expression', 'children': ['168', '169', '179'], 'value': 'if'},{'id': '168', 'type': 'string', 'children': [], 'value': "'lower'"},{'id': '169', 'type': 'boolean_operator', 'children': ['170', '171'], 'value': 'and'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'last'},{'id': '171', 'type': 'call', 'children': ['172', '178']},{'id': '172', 'type': 'attribute', 'children': ['173', '177']},{'id': '173', 'type': 'subscript', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'last'},{'id': '175', 'type': 'unary_operator', 'children': ['176'], 'value': '-'},{'id': '176', 'type': 'integer', 'children': [], 'value': '1'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'islower'},{'id': '178', 'type': 'argument_list', 'children': []},{'id': '179', 'type': 'string', 'children': [], 'value': "'upper'"},{'id': '180', 'type': 'function_definition', 'children': ['181', '182', '184']},{'id': '181', 'type': 'function_name', 'children': [], 'value': 'apply_case'},{'id': '182', 'type': 'parameters', 'children': ['183']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '184', 'type': 'block', 'children': ['185', '196']},{'id': '185', 'type': 'if_statement', 'children': ['186', '189']},{'id': '186', 'type': 'comparison_operator', 'children': ['187', '188'], 'value': '=='},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'casing'},{'id': '188', 'type': 'string', 'children': [], 'value': "'upper'"},{'id': '189', 'type': 'block', 'children': ['190']},{'id': '190', 'type': 'return_statement', 'children': ['191']},{'id': '191', 'type': 'call', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '195', 'type': 'argument_list', 'children': []},{'id': '196', 'type': 'return_statement', 'children': ['197']},{'id': '197', 'type': 'call', 'children': ['198', '201']},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '201', 'type': 'argument_list', 'children': []},{'id': '202', 'type': 'return_statement', 'children': ['203']},{'id': '203', 'type': 'generator_expression', 'children': ['204', '221']},{'id': '204', 'type': 'call', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'Completion'},{'id': '206', 'type': 'argument_list', 'children': ['207', '216']},{'id': '207', 'type': 'conditional_expression', 'children': ['208', '209', '212'], 'value': 'if'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '209', 'type': 'comparison_operator', 'children': ['210', '211'], 'value': 'is'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'casing'},{'id': '211', 'type': 'None', 'children': []},{'id': '212', 'type': 'call', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'apply_case'},{'id': '214', 'type': 'argument_list', 'children': ['215']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '216', 'type': 'unary_operator', 'children': ['217'], 'value': '-'},{'id': '217', 'type': 'call', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '219', 'type': 'argument_list', 'children': ['220']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '221', 'type': 'for_in_clause', 'children': ['222', '226']},{'id': '222', 'type': 'pattern_list', 'children': ['223', '224', '225']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '226', 'type': 'call', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '228', 'type': 'argument_list', 'children': ['229']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'completions'} | def find_matches(text, collection, start_only=False, fuzzy=True, casing=None):
last = last_word(text, include='most_punctuations')
text = last.lower()
completions = []
if fuzzy:
regex = '.*?'.join(map(escape, text))
pat = compile('(%s)' % regex)
for item in sorted(collection):
r = pat.search(item.lower())
if r:
completions.append((len(r.group()), r.start(), item))
else:
match_end_limit = len(text) if start_only else None
for item in sorted(collection):
match_point = item.lower().find(text, 0, match_end_limit)
if match_point >= 0:
completions.append((len(text), match_point, item))
if casing == 'auto':
casing = 'lower' if last and last[-1].islower() else 'upper'
def apply_case(kw):
if casing == 'upper':
return kw.upper()
return kw.lower()
return (Completion(z if casing is None else apply_case(z), -len(text))
for x, y, z in sorted(completions)) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'cli_bindings'},{'id': '3', 'type': 'parameters', 'children': []},{'id': '4', 'type': 'block', 'children': ['5', '26', '71', '112', '169', '225', '281', '332']},{'id': '5', 'type': 'expression_statement', 'children': ['6']},{'id': '6', 'type': 'assignment', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'key_binding_manager'},{'id': '8', 'type': 'call', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'KeyBindingManager'},{'id': '10', 'type': 'argument_list', 'children': ['11', '14', '17', '20', '23']},{'id': '11', 'type': 'keyword_argument', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'enable_open_in_editor'},{'id': '13', 'type': 'True', 'children': []},{'id': '14', 'type': 'keyword_argument', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'enable_system_bindings'},{'id': '16', 'type': 'True', 'children': []},{'id': '17', 'type': 'keyword_argument', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'enable_auto_suggest_bindings'},{'id': '19', 'type': 'True', 'children': []},{'id': '20', 'type': 'keyword_argument', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'enable_search'},{'id': '22', 'type': 'True', 'children': []},{'id': '23', 'type': 'keyword_argument', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'enable_abort_and_exit_bindings'},{'id': '25', 'type': 'True', 'children': []},{'id': '26', 'type': 'decorated_definition', 'children': ['27', '38']},{'id': '27', 'type': 'decorator', 'children': ['28']},{'id': '28', 'type': 'call', 'children': ['29', '34']},{'id': '29', 'type': 'attribute', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'key_binding_manager'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'registry'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'add_binding'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'Keys'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'F2'},{'id': '38', 'type': 'function_definition', 'children': ['39', '40', '42']},{'id': '39', 'type': 'function_name', 'children': [], 'value': '_'},{'id': '40', 'type': 'parameters', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '42', 'type': 'block', 'children': ['43', '50', '58']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': '_logger'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'string', 'children': [], 'value': "'Detected F2 key.'"},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '53', 'type': 'attribute', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'cli'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'current_buffer'},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '65']},{'id': '60', 'type': 'attribute', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'completer'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'smart_completion'},{'id': '65', 'type': 'not_operator', 'children': ['66']},{'id': '66', 'type': 'attribute', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'completer'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'smart_completion'},{'id': '71', 'type': 'decorated_definition', 'children': ['72', '83']},{'id': '72', 'type': 'decorator', 'children': ['73']},{'id': '73', 'type': 'call', 'children': ['74', '79']},{'id': '74', 'type': 'attribute', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'key_binding_manager'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'registry'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'add_binding'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'Keys'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'F3'},{'id': '83', 'type': 'function_definition', 'children': ['84', '85', '87']},{'id': '84', 'type': 'function_name', 'children': [], 'value': '_'},{'id': '85', 'type': 'parameters', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '87', 'type': 'block', 'children': ['88', '95', '103']},{'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': '_logger'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'string', 'children': [], 'value': "'Detected F3 key.'"},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'assignment', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '98', 'type': 'attribute', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'cli'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'current_buffer'},{'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': 'buf'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'always_multiline'},{'id': '108', 'type': 'not_operator', 'children': ['109']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'always_multiline'},{'id': '112', 'type': 'decorated_definition', 'children': ['113', '124']},{'id': '113', 'type': 'decorator', 'children': ['114']},{'id': '114', 'type': 'call', 'children': ['115', '120']},{'id': '115', 'type': 'attribute', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'key_binding_manager'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'registry'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'add_binding'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'Keys'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'F4'},{'id': '124', 'type': 'function_definition', 'children': ['125', '126', '128']},{'id': '125', 'type': 'function_name', 'children': [], 'value': '_'},{'id': '126', 'type': 'parameters', 'children': ['127']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '128', 'type': 'block', 'children': ['129', '136']},{'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': '_logger'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'string', 'children': [], 'value': "'Detected F4 key.'"},{'id': '136', 'type': 'if_statement', 'children': ['137', '146', '157']},{'id': '137', 'type': 'comparison_operator', 'children': ['138', '143'], 'value': '=='},{'id': '138', 'type': 'attribute', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'cli'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'editing_mode'},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'EditingMode'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'VI'},{'id': '146', 'type': 'block', 'children': ['147']},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'assignment', 'children': ['149', '154']},{'id': '149', 'type': 'attribute', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'cli'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'editing_mode'},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'EditingMode'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'EMACS'},{'id': '157', 'type': 'else_clause', 'children': ['158']},{'id': '158', 'type': 'block', 'children': ['159']},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'assignment', 'children': ['161', '166']},{'id': '161', 'type': 'attribute', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'cli'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'editing_mode'},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'EditingMode'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'VI'},{'id': '169', 'type': 'decorated_definition', 'children': ['170', '181']},{'id': '170', 'type': 'decorator', 'children': ['171']},{'id': '171', 'type': 'call', 'children': ['172', '177']},{'id': '172', 'type': 'attribute', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'key_binding_manager'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'registry'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'add_binding'},{'id': '177', 'type': 'argument_list', 'children': ['178']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'Keys'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'Tab'},{'id': '181', 'type': 'function_definition', 'children': ['182', '183', '185']},{'id': '182', 'type': 'function_name', 'children': [], 'value': '_'},{'id': '183', 'type': 'parameters', 'children': ['184']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '185', 'type': 'block', 'children': ['186', '193', '201']},{'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': '_logger'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '191', 'type': 'argument_list', 'children': ['192']},{'id': '192', 'type': 'string', 'children': [], 'value': "'Detected <Tab> key.'"},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'assignment', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '196', 'type': 'attribute', 'children': ['197', '200']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'cli'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'current_buffer'},{'id': '201', 'type': 'if_statement', 'children': ['202', '205', '212']},{'id': '202', 'type': 'attribute', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'complete_state'},{'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': 'b'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'complete_next'},{'id': '211', 'type': 'argument_list', 'children': []},{'id': '212', 'type': 'else_clause', 'children': ['213']},{'id': '213', 'type': 'block', 'children': ['214']},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'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': 'event'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'cli'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'start_completion'},{'id': '221', 'type': 'argument_list', 'children': ['222']},{'id': '222', 'type': 'keyword_argument', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'select_first'},{'id': '224', 'type': 'True', 'children': []},{'id': '225', 'type': 'decorated_definition', 'children': ['226', '237']},{'id': '226', 'type': 'decorator', 'children': ['227']},{'id': '227', 'type': 'call', 'children': ['228', '233']},{'id': '228', 'type': 'attribute', 'children': ['229', '232']},{'id': '229', 'type': 'attribute', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'key_binding_manager'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'registry'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'add_binding'},{'id': '233', 'type': 'argument_list', 'children': ['234']},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'Keys'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'ControlSpace'},{'id': '237', 'type': 'function_definition', 'children': ['238', '239', '241']},{'id': '238', 'type': 'function_name', 'children': [], 'value': '_'},{'id': '239', 'type': 'parameters', 'children': ['240']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '241', 'type': 'block', 'children': ['242', '249', '257']},{'id': '242', 'type': 'expression_statement', 'children': ['243']},{'id': '243', 'type': 'call', 'children': ['244', '247']},{'id': '244', 'type': 'attribute', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': '_logger'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '247', 'type': 'argument_list', 'children': ['248']},{'id': '248', 'type': 'string', 'children': [], 'value': "'Detected <C-Space> key.'"},{'id': '249', 'type': 'expression_statement', 'children': ['250']},{'id': '250', 'type': 'assignment', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '252', 'type': 'attribute', 'children': ['253', '256']},{'id': '253', 'type': 'attribute', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'cli'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'current_buffer'},{'id': '257', 'type': 'if_statement', 'children': ['258', '261', '268']},{'id': '258', 'type': 'attribute', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'complete_state'},{'id': '261', 'type': 'block', 'children': ['262']},{'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': 'b'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'complete_next'},{'id': '267', 'type': 'argument_list', 'children': []},{'id': '268', 'type': 'else_clause', 'children': ['269']},{'id': '269', 'type': 'block', 'children': ['270']},{'id': '270', 'type': 'expression_statement', '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': 'event'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'cli'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'start_completion'},{'id': '277', 'type': 'argument_list', 'children': ['278']},{'id': '278', 'type': 'keyword_argument', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'select_first'},{'id': '280', 'type': 'False', 'children': []},{'id': '281', 'type': 'decorated_definition', 'children': ['282', '298']},{'id': '282', 'type': 'decorator', 'children': ['283']},{'id': '283', 'type': 'call', 'children': ['284', '289']},{'id': '284', 'type': 'attribute', 'children': ['285', '288']},{'id': '285', 'type': 'attribute', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'key_binding_manager'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'registry'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'add_binding'},{'id': '289', 'type': 'argument_list', 'children': ['290', '293']},{'id': '290', 'type': 'attribute', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'Keys'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'ControlJ'},{'id': '293', 'type': 'keyword_argument', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '295', 'type': 'call', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'HasSelectedCompletion'},{'id': '297', 'type': 'argument_list', 'children': []},{'id': '298', 'type': 'function_definition', 'children': ['299', '300', '302']},{'id': '299', 'type': 'function_name', 'children': [], 'value': '_'},{'id': '300', 'type': 'parameters', 'children': ['301']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '302', 'type': 'block', 'children': ['303', '310', '318', '326']},{'id': '303', 'type': 'expression_statement', 'children': ['304']},{'id': '304', 'type': 'call', 'children': ['305', '308']},{'id': '305', 'type': 'attribute', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': '_logger'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '308', 'type': 'argument_list', 'children': ['309']},{'id': '309', 'type': 'string', 'children': [], 'value': "'Detected <C-J> key.'"},{'id': '310', 'type': 'expression_statement', 'children': ['311']},{'id': '311', 'type': 'assignment', 'children': ['312', '317']},{'id': '312', 'type': 'attribute', 'children': ['313', '316']},{'id': '313', 'type': 'attribute', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'current_buffer'},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'complete_state'},{'id': '317', 'type': 'None', 'children': []},{'id': '318', 'type': 'expression_statement', 'children': ['319']},{'id': '319', 'type': 'assignment', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '321', 'type': 'attribute', 'children': ['322', '325']},{'id': '322', 'type': 'attribute', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'cli'},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'current_buffer'},{'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': 'b'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'complete_state'},{'id': '331', 'type': 'None', 'children': []},{'id': '332', 'type': 'return_statement', 'children': ['333']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'key_binding_manager'} | def cli_bindings():
key_binding_manager = KeyBindingManager(
enable_open_in_editor=True,
enable_system_bindings=True,
enable_auto_suggest_bindings=True,
enable_search=True,
enable_abort_and_exit_bindings=True)
@key_binding_manager.registry.add_binding(Keys.F2)
def _(event):
_logger.debug('Detected F2 key.')
buf = event.cli.current_buffer
buf.completer.smart_completion = not buf.completer.smart_completion
@key_binding_manager.registry.add_binding(Keys.F3)
def _(event):
_logger.debug('Detected F3 key.')
buf = event.cli.current_buffer
buf.always_multiline = not buf.always_multiline
@key_binding_manager.registry.add_binding(Keys.F4)
def _(event):
_logger.debug('Detected F4 key.')
if event.cli.editing_mode == EditingMode.VI:
event.cli.editing_mode = EditingMode.EMACS
else:
event.cli.editing_mode = EditingMode.VI
@key_binding_manager.registry.add_binding(Keys.Tab)
def _(event):
_logger.debug('Detected <Tab> key.')
b = event.cli.current_buffer
if b.complete_state:
b.complete_next()
else:
event.cli.start_completion(select_first=True)
@key_binding_manager.registry.add_binding(Keys.ControlSpace)
def _(event):
_logger.debug('Detected <C-Space> key.')
b = event.cli.current_buffer
if b.complete_state:
b.complete_next()
else:
event.cli.start_completion(select_first=False)
@key_binding_manager.registry.add_binding(Keys.ControlJ, filter=HasSelectedCompletion())
def _(event):
_logger.debug('Detected <C-J> key.')
event.current_buffer.complete_state = None
b = event.cli.current_buffer
b.complete_state = None
return key_binding_manager |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_thumbnail_options'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '7', 'type': 'block', 'children': ['8', '16', '20', '30', '40', '54', '79', '90', '202']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '13']},{'id': '10', 'type': 'pattern_list', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'width'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'height'},{'id': '13', 'type': 'expression_list', 'children': ['14', '15']},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'subject_location'},{'id': '19', 'type': 'False', 'children': []},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'placeholder_width'},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '27', 'type': 'argument_list', 'children': ['28', '29']},{'id': '28', 'type': 'string', 'children': [], 'value': "'width'"},{'id': '29', 'type': 'None', 'children': []},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'placeholder_height'},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '37', 'type': 'argument_list', 'children': ['38', '39']},{'id': '38', 'type': 'string', 'children': [], 'value': "'height'"},{'id': '39', 'type': 'None', 'children': []},{'id': '40', 'type': 'if_statement', 'children': ['41', '46']},{'id': '41', 'type': 'boolean_operator', 'children': ['42', '45'], 'value': 'and'},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'use_autoscale'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'placeholder_width'},{'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': 'width'},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'placeholder_width'},{'id': '54', 'type': 'if_statement', 'children': ['55', '60', '68']},{'id': '55', 'type': 'boolean_operator', 'children': ['56', '59'], 'value': 'and'},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'use_autoscale'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'placeholder_height'},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'height'},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'placeholder_height'},{'id': '68', 'type': 'elif_clause', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'width'},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'width'},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'width'},{'id': '79', 'type': 'if_statement', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'height'},{'id': '83', 'type': 'block', 'children': ['84']},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'height'},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'height'},{'id': '90', 'type': 'if_statement', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '94', 'type': 'block', 'children': ['95', '110', '144', '178', '190']},{'id': '95', 'type': 'if_statement', 'children': ['96', '101']},{'id': '96', 'type': 'attribute', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'subject_location'},{'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': 'subject_location'},{'id': '105', 'type': 'attribute', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'subject_location'},{'id': '110', 'type': 'if_statement', 'children': ['111', '115']},{'id': '111', 'type': 'boolean_operator', 'children': ['112', '114'], 'value': 'and'},{'id': '112', 'type': 'not_operator', 'children': ['113']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'height'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'width'},{'id': '115', 'type': 'block', 'children': ['116']},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'height'},{'id': '119', 'type': 'call', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'binary_operator', 'children': ['123', '136'], 'value': '/'},{'id': '123', 'type': 'binary_operator', 'children': ['124', '128'], 'value': '*'},{'id': '124', 'type': 'call', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'width'},{'id': '128', 'type': 'call', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'attribute', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'height'},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'attribute', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'width'},{'id': '144', 'type': 'if_statement', 'children': ['145', '149']},{'id': '145', 'type': 'boolean_operator', 'children': ['146', '148'], 'value': 'and'},{'id': '146', 'type': 'not_operator', 'children': ['147']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'width'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'height'},{'id': '149', 'type': 'block', 'children': ['150']},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'width'},{'id': '153', 'type': 'call', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'binary_operator', 'children': ['157', '170'], 'value': '/'},{'id': '157', 'type': 'binary_operator', 'children': ['158', '162'], 'value': '*'},{'id': '158', 'type': 'call', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'height'},{'id': '162', 'type': 'call', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'attribute', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'width'},{'id': '170', 'type': 'call', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'attribute', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'height'},{'id': '178', 'type': 'if_statement', 'children': ['179', '181']},{'id': '179', 'type': 'not_operator', 'children': ['180']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'width'},{'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': 'width'},{'id': '185', 'type': 'attribute', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'width'},{'id': '190', 'type': 'if_statement', 'children': ['191', '193']},{'id': '191', 'type': 'not_operator', 'children': ['192']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'height'},{'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': 'height'},{'id': '197', 'type': 'attribute', 'children': ['198', '201']},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'height'},{'id': '202', 'type': 'return_statement', 'children': ['203']},{'id': '203', 'type': 'dictionary', 'children': ['204', '209']},{'id': '204', 'type': 'pair', 'children': ['205', '206']},{'id': '205', 'type': 'string', 'children': [], 'value': "'size'"},{'id': '206', 'type': 'tuple', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'width'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'height'},{'id': '209', 'type': 'pair', 'children': ['210', '211']},{'id': '210', 'type': 'string', 'children': [], 'value': "'subject_location'"},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'subject_location'} | def _get_thumbnail_options(self, context, instance):
width, height = None, None
subject_location = False
placeholder_width = context.get('width', None)
placeholder_height = context.get('height', None)
if instance.use_autoscale and placeholder_width:
width = int(placeholder_width)
if instance.use_autoscale and placeholder_height:
height = int(placeholder_height)
elif instance.width:
width = instance.width
if instance.height:
height = instance.height
if instance.image:
if instance.image.subject_location:
subject_location = instance.image.subject_location
if not height and width:
height = int(float(width) * float(instance.image.height) / float(instance.image.width))
if not width and height:
width = int(float(height) * float(instance.image.width) / float(instance.image.height))
if not width:
width = instance.image.width
if not height:
height = instance.image.height
return {'size': (width, height),
'subject_location': subject_location} |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'group_and_sort_statements'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'stmt_list'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'ev_totals'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '36', '43', '51', '59', '135', '267', '288']},{'id': '9', 'type': 'function_definition', 'children': ['10', '11', '13']},{'id': '10', 'type': 'function_name', 'children': [], 'value': '_count'},{'id': '11', 'type': 'parameters', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'if_statement', 'children': ['15', '18', '26']},{'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': 'is'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'ev_totals'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'return_statement', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'evidence'},{'id': '26', 'type': 'else_clause', 'children': ['27']},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'return_statement', 'children': ['29']},{'id': '29', 'type': 'subscript', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'ev_totals'},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'get_hash'},{'id': '35', 'type': 'argument_list', 'children': []},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'stmt_rows'},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'stmt_counts'},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'lambda', 'children': ['50']},{'id': '50', 'type': 'integer', 'children': [], 'value': '0'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'arg_counts'},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'lambda', 'children': ['58']},{'id': '58', 'type': 'integer', 'children': [], 'value': '0'},{'id': '59', 'type': 'for_statement', 'children': ['60', '63', '67']},{'id': '60', 'type': 'pattern_list', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': '_get_keyed_stmts'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'stmt_list'},{'id': '67', 'type': 'block', 'children': ['68', '77', '86']},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'call', 'children': ['70', '75']},{'id': '70', 'type': 'attribute', 'children': ['71', '74']},{'id': '71', 'type': 'subscript', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'stmt_rows'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'augmented_assignment', 'children': ['79', '82'], 'value': '+='},{'id': '79', 'type': 'subscript', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'stmt_counts'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': '_count'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '86', 'type': 'if_statement', 'children': ['87', '92', '120']},{'id': '87', 'type': 'comparison_operator', 'children': ['88', '91'], 'value': '=='},{'id': '88', 'type': 'subscript', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '90', 'type': 'integer', 'children': [], 'value': '0'},{'id': '91', 'type': 'string', 'children': [], 'value': "'Conversion'"},{'id': '92', 'type': 'block', 'children': ['93', '99']},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'subj'},{'id': '96', 'type': 'subscript', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '98', 'type': 'integer', 'children': [], 'value': '1'},{'id': '99', 'type': 'for_statement', 'children': ['100', '101', '108']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '101', 'type': 'binary_operator', 'children': ['102', '105'], 'value': '+'},{'id': '102', 'type': 'subscript', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '104', 'type': 'integer', 'children': [], 'value': '2'},{'id': '105', 'type': 'subscript', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '107', 'type': 'integer', 'children': [], 'value': '3'},{'id': '108', 'type': 'block', 'children': ['109']},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'augmented_assignment', 'children': ['111', '116'], 'value': '+='},{'id': '111', 'type': 'subscript', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'arg_counts'},{'id': '113', 'type': 'tuple', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'subj'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '116', 'type': 'call', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': '_count'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '120', 'type': 'else_clause', 'children': ['121']},{'id': '121', 'type': 'block', 'children': ['122']},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'augmented_assignment', 'children': ['124', '131'], 'value': '+='},{'id': '124', 'type': 'subscript', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'arg_counts'},{'id': '126', 'type': 'subscript', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '128', 'type': 'slice', 'children': ['129', '130']},{'id': '129', 'type': 'integer', 'children': [], 'value': '1'},{'id': '130', 'type': 'colon', 'children': []},{'id': '131', 'type': 'call', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': '_count'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '135', 'type': 'function_definition', 'children': ['136', '137', '139']},{'id': '136', 'type': 'function_name', 'children': [], 'value': 'process_rows'},{'id': '137', 'type': 'parameters', 'children': ['138']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'stmt_rows'},{'id': '139', 'type': 'block', 'children': ['140']},{'id': '140', 'type': 'for_statement', 'children': ['141', '144', '149']},{'id': '141', 'type': 'pattern_list', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '144', 'type': 'call', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'stmt_rows'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '148', 'type': 'argument_list', 'children': []},{'id': '149', 'type': 'block', 'children': ['150', '156', '164', '170', '176', '220', '228', '261']},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'verb'},{'id': '153', 'type': 'subscript', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '155', 'type': 'integer', 'children': [], 'value': '0'},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'assignment', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'inps'},{'id': '159', 'type': 'subscript', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '161', 'type': 'slice', 'children': ['162', '163']},{'id': '162', 'type': 'integer', 'children': [], 'value': '1'},{'id': '163', 'type': 'colon', 'children': []},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'assignment', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'sub_count'},{'id': '167', 'type': 'subscript', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'stmt_counts'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'assignment', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'arg_count'},{'id': '173', 'type': 'subscript', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'arg_counts'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'inps'},{'id': '176', 'type': 'if_statement', 'children': ['177', '191']},{'id': '177', 'type': 'boolean_operator', 'children': ['178', '185'], 'value': 'and'},{'id': '178', 'type': 'boolean_operator', 'children': ['179', '182'], 'value': 'and'},{'id': '179', 'type': 'comparison_operator', 'children': ['180', '181'], 'value': '=='},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'verb'},{'id': '181', 'type': 'string', 'children': [], 'value': "'Complex'"},{'id': '182', 'type': 'comparison_operator', 'children': ['183', '184'], 'value': '=='},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'sub_count'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'arg_count'},{'id': '185', 'type': 'comparison_operator', 'children': ['186', '190'], 'value': '<='},{'id': '186', 'type': 'call', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'inps'},{'id': '190', 'type': 'integer', 'children': [], 'value': '2'},{'id': '191', 'type': 'block', 'children': ['192']},{'id': '192', 'type': 'if_statement', 'children': ['193', '218']},{'id': '193', 'type': 'call', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '195', 'type': 'argument_list', 'children': ['196']},{'id': '196', 'type': 'list_comprehension', 'children': ['197', '215']},{'id': '197', 'type': 'comparison_operator', 'children': ['198', '214'], 'value': '>'},{'id': '198', 'type': 'call', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '200', 'type': 'argument_list', 'children': ['201']},{'id': '201', 'type': 'call', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '203', 'type': 'generator_expression', 'children': ['204', '207']},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'ag'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '207', 'type': 'for_in_clause', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'ag'},{'id': '209', 'type': 'call', 'children': ['210', '213']},{'id': '210', 'type': 'attribute', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'agent_list'},{'id': '213', 'type': 'argument_list', 'children': []},{'id': '214', 'type': 'integer', 'children': [], 'value': '2'},{'id': '215', 'type': 'for_in_clause', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '218', 'type': 'block', 'children': ['219']},{'id': '219', 'type': 'continue_statement', 'children': []},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'assignment', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'new_key'},{'id': '223', 'type': 'tuple', 'children': ['224', '225', '226', '227']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'arg_count'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'inps'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'sub_count'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'verb'},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'assignment', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '231', 'type': 'call', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '233', 'type': 'argument_list', 'children': ['234', '235', '258']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '235', 'type': 'keyword_argument', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '237', 'type': 'lambda', 'children': ['238', '240']},{'id': '238', 'type': 'lambda_parameters', 'children': ['239']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '240', 'type': 'binary_operator', 'children': ['241', '245'], 'value': '+'},{'id': '241', 'type': 'call', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': '_count'},{'id': '243', 'type': 'argument_list', 'children': ['244']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '245', 'type': 'binary_operator', 'children': ['246', '247'], 'value': '/'},{'id': '246', 'type': 'integer', 'children': [], 'value': '1'},{'id': '247', 'type': '()', 'children': ['248']},{'id': '248', 'type': 'binary_operator', 'children': ['249', '250'], 'value': '+'},{'id': '249', 'type': 'integer', 'children': [], 'value': '1'},{'id': '250', 'type': 'call', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '252', 'type': 'argument_list', 'children': ['253']},{'id': '253', 'type': 'call', 'children': ['254', '257']},{'id': '254', 'type': 'attribute', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'agent_list'},{'id': '257', 'type': 'argument_list', 'children': []},{'id': '258', 'type': 'keyword_argument', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '260', 'type': 'True', 'children': []},{'id': '261', 'type': 'expression_statement', 'children': ['262']},{'id': '262', 'type': 'yield', 'children': ['263']},{'id': '263', 'type': 'expression_list', 'children': ['264', '265', '266']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'new_key'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'verb'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '267', 'type': 'expression_statement', 'children': ['268']},{'id': '268', 'type': 'assignment', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'sorted_groups'},{'id': '270', 'type': 'call', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '272', 'type': 'argument_list', 'children': ['273', '277', '285']},{'id': '273', 'type': 'call', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'process_rows'},{'id': '275', 'type': 'argument_list', 'children': ['276']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'stmt_rows'},{'id': '277', 'type': 'keyword_argument', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '279', 'type': 'lambda', 'children': ['280', '282']},{'id': '280', 'type': 'lambda_parameters', 'children': ['281']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'tpl'},{'id': '282', 'type': 'subscript', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'tpl'},{'id': '284', 'type': 'integer', 'children': [], 'value': '0'},{'id': '285', 'type': 'keyword_argument', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '287', 'type': 'True', 'children': []},{'id': '288', 'type': 'return_statement', 'children': ['289']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'sorted_groups'} | def group_and_sort_statements(stmt_list, ev_totals=None):
def _count(stmt):
if ev_totals is None:
return len(stmt.evidence)
else:
return ev_totals[stmt.get_hash()]
stmt_rows = defaultdict(list)
stmt_counts = defaultdict(lambda: 0)
arg_counts = defaultdict(lambda: 0)
for key, s in _get_keyed_stmts(stmt_list):
stmt_rows[key].append(s)
stmt_counts[key] += _count(s)
if key[0] == 'Conversion':
subj = key[1]
for obj in key[2] + key[3]:
arg_counts[(subj, obj)] += _count(s)
else:
arg_counts[key[1:]] += _count(s)
def process_rows(stmt_rows):
for key, stmts in stmt_rows.items():
verb = key[0]
inps = key[1:]
sub_count = stmt_counts[key]
arg_count = arg_counts[inps]
if verb == 'Complex' and sub_count == arg_count and len(inps) <= 2:
if all([len(set(ag.name for ag in s.agent_list())) > 2
for s in stmts]):
continue
new_key = (arg_count, inps, sub_count, verb)
stmts = sorted(stmts,
key=lambda s: _count(s) + 1/(1+len(s.agent_list())),
reverse=True)
yield new_key, verb, stmts
sorted_groups = sorted(process_rows(stmt_rows),
key=lambda tpl: tpl[0], reverse=True)
return sorted_groups |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'make_stmt_from_sort_key'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'verb'},{'id': '6', 'type': 'block', 'children': ['7', '28', '35', '44', '144']},{'id': '7', 'type': 'function_definition', 'children': ['8', '9', '11']},{'id': '8', 'type': 'function_name', 'children': [], 'value': 'make_agent'},{'id': '9', 'type': 'parameters', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '11', 'type': 'block', 'children': ['12', '23']},{'id': '12', 'type': 'if_statement', 'children': ['13', '20']},{'id': '13', 'type': 'boolean_operator', 'children': ['14', '17'], 'value': 'or'},{'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': '=='},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '16', 'type': 'string', 'children': [], 'value': "'None'"},{'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': 'is'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'return_statement', 'children': ['22']},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'return_statement', 'children': ['24']},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'Agent'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'StmtClass'},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'get_statement_by_name'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'verb'},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'inps'},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'subscript', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '43', 'type': 'integer', 'children': [], 'value': '1'},{'id': '44', 'type': 'if_statement', 'children': ['45', '48', '63', '100', '127']},{'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': '=='},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'verb'},{'id': '47', 'type': 'string', 'children': [], 'value': "'Complex'"},{'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': 'stmt'},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'StmtClass'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'list_comprehension', 'children': ['56', '60']},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'make_agent'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '60', 'type': 'for_in_clause', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'inps'},{'id': '63', 'type': 'elif_clause', 'children': ['64', '67']},{'id': '64', 'type': 'comparison_operator', 'children': ['65', '66'], 'value': '=='},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'verb'},{'id': '66', 'type': 'string', 'children': [], 'value': "'Conversion'"},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'StmtClass'},{'id': '73', 'type': 'argument_list', 'children': ['74', '80', '90']},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'make_agent'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'subscript', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'inps'},{'id': '79', 'type': 'integer', 'children': [], 'value': '0'},{'id': '80', 'type': 'list_comprehension', 'children': ['81', '85']},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'make_agent'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '85', 'type': 'for_in_clause', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '87', 'type': 'subscript', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'inps'},{'id': '89', 'type': 'integer', 'children': [], 'value': '1'},{'id': '90', 'type': 'list_comprehension', 'children': ['91', '95']},{'id': '91', 'type': 'call', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'make_agent'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '95', 'type': 'for_in_clause', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '97', 'type': 'subscript', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'inps'},{'id': '99', 'type': 'integer', 'children': [], 'value': '2'},{'id': '100', 'type': 'elif_clause', 'children': ['101', '108']},{'id': '101', 'type': 'boolean_operator', 'children': ['102', '105'], 'value': 'or'},{'id': '102', 'type': 'comparison_operator', 'children': ['103', '104'], 'value': '=='},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'verb'},{'id': '104', 'type': 'string', 'children': [], 'value': "'ActiveForm'"},{'id': '105', 'type': 'comparison_operator', 'children': ['106', '107'], 'value': '=='},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'verb'},{'id': '107', 'type': 'string', 'children': [], 'value': "'HasActivity'"},{'id': '108', 'type': 'block', 'children': ['109']},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'StmtClass'},{'id': '114', 'type': 'argument_list', 'children': ['115', '121', '124']},{'id': '115', 'type': 'call', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'make_agent'},{'id': '117', 'type': 'argument_list', 'children': ['118']},{'id': '118', 'type': 'subscript', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'inps'},{'id': '120', 'type': 'integer', 'children': [], 'value': '0'},{'id': '121', 'type': 'subscript', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'inps'},{'id': '123', 'type': 'integer', 'children': [], 'value': '1'},{'id': '124', 'type': 'subscript', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'inps'},{'id': '126', 'type': 'integer', 'children': [], 'value': '2'},{'id': '127', 'type': 'else_clause', 'children': ['128']},{'id': '128', 'type': 'block', 'children': ['129']},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'assignment', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '132', 'type': 'call', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'StmtClass'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'list_splat', 'children': ['136']},{'id': '136', 'type': 'list_comprehension', 'children': ['137', '141']},{'id': '137', 'type': 'call', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'make_agent'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '141', 'type': 'for_in_clause', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'inps'},{'id': '144', 'type': 'return_statement', 'children': ['145']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'stmt'} | def make_stmt_from_sort_key(key, verb):
def make_agent(name):
if name == 'None' or name is None:
return None
return Agent(name)
StmtClass = get_statement_by_name(verb)
inps = list(key[1])
if verb == 'Complex':
stmt = StmtClass([make_agent(name) for name in inps])
elif verb == 'Conversion':
stmt = StmtClass(make_agent(inps[0]),
[make_agent(name) for name in inps[1]],
[make_agent(name) for name in inps[2]])
elif verb == 'ActiveForm' or verb == 'HasActivity':
stmt = StmtClass(make_agent(inps[0]), inps[1], inps[2])
else:
stmt = StmtClass(*[make_agent(name) for name in inps])
return stmt |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'print_boolean_net'},{'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': 'out_file'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '13', '41', '45', '259', '267', '291']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'init_str'},{'id': '12', 'type': 'string', 'children': [], 'value': "''"},{'id': '13', 'type': 'for_statement', 'children': ['14', '15', '22']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'node_key'},{'id': '15', 'type': 'call', 'children': ['16', '21']},{'id': '16', 'type': 'attribute', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '21', 'type': 'argument_list', 'children': []},{'id': '22', 'type': 'block', 'children': ['23', '35']},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'node_name'},{'id': '26', 'type': 'subscript', 'children': ['27', '34']},{'id': '27', 'type': 'subscript', 'children': ['28', '33']},{'id': '28', 'type': 'attribute', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'node_key'},{'id': '34', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'augmented_assignment', 'children': ['37', '38'], 'value': '+='},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'init_str'},{'id': '38', 'type': 'binary_operator', 'children': ['39', '40'], 'value': '%'},{'id': '39', 'type': 'string', 'children': [], 'value': "'%s = False\\n'"},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'node_name'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'rule_str'},{'id': '44', 'type': 'string', 'children': [], 'value': "''"},{'id': '45', 'type': 'for_statement', 'children': ['46', '47', '54']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'node_key'},{'id': '47', 'type': 'call', 'children': ['48', '53']},{'id': '48', 'type': 'attribute', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '53', 'type': 'argument_list', 'children': []},{'id': '54', 'type': 'block', 'children': ['55', '67', '78', '83', '93', '113', '131', '149', '153', '172', '181', '185', '204', '213', '247', '255']},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'node_name'},{'id': '58', 'type': 'subscript', 'children': ['59', '66']},{'id': '59', 'type': 'subscript', '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': 'graph'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'node_key'},{'id': '66', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'in_edges'},{'id': '70', 'type': 'call', 'children': ['71', '76']},{'id': '71', 'type': 'attribute', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'in_edges'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'node_key'},{'id': '78', 'type': 'if_statement', 'children': ['79', '81']},{'id': '79', 'type': 'not_operator', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'in_edges'},{'id': '81', 'type': 'block', 'children': ['82']},{'id': '82', 'type': 'continue_statement', 'children': []},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'parents'},{'id': '86', 'type': 'list_comprehension', 'children': ['87', '90']},{'id': '87', 'type': 'subscript', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '89', 'type': 'integer', 'children': [], 'value': '0'},{'id': '90', 'type': 'for_in_clause', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'in_edges'},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'polarities'},{'id': '96', 'type': 'list_comprehension', 'children': ['97', '110']},{'id': '97', 'type': 'subscript', 'children': ['98', '109']},{'id': '98', 'type': 'subscript', 'children': ['99', '108']},{'id': '99', 'type': 'subscript', 'children': ['100', '105']},{'id': '100', 'type': 'attribute', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'edge'},{'id': '105', 'type': 'subscript', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '107', 'type': 'integer', 'children': [], 'value': '0'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'node_key'},{'id': '109', 'type': 'string', 'children': [], 'value': "'polarity'"},{'id': '110', 'type': 'for_in_clause', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'in_edges'},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'pos_parents'},{'id': '116', 'type': 'list_comprehension', 'children': ['117', '118', '127']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'par'},{'id': '118', 'type': 'for_in_clause', 'children': ['119', '122']},{'id': '119', 'type': 'pattern_list', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'par'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'pol'},{'id': '122', 'type': 'call', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '124', 'type': 'argument_list', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'parents'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'polarities'},{'id': '127', 'type': 'if_clause', 'children': ['128']},{'id': '128', 'type': 'comparison_operator', 'children': ['129', '130'], 'value': '=='},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'pol'},{'id': '130', 'type': 'string', 'children': [], 'value': "'positive'"},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'neg_parents'},{'id': '134', 'type': 'list_comprehension', 'children': ['135', '136', '145']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'par'},{'id': '136', 'type': 'for_in_clause', 'children': ['137', '140']},{'id': '137', 'type': 'pattern_list', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'par'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'pol'},{'id': '140', 'type': 'call', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '142', 'type': 'argument_list', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'parents'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'polarities'},{'id': '145', 'type': 'if_clause', 'children': ['146']},{'id': '146', 'type': 'comparison_operator', 'children': ['147', '148'], 'value': '=='},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'pol'},{'id': '148', 'type': 'string', 'children': [], 'value': "'negative'"},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'rhs_pos_parts'},{'id': '152', 'type': 'list', 'children': [], 'value': '[]'},{'id': '153', 'type': 'for_statement', 'children': ['154', '155', '156']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'par'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'pos_parents'},{'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': 'rhs_pos_parts'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'subscript', 'children': ['164', '171']},{'id': '164', 'type': 'subscript', 'children': ['165', '170']},{'id': '165', 'type': 'attribute', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'par'},{'id': '171', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'assignment', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'rhs_pos_str'},{'id': '175', 'type': 'call', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'string', 'children': [], 'value': "' or '"},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'rhs_pos_parts'},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'assignment', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'rhs_neg_parts'},{'id': '184', 'type': 'list', 'children': [], 'value': '[]'},{'id': '185', 'type': 'for_statement', 'children': ['186', '187', '188']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'par'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'neg_parents'},{'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': 'rhs_neg_parts'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '194', 'type': 'argument_list', 'children': ['195']},{'id': '195', 'type': 'subscript', 'children': ['196', '203']},{'id': '196', 'type': 'subscript', 'children': ['197', '202']},{'id': '197', 'type': 'attribute', 'children': ['198', '201']},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'par'},{'id': '203', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'assignment', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'rhs_neg_str'},{'id': '207', 'type': 'call', 'children': ['208', '211']},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'string', 'children': [], 'value': "' or '"},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '211', 'type': 'argument_list', 'children': ['212']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'rhs_neg_parts'},{'id': '213', 'type': 'if_statement', 'children': ['214', '215', '237']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'rhs_pos_str'},{'id': '215', 'type': 'block', 'children': ['216']},{'id': '216', 'type': 'if_statement', 'children': ['217', '218', '231']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'rhs_neg_str'},{'id': '218', 'type': 'block', 'children': ['219']},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'assignment', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'rhs_str'},{'id': '222', 'type': 'binary_operator', 'children': ['223', '230'], 'value': '+'},{'id': '223', 'type': 'binary_operator', 'children': ['224', '229'], 'value': '+'},{'id': '224', 'type': 'binary_operator', 'children': ['225', '228'], 'value': '+'},{'id': '225', 'type': 'binary_operator', 'children': ['226', '227'], 'value': '+'},{'id': '226', 'type': 'string', 'children': [], 'value': "'('"},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'rhs_pos_str'},{'id': '228', 'type': 'string', 'children': [], 'value': "') and not ('"},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'rhs_neg_str'},{'id': '230', 'type': 'string', 'children': [], 'value': "')'"},{'id': '231', 'type': 'else_clause', 'children': ['232']},{'id': '232', 'type': 'block', 'children': ['233']},{'id': '233', 'type': 'expression_statement', 'children': ['234']},{'id': '234', 'type': 'assignment', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'rhs_str'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'rhs_pos_str'},{'id': '237', 'type': 'else_clause', 'children': ['238']},{'id': '238', 'type': 'block', 'children': ['239']},{'id': '239', 'type': 'expression_statement', 'children': ['240']},{'id': '240', 'type': 'assignment', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'rhs_str'},{'id': '242', 'type': 'binary_operator', 'children': ['243', '246'], 'value': '+'},{'id': '243', 'type': 'binary_operator', 'children': ['244', '245'], 'value': '+'},{'id': '244', 'type': 'string', 'children': [], 'value': "'not ('"},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'rhs_neg_str'},{'id': '246', 'type': 'string', 'children': [], 'value': "')'"},{'id': '247', 'type': 'expression_statement', 'children': ['248']},{'id': '248', 'type': 'assignment', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'node_eq'},{'id': '250', 'type': 'binary_operator', 'children': ['251', '252'], 'value': '%'},{'id': '251', 'type': 'string', 'children': [], 'value': "'%s* = %s\\n'"},{'id': '252', 'type': 'tuple', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'node_name'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'rhs_str'},{'id': '255', 'type': 'expression_statement', 'children': ['256']},{'id': '256', 'type': 'augmented_assignment', 'children': ['257', '258'], 'value': '+='},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'rule_str'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'node_eq'},{'id': '259', 'type': 'expression_statement', 'children': ['260']},{'id': '260', 'type': 'assignment', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'full_str'},{'id': '262', 'type': 'binary_operator', 'children': ['263', '266'], 'value': '+'},{'id': '263', 'type': 'binary_operator', 'children': ['264', '265'], 'value': '+'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'init_str'},{'id': '265', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'rule_str'},{'id': '267', 'type': 'if_statement', 'children': ['268', '271']},{'id': '268', 'type': 'comparison_operator', 'children': ['269', '270'], 'value': 'is'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '270', 'type': 'None', 'children': []},{'id': '271', 'type': 'block', 'children': ['272']},{'id': '272', 'type': 'with_statement', 'children': ['273', '283']},{'id': '273', 'type': 'with_clause', 'children': ['274']},{'id': '274', 'type': 'with_item', 'children': ['275']},{'id': '275', 'type': 'as_pattern', 'children': ['276', '281']},{'id': '276', 'type': 'call', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '278', 'type': 'argument_list', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '280', 'type': 'string', 'children': [], 'value': "'wt'"},{'id': '281', 'type': 'as_pattern_target', 'children': ['282']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'fh'},{'id': '283', 'type': 'block', 'children': ['284']},{'id': '284', 'type': 'expression_statement', 'children': ['285']},{'id': '285', 'type': 'call', 'children': ['286', '289']},{'id': '286', 'type': 'attribute', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'fh'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '289', 'type': 'argument_list', 'children': ['290']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'full_str'},{'id': '291', 'type': 'return_statement', 'children': ['292']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'full_str'} | def print_boolean_net(self, out_file=None):
init_str = ''
for node_key in self.graph.nodes():
node_name = self.graph.node[node_key]['name']
init_str += '%s = False\n' % node_name
rule_str = ''
for node_key in self.graph.nodes():
node_name = self.graph.node[node_key]['name']
in_edges = self.graph.in_edges(node_key)
if not in_edges:
continue
parents = [e[0] for e in in_edges]
polarities = [self.graph.edge[e[0]][node_key]['polarity']
for e in in_edges]
pos_parents = [par for par, pol in zip(parents, polarities) if
pol == 'positive']
neg_parents = [par for par, pol in zip(parents, polarities) if
pol == 'negative']
rhs_pos_parts = []
for par in pos_parents:
rhs_pos_parts.append(self.graph.node[par]['name'])
rhs_pos_str = ' or '.join(rhs_pos_parts)
rhs_neg_parts = []
for par in neg_parents:
rhs_neg_parts.append(self.graph.node[par]['name'])
rhs_neg_str = ' or '.join(rhs_neg_parts)
if rhs_pos_str:
if rhs_neg_str:
rhs_str = '(' + rhs_pos_str + \
') and not (' + rhs_neg_str + ')'
else:
rhs_str = rhs_pos_str
else:
rhs_str = 'not (' + rhs_neg_str + ')'
node_eq = '%s* = %s\n' % (node_name, rhs_str)
rule_str += node_eq
full_str = init_str + '\n' + rule_str
if out_file is not None:
with open(out_file, 'wt') as fh:
fh.write(full_str)
return full_str |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_complex_agents'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'complex_id'},{'id': '6', 'type': 'block', 'children': ['7', '11', '20', '146']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'agents'},{'id': '10', 'type': 'list', 'children': [], 'value': '[]'},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'components'},{'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': '_recursively_lookup_complex'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'complex_id'},{'id': '20', 'type': 'for_statement', 'children': ['21', '22', '23']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'components'},{'id': '23', 'type': 'block', 'children': ['24', '28', '37', '74', '80', '128', '133']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'db_refs'},{'id': '27', 'type': 'dictionary', 'children': []},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'uniprot_client'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'get_gene_name'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '37', 'type': 'if_statement', 'children': ['38', '41', '48']},{'id': '38', 'type': 'comparison_operator', 'children': ['39', '40'], 'value': 'is'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'name'},{'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': 'db_refs'},{'id': '46', 'type': 'string', 'children': [], 'value': "'SIGNOR'"},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '48', 'type': 'else_clause', 'children': ['49']},{'id': '49', 'type': 'block', 'children': ['50', '56', '65']},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '55']},{'id': '52', 'type': 'subscript', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'db_refs'},{'id': '54', 'type': 'string', 'children': [], 'value': "'UP'"},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'hgnc_id'},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'hgnc_client'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'get_hgnc_id'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '65', 'type': 'if_statement', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'hgnc_id'},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '73']},{'id': '70', 'type': 'subscript', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'db_refs'},{'id': '72', 'type': 'string', 'children': [], 'value': "'HGNC'"},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'hgnc_id'},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'famplex_key'},{'id': '77', 'type': 'tuple', 'children': ['78', '79']},{'id': '78', 'type': 'string', 'children': [], 'value': "'SIGNOR'"},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '80', 'type': 'if_statement', 'children': ['81', '84', '103']},{'id': '81', 'type': 'comparison_operator', 'children': ['82', '83'], 'value': 'in'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'famplex_key'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'famplex_map'},{'id': '84', 'type': 'block', 'children': ['85', '93']},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '90']},{'id': '87', 'type': 'subscript', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'db_refs'},{'id': '89', 'type': 'string', 'children': [], 'value': "'FPLX'"},{'id': '90', 'type': 'subscript', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'famplex_map'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'famplex_key'},{'id': '93', 'type': 'if_statement', 'children': ['94', '96']},{'id': '94', 'type': 'not_operator', 'children': ['95']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'name'},{'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': 'name'},{'id': '100', 'type': 'subscript', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'db_refs'},{'id': '102', 'type': 'string', 'children': [], 'value': "'FPLX'"},{'id': '103', 'type': 'elif_clause', 'children': ['104', '106']},{'id': '104', 'type': 'not_operator', 'children': ['105']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '106', 'type': 'block', 'children': ['107', '118']},{'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': 'logger'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'binary_operator', 'children': ['114', '117'], 'value': '+'},{'id': '114', 'type': 'binary_operator', 'children': ['115', '116'], 'value': '+'},{'id': '115', 'type': 'string', 'children': [], 'value': "'Have neither a Uniprot nor Famplex grounding '"},{'id': '116', 'type': 'string', 'children': [], 'value': "'for '"},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '118', 'type': 'if_statement', 'children': ['119', '121']},{'id': '119', 'type': 'not_operator', 'children': ['120']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '121', 'type': 'block', 'children': ['122']},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '125', 'type': 'subscript', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'db_refs'},{'id': '127', 'type': 'string', 'children': [], 'value': "'SIGNOR'"},{'id': '128', 'type': 'assert_statement', 'children': ['129']},{'id': '129', 'type': '()', 'children': ['130']},{'id': '130', 'type': 'comparison_operator', 'children': ['131', '132'], 'value': 'is'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '132', 'type': 'None', 'children': []},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'call', 'children': ['135', '138']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'agents'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'call', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'Agent'},{'id': '141', 'type': 'argument_list', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '143', 'type': 'keyword_argument', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'db_refs'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'db_refs'},{'id': '146', 'type': 'return_statement', 'children': ['147']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'agents'} | def _get_complex_agents(self, complex_id):
agents = []
components = self._recursively_lookup_complex(complex_id)
for c in components:
db_refs = {}
name = uniprot_client.get_gene_name(c)
if name is None:
db_refs['SIGNOR'] = c
else:
db_refs['UP'] = c
hgnc_id = hgnc_client.get_hgnc_id(name)
if hgnc_id:
db_refs['HGNC'] = hgnc_id
famplex_key = ('SIGNOR', c)
if famplex_key in famplex_map:
db_refs['FPLX'] = famplex_map[famplex_key]
if not name:
name = db_refs['FPLX']
elif not name:
logger.info('Have neither a Uniprot nor Famplex grounding ' + \
'for ' + c)
if not name:
name = db_refs['SIGNOR']
assert(name is not None)
agents.append(Agent(name, db_refs=db_refs))
return agents |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_args'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '5', 'type': 'block', 'children': ['6', '10', '40', '81', '162', '171', '192']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'arg_roles'},{'id': '9', 'type': 'dictionary', 'children': []},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '13', 'type': 'binary_operator', 'children': ['14', '20', '21'], 'value': '+'},{'id': '14', 'type': 'call', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'findall'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'string', 'children': [], 'value': "'arg'"},{'id': '20', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '21', 'type': 'list', 'children': ['22', '28', '34'], 'value': "[node.find('arg1'), node.find('arg2'), node.find('arg3')]"},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'string', 'children': [], 'value': "'arg1'"},{'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': 'find'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'string', 'children': [], 'value': "'arg2'"},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'string', 'children': [], 'value': "'arg3'"},{'id': '40', 'type': 'for_statement', 'children': ['41', '42', '43']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'if_statement', 'children': ['45', '48']},{'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': 'is'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '47', 'type': 'None', 'children': []},{'id': '48', 'type': 'block', 'children': ['49', '60']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'id'},{'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': 'arg'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '60', 'type': 'if_statement', 'children': ['61', '64']},{'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': 'is'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '63', 'type': 'None', 'children': []},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '74']},{'id': '67', 'type': 'subscript', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'arg_roles'},{'id': '69', 'type': 'subscript', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '73', 'type': 'string', 'children': [], 'value': "'role'"},{'id': '74', 'type': 'tuple', 'children': ['75', '80']},{'id': '75', 'type': 'subscript', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '79', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '81', 'type': 'if_statement', 'children': ['82', '90']},{'id': '82', 'type': 'comparison_operator', 'children': ['83', '89'], 'value': 'is'},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'string', 'children': [], 'value': "'features'"},{'id': '89', 'type': 'None', 'children': []},{'id': '90', 'type': 'block', 'children': ['91', '100', '123', '139']},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'inevents'},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'findall'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'string', 'children': [], 'value': "'features/inevent'"},{'id': '100', 'type': 'for_statement', 'children': ['101', '102', '103']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'inevent'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'inevents'},{'id': '103', 'type': 'block', 'children': ['104']},{'id': '104', 'type': 'if_statement', 'children': ['105', '110']},{'id': '105', 'type': 'comparison_operator', 'children': ['106', '107'], 'value': 'in'},{'id': '106', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'inevent'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '110', 'type': 'block', 'children': ['111']},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '116']},{'id': '113', 'type': 'subscript', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'arg_roles'},{'id': '115', 'type': 'string', 'children': [], 'value': "'inevent'"},{'id': '116', 'type': 'tuple', 'children': ['117', '122']},{'id': '117', 'type': 'subscript', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'inevent'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '121', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'inevent'},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'assignment', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'ptms'},{'id': '126', 'type': 'binary_operator', 'children': ['127', '133'], 'value': '+'},{'id': '127', 'type': 'call', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'findall'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'string', 'children': [], 'value': "'features/ptm'"},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'findall'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'string', 'children': [], 'value': "'features/no-ptm'"},{'id': '139', 'type': 'for_statement', 'children': ['140', '141', '142']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'ptm'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'ptms'},{'id': '142', 'type': 'block', 'children': ['143']},{'id': '143', 'type': 'if_statement', 'children': ['144', '149']},{'id': '144', 'type': 'comparison_operator', 'children': ['145', '146'], 'value': 'in'},{'id': '145', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'inevent'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '149', 'type': 'block', 'children': ['150']},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '155']},{'id': '152', 'type': 'subscript', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'arg_roles'},{'id': '154', 'type': 'string', 'children': [], 'value': "'ptm'"},{'id': '155', 'type': 'tuple', 'children': ['156', '161']},{'id': '156', 'type': 'subscript', 'children': ['157', '160']},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'inevent'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '160', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'ptm'},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'assignment', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'aw'},{'id': '165', 'type': 'call', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '169', 'type': 'argument_list', 'children': ['170']},{'id': '170', 'type': 'string', 'children': [], 'value': "'assoc-with'"},{'id': '171', 'type': 'if_statement', 'children': ['172', '175']},{'id': '172', 'type': 'comparison_operator', 'children': ['173', '174'], 'value': 'is'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'aw'},{'id': '174', 'type': 'None', 'children': []},{'id': '175', 'type': 'block', 'children': ['176', '184']},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'assignment', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'aw_id'},{'id': '179', 'type': 'subscript', 'children': ['180', '183']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'aw'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '183', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '184', 'type': 'expression_statement', 'children': ['185']},{'id': '185', 'type': 'assignment', 'children': ['186', '189']},{'id': '186', 'type': 'subscript', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'arg_roles'},{'id': '188', 'type': 'string', 'children': [], 'value': "'assoc-with'"},{'id': '189', 'type': 'tuple', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'aw_id'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'aw'},{'id': '192', 'type': 'return_statement', 'children': ['193']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'arg_roles'} | def get_args(node):
arg_roles = {}
args = node.findall('arg') + \
[node.find('arg1'), node.find('arg2'), node.find('arg3')]
for arg in args:
if arg is not None:
id = arg.attrib.get('id')
if id is not None:
arg_roles[arg.attrib['role']] = (arg.attrib['id'], arg)
if node.find('features') is not None:
inevents = node.findall('features/inevent')
for inevent in inevents:
if 'id' in inevent.attrib:
arg_roles['inevent'] = (inevent.attrib['id'], inevent)
ptms = node.findall('features/ptm') + node.findall('features/no-ptm')
for ptm in ptms:
if 'id' in inevent.attrib:
arg_roles['ptm'] = (inevent.attrib['id'], ptm)
aw = node.find('assoc-with')
if aw is not None:
aw_id = aw.attrib['id']
arg_roles['assoc-with'] = (aw_id, aw)
return arg_roles |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'map_statements'},{'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': 'stmt'},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'statements'},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'for_statement', 'children': ['13', '14', '19']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '14', 'type': 'call', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'agent_list'},{'id': '18', 'type': 'argument_list', 'children': []},{'id': '19', 'type': 'block', 'children': ['20', '26', '30', '71']},{'id': '20', 'type': 'if_statement', 'children': ['21', '24']},{'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': 'is'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '23', 'type': 'None', 'children': []},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'continue_statement', 'children': []},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'all_mappings'},{'id': '29', 'type': 'list', 'children': [], 'value': '[]'},{'id': '30', 'type': 'for_statement', 'children': ['31', '34', '41']},{'id': '31', 'type': 'pattern_list', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'db_name'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'db_id'},{'id': '34', 'type': 'call', 'children': ['35', '40']},{'id': '35', 'type': 'attribute', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'db_refs'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '40', 'type': 'argument_list', 'children': []},{'id': '41', 'type': 'block', 'children': ['42', '57', '67']},{'id': '42', 'type': 'if_statement', 'children': ['43', '48']},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '45', 'type': 'argument_list', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'db_id'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'list'},{'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': 'db_id'},{'id': '52', 'type': 'subscript', 'children': ['53', '56']},{'id': '53', 'type': 'subscript', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'db_id'},{'id': '55', 'type': 'integer', 'children': [], 'value': '0'},{'id': '56', 'type': 'integer', 'children': [], 'value': '0'},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'mappings'},{'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': '_map_id'},{'id': '64', 'type': 'argument_list', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'db_name'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'db_id'},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'augmented_assignment', 'children': ['69', '70'], 'value': '+='},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'all_mappings'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'mappings'},{'id': '71', 'type': 'for_statement', 'children': ['72', '77', '78']},{'id': '72', 'type': 'pattern_list', 'children': ['73', '74', '75', '76']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'map_db_name'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'map_db_id'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'orig_db_name'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'all_mappings'},{'id': '78', 'type': 'block', 'children': ['79', '87']},{'id': '79', 'type': 'if_statement', 'children': ['80', '85']},{'id': '80', 'type': 'comparison_operator', 'children': ['81', '82'], 'value': 'in'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'map_db_name'},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'db_refs'},{'id': '85', 'type': 'block', 'children': ['86']},{'id': '86', 'type': 'continue_statement', 'children': []},{'id': '87', 'type': 'if_statement', 'children': ['88', '91', '127']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'scored'},{'id': '91', 'type': 'block', 'children': ['92', '113']},{'id': '92', 'type': 'try_statement', 'children': ['93', '106']},{'id': '93', 'type': 'block', 'children': ['94']},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'orig_score'},{'id': '97', 'type': 'subscript', 'children': ['98', '105']},{'id': '98', 'type': 'subscript', 'children': ['99', '104']},{'id': '99', 'type': 'subscript', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'db_refs'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'orig_db_name'},{'id': '104', 'type': 'integer', 'children': [], 'value': '0'},{'id': '105', 'type': 'integer', 'children': [], 'value': '1'},{'id': '106', 'type': 'except_clause', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '108', 'type': 'block', 'children': ['109']},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'orig_score'},{'id': '112', 'type': 'float', 'children': [], 'value': '1.0'},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '120', '121']},{'id': '115', 'type': 'subscript', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'db_refs'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'map_db_name'},{'id': '120', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '121', 'type': 'list', 'children': ['122'], 'value': '[(map_db_id, score * orig_score)]'},{'id': '122', 'type': 'tuple', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'map_db_id'},{'id': '124', 'type': 'binary_operator', 'children': ['125', '126'], 'value': '*'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'orig_score'},{'id': '127', 'type': 'else_clause', 'children': ['128']},{'id': '128', 'type': 'block', 'children': ['129']},{'id': '129', 'type': 'if_statement', 'children': ['130', '135', '147']},{'id': '130', 'type': 'comparison_operator', 'children': ['131', '132'], 'value': 'in'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'map_db_name'},{'id': '132', 'type': 'tuple', 'children': ['133', '134']},{'id': '133', 'type': 'string', 'children': [], 'value': "'UN'"},{'id': '134', 'type': 'string', 'children': [], 'value': "'HUME'"},{'id': '135', 'type': 'block', 'children': ['136']},{'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': 'agent'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'db_refs'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'map_db_name'},{'id': '143', 'type': 'list', 'children': ['144'], 'value': '[(map_db_id, 1.0)]'},{'id': '144', 'type': 'tuple', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'map_db_id'},{'id': '146', 'type': 'float', 'children': [], 'value': '1.0'},{'id': '147', 'type': 'else_clause', 'children': ['148']},{'id': '148', 'type': 'block', 'children': ['149']},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '156']},{'id': '151', 'type': 'subscript', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'db_refs'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'map_db_name'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'map_db_id'} | def map_statements(self):
for stmt in self.statements:
for agent in stmt.agent_list():
if agent is None:
continue
all_mappings = []
for db_name, db_id in agent.db_refs.items():
if isinstance(db_id, list):
db_id = db_id[0][0]
mappings = self._map_id(db_name, db_id)
all_mappings += mappings
for map_db_name, map_db_id, score, orig_db_name in all_mappings:
if map_db_name in agent.db_refs:
continue
if self.scored:
try:
orig_score = agent.db_refs[orig_db_name][0][1]
except Exception:
orig_score = 1.0
agent.db_refs[map_db_name] = \
[(map_db_id, score * orig_score)]
else:
if map_db_name in ('UN', 'HUME'):
agent.db_refs[map_db_name] = [(map_db_id, 1.0)]
else:
agent.db_refs[map_db_name] = map_db_id |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'agent_texts_with_grounding'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '5', 'type': 'block', 'children': ['6', '13', '44', '61', '68', '89', '108', '112', '249', '266']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'allag'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'all_agents'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '13', 'type': 'for_statement', 'children': ['14', '15', '16']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'ag'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'allag'},{'id': '16', 'type': 'block', 'children': ['17', '28']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'pfam_def'},{'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': 'ag'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'db_refs'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'string', 'children': [], 'value': "'PFAM-DEF'"},{'id': '28', 'type': 'if_statement', 'children': ['29', '32']},{'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': 'is'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'pfam_def'},{'id': '31', 'type': 'None', 'children': []},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '40']},{'id': '35', 'type': 'subscript', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'ag'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'db_refs'},{'id': '39', 'type': 'string', 'children': [], 'value': "'PFAM-DEF'"},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'pfam_def'},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'refs'},{'id': '47', 'type': 'list_comprehension', 'children': ['48', '58']},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '50', 'type': 'argument_list', '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': 'ag'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'db_refs'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '57', 'type': 'argument_list', 'children': []},{'id': '58', 'type': 'for_in_clause', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'ag'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'allag'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'refs_counter'},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'Counter'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'refs'},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'refs_counter_dict'},{'id': '71', 'type': 'list_comprehension', 'children': ['72', '82']},{'id': '72', 'type': 'tuple', 'children': ['73', '79']},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'subscript', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '78', 'type': 'integer', 'children': [], 'value': '0'},{'id': '79', 'type': 'subscript', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '81', 'type': 'integer', 'children': [], 'value': '1'},{'id': '82', 'type': 'for_in_clause', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '84', 'type': 'call', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'refs_counter'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '88', 'type': 'argument_list', 'children': []},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'refs_counter_dict'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'keyword_argument', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '97', 'type': 'lambda', 'children': ['98', '100']},{'id': '98', 'type': 'lambda_parameters', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '100', 'type': 'call', 'children': ['101', '106']},{'id': '101', 'type': 'attribute', 'children': ['102', '105']},{'id': '102', 'type': 'subscript', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '104', 'type': 'integer', 'children': [], 'value': '0'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'string', 'children': [], 'value': "'TEXT'"},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'grouped_by_text'},{'id': '111', 'type': 'list', 'children': [], 'value': '[]'},{'id': '112', 'type': 'for_statement', 'children': ['113', '116', '133']},{'id': '113', 'type': 'pattern_list', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '116', 'type': 'call', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'groupby'},{'id': '118', 'type': 'argument_list', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'refs_counter_dict'},{'id': '120', 'type': 'keyword_argument', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '122', 'type': 'lambda', 'children': ['123', '125']},{'id': '123', 'type': 'lambda_parameters', 'children': ['124']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '125', 'type': 'call', 'children': ['126', '131']},{'id': '126', 'type': 'attribute', 'children': ['127', '130']},{'id': '127', 'type': 'subscript', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '129', 'type': 'integer', 'children': [], 'value': '0'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'string', 'children': [], 'value': "'TEXT'"},{'id': '133', 'type': 'block', 'children': ['134', '138', '143', '147', '208', '232', '239']},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'total'},{'id': '137', 'type': 'integer', 'children': [], 'value': '0'},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'assignment', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '141', 'type': 'list', 'children': ['142'], 'value': '[k]'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'db_ref_list'},{'id': '146', 'type': 'list', 'children': [], 'value': '[]'},{'id': '147', 'type': 'for_statement', 'children': ['148', '151', '152']},{'id': '148', 'type': 'pattern_list', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'db_refs'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '152', 'type': 'block', 'children': ['153', '176', '204']},{'id': '153', 'type': 'if_statement', 'children': ['154', '165']},{'id': '154', 'type': 'comparison_operator', 'children': ['155', '163'], 'value': '=='},{'id': '155', 'type': 'call', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'call', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'db_refs'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '162', 'type': 'argument_list', 'children': []},{'id': '163', 'type': 'list', 'children': ['164'], 'value': "['TEXT']"},{'id': '164', 'type': 'string', 'children': [], 'value': "'TEXT'"},{'id': '165', 'type': 'block', 'children': ['166']},{'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': 'db_ref_list'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'tuple', 'children': ['173', '174', '175']},{'id': '173', 'type': 'None', 'children': []},{'id': '174', 'type': 'None', 'children': []},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '176', 'type': 'for_statement', 'children': ['177', '180', '185']},{'id': '177', 'type': 'pattern_list', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'db_id'},{'id': '180', 'type': 'call', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'db_refs'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '184', 'type': 'argument_list', 'children': []},{'id': '185', 'type': 'block', 'children': ['186']},{'id': '186', 'type': 'if_statement', 'children': ['187', '190', '192']},{'id': '187', 'type': 'comparison_operator', 'children': ['188', '189'], 'value': '=='},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '189', 'type': 'string', 'children': [], 'value': "'TEXT'"},{'id': '190', 'type': 'block', 'children': ['191']},{'id': '191', 'type': 'continue_statement', 'children': []},{'id': '192', 'type': 'else_clause', 'children': ['193']},{'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': 'db_ref_list'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '199', 'type': 'argument_list', 'children': ['200']},{'id': '200', 'type': 'tuple', 'children': ['201', '202', '203']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'db_id'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'augmented_assignment', 'children': ['206', '207'], 'value': '+='},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'total'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '208', 'type': 'expression_statement', 'children': ['209']},{'id': '209', 'type': 'call', 'children': ['210', '213']},{'id': '210', 'type': 'attribute', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '213', 'type': 'argument_list', 'children': ['214']},{'id': '214', 'type': 'call', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '216', 'type': 'argument_list', 'children': ['217']},{'id': '217', 'type': 'call', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '219', 'type': 'argument_list', 'children': ['220', '221', '229']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'db_ref_list'},{'id': '221', 'type': 'keyword_argument', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '223', 'type': 'lambda', 'children': ['224', '226']},{'id': '224', 'type': 'lambda_parameters', 'children': ['225']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '226', 'type': 'subscript', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '228', 'type': 'integer', 'children': [], 'value': '2'},{'id': '229', 'type': 'keyword_argument', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '231', 'type': 'True', 'children': []},{'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': 'entry'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '237', 'type': 'argument_list', 'children': ['238']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'total'},{'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': 'grouped_by_text'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '244', 'type': 'argument_list', 'children': ['245']},{'id': '245', 'type': 'call', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '247', 'type': 'argument_list', 'children': ['248']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '249', 'type': 'expression_statement', 'children': ['250']},{'id': '250', 'type': 'call', 'children': ['251', '254']},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'grouped_by_text'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '254', 'type': 'argument_list', 'children': ['255', '263']},{'id': '255', 'type': 'keyword_argument', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '257', 'type': 'lambda', 'children': ['258', '260']},{'id': '258', 'type': 'lambda_parameters', 'children': ['259']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '260', 'type': 'subscript', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '262', 'type': 'integer', 'children': [], 'value': '2'},{'id': '263', 'type': 'keyword_argument', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '265', 'type': 'True', 'children': []},{'id': '266', 'type': 'return_statement', 'children': ['267']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'grouped_by_text'} | def agent_texts_with_grounding(stmts):
allag = all_agents(stmts)
for ag in allag:
pfam_def = ag.db_refs.get('PFAM-DEF')
if pfam_def is not None:
ag.db_refs['PFAM-DEF'] = tuple(pfam_def)
refs = [tuple(ag.db_refs.items()) for ag in allag]
refs_counter = Counter(refs)
refs_counter_dict = [(dict(entry[0]), entry[1])
for entry in refs_counter.items()]
refs_counter_dict.sort(key=lambda x: x[0].get('TEXT'))
grouped_by_text = []
for k, g in groupby(refs_counter_dict, key=lambda x: x[0].get('TEXT')):
total = 0
entry = [k]
db_ref_list = []
for db_refs, count in g:
if list(db_refs.keys()) == ['TEXT']:
db_ref_list.append((None, None, count))
for db, db_id in db_refs.items():
if db == 'TEXT':
continue
else:
db_ref_list.append((db, db_id, count))
total += count
entry.append(tuple(sorted(db_ref_list, key=lambda x: x[2],
reverse=True)))
entry.append(total)
grouped_by_text.append(tuple(entry))
grouped_by_text.sort(key=lambda x: x[2], reverse=True)
return grouped_by_text |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'ungrounded_texts'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '5', 'type': 'block', 'children': ['6', '43', '50', '58', '76']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'ungrounded'},{'id': '9', 'type': 'list_comprehension', 'children': ['10', '15', '18', '25']},{'id': '10', 'type': 'subscript', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'ag'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'db_refs'},{'id': '14', 'type': 'string', 'children': [], 'value': "'TEXT'"},{'id': '15', 'type': 'for_in_clause', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '18', 'type': 'for_in_clause', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'ag'},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'agent_list'},{'id': '24', 'type': 'argument_list', 'children': []},{'id': '25', 'type': 'if_clause', 'children': ['26']},{'id': '26', 'type': 'boolean_operator', 'children': ['27', '30'], 'value': 'and'},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': 'is'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'ag'},{'id': '29', 'type': 'None', 'children': []},{'id': '30', 'type': 'comparison_operator', 'children': ['31', '41'], 'value': '=='},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '40']},{'id': '35', 'type': 'attribute', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'ag'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'db_refs'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '40', 'type': 'argument_list', 'children': []},{'id': '41', 'type': 'list', 'children': ['42'], 'value': "['TEXT']"},{'id': '42', 'type': 'string', 'children': [], 'value': "'TEXT'"},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'ungroundc'},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'Counter'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'ungrounded'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'ungroundc'},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'ungroundc'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '57', 'type': 'argument_list', 'children': []},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'ungroundc'},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '63', 'type': 'argument_list', 'children': ['64', '65', '73']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'ungroundc'},{'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '67', 'type': 'lambda', 'children': ['68', '70']},{'id': '68', 'type': 'lambda_parameters', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '70', 'type': 'subscript', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '72', 'type': 'integer', 'children': [], 'value': '1'},{'id': '73', 'type': 'keyword_argument', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '75', 'type': 'True', 'children': []},{'id': '76', 'type': 'return_statement', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'ungroundc'} | def ungrounded_texts(stmts):
ungrounded = [ag.db_refs['TEXT']
for s in stmts
for ag in s.agent_list()
if ag is not None and list(ag.db_refs.keys()) == ['TEXT']]
ungroundc = Counter(ungrounded)
ungroundc = ungroundc.items()
ungroundc = sorted(ungroundc, key=lambda x: x[1], reverse=True)
return ungroundc |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'protein_map_from_twg'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'twg'},{'id': '5', 'type': 'block', 'children': ['6', '10', '14', '18', '25', '141', '150', '159']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'protein_map'},{'id': '9', 'type': 'dictionary', 'children': []},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'unmatched'},{'id': '13', 'type': 'integer', 'children': [], 'value': '0'},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'matched'},{'id': '17', 'type': 'integer', 'children': [], 'value': '0'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'string', 'children': [], 'value': "'Building grounding map for human proteins'"},{'id': '25', 'type': 'for_statement', 'children': ['26', '30', '31']},{'id': '26', 'type': 'pattern_list', 'children': ['27', '28', '29']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'agent_text'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'grounding_list'},{'id': '29', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'twg'},{'id': '31', 'type': 'block', 'children': ['32', '44', '60']},{'id': '32', 'type': 'if_statement', 'children': ['33', '42']},{'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': 'not'},{'id': '34', 'type': 'string', 'children': [], 'value': "'UP'"},{'id': '35', 'type': 'list_comprehension', 'children': ['36', '39']},{'id': '36', 'type': 'subscript', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '38', 'type': 'integer', 'children': [], 'value': '0'},{'id': '39', 'type': 'for_in_clause', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'grounding_list'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'continue_statement', 'children': []},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'uniprot_ids'},{'id': '47', 'type': 'list_comprehension', 'children': ['48', '51', '54']},{'id': '48', 'type': 'subscript', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '50', 'type': 'integer', 'children': [], 'value': '1'},{'id': '51', 'type': 'for_in_clause', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'grounding_list'},{'id': '54', 'type': 'if_clause', 'children': ['55']},{'id': '55', 'type': 'comparison_operator', 'children': ['56', '59'], 'value': '=='},{'id': '56', 'type': 'subscript', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '58', 'type': 'integer', 'children': [], 'value': '0'},{'id': '59', 'type': 'string', 'children': [], 'value': "'UP'"},{'id': '60', 'type': 'for_statement', 'children': ['61', '62', '63']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'uniprot_id'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'uniprot_ids'},{'id': '63', 'type': 'block', 'children': ['64', '73', '87', '96', '106']},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'mnemonic'},{'id': '67', 'type': 'call', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'uniprot_client'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'get_mnemonic'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'uniprot_id'},{'id': '73', 'type': 'if_statement', 'children': ['74', '85']},{'id': '74', 'type': 'boolean_operator', 'children': ['75', '78'], 'value': 'or'},{'id': '75', 'type': 'comparison_operator', 'children': ['76', '77'], 'value': 'is'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'mnemonic'},{'id': '77', 'type': 'None', 'children': []},{'id': '78', 'type': 'not_operator', 'children': ['79']},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'mnemonic'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'string', 'children': [], 'value': "'_HUMAN'"},{'id': '85', 'type': 'block', 'children': ['86']},{'id': '86', 'type': 'continue_statement', 'children': []},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'gene_name'},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'uniprot_client'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'get_gene_name'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'uniprot_id'},{'id': '96', 'type': 'if_statement', 'children': ['97', '100']},{'id': '97', 'type': 'comparison_operator', 'children': ['98', '99'], 'value': 'is'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'gene_name'},{'id': '99', 'type': 'None', 'children': []},{'id': '100', 'type': 'block', 'children': ['101', '105']},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'augmented_assignment', 'children': ['103', '104'], 'value': '+='},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'unmatched'},{'id': '104', 'type': 'integer', 'children': [], 'value': '1'},{'id': '105', 'type': 'continue_statement', 'children': []},{'id': '106', 'type': 'if_statement', 'children': ['107', '118', '135']},{'id': '107', 'type': 'comparison_operator', 'children': ['108', '113'], 'value': '=='},{'id': '108', 'type': 'call', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'agent_text'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '112', 'type': 'argument_list', 'children': []},{'id': '113', 'type': 'call', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'gene_name'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '117', 'type': 'argument_list', 'children': []},{'id': '118', 'type': 'block', 'children': ['119', '123']},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'augmented_assignment', 'children': ['121', '122'], 'value': '+='},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'matched'},{'id': '122', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'protein_map'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'agent_text'},{'id': '128', 'type': 'dictionary', 'children': ['129', '132']},{'id': '129', 'type': 'pair', 'children': ['130', '131']},{'id': '130', 'type': 'string', 'children': [], 'value': "'TEXT'"},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'agent_text'},{'id': '132', 'type': 'pair', 'children': ['133', '134']},{'id': '133', 'type': 'string', 'children': [], 'value': "'UP'"},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'uniprot_id'},{'id': '135', 'type': 'else_clause', 'children': ['136']},{'id': '136', 'type': 'block', 'children': ['137']},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'augmented_assignment', 'children': ['139', '140'], 'value': '+='},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'unmatched'},{'id': '140', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'info'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'binary_operator', 'children': ['148', '149'], 'value': '%'},{'id': '148', 'type': 'string', 'children': [], 'value': "'Exact matches for %d proteins'"},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'matched'},{'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': 'logger'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'binary_operator', 'children': ['157', '158'], 'value': '%'},{'id': '157', 'type': 'string', 'children': [], 'value': "'No match (or no gene name) for %d proteins'"},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'unmatched'},{'id': '159', 'type': 'return_statement', 'children': ['160']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'protein_map'} | def protein_map_from_twg(twg):
protein_map = {}
unmatched = 0
matched = 0
logger.info('Building grounding map for human proteins')
for agent_text, grounding_list, _ in twg:
if 'UP' not in [entry[0] for entry in grounding_list]:
continue
uniprot_ids = [entry[1] for entry in grounding_list
if entry[0] == 'UP']
for uniprot_id in uniprot_ids:
mnemonic = uniprot_client.get_mnemonic(uniprot_id)
if mnemonic is None or not mnemonic.endswith('_HUMAN'):
continue
gene_name = uniprot_client.get_gene_name(uniprot_id)
if gene_name is None:
unmatched += 1
continue
if agent_text.upper() == gene_name.upper():
matched += 1
protein_map[agent_text] = {'TEXT': agent_text,
'UP': uniprot_id}
else:
unmatched += 1
logger.info('Exact matches for %d proteins' % matched)
logger.info('No match (or no gene name) for %d proteins' % unmatched)
return protein_map |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'save_sentences'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'twg'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'agent_limit'},{'id': '9', 'type': 'integer', 'children': [], 'value': '300'},{'id': '10', 'type': 'block', 'children': ['11', '15', '25', '29', '38', '74']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'sentences'},{'id': '14', 'type': 'list', 'children': [], 'value': '[]'},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'unmapped_texts'},{'id': '18', 'type': 'list_comprehension', 'children': ['19', '22']},{'id': '19', 'type': 'subscript', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '21', 'type': 'integer', 'children': [], 'value': '0'},{'id': '22', 'type': 'for_in_clause', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'twg'},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'counter'},{'id': '28', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'logger'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'binary_operator', 'children': ['36', '37'], 'value': '%'},{'id': '36', 'type': 'string', 'children': [], 'value': "'Getting sentences for top %d unmapped agent texts.'"},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'agent_limit'},{'id': '38', 'type': 'for_statement', 'children': ['39', '40', '41']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'unmapped_texts'},{'id': '41', 'type': 'block', 'children': ['42', '50', '64', '68']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'agent_sentences'},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'get_sentences_for_agent'},{'id': '47', 'type': 'argument_list', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'augmented_assignment', 'children': ['52', '53'], 'value': '+='},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'sentences'},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '55', 'type': 'argument_list', 'children': ['56', '63']},{'id': '56', 'type': 'lambda', 'children': ['57', '59']},{'id': '57', 'type': 'lambda_parameters', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'tup'},{'id': '59', 'type': 'binary_operator', 'children': ['60', '62'], 'value': '+'},{'id': '60', 'type': 'tuple', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'tup'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'agent_sentences'},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'augmented_assignment', 'children': ['66', '67'], 'value': '+='},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'counter'},{'id': '67', 'type': 'integer', 'children': [], 'value': '1'},{'id': '68', 'type': 'if_statement', 'children': ['69', '72']},{'id': '69', 'type': 'comparison_operator', 'children': ['70', '71'], 'value': '>='},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'counter'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'agent_limit'},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'break_statement', 'children': []},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'write_unicode_csv'},{'id': '77', 'type': 'argument_list', 'children': ['78', '79', '80', '83', '86', '91']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'sentences'},{'id': '80', 'type': 'keyword_argument', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'delimiter'},{'id': '82', 'type': 'string', 'children': [], 'value': "','"},{'id': '83', 'type': 'keyword_argument', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'quotechar'},{'id': '85', 'type': 'string', 'children': [], 'value': '\'"\''},{'id': '86', 'type': 'keyword_argument', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'quoting'},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'csv'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'QUOTE_MINIMAL'},{'id': '91', 'type': 'keyword_argument', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'lineterminator'},{'id': '93', 'type': 'string', 'children': [], 'value': "'\\r\\n'"} | def save_sentences(twg, stmts, filename, agent_limit=300):
sentences = []
unmapped_texts = [t[0] for t in twg]
counter = 0
logger.info('Getting sentences for top %d unmapped agent texts.' %
agent_limit)
for text in unmapped_texts:
agent_sentences = get_sentences_for_agent(text, stmts)
sentences += map(lambda tup: (text,) + tup, agent_sentences)
counter += 1
if counter >= agent_limit:
break
write_unicode_csv(filename, sentences, delimiter=',', quotechar='"',
quoting=csv.QUOTE_MINIMAL, lineterminator='\r\n') |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_text_for_grounding'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'agent_text'},{'id': '6', 'type': 'block', 'children': ['7', '11', '103', '150', '174']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'try_statement', 'children': ['12', '90']},{'id': '12', 'type': 'block', 'children': ['13', '21', '28', '38', '59', '68', '75', '85']},{'id': '13', 'type': 'import_from_statement', 'children': ['14', '18', '19']},{'id': '14', 'type': 'dotted_name', 'children': ['15', '16', '17']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'indra_db'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'util'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'content_scripts'},{'id': '18', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '19', 'type': 'dotted_name', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'get_text_content_from_text_refs'},{'id': '21', 'type': 'import_from_statement', 'children': ['22', '26']},{'id': '22', 'type': 'dotted_name', 'children': ['23', '24', '25']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'indra'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'literature'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'deft_tools'},{'id': '26', 'type': 'dotted_name', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'universal_extract_text'},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'refs'},{'id': '31', 'type': 'attribute', 'children': ['32', '37']},{'id': '32', 'type': 'subscript', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'evidence'},{'id': '36', 'type': 'integer', 'children': [], 'value': '0'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'text_refs'},{'id': '38', 'type': 'if_statement', 'children': ['39', '46']},{'id': '39', 'type': 'attribute', 'children': ['40', '45']},{'id': '40', 'type': 'subscript', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'evidence'},{'id': '44', 'type': 'integer', 'children': [], 'value': '0'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'pmid'},{'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': 'refs'},{'id': '51', 'type': 'string', 'children': [], 'value': "'PMID'"},{'id': '52', 'type': 'attribute', 'children': ['53', '58']},{'id': '53', 'type': 'subscript', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'evidence'},{'id': '57', 'type': 'integer', 'children': [], 'value': '0'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'pmid'},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'binary_operator', 'children': ['66', '67'], 'value': '%'},{'id': '66', 'type': 'string', 'children': [], 'value': "'Obtaining text for disambiguation with refs: %s'"},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'refs'},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'get_text_content_from_text_refs'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'refs'},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'universal_extract_text'},{'id': '80', 'type': 'argument_list', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '82', 'type': 'keyword_argument', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'contains'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'agent_text'},{'id': '85', 'type': 'if_statement', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'return_statement', 'children': ['89']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '90', 'type': 'except_clause', 'children': ['91', '95']},{'id': '91', 'type': 'as_pattern', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '93', 'type': 'as_pattern_target', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '95', 'type': 'block', 'children': ['96']},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'call', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'string', 'children': [], 'value': "'Could not get text for disambiguation from DB.'"},{'id': '103', 'type': 'if_statement', 'children': ['104', '107']},{'id': '104', 'type': 'comparison_operator', 'children': ['105', '106'], 'value': 'is'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '106', 'type': 'None', 'children': []},{'id': '107', 'type': 'block', 'children': ['108', '114', '124']},{'id': '108', 'type': 'import_from_statement', 'children': ['109', '112']},{'id': '109', 'type': 'dotted_name', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'indra'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'literature'},{'id': '112', 'type': 'dotted_name', 'children': ['113']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'pubmed_client'},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'pmid'},{'id': '117', 'type': 'attribute', 'children': ['118', '123']},{'id': '118', 'type': 'subscript', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'evidence'},{'id': '122', 'type': 'integer', 'children': [], 'value': '0'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'pmid'},{'id': '124', 'type': 'if_statement', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'pmid'},{'id': '126', 'type': 'block', 'children': ['127', '136', '145']},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'call', 'children': ['129', '132']},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'binary_operator', 'children': ['134', '135'], 'value': '%'},{'id': '134', 'type': 'string', 'children': [], 'value': "'Obtaining abstract for disambiguation for PMID%s'"},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'pmid'},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'pubmed_client'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'get_abstract'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'pmid'},{'id': '145', 'type': 'if_statement', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '147', 'type': 'block', 'children': ['148']},{'id': '148', 'type': 'return_statement', 'children': ['149']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '150', 'type': 'if_statement', 'children': ['151', '154']},{'id': '151', 'type': 'comparison_operator', 'children': ['152', '153'], 'value': 'is'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '153', 'type': 'None', 'children': []},{'id': '154', 'type': 'block', 'children': ['155', '162', '172']},{'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': 'logger'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'string', 'children': [], 'value': "'Falling back on sentence-based disambiguation'"},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'assignment', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '165', 'type': 'attribute', 'children': ['166', '171']},{'id': '166', 'type': 'subscript', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'evidence'},{'id': '170', 'type': 'integer', 'children': [], 'value': '0'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '172', 'type': 'return_statement', 'children': ['173']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '174', 'type': 'return_statement', 'children': ['175']},{'id': '175', 'type': 'None', 'children': []} | def _get_text_for_grounding(stmt, agent_text):
text = None
try:
from indra_db.util.content_scripts \
import get_text_content_from_text_refs
from indra.literature.deft_tools import universal_extract_text
refs = stmt.evidence[0].text_refs
if stmt.evidence[0].pmid:
refs['PMID'] = stmt.evidence[0].pmid
logger.info('Obtaining text for disambiguation with refs: %s' %
refs)
content = get_text_content_from_text_refs(refs)
text = universal_extract_text(content, contains=agent_text)
if text:
return text
except Exception as e:
logger.info('Could not get text for disambiguation from DB.')
if text is None:
from indra.literature import pubmed_client
pmid = stmt.evidence[0].pmid
if pmid:
logger.info('Obtaining abstract for disambiguation for PMID%s' %
pmid)
text = pubmed_client.get_abstract(pmid)
if text:
return text
if text is None:
logger.info('Falling back on sentence-based disambiguation')
text = stmt.evidence[0].text
return text
return None |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'map_agents_for_stmt'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'do_rename'},{'id': '8', 'type': 'True', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '17', '25', '144', '151', '187']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'mapped_stmt'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'deepcopy'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'agent_list'},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'mapped_stmt'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'agent_list'},{'id': '24', 'type': 'argument_list', 'children': []},{'id': '25', 'type': 'for_statement', 'children': ['26', '29', '33']},{'id': '26', 'type': 'pattern_list', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'agent_list'},{'id': '33', 'type': 'block', 'children': ['34', '40', '51', '57', '69', '111', '116', '138']},{'id': '34', 'type': 'if_statement', 'children': ['35', '38']},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': 'is'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '37', 'type': 'None', 'children': []},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'continue_statement', 'children': []},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'agent_txt'},{'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': 'agent'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'db_refs'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'string', 'children': [], 'value': "'TEXT'"},{'id': '51', 'type': 'if_statement', 'children': ['52', '55']},{'id': '52', 'type': 'comparison_operator', 'children': ['53', '54'], 'value': 'is'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'agent_txt'},{'id': '54', 'type': 'None', 'children': []},{'id': '55', 'type': 'block', 'children': ['56']},{'id': '56', 'type': 'continue_statement', 'children': []},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '62']},{'id': '59', 'type': 'pattern_list', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'new_agent'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'maps_to_none'},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'map_agent'},{'id': '66', 'type': 'argument_list', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'do_rename'},{'id': '69', 'type': 'if_statement', 'children': ['70', '77']},{'id': '70', 'type': 'boolean_operator', 'children': ['71', '74'], 'value': 'and'},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'use_deft'},{'id': '74', 'type': 'comparison_operator', 'children': ['75', '76'], 'value': 'in'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'agent_txt'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'deft_disambiguators'},{'id': '77', 'type': 'block', 'children': ['78']},{'id': '78', 'type': 'try_statement', 'children': ['79', '89']},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'run_deft_disambiguation'},{'id': '83', 'type': 'argument_list', 'children': ['84', '85', '86', '87', '88']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'mapped_stmt'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'agent_list'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'new_agent'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'agent_txt'},{'id': '89', 'type': 'except_clause', 'children': ['90', '94']},{'id': '90', 'type': 'as_pattern', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '92', 'type': 'as_pattern_target', 'children': ['93']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '94', 'type': 'block', 'children': ['95', '104']},{'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': 'error'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'concatenated_string', 'children': ['102', '103']},{'id': '102', 'type': 'string', 'children': [], 'value': "'There was an error during Deft'"},{'id': '103', 'type': 'string', 'children': [], 'value': "' disambiguation.'"},{'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': 'logger'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '111', 'type': 'if_statement', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'maps_to_none'},{'id': '113', 'type': 'block', 'children': ['114']},{'id': '114', 'type': 'return_statement', 'children': ['115']},{'id': '115', 'type': 'None', 'children': []},{'id': '116', 'type': 'if_statement', 'children': ['117', '129']},{'id': '117', 'type': 'boolean_operator', 'children': ['118', '121'], 'value': 'and'},{'id': '118', 'type': 'comparison_operator', 'children': ['119', '120'], 'value': 'is'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'new_agent'},{'id': '120', 'type': 'None', 'children': []},{'id': '121', 'type': 'comparison_operator', 'children': ['122', '128'], 'value': '=='},{'id': '122', 'type': 'call', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'new_agent'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'bound_conditions'},{'id': '128', 'type': 'integer', 'children': [], 'value': '0'},{'id': '129', 'type': 'block', 'children': ['130']},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'new_agent'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'bound_conditions'},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'bound_conditions'},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'assignment', 'children': ['140', '143']},{'id': '140', 'type': 'subscript', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'agent_list'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'new_agent'},{'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': 'mapped_stmt'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'set_agent_list'},{'id': '149', 'type': 'argument_list', 'children': ['150']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'agent_list'},{'id': '151', 'type': 'for_statement', 'children': ['152', '153', '154']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'agent_list'},{'id': '154', 'type': 'block', 'children': ['155']},{'id': '155', 'type': 'if_statement', 'children': ['156', '159']},{'id': '156', 'type': 'comparison_operator', 'children': ['157', '158'], 'value': 'is'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '158', 'type': 'None', 'children': []},{'id': '159', 'type': 'block', 'children': ['160']},{'id': '160', 'type': 'for_statement', 'children': ['161', '162', '165']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'bc'},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'bound_conditions'},{'id': '165', 'type': 'block', 'children': ['166', '182']},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '173']},{'id': '168', 'type': 'pattern_list', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'bc'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'maps_to_none'},{'id': '173', 'type': 'call', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'map_agent'},{'id': '177', 'type': 'argument_list', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'bc'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'do_rename'},{'id': '182', 'type': 'if_statement', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'maps_to_none'},{'id': '184', 'type': 'block', 'children': ['185']},{'id': '185', 'type': 'return_statement', 'children': ['186']},{'id': '186', 'type': 'None', 'children': []},{'id': '187', 'type': 'return_statement', 'children': ['188']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'mapped_stmt'} | def map_agents_for_stmt(self, stmt, do_rename=True):
mapped_stmt = deepcopy(stmt)
agent_list = mapped_stmt.agent_list()
for idx, agent in enumerate(agent_list):
if agent is None:
continue
agent_txt = agent.db_refs.get('TEXT')
if agent_txt is None:
continue
new_agent, maps_to_none = self.map_agent(agent, do_rename)
if self.use_deft and agent_txt in deft_disambiguators:
try:
run_deft_disambiguation(mapped_stmt, agent_list, idx,
new_agent, agent_txt)
except Exception as e:
logger.error('There was an error during Deft'
' disambiguation.')
logger.error(e)
if maps_to_none:
return None
if new_agent is not None and len(new_agent.bound_conditions) == 0:
new_agent.bound_conditions = agent.bound_conditions
agent_list[idx] = new_agent
mapped_stmt.set_agent_list(agent_list)
for agent in agent_list:
if agent is not None:
for bc in agent.bound_conditions:
bc.agent, maps_to_none = self.map_agent(bc.agent,
do_rename)
if maps_to_none:
return None
return mapped_stmt |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'map_agent'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'do_rename'},{'id': '7', 'type': 'block', 'children': ['8', '19', '30', '49', '74', '103']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'agent_text'},{'id': '11', 'type': 'call', 'children': ['12', '17']},{'id': '12', 'type': 'attribute', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'db_refs'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'string', 'children': [], 'value': "'TEXT'"},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'mapped_to_agent_json'},{'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': 'agent_map'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'agent_text'},{'id': '30', 'type': 'if_statement', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'mapped_to_agent_json'},{'id': '32', 'type': 'block', 'children': ['33', '45']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36', '37']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'mapped_to_agent'},{'id': '36', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'Agent'},{'id': '40', 'type': 'identifier', 'children': [], 'value': '_from_json'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'subscript', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'mapped_to_agent_json'},{'id': '44', 'type': 'string', 'children': [], 'value': "'agent'"},{'id': '45', 'type': 'return_statement', 'children': ['46']},{'id': '46', 'type': 'expression_list', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'mapped_to_agent'},{'id': '48', 'type': 'False', 'children': []},{'id': '49', 'type': 'if_statement', 'children': ['50', '59', '68']},{'id': '50', 'type': 'comparison_operator', 'children': ['51', '52'], 'value': 'in'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'agent_text'},{'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': 'self'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'gm'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '58', 'type': 'argument_list', 'children': []},{'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': 'map_db_refs'},{'id': '63', 'type': 'subscript', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'gm'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'agent_text'},{'id': '68', 'type': 'else_clause', 'children': ['69']},{'id': '69', 'type': 'block', 'children': ['70']},{'id': '70', 'type': 'return_statement', 'children': ['71']},{'id': '71', 'type': 'expression_list', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '73', 'type': 'False', 'children': []},{'id': '74', 'type': 'if_statement', 'children': ['75', '78', '92']},{'id': '75', 'type': 'comparison_operator', 'children': ['76', '77'], 'value': 'is'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'map_db_refs'},{'id': '77', 'type': 'None', 'children': []},{'id': '78', 'type': 'block', 'children': ['79', '88']},{'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': 'logger'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'binary_operator', 'children': ['86', '87'], 'value': '%'},{'id': '86', 'type': 'string', 'children': [], 'value': '"Skipping %s"'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'agent_text'},{'id': '88', 'type': 'return_statement', 'children': ['89']},{'id': '89', 'type': 'expression_list', 'children': ['90', '91']},{'id': '90', 'type': 'None', 'children': []},{'id': '91', 'type': 'True', 'children': []},{'id': '92', 'type': 'else_clause', 'children': ['93']},{'id': '93', 'type': 'block', 'children': ['94']},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'call', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'update_agent_db_refs'},{'id': '99', 'type': 'argument_list', 'children': ['100', '101', '102']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'agent_text'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'do_rename'},{'id': '103', 'type': 'return_statement', 'children': ['104']},{'id': '104', 'type': 'expression_list', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '106', 'type': 'False', 'children': []} | def map_agent(self, agent, do_rename):
agent_text = agent.db_refs.get('TEXT')
mapped_to_agent_json = self.agent_map.get(agent_text)
if mapped_to_agent_json:
mapped_to_agent = \
Agent._from_json(mapped_to_agent_json['agent'])
return mapped_to_agent, False
if agent_text in self.gm.keys():
map_db_refs = self.gm[agent_text]
else:
return agent, False
if map_db_refs is None:
logger.debug("Skipping %s" % agent_text)
return None, True
else:
self.update_agent_db_refs(agent, agent_text, do_rename)
return agent, False |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'rename_agents'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '6', 'type': 'block', 'children': ['7', '14', '118']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'mapped_stmts'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'deepcopy'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '14', 'type': 'for_statement', 'children': ['15', '18', '22']},{'id': '15', 'type': 'pattern_list', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'mapped_stmts'},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'for_statement', 'children': ['24', '25', '30']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'agent_list'},{'id': '29', 'type': 'argument_list', 'children': []},{'id': '30', 'type': 'block', 'children': ['31', '37']},{'id': '31', 'type': 'if_statement', 'children': ['32', '35']},{'id': '32', 'type': 'comparison_operator', 'children': ['33', '34'], 'value': 'is'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '34', 'type': 'None', 'children': []},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'continue_statement', 'children': []},{'id': '37', 'type': 'if_statement', 'children': ['38', '46', '60']},{'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': 'agent'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'db_refs'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'string', 'children': [], 'value': "'FPLX'"},{'id': '46', 'type': 'block', 'children': ['47']},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'name'},{'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': 'agent'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'db_refs'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'string', 'children': [], 'value': "'FPLX'"},{'id': '60', 'type': 'elif_clause', 'children': ['61', '69']},{'id': '61', 'type': 'call', 'children': ['62', '67']},{'id': '62', 'type': 'attribute', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'db_refs'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'string', 'children': [], 'value': "'UP'"},{'id': '69', 'type': 'block', 'children': ['70', '89']},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'gene_name'},{'id': '73', 'type': 'call', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'uniprot_client'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'get_gene_name'},{'id': '77', 'type': 'argument_list', 'children': ['78', '86']},{'id': '78', 'type': 'call', 'children': ['79', '84']},{'id': '79', 'type': 'attribute', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'db_refs'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'string', 'children': [], 'value': "'UP'"},{'id': '86', 'type': 'keyword_argument', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'web_fallback'},{'id': '88', 'type': 'False', 'children': []},{'id': '89', 'type': 'if_statement', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'gene_name'},{'id': '91', 'type': 'block', 'children': ['92', '98', '107']},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'gene_name'},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'hgnc_id'},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'hgnc_client'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'get_hgnc_id'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'gene_name'},{'id': '107', 'type': 'if_statement', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'hgnc_id'},{'id': '109', 'type': 'block', 'children': ['110']},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'assignment', 'children': ['112', '117']},{'id': '112', 'type': 'subscript', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'db_refs'},{'id': '116', 'type': 'string', 'children': [], 'value': "'HGNC'"},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'hgnc_id'},{'id': '118', 'type': 'return_statement', 'children': ['119']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'mapped_stmts'} | def rename_agents(self, stmts):
mapped_stmts = deepcopy(stmts)
for _, stmt in enumerate(mapped_stmts):
for agent in stmt.agent_list():
if agent is None:
continue
if agent.db_refs.get('FPLX'):
agent.name = agent.db_refs.get('FPLX')
elif agent.db_refs.get('UP'):
gene_name = uniprot_client.get_gene_name(
agent.db_refs.get('UP'),
web_fallback=False)
if gene_name:
agent.name = gene_name
hgnc_id = hgnc_client.get_hgnc_id(gene_name)
if hgnc_id:
agent.db_refs['HGNC'] = hgnc_id
return mapped_stmts |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_ptms'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'ptm_df'},{'id': '6', 'type': 'block', 'children': ['7', '14']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'call', 'children': ['9', '12']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'string', 'children': [], 'value': "'Processing PTMs...'"},{'id': '14', 'type': 'for_statement', 'children': ['15', '18', '23']},{'id': '15', 'type': 'pattern_list', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'ix'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'ptm_df'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'iterrows'},{'id': '22', 'type': 'argument_list', 'children': []},{'id': '23', 'type': 'block', 'children': ['24', '32', '38', '54', '60', '69', '78', '87', '96', '120', '122', '124', '137', '159', '172']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'ptm_class'},{'id': '27', 'type': 'subscript', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': '_ptm_map'},{'id': '29', 'type': 'subscript', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '31', 'type': 'string', 'children': [], 'value': "'MOD_TYPE'"},{'id': '32', 'type': 'if_statement', 'children': ['33', '36']},{'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': 'is'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'ptm_class'},{'id': '35', 'type': 'None', 'children': []},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'continue_statement', 'children': []},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'sub_ag'},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '44', 'type': 'identifier', 'children': [], 'value': '_make_agent'},{'id': '45', 'type': 'argument_list', 'children': ['46', '49']},{'id': '46', 'type': 'subscript', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '48', 'type': 'string', 'children': [], 'value': "'HPRD_ID'"},{'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'refseq_id'},{'id': '51', 'type': 'subscript', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '53', 'type': 'string', 'children': [], 'value': "'REFSEQ_PROTEIN'"},{'id': '54', 'type': 'if_statement', 'children': ['55', '58']},{'id': '55', 'type': 'comparison_operator', 'children': ['56', '57'], 'value': 'is'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'sub_ag'},{'id': '57', 'type': 'None', 'children': []},{'id': '58', 'type': 'block', 'children': ['59']},{'id': '59', 'type': 'continue_statement', 'children': []},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'enz_id'},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': '_nan_to_none'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'subscript', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '68', 'type': 'string', 'children': [], 'value': "'ENZ_HPRD_ID'"},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'enz_ag'},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '75', 'type': 'identifier', 'children': [], 'value': '_make_agent'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'enz_id'},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': '_nan_to_none'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'subscript', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '86', 'type': 'string', 'children': [], 'value': "'RESIDUE'"},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'pos'},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': '_nan_to_none'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'subscript', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '95', 'type': 'string', 'children': [], 'value': "'POSITION'"},{'id': '96', 'type': 'if_statement', 'children': ['97', '104']},{'id': '97', 'type': 'boolean_operator', 'children': ['98', '101'], 'value': 'and'},{'id': '98', 'type': 'comparison_operator', 'children': ['99', '100'], 'value': 'is'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'pos'},{'id': '100', 'type': 'None', 'children': []},{'id': '101', 'type': 'comparison_operator', 'children': ['102', '103'], 'value': 'in'},{'id': '102', 'type': 'string', 'children': [], 'value': "';'"},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'pos'},{'id': '104', 'type': 'block', 'children': ['105', '116']},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '110']},{'id': '107', 'type': 'pattern_list', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'pos'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'dash'},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'pos'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'string', 'children': [], 'value': "';'"},{'id': '116', 'type': 'assert_statement', 'children': ['117']},{'id': '117', 'type': 'comparison_operator', 'children': ['118', '119'], 'value': '=='},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'dash'},{'id': '119', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '120', 'type': 'assert_statement', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '122', 'type': 'assert_statement', 'children': ['123']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'pos'},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'assignment', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'motif_dict'},{'id': '127', 'type': 'call', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '130', 'type': 'identifier', 'children': [], 'value': '_get_seq_motif'},{'id': '131', 'type': 'argument_list', 'children': ['132', '135', '136']},{'id': '132', 'type': 'subscript', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '134', 'type': 'string', 'children': [], 'value': "'REFSEQ_PROTEIN'"},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'pos'},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'assignment', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'ev_list'},{'id': '140', 'type': 'call', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '143', 'type': 'identifier', 'children': [], 'value': '_get_evidence'},{'id': '144', 'type': 'argument_list', 'children': ['145', '148', '151', '154', '157', '158']},{'id': '145', 'type': 'subscript', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '147', 'type': 'string', 'children': [], 'value': "'HPRD_ID'"},{'id': '148', 'type': 'subscript', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '150', 'type': 'string', 'children': [], 'value': "'HPRD_ISOFORM'"},{'id': '151', 'type': 'subscript', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '153', 'type': 'string', 'children': [], 'value': "'PMIDS'"},{'id': '154', 'type': 'subscript', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '156', 'type': 'string', 'children': [], 'value': "'EVIDENCE'"},{'id': '157', 'type': 'string', 'children': [], 'value': "'ptms'"},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'motif_dict'},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'assignment', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '162', 'type': 'call', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'ptm_class'},{'id': '164', 'type': 'argument_list', 'children': ['165', '166', '167', '168', '169']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'enz_ag'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'sub_ag'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'pos'},{'id': '169', 'type': 'keyword_argument', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'evidence'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'ev_list'},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'call', 'children': ['174', '179']},{'id': '174', 'type': 'attribute', 'children': ['175', '178']},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'statements'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'stmt'} | def get_ptms(self, ptm_df):
logger.info('Processing PTMs...')
for ix, row in ptm_df.iterrows():
ptm_class = _ptm_map[row['MOD_TYPE']]
if ptm_class is None:
continue
sub_ag = self._make_agent(row['HPRD_ID'],
refseq_id=row['REFSEQ_PROTEIN'])
if sub_ag is None:
continue
enz_id = _nan_to_none(row['ENZ_HPRD_ID'])
enz_ag = self._make_agent(enz_id)
res = _nan_to_none(row['RESIDUE'])
pos = _nan_to_none(row['POSITION'])
if pos is not None and ';' in pos:
pos, dash = pos.split(';')
assert dash == '-'
assert res
assert pos
motif_dict = self._get_seq_motif(row['REFSEQ_PROTEIN'], res, pos)
ev_list = self._get_evidence(
row['HPRD_ID'], row['HPRD_ISOFORM'], row['PMIDS'],
row['EVIDENCE'], 'ptms', motif_dict)
stmt = ptm_class(enz_ag, sub_ag, res, pos, evidence=ev_list)
self.statements.append(stmt) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_process_interaction'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'source_id'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'interaction'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'pmid'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'extra_annotations'},{'id': '10', 'type': 'block', 'children': ['11', '21', '28', '35', '44', '53', '60', '76', '82', '88', '112', '116', '139', '148', '152', '197']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'verb'},{'id': '14', 'type': 'call', 'children': ['15', '20']},{'id': '15', 'type': 'attribute', 'children': ['16', '19']},{'id': '16', 'type': 'subscript', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'interaction'},{'id': '18', 'type': 'integer', 'children': [], 'value': '0'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '20', 'type': 'argument_list', 'children': []},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'subj'},{'id': '24', 'type': 'subscript', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'interaction'},{'id': '26', 'type': 'unary_operator', 'children': ['27'], 'value': '-'},{'id': '27', 'type': 'integer', 'children': [], 'value': '2'},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '31', 'type': 'subscript', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'interaction'},{'id': '33', 'type': 'unary_operator', 'children': ['34'], 'value': '-'},{'id': '34', 'type': 'integer', 'children': [], 'value': '1'},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'subj'},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '41', 'type': 'identifier', 'children': [], 'value': '_make_agent'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'subj'},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'obj'},{'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': '_make_agent'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'annotations'},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'deepcopy'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'extra_annotations'},{'id': '60', 'type': 'if_statement', 'children': ['61', '64']},{'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': 'in'},{'id': '62', 'type': 'string', 'children': [], 'value': "'interaction'"},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'extra_annotations'},{'id': '64', 'type': 'block', 'children': ['65']},{'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': 'warning'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'binary_operator', 'children': ['72', '75'], 'value': '+'},{'id': '72', 'type': 'binary_operator', 'children': ['73', '74'], 'value': '+'},{'id': '73', 'type': 'string', 'children': [], 'value': '"\'interaction\' key of extra_annotations ignored"'},{'id': '74', 'type': 'string', 'children': [], 'value': '" since this is reserved for storing the raw ISI "'},{'id': '75', 'type': 'string', 'children': [], 'value': '"input."'},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '81']},{'id': '78', 'type': 'subscript', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'annotations'},{'id': '80', 'type': 'string', 'children': [], 'value': "'source_id'"},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'source_id'},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '87']},{'id': '84', 'type': 'subscript', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'annotations'},{'id': '86', 'type': 'string', 'children': [], 'value': "'interaction'"},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'interaction'},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'ist'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'Evidence'},{'id': '95', 'type': 'argument_list', 'children': ['96', '99', '102', '109']},{'id': '96', 'type': 'keyword_argument', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'source_api'},{'id': '98', 'type': 'string', 'children': [], 'value': "'isi'"},{'id': '99', 'type': 'keyword_argument', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'pmid'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'pmid'},{'id': '102', 'type': 'keyword_argument', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '104', 'type': 'call', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'rstrip'},{'id': '108', 'type': 'argument_list', 'children': []},{'id': '109', 'type': 'keyword_argument', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'annotations'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'annotations'},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'cataylst_specified'},{'id': '115', 'type': 'False', 'children': []},{'id': '116', 'type': 'if_statement', 'children': ['117', '123']},{'id': '117', 'type': 'comparison_operator', 'children': ['118', '122'], 'value': '=='},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'interaction'},{'id': '122', 'type': 'integer', 'children': [], 'value': '4'},{'id': '123', 'type': 'block', 'children': ['124', '130']},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'assignment', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'catalyst'},{'id': '127', 'type': 'subscript', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'interaction'},{'id': '129', 'type': 'integer', 'children': [], 'value': '1'},{'id': '130', 'type': 'if_statement', 'children': ['131', '134']},{'id': '131', 'type': 'comparison_operator', 'children': ['132', '133'], 'value': 'is'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'catalyst'},{'id': '133', 'type': 'None', 'children': []},{'id': '134', 'type': 'block', 'children': ['135']},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'assignment', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'cataylst_specified'},{'id': '138', 'type': 'True', 'children': []},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'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': 'self'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'verbs'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'verb'},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'statement'},{'id': '151', 'type': 'None', 'children': []},{'id': '152', 'type': 'if_statement', 'children': ['153', '156']},{'id': '153', 'type': 'comparison_operator', 'children': ['154', '155'], 'value': 'in'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'verb'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'verb_to_statement_type'},{'id': '156', 'type': 'block', 'children': ['157', '163']},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'statement_class'},{'id': '160', 'type': 'subscript', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'verb_to_statement_type'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'verb'},{'id': '163', 'type': 'if_statement', 'children': ['164', '169', '184']},{'id': '164', 'type': 'comparison_operator', 'children': ['165', '166'], 'value': '=='},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'statement_class'},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'ist'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'Complex'},{'id': '169', 'type': 'block', 'children': ['170']},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'assignment', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'statement'},{'id': '173', 'type': 'call', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'ist'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'Complex'},{'id': '177', 'type': 'argument_list', 'children': ['178', '181']},{'id': '178', 'type': 'list', 'children': ['179', '180'], 'value': '[subj, obj]'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'subj'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '181', 'type': 'keyword_argument', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'evidence'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '184', 'type': 'else_clause', 'children': ['185']},{'id': '185', 'type': 'block', 'children': ['186']},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'statement'},{'id': '189', 'type': 'call', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'statement_class'},{'id': '191', 'type': 'argument_list', 'children': ['192', '193', '194']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'subj'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '194', 'type': 'keyword_argument', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'evidence'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '197', 'type': 'if_statement', 'children': ['198', '201']},{'id': '198', 'type': 'comparison_operator', 'children': ['199', '200'], 'value': 'is'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'statement'},{'id': '200', 'type': 'None', 'children': []},{'id': '201', 'type': 'block', 'children': ['202', '206', '309']},{'id': '202', 'type': 'expression_statement', 'children': ['203']},{'id': '203', 'type': 'assignment', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'already_have'},{'id': '205', 'type': 'False', 'children': []},{'id': '206', 'type': 'if_statement', 'children': ['207', '215']},{'id': '207', 'type': 'comparison_operator', 'children': ['208', '212'], 'value': '=='},{'id': '208', 'type': 'call', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '210', 'type': 'argument_list', 'children': ['211']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'statement'},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'ist'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'Complex'},{'id': '215', 'type': 'block', 'children': ['216']},{'id': '216', 'type': 'for_statement', 'children': ['217', '218', '221']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'old_s'},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'statements'},{'id': '221', 'type': 'block', 'children': ['222', '232', '242']},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'assignment', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'old_id'},{'id': '225', 'type': 'attribute', 'children': ['226', '231']},{'id': '226', 'type': 'subscript', 'children': ['227', '230']},{'id': '227', 'type': 'attribute', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'statement'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'evidence'},{'id': '230', 'type': 'integer', 'children': [], 'value': '0'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'source_id'},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'assignment', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'new_id'},{'id': '235', 'type': 'attribute', 'children': ['236', '241']},{'id': '236', 'type': 'subscript', 'children': ['237', '240']},{'id': '237', 'type': 'attribute', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'old_s'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'evidence'},{'id': '240', 'type': 'integer', 'children': [], 'value': '0'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'source_id'},{'id': '242', 'type': 'if_statement', 'children': ['243', '255']},{'id': '243', 'type': 'boolean_operator', 'children': ['244', '252'], 'value': 'and'},{'id': '244', 'type': 'comparison_operator', 'children': ['245', '249'], 'value': '=='},{'id': '245', 'type': 'call', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '247', 'type': 'argument_list', 'children': ['248']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'old_s'},{'id': '249', 'type': 'attribute', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'ist'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'Complex'},{'id': '252', 'type': 'comparison_operator', 'children': ['253', '254'], 'value': '=='},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'old_id'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'new_id'},{'id': '255', 'type': 'block', 'children': ['256', '271', '278', '292', '299']},{'id': '256', 'type': 'expression_statement', 'children': ['257']},{'id': '257', 'type': 'assignment', 'children': ['258', '259', '260']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'old_statement_members'},{'id': '259', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '260', 'type': 'list_comprehension', 'children': ['261', '266']},{'id': '261', 'type': 'subscript', 'children': ['262', '265']},{'id': '262', 'type': 'attribute', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'db_refs'},{'id': '265', 'type': 'string', 'children': [], 'value': "'TEXT'"},{'id': '266', 'type': 'for_in_clause', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '268', 'type': 'attribute', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'old_s'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'members'},{'id': '271', 'type': 'expression_statement', 'children': ['272']},{'id': '272', 'type': 'assignment', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'old_statement_members'},{'id': '274', 'type': 'call', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '276', 'type': 'argument_list', 'children': ['277']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'old_statement_members'},{'id': '278', 'type': 'expression_statement', 'children': ['279']},{'id': '279', 'type': 'assignment', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'new_statement_members'},{'id': '281', 'type': 'list_comprehension', 'children': ['282', '287']},{'id': '282', 'type': 'subscript', 'children': ['283', '286']},{'id': '283', 'type': 'attribute', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'db_refs'},{'id': '286', 'type': 'string', 'children': [], 'value': "'TEXT'"},{'id': '287', 'type': 'for_in_clause', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '289', 'type': 'attribute', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'statement'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'members'},{'id': '292', 'type': 'expression_statement', 'children': ['293']},{'id': '293', 'type': 'assignment', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'new_statement_members'},{'id': '295', 'type': 'call', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '297', 'type': 'argument_list', 'children': ['298']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'new_statement_members'},{'id': '299', 'type': 'if_statement', 'children': ['300', '303']},{'id': '300', 'type': 'comparison_operator', 'children': ['301', '302'], 'value': '=='},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'old_statement_members'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'new_statement_members'},{'id': '303', 'type': 'block', 'children': ['304', '308']},{'id': '304', 'type': 'expression_statement', 'children': ['305']},{'id': '305', 'type': 'assignment', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'already_have'},{'id': '307', 'type': 'True', 'children': []},{'id': '308', 'type': 'break_statement', 'children': []},{'id': '309', 'type': 'if_statement', 'children': ['310', '312']},{'id': '310', 'type': 'not_operator', 'children': ['311']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'already_have'},{'id': '312', 'type': 'block', 'children': ['313']},{'id': '313', 'type': 'expression_statement', 'children': ['314']},{'id': '314', 'type': 'call', 'children': ['315', '320']},{'id': '315', 'type': 'attribute', 'children': ['316', '319']},{'id': '316', 'type': 'attribute', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'statements'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '320', 'type': 'argument_list', 'children': ['321']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'statement'} | def _process_interaction(self, source_id, interaction, text, pmid,
extra_annotations):
verb = interaction[0].lower()
subj = interaction[-2]
obj = interaction[-1]
subj = self._make_agent(subj)
obj = self._make_agent(obj)
annotations = deepcopy(extra_annotations)
if 'interaction' in extra_annotations:
logger.warning("'interaction' key of extra_annotations ignored" +
" since this is reserved for storing the raw ISI " +
"input.")
annotations['source_id'] = source_id
annotations['interaction'] = interaction
ev = ist.Evidence(source_api='isi',
pmid=pmid,
text=text.rstrip(),
annotations=annotations)
cataylst_specified = False
if len(interaction) == 4:
catalyst = interaction[1]
if catalyst is not None:
cataylst_specified = True
self.verbs.add(verb)
statement = None
if verb in verb_to_statement_type:
statement_class = verb_to_statement_type[verb]
if statement_class == ist.Complex:
statement = ist.Complex([subj, obj], evidence=ev)
else:
statement = statement_class(subj, obj, evidence=ev)
if statement is not None:
already_have = False
if type(statement) == ist.Complex:
for old_s in self.statements:
old_id = statement.evidence[0].source_id
new_id = old_s.evidence[0].source_id
if type(old_s) == ist.Complex and old_id == new_id:
old_statement_members = \
[m.db_refs['TEXT'] for m in old_s.members]
old_statement_members = sorted(old_statement_members)
new_statement_members = [m.db_refs['TEXT']
for m in statement.members]
new_statement_members = sorted(new_statement_members)
if old_statement_members == new_statement_members:
already_have = True
break
if not already_have:
self.statements.append(statement) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_regulate_amounts'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '14', '21', '33', '48', '52']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'pb'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'controlsExpressionWithTemplateReac'},{'id': '13', 'type': 'argument_list', 'children': []},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': '_bpp'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'string', 'children': [], 'value': "'Searcher'"},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'searchPlain'},{'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': 'model'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'res_array'},{'id': '36', 'type': 'list_comprehension', 'children': ['37', '41']},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': '_match_to_array'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '41', 'type': 'for_in_clause', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'toArray'},{'id': '47', 'type': 'argument_list', 'children': []},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '51', 'type': 'list', 'children': [], 'value': '[]'},{'id': '52', 'type': 'for_statement', 'children': ['53', '54', '55']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'res_array'},{'id': '55', 'type': 'block', 'children': ['56', '58', '69', '75', '84', '90', '98', '126', '138', '158', '164', '172', '183', '192']},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'string', 'children': [], 'value': "'''\n controller_er = res[p.indexOf('controller ER')]\n generic_controller_er = res[p.indexOf('generic controller ER')]\n controller_simple_pe = res[p.indexOf('controller simple PE')]\n controller_pe = res[p.indexOf('controller PE')]\n control = res[p.indexOf('Control')]\n conversion = res[p.indexOf('Conversion')]\n input_pe = res[p.indexOf('input PE')]\n input_simple_pe = res[p.indexOf('input simple PE')]\n changed_generic_er = res[p.indexOf('changed generic ER')]\n output_pe = res[p.indexOf('output PE')]\n output_simple_pe = res[p.indexOf('output simple PE')]\n changed_er = res[p.indexOf('changed ER')]\n '''"},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'controller'},{'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': '_get_agents_from_entity'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'subscript', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '68', 'type': 'integer', 'children': [], 'value': '2'},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'controlled_pe'},{'id': '72', 'type': 'subscript', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '74', 'type': 'integer', 'children': [], 'value': '6'},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'controlled'},{'id': '78', 'type': 'call', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '81', 'type': 'identifier', 'children': [], 'value': '_get_agents_from_entity'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'controlled_pe'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'conversion'},{'id': '87', 'type': 'subscript', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '89', 'type': 'integer', 'children': [], 'value': '5'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'conversion'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'getTemplateDirection'},{'id': '97', 'type': 'argument_list', 'children': []},{'id': '98', 'type': 'if_statement', 'children': ['99', '102']},{'id': '99', 'type': 'comparison_operator', 'children': ['100', '101'], 'value': 'is'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '101', 'type': 'None', 'children': []},{'id': '102', 'type': 'block', 'children': ['103', '111']},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '106', 'type': 'call', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '110', 'type': 'argument_list', 'children': []},{'id': '111', 'type': 'if_statement', 'children': ['112', '115']},{'id': '112', 'type': 'comparison_operator', 'children': ['113', '114'], 'value': '!='},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '114', 'type': 'string', 'children': [], 'value': "'FORWARD'"},{'id': '115', 'type': 'block', 'children': ['116', '125']},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'call', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'binary_operator', 'children': ['123', '124'], 'value': '%'},{'id': '123', 'type': 'string', 'children': [], 'value': "'Unhandled conversion direction %s'"},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '125', 'type': 'continue_statement', 'children': []},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'int_type'},{'id': '129', 'type': 'call', 'children': ['130', '137']},{'id': '130', 'type': 'attribute', 'children': ['131', '136']},{'id': '131', 'type': 'call', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'conversion'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'getInteractionType'},{'id': '135', 'type': 'argument_list', 'children': []},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'toArray'},{'id': '137', 'type': 'argument_list', 'children': []},{'id': '138', 'type': 'if_statement', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'int_type'},{'id': '140', 'type': 'block', 'children': ['141']},{'id': '141', 'type': 'for_statement', 'children': ['142', '143', '144']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'int_type'},{'id': '144', 'type': 'block', 'children': ['145']},{'id': '145', 'type': 'for_statement', 'children': ['146', '147', '156']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '147', 'type': 'call', 'children': ['148', '155']},{'id': '148', 'type': 'attribute', 'children': ['149', '154']},{'id': '149', 'type': 'call', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'getTerm'},{'id': '153', 'type': 'argument_list', 'children': []},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'toArray'},{'id': '155', 'type': 'argument_list', 'children': []},{'id': '156', 'type': 'block', 'children': ['157']},{'id': '157', 'type': 'pass_statement', 'children': []},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'control'},{'id': '161', 'type': 'subscript', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '163', 'type': 'integer', 'children': [], 'value': '4'},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'assignment', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'control_type'},{'id': '167', 'type': 'call', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'control'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'getControlType'},{'id': '171', 'type': 'argument_list', 'children': []},{'id': '172', 'type': 'if_statement', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'control_type'},{'id': '174', 'type': 'block', 'children': ['175']},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'assignment', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'control_type'},{'id': '178', 'type': 'call', 'children': ['179', '182']},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'control_type'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '182', 'type': 'argument_list', 'children': []},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'assignment', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '186', 'type': 'call', 'children': ['187', '190']},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '189', 'type': 'identifier', 'children': [], 'value': '_get_evidence'},{'id': '190', 'type': 'argument_list', 'children': ['191']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'control'},{'id': '192', 'type': 'for_statement', 'children': ['193', '196', '209']},{'id': '193', 'type': 'pattern_list', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'subj'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '196', 'type': 'call', 'children': ['197', '200']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'itertools'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'product'},{'id': '200', 'type': 'argument_list', 'children': ['201', '205']},{'id': '201', 'type': 'call', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': '_listify'},{'id': '203', 'type': 'argument_list', 'children': ['204']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'controller'},{'id': '205', 'type': 'call', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': '_listify'},{'id': '207', 'type': 'argument_list', 'children': ['208']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'controlled'},{'id': '209', 'type': 'block', 'children': ['210', '218', '224', '268', '278']},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'id': '211', 'type': 'assignment', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'subj_act'},{'id': '213', 'type': 'call', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'ActivityCondition'},{'id': '215', 'type': 'argument_list', 'children': ['216', '217']},{'id': '216', 'type': 'string', 'children': [], 'value': "'transcription'"},{'id': '217', 'type': 'True', 'children': []},{'id': '218', 'type': 'expression_statement', 'children': ['219']},{'id': '219', 'type': 'assignment', 'children': ['220', '223']},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'subj'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'activity'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'subj_act'},{'id': '224', 'type': 'if_statement', 'children': ['225', '228', '240', '256']},{'id': '225', 'type': 'comparison_operator', 'children': ['226', '227'], 'value': '=='},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'control_type'},{'id': '227', 'type': 'string', 'children': [], 'value': "'ACTIVATION'"},{'id': '228', 'type': 'block', 'children': ['229']},{'id': '229', 'type': 'expression_statement', 'children': ['230']},{'id': '230', 'type': 'assignment', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '232', 'type': 'call', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'IncreaseAmount'},{'id': '234', 'type': 'argument_list', 'children': ['235', '236', '237']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'subj'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '237', 'type': 'keyword_argument', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'evidence'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '240', 'type': 'elif_clause', 'children': ['241', '244']},{'id': '241', 'type': 'comparison_operator', 'children': ['242', '243'], 'value': '=='},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'control_type'},{'id': '243', 'type': 'string', 'children': [], 'value': "'INHIBITION'"},{'id': '244', 'type': 'block', 'children': ['245']},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'assignment', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '248', 'type': 'call', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'DecreaseAmount'},{'id': '250', 'type': 'argument_list', 'children': ['251', '252', '253']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'subj'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '253', 'type': 'keyword_argument', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'evidence'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '256', 'type': 'else_clause', 'children': ['257']},{'id': '257', 'type': 'block', 'children': ['258', '267']},{'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': 'logger'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '263', 'type': 'argument_list', 'children': ['264']},{'id': '264', 'type': 'binary_operator', 'children': ['265', '266'], 'value': '%'},{'id': '265', 'type': 'string', 'children': [], 'value': "'Unhandled control type %s'"},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'control_type'},{'id': '267', 'type': 'continue_statement', 'children': []},{'id': '268', 'type': 'expression_statement', 'children': ['269']},{'id': '269', 'type': 'assignment', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'st_dec'},{'id': '271', 'type': 'call', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'decode_obj'},{'id': '273', 'type': 'argument_list', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '275', 'type': 'keyword_argument', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '277', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '278', 'type': 'expression_statement', 'children': ['279']},{'id': '279', 'type': 'call', 'children': ['280', '285']},{'id': '280', 'type': 'attribute', 'children': ['281', '284']},{'id': '281', 'type': 'attribute', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'statements'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '285', 'type': 'argument_list', 'children': ['286']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'st_dec'} | def get_regulate_amounts(self):
p = pb.controlsExpressionWithTemplateReac()
s = _bpp('Searcher')
res = s.searchPlain(self.model, p)
res_array = [_match_to_array(m) for m in res.toArray()]
stmts = []
for res in res_array:
'''
controller_er = res[p.indexOf('controller ER')]
generic_controller_er = res[p.indexOf('generic controller ER')]
controller_simple_pe = res[p.indexOf('controller simple PE')]
controller_pe = res[p.indexOf('controller PE')]
control = res[p.indexOf('Control')]
conversion = res[p.indexOf('Conversion')]
input_pe = res[p.indexOf('input PE')]
input_simple_pe = res[p.indexOf('input simple PE')]
changed_generic_er = res[p.indexOf('changed generic ER')]
output_pe = res[p.indexOf('output PE')]
output_simple_pe = res[p.indexOf('output simple PE')]
changed_er = res[p.indexOf('changed ER')]
'''
controller = self._get_agents_from_entity(res[2])
controlled_pe = res[6]
controlled = self._get_agents_from_entity(controlled_pe)
conversion = res[5]
direction = conversion.getTemplateDirection()
if direction is not None:
direction = direction.name()
if direction != 'FORWARD':
logger.warning('Unhandled conversion direction %s' %
direction)
continue
int_type = conversion.getInteractionType().toArray()
if int_type:
for it in int_type:
for term in it.getTerm().toArray():
pass
control = res[4]
control_type = control.getControlType()
if control_type:
control_type = control_type.name()
ev = self._get_evidence(control)
for subj, obj in itertools.product(_listify(controller),
_listify(controlled)):
subj_act = ActivityCondition('transcription', True)
subj.activity = subj_act
if control_type == 'ACTIVATION':
st = IncreaseAmount(subj, obj, evidence=ev)
elif control_type == 'INHIBITION':
st = DecreaseAmount(subj, obj, evidence=ev)
else:
logger.warning('Unhandled control type %s' % control_type)
continue
st_dec = decode_obj(st, encoding='utf-8')
self.statements.append(st_dec) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_gef'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '14', '21', '33', '48']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '12', 'type': 'identifier', 'children': [], 'value': '_gef_gap_base'},{'id': '13', 'type': 'argument_list', 'children': []},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': '_bpp'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'string', 'children': [], 'value': "'Searcher'"},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'searchPlain'},{'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': 'model'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'res_array'},{'id': '36', 'type': 'list_comprehension', 'children': ['37', '41']},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': '_match_to_array'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '41', 'type': 'for_in_clause', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'toArray'},{'id': '47', 'type': 'argument_list', 'children': []},{'id': '48', 'type': 'for_statement', 'children': ['49', '50', '51']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'res_array'},{'id': '51', 'type': 'block', 'children': ['52', '63', '74', '85', '96', '107', '118', '129', '136', '145', '154', '162', '171', '175', '196', '200', '221', '229', '238', '247', '256']},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'controller_pe'},{'id': '55', 'type': 'subscript', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '57', 'type': 'call', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'indexOf'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'string', 'children': [], 'value': "'controller PE'"},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'input_pe'},{'id': '66', 'type': 'subscript', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'indexOf'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'string', 'children': [], 'value': "'input PE'"},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'input_spe'},{'id': '77', 'type': 'subscript', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'indexOf'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'string', 'children': [], 'value': "'input simple PE'"},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'output_pe'},{'id': '88', 'type': 'subscript', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'indexOf'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'string', 'children': [], 'value': "'output PE'"},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'output_spe'},{'id': '99', 'type': 'subscript', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'indexOf'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'string', 'children': [], 'value': "'output simple PE'"},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'reaction'},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '112', 'type': 'call', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'indexOf'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'string', 'children': [], 'value': "'Conversion'"},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'control'},{'id': '121', 'type': 'subscript', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '123', 'type': 'call', 'children': ['124', '127']},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'indexOf'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'string', 'children': [], 'value': "'Control'"},{'id': '129', 'type': 'if_statement', 'children': ['130', '134']},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': '_is_complex'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'controller_pe'},{'id': '134', 'type': 'block', 'children': ['135']},{'id': '135', 'type': 'continue_statement', 'children': []},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'members_in'},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '142', 'type': 'identifier', 'children': [], 'value': '_get_complex_members'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'input_pe'},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'members_out'},{'id': '148', 'type': 'call', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '151', 'type': 'identifier', 'children': [], 'value': '_get_complex_members'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'output_pe'},{'id': '154', 'type': 'if_statement', 'children': ['155', '160']},{'id': '155', 'type': 'not_operator', 'children': ['156']},{'id': '156', 'type': '()', 'children': ['157']},{'id': '157', 'type': 'boolean_operator', 'children': ['158', '159'], 'value': 'and'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'members_in'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'members_out'},{'id': '160', 'type': 'block', 'children': ['161']},{'id': '161', 'type': 'continue_statement', 'children': []},{'id': '162', 'type': 'if_statement', 'children': ['163', '169']},{'id': '163', 'type': 'comparison_operator', 'children': ['164', '168'], 'value': '!='},{'id': '164', 'type': 'call', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'members_out'},{'id': '168', 'type': 'integer', 'children': [], 'value': '2'},{'id': '169', 'type': 'block', 'children': ['170']},{'id': '170', 'type': 'continue_statement', 'children': []},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'assignment', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'gdp_in'},{'id': '174', 'type': 'False', 'children': []},{'id': '175', 'type': 'for_statement', 'children': ['176', '177', '178']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'member'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'members_in'},{'id': '178', 'type': 'block', 'children': ['179']},{'id': '179', 'type': 'if_statement', 'children': ['180', '191']},{'id': '180', 'type': 'boolean_operator', 'children': ['181', '186'], 'value': 'and'},{'id': '181', 'type': 'call', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '183', 'type': 'argument_list', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'member'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'Agent'},{'id': '186', 'type': 'comparison_operator', 'children': ['187', '190'], 'value': '=='},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'member'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '190', 'type': 'string', 'children': [], 'value': "'GDP'"},{'id': '191', 'type': 'block', 'children': ['192']},{'id': '192', 'type': 'expression_statement', 'children': ['193']},{'id': '193', 'type': 'assignment', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'gdp_in'},{'id': '195', 'type': 'True', 'children': []},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'assignment', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'gtp_out'},{'id': '199', 'type': 'False', 'children': []},{'id': '200', 'type': 'for_statement', 'children': ['201', '202', '203']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'member'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'members_out'},{'id': '203', 'type': 'block', 'children': ['204']},{'id': '204', 'type': 'if_statement', 'children': ['205', '216']},{'id': '205', 'type': 'boolean_operator', 'children': ['206', '211'], 'value': 'and'},{'id': '206', 'type': 'call', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '208', 'type': 'argument_list', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'member'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'Agent'},{'id': '211', 'type': 'comparison_operator', 'children': ['212', '215'], 'value': '=='},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'member'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '215', 'type': 'string', 'children': [], 'value': "'GTP'"},{'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': 'gtp_out'},{'id': '220', 'type': 'True', 'children': []},{'id': '221', 'type': 'if_statement', 'children': ['222', '227']},{'id': '222', 'type': 'not_operator', 'children': ['223']},{'id': '223', 'type': '()', 'children': ['224']},{'id': '224', 'type': 'boolean_operator', 'children': ['225', '226'], 'value': 'and'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'gdp_in'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'gtp_out'},{'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': 'ras_list'},{'id': '232', 'type': 'call', 'children': ['233', '236']},{'id': '233', 'type': 'attribute', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '235', 'type': 'identifier', 'children': [], 'value': '_get_agents_from_entity'},{'id': '236', 'type': 'argument_list', 'children': ['237']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'input_spe'},{'id': '238', 'type': 'expression_statement', 'children': ['239']},{'id': '239', 'type': 'assignment', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'gef_list'},{'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': '_get_agents_from_entity'},{'id': '245', 'type': 'argument_list', 'children': ['246']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'controller_pe'},{'id': '247', 'type': 'expression_statement', 'children': ['248']},{'id': '248', 'type': 'assignment', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '250', 'type': 'call', 'children': ['251', '254']},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '253', 'type': 'identifier', 'children': [], 'value': '_get_evidence'},{'id': '254', 'type': 'argument_list', 'children': ['255']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'control'},{'id': '256', 'type': 'for_statement', 'children': ['257', '260', '273']},{'id': '257', 'type': 'pattern_list', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'gef'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'ras'},{'id': '260', 'type': 'call', 'children': ['261', '264']},{'id': '261', 'type': 'attribute', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'itertools'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'product'},{'id': '264', 'type': 'argument_list', 'children': ['265', '269']},{'id': '265', 'type': 'call', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': '_listify'},{'id': '267', 'type': 'argument_list', 'children': ['268']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'gef_list'},{'id': '269', 'type': 'call', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': '_listify'},{'id': '271', 'type': 'argument_list', 'children': ['272']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'ras_list'},{'id': '273', 'type': 'block', 'children': ['274', '285', '295']},{'id': '274', 'type': 'expression_statement', 'children': ['275']},{'id': '275', 'type': 'assignment', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '277', 'type': 'call', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'Gef'},{'id': '279', 'type': 'argument_list', 'children': ['280', '281', '282']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'gef'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'ras'},{'id': '282', 'type': 'keyword_argument', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'evidence'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '285', 'type': 'expression_statement', 'children': ['286']},{'id': '286', 'type': 'assignment', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'st_dec'},{'id': '288', 'type': 'call', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'decode_obj'},{'id': '290', 'type': 'argument_list', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '292', 'type': 'keyword_argument', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '294', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '295', 'type': 'expression_statement', 'children': ['296']},{'id': '296', 'type': 'call', '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': 'statements'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '302', 'type': 'argument_list', 'children': ['303']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'st_dec'} | def get_gef(self):
p = self._gef_gap_base()
s = _bpp('Searcher')
res = s.searchPlain(self.model, p)
res_array = [_match_to_array(m) for m in res.toArray()]
for r in res_array:
controller_pe = r[p.indexOf('controller PE')]
input_pe = r[p.indexOf('input PE')]
input_spe = r[p.indexOf('input simple PE')]
output_pe = r[p.indexOf('output PE')]
output_spe = r[p.indexOf('output simple PE')]
reaction = r[p.indexOf('Conversion')]
control = r[p.indexOf('Control')]
if _is_complex(controller_pe):
continue
members_in = self._get_complex_members(input_pe)
members_out = self._get_complex_members(output_pe)
if not (members_in and members_out):
continue
if len(members_out) != 2:
continue
gdp_in = False
for member in members_in:
if isinstance(member, Agent) and member.name == 'GDP':
gdp_in = True
gtp_out = False
for member in members_out:
if isinstance(member, Agent) and member.name == 'GTP':
gtp_out = True
if not (gdp_in and gtp_out):
continue
ras_list = self._get_agents_from_entity(input_spe)
gef_list = self._get_agents_from_entity(controller_pe)
ev = self._get_evidence(control)
for gef, ras in itertools.product(_listify(gef_list),
_listify(ras_list)):
st = Gef(gef, ras, evidence=ev)
st_dec = decode_obj(st, encoding='utf-8')
self.statements.append(st_dec) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_gap'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '14', '21', '33', '48']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '12', 'type': 'identifier', 'children': [], 'value': '_gef_gap_base'},{'id': '13', 'type': 'argument_list', 'children': []},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': '_bpp'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'string', 'children': [], 'value': "'Searcher'"},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'searchPlain'},{'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': 'model'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'res_array'},{'id': '36', 'type': 'list_comprehension', 'children': ['37', '41']},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': '_match_to_array'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '41', 'type': 'for_in_clause', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'toArray'},{'id': '47', 'type': 'argument_list', 'children': []},{'id': '48', 'type': 'for_statement', 'children': ['49', '50', '51']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'res_array'},{'id': '51', 'type': 'block', 'children': ['52', '63', '74', '85', '96', '107', '118', '129', '136', '145', '154', '162', '171', '175', '196', '200', '221', '229', '238', '247', '256']},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'controller_pe'},{'id': '55', 'type': 'subscript', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '57', 'type': 'call', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'indexOf'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'string', 'children': [], 'value': "'controller PE'"},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'input_pe'},{'id': '66', 'type': 'subscript', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'indexOf'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'string', 'children': [], 'value': "'input PE'"},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'input_spe'},{'id': '77', 'type': 'subscript', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'indexOf'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'string', 'children': [], 'value': "'input simple PE'"},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'output_pe'},{'id': '88', 'type': 'subscript', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'indexOf'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'string', 'children': [], 'value': "'output PE'"},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'output_spe'},{'id': '99', 'type': 'subscript', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'indexOf'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'string', 'children': [], 'value': "'output simple PE'"},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'reaction'},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '112', 'type': 'call', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'indexOf'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'string', 'children': [], 'value': "'Conversion'"},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'control'},{'id': '121', 'type': 'subscript', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '123', 'type': 'call', 'children': ['124', '127']},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'indexOf'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'string', 'children': [], 'value': "'Control'"},{'id': '129', 'type': 'if_statement', 'children': ['130', '134']},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': '_is_complex'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'controller_pe'},{'id': '134', 'type': 'block', 'children': ['135']},{'id': '135', 'type': 'continue_statement', 'children': []},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'members_in'},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '142', 'type': 'identifier', 'children': [], 'value': '_get_complex_members'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'input_pe'},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'members_out'},{'id': '148', 'type': 'call', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '151', 'type': 'identifier', 'children': [], 'value': '_get_complex_members'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'output_pe'},{'id': '154', 'type': 'if_statement', 'children': ['155', '160']},{'id': '155', 'type': 'not_operator', 'children': ['156']},{'id': '156', 'type': '()', 'children': ['157']},{'id': '157', 'type': 'boolean_operator', 'children': ['158', '159'], 'value': 'and'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'members_in'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'members_out'},{'id': '160', 'type': 'block', 'children': ['161']},{'id': '161', 'type': 'continue_statement', 'children': []},{'id': '162', 'type': 'if_statement', 'children': ['163', '169']},{'id': '163', 'type': 'comparison_operator', 'children': ['164', '168'], 'value': '!='},{'id': '164', 'type': 'call', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'members_out'},{'id': '168', 'type': 'integer', 'children': [], 'value': '2'},{'id': '169', 'type': 'block', 'children': ['170']},{'id': '170', 'type': 'continue_statement', 'children': []},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'assignment', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'gtp_in'},{'id': '174', 'type': 'False', 'children': []},{'id': '175', 'type': 'for_statement', 'children': ['176', '177', '178']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'member'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'members_in'},{'id': '178', 'type': 'block', 'children': ['179']},{'id': '179', 'type': 'if_statement', 'children': ['180', '191']},{'id': '180', 'type': 'boolean_operator', 'children': ['181', '186'], 'value': 'and'},{'id': '181', 'type': 'call', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '183', 'type': 'argument_list', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'member'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'Agent'},{'id': '186', 'type': 'comparison_operator', 'children': ['187', '190'], 'value': '=='},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'member'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '190', 'type': 'string', 'children': [], 'value': "'GTP'"},{'id': '191', 'type': 'block', 'children': ['192']},{'id': '192', 'type': 'expression_statement', 'children': ['193']},{'id': '193', 'type': 'assignment', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'gtp_in'},{'id': '195', 'type': 'True', 'children': []},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'assignment', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'gdp_out'},{'id': '199', 'type': 'False', 'children': []},{'id': '200', 'type': 'for_statement', 'children': ['201', '202', '203']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'member'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'members_out'},{'id': '203', 'type': 'block', 'children': ['204']},{'id': '204', 'type': 'if_statement', 'children': ['205', '216']},{'id': '205', 'type': 'boolean_operator', 'children': ['206', '211'], 'value': 'and'},{'id': '206', 'type': 'call', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '208', 'type': 'argument_list', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'member'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'Agent'},{'id': '211', 'type': 'comparison_operator', 'children': ['212', '215'], 'value': '=='},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'member'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '215', 'type': 'string', 'children': [], 'value': "'GDP'"},{'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': 'gdp_out'},{'id': '220', 'type': 'True', 'children': []},{'id': '221', 'type': 'if_statement', 'children': ['222', '227']},{'id': '222', 'type': 'not_operator', 'children': ['223']},{'id': '223', 'type': '()', 'children': ['224']},{'id': '224', 'type': 'boolean_operator', 'children': ['225', '226'], 'value': 'and'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'gtp_in'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'gdp_out'},{'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': 'ras_list'},{'id': '232', 'type': 'call', 'children': ['233', '236']},{'id': '233', 'type': 'attribute', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '235', 'type': 'identifier', 'children': [], 'value': '_get_agents_from_entity'},{'id': '236', 'type': 'argument_list', 'children': ['237']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'input_spe'},{'id': '238', 'type': 'expression_statement', 'children': ['239']},{'id': '239', 'type': 'assignment', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'gap_list'},{'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': '_get_agents_from_entity'},{'id': '245', 'type': 'argument_list', 'children': ['246']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'controller_pe'},{'id': '247', 'type': 'expression_statement', 'children': ['248']},{'id': '248', 'type': 'assignment', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '250', 'type': 'call', 'children': ['251', '254']},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '253', 'type': 'identifier', 'children': [], 'value': '_get_evidence'},{'id': '254', 'type': 'argument_list', 'children': ['255']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'control'},{'id': '256', 'type': 'for_statement', 'children': ['257', '260', '273']},{'id': '257', 'type': 'pattern_list', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'gap'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'ras'},{'id': '260', 'type': 'call', 'children': ['261', '264']},{'id': '261', 'type': 'attribute', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'itertools'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'product'},{'id': '264', 'type': 'argument_list', 'children': ['265', '269']},{'id': '265', 'type': 'call', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': '_listify'},{'id': '267', 'type': 'argument_list', 'children': ['268']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'gap_list'},{'id': '269', 'type': 'call', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': '_listify'},{'id': '271', 'type': 'argument_list', 'children': ['272']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'ras_list'},{'id': '273', 'type': 'block', 'children': ['274', '285', '295']},{'id': '274', 'type': 'expression_statement', 'children': ['275']},{'id': '275', 'type': 'assignment', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '277', 'type': 'call', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'Gap'},{'id': '279', 'type': 'argument_list', 'children': ['280', '281', '282']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'gap'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'ras'},{'id': '282', 'type': 'keyword_argument', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'evidence'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '285', 'type': 'expression_statement', 'children': ['286']},{'id': '286', 'type': 'assignment', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'st_dec'},{'id': '288', 'type': 'call', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'decode_obj'},{'id': '290', 'type': 'argument_list', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '292', 'type': 'keyword_argument', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '294', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '295', 'type': 'expression_statement', 'children': ['296']},{'id': '296', 'type': 'call', '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': 'statements'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '302', 'type': 'argument_list', 'children': ['303']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'st_dec'} | def get_gap(self):
p = self._gef_gap_base()
s = _bpp('Searcher')
res = s.searchPlain(self.model, p)
res_array = [_match_to_array(m) for m in res.toArray()]
for r in res_array:
controller_pe = r[p.indexOf('controller PE')]
input_pe = r[p.indexOf('input PE')]
input_spe = r[p.indexOf('input simple PE')]
output_pe = r[p.indexOf('output PE')]
output_spe = r[p.indexOf('output simple PE')]
reaction = r[p.indexOf('Conversion')]
control = r[p.indexOf('Control')]
if _is_complex(controller_pe):
continue
members_in = self._get_complex_members(input_pe)
members_out = self._get_complex_members(output_pe)
if not (members_in and members_out):
continue
if len(members_out) != 2:
continue
gtp_in = False
for member in members_in:
if isinstance(member, Agent) and member.name == 'GTP':
gtp_in = True
gdp_out = False
for member in members_out:
if isinstance(member, Agent) and member.name == 'GDP':
gdp_out = True
if not (gtp_in and gdp_out):
continue
ras_list = self._get_agents_from_entity(input_spe)
gap_list = self._get_agents_from_entity(controller_pe)
ev = self._get_evidence(control)
for gap, ras in itertools.product(_listify(gap_list),
_listify(ras_list)):
st = Gap(gap, ras, evidence=ev)
st_dec = decode_obj(st, encoding='utf-8')
self.statements.append(st_dec) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_generic_modification'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'mod_class'},{'id': '6', 'type': 'block', 'children': ['7', '13', '40', '48', '56', '69', '76', '88', '103', '107', '377']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'mod_type'},{'id': '10', 'type': 'subscript', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'modclass_to_modtype'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'mod_class'},{'id': '13', 'type': 'if_statement', 'children': ['14', '19', '32']},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'issubclass'},{'id': '16', 'type': 'argument_list', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'mod_class'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'RemoveModification'},{'id': '19', 'type': 'block', 'children': ['20', '26']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'mod_gain_const'},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'mcct'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'LOSS'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'mod_type'},{'id': '29', 'type': 'subscript', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'modtype_to_inverse'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'mod_type'},{'id': '32', 'type': 'else_clause', 'children': ['33']},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'mod_gain_const'},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'mcct'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'GAIN'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'mod_filter'},{'id': '43', 'type': 'subscript', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'mod_type'},{'id': '45', 'type': 'slice', 'children': ['46', '47']},{'id': '46', 'type': 'colon', 'children': []},{'id': '47', 'type': 'integer', 'children': [], 'value': '5'},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '51', 'type': 'call', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'BiopaxProcessor'},{'id': '54', 'type': 'identifier', 'children': [], 'value': '_construct_modification_pattern'},{'id': '55', 'type': 'argument_list', 'children': []},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'call', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '61', 'type': 'argument_list', 'children': ['62', '67', '68']},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'mcc'},{'id': '64', 'type': 'argument_list', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'mod_gain_const'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'mod_filter'},{'id': '67', 'type': 'string', 'children': [], 'value': '"input simple PE"'},{'id': '68', 'type': 'string', 'children': [], 'value': '"output simple PE"'},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': '_bpp'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'string', 'children': [], 'value': "'Searcher'"},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'searchPlain'},{'id': '83', 'type': 'argument_list', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'res_array'},{'id': '91', 'type': 'list_comprehension', 'children': ['92', '96']},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': '_match_to_array'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '96', 'type': 'for_in_clause', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'toArray'},{'id': '102', 'type': 'argument_list', 'children': []},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '106', 'type': 'list', 'children': [], 'value': '[]'},{'id': '107', 'type': 'for_statement', 'children': ['108', '109', '110']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'res_array'},{'id': '110', 'type': 'block', 'children': ['111', '122', '133', '144', '155', '166', '177', '185', '193', '221', '230', '235', '237', '249', '258']},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'controller_pe'},{'id': '114', 'type': 'subscript', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '116', 'type': 'call', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'indexOf'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'string', 'children': [], 'value': "'controller PE'"},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'input_pe'},{'id': '125', 'type': 'subscript', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '127', 'type': 'call', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'indexOf'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'string', 'children': [], 'value': "'input PE'"},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'input_spe'},{'id': '136', 'type': 'subscript', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'indexOf'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'string', 'children': [], 'value': "'input simple PE'"},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'output_spe'},{'id': '147', 'type': 'subscript', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '149', 'type': 'call', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'indexOf'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'string', 'children': [], 'value': "'output simple PE'"},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'reaction'},{'id': '158', 'type': 'subscript', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '160', 'type': 'call', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'indexOf'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'string', 'children': [], 'value': "'Conversion'"},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'control'},{'id': '169', 'type': 'subscript', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '171', 'type': 'call', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'indexOf'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'string', 'children': [], 'value': "'Control'"},{'id': '177', 'type': 'if_statement', 'children': ['178', '183']},{'id': '178', 'type': 'not_operator', 'children': ['179']},{'id': '179', 'type': 'call', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': '_is_catalysis'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'control'},{'id': '183', 'type': 'block', 'children': ['184']},{'id': '184', 'type': 'continue_statement', 'children': []},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'assignment', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'cat_dir'},{'id': '188', 'type': 'call', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'control'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'getCatalysisDirection'},{'id': '192', 'type': 'argument_list', 'children': []},{'id': '193', 'type': 'if_statement', 'children': ['194', '205']},{'id': '194', 'type': 'boolean_operator', 'children': ['195', '198'], 'value': 'and'},{'id': '195', 'type': 'comparison_operator', 'children': ['196', '197'], 'value': 'is'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'cat_dir'},{'id': '197', 'type': 'None', 'children': []},{'id': '198', 'type': 'comparison_operator', 'children': ['199', '204'], 'value': '!='},{'id': '199', 'type': 'call', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'cat_dir'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '203', 'type': 'argument_list', 'children': []},{'id': '204', 'type': 'string', 'children': [], 'value': "'LEFT_TO_RIGHT'"},{'id': '205', 'type': 'block', 'children': ['206', '220']},{'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': 'logger'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '211', 'type': 'argument_list', 'children': ['212']},{'id': '212', 'type': 'binary_operator', 'children': ['213', '214', '215'], 'value': '%'},{'id': '213', 'type': 'string', 'children': [], 'value': "'Unexpected catalysis direction: %s.'"},{'id': '214', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '215', 'type': 'call', 'children': ['216', '219']},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'control'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'getCatalysisDirection'},{'id': '219', 'type': 'argument_list', 'children': []},{'id': '220', 'type': 'continue_statement', 'children': []},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'assignment', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'enzs'},{'id': '224', 'type': 'call', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'BiopaxProcessor'},{'id': '227', 'type': 'identifier', 'children': [], 'value': '_get_primary_controller'},{'id': '228', 'type': 'argument_list', 'children': ['229']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'controller_pe'},{'id': '230', 'type': 'if_statement', 'children': ['231', '233']},{'id': '231', 'type': 'not_operator', 'children': ['232']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'enzs'},{'id': '233', 'type': 'block', 'children': ['234']},{'id': '234', 'type': 'continue_statement', 'children': []},{'id': '235', 'type': 'expression_statement', 'children': ['236']},{'id': '236', 'type': 'string', 'children': [], 'value': "'''\n if _is_complex(input_pe):\n sub_members_in = self._get_complex_members(input_pe)\n sub_members_out = self._get_complex_members(output_pe)\n logger.info('Cannot handle complex substrates.')\n continue\n '''"},{'id': '237', 'type': 'expression_statement', 'children': ['238']},{'id': '238', 'type': 'assignment', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'subs'},{'id': '240', 'type': 'call', 'children': ['241', '244']},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'BiopaxProcessor'},{'id': '243', 'type': 'identifier', 'children': [], 'value': '_get_agents_from_entity'},{'id': '244', 'type': 'argument_list', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'input_spe'},{'id': '246', 'type': 'keyword_argument', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'expand_pe'},{'id': '248', 'type': 'False', 'children': []},{'id': '249', 'type': 'expression_statement', 'children': ['250']},{'id': '250', 'type': 'assignment', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '252', 'type': 'call', 'children': ['253', '256']},{'id': '253', 'type': 'attribute', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '255', 'type': 'identifier', 'children': [], 'value': '_get_evidence'},{'id': '256', 'type': 'argument_list', 'children': ['257']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'control'},{'id': '258', 'type': 'for_statement', 'children': ['259', '262', '275']},{'id': '259', 'type': 'pattern_list', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'enz'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '262', 'type': 'call', 'children': ['263', '266']},{'id': '263', 'type': 'attribute', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'itertools'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'product'},{'id': '266', 'type': 'argument_list', 'children': ['267', '271']},{'id': '267', 'type': 'call', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': '_listify'},{'id': '269', 'type': 'argument_list', 'children': ['270']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'enzs'},{'id': '271', 'type': 'call', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': '_listify'},{'id': '273', 'type': 'argument_list', 'children': ['274']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'subs'},{'id': '275', 'type': 'block', 'children': ['276', '286', '296', '306', '331']},{'id': '276', 'type': 'expression_statement', 'children': ['277']},{'id': '277', 'type': 'assignment', 'children': ['278', '279', '280']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'mod_in'},{'id': '279', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '280', 'type': 'call', 'children': ['281', '284']},{'id': '281', 'type': 'attribute', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'BiopaxProcessor'},{'id': '283', 'type': 'identifier', 'children': [], 'value': '_get_entity_mods'},{'id': '284', 'type': 'argument_list', 'children': ['285']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'input_spe'},{'id': '286', 'type': 'expression_statement', 'children': ['287']},{'id': '287', 'type': 'assignment', 'children': ['288', '289', '290']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'mod_out'},{'id': '289', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '290', 'type': 'call', 'children': ['291', '294']},{'id': '291', 'type': 'attribute', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'BiopaxProcessor'},{'id': '293', 'type': 'identifier', 'children': [], 'value': '_get_entity_mods'},{'id': '294', 'type': 'argument_list', 'children': ['295']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'output_spe'},{'id': '296', 'type': 'expression_statement', 'children': ['297']},{'id': '297', 'type': 'assignment', 'children': ['298', '301']},{'id': '298', 'type': 'attribute', 'children': ['299', '300']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'mods'},{'id': '301', 'type': 'call', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': '_get_mod_intersection'},{'id': '303', 'type': 'argument_list', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'mod_in'},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'mod_out'},{'id': '306', 'type': 'if_statement', 'children': ['307', '312', '321']},{'id': '307', 'type': 'call', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'issubclass'},{'id': '309', 'type': 'argument_list', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'mod_class'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'AddModification'},{'id': '312', 'type': 'block', 'children': ['313']},{'id': '313', 'type': 'expression_statement', 'children': ['314']},{'id': '314', 'type': 'assignment', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'gained_mods'},{'id': '316', 'type': 'call', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': '_get_mod_difference'},{'id': '318', 'type': 'argument_list', 'children': ['319', '320']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'mod_out'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'mod_in'},{'id': '321', 'type': 'else_clause', 'children': ['322']},{'id': '322', 'type': 'block', 'children': ['323']},{'id': '323', 'type': 'expression_statement', 'children': ['324']},{'id': '324', 'type': 'assignment', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'gained_mods'},{'id': '326', 'type': 'call', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': '_get_mod_difference'},{'id': '328', 'type': 'argument_list', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'mod_in'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'mod_out'},{'id': '331', 'type': 'for_statement', 'children': ['332', '333', '334']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'gained_mods'},{'id': '334', 'type': 'block', 'children': ['335', '347', '364']},{'id': '335', 'type': 'if_statement', 'children': ['336', '345']},{'id': '336', 'type': 'comparison_operator', 'children': ['337', '340'], 'value': 'not'},{'id': '337', 'type': 'attribute', 'children': ['338', '339']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'mod_type'},{'id': '340', 'type': 'tuple', 'children': ['341', '342']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'mod_type'},{'id': '342', 'type': 'subscript', 'children': ['343', '344']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'modtype_to_inverse'},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'mod_type'},{'id': '345', 'type': 'block', 'children': ['346']},{'id': '346', 'type': 'continue_statement', 'children': []},{'id': '347', 'type': 'expression_statement', 'children': ['348']},{'id': '348', 'type': 'assignment', 'children': ['349', '350']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '350', 'type': 'call', 'children': ['351', '352']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'mod_class'},{'id': '352', 'type': 'argument_list', 'children': ['353', '354', '355', '358', '361']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'enz'},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '355', 'type': 'attribute', 'children': ['356', '357']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'residue'},{'id': '358', 'type': 'attribute', 'children': ['359', '360']},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '361', 'type': 'keyword_argument', 'children': ['362', '363']},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'evidence'},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '364', 'type': 'expression_statement', 'children': ['365']},{'id': '365', 'type': 'call', 'children': ['366', '369']},{'id': '366', 'type': 'attribute', 'children': ['367', '368']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '369', 'type': 'argument_list', 'children': ['370']},{'id': '370', 'type': 'call', 'children': ['371', '372']},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'decode_obj'},{'id': '372', 'type': 'argument_list', 'children': ['373', '374']},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '374', 'type': 'keyword_argument', 'children': ['375', '376']},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '376', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '377', 'type': 'return_statement', 'children': ['378']},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'stmts'} | def _get_generic_modification(self, mod_class):
mod_type = modclass_to_modtype[mod_class]
if issubclass(mod_class, RemoveModification):
mod_gain_const = mcct.LOSS
mod_type = modtype_to_inverse[mod_type]
else:
mod_gain_const = mcct.GAIN
mod_filter = mod_type[:5]
p = BiopaxProcessor._construct_modification_pattern()
p.add(mcc(mod_gain_const, mod_filter),
"input simple PE", "output simple PE")
s = _bpp('Searcher')
res = s.searchPlain(self.model, p)
res_array = [_match_to_array(m) for m in res.toArray()]
stmts = []
for r in res_array:
controller_pe = r[p.indexOf('controller PE')]
input_pe = r[p.indexOf('input PE')]
input_spe = r[p.indexOf('input simple PE')]
output_spe = r[p.indexOf('output simple PE')]
reaction = r[p.indexOf('Conversion')]
control = r[p.indexOf('Control')]
if not _is_catalysis(control):
continue
cat_dir = control.getCatalysisDirection()
if cat_dir is not None and cat_dir.name() != 'LEFT_TO_RIGHT':
logger.debug('Unexpected catalysis direction: %s.' % \
control.getCatalysisDirection())
continue
enzs = BiopaxProcessor._get_primary_controller(controller_pe)
if not enzs:
continue
'''
if _is_complex(input_pe):
sub_members_in = self._get_complex_members(input_pe)
sub_members_out = self._get_complex_members(output_pe)
logger.info('Cannot handle complex substrates.')
continue
'''
subs = BiopaxProcessor._get_agents_from_entity(input_spe,
expand_pe=False)
ev = self._get_evidence(control)
for enz, sub in itertools.product(_listify(enzs), _listify(subs)):
mod_in = \
BiopaxProcessor._get_entity_mods(input_spe)
mod_out = \
BiopaxProcessor._get_entity_mods(output_spe)
sub.mods = _get_mod_intersection(mod_in, mod_out)
if issubclass(mod_class, AddModification):
gained_mods = _get_mod_difference(mod_out, mod_in)
else:
gained_mods = _get_mod_difference(mod_in, mod_out)
for mod in gained_mods:
if mod.mod_type not in (mod_type,
modtype_to_inverse[mod_type]):
continue
stmt = mod_class(enz, sub, mod.residue, mod.position,
evidence=ev)
stmts.append(decode_obj(stmt, encoding='utf-8'))
return stmts |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_extract_mod_from_feature'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'mf'},{'id': '5', 'type': 'block', 'children': ['6', '14', '21', '33', '37', '76', '96', '102', '110', '207', '217']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'mf_type'},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'mf'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'getModificationType'},{'id': '13', 'type': 'argument_list', 'children': []},{'id': '14', 'type': 'if_statement', 'children': ['15', '18']},{'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': 'is'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'mf_type'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'return_statement', 'children': ['20']},{'id': '20', 'type': 'None', 'children': []},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'mf_type_terms'},{'id': '24', 'type': 'call', 'children': ['25', '32']},{'id': '25', 'type': 'attribute', 'children': ['26', '31']},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'mf_type'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'getTerm'},{'id': '30', 'type': 'argument_list', 'children': []},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'toArray'},{'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': 'known_mf_type'},{'id': '36', 'type': 'None', 'children': []},{'id': '37', 'type': 'for_statement', 'children': ['38', '39', '40']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'mf_type_terms'},{'id': '40', 'type': 'block', 'children': ['41', '57', '66']},{'id': '41', 'type': 'if_statement', 'children': ['42', '48']},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'string', 'children': [], 'value': "'MOD_RES '"},{'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': 't'},{'id': '52', 'type': 'subscript', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '54', 'type': 'slice', 'children': ['55', '56']},{'id': '55', 'type': 'integer', 'children': [], 'value': '8'},{'id': '56', 'type': 'colon', 'children': []},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'mf_type_indra'},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': '_mftype_dict'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '66', 'type': 'if_statement', 'children': ['67', '70']},{'id': '67', 'type': 'comparison_operator', 'children': ['68', '69'], 'value': 'is'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'mf_type_indra'},{'id': '69', 'type': 'None', 'children': []},{'id': '70', 'type': 'block', 'children': ['71', '75']},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'known_mf_type'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'mf_type_indra'},{'id': '75', 'type': 'break_statement', 'children': []},{'id': '76', 'type': 'if_statement', 'children': ['77', '79']},{'id': '77', 'type': 'not_operator', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'known_mf_type'},{'id': '79', 'type': 'block', 'children': ['80', '94']},{'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': 'logger'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'binary_operator', 'children': ['87', '88'], 'value': '%'},{'id': '87', 'type': 'string', 'children': [], 'value': "'Skipping modification with unknown terms: %s'"},{'id': '88', 'type': 'call', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'string', 'children': [], 'value': "', '"},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'mf_type_terms'},{'id': '94', 'type': 'return_statement', 'children': ['95']},{'id': '95', 'type': 'None', 'children': []},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '101']},{'id': '98', 'type': 'pattern_list', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'mod_type'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'residue'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'known_mf_type'},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'mf_pos'},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'mf'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'getFeatureLocation'},{'id': '109', 'type': 'argument_list', 'children': []},{'id': '110', 'type': 'if_statement', 'children': ['111', '114', '201']},{'id': '111', 'type': 'comparison_operator', 'children': ['112', '113'], 'value': 'is'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'mf_pos'},{'id': '113', 'type': 'None', 'children': []},{'id': '114', 'type': 'block', 'children': ['115']},{'id': '115', 'type': 'if_statement', 'children': ['116', '126', '131']},{'id': '116', 'type': 'not_operator', 'children': ['117']},{'id': '117', 'type': 'comparison_operator', 'children': ['118', '125'], 'value': '=='},{'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': 'mf_pos'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'modelInterface'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'getName'},{'id': '124', 'type': 'argument_list', 'children': []},{'id': '125', 'type': 'string', 'children': [], 'value': "'org.biopax.paxtools.model.level3.SequenceSite'"},{'id': '126', 'type': 'block', 'children': ['127']},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'mod_pos'},{'id': '130', 'type': 'None', 'children': []},{'id': '131', 'type': 'else_clause', 'children': ['132']},{'id': '132', 'type': 'block', 'children': ['133', '144', '152']},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'mf_site'},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'cast'},{'id': '138', 'type': 'argument_list', 'children': ['139', '143']},{'id': '139', 'type': 'call', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': '_bp'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'string', 'children': [], 'value': "'SequenceSite'"},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'mf_pos'},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'mf_pos_status'},{'id': '147', 'type': 'call', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'mf_site'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'getPositionStatus'},{'id': '151', 'type': 'argument_list', 'children': []},{'id': '152', 'type': 'if_statement', 'children': ['153', '156', '161', '185']},{'id': '153', 'type': 'comparison_operator', 'children': ['154', '155'], 'value': 'is'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'mf_pos_status'},{'id': '155', 'type': 'None', 'children': []},{'id': '156', 'type': 'block', 'children': ['157']},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'mod_pos'},{'id': '160', 'type': 'None', 'children': []},{'id': '161', 'type': 'elif_clause', 'children': ['162', '171']},{'id': '162', 'type': 'boolean_operator', 'children': ['163', '164'], 'value': 'and'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'mf_pos_status'},{'id': '164', 'type': 'comparison_operator', 'children': ['165', '170'], 'value': '!='},{'id': '165', 'type': 'call', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'mf_pos_status'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'toString'},{'id': '169', 'type': 'argument_list', 'children': []},{'id': '170', 'type': 'string', 'children': [], 'value': "'EQUAL'"},{'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': 'logger'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '177', 'type': 'argument_list', 'children': ['178']},{'id': '178', 'type': 'binary_operator', 'children': ['179', '180'], 'value': '%'},{'id': '179', 'type': 'string', 'children': [], 'value': "'Modification site position is %s'"},{'id': '180', 'type': 'call', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'mf_pos_status'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'toString'},{'id': '184', 'type': 'argument_list', 'children': []},{'id': '185', 'type': 'else_clause', 'children': ['186']},{'id': '186', 'type': 'block', 'children': ['187', '195']},{'id': '187', 'type': 'expression_statement', 'children': ['188']},{'id': '188', 'type': 'assignment', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'mod_pos'},{'id': '190', 'type': 'call', 'children': ['191', '194']},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'mf_site'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'getSequencePosition'},{'id': '194', 'type': 'argument_list', 'children': []},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'assignment', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'mod_pos'},{'id': '198', 'type': 'binary_operator', 'children': ['199', '200'], 'value': '%'},{'id': '199', 'type': 'string', 'children': [], 'value': "'%s'"},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'mod_pos'},{'id': '201', 'type': 'else_clause', 'children': ['202']},{'id': '202', 'type': 'block', 'children': ['203']},{'id': '203', 'type': 'expression_statement', 'children': ['204']},{'id': '204', 'type': 'assignment', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'mod_pos'},{'id': '206', 'type': 'None', 'children': []},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'assignment', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'mc'},{'id': '210', 'type': 'call', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'ModCondition'},{'id': '212', 'type': 'argument_list', 'children': ['213', '214', '215', '216']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'mod_type'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'residue'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'mod_pos'},{'id': '216', 'type': 'True', 'children': []},{'id': '217', 'type': 'return_statement', 'children': ['218']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'mc'} | def _extract_mod_from_feature(mf):
mf_type = mf.getModificationType()
if mf_type is None:
return None
mf_type_terms = mf_type.getTerm().toArray()
known_mf_type = None
for t in mf_type_terms:
if t.startswith('MOD_RES '):
t = t[8:]
mf_type_indra = _mftype_dict.get(t)
if mf_type_indra is not None:
known_mf_type = mf_type_indra
break
if not known_mf_type:
logger.debug('Skipping modification with unknown terms: %s' %
', '.join(mf_type_terms))
return None
mod_type, residue = known_mf_type
mf_pos = mf.getFeatureLocation()
if mf_pos is not None:
if not mf_pos.modelInterface.getName() == \
'org.biopax.paxtools.model.level3.SequenceSite':
mod_pos = None
else:
mf_site = cast(_bp('SequenceSite'), mf_pos)
mf_pos_status = mf_site.getPositionStatus()
if mf_pos_status is None:
mod_pos = None
elif mf_pos_status and mf_pos_status.toString() != 'EQUAL':
logger.debug('Modification site position is %s' %
mf_pos_status.toString())
else:
mod_pos = mf_site.getSequencePosition()
mod_pos = '%s' % mod_pos
else:
mod_pos = None
mc = ModCondition(mod_type, residue, mod_pos, True)
return mc |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_activations'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '17', '28', '39']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'act_events'},{'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': 'tree'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'findall'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'string', 'children': [], 'value': '"EVENT/[type=\'ONT::ACTIVATE\']"'},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'inact_events'},{'id': '20', 'type': 'call', 'children': ['21', '26']},{'id': '21', 'type': 'attribute', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'findall'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'string', 'children': [], 'value': '"EVENT/[type=\'ONT::DEACTIVATE\']"'},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'augmented_assignment', 'children': ['30', '31'], 'value': '+='},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'inact_events'},{'id': '31', 'type': 'call', 'children': ['32', '37']},{'id': '32', 'type': 'attribute', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'findall'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'string', 'children': [], 'value': '"EVENT/[type=\'ONT::INHIBIT\']"'},{'id': '39', 'type': 'for_statement', 'children': ['40', '41', '45']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '41', 'type': '()', 'children': ['42']},{'id': '42', 'type': 'binary_operator', 'children': ['43', '44'], 'value': '+'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'act_events'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'inact_events'},{'id': '45', 'type': 'block', 'children': ['46', '54', '62', '71', '77', '88', '101', '111', '117', '126', '139', '150', '163', '173', '186', '190', '255', '264', '273']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'event_id'},{'id': '49', 'type': 'subscript', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '53', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '54', 'type': 'if_statement', 'children': ['55', '60']},{'id': '55', 'type': 'comparison_operator', 'children': ['56', '57'], 'value': 'in'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'event_id'},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '59', 'type': 'identifier', 'children': [], 'value': '_static_events'},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'continue_statement', 'children': []},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'string', 'children': [], 'value': '".//*[@role=\':AGENT\']"'},{'id': '71', 'type': 'if_statement', 'children': ['72', '75']},{'id': '72', 'type': 'comparison_operator', 'children': ['73', '74'], 'value': 'is'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '74', 'type': 'None', 'children': []},{'id': '75', 'type': 'block', 'children': ['76']},{'id': '76', 'type': 'continue_statement', 'children': []},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'agent_id'},{'id': '80', 'type': 'call', 'children': ['81', '86']},{'id': '81', 'type': 'attribute', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '88', 'type': 'if_statement', 'children': ['89', '92']},{'id': '89', 'type': 'comparison_operator', 'children': ['90', '91'], 'value': 'is'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'agent_id'},{'id': '91', 'type': 'None', 'children': []},{'id': '92', 'type': 'block', 'children': ['93', '100']},{'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': 'logger'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'string', 'children': [], 'value': "'Skipping activation with missing activator agent'"},{'id': '100', 'type': 'continue_statement', 'children': []},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'activator_agent'},{'id': '104', 'type': 'call', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '107', 'type': 'identifier', 'children': [], 'value': '_get_agent_by_id'},{'id': '108', 'type': 'argument_list', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'agent_id'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'event_id'},{'id': '111', 'type': 'if_statement', 'children': ['112', '115']},{'id': '112', 'type': 'comparison_operator', 'children': ['113', '114'], 'value': 'is'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'activator_agent'},{'id': '114', 'type': 'None', 'children': []},{'id': '115', 'type': 'block', 'children': ['116']},{'id': '116', 'type': 'continue_statement', 'children': []},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'affected'},{'id': '120', 'type': 'call', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'string', 'children': [], 'value': '".//*[@role=\':AFFECTED\']"'},{'id': '126', 'type': 'if_statement', 'children': ['127', '130']},{'id': '127', 'type': 'comparison_operator', 'children': ['128', '129'], 'value': 'is'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'affected'},{'id': '129', 'type': 'None', 'children': []},{'id': '130', 'type': 'block', 'children': ['131', '138']},{'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': 'logger'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'string', 'children': [], 'value': "'Skipping activation with missing affected agent'"},{'id': '138', 'type': 'continue_statement', 'children': []},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'assignment', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'affected_id'},{'id': '142', 'type': 'call', 'children': ['143', '148']},{'id': '143', 'type': 'attribute', 'children': ['144', '147']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'affected'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '150', 'type': 'if_statement', 'children': ['151', '154']},{'id': '151', 'type': 'comparison_operator', 'children': ['152', '153'], 'value': 'is'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'affected_id'},{'id': '153', 'type': 'None', 'children': []},{'id': '154', 'type': 'block', 'children': ['155', '162']},{'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': 'logger'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'string', 'children': [], 'value': "'Skipping activation with missing affected agent'"},{'id': '162', 'type': 'continue_statement', 'children': []},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'affected_agent'},{'id': '166', 'type': 'call', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '169', 'type': 'identifier', 'children': [], 'value': '_get_agent_by_id'},{'id': '170', 'type': 'argument_list', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'affected_id'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'event_id'},{'id': '173', 'type': 'if_statement', 'children': ['174', '177']},{'id': '174', 'type': 'comparison_operator', 'children': ['175', '176'], 'value': 'is'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'affected_agent'},{'id': '176', 'type': 'None', 'children': []},{'id': '177', 'type': 'block', 'children': ['178', '185']},{'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': 'logger'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '183', 'type': 'argument_list', 'children': ['184']},{'id': '184', 'type': 'string', 'children': [], 'value': "'Skipping activation with missing affected agent'"},{'id': '185', 'type': 'continue_statement', 'children': []},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'is_activation'},{'id': '189', 'type': 'True', 'children': []},{'id': '190', 'type': 'if_statement', 'children': ['191', '196', '209', '232']},{'id': '191', 'type': 'call', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': '_is_type'},{'id': '193', 'type': 'argument_list', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '195', 'type': 'string', 'children': [], 'value': "'ONT::ACTIVATE'"},{'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': 'self'},{'id': '201', 'type': 'identifier', 'children': [], 'value': '_add_extracted'},{'id': '202', 'type': 'argument_list', 'children': ['203', '204']},{'id': '203', 'type': 'string', 'children': [], 'value': "'ONT::ACTIVATE'"},{'id': '204', 'type': 'subscript', 'children': ['205', '208']},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '208', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '209', 'type': 'elif_clause', 'children': ['210', '215']},{'id': '210', 'type': 'call', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': '_is_type'},{'id': '212', 'type': 'argument_list', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '214', 'type': 'string', 'children': [], 'value': "'ONT::INHIBIT'"},{'id': '215', 'type': 'block', 'children': ['216', '220']},{'id': '216', 'type': 'expression_statement', 'children': ['217']},{'id': '217', 'type': 'assignment', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'is_activation'},{'id': '219', 'type': 'False', 'children': []},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'call', 'children': ['222', '225']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '224', 'type': 'identifier', 'children': [], 'value': '_add_extracted'},{'id': '225', 'type': 'argument_list', 'children': ['226', '227']},{'id': '226', 'type': 'string', 'children': [], 'value': "'ONT::INHIBIT'"},{'id': '227', 'type': 'subscript', 'children': ['228', '231']},{'id': '228', 'type': 'attribute', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '231', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '232', 'type': 'elif_clause', 'children': ['233', '238']},{'id': '233', 'type': 'call', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': '_is_type'},{'id': '235', 'type': 'argument_list', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '237', 'type': 'string', 'children': [], 'value': "'ONT::DEACTIVATE'"},{'id': '238', 'type': 'block', 'children': ['239', '243']},{'id': '239', 'type': 'expression_statement', 'children': ['240']},{'id': '240', 'type': 'assignment', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'is_activation'},{'id': '242', 'type': 'False', 'children': []},{'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': 'self'},{'id': '247', 'type': 'identifier', 'children': [], 'value': '_add_extracted'},{'id': '248', 'type': 'argument_list', 'children': ['249', '250']},{'id': '249', 'type': 'string', 'children': [], 'value': "'ONT::DEACTIVATE'"},{'id': '250', 'type': 'subscript', 'children': ['251', '254']},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '254', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '255', 'type': 'expression_statement', 'children': ['256']},{'id': '256', 'type': 'assignment', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '258', 'type': 'call', 'children': ['259', '262']},{'id': '259', 'type': 'attribute', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '261', 'type': 'identifier', 'children': [], 'value': '_get_evidence'},{'id': '262', 'type': 'argument_list', 'children': ['263']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '264', 'type': 'expression_statement', 'children': ['265']},{'id': '265', 'type': 'assignment', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'location'},{'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': '_get_event_location'},{'id': '271', 'type': 'argument_list', 'children': ['272']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '273', 'type': 'for_statement', 'children': ['274', '277', '283']},{'id': '274', 'type': 'pattern_list', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'a1'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'a2'},{'id': '277', 'type': 'call', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': '_agent_list_product'},{'id': '279', 'type': 'argument_list', 'children': ['280']},{'id': '280', 'type': 'tuple', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'activator_agent'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'affected_agent'},{'id': '283', 'type': 'block', 'children': ['284', '319', '325']},{'id': '284', 'type': 'if_statement', 'children': ['285', '286', '302']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'is_activation'},{'id': '286', 'type': 'block', 'children': ['287']},{'id': '287', 'type': 'expression_statement', 'children': ['288']},{'id': '288', 'type': 'assignment', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '290', 'type': 'call', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'Activation'},{'id': '292', 'type': 'argument_list', 'children': ['293', '294', '295']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'a1'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'a2'},{'id': '295', 'type': 'keyword_argument', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'evidence'},{'id': '297', 'type': 'list', 'children': ['298'], 'value': '[deepcopy(ev)]'},{'id': '298', 'type': 'call', 'children': ['299', '300']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'deepcopy'},{'id': '300', 'type': 'argument_list', 'children': ['301']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '302', 'type': 'else_clause', 'children': ['303']},{'id': '303', 'type': 'block', 'children': ['304']},{'id': '304', 'type': 'expression_statement', 'children': ['305']},{'id': '305', 'type': 'assignment', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '307', 'type': 'call', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'Inhibition'},{'id': '309', 'type': 'argument_list', 'children': ['310', '311', '312']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'a1'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'a2'},{'id': '312', 'type': 'keyword_argument', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'evidence'},{'id': '314', 'type': 'list', 'children': ['315'], 'value': '[deepcopy(ev)]'},{'id': '315', 'type': 'call', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'deepcopy'},{'id': '317', 'type': 'argument_list', 'children': ['318']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '319', 'type': 'expression_statement', 'children': ['320']},{'id': '320', 'type': 'call', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': '_stmt_location_to_agents'},{'id': '322', 'type': 'argument_list', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '325', 'type': 'expression_statement', 'children': ['326']},{'id': '326', 'type': 'call', 'children': ['327', '332']},{'id': '327', 'type': 'attribute', 'children': ['328', '331']},{'id': '328', 'type': 'attribute', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'statements'},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '332', 'type': 'argument_list', 'children': ['333']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'st'} | def get_activations(self):
act_events = self.tree.findall("EVENT/[type='ONT::ACTIVATE']")
inact_events = self.tree.findall("EVENT/[type='ONT::DEACTIVATE']")
inact_events += self.tree.findall("EVENT/[type='ONT::INHIBIT']")
for event in (act_events + inact_events):
event_id = event.attrib['id']
if event_id in self._static_events:
continue
agent = event.find(".//*[@role=':AGENT']")
if agent is None:
continue
agent_id = agent.attrib.get('id')
if agent_id is None:
logger.debug(
'Skipping activation with missing activator agent')
continue
activator_agent = self._get_agent_by_id(agent_id, event_id)
if activator_agent is None:
continue
affected = event.find(".//*[@role=':AFFECTED']")
if affected is None:
logger.debug(
'Skipping activation with missing affected agent')
continue
affected_id = affected.attrib.get('id')
if affected_id is None:
logger.debug(
'Skipping activation with missing affected agent')
continue
affected_agent = self._get_agent_by_id(affected_id, event_id)
if affected_agent is None:
logger.debug(
'Skipping activation with missing affected agent')
continue
is_activation = True
if _is_type(event, 'ONT::ACTIVATE'):
self._add_extracted('ONT::ACTIVATE', event.attrib['id'])
elif _is_type(event, 'ONT::INHIBIT'):
is_activation = False
self._add_extracted('ONT::INHIBIT', event.attrib['id'])
elif _is_type(event, 'ONT::DEACTIVATE'):
is_activation = False
self._add_extracted('ONT::DEACTIVATE', event.attrib['id'])
ev = self._get_evidence(event)
location = self._get_event_location(event)
for a1, a2 in _agent_list_product((activator_agent,
affected_agent)):
if is_activation:
st = Activation(a1, a2, evidence=[deepcopy(ev)])
else:
st = Inhibition(a1, a2, evidence=[deepcopy(ev)])
_stmt_location_to_agents(st, location)
self.statements.append(st) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_activations_causal'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '17']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'ccs'},{'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': 'tree'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'findall'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'string', 'children': [], 'value': '"CC/[type=\'ONT::CAUSE\']"'},{'id': '17', 'type': 'for_statement', 'children': ['18', '19', '20']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'cc'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'ccs'},{'id': '20', 'type': 'block', 'children': ['21', '30', '39', '49', '60', '73', '84', '97', '107', '116', '129', '139', '145', '154', '160', '169', '177', '186']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'factor'},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'cc'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'string', 'children': [], 'value': '"arg/[@role=\':FACTOR\']"'},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'outcome'},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'cc'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'string', 'children': [], 'value': '"arg/[@role=\':OUTCOME\']"'},{'id': '39', 'type': 'if_statement', 'children': ['40', '47']},{'id': '40', 'type': 'boolean_operator', 'children': ['41', '44'], 'value': 'or'},{'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': 'is'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'factor'},{'id': '43', 'type': 'None', 'children': []},{'id': '44', 'type': 'comparison_operator', 'children': ['45', '46'], 'value': 'is'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'outcome'},{'id': '46', 'type': 'None', 'children': []},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'continue_statement', 'children': []},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'factor_id'},{'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': 'factor'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'factor_term'},{'id': '63', 'type': 'call', 'children': ['64', '69']},{'id': '64', 'type': 'attribute', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'binary_operator', 'children': ['71', '72'], 'value': '%'},{'id': '71', 'type': 'string', 'children': [], 'value': '"TERM/[@id=\'%s\']"'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'factor_id'},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'outcome_id'},{'id': '76', 'type': 'call', 'children': ['77', '82']},{'id': '77', 'type': 'attribute', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'outcome'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'outcome_event'},{'id': '87', 'type': 'call', 'children': ['88', '93']},{'id': '88', 'type': 'attribute', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'binary_operator', 'children': ['95', '96'], 'value': '%'},{'id': '95', 'type': 'string', 'children': [], 'value': '"EVENT/[@id=\'%s\']"'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'outcome_id'},{'id': '97', 'type': 'if_statement', 'children': ['98', '105']},{'id': '98', 'type': 'boolean_operator', 'children': ['99', '102'], 'value': 'or'},{'id': '99', 'type': 'comparison_operator', 'children': ['100', '101'], 'value': 'is'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'factor_term'},{'id': '101', 'type': 'None', 'children': []},{'id': '102', 'type': 'comparison_operator', 'children': ['103', '104'], 'value': 'is'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'outcome_event'},{'id': '104', 'type': 'None', 'children': []},{'id': '105', 'type': 'block', 'children': ['106']},{'id': '106', 'type': 'continue_statement', 'children': []},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'factor_term_type'},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'factor_term'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '116', 'type': 'if_statement', 'children': ['117', '127']},{'id': '117', 'type': 'boolean_operator', 'children': ['118', '121', '122'], 'value': 'or'},{'id': '118', 'type': 'comparison_operator', 'children': ['119', '120'], 'value': 'is'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'factor_term_type'},{'id': '120', 'type': 'None', 'children': []},{'id': '121', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '122', 'type': 'comparison_operator', 'children': ['123', '126'], 'value': 'not'},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'factor_term_type'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'molecule_types'},{'id': '127', 'type': 'block', 'children': ['128']},{'id': '128', 'type': 'continue_statement', 'children': []},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'assignment', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'factor_agent'},{'id': '132', 'type': 'call', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '135', 'type': 'identifier', 'children': [], 'value': '_get_agent_by_id'},{'id': '136', 'type': 'argument_list', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'factor_id'},{'id': '138', 'type': 'None', 'children': []},{'id': '139', 'type': 'if_statement', 'children': ['140', '143']},{'id': '140', 'type': 'comparison_operator', 'children': ['141', '142'], 'value': 'is'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'factor_agent'},{'id': '142', 'type': 'None', 'children': []},{'id': '143', 'type': 'block', 'children': ['144']},{'id': '144', 'type': 'continue_statement', 'children': []},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'outcome_event_type'},{'id': '148', 'type': 'call', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'outcome_event'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '154', 'type': 'if_statement', 'children': ['155', '158']},{'id': '155', 'type': 'comparison_operator', 'children': ['156', '157'], 'value': 'is'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'outcome_event_type'},{'id': '157', 'type': 'None', 'children': []},{'id': '158', 'type': 'block', 'children': ['159']},{'id': '159', 'type': 'continue_statement', 'children': []},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '163', 'type': 'call', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '166', 'type': 'identifier', 'children': [], 'value': '_get_evidence'},{'id': '167', 'type': 'argument_list', 'children': ['168']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'cc'},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'assignment', 'children': ['171', '176']},{'id': '171', 'type': 'subscript', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'epistemics'},{'id': '175', 'type': 'string', 'children': [], 'value': "'direct'"},{'id': '176', 'type': 'False', 'children': []},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '180', 'type': 'call', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '183', 'type': 'identifier', 'children': [], 'value': '_get_event_location'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'outcome_event'},{'id': '186', 'type': 'if_statement', 'children': ['187', '195']},{'id': '187', 'type': 'comparison_operator', 'children': ['188', '191'], 'value': 'in'},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'outcome_event_type'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '191', 'type': 'list', 'children': ['192', '193', '194'], 'value': "['ONT::ACTIVATE', 'ONT::ACTIVITY',\n 'ONT::DEACTIVATE']"},{'id': '192', 'type': 'string', 'children': [], 'value': "'ONT::ACTIVATE'"},{'id': '193', 'type': 'string', 'children': [], 'value': "'ONT::ACTIVITY'"},{'id': '194', 'type': 'string', 'children': [], 'value': "'ONT::DEACTIVATE'"},{'id': '195', 'type': 'block', 'children': ['196', '230', '247', '261', '267', '284']},{'id': '196', 'type': 'if_statement', 'children': ['197', '204', '214']},{'id': '197', 'type': 'comparison_operator', 'children': ['198', '201'], 'value': 'in'},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'outcome_event_type'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '201', 'type': 'list', 'children': ['202', '203'], 'value': "['ONT::ACTIVATE',\n 'ONT::DEACTIVATE']"},{'id': '202', 'type': 'string', 'children': [], 'value': "'ONT::ACTIVATE'"},{'id': '203', 'type': 'string', 'children': [], 'value': "'ONT::DEACTIVATE'"},{'id': '204', 'type': 'block', 'children': ['205']},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'assignment', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'agent_tag'},{'id': '208', 'type': 'call', 'children': ['209', '212']},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'outcome_event'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '212', 'type': 'argument_list', 'children': ['213']},{'id': '213', 'type': 'string', 'children': [], 'value': '".//*[@role=\':AFFECTED\']"'},{'id': '214', 'type': 'elif_clause', 'children': ['215', '220']},{'id': '215', 'type': 'comparison_operator', 'children': ['216', '219'], 'value': '=='},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'outcome_event_type'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '219', 'type': 'string', 'children': [], 'value': "'ONT::ACTIVITY'"},{'id': '220', 'type': 'block', 'children': ['221']},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'assignment', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'agent_tag'},{'id': '224', 'type': 'call', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'outcome_event'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '228', 'type': 'argument_list', 'children': ['229']},{'id': '229', 'type': 'string', 'children': [], 'value': '".//*[@role=\':AGENT\']"'},{'id': '230', 'type': 'if_statement', 'children': ['231', '245']},{'id': '231', 'type': 'boolean_operator', 'children': ['232', '235'], 'value': 'or'},{'id': '232', 'type': 'comparison_operator', 'children': ['233', '234'], 'value': 'is'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'agent_tag'},{'id': '234', 'type': 'None', 'children': []},{'id': '235', 'type': 'comparison_operator', 'children': ['236', '244'], 'value': 'is'},{'id': '236', 'type': 'call', 'children': ['237', '242']},{'id': '237', 'type': 'attribute', 'children': ['238', '241']},{'id': '238', 'type': 'attribute', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'agent_tag'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '242', 'type': 'argument_list', 'children': ['243']},{'id': '243', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '244', 'type': 'None', 'children': []},{'id': '245', 'type': 'block', 'children': ['246']},{'id': '246', 'type': 'continue_statement', 'children': []},{'id': '247', 'type': 'expression_statement', 'children': ['248']},{'id': '248', 'type': 'assignment', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'outcome_agent'},{'id': '250', 'type': 'call', 'children': ['251', '254']},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '253', 'type': 'identifier', 'children': [], 'value': '_get_agent_by_id'},{'id': '254', 'type': 'argument_list', 'children': ['255', '260']},{'id': '255', 'type': 'subscript', 'children': ['256', '259']},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'agent_tag'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '259', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'outcome_id'},{'id': '261', 'type': 'if_statement', 'children': ['262', '265']},{'id': '262', 'type': 'comparison_operator', 'children': ['263', '264'], 'value': 'is'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'outcome_agent'},{'id': '264', 'type': 'None', 'children': []},{'id': '265', 'type': 'block', 'children': ['266']},{'id': '266', 'type': 'continue_statement', 'children': []},{'id': '267', 'type': 'if_statement', 'children': ['268', '273', '278']},{'id': '268', 'type': 'comparison_operator', 'children': ['269', '272'], 'value': '=='},{'id': '269', 'type': 'attribute', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'outcome_event_type'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '272', 'type': 'string', 'children': [], 'value': "'ONT::DEACTIVATE'"},{'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': 'is_activation'},{'id': '277', 'type': 'False', 'children': []},{'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': 'is_activation'},{'id': '283', 'type': 'True', 'children': []},{'id': '284', 'type': 'for_statement', 'children': ['285', '288', '294']},{'id': '285', 'type': 'pattern_list', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'a1'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'a2'},{'id': '288', 'type': 'call', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': '_agent_list_product'},{'id': '290', 'type': 'argument_list', 'children': ['291']},{'id': '291', 'type': 'tuple', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'factor_agent'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'outcome_agent'},{'id': '294', 'type': 'block', 'children': ['295', '330', '336']},{'id': '295', 'type': 'if_statement', 'children': ['296', '297', '313']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'is_activation'},{'id': '297', 'type': 'block', 'children': ['298']},{'id': '298', 'type': 'expression_statement', 'children': ['299']},{'id': '299', 'type': 'assignment', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '301', 'type': 'call', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'Activation'},{'id': '303', 'type': 'argument_list', 'children': ['304', '305', '306']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'a1'},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'a2'},{'id': '306', 'type': 'keyword_argument', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'evidence'},{'id': '308', 'type': 'list', 'children': ['309'], 'value': '[deepcopy(ev)]'},{'id': '309', 'type': 'call', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'deepcopy'},{'id': '311', 'type': 'argument_list', 'children': ['312']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '313', 'type': 'else_clause', 'children': ['314']},{'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': 'st'},{'id': '318', 'type': 'call', 'children': ['319', '320']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'Inhibition'},{'id': '320', 'type': 'argument_list', 'children': ['321', '322', '323']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'a1'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'a2'},{'id': '323', 'type': 'keyword_argument', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'evidence'},{'id': '325', 'type': 'list', 'children': ['326'], 'value': '[deepcopy(ev)]'},{'id': '326', 'type': 'call', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'deepcopy'},{'id': '328', 'type': 'argument_list', 'children': ['329']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '330', 'type': 'expression_statement', 'children': ['331']},{'id': '331', 'type': 'call', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': '_stmt_location_to_agents'},{'id': '333', 'type': 'argument_list', 'children': ['334', '335']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '336', 'type': 'expression_statement', 'children': ['337']},{'id': '337', 'type': 'call', 'children': ['338', '343']},{'id': '338', 'type': 'attribute', 'children': ['339', '342']},{'id': '339', 'type': 'attribute', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'statements'},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '343', 'type': 'argument_list', 'children': ['344']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'st'} | def get_activations_causal(self):
ccs = self.tree.findall("CC/[type='ONT::CAUSE']")
for cc in ccs:
factor = cc.find("arg/[@role=':FACTOR']")
outcome = cc.find("arg/[@role=':OUTCOME']")
if factor is None or outcome is None:
continue
factor_id = factor.attrib.get('id')
factor_term = self.tree.find("TERM/[@id='%s']" % factor_id)
outcome_id = outcome.attrib.get('id')
outcome_event = self.tree.find("EVENT/[@id='%s']" % outcome_id)
if factor_term is None or outcome_event is None:
continue
factor_term_type = factor_term.find('type')
if factor_term_type is None or \
factor_term_type.text not in molecule_types:
continue
factor_agent = self._get_agent_by_id(factor_id, None)
if factor_agent is None:
continue
outcome_event_type = outcome_event.find('type')
if outcome_event_type is None:
continue
ev = self._get_evidence(cc)
ev.epistemics['direct'] = False
location = self._get_event_location(outcome_event)
if outcome_event_type.text in ['ONT::ACTIVATE', 'ONT::ACTIVITY',
'ONT::DEACTIVATE']:
if outcome_event_type.text in ['ONT::ACTIVATE',
'ONT::DEACTIVATE']:
agent_tag = outcome_event.find(".//*[@role=':AFFECTED']")
elif outcome_event_type.text == 'ONT::ACTIVITY':
agent_tag = outcome_event.find(".//*[@role=':AGENT']")
if agent_tag is None or agent_tag.attrib.get('id') is None:
continue
outcome_agent = self._get_agent_by_id(agent_tag.attrib['id'],
outcome_id)
if outcome_agent is None:
continue
if outcome_event_type.text == 'ONT::DEACTIVATE':
is_activation = False
else:
is_activation = True
for a1, a2 in _agent_list_product((factor_agent,
outcome_agent)):
if is_activation:
st = Activation(a1, a2, evidence=[deepcopy(ev)])
else:
st = Inhibition(a1, a2, evidence=[deepcopy(ev)])
_stmt_location_to_agents(st, location)
self.statements.append(st) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_activations_stimulate'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '17']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'stim_events'},{'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': 'tree'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'findall'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'string', 'children': [], 'value': '"EVENT/[type=\'ONT::STIMULATE\']"'},{'id': '17', 'type': 'for_statement', 'children': ['18', '19', '20']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'stim_events'},{'id': '20', 'type': 'block', 'children': ['21', '32', '40', '49', '58', '68', '79', '92', '103', '116', '126', '135', '148', '158', '164', '173', '179', '188', '196', '205']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'event_id'},{'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': 'event'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '32', 'type': 'if_statement', 'children': ['33', '38']},{'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': 'in'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'event_id'},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': '_static_events'},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'continue_statement', 'children': []},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'controller'},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'string', 'children': [], 'value': '"arg1/[@role=\':AGENT\']"'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'affected'},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'string', 'children': [], 'value': '"arg2/[@role=\':AFFECTED\']"'},{'id': '58', 'type': 'if_statement', 'children': ['59', '66']},{'id': '59', 'type': 'boolean_operator', 'children': ['60', '63'], 'value': 'or'},{'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': 'is'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'controller'},{'id': '62', 'type': 'None', 'children': []},{'id': '63', 'type': 'comparison_operator', 'children': ['64', '65'], 'value': 'is'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'affected'},{'id': '65', 'type': 'None', 'children': []},{'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': 'controller_id'},{'id': '71', 'type': 'call', 'children': ['72', '77']},{'id': '72', 'type': 'attribute', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'controller'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'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': 'controller_term'},{'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': 'self'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'binary_operator', 'children': ['90', '91'], 'value': '%'},{'id': '90', 'type': 'string', 'children': [], 'value': '"TERM/[@id=\'%s\']"'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'controller_id'},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'affected_id'},{'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': 'affected'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'affected_event'},{'id': '106', 'type': 'call', 'children': ['107', '112']},{'id': '107', 'type': 'attribute', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'binary_operator', 'children': ['114', '115'], 'value': '%'},{'id': '114', 'type': 'string', 'children': [], 'value': '"EVENT/[@id=\'%s\']"'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'affected_id'},{'id': '116', 'type': 'if_statement', 'children': ['117', '124']},{'id': '117', 'type': 'boolean_operator', 'children': ['118', '121'], 'value': 'or'},{'id': '118', 'type': 'comparison_operator', 'children': ['119', '120'], 'value': 'is'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'controller_term'},{'id': '120', 'type': 'None', 'children': []},{'id': '121', 'type': 'comparison_operator', 'children': ['122', '123'], 'value': 'is'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'affected_event'},{'id': '123', 'type': 'None', 'children': []},{'id': '124', 'type': 'block', 'children': ['125']},{'id': '125', 'type': 'continue_statement', 'children': []},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'controller_term_type'},{'id': '129', 'type': 'call', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'controller_term'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '135', 'type': 'if_statement', 'children': ['136', '146']},{'id': '136', 'type': 'boolean_operator', 'children': ['137', '140', '141'], 'value': 'or'},{'id': '137', 'type': 'comparison_operator', 'children': ['138', '139'], 'value': 'is'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'controller_term_type'},{'id': '139', 'type': 'None', 'children': []},{'id': '140', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '141', 'type': 'comparison_operator', 'children': ['142', '145'], 'value': 'not'},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'controller_term_type'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'molecule_types'},{'id': '146', 'type': 'block', 'children': ['147']},{'id': '147', 'type': 'continue_statement', 'children': []},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'controller_agent'},{'id': '151', 'type': 'call', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '154', 'type': 'identifier', 'children': [], 'value': '_get_agent_by_id'},{'id': '155', 'type': 'argument_list', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'controller_id'},{'id': '157', 'type': 'None', 'children': []},{'id': '158', 'type': 'if_statement', 'children': ['159', '162']},{'id': '159', 'type': 'comparison_operator', 'children': ['160', '161'], 'value': 'is'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'controller_agent'},{'id': '161', 'type': 'None', 'children': []},{'id': '162', 'type': 'block', 'children': ['163']},{'id': '163', 'type': 'continue_statement', 'children': []},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'assignment', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'affected_event_type'},{'id': '167', 'type': 'call', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'affected_event'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '173', 'type': 'if_statement', 'children': ['174', '177']},{'id': '174', 'type': 'comparison_operator', 'children': ['175', '176'], 'value': 'is'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'affected_event_type'},{'id': '176', 'type': 'None', 'children': []},{'id': '177', 'type': 'block', 'children': ['178']},{'id': '178', 'type': 'continue_statement', 'children': []},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'assignment', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '182', 'type': 'call', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '185', 'type': 'identifier', 'children': [], 'value': '_get_evidence'},{'id': '186', 'type': 'argument_list', 'children': ['187']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'assignment', 'children': ['190', '195']},{'id': '190', 'type': 'subscript', 'children': ['191', '194']},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'epistemics'},{'id': '194', 'type': 'string', 'children': [], 'value': "'direct'"},{'id': '195', 'type': 'False', 'children': []},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'assignment', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '199', 'type': 'call', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '202', 'type': 'identifier', 'children': [], 'value': '_get_event_location'},{'id': '203', 'type': 'argument_list', 'children': ['204']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'affected_event'},{'id': '205', 'type': 'if_statement', 'children': ['206', '211', '288']},{'id': '206', 'type': 'comparison_operator', 'children': ['207', '210'], 'value': '=='},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'affected_event_type'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '210', 'type': 'string', 'children': [], 'value': "'ONT::ACTIVATE'"},{'id': '211', 'type': 'block', 'children': ['212', '221', '227', '241', '247']},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'assignment', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'affected'},{'id': '215', 'type': 'call', 'children': ['216', '219']},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'affected_event'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '219', 'type': 'argument_list', 'children': ['220']},{'id': '220', 'type': 'string', 'children': [], 'value': '".//*[@role=\':AFFECTED\']"'},{'id': '221', 'type': 'if_statement', 'children': ['222', '225']},{'id': '222', 'type': 'comparison_operator', 'children': ['223', '224'], 'value': 'is'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'affected'},{'id': '224', 'type': 'None', 'children': []},{'id': '225', 'type': 'block', 'children': ['226']},{'id': '226', 'type': 'continue_statement', 'children': []},{'id': '227', 'type': 'expression_statement', 'children': ['228']},{'id': '228', 'type': 'assignment', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'affected_agent'},{'id': '230', 'type': 'call', 'children': ['231', '234']},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '233', 'type': 'identifier', 'children': [], 'value': '_get_agent_by_id'},{'id': '234', 'type': 'argument_list', 'children': ['235', '240']},{'id': '235', 'type': 'subscript', 'children': ['236', '239']},{'id': '236', 'type': 'attribute', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'affected'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '239', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'affected_id'},{'id': '241', 'type': 'if_statement', 'children': ['242', '245']},{'id': '242', 'type': 'comparison_operator', 'children': ['243', '244'], 'value': 'is'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'affected_agent'},{'id': '244', 'type': 'None', 'children': []},{'id': '245', 'type': 'block', 'children': ['246']},{'id': '246', 'type': 'continue_statement', 'children': []},{'id': '247', 'type': 'for_statement', 'children': ['248', '251', '257']},{'id': '248', 'type': 'pattern_list', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'a1'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'a2'},{'id': '251', 'type': 'call', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': '_agent_list_product'},{'id': '253', 'type': 'argument_list', 'children': ['254']},{'id': '254', 'type': 'tuple', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'controller_agent'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'affected_agent'},{'id': '257', 'type': 'block', 'children': ['258', '273', '279']},{'id': '258', 'type': 'expression_statement', 'children': ['259']},{'id': '259', 'type': 'assignment', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '261', 'type': 'call', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'Activation'},{'id': '263', 'type': 'argument_list', 'children': ['264', '265', '266']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'a1'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'a2'},{'id': '266', 'type': 'keyword_argument', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'evidence'},{'id': '268', 'type': 'list', 'children': ['269'], 'value': '[deepcopy(ev)]'},{'id': '269', 'type': 'call', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'deepcopy'},{'id': '271', 'type': 'argument_list', 'children': ['272']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '273', 'type': 'expression_statement', 'children': ['274']},{'id': '274', 'type': 'call', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': '_stmt_location_to_agents'},{'id': '276', 'type': 'argument_list', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '279', 'type': 'expression_statement', 'children': ['280']},{'id': '280', 'type': 'call', 'children': ['281', '286']},{'id': '281', 'type': 'attribute', 'children': ['282', '285']},{'id': '282', 'type': 'attribute', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'statements'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '286', 'type': 'argument_list', 'children': ['287']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '288', 'type': 'elif_clause', 'children': ['289', '294']},{'id': '289', 'type': 'comparison_operator', 'children': ['290', '293'], 'value': '=='},{'id': '290', 'type': 'attribute', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'affected_event_type'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '293', 'type': 'string', 'children': [], 'value': "'ONT::ACTIVITY'"},{'id': '294', 'type': 'block', 'children': ['295', '304', '310', '324', '330']},{'id': '295', 'type': 'expression_statement', 'children': ['296']},{'id': '296', 'type': 'assignment', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'agent_tag'},{'id': '298', 'type': 'call', 'children': ['299', '302']},{'id': '299', 'type': 'attribute', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'affected_event'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '302', 'type': 'argument_list', 'children': ['303']},{'id': '303', 'type': 'string', 'children': [], 'value': '".//*[@role=\':AGENT\']"'},{'id': '304', 'type': 'if_statement', 'children': ['305', '308']},{'id': '305', 'type': 'comparison_operator', 'children': ['306', '307'], 'value': 'is'},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'agent_tag'},{'id': '307', 'type': 'None', 'children': []},{'id': '308', 'type': 'block', 'children': ['309']},{'id': '309', 'type': 'continue_statement', 'children': []},{'id': '310', 'type': 'expression_statement', 'children': ['311']},{'id': '311', 'type': 'assignment', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'affected_agent'},{'id': '313', 'type': 'call', 'children': ['314', '317']},{'id': '314', 'type': 'attribute', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '316', 'type': 'identifier', 'children': [], 'value': '_get_agent_by_id'},{'id': '317', 'type': 'argument_list', 'children': ['318', '323']},{'id': '318', 'type': 'subscript', 'children': ['319', '322']},{'id': '319', 'type': 'attribute', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'agent_tag'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '322', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'affected_id'},{'id': '324', 'type': 'if_statement', 'children': ['325', '328']},{'id': '325', 'type': 'comparison_operator', 'children': ['326', '327'], 'value': 'is'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'affected_agent'},{'id': '327', 'type': 'None', 'children': []},{'id': '328', 'type': 'block', 'children': ['329']},{'id': '329', 'type': 'continue_statement', 'children': []},{'id': '330', 'type': 'for_statement', 'children': ['331', '334', '340']},{'id': '331', 'type': 'pattern_list', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'a1'},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'a2'},{'id': '334', 'type': 'call', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': '_agent_list_product'},{'id': '336', 'type': 'argument_list', 'children': ['337']},{'id': '337', 'type': 'tuple', 'children': ['338', '339']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'controller_agent'},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'affected_agent'},{'id': '340', 'type': 'block', 'children': ['341', '356', '362']},{'id': '341', 'type': 'expression_statement', 'children': ['342']},{'id': '342', 'type': 'assignment', 'children': ['343', '344']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '344', 'type': 'call', 'children': ['345', '346']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'Activation'},{'id': '346', 'type': 'argument_list', 'children': ['347', '348', '349']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'a1'},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'a2'},{'id': '349', 'type': 'keyword_argument', 'children': ['350', '351']},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'evidence'},{'id': '351', 'type': 'list', 'children': ['352'], 'value': '[deepcopy(ev)]'},{'id': '352', 'type': 'call', 'children': ['353', '354']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'deepcopy'},{'id': '354', 'type': 'argument_list', 'children': ['355']},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '356', 'type': 'expression_statement', 'children': ['357']},{'id': '357', 'type': 'call', 'children': ['358', '359']},{'id': '358', 'type': 'identifier', 'children': [], 'value': '_stmt_location_to_agents'},{'id': '359', 'type': 'argument_list', 'children': ['360', '361']},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '362', 'type': 'expression_statement', 'children': ['363']},{'id': '363', 'type': 'call', 'children': ['364', '369']},{'id': '364', 'type': 'attribute', 'children': ['365', '368']},{'id': '365', 'type': 'attribute', 'children': ['366', '367']},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'statements'},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '369', 'type': 'argument_list', 'children': ['370']},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'st'} | def get_activations_stimulate(self):
stim_events = self.tree.findall("EVENT/[type='ONT::STIMULATE']")
for event in stim_events:
event_id = event.attrib.get('id')
if event_id in self._static_events:
continue
controller = event.find("arg1/[@role=':AGENT']")
affected = event.find("arg2/[@role=':AFFECTED']")
if controller is None or affected is None:
continue
controller_id = controller.attrib.get('id')
controller_term = self.tree.find("TERM/[@id='%s']" % controller_id)
affected_id = affected.attrib.get('id')
affected_event = self.tree.find("EVENT/[@id='%s']" % affected_id)
if controller_term is None or affected_event is None:
continue
controller_term_type = controller_term.find('type')
if controller_term_type is None or \
controller_term_type.text not in molecule_types:
continue
controller_agent = self._get_agent_by_id(controller_id, None)
if controller_agent is None:
continue
affected_event_type = affected_event.find('type')
if affected_event_type is None:
continue
ev = self._get_evidence(event)
ev.epistemics['direct'] = False
location = self._get_event_location(affected_event)
if affected_event_type.text == 'ONT::ACTIVATE':
affected = affected_event.find(".//*[@role=':AFFECTED']")
if affected is None:
continue
affected_agent = self._get_agent_by_id(affected.attrib['id'],
affected_id)
if affected_agent is None:
continue
for a1, a2 in _agent_list_product((controller_agent,
affected_agent)):
st = Activation(a1, a2, evidence=[deepcopy(ev)])
_stmt_location_to_agents(st, location)
self.statements.append(st)
elif affected_event_type.text == 'ONT::ACTIVITY':
agent_tag = affected_event.find(".//*[@role=':AGENT']")
if agent_tag is None:
continue
affected_agent = self._get_agent_by_id(agent_tag.attrib['id'],
affected_id)
if affected_agent is None:
continue
for a1, a2 in _agent_list_product((controller_agent,
affected_agent)):
st = Activation(a1, a2, evidence=[deepcopy(ev)])
_stmt_location_to_agents(st, location)
self.statements.append(st) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_degradations'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '17']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'deg_events'},{'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': 'tree'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'findall'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'string', 'children': [], 'value': '"EVENT/[type=\'ONT::CONSUME\']"'},{'id': '17', 'type': 'for_statement', 'children': ['18', '19', '20']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'deg_events'},{'id': '20', 'type': 'block', 'children': ['21', '33', '42', '59', '70', '83', '97', '110', '119', '166', '175', '184', '225']},{'id': '21', 'type': 'if_statement', 'children': ['22', '31']},{'id': '22', 'type': 'comparison_operator', 'children': ['23', '28'], 'value': 'in'},{'id': '23', 'type': 'subscript', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '27', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '30', 'type': 'identifier', 'children': [], 'value': '_static_events'},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'continue_statement', 'children': []},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'affected'},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'string', 'children': [], 'value': '".//*[@role=\':AFFECTED\']"'},{'id': '42', 'type': 'if_statement', 'children': ['43', '46']},{'id': '43', 'type': 'comparison_operator', 'children': ['44', '45'], 'value': 'is'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'affected'},{'id': '45', 'type': 'None', 'children': []},{'id': '46', 'type': 'block', 'children': ['47', '51', '58']},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '50', 'type': 'string', 'children': [], 'value': "'Skipping degradation event with no affected term.'"},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '58', 'type': 'continue_statement', 'children': []},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'affected_id'},{'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': 'affected'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '70', 'type': 'if_statement', 'children': ['71', '74']},{'id': '71', 'type': 'comparison_operator', 'children': ['72', '73'], 'value': 'is'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'affected_id'},{'id': '73', 'type': 'None', 'children': []},{'id': '74', 'type': 'block', 'children': ['75', '82']},{'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': 'logger'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'string', 'children': [], 'value': "'Skipping degradation event with missing affected agent'"},{'id': '82', 'type': 'continue_statement', 'children': []},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'affected_agent'},{'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': '_get_agent_by_id'},{'id': '90', 'type': 'argument_list', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'affected_id'},{'id': '92', 'type': 'subscript', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '96', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '97', 'type': 'if_statement', 'children': ['98', '101']},{'id': '98', 'type': 'comparison_operator', 'children': ['99', '100'], 'value': 'is'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'affected_agent'},{'id': '100', 'type': 'None', 'children': []},{'id': '101', 'type': 'block', 'children': ['102', '109']},{'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': 'logger'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'string', 'children': [], 'value': "'Skipping degradation event with missing affected agent'"},{'id': '109', 'type': 'continue_statement', 'children': []},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'assignment', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '113', 'type': 'call', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '117', 'type': 'argument_list', 'children': ['118']},{'id': '118', 'type': 'string', 'children': [], 'value': '".//*[@role=\':AGENT\']"'},{'id': '119', 'type': 'if_statement', 'children': ['120', '123', '128']},{'id': '120', 'type': 'comparison_operator', 'children': ['121', '122'], 'value': 'is'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '122', 'type': 'None', 'children': []},{'id': '123', 'type': 'block', 'children': ['124']},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'assignment', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'agent_agent'},{'id': '127', 'type': 'None', 'children': []},{'id': '128', 'type': 'else_clause', 'children': ['129']},{'id': '129', 'type': 'block', 'children': ['130', '141']},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'agent_id'},{'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': 'agent'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '141', 'type': 'if_statement', 'children': ['142', '145', '150']},{'id': '142', 'type': 'comparison_operator', 'children': ['143', '144'], 'value': 'is'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'agent_id'},{'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': 'agent_agent'},{'id': '149', 'type': 'None', 'children': []},{'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': 'agent_agent'},{'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_agent_by_id'},{'id': '159', 'type': 'argument_list', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'agent_id'},{'id': '161', 'type': 'subscript', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '165', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '169', 'type': 'call', 'children': ['170', '173']},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '172', 'type': 'identifier', 'children': [], 'value': '_get_evidence'},{'id': '173', 'type': 'argument_list', 'children': ['174']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'assignment', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'location'},{'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': '_get_event_location'},{'id': '182', 'type': 'argument_list', 'children': ['183']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '184', 'type': 'for_statement', 'children': ['185', '188', '189', '195']},{'id': '185', 'type': 'pattern_list', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'subj'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '188', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '189', 'type': 'call', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': '_agent_list_product'},{'id': '191', 'type': 'argument_list', 'children': ['192']},{'id': '192', 'type': 'tuple', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'agent_agent'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'affected_agent'},{'id': '195', 'type': 'block', 'children': ['196', '210', '216']},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'assignment', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '199', 'type': 'call', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'DecreaseAmount'},{'id': '201', 'type': 'argument_list', 'children': ['202', '203', '204']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'subj'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '204', 'type': 'keyword_argument', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'evidence'},{'id': '206', 'type': 'call', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'deepcopy'},{'id': '208', 'type': 'argument_list', 'children': ['209']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'id': '211', 'type': 'call', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': '_stmt_location_to_agents'},{'id': '213', 'type': 'argument_list', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '216', 'type': 'expression_statement', 'children': ['217']},{'id': '217', 'type': 'call', 'children': ['218', '223']},{'id': '218', 'type': 'attribute', 'children': ['219', '222']},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'statements'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '223', 'type': 'argument_list', 'children': ['224']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '225', 'type': 'expression_statement', 'children': ['226']},{'id': '226', 'type': 'call', 'children': ['227', '230']},{'id': '227', 'type': 'attribute', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '229', 'type': 'identifier', 'children': [], 'value': '_add_extracted'},{'id': '230', 'type': 'argument_list', 'children': ['231', '235']},{'id': '231', 'type': 'call', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': '_get_type'},{'id': '233', 'type': 'argument_list', 'children': ['234']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '235', 'type': 'subscript', 'children': ['236', '239']},{'id': '236', 'type': 'attribute', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '239', 'type': 'string', 'children': [], 'value': "'id'"} | def get_degradations(self):
deg_events = self.tree.findall("EVENT/[type='ONT::CONSUME']")
for event in deg_events:
if event.attrib['id'] in self._static_events:
continue
affected = event.find(".//*[@role=':AFFECTED']")
if affected is None:
msg = 'Skipping degradation event with no affected term.'
logger.debug(msg)
continue
affected_id = affected.attrib.get('id')
if affected_id is None:
logger.debug(
'Skipping degradation event with missing affected agent')
continue
affected_agent = self._get_agent_by_id(affected_id,
event.attrib['id'])
if affected_agent is None:
logger.debug(
'Skipping degradation event with missing affected agent')
continue
agent = event.find(".//*[@role=':AGENT']")
if agent is None:
agent_agent = None
else:
agent_id = agent.attrib.get('id')
if agent_id is None:
agent_agent = None
else:
agent_agent = self._get_agent_by_id(agent_id,
event.attrib['id'])
ev = self._get_evidence(event)
location = self._get_event_location(event)
for subj, obj in \
_agent_list_product((agent_agent, affected_agent)):
st = DecreaseAmount(subj, obj, evidence=deepcopy(ev))
_stmt_location_to_agents(st, location)
self.statements.append(st)
self._add_extracted(_get_type(event), event.attrib['id']) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_complexes'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '17', '28']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'bind_events'},{'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': 'tree'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'findall'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'string', 'children': [], 'value': '"EVENT/[type=\'ONT::BIND\']"'},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'augmented_assignment', 'children': ['19', '20'], 'value': '+='},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'bind_events'},{'id': '20', 'type': 'call', 'children': ['21', '26']},{'id': '21', 'type': 'attribute', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'findall'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'string', 'children': [], 'value': '"EVENT/[type=\'ONT::INTERACT\']"'},{'id': '28', 'type': 'for_statement', 'children': ['29', '30', '31']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'bind_events'},{'id': '31', 'type': 'block', 'children': ['32', '44', '53', '62', '104', '146', '164', '182', '199', '201', '210', '219', '260']},{'id': '32', 'type': 'if_statement', 'children': ['33', '42']},{'id': '33', 'type': 'comparison_operator', 'children': ['34', '39'], 'value': 'in'},{'id': '34', 'type': 'subscript', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '38', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '41', 'type': 'identifier', 'children': [], 'value': '_static_events'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'continue_statement', 'children': []},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'arg1'},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'string', 'children': [], 'value': '"arg1"'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'arg2'},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'string', 'children': [], 'value': '"arg2"'},{'id': '62', 'type': 'if_statement', 'children': ['63', '70']},{'id': '63', 'type': 'boolean_operator', 'children': ['64', '67'], 'value': 'and'},{'id': '64', 'type': 'comparison_operator', 'children': ['65', '66'], 'value': 'is'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'arg1'},{'id': '66', 'type': 'None', 'children': []},{'id': '67', 'type': 'comparison_operator', 'children': ['68', '69'], 'value': 'is'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'arg2'},{'id': '69', 'type': 'None', 'children': []},{'id': '70', 'type': 'block', 'children': ['71', '83', '92', '98']},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'findall'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'string', 'children': [], 'value': "'arg'"},{'id': '83', 'type': 'if_statement', 'children': ['84', '90']},{'id': '84', 'type': 'comparison_operator', 'children': ['85', '89'], 'value': '<'},{'id': '85', 'type': 'call', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '89', 'type': 'integer', 'children': [], 'value': '2'},{'id': '90', 'type': 'block', 'children': ['91']},{'id': '91', 'type': 'continue_statement', 'children': []},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'arg1'},{'id': '95', 'type': 'subscript', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '97', 'type': 'integer', 'children': [], 'value': '0'},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'arg2'},{'id': '101', 'type': 'subscript', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '103', 'type': 'integer', 'children': [], 'value': '1'},{'id': '104', 'type': 'if_statement', 'children': ['105', '137']},{'id': '105', 'type': 'boolean_operator', 'children': ['106', '121', '122'], 'value': 'or'},{'id': '106', 'type': '()', 'children': ['107']},{'id': '107', 'type': 'boolean_operator', 'children': ['108', '111'], 'value': 'or'},{'id': '108', 'type': 'comparison_operator', 'children': ['109', '110'], 'value': 'is'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'arg1'},{'id': '110', 'type': 'None', 'children': []},{'id': '111', 'type': 'comparison_operator', 'children': ['112', '120'], 'value': 'is'},{'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': 'arg1'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '120', 'type': 'None', 'children': []},{'id': '121', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '122', 'type': '()', 'children': ['123']},{'id': '123', 'type': 'boolean_operator', 'children': ['124', '127'], 'value': 'or'},{'id': '124', 'type': 'comparison_operator', 'children': ['125', '126'], 'value': 'is'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'arg2'},{'id': '126', 'type': 'None', 'children': []},{'id': '127', 'type': 'comparison_operator', 'children': ['128', '136'], 'value': 'is'},{'id': '128', 'type': 'call', 'children': ['129', '134']},{'id': '129', 'type': 'attribute', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'arg2'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '136', 'type': 'None', 'children': []},{'id': '137', 'type': 'block', 'children': ['138', '145']},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'string', 'children': [], 'value': "'Skipping complex with less than 2 members'"},{'id': '145', 'type': 'continue_statement', 'children': []},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'assignment', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'agent1'},{'id': '149', 'type': 'call', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '152', 'type': 'identifier', 'children': [], 'value': '_get_agent_by_id'},{'id': '153', 'type': 'argument_list', 'children': ['154', '159']},{'id': '154', 'type': 'subscript', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'arg1'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '158', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '159', 'type': 'subscript', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '163', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'assignment', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'agent2'},{'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': '_get_agent_by_id'},{'id': '171', 'type': 'argument_list', 'children': ['172', '177']},{'id': '172', 'type': 'subscript', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'arg2'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '176', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '177', 'type': 'subscript', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '181', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '182', 'type': 'if_statement', 'children': ['183', '190']},{'id': '183', 'type': 'boolean_operator', 'children': ['184', '187'], 'value': 'or'},{'id': '184', 'type': 'comparison_operator', 'children': ['185', '186'], 'value': 'is'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'agent1'},{'id': '186', 'type': 'None', 'children': []},{'id': '187', 'type': 'comparison_operator', 'children': ['188', '189'], 'value': 'is'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'agent2'},{'id': '189', 'type': 'None', 'children': []},{'id': '190', 'type': 'block', 'children': ['191', '198']},{'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': 'logger'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '196', 'type': 'argument_list', 'children': ['197']},{'id': '197', 'type': 'string', 'children': [], 'value': "'Skipping complex with less than 2 members'"},{'id': '198', 'type': 'continue_statement', 'children': []},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'string', 'children': [], 'value': '\'\'\'\n site_feature = self._find_in_term(arg1.attrib[\'id\'], \'features/site\')\n if site_feature is not None:\n sites, positions = self._get_site_by_id(site_id)\n print sites, positions\n site_feature = self._find_in_term(arg2.attrib[\'id\'], \'features/site\')\n if site_feature is not None:\n sites, positions = self._get_site_by_id(site_id)\n print sites, positions\n site = event.find("site")\n if site is not None:\n sites, positions = self._get_site_by_id(site.attrib[\'id\'])\n print sites, positions\n \'\'\''},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'assignment', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '204', 'type': 'call', 'children': ['205', '208']},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '207', 'type': 'identifier', 'children': [], 'value': '_get_evidence'},{'id': '208', 'type': 'argument_list', 'children': ['209']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'id': '211', 'type': 'assignment', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'location'},{'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_event_location'},{'id': '217', 'type': 'argument_list', 'children': ['218']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '219', 'type': 'for_statement', 'children': ['220', '223', '229']},{'id': '220', 'type': 'pattern_list', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'a1'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'a2'},{'id': '223', 'type': 'call', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': '_agent_list_product'},{'id': '225', 'type': 'argument_list', 'children': ['226']},{'id': '226', 'type': 'tuple', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'agent1'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'agent2'},{'id': '229', 'type': 'block', 'children': ['230', '245', '251']},{'id': '230', 'type': 'expression_statement', 'children': ['231']},{'id': '231', 'type': 'assignment', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '233', 'type': 'call', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'Complex'},{'id': '235', 'type': 'argument_list', 'children': ['236', '239']},{'id': '236', 'type': 'list', 'children': ['237', '238'], 'value': '[a1, a2]'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'a1'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'a2'},{'id': '239', 'type': 'keyword_argument', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'evidence'},{'id': '241', 'type': 'call', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'deepcopy'},{'id': '243', 'type': 'argument_list', 'children': ['244']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'call', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': '_stmt_location_to_agents'},{'id': '248', 'type': 'argument_list', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '251', 'type': 'expression_statement', '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': 'self'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'statements'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '258', 'type': 'argument_list', 'children': ['259']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '260', 'type': 'expression_statement', 'children': ['261']},{'id': '261', 'type': 'call', 'children': ['262', '265']},{'id': '262', 'type': 'attribute', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '264', 'type': 'identifier', 'children': [], 'value': '_add_extracted'},{'id': '265', 'type': 'argument_list', 'children': ['266', '270']},{'id': '266', 'type': 'call', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': '_get_type'},{'id': '268', 'type': 'argument_list', 'children': ['269']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '270', 'type': 'subscript', 'children': ['271', '274']},{'id': '271', 'type': 'attribute', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '274', 'type': 'string', 'children': [], 'value': "'id'"} | def get_complexes(self):
bind_events = self.tree.findall("EVENT/[type='ONT::BIND']")
bind_events += self.tree.findall("EVENT/[type='ONT::INTERACT']")
for event in bind_events:
if event.attrib['id'] in self._static_events:
continue
arg1 = event.find("arg1")
arg2 = event.find("arg2")
if arg1 is None and arg2 is None:
args = list(event.findall('arg'))
if len(args) < 2:
continue
arg1 = args[0]
arg2 = args[1]
if (arg1 is None or arg1.attrib.get('id') is None) or \
(arg2 is None or arg2.attrib.get('id') is None):
logger.debug('Skipping complex with less than 2 members')
continue
agent1 = self._get_agent_by_id(arg1.attrib['id'],
event.attrib['id'])
agent2 = self._get_agent_by_id(arg2.attrib['id'],
event.attrib['id'])
if agent1 is None or agent2 is None:
logger.debug('Skipping complex with less than 2 members')
continue
'''
site_feature = self._find_in_term(arg1.attrib['id'], 'features/site')
if site_feature is not None:
sites, positions = self._get_site_by_id(site_id)
print sites, positions
site_feature = self._find_in_term(arg2.attrib['id'], 'features/site')
if site_feature is not None:
sites, positions = self._get_site_by_id(site_id)
print sites, positions
site = event.find("site")
if site is not None:
sites, positions = self._get_site_by_id(site.attrib['id'])
print sites, positions
'''
ev = self._get_evidence(event)
location = self._get_event_location(event)
for a1, a2 in _agent_list_product((agent1, agent2)):
st = Complex([a1, a2], evidence=deepcopy(ev))
_stmt_location_to_agents(st, location)
self.statements.append(st)
self._add_extracted(_get_type(event), event.attrib['id']) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_modifications_indirect'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '17', '22', '129', '236', '243', '250']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'mod_event_types'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'ont_to_mod_type'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '16', 'type': 'argument_list', 'children': []},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'augmented_assignment', 'children': ['19', '20'], 'value': '+='},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'mod_event_types'},{'id': '20', 'type': 'list', 'children': ['21'], 'value': "['ONT::PTM']"},{'id': '21', 'type': 'string', 'children': [], 'value': "'ONT::PTM'"},{'id': '22', 'type': 'function_definition', 'children': ['23', '24', '26']},{'id': '23', 'type': 'function_name', 'children': [], 'value': 'get_increase_events'},{'id': '24', 'type': 'parameters', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'mod_event_types'},{'id': '26', 'type': 'block', 'children': ['27', '31', '42', '127']},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'mod_events'},{'id': '30', 'type': 'list', 'children': [], 'value': '[]'},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'events'},{'id': '34', 'type': 'call', 'children': ['35', '40']},{'id': '35', 'type': 'attribute', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'findall'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'string', 'children': [], 'value': '"EVENT/[type=\'ONT::INCREASE\']"'},{'id': '42', 'type': 'for_statement', 'children': ['43', '44', '45']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'events'},{'id': '45', 'type': 'block', 'children': ['46', '55', '61', '72', '77', '83', '94']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'affected'},{'id': '49', 'type': 'call', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'string', 'children': [], 'value': '".//*[@role=\':AFFECTED\']"'},{'id': '55', 'type': 'if_statement', 'children': ['56', '59']},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': 'is'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'affected'},{'id': '58', 'type': 'None', 'children': []},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'continue_statement', 'children': []},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'affected_id'},{'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': 'affected'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '72', 'type': 'if_statement', 'children': ['73', '75']},{'id': '73', 'type': 'not_operator', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'affected_id'},{'id': '75', 'type': 'block', 'children': ['76']},{'id': '76', 'type': 'continue_statement', 'children': []},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '80', 'type': 'binary_operator', 'children': ['81', '82'], 'value': '%'},{'id': '81', 'type': 'string', 'children': [], 'value': '"EVENT/[@id=\'%s\']"'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'affected_id'},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'affected_event'},{'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': 'tree'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '94', 'type': 'if_statement', 'children': ['95', '98']},{'id': '95', 'type': 'comparison_operator', 'children': ['96', '97'], 'value': 'is'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'affected_event'},{'id': '97', 'type': 'None', 'children': []},{'id': '98', 'type': 'block', 'children': ['99', '108']},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'affected_type'},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'affected_event'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '108', 'type': 'if_statement', 'children': ['109', '119']},{'id': '109', 'type': 'boolean_operator', 'children': ['110', '113', '114'], 'value': 'and'},{'id': '110', 'type': 'comparison_operator', 'children': ['111', '112'], 'value': 'is'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'affected_type'},{'id': '112', 'type': 'None', 'children': []},{'id': '113', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '114', 'type': 'comparison_operator', 'children': ['115', '118'], 'value': 'in'},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'affected_type'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'mod_event_types'},{'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': 'mod_events'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '127', 'type': 'return_statement', 'children': ['128']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'mod_events'},{'id': '129', 'type': 'function_definition', 'children': ['130', '131', '133']},{'id': '130', 'type': 'function_name', 'children': [], 'value': 'get_cause_events'},{'id': '131', 'type': 'parameters', 'children': ['132']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'mod_event_types'},{'id': '133', 'type': 'block', 'children': ['134', '138', '149', '234']},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'mod_events'},{'id': '137', 'type': 'list', 'children': [], 'value': '[]'},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'assignment', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'ccs'},{'id': '141', 'type': 'call', 'children': ['142', '147']},{'id': '142', 'type': 'attribute', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'findall'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'string', 'children': [], 'value': '"CC/[type=\'ONT::CAUSE\']"'},{'id': '149', 'type': 'for_statement', 'children': ['150', '151', '152']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'cc'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'ccs'},{'id': '152', 'type': 'block', 'children': ['153', '162', '168', '179', '184', '190', '201']},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'outcome'},{'id': '156', 'type': 'call', 'children': ['157', '160']},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'cc'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'string', 'children': [], 'value': '".//*[@role=\':OUTCOME\']"'},{'id': '162', 'type': 'if_statement', 'children': ['163', '166']},{'id': '163', 'type': 'comparison_operator', 'children': ['164', '165'], 'value': 'is'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'outcome'},{'id': '165', 'type': 'None', 'children': []},{'id': '166', 'type': 'block', 'children': ['167']},{'id': '167', 'type': 'continue_statement', 'children': []},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'assignment', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'outcome_id'},{'id': '171', 'type': 'call', 'children': ['172', '177']},{'id': '172', 'type': 'attribute', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'outcome'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '177', 'type': 'argument_list', 'children': ['178']},{'id': '178', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '179', 'type': 'if_statement', 'children': ['180', '182']},{'id': '180', 'type': 'not_operator', 'children': ['181']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'outcome_id'},{'id': '182', 'type': 'block', 'children': ['183']},{'id': '183', 'type': 'continue_statement', 'children': []},{'id': '184', 'type': 'expression_statement', 'children': ['185']},{'id': '185', 'type': 'assignment', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '187', 'type': 'binary_operator', 'children': ['188', '189'], 'value': '%'},{'id': '188', 'type': 'string', 'children': [], 'value': '"EVENT/[@id=\'%s\']"'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'outcome_id'},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'assignment', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'outcome_event'},{'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': 'self'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '199', 'type': 'argument_list', 'children': ['200']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '201', 'type': 'if_statement', 'children': ['202', '205']},{'id': '202', 'type': 'comparison_operator', 'children': ['203', '204'], 'value': 'is'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'outcome_event'},{'id': '204', 'type': 'None', 'children': []},{'id': '205', 'type': 'block', 'children': ['206', '215']},{'id': '206', 'type': 'expression_statement', 'children': ['207']},{'id': '207', 'type': 'assignment', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'outcome_type'},{'id': '209', 'type': 'call', 'children': ['210', '213']},{'id': '210', 'type': 'attribute', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'outcome_event'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '213', 'type': 'argument_list', 'children': ['214']},{'id': '214', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '215', 'type': 'if_statement', 'children': ['216', '226']},{'id': '216', 'type': 'boolean_operator', 'children': ['217', '220', '221'], 'value': 'and'},{'id': '217', 'type': 'comparison_operator', 'children': ['218', '219'], 'value': 'is'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'outcome_type'},{'id': '219', 'type': 'None', 'children': []},{'id': '220', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '221', 'type': 'comparison_operator', 'children': ['222', '225'], 'value': 'in'},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'outcome_type'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'mod_event_types'},{'id': '226', 'type': 'block', 'children': ['227']},{'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': 'mod_events'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '232', 'type': 'argument_list', 'children': ['233']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'cc'},{'id': '234', 'type': 'return_statement', 'children': ['235']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'mod_events'},{'id': '236', 'type': 'expression_statement', 'children': ['237']},{'id': '237', 'type': 'assignment', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'mod_events'},{'id': '239', 'type': 'call', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'get_increase_events'},{'id': '241', 'type': 'argument_list', 'children': ['242']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'mod_event_types'},{'id': '243', 'type': 'expression_statement', 'children': ['244']},{'id': '244', 'type': 'augmented_assignment', 'children': ['245', '246'], 'value': '+='},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'mod_events'},{'id': '246', 'type': 'call', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'get_cause_events'},{'id': '248', 'type': 'argument_list', 'children': ['249']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'mod_event_types'},{'id': '250', 'type': 'for_statement', 'children': ['251', '252', '253']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'mod_events'},{'id': '253', 'type': 'block', 'children': ['254', '262', '270', '277', '286', '306', '317', '323', '333', '342', '362', '373', '378', '391', '397', '484', '496']},{'id': '254', 'type': 'expression_statement', 'children': ['255']},{'id': '255', 'type': 'assignment', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'event_id'},{'id': '257', 'type': 'subscript', 'children': ['258', '261']},{'id': '258', 'type': 'attribute', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '261', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '262', 'type': 'if_statement', 'children': ['263', '268']},{'id': '263', 'type': 'comparison_operator', 'children': ['264', '265'], 'value': 'in'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'event_id'},{'id': '265', 'type': 'attribute', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '267', 'type': 'identifier', 'children': [], 'value': '_static_events'},{'id': '268', 'type': 'block', 'children': ['269']},{'id': '269', 'type': 'continue_statement', 'children': []},{'id': '270', 'type': 'expression_statement', 'children': ['271']},{'id': '271', 'type': 'assignment', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'event_type'},{'id': '273', 'type': 'call', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': '_get_type'},{'id': '275', 'type': 'argument_list', 'children': ['276']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '277', 'type': 'expression_statement', 'children': ['278']},{'id': '278', 'type': 'assignment', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'enzyme'},{'id': '280', 'type': 'call', 'children': ['281', '284']},{'id': '281', 'type': 'attribute', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '284', 'type': 'argument_list', 'children': ['285']},{'id': '285', 'type': 'string', 'children': [], 'value': '".//*[@role=\':AGENT\']"'},{'id': '286', 'type': 'if_statement', 'children': ['287', '290']},{'id': '287', 'type': 'comparison_operator', 'children': ['288', '289'], 'value': 'is'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'enzyme'},{'id': '289', 'type': 'None', 'children': []},{'id': '290', 'type': 'block', 'children': ['291', '300']},{'id': '291', 'type': 'expression_statement', 'children': ['292']},{'id': '292', 'type': 'assignment', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'enzyme'},{'id': '294', 'type': 'call', 'children': ['295', '298']},{'id': '295', 'type': 'attribute', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '298', 'type': 'argument_list', 'children': ['299']},{'id': '299', 'type': 'string', 'children': [], 'value': '".//*[@role=\':FACTOR\']"'},{'id': '300', 'type': 'if_statement', 'children': ['301', '304']},{'id': '301', 'type': 'comparison_operator', 'children': ['302', '303'], 'value': 'is'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'enzyme'},{'id': '303', 'type': 'None', 'children': []},{'id': '304', 'type': 'block', 'children': ['305']},{'id': '305', 'type': 'return_statement', 'children': []},{'id': '306', 'type': 'expression_statement', 'children': ['307']},{'id': '307', 'type': 'assignment', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'enzyme_id'},{'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': 'enzyme'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '315', 'type': 'argument_list', 'children': ['316']},{'id': '316', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '317', 'type': 'if_statement', 'children': ['318', '321']},{'id': '318', 'type': 'comparison_operator', 'children': ['319', '320'], 'value': 'is'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'enzyme_id'},{'id': '320', 'type': 'None', 'children': []},{'id': '321', 'type': 'block', 'children': ['322']},{'id': '322', 'type': 'continue_statement', 'children': []},{'id': '323', 'type': 'expression_statement', 'children': ['324']},{'id': '324', 'type': 'assignment', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'enzyme_agent'},{'id': '326', 'type': 'call', 'children': ['327', '330']},{'id': '327', 'type': 'attribute', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '329', 'type': 'identifier', 'children': [], 'value': '_get_agent_by_id'},{'id': '330', 'type': 'argument_list', 'children': ['331', '332']},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'enzyme_id'},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'event_id'},{'id': '333', 'type': 'expression_statement', 'children': ['334']},{'id': '334', 'type': 'assignment', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'affected_event_tag'},{'id': '336', 'type': 'call', 'children': ['337', '340']},{'id': '337', 'type': 'attribute', 'children': ['338', '339']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '340', 'type': 'argument_list', 'children': ['341']},{'id': '341', 'type': 'string', 'children': [], 'value': '".//*[@role=\':AFFECTED\']"'},{'id': '342', 'type': 'if_statement', 'children': ['343', '346']},{'id': '343', 'type': 'comparison_operator', 'children': ['344', '345'], 'value': 'is'},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'affected_event_tag'},{'id': '345', 'type': 'None', 'children': []},{'id': '346', 'type': 'block', 'children': ['347', '356']},{'id': '347', 'type': 'expression_statement', 'children': ['348']},{'id': '348', 'type': 'assignment', 'children': ['349', '350']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'affected_event_tag'},{'id': '350', 'type': 'call', 'children': ['351', '354']},{'id': '351', 'type': 'attribute', 'children': ['352', '353']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '354', 'type': 'argument_list', 'children': ['355']},{'id': '355', 'type': 'string', 'children': [], 'value': '".//*[@role=\':OUTCOME\']"'},{'id': '356', 'type': 'if_statement', 'children': ['357', '360']},{'id': '357', 'type': 'comparison_operator', 'children': ['358', '359'], 'value': 'is'},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'affected_event_tag'},{'id': '359', 'type': 'None', 'children': []},{'id': '360', 'type': 'block', 'children': ['361']},{'id': '361', 'type': 'return_statement', 'children': []},{'id': '362', 'type': 'expression_statement', 'children': ['363']},{'id': '363', 'type': 'assignment', 'children': ['364', '365']},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'affected_id'},{'id': '365', 'type': 'call', 'children': ['366', '371']},{'id': '366', 'type': 'attribute', 'children': ['367', '370']},{'id': '367', 'type': 'attribute', 'children': ['368', '369']},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'affected_event_tag'},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '371', 'type': 'argument_list', 'children': ['372']},{'id': '372', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '373', 'type': 'if_statement', 'children': ['374', '376']},{'id': '374', 'type': 'not_operator', 'children': ['375']},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'affected_id'},{'id': '376', 'type': 'block', 'children': ['377']},{'id': '377', 'type': 'return_statement', 'children': []},{'id': '378', 'type': 'expression_statement', 'children': ['379']},{'id': '379', 'type': 'assignment', 'children': ['380', '381']},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'affected_event'},{'id': '381', 'type': 'call', 'children': ['382', '387']},{'id': '382', 'type': 'attribute', 'children': ['383', '386']},{'id': '383', 'type': 'attribute', 'children': ['384', '385']},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '385', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '387', 'type': 'argument_list', 'children': ['388']},{'id': '388', 'type': 'binary_operator', 'children': ['389', '390'], 'value': '%'},{'id': '389', 'type': 'string', 'children': [], 'value': '"EVENT/[@id=\'%s\']"'},{'id': '390', 'type': 'identifier', 'children': [], 'value': 'affected_id'},{'id': '391', 'type': 'if_statement', 'children': ['392', '395']},{'id': '392', 'type': 'comparison_operator', 'children': ['393', '394'], 'value': 'is'},{'id': '393', 'type': 'identifier', 'children': [], 'value': 'affected_event'},{'id': '394', 'type': 'None', 'children': []},{'id': '395', 'type': 'block', 'children': ['396']},{'id': '396', 'type': 'return_statement', 'children': []},{'id': '397', 'type': 'for_statement', 'children': ['398', '399', '404']},{'id': '398', 'type': 'identifier', 'children': [], 'value': 'enz_t'},{'id': '399', 'type': 'call', 'children': ['400', '401']},{'id': '400', 'type': 'identifier', 'children': [], 'value': '_agent_list_product'},{'id': '401', 'type': 'argument_list', 'children': ['402']},{'id': '402', 'type': 'tuple', 'children': ['403']},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'enzyme_agent'},{'id': '404', 'type': 'block', 'children': ['405', '411', '420', '424', '451']},{'id': '405', 'type': 'expression_statement', 'children': ['406']},{'id': '406', 'type': 'assignment', 'children': ['407', '408']},{'id': '407', 'type': 'identifier', 'children': [], 'value': 'enz'},{'id': '408', 'type': 'subscript', 'children': ['409', '410']},{'id': '409', 'type': 'identifier', 'children': [], 'value': 'enz_t'},{'id': '410', 'type': 'integer', 'children': [], 'value': '0'},{'id': '411', 'type': 'expression_statement', 'children': ['412']},{'id': '412', 'type': 'assignment', 'children': ['413', '414']},{'id': '413', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '414', 'type': 'call', 'children': ['415', '418']},{'id': '415', 'type': 'attribute', 'children': ['416', '417']},{'id': '416', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '417', 'type': 'identifier', 'children': [], 'value': '_get_modification_event'},{'id': '418', 'type': 'argument_list', 'children': ['419']},{'id': '419', 'type': 'identifier', 'children': [], 'value': 'affected_event'},{'id': '420', 'type': 'expression_statement', 'children': ['421']},{'id': '421', 'type': 'assignment', 'children': ['422', '423']},{'id': '422', 'type': 'identifier', 'children': [], 'value': 'stmts_to_make'},{'id': '423', 'type': 'list', 'children': [], 'value': '[]'},{'id': '424', 'type': 'if_statement', 'children': ['425', '426']},{'id': '425', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '426', 'type': 'block', 'children': ['427']},{'id': '427', 'type': 'for_statement', 'children': ['428', '429', '430']},{'id': '428', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '429', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '430', 'type': 'block', 'children': ['431']},{'id': '431', 'type': 'if_statement', 'children': ['432', '443']},{'id': '432', 'type': 'boolean_operator', 'children': ['433', '438'], 'value': 'and'},{'id': '433', 'type': 'comparison_operator', 'children': ['434', '437'], 'value': 'is'},{'id': '434', 'type': 'attribute', 'children': ['435', '436']},{'id': '435', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '436', 'type': 'identifier', 'children': [], 'value': 'enz'},{'id': '437', 'type': 'None', 'children': []},{'id': '438', 'type': 'comparison_operator', 'children': ['439', '442'], 'value': 'is'},{'id': '439', 'type': 'attribute', 'children': ['440', '441']},{'id': '440', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '441', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '442', 'type': 'None', 'children': []},{'id': '443', 'type': 'block', 'children': ['444']},{'id': '444', 'type': 'expression_statement', 'children': ['445']},{'id': '445', 'type': 'call', 'children': ['446', '449']},{'id': '446', 'type': 'attribute', 'children': ['447', '448']},{'id': '447', 'type': 'identifier', 'children': [], 'value': 'stmts_to_make'},{'id': '448', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '449', 'type': 'argument_list', 'children': ['450']},{'id': '450', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '451', 'type': 'for_statement', 'children': ['452', '453', '454']},{'id': '452', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '453', 'type': 'identifier', 'children': [], 'value': 'stmts_to_make'},{'id': '454', 'type': 'block', 'children': ['455', '461', '475']},{'id': '455', 'type': 'expression_statement', 'children': ['456']},{'id': '456', 'type': 'assignment', 'children': ['457', '460']},{'id': '457', 'type': 'attribute', 'children': ['458', '459']},{'id': '458', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '459', 'type': 'identifier', 'children': [], 'value': 'enz'},{'id': '460', 'type': 'identifier', 'children': [], 'value': 'enz'},{'id': '461', 'type': 'for_statement', 'children': ['462', '463', '466']},{'id': '462', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '463', 'type': 'attribute', 'children': ['464', '465']},{'id': '464', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '465', 'type': 'identifier', 'children': [], 'value': 'evidence'},{'id': '466', 'type': 'block', 'children': ['467']},{'id': '467', 'type': 'expression_statement', 'children': ['468']},{'id': '468', 'type': 'assignment', 'children': ['469', '474']},{'id': '469', 'type': 'subscript', 'children': ['470', '473']},{'id': '470', 'type': 'attribute', 'children': ['471', '472']},{'id': '471', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '472', 'type': 'identifier', 'children': [], 'value': 'epistemics'},{'id': '473', 'type': 'string', 'children': [], 'value': "'direct'"},{'id': '474', 'type': 'False', 'children': []},{'id': '475', 'type': 'expression_statement', 'children': ['476']},{'id': '476', 'type': 'call', 'children': ['477', '482']},{'id': '477', 'type': 'attribute', 'children': ['478', '481']},{'id': '478', 'type': 'attribute', 'children': ['479', '480']},{'id': '479', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '480', 'type': 'identifier', 'children': [], 'value': 'statements'},{'id': '481', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '482', 'type': 'argument_list', 'children': ['483']},{'id': '483', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '484', 'type': 'expression_statement', 'children': ['485']},{'id': '485', 'type': 'call', 'children': ['486', '489']},{'id': '486', 'type': 'attribute', 'children': ['487', '488']},{'id': '487', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '488', 'type': 'identifier', 'children': [], 'value': '_add_extracted'},{'id': '489', 'type': 'argument_list', 'children': ['490', '491']},{'id': '490', 'type': 'identifier', 'children': [], 'value': 'event_type'},{'id': '491', 'type': 'subscript', 'children': ['492', '495']},{'id': '492', 'type': 'attribute', 'children': ['493', '494']},{'id': '493', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '494', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '495', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '496', 'type': 'expression_statement', 'children': ['497']},{'id': '497', 'type': 'call', 'children': ['498', '501']},{'id': '498', 'type': 'attribute', 'children': ['499', '500']},{'id': '499', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '500', 'type': 'identifier', 'children': [], 'value': '_add_extracted'},{'id': '501', 'type': 'argument_list', 'children': ['502', '510']},{'id': '502', 'type': 'attribute', 'children': ['503', '509']},{'id': '503', 'type': 'call', 'children': ['504', '507']},{'id': '504', 'type': 'attribute', 'children': ['505', '506']},{'id': '505', 'type': 'identifier', 'children': [], 'value': 'affected_event'},{'id': '506', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '507', 'type': 'argument_list', 'children': ['508']},{'id': '508', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '509', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '510', 'type': 'identifier', 'children': [], 'value': 'affected_id'} | def get_modifications_indirect(self):
mod_event_types = list(ont_to_mod_type.keys())
mod_event_types += ['ONT::PTM']
def get_increase_events(mod_event_types):
mod_events = []
events = self.tree.findall("EVENT/[type='ONT::INCREASE']")
for event in events:
affected = event.find(".//*[@role=':AFFECTED']")
if affected is None:
continue
affected_id = affected.attrib.get('id')
if not affected_id:
continue
pattern = "EVENT/[@id='%s']" % affected_id
affected_event = self.tree.find(pattern)
if affected_event is not None:
affected_type = affected_event.find('type')
if affected_type is not None and \
affected_type.text in mod_event_types:
mod_events.append(event)
return mod_events
def get_cause_events(mod_event_types):
mod_events = []
ccs = self.tree.findall("CC/[type='ONT::CAUSE']")
for cc in ccs:
outcome = cc.find(".//*[@role=':OUTCOME']")
if outcome is None:
continue
outcome_id = outcome.attrib.get('id')
if not outcome_id:
continue
pattern = "EVENT/[@id='%s']" % outcome_id
outcome_event = self.tree.find(pattern)
if outcome_event is not None:
outcome_type = outcome_event.find('type')
if outcome_type is not None and \
outcome_type.text in mod_event_types:
mod_events.append(cc)
return mod_events
mod_events = get_increase_events(mod_event_types)
mod_events += get_cause_events(mod_event_types)
for event in mod_events:
event_id = event.attrib['id']
if event_id in self._static_events:
continue
event_type = _get_type(event)
enzyme = event.find(".//*[@role=':AGENT']")
if enzyme is None:
enzyme = event.find(".//*[@role=':FACTOR']")
if enzyme is None:
return
enzyme_id = enzyme.attrib.get('id')
if enzyme_id is None:
continue
enzyme_agent = self._get_agent_by_id(enzyme_id, event_id)
affected_event_tag = event.find(".//*[@role=':AFFECTED']")
if affected_event_tag is None:
affected_event_tag = event.find(".//*[@role=':OUTCOME']")
if affected_event_tag is None:
return
affected_id = affected_event_tag.attrib.get('id')
if not affected_id:
return
affected_event = self.tree.find("EVENT/[@id='%s']" % affected_id)
if affected_event is None:
return
for enz_t in _agent_list_product((enzyme_agent, )):
enz = enz_t[0]
stmts = self._get_modification_event(affected_event)
stmts_to_make = []
if stmts:
for stmt in stmts:
if stmt.enz is None and stmt.sub is not None:
stmts_to_make.append(stmt)
for stmt in stmts_to_make:
stmt.enz = enz
for ev in stmt.evidence:
ev.epistemics['direct'] = False
self.statements.append(stmt)
self._add_extracted(event_type, event.attrib['id'])
self._add_extracted(affected_event.find('type').text, affected_id) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'replace_activities'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '13', '17', '47', '53', '272']},{'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': 'logger'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'string', 'children': [], 'value': "'Running PySB Preassembler replace activities'"},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'new_stmts'},{'id': '16', 'type': 'list', 'children': [], 'value': '[]'},{'id': '17', 'type': 'function_definition', 'children': ['18', '19', '21']},{'id': '18', 'type': 'function_name', 'children': [], 'value': 'has_agent_activity'},{'id': '19', 'type': 'parameters', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '21', 'type': 'block', 'children': ['22', '45']},{'id': '22', 'type': 'for_statement', 'children': ['23', '24', '29']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'agent_list'},{'id': '28', 'type': 'argument_list', 'children': []},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'if_statement', 'children': ['31', '42']},{'id': '31', 'type': 'boolean_operator', 'children': ['32', '37'], 'value': 'and'},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '34', 'type': 'argument_list', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'Agent'},{'id': '37', 'type': 'comparison_operator', 'children': ['38', '41'], 'value': 'is'},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'activity'},{'id': '41', 'type': 'None', 'children': []},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'return_statement', 'children': ['44']},{'id': '44', 'type': 'True', 'children': []},{'id': '45', 'type': 'return_statement', 'children': ['46']},{'id': '46', 'type': 'False', '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': 'self'},{'id': '51', 'type': 'identifier', 'children': [], 'value': '_gather_active_forms'},{'id': '52', 'type': 'argument_list', 'children': []},{'id': '53', 'type': 'for_statement', 'children': ['54', '57', '63']},{'id': '54', 'type': 'pattern_list', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'statements'},{'id': '63', 'type': 'block', 'children': ['64', '83', '98', '106', '113', '121', '237', '247']},{'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': 'logger'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'binary_operator', 'children': ['71', '72'], 'value': '%'},{'id': '71', 'type': 'string', 'children': [], 'value': "'%d/%d %s'"},{'id': '72', 'type': 'tuple', 'children': ['73', '76', '82']},{'id': '73', 'type': 'binary_operator', 'children': ['74', '75'], 'value': '+'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '75', 'type': 'integer', 'children': [], 'value': '1'},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'statements'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '83', 'type': 'if_statement', 'children': ['84', '89']},{'id': '84', 'type': 'not_operator', 'children': ['85']},{'id': '85', 'type': 'call', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'has_agent_activity'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '89', 'type': 'block', 'children': ['90', '97']},{'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': 'new_stmts'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '97', 'type': 'continue_statement', 'children': []},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'stmt_agents'},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'agent_list'},{'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': 'num_agents'},{'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': 'stmt_agents'},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'agent_forms'},{'id': '116', 'type': 'list_comprehension', 'children': ['117', '118']},{'id': '117', 'type': 'list', 'children': [], 'value': '[]'},{'id': '118', 'type': 'for_in_clause', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'stmt_agents'},{'id': '121', 'type': 'for_statement', 'children': ['122', '125', '129']},{'id': '122', 'type': 'pattern_list', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '125', 'type': 'call', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'stmt_agents'},{'id': '129', 'type': 'block', 'children': ['130']},{'id': '130', 'type': 'if_statement', 'children': ['131', '147', '226']},{'id': '131', 'type': 'boolean_operator', 'children': ['132', '141', '142'], 'value': 'and'},{'id': '132', 'type': 'boolean_operator', 'children': ['133', '136'], 'value': 'and'},{'id': '133', 'type': 'comparison_operator', 'children': ['134', '135'], 'value': 'is'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '135', 'type': 'None', 'children': []},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '138', 'type': 'argument_list', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'Agent'},{'id': '141', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '142', 'type': 'comparison_operator', 'children': ['143', '146'], 'value': 'is'},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'activity'},{'id': '146', 'type': 'None', 'children': []},{'id': '147', 'type': 'block', 'children': ['148', '159', '198']},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'base_agent'},{'id': '151', 'type': 'call', 'children': ['152', '157']},{'id': '152', 'type': 'attribute', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'agent_set'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'get_create_base_agent'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '159', 'type': 'if_statement', 'children': ['160', '165', '181']},{'id': '160', 'type': 'attribute', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'activity'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'is_active'},{'id': '165', 'type': 'block', 'children': ['166', '172']},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'active_forms'},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'base_agent'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'active_forms'},{'id': '172', 'type': 'if_statement', 'children': ['173', '175']},{'id': '173', 'type': 'not_operator', 'children': ['174']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'active_forms'},{'id': '175', 'type': 'block', 'children': ['176']},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'assignment', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'active_forms'},{'id': '179', 'type': 'list', 'children': ['180'], 'value': '[agent]'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '181', 'type': 'else_clause', 'children': ['182']},{'id': '182', 'type': 'block', 'children': ['183', '189']},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'assignment', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'active_forms'},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'base_agent'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'inactive_forms'},{'id': '189', 'type': 'if_statement', 'children': ['190', '192']},{'id': '190', 'type': 'not_operator', 'children': ['191']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'active_forms'},{'id': '192', 'type': 'block', 'children': ['193']},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'assignment', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'active_forms'},{'id': '196', 'type': 'list', 'children': ['197'], 'value': '[agent]'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '198', 'type': 'for_statement', 'children': ['199', '200', '201']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'af'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'active_forms'},{'id': '201', 'type': 'block', 'children': ['202', '209', '217']},{'id': '202', 'type': 'expression_statement', 'children': ['203']},{'id': '203', 'type': 'assignment', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'new_agent'},{'id': '205', 'type': 'call', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'fast_deepcopy'},{'id': '207', 'type': 'argument_list', 'children': ['208']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'call', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '213', 'type': 'identifier', 'children': [], 'value': '_set_agent_context'},{'id': '214', 'type': 'argument_list', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'af'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'new_agent'},{'id': '217', 'type': 'expression_statement', 'children': ['218']},{'id': '218', 'type': 'call', 'children': ['219', '224']},{'id': '219', 'type': 'attribute', 'children': ['220', '223']},{'id': '220', 'type': 'subscript', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'agent_forms'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '224', 'type': 'argument_list', 'children': ['225']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'new_agent'},{'id': '226', 'type': 'else_clause', 'children': ['227']},{'id': '227', 'type': 'block', 'children': ['228']},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'call', 'children': ['230', '235']},{'id': '230', 'type': 'attribute', 'children': ['231', '234']},{'id': '231', 'type': 'subscript', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'agent_forms'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '235', 'type': 'argument_list', 'children': ['236']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '237', 'type': 'expression_statement', 'children': ['238']},{'id': '238', 'type': 'assignment', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'agent_combs'},{'id': '240', 'type': 'call', 'children': ['241', '244']},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'itertools'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'product'},{'id': '244', 'type': 'argument_list', 'children': ['245']},{'id': '245', 'type': 'list_splat', 'children': ['246']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'agent_forms'},{'id': '247', 'type': 'for_statement', 'children': ['248', '249', '250']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'agent_comb'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'agent_combs'},{'id': '250', 'type': 'block', 'children': ['251', '258', '265']},{'id': '251', 'type': 'expression_statement', 'children': ['252']},{'id': '252', 'type': 'assignment', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'new_stmt'},{'id': '254', 'type': 'call', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'fast_deepcopy'},{'id': '256', 'type': 'argument_list', 'children': ['257']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'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': 'new_stmt'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'set_agent_list'},{'id': '263', 'type': 'argument_list', 'children': ['264']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'agent_comb'},{'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': 'new_stmts'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '270', 'type': 'argument_list', 'children': ['271']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'new_stmt'},{'id': '272', 'type': 'expression_statement', 'children': ['273']},{'id': '273', 'type': 'assignment', 'children': ['274', '277']},{'id': '274', 'type': 'attribute', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'statements'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'new_stmts'} | def replace_activities(self):
logger.debug('Running PySB Preassembler replace activities')
new_stmts = []
def has_agent_activity(stmt):
for agent in stmt.agent_list():
if isinstance(agent, Agent) and agent.activity is not None:
return True
return False
self._gather_active_forms()
for j, stmt in enumerate(self.statements):
logger.debug('%d/%d %s' % (j + 1, len(self.statements), stmt))
if not has_agent_activity(stmt):
new_stmts.append(stmt)
continue
stmt_agents = stmt.agent_list()
num_agents = len(stmt_agents)
agent_forms = [[] for a in stmt_agents]
for i, agent in enumerate(stmt_agents):
if agent is not None and isinstance(agent, Agent) and \
agent.activity is not None:
base_agent = self.agent_set.get_create_base_agent(agent)
if agent.activity.is_active:
active_forms = base_agent.active_forms
if not active_forms:
active_forms = [agent]
else:
active_forms = base_agent.inactive_forms
if not active_forms:
active_forms = [agent]
for af in active_forms:
new_agent = fast_deepcopy(agent)
self._set_agent_context(af, new_agent)
agent_forms[i].append(new_agent)
else:
agent_forms[i].append(agent)
agent_combs = itertools.product(*agent_forms)
for agent_comb in agent_combs:
new_stmt = fast_deepcopy(stmt)
new_stmt.set_agent_list(agent_comb)
new_stmts.append(new_stmt)
self.statements = new_stmts |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_reverse_effects'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '10', '14', '18', '22', '208', '212', '276', '303']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'pos_mod_sites'},{'id': '9', 'type': 'dictionary', 'children': []},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'neg_mod_sites'},{'id': '13', 'type': 'dictionary', 'children': []},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'syntheses'},{'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': 'degradations'},{'id': '21', 'type': 'list', 'children': [], 'value': '[]'},{'id': '22', 'type': 'for_statement', 'children': ['23', '24', '27']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'statements'},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'if_statement', 'children': ['29', '34', '76', '124', '172', '190']},{'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': 'stmt'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'Phosphorylation'},{'id': '34', 'type': 'block', 'children': ['35', '43']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '38', 'type': 'attribute', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '43', 'type': 'try_statement', 'children': ['44', '60']},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '52']},{'id': '47', 'type': 'attribute', 'children': ['48', '51']},{'id': '48', 'type': 'subscript', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'pos_mod_sites'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'tuple', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'residue'},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '60', 'type': 'except_clause', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '68']},{'id': '65', 'type': 'subscript', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'pos_mod_sites'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '68', 'type': 'list', 'children': ['69'], 'value': '[(stmt.residue, stmt.position)]'},{'id': '69', 'type': 'tuple', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'residue'},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '76', 'type': 'elif_clause', 'children': ['77', '82']},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '79', 'type': 'argument_list', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'Dephosphorylation'},{'id': '82', 'type': 'block', 'children': ['83', '91']},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '86', 'type': 'attribute', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '91', 'type': 'try_statement', 'children': ['92', '108']},{'id': '92', 'type': 'block', 'children': ['93']},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'call', 'children': ['95', '100']},{'id': '95', 'type': 'attribute', 'children': ['96', '99']},{'id': '96', 'type': 'subscript', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'neg_mod_sites'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'tuple', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'residue'},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '108', 'type': 'except_clause', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '110', 'type': 'block', 'children': ['111']},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '116']},{'id': '113', 'type': 'subscript', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'neg_mod_sites'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '116', 'type': 'list', 'children': ['117'], 'value': '[(stmt.residue, stmt.position)]'},{'id': '117', 'type': 'tuple', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'residue'},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '124', 'type': 'elif_clause', 'children': ['125', '130']},{'id': '125', 'type': 'call', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '127', 'type': 'argument_list', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'Influence'},{'id': '130', 'type': 'block', 'children': ['131']},{'id': '131', 'type': 'if_statement', 'children': ['132', '139', '151']},{'id': '132', 'type': 'comparison_operator', 'children': ['133', '138'], 'value': '=='},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'overall_polarity'},{'id': '137', 'type': 'argument_list', 'children': []},{'id': '138', 'type': 'integer', 'children': [], 'value': '1'},{'id': '139', 'type': 'block', 'children': ['140']},{'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': 'syntheses'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '145', 'type': 'argument_list', 'children': ['146']},{'id': '146', 'type': 'attribute', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '151', 'type': 'elif_clause', 'children': ['152', '160']},{'id': '152', 'type': 'comparison_operator', 'children': ['153', '158'], 'value': '=='},{'id': '153', 'type': 'call', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'overall_polarity'},{'id': '157', 'type': 'argument_list', 'children': []},{'id': '158', 'type': 'unary_operator', 'children': ['159'], 'value': '-'},{'id': '159', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'degradations'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'attribute', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '172', 'type': 'elif_clause', 'children': ['173', '178']},{'id': '173', 'type': 'call', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '175', 'type': 'argument_list', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'IncreaseAmount'},{'id': '178', 'type': 'block', 'children': ['179']},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'call', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'syntheses'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'attribute', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '190', 'type': 'elif_clause', 'children': ['191', '196']},{'id': '191', 'type': 'call', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '193', 'type': 'argument_list', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'DecreaseAmount'},{'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': 'degradations'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '202', 'type': 'argument_list', 'children': ['203']},{'id': '203', 'type': 'attribute', 'children': ['204', '207']},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '208', 'type': 'expression_statement', 'children': ['209']},{'id': '209', 'type': 'assignment', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'new_stmts'},{'id': '211', 'type': 'list', 'children': [], 'value': '[]'},{'id': '212', 'type': 'for_statement', 'children': ['213', '216', '221']},{'id': '213', 'type': 'pattern_list', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'agent_name'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'pos_sites'},{'id': '216', 'type': 'call', 'children': ['217', '220']},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'pos_mod_sites'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '220', 'type': 'argument_list', 'children': []},{'id': '221', 'type': 'block', 'children': ['222', '232', '247']},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'assignment', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'neg_sites'},{'id': '225', 'type': 'call', 'children': ['226', '229']},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'neg_mod_sites'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '229', 'type': 'argument_list', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'agent_name'},{'id': '231', 'type': 'list', 'children': [], 'value': '[]'},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'assignment', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'no_neg_site'},{'id': '235', 'type': 'call', 'children': ['236', '242']},{'id': '236', 'type': 'attribute', 'children': ['237', '241']},{'id': '237', 'type': 'call', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '239', 'type': 'argument_list', 'children': ['240']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'pos_sites'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'difference'},{'id': '242', 'type': 'argument_list', 'children': ['243']},{'id': '243', 'type': 'call', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '245', 'type': 'argument_list', 'children': ['246']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'neg_sites'},{'id': '247', 'type': 'for_statement', 'children': ['248', '251', '252']},{'id': '248', 'type': 'pattern_list', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'residue'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'no_neg_site'},{'id': '252', 'type': 'block', 'children': ['253', '269']},{'id': '253', 'type': 'expression_statement', 'children': ['254']},{'id': '254', 'type': 'assignment', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '256', 'type': 'call', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'Dephosphorylation'},{'id': '258', 'type': 'argument_list', 'children': ['259', '263', '267', '268']},{'id': '259', 'type': 'call', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'Agent'},{'id': '261', 'type': 'argument_list', 'children': ['262']},{'id': '262', 'type': 'string', 'children': [], 'value': "'phosphatase'"},{'id': '263', 'type': 'call', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'Agent'},{'id': '265', 'type': 'argument_list', 'children': ['266']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'agent_name'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'residue'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '269', 'type': 'expression_statement', 'children': ['270']},{'id': '270', 'type': 'call', 'children': ['271', '274']},{'id': '271', 'type': 'attribute', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'new_stmts'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '274', 'type': 'argument_list', 'children': ['275']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '276', 'type': 'for_statement', 'children': ['277', '278', '279']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'agent_name'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'syntheses'},{'id': '279', 'type': 'block', 'children': ['280']},{'id': '280', 'type': 'if_statement', 'children': ['281', '284']},{'id': '281', 'type': 'comparison_operator', 'children': ['282', '283'], 'value': 'not'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'agent_name'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'degradations'},{'id': '284', 'type': 'block', 'children': ['285', '296']},{'id': '285', 'type': 'expression_statement', 'children': ['286']},{'id': '286', 'type': 'assignment', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '288', 'type': 'call', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'DecreaseAmount'},{'id': '290', 'type': 'argument_list', 'children': ['291', '292']},{'id': '291', 'type': 'None', 'children': []},{'id': '292', 'type': 'call', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'Agent'},{'id': '294', 'type': 'argument_list', 'children': ['295']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'agent_name'},{'id': '296', 'type': 'expression_statement', 'children': ['297']},{'id': '297', 'type': 'call', 'children': ['298', '301']},{'id': '298', 'type': 'attribute', 'children': ['299', '300']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'new_stmts'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '301', 'type': 'argument_list', 'children': ['302']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '303', 'type': 'expression_statement', 'children': ['304']},{'id': '304', 'type': 'augmented_assignment', 'children': ['305', '308'], 'value': '+='},{'id': '305', 'type': 'attribute', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'statements'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'new_stmts'} | def add_reverse_effects(self):
pos_mod_sites = {}
neg_mod_sites = {}
syntheses = []
degradations = []
for stmt in self.statements:
if isinstance(stmt, Phosphorylation):
agent = stmt.sub.name
try:
pos_mod_sites[agent].append((stmt.residue, stmt.position))
except KeyError:
pos_mod_sites[agent] = [(stmt.residue, stmt.position)]
elif isinstance(stmt, Dephosphorylation):
agent = stmt.sub.name
try:
neg_mod_sites[agent].append((stmt.residue, stmt.position))
except KeyError:
neg_mod_sites[agent] = [(stmt.residue, stmt.position)]
elif isinstance(stmt, Influence):
if stmt.overall_polarity() == 1:
syntheses.append(stmt.obj.name)
elif stmt.overall_polarity() == -1:
degradations.append(stmt.obj.name)
elif isinstance(stmt, IncreaseAmount):
syntheses.append(stmt.obj.name)
elif isinstance(stmt, DecreaseAmount):
degradations.append(stmt.obj.name)
new_stmts = []
for agent_name, pos_sites in pos_mod_sites.items():
neg_sites = neg_mod_sites.get(agent_name, [])
no_neg_site = set(pos_sites).difference(set(neg_sites))
for residue, position in no_neg_site:
st = Dephosphorylation(Agent('phosphatase'),
Agent(agent_name),
residue, position)
new_stmts.append(st)
for agent_name in syntheses:
if agent_name not in degradations:
st = DecreaseAmount(None, Agent(agent_name))
new_stmts.append(st)
self.statements += new_stmts |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'map_sites'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '6', 'type': 'block', 'children': ['7', '11', '15', '49']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'valid_statements'},{'id': '10', 'type': 'list', 'children': [], 'value': '[]'},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'mapped_statements'},{'id': '14', 'type': 'list', 'children': [], 'value': '[]'},{'id': '15', 'type': 'for_statement', 'children': ['16', '17', '18']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '18', 'type': 'block', 'children': ['19', '28']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'mapped_stmt'},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'map_stmt_sites'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '28', 'type': 'if_statement', 'children': ['29', '32', '40']},{'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': 'is'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'mapped_stmt'},{'id': '31', 'type': 'None', 'children': []},{'id': '32', 'type': 'block', 'children': ['33']},{'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': 'mapped_statements'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'mapped_stmt'},{'id': '40', 'type': 'else_clause', 'children': ['41']},{'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': 'valid_statements'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '49', 'type': 'return_statement', 'children': ['50']},{'id': '50', 'type': 'expression_list', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'valid_statements'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'mapped_statements'} | def map_sites(self, stmts):
valid_statements = []
mapped_statements = []
for stmt in stmts:
mapped_stmt = self.map_stmt_sites(stmt)
if mapped_stmt is not None:
mapped_statements.append(mapped_stmt)
else:
valid_statements.append(stmt)
return valid_statements, mapped_statements |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_map_agent_sites'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '6', 'type': 'block', 'children': ['7', '21', '28', '32', '105']},{'id': '7', 'type': 'if_statement', 'children': ['8', '16']},{'id': '8', 'type': 'boolean_operator', 'children': ['9', '12'], 'value': 'or'},{'id': '9', 'type': 'comparison_operator', 'children': ['10', '11'], 'value': 'is'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'not_operator', 'children': ['13']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'mods'},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'return_statement', 'children': ['18']},{'id': '18', 'type': 'expression_list', 'children': ['19', '20']},{'id': '19', 'type': 'list', 'children': [], 'value': '[]'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'new_agent'},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'deepcopy'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'mapped_sites'},{'id': '31', 'type': 'list', 'children': [], 'value': '[]'},{'id': '32', 'type': 'for_statement', 'children': ['33', '36', '42']},{'id': '33', 'type': 'pattern_list', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'mod_condition'},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'mods'},{'id': '42', 'type': 'block', 'children': ['43', '54', '65', '98']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46', '47']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'mapped_site'},{'id': '46', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'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': '_map_agent_mod'},{'id': '51', 'type': 'argument_list', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'mod_condition'},{'id': '54', 'type': 'if_statement', 'children': ['55', '63']},{'id': '55', 'type': 'boolean_operator', 'children': ['56', '58'], 'value': 'or'},{'id': '56', 'type': 'not_operator', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'mapped_site'},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'mapped_site'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'not_invalid'},{'id': '62', 'type': 'argument_list', 'children': []},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'continue_statement', 'children': []},{'id': '65', 'type': 'if_statement', 'children': ['66', '71']},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'mapped_site'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'has_mapping'},{'id': '70', 'type': 'argument_list', 'children': []},{'id': '71', 'type': 'block', 'children': ['72', '90']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'mc'},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'ModCondition'},{'id': '77', 'type': 'argument_list', 'children': ['78', '81', '84', '87']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'mod_condition'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'mod_type'},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'mapped_site'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'mapped_res'},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'mapped_site'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'mapped_pos'},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'mod_condition'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'is_modified'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '97']},{'id': '92', 'type': 'subscript', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'new_agent'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'mods'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'mc'},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'call', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'mapped_sites'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'mapped_site'},{'id': '105', 'type': 'return_statement', 'children': ['106']},{'id': '106', 'type': 'expression_list', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'mapped_sites'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'new_agent'} | def _map_agent_sites(self, agent):
if agent is None or not agent.mods:
return [], agent
new_agent = deepcopy(agent)
mapped_sites = []
for idx, mod_condition in enumerate(agent.mods):
mapped_site = \
self._map_agent_mod(agent, mod_condition)
if not mapped_site or mapped_site.not_invalid():
continue
if mapped_site.has_mapping():
mc = ModCondition(mod_condition.mod_type,
mapped_site.mapped_res,
mapped_site.mapped_pos,
mod_condition.is_modified)
new_agent.mods[idx] = mc
mapped_sites.append(mapped_site)
return mapped_sites, new_agent |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_map_agent_mod'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'mod_condition'},{'id': '7', 'type': 'block', 'children': ['8', '15', '32', '47', '79']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'up_id'},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': '_get_uniprot_id'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '15', 'type': 'if_statement', 'children': ['16', '18']},{'id': '16', 'type': 'not_operator', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'up_id'},{'id': '18', 'type': 'block', 'children': ['19', '30']},{'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': 'logger'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'binary_operator', 'children': ['26', '27'], 'value': '%'},{'id': '26', 'type': 'string', 'children': [], 'value': '"No uniprot ID for %s"'},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '30', 'type': 'return_statement', 'children': ['31']},{'id': '31', 'type': 'None', 'children': []},{'id': '32', 'type': 'if_statement', 'children': ['33', '44']},{'id': '33', 'type': 'boolean_operator', 'children': ['34', '39'], 'value': 'or'},{'id': '34', 'type': 'comparison_operator', 'children': ['35', '38'], 'value': 'is'},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'mod_condition'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '38', 'type': 'None', 'children': []},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '43'], 'value': 'is'},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'mod_condition'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'residue'},{'id': '43', 'type': 'None', 'children': []},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'return_statement', 'children': ['46']},{'id': '46', 'type': 'None', 'children': []},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50', '51']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'mapped_site'},{'id': '50', 'type': 'line_continuation', 'children': [], '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': 'map_to_human_ref'},{'id': '55', 'type': 'argument_list', 'children': ['56', '57', '58', '61', '64', '69', '74']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'up_id'},{'id': '57', 'type': 'string', 'children': [], 'value': "'uniprot'"},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'mod_condition'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'residue'},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'mod_condition'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '64', 'type': 'keyword_argument', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'do_methionine_offset'},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'do_methionine_offset'},{'id': '69', 'type': 'keyword_argument', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'do_orthology_mapping'},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'do_orthology_mapping'},{'id': '74', 'type': 'keyword_argument', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'do_isoform_mapping'},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'do_isoform_mapping'},{'id': '79', 'type': 'return_statement', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'mapped_site'} | def _map_agent_mod(self, agent, mod_condition):
up_id = _get_uniprot_id(agent)
if not up_id:
logger.debug("No uniprot ID for %s" % agent.name)
return None
if mod_condition.position is None or mod_condition.residue is None:
return None
mapped_site = \
self.map_to_human_ref(up_id, 'uniprot',
mod_condition.residue,
mod_condition.position,
do_methionine_offset=self.do_methionine_offset,
do_orthology_mapping=self.do_orthology_mapping,
do_isoform_mapping=self.do_isoform_mapping)
return mapped_site |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_graph_reductions'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '5', 'type': 'block', 'children': ['6', '60', '64', '80', '92', '131']},{'id': '6', 'type': 'function_definition', 'children': ['7', '8', '11']},{'id': '7', 'type': 'function_name', 'children': [], 'value': 'frontier'},{'id': '8', 'type': 'parameters', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'nd'},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'if_statement', 'children': ['13', '21', '28']},{'id': '13', 'type': 'comparison_operator', 'children': ['14', '20'], 'value': '=='},{'id': '14', 'type': 'call', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'out_degree'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'nd'},{'id': '20', 'type': 'integer', 'children': [], 'value': '0'},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'return_statement', 'children': ['23']},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'list', 'children': ['27'], 'value': '[nd]'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'nd'},{'id': '28', 'type': 'else_clause', 'children': ['29']},{'id': '29', 'type': 'block', 'children': ['30', '36', '58']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'frontiers'},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '35', 'type': 'argument_list', 'children': []},{'id': '36', 'type': 'for_statement', 'children': ['37', '38', '44']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'successors'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'nd'},{'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': 'frontiers'},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'frontiers'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'union'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'frontier'},{'id': '55', 'type': 'argument_list', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '58', 'type': 'return_statement', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'frontiers'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'reductions'},{'id': '63', 'type': 'dictionary', 'children': []},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'nodes_sort'},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '78']},{'id': '71', 'type': 'attribute', 'children': ['72', '77']},{'id': '72', 'type': 'attribute', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'networkx'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'algorithms'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'dag'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'topological_sort'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'frontiers'},{'id': '83', 'type': 'list_comprehension', 'children': ['84', '89']},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'frontier'},{'id': '86', 'type': 'argument_list', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '89', 'type': 'for_in_clause', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'nodes_sort'},{'id': '92', 'type': 'for_statement', 'children': ['93', '96', '100']},{'id': '93', 'type': 'pattern_list', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'n1'},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'nodes_sort'},{'id': '100', 'type': 'block', 'children': ['101']},{'id': '101', 'type': 'for_statement', 'children': ['102', '105', '109']},{'id': '102', 'type': 'pattern_list', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'n2'},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'nodes_sort'},{'id': '109', 'type': 'block', 'children': ['110', '116']},{'id': '110', 'type': 'if_statement', 'children': ['111', '114']},{'id': '111', 'type': 'comparison_operator', 'children': ['112', '113'], 'value': '>'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '114', 'type': 'block', 'children': ['115']},{'id': '115', 'type': 'continue_statement', 'children': []},{'id': '116', 'type': 'if_statement', 'children': ['117', '124']},{'id': '117', 'type': 'comparison_operator', 'children': ['118', '121'], 'value': '=='},{'id': '118', 'type': 'subscript', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'frontiers'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '121', 'type': 'subscript', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'frontiers'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '124', 'type': 'block', 'children': ['125']},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '130']},{'id': '127', 'type': 'subscript', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'reductions'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'n1'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'n2'},{'id': '131', 'type': 'return_statement', 'children': ['132']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'reductions'} | def _get_graph_reductions(graph):
def frontier(g, nd):
if g.out_degree(nd) == 0:
return set([nd])
else:
frontiers = set()
for n in g.successors(nd):
frontiers = frontiers.union(frontier(graph, n))
return frontiers
reductions = {}
nodes_sort = list(networkx.algorithms.dag.topological_sort(graph))
frontiers = [frontier(graph, n) for n in nodes_sort]
for i, n1 in enumerate(nodes_sort):
for j, n2 in enumerate(nodes_sort):
if i > j:
continue
if frontiers[i] == frontiers[j]:
reductions[n1] = n2
return reductions |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'gather_implicit_activities'},{'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': 'stmt'},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'statements'},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'if_statement', 'children': ['13', '32', '70', '114', '158', '202', '271', '340']},{'id': '13', 'type': 'boolean_operator', 'children': ['14', '26', '27'], 'value': 'or'},{'id': '14', 'type': 'boolean_operator', 'children': ['15', '20', '21'], 'value': 'or'},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '17', 'type': 'argument_list', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'Phosphorylation'},{'id': '20', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '23', 'type': 'argument_list', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'Transphosphorylation'},{'id': '26', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'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': 'stmt'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'Autophosphorylation'},{'id': '32', 'type': 'block', 'children': ['33']},{'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': 'stmt'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'enz'},{'id': '38', 'type': 'None', 'children': []},{'id': '39', 'type': 'block', 'children': ['40', '51', '58']},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'enz_base'},{'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_base'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'enz'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'enz_base'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'add_activity'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'string', 'children': [], 'value': "'kinase'"},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'enz_base'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'add_active_state'},{'id': '63', 'type': 'argument_list', 'children': ['64', '65']},{'id': '64', 'type': 'string', 'children': [], 'value': "'kinase'"},{'id': '65', 'type': 'attribute', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'enz'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'mods'},{'id': '70', 'type': 'elif_clause', 'children': ['71', '76']},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '73', 'type': 'argument_list', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'Dephosphorylation'},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'if_statement', 'children': ['78', '83']},{'id': '78', 'type': 'comparison_operator', 'children': ['79', '82'], 'value': 'is'},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'enz'},{'id': '82', 'type': 'None', 'children': []},{'id': '83', 'type': 'block', 'children': ['84', '95', '102']},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'enz_base'},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '90', 'type': 'identifier', 'children': [], 'value': '_get_base'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'enz'},{'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': 'enz_base'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'add_activity'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'string', 'children': [], 'value': "'phosphatase'"},{'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': 'enz_base'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'add_active_state'},{'id': '107', 'type': 'argument_list', 'children': ['108', '109']},{'id': '108', 'type': 'string', 'children': [], 'value': "'phosphatase'"},{'id': '109', 'type': 'attribute', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'enz'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'mods'},{'id': '114', 'type': 'elif_clause', 'children': ['115', '120']},{'id': '115', 'type': 'call', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '117', 'type': 'argument_list', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'Modification'},{'id': '120', 'type': 'block', 'children': ['121']},{'id': '121', 'type': 'if_statement', 'children': ['122', '127']},{'id': '122', 'type': 'comparison_operator', 'children': ['123', '126'], 'value': 'is'},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'enz'},{'id': '126', 'type': 'None', 'children': []},{'id': '127', 'type': 'block', 'children': ['128', '139', '146']},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'assignment', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'enz_base'},{'id': '131', 'type': 'call', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '134', 'type': 'identifier', 'children': [], 'value': '_get_base'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'enz'},{'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': 'enz_base'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'add_activity'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'string', 'children': [], 'value': "'catalytic'"},{'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': 'enz_base'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'add_active_state'},{'id': '151', 'type': 'argument_list', 'children': ['152', '153']},{'id': '152', 'type': 'string', 'children': [], 'value': "'catalytic'"},{'id': '153', 'type': 'attribute', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'enz'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'mods'},{'id': '158', 'type': 'elif_clause', 'children': ['159', '164']},{'id': '159', 'type': 'call', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '161', 'type': 'argument_list', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'SelfModification'},{'id': '164', 'type': 'block', 'children': ['165']},{'id': '165', 'type': 'if_statement', 'children': ['166', '171']},{'id': '166', 'type': 'comparison_operator', 'children': ['167', '170'], 'value': 'is'},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'enz'},{'id': '170', 'type': 'None', 'children': []},{'id': '171', 'type': 'block', 'children': ['172', '183', '190']},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'assignment', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'enz_base'},{'id': '175', 'type': 'call', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '178', 'type': 'identifier', 'children': [], 'value': '_get_base'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'enz'},{'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': 'enz_base'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'add_activity'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'string', 'children': [], 'value': "'catalytic'"},{'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': 'enz_base'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'add_active_state'},{'id': '195', 'type': 'argument_list', 'children': ['196', '197']},{'id': '196', 'type': 'string', 'children': [], 'value': "'catalytic'"},{'id': '197', 'type': 'attribute', 'children': ['198', '201']},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'enz'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'mods'},{'id': '202', 'type': 'elif_clause', 'children': ['203', '208']},{'id': '203', 'type': 'call', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '205', 'type': 'argument_list', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'Gef'},{'id': '208', 'type': 'block', 'children': ['209']},{'id': '209', 'type': 'if_statement', 'children': ['210', '215']},{'id': '210', 'type': 'comparison_operator', 'children': ['211', '214'], 'value': 'is'},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'gef'},{'id': '214', 'type': 'None', 'children': []},{'id': '215', 'type': 'block', 'children': ['216', '227', '234', '259']},{'id': '216', 'type': 'expression_statement', 'children': ['217']},{'id': '217', 'type': 'assignment', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'gef_base'},{'id': '219', 'type': 'call', 'children': ['220', '223']},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '222', 'type': 'identifier', 'children': [], 'value': '_get_base'},{'id': '223', 'type': 'argument_list', 'children': ['224']},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'gef'},{'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': 'gef_base'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'add_activity'},{'id': '232', 'type': 'argument_list', 'children': ['233']},{'id': '233', 'type': 'string', 'children': [], 'value': "'gef'"},{'id': '234', 'type': 'if_statement', 'children': ['235', '242', '253']},{'id': '235', 'type': 'comparison_operator', 'children': ['236', '241'], 'value': 'is'},{'id': '236', 'type': 'attribute', 'children': ['237', '240']},{'id': '237', 'type': 'attribute', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'gef'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'activity'},{'id': '241', 'type': 'None', 'children': []},{'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': 'act'},{'id': '246', 'type': 'attribute', 'children': ['247', '252']},{'id': '247', 'type': 'attribute', 'children': ['248', '251']},{'id': '248', 'type': 'attribute', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'gef'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'activity'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'activity_type'},{'id': '253', 'type': 'else_clause', 'children': ['254']},{'id': '254', 'type': 'block', 'children': ['255']},{'id': '255', 'type': 'expression_statement', 'children': ['256']},{'id': '256', 'type': 'assignment', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'act'},{'id': '258', 'type': 'string', 'children': [], 'value': "'activity'"},{'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': 'gef_base'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'add_active_state'},{'id': '264', 'type': 'argument_list', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'act'},{'id': '266', 'type': 'attribute', 'children': ['267', '270']},{'id': '267', 'type': 'attribute', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'gef'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'mods'},{'id': '271', 'type': 'elif_clause', 'children': ['272', '277']},{'id': '272', 'type': 'call', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '274', 'type': 'argument_list', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'Gap'},{'id': '277', 'type': 'block', 'children': ['278']},{'id': '278', 'type': 'if_statement', 'children': ['279', '284']},{'id': '279', 'type': 'comparison_operator', 'children': ['280', '283'], 'value': 'is'},{'id': '280', 'type': 'attribute', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'gap'},{'id': '283', 'type': 'None', 'children': []},{'id': '284', 'type': 'block', 'children': ['285', '296', '303', '328']},{'id': '285', 'type': 'expression_statement', 'children': ['286']},{'id': '286', 'type': 'assignment', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'gap_base'},{'id': '288', 'type': 'call', 'children': ['289', '292']},{'id': '289', 'type': 'attribute', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '291', 'type': 'identifier', 'children': [], 'value': '_get_base'},{'id': '292', 'type': 'argument_list', 'children': ['293']},{'id': '293', 'type': 'attribute', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'gap'},{'id': '296', 'type': 'expression_statement', 'children': ['297']},{'id': '297', 'type': 'call', 'children': ['298', '301']},{'id': '298', 'type': 'attribute', 'children': ['299', '300']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'gap_base'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'add_activity'},{'id': '301', 'type': 'argument_list', 'children': ['302']},{'id': '302', 'type': 'string', 'children': [], 'value': "'gap'"},{'id': '303', 'type': 'if_statement', 'children': ['304', '311', '322']},{'id': '304', 'type': 'comparison_operator', 'children': ['305', '310'], 'value': 'is'},{'id': '305', 'type': 'attribute', 'children': ['306', '309']},{'id': '306', 'type': 'attribute', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'gap'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'activity'},{'id': '310', 'type': 'None', 'children': []},{'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': 'act'},{'id': '315', 'type': 'attribute', 'children': ['316', '321']},{'id': '316', 'type': 'attribute', 'children': ['317', '320']},{'id': '317', 'type': 'attribute', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'gap'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'activity'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'activity_type'},{'id': '322', 'type': 'else_clause', 'children': ['323']},{'id': '323', 'type': 'block', 'children': ['324']},{'id': '324', 'type': 'expression_statement', 'children': ['325']},{'id': '325', 'type': 'assignment', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'act'},{'id': '327', 'type': 'string', 'children': [], 'value': "'activity'"},{'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': 'gap_base'},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'add_active_state'},{'id': '333', 'type': 'argument_list', 'children': ['334', '335']},{'id': '334', 'type': 'string', 'children': [], 'value': "'act'"},{'id': '335', 'type': 'attribute', 'children': ['336', '339']},{'id': '336', 'type': 'attribute', 'children': ['337', '338']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'gap'},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'mods'},{'id': '340', 'type': 'elif_clause', 'children': ['341', '346']},{'id': '341', 'type': 'call', 'children': ['342', '343']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '343', 'type': 'argument_list', 'children': ['344', '345']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'RegulateActivity'},{'id': '346', 'type': 'block', 'children': ['347']},{'id': '347', 'type': 'if_statement', 'children': ['348', '353']},{'id': '348', 'type': 'comparison_operator', 'children': ['349', '352'], 'value': 'is'},{'id': '349', 'type': 'attribute', 'children': ['350', '351']},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'subj'},{'id': '352', 'type': 'None', 'children': []},{'id': '353', 'type': 'block', 'children': ['354', '365']},{'id': '354', 'type': 'expression_statement', 'children': ['355']},{'id': '355', 'type': 'assignment', 'children': ['356', '357']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'subj_base'},{'id': '357', 'type': 'call', 'children': ['358', '361']},{'id': '358', 'type': 'attribute', 'children': ['359', '360']},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '360', 'type': 'identifier', 'children': [], 'value': '_get_base'},{'id': '361', 'type': 'argument_list', 'children': ['362']},{'id': '362', 'type': 'attribute', 'children': ['363', '364']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'subj'},{'id': '365', 'type': 'expression_statement', 'children': ['366']},{'id': '366', 'type': 'call', 'children': ['367', '370']},{'id': '367', 'type': 'attribute', 'children': ['368', '369']},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'subj_base'},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'add_activity'},{'id': '370', 'type': 'argument_list', 'children': ['371']},{'id': '371', 'type': 'attribute', 'children': ['372', '373']},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'j'} | def gather_implicit_activities(self):
for stmt in self.statements:
if isinstance(stmt, Phosphorylation) or \
isinstance(stmt, Transphosphorylation) or \
isinstance(stmt, Autophosphorylation):
if stmt.enz is not None:
enz_base = self._get_base(stmt.enz)
enz_base.add_activity('kinase')
enz_base.add_active_state('kinase', stmt.enz.mods)
elif isinstance(stmt, Dephosphorylation):
if stmt.enz is not None:
enz_base = self._get_base(stmt.enz)
enz_base.add_activity('phosphatase')
enz_base.add_active_state('phosphatase', stmt.enz.mods)
elif isinstance(stmt, Modification):
if stmt.enz is not None:
enz_base = self._get_base(stmt.enz)
enz_base.add_activity('catalytic')
enz_base.add_active_state('catalytic', stmt.enz.mods)
elif isinstance(stmt, SelfModification):
if stmt.enz is not None:
enz_base = self._get_base(stmt.enz)
enz_base.add_activity('catalytic')
enz_base.add_active_state('catalytic', stmt.enz.mods)
elif isinstance(stmt, Gef):
if stmt.gef is not None:
gef_base = self._get_base(stmt.gef)
gef_base.add_activity('gef')
if stmt.gef.activity is not None:
act = stmt.gef.activity.activity_type
else:
act = 'activity'
gef_base.add_active_state(act, stmt.gef.mods)
elif isinstance(stmt, Gap):
if stmt.gap is not None:
gap_base = self._get_base(stmt.gap)
gap_base.add_activity('gap')
if stmt.gap.activity is not None:
act = stmt.gap.activity.activity_type
else:
act = 'activity'
gap_base.add_active_state('act', stmt.gap.mods)
elif isinstance(stmt, RegulateActivity):
if stmt.subj is not None:
subj_base = self._get_base(stmt.subj)
subj_base.add_activity(stmt.j) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'reduce_activities'},{'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': 'stmt'},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'statements'},{'id': '11', 'type': 'block', 'children': ['12', '20', '70']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'agents'},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'agent_list'},{'id': '19', 'type': 'argument_list', 'children': []},{'id': '20', 'type': 'for_statement', 'children': ['21', '22', '23']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'agents'},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'if_statement', 'children': ['25', '34']},{'id': '25', 'type': 'boolean_operator', 'children': ['26', '29'], 'value': 'and'},{'id': '26', 'type': 'comparison_operator', 'children': ['27', '28'], 'value': 'is'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '28', 'type': 'None', 'children': []},{'id': '29', 'type': 'comparison_operator', 'children': ['30', '33'], 'value': 'is'},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'activity'},{'id': '33', 'type': 'None', 'children': []},{'id': '34', 'type': 'block', 'children': ['35', '44', '57']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'agent_base'},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '41', 'type': 'identifier', 'children': [], 'value': '_get_base'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'act_red'},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'agent_base'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'get_activity_reduction'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'attribute', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'activity'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'activity_type'},{'id': '57', 'type': 'if_statement', 'children': ['58', '61']},{'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': 'is'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'act_red'},{'id': '60', 'type': 'None', 'children': []},{'id': '61', 'type': 'block', 'children': ['62']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '69']},{'id': '64', 'type': 'attribute', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'activity'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'activity_type'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'act_red'},{'id': '70', 'type': 'if_statement', 'children': ['71', '76', '118']},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '73', 'type': 'argument_list', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'RegulateActivity'},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'if_statement', 'children': ['78', '83']},{'id': '78', 'type': 'comparison_operator', 'children': ['79', '82'], 'value': 'is'},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '82', 'type': 'None', 'children': []},{'id': '83', 'type': 'block', 'children': ['84', '95', '107']},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'obj_base'},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '90', 'type': 'identifier', 'children': [], 'value': '_get_base'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'assignment', 'children': ['97', '98', '99']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'act_red'},{'id': '98', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '99', 'type': 'call', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'obj_base'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'get_activity_reduction'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'obj_activity'},{'id': '107', 'type': 'if_statement', 'children': ['108', '111']},{'id': '108', 'type': 'comparison_operator', 'children': ['109', '110'], 'value': 'is'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'act_red'},{'id': '110', 'type': 'None', 'children': []},{'id': '111', 'type': 'block', 'children': ['112']},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'obj_activity'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'act_red'},{'id': '118', 'type': 'elif_clause', 'children': ['119', '124']},{'id': '119', 'type': 'call', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '121', 'type': 'argument_list', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'ActiveForm'},{'id': '124', 'type': 'block', 'children': ['125', '136', '147']},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'agent_base'},{'id': '128', 'type': 'call', 'children': ['129', '132']},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '131', 'type': 'identifier', 'children': [], 'value': '_get_base'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'act_red'},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'agent_base'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'get_activity_reduction'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'activity'},{'id': '147', 'type': 'if_statement', 'children': ['148', '151']},{'id': '148', 'type': 'comparison_operator', 'children': ['149', '150'], 'value': 'is'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'act_red'},{'id': '150', 'type': 'None', 'children': []},{'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': 'stmt'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'activity'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'act_red'} | def reduce_activities(self):
for stmt in self.statements:
agents = stmt.agent_list()
for agent in agents:
if agent is not None and agent.activity is not None:
agent_base = self._get_base(agent)
act_red = agent_base.get_activity_reduction(
agent.activity.activity_type)
if act_red is not None:
agent.activity.activity_type = act_red
if isinstance(stmt, RegulateActivity):
if stmt.obj is not None:
obj_base = self._get_base(stmt.obj)
act_red = \
obj_base.get_activity_reduction(stmt.obj_activity)
if act_red is not None:
stmt.obj_activity = act_red
elif isinstance(stmt, ActiveForm):
agent_base = self._get_base(stmt.agent)
act_red = agent_base.get_activity_reduction(stmt.activity)
if act_red is not None:
stmt.activity = act_red |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'infer_activations'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '5', 'type': 'block', 'children': ['6', '10', '18', '26', '183']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'linked_stmts'},{'id': '9', 'type': 'list', 'children': [], 'value': '[]'},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'af_stmts'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': '_get_statements_by_type'},{'id': '15', 'type': 'argument_list', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'ActiveForm'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'mod_stmts'},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': '_get_statements_by_type'},{'id': '23', 'type': 'argument_list', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'Modification'},{'id': '26', 'type': 'for_statement', 'children': ['27', '30', '39']},{'id': '27', 'type': 'pattern_list', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'af_stmt'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'mod_stmt'},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'itertools'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'product'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'list_splat', 'children': ['36']},{'id': '36', 'type': 'tuple', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'af_stmts'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'mod_stmts'},{'id': '39', 'type': 'block', 'children': ['40', '62', '71', '75', '116', '121', '127', '170']},{'id': '40', 'type': 'if_statement', 'children': ['41', '60']},{'id': '41', 'type': 'boolean_operator', 'children': ['42', '47', '48'], 'value': 'or'},{'id': '42', 'type': 'comparison_operator', 'children': ['43', '46'], 'value': 'is'},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'mod_stmt'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'enz'},{'id': '46', 'type': 'None', 'children': []},{'id': '47', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '48', 'type': '()', 'children': ['49']},{'id': '49', 'type': 'not_operator', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '56']},{'id': '51', 'type': 'attribute', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'af_stmt'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'entity_matches'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'mod_stmt'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'continue_statement', 'children': []},{'id': '62', 'type': 'if_statement', 'children': ['63', '69']},{'id': '63', 'type': 'not_operator', 'children': ['64']},{'id': '64', 'type': 'attribute', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'af_stmt'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'mods'},{'id': '69', 'type': 'block', 'children': ['70']},{'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': 'found'},{'id': '74', 'type': 'False', 'children': []},{'id': '75', 'type': 'for_statement', 'children': ['76', '77', '82']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'mc'},{'id': '77', 'type': 'attribute', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'af_stmt'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'mods'},{'id': '82', 'type': 'block', 'children': ['83']},{'id': '83', 'type': 'if_statement', 'children': ['84', '111']},{'id': '84', 'type': 'boolean_operator', 'children': ['85', '103', '104'], 'value': 'and'},{'id': '85', 'type': 'boolean_operator', 'children': ['86', '95', '96'], 'value': 'and'},{'id': '86', 'type': 'comparison_operator', 'children': ['87', '90'], 'value': '=='},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'mc'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'mod_type'},{'id': '90', 'type': 'subscript', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'modclass_to_modtype'},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'mod_stmt'},{'id': '94', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '95', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '96', 'type': 'comparison_operator', 'children': ['97', '100'], 'value': '=='},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'mc'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'residue'},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'mod_stmt'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'residue'},{'id': '103', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '104', 'type': 'comparison_operator', 'children': ['105', '108'], 'value': '=='},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'mc'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'mod_stmt'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'position'},{'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': 'found'},{'id': '115', 'type': 'True', 'children': []},{'id': '116', 'type': 'if_statement', 'children': ['117', '119']},{'id': '117', 'type': 'not_operator', 'children': ['118']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'found'},{'id': '119', 'type': 'block', 'children': ['120']},{'id': '120', 'type': 'continue_statement', 'children': []},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'mod_stmt'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'evidence'},{'id': '127', 'type': 'if_statement', 'children': ['128', '131', '150']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'af_stmt'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'is_active'},{'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': 'st'},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'Activation'},{'id': '137', 'type': 'argument_list', 'children': ['138', '141', '144', '147']},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'mod_stmt'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'enz'},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'mod_stmt'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'af_stmt'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'activity'},{'id': '147', 'type': 'keyword_argument', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'evidence'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'ev'},{'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': 'st'},{'id': '155', 'type': 'call', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'Inhibition'},{'id': '157', 'type': 'argument_list', 'children': ['158', '161', '164', '167']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'mod_stmt'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'enz'},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'mod_stmt'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'af_stmt'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'activity'},{'id': '167', 'type': 'keyword_argument', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'evidence'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'ev'},{'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': 'linked_stmts'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'call', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'LinkedStatement'},{'id': '178', 'type': 'argument_list', 'children': ['179', '182']},{'id': '179', 'type': 'list', 'children': ['180', '181'], 'value': '[af_stmt, mod_stmt]'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'af_stmt'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'mod_stmt'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '183', 'type': 'return_statement', 'children': ['184']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'linked_stmts'} | def infer_activations(stmts):
linked_stmts = []
af_stmts = _get_statements_by_type(stmts, ActiveForm)
mod_stmts = _get_statements_by_type(stmts, Modification)
for af_stmt, mod_stmt in itertools.product(*(af_stmts, mod_stmts)):
if mod_stmt.enz is None or \
(not af_stmt.agent.entity_matches(mod_stmt.sub)):
continue
if not af_stmt.agent.mods:
continue
found = False
for mc in af_stmt.agent.mods:
if mc.mod_type == modclass_to_modtype[mod_stmt.__class__] and \
mc.residue == mod_stmt.residue and \
mc.position == mod_stmt.position:
found = True
if not found:
continue
ev = mod_stmt.evidence
if af_stmt.is_active:
st = Activation(mod_stmt.enz, mod_stmt.sub, af_stmt.activity,
evidence=ev)
else:
st = Inhibition(mod_stmt.enz, mod_stmt.sub, af_stmt.activity,
evidence=ev)
linked_stmts.append(LinkedStatement([af_stmt, mod_stmt], st))
return linked_stmts |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'infer_active_forms'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '5', 'type': 'block', 'children': ['6', '10', '248']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'linked_stmts'},{'id': '9', 'type': 'list', 'children': [], 'value': '[]'},{'id': '10', 'type': 'for_statement', 'children': ['11', '12', '17']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'act_stmt'},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': '_get_statements_by_type'},{'id': '14', 'type': 'argument_list', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'RegulateActivity'},{'id': '17', 'type': 'block', 'children': ['18', '48', '52', '58', '113', '118', '122', '184', '195', '228', '239']},{'id': '18', 'type': 'if_statement', 'children': ['19', '46']},{'id': '19', 'type': 'not_operator', 'children': ['20']},{'id': '20', 'type': '()', 'children': ['21']},{'id': '21', 'type': 'boolean_operator', 'children': ['22', '39'], 'value': 'and'},{'id': '22', 'type': 'boolean_operator', 'children': ['23', '30'], 'value': 'and'},{'id': '23', 'type': 'comparison_operator', 'children': ['24', '29'], 'value': 'is'},{'id': '24', 'type': 'attribute', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'act_stmt'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'subj'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'activity'},{'id': '29', 'type': 'None', 'children': []},{'id': '30', 'type': 'comparison_operator', 'children': ['31', '38'], 'value': '=='},{'id': '31', 'type': 'attribute', 'children': ['32', '37']},{'id': '32', 'type': 'attribute', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'act_stmt'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'subj'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'activity'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'activity_type'},{'id': '38', 'type': 'string', 'children': [], 'value': "'kinase'"},{'id': '39', 'type': 'attribute', 'children': ['40', '45']},{'id': '40', 'type': 'attribute', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'act_stmt'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'subj'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'activity'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'is_active'},{'id': '46', 'type': 'block', 'children': ['47']},{'id': '47', 'type': 'continue_statement', 'children': []},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'matching'},{'id': '51', 'type': 'list', 'children': [], 'value': '[]'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'act_stmt'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'evidence'},{'id': '58', 'type': 'for_statement', 'children': ['59', '60', '65']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'mod_stmt'},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': '_get_statements_by_type'},{'id': '62', 'type': 'argument_list', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'Modification'},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'if_statement', 'children': ['67', '72']},{'id': '67', 'type': 'comparison_operator', 'children': ['68', '71'], 'value': 'is'},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'mod_stmt'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'enz'},{'id': '71', 'type': 'None', 'children': []},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'if_statement', 'children': ['74', '96']},{'id': '74', 'type': 'boolean_operator', 'children': ['75', '85', '86'], 'value': 'and'},{'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': 'mod_stmt'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'enz'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'entity_matches'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'act_stmt'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'subj'},{'id': '85', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'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': 'mod_stmt'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'entity_matches'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'act_stmt'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '96', 'type': 'block', 'children': ['97', '104']},{'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': 'matching'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'mod_stmt'},{'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': 'ev'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'mod_stmt'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'evidence'},{'id': '113', 'type': 'if_statement', 'children': ['114', '116']},{'id': '114', 'type': 'not_operator', 'children': ['115']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'matching'},{'id': '116', 'type': 'block', 'children': ['117']},{'id': '117', 'type': 'continue_statement', 'children': []},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'mods'},{'id': '121', 'type': 'list', 'children': [], 'value': '[]'},{'id': '122', 'type': 'for_statement', 'children': ['123', '124', '125']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'mod_stmt'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'matching'},{'id': '125', 'type': 'block', 'children': ['126', '138', '163', '177']},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'mod_type_name'},{'id': '129', 'type': 'call', 'children': ['130', '137']},{'id': '130', 'type': 'attribute', 'children': ['131', '136']},{'id': '131', 'type': 'attribute', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'mod_stmt'},{'id': '134', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '135', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '137', 'type': 'argument_list', 'children': []},{'id': '138', 'type': 'if_statement', 'children': ['139', '144', '149']},{'id': '139', 'type': 'call', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '141', 'type': 'argument_list', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'mod_stmt'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'AddModification'},{'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': 'is_modified'},{'id': '148', 'type': 'True', 'children': []},{'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': 'is_modified'},{'id': '154', 'type': 'False', 'children': []},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'mod_type_name'},{'id': '158', 'type': 'subscript', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'mod_type_name'},{'id': '160', 'type': 'slice', 'children': ['161', '162']},{'id': '161', 'type': 'integer', 'children': [], 'value': '2'},{'id': '162', 'type': 'colon', 'children': []},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'mc'},{'id': '166', 'type': 'call', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'ModCondition'},{'id': '168', 'type': 'argument_list', 'children': ['169', '170', '173', '176']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'mod_type_name'},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'mod_stmt'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'residue'},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'mod_stmt'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'is_modified'},{'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': 'mods'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '182', 'type': 'argument_list', 'children': ['183']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'mc'},{'id': '184', 'type': 'expression_statement', 'children': ['185']},{'id': '185', 'type': 'assignment', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'source_stmts'},{'id': '187', 'type': 'binary_operator', 'children': ['188', '190'], 'value': '+'},{'id': '188', 'type': 'list', 'children': ['189'], 'value': '[act_stmt]'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'act_stmt'},{'id': '190', 'type': 'list_comprehension', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '192', 'type': 'for_in_clause', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'matching'},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'assignment', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '198', 'type': 'call', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'ActiveForm'},{'id': '200', 'type': 'argument_list', 'children': ['201', '219', '222', '225']},{'id': '201', 'type': 'call', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'Agent'},{'id': '203', 'type': 'argument_list', 'children': ['204', '209', '212']},{'id': '204', 'type': 'attribute', 'children': ['205', '208']},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'act_stmt'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '209', 'type': 'keyword_argument', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'mods'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'mods'},{'id': '212', 'type': 'keyword_argument', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'db_refs'},{'id': '214', 'type': 'attribute', 'children': ['215', '218']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'act_stmt'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'db_refs'},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'act_stmt'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'obj_activity'},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'act_stmt'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'is_activation'},{'id': '225', 'type': 'keyword_argument', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'evidence'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'call', 'children': ['230', '233']},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'linked_stmts'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '233', 'type': 'argument_list', 'children': ['234']},{'id': '234', 'type': 'call', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'LinkedStatement'},{'id': '236', 'type': 'argument_list', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'source_stmts'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'st'},{'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': 'logger'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '244', 'type': 'argument_list', 'children': ['245']},{'id': '245', 'type': 'binary_operator', 'children': ['246', '247'], 'value': '%'},{'id': '246', 'type': 'string', 'children': [], 'value': "'inferred: %s'"},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '248', 'type': 'return_statement', 'children': ['249']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'linked_stmts'} | def infer_active_forms(stmts):
linked_stmts = []
for act_stmt in _get_statements_by_type(stmts, RegulateActivity):
if not (act_stmt.subj.activity is not None and
act_stmt.subj.activity.activity_type == 'kinase' and
act_stmt.subj.activity.is_active):
continue
matching = []
ev = act_stmt.evidence
for mod_stmt in _get_statements_by_type(stmts, Modification):
if mod_stmt.enz is not None:
if mod_stmt.enz.entity_matches(act_stmt.subj) and \
mod_stmt.sub.entity_matches(act_stmt.obj):
matching.append(mod_stmt)
ev.extend(mod_stmt.evidence)
if not matching:
continue
mods = []
for mod_stmt in matching:
mod_type_name = mod_stmt.__class__.__name__.lower()
if isinstance(mod_stmt, AddModification):
is_modified = True
else:
is_modified = False
mod_type_name = mod_type_name[2:]
mc = ModCondition(mod_type_name, mod_stmt.residue,
mod_stmt.position, is_modified)
mods.append(mc)
source_stmts = [act_stmt] + [m for m in matching]
st = ActiveForm(Agent(act_stmt.obj.name, mods=mods,
db_refs=act_stmt.obj.db_refs),
act_stmt.obj_activity, act_stmt.is_activation,
evidence=ev)
linked_stmts.append(LinkedStatement(source_stmts, st))
logger.info('inferred: %s' % st)
return linked_stmts |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'infer_modifications'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '5', 'type': 'block', 'children': ['6', '10', '188']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'linked_stmts'},{'id': '9', 'type': 'list', 'children': [], 'value': '[]'},{'id': '10', 'type': 'for_statement', 'children': ['11', '12', '17']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'act_stmt'},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': '_get_statements_by_type'},{'id': '14', 'type': 'argument_list', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'RegulateActivity'},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'for_statement', 'children': ['19', '20', '25']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'af_stmt'},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': '_get_statements_by_type'},{'id': '22', 'type': 'argument_list', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'ActiveForm'},{'id': '25', 'type': 'block', 'children': ['26', '40', '48', '70', '79']},{'id': '26', 'type': 'if_statement', 'children': ['27', '38']},{'id': '27', 'type': 'not_operator', 'children': ['28']},{'id': '28', 'type': 'call', 'children': ['29', '34']},{'id': '29', 'type': 'attribute', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'af_stmt'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'entity_matches'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'act_stmt'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'continue_statement', 'children': []},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'mods'},{'id': '43', 'type': 'attribute', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'af_stmt'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'mods'},{'id': '48', 'type': 'if_statement', 'children': ['49', '68']},{'id': '49', 'type': 'boolean_operator', 'children': ['50', '62', '63'], 'value': 'or'},{'id': '50', 'type': 'boolean_operator', 'children': ['51', '56', '57'], 'value': 'or'},{'id': '51', 'type': 'attribute', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'af_stmt'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'mutations'},{'id': '56', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '57', 'type': 'attribute', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'af_stmt'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'bound_conditions'},{'id': '62', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '63', 'type': 'attribute', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'af_stmt'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '68', 'type': 'block', 'children': ['69']},{'id': '69', 'type': 'continue_statement', 'children': []},{'id': '70', 'type': 'if_statement', 'children': ['71', '77']},{'id': '71', 'type': 'not_operator', 'children': ['72']},{'id': '72', 'type': 'attribute', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'af_stmt'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'mods'},{'id': '77', 'type': 'block', 'children': ['78']},{'id': '78', 'type': 'continue_statement', 'children': []},{'id': '79', 'type': 'for_statement', 'children': ['80', '81', '86']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '81', 'type': 'attribute', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'af_stmt'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'mods'},{'id': '86', 'type': 'block', 'children': ['87', '97', '109', '130', '136', '141', '162', '172', '179']},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'evs'},{'id': '90', 'type': 'binary_operator', 'children': ['91', '94'], 'value': '+'},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'act_stmt'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'evidence'},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'af_stmt'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'evidence'},{'id': '97', 'type': 'for_statement', 'children': ['98', '99', '100']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'evs'},{'id': '100', 'type': 'block', 'children': ['101']},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '108']},{'id': '103', 'type': 'subscript', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'epistemics'},{'id': '107', 'type': 'string', 'children': [], 'value': "'direct'"},{'id': '108', 'type': 'False', 'children': []},{'id': '109', 'type': 'if_statement', 'children': ['110', '113', '120']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'is_modified'},{'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': 'mod_type_name'},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'mod_type'},{'id': '120', 'type': 'else_clause', 'children': ['121']},{'id': '121', 'type': 'block', 'children': ['122']},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'mod_type_name'},{'id': '125', 'type': 'subscript', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'modtype_to_inverse'},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'mod_type'},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'mod_class'},{'id': '133', 'type': 'subscript', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'modtype_to_modclass'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'mod_type_name'},{'id': '136', 'type': 'if_statement', 'children': ['137', '139']},{'id': '137', 'type': 'not_operator', 'children': ['138']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'mod_class'},{'id': '139', 'type': 'block', 'children': ['140']},{'id': '140', 'type': 'continue_statement', 'children': []},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '144', 'type': 'call', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'mod_class'},{'id': '146', 'type': 'argument_list', 'children': ['147', '150', '153', '156', '159']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'act_stmt'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'subj'},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'act_stmt'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'residue'},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '159', 'type': 'keyword_argument', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'evidence'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'evs'},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'assignment', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'ls'},{'id': '165', 'type': 'call', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'LinkedStatement'},{'id': '167', 'type': 'argument_list', 'children': ['168', '171']},{'id': '168', 'type': 'list', 'children': ['169', '170'], 'value': '[act_stmt, af_stmt]'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'act_stmt'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'af_stmt'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'st'},{'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': 'linked_stmts'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '177', 'type': 'argument_list', 'children': ['178']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'ls'},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'call', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'binary_operator', 'children': ['186', '187'], 'value': '%'},{'id': '186', 'type': 'string', 'children': [], 'value': "'inferred: %s'"},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '188', 'type': 'return_statement', 'children': ['189']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'linked_stmts'} | def infer_modifications(stmts):
linked_stmts = []
for act_stmt in _get_statements_by_type(stmts, RegulateActivity):
for af_stmt in _get_statements_by_type(stmts, ActiveForm):
if not af_stmt.agent.entity_matches(act_stmt.obj):
continue
mods = af_stmt.agent.mods
if af_stmt.agent.mutations or \
af_stmt.agent.bound_conditions or \
af_stmt.agent.location:
continue
if not af_stmt.agent.mods:
continue
for mod in af_stmt.agent.mods:
evs = act_stmt.evidence + af_stmt.evidence
for ev in evs:
ev.epistemics['direct'] = False
if mod.is_modified:
mod_type_name = mod.mod_type
else:
mod_type_name = modtype_to_inverse[mod.mod_type]
mod_class = modtype_to_modclass[mod_type_name]
if not mod_class:
continue
st = mod_class(act_stmt.subj,
act_stmt.obj,
mod.residue, mod.position,
evidence=evs)
ls = LinkedStatement([act_stmt, af_stmt], st)
linked_stmts.append(ls)
logger.info('inferred: %s' % st)
return linked_stmts |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'score_evidence_list'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'evidences'},{'id': '6', 'type': 'block', 'children': ['7', '121', '139', '156', '163', '170', '179']},{'id': '7', 'type': 'function_definition', 'children': ['8', '9', '11']},{'id': '8', 'type': 'function_name', 'children': [], 'value': '_score'},{'id': '9', 'type': 'parameters', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'evidences'},{'id': '11', 'type': 'block', 'children': ['12', '18', '28', '37', '53', '63', '89', '93', '113', '119']},{'id': '12', 'type': 'if_statement', 'children': ['13', '15']},{'id': '13', 'type': 'not_operator', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'evidences'},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'return_statement', 'children': ['17']},{'id': '17', 'type': 'integer', 'children': [], 'value': '0'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'sources'},{'id': '21', 'type': 'list_comprehension', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'source_api'},{'id': '25', 'type': 'for_in_clause', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'evidences'},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'uniq_sources'},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'unique'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'sources'},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'syst_factors'},{'id': '40', 'type': 'dictionary_comprehension', 'children': ['41', '50']},{'id': '41', 'type': 'pair', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '43', 'type': 'subscript', 'children': ['44', '49']},{'id': '44', 'type': 'subscript', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'prior_probs'},{'id': '48', 'type': 'string', 'children': [], 'value': "'syst'"},{'id': '49', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '50', 'type': 'for_in_clause', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'uniq_sources'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'rand_factors'},{'id': '56', 'type': 'dictionary_comprehension', 'children': ['57', '60']},{'id': '57', 'type': 'pair', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '59', 'type': 'list', 'children': [], 'value': '[]'},{'id': '60', 'type': 'for_in_clause', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'uniq_sources'},{'id': '63', 'type': 'for_statement', 'children': ['64', '65', '66']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'evidences'},{'id': '66', 'type': 'block', 'children': ['67']},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'call', 'children': ['69', '76']},{'id': '69', 'type': 'attribute', 'children': ['70', '75']},{'id': '70', 'type': 'subscript', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'rand_factors'},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'source_api'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'evidence_random_noise_prior'},{'id': '79', 'type': 'argument_list', 'children': ['80', '81', '86']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'ev'},{'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': 'prior_probs'},{'id': '85', 'type': 'string', 'children': [], 'value': "'rand'"},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'subtype_probs'},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'neg_prob_prior'},{'id': '92', 'type': 'integer', 'children': [], 'value': '1'},{'id': '93', 'type': 'for_statement', 'children': ['94', '95', '96']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'uniq_sources'},{'id': '96', 'type': 'block', 'children': ['97']},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'augmented_assignment', 'children': ['99', '100'], 'value': '*='},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'neg_prob_prior'},{'id': '100', 'type': '()', 'children': ['101']},{'id': '101', 'type': 'binary_operator', 'children': ['102', '105'], 'value': '+'},{'id': '102', 'type': 'subscript', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'syst_factors'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'prod'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'rand_factors'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'prob_prior'},{'id': '116', 'type': 'binary_operator', 'children': ['117', '118'], 'value': '-'},{'id': '117', 'type': 'integer', 'children': [], 'value': '1'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'neg_prob_prior'},{'id': '119', 'type': 'return_statement', 'children': ['120']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'prob_prior'},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'pos_evidence'},{'id': '124', 'type': 'list_comprehension', 'children': ['125', '126', '129']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '126', 'type': 'for_in_clause', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'evidences'},{'id': '129', 'type': 'if_clause', 'children': ['130']},{'id': '130', 'type': 'not_operator', 'children': ['131']},{'id': '131', 'type': 'call', 'children': ['132', '137']},{'id': '132', 'type': 'attribute', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'epistemics'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'string', 'children': [], 'value': "'negated'"},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'assignment', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'neg_evidence'},{'id': '142', 'type': 'list_comprehension', 'children': ['143', '144', '147']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '144', 'type': 'for_in_clause', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'evidences'},{'id': '147', 'type': 'if_clause', 'children': ['148']},{'id': '148', 'type': 'call', 'children': ['149', '154']},{'id': '149', 'type': 'attribute', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'epistemics'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'string', 'children': [], 'value': "'negated'"},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'assignment', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'pp'},{'id': '159', 'type': 'call', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': '_score'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'pos_evidence'},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '166', 'type': 'call', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': '_score'},{'id': '168', 'type': 'argument_list', 'children': ['169']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'neg_evidence'},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'assignment', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '173', 'type': 'binary_operator', 'children': ['174', '175'], 'value': '*'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'pp'},{'id': '175', 'type': '()', 'children': ['176']},{'id': '176', 'type': 'binary_operator', 'children': ['177', '178'], 'value': '-'},{'id': '177', 'type': 'integer', 'children': [], 'value': '1'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '179', 'type': 'return_statement', 'children': ['180']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'score'} | def score_evidence_list(self, evidences):
def _score(evidences):
if not evidences:
return 0
sources = [ev.source_api for ev in evidences]
uniq_sources = numpy.unique(sources)
syst_factors = {s: self.prior_probs['syst'][s]
for s in uniq_sources}
rand_factors = {k: [] for k in uniq_sources}
for ev in evidences:
rand_factors[ev.source_api].append(
evidence_random_noise_prior(
ev,
self.prior_probs['rand'],
self.subtype_probs))
neg_prob_prior = 1
for s in uniq_sources:
neg_prob_prior *= (syst_factors[s] +
numpy.prod(rand_factors[s]))
prob_prior = 1 - neg_prob_prior
return prob_prior
pos_evidence = [ev for ev in evidences if
not ev.epistemics.get('negated')]
neg_evidence = [ev for ev in evidences if
ev.epistemics.get('negated')]
pp = _score(pos_evidence)
np = _score(neg_evidence)
score = pp * (1 - np)
return score |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'update_probs'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '10', '20', '78', '82', '153']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'syst_error'},{'id': '9', 'type': 'float', 'children': [], 'value': '0.05'},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'prior_probs'},{'id': '13', 'type': 'dictionary', 'children': ['14', '17']},{'id': '14', 'type': 'pair', 'children': ['15', '16']},{'id': '15', 'type': 'string', 'children': [], 'value': "'syst'"},{'id': '16', 'type': 'dictionary', 'children': []},{'id': '17', 'type': 'pair', 'children': ['18', '19']},{'id': '18', 'type': 'string', 'children': [], 'value': "'rand'"},{'id': '19', 'type': 'dictionary', 'children': []},{'id': '20', 'type': 'for_statement', 'children': ['21', '26', '33']},{'id': '21', 'type': 'pattern_list', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '23', 'type': 'tuple_pattern', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'n'},{'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': 'self'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'prior_counts'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '32', 'type': 'argument_list', 'children': []},{'id': '33', 'type': 'block', 'children': ['34', '42', '50']},{'id': '34', 'type': 'if_statement', 'children': ['35', '40']},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '39'], 'value': '=='},{'id': '36', 'type': 'binary_operator', 'children': ['37', '38'], 'value': '+'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '39', 'type': 'integer', 'children': [], 'value': '0'},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'continue_statement', 'children': []},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '49']},{'id': '44', 'type': 'subscript', 'children': ['45', '48']},{'id': '45', 'type': 'subscript', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'prior_probs'},{'id': '47', 'type': 'string', 'children': [], 'value': "'syst'"},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'syst_error'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '57', '58']},{'id': '52', 'type': 'subscript', 'children': ['53', '56']},{'id': '53', 'type': 'subscript', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'prior_probs'},{'id': '55', 'type': 'string', 'children': [], 'value': "'rand'"},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '57', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '58', 'type': 'binary_operator', 'children': ['59', '77'], 'value': '-'},{'id': '59', 'type': 'binary_operator', 'children': ['60', '61'], 'value': '-'},{'id': '60', 'type': 'integer', 'children': [], 'value': '1'},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'tuple', 'children': ['65', '74']},{'id': '65', 'type': 'binary_operator', 'children': ['66', '70'], 'value': '/'},{'id': '66', 'type': 'call', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '70', 'type': '()', 'children': ['71']},{'id': '71', 'type': 'binary_operator', 'children': ['72', '73'], 'value': '+'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '74', 'type': 'binary_operator', 'children': ['75', '76'], 'value': '-'},{'id': '75', 'type': 'integer', 'children': [], 'value': '1'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'syst_error'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'syst_error'},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'subtype_probs'},{'id': '81', 'type': 'dictionary', 'children': []},{'id': '82', 'type': 'for_statement', 'children': ['83', '86', '93']},{'id': '83', 'type': 'pattern_list', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'entry'},{'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': 'subtype_counts'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '92', 'type': 'argument_list', 'children': []},{'id': '93', 'type': 'block', 'children': ['94']},{'id': '94', 'type': 'for_statement', 'children': ['95', '100', '105']},{'id': '95', 'type': 'pattern_list', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'rule'},{'id': '97', 'type': 'tuple_pattern', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '100', 'type': 'call', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '104', 'type': 'argument_list', 'children': []},{'id': '105', 'type': 'block', 'children': ['106', '114', '125']},{'id': '106', 'type': 'if_statement', 'children': ['107', '112']},{'id': '107', 'type': 'comparison_operator', 'children': ['108', '111'], 'value': '=='},{'id': '108', 'type': 'binary_operator', 'children': ['109', '110'], 'value': '+'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '111', 'type': 'integer', 'children': [], 'value': '0'},{'id': '112', 'type': 'block', 'children': ['113']},{'id': '113', 'type': 'continue_statement', 'children': []},{'id': '114', 'type': 'if_statement', 'children': ['115', '118']},{'id': '115', 'type': 'comparison_operator', 'children': ['116', '117'], 'value': 'not'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'subtype_probs'},{'id': '118', 'type': 'block', 'children': ['119']},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '124']},{'id': '121', 'type': 'subscript', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'subtype_probs'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '124', 'type': 'dictionary', 'children': []},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '132', '133']},{'id': '127', 'type': 'subscript', 'children': ['128', '131']},{'id': '128', 'type': 'subscript', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'subtype_probs'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'rule'},{'id': '132', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '133', 'type': 'binary_operator', 'children': ['134', '152'], 'value': '-'},{'id': '134', 'type': 'binary_operator', 'children': ['135', '136'], 'value': '-'},{'id': '135', 'type': 'integer', 'children': [], 'value': '1'},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'tuple', 'children': ['140', '149']},{'id': '140', 'type': 'binary_operator', 'children': ['141', '145'], 'value': '/'},{'id': '141', 'type': 'call', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '145', 'type': '()', 'children': ['146']},{'id': '146', 'type': 'binary_operator', 'children': ['147', '148'], 'value': '+'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '149', 'type': 'binary_operator', 'children': ['150', '151'], 'value': '-'},{'id': '150', 'type': 'integer', 'children': [], 'value': '1'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'syst_error'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'syst_error'},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'call', 'children': ['155', '162']},{'id': '155', 'type': 'attribute', 'children': ['156', '161']},{'id': '156', 'type': 'call', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'super'},{'id': '158', 'type': 'argument_list', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'BayesianScorer'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'update_probs'},{'id': '162', 'type': 'argument_list', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'prior_probs'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'subtype_probs'} | def update_probs(self):
syst_error = 0.05
prior_probs = {'syst': {}, 'rand': {}}
for source, (p, n) in self.prior_counts.items():
if n + p == 0:
continue
prior_probs['syst'][source] = syst_error
prior_probs['rand'][source] = \
1 - min((float(p) / (n + p), 1-syst_error)) - syst_error
subtype_probs = {}
for source, entry in self.subtype_counts.items():
for rule, (p, n) in entry.items():
if n + p == 0:
continue
if source not in subtype_probs:
subtype_probs[source] = {}
subtype_probs[source][rule] = \
1 - min((float(p) / (n + p), 1-syst_error)) - syst_error
super(BayesianScorer, self).update_probs(prior_probs, subtype_probs) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'set_hierarchy_probs'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'statements'},{'id': '6', 'type': 'block', 'children': ['7', '76', '120', '157', '164', '169', '176']},{'id': '7', 'type': 'function_definition', 'children': ['8', '9', '11']},{'id': '8', 'type': 'function_name', 'children': [], 'value': 'build_hierarchy_graph'},{'id': '9', 'type': 'parameters', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '11', 'type': 'block', 'children': ['12', '20', '74']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'networkx'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'DiGraph'},{'id': '19', 'type': 'argument_list', 'children': []},{'id': '20', 'type': 'for_statement', 'children': ['21', '22', '23']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'st1'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '23', 'type': 'block', 'children': ['24', '38']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'add_node'},{'id': '29', 'type': 'argument_list', 'children': ['30', '35']},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'st1'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'matches_key'},{'id': '34', 'type': 'argument_list', 'children': []},{'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'st1'},{'id': '38', 'type': 'for_statement', 'children': ['39', '40', '43']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'st2'},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'st1'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'supported_by'},{'id': '43', 'type': 'block', 'children': ['44', '58']},{'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': 'g'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'add_node'},{'id': '49', 'type': 'argument_list', 'children': ['50', '55']},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'st2'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'matches_key'},{'id': '54', 'type': 'argument_list', 'children': []},{'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'st2'},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'add_edge'},{'id': '63', 'type': 'argument_list', 'children': ['64', '69']},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'st2'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'matches_key'},{'id': '68', 'type': 'argument_list', 'children': []},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'st1'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'matches_key'},{'id': '73', 'type': 'argument_list', 'children': []},{'id': '74', 'type': 'return_statement', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '76', 'type': 'function_definition', 'children': ['77', '78', '80']},{'id': '77', 'type': 'function_name', 'children': [], 'value': 'get_ranked_stmts'},{'id': '78', 'type': 'parameters', 'children': ['79']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '80', 'type': 'block', 'children': ['81', '94', '104', '118']},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'node_ranks'},{'id': '84', 'type': 'call', 'children': ['85', '92']},{'id': '85', 'type': 'attribute', 'children': ['86', '91']},{'id': '86', 'type': 'attribute', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'networkx'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'algorithms'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'dag'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'topological_sort'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'node_ranks'},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'reversed'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'node_ranks'},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '107', 'type': 'list_comprehension', 'children': ['108', '115']},{'id': '108', 'type': 'subscript', 'children': ['109', '114']},{'id': '109', 'type': 'subscript', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '114', 'type': 'string', 'children': [], 'value': "'stmt'"},{'id': '115', 'type': 'for_in_clause', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'node_ranks'},{'id': '118', 'type': 'return_statement', 'children': ['119']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '120', 'type': 'function_definition', 'children': ['121', '122', '124']},{'id': '121', 'type': 'function_name', 'children': [], 'value': 'assert_no_cycle'},{'id': '122', 'type': 'parameters', 'children': ['123']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '124', 'type': 'block', 'children': ['125', '148', '154']},{'id': '125', 'type': 'try_statement', 'children': ['126', '140']},{'id': '126', 'type': 'block', 'children': ['127']},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'cyc'},{'id': '130', 'type': 'call', 'children': ['131', '138']},{'id': '131', 'type': 'attribute', 'children': ['132', '137']},{'id': '132', 'type': 'attribute', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'networkx'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'algorithms'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'cycles'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'find_cycle'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '140', 'type': 'except_clause', 'children': ['141', '146']},{'id': '141', 'type': 'attribute', 'children': ['142', '145']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'networkx'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'exception'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'NetworkXNoCycle'},{'id': '146', 'type': 'block', 'children': ['147']},{'id': '147', 'type': 'return_statement', 'children': []},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '151', 'type': 'binary_operator', 'children': ['152', '153'], 'value': '%'},{'id': '152', 'type': 'string', 'children': [], 'value': "'Cycle found in hierarchy graph: %s'"},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'cyc'},{'id': '154', 'type': 'assert_statement', 'children': ['155', '156']},{'id': '155', 'type': 'False', 'children': []},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '160', 'type': 'call', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'build_hierarchy_graph'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'statements'},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'call', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'assert_no_cycle'},{'id': '167', 'type': 'argument_list', 'children': ['168']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'assignment', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'ranked_stmts'},{'id': '172', 'type': 'call', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'get_ranked_stmts'},{'id': '174', 'type': 'argument_list', 'children': ['175']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '176', 'type': 'for_statement', 'children': ['177', '178', '179']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'ranked_stmts'},{'id': '179', 'type': 'block', 'children': ['180', '187', '191', '224', '236']},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'assignment', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'bps'},{'id': '183', 'type': 'call', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': '_get_belief_package'},{'id': '185', 'type': 'argument_list', 'children': ['186']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '187', 'type': 'expression_statement', 'children': ['188']},{'id': '188', 'type': 'assignment', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'supporting_evidences'},{'id': '190', 'type': 'list', 'children': [], 'value': '[]'},{'id': '191', 'type': 'for_statement', 'children': ['192', '193', '199']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'bp'},{'id': '193', 'type': 'subscript', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'bps'},{'id': '195', 'type': 'slice', 'children': ['196', '197']},{'id': '196', 'type': 'colon', 'children': []},{'id': '197', 'type': 'unary_operator', 'children': ['198'], 'value': '-'},{'id': '198', 'type': 'integer', 'children': [], 'value': '1'},{'id': '199', 'type': 'block', 'children': ['200']},{'id': '200', 'type': 'for_statement', 'children': ['201', '202', '205']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '202', 'type': 'attribute', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'bp'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'evidences'},{'id': '205', 'type': 'block', 'children': ['206']},{'id': '206', 'type': 'if_statement', 'children': ['207', '216']},{'id': '207', 'type': 'not_operator', 'children': ['208']},{'id': '208', 'type': 'call', 'children': ['209', '214']},{'id': '209', 'type': 'attribute', 'children': ['210', '213']},{'id': '210', 'type': 'attribute', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'epistemics'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '214', 'type': 'argument_list', 'children': ['215']},{'id': '215', 'type': 'string', 'children': [], 'value': "'negated'"},{'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': 'supporting_evidences'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'ev'},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'assignment', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'belief'},{'id': '227', 'type': 'call', 'children': ['228', '233']},{'id': '228', 'type': 'attribute', 'children': ['229', '232']},{'id': '229', 'type': 'attribute', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'scorer'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'score_statement'},{'id': '233', 'type': 'argument_list', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'supporting_evidences'},{'id': '236', 'type': 'expression_statement', 'children': ['237']},{'id': '237', 'type': 'assignment', 'children': ['238', '241']},{'id': '238', 'type': 'attribute', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'belief'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'belief'} | def set_hierarchy_probs(self, statements):
def build_hierarchy_graph(stmts):
g = networkx.DiGraph()
for st1 in stmts:
g.add_node(st1.matches_key(), stmt=st1)
for st2 in st1.supported_by:
g.add_node(st2.matches_key(), stmt=st2)
g.add_edge(st2.matches_key(), st1.matches_key())
return g
def get_ranked_stmts(g):
node_ranks = networkx.algorithms.dag.topological_sort(g)
node_ranks = reversed(list(node_ranks))
stmts = [g.node[n]['stmt'] for n in node_ranks]
return stmts
def assert_no_cycle(g):
try:
cyc = networkx.algorithms.cycles.find_cycle(g)
except networkx.exception.NetworkXNoCycle:
return
msg = 'Cycle found in hierarchy graph: %s' % cyc
assert False, msg
g = build_hierarchy_graph(statements)
assert_no_cycle(g)
ranked_stmts = get_ranked_stmts(g)
for st in ranked_stmts:
bps = _get_belief_package(st)
supporting_evidences = []
for bp in bps[:-1]:
for ev in bp.evidences:
if not ev.epistemics.get('negated'):
supporting_evidences.append(ev)
belief = self.scorer.score_statement(st, supporting_evidences)
st.belief = belief |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_statements'},{'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': 'reprocess'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '219']},{'id': '9', 'type': 'if_statement', 'children': ['10', '17', '208']},{'id': '10', 'type': 'boolean_operator', 'children': ['11', '16'], 'value': 'or'},{'id': '11', 'type': 'comparison_operator', 'children': ['12', '15'], 'value': 'is'},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': '_statements'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'reprocess'},{'id': '17', 'type': 'block', 'children': ['18', '33', '167', '199']},{'id': '18', 'type': 'if_statement', 'children': ['19', '24']},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '23'], 'value': 'is'},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '23', 'type': 'None', 'children': []},{'id': '24', 'type': 'block', 'children': ['25', '31']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': '_statements'},{'id': '30', 'type': 'list', 'children': [], 'value': '[]'},{'id': '31', 'type': 'return_statement', 'children': ['32']},{'id': '32', 'type': 'list', 'children': [], 'value': '[]'},{'id': '33', 'type': 'if_statement', 'children': ['34', '41', '82', '136', '156']},{'id': '34', 'type': 'comparison_operator', 'children': ['35', '38'], 'value': '=='},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'reader'},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'ReachReader'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '41', 'type': 'block', 'children': ['42']},{'id': '42', 'type': 'if_statement', 'children': ['43', '50', '71']},{'id': '43', 'type': 'comparison_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': 'format'},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'formats'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'JSON'},{'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': 'json_str'},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'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': 'content'},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'processor'},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'reach'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'process_json_str'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'json_str'},{'id': '71', 'type': 'else_clause', 'children': ['72']},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'raise_statement', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'ReadingError'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'binary_operator', 'children': ['78', '79'], 'value': '%'},{'id': '78', 'type': 'string', 'children': [], 'value': '"Incorrect format for Reach output: %s."'},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '82', 'type': 'elif_clause', 'children': ['83', '90']},{'id': '83', 'type': 'comparison_operator', 'children': ['84', '87'], 'value': '=='},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'reader'},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'SparserReader'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '90', 'type': 'block', 'children': ['91']},{'id': '91', 'type': 'if_statement', 'children': ['92', '99', '123']},{'id': '92', 'type': 'comparison_operator', 'children': ['93', '96'], 'value': '=='},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'formats'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'JSON'},{'id': '99', 'type': 'block', 'children': ['100', '111']},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'processor'},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'sparser'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'process_json_dict'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '111', 'type': 'if_statement', 'children': ['112', '115']},{'id': '112', 'type': 'comparison_operator', 'children': ['113', '114'], 'value': 'is'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'processor'},{'id': '114', 'type': 'None', 'children': []},{'id': '115', 'type': 'block', 'children': ['116']},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'call', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'processor'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'set_statements_pmid'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'None', 'children': []},{'id': '123', 'type': 'else_clause', 'children': ['124']},{'id': '124', 'type': 'block', 'children': ['125']},{'id': '125', 'type': 'raise_statement', 'children': ['126']},{'id': '126', 'type': 'call', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'ReadingError'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'binary_operator', 'children': ['130', '133'], 'value': '%'},{'id': '130', 'type': 'concatenated_string', 'children': ['131', '132']},{'id': '131', 'type': 'string', 'children': [], 'value': '"Sparser should only ever be JSON, not "'},{'id': '132', 'type': 'string', 'children': [], 'value': '"%s."'},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '136', 'type': 'elif_clause', 'children': ['137', '144']},{'id': '137', 'type': 'comparison_operator', 'children': ['138', '141'], 'value': '=='},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'reader'},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'TripsReader'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'name'},{'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': 'processor'},{'id': '148', 'type': 'call', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'trips'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'process_xml'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '156', 'type': 'else_clause', 'children': ['157']},{'id': '157', 'type': 'block', 'children': ['158']},{'id': '158', 'type': 'raise_statement', 'children': ['159']},{'id': '159', 'type': 'call', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'ReadingError'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'binary_operator', 'children': ['163', '164'], 'value': '%'},{'id': '163', 'type': 'string', 'children': [], 'value': '"Unknown reader: %s."'},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'reader'},{'id': '167', 'type': 'if_statement', 'children': ['168', '171', '191']},{'id': '168', 'type': 'comparison_operator', 'children': ['169', '170'], 'value': 'is'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'processor'},{'id': '170', 'type': 'None', 'children': []},{'id': '171', 'type': 'block', 'children': ['172', '187']},{'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': 'logger'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '177', 'type': 'argument_list', 'children': ['178']},{'id': '178', 'type': 'binary_operator', 'children': ['179', '180'], 'value': '%'},{'id': '179', 'type': 'string', 'children': [], 'value': '"Production of statements from %s failed for %s."'},{'id': '180', 'type': 'tuple', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'reader'},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'content_id'},{'id': '187', 'type': 'expression_statement', 'children': ['188']},{'id': '188', 'type': 'assignment', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '190', 'type': 'list', 'children': [], 'value': '[]'},{'id': '191', 'type': 'else_clause', 'children': ['192']},{'id': '192', 'type': 'block', 'children': ['193']},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'assignment', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'processor'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'statements'},{'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': 'self'},{'id': '203', 'type': 'identifier', 'children': [], 'value': '_statements'},{'id': '204', 'type': 'subscript', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '206', 'type': 'slice', 'children': ['207']},{'id': '207', 'type': 'colon', 'children': []},{'id': '208', 'type': 'else_clause', 'children': ['209']},{'id': '209', 'type': 'block', 'children': ['210']},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'id': '211', 'type': 'assignment', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '213', 'type': 'subscript', 'children': ['214', '217']},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '216', 'type': 'identifier', 'children': [], 'value': '_statements'},{'id': '217', 'type': 'slice', 'children': ['218']},{'id': '218', 'type': 'colon', 'children': []},{'id': '219', 'type': 'return_statement', 'children': ['220']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'stmts'} | def get_statements(self, reprocess=False):
if self._statements is None or reprocess:
if self.content is None:
self._statements = []
return []
if self.reader == ReachReader.name:
if self.format == formats.JSON:
json_str = json.dumps(self.content)
processor = reach.process_json_str(json_str)
else:
raise ReadingError("Incorrect format for Reach output: %s."
% self.format)
elif self.reader == SparserReader.name:
if self.format == formats.JSON:
processor = sparser.process_json_dict(self.content)
if processor is not None:
processor.set_statements_pmid(None)
else:
raise ReadingError("Sparser should only ever be JSON, not "
"%s." % self.format)
elif self.reader == TripsReader.name:
processor = trips.process_xml(self.content)
else:
raise ReadingError("Unknown reader: %s." % self.reader)
if processor is None:
logger.error("Production of statements from %s failed for %s."
% (self.reader, self.content_id))
stmts = []
else:
stmts = processor.statements
self._statements = stmts[:]
else:
stmts = self._statements[:]
return stmts |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'read'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'read_list'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'n_per_proc'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'block', 'children': ['16', '18', '22', '29', '38', '45', '52', '56', '81', '357', '366']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'string', 'children': [], 'value': '"Perform the actual reading."'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '21', 'type': 'list', 'children': [], 'value': '[]'},{'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': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'prep_input'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'read_list'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'L'},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'file_list'},{'id': '38', 'type': 'if_statement', 'children': ['39', '42']},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': '=='},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'L'},{'id': '41', 'type': 'integer', 'children': [], 'value': '0'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'return_statement', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'string', 'children': [], 'value': '"Beginning to run sparser."'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'output_file_list'},{'id': '55', 'type': 'list', 'children': [], 'value': '[]'},{'id': '56', 'type': 'if_statement', 'children': ['57', '58', '75']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '58', 'type': 'block', 'children': ['59', '67']},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'log_name'},{'id': '62', 'type': 'binary_operator', 'children': ['63', '64'], 'value': '%'},{'id': '63', 'type': 'string', 'children': [], 'value': "'sparser_run_%s.log'"},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': '_time_stamp'},{'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': 'outbuf'},{'id': '70', 'type': 'call', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '72', 'type': 'argument_list', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'log_name'},{'id': '74', 'type': 'string', 'children': [], 'value': "'wb'"},{'id': '75', 'type': 'else_clause', 'children': ['76']},{'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': 'outbuf'},{'id': '80', 'type': 'None', 'children': []},{'id': '81', 'type': 'try_statement', 'children': ['82', '334']},{'id': '82', 'type': 'block', 'children': ['83']},{'id': '83', 'type': 'if_statement', 'children': ['84', '89', '121']},{'id': '84', 'type': 'comparison_operator', 'children': ['85', '88'], 'value': '=='},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'n_proc'},{'id': '88', 'type': 'integer', 'children': [], 'value': '1'},{'id': '89', 'type': 'block', 'children': ['90']},{'id': '90', 'type': 'for_statement', 'children': ['91', '92', '95']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'fpath'},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'file_list'},{'id': '95', 'type': 'block', 'children': ['96', '109']},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '101']},{'id': '98', 'type': 'pattern_list', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'outpath'},{'id': '100', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'read_one'},{'id': '105', 'type': 'argument_list', 'children': ['106', '107', '108']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'fpath'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'outbuf'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '109', 'type': 'if_statement', 'children': ['110', '113']},{'id': '110', 'type': 'comparison_operator', 'children': ['111', '112'], 'value': 'is'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'outpath'},{'id': '112', 'type': 'None', 'children': []},{'id': '113', 'type': 'block', 'children': ['114']},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'call', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'output_file_list'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'outpath'},{'id': '121', 'type': 'else_clause', 'children': ['122']},{'id': '122', 'type': 'block', 'children': ['123', '146', '150', '255']},{'id': '123', 'type': 'if_statement', 'children': ['124', '127']},{'id': '124', 'type': 'comparison_operator', 'children': ['125', '126'], 'value': 'is'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'n_per_proc'},{'id': '126', 'type': 'None', 'children': []},{'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': 'n_per_proc'},{'id': '131', 'type': 'call', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '133', 'type': 'argument_list', 'children': ['134', '135']},{'id': '134', 'type': 'integer', 'children': [], 'value': '1'},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '137', 'type': 'argument_list', 'children': ['138', '139']},{'id': '138', 'type': 'integer', 'children': [], 'value': '1000'},{'id': '139', 'type': 'binary_operator', 'children': ['140', '145'], 'value': '//'},{'id': '140', 'type': 'binary_operator', 'children': ['141', '142'], 'value': '//'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'L'},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'n_proc'},{'id': '145', 'type': 'integer', 'children': [], 'value': '2'},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'assignment', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'pool'},{'id': '149', 'type': 'None', 'children': []},{'id': '150', 'type': 'try_statement', 'children': ['151', '236']},{'id': '151', 'type': 'block', 'children': ['152', '161']},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'pool'},{'id': '155', 'type': 'call', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'Pool'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'n_proc'},{'id': '161', 'type': 'if_statement', 'children': ['162', '165', '207']},{'id': '162', 'type': 'comparison_operator', 'children': ['163', '164'], 'value': 'is'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'n_per_proc'},{'id': '164', 'type': 'integer', 'children': [], 'value': '1'},{'id': '165', 'type': 'block', 'children': ['166', '195']},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'batches'},{'id': '169', 'type': 'list_comprehension', 'children': ['170', '185']},{'id': '170', 'type': 'subscript', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'file_list'},{'id': '174', 'type': 'slice', 'children': ['175', '178', '179']},{'id': '175', 'type': 'binary_operator', 'children': ['176', '177'], 'value': '*'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'n_per_proc'},{'id': '178', 'type': 'colon', 'children': []},{'id': '179', 'type': 'binary_operator', 'children': ['180', '184'], 'value': '*'},{'id': '180', 'type': '()', 'children': ['181']},{'id': '181', 'type': 'binary_operator', 'children': ['182', '183'], 'value': '+'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '183', 'type': 'integer', 'children': [], 'value': '1'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'n_per_proc'},{'id': '185', 'type': 'for_in_clause', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '187', 'type': 'call', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'binary_operator', 'children': ['191', '194'], 'value': '+'},{'id': '191', 'type': 'binary_operator', 'children': ['192', '193'], 'value': '//'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'L'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'n_per_proc'},{'id': '194', 'type': 'integer', 'children': [], 'value': '1'},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'assignment', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'out_lists_and_buffs'},{'id': '198', 'type': 'call', 'children': ['199', '202']},{'id': '199', 'type': 'attribute', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'pool'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '202', 'type': 'argument_list', 'children': ['203', '206']},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'read_some'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'batches'},{'id': '207', 'type': 'else_clause', 'children': ['208']},{'id': '208', 'type': 'block', 'children': ['209', '223']},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'assignment', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'out_files_and_buffs'},{'id': '212', 'type': 'call', 'children': ['213', '216']},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'pool'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '216', 'type': 'argument_list', 'children': ['217', '220']},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'read_one'},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'file_list'},{'id': '223', 'type': 'expression_statement', 'children': ['224']},{'id': '224', 'type': 'assignment', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'out_lists_and_buffs'},{'id': '226', 'type': 'list_comprehension', 'children': ['227', '231']},{'id': '227', 'type': 'tuple', 'children': ['228', '230']},{'id': '228', 'type': 'list', 'children': ['229'], 'value': '[out_files]'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'out_files'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'buffs'},{'id': '231', 'type': 'for_in_clause', 'children': ['232', '235']},{'id': '232', 'type': 'pattern_list', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'out_files'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'buffs'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'out_files_and_buffs'},{'id': '236', 'type': 'finally_clause', 'children': ['237']},{'id': '237', 'type': 'block', 'children': ['238']},{'id': '238', 'type': 'if_statement', 'children': ['239', '242']},{'id': '239', 'type': 'comparison_operator', 'children': ['240', '241'], 'value': 'is'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'pool'},{'id': '241', 'type': 'None', 'children': []},{'id': '242', 'type': 'block', 'children': ['243', '249']},{'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': 'pool'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '248', 'type': 'argument_list', 'children': []},{'id': '249', 'type': 'expression_statement', 'children': ['250']},{'id': '250', 'type': 'call', 'children': ['251', '254']},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'pool'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '254', 'type': 'argument_list', 'children': []},{'id': '255', 'type': 'for_statement', 'children': ['256', '261', '265']},{'id': '256', 'type': 'pattern_list', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '258', 'type': 'tuple_pattern', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'out_list'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'buff'},{'id': '261', 'type': 'call', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '263', 'type': 'argument_list', 'children': ['264']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'out_lists_and_buffs'},{'id': '265', 'type': 'block', 'children': ['266', '275']},{'id': '266', 'type': 'if_statement', 'children': ['267', '270']},{'id': '267', 'type': 'comparison_operator', 'children': ['268', '269'], 'value': 'is'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'out_list'},{'id': '269', 'type': 'None', 'children': []},{'id': '270', 'type': 'block', 'children': ['271']},{'id': '271', 'type': 'expression_statement', 'children': ['272']},{'id': '272', 'type': 'augmented_assignment', 'children': ['273', '274'], 'value': '+='},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'output_file_list'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'out_list'},{'id': '275', 'type': 'if_statement', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '277', 'type': 'block', 'children': ['278', '292', '328']},{'id': '278', 'type': 'expression_statement', 'children': ['279']},{'id': '279', 'type': 'call', 'children': ['280', '283']},{'id': '280', 'type': 'attribute', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'outbuf'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '283', 'type': 'argument_list', 'children': ['284']},{'id': '284', 'type': 'binary_operator', 'children': ['285', '286'], 'value': '%'},{'id': '285', 'type': 'string', 'children': [], 'value': "b'Log for producing output %d/%d.\\n'"},{'id': '286', 'type': 'tuple', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '288', 'type': 'call', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '290', 'type': 'argument_list', 'children': ['291']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'out_lists_and_buffs'},{'id': '292', 'type': 'if_statement', 'children': ['293', '296', '317']},{'id': '293', 'type': 'comparison_operator', 'children': ['294', '295'], 'value': 'is'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'buff'},{'id': '295', 'type': 'None', 'children': []},{'id': '296', 'type': 'block', 'children': ['297', '304']},{'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': 'buff'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'seek'},{'id': '302', 'type': 'argument_list', 'children': ['303']},{'id': '303', 'type': 'integer', 'children': [], 'value': '0'},{'id': '304', 'type': 'expression_statement', 'children': ['305']},{'id': '305', 'type': 'call', 'children': ['306', '309']},{'id': '306', 'type': 'attribute', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'outbuf'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '309', 'type': 'argument_list', 'children': ['310']},{'id': '310', 'type': 'binary_operator', 'children': ['311', '316'], 'value': '+'},{'id': '311', 'type': 'call', 'children': ['312', '315']},{'id': '312', 'type': 'attribute', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'buff'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '315', 'type': 'argument_list', 'children': []},{'id': '316', 'type': 'string', 'children': [], 'value': "b'\\n'"},{'id': '317', 'type': 'else_clause', 'children': ['318']},{'id': '318', 'type': 'block', 'children': ['319']},{'id': '319', 'type': 'expression_statement', 'children': ['320']},{'id': '320', 'type': 'call', 'children': ['321', '324']},{'id': '321', 'type': 'attribute', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'outbuf'},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '324', 'type': 'argument_list', 'children': ['325']},{'id': '325', 'type': 'concatenated_string', 'children': ['326', '327']},{'id': '326', 'type': 'string', 'children': [], 'value': "b'ERROR: no buffer was None. '"},{'id': '327', 'type': 'string', 'children': [], 'value': "b'No logs available.\\n'"},{'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': 'outbuf'},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'flush'},{'id': '333', 'type': 'argument_list', 'children': []},{'id': '334', 'type': 'finally_clause', 'children': ['335']},{'id': '335', 'type': 'block', 'children': ['336']},{'id': '336', 'type': 'if_statement', 'children': ['337', '338']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '338', 'type': 'block', 'children': ['339', '345']},{'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': 'outbuf'},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '344', 'type': 'argument_list', 'children': []},{'id': '345', 'type': 'if_statement', 'children': ['346', '347']},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '347', 'type': 'block', 'children': ['348']},{'id': '348', 'type': 'expression_statement', 'children': ['349']},{'id': '349', 'type': 'call', 'children': ['350', '353']},{'id': '350', 'type': 'attribute', 'children': ['351', '352']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '353', 'type': 'argument_list', 'children': ['354']},{'id': '354', 'type': 'binary_operator', 'children': ['355', '356'], 'value': '%'},{'id': '355', 'type': 'string', 'children': [], 'value': '"Sparser logs may be found at %s."'},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'log_name'},{'id': '357', 'type': 'expression_statement', 'children': ['358']},{'id': '358', 'type': 'assignment', 'children': ['359', '360']},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '360', 'type': 'call', 'children': ['361', '364']},{'id': '361', 'type': 'attribute', 'children': ['362', '363']},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'get_output'},{'id': '364', 'type': 'argument_list', 'children': ['365']},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'output_file_list'},{'id': '366', 'type': 'return_statement', 'children': ['367']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'ret'} | def read(self, read_list, verbose=False, log=False, n_per_proc=None):
"Perform the actual reading."
ret = []
self.prep_input(read_list)
L = len(self.file_list)
if L == 0:
return ret
logger.info("Beginning to run sparser.")
output_file_list = []
if log:
log_name = 'sparser_run_%s.log' % _time_stamp()
outbuf = open(log_name, 'wb')
else:
outbuf = None
try:
if self.n_proc == 1:
for fpath in self.file_list:
outpath, _ = self.read_one(fpath, outbuf, verbose)
if outpath is not None:
output_file_list.append(outpath)
else:
if n_per_proc is None:
n_per_proc = max(1, min(1000, L//self.n_proc//2))
pool = None
try:
pool = Pool(self.n_proc)
if n_per_proc is not 1:
batches = [self.file_list[n*n_per_proc:(n+1)*n_per_proc]
for n in range(L//n_per_proc + 1)]
out_lists_and_buffs = pool.map(self.read_some,
batches)
else:
out_files_and_buffs = pool.map(self.read_one,
self.file_list)
out_lists_and_buffs = [([out_files], buffs)
for out_files, buffs
in out_files_and_buffs]
finally:
if pool is not None:
pool.close()
pool.join()
for i, (out_list, buff) in enumerate(out_lists_and_buffs):
if out_list is not None:
output_file_list += out_list
if log:
outbuf.write(b'Log for producing output %d/%d.\n'
% (i, len(out_lists_and_buffs)))
if buff is not None:
buff.seek(0)
outbuf.write(buff.read() + b'\n')
else:
outbuf.write(b'ERROR: no buffer was None. '
b'No logs available.\n')
outbuf.flush()
finally:
if log:
outbuf.close()
if verbose:
logger.info("Sparser logs may be found at %s." %
log_name)
ret = self.get_output(output_file_list)
return ret |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'read_pmid_sentences'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'pmid_sentences'},{'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'drum_args'},{'id': '7', 'type': 'block', 'children': ['8', '30', '40', '44', '48', '224', '237']},{'id': '8', 'type': 'function_definition', 'children': ['9', '10', '13']},{'id': '9', 'type': 'function_name', 'children': [], 'value': '_set_pmid'},{'id': '10', 'type': 'parameters', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'statements'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'pmid'},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'for_statement', 'children': ['15', '16', '17']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'statements'},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'for_statement', 'children': ['19', '20', '23']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'evidence'},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'evidence'},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'evidence'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'pmid'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'pmid'},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'run_drum'},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'drum_args'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '37', 'type': 'argument_list', 'children': ['38', '39']},{'id': '38', 'type': 'string', 'children': [], 'value': "'run_drum'"},{'id': '39', 'type': 'False', 'children': []},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'drum_process'},{'id': '43', 'type': 'None', 'children': []},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'all_statements'},{'id': '47', 'type': 'dictionary', 'children': []},{'id': '48', 'type': 'for_statement', 'children': ['49', '52', '57']},{'id': '49', 'type': 'pattern_list', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'pmid'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'sentences'},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'pmid_sentences'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '56', 'type': 'argument_list', 'children': []},{'id': '57', 'type': 'block', 'children': ['58', '65', '79', '87', '95', '103', '110', '137', '148', '160', '164', '188', '194', '202', '218']},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'string', 'children': [], 'value': "'================================'"},{'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': 'info'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'binary_operator', 'children': ['72', '73'], 'value': '%'},{'id': '72', 'type': 'string', 'children': [], 'value': "'Processing %d sentences for %s'"},{'id': '73', 'type': 'tuple', 'children': ['74', '78']},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'sentences'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'pmid'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'ts'},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '86', 'type': 'argument_list', 'children': []},{'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': 'drum_args'},{'id': '91', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '92', 'type': 'binary_operator', 'children': ['93', '94'], 'value': '%'},{'id': '93', 'type': 'string', 'children': [], 'value': "'DrumReader%s'"},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'pmid'},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'assignment', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'dr'},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'DrumReader'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'dictionary_splat', 'children': ['102']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'drum_args'},{'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': 'time'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'sleep'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'integer', 'children': [], 'value': '3'},{'id': '110', 'type': 'if_statement', 'children': ['111', '116']},{'id': '111', 'type': 'boolean_operator', 'children': ['112', '113'], 'value': 'and'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'run_drum'},{'id': '113', 'type': 'comparison_operator', 'children': ['114', '115'], 'value': 'is'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'drum_process'},{'id': '115', 'type': 'None', 'children': []},{'id': '116', 'type': 'block', 'children': ['117', '125', '131']},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'drum_args'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '122', 'type': 'argument_list', 'children': ['123', '124']},{'id': '123', 'type': 'string', 'children': [], 'value': "'run_drum'"},{'id': '124', 'type': 'None', 'children': []},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'drum_process'},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'dr'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'drum_system'},{'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': 'drum_args'},{'id': '135', 'type': 'string', 'children': [], 'value': "'drum_system'"},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'drum_process'},{'id': '137', 'type': 'for_statement', 'children': ['138', '139', '140']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'sentence'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'sentences'},{'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': 'dr'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'read_text'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'sentence'},{'id': '148', 'type': 'try_statement', 'children': ['149', '156']},{'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': 'dr'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '155', 'type': 'argument_list', 'children': []},{'id': '156', 'type': 'except_clause', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'SystemExit'},{'id': '158', 'type': 'block', 'children': ['159']},{'id': '159', 'type': 'pass_statement', 'children': []},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'statements'},{'id': '163', 'type': 'list', 'children': [], 'value': '[]'},{'id': '164', 'type': 'for_statement', 'children': ['165', '166', '169']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'extraction'},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'dr'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'extractions'},{'id': '169', 'type': 'block', 'children': ['170', '175', '182']},{'id': '170', 'type': 'if_statement', 'children': ['171', '173']},{'id': '171', 'type': 'not_operator', 'children': ['172']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'extraction'},{'id': '173', 'type': 'block', 'children': ['174']},{'id': '174', 'type': 'continue_statement', 'children': []},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'assignment', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'tp'},{'id': '178', 'type': 'call', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'process_xml'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'extraction'},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'augmented_assignment', 'children': ['184', '185'], 'value': '+='},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'statements'},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'tp'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'statements'},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'call', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': '_set_pmid'},{'id': '191', 'type': 'argument_list', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'statements'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'pmid'},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'assignment', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'te'},{'id': '197', 'type': 'call', 'children': ['198', '201']},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '201', 'type': 'argument_list', 'children': []},{'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': 'logger'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '207', 'type': 'argument_list', 'children': ['208']},{'id': '208', 'type': 'binary_operator', 'children': ['209', '210'], 'value': '%'},{'id': '209', 'type': 'string', 'children': [], 'value': "'Reading took %d seconds and produced %d Statements.'"},{'id': '210', 'type': 'tuple', 'children': ['211', '214']},{'id': '211', 'type': 'binary_operator', 'children': ['212', '213'], 'value': '-'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'te'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'ts'},{'id': '214', 'type': 'call', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '216', 'type': 'argument_list', 'children': ['217']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'statements'},{'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': 'all_statements'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'pmid'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'statements'},{'id': '224', 'type': 'if_statement', 'children': ['225', '230']},{'id': '225', 'type': 'boolean_operator', 'children': ['226', '227'], 'value': 'and'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'drum_process'},{'id': '227', 'type': 'attribute', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'dr'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'drum_system'},{'id': '230', 'type': 'block', 'children': ['231']},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'call', 'children': ['233', '236']},{'id': '233', 'type': 'attribute', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'dr'},{'id': '235', 'type': 'identifier', 'children': [], 'value': '_kill_drum'},{'id': '236', 'type': 'argument_list', 'children': []},{'id': '237', 'type': 'return_statement', 'children': ['238']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'all_statements'} | def read_pmid_sentences(pmid_sentences, **drum_args):
def _set_pmid(statements, pmid):
for stmt in statements:
for evidence in stmt.evidence:
evidence.pmid = pmid
run_drum = drum_args.get('run_drum', False)
drum_process = None
all_statements = {}
for pmid, sentences in pmid_sentences.items():
logger.info('================================')
logger.info('Processing %d sentences for %s' % (len(sentences), pmid))
ts = time.time()
drum_args['name'] = 'DrumReader%s' % pmid
dr = DrumReader(**drum_args)
time.sleep(3)
if run_drum and drum_process is None:
drum_args.pop('run_drum', None)
drum_process = dr.drum_system
drum_args['drum_system'] = drum_process
for sentence in sentences:
dr.read_text(sentence)
try:
dr.start()
except SystemExit:
pass
statements = []
for extraction in dr.extractions:
if not extraction:
continue
tp = process_xml(extraction)
statements += tp.statements
_set_pmid(statements, pmid)
te = time.time()
logger.info('Reading took %d seconds and produced %d Statements.' %
(te-ts, len(statements)))
all_statements[pmid] = statements
if drum_process and dr.drum_system:
dr._kill_drum()
return all_statements |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'graph_query'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'neighbor_limit'},{'id': '11', 'type': 'integer', 'children': [], 'value': '1'},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'database_filter'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'block', 'children': ['16', '38', '52', '56', '62', '68', '74', '82', '101', '107', '129', '135', '166', '199', '206', '227', '234', '248', '285', '294', '306']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'default_databases'},{'id': '19', 'type': 'list', 'children': ['20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37'], 'value': "['wp', 'smpdb', 'reconx', 'reactome', 'psp', 'pid',\n 'panther', 'netpath', 'msigdb', 'mirtarbase', 'kegg',\n 'intact', 'inoh', 'humancyc', 'hprd',\n 'drugbank', 'dip', 'corum']"},{'id': '20', 'type': 'string', 'children': [], 'value': "'wp'"},{'id': '21', 'type': 'string', 'children': [], 'value': "'smpdb'"},{'id': '22', 'type': 'string', 'children': [], 'value': "'reconx'"},{'id': '23', 'type': 'string', 'children': [], 'value': "'reactome'"},{'id': '24', 'type': 'string', 'children': [], 'value': "'psp'"},{'id': '25', 'type': 'string', 'children': [], 'value': "'pid'"},{'id': '26', 'type': 'string', 'children': [], 'value': "'panther'"},{'id': '27', 'type': 'string', 'children': [], 'value': "'netpath'"},{'id': '28', 'type': 'string', 'children': [], 'value': "'msigdb'"},{'id': '29', 'type': 'string', 'children': [], 'value': "'mirtarbase'"},{'id': '30', 'type': 'string', 'children': [], 'value': "'kegg'"},{'id': '31', 'type': 'string', 'children': [], 'value': "'intact'"},{'id': '32', 'type': 'string', 'children': [], 'value': "'inoh'"},{'id': '33', 'type': 'string', 'children': [], 'value': "'humancyc'"},{'id': '34', 'type': 'string', 'children': [], 'value': "'hprd'"},{'id': '35', 'type': 'string', 'children': [], 'value': "'drugbank'"},{'id': '36', 'type': 'string', 'children': [], 'value': "'dip'"},{'id': '37', 'type': 'string', 'children': [], 'value': "'corum'"},{'id': '38', 'type': 'if_statement', 'children': ['39', '41', '46']},{'id': '39', 'type': 'not_operator', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'database_filter'},{'id': '41', 'type': 'block', 'children': ['42']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'query_databases'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'default_databases'},{'id': '46', 'type': 'else_clause', 'children': ['47']},{'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': 'query_databases'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'database_filter'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '55', 'type': 'dictionary', 'children': []},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '61']},{'id': '58', 'type': 'subscript', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '60', 'type': 'string', 'children': [], 'value': "'format'"},{'id': '61', 'type': 'string', 'children': [], 'value': "'BIOPAX'"},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '67']},{'id': '64', 'type': 'subscript', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '66', 'type': 'string', 'children': [], 'value': "'organism'"},{'id': '67', 'type': 'string', 'children': [], 'value': "'9606'"},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '73']},{'id': '70', 'type': 'subscript', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '72', 'type': 'string', 'children': [], 'value': "'datasource'"},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'query_databases'},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'kind_str'},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '81', 'type': 'argument_list', 'children': []},{'id': '82', 'type': 'if_statement', 'children': ['83', '89']},{'id': '83', 'type': 'comparison_operator', 'children': ['84', '85'], 'value': 'not'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '85', 'type': 'list', 'children': ['86', '87', '88'], 'value': "['neighborhood', 'pathsbetween', 'pathsfromto']"},{'id': '86', 'type': 'string', 'children': [], 'value': "'neighborhood'"},{'id': '87', 'type': 'string', 'children': [], 'value': "'pathsbetween'"},{'id': '88', 'type': 'string', 'children': [], 'value': "'pathsfromto'"},{'id': '89', 'type': 'block', 'children': ['90', '99']},{'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': 'logger'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'binary_operator', 'children': ['97', '98'], 'value': '%'},{'id': '97', 'type': 'string', 'children': [], 'value': "'Invalid query type %s'"},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'kind_str'},{'id': '99', 'type': 'return_statement', 'children': ['100']},{'id': '100', 'type': 'None', 'children': []},{'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': "'kind'"},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'kind_str'},{'id': '107', 'type': 'if_statement', 'children': ['108', '113', '118']},{'id': '108', 'type': 'call', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '110', 'type': 'argument_list', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'basestring'},{'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': 'source_str'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '118', 'type': 'else_clause', 'children': ['119']},{'id': '119', 'type': 'block', 'children': ['120']},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'source_str'},{'id': '123', 'type': 'call', 'children': ['124', '127']},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'string', 'children': [], 'value': "','"},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'assignment', 'children': ['131', '134']},{'id': '131', 'type': 'subscript', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '133', 'type': 'string', 'children': [], 'value': "'source'"},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'source_str'},{'id': '135', 'type': 'try_statement', 'children': ['136', '150']},{'id': '136', 'type': 'block', 'children': ['137', '144']},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'assignment', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'neighbor_limit'},{'id': '140', 'type': 'call', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'neighbor_limit'},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '149']},{'id': '146', 'type': 'subscript', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '148', 'type': 'string', 'children': [], 'value': "'limit'"},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'neighbor_limit'},{'id': '150', 'type': 'except_clause', 'children': ['151', '154']},{'id': '151', 'type': 'tuple', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '154', 'type': 'block', 'children': ['155', '164']},{'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': 'logger'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'binary_operator', 'children': ['162', '163'], 'value': '%'},{'id': '162', 'type': 'string', 'children': [], 'value': "'Invalid neighborhood limit %s'"},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'neighbor_limit'},{'id': '164', 'type': 'return_statement', 'children': ['165']},{'id': '165', 'type': 'None', 'children': []},{'id': '166', 'type': 'if_statement', 'children': ['167', '170']},{'id': '167', 'type': 'comparison_operator', 'children': ['168', '169'], 'value': 'is'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '169', 'type': 'None', 'children': []},{'id': '170', 'type': 'block', 'children': ['171', '193']},{'id': '171', 'type': 'if_statement', 'children': ['172', '177', '182']},{'id': '172', 'type': 'call', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '174', 'type': 'argument_list', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'basestring'},{'id': '177', 'type': 'block', 'children': ['178']},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'assignment', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'target_str'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'target'},{'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': 'target_str'},{'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': 'join'},{'id': '191', 'type': 'argument_list', 'children': ['192']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'target'},{'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': 'params'},{'id': '197', 'type': 'string', 'children': [], 'value': "'target'"},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'target_str'},{'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': 'logger'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '204', 'type': 'argument_list', 'children': ['205']},{'id': '205', 'type': 'string', 'children': [], 'value': "'Sending Pathway Commons query with parameters: '"},{'id': '206', 'type': 'for_statement', 'children': ['207', '210', '215']},{'id': '207', 'type': 'pattern_list', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '210', 'type': 'call', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '214', 'type': 'argument_list', 'children': []},{'id': '215', 'type': 'block', 'children': ['216']},{'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': 'logger'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '221', 'type': 'argument_list', 'children': ['222']},{'id': '222', 'type': 'binary_operator', 'children': ['223', '224'], 'value': '%'},{'id': '223', 'type': 'string', 'children': [], 'value': "' %s: %s'"},{'id': '224', 'type': 'tuple', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'v'},{'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': 'logger'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '232', 'type': 'argument_list', 'children': ['233']},{'id': '233', 'type': 'string', 'children': [], 'value': "'Sending Pathway Commons query...'"},{'id': '234', 'type': 'expression_statement', 'children': ['235']},{'id': '235', 'type': 'assignment', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '237', 'type': 'call', 'children': ['238', '241']},{'id': '238', 'type': 'attribute', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '241', 'type': 'argument_list', 'children': ['242', '245']},{'id': '242', 'type': 'binary_operator', 'children': ['243', '244'], 'value': '+'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'pc2_url'},{'id': '244', 'type': 'string', 'children': [], 'value': "'graph'"},{'id': '245', 'type': 'keyword_argument', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '248', 'type': 'if_statement', 'children': ['249', '255']},{'id': '249', 'type': 'not_operator', 'children': ['250']},{'id': '250', 'type': 'comparison_operator', 'children': ['251', '254'], 'value': '=='},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '254', 'type': 'integer', 'children': [], 'value': '200'},{'id': '255', 'type': 'block', 'children': ['256', '267', '283']},{'id': '256', 'type': 'expression_statement', 'children': ['257']},{'id': '257', 'type': 'call', 'children': ['258', '261']},{'id': '258', 'type': 'attribute', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '261', 'type': 'argument_list', 'children': ['262']},{'id': '262', 'type': 'binary_operator', 'children': ['263', '264'], 'value': '%'},{'id': '263', 'type': 'string', 'children': [], 'value': "'Response is HTTP code %d.'"},{'id': '264', 'type': 'attribute', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '267', 'type': 'if_statement', 'children': ['268', '273']},{'id': '268', 'type': 'comparison_operator', 'children': ['269', '272'], 'value': '=='},{'id': '269', 'type': 'attribute', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '272', 'type': 'integer', 'children': [], 'value': '500'},{'id': '273', 'type': 'block', 'children': ['274']},{'id': '274', 'type': 'expression_statement', 'children': ['275']},{'id': '275', 'type': 'call', 'children': ['276', '279']},{'id': '276', 'type': 'attribute', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '279', 'type': 'argument_list', 'children': ['280']},{'id': '280', 'type': 'concatenated_string', 'children': ['281', '282']},{'id': '281', 'type': 'string', 'children': [], 'value': "'Note: HTTP code 500 can mean empty '"},{'id': '282', 'type': 'string', 'children': [], 'value': "'results for a valid query.'"},{'id': '283', 'type': 'return_statement', 'children': ['284']},{'id': '284', 'type': 'None', 'children': []},{'id': '285', 'type': 'expression_statement', 'children': ['286']},{'id': '286', 'type': 'assignment', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '288', 'type': 'call', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'owl_str_to_model'},{'id': '290', 'type': 'argument_list', 'children': ['291']},{'id': '291', 'type': 'attribute', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '294', 'type': 'if_statement', 'children': ['295', '298']},{'id': '295', 'type': 'comparison_operator', 'children': ['296', '297'], 'value': 'is'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '297', 'type': 'None', 'children': []},{'id': '298', 'type': 'block', 'children': ['299']},{'id': '299', 'type': 'expression_statement', 'children': ['300']},{'id': '300', 'type': 'call', 'children': ['301', '304']},{'id': '301', 'type': 'attribute', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '304', 'type': 'argument_list', 'children': ['305']},{'id': '305', 'type': 'string', 'children': [], 'value': "'Pathway Commons query returned a model...'"},{'id': '306', 'type': 'return_statement', 'children': ['307']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'model'} | def graph_query(kind, source, target=None, neighbor_limit=1,
database_filter=None):
default_databases = ['wp', 'smpdb', 'reconx', 'reactome', 'psp', 'pid',
'panther', 'netpath', 'msigdb', 'mirtarbase', 'kegg',
'intact', 'inoh', 'humancyc', 'hprd',
'drugbank', 'dip', 'corum']
if not database_filter:
query_databases = default_databases
else:
query_databases = database_filter
params = {}
params['format'] = 'BIOPAX'
params['organism'] = '9606'
params['datasource'] = query_databases
kind_str = kind.lower()
if kind not in ['neighborhood', 'pathsbetween', 'pathsfromto']:
logger.warn('Invalid query type %s' % kind_str)
return None
params['kind'] = kind_str
if isinstance(source, basestring):
source_str = source
else:
source_str = ','.join(source)
params['source'] = source_str
try:
neighbor_limit = int(neighbor_limit)
params['limit'] = neighbor_limit
except (TypeError, ValueError):
logger.warn('Invalid neighborhood limit %s' % neighbor_limit)
return None
if target is not None:
if isinstance(target, basestring):
target_str = target
else:
target_str = ','.join(target)
params['target'] = target_str
logger.info('Sending Pathway Commons query with parameters: ')
for k, v in params.items():
logger.info(' %s: %s' % (k, v))
logger.info('Sending Pathway Commons query...')
res = requests.get(pc2_url + 'graph', params=params)
if not res.status_code == 200:
logger.error('Response is HTTP code %d.' % res.status_code)
if res.status_code == 500:
logger.error('Note: HTTP code 500 can mean empty '
'results for a valid query.')
return None
model = owl_str_to_model(res.content)
if model is not None:
logger.info('Pathway Commons query returned a model...')
return model |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'set_CCLE_context'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'cell_types'},{'id': '6', 'type': 'block', 'children': ['7', '13', '26', '39', '49', '95', '279', '286', '296']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'call', 'children': ['9', '12']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'get_gene_names'},{'id': '12', 'type': 'argument_list', 'children': []},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16', '17']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'exp_values'},{'id': '16', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'context_client'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'get_protein_expression'},{'id': '21', 'type': 'argument_list', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '24', 'type': 'identifier', 'children': [], 'value': '_gene_names'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'cell_types'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29', '30']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'mut_values'},{'id': '29', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'context_client'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'get_mutations'},{'id': '34', 'type': 'argument_list', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': '_gene_names'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'cell_types'},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'muts'},{'id': '42', 'type': 'dictionary_comprehension', 'children': ['43', '46']},{'id': '43', 'type': 'pair', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'cell_line'},{'id': '45', 'type': 'dictionary', 'children': []},{'id': '46', 'type': 'for_in_clause', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'cell_line'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'cell_types'},{'id': '49', 'type': 'for_statement', 'children': ['50', '53', '58']},{'id': '50', 'type': 'pattern_list', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'cell_line'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'entries'},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'mut_values'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '57', 'type': 'argument_list', 'children': []},{'id': '58', 'type': 'block', 'children': ['59']},{'id': '59', 'type': 'if_statement', 'children': ['60', '63']},{'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': 'is'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'entries'},{'id': '62', 'type': 'None', 'children': []},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'for_statement', 'children': ['65', '68', '73']},{'id': '65', 'type': 'pattern_list', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'gene'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'mutations'},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'entries'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '72', 'type': 'argument_list', 'children': []},{'id': '73', 'type': 'block', 'children': ['74']},{'id': '74', 'type': 'if_statement', 'children': ['75', '76', '85']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'mutations'},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '84']},{'id': '79', 'type': 'subscript', 'children': ['80', '83']},{'id': '80', 'type': 'subscript', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'muts'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'cell_line'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'gene'},{'id': '84', 'type': 'integer', 'children': [], 'value': '1'},{'id': '85', 'type': 'else_clause', 'children': ['86']},{'id': '86', 'type': 'block', 'children': ['87']},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '94']},{'id': '89', 'type': 'subscript', 'children': ['90', '93']},{'id': '90', 'type': 'subscript', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'muts'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'cell_line'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'gene'},{'id': '94', 'type': 'integer', 'children': [], 'value': '0'},{'id': '95', 'type': 'function_definition', 'children': ['96', '97', '99']},{'id': '96', 'type': 'function_name', 'children': [], 'value': 'bin_exp'},{'id': '97', 'type': 'parameters', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'expression_dict'},{'id': '99', 'type': 'block', 'children': ['100', '104', '108', '138', '142', '177', '194', '277']},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'expression_dict'},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'exp_values'},{'id': '107', 'type': 'list', 'children': [], 'value': '[]'},{'id': '108', 'type': 'for_statement', 'children': ['109', '110', '111']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '111', 'type': 'block', 'children': ['112']},{'id': '112', 'type': 'for_statement', 'children': ['113', '114', '117']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'gene'},{'id': '114', 'type': 'subscript', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '117', 'type': 'block', 'children': ['118', '126']},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '121', 'type': 'subscript', 'children': ['122', '125']},{'id': '122', 'type': 'subscript', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'gene'},{'id': '126', 'type': 'if_statement', 'children': ['127', '130']},{'id': '127', 'type': 'comparison_operator', 'children': ['128', '129'], 'value': 'is'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '129', 'type': 'None', 'children': []},{'id': '130', 'type': 'block', 'children': ['131']},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'call', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'exp_values'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'assignment', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'thr_dict'},{'id': '141', 'type': 'dictionary', 'children': []},{'id': '142', 'type': 'for_statement', 'children': ['143', '144', '149']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'n_bins'},{'id': '144', 'type': 'call', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '146', 'type': 'argument_list', 'children': ['147', '148']},{'id': '147', 'type': 'integer', 'children': [], 'value': '3'},{'id': '148', 'type': 'integer', 'children': [], 'value': '10'},{'id': '149', 'type': 'block', 'children': ['150', '171']},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'bin_thr'},{'id': '153', 'type': 'subscript', 'children': ['154', '168']},{'id': '154', 'type': 'subscript', 'children': ['155', '167']},{'id': '155', 'type': 'call', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'histogram'},{'id': '159', 'type': 'argument_list', 'children': ['160', '166']},{'id': '160', 'type': 'call', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'log10'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'exp_values'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'n_bins'},{'id': '167', 'type': 'integer', 'children': [], 'value': '1'},{'id': '168', 'type': 'slice', 'children': ['169', '170']},{'id': '169', 'type': 'integer', 'children': [], 'value': '1'},{'id': '170', 'type': 'colon', 'children': []},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'assignment', 'children': ['173', '176']},{'id': '173', 'type': 'subscript', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'thr_dict'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'n_bins'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'bin_thr'},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'binned_dict'},{'id': '180', 'type': 'dictionary_comprehension', 'children': ['181', '187']},{'id': '181', 'type': 'pair', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '183', 'type': 'call', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'deepcopy'},{'id': '185', 'type': 'argument_list', 'children': ['186']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'expression_dict'},{'id': '187', 'type': 'for_in_clause', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '189', 'type': 'call', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '191', 'type': 'argument_list', 'children': ['192', '193']},{'id': '192', 'type': 'integer', 'children': [], 'value': '3'},{'id': '193', 'type': 'integer', 'children': [], 'value': '10'},{'id': '194', 'type': 'for_statement', 'children': ['195', '196', '197']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'n_bins'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'binned_dict'},{'id': '197', 'type': 'block', 'children': ['198']},{'id': '198', 'type': 'for_statement', 'children': ['199', '200', '203']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '200', 'type': 'subscript', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'binned_dict'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'n_bins'},{'id': '203', 'type': 'block', 'children': ['204']},{'id': '204', 'type': 'for_statement', 'children': ['205', '206', '211']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'gene'},{'id': '206', 'type': 'subscript', 'children': ['207', '210']},{'id': '207', 'type': 'subscript', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'binned_dict'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'n_bins'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '211', 'type': 'block', 'children': ['212']},{'id': '212', 'type': 'if_statement', 'children': ['213', '222', '233']},{'id': '213', 'type': 'comparison_operator', 'children': ['214', '221'], 'value': 'is'},{'id': '214', 'type': 'subscript', 'children': ['215', '220']},{'id': '215', 'type': 'subscript', 'children': ['216', '219']},{'id': '216', 'type': 'subscript', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'binned_dict'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'n_bins'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'gene'},{'id': '221', 'type': 'None', 'children': []},{'id': '222', 'type': 'block', 'children': ['223']},{'id': '223', 'type': 'expression_statement', 'children': ['224']},{'id': '224', 'type': 'assignment', 'children': ['225', '232']},{'id': '225', 'type': 'subscript', 'children': ['226', '231']},{'id': '226', 'type': 'subscript', 'children': ['227', '230']},{'id': '227', 'type': 'subscript', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'binned_dict'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'n_bins'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'gene'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'n_bins'},{'id': '233', 'type': 'else_clause', 'children': ['234']},{'id': '234', 'type': 'block', 'children': ['235', '250']},{'id': '235', 'type': 'expression_statement', 'children': ['236']},{'id': '236', 'type': 'assignment', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '238', 'type': 'call', 'children': ['239', '242']},{'id': '239', 'type': 'attribute', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'log10'},{'id': '242', 'type': 'argument_list', 'children': ['243']},{'id': '243', 'type': 'subscript', 'children': ['244', '249']},{'id': '244', 'type': 'subscript', 'children': ['245', '248']},{'id': '245', 'type': 'subscript', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'binned_dict'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'n_bins'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'gene'},{'id': '250', 'type': 'for_statement', 'children': ['251', '254', '260']},{'id': '251', 'type': 'pattern_list', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'thr_idx'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'thr'},{'id': '254', 'type': 'call', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '256', 'type': 'argument_list', 'children': ['257']},{'id': '257', 'type': 'subscript', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'thr_dict'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'n_bins'},{'id': '260', 'type': 'block', 'children': ['261']},{'id': '261', 'type': 'if_statement', 'children': ['262', '265']},{'id': '262', 'type': 'comparison_operator', 'children': ['263', '264'], 'value': '<='},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'thr'},{'id': '265', 'type': 'block', 'children': ['266', '276']},{'id': '266', 'type': 'expression_statement', 'children': ['267']},{'id': '267', 'type': 'assignment', 'children': ['268', '275']},{'id': '268', 'type': 'subscript', 'children': ['269', '274']},{'id': '269', 'type': 'subscript', 'children': ['270', '273']},{'id': '270', 'type': 'subscript', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'binned_dict'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'n_bins'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'gene'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'thr_idx'},{'id': '276', 'type': 'break_statement', 'children': []},{'id': '277', 'type': 'return_statement', 'children': ['278']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'binned_dict'},{'id': '279', 'type': 'expression_statement', 'children': ['280']},{'id': '280', 'type': 'assignment', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'binned_exp'},{'id': '282', 'type': 'call', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'bin_exp'},{'id': '284', 'type': 'argument_list', 'children': ['285']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'exp_values'},{'id': '286', 'type': 'expression_statement', 'children': ['287']},{'id': '287', 'type': 'assignment', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '289', 'type': 'dictionary', 'children': ['290', '293']},{'id': '290', 'type': 'pair', 'children': ['291', '292']},{'id': '291', 'type': 'string', 'children': [], 'value': "'bin_expression'"},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'binned_exp'},{'id': '293', 'type': 'pair', 'children': ['294', '295']},{'id': '294', 'type': 'string', 'children': [], 'value': "'mutation'"},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'muts'},{'id': '296', 'type': 'expression_statement', 'children': ['297']},{'id': '297', 'type': 'assignment', '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': '_context'},{'id': '302', 'type': 'string', 'children': [], 'value': "'CCLE'"},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'context'} | def set_CCLE_context(self, cell_types):
self.get_gene_names()
exp_values = \
context_client.get_protein_expression(self._gene_names, cell_types)
mut_values = \
context_client.get_mutations(self._gene_names, cell_types)
muts = {cell_line: {} for cell_line in cell_types}
for cell_line, entries in mut_values.items():
if entries is not None:
for gene, mutations in entries.items():
if mutations:
muts[cell_line][gene] = 1
else:
muts[cell_line][gene] = 0
def bin_exp(expression_dict):
d = expression_dict
exp_values = []
for line in d:
for gene in d[line]:
val = d[line][gene]
if val is not None:
exp_values.append(val)
thr_dict = {}
for n_bins in range(3, 10):
bin_thr = np.histogram(np.log10(exp_values), n_bins)[1][1:]
thr_dict[n_bins] = bin_thr
binned_dict = {x: deepcopy(expression_dict) for x in range(3, 10)}
for n_bins in binned_dict:
for line in binned_dict[n_bins]:
for gene in binned_dict[n_bins][line]:
if binned_dict[n_bins][line][gene] is None:
binned_dict[n_bins][line][gene] = n_bins
else:
val = np.log10(binned_dict[n_bins][line][gene])
for thr_idx, thr in enumerate(thr_dict[n_bins]):
if val <= thr:
binned_dict[n_bins][line][gene] = thr_idx
break
return binned_dict
binned_exp = bin_exp(exp_values)
context = {'bin_expression': binned_exp,
'mutation': muts}
self._context['CCLE'] = context |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_node_key'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'node_dict_item'},{'id': '6', 'type': 'block', 'children': ['7', '19', '31']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'subscript', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'node_dict_item'},{'id': '18', 'type': 'string', 'children': [], 'value': "'sources'"},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'subscript', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'node_dict_item'},{'id': '30', 'type': 'string', 'children': [], 'value': "'targets'"},{'id': '31', 'type': 'return_statement', 'children': ['32']},{'id': '32', 'type': 'tuple', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 't'} | def _get_node_key(self, node_dict_item):
s = tuple(sorted(node_dict_item['sources']))
t = tuple(sorted(node_dict_item['targets']))
return (s, t) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_node_groups'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '28', '102', '112', '140', '160']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'node_dict'},{'id': '9', 'type': 'dictionary_comprehension', 'children': ['10', '23']},{'id': '10', 'type': 'pair', 'children': ['11', '16']},{'id': '11', 'type': 'subscript', 'children': ['12', '15']},{'id': '12', 'type': 'subscript', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '14', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '15', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '16', 'type': 'dictionary', 'children': ['17', '20']},{'id': '17', 'type': 'pair', 'children': ['18', '19']},{'id': '18', 'type': 'string', 'children': [], 'value': "'sources'"},{'id': '19', 'type': 'list', 'children': [], 'value': '[]'},{'id': '20', 'type': 'pair', 'children': ['21', '22']},{'id': '21', 'type': 'string', 'children': [], 'value': "'targets'"},{'id': '22', 'type': 'list', 'children': [], 'value': '[]'},{'id': '23', 'type': 'for_in_clause', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '27', 'type': 'identifier', 'children': [], 'value': '_nodes'},{'id': '28', 'type': 'for_statement', 'children': ['29', '30', '33']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'edge'},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '32', 'type': 'identifier', 'children': [], 'value': '_edges'},{'id': '33', 'type': 'block', 'children': ['34', '53', '68', '87']},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'edge_data'},{'id': '37', 'type': 'tuple', 'children': ['38', '43', '48']},{'id': '38', 'type': 'subscript', 'children': ['39', '42']},{'id': '39', 'type': 'subscript', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'edge'},{'id': '41', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '42', 'type': 'string', 'children': [], 'value': "'i'"},{'id': '43', 'type': 'subscript', 'children': ['44', '47']},{'id': '44', 'type': 'subscript', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'edge'},{'id': '46', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '47', 'type': 'string', 'children': [], 'value': "'polarity'"},{'id': '48', 'type': 'subscript', 'children': ['49', '52']},{'id': '49', 'type': 'subscript', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'edge'},{'id': '51', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '52', 'type': 'string', 'children': [], 'value': "'source'"},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '66']},{'id': '55', 'type': 'attribute', 'children': ['56', '65']},{'id': '56', 'type': 'subscript', 'children': ['57', '64']},{'id': '57', 'type': 'subscript', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'node_dict'},{'id': '59', 'type': 'subscript', 'children': ['60', '63']},{'id': '60', 'type': 'subscript', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'edge'},{'id': '62', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '63', 'type': 'string', 'children': [], 'value': "'target'"},{'id': '64', 'type': 'string', 'children': [], 'value': "'sources'"},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'edge_data'},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'edge_data'},{'id': '71', 'type': 'tuple', 'children': ['72', '77', '82']},{'id': '72', 'type': 'subscript', 'children': ['73', '76']},{'id': '73', 'type': 'subscript', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'edge'},{'id': '75', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '76', 'type': 'string', 'children': [], 'value': "'i'"},{'id': '77', 'type': 'subscript', 'children': ['78', '81']},{'id': '78', 'type': 'subscript', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'edge'},{'id': '80', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '81', 'type': 'string', 'children': [], 'value': "'polarity'"},{'id': '82', 'type': 'subscript', 'children': ['83', '86']},{'id': '83', 'type': 'subscript', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'edge'},{'id': '85', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '86', 'type': 'string', 'children': [], 'value': "'target'"},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'call', 'children': ['89', '100']},{'id': '89', 'type': 'attribute', 'children': ['90', '99']},{'id': '90', 'type': 'subscript', 'children': ['91', '98']},{'id': '91', 'type': 'subscript', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'node_dict'},{'id': '93', 'type': 'subscript', 'children': ['94', '97']},{'id': '94', 'type': 'subscript', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'edge'},{'id': '96', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '97', 'type': 'string', 'children': [], 'value': "'source'"},{'id': '98', 'type': 'string', 'children': [], 'value': "'targets'"},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'edge_data'},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'node_key_dict'},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'lambda', 'children': ['111']},{'id': '111', 'type': 'list', 'children': [], 'value': '[]'},{'id': '112', 'type': 'for_statement', 'children': ['113', '116', '121']},{'id': '113', 'type': 'pattern_list', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'node_d'},{'id': '116', 'type': 'call', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'node_dict'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '120', 'type': 'argument_list', 'children': []},{'id': '121', 'type': 'block', 'children': ['122', '131']},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '125', 'type': 'call', 'children': ['126', '129']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '128', 'type': 'identifier', 'children': [], 'value': '_get_node_key'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'node_d'},{'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': 'node_key_dict'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'assignment', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'node_groups'},{'id': '143', 'type': 'list_comprehension', 'children': ['144', '145', '152']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '145', 'type': 'for_in_clause', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '147', 'type': 'call', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'node_key_dict'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '151', 'type': 'argument_list', 'children': []},{'id': '152', 'type': 'if_clause', 'children': ['153']},{'id': '153', 'type': '()', 'children': ['154']},{'id': '154', 'type': 'comparison_operator', 'children': ['155', '159'], 'value': '>'},{'id': '155', 'type': 'call', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '159', 'type': 'integer', 'children': [], 'value': '1'},{'id': '160', 'type': 'return_statement', 'children': ['161']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'node_groups'} | def _get_node_groups(self):
node_dict = {node['data']['id']: {'sources': [], 'targets': []}
for node in self._nodes}
for edge in self._edges:
edge_data = (edge['data']['i'], edge['data']['polarity'],
edge['data']['source'])
node_dict[edge['data']['target']]['sources'].append(edge_data)
edge_data = (edge['data']['i'], edge['data']['polarity'],
edge['data']['target'])
node_dict[edge['data']['source']]['targets'].append(edge_data)
node_key_dict = collections.defaultdict(lambda: [])
for node_id, node_d in node_dict.items():
key = self._get_node_key(node_d)
node_key_dict[key].append(node_id)
node_groups = [g for g in node_key_dict.values() if (len(g) > 1)]
return node_groups |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_group_edges'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '12', '234']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'edges_to_add'},{'id': '9', 'type': 'list', 'children': ['10', '11'], 'value': '[[], []]'},{'id': '10', 'type': 'list', 'children': [], 'value': '[]'},{'id': '11', 'type': 'list', 'children': [], 'value': '[]'},{'id': '12', 'type': 'for_statement', 'children': ['13', '14', '17']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '16', 'type': 'identifier', 'children': [], 'value': '_edges'},{'id': '17', 'type': 'block', 'children': ['18', '25', '35', '47', '55', '63', '83', '103', '132', '161']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'new_edge'},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'deepcopy'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'call', 'children': ['27', '32']},{'id': '27', 'type': 'attribute', 'children': ['28', '31']},{'id': '28', 'type': 'subscript', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'new_edge'},{'id': '30', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '32', 'type': 'argument_list', 'children': ['33', '34']},{'id': '33', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '34', 'type': 'None', 'children': []},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'uuid_list'},{'id': '38', 'type': 'call', 'children': ['39', '44']},{'id': '39', 'type': 'attribute', 'children': ['40', '43']},{'id': '40', 'type': 'subscript', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'new_edge'},{'id': '42', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '44', 'type': 'argument_list', 'children': ['45', '46']},{'id': '45', 'type': 'string', 'children': [], 'value': "'uuid_list'"},{'id': '46', 'type': 'list', 'children': [], 'value': '[]'},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '50', 'type': 'subscript', 'children': ['51', '54']},{'id': '51', 'type': 'subscript', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '53', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '54', 'type': 'string', 'children': [], 'value': "'source'"},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '58', 'type': 'subscript', 'children': ['59', '62']},{'id': '59', 'type': 'subscript', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '61', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '62', 'type': 'string', 'children': [], 'value': "'target'"},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'source_node'},{'id': '66', 'type': 'subscript', 'children': ['67', '82']},{'id': '67', 'type': 'list_comprehension', 'children': ['68', '69', '74']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '69', 'type': 'for_in_clause', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '73', 'type': 'identifier', 'children': [], 'value': '_nodes'},{'id': '74', 'type': 'if_clause', 'children': ['75']},{'id': '75', 'type': 'comparison_operator', 'children': ['76', '81'], 'value': '=='},{'id': '76', 'type': 'subscript', 'children': ['77', '80']},{'id': '77', 'type': 'subscript', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '79', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '80', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '82', 'type': 'integer', 'children': [], 'value': '0'},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'target_node'},{'id': '86', 'type': 'subscript', 'children': ['87', '102']},{'id': '87', 'type': 'list_comprehension', 'children': ['88', '89', '94']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '89', 'type': 'for_in_clause', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '93', 'type': 'identifier', 'children': [], 'value': '_nodes'},{'id': '94', 'type': 'if_clause', 'children': ['95']},{'id': '95', 'type': 'comparison_operator', 'children': ['96', '101'], 'value': '=='},{'id': '96', 'type': 'subscript', 'children': ['97', '100']},{'id': '97', 'type': 'subscript', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '99', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '100', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '102', 'type': 'integer', 'children': [], 'value': '0'},{'id': '103', 'type': 'if_statement', 'children': ['104', '111']},{'id': '104', 'type': 'comparison_operator', 'children': ['105', '110'], 'value': '!='},{'id': '105', 'type': 'subscript', 'children': ['106', '109']},{'id': '106', 'type': 'subscript', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'source_node'},{'id': '108', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '109', 'type': 'string', 'children': [], 'value': "'parent'"},{'id': '110', 'type': 'string', 'children': [], 'value': "''"},{'id': '111', 'type': 'block', 'children': ['112', '124']},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '119']},{'id': '114', 'type': 'subscript', 'children': ['115', '118']},{'id': '115', 'type': 'subscript', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'new_edge'},{'id': '117', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '118', 'type': 'string', 'children': [], 'value': "'source'"},{'id': '119', 'type': 'subscript', 'children': ['120', '123']},{'id': '120', 'type': 'subscript', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'source_node'},{'id': '122', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '123', 'type': 'string', 'children': [], 'value': "'parent'"},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'assignment', 'children': ['126', '131']},{'id': '126', 'type': 'subscript', 'children': ['127', '130']},{'id': '127', 'type': 'subscript', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '129', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '130', 'type': 'string', 'children': [], 'value': "'i'"},{'id': '131', 'type': 'string', 'children': [], 'value': "'Virtual'"},{'id': '132', 'type': 'if_statement', 'children': ['133', '140']},{'id': '133', 'type': 'comparison_operator', 'children': ['134', '139'], 'value': '!='},{'id': '134', 'type': 'subscript', 'children': ['135', '138']},{'id': '135', 'type': 'subscript', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'target_node'},{'id': '137', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '138', 'type': 'string', 'children': [], 'value': "'parent'"},{'id': '139', 'type': 'string', 'children': [], 'value': "''"},{'id': '140', 'type': 'block', 'children': ['141', '153']},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '148']},{'id': '143', 'type': 'subscript', 'children': ['144', '147']},{'id': '144', 'type': 'subscript', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'new_edge'},{'id': '146', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '147', 'type': 'string', 'children': [], 'value': "'target'"},{'id': '148', 'type': 'subscript', 'children': ['149', '152']},{'id': '149', 'type': 'subscript', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'target_node'},{'id': '151', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '152', 'type': 'string', 'children': [], 'value': "'parent'"},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '160']},{'id': '155', 'type': 'subscript', 'children': ['156', '159']},{'id': '156', 'type': 'subscript', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '158', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '159', 'type': 'string', 'children': [], 'value': "'i'"},{'id': '160', 'type': 'string', 'children': [], 'value': "'Virtual'"},{'id': '161', 'type': 'if_statement', 'children': ['162', '169']},{'id': '162', 'type': 'comparison_operator', 'children': ['163', '168'], 'value': '=='},{'id': '163', 'type': 'subscript', 'children': ['164', '167']},{'id': '164', 'type': 'subscript', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '166', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '167', 'type': 'string', 'children': [], 'value': "'i'"},{'id': '168', 'type': 'string', 'children': [], 'value': "'Virtual'"},{'id': '169', 'type': 'block', 'children': ['170']},{'id': '170', 'type': 'if_statement', 'children': ['171', '176', '195']},{'id': '171', 'type': 'comparison_operator', 'children': ['172', '173'], 'value': 'not'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'new_edge'},{'id': '173', 'type': 'subscript', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'edges_to_add'},{'id': '175', 'type': 'integer', 'children': [], 'value': '0'},{'id': '176', 'type': 'block', 'children': ['177', '186']},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'call', 'children': ['179', '184']},{'id': '179', 'type': 'attribute', 'children': ['180', '183']},{'id': '180', 'type': 'subscript', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'edges_to_add'},{'id': '182', 'type': 'integer', 'children': [], 'value': '0'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'new_edge'},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'call', 'children': ['188', '193']},{'id': '188', 'type': 'attribute', 'children': ['189', '192']},{'id': '189', 'type': 'subscript', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'edges_to_add'},{'id': '191', 'type': 'integer', 'children': [], 'value': '1'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '193', 'type': 'argument_list', 'children': ['194']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'uuid_list'},{'id': '195', 'type': 'else_clause', 'children': ['196']},{'id': '196', 'type': 'block', 'children': ['197', '208', '216']},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'assignment', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '200', 'type': 'call', 'children': ['201', '206']},{'id': '201', 'type': 'attribute', 'children': ['202', '205']},{'id': '202', 'type': 'subscript', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'edges_to_add'},{'id': '204', 'type': 'integer', 'children': [], 'value': '0'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '206', 'type': 'argument_list', 'children': ['207']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'new_edge'},{'id': '208', 'type': 'expression_statement', 'children': ['209']},{'id': '209', 'type': 'augmented_assignment', 'children': ['210', '215'], 'value': '+='},{'id': '210', 'type': 'subscript', 'children': ['211', '214']},{'id': '211', 'type': 'subscript', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'edges_to_add'},{'id': '213', 'type': 'integer', 'children': [], 'value': '1'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'uuid_list'},{'id': '216', 'type': 'expression_statement', 'children': ['217']},{'id': '217', 'type': 'assignment', 'children': ['218', '223']},{'id': '218', 'type': 'subscript', 'children': ['219', '222']},{'id': '219', 'type': 'subscript', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'edges_to_add'},{'id': '221', 'type': 'integer', 'children': [], 'value': '1'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '223', 'type': 'call', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '225', 'type': 'argument_list', 'children': ['226']},{'id': '226', 'type': 'call', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '228', 'type': 'argument_list', 'children': ['229']},{'id': '229', 'type': 'subscript', 'children': ['230', '233']},{'id': '230', 'type': 'subscript', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'edges_to_add'},{'id': '232', 'type': 'integer', 'children': [], 'value': '1'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '234', 'type': 'for_statement', 'children': ['235', '236', '241']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'ze'},{'id': '236', 'type': 'call', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '238', 'type': 'argument_list', 'children': ['239']},{'id': '239', 'type': 'list_splat', 'children': ['240']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'edges_to_add'},{'id': '241', 'type': 'block', 'children': ['242', '248', '260', '270']},{'id': '242', 'type': 'expression_statement', 'children': ['243']},{'id': '243', 'type': 'assignment', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'edge'},{'id': '245', 'type': 'subscript', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'ze'},{'id': '247', 'type': 'integer', 'children': [], 'value': '0'},{'id': '248', 'type': 'expression_statement', 'children': ['249']},{'id': '249', 'type': 'assignment', 'children': ['250', '255']},{'id': '250', 'type': 'subscript', 'children': ['251', '254']},{'id': '251', 'type': 'subscript', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'edge'},{'id': '253', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '254', 'type': 'string', 'children': [], 'value': "'id'"},{'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': '_get_new_id'},{'id': '259', 'type': 'argument_list', 'children': []},{'id': '260', 'type': 'expression_statement', 'children': ['261']},{'id': '261', 'type': 'assignment', 'children': ['262', '267']},{'id': '262', 'type': 'subscript', 'children': ['263', '266']},{'id': '263', 'type': 'subscript', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'edge'},{'id': '265', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '266', 'type': 'string', 'children': [], 'value': "'uuid_list'"},{'id': '267', 'type': 'subscript', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'ze'},{'id': '269', 'type': 'integer', 'children': [], 'value': '1'},{'id': '270', 'type': 'expression_statement', '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': 'self'},{'id': '275', 'type': 'identifier', 'children': [], 'value': '_edges'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '277', 'type': 'argument_list', 'children': ['278']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'edge'} | def _group_edges(self):
edges_to_add = [[], []]
for e in self._edges:
new_edge = deepcopy(e)
new_edge['data'].pop('id', None)
uuid_list = new_edge['data'].pop('uuid_list', [])
source = e['data']['source']
target = e['data']['target']
source_node = [x for x in self._nodes if
x['data']['id'] == source][0]
target_node = [x for x in self._nodes if
x['data']['id'] == target][0]
if source_node['data']['parent'] != '':
new_edge['data']['source'] = source_node['data']['parent']
e['data']['i'] = 'Virtual'
if target_node['data']['parent'] != '':
new_edge['data']['target'] = target_node['data']['parent']
e['data']['i'] = 'Virtual'
if e['data']['i'] == 'Virtual':
if new_edge not in edges_to_add[0]:
edges_to_add[0].append(new_edge)
edges_to_add[1].append(uuid_list)
else:
idx = edges_to_add[0].index(new_edge)
edges_to_add[1][idx] += uuid_list
edges_to_add[1][idx] = list(set(edges_to_add[1][idx]))
for ze in zip(*edges_to_add):
edge = ze[0]
edge['data']['id'] = self._get_new_id()
edge['data']['uuid_list'] = ze[1]
self._edges.append(edge) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '40']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_statements'},{'id': '3', 'type': 'parameters', 'children': ['4', '7', '10', '13', '16', '19', '22', '25', '28', '31', '34', '37']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'subject'},{'id': '6', 'type': 'None', 'children': []},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'object'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'agents'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'stmt_type'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'use_exact_type'},{'id': '18', 'type': 'False', 'children': []},{'id': '19', 'type': 'default_parameter', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'persist'},{'id': '21', 'type': 'True', 'children': []},{'id': '22', 'type': 'default_parameter', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '24', 'type': 'None', 'children': []},{'id': '25', 'type': 'default_parameter', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'simple_response'},{'id': '27', 'type': 'False', 'children': []},{'id': '28', 'type': 'default_parameter', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'ev_limit'},{'id': '30', 'type': 'integer', 'children': [], 'value': '10'},{'id': '31', 'type': 'default_parameter', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'best_first'},{'id': '33', 'type': 'True', 'children': []},{'id': '34', 'type': 'default_parameter', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'tries'},{'id': '36', 'type': 'integer', 'children': [], 'value': '2'},{'id': '37', 'type': 'default_parameter', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'max_stmts'},{'id': '39', 'type': 'None', 'children': []},{'id': '40', 'type': 'block', 'children': ['41', '58', '73']},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'processor'},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'IndraDBRestProcessor'},{'id': '46', 'type': 'argument_list', 'children': ['47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'subject'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'object'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'agents'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'stmt_type'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'use_exact_type'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'persist'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'ev_limit'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'best_first'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'tries'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'max_stmts'},{'id': '58', 'type': 'if_statement', 'children': ['59', '60', '67']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'simple_response'},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'processor'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'statements'},{'id': '67', 'type': 'else_clause', 'children': ['68']},{'id': '68', 'type': 'block', 'children': ['69']},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'processor'},{'id': '73', 'type': 'return_statement', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'ret'} | def get_statements(subject=None, object=None, agents=None, stmt_type=None,
use_exact_type=False, persist=True, timeout=None,
simple_response=False, ev_limit=10, best_first=True, tries=2,
max_stmts=None):
processor = IndraDBRestProcessor(subject, object, agents, stmt_type,
use_exact_type, persist, timeout,
ev_limit, best_first, tries, max_stmts)
if simple_response:
ret = processor.statements
else:
ret = processor
return ret |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_statements_by_hash'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'hash_list'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'ev_limit'},{'id': '7', 'type': 'integer', 'children': [], 'value': '100'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'best_first'},{'id': '10', 'type': 'True', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'tries'},{'id': '13', 'type': 'integer', 'children': [], 'value': '2'},{'id': '14', 'type': 'block', 'children': ['15', '33', '39', '59', '81', '104']},{'id': '15', 'type': 'if_statement', 'children': ['16', '22']},{'id': '16', 'type': 'not_operator', 'children': ['17']},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '19', 'type': 'argument_list', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'hash_list'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'raise_statement', 'children': ['24']},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'binary_operator', 'children': ['28', '29'], 'value': '%'},{'id': '28', 'type': 'string', 'children': [], 'value': '"The `hash_list` input is a list, not %s."'},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'hash_list'},{'id': '33', 'type': 'if_statement', 'children': ['34', '36']},{'id': '34', 'type': 'not_operator', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'hash_list'},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'return_statement', 'children': ['38']},{'id': '38', 'type': 'list', 'children': [], 'value': '[]'},{'id': '39', 'type': 'if_statement', 'children': ['40', '47']},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '42', 'type': 'argument_list', 'children': ['43', '46']},{'id': '43', 'type': 'subscript', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'hash_list'},{'id': '45', 'type': 'integer', 'children': [], 'value': '0'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'str'},{'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': 'hash_list'},{'id': '51', 'type': 'list_comprehension', 'children': ['52', '56']},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '56', 'type': 'for_in_clause', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'hash_list'},{'id': '59', 'type': 'if_statement', 'children': ['60', '73']},{'id': '60', 'type': 'not_operator', 'children': ['61']},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'list_comprehension', 'children': ['65', '70']},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '67', 'type': 'argument_list', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '70', 'type': 'for_in_clause', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'hash_list'},{'id': '73', 'type': 'block', 'children': ['74']},{'id': '74', 'type': 'raise_statement', 'children': ['75']},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'concatenated_string', 'children': ['79', '80']},{'id': '79', 'type': 'string', 'children': [], 'value': '"Hashes must be ints or strings that can be "'},{'id': '80', 'type': 'string', 'children': [], 'value': '"converted into ints."'},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'resp'},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'submit_statement_request'},{'id': '86', 'type': 'argument_list', 'children': ['87', '88', '89', '92', '98', '101']},{'id': '87', 'type': 'string', 'children': [], 'value': "'post'"},{'id': '88', 'type': 'string', 'children': [], 'value': "'from_hashes'"},{'id': '89', 'type': 'keyword_argument', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'ev_limit'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'ev_limit'},{'id': '92', 'type': 'keyword_argument', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '94', 'type': 'dictionary', 'children': ['95']},{'id': '95', 'type': 'pair', 'children': ['96', '97']},{'id': '96', 'type': 'string', 'children': [], 'value': "'hashes'"},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'hash_list'},{'id': '98', 'type': 'keyword_argument', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'best_first'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'best_first'},{'id': '101', 'type': 'keyword_argument', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'tries'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'tries'},{'id': '104', 'type': 'return_statement', 'children': ['105']},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'stmts_from_json'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'call', 'children': ['109', '118']},{'id': '109', 'type': 'attribute', 'children': ['110', '117']},{'id': '110', 'type': 'subscript', 'children': ['111', '116']},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'resp'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '115', 'type': 'argument_list', 'children': []},{'id': '116', 'type': 'string', 'children': [], 'value': "'statements'"},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '118', 'type': 'argument_list', 'children': []} | def get_statements_by_hash(hash_list, ev_limit=100, best_first=True, tries=2):
if not isinstance(hash_list, list):
raise ValueError("The `hash_list` input is a list, not %s."
% type(hash_list))
if not hash_list:
return []
if isinstance(hash_list[0], str):
hash_list = [int(h) for h in hash_list]
if not all([isinstance(h, int) for h in hash_list]):
raise ValueError("Hashes must be ints or strings that can be "
"converted into ints.")
resp = submit_statement_request('post', 'from_hashes', ev_limit=ev_limit,
data={'hashes': hash_list},
best_first=best_first, tries=tries)
return stmts_from_json(resp.json()['statements'].values()) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_statements_for_paper'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'ev_limit'},{'id': '7', 'type': 'integer', 'children': [], 'value': '10'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'best_first'},{'id': '10', 'type': 'True', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'tries'},{'id': '13', 'type': 'integer', 'children': [], 'value': '2'},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'max_stmts'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'block', 'children': ['18', '34', '60', '70']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'id_l'},{'id': '21', 'type': 'list_comprehension', 'children': ['22', '29']},{'id': '22', 'type': 'dictionary', 'children': ['23', '26']},{'id': '23', 'type': 'pair', 'children': ['24', '25']},{'id': '24', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'id_val'},{'id': '26', 'type': 'pair', 'children': ['27', '28']},{'id': '27', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'id_type'},{'id': '29', 'type': 'for_in_clause', 'children': ['30', '33']},{'id': '30', 'type': 'pattern_list', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'id_type'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'id_val'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'resp'},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'submit_statement_request'},{'id': '39', 'type': 'argument_list', 'children': ['40', '41', '42', '48', '51', '54', '57']},{'id': '40', 'type': 'string', 'children': [], 'value': "'post'"},{'id': '41', 'type': 'string', 'children': [], 'value': "'from_papers'"},{'id': '42', 'type': 'keyword_argument', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '44', 'type': 'dictionary', 'children': ['45']},{'id': '45', 'type': 'pair', 'children': ['46', '47']},{'id': '46', 'type': 'string', 'children': [], 'value': "'ids'"},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'id_l'},{'id': '48', 'type': 'keyword_argument', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'ev_limit'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'ev_limit'},{'id': '51', 'type': 'keyword_argument', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'best_first'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'best_first'},{'id': '54', 'type': 'keyword_argument', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'tries'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'tries'},{'id': '57', 'type': 'keyword_argument', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'max_stmts'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'max_stmts'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'stmts_json'},{'id': '63', 'type': 'subscript', 'children': ['64', '69']},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'resp'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '68', 'type': 'argument_list', 'children': []},{'id': '69', 'type': 'string', 'children': [], 'value': "'statements'"},{'id': '70', 'type': 'return_statement', 'children': ['71']},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'stmts_from_json'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'stmts_json'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '78', 'type': 'argument_list', 'children': []} | def get_statements_for_paper(ids, ev_limit=10, best_first=True, tries=2,
max_stmts=None):
id_l = [{'id': id_val, 'type': id_type} for id_type, id_val in ids]
resp = submit_statement_request('post', 'from_papers', data={'ids': id_l},
ev_limit=ev_limit, best_first=best_first,
tries=tries, max_stmts=max_stmts)
stmts_json = resp.json()['statements']
return stmts_from_json(stmts_json.values()) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_statement_queries'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '7', 'type': 'block', 'children': ['8', '61', '65', '72', '79', '211']},{'id': '8', 'type': 'function_definition', 'children': ['9', '10', '12']},{'id': '9', 'type': 'function_name', 'children': [], 'value': 'pick_ns'},{'id': '10', 'type': 'parameters', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'ag'},{'id': '12', 'type': 'block', 'children': ['13', '55']},{'id': '13', 'type': 'for_statement', 'children': ['14', '15', '22', '43']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '15', 'type': 'list', 'children': ['16', '17', '18', '19', '20', '21'], 'value': "['HGNC', 'FPLX', 'CHEMBL', 'CHEBI', 'GO', 'MESH']"},{'id': '16', 'type': 'string', 'children': [], 'value': "'HGNC'"},{'id': '17', 'type': 'string', 'children': [], 'value': "'FPLX'"},{'id': '18', 'type': 'string', 'children': [], 'value': "'CHEMBL'"},{'id': '19', 'type': 'string', 'children': [], 'value': "'CHEBI'"},{'id': '20', 'type': 'string', 'children': [], 'value': "'GO'"},{'id': '21', 'type': 'string', 'children': [], 'value': "'MESH'"},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'if_statement', 'children': ['24', '33']},{'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': 'in'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'ns'},{'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': 'ag'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'db_refs'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '32', 'type': 'argument_list', 'children': []},{'id': '33', 'type': 'block', 'children': ['34', '42']},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'dbid'},{'id': '37', 'type': 'subscript', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'ag'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'db_refs'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '42', 'type': 'break_statement', 'children': []},{'id': '43', 'type': 'else_clause', 'children': ['44']},{'id': '44', 'type': 'block', 'children': ['45', '49']},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '48', 'type': 'string', 'children': [], 'value': "'TEXT'"},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'dbid'},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'ag'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '55', 'type': 'return_statement', 'children': ['56']},{'id': '56', 'type': 'binary_operator', 'children': ['57', '58'], 'value': '%'},{'id': '57', 'type': 'string', 'children': [], 'value': "'%s@%s'"},{'id': '58', 'type': 'tuple', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'dbid'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'queries'},{'id': '64', 'type': 'list', 'children': [], 'value': '[]'},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'url_base'},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'get_url_base'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'string', 'children': [], 'value': "'statements/from_agents'"},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'non_binary_statements'},{'id': '75', 'type': 'list', 'children': ['76', '77', '78'], 'value': '[Complex, SelfModification, ActiveForm]'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'Complex'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'SelfModification'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'ActiveForm'},{'id': '79', 'type': 'for_statement', 'children': ['80', '81', '82']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '82', 'type': 'block', 'children': ['83', '87', '156', '166', '173', '202']},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '86', 'type': 'dictionary', 'children': []},{'id': '87', 'type': 'if_statement', 'children': ['88', '94', '125']},{'id': '88', 'type': 'comparison_operator', 'children': ['89', '93'], 'value': 'not'},{'id': '89', 'type': 'call', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'non_binary_statements'},{'id': '94', 'type': 'block', 'children': ['95']},{'id': '95', 'type': 'for_statement', 'children': ['96', '99', '110']},{'id': '96', 'type': 'pattern_list', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'pos'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'ag'},{'id': '99', 'type': 'call', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '101', 'type': 'argument_list', 'children': ['102', '105']},{'id': '102', 'type': 'list', 'children': ['103', '104'], 'value': "['subject', 'object']"},{'id': '103', 'type': 'string', 'children': [], 'value': "'subject'"},{'id': '104', 'type': 'string', 'children': [], 'value': "'object'"},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'agent_list'},{'id': '109', 'type': 'argument_list', 'children': []},{'id': '110', 'type': 'block', 'children': ['111']},{'id': '111', 'type': 'if_statement', 'children': ['112', '115']},{'id': '112', 'type': 'comparison_operator', 'children': ['113', '114'], 'value': 'is'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'ag'},{'id': '114', 'type': 'None', 'children': []},{'id': '115', 'type': 'block', 'children': ['116']},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '121']},{'id': '118', 'type': 'subscript', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'pos'},{'id': '121', 'type': 'call', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'pick_ns'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'ag'},{'id': '125', 'type': 'else_clause', 'children': ['126']},{'id': '126', 'type': 'block', 'children': ['127']},{'id': '127', 'type': 'for_statement', 'children': ['128', '131', '139']},{'id': '128', 'type': 'pattern_list', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'ag'},{'id': '131', 'type': 'call', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'call', 'children': ['135', '138']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'agent_list'},{'id': '138', 'type': 'argument_list', 'children': []},{'id': '139', 'type': 'block', 'children': ['140']},{'id': '140', 'type': 'if_statement', 'children': ['141', '144']},{'id': '141', 'type': 'comparison_operator', 'children': ['142', '143'], 'value': 'is'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'ag'},{'id': '143', 'type': 'None', 'children': []},{'id': '144', 'type': 'block', 'children': ['145']},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '152']},{'id': '147', 'type': 'subscript', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '149', 'type': 'binary_operator', 'children': ['150', '151'], 'value': '%'},{'id': '150', 'type': 'string', 'children': [], 'value': "'agent%d'"},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '152', 'type': 'call', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'pick_ns'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'ag'},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'assignment', 'children': ['158', '161']},{'id': '158', 'type': 'subscript', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '160', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '161', 'type': 'attribute', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '164', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '165', 'type': 'identifier', 'children': [], 'value': '__name__'},{'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': 'kwargs'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'assignment', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'query_str'},{'id': '176', 'type': 'binary_operator', 'children': ['177', '178'], 'value': '+'},{'id': '177', 'type': 'string', 'children': [], 'value': "'?'"},{'id': '178', 'type': 'call', 'children': ['179', '182']},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'string', 'children': [], 'value': "'&'"},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '182', 'type': 'argument_list', 'children': ['183']},{'id': '183', 'type': 'list_comprehension', 'children': ['184', '189', '198']},{'id': '184', 'type': 'binary_operator', 'children': ['185', '186'], 'value': '%'},{'id': '185', 'type': 'string', 'children': [], 'value': "'%s=%s'"},{'id': '186', 'type': 'tuple', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '189', 'type': 'for_in_clause', 'children': ['190', '193']},{'id': '190', 'type': 'pattern_list', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '193', 'type': 'call', 'children': ['194', '197']},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '197', 'type': 'argument_list', 'children': []},{'id': '198', 'type': 'if_clause', 'children': ['199']},{'id': '199', 'type': 'comparison_operator', 'children': ['200', '201'], 'value': 'is'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '201', 'type': 'None', 'children': []},{'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': 'queries'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '207', 'type': 'argument_list', 'children': ['208']},{'id': '208', 'type': 'binary_operator', 'children': ['209', '210'], 'value': '+'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'url_base'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'query_str'},{'id': '211', 'type': 'return_statement', 'children': ['212']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'queries'} | def get_statement_queries(stmts, **params):
def pick_ns(ag):
for ns in ['HGNC', 'FPLX', 'CHEMBL', 'CHEBI', 'GO', 'MESH']:
if ns in ag.db_refs.keys():
dbid = ag.db_refs[ns]
break
else:
ns = 'TEXT'
dbid = ag.name
return '%s@%s' % (dbid, ns)
queries = []
url_base = get_url_base('statements/from_agents')
non_binary_statements = [Complex, SelfModification, ActiveForm]
for stmt in stmts:
kwargs = {}
if type(stmt) not in non_binary_statements:
for pos, ag in zip(['subject', 'object'], stmt.agent_list()):
if ag is not None:
kwargs[pos] = pick_ns(ag)
else:
for i, ag in enumerate(stmt.agent_list()):
if ag is not None:
kwargs['agent%d' % i] = pick_ns(ag)
kwargs['type'] = stmt.__class__.__name__
kwargs.update(params)
query_str = '?' + '&'.join(['%s=%s' % (k, v) for k, v in kwargs.items()
if v is not None])
queries.append(url_base + query_str)
return queries |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'make_statement'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'mention'},{'id': '7', 'type': 'block', 'children': ['8', '23', '30', '34', '102', '108', '114', '122', '130', '158', '170', '182']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '13', '14']},{'id': '10', 'type': 'tuple_pattern', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'statement_generator'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'is_direct'},{'id': '13', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'geneways_action_to_indra_statement_type'},{'id': '16', 'type': 'argument_list', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'mention'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'actiontype'},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'plo'},{'id': '23', 'type': 'if_statement', 'children': ['24', '27']},{'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': 'is'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'statement_generator'},{'id': '26', 'type': 'None', 'children': []},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'return_statement', 'children': ['29']},{'id': '29', 'type': 'None', 'children': []},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '33', 'type': 'None', 'children': []},{'id': '34', 'type': 'if_statement', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'get_ft_mention'},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'try_statement', 'children': ['40', '88']},{'id': '40', 'type': 'block', 'children': ['41', '53']},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '46']},{'id': '43', 'type': 'pattern_list', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'content_type'},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'get_full_text'},{'id': '48', 'type': 'argument_list', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'mention'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'pmid'},{'id': '52', 'type': 'string', 'children': [], 'value': "'pmid'"},{'id': '53', 'type': 'if_statement', 'children': ['54', '57']},{'id': '54', 'type': 'comparison_operator', 'children': ['55', '56'], 'value': 'is'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '56', 'type': 'None', 'children': []},{'id': '57', 'type': 'block', 'children': ['58', '66', '74']},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'ftm'},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'FullTextMention'},{'id': '63', 'type': 'argument_list', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'mention'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'sentences'},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'ftm'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'find_matching_sentences'},{'id': '73', 'type': 'argument_list', 'children': []},{'id': '74', 'type': 'if_statement', 'children': ['75', '81']},{'id': '75', 'type': 'comparison_operator', 'children': ['76', '80'], 'value': '=='},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'sentences'},{'id': '80', 'type': 'integer', 'children': [], 'value': '1'},{'id': '81', 'type': 'block', 'children': ['82']},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '85', 'type': 'subscript', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'sentences'},{'id': '87', 'type': 'integer', 'children': [], 'value': '0'},{'id': '88', 'type': 'except_clause', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '90', 'type': 'block', 'children': ['91']},{'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': 'warning'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'binary_operator', 'children': ['98', '99'], 'value': '+'},{'id': '98', 'type': 'string', 'children': [], 'value': "'Could not fetch full text for PMID '"},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'mention'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'pmid'},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'epistemics'},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '107', 'type': 'argument_list', 'children': []},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '113']},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'epistemics'},{'id': '112', 'type': 'string', 'children': [], 'value': "'direct'"},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'is_direct'},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'annotations'},{'id': '117', 'type': 'call', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'mention'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'make_annotation'},{'id': '121', 'type': 'argument_list', 'children': []},{'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': 'annotations'},{'id': '126', 'type': 'string', 'children': [], 'value': "'plo'"},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'plo'},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'evidence'},{'id': '133', 'type': 'call', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'Evidence'},{'id': '135', 'type': 'argument_list', 'children': ['136', '139', '144', '149', '152', '155']},{'id': '136', 'type': 'keyword_argument', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'source_api'},{'id': '138', 'type': 'string', 'children': [], 'value': "'geneways'"},{'id': '139', 'type': 'keyword_argument', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'source_id'},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'mention'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'actionmentionid'},{'id': '144', 'type': 'keyword_argument', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'pmid'},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'mention'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'pmid'},{'id': '149', 'type': 'keyword_argument', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '152', 'type': 'keyword_argument', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'epistemics'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'epistemics'},{'id': '155', 'type': 'keyword_argument', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'annotations'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'annotations'},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'upstream_agent'},{'id': '161', 'type': 'call', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'get_agent'},{'id': '163', 'type': 'argument_list', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'mention'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'upstream'},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'up'},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'assignment', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'downstream_agent'},{'id': '173', 'type': 'call', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'get_agent'},{'id': '175', 'type': 'argument_list', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'mention'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'downstream'},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'dn'},{'id': '182', 'type': 'return_statement', 'children': ['183']},{'id': '183', 'type': 'call', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'statement_generator'},{'id': '185', 'type': 'argument_list', 'children': ['186', '187', '188']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'upstream_agent'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'downstream_agent'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'evidence'} | def make_statement(self, action, mention):
(statement_generator, is_direct) = \
geneways_action_to_indra_statement_type(mention.actiontype,
action.plo)
if statement_generator is None:
return None
text = None
if self.get_ft_mention:
try:
content, content_type = get_full_text(mention.pmid, 'pmid')
if content is not None:
ftm = FullTextMention(mention, content)
sentences = ftm.find_matching_sentences()
if len(sentences) == 1:
text = sentences[0]
except Exception:
logger.warning('Could not fetch full text for PMID ' +
mention.pmid)
epistemics = dict()
epistemics['direct'] = is_direct
annotations = mention.make_annotation()
annotations['plo'] = action.plo
evidence = Evidence(source_api='geneways',
source_id=mention.actionmentionid,
pmid=mention.pmid, text=text,
epistemics=epistemics,
annotations=annotations)
upstream_agent = get_agent(mention.upstream, action.up)
downstream_agent = get_agent(mention.downstream, action.dn)
return statement_generator(upstream_agent, downstream_agent, evidence) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'directly_or_indirectly_related'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'ns1'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'id1'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'ns2'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'id2'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'closure_dict'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'relation_func'},{'id': '11', 'type': 'block', 'children': ['12', '35']},{'id': '12', 'type': 'if_statement', 'children': ['13', '25', '28']},{'id': '13', 'type': 'boolean_operator', 'children': ['14', '17'], 'value': 'or'},{'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': 'is'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'id2'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': '()', 'children': ['18']},{'id': '18', 'type': 'boolean_operator', 'children': ['19', '22'], 'value': 'and'},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': 'is'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'id2'},{'id': '21', 'type': 'None', 'children': []},{'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': 'is'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'id1'},{'id': '24', 'type': 'None', 'children': []},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'return_statement', 'children': ['27']},{'id': '27', 'type': 'True', 'children': []},{'id': '28', 'type': 'elif_clause', 'children': ['29', '32']},{'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': 'is'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'id1'},{'id': '31', 'type': 'None', 'children': []},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'return_statement', 'children': ['34']},{'id': '34', 'type': 'False', 'children': []},{'id': '35', 'type': 'if_statement', 'children': ['36', '37', '82']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'closure_dict'},{'id': '37', 'type': 'block', 'children': ['38', '48', '58', '67']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'term1'},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'get_uri'},{'id': '45', 'type': 'argument_list', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'ns1'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'id1'},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'term2'},{'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_uri'},{'id': '55', 'type': 'argument_list', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'ns2'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'id2'},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'ec'},{'id': '61', 'type': 'call', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'closure_dict'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'term1'},{'id': '67', 'type': 'if_statement', 'children': ['68', '75', '78']},{'id': '68', 'type': 'boolean_operator', 'children': ['69', '72'], 'value': 'and'},{'id': '69', 'type': 'comparison_operator', 'children': ['70', '71'], 'value': 'is'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'ec'},{'id': '71', 'type': 'None', 'children': []},{'id': '72', 'type': 'comparison_operator', 'children': ['73', '74'], 'value': 'in'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'term2'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'ec'},{'id': '75', 'type': 'block', 'children': ['76']},{'id': '76', 'type': 'return_statement', 'children': ['77']},{'id': '77', 'type': 'True', 'children': []},{'id': '78', 'type': 'else_clause', 'children': ['79']},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'return_statement', 'children': ['81']},{'id': '81', 'type': 'False', 'children': []},{'id': '82', 'type': 'else_clause', 'children': ['83']},{'id': '83', 'type': 'block', 'children': ['84', '185', '197']},{'id': '84', 'type': 'if_statement', 'children': ['85', '89', '141']},{'id': '85', 'type': 'not_operator', 'children': ['86']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'uri_as_name'},{'id': '89', 'type': 'block', 'children': ['90', '99', '108', '119', '130']},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'e1'},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'find_entity'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'id1'},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'e2'},{'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': 'find_entity'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'id2'},{'id': '108', 'type': 'if_statement', 'children': ['109', '116']},{'id': '109', 'type': 'boolean_operator', 'children': ['110', '113'], 'value': 'or'},{'id': '110', 'type': 'comparison_operator', 'children': ['111', '112'], 'value': 'is'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'e1'},{'id': '112', 'type': 'None', 'children': []},{'id': '113', 'type': 'comparison_operator', 'children': ['114', '115'], 'value': 'is'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'e2'},{'id': '115', 'type': 'None', 'children': []},{'id': '116', 'type': 'block', 'children': ['117']},{'id': '117', 'type': 'return_statement', 'children': ['118']},{'id': '118', 'type': 'False', 'children': []},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 't1'},{'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': 'rdflib'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'URIRef'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'e1'},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 't2'},{'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': 'rdflib'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'URIRef'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'e2'},{'id': '141', 'type': 'else_clause', 'children': ['142']},{'id': '142', 'type': 'block', 'children': ['143', '153', '163', '174']},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'u1'},{'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': 'get_uri'},{'id': '150', 'type': 'argument_list', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'ns1'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'id1'},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'u2'},{'id': '156', 'type': 'call', 'children': ['157', '160']},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'get_uri'},{'id': '160', 'type': 'argument_list', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'ns2'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'id2'},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 't1'},{'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': 'rdflib'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'URIRef'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'u1'},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'assignment', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 't2'},{'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': 'rdflib'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'URIRef'},{'id': '183', 'type': 'argument_list', 'children': ['184']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'u2'},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'assignment', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'to'},{'id': '188', 'type': 'call', 'children': ['189', '194']},{'id': '189', 'type': 'attribute', 'children': ['190', '193']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'transitiveClosure'},{'id': '194', 'type': 'argument_list', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'relation_func'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 't1'},{'id': '197', 'type': 'if_statement', 'children': ['198', '201', '204']},{'id': '198', 'type': 'comparison_operator', 'children': ['199', '200'], 'value': 'in'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 't2'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'to'},{'id': '201', 'type': 'block', 'children': ['202']},{'id': '202', 'type': 'return_statement', 'children': ['203']},{'id': '203', 'type': 'True', 'children': []},{'id': '204', 'type': 'else_clause', 'children': ['205']},{'id': '205', 'type': 'block', 'children': ['206']},{'id': '206', 'type': 'return_statement', 'children': ['207']},{'id': '207', 'type': 'False', 'children': []} | def directly_or_indirectly_related(self, ns1, id1, ns2, id2, closure_dict,
relation_func):
if id2 is None or (id2 is None and id1 is None):
return True
elif id1 is None:
return False
if closure_dict:
term1 = self.get_uri(ns1, id1)
term2 = self.get_uri(ns2, id2)
ec = closure_dict.get(term1)
if ec is not None and term2 in ec:
return True
else:
return False
else:
if not self.uri_as_name:
e1 = self.find_entity(id1)
e2 = self.find_entity(id2)
if e1 is None or e2 is None:
return False
t1 = rdflib.term.URIRef(e1)
t2 = rdflib.term.URIRef(e2)
else:
u1 = self.get_uri(ns1, id1)
u2 = self.get_uri(ns2, id2)
t1 = rdflib.term.URIRef(u1)
t2 = rdflib.term.URIRef(u2)
to = self.graph.transitiveClosure(relation_func, t1)
if t2 in to:
return True
else:
return False |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'analyze_db_reading'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'job_prefix'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'reading_queue'},{'id': '7', 'type': 'string', 'children': [], 'value': "'run_db_reading_queue'"},{'id': '8', 'type': 'block', 'children': ['9', '17', '21', '25', '29', '66', '80', '98', '108', '118', '239']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'log_strs'},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'get_logs_from_db_reading'},{'id': '14', 'type': 'argument_list', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'job_prefix'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'reading_queue'},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'indra_log_strs'},{'id': '20', 'type': 'list', 'children': [], 'value': '[]'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'all_reach_logs'},{'id': '24', 'type': 'list', 'children': [], 'value': '[]'},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'log_stats'},{'id': '28', 'type': 'list', 'children': [], 'value': '[]'},{'id': '29', 'type': 'for_statement', 'children': ['30', '31', '32']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'log_str'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'log_strs'},{'id': '32', 'type': 'block', 'children': ['33', '42', '49', '56']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '38']},{'id': '35', 'type': 'pattern_list', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'log_str'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'reach_logs'},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'separate_reach_logs'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'log_str'},{'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': 'all_reach_logs'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'reach_logs'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'indra_log_strs'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'log_str'},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'call', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'log_stats'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'get_reading_stats'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'log_str'},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'failed_reach_logs'},{'id': '69', 'type': 'list_comprehension', 'children': ['70', '71', '76']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'reach_log_str'},{'id': '71', 'type': 'for_in_clause', 'children': ['72', '75']},{'id': '72', 'type': 'pattern_list', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'reach_log_str'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'all_reach_logs'},{'id': '76', 'type': 'if_clause', 'children': ['77']},{'id': '77', 'type': 'comparison_operator', 'children': ['78', '79'], 'value': '=='},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '79', 'type': 'string', 'children': [], 'value': "'FAILURE'"},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'failed_id_dicts'},{'id': '83', 'type': 'list_comprehension', 'children': ['84', '90', '93']},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'analyze_reach_log'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'keyword_argument', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'log_str'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'reach_log'},{'id': '90', 'type': 'for_in_clause', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'reach_log'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'failed_reach_logs'},{'id': '93', 'type': 'if_clause', 'children': ['94']},{'id': '94', 'type': 'call', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'reach_log'},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'tcids_unfinished'},{'id': '101', 'type': 'set_comprehension', 'children': ['102', '105']},{'id': '102', 'type': 'subscript', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'id_dict'},{'id': '104', 'type': 'string', 'children': [], 'value': "'not_done'"},{'id': '105', 'type': 'for_in_clause', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'id_dict'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'failed_id_dicts'},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'call', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'binary_operator', 'children': ['113', '114'], 'value': '%'},{'id': '113', 'type': 'string', 'children': [], 'value': '"Found %d unfinished tcids."'},{'id': '114', 'type': 'call', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'tcids_unfinished'},{'id': '118', 'type': 'if_statement', 'children': ['119', '120', '233']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'log_stats'},{'id': '120', 'type': 'block', 'children': ['121', '136']},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'sum_dict'},{'id': '124', 'type': 'call', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'fromkeys'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'call', 'children': ['130', '135']},{'id': '130', 'type': 'attribute', 'children': ['131', '134']},{'id': '131', 'type': 'subscript', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'log_stats'},{'id': '133', 'type': 'integer', 'children': [], 'value': '0'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '135', 'type': 'argument_list', 'children': []},{'id': '136', 'type': 'for_statement', 'children': ['137', '138', '139']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'log_stat'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'log_stats'},{'id': '139', 'type': 'block', 'children': ['140']},{'id': '140', 'type': 'for_statement', 'children': ['141', '142', '147']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '142', 'type': 'call', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'log_stat'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '146', 'type': 'argument_list', 'children': []},{'id': '147', 'type': 'block', 'children': ['148']},{'id': '148', 'type': 'if_statement', 'children': ['149', '156', '208']},{'id': '149', 'type': 'call', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '151', 'type': 'argument_list', 'children': ['152', '155']},{'id': '152', 'type': 'subscript', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'log_stat'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '156', 'type': 'block', 'children': ['157', '180']},{'id': '157', 'type': 'if_statement', 'children': ['158', '165']},{'id': '158', 'type': 'comparison_operator', 'children': ['159', '160'], 'value': 'not'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '160', 'type': 'call', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'sum_dict'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '164', 'type': 'argument_list', 'children': []},{'id': '165', 'type': 'block', 'children': ['166']},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '171']},{'id': '168', 'type': 'subscript', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'sum_dict'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '171', 'type': 'binary_operator', 'children': ['172', '174'], 'value': '*'},{'id': '172', 'type': 'list', 'children': ['173'], 'value': '[0]'},{'id': '173', 'type': 'integer', 'children': [], 'value': '0'},{'id': '174', 'type': 'call', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'subscript', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'log_stat'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'assignment', 'children': ['182', '185']},{'id': '182', 'type': 'subscript', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'sum_dict'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '185', 'type': 'list_comprehension', 'children': ['186', '197']},{'id': '186', 'type': 'binary_operator', 'children': ['187', '192'], 'value': '+'},{'id': '187', 'type': 'subscript', 'children': ['188', '191']},{'id': '188', 'type': 'subscript', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'sum_dict'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '192', 'type': 'subscript', 'children': ['193', '196']},{'id': '193', 'type': 'subscript', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'log_stat'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '197', 'type': 'for_in_clause', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '199', 'type': 'call', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '201', 'type': 'argument_list', 'children': ['202']},{'id': '202', 'type': 'call', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '204', 'type': 'argument_list', 'children': ['205']},{'id': '205', 'type': 'subscript', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'log_stat'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '208', 'type': 'else_clause', 'children': ['209']},{'id': '209', 'type': 'block', 'children': ['210', '225']},{'id': '210', 'type': 'if_statement', 'children': ['211', '218']},{'id': '211', 'type': 'comparison_operator', 'children': ['212', '213'], 'value': 'not'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '213', 'type': 'call', 'children': ['214', '217']},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'sum_dict'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '217', 'type': 'argument_list', 'children': []},{'id': '218', 'type': 'block', 'children': ['219']},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'assignment', 'children': ['221', '224']},{'id': '221', 'type': 'subscript', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'sum_dict'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '224', 'type': 'integer', 'children': [], 'value': '0'},{'id': '225', 'type': 'expression_statement', 'children': ['226']},{'id': '226', 'type': 'augmented_assignment', 'children': ['227', '230'], 'value': '+='},{'id': '227', 'type': 'subscript', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'sum_dict'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '230', 'type': 'subscript', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'log_stat'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '233', 'type': 'else_clause', 'children': ['234']},{'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': 'sum_dict'},{'id': '238', 'type': 'dictionary', 'children': []},{'id': '239', 'type': 'return_statement', 'children': ['240']},{'id': '240', 'type': 'expression_list', 'children': ['241', '242', '243']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'tcids_unfinished'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'sum_dict'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'log_stats'} | def analyze_db_reading(job_prefix, reading_queue='run_db_reading_queue'):
log_strs = get_logs_from_db_reading(job_prefix, reading_queue)
indra_log_strs = []
all_reach_logs = []
log_stats = []
for log_str in log_strs:
log_str, reach_logs = separate_reach_logs(log_str)
all_reach_logs.extend(reach_logs)
indra_log_strs.append(log_str)
log_stats.append(get_reading_stats(log_str))
failed_reach_logs = [reach_log_str
for result, reach_log_str in all_reach_logs
if result == 'FAILURE']
failed_id_dicts = [analyze_reach_log(log_str=reach_log)
for reach_log in failed_reach_logs if bool(reach_log)]
tcids_unfinished = {id_dict['not_done'] for id_dict in failed_id_dicts}
print("Found %d unfinished tcids." % len(tcids_unfinished))
if log_stats:
sum_dict = dict.fromkeys(log_stats[0].keys())
for log_stat in log_stats:
for k in log_stat.keys():
if isinstance(log_stat[k], list):
if k not in sum_dict.keys():
sum_dict[k] = [0]*len(log_stat[k])
sum_dict[k] = [sum_dict[k][i] + log_stat[k][i]
for i in range(len(log_stat[k]))]
else:
if k not in sum_dict.keys():
sum_dict[k] = 0
sum_dict[k] += log_stat[k]
else:
sum_dict = {}
return tcids_unfinished, sum_dict, log_stats |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_create_base_agent'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '6', 'type': 'block', 'children': ['7', '50', '216', '236']},{'id': '7', 'type': 'try_statement', 'children': ['8', '22']},{'id': '8', 'type': 'block', 'children': ['9']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'base_agent'},{'id': '12', 'type': 'subscript', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'agents'},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': '_n'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '22', 'type': 'except_clause', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '24', 'type': 'block', 'children': ['25', '37']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'base_agent'},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'BaseAgent'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': '_n'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '49']},{'id': '39', 'type': 'subscript', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'agents'},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': '_n'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'base_agent'},{'id': '50', 'type': 'if_statement', 'children': ['51', '56']},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '53', 'type': 'argument_list', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'Agent'},{'id': '56', 'type': 'block', 'children': ['57', '96', '109', '170', '191']},{'id': '57', 'type': 'for_statement', 'children': ['58', '59', '62']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'bc'},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'bound_conditions'},{'id': '62', 'type': 'block', 'children': ['63', '74', '84']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'bound_base_agent'},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'get_create_base_agent'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'bc'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'agent'},{'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': 'bound_base_agent'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'create_site'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'get_binding_site_name'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'base_agent'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'create_site'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'get_binding_site_name'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'bc'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '96', 'type': 'for_statement', 'children': ['97', '98', '101']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'mc'},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'mods'},{'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': 'base_agent'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'create_mod_site'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'mc'},{'id': '109', 'type': 'for_statement', 'children': ['110', '111', '114']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'mc'},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'mutations'},{'id': '114', 'type': 'block', 'children': ['115', '126', '137', '158']},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'res_from'},{'id': '118', 'type': 'conditional_expression', 'children': ['119', '122', '125'], 'value': 'if'},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'mc'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'residue_from'},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'mc'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'residue_from'},{'id': '125', 'type': 'string', 'children': [], 'value': "'mut'"},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'res_to'},{'id': '129', 'type': 'conditional_expression', 'children': ['130', '133', '136'], 'value': 'if'},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'mc'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'residue_to'},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'mc'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'residue_to'},{'id': '136', 'type': 'string', 'children': [], 'value': "'X'"},{'id': '137', 'type': 'if_statement', 'children': ['138', '143', '148']},{'id': '138', 'type': 'comparison_operator', 'children': ['139', '142'], 'value': 'is'},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'mc'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '142', 'type': 'None', 'children': []},{'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': 'mut_site_name'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'res_from'},{'id': '148', 'type': 'else_clause', 'children': ['149']},{'id': '149', 'type': 'block', 'children': ['150']},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'mut_site_name'},{'id': '153', 'type': 'binary_operator', 'children': ['154', '155'], 'value': '+'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'res_from'},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'mc'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'position'},{'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': 'base_agent'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'create_site'},{'id': '163', 'type': 'argument_list', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'mut_site_name'},{'id': '165', 'type': 'keyword_argument', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'states'},{'id': '167', 'type': 'list', 'children': ['168', '169'], 'value': "['WT', res_to]"},{'id': '168', 'type': 'string', 'children': [], 'value': "'WT'"},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'res_to'},{'id': '170', 'type': 'if_statement', 'children': ['171', '176']},{'id': '171', 'type': 'comparison_operator', 'children': ['172', '175'], 'value': 'is'},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '175', 'type': 'None', 'children': []},{'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': 'base_agent'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'create_site'},{'id': '182', 'type': 'argument_list', 'children': ['183', '184']},{'id': '183', 'type': 'string', 'children': [], 'value': "'loc'"},{'id': '184', 'type': 'list', 'children': ['185'], 'value': '[_n(agent.location)]'},{'id': '185', 'type': 'call', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': '_n'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '191', 'type': 'if_statement', 'children': ['192', '197']},{'id': '192', 'type': 'comparison_operator', 'children': ['193', '196'], 'value': 'is'},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'activity'},{'id': '196', 'type': 'None', 'children': []},{'id': '197', 'type': 'block', 'children': ['198', '206']},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'site_name'},{'id': '201', 'type': 'attribute', 'children': ['202', '205']},{'id': '202', 'type': 'attribute', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'activity'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'activity_type'},{'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': 'base_agent'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'create_site'},{'id': '211', 'type': 'argument_list', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'site_name'},{'id': '213', 'type': 'list', 'children': ['214', '215'], 'value': "['inactive', 'active']"},{'id': '214', 'type': 'string', 'children': [], 'value': "'inactive'"},{'id': '215', 'type': 'string', 'children': [], 'value': "'active'"},{'id': '216', 'type': 'for_statement', 'children': ['217', '220', '227']},{'id': '217', 'type': 'pattern_list', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'db_name'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'db_ref'},{'id': '220', 'type': 'call', 'children': ['221', '226']},{'id': '221', 'type': 'attribute', 'children': ['222', '225']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'db_refs'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '226', 'type': 'argument_list', 'children': []},{'id': '227', 'type': 'block', 'children': ['228']},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'assignment', 'children': ['230', '235']},{'id': '230', 'type': 'subscript', 'children': ['231', '234']},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'base_agent'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'db_refs'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'db_name'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'db_ref'},{'id': '236', 'type': 'return_statement', 'children': ['237']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'base_agent'} | def get_create_base_agent(self, agent):
try:
base_agent = self.agents[_n(agent.name)]
except KeyError:
base_agent = BaseAgent(_n(agent.name))
self.agents[_n(agent.name)] = base_agent
if isinstance(agent, Agent):
for bc in agent.bound_conditions:
bound_base_agent = self.get_create_base_agent(bc.agent)
bound_base_agent.create_site(get_binding_site_name(agent))
base_agent.create_site(get_binding_site_name(bc.agent))
for mc in agent.mods:
base_agent.create_mod_site(mc)
for mc in agent.mutations:
res_from = mc.residue_from if mc.residue_from else 'mut'
res_to = mc.residue_to if mc.residue_to else 'X'
if mc.position is None:
mut_site_name = res_from
else:
mut_site_name = res_from + mc.position
base_agent.create_site(mut_site_name, states=['WT', res_to])
if agent.location is not None:
base_agent.create_site('loc', [_n(agent.location)])
if agent.activity is not None:
site_name = agent.activity.activity_type
base_agent.create_site(site_name, ['inactive', 'active'])
for db_name, db_ref in agent.db_refs.items():
base_agent.db_refs[db_name] = db_ref
return base_agent |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'classify_nodes'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'hub'},{'id': '6', 'type': 'block', 'children': ['7', '18', '140', '144', '227']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'node_stats'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'lambda', 'children': ['14']},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '18', 'type': 'for_statement', 'children': ['19', '23', '31']},{'id': '19', 'type': 'pattern_list', 'children': ['20', '21', '22']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'keyword_argument', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '30', 'type': 'True', 'children': []},{'id': '31', 'type': 'block', 'children': ['32', '124']},{'id': '32', 'type': 'if_statement', 'children': ['33', '36', '77', '121']},{'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': '=='},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'hub'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '36', 'type': 'block', 'children': ['37', '45']},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '42']},{'id': '39', 'type': 'pattern_list', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '42', 'type': 'expression_list', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '45', 'type': 'if_statement', 'children': ['46', '51', '64']},{'id': '46', 'type': 'comparison_operator', 'children': ['47', '50'], 'value': '!='},{'id': '47', 'type': 'subscript', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '49', 'type': 'string', 'children': [], 'value': "'i'"},{'id': '50', 'type': 'string', 'children': [], 'value': "'Complex'"},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '61']},{'id': '54', 'type': 'attribute', 'children': ['55', '60']},{'id': '55', 'type': 'subscript', 'children': ['56', '59']},{'id': '56', 'type': 'subscript', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'node_stats'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '59', 'type': 'string', 'children': [], 'value': "'up'"},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'unary_operator', 'children': ['63'], 'value': '-'},{'id': '63', 'type': 'integer', 'children': [], 'value': '1'},{'id': '64', 'type': 'else_clause', 'children': ['65']},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'call', 'children': ['68', '75']},{'id': '68', 'type': 'attribute', 'children': ['69', '74']},{'id': '69', 'type': 'subscript', 'children': ['70', '73']},{'id': '70', 'type': 'subscript', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'node_stats'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '73', 'type': 'string', 'children': [], 'value': "'up'"},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'integer', 'children': [], 'value': '0'},{'id': '77', 'type': 'elif_clause', 'children': ['78', '81']},{'id': '78', 'type': 'comparison_operator', 'children': ['79', '80'], 'value': '=='},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'hub'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '81', 'type': 'block', 'children': ['82', '90']},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '87']},{'id': '84', 'type': 'pattern_list', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '87', 'type': 'expression_list', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '90', 'type': 'if_statement', 'children': ['91', '96', '108']},{'id': '91', 'type': 'comparison_operator', 'children': ['92', '95'], 'value': '!='},{'id': '92', 'type': 'subscript', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '94', 'type': 'string', 'children': [], 'value': "'i'"},{'id': '95', 'type': 'string', 'children': [], 'value': "'Complex'"},{'id': '96', 'type': 'block', 'children': ['97']},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'call', 'children': ['99', '106']},{'id': '99', 'type': 'attribute', 'children': ['100', '105']},{'id': '100', 'type': 'subscript', 'children': ['101', '104']},{'id': '101', 'type': 'subscript', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'node_stats'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '104', 'type': 'string', 'children': [], 'value': "'up'"},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'integer', 'children': [], 'value': '1'},{'id': '108', 'type': 'else_clause', 'children': ['109']},{'id': '109', 'type': 'block', 'children': ['110']},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'call', 'children': ['112', '119']},{'id': '112', 'type': 'attribute', 'children': ['113', '118']},{'id': '113', 'type': 'subscript', 'children': ['114', '117']},{'id': '114', 'type': 'subscript', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'node_stats'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '117', 'type': 'string', 'children': [], 'value': "'up'"},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'integer', 'children': [], 'value': '0'},{'id': '121', 'type': 'else_clause', 'children': ['122']},{'id': '122', 'type': 'block', 'children': ['123']},{'id': '123', 'type': 'continue_statement', 'children': []},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'call', 'children': ['126', '133']},{'id': '126', 'type': 'attribute', 'children': ['127', '132']},{'id': '127', 'type': 'subscript', 'children': ['128', '131']},{'id': '128', 'type': 'subscript', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'node_stats'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '131', 'type': 'string', 'children': [], 'value': "'interaction'"},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'call', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'edge_type_to_class'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'subscript', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '139', 'type': 'string', 'children': [], 'value': "'i'"},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'assignment', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'node_classes'},{'id': '143', 'type': 'dictionary', 'children': []},{'id': '144', 'type': 'for_statement', 'children': ['145', '148', '153']},{'id': '145', 'type': 'pattern_list', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'stats'},{'id': '148', 'type': 'call', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'node_stats'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '152', 'type': 'argument_list', 'children': []},{'id': '153', 'type': 'block', 'children': ['154', '173', '193', '208', '218']},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'assignment', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'up'},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '159', 'type': 'argument_list', 'children': ['160', '166']},{'id': '160', 'type': 'call', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'subscript', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'stats'},{'id': '165', 'type': 'string', 'children': [], 'value': "'up'"},{'id': '166', 'type': 'keyword_argument', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '168', 'type': 'attribute', 'children': ['169', '172']},{'id': '169', 'type': 'subscript', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'stats'},{'id': '171', 'type': 'string', 'children': [], 'value': "'up'"},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'assignment', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'interactions'},{'id': '176', 'type': 'list_comprehension', 'children': ['177', '178', '183']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '178', 'type': 'for_in_clause', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '180', 'type': 'subscript', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'stats'},{'id': '182', 'type': 'string', 'children': [], 'value': "'interaction'"},{'id': '183', 'type': 'if_clause', 'children': ['184']},{'id': '184', 'type': 'not_operator', 'children': ['185']},{'id': '185', 'type': '()', 'children': ['186']},{'id': '186', 'type': 'boolean_operator', 'children': ['187', '190'], 'value': 'and'},{'id': '187', 'type': 'comparison_operator', 'children': ['188', '189'], 'value': '!='},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'up'},{'id': '189', 'type': 'integer', 'children': [], 'value': '0'},{'id': '190', 'type': 'comparison_operator', 'children': ['191', '192'], 'value': '=='},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '192', 'type': 'string', 'children': [], 'value': "'complex'"},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'assignment', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'edge_type'},{'id': '196', 'type': 'call', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '198', 'type': 'argument_list', 'children': ['199', '203']},{'id': '199', 'type': 'call', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '201', 'type': 'argument_list', 'children': ['202']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'interactions'},{'id': '203', 'type': 'keyword_argument', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'interactions'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '208', 'type': 'expression_statement', 'children': ['209']},{'id': '209', 'type': 'assignment', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'node_type'},{'id': '211', 'type': 'subscript', 'children': ['212', '217']},{'id': '212', 'type': 'subscript', 'children': ['213', '216']},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '217', 'type': 'string', 'children': [], 'value': "'type'"},{'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': 'node_classes'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '223', 'type': 'tuple', 'children': ['224', '225', '226']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'up'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'edge_type'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'node_type'},{'id': '227', 'type': 'return_statement', 'children': ['228']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'node_classes'} | def classify_nodes(graph, hub):
node_stats = defaultdict(lambda: defaultdict(list))
for u, v, data in graph.edges(data=True):
if hub == u:
h, o = u, v
if data['i'] != 'Complex':
node_stats[o]['up'].append(-1)
else:
node_stats[o]['up'].append(0)
elif hub == v:
h, o = v, u
if data['i'] != 'Complex':
node_stats[o]['up'].append(1)
else:
node_stats[o]['up'].append(0)
else:
continue
node_stats[o]['interaction'].append(edge_type_to_class(data['i']))
node_classes = {}
for node_id, stats in node_stats.items():
up = max(set(stats['up']), key=stats['up'].count)
interactions = [i for i in stats['interaction'] if
not (up != 0 and i == 'complex')]
edge_type = max(set(interactions), key=interactions.count)
node_type = graph.nodes[node_id]['type']
node_classes[node_id] = (up, edge_type, node_type)
return node_classes |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'doi_query'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'pmid'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'search_limit'},{'id': '7', 'type': 'integer', 'children': [], 'value': '10'},{'id': '8', 'type': 'block', 'children': ['9', '22', '47', '53', '68', '77', '93', '102', '117', '126', '141', '145', '155', '213', '235', '243', '247', '436']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'pubmed_meta_dict'},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'pubmed_client'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'get_metadata_for_ids'},{'id': '16', 'type': 'argument_list', 'children': ['17', '19']},{'id': '17', 'type': 'list', 'children': ['18'], 'value': '[pmid]'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'pmid'},{'id': '19', 'type': 'keyword_argument', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'get_issns_from_nlm'},{'id': '21', 'type': 'True', 'children': []},{'id': '22', 'type': 'if_statement', 'children': ['23', '35']},{'id': '23', 'type': 'boolean_operator', 'children': ['24', '27'], 'value': 'or'},{'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': 'is'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'pubmed_meta_dict'},{'id': '26', 'type': 'None', 'children': []},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '34'], 'value': 'is'},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'pubmed_meta_dict'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'pmid'},{'id': '34', 'type': 'None', 'children': []},{'id': '35', 'type': 'block', 'children': ['36', '45']},{'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': 'warning'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'binary_operator', 'children': ['43', '44'], 'value': '%'},{'id': '43', 'type': 'string', 'children': [], 'value': "'No metadata found in Pubmed for PMID%s'"},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'pmid'},{'id': '45', 'type': 'return_statement', 'children': ['46']},{'id': '46', 'type': 'None', 'children': []},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'pubmed_meta'},{'id': '50', 'type': 'subscript', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'pubmed_meta_dict'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'pmid'},{'id': '53', 'type': 'if_statement', 'children': ['54', '60']},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'pubmed_meta'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'string', 'children': [], 'value': "'doi'"},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'return_statement', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'pubmed_meta'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'string', 'children': [], 'value': "'doi'"},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'pm_article_title'},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'pubmed_meta'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'string', 'children': [], 'value': "'title'"},{'id': '77', 'type': 'if_statement', 'children': ['78', '81']},{'id': '78', 'type': 'comparison_operator', 'children': ['79', '80'], 'value': 'is'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'pm_article_title'},{'id': '80', 'type': 'None', 'children': []},{'id': '81', 'type': 'block', 'children': ['82', '91']},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'binary_operator', 'children': ['89', '90'], 'value': '%'},{'id': '89', 'type': 'string', 'children': [], 'value': "'No article title found in Pubmed for PMID%s'"},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'pmid'},{'id': '91', 'type': 'return_statement', 'children': ['92']},{'id': '92', 'type': 'None', 'children': []},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'pm_issn_list'},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'pubmed_meta'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'string', 'children': [], 'value': "'issn_list'"},{'id': '102', 'type': 'if_statement', 'children': ['103', '105']},{'id': '103', 'type': 'not_operator', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'pm_issn_list'},{'id': '105', 'type': 'block', 'children': ['106', '115']},{'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': 'warning'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'binary_operator', 'children': ['113', '114'], 'value': '%'},{'id': '113', 'type': 'string', 'children': [], 'value': "'No ISSNs found in Pubmed for PMID%s'"},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'pmid'},{'id': '115', 'type': 'return_statement', 'children': ['116']},{'id': '116', 'type': 'None', 'children': []},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'pm_page'},{'id': '120', 'type': 'call', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'pubmed_meta'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'string', 'children': [], 'value': "'page'"},{'id': '126', 'type': 'if_statement', 'children': ['127', '129']},{'id': '127', 'type': 'not_operator', 'children': ['128']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'pm_page'},{'id': '129', 'type': 'block', 'children': ['130', '139']},{'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': 'binary_operator', 'children': ['137', '138'], 'value': '%'},{'id': '137', 'type': 'string', 'children': [], 'value': "'No page number found in Pubmed for PMID%s'"},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'pmid'},{'id': '139', 'type': 'return_statement', 'children': ['140']},{'id': '140', 'type': 'None', 'children': []},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'crossref_search_url'},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '148', 'type': 'dictionary', 'children': ['149', '152']},{'id': '149', 'type': 'pair', 'children': ['150', '151']},{'id': '150', 'type': 'string', 'children': [], 'value': "'q'"},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'pm_article_title'},{'id': '152', 'type': 'pair', 'children': ['153', '154']},{'id': '153', 'type': 'string', 'children': [], 'value': "'sort'"},{'id': '154', 'type': 'string', 'children': [], 'value': "'score'"},{'id': '155', 'type': 'try_statement', 'children': ['156', '167', '193']},{'id': '156', 'type': 'block', 'children': ['157']},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '160', 'type': 'call', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '164', 'type': 'argument_list', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'crossref_search_url'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '167', 'type': 'except_clause', 'children': ['168', '176']},{'id': '168', 'type': 'as_pattern', 'children': ['169', '174']},{'id': '169', 'type': 'attribute', 'children': ['170', '173']},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'exceptions'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'ConnectionError'},{'id': '174', 'type': 'as_pattern_target', 'children': ['175']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '176', 'type': 'block', 'children': ['177', '184', '191']},{'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': 'logger'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '182', 'type': 'argument_list', 'children': ['183']},{'id': '183', 'type': 'string', 'children': [], 'value': "'CrossRef service could not be reached.'"},{'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': 'logger'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '191', 'type': 'return_statement', 'children': ['192']},{'id': '192', 'type': 'None', 'children': []},{'id': '193', 'type': 'except_clause', 'children': ['194', '198']},{'id': '194', 'type': 'as_pattern', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '196', 'type': 'as_pattern_target', 'children': ['197']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '198', 'type': 'block', 'children': ['199', '211']},{'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': 'logger'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '204', 'type': 'argument_list', 'children': ['205']},{'id': '205', 'type': 'binary_operator', 'children': ['206', '207'], 'value': '%'},{'id': '206', 'type': 'string', 'children': [], 'value': "'Error accessing CrossRef service: %s'"},{'id': '207', 'type': 'call', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '209', 'type': 'argument_list', 'children': ['210']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '211', 'type': 'return_statement', 'children': ['212']},{'id': '212', 'type': 'None', 'children': []},{'id': '213', 'type': 'if_statement', 'children': ['214', '219']},{'id': '214', 'type': 'comparison_operator', 'children': ['215', '218'], 'value': '!='},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '218', 'type': 'integer', 'children': [], 'value': '200'},{'id': '219', 'type': 'block', 'children': ['220', '233']},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'call', 'children': ['222', '225']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '225', 'type': 'argument_list', 'children': ['226']},{'id': '226', 'type': 'binary_operator', 'children': ['227', '228'], 'value': '%'},{'id': '227', 'type': 'string', 'children': [], 'value': "'PMID%s: no search results from CrossRef, code %d'"},{'id': '228', 'type': 'tuple', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'pmid'},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '233', 'type': 'return_statement', 'children': ['234']},{'id': '234', 'type': 'None', 'children': []},{'id': '235', 'type': 'expression_statement', 'children': ['236']},{'id': '236', 'type': 'assignment', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'raw_message'},{'id': '238', 'type': 'call', 'children': ['239', '242']},{'id': '239', 'type': 'attribute', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '242', 'type': 'argument_list', 'children': []},{'id': '243', 'type': 'expression_statement', 'children': ['244']},{'id': '244', 'type': 'assignment', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'mapped_doi'},{'id': '246', 'type': 'None', 'children': []},{'id': '247', 'type': 'for_statement', 'children': ['248', '251', '255']},{'id': '248', 'type': 'pattern_list', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'result_ix'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '251', 'type': 'call', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '253', 'type': 'argument_list', 'children': ['254']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'raw_message'},{'id': '255', 'type': 'block', 'children': ['256', '275', '281', '291', '301', '308', '314', '323', '332', '346', '360', '375', '390', '405', '424']},{'id': '256', 'type': 'if_statement', 'children': ['257', '260']},{'id': '257', 'type': 'comparison_operator', 'children': ['258', '259'], 'value': '>'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'result_ix'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'search_limit'},{'id': '260', 'type': 'block', 'children': ['261', '274']},{'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': 'logger'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '266', 'type': 'argument_list', 'children': ['267']},{'id': '267', 'type': 'binary_operator', 'children': ['268', '271'], 'value': '%'},{'id': '268', 'type': 'concatenated_string', 'children': ['269', '270']},{'id': '269', 'type': 'string', 'children': [], 'value': "'PMID%s: No match found within first %s results, '"},{'id': '270', 'type': 'string', 'children': [], 'value': "'giving up!'"},{'id': '271', 'type': 'tuple', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'pmid'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'search_limit'},{'id': '274', 'type': 'break_statement', 'children': []},{'id': '275', 'type': 'expression_statement', 'children': ['276']},{'id': '276', 'type': 'assignment', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'xref_doi_url'},{'id': '278', 'type': 'subscript', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '280', 'type': 'string', 'children': [], 'value': "'doi'"},{'id': '281', 'type': 'expression_statement', 'children': ['282']},{'id': '282', 'type': 'assignment', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '284', 'type': 'call', 'children': ['285', '288']},{'id': '285', 'type': 'attribute', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '288', 'type': 'argument_list', 'children': ['289', '290']},{'id': '289', 'type': 'string', 'children': [], 'value': "'^http://dx.doi.org/(.*)$'"},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'xref_doi_url'},{'id': '291', 'type': 'expression_statement', 'children': ['292']},{'id': '292', 'type': 'assignment', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'xref_doi'},{'id': '294', 'type': 'subscript', 'children': ['295', '300']},{'id': '295', 'type': 'call', 'children': ['296', '299']},{'id': '296', 'type': 'attribute', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '299', 'type': 'argument_list', 'children': []},{'id': '300', 'type': 'integer', 'children': [], 'value': '0'},{'id': '301', 'type': 'expression_statement', 'children': ['302']},{'id': '302', 'type': 'assignment', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'xref_meta'},{'id': '304', 'type': 'call', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'get_metadata'},{'id': '306', 'type': 'argument_list', 'children': ['307']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'xref_doi'},{'id': '308', 'type': 'if_statement', 'children': ['309', '312']},{'id': '309', 'type': 'comparison_operator', 'children': ['310', '311'], 'value': 'is'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'xref_meta'},{'id': '311', 'type': 'None', 'children': []},{'id': '312', 'type': 'block', 'children': ['313']},{'id': '313', 'type': 'continue_statement', 'children': []},{'id': '314', 'type': 'expression_statement', 'children': ['315']},{'id': '315', 'type': 'assignment', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'xref_issn_list'},{'id': '317', 'type': 'call', 'children': ['318', '321']},{'id': '318', 'type': 'attribute', 'children': ['319', '320']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'xref_meta'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '321', 'type': 'argument_list', 'children': ['322']},{'id': '322', 'type': 'string', 'children': [], 'value': "'ISSN'"},{'id': '323', 'type': 'expression_statement', 'children': ['324']},{'id': '324', 'type': 'assignment', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'xref_page'},{'id': '326', 'type': 'call', 'children': ['327', '330']},{'id': '327', 'type': 'attribute', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'xref_meta'},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '330', 'type': 'argument_list', 'children': ['331']},{'id': '331', 'type': 'string', 'children': [], 'value': "'page'"},{'id': '332', 'type': 'if_statement', 'children': ['333', '335']},{'id': '333', 'type': 'not_operator', 'children': ['334']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'xref_issn_list'},{'id': '335', 'type': 'block', 'children': ['336', '345']},{'id': '336', 'type': 'expression_statement', 'children': ['337']},{'id': '337', 'type': 'call', 'children': ['338', '341']},{'id': '338', 'type': 'attribute', 'children': ['339', '340']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '341', 'type': 'argument_list', 'children': ['342']},{'id': '342', 'type': 'binary_operator', 'children': ['343', '344'], 'value': '%'},{'id': '343', 'type': 'string', 'children': [], 'value': "'No ISSN found for DOI %s, skipping'"},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'xref_doi_url'},{'id': '345', 'type': 'continue_statement', 'children': []},{'id': '346', 'type': 'if_statement', 'children': ['347', '349']},{'id': '347', 'type': 'not_operator', 'children': ['348']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'xref_page'},{'id': '349', 'type': 'block', 'children': ['350', '359']},{'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': 'logger'},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '355', 'type': 'argument_list', 'children': ['356']},{'id': '356', 'type': 'binary_operator', 'children': ['357', '358'], 'value': '%'},{'id': '357', 'type': 'string', 'children': [], 'value': "'No page number found for DOI %s, skipping'"},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'xref_doi_url'},{'id': '359', 'type': 'continue_statement', 'children': []},{'id': '360', 'type': 'expression_statement', 'children': ['361']},{'id': '361', 'type': 'assignment', 'children': ['362', '363']},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'matching_issns'},{'id': '363', 'type': 'call', 'children': ['364', '370']},{'id': '364', 'type': 'attribute', 'children': ['365', '369']},{'id': '365', 'type': 'call', 'children': ['366', '367']},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '367', 'type': 'argument_list', 'children': ['368']},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'pm_issn_list'},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'intersection'},{'id': '370', 'type': 'argument_list', 'children': ['371']},{'id': '371', 'type': 'call', 'children': ['372', '373']},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '373', 'type': 'argument_list', 'children': ['374']},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'xref_issn_list'},{'id': '375', 'type': 'expression_statement', 'children': ['376']},{'id': '376', 'type': 'assignment', 'children': ['377', '378']},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'pm_start_page'},{'id': '378', 'type': 'call', 'children': ['379', '389']},{'id': '379', 'type': 'attribute', 'children': ['380', '388']},{'id': '380', 'type': 'subscript', 'children': ['381', '387']},{'id': '381', 'type': 'call', 'children': ['382', '385']},{'id': '382', 'type': 'attribute', 'children': ['383', '384']},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'pm_page'},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '385', 'type': 'argument_list', 'children': ['386']},{'id': '386', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '387', 'type': 'integer', 'children': [], 'value': '0'},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '389', 'type': 'argument_list', 'children': []},{'id': '390', 'type': 'expression_statement', 'children': ['391']},{'id': '391', 'type': 'assignment', 'children': ['392', '393']},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'xr_start_page'},{'id': '393', 'type': 'call', 'children': ['394', '404']},{'id': '394', 'type': 'attribute', 'children': ['395', '403']},{'id': '395', 'type': 'subscript', 'children': ['396', '402']},{'id': '396', 'type': 'call', 'children': ['397', '400']},{'id': '397', 'type': 'attribute', 'children': ['398', '399']},{'id': '398', 'type': 'identifier', 'children': [], 'value': 'xref_page'},{'id': '399', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '400', 'type': 'argument_list', 'children': ['401']},{'id': '401', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '402', 'type': 'integer', 'children': [], 'value': '0'},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '404', 'type': 'argument_list', 'children': []},{'id': '405', 'type': 'if_statement', 'children': ['406', '412']},{'id': '406', 'type': 'call', 'children': ['407', '410']},{'id': '407', 'type': 'attribute', 'children': ['408', '409']},{'id': '408', 'type': 'identifier', 'children': [], 'value': 'xr_start_page'},{'id': '409', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '410', 'type': 'argument_list', 'children': ['411']},{'id': '411', 'type': 'string', 'children': [], 'value': "'E'"},{'id': '412', 'type': 'block', 'children': ['413']},{'id': '413', 'type': 'expression_statement', 'children': ['414']},{'id': '414', 'type': 'assignment', 'children': ['415', '416']},{'id': '415', 'type': 'identifier', 'children': [], 'value': 'xr_start_page'},{'id': '416', 'type': 'binary_operator', 'children': ['417', '418'], 'value': '+'},{'id': '417', 'type': 'string', 'children': [], 'value': "'E'"},{'id': '418', 'type': 'subscript', 'children': ['419', '420']},{'id': '419', 'type': 'identifier', 'children': [], 'value': 'xr_start_page'},{'id': '420', 'type': 'slice', 'children': ['421', '422']},{'id': '421', 'type': 'colon', 'children': []},{'id': '422', 'type': 'unary_operator', 'children': ['423'], 'value': '-'},{'id': '423', 'type': 'integer', 'children': [], 'value': '1'},{'id': '424', 'type': 'if_statement', 'children': ['425', '430']},{'id': '425', 'type': 'boolean_operator', 'children': ['426', '427'], 'value': 'and'},{'id': '426', 'type': 'identifier', 'children': [], 'value': 'matching_issns'},{'id': '427', 'type': 'comparison_operator', 'children': ['428', '429'], 'value': '=='},{'id': '428', 'type': 'identifier', 'children': [], 'value': 'pm_start_page'},{'id': '429', 'type': 'identifier', 'children': [], 'value': 'xr_start_page'},{'id': '430', 'type': 'block', 'children': ['431', '435']},{'id': '431', 'type': 'expression_statement', 'children': ['432']},{'id': '432', 'type': 'assignment', 'children': ['433', '434']},{'id': '433', 'type': 'identifier', 'children': [], 'value': 'mapped_doi'},{'id': '434', 'type': 'identifier', 'children': [], 'value': 'xref_doi'},{'id': '435', 'type': 'break_statement', 'children': []},{'id': '436', 'type': 'return_statement', 'children': ['437']},{'id': '437', 'type': 'identifier', 'children': [], 'value': 'mapped_doi'} | def doi_query(pmid, search_limit=10):
pubmed_meta_dict = pubmed_client.get_metadata_for_ids([pmid],
get_issns_from_nlm=True)
if pubmed_meta_dict is None or pubmed_meta_dict.get(pmid) is None:
logger.warning('No metadata found in Pubmed for PMID%s' % pmid)
return None
pubmed_meta = pubmed_meta_dict[pmid]
if pubmed_meta.get('doi'):
return pubmed_meta.get('doi')
pm_article_title = pubmed_meta.get('title')
if pm_article_title is None:
logger.warning('No article title found in Pubmed for PMID%s' % pmid)
return None
pm_issn_list = pubmed_meta.get('issn_list')
if not pm_issn_list:
logger.warning('No ISSNs found in Pubmed for PMID%s' % pmid)
return None
pm_page = pubmed_meta.get('page')
if not pm_page:
logger.debug('No page number found in Pubmed for PMID%s' % pmid)
return None
url = crossref_search_url
params = {'q': pm_article_title, 'sort': 'score'}
try:
res = requests.get(crossref_search_url, params)
except requests.exceptions.ConnectionError as e:
logger.error('CrossRef service could not be reached.')
logger.error(e)
return None
except Exception as e:
logger.error('Error accessing CrossRef service: %s' % str(e))
return None
if res.status_code != 200:
logger.info('PMID%s: no search results from CrossRef, code %d' %
(pmid, res.status_code))
return None
raw_message = res.json()
mapped_doi = None
for result_ix, result in enumerate(raw_message):
if result_ix > search_limit:
logger.info('PMID%s: No match found within first %s results, '
'giving up!' % (pmid, search_limit))
break
xref_doi_url = result['doi']
m = re.match('^http://dx.doi.org/(.*)$', xref_doi_url)
xref_doi = m.groups()[0]
xref_meta = get_metadata(xref_doi)
if xref_meta is None:
continue
xref_issn_list = xref_meta.get('ISSN')
xref_page = xref_meta.get('page')
if not xref_issn_list:
logger.debug('No ISSN found for DOI %s, skipping' % xref_doi_url)
continue
if not xref_page:
logger.debug('No page number found for DOI %s, skipping' %
xref_doi_url)
continue
matching_issns = set(pm_issn_list).intersection(set(xref_issn_list))
pm_start_page = pm_page.split('-')[0].upper()
xr_start_page = xref_page.split('-')[0].upper()
if xr_start_page.endswith('E'):
xr_start_page = 'E' + xr_start_page[:-1]
if matching_issns and pm_start_page == xr_start_page:
mapped_doi = xref_doi
break
return mapped_doi |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_agent_rule_str'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '5', 'type': 'block', 'children': ['6', '16', '251', '260']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'rule_str_list'},{'id': '9', 'type': 'list', 'children': ['10'], 'value': '[_n(agent.name)]'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': '_n'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '16', 'type': 'if_statement', 'children': ['17', '24']},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '19', 'type': 'argument_list', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'ist'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'Agent'},{'id': '24', 'type': 'block', 'children': ['25', '74', '136', '184', '203']},{'id': '25', 'type': 'for_statement', 'children': ['26', '27', '30']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'mods'},{'id': '30', 'type': 'block', 'children': ['31', '39', '52', '65']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'mstr'},{'id': '34', 'type': 'subscript', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'abbrevs'},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'mod_type'},{'id': '39', 'type': 'if_statement', 'children': ['40', '45']},{'id': '40', 'type': 'comparison_operator', 'children': ['41', '44'], 'value': 'is'},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'residue'},{'id': '44', 'type': 'None', 'children': []},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'augmented_assignment', 'children': ['48', '49'], 'value': '+='},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'mstr'},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'residue'},{'id': '52', 'type': 'if_statement', 'children': ['53', '58']},{'id': '53', 'type': 'comparison_operator', 'children': ['54', '57'], 'value': 'is'},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '57', 'type': 'None', 'children': []},{'id': '58', 'type': 'block', 'children': ['59']},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'augmented_assignment', 'children': ['61', '62'], 'value': '+='},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'mstr'},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'position'},{'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': 'rule_str_list'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'binary_operator', 'children': ['72', '73'], 'value': '%'},{'id': '72', 'type': 'string', 'children': [], 'value': "'%s'"},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'mstr'},{'id': '74', 'type': 'for_statement', 'children': ['75', '76', '79']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'mut'},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'mutations'},{'id': '79', 'type': 'block', 'children': ['80', '91', '102', '123', '129']},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'res_from'},{'id': '83', 'type': 'conditional_expression', 'children': ['84', '87', '90'], 'value': 'if'},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'mut'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'residue_from'},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'mut'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'residue_from'},{'id': '90', 'type': 'string', 'children': [], 'value': "'mut'"},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'res_to'},{'id': '94', 'type': 'conditional_expression', 'children': ['95', '98', '101'], 'value': 'if'},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'mut'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'residue_to'},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'mut'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'residue_to'},{'id': '101', 'type': 'string', 'children': [], 'value': "'X'"},{'id': '102', 'type': 'if_statement', 'children': ['103', '108', '113']},{'id': '103', 'type': 'comparison_operator', 'children': ['104', '107'], 'value': 'is'},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'mut'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '107', 'type': 'None', 'children': []},{'id': '108', 'type': 'block', 'children': ['109']},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'mut_site_name'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'res_from'},{'id': '113', 'type': 'else_clause', 'children': ['114']},{'id': '114', 'type': 'block', 'children': ['115']},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'mut_site_name'},{'id': '118', 'type': 'binary_operator', 'children': ['119', '120'], 'value': '+'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'res_from'},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'mut'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'assignment', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'mstr'},{'id': '126', 'type': 'binary_operator', 'children': ['127', '128'], 'value': '+'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'mut_site_name'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'res_to'},{'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': 'rule_str_list'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'mstr'},{'id': '136', 'type': 'if_statement', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'bound_conditions'},{'id': '140', 'type': 'block', 'children': ['141']},{'id': '141', 'type': 'for_statement', 'children': ['142', '143', '146']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'bound_conditions'},{'id': '146', 'type': 'block', 'children': ['147']},{'id': '147', 'type': 'if_statement', 'children': ['148', '151', '166']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'is_bound'},{'id': '151', 'type': 'block', 'children': ['152']},{'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': 'rule_str_list'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'call', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': '_n'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'attribute', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'name'},{'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': 'rule_str_list'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '173', 'type': 'argument_list', 'children': ['174']},{'id': '174', 'type': 'binary_operator', 'children': ['175', '176'], 'value': '+'},{'id': '175', 'type': 'string', 'children': [], 'value': "'n'"},{'id': '176', 'type': 'call', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': '_n'},{'id': '178', 'type': 'argument_list', 'children': ['179']},{'id': '179', 'type': 'attribute', 'children': ['180', '183']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '184', 'type': 'if_statement', 'children': ['185', '190']},{'id': '185', 'type': 'comparison_operator', 'children': ['186', '189'], 'value': 'is'},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '189', 'type': 'None', 'children': []},{'id': '190', 'type': 'block', 'children': ['191']},{'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': 'rule_str_list'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '196', 'type': 'argument_list', 'children': ['197']},{'id': '197', 'type': 'call', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': '_n'},{'id': '199', 'type': 'argument_list', 'children': ['200']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '203', 'type': 'if_statement', 'children': ['204', '209']},{'id': '204', 'type': 'comparison_operator', 'children': ['205', '208'], 'value': 'is'},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'activity'},{'id': '208', 'type': 'None', 'children': []},{'id': '209', 'type': 'block', 'children': ['210']},{'id': '210', 'type': 'if_statement', 'children': ['211', '216', '232']},{'id': '211', 'type': 'attribute', 'children': ['212', '215']},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'activity'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'is_active'},{'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': 'rule_str_list'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'subscript', 'children': ['224', '229']},{'id': '224', 'type': 'attribute', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'activity'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'activity_type'},{'id': '229', 'type': 'slice', 'children': ['230', '231']},{'id': '230', 'type': 'colon', 'children': []},{'id': '231', 'type': 'integer', 'children': [], 'value': '3'},{'id': '232', 'type': 'else_clause', 'children': ['233']},{'id': '233', 'type': 'block', 'children': ['234']},{'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': 'rule_str_list'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '239', 'type': 'argument_list', 'children': ['240']},{'id': '240', 'type': 'binary_operator', 'children': ['241', '250'], 'value': '+'},{'id': '241', 'type': 'subscript', 'children': ['242', '247']},{'id': '242', 'type': 'attribute', 'children': ['243', '246']},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'activity'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'activity_type'},{'id': '247', 'type': 'slice', 'children': ['248', '249']},{'id': '248', 'type': 'colon', 'children': []},{'id': '249', 'type': 'integer', 'children': [], 'value': '3'},{'id': '250', 'type': 'string', 'children': [], 'value': "'_inact'"},{'id': '251', 'type': 'expression_statement', 'children': ['252']},{'id': '252', 'type': 'assignment', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'rule_str'},{'id': '254', 'type': 'call', 'children': ['255', '258']},{'id': '255', 'type': 'attribute', 'children': ['256', '257']},{'id': '256', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '258', 'type': 'argument_list', 'children': ['259']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'rule_str_list'},{'id': '260', 'type': 'return_statement', 'children': ['261']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'rule_str'} | def get_agent_rule_str(agent):
rule_str_list = [_n(agent.name)]
if isinstance(agent, ist.Agent):
for mod in agent.mods:
mstr = abbrevs[mod.mod_type]
if mod.residue is not None:
mstr += mod.residue
if mod.position is not None:
mstr += mod.position
rule_str_list.append('%s' % mstr)
for mut in agent.mutations:
res_from = mut.residue_from if mut.residue_from else 'mut'
res_to = mut.residue_to if mut.residue_to else 'X'
if mut.position is None:
mut_site_name = res_from
else:
mut_site_name = res_from + mut.position
mstr = mut_site_name + res_to
rule_str_list.append(mstr)
if agent.bound_conditions:
for b in agent.bound_conditions:
if b.is_bound:
rule_str_list.append(_n(b.agent.name))
else:
rule_str_list.append('n' + _n(b.agent.name))
if agent.location is not None:
rule_str_list.append(_n(agent.location))
if agent.activity is not None:
if agent.activity.is_active:
rule_str_list.append(agent.activity.activity_type[:3])
else:
rule_str_list.append(agent.activity.activity_type[:3] + '_inact')
rule_str = '_'.join(rule_str_list)
return rule_str |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'grounded_monomer_patterns'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'ignore_activities'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '43', '47', '126', '141', '145', '347', '406', '441']},{'id': '10', 'type': 'if_statement', 'children': ['11', '19']},{'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': 'agent'},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'ist'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'Agent'},{'id': '19', 'type': 'block', 'children': ['20', '33', '38']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'monomer'},{'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': 'model'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'monomers'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '33', 'type': 'if_statement', 'children': ['34', '36']},{'id': '34', 'type': 'not_operator', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'monomer'},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'return_statement', 'children': []},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'yield', 'children': ['40']},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'monomer'},{'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': 'monomer'},{'id': '46', 'type': 'None', 'children': []},{'id': '47', 'type': 'for_statement', 'children': ['48', '49', '52']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'ann'},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'annotations'},{'id': '52', 'type': 'block', 'children': ['53', '57', '66', '77', '88', '98']},{'id': '53', 'type': 'if_statement', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'monomer'},{'id': '55', 'type': 'block', 'children': ['56']},{'id': '56', 'type': 'break_statement', 'children': []},{'id': '57', 'type': 'if_statement', 'children': ['58', '64']},{'id': '58', 'type': 'not_operator', 'children': ['59']},{'id': '59', 'type': 'comparison_operator', 'children': ['60', '63'], 'value': '=='},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'ann'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'predicate'},{'id': '63', 'type': 'string', 'children': [], 'value': "'is'"},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'continue_statement', 'children': []},{'id': '66', 'type': 'if_statement', 'children': ['67', '75']},{'id': '67', 'type': 'not_operator', 'children': ['68']},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '70', 'type': 'argument_list', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'ann'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'subject'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'Monomer'},{'id': '75', 'type': 'block', 'children': ['76']},{'id': '76', 'type': 'continue_statement', 'children': []},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '82']},{'id': '79', 'type': 'tuple_pattern', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'parse_identifiers_url'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'ann'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'object'},{'id': '88', 'type': 'if_statement', 'children': ['89', '96']},{'id': '89', 'type': 'boolean_operator', 'children': ['90', '93'], 'value': 'and'},{'id': '90', 'type': 'comparison_operator', 'children': ['91', '92'], 'value': 'is'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '92', 'type': 'None', 'children': []},{'id': '93', 'type': 'comparison_operator', 'children': ['94', '95'], 'value': 'is'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '95', 'type': 'None', 'children': []},{'id': '96', 'type': 'block', 'children': ['97']},{'id': '97', 'type': 'continue_statement', 'children': []},{'id': '98', 'type': 'for_statement', 'children': ['99', '102', '109']},{'id': '99', 'type': 'pattern_list', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'db_ns'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'db_id'},{'id': '102', 'type': 'call', 'children': ['103', '108']},{'id': '103', 'type': 'attribute', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'db_refs'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '108', 'type': 'argument_list', 'children': []},{'id': '109', 'type': 'block', 'children': ['110']},{'id': '110', 'type': 'if_statement', 'children': ['111', '118']},{'id': '111', 'type': 'boolean_operator', 'children': ['112', '115'], 'value': 'and'},{'id': '112', 'type': 'comparison_operator', 'children': ['113', '114'], 'value': '=='},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'db_ns'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '115', 'type': 'comparison_operator', 'children': ['116', '117'], 'value': '=='},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'db_id'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '118', 'type': 'block', 'children': ['119', '125']},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'monomer'},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'ann'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'subject'},{'id': '125', 'type': 'break_statement', 'children': []},{'id': '126', 'type': 'if_statement', 'children': ['127', '130']},{'id': '127', 'type': 'comparison_operator', 'children': ['128', '129'], 'value': 'is'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'monomer'},{'id': '129', 'type': 'None', 'children': []},{'id': '130', 'type': 'block', 'children': ['131', '140']},{'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': 'logger'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'binary_operator', 'children': ['138', '139'], 'value': '%'},{'id': '138', 'type': 'string', 'children': [], 'value': "'No monomer found corresponding to agent %s'"},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '140', 'type': 'return_statement', 'children': []},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'sc_list'},{'id': '144', 'type': 'list', 'children': [], 'value': '[]'},{'id': '145', 'type': 'for_statement', 'children': ['146', '147', '150']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'mods'},{'id': '150', 'type': 'block', 'children': ['151', '155', '162', '169', '270', '281', '297', '313', '318', '322', '340']},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'mod_sites'},{'id': '154', 'type': 'dictionary', 'children': []},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'res_sites'},{'id': '158', 'type': 'call', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'list', 'children': [], 'value': '[]'},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'assignment', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'pos_sites'},{'id': '165', 'type': 'call', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '167', 'type': 'argument_list', 'children': ['168']},{'id': '168', 'type': 'list', 'children': [], 'value': '[]'},{'id': '169', 'type': 'for_statement', 'children': ['170', '171', '174']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'ann'},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'monomer'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'site_annotations'},{'id': '174', 'type': 'block', 'children': ['175']},{'id': '175', 'type': 'if_statement', 'children': ['176', '190', '220', '245']},{'id': '176', 'type': 'boolean_operator', 'children': ['177', '182', '183'], 'value': 'and'},{'id': '177', 'type': 'comparison_operator', 'children': ['178', '181'], 'value': '=='},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'ann'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'predicate'},{'id': '181', 'type': 'string', 'children': [], 'value': "'is_modification'"},{'id': '182', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '183', 'type': 'comparison_operator', 'children': ['184', '187'], 'value': '=='},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'ann'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'object'},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'mod_type'},{'id': '190', 'type': 'block', 'children': ['191', '197', '203', '210']},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'site_state'},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'ann'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'subject'},{'id': '197', 'type': 'assert_statement', 'children': ['198']},{'id': '198', 'type': 'call', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '200', 'type': 'argument_list', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'site_state'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '203', 'type': 'assert_statement', 'children': ['204']},{'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': 'site_state'},{'id': '209', 'type': 'integer', 'children': [], 'value': '2'},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'id': '211', 'type': 'assignment', 'children': ['212', '217']},{'id': '212', 'type': 'subscript', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'mod_sites'},{'id': '214', 'type': 'subscript', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'site_state'},{'id': '216', 'type': 'integer', 'children': [], 'value': '0'},{'id': '217', 'type': 'subscript', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'site_state'},{'id': '219', 'type': 'integer', 'children': [], 'value': '1'},{'id': '220', 'type': 'elif_clause', 'children': ['221', '235']},{'id': '221', 'type': 'boolean_operator', 'children': ['222', '227', '228'], 'value': 'and'},{'id': '222', 'type': 'comparison_operator', 'children': ['223', '226'], 'value': '=='},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'ann'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'predicate'},{'id': '226', 'type': 'string', 'children': [], 'value': "'is_residue'"},{'id': '227', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '228', 'type': 'comparison_operator', 'children': ['229', '232'], 'value': '=='},{'id': '229', 'type': 'attribute', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'ann'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'object'},{'id': '232', 'type': 'attribute', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'residue'},{'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': 'res_sites'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '241', 'type': 'argument_list', 'children': ['242']},{'id': '242', 'type': 'attribute', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'ann'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'subject'},{'id': '245', 'type': 'elif_clause', 'children': ['246', '260']},{'id': '246', 'type': 'boolean_operator', 'children': ['247', '252', '253'], 'value': 'and'},{'id': '247', 'type': 'comparison_operator', 'children': ['248', '251'], 'value': '=='},{'id': '248', 'type': 'attribute', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'ann'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'predicate'},{'id': '251', 'type': 'string', 'children': [], 'value': "'is_position'"},{'id': '252', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '253', 'type': 'comparison_operator', 'children': ['254', '257'], 'value': '=='},{'id': '254', 'type': 'attribute', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'ann'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'object'},{'id': '257', 'type': 'attribute', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '260', 'type': 'block', 'children': ['261']},{'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': 'pos_sites'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '266', 'type': 'argument_list', 'children': ['267']},{'id': '267', 'type': 'attribute', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'ann'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'subject'},{'id': '270', 'type': 'expression_statement', 'children': ['271']},{'id': '271', 'type': 'assignment', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'viable_sites'},{'id': '273', 'type': 'call', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '275', 'type': 'argument_list', 'children': ['276']},{'id': '276', 'type': 'call', 'children': ['277', '280']},{'id': '277', 'type': 'attribute', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'mod_sites'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '280', 'type': 'argument_list', 'children': []},{'id': '281', 'type': 'if_statement', 'children': ['282', '287']},{'id': '282', 'type': 'comparison_operator', 'children': ['283', '286'], 'value': 'is'},{'id': '283', 'type': 'attribute', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'residue'},{'id': '286', 'type': 'None', 'children': []},{'id': '287', 'type': 'block', 'children': ['288']},{'id': '288', 'type': 'expression_statement', 'children': ['289']},{'id': '289', 'type': 'assignment', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'viable_sites'},{'id': '291', 'type': 'call', 'children': ['292', '295']},{'id': '292', 'type': 'attribute', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'viable_sites'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'intersection'},{'id': '295', 'type': 'argument_list', 'children': ['296']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'res_sites'},{'id': '297', 'type': 'if_statement', 'children': ['298', '303']},{'id': '298', 'type': 'comparison_operator', 'children': ['299', '302'], 'value': 'is'},{'id': '299', 'type': 'attribute', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '302', 'type': 'None', 'children': []},{'id': '303', 'type': 'block', 'children': ['304']},{'id': '304', 'type': 'expression_statement', 'children': ['305']},{'id': '305', 'type': 'assignment', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'viable_sites'},{'id': '307', 'type': 'call', 'children': ['308', '311']},{'id': '308', 'type': 'attribute', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'viable_sites'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'intersection'},{'id': '311', 'type': 'argument_list', 'children': ['312']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'pos_sites'},{'id': '313', 'type': 'if_statement', 'children': ['314', '316']},{'id': '314', 'type': 'not_operator', 'children': ['315']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'viable_sites'},{'id': '316', 'type': 'block', 'children': ['317']},{'id': '317', 'type': 'return_statement', 'children': []},{'id': '318', 'type': 'expression_statement', 'children': ['319']},{'id': '319', 'type': 'assignment', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'pattern_list'},{'id': '321', 'type': 'list', 'children': [], 'value': '[]'},{'id': '322', 'type': 'for_statement', 'children': ['323', '324', '325']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'site_name'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'viable_sites'},{'id': '325', 'type': 'block', 'children': ['326']},{'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': 'pattern_list'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '331', 'type': 'argument_list', 'children': ['332']},{'id': '332', 'type': 'dictionary', 'children': ['333']},{'id': '333', 'type': 'pair', 'children': ['334', '335']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'site_name'},{'id': '335', 'type': 'tuple', 'children': ['336', '339']},{'id': '336', 'type': 'subscript', 'children': ['337', '338']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'mod_sites'},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'site_name'},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'WILD'},{'id': '340', 'type': 'expression_statement', 'children': ['341']},{'id': '341', 'type': 'call', 'children': ['342', '345']},{'id': '342', 'type': 'attribute', 'children': ['343', '344']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'sc_list'},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '345', 'type': 'argument_list', 'children': ['346']},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'pattern_list'},{'id': '347', 'type': 'if_statement', 'children': ['348', '354']},{'id': '348', 'type': 'boolean_operator', 'children': ['349', '352'], 'value': 'and'},{'id': '349', 'type': 'attribute', 'children': ['350', '351']},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'activity'},{'id': '352', 'type': 'not_operator', 'children': ['353']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'ignore_activities'},{'id': '354', 'type': 'block', 'children': ['355', '367', '371', '399']},{'id': '355', 'type': 'expression_statement', 'children': ['356']},{'id': '356', 'type': 'assignment', 'children': ['357', '358']},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'rel_type'},{'id': '358', 'type': 'conditional_expression', 'children': ['359', '360', '365', '366'], 'value': 'if'},{'id': '359', 'type': 'string', 'children': [], 'value': "'has_active_pattern'"},{'id': '360', 'type': 'attribute', 'children': ['361', '364']},{'id': '361', 'type': 'attribute', 'children': ['362', '363']},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'activity'},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'is_active'},{'id': '365', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '366', 'type': 'string', 'children': [], 'value': "'has_inactive_pattern'"},{'id': '367', 'type': 'expression_statement', 'children': ['368']},{'id': '368', 'type': 'assignment', 'children': ['369', '370']},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'active_form_list'},{'id': '370', 'type': 'list', 'children': [], 'value': '[]'},{'id': '371', 'type': 'for_statement', 'children': ['372', '373', '376']},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'ann'},{'id': '373', 'type': 'attribute', 'children': ['374', '375']},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'annotations'},{'id': '376', 'type': 'block', 'children': ['377']},{'id': '377', 'type': 'if_statement', 'children': ['378', '389']},{'id': '378', 'type': 'boolean_operator', 'children': ['379', '384'], 'value': 'and'},{'id': '379', 'type': 'comparison_operator', 'children': ['380', '383'], 'value': '=='},{'id': '380', 'type': 'attribute', 'children': ['381', '382']},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'ann'},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'subject'},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'monomer'},{'id': '384', 'type': 'comparison_operator', 'children': ['385', '388'], 'value': '=='},{'id': '385', 'type': 'attribute', 'children': ['386', '387']},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'ann'},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'predicate'},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'rel_type'},{'id': '389', 'type': 'block', 'children': ['390']},{'id': '390', 'type': 'expression_statement', 'children': ['391']},{'id': '391', 'type': 'call', 'children': ['392', '395']},{'id': '392', 'type': 'attribute', 'children': ['393', '394']},{'id': '393', 'type': 'identifier', 'children': [], 'value': 'active_form_list'},{'id': '394', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '395', 'type': 'argument_list', 'children': ['396']},{'id': '396', 'type': 'attribute', 'children': ['397', '398']},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'ann'},{'id': '398', 'type': 'identifier', 'children': [], 'value': 'object'},{'id': '399', 'type': 'expression_statement', 'children': ['400']},{'id': '400', 'type': 'call', 'children': ['401', '404']},{'id': '401', 'type': 'attribute', 'children': ['402', '403']},{'id': '402', 'type': 'identifier', 'children': [], 'value': 'sc_list'},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '404', 'type': 'argument_list', 'children': ['405']},{'id': '405', 'type': 'identifier', 'children': [], 'value': 'active_form_list'},{'id': '406', 'type': 'for_statement', 'children': ['407', '408', '415']},{'id': '407', 'type': 'identifier', 'children': [], 'value': 'pattern_combo'},{'id': '408', 'type': 'call', 'children': ['409', '412']},{'id': '409', 'type': 'attribute', 'children': ['410', '411']},{'id': '410', 'type': 'identifier', 'children': [], 'value': 'itertools'},{'id': '411', 'type': 'identifier', 'children': [], 'value': 'product'},{'id': '412', 'type': 'argument_list', 'children': ['413']},{'id': '413', 'type': 'list_splat', 'children': ['414']},{'id': '414', 'type': 'identifier', 'children': [], 'value': 'sc_list'},{'id': '415', 'type': 'block', 'children': ['416', '420', '431']},{'id': '416', 'type': 'expression_statement', 'children': ['417']},{'id': '417', 'type': 'assignment', 'children': ['418', '419']},{'id': '418', 'type': 'identifier', 'children': [], 'value': 'mp_sc'},{'id': '419', 'type': 'dictionary', 'children': []},{'id': '420', 'type': 'for_statement', 'children': ['421', '422', '423']},{'id': '421', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '422', 'type': 'identifier', 'children': [], 'value': 'pattern_combo'},{'id': '423', 'type': 'block', 'children': ['424']},{'id': '424', 'type': 'expression_statement', 'children': ['425']},{'id': '425', 'type': 'call', 'children': ['426', '429']},{'id': '426', 'type': 'attribute', 'children': ['427', '428']},{'id': '427', 'type': 'identifier', 'children': [], 'value': 'mp_sc'},{'id': '428', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '429', 'type': 'argument_list', 'children': ['430']},{'id': '430', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '431', 'type': 'if_statement', 'children': ['432', '433']},{'id': '432', 'type': 'identifier', 'children': [], 'value': 'mp_sc'},{'id': '433', 'type': 'block', 'children': ['434']},{'id': '434', 'type': 'expression_statement', 'children': ['435']},{'id': '435', 'type': 'yield', 'children': ['436']},{'id': '436', 'type': 'call', 'children': ['437', '438']},{'id': '437', 'type': 'identifier', 'children': [], 'value': 'monomer'},{'id': '438', 'type': 'argument_list', 'children': ['439']},{'id': '439', 'type': 'dictionary_splat', 'children': ['440']},{'id': '440', 'type': 'identifier', 'children': [], 'value': 'mp_sc'},{'id': '441', 'type': 'if_statement', 'children': ['442', '444']},{'id': '442', 'type': 'not_operator', 'children': ['443']},{'id': '443', 'type': 'identifier', 'children': [], 'value': 'sc_list'},{'id': '444', 'type': 'block', 'children': ['445']},{'id': '445', 'type': 'expression_statement', 'children': ['446']},{'id': '446', 'type': 'yield', 'children': ['447']},{'id': '447', 'type': 'call', 'children': ['448', '449']},{'id': '448', 'type': 'identifier', 'children': [], 'value': 'monomer'},{'id': '449', 'type': 'argument_list', 'children': []} | def grounded_monomer_patterns(model, agent, ignore_activities=False):
if not isinstance(agent, ist.Agent):
monomer = model.monomers.get(agent.name)
if not monomer:
return
yield monomer()
monomer = None
for ann in model.annotations:
if monomer:
break
if not ann.predicate == 'is':
continue
if not isinstance(ann.subject, Monomer):
continue
(ns, id) = parse_identifiers_url(ann.object)
if ns is None and id is None:
continue
for db_ns, db_id in agent.db_refs.items():
if db_ns == ns and db_id == id:
monomer = ann.subject
break
if monomer is None:
logger.info('No monomer found corresponding to agent %s' % agent)
return
sc_list = []
for mod in agent.mods:
mod_sites = {}
res_sites = set([])
pos_sites = set([])
for ann in monomer.site_annotations:
if ann.predicate == 'is_modification' and \
ann.object == mod.mod_type:
site_state = ann.subject
assert isinstance(site_state, tuple)
assert len(site_state) == 2
mod_sites[site_state[0]] = site_state[1]
elif ann.predicate == 'is_residue' and \
ann.object == mod.residue:
res_sites.add(ann.subject)
elif ann.predicate == 'is_position' and \
ann.object == mod.position:
pos_sites.add(ann.subject)
viable_sites = set(mod_sites.keys())
if mod.residue is not None:
viable_sites = viable_sites.intersection(res_sites)
if mod.position is not None:
viable_sites = viable_sites.intersection(pos_sites)
if not viable_sites:
return
pattern_list = []
for site_name in viable_sites:
pattern_list.append({site_name: (mod_sites[site_name], WILD)})
sc_list.append(pattern_list)
if agent.activity and not ignore_activities:
rel_type = 'has_active_pattern' if agent.activity.is_active \
else 'has_inactive_pattern'
active_form_list = []
for ann in model.annotations:
if ann.subject == monomer and ann.predicate == rel_type:
active_form_list.append(ann.object)
sc_list.append(active_form_list)
for pattern_combo in itertools.product(*sc_list):
mp_sc = {}
for pattern in pattern_combo:
mp_sc.update(pattern)
if mp_sc:
yield monomer(**mp_sc)
if not sc_list:
yield monomer() |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_site_pattern'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '5', 'type': 'block', 'children': ['6', '18', '22', '57', '141', '196', '214', '252']},{'id': '6', 'type': 'if_statement', 'children': ['7', '15']},{'id': '7', 'type': 'not_operator', 'children': ['8']},{'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': 'agent'},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'ist'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'Agent'},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'return_statement', 'children': ['17']},{'id': '17', 'type': 'dictionary', 'children': []},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '21', 'type': 'dictionary', 'children': []},{'id': '22', 'type': 'for_statement', 'children': ['23', '24', '27']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'bc'},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'bound_conditions'},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'if_statement', 'children': ['29', '32', '44']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'bc'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'is_bound'},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '43']},{'id': '35', 'type': 'subscript', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'get_binding_site_name'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'bc'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'ANY'},{'id': '44', 'type': 'else_clause', 'children': ['45']},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '56']},{'id': '48', 'type': 'subscript', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'get_binding_site_name'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'bc'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '56', 'type': 'None', 'children': []},{'id': '57', 'type': 'for_statement', 'children': ['58', '59', '62']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'mods'},{'id': '62', 'type': 'block', 'children': ['63', '71', '84', '97', '106', '114']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'mod_site_str'},{'id': '66', 'type': 'subscript', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'abbrevs'},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'mod_type'},{'id': '71', 'type': 'if_statement', 'children': ['72', '77']},{'id': '72', 'type': 'comparison_operator', 'children': ['73', '76'], 'value': 'is'},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'residue'},{'id': '76', 'type': 'None', 'children': []},{'id': '77', 'type': 'block', 'children': ['78']},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'mod_site_str'},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'residue'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'mod_pos_str'},{'id': '87', 'type': 'conditional_expression', 'children': ['88', '91', '96'], 'value': 'if'},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '91', 'type': 'comparison_operator', 'children': ['92', '95'], 'value': 'is'},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '95', 'type': 'None', 'children': []},{'id': '96', 'type': 'string', 'children': [], 'value': "''"},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'mod_site'},{'id': '100', 'type': '()', 'children': ['101']},{'id': '101', 'type': 'binary_operator', 'children': ['102', '103'], 'value': '%'},{'id': '102', 'type': 'string', 'children': [], 'value': "'%s%s'"},{'id': '103', 'type': 'tuple', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'mod_site_str'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'mod_pos_str'},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'site_states'},{'id': '109', 'type': 'subscript', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'states'},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'mod_type'},{'id': '114', 'type': 'if_statement', 'children': ['115', '118', '129']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'is_modified'},{'id': '118', 'type': 'block', 'children': ['119']},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '124']},{'id': '121', 'type': 'subscript', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'mod_site'},{'id': '124', 'type': 'tuple', 'children': ['125', '128']},{'id': '125', 'type': 'subscript', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'site_states'},{'id': '127', 'type': 'integer', 'children': [], 'value': '1'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'WILD'},{'id': '129', 'type': 'else_clause', 'children': ['130']},{'id': '130', 'type': 'block', 'children': ['131']},{'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': 'pattern'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'mod_site'},{'id': '136', 'type': 'tuple', 'children': ['137', '140']},{'id': '137', 'type': 'subscript', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'site_states'},{'id': '139', 'type': 'integer', 'children': [], 'value': '0'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'WILD'},{'id': '141', 'type': 'for_statement', 'children': ['142', '143', '146']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'mc'},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'mutations'},{'id': '146', 'type': 'block', 'children': ['147', '158', '169', '190']},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'assignment', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'res_from'},{'id': '150', 'type': 'conditional_expression', 'children': ['151', '154', '157'], 'value': 'if'},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'mc'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'residue_from'},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'mc'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'residue_from'},{'id': '157', 'type': 'string', 'children': [], 'value': "'mut'"},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'res_to'},{'id': '161', 'type': 'conditional_expression', 'children': ['162', '165', '168'], 'value': 'if'},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'mc'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'residue_to'},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'mc'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'residue_to'},{'id': '168', 'type': 'string', 'children': [], 'value': "'X'"},{'id': '169', 'type': 'if_statement', 'children': ['170', '175', '180']},{'id': '170', 'type': 'comparison_operator', 'children': ['171', '174'], 'value': 'is'},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'mc'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '174', 'type': 'None', 'children': []},{'id': '175', 'type': 'block', 'children': ['176']},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'assignment', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'mut_site_name'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'res_from'},{'id': '180', 'type': 'else_clause', 'children': ['181']},{'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': 'mut_site_name'},{'id': '185', 'type': 'binary_operator', 'children': ['186', '187'], 'value': '+'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'res_from'},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'mc'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'position'},{'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': 'pattern'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'mut_site_name'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'res_to'},{'id': '196', 'type': 'if_statement', 'children': ['197', '202']},{'id': '197', 'type': 'comparison_operator', 'children': ['198', '201'], 'value': 'is'},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '201', 'type': 'None', 'children': []},{'id': '202', 'type': 'block', 'children': ['203']},{'id': '203', 'type': 'expression_statement', 'children': ['204']},{'id': '204', 'type': 'assignment', 'children': ['205', '208']},{'id': '205', 'type': 'subscript', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '207', 'type': 'string', 'children': [], 'value': "'loc'"},{'id': '208', 'type': 'call', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': '_n'},{'id': '210', 'type': 'argument_list', 'children': ['211']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '214', 'type': 'if_statement', 'children': ['215', '220']},{'id': '215', 'type': 'comparison_operator', 'children': ['216', '219'], 'value': 'is'},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'activity'},{'id': '219', 'type': 'None', 'children': []},{'id': '220', 'type': 'block', 'children': ['221', '229', '246']},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'assignment', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'active_site_name'},{'id': '224', 'type': 'attribute', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'activity'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'activity_type'},{'id': '229', 'type': 'if_statement', 'children': ['230', '235', '240']},{'id': '230', 'type': 'attribute', 'children': ['231', '234']},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'activity'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'is_active'},{'id': '235', 'type': 'block', 'children': ['236']},{'id': '236', 'type': 'expression_statement', 'children': ['237']},{'id': '237', 'type': 'assignment', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'active_site_state'},{'id': '239', 'type': 'string', 'children': [], 'value': "'active'"},{'id': '240', 'type': 'else_clause', 'children': ['241']},{'id': '241', 'type': 'block', 'children': ['242']},{'id': '242', 'type': 'expression_statement', 'children': ['243']},{'id': '243', 'type': 'assignment', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'active_site_state'},{'id': '245', 'type': 'string', 'children': [], 'value': "'inactive'"},{'id': '246', 'type': 'expression_statement', 'children': ['247']},{'id': '247', 'type': 'assignment', 'children': ['248', '251']},{'id': '248', 'type': 'subscript', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'active_site_name'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'active_site_state'},{'id': '252', 'type': 'return_statement', 'children': ['253']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'pattern'} | def get_site_pattern(agent):
if not isinstance(agent, ist.Agent):
return {}
pattern = {}
for bc in agent.bound_conditions:
if bc.is_bound:
pattern[get_binding_site_name(bc.agent)] = ANY
else:
pattern[get_binding_site_name(bc.agent)] = None
for mod in agent.mods:
mod_site_str = abbrevs[mod.mod_type]
if mod.residue is not None:
mod_site_str = mod.residue
mod_pos_str = mod.position if mod.position is not None else ''
mod_site = ('%s%s' % (mod_site_str, mod_pos_str))
site_states = states[mod.mod_type]
if mod.is_modified:
pattern[mod_site] = (site_states[1], WILD)
else:
pattern[mod_site] = (site_states[0], WILD)
for mc in agent.mutations:
res_from = mc.residue_from if mc.residue_from else 'mut'
res_to = mc.residue_to if mc.residue_to else 'X'
if mc.position is None:
mut_site_name = res_from
else:
mut_site_name = res_from + mc.position
pattern[mut_site_name] = res_to
if agent.location is not None:
pattern['loc'] = _n(agent.location)
if agent.activity is not None:
active_site_name = agent.activity.activity_type
if agent.activity.is_active:
active_site_state = 'active'
else:
active_site_state = 'inactive'
pattern[active_site_name] = active_site_state
return pattern |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'make_model'},{'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': 'policies'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'initial_conditions'},{'id': '10', 'type': 'True', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'reverse_effects'},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'model_name'},{'id': '16', 'type': 'string', 'children': [], 'value': "'indra_model'"},{'id': '17', 'type': 'block', 'children': ['18', '27', '38', '44', '53', '61', '69', '77', '85', '91', '259', '265', '274']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'ppa'},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'PysbPreassembler'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'statements'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'processed_policies'},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'process_policies'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'policies'},{'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': 'ppa'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'replace_activities'},{'id': '43', 'type': 'argument_list', 'children': []},{'id': '44', 'type': 'if_statement', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'reverse_effects'},{'id': '46', 'type': 'block', 'children': ['47']},{'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': 'ppa'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'add_reverse_effects'},{'id': '52', 'type': 'argument_list', 'children': []},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'statements'},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'ppa'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'statements'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '66', 'type': 'call', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'Model'},{'id': '68', 'type': 'argument_list', 'children': []},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '76']},{'id': '71', 'type': 'attribute', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'model_name'},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'agent_set'},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'BaseAgentSet'},{'id': '84', 'type': 'argument_list', 'children': []},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '89', 'type': 'identifier', 'children': [], 'value': '_monomers'},{'id': '90', 'type': 'argument_list', 'children': []},{'id': '91', 'type': 'for_statement', 'children': ['92', '95', '102']},{'id': '92', 'type': 'pattern_list', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'agent_name'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'agent'},{'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': 'agent_set'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '101', 'type': 'argument_list', 'children': []},{'id': '102', 'type': 'block', 'children': ['103', '119', '127', '136', '171', '191', '211']},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '106', 'type': 'call', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'Monomer'},{'id': '108', 'type': 'argument_list', 'children': ['109', '113', '116']},{'id': '109', 'type': 'call', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': '_n'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'agent_name'},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'sites'},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'site_states'},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'site_annotations'},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'site_annotations'},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'call', 'children': ['129', '134']},{'id': '129', 'type': 'attribute', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'add_component'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '136', 'type': 'for_statement', 'children': ['137', '140', '147']},{'id': '137', 'type': 'pattern_list', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'db_name'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'db_ref'},{'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': 'agent'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'db_refs'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '146', 'type': 'argument_list', 'children': []},{'id': '147', 'type': 'block', 'children': ['148', '157']},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '151', 'type': 'call', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'get_annotation'},{'id': '153', 'type': 'argument_list', 'children': ['154', '155', '156']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'db_name'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'db_ref'},{'id': '157', 'type': 'if_statement', 'children': ['158', '161']},{'id': '158', 'type': 'comparison_operator', 'children': ['159', '160'], 'value': 'is'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '160', 'type': 'None', 'children': []},{'id': '161', 'type': 'block', 'children': ['162']},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'call', 'children': ['164', '169']},{'id': '164', 'type': 'attribute', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'add_annotation'},{'id': '169', 'type': 'argument_list', 'children': ['170']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '171', 'type': 'for_statement', 'children': ['172', '173', '176']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'af'},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'active_forms'},{'id': '176', 'type': 'block', 'children': ['177']},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'call', 'children': ['179', '184']},{'id': '179', 'type': 'attribute', 'children': ['180', '183']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'add_annotation'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'call', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'Annotation'},{'id': '187', 'type': 'argument_list', 'children': ['188', '189', '190']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'af'},{'id': '190', 'type': 'string', 'children': [], 'value': "'has_active_pattern'"},{'id': '191', 'type': 'for_statement', 'children': ['192', '193', '196']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'iaf'},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'inactive_forms'},{'id': '196', 'type': 'block', 'children': ['197']},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'call', 'children': ['199', '204']},{'id': '199', 'type': 'attribute', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'add_annotation'},{'id': '204', 'type': 'argument_list', 'children': ['205']},{'id': '205', 'type': 'call', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'Annotation'},{'id': '207', 'type': 'argument_list', 'children': ['208', '209', '210']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'iaf'},{'id': '210', 'type': 'string', 'children': [], 'value': "'has_inactive_pattern'"},{'id': '211', 'type': 'for_statement', 'children': ['212', '213', '216']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'at'},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'activity_types'},{'id': '216', 'type': 'block', 'children': ['217', '224', '238', '245']},{'id': '217', 'type': 'expression_statement', 'children': ['218']},{'id': '218', 'type': 'assignment', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'act_site_cond'},{'id': '220', 'type': 'dictionary', 'children': ['221']},{'id': '221', 'type': 'pair', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'at'},{'id': '223', 'type': 'string', 'children': [], 'value': "'active'"},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'call', 'children': ['226', '231']},{'id': '226', 'type': 'attribute', 'children': ['227', '230']},{'id': '227', 'type': 'attribute', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'add_annotation'},{'id': '231', 'type': 'argument_list', 'children': ['232']},{'id': '232', 'type': 'call', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'Annotation'},{'id': '234', 'type': 'argument_list', 'children': ['235', '236', '237']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'act_site_cond'},{'id': '237', 'type': 'string', 'children': [], 'value': "'has_active_pattern'"},{'id': '238', 'type': 'expression_statement', 'children': ['239']},{'id': '239', 'type': 'assignment', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'inact_site_cond'},{'id': '241', 'type': 'dictionary', 'children': ['242']},{'id': '242', 'type': 'pair', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'at'},{'id': '244', 'type': 'string', 'children': [], 'value': "'inactive'"},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'call', 'children': ['247', '252']},{'id': '247', 'type': 'attribute', 'children': ['248', '251']},{'id': '248', 'type': 'attribute', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'add_annotation'},{'id': '252', 'type': 'argument_list', 'children': ['253']},{'id': '253', 'type': 'call', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'Annotation'},{'id': '255', 'type': 'argument_list', 'children': ['256', '257', '258']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'inact_site_cond'},{'id': '258', 'type': 'string', 'children': [], 'value': "'has_inactive_pattern'"},{'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': 'self'},{'id': '263', 'type': 'identifier', 'children': [], 'value': '_assemble'},{'id': '264', 'type': 'argument_list', 'children': []},{'id': '265', 'type': 'if_statement', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'initial_conditions'},{'id': '267', 'type': 'block', 'children': ['268']},{'id': '268', 'type': 'expression_statement', 'children': ['269']},{'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': 'add_default_initial_conditions'},{'id': '273', 'type': 'argument_list', 'children': []},{'id': '274', 'type': 'return_statement', 'children': ['275']},{'id': '275', 'type': 'attribute', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'model'} | def make_model(self, policies=None, initial_conditions=True,
reverse_effects=False, model_name='indra_model'):
ppa = PysbPreassembler(self.statements)
self.processed_policies = self.process_policies(policies)
ppa.replace_activities()
if reverse_effects:
ppa.add_reverse_effects()
self.statements = ppa.statements
self.model = Model()
self.model.name = model_name
self.agent_set = BaseAgentSet()
self._monomers()
for agent_name, agent in self.agent_set.items():
m = Monomer(_n(agent_name), agent.sites, agent.site_states)
m.site_annotations = agent.site_annotations
self.model.add_component(m)
for db_name, db_ref in agent.db_refs.items():
a = get_annotation(m, db_name, db_ref)
if a is not None:
self.model.add_annotation(a)
for af in agent.active_forms:
self.model.add_annotation(Annotation(m, af,
'has_active_pattern'))
for iaf in agent.inactive_forms:
self.model.add_annotation(Annotation(m, iaf,
'has_inactive_pattern'))
for at in agent.activity_types:
act_site_cond = {at: 'active'}
self.model.add_annotation(Annotation(m, act_site_cond,
'has_active_pattern'))
inact_site_cond = {at: 'inactive'}
self.model.add_annotation(Annotation(m, inact_site_cond,
'has_inactive_pattern'))
self._assemble()
if initial_conditions:
self.add_default_initial_conditions()
return self.model |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.