sequence
stringlengths 492
15.9k
| code
stringlengths 75
8.58k
|
---|---|
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:serialize_to_normalized_pretty_json; 3, parameters; 3, 4; 4, identifier:py_obj; 5, block; 5, 6; 6, return_statement; 6, 7; 7, call; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:json; 10, identifier:dumps; 11, argument_list; 11, 12; 11, 13; 11, 16; 11, 19; 12, identifier:py_obj; 13, keyword_argument; 13, 14; 13, 15; 14, identifier:sort_keys; 15, True; 16, keyword_argument; 16, 17; 16, 18; 17, identifier:indent; 18, integer:2; 19, keyword_argument; 19, 20; 19, 21; 20, identifier:cls; 21, identifier:ToJsonCompatibleTypes | def serialize_to_normalized_pretty_json(py_obj):
return json.dumps(py_obj, sort_keys=True, indent=2, cls=ToJsonCompatibleTypes) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:serialize_to_normalized_compact_json; 3, parameters; 3, 4; 4, identifier:py_obj; 5, block; 5, 6; 6, return_statement; 6, 7; 7, call; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:json; 10, identifier:dumps; 11, argument_list; 11, 12; 11, 13; 11, 16; 11, 21; 12, identifier:py_obj; 13, keyword_argument; 13, 14; 13, 15; 14, identifier:sort_keys; 15, True; 16, keyword_argument; 16, 17; 16, 18; 17, identifier:separators; 18, tuple; 18, 19; 18, 20; 19, string:','; 20, string:':'; 21, keyword_argument; 21, 22; 21, 23; 22, identifier:cls; 23, identifier:ToJsonCompatibleTypes | def serialize_to_normalized_compact_json(py_obj):
return json.dumps(
py_obj, sort_keys=True, separators=(',', ':'), cls=ToJsonCompatibleTypes
) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:topological_sort; 3, parameters; 3, 4; 4, identifier:unsorted_dict; 5, block; 5, 6; 5, 10; 5, 16; 5, 20; 5, 28; 5, 79; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:sorted_list; 9, list:[]; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:sorted_set; 13, call; 13, 14; 13, 15; 14, identifier:set; 15, argument_list; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:found; 19, True; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:unconnected_dict; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:unsorted_dict; 26, identifier:copy; 27, argument_list; 28, while_statement; 28, 29; 28, 30; 29, identifier:found; 30, block; 30, 31; 30, 35; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:found; 34, False; 35, for_statement; 35, 36; 35, 39; 35, 47; 36, pattern_list; 36, 37; 36, 38; 37, identifier:pid; 38, identifier:obsoletes_pid; 39, call; 39, 40; 39, 41; 40, identifier:list; 41, argument_list; 41, 42; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:unconnected_dict; 45, identifier:items; 46, argument_list; 47, block; 47, 48; 48, if_statement; 48, 49; 48, 56; 49, boolean_operator:or; 49, 50; 49, 53; 50, comparison_operator:is; 50, 51; 50, 52; 51, identifier:obsoletes_pid; 52, None; 53, comparison_operator:in; 53, 54; 53, 55; 54, identifier:obsoletes_pid; 55, identifier:sorted_set; 56, block; 56, 57; 56, 61; 56, 68; 56, 75; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:found; 60, True; 61, expression_statement; 61, 62; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:sorted_list; 65, identifier:append; 66, argument_list; 66, 67; 67, identifier:pid; 68, expression_statement; 68, 69; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:sorted_set; 72, identifier:add; 73, argument_list; 73, 74; 74, identifier:pid; 75, delete_statement; 75, 76; 76, subscript; 76, 77; 76, 78; 77, identifier:unconnected_dict; 78, identifier:pid; 79, return_statement; 79, 80; 80, expression_list; 80, 81; 80, 82; 81, identifier:sorted_list; 82, identifier:unconnected_dict | def topological_sort(unsorted_dict):
sorted_list = []
sorted_set = set()
found = True
unconnected_dict = unsorted_dict.copy()
while found:
found = False
for pid, obsoletes_pid in list(unconnected_dict.items()):
if obsoletes_pid is None or obsoletes_pid in sorted_set:
found = True
sorted_list.append(pid)
sorted_set.add(pid)
del unconnected_dict[pid]
return sorted_list, unconnected_dict |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:sort_elements_by_child_values; 3, parameters; 3, 4; 3, 5; 4, identifier:obj_pyxb; 5, identifier:child_name_list; 6, block; 6, 7; 7, expression_statement; 7, 8; 8, call; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:obj_pyxb; 11, identifier:sort; 12, argument_list; 12, 13; 13, keyword_argument; 13, 14; 13, 15; 14, identifier:key; 15, lambda; 15, 16; 15, 18; 16, lambda_parameters; 16, 17; 17, identifier:x; 18, list_comprehension; 18, 19; 18, 27; 19, call; 19, 20; 19, 21; 20, identifier:get_auto; 21, argument_list; 21, 22; 22, call; 22, 23; 22, 24; 23, identifier:getattr; 24, argument_list; 24, 25; 24, 26; 25, identifier:x; 26, identifier:n; 27, for_in_clause; 27, 28; 27, 29; 28, identifier:n; 29, identifier:child_name_list | def sort_elements_by_child_values(obj_pyxb, child_name_list):
obj_pyxb.sort(key=lambda x: [get_auto(getattr(x, n)) for n in child_name_list]) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:get_field_values; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 10; 3, 13; 4, identifier:self; 5, identifier:name; 6, default_parameter; 6, 7; 6, 8; 7, identifier:maxvalues; 8, unary_operator:-; 8, 9; 9, integer:1; 10, default_parameter; 10, 11; 10, 12; 11, identifier:sort; 12, True; 13, dictionary_splat_pattern; 13, 14; 14, identifier:query_dict; 15, block; 15, 16; 15, 24; 15, 59; 15, 69; 15, 77; 15, 87; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:param_dict; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:query_dict; 22, identifier:copy; 23, argument_list; 24, expression_statement; 24, 25; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:param_dict; 28, identifier:update; 29, argument_list; 29, 30; 30, dictionary; 30, 31; 30, 34; 30, 37; 30, 40; 30, 46; 30, 49; 31, pair; 31, 32; 31, 33; 32, string:'rows'; 33, string:'0'; 34, pair; 34, 35; 34, 36; 35, string:'facet'; 36, string:'true'; 37, pair; 37, 38; 37, 39; 38, string:'facet.field'; 39, identifier:name; 40, pair; 40, 41; 40, 42; 41, string:'facet.limit'; 42, call; 42, 43; 42, 44; 43, identifier:str; 44, argument_list; 44, 45; 45, identifier:maxvalues; 46, pair; 46, 47; 46, 48; 47, string:'facet.zeros'; 48, string:'false'; 49, pair; 49, 50; 49, 51; 50, string:'facet.sort'; 51, call; 51, 52; 51, 58; 52, attribute; 52, 53; 52, 57; 53, call; 53, 54; 53, 55; 54, identifier:str; 55, argument_list; 55, 56; 56, identifier:sort; 57, identifier:lower; 58, argument_list; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:resp_dict; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:_post_query; 66, argument_list; 66, 67; 67, dictionary_splat; 67, 68; 68, identifier:param_dict; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:result_dict; 72, subscript; 72, 73; 72, 76; 73, subscript; 73, 74; 73, 75; 74, identifier:resp_dict; 75, string:'facet_counts'; 76, string:'facet_fields'; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 82; 79, subscript; 79, 80; 79, 81; 80, identifier:result_dict; 81, string:'numFound'; 82, subscript; 82, 83; 82, 86; 83, subscript; 83, 84; 83, 85; 84, identifier:resp_dict; 85, string:'response'; 86, string:'numFound'; 87, return_statement; 87, 88; 88, identifier:result_dict | def get_field_values(self, name, maxvalues=-1, sort=True, **query_dict):
param_dict = query_dict.copy()
param_dict.update(
{
'rows': '0',
'facet': 'true',
'facet.field': name,
'facet.limit': str(maxvalues),
'facet.zeros': 'false',
'facet.sort': str(sort).lower(),
}
)
resp_dict = self._post_query(**param_dict)
result_dict = resp_dict['facet_counts']['facet_fields']
result_dict['numFound'] = resp_dict['response']['numFound']
return result_dict |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:bin; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:x; 5, identifier:bins; 6, default_parameter; 6, 7; 6, 8; 7, identifier:maxX; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:minX; 11, None; 12, block; 12, 13; 12, 15; 12, 28; 12, 41; 12, 65; 13, expression_statement; 13, 14; 14, string:'''
bin signal x using 'binsN' bin. If minX, maxX are None, they default to the full
range of the signal. If they are not None, everything above maxX gets assigned to
binsN-1 and everything below minX gets assigned to 0, this is effectively the same
as clipping x before passing it to 'bin'
input:
-----
x: signal to be binned, some sort of iterable
bins: int, number of bins
iterable, bin edges
maxX: clips data above maxX
minX: clips data below maxX
output:
------
binnedX: x after being binned
bins: bins used for binning.
if input 'bins' is already an iterable it just returns the
same iterable
example:
bin(x, 10)
entropy)
binsN = 10
percentiles = list(np.arange(0, 100.1, 100/binsN))
bins = np.percentile(x, percentiles)
bin(x, bins)
'''; 15, if_statement; 15, 16; 15, 19; 16, comparison_operator:is; 16, 17; 16, 18; 17, identifier:maxX; 18, None; 19, block; 19, 20; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:maxX; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:x; 26, identifier:max; 27, argument_list; 28, if_statement; 28, 29; 28, 32; 29, comparison_operator:is; 29, 30; 29, 31; 30, identifier:minX; 31, None; 32, block; 32, 33; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:minX; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:x; 39, identifier:min; 40, argument_list; 41, if_statement; 41, 42; 41, 49; 42, not_operator; 42, 43; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:np; 46, identifier:iterable; 47, argument_list; 47, 48; 48, identifier:bins; 49, block; 49, 50; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:bins; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:np; 56, identifier:linspace; 57, argument_list; 57, 58; 57, 59; 57, 62; 58, identifier:minX; 59, binary_operator:+; 59, 60; 59, 61; 60, identifier:maxX; 61, float:1e-5; 62, binary_operator:+; 62, 63; 62, 64; 63, identifier:bins; 64, integer:1; 65, return_statement; 65, 66; 66, expression_list; 66, 67; 66, 85; 67, call; 67, 68; 67, 81; 68, attribute; 68, 69; 68, 80; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:np; 72, identifier:digitize; 73, argument_list; 73, 74; 73, 79; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:x; 77, identifier:ravel; 78, argument_list; 79, identifier:bins; 80, identifier:reshape; 81, argument_list; 81, 82; 82, attribute; 82, 83; 82, 84; 83, identifier:x; 84, identifier:shape; 85, identifier:bins | def bin(x, bins, maxX=None, minX=None):
'''
bin signal x using 'binsN' bin. If minX, maxX are None, they default to the full
range of the signal. If they are not None, everything above maxX gets assigned to
binsN-1 and everything below minX gets assigned to 0, this is effectively the same
as clipping x before passing it to 'bin'
input:
-----
x: signal to be binned, some sort of iterable
bins: int, number of bins
iterable, bin edges
maxX: clips data above maxX
minX: clips data below maxX
output:
------
binnedX: x after being binned
bins: bins used for binning.
if input 'bins' is already an iterable it just returns the
same iterable
example:
bin(x, 10)
entropy)
binsN = 10
percentiles = list(np.arange(0, 100.1, 100/binsN))
bins = np.percentile(x, percentiles)
bin(x, bins)
'''
if maxX is None:
maxX = x.max()
if minX is None:
minX = x.min()
if not np.iterable(bins):
bins = np.linspace(minX, maxX+1e-5, bins+1)
return np.digitize(x.ravel(), bins).reshape(x.shape), bins |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 28; 2, function_name:update_item; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 3, 13; 3, 16; 3, 19; 3, 22; 3, 25; 4, identifier:self; 5, identifier:table_name; 6, identifier:key_dict; 7, default_parameter; 7, 8; 7, 9; 8, identifier:condition_expression; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:update_expression; 12, None; 13, default_parameter; 13, 14; 13, 15; 14, identifier:expression_attribute_names; 15, None; 16, default_parameter; 16, 17; 16, 18; 17, identifier:expression_attribute_values; 18, None; 19, default_parameter; 19, 20; 19, 21; 20, identifier:return_consumed_capacity; 21, None; 22, default_parameter; 22, 23; 22, 24; 23, identifier:return_item_collection_metrics; 24, None; 25, default_parameter; 25, 26; 25, 27; 26, identifier:return_values; 27, None; 28, block; 28, 29; 28, 47; 28, 56; 28, 65; 28, 80; 28, 94; 28, 109; 28, 123; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:payload; 32, dictionary; 32, 33; 32, 36; 32, 44; 33, pair; 33, 34; 33, 35; 34, string:'TableName'; 35, identifier:table_name; 36, pair; 36, 37; 36, 38; 37, string:'Key'; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:utils; 41, identifier:marshall; 42, argument_list; 42, 43; 43, identifier:key_dict; 44, pair; 44, 45; 44, 46; 45, string:'UpdateExpression'; 46, identifier:update_expression; 47, if_statement; 47, 48; 47, 49; 48, identifier:condition_expression; 49, block; 49, 50; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 55; 52, subscript; 52, 53; 52, 54; 53, identifier:payload; 54, string:'ConditionExpression'; 55, identifier:condition_expression; 56, if_statement; 56, 57; 56, 58; 57, identifier:expression_attribute_names; 58, block; 58, 59; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 64; 61, subscript; 61, 62; 61, 63; 62, identifier:payload; 63, string:'ExpressionAttributeNames'; 64, identifier:expression_attribute_names; 65, if_statement; 65, 66; 65, 67; 66, identifier:expression_attribute_values; 67, block; 67, 68; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 73; 69, 74; 70, subscript; 70, 71; 70, 72; 71, identifier:payload; 72, string:'ExpressionAttributeValues'; 73, line_continuation:\; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:utils; 77, identifier:marshall; 78, argument_list; 78, 79; 79, identifier:expression_attribute_values; 80, if_statement; 80, 81; 80, 82; 81, identifier:return_consumed_capacity; 82, block; 82, 83; 82, 88; 83, expression_statement; 83, 84; 84, call; 84, 85; 84, 86; 85, identifier:_validate_return_consumed_capacity; 86, argument_list; 86, 87; 87, identifier:return_consumed_capacity; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 93; 90, subscript; 90, 91; 90, 92; 91, identifier:payload; 92, string:'ReturnConsumedCapacity'; 93, identifier:return_consumed_capacity; 94, if_statement; 94, 95; 94, 96; 95, identifier:return_item_collection_metrics; 96, block; 96, 97; 96, 102; 97, expression_statement; 97, 98; 98, call; 98, 99; 98, 100; 99, identifier:_validate_return_item_collection_metrics; 100, argument_list; 100, 101; 101, identifier:return_item_collection_metrics; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 107; 103, 108; 104, subscript; 104, 105; 104, 106; 105, identifier:payload; 106, string:'ReturnItemCollectionMetrics'; 107, line_continuation:\; 108, identifier:return_item_collection_metrics; 109, if_statement; 109, 110; 109, 111; 110, identifier:return_values; 111, block; 111, 112; 111, 117; 112, expression_statement; 112, 113; 113, call; 113, 114; 113, 115; 114, identifier:_validate_return_values; 115, argument_list; 115, 116; 116, identifier:return_values; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 122; 119, subscript; 119, 120; 119, 121; 120, identifier:payload; 121, string:'ReturnValues'; 122, identifier:return_values; 123, return_statement; 123, 124; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:self; 127, identifier:execute; 128, argument_list; 128, 129; 128, 130; 129, string:'UpdateItem'; 130, identifier:payload | def update_item(self, table_name, key_dict,
condition_expression=None,
update_expression=None,
expression_attribute_names=None,
expression_attribute_values=None,
return_consumed_capacity=None,
return_item_collection_metrics=None,
return_values=None):
payload = {'TableName': table_name,
'Key': utils.marshall(key_dict),
'UpdateExpression': update_expression}
if condition_expression:
payload['ConditionExpression'] = condition_expression
if expression_attribute_names:
payload['ExpressionAttributeNames'] = expression_attribute_names
if expression_attribute_values:
payload['ExpressionAttributeValues'] = \
utils.marshall(expression_attribute_values)
if return_consumed_capacity:
_validate_return_consumed_capacity(return_consumed_capacity)
payload['ReturnConsumedCapacity'] = return_consumed_capacity
if return_item_collection_metrics:
_validate_return_item_collection_metrics(
return_item_collection_metrics)
payload['ReturnItemCollectionMetrics'] = \
return_item_collection_metrics
if return_values:
_validate_return_values(return_values)
payload['ReturnValues'] = return_values
return self.execute('UpdateItem', payload) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 42; 2, function_name:query; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 3, 24; 3, 27; 3, 30; 3, 33; 3, 36; 3, 39; 4, identifier:self; 5, identifier:table_name; 6, default_parameter; 6, 7; 6, 8; 7, identifier:index_name; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:consistent_read; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:key_condition_expression; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:filter_expression; 17, None; 18, default_parameter; 18, 19; 18, 20; 19, identifier:expression_attribute_names; 20, None; 21, default_parameter; 21, 22; 21, 23; 22, identifier:expression_attribute_values; 23, None; 24, default_parameter; 24, 25; 24, 26; 25, identifier:projection_expression; 26, None; 27, default_parameter; 27, 28; 27, 29; 28, identifier:select; 29, None; 30, default_parameter; 30, 31; 30, 32; 31, identifier:exclusive_start_key; 32, None; 33, default_parameter; 33, 34; 33, 35; 34, identifier:limit; 35, None; 36, default_parameter; 36, 37; 36, 38; 37, identifier:scan_index_forward; 38, True; 39, default_parameter; 39, 40; 39, 41; 40, identifier:return_consumed_capacity; 41, None; 42, block; 42, 43; 42, 53; 42, 62; 42, 73; 42, 82; 42, 91; 42, 100; 42, 115; 42, 124; 42, 138; 42, 152; 42, 161; 42, 175; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:payload; 46, dictionary; 46, 47; 46, 50; 47, pair; 47, 48; 47, 49; 48, string:'TableName'; 49, identifier:table_name; 50, pair; 50, 51; 50, 52; 51, string:'ScanIndexForward'; 52, identifier:scan_index_forward; 53, if_statement; 53, 54; 53, 55; 54, identifier:index_name; 55, block; 55, 56; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 61; 58, subscript; 58, 59; 58, 60; 59, identifier:payload; 60, string:'IndexName'; 61, identifier:index_name; 62, if_statement; 62, 63; 62, 66; 63, comparison_operator:is; 63, 64; 63, 65; 64, identifier:consistent_read; 65, None; 66, block; 66, 67; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 72; 69, subscript; 69, 70; 69, 71; 70, identifier:payload; 71, string:'ConsistentRead'; 72, identifier:consistent_read; 73, if_statement; 73, 74; 73, 75; 74, identifier:key_condition_expression; 75, block; 75, 76; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 81; 78, subscript; 78, 79; 78, 80; 79, identifier:payload; 80, string:'KeyConditionExpression'; 81, identifier:key_condition_expression; 82, if_statement; 82, 83; 82, 84; 83, identifier:filter_expression; 84, block; 84, 85; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 90; 87, subscript; 87, 88; 87, 89; 88, identifier:payload; 89, string:'FilterExpression'; 90, identifier:filter_expression; 91, if_statement; 91, 92; 91, 93; 92, identifier:expression_attribute_names; 93, block; 93, 94; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 99; 96, subscript; 96, 97; 96, 98; 97, identifier:payload; 98, string:'ExpressionAttributeNames'; 99, identifier:expression_attribute_names; 100, if_statement; 100, 101; 100, 102; 101, identifier:expression_attribute_values; 102, block; 102, 103; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 108; 104, 109; 105, subscript; 105, 106; 105, 107; 106, identifier:payload; 107, string:'ExpressionAttributeValues'; 108, line_continuation:\; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:utils; 112, identifier:marshall; 113, argument_list; 113, 114; 114, identifier:expression_attribute_values; 115, if_statement; 115, 116; 115, 117; 116, identifier:projection_expression; 117, block; 117, 118; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 123; 120, subscript; 120, 121; 120, 122; 121, identifier:payload; 122, string:'ProjectionExpression'; 123, identifier:projection_expression; 124, if_statement; 124, 125; 124, 126; 125, identifier:select; 126, block; 126, 127; 126, 132; 127, expression_statement; 127, 128; 128, call; 128, 129; 128, 130; 129, identifier:_validate_select; 130, argument_list; 130, 131; 131, identifier:select; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 137; 134, subscript; 134, 135; 134, 136; 135, identifier:payload; 136, string:'Select'; 137, identifier:select; 138, if_statement; 138, 139; 138, 140; 139, identifier:exclusive_start_key; 140, block; 140, 141; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 146; 143, subscript; 143, 144; 143, 145; 144, identifier:payload; 145, string:'ExclusiveStartKey'; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:utils; 149, identifier:marshall; 150, argument_list; 150, 151; 151, identifier:exclusive_start_key; 152, if_statement; 152, 153; 152, 154; 153, identifier:limit; 154, block; 154, 155; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 160; 157, subscript; 157, 158; 157, 159; 158, identifier:payload; 159, string:'Limit'; 160, identifier:limit; 161, if_statement; 161, 162; 161, 163; 162, identifier:return_consumed_capacity; 163, block; 163, 164; 163, 169; 164, expression_statement; 164, 165; 165, call; 165, 166; 165, 167; 166, identifier:_validate_return_consumed_capacity; 167, argument_list; 167, 168; 168, identifier:return_consumed_capacity; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 174; 171, subscript; 171, 172; 171, 173; 172, identifier:payload; 173, string:'ReturnConsumedCapacity'; 174, identifier:return_consumed_capacity; 175, return_statement; 175, 176; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:self; 179, identifier:execute; 180, argument_list; 180, 181; 180, 182; 181, string:'Query'; 182, identifier:payload | def query(self, table_name,
index_name=None,
consistent_read=None,
key_condition_expression=None,
filter_expression=None,
expression_attribute_names=None,
expression_attribute_values=None,
projection_expression=None,
select=None,
exclusive_start_key=None,
limit=None,
scan_index_forward=True,
return_consumed_capacity=None):
payload = {'TableName': table_name,
'ScanIndexForward': scan_index_forward}
if index_name:
payload['IndexName'] = index_name
if consistent_read is not None:
payload['ConsistentRead'] = consistent_read
if key_condition_expression:
payload['KeyConditionExpression'] = key_condition_expression
if filter_expression:
payload['FilterExpression'] = filter_expression
if expression_attribute_names:
payload['ExpressionAttributeNames'] = expression_attribute_names
if expression_attribute_values:
payload['ExpressionAttributeValues'] = \
utils.marshall(expression_attribute_values)
if projection_expression:
payload['ProjectionExpression'] = projection_expression
if select:
_validate_select(select)
payload['Select'] = select
if exclusive_start_key:
payload['ExclusiveStartKey'] = utils.marshall(exclusive_start_key)
if limit:
payload['Limit'] = limit
if return_consumed_capacity:
_validate_return_consumed_capacity(return_consumed_capacity)
payload['ReturnConsumedCapacity'] = return_consumed_capacity
return self.execute('Query', payload) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 4; 2, function_name:get_gae_versions; 3, parameters; 4, block; 4, 5; 4, 14; 4, 20; 4, 34; 4, 38; 4, 80; 5, expression_statement; 5, 6; 6, assignment; 6, 7; 6, 8; 7, identifier:r; 8, call; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:requests; 11, identifier:get; 12, argument_list; 12, 13; 13, identifier:SDK_RELEASES_URL; 14, expression_statement; 14, 15; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:r; 18, identifier:raise_for_status; 19, argument_list; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:releases; 23, call; 23, 24; 23, 31; 24, attribute; 24, 25; 24, 30; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:r; 28, identifier:json; 29, argument_list; 30, identifier:get; 31, argument_list; 31, 32; 31, 33; 32, string:'items'; 33, dictionary; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:versions_and_urls; 37, list:[]; 38, for_statement; 38, 39; 38, 40; 38, 41; 39, identifier:release; 40, identifier:releases; 41, block; 41, 42; 41, 53; 41, 58; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:match; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:PYTHON_RELEASE_RE; 48, identifier:match; 49, argument_list; 49, 50; 50, subscript; 50, 51; 50, 52; 51, identifier:release; 52, string:'name'; 53, if_statement; 53, 54; 53, 56; 54, not_operator; 54, 55; 55, identifier:match; 56, block; 56, 57; 57, continue_statement; 58, expression_statement; 58, 59; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:versions_and_urls; 62, identifier:append; 63, argument_list; 63, 64; 64, tuple; 64, 65; 64, 77; 65, list_comprehension; 65, 66; 65, 70; 66, call; 66, 67; 66, 68; 67, identifier:int; 68, argument_list; 68, 69; 69, identifier:x; 70, for_in_clause; 70, 71; 70, 72; 71, identifier:x; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:match; 75, identifier:groups; 76, argument_list; 77, subscript; 77, 78; 77, 79; 78, identifier:release; 79, string:'mediaLink'; 80, return_statement; 80, 81; 81, call; 81, 82; 81, 83; 82, identifier:sorted; 83, argument_list; 83, 84; 83, 85; 84, identifier:versions_and_urls; 85, keyword_argument; 85, 86; 85, 87; 86, identifier:key; 87, lambda; 87, 88; 87, 90; 88, lambda_parameters; 88, 89; 89, identifier:x; 90, subscript; 90, 91; 90, 92; 91, identifier:x; 92, integer:0 | def get_gae_versions():
r = requests.get(SDK_RELEASES_URL)
r.raise_for_status()
releases = r.json().get('items', {})
versions_and_urls = []
for release in releases:
match = PYTHON_RELEASE_RE.match(release['name'])
if not match:
continue
versions_and_urls.append(
([int(x) for x in match.groups()], release['mediaLink']))
return sorted(versions_and_urls, key=lambda x: x[0]) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 1, 20; 2, function_name:_parse_options; 3, parameters; 3, 4; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:options; 6, type; 6, 7; 7, generic_type; 7, 8; 7, 9; 8, identifier:List; 9, type_parameter; 9, 10; 10, type; 10, 11; 11, identifier:str; 12, type; 12, 13; 13, generic_type; 13, 14; 13, 15; 14, identifier:Dict; 15, type_parameter; 15, 16; 15, 18; 16, type; 16, 17; 17, identifier:str; 18, type; 18, 19; 19, identifier:str; 20, block; 20, 21; 21, try_statement; 21, 22; 21, 39; 22, block; 22, 23; 23, return_statement; 23, 24; 24, call; 24, 25; 24, 26; 25, identifier:dict; 26, generator_expression; 26, 27; 26, 36; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:i; 30, identifier:split; 31, argument_list; 31, 32; 31, 33; 32, string:'='; 33, keyword_argument; 33, 34; 33, 35; 34, identifier:maxsplit; 35, integer:1; 36, for_in_clause; 36, 37; 36, 38; 37, identifier:i; 38, identifier:options; 39, except_clause; 39, 40; 39, 41; 40, identifier:ValueError; 41, block; 41, 42; 42, raise_statement; 42, 43; 43, call; 43, 44; 43, 45; 44, identifier:ArgumentError; 45, argument_list; 45, 46; 46, string:f'Option must be in format <key>=<value>, got: {options}' | def _parse_options(options: List[str]) -> Dict[str, str]:
try:
return dict(i.split('=', maxsplit=1) for i in options)
except ValueError:
raise ArgumentError(
f'Option must be in format <key>=<value>, got: {options}') |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:collapse; 3, parameters; 3, 4; 3, 5; 4, identifier:l; 5, identifier:raw; 6, block; 6, 7; 6, 14; 6, 18; 6, 22; 6, 211; 6, 218; 7, expression_statement; 7, 8; 8, call; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:logger_ts; 11, identifier:info; 12, argument_list; 12, 13; 13, string:"enter collapse"; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:_master; 17, dictionary; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:_dsn; 21, string:""; 22, try_statement; 22, 23; 22, 183; 23, block; 23, 24; 23, 32; 23, 149; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:_pc; 27, subscript; 27, 28; 27, 31; 28, subscript; 28, 29; 28, 30; 29, identifier:l; 30, integer:0; 31, string:"mode"; 32, for_statement; 32, 33; 32, 34; 32, 35; 33, identifier:entry; 34, identifier:l; 35, block; 35, 36; 35, 42; 35, 46; 35, 50; 35, 139; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:dsn; 39, subscript; 39, 40; 39, 41; 40, identifier:entry; 41, string:'dataSetName'; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:_dsn; 45, identifier:dsn; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:_current; 49, identifier:entry; 50, if_statement; 50, 51; 50, 54; 51, comparison_operator:not; 51, 52; 51, 53; 52, identifier:dsn; 53, identifier:_master; 54, block; 54, 55; 54, 67; 54, 77; 54, 89; 55, expression_statement; 55, 56; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:logger_ts; 59, identifier:info; 60, argument_list; 60, 61; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, string:"collapsing: {}"; 64, identifier:format; 65, argument_list; 65, 66; 66, identifier:dsn; 67, expression_statement; 67, 68; 68, call; 68, 69; 68, 70; 69, identifier:print; 70, argument_list; 70, 71; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, string:"collapsing: {}"; 74, identifier:format; 75, argument_list; 75, 76; 76, identifier:dsn; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 82; 79, pattern_list; 79, 80; 79, 81; 80, identifier:_master; 81, identifier:_current; 82, call; 82, 83; 82, 84; 83, identifier:_collapse_root; 84, argument_list; 84, 85; 84, 86; 84, 87; 84, 88; 85, identifier:_master; 86, identifier:_current; 87, identifier:dsn; 88, identifier:_pc; 89, try_statement; 89, 90; 89, 122; 90, block; 90, 91; 90, 103; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 98; 93, subscript; 93, 94; 93, 97; 94, subscript; 94, 95; 94, 96; 95, identifier:_master; 96, identifier:dsn; 97, string:"paleoData"; 98, subscript; 98, 99; 98, 102; 99, subscript; 99, 100; 99, 101; 100, identifier:raw; 101, identifier:dsn; 102, string:"paleoData"; 103, if_statement; 103, 104; 103, 109; 104, comparison_operator:in; 104, 105; 104, 106; 105, string:"chronData"; 106, subscript; 106, 107; 106, 108; 107, identifier:raw; 108, identifier:dsn; 109, block; 109, 110; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 117; 112, subscript; 112, 113; 112, 116; 113, subscript; 113, 114; 113, 115; 114, identifier:_master; 115, identifier:dsn; 116, string:"chronData"; 117, subscript; 117, 118; 117, 121; 118, subscript; 118, 119; 118, 120; 119, identifier:raw; 120, identifier:dsn; 121, string:"chronData"; 122, except_clause; 122, 123; 122, 127; 123, as_pattern; 123, 124; 123, 125; 124, identifier:KeyError; 125, as_pattern_target; 125, 126; 126, identifier:e; 127, block; 127, 128; 128, expression_statement; 128, 129; 129, call; 129, 130; 129, 131; 130, identifier:print; 131, argument_list; 131, 132; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, string:"collapse: Could not collapse an object the dataset: {}, {}"; 135, identifier:format; 136, argument_list; 136, 137; 136, 138; 137, identifier:dsn; 138, identifier:e; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:_master; 142, call; 142, 143; 142, 144; 143, identifier:_collapse_pc; 144, argument_list; 144, 145; 144, 146; 144, 147; 144, 148; 145, identifier:_master; 146, identifier:_current; 147, identifier:dsn; 148, identifier:_pc; 149, if_statement; 149, 150; 149, 156; 149, 168; 150, comparison_operator:==; 150, 151; 150, 155; 151, call; 151, 152; 151, 153; 152, identifier:len; 153, argument_list; 153, 154; 154, identifier:_master; 155, integer:1; 156, block; 156, 157; 156, 163; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:_master; 160, subscript; 160, 161; 160, 162; 161, identifier:_master; 162, identifier:_dsn; 163, expression_statement; 163, 164; 164, call; 164, 165; 164, 166; 165, identifier:print; 166, argument_list; 166, 167; 167, string:"Created LiPD data: 1 dataset"; 168, else_clause; 168, 169; 169, block; 169, 170; 170, expression_statement; 170, 171; 171, call; 171, 172; 171, 173; 172, identifier:print; 173, argument_list; 173, 174; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, string:"Created LiPD data: {} datasets"; 177, identifier:format; 178, argument_list; 178, 179; 179, call; 179, 180; 179, 181; 180, identifier:len; 181, argument_list; 181, 182; 182, identifier:_master; 183, except_clause; 183, 184; 183, 188; 184, as_pattern; 184, 185; 184, 186; 185, identifier:Exception; 186, as_pattern_target; 186, 187; 187, identifier:e; 188, block; 188, 189; 188, 199; 189, expression_statement; 189, 190; 190, call; 190, 191; 190, 192; 191, identifier:print; 192, argument_list; 192, 193; 193, call; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, string:"Error: Unable to collapse time series, {}"; 196, identifier:format; 197, argument_list; 197, 198; 198, identifier:e; 199, expression_statement; 199, 200; 200, call; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:logger_ts; 203, identifier:error; 204, argument_list; 204, 205; 205, call; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, string:"collapse: Exception: {}"; 208, identifier:format; 209, argument_list; 209, 210; 210, identifier:e; 211, expression_statement; 211, 212; 212, call; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:logger_ts; 215, identifier:info; 216, argument_list; 216, 217; 217, string:"exit collapse"; 218, return_statement; 218, 219; 219, identifier:_master | def collapse(l, raw):
logger_ts.info("enter collapse")
_master = {}
_dsn = ""
try:
_pc = l[0]["mode"]
for entry in l:
dsn = entry['dataSetName']
_dsn = dsn
_current = entry
if dsn not in _master:
logger_ts.info("collapsing: {}".format(dsn))
print("collapsing: {}".format(dsn))
_master, _current = _collapse_root(_master, _current, dsn, _pc)
try:
_master[dsn]["paleoData"] = raw[dsn]["paleoData"]
if "chronData" in raw[dsn]:
_master[dsn]["chronData"] = raw[dsn]["chronData"]
except KeyError as e:
print("collapse: Could not collapse an object the dataset: {}, {}".format(dsn, e))
_master = _collapse_pc(_master, _current, dsn, _pc)
if len(_master) == 1:
_master = _master[_dsn]
print("Created LiPD data: 1 dataset")
else:
print("Created LiPD data: {} datasets".format(len(_master)))
except Exception as e:
print("Error: Unable to collapse time series, {}".format(e))
logger_ts.error("collapse: Exception: {}".format(e))
logger_ts.info("exit collapse")
return _master |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:collapseTs; 3, parameters; 3, 4; 4, default_parameter; 4, 5; 4, 6; 5, identifier:ts; 6, None; 7, block; 7, 8; 7, 10; 7, 14; 7, 94; 8, global_statement; 8, 9; 9, identifier:_timeseries_data; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:_d; 13, dictionary; 14, if_statement; 14, 15; 14, 17; 14, 23; 15, not_operator; 15, 16; 16, identifier:ts; 17, block; 17, 18; 18, expression_statement; 18, 19; 19, call; 19, 20; 19, 21; 20, identifier:print; 21, argument_list; 21, 22; 22, string:"Error: Time series data not provided. Pass time series into the function."; 23, else_clause; 23, 24; 24, block; 24, 25; 25, try_statement; 25, 26; 25, 66; 26, block; 26, 27; 26, 37; 26, 51; 26, 59; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:_raw; 30, subscript; 30, 31; 30, 32; 31, identifier:_timeseries_data; 32, subscript; 32, 33; 32, 36; 33, subscript; 33, 34; 33, 35; 34, identifier:ts; 35, integer:0; 36, string:"time_id"; 37, expression_statement; 37, 38; 38, call; 38, 39; 38, 40; 39, identifier:print; 40, argument_list; 40, 41; 41, call; 41, 42; 41, 43; 42, identifier:mode_ts; 43, argument_list; 43, 44; 43, 45; 43, 48; 44, string:"collapse"; 45, keyword_argument; 45, 46; 45, 47; 46, identifier:mode; 47, string:""; 48, keyword_argument; 48, 49; 48, 50; 49, identifier:ts; 50, identifier:ts; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:_d; 54, call; 54, 55; 54, 56; 55, identifier:collapse; 56, argument_list; 56, 57; 56, 58; 57, identifier:ts; 58, identifier:_raw; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:_d; 62, call; 62, 63; 62, 64; 63, identifier:rm_empty_fields; 64, argument_list; 64, 65; 65, identifier:_d; 66, except_clause; 66, 67; 66, 71; 67, as_pattern; 67, 68; 67, 69; 68, identifier:Exception; 69, as_pattern_target; 69, 70; 70, identifier:e; 71, block; 71, 72; 71, 82; 72, expression_statement; 72, 73; 73, call; 73, 74; 73, 75; 74, identifier:print; 75, argument_list; 75, 76; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, string:"Error: Unable to collapse the time series: {}"; 79, identifier:format; 80, argument_list; 80, 81; 81, identifier:e; 82, expression_statement; 82, 83; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:logger_start; 86, identifier:error; 87, argument_list; 87, 88; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, string:"collapseTs: unable to collapse the time series: {}"; 91, identifier:format; 92, argument_list; 92, 93; 93, identifier:e; 94, return_statement; 94, 95; 95, identifier:_d | def collapseTs(ts=None):
global _timeseries_data
_d = {}
if not ts:
print("Error: Time series data not provided. Pass time series into the function.")
else:
try:
_raw = _timeseries_data[ts[0]["time_id"]]
print(mode_ts("collapse", mode="", ts=ts))
_d = collapse(ts, _raw)
_d = rm_empty_fields(_d)
except Exception as e:
print("Error: Unable to collapse the time series: {}".format(e))
logger_start.error("collapseTs: unable to collapse the time series: {}".format(e))
return _d |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:display_results; 3, parameters; 3, 4; 3, 5; 4, identifier:results; 5, default_parameter; 5, 6; 5, 7; 6, identifier:detailed; 7, False; 8, block; 8, 9; 8, 18; 8, 92; 9, if_statement; 9, 10; 9, 12; 10, not_operator; 10, 11; 11, identifier:detailed; 12, block; 12, 13; 13, expression_statement; 13, 14; 14, call; 14, 15; 14, 16; 15, identifier:print; 16, argument_list; 16, 17; 17, string:'FILENAME......................................... STATUS..........'; 18, for_statement; 18, 19; 18, 20; 18, 21; 19, identifier:entry; 20, identifier:results; 21, block; 21, 22; 22, try_statement; 22, 23; 22, 64; 23, block; 23, 24; 24, if_statement; 24, 25; 24, 26; 24, 47; 25, identifier:detailed; 26, block; 26, 27; 26, 39; 27, expression_statement; 27, 28; 28, call; 28, 29; 28, 30; 29, identifier:print; 30, argument_list; 30, 31; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, string:"\n{}"; 34, identifier:format; 35, argument_list; 35, 36; 36, subscript; 36, 37; 36, 38; 37, identifier:entry; 38, string:"filename"; 39, expression_statement; 39, 40; 40, call; 40, 41; 40, 42; 41, identifier:print; 42, argument_list; 42, 43; 43, call; 43, 44; 43, 45; 44, identifier:create_detailed_results; 45, argument_list; 45, 46; 46, identifier:entry; 47, else_clause; 47, 48; 48, block; 48, 49; 49, expression_statement; 49, 50; 50, call; 50, 51; 50, 52; 51, identifier:print; 52, argument_list; 52, 53; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, string:"{:<50}{}"; 56, identifier:format; 57, argument_list; 57, 58; 57, 61; 58, subscript; 58, 59; 58, 60; 59, identifier:entry; 60, string:"filename"; 61, subscript; 61, 62; 61, 63; 62, identifier:entry; 63, string:"status"; 64, except_clause; 64, 65; 64, 69; 65, as_pattern; 65, 66; 65, 67; 66, identifier:Exception; 67, as_pattern_target; 67, 68; 68, identifier:e; 69, block; 69, 70; 69, 82; 70, expression_statement; 70, 71; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:logger_validator_api; 74, identifier:debug; 75, argument_list; 75, 76; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, string:"display_results: Exception: {}"; 79, identifier:format; 80, argument_list; 80, 81; 81, identifier:e; 82, expression_statement; 82, 83; 83, call; 83, 84; 83, 85; 84, identifier:print; 85, argument_list; 85, 86; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, string:"Error: display_results: {}"; 89, identifier:format; 90, argument_list; 90, 91; 91, identifier:e; 92, return_statement | def display_results(results, detailed=False):
if not detailed:
print('FILENAME......................................... STATUS..........')
for entry in results:
try:
if detailed:
print("\n{}".format(entry["filename"]))
print(create_detailed_results(entry))
else:
print("{:<50}{}".format(entry["filename"], entry["status"]))
except Exception as e:
logger_validator_api.debug("display_results: Exception: {}".format(e))
print("Error: display_results: {}".format(e))
return |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:call_validator_api; 3, parameters; 3, 4; 3, 5; 4, identifier:dsn; 5, identifier:api_data; 6, block; 6, 7; 6, 13; 6, 241; 6, 261; 6, 267; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:_filename; 10, binary_operator:+; 10, 11; 10, 12; 11, identifier:dsn; 12, string:".lpd"; 13, try_statement; 13, 14; 13, 130; 13, 164; 13, 202; 14, block; 14, 15; 14, 24; 14, 34; 14, 46; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:api_data; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:json; 21, identifier:dumps; 22, argument_list; 22, 23; 23, identifier:api_data; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:payload; 27, dictionary; 27, 28; 27, 31; 28, pair; 28, 29; 28, 30; 29, string:'json_payload'; 30, identifier:api_data; 31, pair; 31, 32; 31, 33; 32, string:'apikey'; 33, string:'lipd_linked'; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:response; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:requests; 40, identifier:post; 41, argument_list; 41, 42; 41, 43; 42, string:'http://www.lipd.net/api/validator'; 43, keyword_argument; 43, 44; 43, 45; 44, identifier:data; 45, identifier:payload; 46, if_statement; 46, 47; 46, 52; 46, 69; 46, 92; 46, 117; 47, comparison_operator:==; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:response; 50, identifier:status_code; 51, integer:413; 52, block; 52, 53; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:result; 56, dictionary; 56, 57; 56, 60; 56, 63; 56, 66; 57, pair; 57, 58; 57, 59; 58, string:"dat"; 59, dictionary; 60, pair; 60, 61; 60, 62; 61, string:"feedback"; 62, dictionary; 63, pair; 63, 64; 63, 65; 64, string:"filename"; 65, identifier:_filename; 66, pair; 66, 67; 66, 68; 67, string:"status"; 68, string:"HTTP 413: Request Entity Too Large"; 69, elif_clause; 69, 70; 69, 75; 70, comparison_operator:==; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:response; 73, identifier:status_code; 74, integer:404; 75, block; 75, 76; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:result; 79, dictionary; 79, 80; 79, 83; 79, 86; 79, 89; 80, pair; 80, 81; 80, 82; 81, string:"dat"; 82, dictionary; 83, pair; 83, 84; 83, 85; 84, string:"feedback"; 85, dictionary; 86, pair; 86, 87; 86, 88; 87, string:"filename"; 88, identifier:_filename; 89, pair; 89, 90; 89, 91; 90, string:"status"; 91, string:"HTTP 404: Not Found"; 92, elif_clause; 92, 93; 92, 98; 93, comparison_operator:==; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:response; 96, identifier:status_code; 97, integer:400; 98, block; 98, 99; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:result; 102, dictionary; 102, 103; 102, 106; 102, 109; 102, 112; 103, pair; 103, 104; 103, 105; 104, string:"dat"; 105, dictionary; 106, pair; 106, 107; 106, 108; 107, string:"feedback"; 108, dictionary; 109, pair; 109, 110; 109, 111; 110, string:"filename"; 111, identifier:_filename; 112, pair; 112, 113; 112, 114; 113, string:"status"; 114, attribute; 114, 115; 114, 116; 115, identifier:response; 116, identifier:text; 117, else_clause; 117, 118; 118, block; 118, 119; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:result; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:json; 125, identifier:loads; 126, argument_list; 126, 127; 127, attribute; 127, 128; 127, 129; 128, identifier:response; 129, identifier:text; 130, except_clause; 130, 131; 130, 135; 131, as_pattern; 131, 132; 131, 133; 132, identifier:TypeError; 133, as_pattern_target; 133, 134; 134, identifier:e; 135, block; 135, 136; 135, 148; 136, expression_statement; 136, 137; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:logger_validator_api; 140, identifier:warning; 141, argument_list; 141, 142; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, string:"get_validator_results: TypeError: {}"; 145, identifier:format; 146, argument_list; 146, 147; 147, identifier:e; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 151; 150, identifier:result; 151, dictionary; 151, 152; 151, 155; 151, 158; 151, 161; 152, pair; 152, 153; 152, 154; 153, string:"dat"; 154, dictionary; 155, pair; 155, 156; 155, 157; 156, string:"feedback"; 157, dictionary; 158, pair; 158, 159; 158, 160; 159, string:"filename"; 160, identifier:_filename; 161, pair; 161, 162; 161, 163; 162, string:"status"; 163, string:"JSON DECODE ERROR"; 164, except_clause; 164, 165; 164, 173; 165, as_pattern; 165, 166; 165, 171; 166, attribute; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:requests; 169, identifier:exceptions; 170, identifier:ConnectionError; 171, as_pattern_target; 171, 172; 172, identifier:e; 173, block; 173, 174; 173, 186; 174, expression_statement; 174, 175; 175, call; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:logger_validator_api; 178, identifier:warning; 179, argument_list; 179, 180; 180, call; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, string:"get_validator_results: ConnectionError: {}"; 183, identifier:format; 184, argument_list; 184, 185; 185, identifier:e; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 189; 188, identifier:result; 189, dictionary; 189, 190; 189, 193; 189, 196; 189, 199; 190, pair; 190, 191; 190, 192; 191, string:"dat"; 192, dictionary; 193, pair; 193, 194; 193, 195; 194, string:"feedback"; 195, dictionary; 196, pair; 196, 197; 196, 198; 197, string:"filename"; 198, identifier:_filename; 199, pair; 199, 200; 199, 201; 200, string:"status"; 201, string:"UNABLE TO REACH SERVER"; 202, except_clause; 202, 203; 202, 207; 203, as_pattern; 203, 204; 203, 205; 204, identifier:Exception; 205, as_pattern_target; 205, 206; 206, identifier:e; 207, block; 207, 208; 207, 220; 208, expression_statement; 208, 209; 209, call; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:logger_validator_api; 212, identifier:debug; 213, argument_list; 213, 214; 214, call; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, string:"get_validator_results: Exception: {}"; 217, identifier:format; 218, argument_list; 218, 219; 219, identifier:e; 220, expression_statement; 220, 221; 221, assignment; 221, 222; 221, 223; 222, identifier:result; 223, dictionary; 223, 224; 223, 227; 223, 230; 223, 233; 224, pair; 224, 225; 224, 226; 225, string:"dat"; 226, dictionary; 227, pair; 227, 228; 227, 229; 228, string:"feedback"; 229, dictionary; 230, pair; 230, 231; 230, 232; 231, string:"filename"; 232, identifier:_filename; 233, pair; 233, 234; 233, 235; 234, string:"status"; 235, call; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, string:"ERROR BEFORE VALIDATION, {}"; 238, identifier:format; 239, argument_list; 239, 240; 240, identifier:e; 241, if_statement; 241, 242; 241, 244; 242, not_operator; 242, 243; 243, identifier:result; 244, block; 244, 245; 245, expression_statement; 245, 246; 246, assignment; 246, 247; 246, 248; 247, identifier:result; 248, dictionary; 248, 249; 248, 252; 248, 255; 248, 258; 249, pair; 249, 250; 249, 251; 250, string:"dat"; 251, dictionary; 252, pair; 252, 253; 252, 254; 253, string:"feedback"; 254, dictionary; 255, pair; 255, 256; 255, 257; 256, string:"filename"; 257, identifier:_filename; 258, pair; 258, 259; 258, 260; 259, string:"status"; 260, string:"EMPTY RESPONSE"; 261, expression_statement; 261, 262; 262, assignment; 262, 263; 262, 266; 263, subscript; 263, 264; 263, 265; 264, identifier:result; 265, string:"filename"; 266, identifier:_filename; 267, return_statement; 267, 268; 268, identifier:result | def call_validator_api(dsn, api_data):
_filename = dsn + ".lpd"
try:
api_data = json.dumps(api_data)
payload = {'json_payload': api_data, 'apikey': 'lipd_linked'}
response = requests.post('http://www.lipd.net/api/validator', data=payload)
if response.status_code == 413:
result = {"dat": {}, "feedback": {}, "filename": _filename,
"status": "HTTP 413: Request Entity Too Large"}
elif response.status_code == 404:
result = {"dat": {}, "feedback": {}, "filename": _filename,
"status": "HTTP 404: Not Found"}
elif response.status_code == 400:
result = {"dat": {}, "feedback": {}, "filename": _filename,
"status": response.text}
else:
result = json.loads(response.text)
except TypeError as e:
logger_validator_api.warning("get_validator_results: TypeError: {}".format(e))
result = {"dat": {}, "feedback": {}, "filename": _filename, "status": "JSON DECODE ERROR"}
except requests.exceptions.ConnectionError as e:
logger_validator_api.warning("get_validator_results: ConnectionError: {}".format(e))
result = {"dat": {}, "feedback": {}, "filename": _filename, "status": "UNABLE TO REACH SERVER"}
except Exception as e:
logger_validator_api.debug("get_validator_results: Exception: {}".format(e))
result = {"dat": {}, "feedback": {}, "filename": _filename, "status": "ERROR BEFORE VALIDATION, {}".format(e)}
if not result:
result = {"dat": {}, "feedback": {}, "filename": _filename, "status": "EMPTY RESPONSE"}
result["filename"] = _filename
return result |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:create_back_links; 3, parameters; 3, 4; 4, identifier:env; 5, block; 5, 6; 5, 14; 5, 20; 5, 148; 6, if_statement; 6, 7; 6, 12; 7, subscript; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:env; 10, identifier:needs_workflow; 11, string:'backlink_creation'; 12, block; 12, 13; 13, return_statement; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:needs; 17, attribute; 17, 18; 17, 19; 18, identifier:env; 19, identifier:needs_all_needs; 20, for_statement; 20, 21; 20, 24; 20, 29; 21, pattern_list; 21, 22; 21, 23; 22, identifier:key; 23, identifier:need; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:needs; 27, identifier:items; 28, argument_list; 29, block; 29, 30; 30, for_statement; 30, 31; 30, 32; 30, 35; 31, identifier:link; 32, subscript; 32, 33; 32, 34; 33, identifier:need; 34, string:"links"; 35, block; 35, 36; 35, 47; 35, 67; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:link_main; 39, subscript; 39, 40; 39, 46; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:link; 43, identifier:split; 44, argument_list; 44, 45; 45, string:'.'; 46, integer:0; 47, try_statement; 47, 48; 47, 60; 48, block; 48, 49; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:link_part; 52, subscript; 52, 53; 52, 59; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:link; 56, identifier:split; 57, argument_list; 57, 58; 58, string:'.'; 59, integer:1; 60, except_clause; 60, 61; 60, 62; 61, identifier:IndexError; 62, block; 62, 63; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:link_part; 66, None; 67, if_statement; 67, 68; 67, 71; 68, comparison_operator:in; 68, 69; 68, 70; 69, identifier:link_main; 70, identifier:needs; 71, block; 71, 72; 71, 92; 72, if_statement; 72, 73; 72, 80; 73, comparison_operator:not; 73, 74; 73, 75; 74, identifier:key; 75, subscript; 75, 76; 75, 79; 76, subscript; 76, 77; 76, 78; 77, identifier:needs; 78, identifier:link_main; 79, string:"links_back"; 80, block; 80, 81; 81, expression_statement; 81, 82; 82, call; 82, 83; 82, 90; 83, attribute; 83, 84; 83, 89; 84, subscript; 84, 85; 84, 88; 85, subscript; 85, 86; 85, 87; 86, identifier:needs; 87, identifier:link_main; 88, string:"links_back"; 89, identifier:append; 90, argument_list; 90, 91; 91, identifier:key; 92, if_statement; 92, 93; 92, 96; 93, comparison_operator:is; 93, 94; 93, 95; 94, identifier:link_part; 95, None; 96, block; 96, 97; 97, if_statement; 97, 98; 97, 105; 98, comparison_operator:in; 98, 99; 98, 100; 99, identifier:link_part; 100, subscript; 100, 101; 100, 104; 101, subscript; 101, 102; 101, 103; 102, identifier:needs; 103, identifier:link_main; 104, string:'parts'; 105, block; 105, 106; 105, 133; 106, if_statement; 106, 107; 106, 120; 107, comparison_operator:not; 107, 108; 107, 109; 108, string:'links_back'; 109, call; 109, 110; 109, 119; 110, attribute; 110, 111; 110, 118; 111, subscript; 111, 112; 111, 117; 112, subscript; 112, 113; 112, 116; 113, subscript; 113, 114; 113, 115; 114, identifier:needs; 115, identifier:link_main; 116, string:'parts'; 117, identifier:link_part; 118, identifier:keys; 119, argument_list; 120, block; 120, 121; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 132; 123, subscript; 123, 124; 123, 131; 124, subscript; 124, 125; 124, 130; 125, subscript; 125, 126; 125, 129; 126, subscript; 126, 127; 126, 128; 127, identifier:needs; 128, identifier:link_main; 129, string:'parts'; 130, identifier:link_part; 131, string:'links_back'; 132, list:[]; 133, expression_statement; 133, 134; 134, call; 134, 135; 134, 146; 135, attribute; 135, 136; 135, 145; 136, subscript; 136, 137; 136, 144; 137, subscript; 137, 138; 137, 143; 138, subscript; 138, 139; 138, 142; 139, subscript; 139, 140; 139, 141; 140, identifier:needs; 141, identifier:link_main; 142, string:'parts'; 143, identifier:link_part; 144, string:'links_back'; 145, identifier:append; 146, argument_list; 146, 147; 147, identifier:key; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 155; 150, subscript; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:env; 153, identifier:needs_workflow; 154, string:'backlink_creation'; 155, True | def create_back_links(env):
if env.needs_workflow['backlink_creation']:
return
needs = env.needs_all_needs
for key, need in needs.items():
for link in need["links"]:
link_main = link.split('.')[0]
try:
link_part = link.split('.')[1]
except IndexError:
link_part = None
if link_main in needs:
if key not in needs[link_main]["links_back"]:
needs[link_main]["links_back"].append(key)
if link_part is not None:
if link_part in needs[link_main]['parts']:
if 'links_back' not in needs[link_main]['parts'][link_part].keys():
needs[link_main]['parts'][link_part]['links_back'] = []
needs[link_main]['parts'][link_part]['links_back'].append(key)
env.needs_workflow['backlink_creation'] = True |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:CaseGroups; 3, parameters; 3, 4; 4, default_parameter; 4, 5; 4, 6; 5, identifier:unicode_dir; 6, identifier:_UNICODE_DIR; 7, block; 7, 8; 7, 12; 7, 55; 7, 64; 7, 72; 7, 82; 7, 88; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:togroup; 11, dictionary; 12, function_definition; 12, 13; 12, 14; 12, 17; 13, function_name:DoLine; 14, parameters; 14, 15; 14, 16; 15, identifier:codes; 16, identifier:fields; 17, block; 17, 18; 17, 26; 17, 34; 17, 41; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 25; 20, tuple_pattern; 20, 21; 20, 22; 20, 23; 20, 24; 21, identifier:_; 22, identifier:foldtype; 23, identifier:lower; 24, identifier:_; 25, identifier:fields; 26, if_statement; 26, 27; 26, 32; 27, comparison_operator:not; 27, 28; 27, 29; 28, identifier:foldtype; 29, tuple; 29, 30; 29, 31; 30, string:"C"; 31, string:"S"; 32, block; 32, 33; 33, return_statement; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:lower; 37, call; 37, 38; 37, 39; 38, identifier:_UInt; 39, argument_list; 39, 40; 40, identifier:lower; 41, expression_statement; 41, 42; 42, call; 42, 43; 42, 53; 43, attribute; 43, 44; 43, 52; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:togroup; 47, identifier:setdefault; 48, argument_list; 48, 49; 48, 50; 49, identifier:lower; 50, list:[lower]; 50, 51; 51, identifier:lower; 52, identifier:extend; 53, argument_list; 53, 54; 54, identifier:codes; 55, expression_statement; 55, 56; 56, call; 56, 57; 56, 58; 57, identifier:ReadUnicodeTable; 58, argument_list; 58, 59; 58, 62; 58, 63; 59, binary_operator:+; 59, 60; 59, 61; 60, identifier:unicode_dir; 61, string:"/CaseFolding.txt"; 62, integer:4; 63, identifier:DoLine; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:groups; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:togroup; 70, identifier:values; 71, argument_list; 72, for_statement; 72, 73; 72, 74; 72, 75; 73, identifier:g; 74, identifier:groups; 75, block; 75, 76; 76, expression_statement; 76, 77; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:g; 80, identifier:sort; 81, argument_list; 82, expression_statement; 82, 83; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:groups; 86, identifier:sort; 87, argument_list; 88, return_statement; 88, 89; 89, expression_list; 89, 90; 89, 91; 90, identifier:togroup; 91, identifier:groups | def CaseGroups(unicode_dir=_UNICODE_DIR):
togroup = {}
def DoLine(codes, fields):
(_, foldtype, lower, _) = fields
if foldtype not in ("C", "S"):
return
lower = _UInt(lower)
togroup.setdefault(lower, [lower]).extend(codes)
ReadUnicodeTable(unicode_dir+"/CaseFolding.txt", 4, DoLine)
groups = togroup.values()
for g in groups:
g.sort()
groups.sort()
return togroup, groups |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:naturalsortkey; 3, parameters; 3, 4; 4, identifier:s; 5, block; 5, 6; 6, return_statement; 6, 7; 7, list_comprehension; 7, 8; 7, 19; 8, conditional_expression:if; 8, 9; 8, 13; 8, 18; 9, call; 9, 10; 9, 11; 10, identifier:int; 11, argument_list; 11, 12; 12, identifier:part; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:part; 16, identifier:isdigit; 17, argument_list; 18, identifier:part; 19, for_in_clause; 19, 20; 19, 21; 20, identifier:part; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:re; 24, identifier:split; 25, argument_list; 25, 26; 25, 27; 26, string:'([0-9]+)'; 27, identifier:s | def naturalsortkey(s):
return [int(part) if part.isdigit() else part
for part in re.split('([0-9]+)', s)] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:max_variance_genes; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:data; 5, default_parameter; 5, 6; 5, 7; 6, identifier:nbins; 7, integer:5; 8, default_parameter; 8, 9; 8, 10; 9, identifier:frac; 10, float:0.2; 11, block; 11, 12; 11, 16; 11, 53; 11, 61; 11, 74; 11, 83; 11, 177; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:indices; 15, list:[]; 16, if_statement; 16, 17; 16, 23; 16, 33; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:sparse; 20, identifier:issparse; 21, argument_list; 21, 22; 22, identifier:data; 23, block; 23, 24; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 29; 26, pattern_list; 26, 27; 26, 28; 27, identifier:means; 28, identifier:var; 29, call; 29, 30; 29, 31; 30, identifier:sparse_mean_var; 31, argument_list; 31, 32; 32, identifier:data; 33, else_clause; 33, 34; 34, block; 34, 35; 34, 44; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:means; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:data; 41, identifier:mean; 42, argument_list; 42, 43; 43, integer:1; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:var; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:data; 50, identifier:var; 51, argument_list; 51, 52; 52, integer:1; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:mean_indices; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:means; 59, identifier:argsort; 60, argument_list; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:n_elements; 64, call; 64, 65; 64, 66; 65, identifier:int; 66, argument_list; 66, 67; 67, binary_operator:/; 67, 68; 67, 73; 68, subscript; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:data; 71, identifier:shape; 72, integer:0; 73, identifier:nbins; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:frac_elements; 77, call; 77, 78; 77, 79; 78, identifier:int; 79, argument_list; 79, 80; 80, binary_operator:*; 80, 81; 80, 82; 81, identifier:n_elements; 82, identifier:frac; 83, for_statement; 83, 84; 83, 85; 83, 89; 84, identifier:i; 85, call; 85, 86; 85, 87; 86, identifier:range; 87, argument_list; 87, 88; 88, identifier:nbins; 89, block; 89, 90; 89, 106; 89, 123; 89, 129; 89, 137; 89, 150; 89, 156; 89, 170; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:bin_i; 93, subscript; 93, 94; 93, 95; 94, identifier:mean_indices; 95, slice; 95, 96; 95, 99; 95, 100; 96, binary_operator:*; 96, 97; 96, 98; 97, identifier:i; 98, identifier:n_elements; 99, colon; 100, binary_operator:*; 100, 101; 100, 105; 101, parenthesized_expression; 101, 102; 102, binary_operator:+; 102, 103; 102, 104; 103, identifier:i; 104, integer:1; 105, identifier:n_elements; 106, if_statement; 106, 107; 106, 112; 107, comparison_operator:==; 107, 108; 107, 109; 108, identifier:i; 109, binary_operator:-; 109, 110; 109, 111; 110, identifier:nbins; 111, integer:1; 112, block; 112, 113; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:bin_i; 116, subscript; 116, 117; 116, 118; 117, identifier:mean_indices; 118, slice; 118, 119; 118, 122; 119, binary_operator:*; 119, 120; 119, 121; 120, identifier:i; 121, identifier:n_elements; 122, colon; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 126; 125, identifier:var_i; 126, subscript; 126, 127; 126, 128; 127, identifier:var; 128, identifier:bin_i; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:var_sorted; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:var_i; 135, identifier:argsort; 136, argument_list; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:top_var_indices; 140, subscript; 140, 141; 140, 142; 141, identifier:var_sorted; 142, slice; 142, 143; 142, 149; 143, binary_operator:-; 143, 144; 143, 148; 144, call; 144, 145; 144, 146; 145, identifier:len; 146, argument_list; 146, 147; 147, identifier:bin_i; 148, identifier:frac_elements; 149, colon; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 153; 152, identifier:ind; 153, subscript; 153, 154; 153, 155; 154, identifier:bin_i; 155, identifier:top_var_indices; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 159; 158, identifier:ind; 159, list_comprehension; 159, 160; 159, 161; 159, 164; 160, identifier:index; 161, for_in_clause; 161, 162; 161, 163; 162, identifier:index; 163, identifier:ind; 164, if_clause; 164, 165; 165, comparison_operator:>; 165, 166; 165, 169; 166, subscript; 166, 167; 166, 168; 167, identifier:var; 168, identifier:index; 169, integer:0; 170, expression_statement; 170, 171; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:indices; 174, identifier:extend; 175, argument_list; 175, 176; 176, identifier:ind; 177, return_statement; 177, 178; 178, identifier:indices | def max_variance_genes(data, nbins=5, frac=0.2):
indices = []
if sparse.issparse(data):
means, var = sparse_mean_var(data)
else:
means = data.mean(1)
var = data.var(1)
mean_indices = means.argsort()
n_elements = int(data.shape[0]/nbins)
frac_elements = int(n_elements*frac)
for i in range(nbins):
bin_i = mean_indices[i*n_elements : (i+1)*n_elements]
if i==nbins-1:
bin_i = mean_indices[i*n_elements :]
var_i = var[bin_i]
var_sorted = var_i.argsort()
top_var_indices = var_sorted[len(bin_i) - frac_elements:]
ind = bin_i[top_var_indices]
ind = [index for index in ind if var[index]>0]
indices.extend(ind)
return indices |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:unique; 3, parameters; 3, 4; 4, identifier:ar; 5, block; 5, 6; 5, 8; 5, 14; 5, 32; 6, expression_statement; 6, 7; 7, identifier:r; 8, import_statement; 8, 9; 9, aliased_import; 9, 10; 9, 13; 10, dotted_name; 10, 11; 10, 12; 11, identifier:dask; 12, identifier:array; 13, identifier:da; 14, if_statement; 14, 15; 14, 24; 15, call; 15, 16; 15, 17; 16, identifier:isinstance; 17, argument_list; 17, 18; 17, 19; 18, identifier:ar; 19, attribute; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:da; 22, identifier:core; 23, identifier:Array; 24, block; 24, 25; 25, return_statement; 25, 26; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:da; 29, identifier:unique; 30, argument_list; 30, 31; 31, identifier:ar; 32, return_statement; 32, 33; 33, call; 33, 34; 33, 35; 34, identifier:_unique; 35, argument_list; 35, 36; 36, identifier:ar | def unique(ar):
r
import dask.array as da
if isinstance(ar, da.core.Array):
return da.unique(ar)
return _unique(ar) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:polls_get; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, dictionary_splat_pattern; 5, 6; 6, identifier:kwargs; 7, block; 7, 8; 7, 14; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 13; 10, subscript; 10, 11; 10, 12; 11, identifier:kwargs; 12, string:'_return_http_data_only'; 13, True; 14, if_statement; 14, 15; 14, 21; 14, 30; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:kwargs; 18, identifier:get; 19, argument_list; 19, 20; 20, string:'callback'; 21, block; 21, 22; 22, return_statement; 22, 23; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:polls_get_with_http_info; 27, argument_list; 27, 28; 28, dictionary_splat; 28, 29; 29, identifier:kwargs; 30, else_clause; 30, 31; 31, block; 31, 32; 31, 43; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 36; 34, tuple_pattern; 34, 35; 35, identifier:data; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:polls_get_with_http_info; 40, argument_list; 40, 41; 41, dictionary_splat; 41, 42; 42, identifier:kwargs; 43, return_statement; 43, 44; 44, identifier:data | def polls_get(self, **kwargs):
kwargs['_return_http_data_only'] = True
if kwargs.get('callback'):
return self.polls_get_with_http_info(**kwargs)
else:
(data) = self.polls_get_with_http_info(**kwargs)
return data |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_sorted_actions; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 35; 5, 63; 6, for_statement; 6, 7; 6, 8; 6, 31; 7, identifier:a; 8, call; 8, 9; 8, 10; 9, identifier:filter; 10, argument_list; 10, 11; 10, 28; 11, lambda; 11, 12; 11, 14; 12, lambda_parameters; 12, 13; 13, identifier:_; 14, boolean_operator:and; 14, 15; 14, 19; 14, 20; 15, not_operator; 15, 16; 16, attribute; 16, 17; 16, 18; 17, identifier:_; 18, identifier:last; 19, line_continuation:\; 20, not_operator; 20, 21; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:is_action; 25, argument_list; 25, 26; 25, 27; 26, identifier:_; 27, string:'parsers'; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:_actions; 31, block; 31, 32; 32, expression_statement; 32, 33; 33, yield; 33, 34; 34, identifier:a; 35, for_statement; 35, 36; 35, 37; 35, 59; 36, identifier:a; 37, call; 37, 38; 37, 39; 38, identifier:filter; 39, argument_list; 39, 40; 39, 56; 40, lambda; 40, 41; 40, 43; 41, lambda_parameters; 41, 42; 42, identifier:_; 43, boolean_operator:and; 43, 44; 43, 47; 43, 48; 44, attribute; 44, 45; 44, 46; 45, identifier:_; 46, identifier:last; 47, line_continuation:\; 48, not_operator; 48, 49; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:is_action; 53, argument_list; 53, 54; 53, 55; 54, identifier:_; 55, string:'parsers'; 56, attribute; 56, 57; 56, 58; 57, identifier:self; 58, identifier:_actions; 59, block; 59, 60; 60, expression_statement; 60, 61; 61, yield; 61, 62; 62, identifier:a; 63, for_statement; 63, 64; 63, 65; 63, 81; 64, identifier:a; 65, call; 65, 66; 65, 67; 66, identifier:filter; 67, argument_list; 67, 68; 67, 78; 68, lambda; 68, 69; 68, 71; 69, lambda_parameters; 69, 70; 70, identifier:_; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:self; 74, identifier:is_action; 75, argument_list; 75, 76; 75, 77; 76, identifier:_; 77, string:'parsers'; 78, attribute; 78, 79; 78, 80; 79, identifier:self; 80, identifier:_actions; 81, block; 81, 82; 82, expression_statement; 82, 83; 83, yield; 83, 84; 84, identifier:a | def _sorted_actions(self):
for a in filter(lambda _: not _.last and \
not self.is_action(_, 'parsers'), self._actions):
yield a
for a in filter(lambda _: _.last and \
not self.is_action(_, 'parsers'), self._actions):
yield a
for a in filter(lambda _: self.is_action(_, 'parsers'),
self._actions):
yield a |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:eigendecomp; 3, parameters; 3, 4; 3, 5; 4, identifier:G; 5, identifier:d; 6, block; 6, 7; 6, 15; 6, 28; 6, 37; 6, 52; 6, 58; 6, 82; 6, 90; 6, 105; 6, 124; 6, 132; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:N; 10, subscript; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:G; 13, identifier:shape; 14, integer:0; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 20; 17, pattern_list; 17, 18; 17, 19; 18, identifier:lamda; 19, identifier:u; 20, call; 20, 21; 20, 26; 21, attribute; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:np; 24, identifier:linalg; 25, identifier:eig; 26, argument_list; 26, 27; 27, identifier:G; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:lamda; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:np; 34, identifier:real; 35, argument_list; 35, 36; 36, identifier:lamda; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:indices; 40, subscript; 40, 41; 40, 47; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:np; 44, identifier:argsort; 45, argument_list; 45, 46; 46, identifier:lamda; 47, slice; 47, 48; 47, 49; 47, 50; 48, colon; 49, colon; 50, unary_operator:-; 50, 51; 51, integer:1; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:lamda_sorted; 55, subscript; 55, 56; 55, 57; 56, identifier:lamda; 57, identifier:indices; 58, assert_statement; 58, 59; 58, 72; 59, call; 59, 60; 59, 71; 60, attribute; 60, 61; 60, 70; 61, parenthesized_expression; 61, 62; 62, comparison_operator:>; 62, 63; 62, 68; 63, subscript; 63, 64; 63, 65; 64, identifier:lamda_sorted; 65, slice; 65, 66; 65, 67; 66, colon; 67, identifier:d; 68, unary_operator:-; 68, 69; 69, float:1e-10; 70, identifier:all; 71, argument_list; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, string:"{} not all positive!"; 75, identifier:format; 76, argument_list; 76, 77; 77, subscript; 77, 78; 77, 79; 78, identifier:lamda_sorted; 79, slice; 79, 80; 79, 81; 80, colon; 81, identifier:d; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:u; 85, subscript; 85, 86; 85, 87; 85, 89; 86, identifier:u; 87, slice; 87, 88; 88, colon; 89, identifier:indices; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:factor; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:np; 96, identifier:empty; 97, argument_list; 97, 98; 97, 100; 98, tuple; 98, 99; 99, identifier:N; 100, keyword_argument; 100, 101; 100, 102; 101, identifier:dtype; 102, attribute; 102, 103; 102, 104; 103, identifier:lamda; 104, identifier:dtype; 105, expression_statement; 105, 106; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:np; 109, identifier:sqrt; 110, argument_list; 110, 111; 110, 116; 111, subscript; 111, 112; 111, 113; 112, identifier:lamda_sorted; 113, slice; 113, 114; 113, 115; 114, colon; 115, identifier:d; 116, keyword_argument; 116, 117; 116, 118; 117, identifier:out; 118, subscript; 118, 119; 118, 120; 119, identifier:factor; 120, slice; 120, 121; 120, 122; 120, 123; 121, integer:0; 122, colon; 123, identifier:d; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 131; 126, subscript; 126, 127; 126, 128; 127, identifier:factor; 128, slice; 128, 129; 128, 130; 129, identifier:d; 130, colon; 131, float:0.0; 132, return_statement; 132, 133; 133, expression_list; 133, 134; 133, 135; 134, identifier:factor; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:np; 138, identifier:real; 139, argument_list; 139, 140; 140, identifier:u | def eigendecomp(G, d):
N = G.shape[0]
lamda, u = np.linalg.eig(G)
lamda = np.real(lamda)
indices = np.argsort(lamda)[::-1]
lamda_sorted = lamda[indices]
assert (lamda_sorted[
:d] > -1e-10).all(), "{} not all positive!".format(lamda_sorted[:d])
u = u[:, indices]
factor = np.empty((N,), dtype=lamda.dtype)
np.sqrt(lamda_sorted[:d], out=factor[0:d])
factor[d:] = 0.0
return factor, np.real(u) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:get_astrom; 3, parameters; 3, 4; 3, 7; 4, default_parameter; 4, 5; 4, 6; 5, identifier:official; 6, string:'%'; 7, default_parameter; 7, 8; 7, 9; 8, identifier:provisional; 9, string:'%'; 10, block; 10, 11; 10, 15; 10, 19; 10, 36; 10, 43; 10, 50; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:sql; 14, string:"SELECT m.* FROM measure m "; 15, expression_statement; 15, 16; 16, augmented_assignment:+=; 16, 17; 16, 18; 17, identifier:sql; 18, string:"LEFT JOIN object o ON m.provisional LIKE o.provisional "; 19, if_statement; 19, 20; 19, 22; 19, 27; 20, not_operator; 20, 21; 21, identifier:official; 22, block; 22, 23; 23, expression_statement; 23, 24; 24, augmented_assignment:+=; 24, 25; 24, 26; 25, identifier:sql; 26, string:"WHERE o.official IS NULL"; 27, else_clause; 27, 28; 28, block; 28, 29; 29, expression_statement; 29, 30; 30, augmented_assignment:+=; 30, 31; 30, 32; 31, identifier:sql; 32, binary_operator:%; 32, 33; 32, 34; 33, string:"WHERE o.official LIKE '%s' "; 34, tuple; 34, 35; 35, identifier:official; 36, expression_statement; 36, 37; 37, augmented_assignment:+=; 37, 38; 37, 39; 38, identifier:sql; 39, binary_operator:%; 39, 40; 39, 41; 40, string:" AND m.provisional LIKE '%s' "; 41, tuple; 41, 42; 42, identifier:provisional; 43, expression_statement; 43, 44; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:cfeps; 47, identifier:execute; 48, argument_list; 48, 49; 49, identifier:sql; 50, return_statement; 50, 51; 51, call; 51, 52; 51, 53; 52, identifier:mk_dict; 53, argument_list; 53, 54; 53, 59; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:cfeps; 57, identifier:fetchall; 58, argument_list; 59, attribute; 59, 60; 59, 61; 60, identifier:cfeps; 61, identifier:description | def get_astrom(official='%',provisional='%'):
sql= "SELECT m.* FROM measure m "
sql+="LEFT JOIN object o ON m.provisional LIKE o.provisional "
if not official:
sql+="WHERE o.official IS NULL"
else:
sql+="WHERE o.official LIKE '%s' " % ( official, )
sql+=" AND m.provisional LIKE '%s' " % ( provisional, )
cfeps.execute(sql)
return mk_dict(cfeps.fetchall(), cfeps.description) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:sorted_by_field; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:issues; 5, default_parameter; 5, 6; 5, 7; 6, identifier:field; 7, string:'closed_at'; 8, default_parameter; 8, 9; 8, 10; 9, identifier:reverse; 10, False; 11, block; 11, 12; 12, return_statement; 12, 13; 13, call; 13, 14; 13, 15; 14, identifier:sorted; 15, argument_list; 15, 16; 15, 17; 15, 25; 16, identifier:issues; 17, keyword_argument; 17, 18; 17, 19; 18, identifier:key; 19, lambda; 19, 20; 19, 22; 20, lambda_parameters; 20, 21; 21, identifier:i; 22, subscript; 22, 23; 22, 24; 23, identifier:i; 24, identifier:field; 25, keyword_argument; 25, 26; 25, 27; 26, identifier:reverse; 27, identifier:reverse | def sorted_by_field(issues, field='closed_at', reverse=False):
return sorted(issues, key = lambda i:i[field], reverse=reverse) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:order_by; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:key_selector; 7, identifier:identity; 8, block; 8, 9; 8, 11; 8, 25; 8, 49; 9, expression_statement; 9, 10; 10, string:'''Sorts by a key in ascending order.
Introduces a primary sorting order to the sequence. Additional sort
criteria should be specified by subsequent calls to then_by() and
then_by_descending(). Calling order_by() or order_by_descending() on
the results of a call to order_by() will introduce a new primary
ordering which will override any already established ordering.
This method performs a stable sort. The order of two elements with the
same key will be preserved.
Note: This method uses deferred execution.
Args:
key_selector: A unary function which extracts a key from each
element using which the result will be ordered.
Returns:
An OrderedQueryable over the sorted elements.
Raises:
ValueError: If the Queryable is closed.
TypeError: If the key_selector is not callable.
'''; 11, if_statement; 11, 12; 11, 17; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:closed; 16, argument_list; 17, block; 17, 18; 18, raise_statement; 18, 19; 19, call; 19, 20; 19, 21; 20, identifier:ValueError; 21, argument_list; 21, 22; 22, concatenated_string; 22, 23; 22, 24; 23, string:"Attempt to call order_by() on a "; 24, string:"closed Queryable."; 25, if_statement; 25, 26; 25, 31; 26, not_operator; 26, 27; 27, call; 27, 28; 27, 29; 28, identifier:is_callable; 29, argument_list; 29, 30; 30, identifier:key_selector; 31, block; 31, 32; 32, raise_statement; 32, 33; 33, call; 33, 34; 33, 35; 34, identifier:TypeError; 35, argument_list; 35, 36; 36, call; 36, 37; 36, 42; 37, attribute; 37, 38; 37, 41; 38, concatenated_string; 38, 39; 38, 40; 39, string:"order_by() parameter key_selector={key_selector} "; 40, string:"is not callable"; 41, identifier:format; 42, argument_list; 42, 43; 43, keyword_argument; 43, 44; 43, 45; 44, identifier:key_selector; 45, call; 45, 46; 45, 47; 46, identifier:repr; 47, argument_list; 47, 48; 48, identifier:key_selector; 49, return_statement; 49, 50; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:self; 53, identifier:_create_ordered; 54, argument_list; 54, 55; 54, 59; 54, 61; 55, call; 55, 56; 55, 57; 56, identifier:iter; 57, argument_list; 57, 58; 58, identifier:self; 59, unary_operator:-; 59, 60; 60, integer:1; 61, identifier:key_selector | def order_by(self, key_selector=identity):
'''Sorts by a key in ascending order.
Introduces a primary sorting order to the sequence. Additional sort
criteria should be specified by subsequent calls to then_by() and
then_by_descending(). Calling order_by() or order_by_descending() on
the results of a call to order_by() will introduce a new primary
ordering which will override any already established ordering.
This method performs a stable sort. The order of two elements with the
same key will be preserved.
Note: This method uses deferred execution.
Args:
key_selector: A unary function which extracts a key from each
element using which the result will be ordered.
Returns:
An OrderedQueryable over the sorted elements.
Raises:
ValueError: If the Queryable is closed.
TypeError: If the key_selector is not callable.
'''
if self.closed():
raise ValueError("Attempt to call order_by() on a "
"closed Queryable.")
if not is_callable(key_selector):
raise TypeError("order_by() parameter key_selector={key_selector} "
"is not callable".format(key_selector=repr(key_selector)))
return self._create_ordered(iter(self), -1, key_selector) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:then_by; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:key_selector; 7, identifier:identity; 8, block; 8, 9; 8, 11; 8, 25; 8, 49; 8, 61; 9, expression_statement; 9, 10; 10, string:'''Introduce subsequent ordering to the sequence with an optional key.
The returned sequence will be sorted in ascending order by the
selected key.
Note: This method uses deferred execution.
Args:
key_selector: A unary function the only positional argument to
which is the element value from which the key will be
selected. The return value should be the key from that
element.
Returns:
An OrderedQueryable over the sorted items.
Raises:
ValueError: If the OrderedQueryable is closed().
TypeError: If key_selector is not callable.
'''; 11, if_statement; 11, 12; 11, 17; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:closed; 16, argument_list; 17, block; 17, 18; 18, raise_statement; 18, 19; 19, call; 19, 20; 19, 21; 20, identifier:ValueError; 21, argument_list; 21, 22; 22, concatenated_string; 22, 23; 22, 24; 23, string:"Attempt to call then_by() on a "; 24, string:"closed OrderedQueryable."; 25, if_statement; 25, 26; 25, 31; 26, not_operator; 26, 27; 27, call; 27, 28; 27, 29; 28, identifier:is_callable; 29, argument_list; 29, 30; 30, identifier:key_selector; 31, block; 31, 32; 32, raise_statement; 32, 33; 33, call; 33, 34; 33, 35; 34, identifier:TypeError; 35, argument_list; 35, 36; 36, call; 36, 37; 36, 42; 37, attribute; 37, 38; 37, 41; 38, concatenated_string; 38, 39; 38, 40; 39, string:"then_by() parameter key_selector={key_selector} "; 40, string:"is not callable"; 41, identifier:format; 42, argument_list; 42, 43; 43, keyword_argument; 43, 44; 43, 45; 44, identifier:key_selector; 45, call; 45, 46; 45, 47; 46, identifier:repr; 47, argument_list; 47, 48; 48, identifier:key_selector; 49, expression_statement; 49, 50; 50, call; 50, 51; 50, 56; 51, attribute; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:self; 54, identifier:_funcs; 55, identifier:append; 56, argument_list; 56, 57; 57, tuple; 57, 58; 57, 60; 58, unary_operator:-; 58, 59; 59, integer:1; 60, identifier:key_selector; 61, return_statement; 61, 62; 62, identifier:self | def then_by(self, key_selector=identity):
'''Introduce subsequent ordering to the sequence with an optional key.
The returned sequence will be sorted in ascending order by the
selected key.
Note: This method uses deferred execution.
Args:
key_selector: A unary function the only positional argument to
which is the element value from which the key will be
selected. The return value should be the key from that
element.
Returns:
An OrderedQueryable over the sorted items.
Raises:
ValueError: If the OrderedQueryable is closed().
TypeError: If key_selector is not callable.
'''
if self.closed():
raise ValueError("Attempt to call then_by() on a "
"closed OrderedQueryable.")
if not is_callable(key_selector):
raise TypeError("then_by() parameter key_selector={key_selector} "
"is not callable".format(key_selector=repr(key_selector)))
self._funcs.append((-1, key_selector))
return self |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 6, expression_statement; 6, 7; 7, call; 7, 8; 7, 13; 8, attribute; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:self; 11, identifier:_matches; 12, identifier:sort_values; 13, argument_list; 13, 14; 13, 35; 13, 44; 14, keyword_argument; 14, 15; 14, 16; 15, identifier:by; 16, list:[constants.SIZE_FIELDNAME, constants.NGRAM_FIELDNAME,
constants.COUNT_FIELDNAME, constants.LABEL_FIELDNAME,
constants.WORK_FIELDNAME, constants.SIGLUM_FIELDNAME]; 16, 17; 16, 20; 16, 23; 16, 26; 16, 29; 16, 32; 17, attribute; 17, 18; 17, 19; 18, identifier:constants; 19, identifier:SIZE_FIELDNAME; 20, attribute; 20, 21; 20, 22; 21, identifier:constants; 22, identifier:NGRAM_FIELDNAME; 23, attribute; 23, 24; 23, 25; 24, identifier:constants; 25, identifier:COUNT_FIELDNAME; 26, attribute; 26, 27; 26, 28; 27, identifier:constants; 28, identifier:LABEL_FIELDNAME; 29, attribute; 29, 30; 29, 31; 30, identifier:constants; 31, identifier:WORK_FIELDNAME; 32, attribute; 32, 33; 32, 34; 33, identifier:constants; 34, identifier:SIGLUM_FIELDNAME; 35, keyword_argument; 35, 36; 35, 37; 36, identifier:ascending; 37, list:[False, True, False, True, True, True]; 37, 38; 37, 39; 37, 40; 37, 41; 37, 42; 37, 43; 38, False; 39, True; 40, False; 41, True; 42, True; 43, True; 44, keyword_argument; 44, 45; 44, 46; 45, identifier:inplace; 46, True | def sort(self):
self._matches.sort_values(
by=[constants.SIZE_FIELDNAME, constants.NGRAM_FIELDNAME,
constants.COUNT_FIELDNAME, constants.LABEL_FIELDNAME,
constants.WORK_FIELDNAME, constants.SIGLUM_FIELDNAME],
ascending=[False, True, False, True, True, True], inplace=True) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_set_labels; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:catalogue; 6, block; 6, 7; 6, 94; 7, with_statement; 7, 8; 7, 13; 8, with_clause; 8, 9; 9, with_item; 9, 10; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:_conn; 13, block; 13, 14; 13, 27; 13, 31; 14, expression_statement; 14, 15; 15, call; 15, 16; 15, 21; 16, attribute; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:_conn; 20, identifier:execute; 21, argument_list; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:constants; 24, identifier:UPDATE_LABELS_SQL; 25, list:['']; 25, 26; 26, string:''; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:labels; 30, dictionary; 31, for_statement; 31, 32; 31, 35; 31, 40; 32, pattern_list; 32, 33; 32, 34; 33, identifier:work; 34, identifier:label; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:catalogue; 38, identifier:items; 39, argument_list; 40, block; 40, 41; 40, 55; 40, 70; 40, 80; 41, expression_statement; 41, 42; 42, call; 42, 43; 42, 48; 43, attribute; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:_conn; 47, identifier:execute; 48, argument_list; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:constants; 51, identifier:UPDATE_LABEL_SQL; 52, list:[label, work]; 52, 53; 52, 54; 53, identifier:label; 54, identifier:work; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:cursor; 58, call; 58, 59; 58, 64; 59, attribute; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:_conn; 63, identifier:execute; 64, argument_list; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:constants; 67, identifier:SELECT_TEXT_TOKEN_COUNT_SQL; 68, list:[work]; 68, 69; 69, identifier:work; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:token_count; 73, subscript; 73, 74; 73, 79; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:cursor; 77, identifier:fetchone; 78, argument_list; 79, string:'token_count'; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 85; 82, subscript; 82, 83; 82, 84; 83, identifier:labels; 84, identifier:label; 85, binary_operator:+; 85, 86; 85, 93; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:labels; 89, identifier:get; 90, argument_list; 90, 91; 90, 92; 91, identifier:label; 92, integer:0; 93, identifier:token_count; 94, return_statement; 94, 95; 95, identifier:labels | def _set_labels(self, catalogue):
with self._conn:
self._conn.execute(constants.UPDATE_LABELS_SQL, [''])
labels = {}
for work, label in catalogue.items():
self._conn.execute(constants.UPDATE_LABEL_SQL, [label, work])
cursor = self._conn.execute(
constants.SELECT_TEXT_TOKEN_COUNT_SQL, [work])
token_count = cursor.fetchone()['token_count']
labels[label] = labels.get(label, 0) + token_count
return labels |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:get_fn_args; 3, parameters; 3, 4; 3, 5; 3, 9; 4, identifier:fn; 5, typed_parameter; 5, 6; 5, 7; 6, identifier:kwargs; 7, type; 7, 8; 8, identifier:dict; 9, typed_default_parameter; 9, 10; 9, 11; 9, 13; 10, identifier:prefix; 11, type; 11, 12; 12, identifier:str; 13, None; 14, block; 14, 15; 14, 22; 14, 29; 14, 38; 14, 50; 14, 68; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:all_args; 18, call; 18, 19; 18, 20; 19, identifier:get_all_args; 20, argument_list; 20, 21; 21, identifier:fn; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:required_args; 25, call; 25, 26; 25, 27; 26, identifier:get_required_args; 27, argument_list; 27, 28; 28, identifier:fn; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:fn_kwargs; 32, call; 32, 33; 32, 34; 33, identifier:pick_kwargs; 34, argument_list; 34, 35; 34, 36; 34, 37; 35, identifier:kwargs; 36, identifier:all_args; 37, identifier:prefix; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:missing_args; 41, list_comprehension; 41, 42; 41, 43; 41, 46; 42, identifier:arg; 43, for_in_clause; 43, 44; 43, 45; 44, identifier:arg; 45, identifier:required_args; 46, if_clause; 46, 47; 47, comparison_operator:not; 47, 48; 47, 49; 48, identifier:arg; 49, identifier:fn_kwargs; 50, if_statement; 50, 51; 50, 52; 51, identifier:missing_args; 52, block; 52, 53; 53, raise_statement; 53, 54; 54, call; 54, 55; 54, 56; 55, identifier:ValueError; 56, argument_list; 56, 57; 57, call; 57, 58; 57, 63; 58, attribute; 58, 59; 58, 62; 59, concatenated_string; 59, 60; 59, 61; 60, string:'The following args are missing for the function '; 61, string:'{}: {}.'; 62, identifier:format; 63, argument_list; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:fn; 66, identifier:__name__; 67, identifier:missing_args; 68, return_statement; 68, 69; 69, identifier:fn_kwargs | def get_fn_args(fn, kwargs: dict, prefix: str = None):
all_args = get_all_args(fn)
required_args = get_required_args(fn)
fn_kwargs = pick_kwargs(kwargs, all_args, prefix)
missing_args = [arg for arg in required_args if arg not in fn_kwargs]
if missing_args:
raise ValueError(
'The following args are missing for the function '
'{}: {}.'.format(fn.__name__, missing_args)
)
return fn_kwargs |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:pick_kwargs; 3, parameters; 3, 4; 3, 8; 3, 12; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:kwargs; 6, type; 6, 7; 7, identifier:dict; 8, typed_parameter; 8, 9; 8, 10; 9, identifier:required_args; 10, type; 10, 11; 11, identifier:list; 12, typed_default_parameter; 12, 13; 12, 14; 12, 16; 13, identifier:prefix; 14, type; 14, 15; 15, identifier:str; 16, None; 17, block; 17, 18; 17, 38; 17, 42; 17, 86; 17, 98; 17, 113; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:picked; 21, dictionary_comprehension; 21, 22; 21, 25; 21, 34; 22, pair; 22, 23; 22, 24; 23, identifier:k; 24, identifier:v; 25, for_in_clause; 25, 26; 25, 29; 26, pattern_list; 26, 27; 26, 28; 27, identifier:k; 28, identifier:v; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:kwargs; 32, identifier:items; 33, argument_list; 34, if_clause; 34, 35; 35, comparison_operator:in; 35, 36; 35, 37; 36, identifier:k; 37, identifier:required_args; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:prefixed; 41, dictionary; 42, if_statement; 42, 43; 42, 44; 43, identifier:prefix; 44, block; 44, 45; 44, 51; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:prefix; 48, binary_operator:+; 48, 49; 48, 50; 49, identifier:prefix; 50, string:'__'; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:prefixed; 54, dictionary_comprehension; 54, 55; 54, 62; 54, 71; 55, pair; 55, 56; 55, 61; 56, call; 56, 57; 56, 58; 57, identifier:_remove_prefix; 58, argument_list; 58, 59; 58, 60; 59, identifier:k; 60, identifier:prefix; 61, identifier:v; 62, for_in_clause; 62, 63; 62, 66; 63, pattern_list; 63, 64; 63, 65; 64, identifier:k; 65, identifier:v; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:kwargs; 69, identifier:items; 70, argument_list; 71, if_clause; 71, 72; 72, boolean_operator:and; 72, 73; 72, 79; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:k; 76, identifier:startswith; 77, argument_list; 77, 78; 78, identifier:prefix; 79, comparison_operator:in; 79, 80; 79, 85; 80, call; 80, 81; 80, 82; 81, identifier:_remove_prefix; 82, argument_list; 82, 83; 82, 84; 83, identifier:k; 84, identifier:prefix; 85, identifier:required_args; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:conflicting_args; 89, list_comprehension; 89, 90; 89, 91; 89, 94; 90, identifier:k; 91, for_in_clause; 91, 92; 91, 93; 92, identifier:k; 93, identifier:picked; 94, if_clause; 94, 95; 95, comparison_operator:in; 95, 96; 95, 97; 96, identifier:k; 97, identifier:prefixed; 98, if_statement; 98, 99; 98, 100; 99, identifier:conflicting_args; 100, block; 100, 101; 101, raise_statement; 101, 102; 102, call; 102, 103; 102, 104; 103, identifier:ValueError; 104, argument_list; 104, 105; 105, call; 105, 106; 105, 111; 106, attribute; 106, 107; 106, 110; 107, concatenated_string; 107, 108; 107, 109; 108, string:'Both prefixed and unprefixed args were specified '; 109, string:'for the following parameters: {}'; 110, identifier:format; 111, argument_list; 111, 112; 112, identifier:conflicting_args; 113, return_statement; 113, 114; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:tz; 117, identifier:merge; 118, argument_list; 118, 119; 118, 120; 119, identifier:picked; 120, identifier:prefixed | def pick_kwargs(kwargs: dict, required_args: list, prefix: str = None):
picked = {k: v for k, v in kwargs.items() if k in required_args}
prefixed = {}
if prefix:
prefix = prefix + '__'
prefixed = {
_remove_prefix(k, prefix): v
for k, v in kwargs.items()
if k.startswith(prefix)
and _remove_prefix(k, prefix) in required_args
}
conflicting_args = [k for k in picked if k in prefixed]
if conflicting_args:
raise ValueError(
'Both prefixed and unprefixed args were specified '
'for the following parameters: {}'.format(conflicting_args)
)
return tz.merge(picked, prefixed) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:search; 3, parameters; 3, 4; 3, 5; 4, identifier:query; 5, default_parameter; 5, 6; 5, 7; 6, identifier:query_type; 7, identifier:DEFAULT_QUERY_TYPE; 8, block; 8, 9; 8, 18; 8, 34; 8, 72; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 14; 11, pattern_list; 11, 12; 11, 13; 12, identifier:statement; 13, identifier:arguments; 14, call; 14, 15; 14, 16; 15, identifier:_build_search; 16, argument_list; 16, 17; 17, identifier:query; 18, if_statement; 18, 19; 18, 26; 19, boolean_operator:and; 19, 20; 19, 23; 20, comparison_operator:is; 20, 21; 20, 22; 21, identifier:statement; 22, None; 23, comparison_operator:is; 23, 24; 23, 25; 24, identifier:arguments; 25, None; 26, block; 26, 27; 27, return_statement; 27, 28; 28, call; 28, 29; 28, 30; 29, identifier:QueryResults; 30, argument_list; 30, 31; 30, 32; 30, 33; 31, list:[]; 32, list:[]; 33, string:'AND'; 34, with_statement; 34, 35; 34, 43; 35, with_clause; 35, 36; 36, with_item; 36, 37; 37, as_pattern; 37, 38; 37, 41; 38, call; 38, 39; 38, 40; 39, identifier:db_connect; 40, argument_list; 41, as_pattern_target; 41, 42; 42, identifier:db_connection; 43, block; 43, 44; 44, with_statement; 44, 45; 44, 55; 45, with_clause; 45, 46; 46, with_item; 46, 47; 47, as_pattern; 47, 48; 47, 53; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:db_connection; 51, identifier:cursor; 52, argument_list; 53, as_pattern_target; 53, 54; 54, identifier:cursor; 55, block; 55, 56; 55, 64; 56, expression_statement; 56, 57; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:cursor; 60, identifier:execute; 61, argument_list; 61, 62; 61, 63; 62, identifier:statement; 63, identifier:arguments; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:search_results; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:cursor; 70, identifier:fetchall; 71, argument_list; 72, return_statement; 72, 73; 73, call; 73, 74; 73, 75; 74, identifier:QueryResults; 75, argument_list; 75, 76; 75, 77; 75, 78; 76, identifier:search_results; 77, identifier:query; 78, identifier:query_type | def search(query, query_type=DEFAULT_QUERY_TYPE):
statement, arguments = _build_search(query)
if statement is None and arguments is None:
return QueryResults([], [], 'AND')
with db_connect() as db_connection:
with db_connection.cursor() as cursor:
cursor.execute(statement, arguments)
search_results = cursor.fetchall()
return QueryResults(search_results, query, query_type) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_tdms_files; 3, parameters; 3, 4; 4, identifier:directory; 5, block; 5, 6; 5, 19; 5, 38; 5, 56; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:path; 9, call; 9, 10; 9, 18; 10, attribute; 10, 11; 10, 17; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:pathlib; 14, identifier:Path; 15, argument_list; 15, 16; 16, identifier:directory; 17, identifier:resolve; 18, argument_list; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:tdmslist; 22, list_comprehension; 22, 23; 22, 24; 22, 32; 23, identifier:r; 24, for_in_clause; 24, 25; 24, 26; 25, identifier:r; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:path; 29, identifier:rglob; 30, argument_list; 30, 31; 31, string:"*.tdms"; 32, if_clause; 32, 33; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:r; 36, identifier:is_file; 37, argument_list; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:tdmslist; 41, list_comprehension; 41, 42; 41, 43; 41, 46; 42, identifier:r; 43, for_in_clause; 43, 44; 43, 45; 44, identifier:r; 45, identifier:tdmslist; 46, if_clause; 46, 47; 47, not_operator; 47, 48; 48, call; 48, 49; 48, 54; 49, attribute; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:r; 52, identifier:name; 53, identifier:endswith; 54, argument_list; 54, 55; 55, string:"_traces.tdms"; 56, return_statement; 56, 57; 57, call; 57, 58; 57, 59; 58, identifier:sorted; 59, argument_list; 59, 60; 60, identifier:tdmslist | def get_tdms_files(directory):
path = pathlib.Path(directory).resolve()
tdmslist = [r for r in path.rglob("*.tdms") if r.is_file()]
tdmslist = [r for r in tdmslist if not r.name.endswith("_traces.tdms")]
return sorted(tdmslist) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:footrule_dist; 3, parameters; 3, 4; 3, 5; 4, identifier:params1; 5, default_parameter; 5, 6; 5, 7; 6, identifier:params2; 7, None; 8, block; 8, 9; 8, 11; 8, 25; 8, 35; 8, 70; 9, expression_statement; 9, 10; 10, identifier:r; 11, assert_statement; 11, 12; 12, boolean_operator:or; 12, 13; 12, 16; 13, comparison_operator:is; 13, 14; 13, 15; 14, identifier:params2; 15, None; 16, comparison_operator:==; 16, 17; 16, 21; 17, call; 17, 18; 17, 19; 18, identifier:len; 19, argument_list; 19, 20; 20, identifier:params1; 21, call; 21, 22; 21, 23; 22, identifier:len; 23, argument_list; 23, 24; 24, identifier:params2; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:ranks1; 28, call; 28, 29; 28, 30; 29, identifier:rankdata; 30, argument_list; 30, 31; 30, 32; 31, identifier:params1; 32, keyword_argument; 32, 33; 32, 34; 33, identifier:method; 34, string:"average"; 35, if_statement; 35, 36; 35, 39; 35, 58; 36, comparison_operator:is; 36, 37; 36, 38; 37, identifier:params2; 38, None; 39, block; 39, 40; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:ranks2; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:np; 46, identifier:arange; 47, argument_list; 47, 48; 47, 49; 47, 55; 48, integer:1; 49, binary_operator:+; 49, 50; 49, 54; 50, call; 50, 51; 50, 52; 51, identifier:len; 52, argument_list; 52, 53; 53, identifier:params1; 54, integer:1; 55, keyword_argument; 55, 56; 55, 57; 56, identifier:dtype; 57, identifier:float; 58, else_clause; 58, 59; 59, block; 59, 60; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:ranks2; 63, call; 63, 64; 63, 65; 64, identifier:rankdata; 65, argument_list; 65, 66; 65, 67; 66, identifier:params2; 67, keyword_argument; 67, 68; 67, 69; 68, identifier:method; 69, string:"average"; 70, return_statement; 70, 71; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:np; 74, identifier:sum; 75, argument_list; 75, 76; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:np; 79, identifier:abs; 80, argument_list; 80, 81; 81, binary_operator:-; 81, 82; 81, 83; 82, identifier:ranks1; 83, identifier:ranks2 | def footrule_dist(params1, params2=None):
r
assert params2 is None or len(params1) == len(params2)
ranks1 = rankdata(params1, method="average")
if params2 is None:
ranks2 = np.arange(1, len(params1) + 1, dtype=float)
else:
ranks2 = rankdata(params2, method="average")
return np.sum(np.abs(ranks1 - ranks2)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:kendalltau_dist; 3, parameters; 3, 4; 3, 5; 4, identifier:params1; 5, default_parameter; 5, 6; 5, 7; 6, identifier:params2; 7, None; 8, block; 8, 9; 8, 11; 8, 25; 8, 35; 8, 70; 8, 80; 8, 87; 8, 98; 9, expression_statement; 9, 10; 10, identifier:r; 11, assert_statement; 11, 12; 12, boolean_operator:or; 12, 13; 12, 16; 13, comparison_operator:is; 13, 14; 13, 15; 14, identifier:params2; 15, None; 16, comparison_operator:==; 16, 17; 16, 21; 17, call; 17, 18; 17, 19; 18, identifier:len; 19, argument_list; 19, 20; 20, identifier:params1; 21, call; 21, 22; 21, 23; 22, identifier:len; 23, argument_list; 23, 24; 24, identifier:params2; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:ranks1; 28, call; 28, 29; 28, 30; 29, identifier:rankdata; 30, argument_list; 30, 31; 30, 32; 31, identifier:params1; 32, keyword_argument; 32, 33; 32, 34; 33, identifier:method; 34, string:"ordinal"; 35, if_statement; 35, 36; 35, 39; 35, 58; 36, comparison_operator:is; 36, 37; 36, 38; 37, identifier:params2; 38, None; 39, block; 39, 40; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:ranks2; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:np; 46, identifier:arange; 47, argument_list; 47, 48; 47, 49; 47, 55; 48, integer:1; 49, binary_operator:+; 49, 50; 49, 54; 50, call; 50, 51; 50, 52; 51, identifier:len; 52, argument_list; 52, 53; 53, identifier:params1; 54, integer:1; 55, keyword_argument; 55, 56; 55, 57; 56, identifier:dtype; 57, identifier:float; 58, else_clause; 58, 59; 59, block; 59, 60; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:ranks2; 63, call; 63, 64; 63, 65; 64, identifier:rankdata; 65, argument_list; 65, 66; 65, 67; 66, identifier:params2; 67, keyword_argument; 67, 68; 67, 69; 68, identifier:method; 69, string:"ordinal"; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 75; 72, pattern_list; 72, 73; 72, 74; 73, identifier:tau; 74, identifier:_; 75, call; 75, 76; 75, 77; 76, identifier:kendalltau; 77, argument_list; 77, 78; 77, 79; 78, identifier:ranks1; 79, identifier:ranks2; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:n_items; 83, call; 83, 84; 83, 85; 84, identifier:len; 85, argument_list; 85, 86; 86, identifier:params1; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:n_pairs; 90, binary_operator:/; 90, 91; 90, 97; 91, binary_operator:*; 91, 92; 91, 93; 92, identifier:n_items; 93, parenthesized_expression; 93, 94; 94, binary_operator:-; 94, 95; 94, 96; 95, identifier:n_items; 96, integer:1; 97, integer:2; 98, return_statement; 98, 99; 99, call; 99, 100; 99, 101; 100, identifier:round; 101, argument_list; 101, 102; 102, binary_operator:/; 102, 103; 102, 109; 103, parenthesized_expression; 103, 104; 104, binary_operator:-; 104, 105; 104, 106; 105, identifier:n_pairs; 106, binary_operator:*; 106, 107; 106, 108; 107, identifier:n_pairs; 108, identifier:tau; 109, integer:2 | def kendalltau_dist(params1, params2=None):
r
assert params2 is None or len(params1) == len(params2)
ranks1 = rankdata(params1, method="ordinal")
if params2 is None:
ranks2 = np.arange(1, len(params1) + 1, dtype=float)
else:
ranks2 = rankdata(params2, method="ordinal")
tau, _ = kendalltau(ranks1, ranks2)
n_items = len(params1)
n_pairs = n_items * (n_items - 1) / 2
return round((n_pairs - n_pairs * tau) / 2) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:parse_sort_string; 3, parameters; 3, 4; 4, identifier:sort; 5, block; 5, 6; 5, 14; 5, 23; 5, 27; 5, 100; 5, 107; 6, if_statement; 6, 7; 6, 10; 7, comparison_operator:is; 7, 8; 7, 9; 8, identifier:sort; 9, None; 10, block; 10, 11; 11, return_statement; 11, 12; 12, list:['_score']; 12, 13; 13, string:'_score'; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:l; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:sort; 20, identifier:rsplit; 21, argument_list; 21, 22; 22, string:','; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:sortlist; 26, list:[]; 27, for_statement; 27, 28; 27, 29; 27, 30; 28, identifier:se; 29, identifier:l; 30, block; 30, 31; 30, 39; 30, 53; 30, 73; 30, 81; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:se; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:se; 37, identifier:strip; 38, argument_list; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:order; 42, conditional_expression:if; 42, 43; 42, 44; 42, 52; 43, string:'desc'; 44, comparison_operator:==; 44, 45; 44, 51; 45, subscript; 45, 46; 45, 47; 46, identifier:se; 47, slice; 47, 48; 47, 49; 47, 50; 48, integer:0; 49, colon; 50, integer:1; 51, string:'-'; 52, string:'asc'; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:field; 56, conditional_expression:if; 56, 57; 56, 62; 56, 72; 57, subscript; 57, 58; 57, 59; 58, identifier:se; 59, slice; 59, 60; 59, 61; 60, integer:1; 61, colon; 62, comparison_operator:in; 62, 63; 62, 69; 63, subscript; 63, 64; 63, 65; 64, identifier:se; 65, slice; 65, 66; 65, 67; 65, 68; 66, integer:0; 67, colon; 68, integer:1; 69, list:['-', '+']; 69, 70; 69, 71; 70, string:'-'; 71, string:'+'; 72, identifier:se; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:field; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:field; 79, identifier:strip; 80, argument_list; 81, expression_statement; 81, 82; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:sortlist; 85, identifier:append; 86, argument_list; 86, 87; 87, dictionary; 87, 88; 88, pair; 88, 89; 88, 90; 89, identifier:field; 90, dictionary; 90, 91; 90, 94; 90, 97; 91, pair; 91, 92; 91, 93; 92, string:"order"; 93, identifier:order; 94, pair; 94, 95; 94, 96; 95, string:"unmapped_type"; 96, string:"string"; 97, pair; 97, 98; 97, 99; 98, string:"missing"; 99, string:"_last"; 100, expression_statement; 100, 101; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:sortlist; 104, identifier:append; 105, argument_list; 105, 106; 106, string:'_score'; 107, return_statement; 107, 108; 108, identifier:sortlist | def parse_sort_string(sort):
if sort is None:
return ['_score']
l = sort.rsplit(',')
sortlist = []
for se in l:
se = se.strip()
order = 'desc' if se[0:1] == '-' else 'asc'
field = se[1:] if se[0:1] in ['-', '+'] else se
field = field.strip()
sortlist.append({field: {"order": order, "unmapped_type": "string", "missing": "_last"}})
sortlist.append('_score')
return sortlist |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:get_config_dir; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:path; 5, default_parameter; 5, 6; 5, 7; 6, identifier:pattern; 7, string:"*.config"; 8, default_parameter; 8, 9; 8, 10; 9, identifier:configspec; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:allow_errors; 13, False; 14, block; 14, 15; 14, 24; 14, 37; 14, 55; 14, 62; 14, 68; 14, 136; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:logger; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:logging; 21, identifier:getLogger; 22, argument_list; 22, 23; 23, identifier:__name__; 24, expression_statement; 24, 25; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:logger; 28, identifier:debug; 29, argument_list; 29, 30; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, string:"Loading all files matching {0} in {1}"; 33, identifier:format; 34, argument_list; 34, 35; 34, 36; 35, identifier:pattern; 36, identifier:path; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:files; 40, call; 40, 41; 40, 54; 41, attribute; 41, 42; 41, 53; 42, call; 42, 43; 42, 44; 43, identifier:Globber; 44, argument_list; 44, 45; 44, 46; 44, 50; 45, identifier:path; 46, keyword_argument; 46, 47; 46, 48; 47, identifier:include; 48, list:[pattern]; 48, 49; 49, identifier:pattern; 50, keyword_argument; 50, 51; 50, 52; 51, identifier:recursive; 52, False; 53, identifier:glob; 54, argument_list; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:files; 58, call; 58, 59; 58, 60; 59, identifier:sorted; 60, argument_list; 60, 61; 61, identifier:files; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:config; 65, call; 65, 66; 65, 67; 66, identifier:ConfigObj; 67, argument_list; 68, for_statement; 68, 69; 68, 70; 68, 71; 69, identifier:filename; 70, identifier:files; 71, block; 71, 72; 71, 84; 71, 117; 71, 129; 72, expression_statement; 72, 73; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:logger; 76, identifier:debug; 77, argument_list; 77, 78; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, string:"- Loading config for {0}"; 81, identifier:format; 82, argument_list; 82, 83; 83, identifier:filename; 84, try_statement; 84, 85; 84, 96; 85, block; 85, 86; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:conf; 89, call; 89, 90; 89, 91; 90, identifier:ConfigObj; 91, argument_list; 91, 92; 91, 93; 92, identifier:filename; 93, keyword_argument; 93, 94; 93, 95; 94, identifier:configspec; 95, identifier:configspec; 96, except_clause; 96, 97; 96, 98; 96, 99; 97, identifier:ConfigObjError; 98, identifier:coe; 99, block; 99, 100; 99, 116; 100, expression_statement; 100, 101; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:logger; 104, identifier:error; 105, argument_list; 105, 106; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, string:"An error occurred while parsing {0}: {1}"; 109, identifier:format; 110, argument_list; 110, 111; 110, 112; 111, identifier:filename; 112, call; 112, 113; 112, 114; 113, identifier:str; 114, argument_list; 114, 115; 115, identifier:coe; 116, continue_statement; 117, if_statement; 117, 118; 117, 119; 118, identifier:configspec; 119, block; 119, 120; 120, expression_statement; 120, 121; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:conf; 124, identifier:validate; 125, argument_list; 125, 126; 126, call; 126, 127; 126, 128; 127, identifier:Validator; 128, argument_list; 129, expression_statement; 129, 130; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:config; 133, identifier:merge; 134, argument_list; 134, 135; 135, identifier:conf; 136, return_statement; 136, 137; 137, identifier:config | def get_config_dir(path, pattern="*.config", configspec=None, allow_errors=False):
logger = logging.getLogger(__name__)
logger.debug("Loading all files matching {0} in {1}".format(pattern, path))
files = Globber(path, include=[pattern], recursive=False).glob()
files = sorted(files)
config = ConfigObj()
for filename in files:
logger.debug("- Loading config for {0}".format(filename))
try:
conf = ConfigObj(filename, configspec=configspec)
except ConfigObjError, coe:
logger.error("An error occurred while parsing {0}: {1}".format(filename, str(coe)))
continue
if configspec:
conf.validate(Validator())
config.merge(conf)
return config |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 4; 2, function_name:is_first_instance_aws; 3, parameters; 4, block; 4, 5; 4, 51; 4, 114; 4, 174; 5, try_statement; 5, 6; 5, 35; 6, block; 6, 7; 6, 23; 6, 29; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:instance_details; 10, call; 10, 11; 10, 22; 11, attribute; 11, 12; 11, 21; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:requests; 15, identifier:get; 16, argument_list; 16, 17; 16, 18; 17, string:'http://169.254.169.254/latest/dynamic/instance-identity/document'; 18, keyword_argument; 18, 19; 18, 20; 19, identifier:timeout; 20, integer:5; 21, identifier:json; 22, argument_list; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:instance_id; 26, subscript; 26, 27; 26, 28; 27, identifier:instance_details; 28, string:'instanceId'; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:instance_region; 32, subscript; 32, 33; 32, 34; 33, identifier:instance_details; 34, string:'region'; 35, except_clause; 35, 36; 35, 45; 36, as_pattern; 36, 37; 36, 43; 37, tuple; 37, 38; 37, 41; 37, 42; 38, attribute; 38, 39; 38, 40; 39, identifier:requests; 40, identifier:RequestException; 41, identifier:ValueError; 42, identifier:KeyError; 43, as_pattern_target; 43, 44; 44, identifier:e; 45, block; 45, 46; 46, raise_statement; 46, 47; 47, call; 47, 48; 47, 49; 48, identifier:StackInterrogationException; 49, argument_list; 49, 50; 50, identifier:e; 51, try_statement; 51, 52; 51, 96; 51, 107; 52, block; 52, 53; 52, 65; 52, 77; 52, 86; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:autoscaling_client; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:boto3; 59, identifier:client; 60, argument_list; 60, 61; 60, 62; 61, string:'autoscaling'; 62, keyword_argument; 62, 63; 62, 64; 63, identifier:region_name; 64, identifier:instance_region; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:response; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:autoscaling_client; 71, identifier:describe_auto_scaling_instances; 72, argument_list; 72, 73; 73, keyword_argument; 73, 74; 73, 75; 74, identifier:InstanceIds; 75, list:[instance_id]; 75, 76; 76, identifier:instance_id; 77, assert_statement; 77, 78; 78, comparison_operator:==; 78, 79; 78, 85; 79, call; 79, 80; 79, 81; 80, identifier:len; 81, argument_list; 81, 82; 82, subscript; 82, 83; 82, 84; 83, identifier:response; 84, string:'AutoScalingInstances'; 85, integer:1; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:autoscaling_group; 89, subscript; 89, 90; 89, 95; 90, subscript; 90, 91; 90, 94; 91, subscript; 91, 92; 91, 93; 92, identifier:response; 93, string:'AutoScalingInstances'; 94, integer:0; 95, string:'AutoScalingGroupName'; 96, except_clause; 96, 97; 96, 101; 97, as_pattern; 97, 98; 97, 99; 98, identifier:ClientError; 99, as_pattern_target; 99, 100; 100, identifier:e; 101, block; 101, 102; 102, raise_statement; 102, 103; 103, call; 103, 104; 103, 105; 104, identifier:StackInterrogationException; 105, argument_list; 105, 106; 106, identifier:e; 107, except_clause; 107, 108; 107, 109; 108, identifier:AssertionError; 109, block; 109, 110; 110, raise_statement; 110, 111; 111, call; 111, 112; 111, 113; 112, identifier:InstanceNotInAsgException; 113, argument_list; 114, try_statement; 114, 115; 114, 161; 115, block; 115, 116; 115, 128; 115, 137; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 119; 118, identifier:response; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:autoscaling_client; 122, identifier:describe_auto_scaling_groups; 123, argument_list; 123, 124; 124, keyword_argument; 124, 125; 124, 126; 125, identifier:AutoScalingGroupNames; 126, list:[autoscaling_group]; 126, 127; 127, identifier:autoscaling_group; 128, assert_statement; 128, 129; 129, comparison_operator:==; 129, 130; 129, 136; 130, call; 130, 131; 130, 132; 131, identifier:len; 132, argument_list; 132, 133; 133, subscript; 133, 134; 133, 135; 134, identifier:response; 135, string:'AutoScalingGroups'; 136, integer:1; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:autoscaling_group_instance_ids; 140, call; 140, 141; 140, 142; 141, identifier:sorted; 142, generator_expression; 142, 143; 142, 146; 142, 155; 143, subscript; 143, 144; 143, 145; 144, identifier:instance; 145, string:'InstanceId'; 146, for_in_clause; 146, 147; 146, 148; 147, identifier:instance; 148, subscript; 148, 149; 148, 154; 149, subscript; 149, 150; 149, 153; 150, subscript; 150, 151; 150, 152; 151, identifier:response; 152, string:'AutoScalingGroups'; 153, integer:0; 154, string:'Instances'; 155, if_clause; 155, 156; 156, comparison_operator:==; 156, 157; 156, 160; 157, subscript; 157, 158; 157, 159; 158, identifier:instance; 159, string:'LifecycleState'; 160, string:'InService'; 161, except_clause; 161, 162; 161, 168; 162, as_pattern; 162, 163; 162, 166; 163, tuple; 163, 164; 163, 165; 164, identifier:ClientError; 165, identifier:AssertionError; 166, as_pattern_target; 166, 167; 167, identifier:e; 168, block; 168, 169; 169, raise_statement; 169, 170; 170, call; 170, 171; 170, 172; 171, identifier:StackInterrogationException; 172, argument_list; 172, 173; 173, identifier:e; 174, return_statement; 174, 175; 175, call; 175, 176; 175, 177; 176, identifier:bool; 177, argument_list; 177, 178; 178, boolean_operator:and; 178, 179; 178, 180; 179, identifier:autoscaling_group_instance_ids; 180, comparison_operator:==; 180, 181; 180, 184; 181, subscript; 181, 182; 181, 183; 182, identifier:autoscaling_group_instance_ids; 183, integer:0; 184, identifier:instance_id | def is_first_instance_aws():
try:
instance_details = requests.get('http://169.254.169.254/latest/dynamic/instance-identity/document',
timeout=5).json()
instance_id = instance_details['instanceId']
instance_region = instance_details['region']
except (requests.RequestException, ValueError, KeyError) as e:
raise StackInterrogationException(e)
try:
autoscaling_client = boto3.client('autoscaling', region_name=instance_region)
response = autoscaling_client.describe_auto_scaling_instances(InstanceIds=[instance_id])
assert len(response['AutoScalingInstances']) == 1
autoscaling_group = response['AutoScalingInstances'][0]['AutoScalingGroupName']
except ClientError as e:
raise StackInterrogationException(e)
except AssertionError:
raise InstanceNotInAsgException()
try:
response = autoscaling_client.describe_auto_scaling_groups(AutoScalingGroupNames=[autoscaling_group])
assert len(response['AutoScalingGroups']) == 1
autoscaling_group_instance_ids = sorted(
instance['InstanceId']
for instance in response['AutoScalingGroups'][0]['Instances']
if instance['LifecycleState'] == 'InService'
)
except (ClientError, AssertionError) as e:
raise StackInterrogationException(e)
return bool(autoscaling_group_instance_ids and autoscaling_group_instance_ids[0] == instance_id) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:creation_ordered; 3, parameters; 3, 4; 4, identifier:class_to_decorate; 5, block; 5, 6; 5, 20; 5, 26; 5, 67; 5, 74; 5, 88; 5, 95; 5, 104; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:next_index; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:functools; 12, identifier:partial; 13, argument_list; 13, 14; 13, 15; 14, identifier:next; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:itertools; 18, identifier:count; 19, argument_list; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:__init__orig; 23, attribute; 23, 24; 23, 25; 24, identifier:class_to_decorate; 25, identifier:__init__; 26, decorated_definition; 26, 27; 26, 38; 27, decorator; 27, 28; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:functools; 31, identifier:wraps; 32, argument_list; 32, 33; 32, 34; 33, identifier:__init__orig; 34, keyword_argument; 34, 35; 34, 36; 35, identifier:assigned; 36, list:['__doc__']; 36, 37; 37, string:'__doc__'; 38, function_definition; 38, 39; 38, 40; 38, 46; 39, function_name:__init__; 40, parameters; 40, 41; 40, 42; 40, 44; 41, identifier:self; 42, list_splat_pattern; 42, 43; 43, identifier:args; 44, dictionary_splat_pattern; 44, 45; 45, identifier:kwargs; 46, block; 46, 47; 46, 58; 47, expression_statement; 47, 48; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:object; 51, identifier:__setattr__; 52, argument_list; 52, 53; 52, 54; 52, 55; 53, identifier:self; 54, string:'_index'; 55, call; 55, 56; 55, 57; 56, identifier:next_index; 57, argument_list; 58, expression_statement; 58, 59; 59, call; 59, 60; 59, 61; 60, identifier:__init__orig; 61, argument_list; 61, 62; 61, 63; 61, 65; 62, identifier:self; 63, list_splat; 63, 64; 64, identifier:args; 65, dictionary_splat; 65, 66; 66, identifier:kwargs; 67, expression_statement; 67, 68; 68, call; 68, 69; 68, 70; 69, identifier:setattr; 70, argument_list; 70, 71; 70, 72; 70, 73; 71, identifier:class_to_decorate; 72, string:'__init__'; 73, identifier:__init__; 74, function_definition; 74, 75; 74, 76; 74, 79; 75, function_name:__lt__; 76, parameters; 76, 77; 76, 78; 77, identifier:self; 78, identifier:other; 79, block; 79, 80; 80, return_statement; 80, 81; 81, comparison_operator:<; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:self; 84, identifier:_index; 85, attribute; 85, 86; 85, 87; 86, identifier:other; 87, identifier:_index; 88, expression_statement; 88, 89; 89, call; 89, 90; 89, 91; 90, identifier:setattr; 91, argument_list; 91, 92; 91, 93; 91, 94; 92, identifier:class_to_decorate; 93, string:'__lt__'; 94, identifier:__lt__; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:class_to_decorate; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:functools; 101, identifier:total_ordering; 102, argument_list; 102, 103; 103, identifier:class_to_decorate; 104, return_statement; 104, 105; 105, identifier:class_to_decorate | def creation_ordered(class_to_decorate):
next_index = functools.partial(next, itertools.count())
__init__orig = class_to_decorate.__init__
@functools.wraps(__init__orig, assigned=['__doc__'])
def __init__(self, *args, **kwargs):
object.__setattr__(self, '_index', next_index())
__init__orig(self, *args, **kwargs)
setattr(class_to_decorate, '__init__', __init__)
def __lt__(self, other):
return self._index < other._index
setattr(class_to_decorate, '__lt__', __lt__)
class_to_decorate = functools.total_ordering(class_to_decorate)
return class_to_decorate |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:get_members; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:cls; 5, default_parameter; 5, 6; 5, 7; 6, identifier:member_class; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:is_member; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:sort_key; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:_parameter; 16, None; 17, block; 17, 18; 17, 32; 17, 38; 17, 82; 17, 170; 17, 176; 17, 233; 18, if_statement; 18, 19; 18, 26; 19, boolean_operator:and; 19, 20; 19, 23; 20, comparison_operator:is; 20, 21; 20, 22; 21, identifier:member_class; 22, None; 23, comparison_operator:is; 23, 24; 23, 25; 24, identifier:is_member; 25, None; 26, block; 26, 27; 27, raise_statement; 27, 28; 28, call; 28, 29; 28, 30; 29, identifier:TypeError; 30, argument_list; 30, 31; 31, string:"get_members either needs a member_class parameter or an is_member check function (or both)"; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:members; 35, call; 35, 36; 35, 37; 36, identifier:OrderedDict; 37, argument_list; 38, for_statement; 38, 39; 38, 40; 38, 43; 39, identifier:base; 40, attribute; 40, 41; 40, 42; 41, identifier:cls; 42, identifier:__bases__; 43, block; 43, 44; 43, 75; 44, if_statement; 44, 45; 44, 48; 44, 65; 45, comparison_operator:is; 45, 46; 45, 47; 46, identifier:_parameter; 47, None; 48, block; 48, 49; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:inherited_members; 52, call; 52, 53; 52, 54; 53, identifier:get_members; 54, argument_list; 54, 55; 54, 56; 54, 59; 54, 62; 55, identifier:base; 56, keyword_argument; 56, 57; 56, 58; 57, identifier:member_class; 58, identifier:member_class; 59, keyword_argument; 59, 60; 59, 61; 60, identifier:is_member; 61, identifier:is_member; 62, keyword_argument; 62, 63; 62, 64; 63, identifier:sort_key; 64, identifier:sort_key; 65, else_clause; 65, 66; 66, block; 66, 67; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:inherited_members; 70, call; 70, 71; 70, 72; 71, identifier:get_declared; 72, argument_list; 72, 73; 72, 74; 73, identifier:base; 74, identifier:_parameter; 75, expression_statement; 75, 76; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:members; 79, identifier:update; 80, argument_list; 80, 81; 81, identifier:inherited_members; 82, function_definition; 82, 83; 82, 84; 82, 85; 83, function_name:generate_member_bindings; 84, parameters; 85, block; 85, 86; 86, for_statement; 86, 87; 86, 88; 86, 91; 87, identifier:name; 88, attribute; 88, 89; 88, 90; 89, identifier:cls; 90, identifier:__dict__; 91, block; 91, 92; 91, 101; 91, 109; 92, if_statement; 92, 93; 92, 99; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:name; 96, identifier:startswith; 97, argument_list; 97, 98; 98, string:'__'; 99, block; 99, 100; 100, continue_statement; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:obj; 104, call; 104, 105; 104, 106; 105, identifier:getattr; 106, argument_list; 106, 107; 106, 108; 107, identifier:cls; 108, identifier:name; 109, if_statement; 109, 110; 109, 119; 109, 125; 109, 140; 110, boolean_operator:and; 110, 111; 110, 114; 111, comparison_operator:is; 111, 112; 111, 113; 112, identifier:member_class; 113, None; 114, call; 114, 115; 114, 116; 115, identifier:isinstance; 116, argument_list; 116, 117; 116, 118; 117, identifier:obj; 118, identifier:member_class; 119, block; 119, 120; 120, expression_statement; 120, 121; 121, yield; 121, 122; 122, expression_list; 122, 123; 122, 124; 123, identifier:name; 124, identifier:obj; 125, elif_clause; 125, 126; 125, 134; 126, boolean_operator:and; 126, 127; 126, 130; 127, comparison_operator:is; 127, 128; 127, 129; 128, identifier:is_member; 129, None; 130, call; 130, 131; 130, 132; 131, identifier:is_member; 132, argument_list; 132, 133; 133, identifier:obj; 134, block; 134, 135; 135, expression_statement; 135, 136; 136, yield; 136, 137; 137, expression_list; 137, 138; 137, 139; 138, identifier:name; 139, identifier:obj; 140, elif_clause; 140, 141; 140, 162; 141, boolean_operator:and; 141, 142; 141, 155; 142, boolean_operator:and; 142, 143; 142, 149; 143, comparison_operator:is; 143, 144; 143, 148; 144, call; 144, 145; 144, 146; 145, identifier:type; 146, argument_list; 146, 147; 147, identifier:obj; 148, identifier:tuple; 149, comparison_operator:==; 149, 150; 149, 154; 150, call; 150, 151; 150, 152; 151, identifier:len; 152, argument_list; 152, 153; 153, identifier:obj; 154, integer:1; 155, call; 155, 156; 155, 157; 156, identifier:isinstance; 157, argument_list; 157, 158; 157, 161; 158, subscript; 158, 159; 158, 160; 159, identifier:obj; 160, integer:0; 161, identifier:member_class; 162, block; 162, 163; 163, raise_statement; 163, 164; 164, call; 164, 165; 164, 166; 165, identifier:TypeError; 166, argument_list; 166, 167; 167, binary_operator:%; 167, 168; 167, 169; 168, string:"'%s' is a one-tuple containing what we are looking for. Trailing comma much? Don't... just don't."; 169, identifier:name; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 173; 172, identifier:bindings; 173, call; 173, 174; 173, 175; 174, identifier:generate_member_bindings; 175, argument_list; 176, if_statement; 176, 177; 176, 180; 176, 224; 177, comparison_operator:is; 177, 178; 177, 179; 178, identifier:sort_key; 179, None; 180, block; 180, 181; 180, 217; 181, try_statement; 181, 182; 181, 201; 182, block; 182, 183; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 186; 185, identifier:sorted_bindings; 186, call; 186, 187; 186, 188; 187, identifier:sorted; 188, argument_list; 188, 189; 188, 190; 189, identifier:bindings; 190, keyword_argument; 190, 191; 190, 192; 191, identifier:key; 192, lambda; 192, 193; 192, 195; 193, lambda_parameters; 193, 194; 194, identifier:x; 195, call; 195, 196; 195, 197; 196, identifier:sort_key; 197, argument_list; 197, 198; 198, subscript; 198, 199; 198, 200; 199, identifier:x; 200, integer:1; 201, except_clause; 201, 202; 201, 203; 202, identifier:AttributeError; 203, block; 203, 204; 204, if_statement; 204, 205; 204, 208; 204, 214; 205, comparison_operator:is; 205, 206; 205, 207; 206, identifier:sort_key; 207, identifier:default_sort_key; 208, block; 208, 209; 209, raise_statement; 209, 210; 210, call; 210, 211; 210, 212; 211, identifier:TypeError; 212, argument_list; 212, 213; 213, string:'Missing member ordering definition. Use @creation_ordered or specify sort_key'; 214, else_clause; 214, 215; 215, block; 215, 216; 216, raise_statement; 217, expression_statement; 217, 218; 218, call; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:members; 221, identifier:update; 222, argument_list; 222, 223; 223, identifier:sorted_bindings; 224, else_clause; 224, 225; 225, block; 225, 226; 226, expression_statement; 226, 227; 227, call; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:members; 230, identifier:update; 231, argument_list; 231, 232; 232, identifier:bindings; 233, return_statement; 233, 234; 234, identifier:members | def get_members(cls, member_class=None, is_member=None, sort_key=None, _parameter=None):
if member_class is None and is_member is None:
raise TypeError("get_members either needs a member_class parameter or an is_member check function (or both)")
members = OrderedDict()
for base in cls.__bases__:
if _parameter is None:
inherited_members = get_members(base, member_class=member_class, is_member=is_member, sort_key=sort_key)
else:
inherited_members = get_declared(base, _parameter)
members.update(inherited_members)
def generate_member_bindings():
for name in cls.__dict__:
if name.startswith('__'):
continue
obj = getattr(cls, name)
if member_class is not None and isinstance(obj, member_class):
yield name, obj
elif is_member is not None and is_member(obj):
yield name, obj
elif type(obj) is tuple and len(obj) == 1 and isinstance(obj[0], member_class):
raise TypeError("'%s' is a one-tuple containing what we are looking for. Trailing comma much? Don't... just don't." % name)
bindings = generate_member_bindings()
if sort_key is not None:
try:
sorted_bindings = sorted(bindings, key=lambda x: sort_key(x[1]))
except AttributeError:
if sort_key is default_sort_key:
raise TypeError('Missing member ordering definition. Use @creation_ordered or specify sort_key')
else:
raise
members.update(sorted_bindings)
else:
members.update(bindings)
return members |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:sort_field; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:field_name; 6, identifier:direction; 7, default_parameter; 7, 8; 7, 9; 8, identifier:field_vals; 9, None; 10, block; 10, 11; 10, 20; 10, 51; 10, 70; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:field_name; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:_normalize_field_name; 18, argument_list; 18, 19; 19, identifier:field_name; 20, if_statement; 20, 21; 20, 24; 20, 29; 20, 39; 21, comparison_operator:>; 21, 22; 21, 23; 22, identifier:direction; 23, integer:0; 24, block; 24, 25; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:direction; 28, integer:1; 29, elif_clause; 29, 30; 29, 33; 30, comparison_operator:<; 30, 31; 30, 32; 31, identifier:direction; 32, integer:0; 33, block; 33, 34; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:direction; 37, unary_operator:-; 37, 38; 38, integer:1; 39, else_clause; 39, 40; 40, block; 40, 41; 41, raise_statement; 41, 42; 42, call; 42, 43; 42, 44; 43, identifier:ValueError; 44, argument_list; 44, 45; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, string:"direction {} is undefined"; 48, identifier:format; 49, argument_list; 49, 50; 50, identifier:direction; 51, expression_statement; 51, 52; 52, call; 52, 53; 52, 58; 53, attribute; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:fields_sort; 57, identifier:append; 58, argument_list; 58, 59; 58, 60; 59, identifier:field_name; 60, list:[direction, field_name, list(field_vals) if field_vals else field_vals]; 60, 61; 60, 62; 60, 63; 61, identifier:direction; 62, identifier:field_name; 63, conditional_expression:if; 63, 64; 63, 68; 63, 69; 64, call; 64, 65; 64, 66; 65, identifier:list; 66, argument_list; 66, 67; 67, identifier:field_vals; 68, identifier:field_vals; 69, identifier:field_vals; 70, return_statement; 70, 71; 71, identifier:self | def sort_field(self, field_name, direction, field_vals=None):
field_name = self._normalize_field_name(field_name)
if direction > 0:
direction = 1
elif direction < 0:
direction = -1
else:
raise ValueError("direction {} is undefined".format(direction))
self.fields_sort.append(field_name, [direction, field_name, list(field_vals) if field_vals else field_vals])
return self |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:check_photometry_categorize; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:x; 5, identifier:y; 6, identifier:levels; 7, default_parameter; 7, 8; 7, 9; 8, identifier:tags; 9, None; 10, block; 10, 11; 10, 13; 10, 22; 10, 31; 10, 39; 10, 45; 10, 62; 10, 66; 10, 70; 10, 87; 10, 91; 10, 115; 10, 189; 11, expression_statement; 11, 12; 12, string:'''Put every point in its category.
levels must be sorted.'''; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:x; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:numpy; 19, identifier:asarray; 20, argument_list; 20, 21; 21, identifier:x; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:y; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:numpy; 28, identifier:asarray; 29, argument_list; 29, 30; 30, identifier:y; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:ys; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:y; 37, identifier:copy; 38, argument_list; 39, expression_statement; 39, 40; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:ys; 43, identifier:sort; 44, argument_list; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:m; 48, call; 48, 49; 48, 61; 49, attribute; 49, 50; 49, 60; 50, subscript; 50, 51; 50, 52; 51, identifier:ys; 52, slice; 52, 53; 52, 59; 53, binary_operator://; 53, 54; 53, 58; 54, call; 54, 55; 54, 56; 55, identifier:len; 56, argument_list; 56, 57; 57, identifier:ys; 58, integer:2; 59, colon; 60, identifier:mean; 61, argument_list; 62, expression_statement; 62, 63; 63, augmented_assignment:/=; 63, 64; 63, 65; 64, identifier:y; 65, identifier:m; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:m; 69, float:1.0; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:s; 73, call; 73, 74; 73, 86; 74, attribute; 74, 75; 74, 85; 75, subscript; 75, 76; 75, 77; 76, identifier:ys; 77, slice; 77, 78; 77, 84; 78, binary_operator://; 78, 79; 78, 83; 79, call; 79, 80; 79, 81; 80, identifier:len; 81, argument_list; 81, 82; 82, identifier:ys; 83, integer:2; 84, colon; 85, identifier:std; 86, argument_list; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:result; 90, list:[]; 91, if_statement; 91, 92; 91, 95; 92, comparison_operator:is; 92, 93; 92, 94; 93, identifier:tags; 94, None; 95, block; 95, 96; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:tags; 99, call; 99, 100; 99, 101; 100, identifier:list; 101, argument_list; 101, 102; 102, call; 102, 103; 102, 108; 103, attribute; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:six; 106, identifier:moves; 107, identifier:range; 108, argument_list; 108, 109; 109, binary_operator:+; 109, 110; 109, 114; 110, call; 110, 111; 110, 112; 111, identifier:len; 112, argument_list; 112, 113; 113, identifier:levels; 114, integer:1; 115, for_statement; 115, 116; 115, 119; 115, 124; 115, 174; 116, pattern_list; 116, 117; 116, 118; 117, identifier:l; 118, identifier:t; 119, call; 119, 120; 119, 121; 120, identifier:zip; 121, argument_list; 121, 122; 121, 123; 122, identifier:levels; 123, identifier:tags; 124, block; 124, 125; 124, 131; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:indc; 128, comparison_operator:<; 128, 129; 128, 130; 129, identifier:y; 130, identifier:l; 131, if_statement; 131, 132; 131, 137; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:indc; 135, identifier:any; 136, argument_list; 137, block; 137, 138; 137, 144; 137, 150; 137, 160; 137, 167; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:x1; 141, subscript; 141, 142; 141, 143; 142, identifier:x; 143, identifier:indc; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:y1; 147, subscript; 147, 148; 147, 149; 148, identifier:y; 149, identifier:indc; 150, expression_statement; 150, 151; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:result; 154, identifier:append; 155, argument_list; 155, 156; 156, tuple; 156, 157; 156, 158; 156, 159; 157, identifier:x1; 158, identifier:y1; 159, identifier:t; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:x; 163, subscript; 163, 164; 163, 165; 164, identifier:x; 165, unary_operator:~; 165, 166; 166, identifier:indc; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 170; 169, identifier:y; 170, subscript; 170, 171; 170, 172; 171, identifier:y; 172, unary_operator:~; 172, 173; 173, identifier:indc; 174, else_clause; 174, 175; 175, block; 175, 176; 176, expression_statement; 176, 177; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:result; 180, identifier:append; 181, argument_list; 181, 182; 182, tuple; 182, 183; 182, 184; 182, 185; 183, identifier:x; 184, identifier:y; 185, subscript; 185, 186; 185, 187; 186, identifier:tags; 187, unary_operator:-; 187, 188; 188, integer:1; 189, return_statement; 189, 190; 190, expression_list; 190, 191; 190, 192; 191, identifier:result; 192, tuple; 192, 193; 192, 194; 193, identifier:m; 194, identifier:s | def check_photometry_categorize(x, y, levels, tags=None):
'''Put every point in its category.
levels must be sorted.'''
x = numpy.asarray(x)
y = numpy.asarray(y)
ys = y.copy()
ys.sort()
m = ys[len(ys) // 2:].mean()
y /= m
m = 1.0
s = ys[len(ys) // 2:].std()
result = []
if tags is None:
tags = list(six.moves.range(len(levels) + 1))
for l, t in zip(levels, tags):
indc = y < l
if indc.any():
x1 = x[indc]
y1 = y[indc]
result.append((x1, y1, t))
x = x[~indc]
y = y[~indc]
else:
result.append((x, y, tags[-1]))
return result, (m, s) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_normalize_sort_SQL; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:field_name; 6, identifier:field_vals; 7, identifier:sort_dir_str; 8, block; 8, 9; 8, 13; 8, 45; 8, 60; 8, 64; 8, 92; 8, 99; 8, 108; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:fvi; 12, None; 13, if_statement; 13, 14; 13, 17; 13, 29; 14, comparison_operator:==; 14, 15; 14, 16; 15, identifier:sort_dir_str; 16, string:'ASC'; 17, block; 17, 18; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:fvi; 21, generator_expression; 21, 22; 21, 23; 22, identifier:t; 23, for_in_clause; 23, 24; 23, 25; 24, identifier:t; 25, call; 25, 26; 25, 27; 26, identifier:enumerate; 27, argument_list; 27, 28; 28, identifier:field_vals; 29, else_clause; 29, 30; 30, block; 30, 31; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:fvi; 34, generator_expression; 34, 35; 34, 36; 35, identifier:t; 36, for_in_clause; 36, 37; 36, 38; 37, identifier:t; 38, call; 38, 39; 38, 40; 39, identifier:enumerate; 40, argument_list; 40, 41; 41, call; 41, 42; 41, 43; 42, identifier:reversed; 43, argument_list; 43, 44; 44, identifier:field_vals; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:query_sort_str; 48, list:[' CASE {}'.format(self._normalize_name(field_name))]; 48, 49; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, string:' CASE {}'; 52, identifier:format; 53, argument_list; 53, 54; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:_normalize_name; 58, argument_list; 58, 59; 59, identifier:field_name; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:query_args; 63, list:[]; 64, for_statement; 64, 65; 64, 68; 64, 69; 65, pattern_list; 65, 66; 65, 67; 66, identifier:i; 67, identifier:v; 68, identifier:fvi; 69, block; 69, 70; 69, 85; 70, expression_statement; 70, 71; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:query_sort_str; 74, identifier:append; 75, argument_list; 75, 76; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, string:' WHEN {} THEN {}'; 79, identifier:format; 80, argument_list; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:self; 83, identifier:val_placeholder; 84, identifier:i; 85, expression_statement; 85, 86; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:query_args; 89, identifier:append; 90, argument_list; 90, 91; 91, identifier:v; 92, expression_statement; 92, 93; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:query_sort_str; 96, identifier:append; 97, argument_list; 97, 98; 98, string:' END'; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:query_sort_str; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, string:"\n"; 105, identifier:join; 106, argument_list; 106, 107; 107, identifier:query_sort_str; 108, return_statement; 108, 109; 109, expression_list; 109, 110; 109, 111; 110, identifier:query_sort_str; 111, identifier:query_args | def _normalize_sort_SQL(self, field_name, field_vals, sort_dir_str):
fvi = None
if sort_dir_str == 'ASC':
fvi = (t for t in enumerate(field_vals))
else:
fvi = (t for t in enumerate(reversed(field_vals)))
query_sort_str = [' CASE {}'.format(self._normalize_name(field_name))]
query_args = []
for i, v in fvi:
query_sort_str.append(' WHEN {} THEN {}'.format(self.val_placeholder, i))
query_args.append(v)
query_sort_str.append(' END')
query_sort_str = "\n".join(query_sort_str)
return query_sort_str, query_args |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_process; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:segments; 6, block; 6, 7; 6, 19; 6, 30; 6, 49; 6, 58; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 12; 9, pattern_list; 9, 10; 9, 11; 10, identifier:mlh; 11, identifier:mlw; 12, expression_list; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:max_line_height; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:max_line_width; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:s; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:segments; 25, identifier:astype; 26, argument_list; 26, 27; 27, attribute; 27, 28; 27, 29; 28, identifier:numpy; 29, identifier:uint32; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:order; 33, binary_operator:+; 33, 34; 33, 44; 34, binary_operator:*; 34, 35; 34, 36; 35, identifier:mlw; 36, parenthesized_expression; 36, 37; 37, binary_operator://; 37, 38; 37, 43; 38, subscript; 38, 39; 38, 40; 38, 42; 39, identifier:s; 40, slice; 40, 41; 41, colon; 42, integer:1; 43, identifier:mlh; 44, subscript; 44, 45; 44, 46; 44, 48; 45, identifier:s; 46, slice; 46, 47; 47, colon; 48, integer:0; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:sort_order; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:numpy; 55, identifier:argsort; 56, argument_list; 56, 57; 57, identifier:order; 58, return_statement; 58, 59; 59, subscript; 59, 60; 59, 61; 60, identifier:segments; 61, identifier:sort_order | def _process(self, segments):
mlh, mlw = self.max_line_height, self.max_line_width
s = segments.astype(numpy.uint32)
order = mlw * (s[:, 1] // mlh) + s[:, 0]
sort_order = numpy.argsort(order)
return segments[sort_order] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:flatten; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:rho; 5, identifier:pval; 6, default_parameter; 6, 7; 6, 8; 7, identifier:sortby; 8, string:"cor"; 9, block; 9, 10; 9, 18; 9, 30; 9, 63; 9, 80; 9, 133; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:n; 13, subscript; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:rho; 16, identifier:shape; 17, integer:0; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:idx; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:np; 24, identifier:triu_indices; 25, argument_list; 25, 26; 25, 27; 26, identifier:n; 27, keyword_argument; 27, 28; 27, 29; 28, identifier:k; 29, integer:1; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:tab; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:pd; 36, identifier:DataFrame; 37, argument_list; 37, 38; 37, 45; 38, keyword_argument; 38, 39; 38, 40; 39, identifier:columns; 40, list:['i', 'j', 'cor', 'pval']; 40, 41; 40, 42; 40, 43; 40, 44; 41, string:'i'; 42, string:'j'; 43, string:'cor'; 44, string:'pval'; 45, keyword_argument; 45, 46; 45, 47; 46, identifier:data; 47, subscript; 47, 48; 47, 51; 47, 54; 47, 57; 47, 60; 48, attribute; 48, 49; 48, 50; 49, identifier:np; 50, identifier:c_; 51, subscript; 51, 52; 51, 53; 52, identifier:idx; 53, integer:0; 54, subscript; 54, 55; 54, 56; 55, identifier:idx; 56, integer:1; 57, subscript; 57, 58; 57, 59; 58, identifier:rho; 59, identifier:idx; 60, subscript; 60, 61; 60, 62; 61, identifier:pval; 62, identifier:idx; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 70; 65, subscript; 65, 66; 65, 67; 66, identifier:tab; 67, list:['i', "j"]; 67, 68; 67, 69; 68, string:'i'; 69, string:"j"; 70, call; 70, 71; 70, 78; 71, attribute; 71, 72; 71, 77; 72, subscript; 72, 73; 72, 74; 73, identifier:tab; 74, list:['i', "j"]; 74, 75; 74, 76; 75, string:'i'; 76, string:"j"; 77, identifier:astype; 78, argument_list; 78, 79; 79, identifier:int; 80, if_statement; 80, 81; 80, 84; 80, 113; 81, comparison_operator:==; 81, 82; 81, 83; 82, identifier:sortby; 83, string:"cor"; 84, block; 84, 85; 84, 98; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 90; 87, subscript; 87, 88; 87, 89; 88, identifier:tab; 89, string:'abscor'; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:np; 93, identifier:abs; 94, argument_list; 94, 95; 95, subscript; 95, 96; 95, 97; 96, identifier:tab; 97, string:'cor'; 98, expression_statement; 98, 99; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:tab; 102, identifier:sort_values; 103, argument_list; 103, 104; 103, 107; 103, 110; 104, keyword_argument; 104, 105; 104, 106; 105, identifier:by; 106, string:'abscor'; 107, keyword_argument; 107, 108; 107, 109; 108, identifier:inplace; 109, True; 110, keyword_argument; 110, 111; 110, 112; 111, identifier:ascending; 112, False; 113, elif_clause; 113, 114; 113, 117; 114, comparison_operator:==; 114, 115; 114, 116; 115, identifier:sortby; 116, string:"pval"; 117, block; 117, 118; 118, expression_statement; 118, 119; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:tab; 122, identifier:sort_values; 123, argument_list; 123, 124; 123, 127; 123, 130; 124, keyword_argument; 124, 125; 124, 126; 125, identifier:by; 126, string:'pval'; 127, keyword_argument; 127, 128; 127, 129; 128, identifier:inplace; 129, True; 130, keyword_argument; 130, 131; 130, 132; 131, identifier:ascending; 132, True; 133, return_statement; 133, 134; 134, subscript; 134, 135; 134, 136; 135, identifier:tab; 136, list:["i", "j", "cor", "pval"]; 136, 137; 136, 138; 136, 139; 136, 140; 137, string:"i"; 138, string:"j"; 139, string:"cor"; 140, string:"pval" | def flatten(rho, pval, sortby="cor"):
n = rho.shape[0]
idx = np.triu_indices(n, k=1)
tab = pd.DataFrame(
columns=['i', 'j', 'cor', 'pval'],
data=np.c_[idx[0], idx[1], rho[idx], pval[idx]])
tab[['i', "j"]] = tab[['i', "j"]].astype(int)
if sortby == "cor":
tab['abscor'] = np.abs(tab['cor'])
tab.sort_values(by='abscor', inplace=True, ascending=False)
elif sortby == "pval":
tab.sort_values(by='pval', inplace=True, ascending=True)
return tab[["i", "j", "cor", "pval"]] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:has_code; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:state; 5, identifier:text; 6, default_parameter; 6, 7; 6, 8; 7, identifier:incorrect_msg; 8, string:"The checker expected to find `{{text}}` in your command."; 9, default_parameter; 9, 10; 9, 11; 10, identifier:fixed; 11, False; 12, block; 12, 13; 12, 19; 12, 34; 12, 60; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:stu_code; 16, attribute; 16, 17; 16, 18; 17, identifier:state; 18, identifier:student_code; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:res; 22, conditional_expression:if; 22, 23; 22, 26; 22, 27; 23, comparison_operator:in; 23, 24; 23, 25; 24, identifier:text; 25, identifier:stu_code; 26, identifier:fixed; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:re; 30, identifier:search; 31, argument_list; 31, 32; 31, 33; 32, identifier:text; 33, identifier:stu_code; 34, if_statement; 34, 35; 34, 37; 35, not_operator; 35, 36; 36, identifier:res; 37, block; 37, 38; 37, 53; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:_msg; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:state; 44, identifier:build_message; 45, argument_list; 45, 46; 45, 47; 46, identifier:incorrect_msg; 47, keyword_argument; 47, 48; 47, 49; 48, identifier:fmt_kwargs; 49, dictionary; 49, 50; 50, pair; 50, 51; 50, 52; 51, string:'text'; 52, identifier:text; 53, expression_statement; 53, 54; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:state; 57, identifier:do_test; 58, argument_list; 58, 59; 59, identifier:_msg; 60, return_statement; 60, 61; 61, identifier:state | def has_code(state, text, incorrect_msg="The checker expected to find `{{text}}` in your command.", fixed=False):
stu_code = state.student_code
res = text in stu_code if fixed else re.search(text, stu_code)
if not res:
_msg = state.build_message(incorrect_msg, fmt_kwargs={ 'text': text })
state.do_test(_msg)
return state |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 16; 2, function_name:topports; 3, parameters; 3, 4; 3, 7; 3, 10; 3, 13; 4, default_parameter; 4, 5; 4, 6; 5, identifier:sort_by; 6, string:'records'; 7, default_parameter; 7, 8; 7, 9; 8, identifier:limit; 9, integer:10; 10, default_parameter; 10, 11; 10, 12; 11, identifier:date; 12, None; 13, default_parameter; 13, 14; 13, 15; 14, identifier:return_format; 15, None; 16, block; 16, 17; 16, 32; 16, 67; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:uri; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, string:'/'; 23, identifier:join; 24, argument_list; 24, 25; 25, list:['topports', sort_by, str(limit)]; 25, 26; 25, 27; 25, 28; 26, string:'topports'; 27, identifier:sort_by; 28, call; 28, 29; 28, 30; 29, identifier:str; 30, argument_list; 30, 31; 31, identifier:limit; 32, if_statement; 32, 33; 32, 34; 33, identifier:date; 34, block; 34, 35; 35, try_statement; 35, 36; 35, 53; 36, block; 36, 37; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:uri; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, string:'/'; 43, identifier:join; 44, argument_list; 44, 45; 45, list:[uri, date.strftime("%Y-%m-%d")]; 45, 46; 45, 47; 46, identifier:uri; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:date; 50, identifier:strftime; 51, argument_list; 51, 52; 52, string:"%Y-%m-%d"; 53, except_clause; 53, 54; 53, 55; 54, identifier:AttributeError; 55, block; 55, 56; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:uri; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, string:'/'; 62, identifier:join; 63, argument_list; 63, 64; 64, list:[uri, date]; 64, 65; 64, 66; 65, identifier:uri; 66, identifier:date; 67, return_statement; 67, 68; 68, call; 68, 69; 68, 70; 69, identifier:_get; 70, argument_list; 70, 71; 70, 72; 71, identifier:uri; 72, identifier:return_format | def topports(sort_by='records', limit=10, date=None, return_format=None):
uri = '/'.join(['topports', sort_by, str(limit)])
if date:
try:
uri = '/'.join([uri, date.strftime("%Y-%m-%d")])
except AttributeError:
uri = '/'.join([uri, date])
return _get(uri, return_format) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:all_nodes_that_receive; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:service; 5, default_parameter; 5, 6; 5, 7; 6, identifier:service_configuration; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:run_only; 10, False; 11, default_parameter; 11, 12; 11, 13; 12, identifier:deploy_to_only; 13, False; 14, block; 14, 15; 14, 21; 14, 32; 14, 40; 14, 51; 14, 60; 14, 88; 15, assert_statement; 15, 16; 16, not_operator; 16, 17; 17, parenthesized_expression; 17, 18; 18, boolean_operator:and; 18, 19; 18, 20; 19, identifier:run_only; 20, identifier:deploy_to_only; 21, if_statement; 21, 22; 21, 25; 22, comparison_operator:is; 22, 23; 22, 24; 23, identifier:service_configuration; 24, None; 25, block; 25, 26; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:service_configuration; 29, call; 29, 30; 29, 31; 30, identifier:read_services_configuration; 31, argument_list; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:runs_on; 35, subscript; 35, 36; 35, 39; 36, subscript; 36, 37; 36, 38; 37, identifier:service_configuration; 38, identifier:service; 39, string:'runs_on'; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:deployed_to; 43, call; 43, 44; 43, 49; 44, attribute; 44, 45; 44, 48; 45, subscript; 45, 46; 45, 47; 46, identifier:service_configuration; 47, identifier:service; 48, identifier:get; 49, argument_list; 49, 50; 50, string:'deployed_to'; 51, if_statement; 51, 52; 51, 55; 52, comparison_operator:is; 52, 53; 52, 54; 53, identifier:deployed_to; 54, None; 55, block; 55, 56; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:deployed_to; 59, list:[]; 60, if_statement; 60, 61; 60, 62; 60, 67; 60, 74; 61, identifier:run_only; 62, block; 62, 63; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:result; 66, identifier:runs_on; 67, elif_clause; 67, 68; 67, 69; 68, identifier:deploy_to_only; 69, block; 69, 70; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:result; 73, identifier:deployed_to; 74, else_clause; 74, 75; 75, block; 75, 76; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:result; 79, binary_operator:|; 79, 80; 79, 84; 80, call; 80, 81; 80, 82; 81, identifier:set; 82, argument_list; 82, 83; 83, identifier:runs_on; 84, call; 84, 85; 84, 86; 85, identifier:set; 86, argument_list; 86, 87; 87, identifier:deployed_to; 88, return_statement; 88, 89; 89, call; 89, 90; 89, 91; 90, identifier:list; 91, argument_list; 91, 92; 92, call; 92, 93; 92, 94; 93, identifier:sorted; 94, argument_list; 94, 95; 95, identifier:result | def all_nodes_that_receive(service, service_configuration=None, run_only=False, deploy_to_only=False):
assert not (run_only and deploy_to_only)
if service_configuration is None:
service_configuration = read_services_configuration()
runs_on = service_configuration[service]['runs_on']
deployed_to = service_configuration[service].get('deployed_to')
if deployed_to is None:
deployed_to = []
if run_only:
result = runs_on
elif deploy_to_only:
result = deployed_to
else:
result = set(runs_on) | set(deployed_to)
return list(sorted(result)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_cuthill_mckee; 3, parameters; 3, 4; 3, 5; 4, identifier:vertices; 5, identifier:vertices_neighbours; 6, block; 6, 7; 6, 25; 6, 41; 6, 49; 6, 54; 6, 62; 6, 129; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:vertices_degrees; 10, dictionary_comprehension; 10, 11; 10, 22; 11, pair; 11, 12; 11, 13; 12, identifier:v; 13, call; 13, 14; 13, 15; 14, identifier:sum; 15, argument_list; 15, 16; 16, call; 16, 17; 16, 18; 17, identifier:itervalues; 18, argument_list; 18, 19; 19, subscript; 19, 20; 19, 21; 20, identifier:vertices_neighbours; 21, identifier:v; 22, for_in_clause; 22, 23; 22, 24; 23, identifier:v; 24, identifier:vertices; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:peripheral_vertex; 28, call; 28, 29; 28, 30; 29, identifier:min; 30, argument_list; 30, 31; 30, 32; 31, identifier:vertices; 32, keyword_argument; 32, 33; 32, 34; 33, identifier:key; 34, parenthesized_expression; 34, 35; 35, lambda; 35, 36; 35, 38; 36, lambda_parameters; 36, 37; 37, identifier:v; 38, subscript; 38, 39; 38, 40; 39, identifier:vertices_degrees; 40, identifier:v; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:visited; 44, call; 44, 45; 44, 46; 45, identifier:set; 46, argument_list; 46, 47; 47, list:[peripheral_vertex]; 47, 48; 48, identifier:peripheral_vertex; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:cm_order; 52, list:[peripheral_vertex]; 52, 53; 53, identifier:peripheral_vertex; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:previous_layer; 57, call; 57, 58; 57, 59; 58, identifier:set; 59, argument_list; 59, 60; 60, list:[peripheral_vertex]; 60, 61; 61, identifier:peripheral_vertex; 62, while_statement; 62, 63; 62, 72; 63, comparison_operator:<; 63, 64; 63, 68; 64, call; 64, 65; 64, 66; 65, identifier:len; 66, argument_list; 66, 67; 67, identifier:cm_order; 68, call; 68, 69; 68, 70; 69, identifier:len; 70, argument_list; 70, 71; 71, identifier:vertices; 72, block; 72, 73; 72, 79; 72, 92; 72, 99; 72, 106; 72, 125; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:adjacent; 76, call; 76, 77; 76, 78; 77, identifier:set; 78, argument_list; 79, for_statement; 79, 80; 79, 81; 79, 82; 80, identifier:vertex; 81, identifier:previous_layer; 82, block; 82, 83; 83, expression_statement; 83, 84; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:adjacent; 87, identifier:update; 88, argument_list; 88, 89; 89, subscript; 89, 90; 89, 91; 90, identifier:vertices_neighbours; 91, identifier:vertex; 92, expression_statement; 92, 93; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:adjacent; 96, identifier:difference_update; 97, argument_list; 97, 98; 98, identifier:visited; 99, expression_statement; 99, 100; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:visited; 103, identifier:update; 104, argument_list; 104, 105; 105, identifier:adjacent; 106, expression_statement; 106, 107; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:cm_order; 110, identifier:extend; 111, argument_list; 111, 112; 112, call; 112, 113; 112, 114; 113, identifier:sorted; 114, argument_list; 114, 115; 114, 116; 115, identifier:adjacent; 116, keyword_argument; 116, 117; 116, 118; 117, identifier:key; 118, parenthesized_expression; 118, 119; 119, lambda; 119, 120; 119, 122; 120, lambda_parameters; 120, 121; 121, identifier:v; 122, subscript; 122, 123; 122, 124; 123, identifier:vertices_degrees; 124, identifier:v; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:previous_layer; 128, identifier:adjacent; 129, return_statement; 129, 130; 130, identifier:cm_order | def _cuthill_mckee(vertices, vertices_neighbours):
vertices_degrees = {v: sum(itervalues(vertices_neighbours[v]))
for v in vertices}
peripheral_vertex = min(vertices, key=(lambda v: vertices_degrees[v]))
visited = set([peripheral_vertex])
cm_order = [peripheral_vertex]
previous_layer = set([peripheral_vertex])
while len(cm_order) < len(vertices):
adjacent = set()
for vertex in previous_layer:
adjacent.update(vertices_neighbours[vertex])
adjacent.difference_update(visited)
visited.update(adjacent)
cm_order.extend(sorted(adjacent, key=(lambda v: vertices_degrees[v])))
previous_layer = adjacent
return cm_order |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:write_csv; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:path; 7, None; 8, block; 8, 9; 8, 23; 8, 36; 8, 49; 8, 60; 8, 68; 8, 74; 9, expression_statement; 9, 10; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:sort_sections; 14, argument_list; 14, 15; 15, list:['Root', 'Contacts', 'Documentation', 'References', 'Resources', 'Citations', 'Schema']; 15, 16; 15, 17; 15, 18; 15, 19; 15, 20; 15, 21; 15, 22; 16, string:'Root'; 17, string:'Contacts'; 18, string:'Documentation'; 19, string:'References'; 20, string:'Resources'; 21, string:'Citations'; 22, string:'Schema'; 23, if_statement; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:description; 27, block; 27, 28; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:description; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:description; 36, if_statement; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:abstract; 40, block; 40, 41; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:description; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:abstract; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:t; 52, call; 52, 53; 52, 58; 53, attribute; 53, 54; 53, 57; 54, subscript; 54, 55; 54, 56; 55, identifier:self; 56, string:'Root'; 57, identifier:get_or_new_term; 58, argument_list; 58, 59; 59, string:'Root.Modified'; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:t; 64, identifier:value; 65, call; 65, 66; 65, 67; 66, identifier:datetime_now; 67, argument_list; 68, expression_statement; 68, 69; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:self; 72, identifier:sort_by_term; 73, argument_list; 74, return_statement; 74, 75; 75, call; 75, 76; 75, 81; 76, attribute; 76, 77; 76, 80; 77, call; 77, 78; 77, 79; 78, identifier:super; 79, argument_list; 80, identifier:write_csv; 81, argument_list; 81, 82; 82, call; 82, 83; 82, 84; 83, identifier:str; 84, argument_list; 84, 85; 85, identifier:path | def write_csv(self, path=None):
self.sort_sections(['Root', 'Contacts', 'Documentation', 'References', 'Resources', 'Citations', 'Schema'])
if self.description:
self.description = self.description
if self.abstract:
self.description = self.abstract
t = self['Root'].get_or_new_term('Root.Modified')
t.value = datetime_now()
self.sort_by_term()
return super().write_csv(str(path)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:validate_functions; 3, parameters; 3, 4; 3, 8; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:ast; 6, type; 6, 7; 7, identifier:BELAst; 8, identifier:bo; 9, block; 9, 10; 9, 99; 9, 118; 10, if_statement; 10, 11; 10, 16; 11, call; 11, 12; 11, 13; 12, identifier:isinstance; 13, argument_list; 13, 14; 13, 15; 14, identifier:ast; 15, identifier:Function; 16, block; 16, 17; 16, 24; 16, 40; 16, 46; 16, 59; 17, expression_statement; 17, 18; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:log; 21, identifier:debug; 22, argument_list; 22, 23; 23, string:f"Validating: {ast.name}, {ast.function_type}, {ast.args}"; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:function_signatures; 27, subscript; 27, 28; 27, 39; 28, subscript; 28, 29; 28, 36; 29, subscript; 29, 30; 29, 35; 30, subscript; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:bo; 33, identifier:spec; 34, string:"functions"; 35, string:"signatures"; 36, attribute; 36, 37; 36, 38; 37, identifier:ast; 38, identifier:name; 39, string:"signatures"; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:function_name; 43, attribute; 43, 44; 43, 45; 44, identifier:ast; 45, identifier:name; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 51; 48, tuple_pattern; 48, 49; 48, 50; 49, identifier:valid_function; 50, identifier:messages; 51, call; 51, 52; 51, 53; 52, identifier:check_function_args; 53, argument_list; 53, 54; 53, 57; 53, 58; 54, attribute; 54, 55; 54, 56; 55, identifier:ast; 56, identifier:args; 57, identifier:function_signatures; 58, identifier:function_name; 59, if_statement; 59, 60; 59, 62; 60, not_operator; 60, 61; 61, identifier:valid_function; 62, block; 62, 63; 62, 72; 62, 93; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:message; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, string:", "; 69, identifier:join; 70, argument_list; 70, 71; 71, identifier:messages; 72, expression_statement; 72, 73; 73, call; 73, 74; 73, 79; 74, attribute; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:bo; 77, identifier:validation_messages; 78, identifier:append; 79, argument_list; 79, 80; 80, tuple; 80, 81; 80, 82; 81, string:"ERROR"; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, string:"Invalid BEL Statement function {} - problem with function signatures: {}"; 85, identifier:format; 86, argument_list; 86, 87; 86, 92; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:ast; 90, identifier:to_string; 91, argument_list; 92, identifier:message; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:bo; 97, identifier:parse_valid; 98, False; 99, if_statement; 99, 100; 99, 105; 100, call; 100, 101; 100, 102; 101, identifier:hasattr; 102, argument_list; 102, 103; 102, 104; 103, identifier:ast; 104, string:"args"; 105, block; 105, 106; 106, for_statement; 106, 107; 106, 108; 106, 111; 107, identifier:arg; 108, attribute; 108, 109; 108, 110; 109, identifier:ast; 110, identifier:args; 111, block; 111, 112; 112, expression_statement; 112, 113; 113, call; 113, 114; 113, 115; 114, identifier:validate_functions; 115, argument_list; 115, 116; 115, 117; 116, identifier:arg; 117, identifier:bo; 118, return_statement; 118, 119; 119, identifier:bo | def validate_functions(ast: BELAst, bo):
if isinstance(ast, Function):
log.debug(f"Validating: {ast.name}, {ast.function_type}, {ast.args}")
function_signatures = bo.spec["functions"]["signatures"][ast.name]["signatures"]
function_name = ast.name
(valid_function, messages) = check_function_args(
ast.args, function_signatures, function_name
)
if not valid_function:
message = ", ".join(messages)
bo.validation_messages.append(
(
"ERROR",
"Invalid BEL Statement function {} - problem with function signatures: {}".format(
ast.to_string(), message
),
)
)
bo.parse_valid = False
if hasattr(ast, "args"):
for arg in ast.args:
validate_functions(arg, bo)
return bo |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 1, 16; 2, function_name:hash_nanopub; 3, parameters; 3, 4; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:nanopub; 6, type; 6, 7; 7, generic_type; 7, 8; 7, 9; 8, identifier:Mapping; 9, type_parameter; 9, 10; 9, 12; 10, type; 10, 11; 11, identifier:str; 12, type; 12, 13; 13, identifier:Any; 14, type; 14, 15; 15, identifier:str; 16, block; 16, 17; 16, 21; 16, 42; 16, 63; 16, 190; 16, 194; 16, 279; 16, 286; 16, 293; 16, 297; 16, 343; 16, 350; 16, 357; 16, 374; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:hash_list; 20, list:[]; 21, expression_statement; 21, 22; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:hash_list; 25, identifier:append; 26, argument_list; 26, 27; 27, call; 27, 28; 27, 41; 28, attribute; 28, 29; 28, 40; 29, call; 29, 30; 29, 37; 30, attribute; 30, 31; 30, 36; 31, subscript; 31, 32; 31, 35; 32, subscript; 32, 33; 32, 34; 33, identifier:nanopub; 34, string:"nanopub"; 35, string:"type"; 36, identifier:get; 37, argument_list; 37, 38; 37, 39; 38, string:"name"; 39, string:""; 40, identifier:strip; 41, argument_list; 42, expression_statement; 42, 43; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:hash_list; 46, identifier:append; 47, argument_list; 47, 48; 48, call; 48, 49; 48, 62; 49, attribute; 49, 50; 49, 61; 50, call; 50, 51; 50, 58; 51, attribute; 51, 52; 51, 57; 52, subscript; 52, 53; 52, 56; 53, subscript; 53, 54; 53, 55; 54, identifier:nanopub; 55, string:"nanopub"; 56, string:"type"; 57, identifier:get; 58, argument_list; 58, 59; 58, 60; 59, string:"version"; 60, string:""; 61, identifier:strip; 62, argument_list; 63, if_statement; 63, 64; 63, 75; 63, 122; 63, 156; 64, call; 64, 65; 64, 72; 65, attribute; 65, 66; 65, 71; 66, subscript; 66, 67; 66, 70; 67, subscript; 67, 68; 67, 69; 68, identifier:nanopub; 69, string:"nanopub"; 70, string:"citation"; 71, identifier:get; 72, argument_list; 72, 73; 72, 74; 73, string:"database"; 74, False; 75, block; 75, 76; 75, 99; 76, expression_statement; 76, 77; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:hash_list; 80, identifier:append; 81, argument_list; 81, 82; 82, call; 82, 83; 82, 98; 83, attribute; 83, 84; 83, 97; 84, call; 84, 85; 84, 94; 85, attribute; 85, 86; 85, 93; 86, subscript; 86, 87; 86, 92; 87, subscript; 87, 88; 87, 91; 88, subscript; 88, 89; 88, 90; 89, identifier:nanopub; 90, string:"nanopub"; 91, string:"citation"; 92, string:"database"; 93, identifier:get; 94, argument_list; 94, 95; 94, 96; 95, string:"name"; 96, string:""; 97, identifier:strip; 98, argument_list; 99, expression_statement; 99, 100; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:hash_list; 103, identifier:append; 104, argument_list; 104, 105; 105, call; 105, 106; 105, 121; 106, attribute; 106, 107; 106, 120; 107, call; 107, 108; 107, 117; 108, attribute; 108, 109; 108, 116; 109, subscript; 109, 110; 109, 115; 110, subscript; 110, 111; 110, 114; 111, subscript; 111, 112; 111, 113; 112, identifier:nanopub; 113, string:"nanopub"; 114, string:"citation"; 115, string:"database"; 116, identifier:get; 117, argument_list; 117, 118; 117, 119; 118, string:"id"; 119, string:""; 120, identifier:strip; 121, argument_list; 122, elif_clause; 122, 123; 122, 134; 123, call; 123, 124; 123, 131; 124, attribute; 124, 125; 124, 130; 125, subscript; 125, 126; 125, 129; 126, subscript; 126, 127; 126, 128; 127, identifier:nanopub; 128, string:"nanopub"; 129, string:"citation"; 130, identifier:get; 131, argument_list; 131, 132; 131, 133; 132, string:"uri"; 133, False; 134, block; 134, 135; 135, expression_statement; 135, 136; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:hash_list; 139, identifier:append; 140, argument_list; 140, 141; 141, call; 141, 142; 141, 155; 142, attribute; 142, 143; 142, 154; 143, call; 143, 144; 143, 151; 144, attribute; 144, 145; 144, 150; 145, subscript; 145, 146; 145, 149; 146, subscript; 146, 147; 146, 148; 147, identifier:nanopub; 148, string:"nanopub"; 149, string:"citation"; 150, identifier:get; 151, argument_list; 151, 152; 151, 153; 152, string:"uri"; 153, string:""; 154, identifier:strip; 155, argument_list; 156, elif_clause; 156, 157; 156, 168; 157, call; 157, 158; 157, 165; 158, attribute; 158, 159; 158, 164; 159, subscript; 159, 160; 159, 163; 160, subscript; 160, 161; 160, 162; 161, identifier:nanopub; 162, string:"nanopub"; 163, string:"citation"; 164, identifier:get; 165, argument_list; 165, 166; 165, 167; 166, string:"reference"; 167, False; 168, block; 168, 169; 169, expression_statement; 169, 170; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:hash_list; 173, identifier:append; 174, argument_list; 174, 175; 175, call; 175, 176; 175, 189; 176, attribute; 176, 177; 176, 188; 177, call; 177, 178; 177, 185; 178, attribute; 178, 179; 178, 184; 179, subscript; 179, 180; 179, 183; 180, subscript; 180, 181; 180, 182; 181, identifier:nanopub; 182, string:"nanopub"; 183, string:"citation"; 184, identifier:get; 185, argument_list; 185, 186; 185, 187; 186, string:"reference"; 187, string:""; 188, identifier:strip; 189, argument_list; 190, expression_statement; 190, 191; 191, assignment; 191, 192; 191, 193; 192, identifier:assertions; 193, list:[]; 194, for_statement; 194, 195; 194, 196; 194, 201; 195, identifier:assertion; 196, subscript; 196, 197; 196, 200; 197, subscript; 197, 198; 197, 199; 198, identifier:nanopub; 199, string:"nanopub"; 200, string:"assertions"; 201, block; 201, 202; 201, 218; 201, 234; 202, if_statement; 202, 203; 202, 211; 203, comparison_operator:is; 203, 204; 203, 210; 204, call; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:assertion; 207, identifier:get; 208, argument_list; 208, 209; 209, string:"relation"; 210, None; 211, block; 211, 212; 212, expression_statement; 212, 213; 213, assignment; 213, 214; 213, 217; 214, subscript; 214, 215; 214, 216; 215, identifier:assertion; 216, string:"relation"; 217, string:""; 218, if_statement; 218, 219; 218, 227; 219, comparison_operator:is; 219, 220; 219, 226; 220, call; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:assertion; 223, identifier:get; 224, argument_list; 224, 225; 225, string:"object"; 226, None; 227, block; 227, 228; 228, expression_statement; 228, 229; 229, assignment; 229, 230; 229, 233; 230, subscript; 230, 231; 230, 232; 231, identifier:assertion; 232, string:"object"; 233, string:""; 234, expression_statement; 234, 235; 235, call; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:assertions; 238, identifier:append; 239, argument_list; 239, 240; 240, call; 240, 241; 240, 278; 241, attribute; 241, 242; 241, 277; 242, call; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, string:" "; 245, identifier:join; 246, argument_list; 246, 247; 247, tuple; 247, 248; 247, 255; 247, 266; 248, call; 248, 249; 248, 254; 249, attribute; 249, 250; 249, 253; 250, subscript; 250, 251; 250, 252; 251, identifier:assertion; 252, string:"subject"; 253, identifier:strip; 254, argument_list; 255, call; 255, 256; 255, 265; 256, attribute; 256, 257; 256, 264; 257, call; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, identifier:assertion; 260, identifier:get; 261, argument_list; 261, 262; 261, 263; 262, string:"relation"; 263, string:""; 264, identifier:strip; 265, argument_list; 266, call; 266, 267; 266, 276; 267, attribute; 267, 268; 267, 275; 268, call; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:assertion; 271, identifier:get; 272, argument_list; 272, 273; 272, 274; 273, string:"object"; 274, string:""; 275, identifier:strip; 276, argument_list; 277, identifier:strip; 278, argument_list; 279, expression_statement; 279, 280; 280, assignment; 280, 281; 280, 282; 281, identifier:assertions; 282, call; 282, 283; 282, 284; 283, identifier:sorted; 284, argument_list; 284, 285; 285, identifier:assertions; 286, expression_statement; 286, 287; 287, call; 287, 288; 287, 291; 288, attribute; 288, 289; 288, 290; 289, identifier:hash_list; 290, identifier:extend; 291, argument_list; 291, 292; 292, identifier:assertions; 293, expression_statement; 293, 294; 294, assignment; 294, 295; 294, 296; 295, identifier:annotations; 296, list:[]; 297, for_statement; 297, 298; 297, 299; 297, 304; 298, identifier:anno; 299, subscript; 299, 300; 299, 303; 300, subscript; 300, 301; 300, 302; 301, identifier:nanopub; 302, string:"nanopub"; 303, string:"annotations"; 304, block; 304, 305; 305, expression_statement; 305, 306; 306, call; 306, 307; 306, 310; 307, attribute; 307, 308; 307, 309; 308, identifier:annotations; 309, identifier:append; 310, argument_list; 310, 311; 311, call; 311, 312; 311, 342; 312, attribute; 312, 313; 312, 341; 313, call; 313, 314; 313, 317; 314, attribute; 314, 315; 314, 316; 315, string:" "; 316, identifier:join; 317, argument_list; 317, 318; 318, tuple; 318, 319; 318, 330; 319, call; 319, 320; 319, 329; 320, attribute; 320, 321; 320, 328; 321, call; 321, 322; 321, 325; 322, attribute; 322, 323; 322, 324; 323, identifier:anno; 324, identifier:get; 325, argument_list; 325, 326; 325, 327; 326, string:"type"; 327, string:""; 328, identifier:strip; 329, argument_list; 330, call; 330, 331; 330, 340; 331, attribute; 331, 332; 331, 339; 332, call; 332, 333; 332, 336; 333, attribute; 333, 334; 333, 335; 334, identifier:anno; 335, identifier:get; 336, argument_list; 336, 337; 336, 338; 337, string:"id"; 338, string:""; 339, identifier:strip; 340, argument_list; 341, identifier:strip; 342, argument_list; 343, expression_statement; 343, 344; 344, assignment; 344, 345; 344, 346; 345, identifier:annotations; 346, call; 346, 347; 346, 348; 347, identifier:sorted; 348, argument_list; 348, 349; 349, identifier:annotations; 350, expression_statement; 350, 351; 351, call; 351, 352; 351, 355; 352, attribute; 352, 353; 352, 354; 353, identifier:hash_list; 354, identifier:extend; 355, argument_list; 355, 356; 356, identifier:annotations; 357, expression_statement; 357, 358; 358, assignment; 358, 359; 358, 360; 359, identifier:np_string; 360, call; 360, 361; 360, 364; 361, attribute; 361, 362; 361, 363; 362, string:" "; 363, identifier:join; 364, argument_list; 364, 365; 365, list_comprehension; 365, 366; 365, 371; 366, call; 366, 367; 366, 370; 367, attribute; 367, 368; 367, 369; 368, identifier:l; 369, identifier:lower; 370, argument_list; 371, for_in_clause; 371, 372; 371, 373; 372, identifier:l; 373, identifier:hash_list; 374, return_statement; 374, 375; 375, call; 375, 376; 375, 379; 376, attribute; 376, 377; 376, 378; 377, string:"{:x}"; 378, identifier:format; 379, argument_list; 379, 380; 380, call; 380, 381; 380, 382; 381, identifier:CityHash64; 382, argument_list; 382, 383; 383, identifier:np_string | def hash_nanopub(nanopub: Mapping[str, Any]) -> str:
hash_list = []
hash_list.append(nanopub["nanopub"]["type"].get("name", "").strip())
hash_list.append(nanopub["nanopub"]["type"].get("version", "").strip())
if nanopub["nanopub"]["citation"].get("database", False):
hash_list.append(
nanopub["nanopub"]["citation"]["database"].get("name", "").strip()
)
hash_list.append(
nanopub["nanopub"]["citation"]["database"].get("id", "").strip()
)
elif nanopub["nanopub"]["citation"].get("uri", False):
hash_list.append(nanopub["nanopub"]["citation"].get("uri", "").strip())
elif nanopub["nanopub"]["citation"].get("reference", False):
hash_list.append(nanopub["nanopub"]["citation"].get("reference", "").strip())
assertions = []
for assertion in nanopub["nanopub"]["assertions"]:
if assertion.get("relation") is None:
assertion["relation"] = ""
if assertion.get("object") is None:
assertion["object"] = ""
assertions.append(
" ".join(
(
assertion["subject"].strip(),
assertion.get("relation", "").strip(),
assertion.get("object", "").strip(),
)
).strip()
)
assertions = sorted(assertions)
hash_list.extend(assertions)
annotations = []
for anno in nanopub["nanopub"]["annotations"]:
annotations.append(
" ".join((anno.get("type", "").strip(), anno.get("id", "").strip())).strip()
)
annotations = sorted(annotations)
hash_list.extend(annotations)
np_string = " ".join([l.lower() for l in hash_list])
return "{:x}".format(CityHash64(np_string)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:build_listing; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 97; 5, 117; 6, function_definition; 6, 7; 6, 8; 6, 11; 7, function_name:func_entry; 8, parameters; 8, 9; 8, 10; 9, identifier:name; 10, identifier:func; 11, block; 11, 12; 11, 24; 11, 50; 11, 70; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 18; 14, pattern_list; 14, 15; 14, 16; 14, 17; 15, identifier:args; 16, identifier:varargs; 17, identifier:defaults; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:_get_arg_spec; 22, argument_list; 22, 23; 23, identifier:func; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:params; 27, list_comprehension; 27, 28; 27, 43; 27, 46; 28, dictionary; 28, 29; 28, 35; 28, 40; 29, pair; 29, 30; 29, 31; 30, string:'name'; 31, call; 31, 32; 31, 33; 32, identifier:str; 33, argument_list; 33, 34; 34, identifier:a; 35, pair; 35, 36; 35, 37; 36, string:'optional'; 37, comparison_operator:in; 37, 38; 37, 39; 38, identifier:a; 39, identifier:defaults; 40, pair; 40, 41; 40, 42; 41, string:'vararg'; 42, False; 43, for_in_clause; 43, 44; 43, 45; 44, identifier:a; 45, identifier:args; 46, if_clause; 46, 47; 47, comparison_operator:!=; 47, 48; 47, 49; 48, identifier:a; 49, string:'ctx'; 50, if_statement; 50, 51; 50, 52; 51, identifier:varargs; 52, block; 52, 53; 53, expression_statement; 53, 54; 54, augmented_assignment:+=; 54, 55; 54, 56; 55, identifier:params; 56, list:[{'name': str(varargs), 'optional': False, 'vararg': True}]; 56, 57; 57, dictionary; 57, 58; 57, 64; 57, 67; 58, pair; 58, 59; 58, 60; 59, string:'name'; 60, call; 60, 61; 60, 62; 61, identifier:str; 62, argument_list; 62, 63; 63, identifier:varargs; 64, pair; 64, 65; 64, 66; 65, string:'optional'; 66, False; 67, pair; 67, 68; 67, 69; 68, string:'vararg'; 69, True; 70, return_statement; 70, 71; 71, dictionary; 71, 72; 71, 82; 71, 94; 72, pair; 72, 73; 72, 74; 73, string:'name'; 74, call; 74, 75; 74, 76; 75, identifier:str; 76, argument_list; 76, 77; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:name; 80, identifier:upper; 81, argument_list; 82, pair; 82, 83; 82, 84; 83, string:'description'; 84, call; 84, 85; 84, 93; 85, attribute; 85, 86; 85, 92; 86, call; 86, 87; 86, 88; 87, identifier:str; 88, argument_list; 88, 89; 89, attribute; 89, 90; 89, 91; 90, identifier:func; 91, identifier:__doc__; 92, identifier:strip; 93, argument_list; 94, pair; 94, 95; 94, 96; 95, string:'params'; 96, identifier:params; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:listing; 100, list_comprehension; 100, 101; 100, 106; 101, call; 101, 102; 101, 103; 102, identifier:func_entry; 103, argument_list; 103, 104; 103, 105; 104, identifier:f_name; 105, identifier:f; 106, for_in_clause; 106, 107; 106, 110; 107, pattern_list; 107, 108; 107, 109; 108, identifier:f_name; 109, identifier:f; 110, call; 110, 111; 110, 116; 111, attribute; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:self; 114, identifier:_functions; 115, identifier:items; 116, argument_list; 117, return_statement; 117, 118; 118, call; 118, 119; 118, 120; 119, identifier:sorted; 120, argument_list; 120, 121; 120, 122; 121, identifier:listing; 122, keyword_argument; 122, 123; 122, 124; 123, identifier:key; 124, lambda; 124, 125; 124, 127; 125, lambda_parameters; 125, 126; 126, identifier:l; 127, subscript; 127, 128; 127, 129; 128, identifier:l; 129, string:'name' | def build_listing(self):
def func_entry(name, func):
args, varargs, defaults = self._get_arg_spec(func)
params = [{'name': str(a), 'optional': a in defaults, 'vararg': False} for a in args if a != 'ctx']
if varargs:
params += [{'name': str(varargs), 'optional': False, 'vararg': True}]
return {'name': str(name.upper()),
'description': str(func.__doc__).strip(),
'params': params}
listing = [func_entry(f_name, f) for f_name, f in self._functions.items()]
return sorted(listing, key=lambda l: l['name']) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:sort_url_qsl; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:cls; 5, identifier:raw_url; 6, dictionary_splat_pattern; 6, 7; 7, identifier:kwargs; 8, block; 8, 9; 8, 16; 8, 25; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:parsed_url; 12, call; 12, 13; 12, 14; 13, identifier:urlparse; 14, argument_list; 14, 15; 15, identifier:raw_url; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:qsl; 19, call; 19, 20; 19, 21; 20, identifier:parse_qsl; 21, argument_list; 21, 22; 22, attribute; 22, 23; 22, 24; 23, identifier:parsed_url; 24, identifier:query; 25, return_statement; 25, 26; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:cls; 29, identifier:_join_url; 30, argument_list; 30, 31; 30, 32; 31, identifier:parsed_url; 32, call; 32, 33; 32, 34; 33, identifier:sorted; 34, argument_list; 34, 35; 34, 36; 35, identifier:qsl; 36, dictionary_splat; 36, 37; 37, identifier:kwargs | def sort_url_qsl(cls, raw_url, **kwargs):
parsed_url = urlparse(raw_url)
qsl = parse_qsl(parsed_url.query)
return cls._join_url(parsed_url, sorted(qsl, **kwargs)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 23; 2, function_name:get_sorted_series_files; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:startpath; 7, string:""; 8, default_parameter; 8, 9; 8, 10; 9, identifier:series_number; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:return_files_with_info; 13, False; 14, default_parameter; 14, 15; 14, 16; 15, identifier:sort_keys; 16, string:"SliceLocation"; 17, default_parameter; 17, 18; 17, 19; 18, identifier:return_files; 19, True; 20, default_parameter; 20, 21; 20, 22; 21, identifier:remove_doubled_slice_locations; 22, True; 23, block; 23, 24; 23, 33; 23, 52; 23, 62; 23, 74; 23, 86; 23, 90; 23, 114; 23, 118; 23, 128; 23, 138; 23, 173; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:dcmdir; 27, subscript; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:files_with_info; 31, slice; 31, 32; 32, colon; 33, if_statement; 33, 34; 33, 37; 34, comparison_operator:is; 34, 35; 34, 36; 35, identifier:series_number; 36, None; 37, block; 37, 38; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:dcmdir; 41, list_comprehension; 41, 42; 41, 43; 41, 46; 42, identifier:line; 43, for_in_clause; 43, 44; 43, 45; 44, identifier:line; 45, identifier:dcmdir; 46, if_clause; 46, 47; 47, comparison_operator:==; 47, 48; 47, 51; 48, subscript; 48, 49; 48, 50; 49, identifier:line; 50, string:'SeriesNumber'; 51, identifier:series_number; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:dcmdir; 55, call; 55, 56; 55, 57; 56, identifier:sort_list_of_dicts; 57, argument_list; 57, 58; 57, 59; 58, identifier:dcmdir; 59, keyword_argument; 59, 60; 59, 61; 60, identifier:keys; 61, identifier:sort_keys; 62, expression_statement; 62, 63; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:logger; 66, identifier:debug; 67, argument_list; 67, 68; 68, binary_operator:+; 68, 69; 68, 70; 69, string:'SeriesNumber: '; 70, call; 70, 71; 70, 72; 71, identifier:str; 72, argument_list; 72, 73; 73, identifier:series_number; 74, if_statement; 74, 75; 74, 76; 75, identifier:remove_doubled_slice_locations; 76, block; 76, 77; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:dcmdir; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:self; 83, identifier:_remove_doubled_slice_locations; 84, argument_list; 84, 85; 85, identifier:dcmdir; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:filelist; 89, list:[]; 90, for_statement; 90, 91; 90, 92; 90, 93; 91, identifier:onefile; 92, identifier:dcmdir; 93, block; 93, 94; 94, expression_statement; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:filelist; 98, identifier:append; 99, argument_list; 99, 100; 100, call; 100, 101; 100, 106; 101, attribute; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:os; 104, identifier:path; 105, identifier:join; 106, argument_list; 106, 107; 106, 108; 106, 111; 107, identifier:startpath; 108, attribute; 108, 109; 108, 110; 109, identifier:self; 110, identifier:dirpath; 111, subscript; 111, 112; 111, 113; 112, identifier:onefile; 113, string:'filename'; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:retval; 117, list:[]; 118, if_statement; 118, 119; 118, 120; 119, identifier:return_files; 120, block; 120, 121; 121, expression_statement; 121, 122; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:retval; 125, identifier:append; 126, argument_list; 126, 127; 127, identifier:filelist; 128, if_statement; 128, 129; 128, 130; 129, identifier:return_files_with_info; 130, block; 130, 131; 131, expression_statement; 131, 132; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:retval; 135, identifier:append; 136, argument_list; 136, 137; 137, identifier:dcmdir; 138, if_statement; 138, 139; 138, 145; 138, 150; 138, 164; 139, comparison_operator:==; 139, 140; 139, 144; 140, call; 140, 141; 140, 142; 141, identifier:len; 142, argument_list; 142, 143; 143, identifier:retval; 144, integer:0; 145, block; 145, 146; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:retval; 149, None; 150, elif_clause; 150, 151; 150, 157; 151, comparison_operator:==; 151, 152; 151, 156; 152, call; 152, 153; 152, 154; 153, identifier:len; 154, argument_list; 154, 155; 155, identifier:retval; 156, integer:1; 157, block; 157, 158; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 161; 160, identifier:retval; 161, subscript; 161, 162; 161, 163; 162, identifier:retval; 163, integer:0; 164, else_clause; 164, 165; 165, block; 165, 166; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 169; 168, identifier:retval; 169, call; 169, 170; 169, 171; 170, identifier:tuple; 171, argument_list; 171, 172; 172, identifier:retval; 173, return_statement; 173, 174; 174, identifier:retval | def get_sorted_series_files(self, startpath="", series_number=None, return_files_with_info=False,
sort_keys="SliceLocation", return_files=True, remove_doubled_slice_locations=True):
dcmdir = self.files_with_info[:]
if series_number is not None:
dcmdir = [
line for line in dcmdir if line['SeriesNumber'] == series_number
]
dcmdir = sort_list_of_dicts(dcmdir, keys=sort_keys)
logger.debug('SeriesNumber: ' + str(series_number))
if remove_doubled_slice_locations:
dcmdir = self._remove_doubled_slice_locations(dcmdir)
filelist = []
for onefile in dcmdir:
filelist.append(os.path.join(startpath,
self.dirpath, onefile['filename']))
retval = []
if return_files:
retval.append(filelist)
if return_files_with_info:
retval.append(dcmdir)
if len(retval) == 0:
retval = None
elif len(retval) == 1:
retval = retval[0]
else:
retval = tuple(retval)
return retval |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:guess_interval; 3, parameters; 3, 4; 3, 5; 4, identifier:nums; 5, default_parameter; 5, 6; 5, 7; 6, identifier:accuracy; 7, integer:0; 8, block; 8, 9; 8, 15; 8, 29; 8, 41; 8, 65; 8, 77; 8, 84; 8, 95; 9, if_statement; 9, 10; 9, 12; 10, not_operator; 10, 11; 11, identifier:nums; 12, block; 12, 13; 13, return_statement; 13, 14; 14, integer:0; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:nums; 18, call; 18, 19; 18, 20; 19, identifier:sorted; 20, argument_list; 20, 21; 21, list_comprehension; 21, 22; 21, 26; 22, call; 22, 23; 22, 24; 23, identifier:int; 24, argument_list; 24, 25; 25, identifier:i; 26, for_in_clause; 26, 27; 26, 28; 27, identifier:i; 28, identifier:nums; 29, if_statement; 29, 30; 29, 36; 30, comparison_operator:==; 30, 31; 30, 35; 31, call; 31, 32; 31, 33; 32, identifier:len; 33, argument_list; 33, 34; 34, identifier:nums; 35, integer:1; 36, block; 36, 37; 37, return_statement; 37, 38; 38, subscript; 38, 39; 38, 40; 39, identifier:nums; 40, integer:0; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:diffs; 44, list_comprehension; 44, 45; 44, 54; 45, binary_operator:-; 45, 46; 45, 51; 46, subscript; 46, 47; 46, 48; 47, identifier:nums; 48, binary_operator:+; 48, 49; 48, 50; 49, identifier:i; 50, integer:1; 51, subscript; 51, 52; 51, 53; 52, identifier:nums; 53, identifier:i; 54, for_in_clause; 54, 55; 54, 56; 55, identifier:i; 56, call; 56, 57; 56, 58; 57, identifier:range; 58, argument_list; 58, 59; 59, binary_operator:-; 59, 60; 59, 64; 60, call; 60, 61; 60, 62; 61, identifier:len; 62, argument_list; 62, 63; 63, identifier:nums; 64, integer:1; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:diffs; 68, list_comprehension; 68, 69; 68, 70; 68, 73; 69, identifier:item; 70, for_in_clause; 70, 71; 70, 72; 71, identifier:item; 72, identifier:diffs; 73, if_clause; 73, 74; 74, comparison_operator:>=; 74, 75; 74, 76; 75, identifier:item; 76, identifier:accuracy; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:sorted_diff; 80, call; 80, 81; 80, 82; 81, identifier:sorted; 82, argument_list; 82, 83; 83, identifier:diffs; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:result; 87, subscript; 87, 88; 87, 89; 88, identifier:sorted_diff; 89, binary_operator://; 89, 90; 89, 94; 90, call; 90, 91; 90, 92; 91, identifier:len; 92, argument_list; 92, 93; 93, identifier:diffs; 94, integer:2; 95, return_statement; 95, 96; 96, identifier:result | def guess_interval(nums, accuracy=0):
if not nums:
return 0
nums = sorted([int(i) for i in nums])
if len(nums) == 1:
return nums[0]
diffs = [nums[i + 1] - nums[i] for i in range(len(nums) - 1)]
diffs = [item for item in diffs if item >= accuracy]
sorted_diff = sorted(diffs)
result = sorted_diff[len(diffs) // 2]
return result |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:sort_list_of_dicts; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:lst_of_dct; 5, identifier:keys; 6, default_parameter; 6, 7; 6, 8; 7, identifier:reverse; 8, False; 9, dictionary_splat_pattern; 9, 10; 10, identifier:sort_args; 11, block; 11, 12; 11, 25; 11, 58; 12, if_statement; 12, 13; 12, 19; 13, comparison_operator:!=; 13, 14; 13, 18; 14, call; 14, 15; 14, 16; 15, identifier:type; 16, argument_list; 16, 17; 17, identifier:keys; 18, identifier:list; 19, block; 19, 20; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:keys; 23, list:[keys]; 23, 24; 24, identifier:keys; 25, expression_statement; 25, 26; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:lst_of_dct; 29, identifier:sort; 30, argument_list; 30, 31; 30, 53; 30, 56; 31, keyword_argument; 31, 32; 31, 33; 32, identifier:key; 33, lambda; 33, 34; 33, 36; 34, lambda_parameters; 34, 35; 35, identifier:x; 36, list_comprehension; 36, 37; 36, 50; 37, parenthesized_expression; 37, 38; 38, conditional_expression:if; 38, 39; 38, 44; 38, 47; 39, tuple; 39, 40; 39, 41; 40, False; 41, subscript; 41, 42; 41, 43; 42, identifier:x; 43, identifier:key; 44, comparison_operator:in; 44, 45; 44, 46; 45, identifier:key; 46, identifier:x; 47, tuple; 47, 48; 47, 49; 48, True; 49, integer:0; 50, for_in_clause; 50, 51; 50, 52; 51, identifier:key; 52, identifier:keys; 53, keyword_argument; 53, 54; 53, 55; 54, identifier:reverse; 55, identifier:reverse; 56, dictionary_splat; 56, 57; 57, identifier:sort_args; 58, return_statement; 58, 59; 59, identifier:lst_of_dct | def sort_list_of_dicts(lst_of_dct, keys, reverse=False, **sort_args):
if type(keys) != list:
keys = [keys]
lst_of_dct.sort(key=lambda x: [((False, x[key]) if key in x else (True, 0)) for key in keys], reverse=reverse, **sort_args)
return lst_of_dct |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:parallel_deblur; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:inputs; 5, identifier:params; 6, identifier:pos_ref_db_fp; 7, identifier:neg_ref_dp_fp; 8, default_parameter; 8, 9; 8, 10; 9, identifier:jobs_to_start; 10, integer:1; 11, block; 11, 12; 11, 21; 11, 33; 11, 42; 11, 46; 11, 50; 11, 83; 11, 109; 11, 135; 11, 144; 11, 153; 11, 162; 11, 173; 11, 180; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:logger; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:logging; 18, identifier:getLogger; 19, argument_list; 19, 20; 20, identifier:__name__; 21, expression_statement; 21, 22; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:logger; 25, identifier:info; 26, argument_list; 26, 27; 27, binary_operator:%; 27, 28; 27, 29; 28, string:'parallel deblur started for %d inputs'; 29, call; 29, 30; 29, 31; 30, identifier:len; 31, argument_list; 31, 32; 32, identifier:inputs; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:remove_param_list; 36, list:['-O', '--jobs-to-start', '--seqs-fp',
'--pos-ref-db-fp', '--neg-ref-db-fp']; 36, 37; 36, 38; 36, 39; 36, 40; 36, 41; 37, string:'-O'; 38, string:'--jobs-to-start'; 39, string:'--seqs-fp'; 40, string:'--pos-ref-db-fp'; 41, string:'--neg-ref-db-fp'; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:skipnext; 45, False; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:newparams; 49, list:[]; 50, for_statement; 50, 51; 50, 52; 50, 57; 51, identifier:carg; 52, subscript; 52, 53; 52, 54; 53, identifier:params; 54, slice; 54, 55; 54, 56; 55, integer:2; 56, colon; 57, block; 57, 58; 57, 66; 57, 76; 58, if_statement; 58, 59; 58, 60; 59, identifier:skipnext; 60, block; 60, 61; 60, 65; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:skipnext; 64, False; 65, continue_statement; 66, if_statement; 66, 67; 66, 70; 67, comparison_operator:in; 67, 68; 67, 69; 68, identifier:carg; 69, identifier:remove_param_list; 70, block; 70, 71; 70, 75; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:skipnext; 74, True; 75, continue_statement; 76, expression_statement; 76, 77; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:newparams; 80, identifier:append; 81, argument_list; 81, 82; 82, identifier:carg; 83, if_statement; 83, 84; 83, 85; 84, identifier:pos_ref_db_fp; 85, block; 85, 86; 85, 95; 85, 102; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:new_pos_ref_db_fp; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, string:','; 92, identifier:join; 93, argument_list; 93, 94; 94, identifier:pos_ref_db_fp; 95, expression_statement; 95, 96; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:newparams; 99, identifier:append; 100, argument_list; 100, 101; 101, string:'--pos-ref-db-fp'; 102, expression_statement; 102, 103; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:newparams; 106, identifier:append; 107, argument_list; 107, 108; 108, identifier:new_pos_ref_db_fp; 109, if_statement; 109, 110; 109, 111; 110, identifier:neg_ref_dp_fp; 111, block; 111, 112; 111, 121; 111, 128; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:new_neg_ref_db_fp; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, string:','; 118, identifier:join; 119, argument_list; 119, 120; 120, identifier:neg_ref_dp_fp; 121, expression_statement; 121, 122; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:newparams; 125, identifier:append; 126, argument_list; 126, 127; 127, string:'--neg-ref-db-fp'; 128, expression_statement; 128, 129; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:newparams; 132, identifier:append; 133, argument_list; 133, 134; 134, identifier:new_neg_ref_db_fp; 135, expression_statement; 135, 136; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:logger; 139, identifier:debug; 140, argument_list; 140, 141; 141, binary_operator:%; 141, 142; 141, 143; 142, string:'ready for functor %s'; 143, identifier:newparams; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:functor; 147, call; 147, 148; 147, 149; 148, identifier:partial; 149, argument_list; 149, 150; 149, 151; 149, 152; 150, identifier:run_functor; 151, identifier:deblur_system_call; 152, identifier:newparams; 153, expression_statement; 153, 154; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:logger; 157, identifier:debug; 158, argument_list; 158, 159; 159, binary_operator:%; 159, 160; 159, 161; 160, string:'ready for pool %d jobs'; 161, identifier:jobs_to_start; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:pool; 165, call; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:mp; 168, identifier:Pool; 169, argument_list; 169, 170; 170, keyword_argument; 170, 171; 170, 172; 171, identifier:processes; 172, identifier:jobs_to_start; 173, expression_statement; 173, 174; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:logger; 177, identifier:debug; 178, argument_list; 178, 179; 179, string:'almost running...'; 180, for_statement; 180, 181; 180, 185; 180, 192; 181, pattern_list; 181, 182; 181, 183; 181, 184; 182, identifier:stdout; 183, identifier:stderr; 184, identifier:es; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:pool; 188, identifier:map; 189, argument_list; 189, 190; 189, 191; 190, identifier:functor; 191, identifier:inputs; 192, block; 192, 193; 193, if_statement; 193, 194; 193, 197; 194, comparison_operator:!=; 194, 195; 194, 196; 195, identifier:es; 196, integer:0; 197, block; 197, 198; 198, raise_statement; 198, 199; 199, call; 199, 200; 199, 201; 200, identifier:RuntimeError; 201, argument_list; 201, 202; 202, binary_operator:%; 202, 203; 202, 204; 203, string:"stdout: %s\nstderr: %s\nexit: %d"; 204, tuple; 204, 205; 204, 206; 204, 207; 205, identifier:stdout; 206, identifier:stderr; 207, identifier:es | def parallel_deblur(inputs, params,
pos_ref_db_fp, neg_ref_dp_fp, jobs_to_start=1):
logger = logging.getLogger(__name__)
logger.info('parallel deblur started for %d inputs' % len(inputs))
remove_param_list = ['-O', '--jobs-to-start', '--seqs-fp',
'--pos-ref-db-fp', '--neg-ref-db-fp']
skipnext = False
newparams = []
for carg in params[2:]:
if skipnext:
skipnext = False
continue
if carg in remove_param_list:
skipnext = True
continue
newparams.append(carg)
if pos_ref_db_fp:
new_pos_ref_db_fp = ','.join(pos_ref_db_fp)
newparams.append('--pos-ref-db-fp')
newparams.append(new_pos_ref_db_fp)
if neg_ref_dp_fp:
new_neg_ref_db_fp = ','.join(neg_ref_dp_fp)
newparams.append('--neg-ref-db-fp')
newparams.append(new_neg_ref_db_fp)
logger.debug('ready for functor %s' % newparams)
functor = partial(run_functor, deblur_system_call, newparams)
logger.debug('ready for pool %d jobs' % jobs_to_start)
pool = mp.Pool(processes=jobs_to_start)
logger.debug('almost running...')
for stdout, stderr, es in pool.map(functor, inputs):
if es != 0:
raise RuntimeError("stdout: %s\nstderr: %s\nexit: %d" % (stdout,
stderr,
es)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:build_index_sortmerna; 3, parameters; 3, 4; 3, 5; 4, identifier:ref_fp; 5, identifier:working_dir; 6, block; 6, 7; 6, 16; 6, 29; 6, 33; 6, 164; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:logger; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:logging; 13, identifier:getLogger; 14, argument_list; 14, 15; 15, identifier:__name__; 16, expression_statement; 16, 17; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:logger; 20, identifier:info; 21, argument_list; 21, 22; 22, binary_operator:%; 22, 23; 22, 26; 23, concatenated_string; 23, 24; 23, 25; 24, string:'build_index_sortmerna files %s to'; 25, string:' dir %s'; 26, tuple; 26, 27; 26, 28; 27, identifier:ref_fp; 28, identifier:working_dir; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:all_db; 32, list:[]; 33, for_statement; 33, 34; 33, 35; 33, 36; 34, identifier:db; 35, identifier:ref_fp; 36, block; 36, 37; 36, 46; 36, 55; 36, 63; 36, 74; 36, 87; 36, 97; 36, 148; 36, 157; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 42; 39, pattern_list; 39, 40; 39, 41; 40, identifier:fasta_dir; 41, identifier:fasta_filename; 42, call; 42, 43; 42, 44; 43, identifier:split; 44, argument_list; 44, 45; 45, identifier:db; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:index_basename; 49, subscript; 49, 50; 49, 54; 50, call; 50, 51; 50, 52; 51, identifier:splitext; 52, argument_list; 52, 53; 53, identifier:fasta_filename; 54, integer:0; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:db_output; 58, call; 58, 59; 58, 60; 59, identifier:join; 60, argument_list; 60, 61; 60, 62; 61, identifier:working_dir; 62, identifier:index_basename; 63, expression_statement; 63, 64; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:logger; 67, identifier:debug; 68, argument_list; 68, 69; 69, binary_operator:%; 69, 70; 69, 71; 70, string:'processing file %s into location %s'; 71, tuple; 71, 72; 71, 73; 72, identifier:db; 73, identifier:db_output; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:params; 77, list:['indexdb_rna', '--ref', '%s,%s' %
(db, db_output), '--tmpdir', working_dir]; 77, 78; 77, 79; 77, 80; 77, 85; 77, 86; 78, string:'indexdb_rna'; 79, string:'--ref'; 80, binary_operator:%; 80, 81; 80, 82; 81, string:'%s,%s'; 82, tuple; 82, 83; 82, 84; 83, identifier:db; 84, identifier:db_output; 85, string:'--tmpdir'; 86, identifier:working_dir; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 93; 89, pattern_list; 89, 90; 89, 91; 89, 92; 90, identifier:sout; 91, identifier:serr; 92, identifier:res; 93, call; 93, 94; 93, 95; 94, identifier:_system_call; 95, argument_list; 95, 96; 96, identifier:params; 97, if_statement; 97, 98; 97, 102; 98, not_operator; 98, 99; 99, comparison_operator:==; 99, 100; 99, 101; 100, identifier:res; 101, integer:0; 102, block; 102, 103; 102, 116; 102, 125; 102, 134; 102, 141; 103, expression_statement; 103, 104; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:logger; 107, identifier:error; 108, argument_list; 108, 109; 109, binary_operator:%; 109, 110; 109, 113; 110, concatenated_string; 110, 111; 110, 112; 111, string:'Problem running indexdb_rna on file %s to dir %s. '; 112, string:'database not indexed'; 113, tuple; 113, 114; 113, 115; 114, identifier:db; 115, identifier:db_output; 116, expression_statement; 116, 117; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:logger; 120, identifier:debug; 121, argument_list; 121, 122; 122, binary_operator:%; 122, 123; 122, 124; 123, string:'stdout: %s'; 124, identifier:sout; 125, expression_statement; 125, 126; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:logger; 129, identifier:debug; 130, argument_list; 130, 131; 131, binary_operator:%; 131, 132; 131, 133; 132, string:'stderr: %s'; 133, identifier:serr; 134, expression_statement; 134, 135; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:logger; 138, identifier:critical; 139, argument_list; 139, 140; 140, string:'execution halted'; 141, raise_statement; 141, 142; 142, call; 142, 143; 142, 144; 143, identifier:RuntimeError; 144, argument_list; 144, 145; 145, binary_operator:%; 145, 146; 145, 147; 146, string:'Cannot index database file %s'; 147, identifier:db; 148, expression_statement; 148, 149; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:logger; 152, identifier:debug; 153, argument_list; 153, 154; 154, binary_operator:%; 154, 155; 154, 156; 155, string:'file %s indexed'; 156, identifier:db; 157, expression_statement; 157, 158; 158, call; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:all_db; 161, identifier:append; 162, argument_list; 162, 163; 163, identifier:db_output; 164, return_statement; 164, 165; 165, identifier:all_db | def build_index_sortmerna(ref_fp, working_dir):
logger = logging.getLogger(__name__)
logger.info('build_index_sortmerna files %s to'
' dir %s' % (ref_fp, working_dir))
all_db = []
for db in ref_fp:
fasta_dir, fasta_filename = split(db)
index_basename = splitext(fasta_filename)[0]
db_output = join(working_dir, index_basename)
logger.debug('processing file %s into location %s' % (db, db_output))
params = ['indexdb_rna', '--ref', '%s,%s' %
(db, db_output), '--tmpdir', working_dir]
sout, serr, res = _system_call(params)
if not res == 0:
logger.error('Problem running indexdb_rna on file %s to dir %s. '
'database not indexed' % (db, db_output))
logger.debug('stdout: %s' % sout)
logger.debug('stderr: %s' % serr)
logger.critical('execution halted')
raise RuntimeError('Cannot index database file %s' % db)
logger.debug('file %s indexed' % db)
all_db.append(db_output)
return all_db |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 21; 2, function_name:remove_artifacts_from_biom_table; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 12; 3, 15; 3, 18; 4, identifier:table_filename; 5, identifier:fasta_filename; 6, identifier:ref_fp; 7, identifier:biom_table_dir; 8, identifier:ref_db_fp; 9, default_parameter; 9, 10; 9, 11; 10, identifier:threads; 11, integer:1; 12, default_parameter; 12, 13; 12, 14; 13, identifier:verbose; 14, False; 15, default_parameter; 15, 16; 15, 17; 16, identifier:sim_thresh; 17, None; 18, default_parameter; 18, 19; 18, 20; 19, identifier:coverage_thresh; 20, None; 21, block; 21, 22; 21, 31; 21, 38; 21, 70; 21, 86; 21, 99; 21, 112; 21, 126; 21, 135; 21, 142; 21, 163; 21, 168; 21, 176; 21, 182; 21, 191; 21, 199; 21, 205; 21, 218; 21, 223; 21, 231; 21, 237; 21, 246; 21, 254; 21, 260; 21, 267; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:logger; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:logging; 28, identifier:getLogger; 29, argument_list; 29, 30; 30, identifier:__name__; 31, expression_statement; 31, 32; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:logger; 35, identifier:info; 36, argument_list; 36, 37; 37, string:'getting 16s sequences from the biom table'; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 44; 40, pattern_list; 40, 41; 40, 42; 40, 43; 41, identifier:clean_fp; 42, identifier:num_seqs_left; 43, identifier:tmp_files; 44, call; 44, 45; 44, 46; 45, identifier:remove_artifacts_seqs; 46, argument_list; 46, 47; 46, 48; 46, 49; 46, 52; 46, 55; 46, 58; 46, 61; 46, 64; 46, 67; 47, identifier:fasta_filename; 48, identifier:ref_fp; 49, keyword_argument; 49, 50; 49, 51; 50, identifier:working_dir; 51, identifier:biom_table_dir; 52, keyword_argument; 52, 53; 52, 54; 53, identifier:ref_db_fp; 54, identifier:ref_db_fp; 55, keyword_argument; 55, 56; 55, 57; 56, identifier:negate; 57, False; 58, keyword_argument; 58, 59; 58, 60; 59, identifier:threads; 60, identifier:threads; 61, keyword_argument; 61, 62; 61, 63; 62, identifier:verbose; 63, identifier:verbose; 64, keyword_argument; 64, 65; 64, 66; 65, identifier:sim_thresh; 66, identifier:sim_thresh; 67, keyword_argument; 67, 68; 67, 69; 68, identifier:coverage_thresh; 69, identifier:coverage_thresh; 70, if_statement; 70, 71; 70, 74; 71, comparison_operator:is; 71, 72; 71, 73; 72, identifier:clean_fp; 73, None; 74, block; 74, 75; 74, 84; 75, expression_statement; 75, 76; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:logger; 79, identifier:warn; 80, argument_list; 80, 81; 81, binary_operator:%; 81, 82; 81, 83; 82, string:"No clean sequences in %s"; 83, identifier:fasta_filename; 84, return_statement; 84, 85; 85, identifier:tmp_files; 86, expression_statement; 86, 87; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:logger; 90, identifier:debug; 91, argument_list; 91, 92; 92, binary_operator:%; 92, 93; 92, 96; 93, concatenated_string; 93, 94; 93, 95; 94, string:'removed artifacts from sequences input %s'; 95, string:' to output %s'; 96, tuple; 96, 97; 96, 98; 97, identifier:fasta_filename; 98, identifier:clean_fp; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:good_seqs; 102, set_comprehension; 102, 103; 102, 104; 103, identifier:s; 104, for_in_clause; 104, 105; 104, 108; 105, pattern_list; 105, 106; 105, 107; 106, identifier:_; 107, identifier:s; 108, call; 108, 109; 108, 110; 109, identifier:sequence_generator; 110, argument_list; 110, 111; 111, identifier:clean_fp; 112, expression_statement; 112, 113; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:logger; 116, identifier:debug; 117, argument_list; 117, 118; 118, binary_operator:%; 118, 119; 118, 122; 119, concatenated_string; 119, 120; 119, 121; 120, string:'loaded %d sequences from cleaned biom table'; 121, string:' fasta file'; 122, call; 122, 123; 122, 124; 123, identifier:len; 124, argument_list; 124, 125; 125, identifier:good_seqs; 126, expression_statement; 126, 127; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:logger; 130, identifier:debug; 131, argument_list; 131, 132; 132, binary_operator:%; 132, 133; 132, 134; 133, string:'loading biom table %s'; 134, identifier:table_filename; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:table; 138, call; 138, 139; 138, 140; 139, identifier:load_table; 140, argument_list; 140, 141; 141, identifier:table_filename; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 145; 144, identifier:artifact_table; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:table; 148, identifier:filter; 149, argument_list; 149, 150; 149, 154; 149, 157; 149, 160; 150, call; 150, 151; 150, 152; 151, identifier:list; 152, argument_list; 152, 153; 153, identifier:good_seqs; 154, keyword_argument; 154, 155; 154, 156; 155, identifier:axis; 156, string:'observation'; 157, keyword_argument; 157, 158; 157, 159; 158, identifier:inplace; 159, False; 160, keyword_argument; 160, 161; 160, 162; 161, identifier:invert; 162, True; 163, expression_statement; 163, 164; 164, call; 164, 165; 164, 166; 165, identifier:filter_minreads_samples_from_table; 166, argument_list; 166, 167; 167, identifier:artifact_table; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:output_nomatch_fp; 171, call; 171, 172; 171, 173; 172, identifier:join; 173, argument_list; 173, 174; 173, 175; 174, identifier:biom_table_dir; 175, string:'reference-non-hit.biom'; 176, expression_statement; 176, 177; 177, call; 177, 178; 177, 179; 178, identifier:write_biom_table; 179, argument_list; 179, 180; 179, 181; 180, identifier:artifact_table; 181, identifier:output_nomatch_fp; 182, expression_statement; 182, 183; 183, call; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:logger; 186, identifier:info; 187, argument_list; 187, 188; 188, binary_operator:%; 188, 189; 188, 190; 189, string:'wrote artifact only filtered biom table to %s'; 190, identifier:output_nomatch_fp; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:output_nomatch_fasta_fp; 194, call; 194, 195; 194, 196; 195, identifier:join; 196, argument_list; 196, 197; 196, 198; 197, identifier:biom_table_dir; 198, string:'reference-non-hit.seqs.fa'; 199, expression_statement; 199, 200; 200, call; 200, 201; 200, 202; 201, identifier:fasta_from_biom; 202, argument_list; 202, 203; 202, 204; 203, identifier:artifact_table; 204, identifier:output_nomatch_fasta_fp; 205, expression_statement; 205, 206; 206, call; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:table; 209, identifier:filter; 210, argument_list; 210, 211; 210, 215; 211, call; 211, 212; 211, 213; 212, identifier:list; 213, argument_list; 213, 214; 214, identifier:good_seqs; 215, keyword_argument; 215, 216; 215, 217; 216, identifier:axis; 217, string:'observation'; 218, expression_statement; 218, 219; 219, call; 219, 220; 219, 221; 220, identifier:filter_minreads_samples_from_table; 221, argument_list; 221, 222; 222, identifier:table; 223, expression_statement; 223, 224; 224, assignment; 224, 225; 224, 226; 225, identifier:output_fp; 226, call; 226, 227; 226, 228; 227, identifier:join; 228, argument_list; 228, 229; 228, 230; 229, identifier:biom_table_dir; 230, string:'reference-hit.biom'; 231, expression_statement; 231, 232; 232, call; 232, 233; 232, 234; 233, identifier:write_biom_table; 234, argument_list; 234, 235; 234, 236; 235, identifier:table; 236, identifier:output_fp; 237, expression_statement; 237, 238; 238, call; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, identifier:logger; 241, identifier:info; 242, argument_list; 242, 243; 243, binary_operator:%; 243, 244; 243, 245; 244, string:'wrote 16s filtered biom table to %s'; 245, identifier:output_fp; 246, expression_statement; 246, 247; 247, assignment; 247, 248; 247, 249; 248, identifier:output_match_fasta_fp; 249, call; 249, 250; 249, 251; 250, identifier:join; 251, argument_list; 251, 252; 251, 253; 252, identifier:biom_table_dir; 253, string:'reference-hit.seqs.fa'; 254, expression_statement; 254, 255; 255, call; 255, 256; 255, 257; 256, identifier:fasta_from_biom; 257, argument_list; 257, 258; 257, 259; 258, identifier:table; 259, identifier:output_match_fasta_fp; 260, expression_statement; 260, 261; 261, call; 261, 262; 261, 265; 262, attribute; 262, 263; 262, 264; 263, identifier:tmp_files; 264, identifier:append; 265, argument_list; 265, 266; 266, identifier:clean_fp; 267, return_statement; 267, 268; 268, identifier:tmp_files | def remove_artifacts_from_biom_table(table_filename,
fasta_filename,
ref_fp,
biom_table_dir,
ref_db_fp,
threads=1,
verbose=False,
sim_thresh=None,
coverage_thresh=None):
logger = logging.getLogger(__name__)
logger.info('getting 16s sequences from the biom table')
clean_fp, num_seqs_left, tmp_files = remove_artifacts_seqs(fasta_filename, ref_fp,
working_dir=biom_table_dir,
ref_db_fp=ref_db_fp,
negate=False, threads=threads,
verbose=verbose,
sim_thresh=sim_thresh,
coverage_thresh=coverage_thresh)
if clean_fp is None:
logger.warn("No clean sequences in %s" % fasta_filename)
return tmp_files
logger.debug('removed artifacts from sequences input %s'
' to output %s' % (fasta_filename, clean_fp))
good_seqs = {s for _, s in sequence_generator(clean_fp)}
logger.debug('loaded %d sequences from cleaned biom table'
' fasta file' % len(good_seqs))
logger.debug('loading biom table %s' % table_filename)
table = load_table(table_filename)
artifact_table = table.filter(list(good_seqs),
axis='observation', inplace=False,
invert=True)
filter_minreads_samples_from_table(artifact_table)
output_nomatch_fp = join(biom_table_dir, 'reference-non-hit.biom')
write_biom_table(artifact_table, output_nomatch_fp)
logger.info('wrote artifact only filtered biom table to %s'
% output_nomatch_fp)
output_nomatch_fasta_fp = join(biom_table_dir, 'reference-non-hit.seqs.fa')
fasta_from_biom(artifact_table, output_nomatch_fasta_fp)
table.filter(list(good_seqs), axis='observation')
filter_minreads_samples_from_table(table)
output_fp = join(biom_table_dir, 'reference-hit.biom')
write_biom_table(table, output_fp)
logger.info('wrote 16s filtered biom table to %s' % output_fp)
output_match_fasta_fp = join(biom_table_dir, 'reference-hit.seqs.fa')
fasta_from_biom(table, output_match_fasta_fp)
tmp_files.append(clean_fp)
return tmp_files |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 23; 2, function_name:remove_artifacts_seqs; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 4, identifier:seqs_fp; 5, identifier:ref_fp; 6, identifier:working_dir; 7, identifier:ref_db_fp; 8, default_parameter; 8, 9; 8, 10; 9, identifier:negate; 10, False; 11, default_parameter; 11, 12; 11, 13; 12, identifier:threads; 13, integer:1; 14, default_parameter; 14, 15; 14, 16; 15, identifier:verbose; 16, False; 17, default_parameter; 17, 18; 17, 19; 18, identifier:sim_thresh; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:coverage_thresh; 22, None; 23, block; 23, 24; 23, 33; 23, 42; 23, 66; 23, 88; 23, 110; 23, 114; 23, 127; 23, 140; 23, 146; 23, 335; 23, 358; 23, 362; 23, 366; 23, 370; 23, 432; 23, 446; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:logger; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:logging; 30, identifier:getLogger; 31, argument_list; 31, 32; 32, identifier:__name__; 33, expression_statement; 33, 34; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:logger; 37, identifier:info; 38, argument_list; 38, 39; 39, binary_operator:%; 39, 40; 39, 41; 40, string:'remove_artifacts_seqs file %s'; 41, identifier:seqs_fp; 42, if_statement; 42, 43; 42, 51; 43, comparison_operator:==; 43, 44; 43, 50; 44, attribute; 44, 45; 44, 49; 45, call; 45, 46; 45, 47; 46, identifier:stat; 47, argument_list; 47, 48; 48, identifier:seqs_fp; 49, identifier:st_size; 50, integer:0; 51, block; 51, 52; 51, 61; 52, expression_statement; 52, 53; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:logger; 56, identifier:warn; 57, argument_list; 57, 58; 58, binary_operator:%; 58, 59; 58, 60; 59, string:'file %s has size 0, continuing'; 60, identifier:seqs_fp; 61, return_statement; 61, 62; 62, expression_list; 62, 63; 62, 64; 62, 65; 63, None; 64, integer:0; 65, list:[]; 66, if_statement; 66, 67; 66, 70; 67, comparison_operator:is; 67, 68; 67, 69; 68, identifier:coverage_thresh; 69, None; 70, block; 70, 71; 71, if_statement; 71, 72; 71, 73; 71, 80; 72, identifier:negate; 73, block; 73, 74; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:coverage_thresh; 77, binary_operator:*; 77, 78; 77, 79; 78, float:0.95; 79, integer:100; 80, else_clause; 80, 81; 81, block; 81, 82; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:coverage_thresh; 85, binary_operator:*; 85, 86; 85, 87; 86, float:0.5; 87, integer:100; 88, if_statement; 88, 89; 88, 92; 89, comparison_operator:is; 89, 90; 89, 91; 90, identifier:sim_thresh; 91, None; 92, block; 92, 93; 93, if_statement; 93, 94; 93, 95; 93, 102; 94, identifier:negate; 95, block; 95, 96; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:sim_thresh; 99, binary_operator:*; 99, 100; 99, 101; 100, float:0.95; 101, integer:100; 102, else_clause; 102, 103; 103, block; 103, 104; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:sim_thresh; 107, binary_operator:*; 107, 108; 107, 109; 108, float:0.65; 109, integer:100; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:bitscore_thresh; 113, float:0.65; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:output_fp; 117, call; 117, 118; 117, 119; 118, identifier:join; 119, argument_list; 119, 120; 119, 121; 120, identifier:working_dir; 121, binary_operator:%; 121, 122; 121, 123; 122, string:"%s.no_artifacts"; 123, call; 123, 124; 123, 125; 124, identifier:basename; 125, argument_list; 125, 126; 126, identifier:seqs_fp; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:blast_output; 130, call; 130, 131; 130, 132; 131, identifier:join; 132, argument_list; 132, 133; 132, 134; 133, identifier:working_dir; 134, binary_operator:%; 134, 135; 134, 136; 135, string:'%s.sortmerna'; 136, call; 136, 137; 136, 138; 137, identifier:basename; 138, argument_list; 138, 139; 139, identifier:seqs_fp; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:aligned_seq_ids; 143, call; 143, 144; 143, 145; 144, identifier:set; 145, argument_list; 146, for_statement; 146, 147; 146, 150; 146, 154; 147, pattern_list; 147, 148; 147, 149; 148, identifier:i; 149, identifier:db; 150, call; 150, 151; 150, 152; 151, identifier:enumerate; 152, argument_list; 152, 153; 153, identifier:ref_fp; 154, block; 154, 155; 154, 170; 154, 195; 154, 205; 154, 243; 154, 249; 155, expression_statement; 155, 156; 156, call; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:logger; 159, identifier:debug; 160, argument_list; 160, 161; 161, binary_operator:%; 161, 162; 161, 163; 162, string:'running on ref_fp %s working dir %s refdb_fp %s seqs %s'; 163, tuple; 163, 164; 163, 165; 163, 166; 163, 169; 164, identifier:db; 165, identifier:working_dir; 166, subscript; 166, 167; 166, 168; 167, identifier:ref_db_fp; 168, identifier:i; 169, identifier:seqs_fp; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 173; 172, identifier:params; 173, list:['sortmerna', '--reads', seqs_fp, '--ref', '%s,%s' %
(db, ref_db_fp[i]),
'--aligned', blast_output, '--blast', '3', '--best', '1',
'--print_all_reads', '-v', '-e', '100']; 173, 174; 173, 175; 173, 176; 173, 177; 173, 178; 173, 185; 173, 186; 173, 187; 173, 188; 173, 189; 173, 190; 173, 191; 173, 192; 173, 193; 173, 194; 174, string:'sortmerna'; 175, string:'--reads'; 176, identifier:seqs_fp; 177, string:'--ref'; 178, binary_operator:%; 178, 179; 178, 180; 179, string:'%s,%s'; 180, tuple; 180, 181; 180, 182; 181, identifier:db; 182, subscript; 182, 183; 182, 184; 183, identifier:ref_db_fp; 184, identifier:i; 185, string:'--aligned'; 186, identifier:blast_output; 187, string:'--blast'; 188, string:'3'; 189, string:'--best'; 190, string:'1'; 191, string:'--print_all_reads'; 192, string:'-v'; 193, string:'-e'; 194, string:'100'; 195, expression_statement; 195, 196; 196, assignment; 196, 197; 196, 201; 197, pattern_list; 197, 198; 197, 199; 197, 200; 198, identifier:sout; 199, identifier:serr; 200, identifier:res; 201, call; 201, 202; 201, 203; 202, identifier:_system_call; 203, argument_list; 203, 204; 204, identifier:params; 205, if_statement; 205, 206; 205, 210; 206, not_operator; 206, 207; 207, comparison_operator:==; 207, 208; 207, 209; 208, identifier:res; 209, integer:0; 210, block; 210, 211; 210, 220; 210, 229; 210, 238; 211, expression_statement; 211, 212; 212, call; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:logger; 215, identifier:error; 216, argument_list; 216, 217; 217, binary_operator:%; 217, 218; 217, 219; 218, string:'sortmerna error on file %s'; 219, identifier:seqs_fp; 220, expression_statement; 220, 221; 221, call; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:logger; 224, identifier:error; 225, argument_list; 225, 226; 226, binary_operator:%; 226, 227; 226, 228; 227, string:'stdout : %s'; 228, identifier:sout; 229, expression_statement; 229, 230; 230, call; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:logger; 233, identifier:error; 234, argument_list; 234, 235; 235, binary_operator:%; 235, 236; 235, 237; 236, string:'stderr : %s'; 237, identifier:serr; 238, return_statement; 238, 239; 239, expression_list; 239, 240; 239, 241; 239, 242; 240, identifier:output_fp; 241, integer:0; 242, list:[]; 243, expression_statement; 243, 244; 244, assignment; 244, 245; 244, 246; 245, identifier:blast_output_filename; 246, binary_operator:%; 246, 247; 246, 248; 247, string:'%s.blast'; 248, identifier:blast_output; 249, with_statement; 249, 250; 249, 260; 250, with_clause; 250, 251; 251, with_item; 251, 252; 252, as_pattern; 252, 253; 252, 258; 253, call; 253, 254; 253, 255; 254, identifier:open; 255, argument_list; 255, 256; 255, 257; 256, identifier:blast_output_filename; 257, string:'r'; 258, as_pattern_target; 258, 259; 259, identifier:bfl; 260, block; 260, 261; 261, for_statement; 261, 262; 261, 263; 261, 264; 262, identifier:line; 263, identifier:bfl; 264, block; 264, 265; 264, 278; 264, 286; 265, expression_statement; 265, 266; 266, assignment; 266, 267; 266, 268; 267, identifier:line; 268, call; 268, 269; 268, 276; 269, attribute; 269, 270; 269, 275; 270, call; 270, 271; 270, 274; 271, attribute; 271, 272; 271, 273; 272, identifier:line; 273, identifier:strip; 274, argument_list; 275, identifier:split; 276, argument_list; 276, 277; 277, string:'\t'; 278, if_statement; 278, 279; 278, 284; 279, comparison_operator:==; 279, 280; 279, 283; 280, subscript; 280, 281; 280, 282; 281, identifier:line; 282, integer:1; 283, string:'*'; 284, block; 284, 285; 285, continue_statement; 286, if_statement; 286, 287; 286, 325; 287, boolean_operator:and; 287, 288; 287, 308; 287, 309; 288, boolean_operator:and; 288, 289; 288, 298; 288, 299; 289, parenthesized_expression; 289, 290; 290, comparison_operator:>=; 290, 291; 290, 297; 291, call; 291, 292; 291, 293; 292, identifier:float; 293, argument_list; 293, 294; 294, subscript; 294, 295; 294, 296; 295, identifier:line; 296, integer:2; 297, identifier:sim_thresh; 298, line_continuation:\; 299, parenthesized_expression; 299, 300; 300, comparison_operator:>=; 300, 301; 300, 307; 301, call; 301, 302; 301, 303; 302, identifier:float; 303, argument_list; 303, 304; 304, subscript; 304, 305; 304, 306; 305, identifier:line; 306, integer:13; 307, identifier:coverage_thresh; 308, line_continuation:\; 309, parenthesized_expression; 309, 310; 310, comparison_operator:>=; 310, 311; 310, 317; 311, call; 311, 312; 311, 313; 312, identifier:float; 313, argument_list; 313, 314; 314, subscript; 314, 315; 314, 316; 315, identifier:line; 316, integer:11; 317, binary_operator:*; 317, 318; 317, 319; 318, identifier:bitscore_thresh; 319, call; 319, 320; 319, 321; 320, identifier:len; 321, argument_list; 321, 322; 322, subscript; 322, 323; 322, 324; 323, identifier:line; 324, integer:0; 325, block; 325, 326; 326, expression_statement; 326, 327; 327, call; 327, 328; 327, 331; 328, attribute; 328, 329; 328, 330; 329, identifier:aligned_seq_ids; 330, identifier:add; 331, argument_list; 331, 332; 332, subscript; 332, 333; 332, 334; 333, identifier:line; 334, integer:0; 335, if_statement; 335, 336; 335, 337; 335, 347; 336, identifier:negate; 337, block; 337, 338; 338, function_definition; 338, 339; 338, 340; 338, 342; 339, function_name:op; 340, parameters; 340, 341; 341, identifier:x; 342, block; 342, 343; 343, return_statement; 343, 344; 344, comparison_operator:not; 344, 345; 344, 346; 345, identifier:x; 346, identifier:aligned_seq_ids; 347, else_clause; 347, 348; 348, block; 348, 349; 349, function_definition; 349, 350; 349, 351; 349, 353; 350, function_name:op; 351, parameters; 351, 352; 352, identifier:x; 353, block; 353, 354; 354, return_statement; 354, 355; 355, comparison_operator:in; 355, 356; 355, 357; 356, identifier:x; 357, identifier:aligned_seq_ids; 358, expression_statement; 358, 359; 359, assignment; 359, 360; 359, 361; 360, identifier:totalseqs; 361, integer:0; 362, expression_statement; 362, 363; 363, assignment; 363, 364; 363, 365; 364, identifier:okseqs; 365, integer:0; 366, expression_statement; 366, 367; 367, assignment; 367, 368; 367, 369; 368, identifier:badseqs; 369, integer:0; 370, with_statement; 370, 371; 370, 381; 371, with_clause; 371, 372; 372, with_item; 372, 373; 373, as_pattern; 373, 374; 373, 379; 374, call; 374, 375; 374, 376; 375, identifier:open; 376, argument_list; 376, 377; 376, 378; 377, identifier:output_fp; 378, string:'w'; 379, as_pattern_target; 379, 380; 380, identifier:out_f; 381, block; 381, 382; 382, for_statement; 382, 383; 382, 386; 382, 390; 383, pattern_list; 383, 384; 383, 385; 384, identifier:label; 385, identifier:seq; 386, call; 386, 387; 386, 388; 387, identifier:sequence_generator; 388, argument_list; 388, 389; 389, identifier:seqs_fp; 390, block; 390, 391; 390, 395; 390, 405; 391, expression_statement; 391, 392; 392, augmented_assignment:+=; 392, 393; 392, 394; 393, identifier:totalseqs; 394, integer:1; 395, expression_statement; 395, 396; 396, assignment; 396, 397; 396, 398; 397, identifier:label; 398, subscript; 398, 399; 398, 404; 399, call; 399, 400; 399, 403; 400, attribute; 400, 401; 400, 402; 401, identifier:label; 402, identifier:split; 403, argument_list; 404, integer:0; 405, if_statement; 405, 406; 405, 410; 405, 426; 406, call; 406, 407; 406, 408; 407, identifier:op; 408, argument_list; 408, 409; 409, identifier:label; 410, block; 410, 411; 410, 422; 411, expression_statement; 411, 412; 412, call; 412, 413; 412, 416; 413, attribute; 413, 414; 413, 415; 414, identifier:out_f; 415, identifier:write; 416, argument_list; 416, 417; 417, binary_operator:%; 417, 418; 417, 419; 418, string:">%s\n%s\n"; 419, tuple; 419, 420; 419, 421; 420, identifier:label; 421, identifier:seq; 422, expression_statement; 422, 423; 423, augmented_assignment:+=; 423, 424; 423, 425; 424, identifier:okseqs; 425, integer:1; 426, else_clause; 426, 427; 427, block; 427, 428; 428, expression_statement; 428, 429; 429, augmented_assignment:+=; 429, 430; 429, 431; 430, identifier:badseqs; 431, integer:1; 432, expression_statement; 432, 433; 433, call; 433, 434; 433, 437; 434, attribute; 434, 435; 434, 436; 435, identifier:logger; 436, identifier:info; 437, argument_list; 437, 438; 438, binary_operator:%; 438, 439; 438, 442; 439, concatenated_string; 439, 440; 439, 441; 440, string:'total sequences %d, passing sequences %d, '; 441, string:'failing sequences %d'; 442, tuple; 442, 443; 442, 444; 442, 445; 443, identifier:totalseqs; 444, identifier:okseqs; 445, identifier:badseqs; 446, return_statement; 446, 447; 447, expression_list; 447, 448; 447, 449; 447, 450; 448, identifier:output_fp; 449, identifier:okseqs; 450, list:[blast_output_filename]; 450, 451; 451, identifier:blast_output_filename | def remove_artifacts_seqs(seqs_fp,
ref_fp,
working_dir,
ref_db_fp,
negate=False,
threads=1,
verbose=False,
sim_thresh=None,
coverage_thresh=None):
logger = logging.getLogger(__name__)
logger.info('remove_artifacts_seqs file %s' % seqs_fp)
if stat(seqs_fp).st_size == 0:
logger.warn('file %s has size 0, continuing' % seqs_fp)
return None, 0, []
if coverage_thresh is None:
if negate:
coverage_thresh = 0.95 * 100
else:
coverage_thresh = 0.5 * 100
if sim_thresh is None:
if negate:
sim_thresh = 0.95 * 100
else:
sim_thresh = 0.65 * 100
bitscore_thresh = 0.65
output_fp = join(working_dir,
"%s.no_artifacts" % basename(seqs_fp))
blast_output = join(working_dir,
'%s.sortmerna' % basename(seqs_fp))
aligned_seq_ids = set()
for i, db in enumerate(ref_fp):
logger.debug('running on ref_fp %s working dir %s refdb_fp %s seqs %s'
% (db, working_dir, ref_db_fp[i], seqs_fp))
params = ['sortmerna', '--reads', seqs_fp, '--ref', '%s,%s' %
(db, ref_db_fp[i]),
'--aligned', blast_output, '--blast', '3', '--best', '1',
'--print_all_reads', '-v', '-e', '100']
sout, serr, res = _system_call(params)
if not res == 0:
logger.error('sortmerna error on file %s' % seqs_fp)
logger.error('stdout : %s' % sout)
logger.error('stderr : %s' % serr)
return output_fp, 0, []
blast_output_filename = '%s.blast' % blast_output
with open(blast_output_filename, 'r') as bfl:
for line in bfl:
line = line.strip().split('\t')
if line[1] == '*':
continue
if (float(line[2]) >= sim_thresh) and \
(float(line[13]) >= coverage_thresh) and \
(float(line[11]) >= bitscore_thresh * len(line[0])):
aligned_seq_ids.add(line[0])
if negate:
def op(x): return x not in aligned_seq_ids
else:
def op(x): return x in aligned_seq_ids
totalseqs = 0
okseqs = 0
badseqs = 0
with open(output_fp, 'w') as out_f:
for label, seq in sequence_generator(seqs_fp):
totalseqs += 1
label = label.split()[0]
if op(label):
out_f.write(">%s\n%s\n" % (label, seq))
okseqs += 1
else:
badseqs += 1
logger.info('total sequences %d, passing sequences %d, '
'failing sequences %d' % (totalseqs, okseqs, badseqs))
return output_fp, okseqs, [blast_output_filename] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 24; 2, function_name:launch_workflow; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 3, 12; 3, 13; 3, 14; 3, 15; 3, 18; 3, 21; 4, identifier:seqs_fp; 5, identifier:working_dir; 6, identifier:mean_error; 7, identifier:error_dist; 8, identifier:indel_prob; 9, identifier:indel_max; 10, identifier:trim_length; 11, identifier:left_trim_length; 12, identifier:min_size; 13, identifier:ref_fp; 14, identifier:ref_db_fp; 15, default_parameter; 15, 16; 15, 17; 16, identifier:threads_per_sample; 17, integer:1; 18, default_parameter; 18, 19; 18, 20; 19, identifier:sim_thresh; 20, None; 21, default_parameter; 21, 22; 21, 23; 22, identifier:coverage_thresh; 23, None; 24, block; 24, 25; 24, 34; 24, 41; 24, 50; 24, 63; 24, 106; 24, 119; 24, 135; 24, 165; 24, 188; 24, 280; 24, 293; 24, 376; 24, 387; 24, 394; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:logger; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:logging; 31, identifier:getLogger; 32, argument_list; 32, 33; 33, identifier:__name__; 34, expression_statement; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:logger; 38, identifier:info; 39, argument_list; 39, 40; 40, string:'--------------------------------------------------------'; 41, expression_statement; 41, 42; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:logger; 45, identifier:info; 46, argument_list; 46, 47; 47, binary_operator:%; 47, 48; 47, 49; 48, string:'launch_workflow for file %s'; 49, identifier:seqs_fp; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:output_trim_fp; 53, call; 53, 54; 53, 55; 54, identifier:join; 55, argument_list; 55, 56; 55, 57; 56, identifier:working_dir; 57, binary_operator:%; 57, 58; 57, 59; 58, string:"%s.trim"; 59, call; 59, 60; 59, 61; 60, identifier:basename; 61, argument_list; 61, 62; 62, identifier:seqs_fp; 63, with_statement; 63, 64; 63, 74; 64, with_clause; 64, 65; 65, with_item; 65, 66; 66, as_pattern; 66, 67; 66, 72; 67, call; 67, 68; 67, 69; 68, identifier:open; 69, argument_list; 69, 70; 69, 71; 70, identifier:output_trim_fp; 71, string:'w'; 72, as_pattern_target; 72, 73; 73, identifier:out_f; 74, block; 74, 75; 75, for_statement; 75, 76; 75, 79; 75, 94; 76, pattern_list; 76, 77; 76, 78; 77, identifier:label; 78, identifier:seq; 79, call; 79, 80; 79, 81; 80, identifier:trim_seqs; 81, argument_list; 81, 82; 81, 88; 81, 91; 82, keyword_argument; 82, 83; 82, 84; 83, identifier:input_seqs; 84, call; 84, 85; 84, 86; 85, identifier:sequence_generator; 86, argument_list; 86, 87; 87, identifier:seqs_fp; 88, keyword_argument; 88, 89; 88, 90; 89, identifier:trim_len; 90, identifier:trim_length; 91, keyword_argument; 91, 92; 91, 93; 92, identifier:left_trim_len; 93, identifier:left_trim_length; 94, block; 94, 95; 95, expression_statement; 95, 96; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:out_f; 99, identifier:write; 100, argument_list; 100, 101; 101, binary_operator:%; 101, 102; 101, 103; 102, string:">%s\n%s\n"; 103, tuple; 103, 104; 103, 105; 104, identifier:label; 105, identifier:seq; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:output_derep_fp; 109, call; 109, 110; 109, 111; 110, identifier:join; 111, argument_list; 111, 112; 111, 113; 112, identifier:working_dir; 113, binary_operator:%; 113, 114; 113, 115; 114, string:"%s.derep"; 115, call; 115, 116; 115, 117; 116, identifier:basename; 117, argument_list; 117, 118; 118, identifier:output_trim_fp; 119, expression_statement; 119, 120; 120, call; 120, 121; 120, 122; 121, identifier:dereplicate_seqs; 122, argument_list; 122, 123; 122, 126; 122, 129; 122, 132; 123, keyword_argument; 123, 124; 123, 125; 124, identifier:seqs_fp; 125, identifier:output_trim_fp; 126, keyword_argument; 126, 127; 126, 128; 127, identifier:output_fp; 128, identifier:output_derep_fp; 129, keyword_argument; 129, 130; 129, 131; 130, identifier:min_size; 131, identifier:min_size; 132, keyword_argument; 132, 133; 132, 134; 133, identifier:threads; 134, identifier:threads_per_sample; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 141; 137, pattern_list; 137, 138; 137, 139; 137, 140; 138, identifier:output_artif_fp; 139, identifier:num_seqs_left; 140, identifier:_; 141, call; 141, 142; 141, 143; 142, identifier:remove_artifacts_seqs; 143, argument_list; 143, 144; 143, 147; 143, 150; 143, 153; 143, 156; 143, 159; 143, 162; 144, keyword_argument; 144, 145; 144, 146; 145, identifier:seqs_fp; 146, identifier:output_derep_fp; 147, keyword_argument; 147, 148; 147, 149; 148, identifier:ref_fp; 149, identifier:ref_fp; 150, keyword_argument; 150, 151; 150, 152; 151, identifier:working_dir; 152, identifier:working_dir; 153, keyword_argument; 153, 154; 153, 155; 154, identifier:ref_db_fp; 155, identifier:ref_db_fp; 156, keyword_argument; 156, 157; 156, 158; 157, identifier:negate; 158, True; 159, keyword_argument; 159, 160; 159, 161; 160, identifier:threads; 161, identifier:threads_per_sample; 162, keyword_argument; 162, 163; 162, 164; 163, identifier:sim_thresh; 164, identifier:sim_thresh; 165, if_statement; 165, 166; 165, 168; 166, not_operator; 166, 167; 167, identifier:output_artif_fp; 168, block; 168, 169; 168, 179; 168, 186; 169, expression_statement; 169, 170; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:warnings; 173, identifier:warn; 174, argument_list; 174, 175; 174, 178; 175, binary_operator:%; 175, 176; 175, 177; 176, string:'Problem removing artifacts from file %s'; 177, identifier:seqs_fp; 178, identifier:UserWarning; 179, expression_statement; 179, 180; 180, call; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:logger; 183, identifier:warning; 184, argument_list; 184, 185; 185, string:'remove artifacts failed, aborting'; 186, return_statement; 186, 187; 187, None; 188, if_statement; 188, 189; 188, 192; 188, 243; 188, 252; 189, comparison_operator:>; 189, 190; 189, 191; 190, identifier:num_seqs_left; 191, integer:1; 192, block; 192, 193; 192, 206; 192, 218; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 196; 195, identifier:output_msa_fp; 196, call; 196, 197; 196, 198; 197, identifier:join; 198, argument_list; 198, 199; 198, 200; 199, identifier:working_dir; 200, binary_operator:%; 200, 201; 200, 202; 201, string:"%s.msa"; 202, call; 202, 203; 202, 204; 203, identifier:basename; 204, argument_list; 204, 205; 205, identifier:output_artif_fp; 206, expression_statement; 206, 207; 207, assignment; 207, 208; 207, 209; 208, identifier:alignment; 209, call; 209, 210; 209, 211; 210, identifier:multiple_sequence_alignment; 211, argument_list; 211, 212; 211, 215; 212, keyword_argument; 212, 213; 212, 214; 213, identifier:seqs_fp; 214, identifier:output_artif_fp; 215, keyword_argument; 215, 216; 215, 217; 216, identifier:threads; 217, identifier:threads_per_sample; 218, if_statement; 218, 219; 218, 221; 219, not_operator; 219, 220; 220, identifier:alignment; 221, block; 221, 222; 221, 234; 221, 241; 222, expression_statement; 222, 223; 223, call; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:warnings; 226, identifier:warn; 227, argument_list; 227, 228; 227, 233; 228, binary_operator:%; 228, 229; 228, 232; 229, concatenated_string; 229, 230; 229, 231; 230, string:'Problem performing multiple sequence alignment '; 231, string:'on file %s'; 232, identifier:seqs_fp; 233, identifier:UserWarning; 234, expression_statement; 234, 235; 235, call; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:logger; 238, identifier:warning; 239, argument_list; 239, 240; 240, string:'msa failed. aborting'; 241, return_statement; 241, 242; 242, None; 243, elif_clause; 243, 244; 243, 247; 244, comparison_operator:==; 244, 245; 244, 246; 245, identifier:num_seqs_left; 246, integer:1; 247, block; 247, 248; 248, expression_statement; 248, 249; 249, assignment; 249, 250; 249, 251; 250, identifier:output_msa_fp; 251, identifier:output_artif_fp; 252, else_clause; 252, 253; 253, block; 253, 254; 253, 263; 253, 271; 253, 278; 254, expression_statement; 254, 255; 255, assignment; 255, 256; 255, 257; 256, identifier:err_msg; 257, parenthesized_expression; 257, 258; 258, binary_operator:%; 258, 259; 258, 262; 259, concatenated_string; 259, 260; 259, 261; 260, string:'No sequences left after artifact removal in '; 261, string:'file %s'; 262, identifier:seqs_fp; 263, expression_statement; 263, 264; 264, call; 264, 265; 264, 268; 265, attribute; 265, 266; 265, 267; 266, identifier:warnings; 267, identifier:warn; 268, argument_list; 268, 269; 268, 270; 269, identifier:err_msg; 270, identifier:UserWarning; 271, expression_statement; 271, 272; 272, call; 272, 273; 272, 276; 273, attribute; 273, 274; 273, 275; 274, identifier:logger; 275, identifier:warning; 276, argument_list; 276, 277; 277, identifier:err_msg; 278, return_statement; 278, 279; 279, None; 280, expression_statement; 280, 281; 281, assignment; 281, 282; 281, 283; 282, identifier:output_deblur_fp; 283, call; 283, 284; 283, 285; 284, identifier:join; 285, argument_list; 285, 286; 285, 287; 286, identifier:working_dir; 287, binary_operator:%; 287, 288; 287, 289; 288, string:"%s.deblur"; 289, call; 289, 290; 289, 291; 290, identifier:basename; 291, argument_list; 291, 292; 292, identifier:output_msa_fp; 293, with_statement; 293, 294; 293, 304; 294, with_clause; 294, 295; 295, with_item; 295, 296; 296, as_pattern; 296, 297; 296, 302; 297, call; 297, 298; 297, 299; 298, identifier:open; 299, argument_list; 299, 300; 299, 301; 300, identifier:output_deblur_fp; 301, string:'w'; 302, as_pattern_target; 302, 303; 303, identifier:f; 304, block; 304, 305; 304, 319; 304, 347; 305, expression_statement; 305, 306; 306, assignment; 306, 307; 306, 308; 307, identifier:seqs; 308, call; 308, 309; 308, 310; 309, identifier:deblur; 310, argument_list; 310, 311; 310, 315; 310, 316; 310, 317; 310, 318; 311, call; 311, 312; 311, 313; 312, identifier:sequence_generator; 313, argument_list; 313, 314; 314, identifier:output_msa_fp; 315, identifier:mean_error; 316, identifier:error_dist; 317, identifier:indel_prob; 318, identifier:indel_max; 319, if_statement; 319, 320; 319, 323; 320, comparison_operator:is; 320, 321; 320, 322; 321, identifier:seqs; 322, None; 323, block; 323, 324; 323, 336; 323, 345; 324, expression_statement; 324, 325; 325, call; 325, 326; 325, 329; 326, attribute; 326, 327; 326, 328; 327, identifier:warnings; 328, identifier:warn; 329, argument_list; 329, 330; 329, 335; 330, binary_operator:%; 330, 331; 330, 334; 331, concatenated_string; 331, 332; 331, 333; 332, string:'multiple sequence alignment file %s contains '; 333, string:'no sequences'; 334, identifier:output_msa_fp; 335, identifier:UserWarning; 336, expression_statement; 336, 337; 337, call; 337, 338; 337, 341; 338, attribute; 338, 339; 338, 340; 339, identifier:logger; 340, identifier:warn; 341, argument_list; 341, 342; 342, binary_operator:%; 342, 343; 342, 344; 343, string:'no sequences returned from deblur for file %s'; 344, identifier:output_msa_fp; 345, return_statement; 345, 346; 346, None; 347, for_statement; 347, 348; 347, 349; 347, 350; 348, identifier:s; 349, identifier:seqs; 350, block; 350, 351; 350, 365; 351, expression_statement; 351, 352; 352, assignment; 352, 353; 352, 356; 353, attribute; 353, 354; 353, 355; 354, identifier:s; 355, identifier:sequence; 356, call; 356, 357; 356, 362; 357, attribute; 357, 358; 357, 361; 358, attribute; 358, 359; 358, 360; 359, identifier:s; 360, identifier:sequence; 361, identifier:replace; 362, argument_list; 362, 363; 362, 364; 363, string:'-'; 364, string:''; 365, expression_statement; 365, 366; 366, call; 366, 367; 366, 370; 367, attribute; 367, 368; 367, 369; 368, identifier:f; 369, identifier:write; 370, argument_list; 370, 371; 371, call; 371, 372; 371, 375; 372, attribute; 372, 373; 372, 374; 373, identifier:s; 374, identifier:to_fasta; 375, argument_list; 376, expression_statement; 376, 377; 377, assignment; 377, 378; 377, 379; 378, identifier:output_no_chimeras_fp; 379, call; 379, 380; 379, 381; 380, identifier:remove_chimeras_denovo_from_seqs; 381, argument_list; 381, 382; 381, 383; 381, 384; 382, identifier:output_deblur_fp; 383, identifier:working_dir; 384, keyword_argument; 384, 385; 384, 386; 385, identifier:threads; 386, identifier:threads_per_sample; 387, expression_statement; 387, 388; 388, call; 388, 389; 388, 392; 389, attribute; 389, 390; 389, 391; 390, identifier:logger; 391, identifier:info; 392, argument_list; 392, 393; 393, string:'finished processing file'; 394, return_statement; 394, 395; 395, identifier:output_no_chimeras_fp | def launch_workflow(seqs_fp, working_dir, mean_error, error_dist,
indel_prob, indel_max, trim_length, left_trim_length,
min_size, ref_fp, ref_db_fp, threads_per_sample=1,
sim_thresh=None, coverage_thresh=None):
logger = logging.getLogger(__name__)
logger.info('--------------------------------------------------------')
logger.info('launch_workflow for file %s' % seqs_fp)
output_trim_fp = join(working_dir, "%s.trim" % basename(seqs_fp))
with open(output_trim_fp, 'w') as out_f:
for label, seq in trim_seqs(
input_seqs=sequence_generator(seqs_fp),
trim_len=trim_length,
left_trim_len=left_trim_length):
out_f.write(">%s\n%s\n" % (label, seq))
output_derep_fp = join(working_dir,
"%s.derep" % basename(output_trim_fp))
dereplicate_seqs(seqs_fp=output_trim_fp,
output_fp=output_derep_fp,
min_size=min_size, threads=threads_per_sample)
output_artif_fp, num_seqs_left, _ = remove_artifacts_seqs(seqs_fp=output_derep_fp,
ref_fp=ref_fp,
working_dir=working_dir,
ref_db_fp=ref_db_fp,
negate=True,
threads=threads_per_sample,
sim_thresh=sim_thresh)
if not output_artif_fp:
warnings.warn('Problem removing artifacts from file %s' %
seqs_fp, UserWarning)
logger.warning('remove artifacts failed, aborting')
return None
if num_seqs_left > 1:
output_msa_fp = join(working_dir,
"%s.msa" % basename(output_artif_fp))
alignment = multiple_sequence_alignment(seqs_fp=output_artif_fp,
threads=threads_per_sample)
if not alignment:
warnings.warn('Problem performing multiple sequence alignment '
'on file %s' % seqs_fp, UserWarning)
logger.warning('msa failed. aborting')
return None
elif num_seqs_left == 1:
output_msa_fp = output_artif_fp
else:
err_msg = ('No sequences left after artifact removal in '
'file %s' % seqs_fp)
warnings.warn(err_msg, UserWarning)
logger.warning(err_msg)
return None
output_deblur_fp = join(working_dir,
"%s.deblur" % basename(output_msa_fp))
with open(output_deblur_fp, 'w') as f:
seqs = deblur(sequence_generator(output_msa_fp), mean_error,
error_dist, indel_prob, indel_max)
if seqs is None:
warnings.warn('multiple sequence alignment file %s contains '
'no sequences' % output_msa_fp, UserWarning)
logger.warn('no sequences returned from deblur for file %s' %
output_msa_fp)
return None
for s in seqs:
s.sequence = s.sequence.replace('-', '')
f.write(s.to_fasta())
output_no_chimeras_fp = remove_chimeras_denovo_from_seqs(
output_deblur_fp, working_dir, threads=threads_per_sample)
logger.info('finished processing file')
return output_no_chimeras_fp |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:logs; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 22; 5, 34; 5, 48; 6, if_statement; 6, 7; 6, 13; 7, not_operator; 7, 8; 8, attribute; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:self; 11, identifier:parent; 12, identifier:loaded; 13, block; 13, 14; 14, expression_statement; 14, 15; 15, call; 15, 16; 15, 21; 16, attribute; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:parent; 20, identifier:load; 21, argument_list; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:logs; 25, attribute; 25, 26; 25, 33; 26, attribute; 26, 27; 26, 32; 27, attribute; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:parent; 31, identifier:p; 32, identifier:logs_dir; 33, identifier:flat_directories; 34, expression_statement; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:logs; 38, identifier:sort; 39, argument_list; 39, 40; 40, keyword_argument; 40, 41; 40, 42; 41, identifier:key; 42, lambda; 42, 43; 42, 45; 43, lambda_parameters; 43, 44; 44, identifier:x; 45, attribute; 45, 46; 45, 47; 46, identifier:x; 47, identifier:mod_time; 48, return_statement; 48, 49; 49, identifier:logs | def logs(self):
if not self.parent.loaded: self.parent.load()
logs = self.parent.p.logs_dir.flat_directories
logs.sort(key=lambda x: x.mod_time)
return logs |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort_string_by_pairs; 3, parameters; 3, 4; 4, identifier:strings; 5, block; 5, 6; 5, 15; 5, 19; 5, 26; 5, 80; 6, assert_statement; 6, 7; 7, comparison_operator:==; 7, 8; 7, 14; 8, binary_operator:%; 8, 9; 8, 13; 9, call; 9, 10; 9, 11; 10, identifier:len; 11, argument_list; 11, 12; 12, identifier:strings; 13, integer:2; 14, integer:0; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:pairs; 18, list:[]; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:strings; 22, call; 22, 23; 22, 24; 23, identifier:list; 24, argument_list; 24, 25; 25, identifier:strings; 26, while_statement; 26, 27; 26, 28; 27, identifier:strings; 28, block; 28, 29; 28, 37; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:template; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:strings; 35, identifier:pop; 36, argument_list; 37, for_statement; 37, 38; 37, 41; 37, 45; 38, pattern_list; 38, 39; 38, 40; 39, identifier:i; 40, identifier:candidate; 41, call; 41, 42; 41, 43; 42, identifier:enumerate; 43, argument_list; 43, 44; 44, identifier:strings; 45, block; 45, 46; 46, if_statement; 46, 47; 46, 54; 47, comparison_operator:==; 47, 48; 47, 53; 48, call; 48, 49; 48, 50; 49, identifier:count_string_diff; 50, argument_list; 50, 51; 50, 52; 51, identifier:template; 52, identifier:candidate; 53, integer:1; 54, block; 54, 55; 54, 66; 54, 72; 54, 79; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:pair; 58, list:[template, strings.pop(i)]; 58, 59; 58, 60; 59, identifier:template; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:strings; 63, identifier:pop; 64, argument_list; 64, 65; 65, identifier:i; 66, expression_statement; 66, 67; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:pair; 70, identifier:sort; 71, argument_list; 72, expression_statement; 72, 73; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:pairs; 76, identifier:append; 77, argument_list; 77, 78; 78, identifier:pair; 79, break_statement; 80, return_statement; 80, 81; 81, identifier:pairs | def sort_string_by_pairs(strings):
assert len(strings) % 2 == 0
pairs = []
strings = list(strings)
while strings:
template = strings.pop()
for i, candidate in enumerate(strings):
if count_string_diff(template, candidate) == 1:
pair = [template, strings.pop(i)]
pair.sort()
pairs.append(pair)
break
return pairs |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:natural_sort; 3, parameters; 3, 4; 4, identifier:item; 5, block; 5, 6; 5, 15; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:dre; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:re; 12, identifier:compile; 13, argument_list; 13, 14; 14, string:r'(\d+)'; 15, return_statement; 15, 16; 16, list_comprehension; 16, 17; 16, 32; 17, conditional_expression:if; 17, 18; 17, 22; 17, 27; 18, call; 18, 19; 18, 20; 19, identifier:int; 20, argument_list; 20, 21; 21, identifier:s; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:s; 25, identifier:isdigit; 26, argument_list; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:s; 30, identifier:lower; 31, argument_list; 32, for_in_clause; 32, 33; 32, 34; 33, identifier:s; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:re; 37, identifier:split; 38, argument_list; 38, 39; 38, 40; 39, identifier:dre; 40, identifier:item | def natural_sort(item):
dre = re.compile(r'(\d+)')
return [int(s) if s.isdigit() else s.lower() for s in re.split(dre, item)] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:get_elementary_intervals; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:features; 6, block; 6, 7; 6, 11; 6, 61; 6, 71; 6, 77; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:coords; 10, list:[]; 11, try_statement; 11, 12; 11, 48; 12, block; 12, 13; 13, for_statement; 13, 14; 13, 15; 13, 16; 14, identifier:interval; 15, identifier:features; 16, block; 16, 17; 16, 35; 17, if_statement; 17, 18; 17, 24; 18, comparison_operator:!=; 18, 19; 18, 23; 19, call; 19, 20; 19, 21; 20, identifier:len; 21, argument_list; 21, 22; 22, identifier:interval; 23, integer:3; 24, block; 24, 25; 25, raise_statement; 25, 26; 26, call; 26, 27; 26, 28; 27, identifier:SyntaxError; 28, argument_list; 28, 29; 29, binary_operator:%; 29, 30; 29, 31; 30, string:'Interval malformed %s. Allways specify start and end position for interval.'; 31, call; 31, 32; 31, 33; 32, identifier:str; 33, argument_list; 33, 34; 34, identifier:interval; 35, expression_statement; 35, 36; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:coords; 39, identifier:extend; 40, argument_list; 40, 41; 41, list:[interval[0],interval[1]]; 41, 42; 41, 45; 42, subscript; 42, 43; 42, 44; 43, identifier:interval; 44, integer:0; 45, subscript; 45, 46; 45, 47; 46, identifier:interval; 47, integer:1; 48, except_clause; 48, 49; 48, 50; 49, identifier:IndexError; 50, block; 50, 51; 51, raise_statement; 51, 52; 52, call; 52, 53; 52, 54; 53, identifier:SyntaxError; 54, argument_list; 54, 55; 55, binary_operator:%; 55, 56; 55, 57; 56, string:'Interval malformed %s. Allways specify start and end position for interval.'; 57, call; 57, 58; 57, 59; 58, identifier:str; 59, argument_list; 59, 60; 60, identifier:interval; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:coords; 64, call; 64, 65; 64, 66; 65, identifier:list; 66, argument_list; 66, 67; 67, call; 67, 68; 67, 69; 68, identifier:set; 69, argument_list; 69, 70; 70, identifier:coords; 71, expression_statement; 71, 72; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:coords; 75, identifier:sort; 76, argument_list; 77, return_statement; 77, 78; 78, identifier:coords | def get_elementary_intervals(self, features):
coords = []
try:
for interval in features:
if len(interval) != 3:
raise SyntaxError('Interval malformed %s. Allways specify start and end position for interval.' % str(interval))
coords.extend([interval[0],interval[1]])
except IndexError:
raise SyntaxError('Interval malformed %s. Allways specify start and end position for interval.' % str(interval))
coords = list(set(coords))
coords.sort()
return coords |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:convtable2dict; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:convtable; 5, identifier:locale; 6, default_parameter; 6, 7; 6, 8; 7, identifier:update; 8, None; 9, block; 9, 10; 9, 21; 9, 100; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:rdict; 13, conditional_expression:if; 13, 14; 13, 19; 13, 20; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:update; 17, identifier:copy; 18, argument_list; 19, identifier:update; 20, dictionary; 21, for_statement; 21, 22; 21, 23; 21, 24; 22, identifier:r; 23, identifier:convtable; 24, block; 24, 25; 25, if_statement; 25, 26; 25, 29; 25, 45; 25, 76; 26, comparison_operator:in; 26, 27; 26, 28; 27, string:':uni'; 28, identifier:r; 29, block; 29, 30; 30, if_statement; 30, 31; 30, 34; 31, comparison_operator:in; 31, 32; 31, 33; 32, identifier:locale; 33, identifier:r; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 42; 37, subscript; 37, 38; 37, 39; 38, identifier:rdict; 39, subscript; 39, 40; 39, 41; 40, identifier:r; 41, string:':uni'; 42, subscript; 42, 43; 42, 44; 43, identifier:r; 44, identifier:locale; 45, elif_clause; 45, 46; 45, 54; 46, comparison_operator:==; 46, 47; 46, 53; 47, subscript; 47, 48; 47, 49; 48, identifier:locale; 49, slice; 49, 50; 49, 51; 50, colon; 51, unary_operator:-; 51, 52; 52, integer:1; 53, string:'zh-han'; 54, block; 54, 55; 55, if_statement; 55, 56; 55, 59; 56, comparison_operator:in; 56, 57; 56, 58; 57, identifier:locale; 58, identifier:r; 59, block; 59, 60; 60, for_statement; 60, 61; 60, 62; 60, 67; 61, identifier:word; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:r; 65, identifier:values; 66, argument_list; 67, block; 67, 68; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 73; 70, subscript; 70, 71; 70, 72; 71, identifier:rdict; 72, identifier:word; 73, subscript; 73, 74; 73, 75; 74, identifier:r; 75, identifier:locale; 76, else_clause; 76, 77; 77, block; 77, 78; 77, 86; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:v; 81, call; 81, 82; 81, 83; 82, identifier:fallback; 83, argument_list; 83, 84; 83, 85; 84, identifier:locale; 85, identifier:r; 86, for_statement; 86, 87; 86, 88; 86, 93; 87, identifier:word; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:r; 91, identifier:values; 92, argument_list; 93, block; 93, 94; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 99; 96, subscript; 96, 97; 96, 98; 97, identifier:rdict; 98, identifier:word; 99, identifier:v; 100, return_statement; 100, 101; 101, identifier:rdict | def convtable2dict(convtable, locale, update=None):
rdict = update.copy() if update else {}
for r in convtable:
if ':uni' in r:
if locale in r:
rdict[r[':uni']] = r[locale]
elif locale[:-1] == 'zh-han':
if locale in r:
for word in r.values():
rdict[word] = r[locale]
else:
v = fallback(locale, r)
for word in r.values():
rdict[word] = v
return rdict |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:re_sort; 3, parameters; 3, 4; 4, identifier:data; 5, block; 5, 6; 5, 17; 5, 21; 5, 38; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:keys; 9, call; 9, 10; 9, 11; 10, identifier:sorted; 11, argument_list; 11, 12; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:data; 15, identifier:keys; 16, argument_list; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:new_data; 20, dictionary; 21, for_statement; 21, 22; 21, 25; 21, 29; 22, pattern_list; 22, 23; 22, 24; 23, identifier:number; 24, identifier:key; 25, call; 25, 26; 25, 27; 26, identifier:enumerate; 27, argument_list; 27, 28; 28, identifier:keys; 29, block; 29, 30; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 35; 32, subscript; 32, 33; 32, 34; 33, identifier:new_data; 34, identifier:number; 35, subscript; 35, 36; 35, 37; 36, identifier:data; 37, identifier:key; 38, return_statement; 38, 39; 39, identifier:new_data | def re_sort(data):
keys = sorted(data.keys())
new_data = {}
for number, key in enumerate(keys):
new_data[number] = data[key]
return new_data |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:natural_sorted; 3, parameters; 3, 4; 4, identifier:iterable; 5, block; 5, 6; 5, 34; 5, 43; 6, function_definition; 6, 7; 6, 8; 6, 10; 7, function_name:sortkey; 8, parameters; 8, 9; 9, identifier:x; 10, block; 10, 11; 11, return_statement; 11, 12; 12, list_comprehension; 12, 13; 12, 25; 13, parenthesized_expression; 13, 14; 14, conditional_expression:if; 14, 15; 14, 19; 14, 24; 15, call; 15, 16; 15, 17; 16, identifier:int; 17, argument_list; 17, 18; 18, identifier:c; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:c; 22, identifier:isdigit; 23, argument_list; 24, identifier:c; 25, for_in_clause; 25, 26; 25, 27; 26, identifier:c; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:re; 30, identifier:split; 31, argument_list; 31, 32; 31, 33; 32, identifier:numbers; 33, identifier:x; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:numbers; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:re; 40, identifier:compile; 41, argument_list; 41, 42; 42, string:r'(\d+)'; 43, return_statement; 43, 44; 44, call; 44, 45; 44, 46; 45, identifier:sorted; 46, argument_list; 46, 47; 46, 48; 47, identifier:iterable; 48, keyword_argument; 48, 49; 48, 50; 49, identifier:key; 50, identifier:sortkey | def natural_sorted(iterable):
def sortkey(x):
return [(int(c) if c.isdigit() else c) for c in re.split(numbers, x)]
numbers = re.compile(r'(\d+)')
return sorted(iterable, key=sortkey) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:sort_keys; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:keys; 6, default_parameter; 6, 7; 6, 8; 7, identifier:order; 8, attribute; 8, 9; 8, 10; 9, identifier:QuerySet; 10, identifier:ASCENDING; 11, block; 11, 12; 11, 30; 11, 50; 11, 81; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:missing_keys; 15, list_comprehension; 15, 16; 15, 17; 15, 20; 16, identifier:key; 17, for_in_clause; 17, 18; 17, 19; 18, identifier:key; 19, identifier:keys; 20, if_clause; 20, 21; 21, not_operator; 21, 22; 22, call; 22, 23; 22, 24; 23, identifier:len; 24, argument_list; 24, 25; 25, subscript; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:_reverse_index; 29, identifier:key; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:keys_and_values; 33, list_comprehension; 33, 34; 33, 43; 33, 46; 34, tuple; 34, 35; 34, 36; 35, identifier:key; 36, subscript; 36, 37; 36, 42; 37, subscript; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:_reverse_index; 41, identifier:key; 42, integer:0; 43, for_in_clause; 43, 44; 43, 45; 44, identifier:key; 45, identifier:keys; 46, if_clause; 46, 47; 47, comparison_operator:not; 47, 48; 47, 49; 48, identifier:key; 49, identifier:missing_keys; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:sorted_keys; 53, list_comprehension; 53, 54; 53, 57; 54, subscript; 54, 55; 54, 56; 55, identifier:kv; 56, integer:0; 57, for_in_clause; 57, 58; 57, 59; 58, identifier:kv; 59, call; 59, 60; 59, 61; 60, identifier:sorted; 61, argument_list; 61, 62; 61, 63; 61, 71; 62, identifier:keys_and_values; 63, keyword_argument; 63, 64; 63, 65; 64, identifier:key; 65, lambda; 65, 66; 65, 68; 66, lambda_parameters; 66, 67; 67, identifier:x; 68, subscript; 68, 69; 68, 70; 69, identifier:x; 70, integer:1; 71, keyword_argument; 71, 72; 71, 73; 72, identifier:reverse; 73, conditional_expression:if; 73, 74; 73, 75; 73, 80; 74, True; 75, comparison_operator:==; 75, 76; 75, 77; 76, identifier:order; 77, attribute; 77, 78; 77, 79; 78, identifier:QuerySet; 79, identifier:DESCENDING; 80, False; 81, if_statement; 81, 82; 81, 87; 81, 92; 81, 103; 82, comparison_operator:==; 82, 83; 82, 84; 83, identifier:order; 84, attribute; 84, 85; 84, 86; 85, identifier:QuerySet; 86, identifier:ASCENDING; 87, block; 87, 88; 88, return_statement; 88, 89; 89, binary_operator:+; 89, 90; 89, 91; 90, identifier:missing_keys; 91, identifier:sorted_keys; 92, elif_clause; 92, 93; 92, 98; 93, comparison_operator:==; 93, 94; 93, 95; 94, identifier:order; 95, attribute; 95, 96; 95, 97; 96, identifier:QuerySet; 97, identifier:DESCENDING; 98, block; 98, 99; 99, return_statement; 99, 100; 100, binary_operator:+; 100, 101; 100, 102; 101, identifier:sorted_keys; 102, identifier:missing_keys; 103, else_clause; 103, 104; 104, block; 104, 105; 105, raise_statement; 105, 106; 106, call; 106, 107; 106, 108; 107, identifier:ValueError; 108, argument_list; 108, 109; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, string:'Unexpected order value: {:d}'; 112, identifier:format; 113, argument_list; 113, 114; 114, identifier:order | def sort_keys(self, keys, order=QuerySet.ASCENDING):
missing_keys = [
key
for key in keys
if not len(self._reverse_index[key])
]
keys_and_values = [
(key, self._reverse_index[key][0])
for key in keys
if key not in missing_keys
]
sorted_keys = [
kv[0]
for kv in sorted(
keys_and_values,
key=lambda x: x[1],
reverse=True if order == QuerySet.DESCENDING else False)
]
if order == QuerySet.ASCENDING:
return missing_keys + sorted_keys
elif order == QuerySet.DESCENDING:
return sorted_keys + missing_keys
else:
raise ValueError('Unexpected order value: {:d}'.format(order)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:options; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 18; 5, 27; 5, 38; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:keys; 9, call; 9, 10; 9, 17; 10, attribute; 10, 11; 10, 16; 11, attribute; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:__class__; 15, identifier:__dict__; 16, identifier:copy; 17, argument_list; 18, expression_statement; 18, 19; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:keys; 22, identifier:update; 23, argument_list; 23, 24; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:__dict__; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:keys; 30, call; 30, 31; 30, 32; 31, identifier:sorted; 32, argument_list; 32, 33; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:keys; 36, identifier:keys; 37, argument_list; 38, for_statement; 38, 39; 38, 40; 38, 41; 39, identifier:opt; 40, identifier:keys; 41, block; 41, 42; 41, 51; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:val; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:get; 49, argument_list; 49, 50; 50, identifier:opt; 51, if_statement; 51, 52; 51, 55; 52, comparison_operator:is; 52, 53; 52, 54; 53, identifier:val; 54, None; 55, block; 55, 56; 56, expression_statement; 56, 57; 57, yield; 57, 58; 58, expression_list; 58, 59; 58, 60; 59, identifier:opt; 60, identifier:val | def options(self):
keys = self.__class__.__dict__.copy()
keys.update(self.__dict__)
keys = sorted(keys.keys())
for opt in keys:
val = self.get(opt)
if val is not None:
yield opt, val |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 1, 7; 2, function_name:_tidy; 3, parameters; 3, 4; 4, identifier:self; 5, type; 5, 6; 6, None; 7, block; 7, 8; 8, if_statement; 8, 9; 8, 12; 8, 22; 9, attribute; 9, 10; 9, 11; 10, identifier:self; 11, identifier:no_overlap; 12, block; 12, 13; 13, expression_statement; 13, 14; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:remove_overlap; 18, argument_list; 18, 19; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:no_contiguous; 22, else_clause; 22, 23; 23, block; 23, 24; 24, expression_statement; 24, 25; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:_sort; 29, argument_list | def _tidy(self) -> None:
if self.no_overlap:
self.remove_overlap(self.no_contiguous)
else:
self._sort() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 29; 1, 35; 2, function_name:index_list_for_sort_order; 3, parameters; 3, 4; 3, 12; 3, 24; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:x; 6, type; 6, 7; 7, generic_type; 7, 8; 7, 9; 8, identifier:List; 9, type_parameter; 9, 10; 10, type; 10, 11; 11, identifier:Any; 12, typed_default_parameter; 12, 13; 12, 14; 12, 23; 13, identifier:key; 14, type; 14, 15; 15, generic_type; 15, 16; 15, 17; 16, identifier:Callable; 17, type_parameter; 17, 18; 17, 21; 18, type; 18, 19; 19, list:[Any]; 19, 20; 20, identifier:Any; 21, type; 21, 22; 22, identifier:Any; 23, None; 24, typed_default_parameter; 24, 25; 24, 26; 24, 28; 25, identifier:reverse; 26, type; 26, 27; 27, identifier:bool; 28, False; 29, type; 29, 30; 30, generic_type; 30, 31; 30, 32; 31, identifier:List; 32, type_parameter; 32, 33; 33, type; 33, 34; 34, identifier:int; 35, block; 35, 36; 35, 57; 35, 73; 35, 89; 36, function_definition; 36, 37; 36, 38; 36, 49; 37, function_name:key_with_user_func; 38, parameters; 38, 39; 39, typed_parameter; 39, 40; 39, 41; 40, identifier:idx_val; 41, type; 41, 42; 42, generic_type; 42, 43; 42, 44; 43, identifier:Tuple; 44, type_parameter; 44, 45; 44, 47; 45, type; 45, 46; 46, identifier:int; 47, type; 47, 48; 48, identifier:Any; 49, block; 49, 50; 50, return_statement; 50, 51; 51, call; 51, 52; 51, 53; 52, identifier:key; 53, argument_list; 53, 54; 54, subscript; 54, 55; 54, 56; 55, identifier:idx_val; 56, integer:1; 57, if_statement; 57, 58; 57, 59; 57, 64; 58, identifier:key; 59, block; 59, 60; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:sort_key; 63, identifier:key_with_user_func; 64, else_clause; 64, 65; 65, block; 65, 66; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:sort_key; 69, call; 69, 70; 69, 71; 70, identifier:itemgetter; 71, argument_list; 71, 72; 72, integer:1; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:index_value_list; 76, call; 76, 77; 76, 78; 77, identifier:sorted; 78, argument_list; 78, 79; 78, 83; 78, 86; 79, call; 79, 80; 79, 81; 80, identifier:enumerate; 81, argument_list; 81, 82; 82, identifier:x; 83, keyword_argument; 83, 84; 83, 85; 84, identifier:key; 85, identifier:sort_key; 86, keyword_argument; 86, 87; 86, 88; 87, identifier:reverse; 88, identifier:reverse; 89, return_statement; 89, 90; 90, list_comprehension; 90, 91; 90, 92; 91, identifier:i; 92, for_in_clause; 92, 93; 92, 96; 93, pattern_list; 93, 94; 93, 95; 94, identifier:i; 95, identifier:_; 96, identifier:index_value_list | def index_list_for_sort_order(x: List[Any], key: Callable[[Any], Any] = None,
reverse: bool = False) -> List[int]:
def key_with_user_func(idx_val: Tuple[int, Any]):
return key(idx_val[1])
if key:
sort_key = key_with_user_func
else:
sort_key = itemgetter(1)
index_value_list = sorted(enumerate(x), key=sort_key, reverse=reverse)
return [i for i, _ in index_value_list] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 1, 22; 2, function_name:sort_list_by_index_list; 3, parameters; 3, 4; 3, 12; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:x; 6, type; 6, 7; 7, generic_type; 7, 8; 7, 9; 8, identifier:List; 9, type_parameter; 9, 10; 10, type; 10, 11; 11, identifier:Any; 12, typed_parameter; 12, 13; 12, 14; 13, identifier:indexes; 14, type; 14, 15; 15, generic_type; 15, 16; 15, 17; 16, identifier:List; 17, type_parameter; 17, 18; 18, type; 18, 19; 19, identifier:int; 20, type; 20, 21; 21, None; 22, block; 22, 23; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 29; 25, subscript; 25, 26; 25, 27; 26, identifier:x; 27, slice; 27, 28; 28, colon; 29, list_comprehension; 29, 30; 29, 33; 30, subscript; 30, 31; 30, 32; 31, identifier:x; 32, identifier:i; 33, for_in_clause; 33, 34; 33, 35; 34, identifier:i; 35, identifier:indexes | def sort_list_by_index_list(x: List[Any], indexes: List[int]) -> None:
x[:] = [x[i] for i in indexes] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 1, 18; 2, function_name:fetch_all_first_values; 3, parameters; 3, 4; 3, 8; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:session; 6, type; 6, 7; 7, identifier:Session; 8, typed_parameter; 8, 9; 8, 10; 9, identifier:select_statement; 10, type; 10, 11; 11, identifier:Select; 12, type; 12, 13; 13, generic_type; 13, 14; 13, 15; 14, identifier:List; 15, type_parameter; 15, 16; 16, type; 16, 17; 17, identifier:Any; 18, block; 18, 19; 18, 28; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:rows; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:session; 25, identifier:execute; 26, argument_list; 26, 27; 27, identifier:select_statement; 28, try_statement; 28, 29; 28, 38; 29, block; 29, 30; 30, return_statement; 30, 31; 31, list_comprehension; 31, 32; 31, 35; 32, subscript; 32, 33; 32, 34; 33, identifier:row; 34, integer:0; 35, for_in_clause; 35, 36; 35, 37; 36, identifier:row; 37, identifier:rows; 38, except_clause; 38, 39; 38, 43; 39, as_pattern; 39, 40; 39, 41; 40, identifier:ValueError; 41, as_pattern_target; 41, 42; 42, identifier:e; 43, block; 43, 44; 44, raise_statement; 44, 45; 45, call; 45, 46; 45, 47; 46, identifier:MultipleResultsFound; 47, argument_list; 47, 48; 48, call; 48, 49; 48, 50; 49, identifier:str; 50, argument_list; 50, 51; 51, identifier:e | def fetch_all_first_values(session: Session,
select_statement: Select) -> List[Any]:
rows = session.execute(select_statement)
try:
return [row[0] for row in rows]
except ValueError as e:
raise MultipleResultsFound(str(e)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 1, 16; 2, function_name:atoi; 3, parameters; 3, 4; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:text; 6, type; 6, 7; 7, identifier:str; 8, type; 8, 9; 9, generic_type; 9, 10; 9, 11; 10, identifier:Union; 11, type_parameter; 11, 12; 11, 14; 12, type; 12, 13; 13, identifier:int; 14, type; 14, 15; 15, identifier:str; 16, block; 16, 17; 17, return_statement; 17, 18; 18, conditional_expression:if; 18, 19; 18, 23; 18, 28; 19, call; 19, 20; 19, 21; 20, identifier:int; 21, argument_list; 21, 22; 22, identifier:text; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:text; 26, identifier:isdigit; 27, argument_list; 28, identifier:text | def atoi(text: str) -> Union[int, str]:
return int(text) if text.isdigit() else text |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:reducer_metro; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:metro; 6, identifier:values; 7, block; 7, 8; 7, 17; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:lookup; 11, call; 11, 12; 11, 13; 12, identifier:CachedLookup; 13, argument_list; 13, 14; 14, keyword_argument; 14, 15; 14, 16; 15, identifier:precision; 16, identifier:POI_GEOHASH_PRECISION; 17, for_statement; 17, 18; 17, 21; 17, 25; 18, pattern_list; 18, 19; 18, 20; 19, identifier:i; 20, identifier:value; 21, call; 21, 22; 21, 23; 22, identifier:enumerate; 23, argument_list; 23, 24; 24, identifier:values; 25, block; 25, 26; 25, 33; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 32; 28, pattern_list; 28, 29; 28, 30; 28, 31; 29, identifier:type_tag; 30, identifier:lonlat; 31, identifier:data; 32, identifier:value; 33, if_statement; 33, 34; 33, 37; 33, 70; 34, comparison_operator:==; 34, 35; 34, 36; 35, identifier:type_tag; 36, integer:1; 37, block; 37, 38; 38, expression_statement; 38, 39; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:lookup; 42, identifier:insert; 43, argument_list; 43, 44; 43, 45; 44, identifier:i; 45, call; 45, 46; 45, 47; 46, identifier:dict; 47, argument_list; 47, 48; 47, 62; 48, keyword_argument; 48, 49; 48, 50; 49, identifier:geometry; 50, call; 50, 51; 50, 52; 51, identifier:dict; 52, argument_list; 52, 53; 52, 56; 53, keyword_argument; 53, 54; 53, 55; 54, identifier:type; 55, string:'Point'; 56, keyword_argument; 56, 57; 56, 58; 57, identifier:coordinates; 58, call; 58, 59; 58, 60; 59, identifier:project; 60, argument_list; 60, 61; 61, identifier:lonlat; 62, keyword_argument; 62, 63; 62, 64; 63, identifier:properties; 64, call; 64, 65; 64, 66; 65, identifier:dict; 66, argument_list; 66, 67; 67, keyword_argument; 67, 68; 67, 69; 68, identifier:tags; 69, identifier:data; 70, else_clause; 70, 71; 71, block; 71, 72; 71, 79; 71, 83; 71, 95; 71, 141; 72, if_statement; 72, 73; 72, 77; 73, not_operator; 73, 74; 74, attribute; 74, 75; 74, 76; 75, identifier:lookup; 76, identifier:data_store; 77, block; 77, 78; 78, return_statement; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:poi_names; 82, list:[]; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:kwargs; 86, call; 86, 87; 86, 88; 87, identifier:dict; 88, argument_list; 88, 89; 88, 92; 89, keyword_argument; 89, 90; 89, 91; 90, identifier:buffer_size; 91, identifier:POI_DISTANCE; 92, keyword_argument; 92, 93; 92, 94; 93, identifier:multiple; 94, True; 95, for_statement; 95, 96; 95, 97; 95, 105; 96, identifier:poi; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:lookup; 100, identifier:get; 101, argument_list; 101, 102; 101, 103; 102, identifier:lonlat; 103, dictionary_splat; 103, 104; 104, identifier:kwargs; 105, block; 105, 106; 105, 118; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:has_tag; 109, list_comprehension; 109, 110; 109, 115; 110, comparison_operator:in; 110, 111; 110, 112; 111, identifier:tag; 112, subscript; 112, 113; 112, 114; 113, identifier:poi; 114, string:'tags'; 115, for_in_clause; 115, 116; 115, 117; 116, identifier:tag; 117, identifier:POI_TAGS; 118, if_statement; 118, 119; 118, 129; 119, boolean_operator:and; 119, 120; 119, 124; 120, call; 120, 121; 120, 122; 121, identifier:any; 122, argument_list; 122, 123; 123, identifier:has_tag; 124, comparison_operator:in; 124, 125; 124, 126; 125, string:'name'; 126, subscript; 126, 127; 126, 128; 127, identifier:poi; 128, string:'tags'; 129, block; 129, 130; 130, expression_statement; 130, 131; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:poi_names; 134, identifier:append; 135, argument_list; 135, 136; 136, subscript; 136, 137; 136, 140; 137, subscript; 137, 138; 137, 139; 138, identifier:poi; 139, string:'tags'; 140, string:'name'; 141, for_statement; 141, 142; 141, 143; 141, 147; 142, identifier:poi; 143, call; 143, 144; 143, 145; 144, identifier:set; 145, argument_list; 145, 146; 146, identifier:poi_names; 147, block; 147, 148; 148, expression_statement; 148, 149; 149, yield; 149, 150; 150, expression_list; 150, 151; 150, 154; 151, tuple; 151, 152; 151, 153; 152, identifier:metro; 153, identifier:poi; 154, integer:1 | def reducer_metro(self, metro, values):
lookup = CachedLookup(precision=POI_GEOHASH_PRECISION)
for i, value in enumerate(values):
type_tag, lonlat, data = value
if type_tag == 1:
lookup.insert(i, dict(
geometry=dict(type='Point', coordinates=project(lonlat)),
properties=dict(tags=data)
))
else:
if not lookup.data_store:
return
poi_names = []
kwargs = dict(buffer_size=POI_DISTANCE, multiple=True)
for poi in lookup.get(lonlat, **kwargs):
has_tag = [ tag in poi['tags'] for tag in POI_TAGS ]
if any(has_tag) and 'name' in poi['tags']:
poi_names.append(poi['tags']['name'])
for poi in set(poi_names):
yield (metro, poi), 1 |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 1, 19; 2, function_name:list_file_extensions; 3, parameters; 3, 4; 3, 8; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:path; 6, type; 6, 7; 7, identifier:str; 8, typed_default_parameter; 8, 9; 8, 10; 8, 12; 9, identifier:reportevery; 10, type; 10, 11; 11, identifier:int; 12, integer:1; 13, type; 13, 14; 14, generic_type; 14, 15; 14, 16; 15, identifier:List; 16, type_parameter; 16, 17; 17, type; 17, 18; 18, identifier:str; 19, block; 19, 20; 19, 26; 19, 30; 19, 86; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:extensions; 23, call; 23, 24; 23, 25; 24, identifier:set; 25, argument_list; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:count; 29, integer:0; 30, for_statement; 30, 31; 30, 35; 30, 41; 31, pattern_list; 31, 32; 31, 33; 31, 34; 32, identifier:root; 33, identifier:dirs; 34, identifier:files; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:os; 38, identifier:walk; 39, argument_list; 39, 40; 40, identifier:path; 41, block; 41, 42; 41, 46; 41, 62; 42, expression_statement; 42, 43; 43, augmented_assignment:+=; 43, 44; 43, 45; 44, identifier:count; 45, integer:1; 46, if_statement; 46, 47; 46, 52; 47, comparison_operator:==; 47, 48; 47, 51; 48, binary_operator:%; 48, 49; 48, 50; 49, identifier:count; 50, identifier:reportevery; 51, integer:0; 52, block; 52, 53; 53, expression_statement; 53, 54; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:log; 57, identifier:debug; 58, argument_list; 58, 59; 58, 60; 58, 61; 59, string:"Walking directory {}: {!r}"; 60, identifier:count; 61, identifier:root; 62, for_statement; 62, 63; 62, 64; 62, 65; 63, identifier:file; 64, identifier:files; 65, block; 65, 66; 65, 79; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 71; 68, pattern_list; 68, 69; 68, 70; 69, identifier:filename; 70, identifier:ext; 71, call; 71, 72; 71, 77; 72, attribute; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:os; 75, identifier:path; 76, identifier:splitext; 77, argument_list; 77, 78; 78, identifier:file; 79, expression_statement; 79, 80; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:extensions; 83, identifier:add; 84, argument_list; 84, 85; 85, identifier:ext; 86, return_statement; 86, 87; 87, call; 87, 88; 87, 89; 88, identifier:sorted; 89, argument_list; 89, 90; 90, call; 90, 91; 90, 92; 91, identifier:list; 92, argument_list; 92, 93; 93, identifier:extensions | def list_file_extensions(path: str, reportevery: int = 1) -> List[str]:
extensions = set()
count = 0
for root, dirs, files in os.walk(path):
count += 1
if count % reportevery == 0:
log.debug("Walking directory {}: {!r}", count, root)
for file in files:
filename, ext = os.path.splitext(file)
extensions.add(ext)
return sorted(list(extensions)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:sort_by_dependencies; 3, parameters; 3, 4; 3, 5; 4, identifier:exts; 5, default_parameter; 5, 6; 5, 7; 6, identifier:retry; 7, None; 8, block; 8, 9; 8, 19; 8, 29; 8, 43; 8, 161; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 14; 11, pattern_list; 11, 12; 11, 13; 12, identifier:sorted_ext; 13, identifier:features_from_sorted; 14, expression_list; 14, 15; 14, 16; 15, list:[]; 16, call; 16, 17; 16, 18; 17, identifier:set; 18, argument_list; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:pending; 22, list_comprehension; 22, 23; 22, 26; 23, tuple; 23, 24; 23, 25; 24, identifier:e; 25, integer:0; 26, for_in_clause; 26, 27; 26, 28; 27, identifier:e; 28, identifier:exts; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:retry; 32, conditional_expression:if; 32, 33; 32, 39; 32, 42; 33, binary_operator:*; 33, 34; 33, 38; 34, call; 34, 35; 34, 36; 35, identifier:len; 36, argument_list; 36, 37; 37, identifier:exts; 38, integer:100; 39, comparison_operator:is; 39, 40; 39, 41; 40, identifier:retry; 41, None; 42, identifier:retry; 43, while_statement; 43, 44; 43, 45; 44, identifier:pending; 45, block; 45, 46; 45, 57; 45, 89; 45, 97; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 51; 48, pattern_list; 48, 49; 48, 50; 49, identifier:ext; 50, identifier:cnt; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:pending; 54, identifier:pop; 55, argument_list; 55, 56; 56, integer:0; 57, if_statement; 57, 58; 57, 71; 58, boolean_operator:and; 58, 59; 58, 65; 59, not_operator; 59, 60; 60, call; 60, 61; 60, 62; 61, identifier:isinstance; 62, argument_list; 62, 63; 62, 64; 63, identifier:ext; 64, identifier:Extractor; 65, not_operator; 65, 66; 66, call; 66, 67; 66, 68; 67, identifier:issubclass; 68, argument_list; 68, 69; 68, 70; 69, identifier:ext; 70, identifier:Extractor; 71, block; 71, 72; 71, 76; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:msg; 75, string:"Only Extractor instances are allowed. Found {}."; 76, raise_statement; 76, 77; 77, call; 77, 78; 77, 79; 78, identifier:TypeError; 79, argument_list; 79, 80; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:msg; 83, identifier:format; 84, argument_list; 84, 85; 85, call; 85, 86; 85, 87; 86, identifier:type; 87, argument_list; 87, 88; 88, identifier:ext; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:deps; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:ext; 95, identifier:get_dependencies; 96, argument_list; 97, if_statement; 97, 98; 97, 104; 97, 141; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:deps; 101, identifier:difference; 102, argument_list; 102, 103; 103, identifier:features_from_sorted; 104, block; 104, 105; 104, 130; 105, if_statement; 105, 106; 105, 111; 106, comparison_operator:>; 106, 107; 106, 110; 107, binary_operator:+; 107, 108; 107, 109; 108, identifier:cnt; 109, integer:1; 110, identifier:retry; 111, block; 111, 112; 111, 116; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:msg; 115, string:"Maximun retry ({}) to sort achieved from extractor {}."; 116, raise_statement; 116, 117; 117, call; 117, 118; 117, 119; 118, identifier:RuntimeError; 119, argument_list; 119, 120; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:msg; 123, identifier:format; 124, argument_list; 124, 125; 124, 126; 125, identifier:retry; 126, call; 126, 127; 126, 128; 127, identifier:type; 128, argument_list; 128, 129; 129, identifier:ext; 130, expression_statement; 130, 131; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:pending; 134, identifier:append; 135, argument_list; 135, 136; 136, tuple; 136, 137; 136, 138; 137, identifier:ext; 138, binary_operator:+; 138, 139; 138, 140; 139, identifier:cnt; 140, integer:1; 141, else_clause; 141, 142; 142, block; 142, 143; 142, 150; 143, expression_statement; 143, 144; 144, call; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:sorted_ext; 147, identifier:append; 148, argument_list; 148, 149; 149, identifier:ext; 150, expression_statement; 150, 151; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:features_from_sorted; 154, identifier:update; 155, argument_list; 155, 156; 156, call; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:ext; 159, identifier:get_features; 160, argument_list; 161, return_statement; 161, 162; 162, call; 162, 163; 162, 164; 163, identifier:tuple; 164, argument_list; 164, 165; 165, identifier:sorted_ext | def sort_by_dependencies(exts, retry=None):
sorted_ext, features_from_sorted = [], set()
pending = [(e, 0) for e in exts]
retry = len(exts) * 100 if retry is None else retry
while pending:
ext, cnt = pending.pop(0)
if not isinstance(ext, Extractor) and not issubclass(ext, Extractor):
msg = "Only Extractor instances are allowed. Found {}."
raise TypeError(msg.format(type(ext)))
deps = ext.get_dependencies()
if deps.difference(features_from_sorted):
if cnt + 1 > retry:
msg = "Maximun retry ({}) to sort achieved from extractor {}."
raise RuntimeError(msg.format(retry, type(ext)))
pending.append((ext, cnt + 1))
else:
sorted_ext.append(ext)
features_from_sorted.update(ext.get_features())
return tuple(sorted_ext) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_sort_layers; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:_layers; 11, call; 11, 12; 11, 13; 12, identifier:OrderedDict; 13, argument_list; 13, 14; 14, call; 14, 15; 14, 16; 15, identifier:sorted; 16, argument_list; 16, 17; 16, 24; 17, call; 17, 18; 17, 23; 18, attribute; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:_layers; 22, identifier:items; 23, argument_list; 24, keyword_argument; 24, 25; 24, 26; 25, identifier:key; 26, lambda; 26, 27; 26, 29; 27, lambda_parameters; 27, 28; 28, identifier:t; 29, subscript; 29, 30; 29, 31; 30, identifier:t; 31, integer:0 | def _sort_layers(self):
self._layers = OrderedDict(sorted(self._layers.items(), key=lambda t: t[0])) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:sort_sections; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:order; 6, block; 6, 7; 6, 19; 6, 41; 6, 67; 6, 79; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:order_lc; 10, list_comprehension; 10, 11; 10, 16; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:e; 14, identifier:lower; 15, argument_list; 16, for_in_clause; 16, 17; 16, 18; 17, identifier:e; 18, identifier:order; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:sections; 22, call; 22, 23; 22, 24; 23, identifier:OrderedDict; 24, generator_expression; 24, 25; 24, 32; 24, 35; 25, tuple; 25, 26; 25, 27; 26, identifier:k; 27, subscript; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:sections; 31, identifier:k; 32, for_in_clause; 32, 33; 32, 34; 33, identifier:k; 34, identifier:order_lc; 35, if_clause; 35, 36; 36, comparison_operator:in; 36, 37; 36, 38; 37, identifier:k; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:sections; 41, expression_statement; 41, 42; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:sections; 45, identifier:update; 46, generator_expression; 46, 47; 46, 54; 46, 63; 47, tuple; 47, 48; 47, 49; 48, identifier:k; 49, subscript; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:sections; 53, identifier:k; 54, for_in_clause; 54, 55; 54, 56; 55, identifier:k; 56, call; 56, 57; 56, 62; 57, attribute; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:self; 60, identifier:sections; 61, identifier:keys; 62, argument_list; 63, if_clause; 63, 64; 64, comparison_operator:not; 64, 65; 64, 66; 65, identifier:k; 66, identifier:order_lc; 67, assert_statement; 67, 68; 68, comparison_operator:==; 68, 69; 68, 75; 69, call; 69, 70; 69, 71; 70, identifier:len; 71, argument_list; 71, 72; 72, attribute; 72, 73; 72, 74; 73, identifier:self; 74, identifier:sections; 75, call; 75, 76; 75, 77; 76, identifier:len; 77, argument_list; 77, 78; 78, identifier:sections; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:self; 83, identifier:sections; 84, identifier:sections | def sort_sections(self, order):
order_lc = [e.lower() for e in order]
sections = OrderedDict( (k,self.sections[k]) for k in order_lc if k in self.sections)
sections.update( (k,self.sections[k]) for k in self.sections.keys() if k not in order_lc)
assert len(self.sections) == len(sections)
self.sections = sections |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:split_iterable_as_iterable; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:values; 6, block; 6, 7; 6, 17; 6, 23; 6, 64; 6, 75; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:values; 10, call; 10, 11; 10, 12; 11, identifier:iter; 12, argument_list; 12, 13; 13, call; 13, 14; 13, 15; 14, identifier:enumerate; 15, argument_list; 15, 16; 16, identifier:values; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:cache; 20, call; 20, 21; 20, 22; 21, identifier:dict; 22, argument_list; 23, function_definition; 23, 24; 23, 25; 23, 27; 24, function_name:get_value; 25, parameters; 25, 26; 26, identifier:ti; 27, block; 27, 28; 28, try_statement; 28, 29; 28, 37; 29, block; 29, 30; 30, return_statement; 30, 31; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:cache; 34, identifier:pop; 35, argument_list; 35, 36; 36, identifier:ti; 37, except_clause; 37, 38; 38, block; 38, 39; 39, while_statement; 39, 40; 39, 41; 40, True; 41, block; 41, 42; 41, 51; 41, 58; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 47; 44, pattern_list; 44, 45; 44, 46; 45, identifier:i; 46, identifier:v; 47, call; 47, 48; 47, 49; 48, identifier:next; 49, argument_list; 49, 50; 50, identifier:values; 51, if_statement; 51, 52; 51, 55; 52, comparison_operator:==; 52, 53; 52, 54; 53, identifier:i; 54, identifier:ti; 55, block; 55, 56; 56, return_statement; 56, 57; 57, identifier:v; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 63; 60, subscript; 60, 61; 60, 62; 61, identifier:cache; 62, identifier:i; 63, identifier:v; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:s; 67, call; 67, 68; 67, 69; 68, identifier:iter; 69, argument_list; 69, 70; 70, attribute; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:index; 74, identifier:sorter; 75, for_statement; 75, 76; 75, 77; 75, 80; 76, identifier:c; 77, attribute; 77, 78; 77, 79; 78, identifier:self; 79, identifier:count; 80, block; 80, 81; 81, expression_statement; 81, 82; 82, yield; 82, 83; 83, generator_expression; 83, 84; 83, 88; 84, call; 84, 85; 84, 86; 85, identifier:get_value; 86, argument_list; 86, 87; 87, identifier:i; 88, for_in_clause; 88, 89; 88, 90; 89, identifier:i; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:itertools; 93, identifier:islice; 94, argument_list; 94, 95; 94, 96; 95, identifier:s; 96, call; 96, 97; 96, 98; 97, identifier:int; 98, argument_list; 98, 99; 99, identifier:c | def split_iterable_as_iterable(self, values):
values = iter(enumerate(values))
cache = dict()
def get_value(ti):
try:
return cache.pop(ti)
except:
while True:
i, v = next(values)
if i==ti:
return v
cache[i] = v
s = iter(self.index.sorter)
for c in self.count:
yield (get_value(i) for i in itertools.islice(s, int(c))) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 19; 2, function_name:as_index; 3, parameters; 3, 4; 3, 5; 3, 10; 3, 13; 3, 16; 4, identifier:keys; 5, default_parameter; 5, 6; 5, 7; 6, identifier:axis; 7, attribute; 7, 8; 7, 9; 8, identifier:semantics; 9, identifier:axis_default; 10, default_parameter; 10, 11; 10, 12; 11, identifier:base; 12, False; 13, default_parameter; 13, 14; 13, 15; 14, identifier:stable; 15, True; 16, default_parameter; 16, 17; 16, 18; 17, identifier:lex_as_struct; 18, False; 19, block; 19, 20; 19, 49; 19, 75; 19, 93; 19, 106; 20, if_statement; 20, 21; 20, 26; 21, call; 21, 22; 21, 23; 22, identifier:isinstance; 23, argument_list; 23, 24; 23, 25; 24, identifier:keys; 25, identifier:Index; 26, block; 26, 27; 27, if_statement; 27, 28; 27, 38; 27, 45; 28, boolean_operator:and; 28, 29; 28, 35; 29, comparison_operator:is; 29, 30; 29, 34; 30, call; 30, 31; 30, 32; 31, identifier:type; 32, argument_list; 32, 33; 33, identifier:keys; 34, identifier:BaseIndex; 35, comparison_operator:==; 35, 36; 35, 37; 36, identifier:base; 37, False; 38, block; 38, 39; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:keys; 42, attribute; 42, 43; 42, 44; 43, identifier:keys; 44, identifier:keys; 45, else_clause; 45, 46; 46, block; 46, 47; 47, return_statement; 47, 48; 48, identifier:keys; 49, if_statement; 49, 50; 49, 55; 50, call; 50, 51; 50, 52; 51, identifier:isinstance; 52, argument_list; 52, 53; 52, 54; 53, identifier:keys; 54, identifier:tuple; 55, block; 55, 56; 56, if_statement; 56, 57; 56, 58; 56, 67; 57, identifier:lex_as_struct; 58, block; 58, 59; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:keys; 62, call; 62, 63; 62, 64; 63, identifier:as_struct_array; 64, argument_list; 64, 65; 65, list_splat; 65, 66; 66, identifier:keys; 67, else_clause; 67, 68; 68, block; 68, 69; 69, return_statement; 69, 70; 70, call; 70, 71; 70, 72; 71, identifier:LexIndex; 72, argument_list; 72, 73; 72, 74; 73, identifier:keys; 74, identifier:stable; 75, try_statement; 75, 76; 75, 86; 76, block; 76, 77; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:keys; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:np; 83, identifier:asarray; 84, argument_list; 84, 85; 85, identifier:keys; 86, except_clause; 86, 87; 87, block; 87, 88; 88, raise_statement; 88, 89; 89, call; 89, 90; 89, 91; 90, identifier:TypeError; 91, argument_list; 91, 92; 92, string:'Given object does not form a valid set of keys'; 93, if_statement; 93, 94; 93, 97; 94, comparison_operator:is; 94, 95; 94, 96; 95, identifier:axis; 96, None; 97, block; 97, 98; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:keys; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:keys; 104, identifier:flatten; 105, argument_list; 106, if_statement; 106, 107; 106, 112; 106, 131; 107, comparison_operator:==; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:keys; 110, identifier:ndim; 111, integer:1; 112, block; 112, 113; 113, if_statement; 113, 114; 113, 115; 113, 121; 114, identifier:base; 115, block; 115, 116; 116, return_statement; 116, 117; 117, call; 117, 118; 117, 119; 118, identifier:BaseIndex; 119, argument_list; 119, 120; 120, identifier:keys; 121, else_clause; 121, 122; 122, block; 122, 123; 123, return_statement; 123, 124; 124, call; 124, 125; 124, 126; 125, identifier:Index; 126, argument_list; 126, 127; 126, 128; 127, identifier:keys; 128, keyword_argument; 128, 129; 128, 130; 129, identifier:stable; 130, identifier:stable; 131, else_clause; 131, 132; 132, block; 132, 133; 133, return_statement; 133, 134; 134, call; 134, 135; 134, 136; 135, identifier:ObjectIndex; 136, argument_list; 136, 137; 136, 138; 136, 139; 137, identifier:keys; 138, identifier:axis; 139, keyword_argument; 139, 140; 139, 141; 140, identifier:stable; 141, identifier:stable | def as_index(keys, axis=semantics.axis_default, base=False, stable=True, lex_as_struct=False):
if isinstance(keys, Index):
if type(keys) is BaseIndex and base==False:
keys = keys.keys
else:
return keys
if isinstance(keys, tuple):
if lex_as_struct:
keys = as_struct_array(*keys)
else:
return LexIndex(keys, stable)
try:
keys = np.asarray(keys)
except:
raise TypeError('Given object does not form a valid set of keys')
if axis is None:
keys = keys.flatten()
if keys.ndim==1:
if base:
return BaseIndex(keys)
else:
return Index(keys, stable=stable)
else:
return ObjectIndex(keys, axis, stable=stable) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:axis_as_object; 3, parameters; 3, 4; 3, 5; 4, identifier:arr; 5, default_parameter; 5, 6; 5, 7; 6, identifier:axis; 7, unary_operator:-; 7, 8; 8, integer:1; 9, block; 9, 10; 9, 16; 9, 34; 9, 46; 9, 59; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:shape; 13, attribute; 13, 14; 13, 15; 14, identifier:arr; 15, identifier:shape; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:arr; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:np; 22, identifier:ascontiguousarray; 23, argument_list; 23, 24; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:np; 27, identifier:rollaxis; 28, argument_list; 28, 29; 28, 30; 28, 31; 29, identifier:arr; 30, identifier:axis; 31, attribute; 31, 32; 31, 33; 32, identifier:arr; 33, identifier:ndim; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:nbytes; 37, binary_operator:*; 37, 38; 37, 43; 38, attribute; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:arr; 41, identifier:dtype; 42, identifier:itemsize; 43, subscript; 43, 44; 43, 45; 44, identifier:shape; 45, identifier:axis; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:voidtype; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:np; 52, identifier:dtype; 53, argument_list; 53, 54; 54, tuple; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:np; 57, identifier:void; 58, identifier:nbytes; 59, return_statement; 59, 60; 60, call; 60, 61; 60, 69; 61, attribute; 61, 62; 61, 68; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:arr; 65, identifier:view; 66, argument_list; 66, 67; 67, identifier:voidtype; 68, identifier:reshape; 69, argument_list; 69, 70; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:np; 73, identifier:delete; 74, argument_list; 74, 75; 74, 76; 75, identifier:shape; 76, identifier:axis | def axis_as_object(arr, axis=-1):
shape = arr.shape
arr = np.ascontiguousarray(np.rollaxis(arr, axis, arr.ndim))
nbytes = arr.dtype.itemsize * shape[axis]
voidtype = np.dtype((np.void, nbytes))
return arr.view(voidtype).reshape(np.delete(shape, axis)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:rank; 3, parameters; 3, 4; 3, 5; 4, identifier:keys; 5, default_parameter; 5, 6; 5, 7; 6, identifier:axis; 7, attribute; 7, 8; 7, 9; 8, identifier:semantics; 9, identifier:axis_default; 10, block; 10, 11; 10, 19; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:index; 14, call; 14, 15; 14, 16; 15, identifier:as_index; 16, argument_list; 16, 17; 16, 18; 17, identifier:keys; 18, identifier:axis; 19, return_statement; 19, 20; 20, attribute; 20, 21; 20, 22; 21, identifier:index; 22, identifier:rank | def rank(keys, axis=semantics.axis_default):
index = as_index(keys, axis)
return index.rank |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort_by; 3, parameters; 3, 4; 4, identifier:function; 5, block; 5, 6; 5, 16; 5, 28; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:f; 9, call; 9, 10; 9, 11; 10, identifier:partial; 11, argument_list; 11, 12; 11, 13; 12, identifier:sorted; 13, keyword_argument; 13, 14; 13, 15; 14, identifier:key; 15, identifier:function; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:f; 20, identifier:attrs; 21, dictionary; 21, 22; 22, pair; 22, 23; 22, 24; 23, string:'descending'; 24, call; 24, 25; 24, 26; 25, identifier:_descending_sort_by; 26, argument_list; 26, 27; 27, identifier:function; 28, return_statement; 28, 29; 29, identifier:f | def sort_by(function):
f = partial(sorted, key=function)
f.attrs = {'descending': _descending_sort_by(function)}
return f |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:in_sorted; 3, parameters; 3, 4; 3, 5; 4, identifier:values; 5, identifier:value; 6, block; 6, 7; 6, 17; 6, 27; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:index; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:bisect; 13, identifier:bisect_left; 14, argument_list; 14, 15; 14, 16; 15, identifier:values; 16, identifier:value; 17, if_statement; 17, 18; 17, 24; 18, comparison_operator:>=; 18, 19; 18, 20; 19, identifier:index; 20, call; 20, 21; 20, 22; 21, identifier:len; 22, argument_list; 22, 23; 23, identifier:values; 24, block; 24, 25; 25, return_statement; 25, 26; 26, False; 27, return_statement; 27, 28; 28, comparison_operator:==; 28, 29; 28, 32; 29, subscript; 29, 30; 29, 31; 30, identifier:values; 31, identifier:index; 32, identifier:value | def in_sorted(values, value):
index = bisect.bisect_left(values, value)
if index >= len(values):
return False
return values[index] == value |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:handle_keypress; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:k; 6, block; 6, 7; 7, if_statement; 7, 8; 7, 11; 7, 24; 7, 37; 7, 50; 8, comparison_operator:==; 8, 9; 8, 10; 9, identifier:k; 10, string:"esc"; 11, block; 11, 12; 11, 18; 12, expression_statement; 12, 13; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:save_file; 17, argument_list; 18, raise_statement; 18, 19; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:urwid; 22, identifier:ExitMainLoop; 23, argument_list; 24, elif_clause; 24, 25; 24, 28; 25, comparison_operator:==; 25, 26; 25, 27; 26, identifier:k; 27, string:"delete"; 28, block; 28, 29; 29, expression_statement; 29, 30; 30, call; 30, 31; 30, 36; 31, attribute; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:walker; 35, identifier:combine_focus_with_next; 36, argument_list; 37, elif_clause; 37, 38; 37, 41; 38, comparison_operator:==; 38, 39; 38, 40; 39, identifier:k; 40, string:"backspace"; 41, block; 41, 42; 42, expression_statement; 42, 43; 43, call; 43, 44; 43, 49; 44, attribute; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:walker; 48, identifier:combine_focus_with_prev; 49, argument_list; 50, elif_clause; 50, 51; 50, 54; 51, comparison_operator:==; 51, 52; 51, 53; 52, identifier:k; 53, string:"enter"; 54, block; 54, 55; 54, 63; 54, 73; 55, expression_statement; 55, 56; 56, call; 56, 57; 56, 62; 57, attribute; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:self; 60, identifier:walker; 61, identifier:split_focus; 62, argument_list; 63, expression_statement; 63, 64; 64, call; 64, 65; 64, 70; 65, attribute; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:view; 69, identifier:keypress; 70, argument_list; 70, 71; 70, 72; 71, identifier:size; 72, string:"down"; 73, expression_statement; 73, 74; 74, call; 74, 75; 74, 80; 75, attribute; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:self; 78, identifier:view; 79, identifier:keypress; 80, argument_list; 80, 81; 80, 82; 81, identifier:size; 82, string:"home" | def handle_keypress(self, k):
if k == "esc":
self.save_file()
raise urwid.ExitMainLoop()
elif k == "delete":
self.walker.combine_focus_with_next()
elif k == "backspace":
self.walker.combine_focus_with_prev()
elif k == "enter":
self.walker.split_focus()
self.view.keypress(size, "down")
self.view.keypress(size, "home") |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:sorted; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:fsort; 6, block; 6, 7; 6, 9; 6, 23; 6, 31; 7, expression_statement; 7, 8; 8, string:'''
Allows to add one or more sort on specific fields. Each sort can be reversed as well. The sort is defined on a per field level, with special field name for _score to sort by score.
'''; 9, if_statement; 9, 10; 9, 14; 10, not_operator; 10, 11; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:params; 14, block; 14, 15; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:params; 20, call; 20, 21; 20, 22; 21, identifier:dict; 22, argument_list; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 30; 25, subscript; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:params; 29, string:'sort'; 30, identifier:fsort; 31, return_statement; 31, 32; 32, identifier:self | def sorted(self, fsort):
'''
Allows to add one or more sort on specific fields. Each sort can be reversed as well. The sort is defined on a per field level, with special field name for _score to sort by score.
'''
if not self.params:
self.params = dict()
self.params['sort'] = fsort
return self |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_filter_sources; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:sources; 6, block; 6, 7; 6, 15; 6, 41; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 12; 9, pattern_list; 9, 10; 9, 11; 10, identifier:filtered; 11, identifier:hosts; 12, expression_list; 12, 13; 12, 14; 13, list:[]; 14, list:[]; 15, for_statement; 15, 16; 15, 17; 15, 18; 16, identifier:source; 17, identifier:sources; 18, block; 18, 19; 18, 25; 18, 32; 19, if_statement; 19, 20; 19, 23; 20, comparison_operator:in; 20, 21; 20, 22; 21, string:'error'; 22, identifier:source; 23, block; 23, 24; 24, continue_statement; 25, expression_statement; 25, 26; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:filtered; 29, identifier:append; 30, argument_list; 30, 31; 31, identifier:source; 32, expression_statement; 32, 33; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:hosts; 36, identifier:append; 37, argument_list; 37, 38; 38, subscript; 38, 39; 38, 40; 39, identifier:source; 40, string:'host_name'; 41, return_statement; 41, 42; 42, call; 42, 43; 42, 44; 43, identifier:sorted; 44, argument_list; 44, 45; 44, 46; 45, identifier:filtered; 46, keyword_argument; 46, 47; 46, 48; 47, identifier:key; 48, lambda; 48, 49; 48, 51; 49, lambda_parameters; 49, 50; 50, identifier:s; 51, call; 51, 52; 51, 60; 52, attribute; 52, 53; 52, 59; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:_hosts_by_success; 57, argument_list; 57, 58; 58, identifier:hosts; 59, identifier:index; 60, argument_list; 60, 61; 61, subscript; 61, 62; 61, 63; 62, identifier:s; 63, string:'host_name' | def _filter_sources(self, sources):
filtered, hosts = [], []
for source in sources:
if 'error' in source:
continue
filtered.append(source)
hosts.append(source['host_name'])
return sorted(filtered, key=lambda s:
self._hosts_by_success(hosts).index(s['host_name'])) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_cantons; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 6, return_statement; 6, 7; 7, call; 7, 8; 7, 9; 8, identifier:sorted; 9, argument_list; 9, 10; 10, call; 10, 11; 10, 12; 11, identifier:list; 12, argument_list; 12, 13; 13, call; 13, 14; 13, 15; 14, identifier:set; 15, argument_list; 15, 16; 16, list_comprehension; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:location; 19, identifier:canton; 20, for_in_clause; 20, 21; 20, 22; 21, identifier:location; 22, call; 22, 23; 22, 30; 23, attribute; 23, 24; 23, 29; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:get_locations; 28, argument_list; 29, identifier:values; 30, argument_list | def get_cantons(self):
return sorted(list(set([
location.canton for location in self.get_locations().values()
]))) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_municipalities; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 6, return_statement; 6, 7; 7, call; 7, 8; 7, 9; 8, identifier:sorted; 9, argument_list; 9, 10; 10, call; 10, 11; 10, 12; 11, identifier:list; 12, argument_list; 12, 13; 13, call; 13, 14; 13, 15; 14, identifier:set; 15, argument_list; 15, 16; 16, list_comprehension; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:location; 19, identifier:municipality; 20, for_in_clause; 20, 21; 20, 22; 21, identifier:location; 22, call; 22, 23; 22, 30; 23, attribute; 23, 24; 23, 29; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:get_locations; 28, argument_list; 29, identifier:values; 30, argument_list | def get_municipalities(self):
return sorted(list(set([
location.municipality for location in self.get_locations().values()
]))) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:execute; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 8; 4, identifier:self; 5, identifier:sql; 6, list_splat_pattern; 6, 7; 7, identifier:args; 8, dictionary_splat_pattern; 8, 9; 9, identifier:kwargs; 10, block; 10, 11; 10, 13; 10, 48; 10, 58; 10, 65; 11, expression_statement; 11, 12; 12, string:'''
Run raw SQL on the database, and receive relaxing output.
This is sort of the foundational method that most of the
others build on.
'''; 13, try_statement; 13, 14; 13, 26; 14, block; 14, 15; 15, expression_statement; 15, 16; 16, call; 16, 17; 16, 22; 17, attribute; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:cursor; 21, identifier:execute; 22, argument_list; 22, 23; 22, 24; 23, identifier:sql; 24, list_splat; 24, 25; 25, identifier:args; 26, except_clause; 26, 27; 26, 32; 26, 33; 27, attribute; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:sqlite3; 31, identifier:InterfaceError; 32, identifier:msg; 33, block; 33, 34; 34, raise_statement; 34, 35; 35, call; 35, 36; 35, 41; 36, attribute; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:sqlite3; 40, identifier:InterfaceError; 41, argument_list; 41, 42; 42, binary_operator:+; 42, 43; 42, 47; 43, call; 43, 44; 43, 45; 44, identifier:unicode; 45, argument_list; 45, 46; 46, identifier:msg; 47, string:'\nTry converting types or pickling.'; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:rows; 51, call; 51, 52; 51, 57; 52, attribute; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:cursor; 56, identifier:fetchall; 57, argument_list; 58, expression_statement; 58, 59; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:__commit_if_necessary; 63, argument_list; 63, 64; 64, identifier:kwargs; 65, if_statement; 65, 66; 65, 73; 65, 76; 66, comparison_operator:==; 66, 67; 66, 68; 67, None; 68, attribute; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:self; 71, identifier:cursor; 72, identifier:description; 73, block; 73, 74; 74, return_statement; 74, 75; 75, None; 76, else_clause; 76, 77; 77, block; 77, 78; 77, 97; 77, 112; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:colnames; 81, list_comprehension; 81, 82; 81, 90; 82, call; 82, 83; 82, 88; 83, attribute; 83, 84; 83, 87; 84, subscript; 84, 85; 84, 86; 85, identifier:d; 86, integer:0; 87, identifier:decode; 88, argument_list; 88, 89; 89, string:'utf-8'; 90, for_in_clause; 90, 91; 90, 92; 91, identifier:d; 92, attribute; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:self; 95, identifier:cursor; 96, identifier:description; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:rawdata; 100, list_comprehension; 100, 101; 100, 109; 101, call; 101, 102; 101, 103; 102, identifier:OrderedDict; 103, argument_list; 103, 104; 104, call; 104, 105; 104, 106; 105, identifier:zip; 106, argument_list; 106, 107; 106, 108; 107, identifier:colnames; 108, identifier:row; 109, for_in_clause; 109, 110; 109, 111; 110, identifier:row; 111, identifier:rows; 112, return_statement; 112, 113; 113, identifier:rawdata | def execute(self, sql, *args, **kwargs):
'''
Run raw SQL on the database, and receive relaxing output.
This is sort of the foundational method that most of the
others build on.
'''
try:
self.cursor.execute(sql, *args)
except self.sqlite3.InterfaceError, msg:
raise self.sqlite3.InterfaceError(unicode(msg) + '\nTry converting types or pickling.')
rows = self.cursor.fetchall()
self.__commit_if_necessary(kwargs)
if None == self.cursor.description:
return None
else:
colnames = [d[0].decode('utf-8') for d in self.cursor.description]
rawdata = [OrderedDict(zip(colnames,row)) for row in rows]
return rawdata |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:check_message; 3, parameters; 3, 4; 3, 5; 4, identifier:message; 5, dictionary_splat_pattern; 5, 6; 6, identifier:kwargs; 7, block; 7, 8; 7, 29; 7, 39; 7, 50; 7, 61; 7, 65; 7, 74; 7, 98; 8, if_statement; 8, 9; 8, 16; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:kwargs; 12, identifier:pop; 13, argument_list; 13, 14; 13, 15; 14, string:"allow_empty"; 15, False; 16, block; 16, 17; 17, if_statement; 17, 18; 17, 26; 18, boolean_operator:or; 18, 19; 18, 21; 19, not_operator; 19, 20; 20, identifier:message; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:message; 24, identifier:isspace; 25, argument_list; 26, block; 26, 27; 27, return_statement; 27, 28; 28, list:[]; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:lines; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:re; 35, identifier:split; 36, argument_list; 36, 37; 36, 38; 37, string:r"\r\n|\r|\n"; 38, identifier:message; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:errors; 42, call; 42, 43; 42, 44; 43, identifier:_check_1st_line; 44, argument_list; 44, 45; 44, 48; 45, subscript; 45, 46; 45, 47; 46, identifier:lines; 47, integer:0; 48, dictionary_splat; 48, 49; 49, identifier:kwargs; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 55; 52, pattern_list; 52, 53; 52, 54; 53, identifier:err; 54, identifier:signature_lines; 55, call; 55, 56; 55, 57; 56, identifier:_check_bullets; 57, argument_list; 57, 58; 57, 59; 58, identifier:lines; 59, dictionary_splat; 59, 60; 60, identifier:kwargs; 61, expression_statement; 61, 62; 62, augmented_assignment:+=; 62, 63; 62, 64; 63, identifier:errors; 64, identifier:err; 65, expression_statement; 65, 66; 66, augmented_assignment:+=; 66, 67; 66, 68; 67, identifier:errors; 68, call; 68, 69; 68, 70; 69, identifier:_check_signatures; 70, argument_list; 70, 71; 70, 72; 71, identifier:signature_lines; 72, dictionary_splat; 72, 73; 73, identifier:kwargs; 74, function_definition; 74, 75; 74, 76; 74, 80; 75, function_name:_format; 76, parameters; 76, 77; 76, 78; 76, 79; 77, identifier:code; 78, identifier:lineno; 79, identifier:args; 80, block; 80, 81; 81, return_statement; 81, 82; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, string:"{0}: {1} {2}"; 85, identifier:format; 86, argument_list; 86, 87; 86, 88; 86, 89; 87, identifier:lineno; 88, identifier:code; 89, call; 89, 90; 89, 95; 90, attribute; 90, 91; 90, 94; 91, subscript; 91, 92; 91, 93; 92, identifier:_messages_codes; 93, identifier:code; 94, identifier:format; 95, argument_list; 95, 96; 96, list_splat; 96, 97; 97, identifier:args; 98, return_statement; 98, 99; 99, call; 99, 100; 99, 101; 100, identifier:list; 101, argument_list; 101, 102; 102, call; 102, 103; 102, 104; 103, identifier:map; 104, argument_list; 104, 105; 104, 122; 105, lambda; 105, 106; 105, 108; 106, lambda_parameters; 106, 107; 107, identifier:x; 108, call; 108, 109; 108, 110; 109, identifier:_format; 110, argument_list; 110, 111; 110, 114; 110, 117; 111, subscript; 111, 112; 111, 113; 112, identifier:x; 113, integer:0; 114, subscript; 114, 115; 114, 116; 115, identifier:x; 116, integer:1; 117, subscript; 117, 118; 117, 119; 118, identifier:x; 119, slice; 119, 120; 119, 121; 120, integer:2; 121, colon; 122, call; 122, 123; 122, 124; 123, identifier:sorted; 124, argument_list; 124, 125; 124, 126; 125, identifier:errors; 126, keyword_argument; 126, 127; 126, 128; 127, identifier:key; 128, lambda; 128, 129; 128, 131; 129, lambda_parameters; 129, 130; 130, identifier:x; 131, subscript; 131, 132; 131, 133; 132, identifier:x; 133, integer:0 | def check_message(message, **kwargs):
if kwargs.pop("allow_empty", False):
if not message or message.isspace():
return []
lines = re.split(r"\r\n|\r|\n", message)
errors = _check_1st_line(lines[0], **kwargs)
err, signature_lines = _check_bullets(lines, **kwargs)
errors += err
errors += _check_signatures(signature_lines, **kwargs)
def _format(code, lineno, args):
return "{0}: {1} {2}".format(lineno,
code,
_messages_codes[code].format(*args))
return list(map(lambda x: _format(x[0], x[1], x[2:]),
sorted(errors, key=lambda x: x[0]))) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_getArrays; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:items; 5, identifier:attr; 6, identifier:defaultValue; 7, block; 7, 8; 7, 21; 7, 43; 7, 67; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:arrays; 11, call; 11, 12; 11, 13; 12, identifier:dict; 13, argument_list; 13, 14; 14, list_comprehension; 14, 15; 14, 18; 15, tuple; 15, 16; 15, 17; 16, identifier:key; 17, list:[]; 18, for_in_clause; 18, 19; 18, 20; 19, identifier:key; 20, identifier:attr; 21, for_statement; 21, 22; 21, 23; 21, 24; 22, identifier:item; 23, identifier:items; 24, block; 24, 25; 25, for_statement; 25, 26; 25, 27; 25, 28; 26, identifier:key; 27, identifier:attr; 28, block; 28, 29; 29, expression_statement; 29, 30; 30, call; 30, 31; 30, 36; 31, attribute; 31, 32; 31, 35; 32, subscript; 32, 33; 32, 34; 33, identifier:arrays; 34, identifier:key; 35, identifier:append; 36, argument_list; 36, 37; 37, call; 37, 38; 37, 39; 38, identifier:getattr; 39, argument_list; 39, 40; 39, 41; 39, 42; 40, identifier:item; 41, identifier:key; 42, identifier:defaultValue; 43, for_statement; 43, 44; 43, 45; 43, 53; 44, identifier:key; 45, list_comprehension; 45, 46; 45, 47; 46, identifier:_; 47, for_in_clause; 47, 48; 47, 49; 48, identifier:_; 49, call; 49, 50; 49, 51; 50, identifier:viewkeys; 51, argument_list; 51, 52; 52, identifier:arrays; 53, block; 53, 54; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 59; 56, subscript; 56, 57; 56, 58; 57, identifier:arrays; 58, identifier:key; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:numpy; 62, identifier:array; 63, argument_list; 63, 64; 64, subscript; 64, 65; 64, 66; 65, identifier:arrays; 66, identifier:key; 67, return_statement; 67, 68; 68, identifier:arrays | def _getArrays(items, attr, defaultValue):
arrays = dict([(key, []) for key in attr])
for item in items:
for key in attr:
arrays[key].append(getattr(item, key, defaultValue))
for key in [_ for _ in viewkeys(arrays)]:
arrays[key] = numpy.array(arrays[key])
return arrays |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_log_board_ports; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:ports; 6, block; 6, 7; 6, 26; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:ports; 10, call; 10, 11; 10, 12; 11, identifier:sorted; 12, argument_list; 12, 13; 12, 14; 13, identifier:ports; 14, keyword_argument; 14, 15; 14, 16; 15, identifier:key; 16, lambda; 16, 17; 16, 19; 17, lambda_parameters; 17, 18; 18, identifier:port; 19, tuple; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:port; 22, identifier:tile_id; 23, attribute; 23, 24; 23, 25; 24, identifier:port; 25, identifier:direction; 26, expression_statement; 26, 27; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:_logln; 31, argument_list; 31, 32; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, string:'ports: {0}'; 35, identifier:format; 36, argument_list; 36, 37; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, string:' '; 40, identifier:join; 41, generator_expression; 41, 42; 41, 58; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, string:'{}({} {})'; 45, identifier:format; 46, argument_list; 46, 47; 46, 52; 46, 55; 47, attribute; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:p; 50, identifier:type; 51, identifier:value; 52, attribute; 52, 53; 52, 54; 53, identifier:p; 54, identifier:tile_id; 55, attribute; 55, 56; 55, 57; 56, identifier:p; 57, identifier:direction; 58, for_in_clause; 58, 59; 58, 60; 59, identifier:p; 60, identifier:ports | def _log_board_ports(self, ports):
ports = sorted(ports, key=lambda port: (port.tile_id, port.direction))
self._logln('ports: {0}'.format(' '.join('{}({} {})'.format(p.type.value, p.tile_id, p.direction)
for p in ports))) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:sort; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:attr; 6, block; 6, 7; 6, 26; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:self; 11, identifier:entries; 12, call; 12, 13; 12, 25; 13, attribute; 13, 14; 13, 24; 14, call; 14, 15; 14, 16; 15, identifier:Sorter; 16, argument_list; 16, 17; 16, 20; 16, 23; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:entries; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:category; 23, identifier:attr; 24, identifier:sort_entries; 25, argument_list; 26, return_statement; 26, 27; 27, identifier:self | def sort(self, attr):
self.entries = Sorter(self.entries, self.category, attr).sort_entries()
return self |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_visit; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:L; 6, identifier:marked; 7, identifier:tempmarked; 8, block; 8, 9; 8, 14; 8, 24; 9, assert_statement; 9, 10; 10, not_operator; 10, 11; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:is_pseudo; 14, if_statement; 14, 15; 14, 18; 15, comparison_operator:in; 15, 16; 15, 17; 16, identifier:self; 17, identifier:tempmarked; 18, block; 18, 19; 19, raise_statement; 19, 20; 20, call; 20, 21; 20, 22; 21, identifier:Exception; 22, argument_list; 22, 23; 23, string:'feature graph is cyclic'; 24, if_statement; 24, 25; 24, 28; 25, comparison_operator:not; 25, 26; 25, 27; 26, identifier:self; 27, identifier:marked; 28, block; 28, 29; 28, 35; 28, 41; 28, 64; 28, 83; 28, 104; 28, 110; 28, 114; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 34; 31, subscript; 31, 32; 31, 33; 32, identifier:tempmarked; 33, identifier:self; 34, True; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:features; 38, call; 38, 39; 38, 40; 39, identifier:list; 40, argument_list; 41, if_statement; 41, 42; 41, 51; 42, boolean_operator:and; 42, 43; 42, 48; 43, comparison_operator:is; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:siblings; 47, None; 48, attribute; 48, 49; 48, 50; 49, identifier:self; 50, identifier:is_toplevel; 51, block; 51, 52; 52, expression_statement; 52, 53; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:features; 56, identifier:extend; 57, argument_list; 57, 58; 58, call; 58, 59; 58, 60; 59, identifier:reversed; 60, argument_list; 60, 61; 61, attribute; 61, 62; 61, 63; 62, identifier:self; 63, identifier:siblings; 64, if_statement; 64, 65; 64, 70; 65, comparison_operator:is; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:children; 69, None; 70, block; 70, 71; 71, expression_statement; 71, 72; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:features; 75, identifier:extend; 76, argument_list; 76, 77; 77, call; 77, 78; 77, 79; 78, identifier:reversed; 79, argument_list; 79, 80; 80, attribute; 80, 81; 80, 82; 81, identifier:self; 82, identifier:children; 83, if_statement; 83, 84; 83, 90; 84, comparison_operator:>; 84, 85; 84, 89; 85, call; 85, 86; 85, 87; 86, identifier:len; 87, argument_list; 87, 88; 88, identifier:features; 89, integer:0; 90, block; 90, 91; 91, for_statement; 91, 92; 91, 93; 91, 94; 92, identifier:feature; 93, identifier:features; 94, block; 94, 95; 95, expression_statement; 95, 96; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:feature; 99, identifier:_visit; 100, argument_list; 100, 101; 100, 102; 100, 103; 101, identifier:L; 102, identifier:marked; 103, identifier:tempmarked; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 109; 106, subscript; 106, 107; 106, 108; 107, identifier:marked; 108, identifier:self; 109, True; 110, delete_statement; 110, 111; 111, subscript; 111, 112; 111, 113; 112, identifier:tempmarked; 113, identifier:self; 114, expression_statement; 114, 115; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:L; 118, identifier:insert; 119, argument_list; 119, 120; 119, 121; 120, integer:0; 121, identifier:self | def _visit(self, L, marked, tempmarked):
assert not self.is_pseudo
if self in tempmarked:
raise Exception('feature graph is cyclic')
if self not in marked:
tempmarked[self] = True
features = list()
if self.siblings is not None and self.is_toplevel:
features.extend(reversed(self.siblings))
if self.children is not None:
features.extend(reversed(self.children))
if len(features) > 0:
for feature in features:
feature._visit(L, marked, tempmarked)
marked[self] = True
del tempmarked[self]
L.insert(0, self) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:pseudoify; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 10; 5, 14; 5, 25; 5, 31; 5, 49; 5, 67; 5, 74; 5, 80; 5, 88; 5, 96; 5, 104; 5, 123; 5, 134; 5, 145; 6, assert_statement; 6, 7; 7, attribute; 7, 8; 7, 9; 8, identifier:self; 9, identifier:is_toplevel; 10, assert_statement; 10, 11; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:is_multi; 14, assert_statement; 14, 15; 15, comparison_operator:>; 15, 16; 15, 24; 16, call; 16, 17; 16, 18; 17, identifier:len; 18, argument_list; 18, 19; 19, attribute; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:multi_rep; 23, identifier:siblings; 24, integer:0; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:rep; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:multi_rep; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:start; 34, call; 34, 35; 34, 36; 35, identifier:min; 36, argument_list; 36, 37; 37, list_comprehension; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:s; 40, identifier:start; 41, for_in_clause; 41, 42; 41, 43; 42, identifier:s; 43, binary_operator:+; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:rep; 46, identifier:siblings; 47, list:[rep]; 47, 48; 48, identifier:rep; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:end; 52, call; 52, 53; 52, 54; 53, identifier:max; 54, argument_list; 54, 55; 55, list_comprehension; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:s; 58, identifier:end; 59, for_in_clause; 59, 60; 59, 61; 60, identifier:s; 61, binary_operator:+; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:rep; 64, identifier:siblings; 65, list:[rep]; 65, 66; 66, identifier:rep; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:parent; 70, call; 70, 71; 70, 72; 71, identifier:Feature; 72, argument_list; 72, 73; 73, None; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:parent; 78, identifier:_pseudo; 79, True; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:parent; 84, identifier:_seqid; 85, attribute; 85, 86; 85, 87; 86, identifier:self; 87, identifier:_seqid; 88, expression_statement; 88, 89; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:parent; 92, identifier:set_coord; 93, argument_list; 93, 94; 93, 95; 94, identifier:start; 95, identifier:end; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:parent; 100, identifier:_strand; 101, attribute; 101, 102; 101, 103; 102, identifier:self; 103, identifier:_strand; 104, for_statement; 104, 105; 104, 106; 104, 112; 105, identifier:sibling; 106, binary_operator:+; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:rep; 109, identifier:siblings; 110, list:[rep]; 110, 111; 111, identifier:rep; 112, block; 112, 113; 113, expression_statement; 113, 114; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:parent; 117, identifier:add_child; 118, argument_list; 118, 119; 118, 120; 119, identifier:sibling; 120, keyword_argument; 120, 121; 120, 122; 121, identifier:rangecheck; 122, True; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:parent; 127, identifier:children; 128, call; 128, 129; 128, 130; 129, identifier:sorted; 130, argument_list; 130, 131; 131, attribute; 131, 132; 131, 133; 132, identifier:parent; 133, identifier:children; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:rep; 138, identifier:siblings; 139, call; 139, 140; 139, 141; 140, identifier:sorted; 141, argument_list; 141, 142; 142, attribute; 142, 143; 142, 144; 143, identifier:rep; 144, identifier:siblings; 145, return_statement; 145, 146; 146, identifier:parent | def pseudoify(self):
assert self.is_toplevel
assert self.is_multi
assert len(self.multi_rep.siblings) > 0
rep = self.multi_rep
start = min([s.start for s in rep.siblings + [rep]])
end = max([s.end for s in rep.siblings + [rep]])
parent = Feature(None)
parent._pseudo = True
parent._seqid = self._seqid
parent.set_coord(start, end)
parent._strand = self._strand
for sibling in rep.siblings + [rep]:
parent.add_child(sibling, rangecheck=True)
parent.children = sorted(parent.children)
rep.siblings = sorted(rep.siblings)
return parent |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:attribute_crawl; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:key; 6, block; 6, 7; 6, 13; 6, 44; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:union; 10, call; 10, 11; 10, 12; 11, identifier:set; 12, argument_list; 13, for_statement; 13, 14; 13, 15; 13, 16; 14, identifier:feature; 15, identifier:self; 16, block; 16, 17; 16, 29; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:values; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:feature; 23, identifier:get_attribute; 24, argument_list; 24, 25; 24, 26; 25, identifier:key; 26, keyword_argument; 26, 27; 26, 28; 27, identifier:as_list; 28, True; 29, if_statement; 29, 30; 29, 33; 30, comparison_operator:is; 30, 31; 30, 32; 31, identifier:values; 32, None; 33, block; 33, 34; 34, expression_statement; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:union; 38, identifier:update; 39, argument_list; 39, 40; 40, call; 40, 41; 40, 42; 41, identifier:set; 42, argument_list; 42, 43; 43, identifier:values; 44, return_statement; 44, 45; 45, identifier:union | def attribute_crawl(self, key):
union = set()
for feature in self:
values = feature.get_attribute(key, as_list=True)
if values is not None:
union.update(set(values))
return union |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_findSamesetProteins; 3, parameters; 3, 4; 3, 5; 4, identifier:protToPeps; 5, default_parameter; 5, 6; 5, 7; 6, identifier:proteins; 7, None; 8, block; 8, 9; 8, 21; 8, 28; 8, 53; 8, 59; 8, 87; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:proteins; 12, conditional_expression:if; 12, 13; 12, 17; 12, 20; 13, call; 13, 14; 13, 15; 14, identifier:viewkeys; 15, argument_list; 15, 16; 16, identifier:protToPeps; 17, comparison_operator:is; 17, 18; 17, 19; 18, identifier:proteins; 19, None; 20, identifier:proteins; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:equalEvidence; 24, call; 24, 25; 24, 26; 25, identifier:ddict; 26, argument_list; 26, 27; 27, identifier:set; 28, for_statement; 28, 29; 28, 30; 28, 31; 29, identifier:protein; 30, identifier:proteins; 31, block; 31, 32; 31, 38; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:peptides; 35, subscript; 35, 36; 35, 37; 36, identifier:protToPeps; 37, identifier:protein; 38, expression_statement; 38, 39; 39, call; 39, 40; 39, 51; 40, attribute; 40, 41; 40, 50; 41, subscript; 41, 42; 41, 43; 42, identifier:equalEvidence; 43, call; 43, 44; 43, 45; 44, identifier:tuple; 45, argument_list; 45, 46; 46, call; 46, 47; 46, 48; 47, identifier:sorted; 48, argument_list; 48, 49; 49, identifier:peptides; 50, identifier:add; 51, argument_list; 51, 52; 52, identifier:protein; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:equalProteins; 56, call; 56, 57; 56, 58; 57, identifier:list; 58, argument_list; 59, for_statement; 59, 60; 59, 61; 59, 65; 60, identifier:proteins; 61, call; 61, 62; 61, 63; 62, identifier:viewvalues; 63, argument_list; 63, 64; 64, identifier:equalEvidence; 65, block; 65, 66; 66, if_statement; 66, 67; 66, 73; 67, comparison_operator:>; 67, 68; 67, 72; 68, call; 68, 69; 68, 70; 69, identifier:len; 70, argument_list; 70, 71; 71, identifier:proteins; 72, integer:1; 73, block; 73, 74; 74, expression_statement; 74, 75; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:equalProteins; 78, identifier:append; 79, argument_list; 79, 80; 80, call; 80, 81; 80, 82; 81, identifier:tuple; 82, argument_list; 82, 83; 83, call; 83, 84; 83, 85; 84, identifier:sorted; 85, argument_list; 85, 86; 86, identifier:proteins; 87, return_statement; 87, 88; 88, identifier:equalProteins | def _findSamesetProteins(protToPeps, proteins=None):
proteins = viewkeys(protToPeps) if proteins is None else proteins
equalEvidence = ddict(set)
for protein in proteins:
peptides = protToPeps[protein]
equalEvidence[tuple(sorted(peptides))].add(protein)
equalProteins = list()
for proteins in viewvalues(equalEvidence):
if len(proteins) > 1:
equalProteins.append(tuple(sorted(proteins)))
return equalProteins |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.