sequence
stringlengths 492
15.9k
| code
stringlengths 75
8.58k
|
---|---|
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:get_keys; 3, parameters; 3, 4; 3, 5; 4, identifier:data_list; 5, default_parameter; 5, 6; 5, 7; 6, identifier:leading_columns; 7, identifier:LEADING_COLUMNS; 8, block; 8, 9; 8, 32; 8, 36; 8, 60; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:all_keys; 12, call; 12, 13; 12, 18; 13, attribute; 13, 14; 13, 17; 14, call; 14, 15; 14, 16; 15, identifier:set; 16, argument_list; 17, identifier:union; 18, argument_list; 18, 19; 19, list_splat; 19, 20; 20, generator_expression; 20, 21; 20, 29; 21, call; 21, 22; 21, 23; 22, identifier:list; 23, argument_list; 23, 24; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:d; 27, identifier:keys; 28, argument_list; 29, for_in_clause; 29, 30; 29, 31; 30, identifier:d; 31, identifier:data_list; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:leading_keys; 35, list:[]; 36, for_statement; 36, 37; 36, 38; 36, 39; 37, identifier:key; 38, identifier:leading_columns; 39, block; 39, 40; 39, 46; 39, 53; 40, if_statement; 40, 41; 40, 44; 41, comparison_operator:not; 41, 42; 41, 43; 42, identifier:key; 43, identifier:all_keys; 44, block; 44, 45; 45, continue_statement; 46, expression_statement; 46, 47; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:leading_keys; 50, identifier:append; 51, argument_list; 51, 52; 52, identifier:key; 53, expression_statement; 53, 54; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:all_keys; 57, identifier:remove; 58, argument_list; 58, 59; 59, identifier:key; 60, return_statement; 60, 61; 61, binary_operator:+; 61, 62; 61, 63; 62, identifier:leading_keys; 63, call; 63, 64; 63, 65; 64, identifier:sorted; 65, argument_list; 65, 66; 66, identifier:all_keys | def get_keys(data_list, leading_columns=LEADING_COLUMNS):
all_keys = set().union(*(list(d.keys()) for d in data_list))
leading_keys = []
for key in leading_columns:
if key not in all_keys:
continue
leading_keys.append(key)
all_keys.remove(key)
return leading_keys + sorted(all_keys) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:to_file; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:self; 5, identifier:f; 6, default_parameter; 6, 7; 6, 8; 7, identifier:sorted; 8, True; 9, default_parameter; 9, 10; 9, 11; 10, identifier:relativize; 11, True; 12, default_parameter; 12, 13; 12, 14; 13, identifier:nl; 14, None; 15, block; 15, 16; 15, 33; 15, 48; 15, 73; 16, if_statement; 16, 17; 16, 22; 16, 27; 17, comparison_operator:>=; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:sys; 20, identifier:hexversion; 21, integer:0x02030000; 22, block; 22, 23; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:str_type; 26, identifier:basestring; 27, else_clause; 27, 28; 28, block; 28, 29; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:str_type; 32, identifier:str; 33, if_statement; 33, 34; 33, 37; 33, 42; 34, comparison_operator:is; 34, 35; 34, 36; 35, identifier:nl; 36, None; 37, block; 37, 38; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:opts; 41, string:'w'; 42, else_clause; 42, 43; 43, block; 43, 44; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:opts; 47, string:'wb'; 48, if_statement; 48, 49; 48, 54; 48, 67; 49, call; 49, 50; 49, 51; 50, identifier:isinstance; 51, argument_list; 51, 52; 51, 53; 52, identifier:f; 53, identifier:str_type; 54, block; 54, 55; 54, 63; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:f; 58, call; 58, 59; 58, 60; 59, identifier:file; 60, argument_list; 60, 61; 60, 62; 61, identifier:f; 62, identifier:opts; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:want_close; 66, True; 67, else_clause; 67, 68; 68, block; 68, 69; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:want_close; 72, False; 73, try_statement; 73, 74; 73, 150; 74, block; 74, 75; 74, 102; 75, if_statement; 75, 76; 75, 77; 75, 92; 76, identifier:sorted; 77, block; 77, 78; 77, 86; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:names; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:self; 84, identifier:keys; 85, argument_list; 86, expression_statement; 86, 87; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:names; 90, identifier:sort; 91, argument_list; 92, else_clause; 92, 93; 93, block; 93, 94; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:names; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:self; 100, identifier:iterkeys; 101, argument_list; 102, for_statement; 102, 103; 102, 104; 102, 105; 103, identifier:n; 104, identifier:names; 105, block; 105, 106; 105, 125; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:l; 109, call; 109, 110; 109, 115; 110, attribute; 110, 111; 110, 114; 111, subscript; 111, 112; 111, 113; 112, identifier:self; 113, identifier:n; 114, identifier:to_text; 115, argument_list; 115, 116; 115, 117; 115, 122; 116, identifier:n; 117, keyword_argument; 117, 118; 117, 119; 118, identifier:origin; 119, attribute; 119, 120; 119, 121; 120, identifier:self; 121, identifier:origin; 122, keyword_argument; 122, 123; 122, 124; 123, identifier:relativize; 124, identifier:relativize; 125, if_statement; 125, 126; 125, 129; 125, 134; 126, comparison_operator:is; 126, 127; 126, 128; 127, identifier:nl; 128, None; 129, block; 129, 130; 130, print_statement; 130, 131; 130, 133; 131, chevron; 131, 132; 132, identifier:f; 133, identifier:l; 134, else_clause; 134, 135; 135, block; 135, 136; 135, 143; 136, expression_statement; 136, 137; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:f; 140, identifier:write; 141, argument_list; 141, 142; 142, identifier:l; 143, expression_statement; 143, 144; 144, call; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:f; 147, identifier:write; 148, argument_list; 148, 149; 149, identifier:nl; 150, finally_clause; 150, 151; 151, block; 151, 152; 152, if_statement; 152, 153; 152, 154; 153, identifier:want_close; 154, block; 154, 155; 155, expression_statement; 155, 156; 156, call; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:f; 159, identifier:close; 160, argument_list | def to_file(self, f, sorted=True, relativize=True, nl=None):
if sys.hexversion >= 0x02030000:
str_type = basestring
else:
str_type = str
if nl is None:
opts = 'w'
else:
opts = 'wb'
if isinstance(f, str_type):
f = file(f, opts)
want_close = True
else:
want_close = False
try:
if sorted:
names = self.keys()
names.sort()
else:
names = self.iterkeys()
for n in names:
l = self[n].to_text(n, origin=self.origin,
relativize=relativize)
if nl is None:
print >> f, l
else:
f.write(l)
f.write(nl)
finally:
if want_close:
f.close() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_sorted_keys; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:keys; 6, block; 6, 7; 6, 11; 6, 31; 6, 76; 6, 105; 6, 125; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:sorted_keys; 10, list:[]; 11, if_statement; 11, 12; 11, 23; 12, boolean_operator:and; 12, 13; 12, 17; 13, parenthesized_expression; 13, 14; 14, comparison_operator:in; 14, 15; 14, 16; 15, string:'epoch'; 16, identifier:keys; 17, parenthesized_expression; 17, 18; 18, comparison_operator:not; 18, 19; 18, 20; 19, string:'epoch'; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:keys_ignored_; 23, block; 23, 24; 24, expression_statement; 24, 25; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:sorted_keys; 28, identifier:append; 29, argument_list; 29, 30; 30, string:'epoch'; 31, for_statement; 31, 32; 31, 33; 31, 37; 32, identifier:key; 33, call; 33, 34; 33, 35; 34, identifier:sorted; 35, argument_list; 35, 36; 36, identifier:keys; 37, block; 37, 38; 38, if_statement; 38, 39; 38, 68; 39, not_operator; 39, 40; 40, parenthesized_expression; 40, 41; 41, boolean_operator:or; 41, 42; 41, 62; 42, boolean_operator:or; 42, 43; 42, 56; 43, boolean_operator:or; 43, 44; 43, 50; 44, parenthesized_expression; 44, 45; 45, comparison_operator:in; 45, 46; 45, 47; 46, identifier:key; 47, tuple; 47, 48; 47, 49; 48, string:'epoch'; 49, string:'dur'; 50, parenthesized_expression; 50, 51; 51, comparison_operator:in; 51, 52; 51, 53; 52, identifier:key; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:keys_ignored_; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:key; 59, identifier:endswith; 60, argument_list; 60, 61; 61, string:'_best'; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:key; 65, identifier:startswith; 66, argument_list; 66, 67; 67, string:'event_'; 68, block; 68, 69; 69, expression_statement; 69, 70; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:sorted_keys; 73, identifier:append; 74, argument_list; 74, 75; 75, identifier:key; 76, for_statement; 76, 77; 76, 78; 76, 82; 77, identifier:key; 78, call; 78, 79; 78, 80; 79, identifier:sorted; 80, argument_list; 80, 81; 81, identifier:keys; 82, block; 82, 83; 83, if_statement; 83, 84; 83, 97; 84, boolean_operator:and; 84, 85; 84, 91; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:key; 88, identifier:startswith; 89, argument_list; 89, 90; 90, string:'event_'; 91, parenthesized_expression; 91, 92; 92, comparison_operator:not; 92, 93; 92, 94; 93, identifier:key; 94, attribute; 94, 95; 94, 96; 95, identifier:self; 96, identifier:keys_ignored_; 97, block; 97, 98; 98, expression_statement; 98, 99; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:sorted_keys; 102, identifier:append; 103, argument_list; 103, 104; 104, identifier:key; 105, if_statement; 105, 106; 105, 117; 106, boolean_operator:and; 106, 107; 106, 111; 107, parenthesized_expression; 107, 108; 108, comparison_operator:in; 108, 109; 108, 110; 109, string:'dur'; 110, identifier:keys; 111, parenthesized_expression; 111, 112; 112, comparison_operator:not; 112, 113; 112, 114; 113, string:'dur'; 114, attribute; 114, 115; 114, 116; 115, identifier:self; 116, identifier:keys_ignored_; 117, block; 117, 118; 118, expression_statement; 118, 119; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:sorted_keys; 122, identifier:append; 123, argument_list; 123, 124; 124, string:'dur'; 125, return_statement; 125, 126; 126, identifier:sorted_keys | def _sorted_keys(self, keys):
sorted_keys = []
if ('epoch' in keys) and ('epoch' not in self.keys_ignored_):
sorted_keys.append('epoch')
for key in sorted(keys):
if not (
(key in ('epoch', 'dur')) or
(key in self.keys_ignored_) or
key.endswith('_best') or
key.startswith('event_')
):
sorted_keys.append(key)
for key in sorted(keys):
if key.startswith('event_') and (key not in self.keys_ignored_):
sorted_keys.append(key)
if ('dur' in keys) and ('dur' not in self.keys_ignored_):
sorted_keys.append('dur')
return sorted_keys |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:sort_values; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:expr; 5, identifier:by; 6, default_parameter; 6, 7; 6, 8; 7, identifier:ascending; 8, True; 9, block; 9, 10; 9, 23; 9, 42; 10, if_statement; 10, 11; 10, 17; 11, not_operator; 11, 12; 12, call; 12, 13; 12, 14; 13, identifier:isinstance; 14, argument_list; 14, 15; 14, 16; 15, identifier:by; 16, identifier:list; 17, block; 17, 18; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:by; 21, list:[by, ]; 21, 22; 22, identifier:by; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:by; 26, list_comprehension; 26, 27; 26, 39; 27, conditional_expression:if; 27, 28; 27, 32; 27, 38; 28, call; 28, 29; 28, 30; 29, identifier:it; 30, argument_list; 30, 31; 31, identifier:expr; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:inspect; 35, identifier:isfunction; 36, argument_list; 36, 37; 37, identifier:it; 38, identifier:it; 39, for_in_clause; 39, 40; 39, 41; 40, identifier:it; 41, identifier:by; 42, return_statement; 42, 43; 43, call; 43, 44; 43, 45; 44, identifier:SortedCollectionExpr; 45, argument_list; 45, 46; 45, 47; 45, 50; 45, 53; 46, identifier:expr; 47, keyword_argument; 47, 48; 47, 49; 48, identifier:_sorted_fields; 49, identifier:by; 50, keyword_argument; 50, 51; 50, 52; 51, identifier:_ascending; 52, identifier:ascending; 53, keyword_argument; 53, 54; 53, 55; 54, identifier:_schema; 55, attribute; 55, 56; 55, 57; 56, identifier:expr; 57, identifier:_schema | def sort_values(expr, by, ascending=True):
if not isinstance(by, list):
by = [by, ]
by = [it(expr) if inspect.isfunction(it) else it for it in by]
return SortedCollectionExpr(expr, _sorted_fields=by, _ascending=ascending,
_schema=expr._schema) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:reshuffle; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:expr; 5, default_parameter; 5, 6; 5, 7; 6, identifier:by; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:sort; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:ascending; 13, True; 14, block; 14, 15; 14, 23; 14, 32; 14, 47; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:by; 18, boolean_operator:or; 18, 19; 18, 20; 19, identifier:by; 20, call; 20, 21; 20, 22; 21, identifier:RandomScalar; 22, argument_list; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:grouped; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:expr; 29, identifier:groupby; 30, argument_list; 30, 31; 31, identifier:by; 32, if_statement; 32, 33; 32, 34; 33, identifier:sort; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:grouped; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:grouped; 41, identifier:sort_values; 42, argument_list; 42, 43; 42, 44; 43, identifier:sort; 44, keyword_argument; 44, 45; 44, 46; 45, identifier:ascending; 46, identifier:ascending; 47, return_statement; 47, 48; 48, call; 48, 49; 48, 50; 49, identifier:ReshuffledCollectionExpr; 50, argument_list; 50, 51; 50, 54; 51, keyword_argument; 51, 52; 51, 53; 52, identifier:_input; 53, identifier:grouped; 54, keyword_argument; 54, 55; 54, 56; 55, identifier:_schema; 56, attribute; 56, 57; 56, 58; 57, identifier:expr; 58, identifier:_schema | def reshuffle(expr, by=None, sort=None, ascending=True):
by = by or RandomScalar()
grouped = expr.groupby(by)
if sort:
grouped = grouped.sort_values(sort, ascending=ascending)
return ReshuffledCollectionExpr(_input=grouped, _schema=expr._schema) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:cumsum; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:expr; 5, default_parameter; 5, 6; 5, 7; 6, identifier:sort; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:ascending; 10, True; 11, default_parameter; 11, 12; 11, 13; 12, identifier:unique; 13, False; 14, default_parameter; 14, 15; 14, 16; 15, identifier:preceding; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:following; 19, None; 20, block; 20, 21; 20, 44; 21, if_statement; 21, 22; 21, 29; 21, 36; 22, comparison_operator:==; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:expr; 25, identifier:_data_type; 26, attribute; 26, 27; 26, 28; 27, identifier:types; 28, identifier:boolean; 29, block; 29, 30; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:output_type; 33, attribute; 33, 34; 33, 35; 34, identifier:types; 35, identifier:int64; 36, else_clause; 36, 37; 37, block; 37, 38; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:output_type; 41, attribute; 41, 42; 41, 43; 42, identifier:expr; 43, identifier:_data_type; 44, return_statement; 44, 45; 45, call; 45, 46; 45, 47; 46, identifier:_cumulative_op; 47, argument_list; 47, 48; 47, 49; 47, 50; 47, 53; 47, 56; 47, 59; 47, 62; 47, 65; 48, identifier:expr; 49, identifier:CumSum; 50, keyword_argument; 50, 51; 50, 52; 51, identifier:sort; 52, identifier:sort; 53, keyword_argument; 53, 54; 53, 55; 54, identifier:ascending; 55, identifier:ascending; 56, keyword_argument; 56, 57; 56, 58; 57, identifier:unique; 58, identifier:unique; 59, keyword_argument; 59, 60; 59, 61; 60, identifier:preceding; 61, identifier:preceding; 62, keyword_argument; 62, 63; 62, 64; 63, identifier:following; 64, identifier:following; 65, keyword_argument; 65, 66; 65, 67; 66, identifier:data_type; 67, identifier:output_type | def cumsum(expr, sort=None, ascending=True, unique=False,
preceding=None, following=None):
if expr._data_type == types.boolean:
output_type = types.int64
else:
output_type = expr._data_type
return _cumulative_op(expr, CumSum, sort=sort, ascending=ascending,
unique=unique, preceding=preceding,
following=following, data_type=output_type) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:cummax; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:expr; 5, default_parameter; 5, 6; 5, 7; 6, identifier:sort; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:ascending; 10, True; 11, default_parameter; 11, 12; 11, 13; 12, identifier:unique; 13, False; 14, default_parameter; 14, 15; 14, 16; 15, identifier:preceding; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:following; 19, None; 20, block; 20, 21; 21, return_statement; 21, 22; 22, call; 22, 23; 22, 24; 23, identifier:_cumulative_op; 24, argument_list; 24, 25; 24, 26; 24, 27; 24, 30; 24, 33; 24, 36; 24, 39; 25, identifier:expr; 26, identifier:CumMax; 27, keyword_argument; 27, 28; 27, 29; 28, identifier:sort; 29, identifier:sort; 30, keyword_argument; 30, 31; 30, 32; 31, identifier:ascending; 32, identifier:ascending; 33, keyword_argument; 33, 34; 33, 35; 34, identifier:unique; 35, identifier:unique; 36, keyword_argument; 36, 37; 36, 38; 37, identifier:preceding; 38, identifier:preceding; 39, keyword_argument; 39, 40; 39, 41; 40, identifier:following; 41, identifier:following | def cummax(expr, sort=None, ascending=True, unique=False,
preceding=None, following=None):
return _cumulative_op(expr, CumMax, sort=sort, ascending=ascending,
unique=unique, preceding=preceding,
following=following) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:cummin; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:expr; 5, default_parameter; 5, 6; 5, 7; 6, identifier:sort; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:ascending; 10, True; 11, default_parameter; 11, 12; 11, 13; 12, identifier:unique; 13, False; 14, default_parameter; 14, 15; 14, 16; 15, identifier:preceding; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:following; 19, None; 20, block; 20, 21; 21, return_statement; 21, 22; 22, call; 22, 23; 22, 24; 23, identifier:_cumulative_op; 24, argument_list; 24, 25; 24, 26; 24, 27; 24, 30; 24, 33; 24, 36; 24, 39; 25, identifier:expr; 26, identifier:CumMin; 27, keyword_argument; 27, 28; 27, 29; 28, identifier:sort; 29, identifier:sort; 30, keyword_argument; 30, 31; 30, 32; 31, identifier:ascending; 32, identifier:ascending; 33, keyword_argument; 33, 34; 33, 35; 34, identifier:unique; 35, identifier:unique; 36, keyword_argument; 36, 37; 36, 38; 37, identifier:preceding; 38, identifier:preceding; 39, keyword_argument; 39, 40; 39, 41; 40, identifier:following; 41, identifier:following | def cummin(expr, sort=None, ascending=True, unique=False,
preceding=None, following=None):
return _cumulative_op(expr, CumMin, sort=sort, ascending=ascending,
unique=unique, preceding=preceding,
following=following) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:cummean; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:expr; 5, default_parameter; 5, 6; 5, 7; 6, identifier:sort; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:ascending; 10, True; 11, default_parameter; 11, 12; 11, 13; 12, identifier:unique; 13, False; 14, default_parameter; 14, 15; 14, 16; 15, identifier:preceding; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:following; 19, None; 20, block; 20, 21; 20, 28; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:data_type; 24, call; 24, 25; 24, 26; 25, identifier:_stats_type; 26, argument_list; 26, 27; 27, identifier:expr; 28, return_statement; 28, 29; 29, call; 29, 30; 29, 31; 30, identifier:_cumulative_op; 31, argument_list; 31, 32; 31, 33; 31, 34; 31, 37; 31, 40; 31, 43; 31, 46; 31, 49; 32, identifier:expr; 33, identifier:CumMean; 34, keyword_argument; 34, 35; 34, 36; 35, identifier:sort; 36, identifier:sort; 37, keyword_argument; 37, 38; 37, 39; 38, identifier:ascending; 39, identifier:ascending; 40, keyword_argument; 40, 41; 40, 42; 41, identifier:unique; 42, identifier:unique; 43, keyword_argument; 43, 44; 43, 45; 44, identifier:preceding; 45, identifier:preceding; 46, keyword_argument; 46, 47; 46, 48; 47, identifier:following; 48, identifier:following; 49, keyword_argument; 49, 50; 49, 51; 50, identifier:data_type; 51, identifier:data_type | def cummean(expr, sort=None, ascending=True, unique=False,
preceding=None, following=None):
data_type = _stats_type(expr)
return _cumulative_op(expr, CumMean, sort=sort, ascending=ascending,
unique=unique, preceding=preceding,
following=following, data_type=data_type) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:cummedian; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:expr; 5, default_parameter; 5, 6; 5, 7; 6, identifier:sort; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:ascending; 10, True; 11, default_parameter; 11, 12; 11, 13; 12, identifier:unique; 13, False; 14, default_parameter; 14, 15; 14, 16; 15, identifier:preceding; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:following; 19, None; 20, block; 20, 21; 20, 28; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:data_type; 24, call; 24, 25; 24, 26; 25, identifier:_stats_type; 26, argument_list; 26, 27; 27, identifier:expr; 28, return_statement; 28, 29; 29, call; 29, 30; 29, 31; 30, identifier:_cumulative_op; 31, argument_list; 31, 32; 31, 33; 31, 34; 31, 37; 31, 40; 31, 43; 31, 46; 31, 49; 32, identifier:expr; 33, identifier:CumMedian; 34, keyword_argument; 34, 35; 34, 36; 35, identifier:sort; 36, identifier:sort; 37, keyword_argument; 37, 38; 37, 39; 38, identifier:ascending; 39, identifier:ascending; 40, keyword_argument; 40, 41; 40, 42; 41, identifier:unique; 42, identifier:unique; 43, keyword_argument; 43, 44; 43, 45; 44, identifier:preceding; 45, identifier:preceding; 46, keyword_argument; 46, 47; 46, 48; 47, identifier:following; 48, identifier:following; 49, keyword_argument; 49, 50; 49, 51; 50, identifier:data_type; 51, identifier:data_type | def cummedian(expr, sort=None, ascending=True, unique=False,
preceding=None, following=None):
data_type = _stats_type(expr)
return _cumulative_op(expr, CumMedian, sort=sort, ascending=ascending,
unique=unique, preceding=preceding,
following=following, data_type=data_type) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:cumcount; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:expr; 5, default_parameter; 5, 6; 5, 7; 6, identifier:sort; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:ascending; 10, True; 11, default_parameter; 11, 12; 11, 13; 12, identifier:unique; 13, False; 14, default_parameter; 14, 15; 14, 16; 15, identifier:preceding; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:following; 19, None; 20, block; 20, 21; 20, 27; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:data_type; 24, attribute; 24, 25; 24, 26; 25, identifier:types; 26, identifier:int64; 27, return_statement; 27, 28; 28, call; 28, 29; 28, 30; 29, identifier:_cumulative_op; 30, argument_list; 30, 31; 30, 32; 30, 33; 30, 36; 30, 39; 30, 42; 30, 45; 30, 48; 31, identifier:expr; 32, identifier:CumCount; 33, keyword_argument; 33, 34; 33, 35; 34, identifier:sort; 35, identifier:sort; 36, keyword_argument; 36, 37; 36, 38; 37, identifier:ascending; 38, identifier:ascending; 39, keyword_argument; 39, 40; 39, 41; 40, identifier:unique; 41, identifier:unique; 42, keyword_argument; 42, 43; 42, 44; 43, identifier:preceding; 44, identifier:preceding; 45, keyword_argument; 45, 46; 45, 47; 46, identifier:following; 47, identifier:following; 48, keyword_argument; 48, 49; 48, 50; 49, identifier:data_type; 50, identifier:data_type | def cumcount(expr, sort=None, ascending=True, unique=False,
preceding=None, following=None):
data_type = types.int64
return _cumulative_op(expr, CumCount, sort=sort, ascending=ascending,
unique=unique, preceding=preceding,
following=following, data_type=data_type) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:cumstd; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:expr; 5, default_parameter; 5, 6; 5, 7; 6, identifier:sort; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:ascending; 10, True; 11, default_parameter; 11, 12; 11, 13; 12, identifier:unique; 13, False; 14, default_parameter; 14, 15; 14, 16; 15, identifier:preceding; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:following; 19, None; 20, block; 20, 21; 20, 28; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:data_type; 24, call; 24, 25; 24, 26; 25, identifier:_stats_type; 26, argument_list; 26, 27; 27, identifier:expr; 28, return_statement; 28, 29; 29, call; 29, 30; 29, 31; 30, identifier:_cumulative_op; 31, argument_list; 31, 32; 31, 33; 31, 34; 31, 37; 31, 40; 31, 43; 31, 46; 31, 49; 32, identifier:expr; 33, identifier:CumStd; 34, keyword_argument; 34, 35; 34, 36; 35, identifier:sort; 36, identifier:sort; 37, keyword_argument; 37, 38; 37, 39; 38, identifier:ascending; 39, identifier:ascending; 40, keyword_argument; 40, 41; 40, 42; 41, identifier:unique; 42, identifier:unique; 43, keyword_argument; 43, 44; 43, 45; 44, identifier:preceding; 45, identifier:preceding; 46, keyword_argument; 46, 47; 46, 48; 47, identifier:following; 48, identifier:following; 49, keyword_argument; 49, 50; 49, 51; 50, identifier:data_type; 51, identifier:data_type | def cumstd(expr, sort=None, ascending=True, unique=False,
preceding=None, following=None):
data_type = _stats_type(expr)
return _cumulative_op(expr, CumStd, sort=sort, ascending=ascending,
unique=unique, preceding=preceding,
following=following, data_type=data_type) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:nth_value; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:expr; 5, identifier:nth; 6, default_parameter; 6, 7; 6, 8; 7, identifier:skip_nulls; 8, False; 9, default_parameter; 9, 10; 9, 11; 10, identifier:sort; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:ascending; 14, True; 15, block; 15, 16; 16, return_statement; 16, 17; 17, call; 17, 18; 17, 19; 18, identifier:_cumulative_op; 19, argument_list; 19, 20; 19, 21; 19, 22; 19, 27; 19, 30; 19, 33; 19, 36; 20, identifier:expr; 21, identifier:NthValue; 22, keyword_argument; 22, 23; 22, 24; 23, identifier:data_type; 24, attribute; 24, 25; 24, 26; 25, identifier:expr; 26, identifier:_data_type; 27, keyword_argument; 27, 28; 27, 29; 28, identifier:sort; 29, identifier:sort; 30, keyword_argument; 30, 31; 30, 32; 31, identifier:ascending; 32, identifier:ascending; 33, keyword_argument; 33, 34; 33, 35; 34, identifier:_nth; 35, identifier:nth; 36, keyword_argument; 36, 37; 36, 38; 37, identifier:_skip_nulls; 38, identifier:skip_nulls | def nth_value(expr, nth, skip_nulls=False, sort=None, ascending=True):
return _cumulative_op(expr, NthValue, data_type=expr._data_type, sort=sort,
ascending=ascending, _nth=nth, _skip_nulls=skip_nulls) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:rank; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:expr; 5, default_parameter; 5, 6; 5, 7; 6, identifier:sort; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:ascending; 10, True; 11, block; 11, 12; 12, return_statement; 12, 13; 13, call; 13, 14; 13, 15; 14, identifier:_rank_op; 15, argument_list; 15, 16; 15, 17; 15, 18; 15, 21; 15, 24; 16, identifier:expr; 17, identifier:Rank; 18, attribute; 18, 19; 18, 20; 19, identifier:types; 20, identifier:int64; 21, keyword_argument; 21, 22; 21, 23; 22, identifier:sort; 23, identifier:sort; 24, keyword_argument; 24, 25; 24, 26; 25, identifier:ascending; 26, identifier:ascending | def rank(expr, sort=None, ascending=True):
return _rank_op(expr, Rank, types.int64, sort=sort, ascending=ascending) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:dense_rank; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:expr; 5, default_parameter; 5, 6; 5, 7; 6, identifier:sort; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:ascending; 10, True; 11, block; 11, 12; 12, return_statement; 12, 13; 13, call; 13, 14; 13, 15; 14, identifier:_rank_op; 15, argument_list; 15, 16; 15, 17; 15, 18; 15, 21; 15, 24; 16, identifier:expr; 17, identifier:DenseRank; 18, attribute; 18, 19; 18, 20; 19, identifier:types; 20, identifier:int64; 21, keyword_argument; 21, 22; 21, 23; 22, identifier:sort; 23, identifier:sort; 24, keyword_argument; 24, 25; 24, 26; 25, identifier:ascending; 26, identifier:ascending | def dense_rank(expr, sort=None, ascending=True):
return _rank_op(expr, DenseRank, types.int64, sort=sort, ascending=ascending) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:percent_rank; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:expr; 5, default_parameter; 5, 6; 5, 7; 6, identifier:sort; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:ascending; 10, True; 11, block; 11, 12; 12, return_statement; 12, 13; 13, call; 13, 14; 13, 15; 14, identifier:_rank_op; 15, argument_list; 15, 16; 15, 17; 15, 18; 15, 21; 15, 24; 16, identifier:expr; 17, identifier:PercentRank; 18, attribute; 18, 19; 18, 20; 19, identifier:types; 20, identifier:float64; 21, keyword_argument; 21, 22; 21, 23; 22, identifier:sort; 23, identifier:sort; 24, keyword_argument; 24, 25; 24, 26; 25, identifier:ascending; 26, identifier:ascending | def percent_rank(expr, sort=None, ascending=True):
return _rank_op(expr, PercentRank, types.float64, sort=sort, ascending=ascending) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:row_number; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:expr; 5, default_parameter; 5, 6; 5, 7; 6, identifier:sort; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:ascending; 10, True; 11, block; 11, 12; 12, return_statement; 12, 13; 13, call; 13, 14; 13, 15; 14, identifier:_rank_op; 15, argument_list; 15, 16; 15, 17; 15, 18; 15, 21; 15, 24; 16, identifier:expr; 17, identifier:RowNumber; 18, attribute; 18, 19; 18, 20; 19, identifier:types; 20, identifier:int64; 21, keyword_argument; 21, 22; 21, 23; 22, identifier:sort; 23, identifier:sort; 24, keyword_argument; 24, 25; 24, 26; 25, identifier:ascending; 26, identifier:ascending | def row_number(expr, sort=None, ascending=True):
return _rank_op(expr, RowNumber, types.int64, sort=sort, ascending=ascending) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:qcut; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:expr; 5, identifier:bins; 6, default_parameter; 6, 7; 6, 8; 7, identifier:labels; 8, False; 9, default_parameter; 9, 10; 9, 11; 10, identifier:sort; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:ascending; 14, True; 15, block; 15, 16; 15, 28; 16, if_statement; 16, 17; 16, 22; 17, boolean_operator:or; 17, 18; 17, 21; 18, comparison_operator:is; 18, 19; 18, 20; 19, identifier:labels; 20, None; 21, identifier:labels; 22, block; 22, 23; 23, raise_statement; 23, 24; 24, call; 24, 25; 24, 26; 25, identifier:NotImplementedError; 26, argument_list; 26, 27; 27, string:'Showing bins or customizing labels not supported'; 28, return_statement; 28, 29; 29, call; 29, 30; 29, 31; 30, identifier:_rank_op; 31, argument_list; 31, 32; 31, 33; 31, 34; 31, 37; 31, 40; 31, 43; 32, identifier:expr; 33, identifier:QCut; 34, attribute; 34, 35; 34, 36; 35, identifier:types; 36, identifier:int64; 37, keyword_argument; 37, 38; 37, 39; 38, identifier:sort; 39, identifier:sort; 40, keyword_argument; 40, 41; 40, 42; 41, identifier:ascending; 42, identifier:ascending; 43, keyword_argument; 43, 44; 43, 45; 44, identifier:_bins; 45, identifier:bins | def qcut(expr, bins, labels=False, sort=None, ascending=True):
if labels is None or labels:
raise NotImplementedError('Showing bins or customizing labels not supported')
return _rank_op(expr, QCut, types.int64, sort=sort, ascending=ascending,
_bins=bins) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:cume_dist; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:expr; 5, default_parameter; 5, 6; 5, 7; 6, identifier:sort; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:ascending; 10, True; 11, block; 11, 12; 12, return_statement; 12, 13; 13, call; 13, 14; 13, 15; 14, identifier:_rank_op; 15, argument_list; 15, 16; 15, 17; 15, 18; 15, 21; 15, 24; 16, identifier:expr; 17, identifier:CumeDist; 18, attribute; 18, 19; 18, 20; 19, identifier:types; 20, identifier:float64; 21, keyword_argument; 21, 22; 21, 23; 22, identifier:sort; 23, identifier:sort; 24, keyword_argument; 24, 25; 24, 26; 25, identifier:ascending; 26, identifier:ascending | def cume_dist(expr, sort=None, ascending=True):
return _rank_op(expr, CumeDist, types.float64, sort=sort, ascending=ascending) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:lag; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:expr; 5, identifier:offset; 6, default_parameter; 6, 7; 6, 8; 7, identifier:default; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:sort; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:ascending; 14, True; 15, block; 15, 16; 16, return_statement; 16, 17; 17, call; 17, 18; 17, 19; 18, identifier:_shift_op; 19, argument_list; 19, 20; 19, 21; 19, 22; 19, 23; 19, 26; 19, 29; 20, identifier:expr; 21, identifier:Lag; 22, identifier:offset; 23, keyword_argument; 23, 24; 23, 25; 24, identifier:default; 25, identifier:default; 26, keyword_argument; 26, 27; 26, 28; 27, identifier:sort; 28, identifier:sort; 29, keyword_argument; 29, 30; 29, 31; 30, identifier:ascending; 31, identifier:ascending | def lag(expr, offset, default=None, sort=None, ascending=True):
return _shift_op(expr, Lag, offset, default=default,
sort=sort, ascending=ascending) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:lead; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:expr; 5, identifier:offset; 6, default_parameter; 6, 7; 6, 8; 7, identifier:default; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:sort; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:ascending; 14, True; 15, block; 15, 16; 16, return_statement; 16, 17; 17, call; 17, 18; 17, 19; 18, identifier:_shift_op; 19, argument_list; 19, 20; 19, 21; 19, 22; 19, 23; 19, 26; 19, 29; 20, identifier:expr; 21, identifier:Lead; 22, identifier:offset; 23, keyword_argument; 23, 24; 23, 25; 24, identifier:default; 25, identifier:default; 26, keyword_argument; 26, 27; 26, 28; 27, identifier:sort; 28, identifier:sort; 29, keyword_argument; 29, 30; 29, 31; 30, identifier:ascending; 31, identifier:ascending | def lead(expr, offset, default=None, sort=None, ascending=True):
return _shift_op(expr, Lead, offset, default=default,
sort=sort, ascending=ascending) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:value_counts; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:expr; 5, default_parameter; 5, 6; 5, 7; 6, identifier:sort; 7, True; 8, default_parameter; 8, 9; 8, 10; 9, identifier:ascending; 10, False; 11, default_parameter; 11, 12; 11, 13; 12, identifier:dropna; 13, False; 14, block; 14, 15; 14, 23; 14, 33; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:names; 18, list:[expr.name, 'count']; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:expr; 21, identifier:name; 22, string:'count'; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:typos; 26, list:[expr.dtype, types.int64]; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:expr; 29, identifier:dtype; 30, attribute; 30, 31; 30, 32; 31, identifier:types; 32, identifier:int64; 33, return_statement; 33, 34; 34, call; 34, 35; 34, 36; 35, identifier:ValueCounts; 36, argument_list; 36, 37; 36, 40; 36, 49; 36, 52; 36, 55; 37, keyword_argument; 37, 38; 37, 39; 38, identifier:_input; 39, identifier:expr; 40, keyword_argument; 40, 41; 40, 42; 41, identifier:_schema; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:Schema; 45, identifier:from_lists; 46, argument_list; 46, 47; 46, 48; 47, identifier:names; 48, identifier:typos; 49, keyword_argument; 49, 50; 49, 51; 50, identifier:_sort; 51, identifier:sort; 52, keyword_argument; 52, 53; 52, 54; 53, identifier:_ascending; 54, identifier:ascending; 55, keyword_argument; 55, 56; 55, 57; 56, identifier:_dropna; 57, identifier:dropna | def value_counts(expr, sort=True, ascending=False, dropna=False):
names = [expr.name, 'count']
typos = [expr.dtype, types.int64]
return ValueCounts(_input=expr, _schema=Schema.from_lists(names, typos),
_sort=sort, _ascending=ascending, _dropna=dropna) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:last; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:limit; 7, integer:1; 8, dictionary_splat_pattern; 8, 9; 9, identifier:kwargs; 10, block; 10, 11; 11, return_statement; 11, 12; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:collection_instance; 16, argument_list; 16, 17; 17, call; 17, 18; 17, 42; 18, attribute; 18, 19; 18, 41; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:db_adapter; 23, argument_list; 23, 24; 23, 32; 24, keyword_argument; 24, 25; 24, 26; 25, identifier:db_name; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:kwargs; 29, identifier:get; 30, argument_list; 30, 31; 31, string:'db'; 32, keyword_argument; 32, 33; 32, 34; 33, identifier:role; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:kwargs; 37, identifier:get; 38, argument_list; 38, 39; 38, 40; 39, string:'role'; 40, string:'replica'; 41, identifier:select; 42, argument_list; 42, 43; 42, 46; 42, 49; 43, keyword_argument; 43, 44; 43, 45; 44, identifier:where; 45, string:'created_at IS NOT NULL'; 46, keyword_argument; 46, 47; 46, 48; 47, identifier:order; 48, string:'created_at DESC'; 49, keyword_argument; 49, 50; 49, 51; 50, identifier:limit; 51, identifier:limit | def last(self, limit=1, **kwargs):
return self.collection_instance(
self.db_adapter(
db_name=kwargs.get('db'),
role=kwargs.get('role', 'replica')
).select(
where='created_at IS NOT NULL',
order='created_at DESC',
limit=limit
)
) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 4; 2, function_name:_compile_itemsort; 3, parameters; 4, block; 4, 5; 4, 7; 4, 16; 4, 27; 4, 38; 4, 50; 4, 60; 4, 79; 4, 106; 5, expression_statement; 5, 6; 6, string:'''return sort function of mappings'''; 7, function_definition; 7, 8; 7, 9; 7, 11; 8, function_name:is_extra; 9, parameters; 9, 10; 10, identifier:key_; 11, block; 11, 12; 12, return_statement; 12, 13; 13, comparison_operator:is; 13, 14; 13, 15; 14, identifier:key_; 15, identifier:Extra; 16, function_definition; 16, 17; 16, 18; 16, 20; 17, function_name:is_remove; 18, parameters; 18, 19; 19, identifier:key_; 20, block; 20, 21; 21, return_statement; 21, 22; 22, call; 22, 23; 22, 24; 23, identifier:isinstance; 24, argument_list; 24, 25; 24, 26; 25, identifier:key_; 26, identifier:Remove; 27, function_definition; 27, 28; 27, 29; 27, 31; 28, function_name:is_marker; 29, parameters; 29, 30; 30, identifier:key_; 31, block; 31, 32; 32, return_statement; 32, 33; 33, call; 33, 34; 33, 35; 34, identifier:isinstance; 35, argument_list; 35, 36; 35, 37; 36, identifier:key_; 37, identifier:Marker; 38, function_definition; 38, 39; 38, 40; 38, 42; 39, function_name:is_type; 40, parameters; 40, 41; 41, identifier:key_; 42, block; 42, 43; 43, return_statement; 43, 44; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:inspect; 47, identifier:isclass; 48, argument_list; 48, 49; 49, identifier:key_; 50, function_definition; 50, 51; 50, 52; 50, 54; 51, function_name:is_callable; 52, parameters; 52, 53; 53, identifier:key_; 54, block; 54, 55; 55, return_statement; 55, 56; 56, call; 56, 57; 56, 58; 57, identifier:callable; 58, argument_list; 58, 59; 59, identifier:key_; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:priority; 63, list:[(1, is_remove),
(2, is_marker),
(4, is_type),
(3, is_callable),
(5, is_extra)]; 63, 64; 63, 67; 63, 70; 63, 73; 63, 76; 64, tuple; 64, 65; 64, 66; 65, integer:1; 66, identifier:is_remove; 67, tuple; 67, 68; 67, 69; 68, integer:2; 69, identifier:is_marker; 70, tuple; 70, 71; 70, 72; 71, integer:4; 72, identifier:is_type; 73, tuple; 73, 74; 73, 75; 74, integer:3; 75, identifier:is_callable; 76, tuple; 76, 77; 76, 78; 77, integer:5; 78, identifier:is_extra; 79, function_definition; 79, 80; 79, 81; 79, 83; 80, function_name:item_priority; 81, parameters; 81, 82; 82, identifier:item_; 83, block; 83, 84; 83, 90; 83, 104; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:key_; 87, subscript; 87, 88; 87, 89; 88, identifier:item_; 89, integer:0; 90, for_statement; 90, 91; 90, 94; 90, 95; 91, pattern_list; 91, 92; 91, 93; 92, identifier:i; 93, identifier:check_; 94, identifier:priority; 95, block; 95, 96; 96, if_statement; 96, 97; 96, 101; 97, call; 97, 98; 97, 99; 98, identifier:check_; 99, argument_list; 99, 100; 100, identifier:key_; 101, block; 101, 102; 102, return_statement; 102, 103; 103, identifier:i; 104, return_statement; 104, 105; 105, integer:0; 106, return_statement; 106, 107; 107, identifier:item_priority | def _compile_itemsort():
'''return sort function of mappings'''
def is_extra(key_):
return key_ is Extra
def is_remove(key_):
return isinstance(key_, Remove)
def is_marker(key_):
return isinstance(key_, Marker)
def is_type(key_):
return inspect.isclass(key_)
def is_callable(key_):
return callable(key_)
priority = [(1, is_remove),
(2, is_marker),
(4, is_type),
(3, is_callable),
(5, is_extra)]
def item_priority(item_):
key_ = item_[0]
for i, check_ in priority:
if check_(key_):
return i
return 0
return item_priority |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_compile_dict; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:schema; 6, block; 6, 7; 6, 19; 6, 23; 6, 27; 6, 83; 6, 308; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:base_validate; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:_compile_mapping; 14, argument_list; 14, 15; 14, 16; 15, identifier:schema; 16, keyword_argument; 16, 17; 16, 18; 17, identifier:invalid_msg; 18, string:'dictionary value'; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:groups_of_exclusion; 22, dictionary; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:groups_of_inclusion; 26, dictionary; 27, for_statement; 27, 28; 27, 29; 27, 30; 28, identifier:node; 29, identifier:schema; 30, block; 30, 31; 31, if_statement; 31, 32; 31, 37; 31, 57; 32, call; 32, 33; 32, 34; 33, identifier:isinstance; 34, argument_list; 34, 35; 34, 36; 35, identifier:node; 36, identifier:Exclusive; 37, block; 37, 38; 37, 50; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:g; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:groups_of_exclusion; 44, identifier:setdefault; 45, argument_list; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:node; 48, identifier:group_of_exclusion; 49, list:[]; 50, expression_statement; 50, 51; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:g; 54, identifier:append; 55, argument_list; 55, 56; 56, identifier:node; 57, elif_clause; 57, 58; 57, 63; 58, call; 58, 59; 58, 60; 59, identifier:isinstance; 60, argument_list; 60, 61; 60, 62; 61, identifier:node; 62, identifier:Inclusive; 63, block; 63, 64; 63, 76; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:g; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:groups_of_inclusion; 70, identifier:setdefault; 71, argument_list; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:node; 74, identifier:group_of_inclusion; 75, list:[]; 76, expression_statement; 76, 77; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:g; 80, identifier:append; 81, argument_list; 81, 82; 82, identifier:node; 83, function_definition; 83, 84; 83, 85; 83, 88; 84, function_name:validate_dict; 85, parameters; 85, 86; 85, 87; 86, identifier:path; 87, identifier:data; 88, block; 88, 89; 88, 105; 88, 109; 88, 184; 88, 194; 88, 280; 88, 290; 88, 298; 89, if_statement; 89, 90; 89, 96; 90, not_operator; 90, 91; 91, call; 91, 92; 91, 93; 92, identifier:isinstance; 93, argument_list; 93, 94; 93, 95; 94, identifier:data; 95, identifier:dict; 96, block; 96, 97; 97, raise_statement; 97, 98; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:er; 101, identifier:DictInvalid; 102, argument_list; 102, 103; 102, 104; 103, string:'expected a dictionary'; 104, identifier:path; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:errors; 108, list:[]; 109, for_statement; 109, 110; 109, 113; 109, 118; 110, pattern_list; 110, 111; 110, 112; 111, identifier:label; 112, identifier:group; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:groups_of_exclusion; 116, identifier:items; 117, argument_list; 118, block; 118, 119; 118, 123; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:exists; 122, False; 123, for_statement; 123, 124; 123, 125; 123, 126; 124, identifier:exclusive; 125, identifier:group; 126, block; 126, 127; 127, if_statement; 127, 128; 127, 133; 128, comparison_operator:in; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:exclusive; 131, identifier:schema; 132, identifier:data; 133, block; 133, 134; 133, 180; 134, if_statement; 134, 135; 134, 136; 135, identifier:exists; 136, block; 136, 137; 136, 156; 136, 166; 136, 179; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:msg; 140, conditional_expression:if; 140, 141; 140, 144; 140, 153; 141, attribute; 141, 142; 141, 143; 142, identifier:exclusive; 143, identifier:msg; 144, boolean_operator:and; 144, 145; 144, 150; 145, call; 145, 146; 145, 147; 146, identifier:hasattr; 147, argument_list; 147, 148; 147, 149; 148, identifier:exclusive; 149, string:'msg'; 150, attribute; 150, 151; 150, 152; 151, identifier:exclusive; 152, identifier:msg; 153, binary_operator:%; 153, 154; 153, 155; 154, string:"two or more values in the same group of exclusion '%s'"; 155, identifier:label; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 159; 158, identifier:next_path; 159, binary_operator:+; 159, 160; 159, 161; 160, identifier:path; 161, list:[VirtualPathComponent(label)]; 161, 162; 162, call; 162, 163; 162, 164; 163, identifier:VirtualPathComponent; 164, argument_list; 164, 165; 165, identifier:label; 166, expression_statement; 166, 167; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:errors; 170, identifier:append; 171, argument_list; 171, 172; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:er; 175, identifier:ExclusiveInvalid; 176, argument_list; 176, 177; 176, 178; 177, identifier:msg; 178, identifier:next_path; 179, break_statement; 180, expression_statement; 180, 181; 181, assignment; 181, 182; 181, 183; 182, identifier:exists; 183, True; 184, if_statement; 184, 185; 184, 186; 185, identifier:errors; 186, block; 186, 187; 187, raise_statement; 187, 188; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:er; 191, identifier:MultipleInvalid; 192, argument_list; 192, 193; 193, identifier:errors; 194, for_statement; 194, 195; 194, 198; 194, 203; 195, pattern_list; 195, 196; 195, 197; 196, identifier:label; 197, identifier:group; 198, call; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, identifier:groups_of_inclusion; 201, identifier:items; 202, argument_list; 203, block; 203, 204; 203, 216; 204, expression_statement; 204, 205; 205, assignment; 205, 206; 205, 207; 206, identifier:included; 207, list_comprehension; 207, 208; 207, 213; 208, comparison_operator:in; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:node; 211, identifier:schema; 212, identifier:data; 213, for_in_clause; 213, 214; 213, 215; 214, identifier:node; 215, identifier:group; 216, if_statement; 216, 217; 216, 227; 217, boolean_operator:and; 217, 218; 217, 222; 218, call; 218, 219; 218, 220; 219, identifier:any; 220, argument_list; 220, 221; 221, identifier:included; 222, not_operator; 222, 223; 223, call; 223, 224; 223, 225; 224, identifier:all; 225, argument_list; 225, 226; 226, identifier:included; 227, block; 227, 228; 227, 234; 227, 256; 227, 266; 227, 279; 228, expression_statement; 228, 229; 229, assignment; 229, 230; 229, 231; 230, identifier:msg; 231, binary_operator:%; 231, 232; 231, 233; 232, string:"some but not all values in the same group of inclusion '%s'"; 233, identifier:label; 234, for_statement; 234, 235; 234, 236; 234, 237; 235, identifier:g; 236, identifier:group; 237, block; 237, 238; 238, if_statement; 238, 239; 238, 248; 239, boolean_operator:and; 239, 240; 239, 245; 240, call; 240, 241; 240, 242; 241, identifier:hasattr; 242, argument_list; 242, 243; 242, 244; 243, identifier:g; 244, string:'msg'; 245, attribute; 245, 246; 245, 247; 246, identifier:g; 247, identifier:msg; 248, block; 248, 249; 248, 255; 249, expression_statement; 249, 250; 250, assignment; 250, 251; 250, 252; 251, identifier:msg; 252, attribute; 252, 253; 252, 254; 253, identifier:g; 254, identifier:msg; 255, break_statement; 256, expression_statement; 256, 257; 257, assignment; 257, 258; 257, 259; 258, identifier:next_path; 259, binary_operator:+; 259, 260; 259, 261; 260, identifier:path; 261, list:[VirtualPathComponent(label)]; 261, 262; 262, call; 262, 263; 262, 264; 263, identifier:VirtualPathComponent; 264, argument_list; 264, 265; 265, identifier:label; 266, expression_statement; 266, 267; 267, call; 267, 268; 267, 271; 268, attribute; 268, 269; 268, 270; 269, identifier:errors; 270, identifier:append; 271, argument_list; 271, 272; 272, call; 272, 273; 272, 276; 273, attribute; 273, 274; 273, 275; 274, identifier:er; 275, identifier:InclusiveInvalid; 276, argument_list; 276, 277; 276, 278; 277, identifier:msg; 278, identifier:next_path; 279, break_statement; 280, if_statement; 280, 281; 280, 282; 281, identifier:errors; 282, block; 282, 283; 283, raise_statement; 283, 284; 284, call; 284, 285; 284, 288; 285, attribute; 285, 286; 285, 287; 286, identifier:er; 287, identifier:MultipleInvalid; 288, argument_list; 288, 289; 289, identifier:errors; 290, expression_statement; 290, 291; 291, assignment; 291, 292; 291, 293; 292, identifier:out; 293, call; 293, 294; 293, 297; 294, attribute; 294, 295; 294, 296; 295, identifier:data; 296, identifier:__class__; 297, argument_list; 298, return_statement; 298, 299; 299, call; 299, 300; 299, 301; 300, identifier:base_validate; 301, argument_list; 301, 302; 301, 303; 301, 307; 302, identifier:path; 303, call; 303, 304; 303, 305; 304, identifier:iteritems; 305, argument_list; 305, 306; 306, identifier:data; 307, identifier:out; 308, return_statement; 308, 309; 309, identifier:validate_dict | def _compile_dict(self, schema):
base_validate = self._compile_mapping(
schema, invalid_msg='dictionary value')
groups_of_exclusion = {}
groups_of_inclusion = {}
for node in schema:
if isinstance(node, Exclusive):
g = groups_of_exclusion.setdefault(node.group_of_exclusion, [])
g.append(node)
elif isinstance(node, Inclusive):
g = groups_of_inclusion.setdefault(node.group_of_inclusion, [])
g.append(node)
def validate_dict(path, data):
if not isinstance(data, dict):
raise er.DictInvalid('expected a dictionary', path)
errors = []
for label, group in groups_of_exclusion.items():
exists = False
for exclusive in group:
if exclusive.schema in data:
if exists:
msg = exclusive.msg if hasattr(exclusive, 'msg') and exclusive.msg else \
"two or more values in the same group of exclusion '%s'" % label
next_path = path + [VirtualPathComponent(label)]
errors.append(er.ExclusiveInvalid(msg, next_path))
break
exists = True
if errors:
raise er.MultipleInvalid(errors)
for label, group in groups_of_inclusion.items():
included = [node.schema in data for node in group]
if any(included) and not all(included):
msg = "some but not all values in the same group of inclusion '%s'" % label
for g in group:
if hasattr(g, 'msg') and g.msg:
msg = g.msg
break
next_path = path + [VirtualPathComponent(label)]
errors.append(er.InclusiveInvalid(msg, next_path))
break
if errors:
raise er.MultipleInvalid(errors)
out = data.__class__()
return base_validate(path, iteritems(data), out)
return validate_dict |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:to_list; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:length; 6, block; 6, 7; 6, 37; 6, 57; 6, 72; 6, 115; 7, if_statement; 7, 8; 7, 11; 8, comparison_operator:is; 8, 9; 8, 10; 9, identifier:length; 10, None; 11, block; 11, 12; 12, if_statement; 12, 13; 12, 19; 12, 27; 13, not_operator; 13, 14; 14, call; 14, 15; 14, 16; 15, identifier:isinstance; 16, argument_list; 16, 17; 16, 18; 17, identifier:length; 18, identifier:int; 19, block; 19, 20; 20, raise_statement; 20, 21; 21, call; 21, 22; 21, 23; 22, identifier:TypeError; 23, argument_list; 23, 24; 24, binary_operator:%; 24, 25; 24, 26; 25, string:'length must be an int, not %r'; 26, identifier:length; 27, elif_clause; 27, 28; 27, 31; 28, comparison_operator:<; 28, 29; 28, 30; 29, identifier:length; 30, integer:0; 31, block; 31, 32; 32, raise_statement; 32, 33; 33, call; 33, 34; 33, 35; 34, identifier:ValueError; 35, argument_list; 35, 36; 36, string:'length must be non-negative'; 37, if_statement; 37, 38; 37, 47; 38, binary_operator:&; 38, 39; 38, 44; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:_query_flags; 43, argument_list; 44, subscript; 44, 45; 44, 46; 45, identifier:_QUERY_OPTIONS; 46, string:'tailable_cursor'; 47, block; 47, 48; 48, raise_statement; 48, 49; 49, call; 49, 50; 49, 55; 50, attribute; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:pymongo; 53, identifier:errors; 54, identifier:InvalidOperation; 55, argument_list; 55, 56; 56, string:"Can't call to_list on tailable cursor"; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:future; 60, call; 60, 61; 60, 66; 61, attribute; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:self; 64, identifier:_framework; 65, identifier:get_future; 66, argument_list; 66, 67; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:get_io_loop; 71, argument_list; 72, if_statement; 72, 73; 72, 77; 72, 85; 73, not_operator; 73, 74; 74, attribute; 74, 75; 74, 76; 75, identifier:self; 76, identifier:alive; 77, block; 77, 78; 78, expression_statement; 78, 79; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:future; 82, identifier:set_result; 83, argument_list; 83, 84; 84, list:[]; 85, else_clause; 85, 86; 86, block; 86, 87; 86, 91; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:the_list; 90, list:[]; 91, expression_statement; 91, 92; 92, call; 92, 93; 92, 98; 93, attribute; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:self; 96, identifier:_framework; 97, identifier:add_future; 98, argument_list; 98, 99; 98, 104; 98, 109; 98, 112; 98, 113; 98, 114; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:self; 102, identifier:get_io_loop; 103, argument_list; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:self; 107, identifier:_get_more; 108, argument_list; 109, attribute; 109, 110; 109, 111; 110, identifier:self; 111, identifier:_to_list; 112, identifier:length; 113, identifier:the_list; 114, identifier:future; 115, return_statement; 115, 116; 116, identifier:future | def to_list(self, length):
if length is not None:
if not isinstance(length, int):
raise TypeError('length must be an int, not %r' % length)
elif length < 0:
raise ValueError('length must be non-negative')
if self._query_flags() & _QUERY_OPTIONS['tailable_cursor']:
raise pymongo.errors.InvalidOperation(
"Can't call to_list on tailable cursor")
future = self._framework.get_future(self.get_io_loop())
if not self.alive:
future.set_result([])
else:
the_list = []
self._framework.add_future(
self.get_io_loop(),
self._get_more(),
self._to_list, length, the_list, future)
return future |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:find; 3, parameters; 3, 4; 3, 5; 3, 7; 4, identifier:self; 5, list_splat_pattern; 5, 6; 6, identifier:args; 7, dictionary_splat_pattern; 7, 8; 8, identifier:kwargs; 9, block; 9, 10; 9, 24; 9, 37; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:cursor; 13, call; 13, 14; 13, 19; 14, attribute; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:delegate; 18, identifier:find; 19, argument_list; 19, 20; 19, 22; 20, list_splat; 20, 21; 21, identifier:args; 22, dictionary_splat; 22, 23; 23, identifier:kwargs; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:grid_out_cursor; 27, call; 27, 28; 27, 29; 28, identifier:create_class_with_framework; 29, argument_list; 29, 30; 29, 31; 29, 34; 30, identifier:AgnosticGridOutCursor; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:_framework; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:__module__; 37, return_statement; 37, 38; 38, call; 38, 39; 38, 40; 39, identifier:grid_out_cursor; 40, argument_list; 40, 41; 40, 42; 41, identifier:cursor; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:collection | def find(self, *args, **kwargs):
cursor = self.delegate.find(*args, **kwargs)
grid_out_cursor = create_class_with_framework(
AgnosticGridOutCursor, self._framework, self.__module__)
return grid_out_cursor(cursor, self.collection) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_serial_poller; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 199; 6, while_statement; 6, 7; 6, 8; 7, True; 8, block; 8, 9; 8, 23; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:_next; 12, call; 12, 13; 12, 14; 13, identifier:dict; 14, argument_list; 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:_poller; 20, identifier:poll; 21, argument_list; 21, 22; 22, identifier:POLLING_FREQUENCY_MS; 23, if_statement; 23, 24; 23, 33; 23, 58; 23, 102; 23, 164; 24, comparison_operator:in; 24, 25; 24, 32; 25, call; 25, 26; 25, 31; 26, attribute; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:_halt_read_file; 30, identifier:fileno; 31, argument_list; 32, identifier:_next; 33, block; 33, 34; 33, 49; 33, 57; 34, expression_statement; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:log; 38, identifier:debug; 39, argument_list; 39, 40; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, string:"Poller [{}]: halt"; 43, identifier:format; 44, argument_list; 44, 45; 45, call; 45, 46; 45, 47; 46, identifier:hash; 47, argument_list; 47, 48; 48, identifier:self; 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:_halt_read_file; 55, identifier:read; 56, argument_list; 57, break_statement; 58, elif_clause; 58, 59; 58, 68; 59, comparison_operator:in; 59, 60; 59, 67; 60, call; 60, 61; 60, 66; 61, attribute; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:self; 64, identifier:_connection; 65, identifier:fileno; 66, argument_list; 67, identifier:_next; 68, block; 68, 69; 68, 84; 68, 95; 69, expression_statement; 69, 70; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:log; 73, identifier:debug; 74, argument_list; 74, 75; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, string:"Poller [{}]: interrupt"; 78, identifier:format; 79, argument_list; 79, 80; 80, call; 80, 81; 80, 82; 81, identifier:hash; 82, argument_list; 82, 83; 83, identifier:self; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:res; 87, call; 87, 88; 87, 93; 88, attribute; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:self; 91, identifier:_connection; 92, identifier:read_until; 93, argument_list; 93, 94; 94, identifier:SERIAL_ACK; 95, expression_statement; 95, 96; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:_interrupt_callback; 100, argument_list; 100, 101; 101, identifier:res; 102, elif_clause; 102, 103; 102, 112; 103, comparison_operator:in; 103, 104; 103, 111; 104, call; 104, 105; 104, 110; 105, attribute; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:self; 108, identifier:_send_read_file; 109, identifier:fileno; 110, argument_list; 111, identifier:_next; 112, block; 112, 113; 112, 122; 112, 134; 112, 150; 112, 159; 113, expression_statement; 113, 114; 114, call; 114, 115; 114, 120; 115, attribute; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:self; 118, identifier:_send_read_file; 119, identifier:read; 120, argument_list; 120, 121; 121, integer:1; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 127; 124, pattern_list; 124, 125; 124, 126; 125, identifier:command; 126, identifier:callback; 127, call; 127, 128; 127, 133; 128, attribute; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:self; 131, identifier:_command_queue; 132, identifier:get; 133, argument_list; 134, expression_statement; 134, 135; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:log; 138, identifier:debug; 139, argument_list; 139, 140; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, string:"Poller [{}]: send {}"; 143, identifier:format; 144, argument_list; 144, 145; 144, 149; 145, call; 145, 146; 145, 147; 146, identifier:hash; 147, argument_list; 147, 148; 148, identifier:self; 149, identifier:command; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 153; 152, identifier:res; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:self; 156, identifier:_send_command; 157, argument_list; 157, 158; 158, identifier:command; 159, expression_statement; 159, 160; 160, call; 160, 161; 160, 162; 161, identifier:callback; 162, argument_list; 162, 163; 163, identifier:res; 164, else_clause; 164, 165; 165, block; 165, 166; 165, 181; 165, 192; 166, expression_statement; 166, 167; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:log; 170, identifier:debug; 171, argument_list; 171, 172; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, string:"Poller [{}]: updating temp"; 175, identifier:format; 176, argument_list; 176, 177; 177, call; 177, 178; 177, 179; 178, identifier:hash; 179, argument_list; 179, 180; 180, identifier:self; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 184; 183, identifier:res; 184, call; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:self; 187, identifier:_send_command; 188, argument_list; 188, 189; 189, subscript; 189, 190; 189, 191; 190, identifier:GCODES; 191, string:'GET_PLATE_TEMP'; 192, expression_statement; 192, 193; 193, call; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:self; 196, identifier:_status_callback; 197, argument_list; 197, 198; 198, identifier:res; 199, expression_statement; 199, 200; 200, call; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:log; 203, identifier:info; 204, argument_list; 204, 205; 205, call; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, string:"Exiting TC poller loop [{}]"; 208, identifier:format; 209, argument_list; 209, 210; 210, call; 210, 211; 210, 212; 211, identifier:hash; 212, argument_list; 212, 213; 213, identifier:self | def _serial_poller(self):
while True:
_next = dict(self._poller.poll(POLLING_FREQUENCY_MS))
if self._halt_read_file.fileno() in _next:
log.debug("Poller [{}]: halt".format(hash(self)))
self._halt_read_file.read()
break
elif self._connection.fileno() in _next:
log.debug("Poller [{}]: interrupt".format(hash(self)))
res = self._connection.read_until(SERIAL_ACK)
self._interrupt_callback(res)
elif self._send_read_file.fileno() in _next:
self._send_read_file.read(1)
command, callback = self._command_queue.get()
log.debug("Poller [{}]: send {}".format(hash(self), command))
res = self._send_command(command)
callback(res)
else:
log.debug("Poller [{}]: updating temp".format(hash(self)))
res = self._send_command(GCODES['GET_PLATE_TEMP'])
self._status_callback(res)
log.info("Exiting TC poller loop [{}]".format(hash(self))) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:enqueue_at; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 9; 4, identifier:self; 5, identifier:scheduled_time; 6, identifier:func; 7, list_splat_pattern; 7, 8; 8, identifier:args; 9, dictionary_splat_pattern; 9, 10; 10, identifier:kwargs; 11, block; 11, 12; 11, 22; 11, 32; 11, 42; 11, 52; 11, 62; 11, 72; 11, 105; 11, 125; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:timeout; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:kwargs; 18, identifier:pop; 19, argument_list; 19, 20; 19, 21; 20, string:'timeout'; 21, None; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:job_id; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:kwargs; 28, identifier:pop; 29, argument_list; 29, 30; 29, 31; 30, string:'job_id'; 31, None; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:job_ttl; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:kwargs; 38, identifier:pop; 39, argument_list; 39, 40; 39, 41; 40, string:'job_ttl'; 41, None; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:job_result_ttl; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:kwargs; 48, identifier:pop; 49, argument_list; 49, 50; 49, 51; 50, string:'job_result_ttl'; 51, None; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:job_description; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:kwargs; 58, identifier:pop; 59, argument_list; 59, 60; 59, 61; 60, string:'job_description'; 61, None; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:meta; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:kwargs; 68, identifier:pop; 69, argument_list; 69, 70; 69, 71; 70, string:'meta'; 71, None; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:job; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:self; 78, identifier:_create_job; 79, argument_list; 79, 80; 79, 81; 79, 84; 79, 87; 79, 90; 79, 93; 79, 96; 79, 99; 79, 102; 80, identifier:func; 81, keyword_argument; 81, 82; 81, 83; 82, identifier:args; 83, identifier:args; 84, keyword_argument; 84, 85; 84, 86; 85, identifier:kwargs; 86, identifier:kwargs; 87, keyword_argument; 87, 88; 87, 89; 88, identifier:timeout; 89, identifier:timeout; 90, keyword_argument; 90, 91; 90, 92; 91, identifier:id; 92, identifier:job_id; 93, keyword_argument; 93, 94; 93, 95; 94, identifier:result_ttl; 95, identifier:job_result_ttl; 96, keyword_argument; 96, 97; 96, 98; 97, identifier:ttl; 98, identifier:job_ttl; 99, keyword_argument; 99, 100; 99, 101; 100, identifier:description; 101, identifier:job_description; 102, keyword_argument; 102, 103; 102, 104; 103, identifier:meta; 104, identifier:meta; 105, expression_statement; 105, 106; 106, call; 106, 107; 106, 112; 107, attribute; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:self; 110, identifier:connection; 111, identifier:zadd; 112, argument_list; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:self; 115, identifier:scheduled_jobs_key; 116, dictionary; 116, 117; 117, pair; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:job; 120, identifier:id; 121, call; 121, 122; 121, 123; 122, identifier:to_unix; 123, argument_list; 123, 124; 124, identifier:scheduled_time; 125, return_statement; 125, 126; 126, identifier:job | def enqueue_at(self, scheduled_time, func, *args, **kwargs):
timeout = kwargs.pop('timeout', None)
job_id = kwargs.pop('job_id', None)
job_ttl = kwargs.pop('job_ttl', None)
job_result_ttl = kwargs.pop('job_result_ttl', None)
job_description = kwargs.pop('job_description', None)
meta = kwargs.pop('meta', None)
job = self._create_job(func, args=args, kwargs=kwargs, timeout=timeout,
id=job_id, result_ttl=job_result_ttl, ttl=job_ttl,
description=job_description, meta=meta)
self.connection.zadd(self.scheduled_jobs_key,
{job.id: to_unix(scheduled_time)})
return job |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_getMostActiveCells; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 12; 5, 27; 5, 40; 5, 57; 5, 68; 5, 104; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:poolingActivation; 9, attribute; 9, 10; 9, 11; 10, identifier:self; 11, identifier:_poolingActivation; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:nonZeroCells; 15, subscript; 15, 16; 15, 24; 15, 26; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:numpy; 19, identifier:argwhere; 20, argument_list; 20, 21; 21, comparison_operator:>; 21, 22; 21, 23; 22, identifier:poolingActivation; 23, integer:0; 24, slice; 24, 25; 25, colon; 26, integer:0; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:poolingActivationSubset; 30, binary_operator:+; 30, 31; 30, 34; 30, 35; 31, subscript; 31, 32; 31, 33; 32, identifier:poolingActivation; 33, identifier:nonZeroCells; 34, line_continuation:\; 35, subscript; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:_poolingActivation_tieBreaker; 39, identifier:nonZeroCells; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:potentialUnionSDR; 43, subscript; 43, 44; 43, 45; 44, identifier:nonZeroCells; 45, subscript; 45, 46; 45, 52; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:numpy; 49, identifier:argsort; 50, argument_list; 50, 51; 51, identifier:poolingActivationSubset; 52, slice; 52, 53; 52, 54; 52, 55; 53, colon; 54, colon; 55, unary_operator:-; 55, 56; 56, integer:1; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:topCells; 60, subscript; 60, 61; 60, 62; 61, identifier:potentialUnionSDR; 62, slice; 62, 63; 62, 64; 62, 65; 63, integer:0; 64, colon; 65, attribute; 65, 66; 65, 67; 66, identifier:self; 67, identifier:_maxUnionCells; 68, if_statement; 68, 69; 68, 79; 68, 96; 69, comparison_operator:>; 69, 70; 69, 76; 70, call; 70, 71; 70, 72; 71, identifier:max; 72, argument_list; 72, 73; 73, attribute; 73, 74; 73, 75; 74, identifier:self; 75, identifier:_poolingTimer; 76, attribute; 76, 77; 76, 78; 77, identifier:self; 78, identifier:_minHistory; 79, block; 79, 80; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:self; 84, identifier:_unionSDR; 85, call; 85, 86; 85, 94; 86, attribute; 86, 87; 86, 93; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:numpy; 90, identifier:sort; 91, argument_list; 91, 92; 92, identifier:topCells; 93, identifier:astype; 94, argument_list; 94, 95; 95, identifier:UINT_DTYPE; 96, else_clause; 96, 97; 97, block; 97, 98; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:self; 102, identifier:_unionSDR; 103, list:[]; 104, return_statement; 104, 105; 105, attribute; 105, 106; 105, 107; 106, identifier:self; 107, identifier:_unionSDR | def _getMostActiveCells(self):
poolingActivation = self._poolingActivation
nonZeroCells = numpy.argwhere(poolingActivation > 0)[:,0]
poolingActivationSubset = poolingActivation[nonZeroCells] + \
self._poolingActivation_tieBreaker[nonZeroCells]
potentialUnionSDR = nonZeroCells[numpy.argsort(poolingActivationSubset)[::-1]]
topCells = potentialUnionSDR[0: self._maxUnionCells]
if max(self._poolingTimer) > self._minHistory:
self._unionSDR = numpy.sort(topCells).astype(UINT_DTYPE)
else:
self._unionSDR = []
return self._unionSDR |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:printNetwork; 3, parameters; 3, 4; 4, identifier:network; 5, block; 5, 6; 5, 19; 6, print_statement; 6, 7; 6, 8; 6, 18; 7, string:"The network has"; 8, call; 8, 9; 8, 10; 9, identifier:len; 10, argument_list; 10, 11; 11, call; 11, 12; 11, 17; 12, attribute; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:network; 15, identifier:regions; 16, identifier:values; 17, argument_list; 18, string:"regions"; 19, for_statement; 19, 20; 19, 21; 19, 29; 20, identifier:p; 21, call; 21, 22; 21, 23; 22, identifier:range; 23, argument_list; 23, 24; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:network; 27, identifier:getMaxPhase; 28, argument_list; 29, block; 29, 30; 29, 33; 30, print_statement; 30, 31; 30, 32; 31, string:"=== Phase"; 32, identifier:p; 33, for_statement; 33, 34; 33, 35; 33, 42; 34, identifier:region; 35, call; 35, 36; 35, 41; 36, attribute; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:network; 39, identifier:regions; 40, identifier:values; 41, argument_list; 42, block; 42, 43; 43, if_statement; 43, 44; 43, 56; 44, comparison_operator:==; 44, 45; 44, 55; 45, subscript; 45, 46; 45, 54; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:network; 49, identifier:getPhases; 50, argument_list; 50, 51; 51, attribute; 51, 52; 51, 53; 52, identifier:region; 53, identifier:name; 54, integer:0; 55, identifier:p; 56, block; 56, 57; 57, print_statement; 57, 58; 57, 59; 58, string:" "; 59, attribute; 59, 60; 59, 61; 60, identifier:region; 61, identifier:name | def printNetwork(network):
print "The network has",len(network.regions.values()),"regions"
for p in range(network.getMaxPhase()):
print "=== Phase",p
for region in network.regions.values():
if network.getPhases(region.name)[0] == p:
print " ",region.name |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:argmaxMulti; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:a; 5, identifier:groupKeys; 6, default_parameter; 6, 7; 6, 8; 7, identifier:assumeSorted; 8, False; 9, block; 9, 10; 9, 38; 9, 56; 9, 68; 9, 85; 9, 97; 10, if_statement; 10, 11; 10, 13; 11, not_operator; 11, 12; 12, identifier:assumeSorted; 13, block; 13, 14; 13, 26; 13, 32; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:sorter; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:np; 20, identifier:argsort; 21, argument_list; 21, 22; 21, 23; 22, identifier:groupKeys; 23, keyword_argument; 23, 24; 23, 25; 24, identifier:kind; 25, string:"mergesort"; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:a; 29, subscript; 29, 30; 29, 31; 30, identifier:a; 31, identifier:sorter; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:groupKeys; 35, subscript; 35, 36; 35, 37; 36, identifier:groupKeys; 37, identifier:sorter; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 44; 40, pattern_list; 40, 41; 40, 42; 40, 43; 41, identifier:_; 42, identifier:indices; 43, identifier:lengths; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:np; 47, identifier:unique; 48, argument_list; 48, 49; 48, 50; 48, 53; 49, identifier:groupKeys; 50, keyword_argument; 50, 51; 50, 52; 51, identifier:return_index; 52, True; 53, keyword_argument; 53, 54; 53, 55; 54, identifier:return_counts; 55, True; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:maxValues; 59, call; 59, 60; 59, 65; 60, attribute; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:np; 63, identifier:maximum; 64, identifier:reduceat; 65, argument_list; 65, 66; 65, 67; 66, identifier:a; 67, identifier:indices; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:allMaxIndices; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:np; 74, identifier:flatnonzero; 75, argument_list; 75, 76; 76, comparison_operator:==; 76, 77; 76, 84; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:np; 80, identifier:repeat; 81, argument_list; 81, 82; 81, 83; 82, identifier:maxValues; 83, identifier:lengths; 84, identifier:a; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:indices; 88, subscript; 88, 89; 88, 90; 89, identifier:allMaxIndices; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:np; 93, identifier:searchsorted; 94, argument_list; 94, 95; 94, 96; 95, identifier:allMaxIndices; 96, identifier:indices; 97, if_statement; 97, 98; 97, 99; 97, 102; 98, identifier:assumeSorted; 99, block; 99, 100; 100, return_statement; 100, 101; 101, identifier:indices; 102, else_clause; 102, 103; 103, block; 103, 104; 104, return_statement; 104, 105; 105, subscript; 105, 106; 105, 107; 106, identifier:sorter; 107, identifier:indices | def argmaxMulti(a, groupKeys, assumeSorted=False):
if not assumeSorted:
sorter = np.argsort(groupKeys, kind="mergesort")
a = a[sorter]
groupKeys = groupKeys[sorter]
_, indices, lengths = np.unique(groupKeys, return_index=True,
return_counts=True)
maxValues = np.maximum.reduceat(a, indices)
allMaxIndices = np.flatnonzero(np.repeat(maxValues, lengths) == a)
indices = allMaxIndices[np.searchsorted(allMaxIndices, indices)]
if assumeSorted:
return indices
else:
return sorter[indices] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:getAllCellsInColumns; 3, parameters; 3, 4; 3, 5; 4, identifier:columns; 5, identifier:cellsPerColumn; 6, block; 6, 7; 7, return_statement; 7, 8; 8, call; 8, 9; 8, 34; 9, attribute; 9, 10; 9, 33; 10, parenthesized_expression; 10, 11; 11, binary_operator:+; 11, 12; 11, 24; 12, call; 12, 13; 12, 19; 13, attribute; 13, 14; 13, 18; 14, parenthesized_expression; 14, 15; 15, binary_operator:*; 15, 16; 15, 17; 16, identifier:columns; 17, identifier:cellsPerColumn; 18, identifier:reshape; 19, argument_list; 19, 20; 20, tuple; 20, 21; 20, 23; 21, unary_operator:-; 21, 22; 22, integer:1; 23, integer:1; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:np; 27, identifier:arange; 28, argument_list; 28, 29; 28, 30; 29, identifier:cellsPerColumn; 30, keyword_argument; 30, 31; 30, 32; 31, identifier:dtype; 32, string:"uint32"; 33, identifier:flatten; 34, argument_list | def getAllCellsInColumns(columns, cellsPerColumn):
return ((columns * cellsPerColumn).reshape((-1, 1)) +
np.arange(cellsPerColumn, dtype="uint32")).flatten() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:shuffle_sparse_matrix_and_labels; 3, parameters; 3, 4; 3, 5; 4, identifier:matrix; 5, identifier:labels; 6, block; 6, 7; 6, 9; 6, 17; 6, 27; 6, 36; 6, 45; 6, 54; 6, 56; 7, print_statement; 7, 8; 8, string:"Shuffling data"; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:new_matrix; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:matrix; 15, identifier:toDense; 16, argument_list; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:rng_state; 20, call; 20, 21; 20, 26; 21, attribute; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:numpy; 24, identifier:random; 25, identifier:get_state; 26, argument_list; 27, expression_statement; 27, 28; 28, call; 28, 29; 28, 34; 29, attribute; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:numpy; 32, identifier:random; 33, identifier:shuffle; 34, argument_list; 34, 35; 35, identifier:new_matrix; 36, expression_statement; 36, 37; 37, call; 37, 38; 37, 43; 38, attribute; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:numpy; 41, identifier:random; 42, identifier:set_state; 43, argument_list; 43, 44; 44, identifier:rng_state; 45, expression_statement; 45, 46; 46, call; 46, 47; 46, 52; 47, attribute; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:numpy; 50, identifier:random; 51, identifier:shuffle; 52, argument_list; 52, 53; 53, identifier:labels; 54, print_statement; 54, 55; 55, string:"Data shuffled"; 56, return_statement; 56, 57; 57, expression_list; 57, 58; 57, 62; 58, call; 58, 59; 58, 60; 59, identifier:SM32; 60, argument_list; 60, 61; 61, identifier:new_matrix; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:numpy; 65, identifier:asarray; 66, argument_list; 66, 67; 67, identifier:labels | def shuffle_sparse_matrix_and_labels(matrix, labels):
print "Shuffling data"
new_matrix = matrix.toDense()
rng_state = numpy.random.get_state()
numpy.random.shuffle(new_matrix)
numpy.random.set_state(rng_state)
numpy.random.shuffle(labels)
print "Data shuffled"
return SM32(new_matrix), numpy.asarray(labels) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:compute; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:sensorToBodyByColumn; 6, identifier:sensorToSpecificObjectByColumn; 7, block; 7, 8; 7, 22; 7, 28; 7, 103; 7, 121; 7, 135; 7, 150; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:votesByCell; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:np; 14, identifier:zeros; 15, argument_list; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:cellCount; 19, keyword_argument; 19, 20; 19, 21; 20, identifier:dtype; 21, string:"int"; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:activeSegmentsByColumn; 27, list:[]; 28, for_statement; 28, 29; 28, 33; 28, 41; 29, tuple_pattern; 29, 30; 29, 31; 29, 32; 30, identifier:connections; 31, identifier:activeSensorToBodyCells; 32, identifier:activeSensorToSpecificObjectCells; 33, call; 33, 34; 33, 35; 34, identifier:zip; 35, argument_list; 35, 36; 35, 39; 35, 40; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:connectionsByColumn; 39, identifier:sensorToBodyByColumn; 40, identifier:sensorToSpecificObjectByColumn; 41, block; 41, 42; 41, 57; 41, 70; 41, 79; 41, 88; 41, 94; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:overlaps; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:connections; 48, identifier:computeActivity; 49, argument_list; 49, 50; 50, dictionary; 50, 51; 50, 54; 51, pair; 51, 52; 51, 53; 52, string:"sensorToBody"; 53, identifier:activeSensorToBodyCells; 54, pair; 54, 55; 54, 56; 55, string:"sensorToSpecificObject"; 56, identifier:activeSensorToSpecificObjectCells; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:activeSegments; 60, subscript; 60, 61; 60, 69; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:np; 64, identifier:where; 65, argument_list; 65, 66; 66, comparison_operator:>=; 66, 67; 66, 68; 67, identifier:overlaps; 68, integer:2; 69, integer:0; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:votes; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:connections; 76, identifier:mapSegmentsToCells; 77, argument_list; 77, 78; 78, identifier:activeSegments; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:votes; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:np; 85, identifier:unique; 86, argument_list; 86, 87; 87, identifier:votes; 88, expression_statement; 88, 89; 89, augmented_assignment:+=; 89, 90; 89, 93; 90, subscript; 90, 91; 90, 92; 91, identifier:votesByCell; 92, identifier:votes; 93, integer:1; 94, expression_statement; 94, 95; 95, call; 95, 96; 95, 101; 96, attribute; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:activeSegmentsByColumn; 100, identifier:append; 101, argument_list; 101, 102; 102, identifier:activeSegments; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:candidates; 106, subscript; 106, 107; 106, 120; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:np; 110, identifier:where; 111, argument_list; 111, 112; 112, comparison_operator:==; 112, 113; 112, 114; 113, identifier:votesByCell; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:np; 117, identifier:max; 118, argument_list; 118, 119; 119, identifier:votesByCell; 120, integer:0; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:self; 125, identifier:activeCells; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:np; 129, identifier:intersect1d; 130, argument_list; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:self; 133, identifier:activeCells; 134, identifier:candidates; 135, if_statement; 135, 136; 135, 143; 136, comparison_operator:==; 136, 137; 136, 142; 137, attribute; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:self; 140, identifier:activeCells; 141, identifier:size; 142, integer:0; 143, block; 143, 144; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:self; 148, identifier:activeCells; 149, identifier:candidates; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:self; 154, identifier:inhibitedCells; 155, call; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:np; 158, identifier:setdiff1d; 159, argument_list; 159, 160; 159, 170; 160, subscript; 160, 161; 160, 169; 161, call; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:np; 164, identifier:where; 165, argument_list; 165, 166; 166, comparison_operator:>; 166, 167; 166, 168; 167, identifier:votesByCell; 168, integer:0; 169, integer:0; 170, attribute; 170, 171; 170, 172; 171, identifier:self; 172, identifier:activeCells | def compute(self, sensorToBodyByColumn, sensorToSpecificObjectByColumn):
votesByCell = np.zeros(self.cellCount, dtype="int")
self.activeSegmentsByColumn = []
for (connections,
activeSensorToBodyCells,
activeSensorToSpecificObjectCells) in zip(self.connectionsByColumn,
sensorToBodyByColumn,
sensorToSpecificObjectByColumn):
overlaps = connections.computeActivity({
"sensorToBody": activeSensorToBodyCells,
"sensorToSpecificObject": activeSensorToSpecificObjectCells,
})
activeSegments = np.where(overlaps >= 2)[0]
votes = connections.mapSegmentsToCells(activeSegments)
votes = np.unique(votes)
votesByCell[votes] += 1
self.activeSegmentsByColumn.append(activeSegments)
candidates = np.where(votesByCell == np.max(votesByCell))[0]
self.activeCells = np.intersect1d(self.activeCells, candidates)
if self.activeCells.size == 0:
self.activeCells = candidates
self.inhibitedCells = np.setdiff1d(np.where(votesByCell > 0)[0],
self.activeCells) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:metricCompute; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:sensorToBody; 6, identifier:bodyToSpecificObject; 7, block; 7, 8; 7, 25; 7, 40; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:overlaps; 11, call; 11, 12; 11, 17; 12, attribute; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:metricConnections; 16, identifier:computeActivity; 17, argument_list; 17, 18; 18, dictionary; 18, 19; 18, 22; 19, pair; 19, 20; 19, 21; 20, string:"bodyToSpecificObject"; 21, identifier:bodyToSpecificObject; 22, pair; 22, 23; 22, 24; 23, string:"sensorToBody"; 24, identifier:sensorToBody; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:activeMetricSegments; 30, subscript; 30, 31; 30, 39; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:np; 34, identifier:where; 35, argument_list; 35, 36; 36, comparison_operator:>=; 36, 37; 36, 38; 37, identifier:overlaps; 38, integer:2; 39, integer:0; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:activeCells; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:np; 48, identifier:unique; 49, argument_list; 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:metricConnections; 55, identifier:mapSegmentsToCells; 56, argument_list; 56, 57; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:activeMetricSegments | def metricCompute(self, sensorToBody, bodyToSpecificObject):
overlaps = self.metricConnections.computeActivity({
"bodyToSpecificObject": bodyToSpecificObject,
"sensorToBody": sensorToBody,
})
self.activeMetricSegments = np.where(overlaps >= 2)[0]
self.activeCells = np.unique(
self.metricConnections.mapSegmentsToCells(
self.activeMetricSegments)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:compute; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:feedforwardInput; 7, tuple; 8, default_parameter; 8, 9; 8, 10; 9, identifier:lateralInputs; 10, tuple; 11, default_parameter; 11, 12; 11, 13; 12, identifier:feedforwardGrowthCandidates; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:learn; 16, True; 17, default_parameter; 17, 18; 17, 19; 18, identifier:predictedInput; 19, None; 20, block; 20, 21; 20, 30; 21, if_statement; 21, 22; 21, 25; 22, comparison_operator:is; 22, 23; 22, 24; 23, identifier:feedforwardGrowthCandidates; 24, None; 25, block; 25, 26; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:feedforwardGrowthCandidates; 29, identifier:feedforwardInput; 30, if_statement; 30, 31; 30, 33; 30, 42; 30, 57; 31, not_operator; 31, 32; 32, identifier:learn; 33, block; 33, 34; 34, expression_statement; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:_computeInferenceMode; 39, argument_list; 39, 40; 39, 41; 40, identifier:feedforwardInput; 41, identifier:lateralInputs; 42, elif_clause; 42, 43; 42, 47; 43, not_operator; 43, 44; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:onlineLearning; 47, block; 47, 48; 48, expression_statement; 48, 49; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:_computeLearningMode; 53, argument_list; 53, 54; 53, 55; 53, 56; 54, identifier:feedforwardInput; 55, identifier:lateralInputs; 56, identifier:feedforwardGrowthCandidates; 57, else_clause; 57, 58; 58, block; 58, 59; 59, if_statement; 59, 60; 59, 73; 59, 111; 59, 144; 60, parenthesized_expression; 60, 61; 61, boolean_operator:and; 61, 62; 61, 65; 62, comparison_operator:is; 62, 63; 62, 64; 63, identifier:predictedInput; 64, None; 65, comparison_operator:>; 65, 66; 65, 70; 66, call; 66, 67; 66, 68; 67, identifier:len; 68, argument_list; 68, 69; 69, identifier:predictedInput; 70, attribute; 70, 71; 70, 72; 71, identifier:self; 72, identifier:predictedInhibitionThreshold; 73, block; 73, 74; 73, 84; 73, 94; 73, 102; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:predictedActiveInput; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:numpy; 80, identifier:intersect1d; 81, argument_list; 81, 82; 81, 83; 82, identifier:feedforwardInput; 83, identifier:predictedInput; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:predictedGrowthCandidates; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:numpy; 90, identifier:intersect1d; 91, argument_list; 91, 92; 91, 93; 92, identifier:feedforwardGrowthCandidates; 93, identifier:predictedInput; 94, expression_statement; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:self; 98, identifier:_computeInferenceMode; 99, argument_list; 99, 100; 99, 101; 100, identifier:predictedActiveInput; 101, identifier:lateralInputs; 102, expression_statement; 102, 103; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:self; 106, identifier:_computeLearningMode; 107, argument_list; 107, 108; 107, 109; 107, 110; 108, identifier:predictedActiveInput; 109, identifier:lateralInputs; 110, identifier:feedforwardGrowthCandidates; 111, elif_clause; 111, 112; 111, 126; 112, not_operator; 112, 113; 113, comparison_operator:<=; 113, 114; 113, 117; 113, 123; 114, attribute; 114, 115; 114, 116; 115, identifier:self; 116, identifier:minSdrSize; 117, call; 117, 118; 117, 119; 118, identifier:len; 119, argument_list; 119, 120; 120, attribute; 120, 121; 120, 122; 121, identifier:self; 122, identifier:activeCells; 123, attribute; 123, 124; 123, 125; 124, identifier:self; 125, identifier:maxSdrSize; 126, block; 126, 127; 126, 135; 127, expression_statement; 127, 128; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:self; 131, identifier:_computeInferenceMode; 132, argument_list; 132, 133; 132, 134; 133, identifier:feedforwardInput; 134, identifier:lateralInputs; 135, expression_statement; 135, 136; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:self; 139, identifier:_computeLearningMode; 140, argument_list; 140, 141; 140, 142; 140, 143; 141, identifier:feedforwardInput; 142, identifier:lateralInputs; 143, identifier:feedforwardGrowthCandidates; 144, else_clause; 144, 145; 145, block; 145, 146; 146, expression_statement; 146, 147; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:self; 150, identifier:_computeLearningMode; 151, argument_list; 151, 152; 151, 153; 151, 154; 152, identifier:feedforwardInput; 153, identifier:lateralInputs; 154, identifier:feedforwardGrowthCandidates | def compute(self, feedforwardInput=(), lateralInputs=(),
feedforwardGrowthCandidates=None, learn=True,
predictedInput = None,):
if feedforwardGrowthCandidates is None:
feedforwardGrowthCandidates = feedforwardInput
if not learn:
self._computeInferenceMode(feedforwardInput, lateralInputs)
elif not self.onlineLearning:
self._computeLearningMode(feedforwardInput, lateralInputs,
feedforwardGrowthCandidates)
else:
if (predictedInput is not None and
len(predictedInput) > self.predictedInhibitionThreshold):
predictedActiveInput = numpy.intersect1d(feedforwardInput,
predictedInput)
predictedGrowthCandidates = numpy.intersect1d(
feedforwardGrowthCandidates, predictedInput)
self._computeInferenceMode(predictedActiveInput, lateralInputs)
self._computeLearningMode(predictedActiveInput, lateralInputs,
feedforwardGrowthCandidates)
elif not self.minSdrSize <= len(self.activeCells) <= self.maxSdrSize:
self._computeInferenceMode(feedforwardInput, lateralInputs)
self._computeLearningMode(feedforwardInput, lateralInputs,
feedforwardGrowthCandidates)
else:
self._computeLearningMode(feedforwardInput, lateralInputs,
feedforwardGrowthCandidates) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:_learn; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 3, 12; 3, 13; 4, identifier:permanences; 5, identifier:rng; 6, identifier:activeCells; 7, identifier:activeInput; 8, identifier:growthCandidateInput; 9, identifier:sampleSize; 10, identifier:initialPermanence; 11, identifier:permanenceIncrement; 12, identifier:permanenceDecrement; 13, identifier:connectedPermanence; 14, block; 14, 15; 14, 24; 14, 34; 14, 43; 15, expression_statement; 15, 16; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:permanences; 19, identifier:incrementNonZerosOnOuter; 20, argument_list; 20, 21; 20, 22; 20, 23; 21, identifier:activeCells; 22, identifier:activeInput; 23, identifier:permanenceIncrement; 24, expression_statement; 24, 25; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:permanences; 28, identifier:incrementNonZerosOnRowsExcludingCols; 29, argument_list; 29, 30; 29, 31; 29, 32; 30, identifier:activeCells; 31, identifier:activeInput; 32, unary_operator:-; 32, 33; 33, identifier:permanenceDecrement; 34, expression_statement; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:permanences; 38, identifier:clipRowsBelowAndAbove; 39, argument_list; 39, 40; 39, 41; 39, 42; 40, identifier:activeCells; 41, float:0.0; 42, float:1.0; 43, if_statement; 43, 44; 43, 48; 43, 58; 44, comparison_operator:==; 44, 45; 44, 46; 45, identifier:sampleSize; 46, unary_operator:-; 46, 47; 47, integer:1; 48, block; 48, 49; 49, expression_statement; 49, 50; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:permanences; 53, identifier:setZerosOnOuter; 54, argument_list; 54, 55; 54, 56; 54, 57; 55, identifier:activeCells; 56, identifier:activeInput; 57, identifier:initialPermanence; 58, else_clause; 58, 59; 59, block; 59, 60; 59, 70; 59, 85; 59, 96; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:existingSynapseCounts; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:permanences; 66, identifier:nNonZerosPerRowOnCols; 67, argument_list; 67, 68; 67, 69; 68, identifier:activeCells; 69, identifier:activeInput; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:maxNewByCell; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:numpy; 76, identifier:empty; 77, argument_list; 77, 78; 77, 82; 78, call; 78, 79; 78, 80; 79, identifier:len; 80, argument_list; 80, 81; 81, identifier:activeCells; 82, keyword_argument; 82, 83; 82, 84; 83, identifier:dtype; 84, string:"int32"; 85, expression_statement; 85, 86; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:numpy; 89, identifier:subtract; 90, argument_list; 90, 91; 90, 92; 90, 93; 91, identifier:sampleSize; 92, identifier:existingSynapseCounts; 93, keyword_argument; 93, 94; 93, 95; 94, identifier:out; 95, identifier:maxNewByCell; 96, expression_statement; 96, 97; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:permanences; 100, identifier:setRandomZerosOnOuter; 101, argument_list; 101, 102; 101, 103; 101, 104; 101, 105; 101, 106; 102, identifier:activeCells; 103, identifier:growthCandidateInput; 104, identifier:maxNewByCell; 105, identifier:initialPermanence; 106, identifier:rng | def _learn(
permanences, rng,
activeCells, activeInput, growthCandidateInput,
sampleSize, initialPermanence, permanenceIncrement,
permanenceDecrement, connectedPermanence):
permanences.incrementNonZerosOnOuter(
activeCells, activeInput, permanenceIncrement)
permanences.incrementNonZerosOnRowsExcludingCols(
activeCells, activeInput, -permanenceDecrement)
permanences.clipRowsBelowAndAbove(
activeCells, 0.0, 1.0)
if sampleSize == -1:
permanences.setZerosOnOuter(
activeCells, activeInput, initialPermanence)
else:
existingSynapseCounts = permanences.nNonZerosPerRowOnCols(
activeCells, activeInput)
maxNewByCell = numpy.empty(len(activeCells), dtype="int32")
numpy.subtract(sampleSize, existingSynapseCounts, out=maxNewByCell)
permanences.setRandomZerosOnOuter(
activeCells, growthCandidateInput, maxNewByCell, initialPermanence, rng) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:compute; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:deltaLocation; 7, tuple; 8, default_parameter; 8, 9; 8, 10; 9, identifier:newLocation; 10, tuple; 11, default_parameter; 11, 12; 11, 13; 12, identifier:featureLocationInput; 13, tuple; 14, default_parameter; 14, 15; 14, 16; 15, identifier:featureLocationGrowthCandidates; 16, tuple; 17, default_parameter; 17, 18; 17, 19; 18, identifier:learn; 19, True; 20, block; 20, 21; 20, 27; 20, 72; 20, 123; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:prevActiveCells; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:activeCells; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:activeDeltaSegments; 32, subscript; 32, 33; 32, 71; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:np; 36, identifier:where; 37, argument_list; 37, 38; 38, binary_operator:&; 38, 39; 38, 55; 39, parenthesized_expression; 39, 40; 40, comparison_operator:>=; 40, 41; 40, 52; 41, call; 41, 42; 41, 47; 42, attribute; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:internalConnections; 46, identifier:computeActivity; 47, argument_list; 47, 48; 47, 49; 48, identifier:prevActiveCells; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:connectedPermanence; 52, attribute; 52, 53; 52, 54; 53, identifier:self; 54, identifier:activationThreshold; 55, parenthesized_expression; 55, 56; 56, comparison_operator:>=; 56, 57; 56, 68; 57, call; 57, 58; 57, 63; 58, attribute; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:deltaConnections; 62, identifier:computeActivity; 63, argument_list; 63, 64; 63, 65; 64, identifier:deltaLocation; 65, attribute; 65, 66; 65, 67; 66, identifier:self; 67, identifier:connectedPermanence; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:activationThreshold; 71, integer:0; 72, if_statement; 72, 73; 72, 79; 72, 107; 73, comparison_operator:==; 73, 74; 73, 78; 74, call; 74, 75; 74, 76; 75, identifier:len; 76, argument_list; 76, 77; 77, identifier:deltaLocation; 78, integer:0; 79, block; 79, 80; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:self; 84, identifier:activeFeatureLocationSegments; 85, subscript; 85, 86; 85, 106; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:np; 89, identifier:where; 90, argument_list; 90, 91; 91, comparison_operator:>=; 91, 92; 91, 103; 92, call; 92, 93; 92, 98; 93, attribute; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:self; 96, identifier:featureLocationConnections; 97, identifier:computeActivity; 98, argument_list; 98, 99; 98, 100; 99, identifier:featureLocationInput; 100, attribute; 100, 101; 100, 102; 101, identifier:self; 102, identifier:connectedPermanence; 103, attribute; 103, 104; 103, 105; 104, identifier:self; 105, identifier:activationThreshold; 106, integer:0; 107, else_clause; 107, 108; 108, block; 108, 109; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:self; 113, identifier:activeFeatureLocationSegments; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:np; 117, identifier:empty; 118, argument_list; 118, 119; 118, 120; 119, integer:0; 120, keyword_argument; 120, 121; 120, 122; 121, identifier:dtype; 122, string:"uint32"; 123, if_statement; 123, 124; 123, 130; 123, 158; 123, 244; 124, comparison_operator:>; 124, 125; 124, 129; 125, call; 125, 126; 125, 127; 126, identifier:len; 127, argument_list; 127, 128; 128, identifier:newLocation; 129, integer:0; 130, block; 130, 131; 130, 137; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:self; 135, identifier:activeCells; 136, identifier:newLocation; 137, if_statement; 137, 138; 137, 139; 138, identifier:learn; 139, block; 139, 140; 139, 149; 140, expression_statement; 140, 141; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:self; 144, identifier:_learnTransition; 145, argument_list; 145, 146; 145, 147; 145, 148; 146, identifier:prevActiveCells; 147, identifier:deltaLocation; 148, identifier:newLocation; 149, expression_statement; 149, 150; 150, call; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:self; 153, identifier:_learnFeatureLocationPair; 154, argument_list; 154, 155; 154, 156; 154, 157; 155, identifier:newLocation; 156, identifier:featureLocationInput; 157, identifier:featureLocationGrowthCandidates; 158, elif_clause; 158, 159; 158, 165; 159, comparison_operator:>; 159, 160; 159, 164; 160, call; 160, 161; 160, 162; 161, identifier:len; 162, argument_list; 162, 163; 163, identifier:prevActiveCells; 164, integer:0; 165, block; 165, 166; 166, if_statement; 166, 167; 166, 173; 166, 198; 167, comparison_operator:>; 167, 168; 167, 172; 168, call; 168, 169; 168, 170; 169, identifier:len; 170, argument_list; 170, 171; 171, identifier:deltaLocation; 172, integer:0; 173, block; 173, 174; 173, 187; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 177; 176, identifier:cellsForDeltaSegments; 177, call; 177, 178; 177, 183; 178, attribute; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:self; 181, identifier:internalConnections; 182, identifier:mapSegmentsToCells; 183, argument_list; 183, 184; 184, attribute; 184, 185; 184, 186; 185, identifier:self; 186, identifier:activeDeltaSegments; 187, expression_statement; 187, 188; 188, assignment; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:self; 191, identifier:activeCells; 192, call; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:np; 195, identifier:unique; 196, argument_list; 196, 197; 197, identifier:cellsForDeltaSegments; 198, else_clause; 198, 199; 199, block; 199, 200; 200, if_statement; 200, 201; 200, 209; 200, 236; 201, comparison_operator:>; 201, 202; 201, 208; 202, call; 202, 203; 202, 204; 203, identifier:len; 204, argument_list; 204, 205; 205, attribute; 205, 206; 205, 207; 206, identifier:self; 207, identifier:activeFeatureLocationSegments; 208, integer:0; 209, block; 209, 210; 209, 224; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 213; 212, identifier:cellsForFeatureLocationSegments; 213, parenthesized_expression; 213, 214; 214, call; 214, 215; 214, 220; 215, attribute; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:self; 218, identifier:featureLocationConnections; 219, identifier:mapSegmentsToCells; 220, argument_list; 220, 221; 221, attribute; 221, 222; 221, 223; 222, identifier:self; 223, identifier:activeFeatureLocationSegments; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, identifier:self; 228, identifier:activeCells; 229, call; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:np; 232, identifier:intersect1d; 233, argument_list; 233, 234; 233, 235; 234, identifier:prevActiveCells; 235, identifier:cellsForFeatureLocationSegments; 236, else_clause; 236, 237; 237, block; 237, 238; 238, expression_statement; 238, 239; 239, assignment; 239, 240; 239, 243; 240, attribute; 240, 241; 240, 242; 241, identifier:self; 242, identifier:activeCells; 243, identifier:prevActiveCells; 244, elif_clause; 244, 245; 244, 251; 245, comparison_operator:>; 245, 246; 245, 250; 246, call; 246, 247; 246, 248; 247, identifier:len; 248, argument_list; 248, 249; 249, identifier:featureLocationInput; 250, integer:0; 251, block; 251, 252; 251, 266; 252, expression_statement; 252, 253; 253, assignment; 253, 254; 253, 255; 254, identifier:cellsForFeatureLocationSegments; 255, parenthesized_expression; 255, 256; 256, call; 256, 257; 256, 262; 257, attribute; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, identifier:self; 260, identifier:featureLocationConnections; 261, identifier:mapSegmentsToCells; 262, argument_list; 262, 263; 263, attribute; 263, 264; 263, 265; 264, identifier:self; 265, identifier:activeFeatureLocationSegments; 266, expression_statement; 266, 267; 267, assignment; 267, 268; 267, 271; 268, attribute; 268, 269; 268, 270; 269, identifier:self; 270, identifier:activeCells; 271, call; 271, 272; 271, 275; 272, attribute; 272, 273; 272, 274; 273, identifier:np; 274, identifier:unique; 275, argument_list; 275, 276; 276, identifier:cellsForFeatureLocationSegments | def compute(self, deltaLocation=(), newLocation=(),
featureLocationInput=(), featureLocationGrowthCandidates=(),
learn=True):
prevActiveCells = self.activeCells
self.activeDeltaSegments = np.where(
(self.internalConnections.computeActivity(
prevActiveCells, self.connectedPermanence
) >= self.activationThreshold)
&
(self.deltaConnections.computeActivity(
deltaLocation, self.connectedPermanence
) >= self.activationThreshold))[0]
if len(deltaLocation) == 0:
self.activeFeatureLocationSegments = np.where(
self.featureLocationConnections.computeActivity(
featureLocationInput, self.connectedPermanence
) >= self.activationThreshold)[0]
else:
self.activeFeatureLocationSegments = np.empty(0, dtype="uint32")
if len(newLocation) > 0:
self.activeCells = newLocation
if learn:
self._learnTransition(prevActiveCells, deltaLocation, newLocation)
self._learnFeatureLocationPair(newLocation, featureLocationInput,
featureLocationGrowthCandidates)
elif len(prevActiveCells) > 0:
if len(deltaLocation) > 0:
cellsForDeltaSegments = self.internalConnections.mapSegmentsToCells(
self.activeDeltaSegments)
self.activeCells = np.unique(cellsForDeltaSegments)
else:
if len(self.activeFeatureLocationSegments) > 0:
cellsForFeatureLocationSegments = (
self.featureLocationConnections.mapSegmentsToCells(
self.activeFeatureLocationSegments))
self.activeCells = np.intersect1d(prevActiveCells,
cellsForFeatureLocationSegments)
else:
self.activeCells = prevActiveCells
elif len(featureLocationInput) > 0:
cellsForFeatureLocationSegments = (
self.featureLocationConnections.mapSegmentsToCells(
self.activeFeatureLocationSegments))
self.activeCells = np.unique(cellsForFeatureLocationSegments) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:getmerge; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 4, identifier:self; 5, identifier:path; 6, identifier:dst; 7, default_parameter; 7, 8; 7, 9; 8, identifier:newline; 9, False; 10, default_parameter; 10, 11; 10, 12; 11, identifier:check_crc; 12, False; 13, block; 13, 14; 13, 16; 13, 25; 13, 34; 13, 40; 13, 48; 13, 70; 14, expression_statement; 14, 15; 15, string:''' Get all the files in the directories that
match the source file pattern and merge and sort them to only
one file on local fs.
:param paths: Directory containing files that will be merged
:type paths: string
:param dst: Path of file that will be written
:type dst: string
:param nl: Add a newline character at the end of each file.
:type nl: boolean
:returns: string content of the merged file at dst
'''; 16, if_statement; 16, 17; 16, 19; 17, not_operator; 17, 18; 18, identifier:path; 19, block; 19, 20; 20, raise_statement; 20, 21; 21, call; 21, 22; 21, 23; 22, identifier:InvalidInputException; 23, argument_list; 23, 24; 24, string:"getmerge: no path given"; 25, if_statement; 25, 26; 25, 28; 26, not_operator; 26, 27; 27, identifier:dst; 28, block; 28, 29; 29, raise_statement; 29, 30; 30, call; 30, 31; 30, 32; 31, identifier:InvalidInputException; 32, argument_list; 32, 33; 33, string:"getmerge: no destination given"; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:temporary_target; 37, binary_operator:%; 37, 38; 37, 39; 38, string:"%s._COPYING_"; 39, identifier:dst; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:f; 43, call; 43, 44; 43, 45; 44, identifier:open; 45, argument_list; 45, 46; 45, 47; 46, identifier:temporary_target; 47, string:'w'; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:processor; 51, lambda; 51, 52; 51, 61; 52, lambda_parameters; 52, 53; 52, 54; 52, 55; 52, 58; 53, identifier:path; 54, identifier:node; 55, default_parameter; 55, 56; 55, 57; 56, identifier:dst; 57, identifier:dst; 58, default_parameter; 58, 59; 58, 60; 59, identifier:check_crc; 60, identifier:check_crc; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:self; 64, identifier:_handle_getmerge; 65, argument_list; 65, 66; 65, 67; 65, 68; 65, 69; 66, identifier:path; 67, identifier:node; 68, identifier:dst; 69, identifier:check_crc; 70, try_statement; 70, 71; 70, 176; 71, block; 71, 72; 71, 156; 72, for_statement; 72, 73; 72, 74; 72, 91; 73, identifier:item; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:_find_items; 78, argument_list; 78, 79; 78, 81; 78, 82; 78, 85; 78, 88; 79, list:[path]; 79, 80; 80, identifier:path; 81, identifier:processor; 82, keyword_argument; 82, 83; 82, 84; 83, identifier:include_toplevel; 84, True; 85, keyword_argument; 85, 86; 85, 87; 86, identifier:recurse; 87, False; 88, keyword_argument; 88, 89; 88, 90; 89, identifier:include_children; 90, True; 91, block; 91, 92; 91, 142; 92, for_statement; 92, 93; 92, 94; 92, 95; 93, identifier:load; 94, identifier:item; 95, block; 95, 96; 96, if_statement; 96, 97; 96, 100; 96, 110; 97, subscript; 97, 98; 97, 99; 98, identifier:load; 99, string:'result'; 100, block; 100, 101; 101, expression_statement; 101, 102; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:f; 105, identifier:write; 106, argument_list; 106, 107; 107, subscript; 107, 108; 107, 109; 108, identifier:load; 109, string:'response'; 110, elif_clause; 110, 111; 110, 117; 111, not_operator; 111, 112; 112, comparison_operator:is; 112, 113; 112, 116; 113, subscript; 113, 114; 113, 115; 114, identifier:load; 115, string:'error'; 116, string:''; 117, block; 117, 118; 117, 135; 118, if_statement; 118, 119; 118, 127; 119, call; 119, 120; 119, 125; 120, attribute; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:os; 123, identifier:path; 124, identifier:isfile; 125, argument_list; 125, 126; 126, identifier:temporary_target; 127, block; 127, 128; 128, expression_statement; 128, 129; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:os; 132, identifier:remove; 133, argument_list; 133, 134; 134, identifier:temporary_target; 135, raise_statement; 135, 136; 136, call; 136, 137; 136, 138; 137, identifier:FatalException; 138, argument_list; 138, 139; 139, subscript; 139, 140; 139, 141; 140, identifier:load; 141, string:'error'; 142, if_statement; 142, 143; 142, 148; 143, boolean_operator:and; 143, 144; 143, 145; 144, identifier:newline; 145, subscript; 145, 146; 145, 147; 146, identifier:load; 147, string:'response'; 148, block; 148, 149; 149, expression_statement; 149, 150; 150, call; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:f; 153, identifier:write; 154, argument_list; 154, 155; 155, string:"\n"; 156, expression_statement; 156, 157; 157, yield; 157, 158; 158, dictionary; 158, 159; 158, 162; 158, 165; 158, 168; 158, 173; 159, pair; 159, 160; 159, 161; 160, string:"path"; 161, identifier:dst; 162, pair; 162, 163; 162, 164; 163, string:"response"; 164, string:''; 165, pair; 165, 166; 165, 167; 166, string:"result"; 167, True; 168, pair; 168, 169; 168, 170; 169, string:"error"; 170, subscript; 170, 171; 170, 172; 171, identifier:load; 172, string:'error'; 173, pair; 173, 174; 173, 175; 174, string:"source_path"; 175, identifier:path; 176, finally_clause; 176, 177; 177, block; 177, 178; 178, if_statement; 178, 179; 178, 187; 179, call; 179, 180; 179, 185; 180, attribute; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:os; 183, identifier:path; 184, identifier:isfile; 185, argument_list; 185, 186; 186, identifier:temporary_target; 187, block; 187, 188; 187, 194; 188, expression_statement; 188, 189; 189, call; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:f; 192, identifier:close; 193, argument_list; 194, expression_statement; 194, 195; 195, call; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:os; 198, identifier:rename; 199, argument_list; 199, 200; 199, 201; 200, identifier:temporary_target; 201, identifier:dst | def getmerge(self, path, dst, newline=False, check_crc=False):
''' Get all the files in the directories that
match the source file pattern and merge and sort them to only
one file on local fs.
:param paths: Directory containing files that will be merged
:type paths: string
:param dst: Path of file that will be written
:type dst: string
:param nl: Add a newline character at the end of each file.
:type nl: boolean
:returns: string content of the merged file at dst
'''
if not path:
raise InvalidInputException("getmerge: no path given")
if not dst:
raise InvalidInputException("getmerge: no destination given")
temporary_target = "%s._COPYING_" % dst
f = open(temporary_target, 'w')
processor = lambda path, node, dst=dst, check_crc=check_crc: self._handle_getmerge(path, node, dst, check_crc)
try:
for item in self._find_items([path], processor, include_toplevel=True, recurse=False, include_children=True):
for load in item:
if load['result']:
f.write(load['response'])
elif not load['error'] is '':
if os.path.isfile(temporary_target):
os.remove(temporary_target)
raise FatalException(load['error'])
if newline and load['response']:
f.write("\n")
yield {"path": dst, "response": '', "result": True, "error": load['error'], "source_path": path}
finally:
if os.path.isfile(temporary_target):
f.close()
os.rename(temporary_target, dst) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:countByValue; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 6, return_statement; 6, 7; 7, call; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:transform; 11, argument_list; 11, 12; 12, lambda; 12, 13; 12, 15; 13, lambda_parameters; 13, 14; 14, identifier:rdd; 15, call; 15, 16; 15, 23; 16, attribute; 16, 17; 16, 22; 17, attribute; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:_context; 21, identifier:_context; 22, identifier:parallelize; 23, argument_list; 23, 24; 24, call; 24, 25; 24, 32; 25, attribute; 25, 26; 25, 31; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:rdd; 29, identifier:countByValue; 30, argument_list; 31, identifier:items; 32, argument_list | def countByValue(self):
return self.transform(
lambda rdd: self._context._context.parallelize(
rdd.countByValue().items())) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_contiguous_offsets; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:offsets; 6, block; 6, 7; 6, 13; 6, 41; 7, expression_statement; 7, 8; 8, call; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:offsets; 11, identifier:sort; 12, argument_list; 13, for_statement; 13, 14; 13, 15; 13, 24; 14, identifier:i; 15, call; 15, 16; 15, 17; 16, identifier:range; 17, argument_list; 17, 18; 18, binary_operator:-; 18, 19; 18, 23; 19, call; 19, 20; 19, 21; 20, identifier:len; 21, argument_list; 21, 22; 22, identifier:offsets; 23, integer:1; 24, block; 24, 25; 25, assert_statement; 25, 26; 25, 37; 26, comparison_operator:==; 26, 27; 26, 32; 27, binary_operator:+; 27, 28; 27, 31; 28, subscript; 28, 29; 28, 30; 29, identifier:offsets; 30, identifier:i; 31, integer:1; 32, subscript; 32, 33; 32, 34; 33, identifier:offsets; 34, binary_operator:+; 34, 35; 34, 36; 35, identifier:i; 36, integer:1; 37, binary_operator:%; 37, 38; 37, 39; 38, string:"Offsets not contiguous: %s"; 39, tuple; 39, 40; 40, identifier:offsets; 41, return_statement; 41, 42; 42, identifier:offsets | def _contiguous_offsets(self, offsets):
offsets.sort()
for i in range(len(offsets) - 1):
assert offsets[i] + 1 == offsets[i + 1], \
"Offsets not contiguous: %s" % (offsets,)
return offsets |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_collapse; 3, parameters; 3, 4; 4, identifier:intervals; 5, block; 5, 6; 5, 10; 5, 65; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:span; 9, None; 10, for_statement; 10, 11; 10, 14; 10, 15; 11, pattern_list; 11, 12; 11, 13; 12, identifier:start; 13, identifier:stop; 14, identifier:intervals; 15, block; 15, 16; 16, if_statement; 16, 17; 16, 20; 16, 29; 16, 47; 17, comparison_operator:is; 17, 18; 17, 19; 18, identifier:span; 19, None; 20, block; 20, 21; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:span; 24, call; 24, 25; 24, 26; 25, identifier:_Interval; 26, argument_list; 26, 27; 26, 28; 27, identifier:start; 28, identifier:stop; 29, elif_clause; 29, 30; 29, 36; 30, comparison_operator:<=; 30, 31; 30, 32; 30, 35; 31, identifier:start; 32, attribute; 32, 33; 32, 34; 33, identifier:span; 34, identifier:stop; 35, identifier:stop; 36, block; 36, 37; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:span; 40, call; 40, 41; 40, 42; 41, identifier:_Interval; 42, argument_list; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:span; 45, identifier:start; 46, identifier:stop; 47, elif_clause; 47, 48; 47, 53; 48, comparison_operator:>; 48, 49; 48, 50; 49, identifier:start; 50, attribute; 50, 51; 50, 52; 51, identifier:span; 52, identifier:stop; 53, block; 53, 54; 53, 57; 54, expression_statement; 54, 55; 55, yield; 55, 56; 56, identifier:span; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:span; 60, call; 60, 61; 60, 62; 61, identifier:_Interval; 62, argument_list; 62, 63; 62, 64; 63, identifier:start; 64, identifier:stop; 65, if_statement; 65, 66; 65, 69; 66, comparison_operator:is; 66, 67; 66, 68; 67, identifier:span; 68, None; 69, block; 69, 70; 70, expression_statement; 70, 71; 71, yield; 71, 72; 72, identifier:span | def _collapse(intervals):
span = None
for start, stop in intervals:
if span is None:
span = _Interval(start, stop)
elif start <= span.stop < stop:
span = _Interval(span.start, stop)
elif start > span.stop:
yield span
span = _Interval(start, stop)
if span is not None:
yield span |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:remove; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:index; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:hash; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:keepSorted; 13, True; 14, block; 14, 15; 14, 32; 14, 143; 14, 160; 15, if_statement; 15, 16; 15, 19; 16, comparison_operator:is; 16, 17; 16, 18; 17, identifier:index; 18, None; 19, block; 19, 20; 20, expression_statement; 20, 21; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:clibrebound; 24, identifier:reb_remove; 25, argument_list; 25, 26; 25, 30; 25, 31; 26, call; 26, 27; 26, 28; 27, identifier:byref; 28, argument_list; 28, 29; 29, identifier:self; 30, identifier:index; 31, identifier:keepSorted; 32, if_statement; 32, 33; 32, 36; 33, comparison_operator:is; 33, 34; 33, 35; 34, identifier:hash; 35, None; 36, block; 36, 37; 36, 44; 36, 54; 36, 80; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:hash_types; 40, expression_list; 40, 41; 40, 42; 40, 43; 41, identifier:c_uint32; 42, identifier:c_uint; 43, identifier:c_ulong; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:PY3; 47, comparison_operator:==; 47, 48; 47, 53; 48, subscript; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:sys; 51, identifier:version_info; 52, integer:0; 53, integer:3; 54, if_statement; 54, 55; 54, 56; 54, 67; 55, identifier:PY3; 56, block; 56, 57; 56, 62; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:string_types; 60, expression_list; 60, 61; 61, identifier:str; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:int_types; 65, expression_list; 65, 66; 66, identifier:int; 67, else_clause; 67, 68; 68, block; 68, 69; 68, 74; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:string_types; 72, expression_list; 72, 73; 73, identifier:basestring; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:int_types; 77, expression_list; 77, 78; 77, 79; 78, identifier:int; 79, identifier:long; 80, if_statement; 80, 81; 80, 86; 80, 102; 80, 124; 81, call; 81, 82; 81, 83; 82, identifier:isinstance; 83, argument_list; 83, 84; 83, 85; 84, identifier:hash; 85, identifier:string_types; 86, block; 86, 87; 87, expression_statement; 87, 88; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:clibrebound; 91, identifier:reb_remove_by_hash; 92, argument_list; 92, 93; 92, 97; 92, 101; 93, call; 93, 94; 93, 95; 94, identifier:byref; 95, argument_list; 95, 96; 96, identifier:self; 97, call; 97, 98; 97, 99; 98, identifier:rebhash; 99, argument_list; 99, 100; 100, identifier:hash; 101, identifier:keepSorted; 102, elif_clause; 102, 103; 102, 108; 103, call; 103, 104; 103, 105; 104, identifier:isinstance; 105, argument_list; 105, 106; 105, 107; 106, identifier:hash; 107, identifier:int_types; 108, block; 108, 109; 109, expression_statement; 109, 110; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:clibrebound; 113, identifier:reb_remove_by_hash; 114, argument_list; 114, 115; 114, 119; 114, 123; 115, call; 115, 116; 115, 117; 116, identifier:byref; 117, argument_list; 117, 118; 118, identifier:self; 119, call; 119, 120; 119, 121; 120, identifier:c_uint32; 121, argument_list; 121, 122; 122, identifier:hash; 123, identifier:keepSorted; 124, elif_clause; 124, 125; 124, 130; 125, call; 125, 126; 125, 127; 126, identifier:isinstance; 127, argument_list; 127, 128; 127, 129; 128, identifier:hash; 129, identifier:hash_types; 130, block; 130, 131; 131, expression_statement; 131, 132; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:clibrebound; 135, identifier:reb_remove_by_hash; 136, argument_list; 136, 137; 136, 141; 136, 142; 137, call; 137, 138; 137, 139; 138, identifier:byref; 139, argument_list; 139, 140; 140, identifier:self; 141, identifier:hash; 142, identifier:keepSorted; 143, if_statement; 143, 144; 143, 149; 144, call; 144, 145; 144, 146; 145, identifier:hasattr; 146, argument_list; 146, 147; 146, 148; 147, identifier:self; 148, string:'_widgets'; 149, block; 149, 150; 150, expression_statement; 150, 151; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:self; 154, identifier:_display_heartbeat; 155, argument_list; 155, 156; 156, call; 156, 157; 156, 158; 157, identifier:pointer; 158, argument_list; 158, 159; 159, identifier:self; 160, expression_statement; 160, 161; 161, call; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:self; 164, identifier:process_messages; 165, argument_list | def remove(self, index=None, hash=None, keepSorted=True):
if index is not None:
clibrebound.reb_remove(byref(self), index, keepSorted)
if hash is not None:
hash_types = c_uint32, c_uint, c_ulong
PY3 = sys.version_info[0] == 3
if PY3:
string_types = str,
int_types = int,
else:
string_types = basestring,
int_types = int, long
if isinstance(hash, string_types):
clibrebound.reb_remove_by_hash(byref(self), rebhash(hash), keepSorted)
elif isinstance(hash, int_types):
clibrebound.reb_remove_by_hash(byref(self), c_uint32(hash), keepSorted)
elif isinstance(hash, hash_types):
clibrebound.reb_remove_by_hash(byref(self), hash, keepSorted)
if hasattr(self, '_widgets'):
self._display_heartbeat(pointer(self))
self.process_messages() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:particles; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 14; 5, 18; 5, 41; 5, 47; 5, 76; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:sim; 9, attribute; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:_sim; 13, identifier:contents; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:ps; 17, list:[]; 18, if_statement; 18, 19; 18, 24; 18, 29; 19, comparison_operator:>=; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:testparticle; 23, integer:0; 24, block; 24, 25; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:N; 28, integer:1; 29, else_clause; 29, 30; 30, block; 30, 31; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:N; 34, binary_operator:-; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:sim; 37, identifier:N; 38, attribute; 38, 39; 38, 40; 39, identifier:sim; 40, identifier:N_var; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:ParticleList; 44, binary_operator:*; 44, 45; 44, 46; 45, identifier:Particle; 46, identifier:N; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:ps; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:ParticleList; 53, identifier:from_address; 54, argument_list; 54, 55; 55, binary_operator:+; 55, 56; 55, 66; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:ctypes; 59, identifier:addressof; 60, argument_list; 60, 61; 61, attribute; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:sim; 64, identifier:_particles; 65, identifier:contents; 66, binary_operator:*; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:index; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:ctypes; 73, identifier:sizeof; 74, argument_list; 74, 75; 75, identifier:Particle; 76, return_statement; 76, 77; 77, identifier:ps | def particles(self):
sim = self._sim.contents
ps = []
if self.testparticle>=0:
N = 1
else:
N = sim.N-sim.N_var
ParticleList = Particle*N
ps = ParticleList.from_address(ctypes.addressof(sim._particles.contents)+self.index*ctypes.sizeof(Particle))
return ps |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:filter_queryset; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:request; 6, identifier:queryset; 7, identifier:view; 8, block; 8, 9; 8, 17; 8, 28; 8, 39; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:ordering_param; 14, attribute; 14, 15; 14, 16; 15, identifier:view; 16, identifier:SORT; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:ordering; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:get_ordering; 24, argument_list; 24, 25; 24, 26; 24, 27; 25, identifier:request; 26, identifier:queryset; 27, identifier:view; 28, if_statement; 28, 29; 28, 30; 29, identifier:ordering; 30, block; 30, 31; 31, return_statement; 31, 32; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:queryset; 35, identifier:order_by; 36, argument_list; 36, 37; 37, list_splat; 37, 38; 38, identifier:ordering; 39, return_statement; 39, 40; 40, identifier:queryset | def filter_queryset(self, request, queryset, view):
self.ordering_param = view.SORT
ordering = self.get_ordering(request, queryset, view)
if ordering:
return queryset.order_by(*ordering)
return queryset |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:get_ordering; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:request; 6, identifier:queryset; 7, identifier:view; 8, block; 8, 9; 8, 20; 8, 62; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:params; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:view; 15, identifier:get_request_feature; 16, argument_list; 16, 17; 17, attribute; 17, 18; 17, 19; 18, identifier:view; 19, identifier:SORT; 20, if_statement; 20, 21; 20, 22; 21, identifier:params; 22, block; 22, 23; 22, 35; 22, 48; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:fields; 26, list_comprehension; 26, 27; 26, 32; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:param; 30, identifier:strip; 31, argument_list; 32, for_in_clause; 32, 33; 32, 34; 33, identifier:param; 34, identifier:params; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 40; 37, pattern_list; 37, 38; 37, 39; 38, identifier:valid_ordering; 39, identifier:invalid_ordering; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:remove_invalid_fields; 44, argument_list; 44, 45; 44, 46; 44, 47; 45, identifier:queryset; 46, identifier:fields; 47, identifier:view; 48, if_statement; 48, 49; 48, 50; 48, 58; 49, identifier:invalid_ordering; 50, block; 50, 51; 51, raise_statement; 51, 52; 52, call; 52, 53; 52, 54; 53, identifier:ValidationError; 54, argument_list; 54, 55; 55, binary_operator:%; 55, 56; 55, 57; 56, string:"Invalid filter field: %s"; 57, identifier:invalid_ordering; 58, else_clause; 58, 59; 59, block; 59, 60; 60, return_statement; 60, 61; 61, identifier:valid_ordering; 62, return_statement; 62, 63; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:self; 66, identifier:get_default_ordering; 67, argument_list; 67, 68; 68, identifier:view | def get_ordering(self, request, queryset, view):
params = view.get_request_feature(view.SORT)
if params:
fields = [param.strip() for param in params]
valid_ordering, invalid_ordering = self.remove_invalid_fields(
queryset, fields, view
)
if invalid_ordering:
raise ValidationError(
"Invalid filter field: %s" % invalid_ordering
)
else:
return valid_ordering
return self.get_default_ordering(view) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:remove_invalid_fields; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:queryset; 6, identifier:fields; 7, identifier:view; 8, block; 8, 9; 8, 13; 8, 17; 8, 76; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:valid_orderings; 12, list:[]; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:invalid_orderings; 16, list:[]; 17, for_statement; 17, 18; 17, 19; 17, 20; 18, identifier:term; 19, identifier:fields; 20, block; 20, 21; 20, 30; 20, 45; 20, 55; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:stripped_term; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:term; 27, identifier:lstrip; 28, argument_list; 28, 29; 29, string:'-'; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:reverse_sort_term; 33, conditional_expression:if; 33, 34; 33, 35; 33, 44; 34, string:''; 35, comparison_operator:is; 35, 36; 35, 40; 36, call; 36, 37; 36, 38; 37, identifier:len; 38, argument_list; 38, 39; 39, identifier:stripped_term; 40, call; 40, 41; 40, 42; 41, identifier:len; 42, argument_list; 42, 43; 43, identifier:term; 44, string:'-'; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:ordering; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:ordering_for; 52, argument_list; 52, 53; 52, 54; 53, identifier:stripped_term; 54, identifier:view; 55, if_statement; 55, 56; 55, 57; 55, 67; 56, identifier:ordering; 57, block; 57, 58; 58, expression_statement; 58, 59; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:valid_orderings; 62, identifier:append; 63, argument_list; 63, 64; 64, binary_operator:+; 64, 65; 64, 66; 65, identifier:reverse_sort_term; 66, identifier:ordering; 67, else_clause; 67, 68; 68, block; 68, 69; 69, expression_statement; 69, 70; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:invalid_orderings; 73, identifier:append; 74, argument_list; 74, 75; 75, identifier:term; 76, return_statement; 76, 77; 77, expression_list; 77, 78; 77, 79; 78, identifier:valid_orderings; 79, identifier:invalid_orderings | def remove_invalid_fields(self, queryset, fields, view):
valid_orderings = []
invalid_orderings = []
for term in fields:
stripped_term = term.lstrip('-')
reverse_sort_term = '' if len(stripped_term) is len(term) else '-'
ordering = self.ordering_for(stripped_term, view)
if ordering:
valid_orderings.append(reverse_sort_term + ordering)
else:
invalid_orderings.append(term)
return valid_orderings, invalid_orderings |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 1, 17; 2, function_name:_format_dataframe; 3, parameters; 3, 4; 3, 10; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:df; 6, type; 6, 7; 7, attribute; 7, 8; 7, 9; 8, identifier:pd; 9, identifier:DataFrame; 10, default_parameter; 10, 11; 10, 12; 11, identifier:nautical_units; 12, True; 13, type; 13, 14; 14, attribute; 14, 15; 14, 16; 15, identifier:pd; 16, identifier:DataFrame; 17, block; 17, 18; 17, 47; 17, 115; 17, 137; 17, 176; 18, if_statement; 18, 19; 18, 32; 19, boolean_operator:and; 19, 20; 19, 25; 20, comparison_operator:in; 20, 21; 20, 22; 21, string:"callsign"; 22, attribute; 22, 23; 22, 24; 23, identifier:df; 24, identifier:columns; 25, comparison_operator:==; 25, 26; 25, 31; 26, attribute; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:df; 29, identifier:callsign; 30, identifier:dtype; 31, identifier:object; 32, block; 32, 33; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:df; 37, identifier:callsign; 38, call; 38, 39; 38, 46; 39, attribute; 39, 40; 39, 45; 40, attribute; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:df; 43, identifier:callsign; 44, identifier:str; 45, identifier:strip; 46, argument_list; 47, if_statement; 47, 48; 47, 49; 48, identifier:nautical_units; 49, block; 49, 50; 49, 60; 49, 77; 49, 96; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:df; 54, identifier:altitude; 55, binary_operator:/; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:df; 58, identifier:altitude; 59, float:0.3048; 60, if_statement; 60, 61; 60, 66; 61, comparison_operator:in; 61, 62; 61, 63; 62, string:"geoaltitude"; 63, attribute; 63, 64; 63, 65; 64, identifier:df; 65, identifier:columns; 66, block; 66, 67; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:df; 71, identifier:geoaltitude; 72, binary_operator:/; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:df; 75, identifier:geoaltitude; 76, float:0.3048; 77, if_statement; 77, 78; 77, 83; 78, comparison_operator:in; 78, 79; 78, 80; 79, string:"groundspeed"; 80, attribute; 80, 81; 80, 82; 81, identifier:df; 82, identifier:columns; 83, block; 83, 84; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:df; 88, identifier:groundspeed; 89, binary_operator:*; 89, 90; 89, 95; 90, binary_operator:/; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:df; 93, identifier:groundspeed; 94, integer:1852; 95, integer:3600; 96, if_statement; 96, 97; 96, 102; 97, comparison_operator:in; 97, 98; 97, 99; 98, string:"vertical_rate"; 99, attribute; 99, 100; 99, 101; 100, identifier:df; 101, identifier:columns; 102, block; 102, 103; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:df; 107, identifier:vertical_rate; 108, binary_operator:*; 108, 109; 108, 114; 109, binary_operator:/; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:df; 112, identifier:vertical_rate; 113, float:0.3048; 114, integer:60; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:df; 119, identifier:timestamp; 120, call; 120, 121; 120, 135; 121, attribute; 121, 122; 121, 134; 122, attribute; 122, 123; 122, 133; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:pd; 126, identifier:to_datetime; 127, argument_list; 127, 128; 128, binary_operator:*; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:df; 131, identifier:timestamp; 132, float:1e9; 133, identifier:dt; 134, identifier:tz_localize; 135, argument_list; 135, 136; 136, string:"utc"; 137, if_statement; 137, 138; 137, 143; 138, comparison_operator:in; 138, 139; 138, 140; 139, string:"last_position"; 140, attribute; 140, 141; 140, 142; 141, identifier:df; 142, identifier:columns; 143, block; 143, 144; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:df; 147, call; 147, 148; 147, 156; 148, attribute; 148, 149; 148, 155; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:df; 152, identifier:query; 153, argument_list; 153, 154; 154, string:"last_position == last_position"; 155, identifier:assign; 156, argument_list; 156, 157; 157, keyword_argument; 157, 158; 157, 159; 158, identifier:last_position; 159, call; 159, 160; 159, 174; 160, attribute; 160, 161; 160, 173; 161, attribute; 161, 162; 161, 172; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:pd; 165, identifier:to_datetime; 166, argument_list; 166, 167; 167, binary_operator:*; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:df; 170, identifier:last_position; 171, float:1e9; 172, identifier:dt; 173, identifier:tz_localize; 174, argument_list; 174, 175; 175, string:"utc"; 176, return_statement; 176, 177; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:df; 180, identifier:sort_values; 181, argument_list; 181, 182; 182, string:"timestamp" | def _format_dataframe(
df: pd.DataFrame, nautical_units=True
) -> pd.DataFrame:
if "callsign" in df.columns and df.callsign.dtype == object:
df.callsign = df.callsign.str.strip()
if nautical_units:
df.altitude = df.altitude / 0.3048
if "geoaltitude" in df.columns:
df.geoaltitude = df.geoaltitude / 0.3048
if "groundspeed" in df.columns:
df.groundspeed = df.groundspeed / 1852 * 3600
if "vertical_rate" in df.columns:
df.vertical_rate = df.vertical_rate / 0.3048 * 60
df.timestamp = pd.to_datetime(df.timestamp * 1e9).dt.tz_localize("utc")
if "last_position" in df.columns:
df = df.query("last_position == last_position").assign(
last_position=pd.to_datetime(
df.last_position * 1e9
).dt.tz_localize("utc")
)
return df.sort_values("timestamp") |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:find_package_indexes_in_dir; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:simple_dir; 6, block; 6, 7; 6, 26; 6, 51; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:packages; 10, call; 10, 11; 10, 12; 11, identifier:sorted; 12, argument_list; 12, 13; 13, set_comprehension; 13, 14; 13, 18; 14, call; 14, 15; 14, 16; 15, identifier:canonicalize_name; 16, argument_list; 16, 17; 17, identifier:x; 18, for_in_clause; 18, 19; 18, 20; 19, identifier:x; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:os; 23, identifier:listdir; 24, argument_list; 24, 25; 25, identifier:simple_dir; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:packages; 29, list_comprehension; 29, 30; 29, 31; 29, 34; 30, identifier:x; 31, for_in_clause; 31, 32; 31, 33; 32, identifier:x; 33, identifier:packages; 34, if_clause; 34, 35; 35, call; 35, 36; 35, 41; 36, attribute; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:os; 39, identifier:path; 40, identifier:isdir; 41, argument_list; 41, 42; 42, call; 42, 43; 42, 48; 43, attribute; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:os; 46, identifier:path; 47, identifier:join; 48, argument_list; 48, 49; 48, 50; 49, identifier:simple_dir; 50, identifier:x; 51, return_statement; 51, 52; 52, identifier:packages | def find_package_indexes_in_dir(self, simple_dir):
packages = sorted(
{
canonicalize_name(x)
for x in os.listdir(simple_dir)
}
)
packages = [x for x in packages if os.path.isdir(os.path.join(simple_dir, x))]
return packages |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:factorize; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 11; 3, 14; 4, identifier:train; 5, identifier:test; 6, identifier:features; 7, default_parameter; 7, 8; 7, 9; 8, identifier:na_value; 9, unary_operator:-; 9, 10; 10, integer:9999; 11, default_parameter; 11, 12; 11, 13; 12, identifier:full; 13, False; 14, default_parameter; 14, 15; 14, 16; 15, identifier:sort; 16, True; 17, block; 17, 18; 17, 134; 18, for_statement; 18, 19; 18, 20; 18, 21; 19, identifier:column; 20, identifier:features; 21, block; 21, 22; 21, 72; 21, 85; 21, 98; 22, if_statement; 22, 23; 22, 24; 22, 54; 23, identifier:full; 24, block; 24, 25; 24, 40; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:vs; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:pd; 31, identifier:concat; 32, argument_list; 32, 33; 33, list:[train[column], test[column]]; 33, 34; 33, 37; 34, subscript; 34, 35; 34, 36; 35, identifier:train; 36, identifier:column; 37, subscript; 37, 38; 37, 39; 38, identifier:test; 39, identifier:column; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 45; 42, pattern_list; 42, 43; 42, 44; 43, identifier:labels; 44, identifier:indexer; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:pd; 48, identifier:factorize; 49, argument_list; 49, 50; 49, 51; 50, identifier:vs; 51, keyword_argument; 51, 52; 51, 53; 52, identifier:sort; 53, identifier:sort; 54, else_clause; 54, 55; 55, block; 55, 56; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 61; 58, pattern_list; 58, 59; 58, 60; 59, identifier:labels; 60, identifier:indexer; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:pd; 64, identifier:factorize; 65, argument_list; 65, 66; 65, 69; 66, subscript; 66, 67; 66, 68; 67, identifier:train; 68, identifier:column; 69, keyword_argument; 69, 70; 69, 71; 70, identifier:sort; 71, identifier:sort; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 77; 74, subscript; 74, 75; 74, 76; 75, identifier:train; 76, identifier:column; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:indexer; 80, identifier:get_indexer; 81, argument_list; 81, 82; 82, subscript; 82, 83; 82, 84; 83, identifier:train; 84, identifier:column; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 90; 87, subscript; 87, 88; 87, 89; 88, identifier:test; 89, identifier:column; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:indexer; 93, identifier:get_indexer; 94, argument_list; 94, 95; 95, subscript; 95, 96; 95, 97; 96, identifier:test; 97, identifier:column; 98, if_statement; 98, 99; 98, 103; 99, comparison_operator:!=; 99, 100; 99, 101; 100, identifier:na_value; 101, unary_operator:-; 101, 102; 102, integer:1; 103, block; 103, 104; 103, 119; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 109; 106, subscript; 106, 107; 106, 108; 107, identifier:train; 108, identifier:column; 109, call; 109, 110; 109, 115; 110, attribute; 110, 111; 110, 114; 111, subscript; 111, 112; 111, 113; 112, identifier:train; 113, identifier:column; 114, identifier:replace; 115, argument_list; 115, 116; 115, 118; 116, unary_operator:-; 116, 117; 117, integer:1; 118, identifier:na_value; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 124; 121, subscript; 121, 122; 121, 123; 122, identifier:test; 123, identifier:column; 124, call; 124, 125; 124, 130; 125, attribute; 125, 126; 125, 129; 126, subscript; 126, 127; 126, 128; 127, identifier:test; 128, identifier:column; 129, identifier:replace; 130, argument_list; 130, 131; 130, 133; 131, unary_operator:-; 131, 132; 132, integer:1; 133, identifier:na_value; 134, return_statement; 134, 135; 135, expression_list; 135, 136; 135, 137; 136, identifier:train; 137, identifier:test | def factorize(train, test, features, na_value=-9999, full=False, sort=True):
for column in features:
if full:
vs = pd.concat([train[column], test[column]])
labels, indexer = pd.factorize(vs, sort=sort)
else:
labels, indexer = pd.factorize(train[column], sort=sort)
train[column] = indexer.get_indexer(train[column])
test[column] = indexer.get_indexer(test[column])
if na_value != -1:
train[column] = train[column].replace(-1, na_value)
test[column] = test[column].replace(-1, na_value)
return train, test |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:preferred_ordinal; 3, parameters; 3, 4; 3, 5; 4, identifier:cls; 5, identifier:attr_name; 6, block; 6, 7; 6, 16; 6, 45; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:attr_name; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:cls; 13, identifier:map; 14, argument_list; 14, 15; 15, identifier:attr_name; 16, if_statement; 16, 17; 16, 22; 16, 34; 17, comparison_operator:in; 17, 18; 17, 19; 18, identifier:attr_name; 19, attribute; 19, 20; 19, 21; 20, identifier:cls; 21, identifier:preferred_order; 22, block; 22, 23; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:ordinal; 26, call; 26, 27; 26, 32; 27, attribute; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:cls; 30, identifier:preferred_order; 31, identifier:index; 32, argument_list; 32, 33; 33, identifier:attr_name; 34, else_clause; 34, 35; 35, block; 35, 36; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:ordinal; 39, call; 39, 40; 39, 41; 40, identifier:len; 41, argument_list; 41, 42; 42, attribute; 42, 43; 42, 44; 43, identifier:cls; 44, identifier:preferred_order; 45, return_statement; 45, 46; 46, tuple; 46, 47; 46, 48; 47, identifier:ordinal; 48, identifier:attr_name | def preferred_ordinal(cls, attr_name):
attr_name = cls.map(attr_name)
if attr_name in cls.preferred_order:
ordinal = cls.preferred_order.index(attr_name)
else:
ordinal = len(cls.preferred_order)
return (ordinal, attr_name) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:patience_sort; 3, parameters; 3, 4; 4, identifier:xs; 5, block; 5, 6; 5, 8; 5, 14; 6, expression_statement; 6, 7; 7, string:'''Patience sort an iterable, xs.
This function generates a series of pairs (x, pile), where "pile"
is the 0-based index of the pile "x" should be placed on top of.
Elements of "xs" must be less-than comparable.
'''; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:pile_tops; 11, call; 11, 12; 11, 13; 12, identifier:list; 13, argument_list; 14, for_statement; 14, 15; 14, 16; 14, 17; 15, identifier:x; 16, identifier:xs; 17, block; 17, 18; 17, 28; 17, 51; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:pile; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:bisect; 24, identifier:bisect_left; 25, argument_list; 25, 26; 25, 27; 26, identifier:pile_tops; 27, identifier:x; 28, if_statement; 28, 29; 28, 35; 28, 43; 29, comparison_operator:==; 29, 30; 29, 31; 30, identifier:pile; 31, call; 31, 32; 31, 33; 32, identifier:len; 33, argument_list; 33, 34; 34, identifier:pile_tops; 35, block; 35, 36; 36, expression_statement; 36, 37; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:pile_tops; 40, identifier:append; 41, argument_list; 41, 42; 42, identifier:x; 43, else_clause; 43, 44; 44, block; 44, 45; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 50; 47, subscript; 47, 48; 47, 49; 48, identifier:pile_tops; 49, identifier:pile; 50, identifier:x; 51, expression_statement; 51, 52; 52, yield; 52, 53; 53, expression_list; 53, 54; 53, 55; 54, identifier:x; 55, identifier:pile | def patience_sort(xs):
'''Patience sort an iterable, xs.
This function generates a series of pairs (x, pile), where "pile"
is the 0-based index of the pile "x" should be placed on top of.
Elements of "xs" must be less-than comparable.
'''
pile_tops = list()
for x in xs:
pile = bisect.bisect_left(pile_tops, x)
if pile == len(pile_tops):
pile_tops.append(x)
else:
pile_tops[pile] = x
yield x, pile |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort; 3, parameters; 3, 4; 4, identifier:args; 5, block; 5, 6; 5, 15; 5, 31; 5, 42; 5, 61; 5, 66; 5, 80; 5, 90; 5, 98; 5, 169; 5, 189; 5, 201; 5, 207; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:p; 9, call; 9, 10; 9, 11; 10, identifier:OptionParser; 11, argument_list; 11, 12; 12, attribute; 12, 13; 12, 14; 13, identifier:sort; 14, identifier:__doc__; 15, expression_statement; 15, 16; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:p; 19, identifier:add_option; 20, argument_list; 20, 21; 20, 22; 20, 25; 20, 28; 21, string:"--sizes"; 22, keyword_argument; 22, 23; 22, 24; 23, identifier:default; 24, False; 25, keyword_argument; 25, 26; 25, 27; 26, identifier:action; 27, string:"store_true"; 28, keyword_argument; 28, 29; 28, 30; 29, identifier:help; 30, string:"Sort by decreasing size [default: %default]"; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 36; 33, pattern_list; 33, 34; 33, 35; 34, identifier:opts; 35, identifier:args; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:p; 39, identifier:parse_args; 40, argument_list; 40, 41; 41, identifier:args; 42, if_statement; 42, 43; 42, 49; 43, comparison_operator:!=; 43, 44; 43, 48; 44, call; 44, 45; 44, 46; 45, identifier:len; 46, argument_list; 46, 47; 47, identifier:args; 48, integer:1; 49, block; 49, 50; 50, expression_statement; 50, 51; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:sys; 54, identifier:exit; 55, argument_list; 55, 56; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:p; 59, identifier:print_help; 60, argument_list; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 65; 63, pattern_list; 63, 64; 64, identifier:fastafile; 65, identifier:args; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:sortedfastafile; 69, binary_operator:+; 69, 70; 69, 79; 70, subscript; 70, 71; 70, 78; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:fastafile; 74, identifier:rsplit; 75, argument_list; 75, 76; 75, 77; 76, string:"."; 77, integer:1; 78, integer:0; 79, string:".sorted.fasta"; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:f; 83, call; 83, 84; 83, 85; 84, identifier:Fasta; 85, argument_list; 85, 86; 85, 87; 86, identifier:fastafile; 87, keyword_argument; 87, 88; 87, 89; 88, identifier:index; 89, False; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:fw; 93, call; 93, 94; 93, 95; 94, identifier:must_open; 95, argument_list; 95, 96; 95, 97; 96, identifier:sortedfastafile; 97, string:"w"; 98, if_statement; 98, 99; 98, 102; 98, 156; 99, attribute; 99, 100; 99, 101; 100, identifier:opts; 101, identifier:sizes; 102, block; 102, 103; 102, 127; 102, 146; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:sortlist; 106, call; 106, 107; 106, 108; 107, identifier:sorted; 108, argument_list; 108, 109; 108, 114; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:f; 112, identifier:itersizes; 113, argument_list; 114, keyword_argument; 114, 115; 114, 116; 115, identifier:key; 116, lambda; 116, 117; 116, 119; 117, lambda_parameters; 117, 118; 118, identifier:x; 119, tuple; 119, 120; 119, 124; 120, unary_operator:-; 120, 121; 121, subscript; 121, 122; 121, 123; 122, identifier:x; 123, integer:1; 124, subscript; 124, 125; 124, 126; 125, identifier:x; 126, integer:0; 127, expression_statement; 127, 128; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:logging; 131, identifier:debug; 132, argument_list; 132, 133; 133, call; 133, 134; 133, 138; 134, attribute; 134, 135; 134, 136; 134, 137; 135, string:"Sort by size: max: {0}, min: {1}"; 136, line_continuation:\; 137, identifier:format; 138, argument_list; 138, 139; 138, 142; 139, subscript; 139, 140; 139, 141; 140, identifier:sortlist; 141, integer:0; 142, subscript; 142, 143; 142, 144; 143, identifier:sortlist; 144, unary_operator:-; 144, 145; 145, integer:1; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:sortlist; 149, list_comprehension; 149, 150; 149, 151; 150, identifier:x; 151, for_in_clause; 151, 152; 151, 155; 152, pattern_list; 152, 153; 152, 154; 153, identifier:x; 154, identifier:s; 155, identifier:sortlist; 156, else_clause; 156, 157; 157, block; 157, 158; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 161; 160, identifier:sortlist; 161, call; 161, 162; 161, 163; 162, identifier:sorted; 163, argument_list; 163, 164; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:f; 167, identifier:iterkeys; 168, argument_list; 169, for_statement; 169, 170; 169, 171; 169, 172; 170, identifier:key; 171, identifier:sortlist; 172, block; 172, 173; 172, 179; 173, expression_statement; 173, 174; 174, assignment; 174, 175; 174, 176; 175, identifier:rec; 176, subscript; 176, 177; 176, 178; 177, identifier:f; 178, identifier:key; 179, expression_statement; 179, 180; 180, call; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:SeqIO; 183, identifier:write; 184, argument_list; 184, 185; 184, 187; 184, 188; 185, list:[rec]; 185, 186; 186, identifier:rec; 187, identifier:fw; 188, string:"fasta"; 189, expression_statement; 189, 190; 190, call; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:logging; 193, identifier:debug; 194, argument_list; 194, 195; 195, call; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, string:"Sorted file written to `{0}`."; 198, identifier:format; 199, argument_list; 199, 200; 200, identifier:sortedfastafile; 201, expression_statement; 201, 202; 202, call; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:fw; 205, identifier:close; 206, argument_list; 207, return_statement; 207, 208; 208, identifier:sortedfastafile | def sort(args):
p = OptionParser(sort.__doc__)
p.add_option("--sizes", default=False, action="store_true",
help="Sort by decreasing size [default: %default]")
opts, args = p.parse_args(args)
if len(args) != 1:
sys.exit(p.print_help())
fastafile, = args
sortedfastafile = fastafile.rsplit(".", 1)[0] + ".sorted.fasta"
f = Fasta(fastafile, index=False)
fw = must_open(sortedfastafile, "w")
if opts.sizes:
sortlist = sorted(f.itersizes(), key=lambda x: (-x[1], x[0]))
logging.debug("Sort by size: max: {0}, min: {1}".\
format(sortlist[0], sortlist[-1]))
sortlist = [x for x, s in sortlist]
else:
sortlist = sorted(f.iterkeys())
for key in sortlist:
rec = f[key]
SeqIO.write([rec], fw, "fasta")
logging.debug("Sorted file written to `{0}`.".format(sortedfastafile))
fw.close()
return sortedfastafile |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:posmap; 3, parameters; 3, 4; 4, identifier:args; 5, block; 5, 6; 5, 15; 5, 26; 5, 45; 5, 52; 5, 62; 5, 68; 5, 85; 5, 91; 5, 100; 5, 106; 5, 119; 5, 125; 5, 146; 5, 152; 5, 172; 5, 178; 5, 197; 5, 203; 5, 209; 5, 238; 5, 244; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:p; 9, call; 9, 10; 9, 11; 10, identifier:OptionParser; 11, argument_list; 11, 12; 12, attribute; 12, 13; 12, 14; 13, identifier:posmap; 14, identifier:__doc__; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 20; 17, pattern_list; 17, 18; 17, 19; 18, identifier:opts; 19, identifier:args; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:p; 23, identifier:parse_args; 24, argument_list; 24, 25; 25, identifier:args; 26, if_statement; 26, 27; 26, 33; 27, comparison_operator:!=; 27, 28; 27, 32; 28, call; 28, 29; 28, 30; 29, identifier:len; 30, argument_list; 30, 31; 31, identifier:args; 32, integer:3; 33, block; 33, 34; 34, expression_statement; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:sys; 38, identifier:exit; 39, argument_list; 39, 40; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:p; 43, identifier:print_help; 44, argument_list; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 51; 47, pattern_list; 47, 48; 47, 49; 47, 50; 48, identifier:frgscffile; 49, identifier:fastafile; 50, identifier:scf; 51, identifier:args; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:cmd; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, string:"faOneRecord {0} {1}"; 58, identifier:format; 59, argument_list; 59, 60; 59, 61; 60, identifier:fastafile; 61, identifier:scf; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:scffastafile; 65, binary_operator:+; 65, 66; 65, 67; 66, identifier:scf; 67, string:".fasta"; 68, if_statement; 68, 69; 68, 76; 69, not_operator; 69, 70; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:op; 73, identifier:exists; 74, argument_list; 74, 75; 75, identifier:scffastafile; 76, block; 76, 77; 77, expression_statement; 77, 78; 78, call; 78, 79; 78, 80; 79, identifier:sh; 80, argument_list; 80, 81; 80, 82; 81, identifier:cmd; 82, keyword_argument; 82, 83; 82, 84; 83, identifier:outfile; 84, identifier:scffastafile; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:sizesfile; 88, binary_operator:+; 88, 89; 88, 90; 89, identifier:scffastafile; 90, string:".sizes"; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:sizes; 94, attribute; 94, 95; 94, 99; 95, call; 95, 96; 95, 97; 96, identifier:Sizes; 97, argument_list; 97, 98; 98, identifier:scffastafile; 99, identifier:mapping; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:scfsize; 103, subscript; 103, 104; 103, 105; 104, identifier:sizes; 105, identifier:scf; 106, expression_statement; 106, 107; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:logging; 110, identifier:debug; 111, argument_list; 111, 112; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, string:"`{0}` has length of {1}."; 115, identifier:format; 116, argument_list; 116, 117; 116, 118; 117, identifier:scf; 118, identifier:scfsize; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:gapsbedfile; 122, binary_operator:+; 122, 123; 122, 124; 123, identifier:scf; 124, string:".gaps.bed"; 125, if_statement; 125, 126; 125, 133; 126, not_operator; 126, 127; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:op; 130, identifier:exists; 131, argument_list; 131, 132; 132, identifier:gapsbedfile; 133, block; 133, 134; 133, 141; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:args; 137, list:[scffastafile, "--bed", "--mingap=100"]; 137, 138; 137, 139; 137, 140; 138, identifier:scffastafile; 139, string:"--bed"; 140, string:"--mingap=100"; 141, expression_statement; 141, 142; 142, call; 142, 143; 142, 144; 143, identifier:gaps; 144, argument_list; 144, 145; 145, identifier:args; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:posmapfile; 149, binary_operator:+; 149, 150; 149, 151; 150, identifier:scf; 151, string:".posmap"; 152, if_statement; 152, 153; 152, 160; 153, not_operator; 153, 154; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:op; 157, identifier:exists; 158, argument_list; 158, 159; 159, identifier:posmapfile; 160, block; 160, 161; 160, 167; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:args; 164, list:[frgscffile, scf]; 164, 165; 164, 166; 165, identifier:frgscffile; 166, identifier:scf; 167, expression_statement; 167, 168; 168, call; 168, 169; 168, 170; 169, identifier:query; 170, argument_list; 170, 171; 171, identifier:args; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:bedfile; 175, binary_operator:+; 175, 176; 175, 177; 176, identifier:scf; 177, string:".bed"; 178, if_statement; 178, 179; 178, 186; 179, not_operator; 179, 180; 180, call; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:op; 183, identifier:exists; 184, argument_list; 184, 185; 185, identifier:bedfile; 186, block; 186, 187; 186, 192; 187, expression_statement; 187, 188; 188, assignment; 188, 189; 188, 190; 189, identifier:args; 190, list:[posmapfile]; 190, 191; 191, identifier:posmapfile; 192, expression_statement; 192, 193; 193, call; 193, 194; 193, 195; 194, identifier:bed; 195, argument_list; 195, 196; 196, identifier:args; 197, expression_statement; 197, 198; 198, assignment; 198, 199; 198, 200; 199, identifier:bedpefile; 200, binary_operator:+; 200, 201; 200, 202; 201, identifier:scf; 202, string:".bedpe"; 203, expression_statement; 203, 204; 204, assignment; 204, 205; 204, 206; 205, identifier:pairsbedfile; 206, binary_operator:+; 206, 207; 206, 208; 207, identifier:scf; 208, string:".pairs.bed"; 209, if_statement; 209, 210; 209, 225; 210, not_operator; 210, 211; 211, parenthesized_expression; 211, 212; 212, boolean_operator:and; 212, 213; 212, 219; 213, call; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:op; 216, identifier:exists; 217, argument_list; 217, 218; 218, identifier:bedpefile; 219, call; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:op; 222, identifier:exists; 223, argument_list; 223, 224; 224, identifier:pairsbedfile; 225, block; 225, 226; 226, expression_statement; 226, 227; 227, call; 227, 228; 227, 229; 228, identifier:bed_to_bedpe; 229, argument_list; 229, 230; 229, 231; 229, 232; 229, 235; 230, identifier:bedfile; 231, identifier:bedpefile; 232, keyword_argument; 232, 233; 232, 234; 233, identifier:pairsbedfile; 234, identifier:pairsbedfile; 235, keyword_argument; 235, 236; 235, 237; 236, identifier:ca; 237, True; 238, expression_statement; 238, 239; 239, call; 239, 240; 239, 241; 240, identifier:Coverage; 241, argument_list; 241, 242; 241, 243; 242, identifier:bedfile; 243, identifier:sizesfile; 244, expression_statement; 244, 245; 245, call; 245, 246; 245, 247; 246, identifier:Coverage; 247, argument_list; 247, 248; 247, 249; 248, identifier:pairsbedfile; 249, identifier:sizesfile | def posmap(args):
p = OptionParser(posmap.__doc__)
opts, args = p.parse_args(args)
if len(args) != 3:
sys.exit(p.print_help())
frgscffile, fastafile, scf = args
cmd = "faOneRecord {0} {1}".format(fastafile, scf)
scffastafile = scf + ".fasta"
if not op.exists(scffastafile):
sh(cmd, outfile=scffastafile)
sizesfile = scffastafile + ".sizes"
sizes = Sizes(scffastafile).mapping
scfsize = sizes[scf]
logging.debug("`{0}` has length of {1}.".format(scf, scfsize))
gapsbedfile = scf + ".gaps.bed"
if not op.exists(gapsbedfile):
args = [scffastafile, "--bed", "--mingap=100"]
gaps(args)
posmapfile = scf + ".posmap"
if not op.exists(posmapfile):
args = [frgscffile, scf]
query(args)
bedfile = scf + ".bed"
if not op.exists(bedfile):
args = [posmapfile]
bed(args)
bedpefile = scf + ".bedpe"
pairsbedfile = scf + ".pairs.bed"
if not (op.exists(bedpefile) and op.exists(pairsbedfile)):
bed_to_bedpe(bedfile, bedpefile, pairsbedfile=pairsbedfile, ca=True)
Coverage(bedfile, sizesfile)
Coverage(pairsbedfile, sizesfile) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:shred; 3, parameters; 3, 4; 4, identifier:args; 5, block; 5, 6; 5, 15; 5, 26; 5, 46; 5, 51; 5, 58; 5, 64; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:p; 9, call; 9, 10; 9, 11; 10, identifier:OptionParser; 11, argument_list; 11, 12; 12, attribute; 12, 13; 12, 14; 13, identifier:shred; 14, identifier:__doc__; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 20; 17, pattern_list; 17, 18; 17, 19; 18, identifier:opts; 19, identifier:args; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:p; 23, identifier:parse_args; 24, argument_list; 24, 25; 25, identifier:args; 26, if_statement; 26, 27; 26, 33; 27, comparison_operator:!=; 27, 28; 27, 32; 28, call; 28, 29; 28, 30; 29, identifier:len; 30, argument_list; 30, 31; 31, identifier:args; 32, integer:1; 33, block; 33, 34; 34, expression_statement; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:sys; 38, identifier:exit; 39, argument_list; 39, 40; 40, not_operator; 40, 41; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:p; 44, identifier:print_help; 45, argument_list; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 50; 48, pattern_list; 48, 49; 49, identifier:s; 50, identifier:args; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:u; 54, call; 54, 55; 54, 56; 55, identifier:UnitigLayout; 56, argument_list; 56, 57; 57, identifier:s; 58, expression_statement; 58, 59; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:u; 62, identifier:shred; 63, argument_list; 64, expression_statement; 64, 65; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:u; 68, identifier:print_to_file; 69, argument_list; 69, 70; 70, keyword_argument; 70, 71; 70, 72; 71, identifier:inplace; 72, True | def shred(args):
p = OptionParser(shred.__doc__)
opts, args = p.parse_args(args)
if len(args) != 1:
sys.exit(not p.print_help())
s, = args
u = UnitigLayout(s)
u.shred()
u.print_to_file(inplace=True) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:index; 3, parameters; 3, 4; 4, identifier:args; 5, block; 5, 6; 5, 15; 5, 26; 5, 45; 5, 50; 5, 56; 5, 65; 5, 82; 5, 88; 5, 97; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:p; 9, call; 9, 10; 9, 11; 10, identifier:OptionParser; 11, argument_list; 11, 12; 12, attribute; 12, 13; 12, 14; 13, identifier:index; 14, identifier:__doc__; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 20; 17, pattern_list; 17, 18; 17, 19; 18, identifier:opts; 19, identifier:args; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:p; 23, identifier:parse_args; 24, argument_list; 24, 25; 25, identifier:args; 26, if_statement; 26, 27; 26, 33; 27, comparison_operator:!=; 27, 28; 27, 32; 28, call; 28, 29; 28, 30; 29, identifier:len; 30, argument_list; 30, 31; 31, identifier:args; 32, integer:1; 33, block; 33, 34; 34, expression_statement; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:sys; 38, identifier:exit; 39, argument_list; 39, 40; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:p; 43, identifier:print_help; 44, argument_list; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 49; 47, pattern_list; 47, 48; 48, identifier:frgscffile; 49, identifier:args; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:gzfile; 53, binary_operator:+; 53, 54; 53, 55; 54, identifier:frgscffile; 55, string:".gz"; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:cmd; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, string:"bgzip -c {0}"; 62, identifier:format; 63, argument_list; 63, 64; 64, identifier:frgscffile; 65, if_statement; 65, 66; 65, 73; 66, not_operator; 66, 67; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:op; 70, identifier:exists; 71, argument_list; 71, 72; 72, identifier:gzfile; 73, block; 73, 74; 74, expression_statement; 74, 75; 75, call; 75, 76; 75, 77; 76, identifier:sh; 77, argument_list; 77, 78; 77, 79; 78, identifier:cmd; 79, keyword_argument; 79, 80; 79, 81; 80, identifier:outfile; 81, identifier:gzfile; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:tbifile; 85, binary_operator:+; 85, 86; 85, 87; 86, identifier:gzfile; 87, string:".tbi"; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:cmd; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, string:"tabix -s 2 -b 3 -e 4 {0}"; 94, identifier:format; 95, argument_list; 95, 96; 96, identifier:gzfile; 97, if_statement; 97, 98; 97, 105; 98, not_operator; 98, 99; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:op; 102, identifier:exists; 103, argument_list; 103, 104; 104, identifier:tbifile; 105, block; 105, 106; 106, expression_statement; 106, 107; 107, call; 107, 108; 107, 109; 108, identifier:sh; 109, argument_list; 109, 110; 110, identifier:cmd | def index(args):
p = OptionParser(index.__doc__)
opts, args = p.parse_args(args)
if len(args) != 1:
sys.exit(p.print_help())
frgscffile, = args
gzfile = frgscffile + ".gz"
cmd = "bgzip -c {0}".format(frgscffile)
if not op.exists(gzfile):
sh(cmd, outfile=gzfile)
tbifile = gzfile + ".tbi"
cmd = "tabix -s 2 -b 3 -e 4 {0}".format(gzfile)
if not op.exists(tbifile):
sh(cmd) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort; 3, parameters; 3, 4; 4, identifier:args; 5, block; 5, 6; 5, 12; 5, 21; 5, 37; 5, 56; 5, 62; 5, 68; 5, 75; 5, 86; 5, 106; 5, 111; 5, 117; 5, 157; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:valid_sort_methods; 9, tuple; 9, 10; 9, 11; 10, string:"unix"; 11, string:"topo"; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:p; 15, call; 15, 16; 15, 17; 16, identifier:OptionParser; 17, argument_list; 17, 18; 18, attribute; 18, 19; 18, 20; 19, identifier:sort; 20, identifier:__doc__; 21, expression_statement; 21, 22; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:p; 25, identifier:add_option; 26, argument_list; 26, 27; 26, 28; 26, 31; 26, 34; 27, string:"--method"; 28, keyword_argument; 28, 29; 28, 30; 29, identifier:default; 30, string:"unix"; 31, keyword_argument; 31, 32; 31, 33; 32, identifier:choices; 33, identifier:valid_sort_methods; 34, keyword_argument; 34, 35; 34, 36; 35, identifier:help; 36, string:"Specify sort method [default: %default]"; 37, expression_statement; 37, 38; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:p; 41, identifier:add_option; 42, argument_list; 42, 43; 42, 44; 42, 47; 42, 50; 42, 53; 43, string:"-i"; 44, keyword_argument; 44, 45; 44, 46; 45, identifier:dest; 46, string:"inplace"; 47, keyword_argument; 47, 48; 47, 49; 48, identifier:default; 49, False; 50, keyword_argument; 50, 51; 50, 52; 51, identifier:action; 52, string:"store_true"; 53, keyword_argument; 53, 54; 53, 55; 54, identifier:help; 55, string:"If doing a unix sort, perform sort inplace [default: %default]"; 56, expression_statement; 56, 57; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:p; 60, identifier:set_tmpdir; 61, argument_list; 62, expression_statement; 62, 63; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:p; 66, identifier:set_outfile; 67, argument_list; 68, expression_statement; 68, 69; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:p; 72, identifier:set_home; 73, argument_list; 73, 74; 74, string:"gt"; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 80; 77, pattern_list; 77, 78; 77, 79; 78, identifier:opts; 79, identifier:args; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:p; 83, identifier:parse_args; 84, argument_list; 84, 85; 85, identifier:args; 86, if_statement; 86, 87; 86, 93; 87, comparison_operator:!=; 87, 88; 87, 92; 88, call; 88, 89; 88, 90; 89, identifier:len; 90, argument_list; 90, 91; 91, identifier:args; 92, integer:1; 93, block; 93, 94; 94, expression_statement; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:sys; 98, identifier:exit; 99, argument_list; 99, 100; 100, not_operator; 100, 101; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:p; 104, identifier:print_help; 105, argument_list; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 110; 108, pattern_list; 108, 109; 109, identifier:gffile; 110, identifier:args; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:sortedgff; 114, attribute; 114, 115; 114, 116; 115, identifier:opts; 116, identifier:outfile; 117, if_statement; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:opts; 120, identifier:inplace; 121, block; 121, 122; 122, if_statement; 122, 123; 122, 141; 123, boolean_operator:or; 123, 124; 123, 129; 124, comparison_operator:==; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:opts; 127, identifier:method; 128, string:"topo"; 129, parenthesized_expression; 129, 130; 130, boolean_operator:and; 130, 131; 130, 136; 131, comparison_operator:==; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:opts; 134, identifier:method; 135, string:"unix"; 136, comparison_operator:in; 136, 137; 136, 138; 137, identifier:gffile; 138, tuple; 138, 139; 138, 140; 139, string:"-"; 140, string:"stdin"; 141, block; 141, 142; 141, 151; 142, expression_statement; 142, 143; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:logging; 146, identifier:error; 147, argument_list; 147, 148; 148, binary_operator:+; 148, 149; 148, 150; 149, string:"Cannot perform inplace sort when method is `topo`"; 150, string:" or method is `unix` and input is `stdin` stream"; 151, expression_statement; 151, 152; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:sys; 155, identifier:exit; 156, argument_list; 157, if_statement; 157, 158; 157, 163; 157, 216; 158, comparison_operator:==; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:opts; 161, identifier:method; 162, string:"unix"; 163, block; 163, 164; 163, 168; 163, 177; 163, 193; 163, 208; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 167; 166, identifier:cmd; 167, string:"sort"; 168, expression_statement; 168, 169; 169, augmented_assignment:+=; 169, 170; 169, 171; 170, identifier:cmd; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, string:" -k1,1 -k4,4n {0}"; 174, identifier:format; 175, argument_list; 175, 176; 176, identifier:gffile; 177, if_statement; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:opts; 180, identifier:tmpdir; 181, block; 181, 182; 182, expression_statement; 182, 183; 183, augmented_assignment:+=; 183, 184; 183, 185; 184, identifier:cmd; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, string:" -T {0}"; 188, identifier:format; 189, argument_list; 189, 190; 190, attribute; 190, 191; 190, 192; 191, identifier:opts; 192, identifier:tmpdir; 193, if_statement; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:opts; 196, identifier:inplace; 197, block; 197, 198; 197, 204; 198, expression_statement; 198, 199; 199, augmented_assignment:+=; 199, 200; 199, 201; 200, identifier:cmd; 201, attribute; 201, 202; 201, 203; 202, string:" -o {0}"; 203, identifier:gffile; 204, expression_statement; 204, 205; 205, assignment; 205, 206; 205, 207; 206, identifier:sortedgff; 207, None; 208, expression_statement; 208, 209; 209, call; 209, 210; 209, 211; 210, identifier:sh; 211, argument_list; 211, 212; 211, 213; 212, identifier:cmd; 213, keyword_argument; 213, 214; 213, 215; 214, identifier:outfile; 215, identifier:sortedgff; 216, elif_clause; 216, 217; 216, 222; 217, comparison_operator:==; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:opts; 220, identifier:method; 221, string:"topo"; 222, block; 222, 223; 222, 229; 222, 256; 222, 272; 222, 281; 223, expression_statement; 223, 224; 224, assignment; 224, 225; 224, 226; 225, identifier:GT_HOME; 226, attribute; 226, 227; 226, 228; 227, identifier:opts; 228, identifier:gt_home; 229, if_statement; 229, 230; 229, 237; 230, not_operator; 230, 231; 231, call; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:op; 234, identifier:isdir; 235, argument_list; 235, 236; 236, identifier:GT_HOME; 237, block; 237, 238; 237, 250; 238, expression_statement; 238, 239; 239, call; 239, 240; 239, 243; 240, attribute; 240, 241; 240, 242; 241, identifier:logging; 242, identifier:error; 243, argument_list; 243, 244; 244, call; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, string:"GT_HOME={0} directory does not exist"; 247, identifier:format; 248, argument_list; 248, 249; 249, identifier:GT_HOME; 250, expression_statement; 250, 251; 251, call; 251, 252; 251, 255; 252, attribute; 252, 253; 252, 254; 253, identifier:sys; 254, identifier:exit; 255, argument_list; 256, expression_statement; 256, 257; 257, assignment; 257, 258; 257, 259; 258, identifier:cmd; 259, call; 259, 260; 259, 263; 260, attribute; 260, 261; 260, 262; 261, string:"{0}"; 262, identifier:format; 263, argument_list; 263, 264; 264, call; 264, 265; 264, 268; 265, attribute; 265, 266; 265, 267; 266, identifier:op; 267, identifier:join; 268, argument_list; 268, 269; 268, 270; 268, 271; 269, identifier:GT_HOME; 270, string:"bin"; 271, string:"gt"; 272, expression_statement; 272, 273; 273, augmented_assignment:+=; 273, 274; 273, 275; 274, identifier:cmd; 275, call; 275, 276; 275, 279; 276, attribute; 276, 277; 276, 278; 277, string:" gff3 -sort -tidy -retainids -addids no {0}"; 278, identifier:format; 279, argument_list; 279, 280; 280, identifier:gffile; 281, expression_statement; 281, 282; 282, call; 282, 283; 282, 284; 283, identifier:sh; 284, argument_list; 284, 285; 284, 286; 285, identifier:cmd; 286, keyword_argument; 286, 287; 286, 288; 287, identifier:outfile; 288, identifier:sortedgff | def sort(args):
valid_sort_methods = ("unix", "topo")
p = OptionParser(sort.__doc__)
p.add_option("--method", default="unix", choices=valid_sort_methods,
help="Specify sort method [default: %default]")
p.add_option("-i", dest="inplace", default=False, action="store_true",
help="If doing a unix sort, perform sort inplace [default: %default]")
p.set_tmpdir()
p.set_outfile()
p.set_home("gt")
opts, args = p.parse_args(args)
if len(args) != 1:
sys.exit(not p.print_help())
gffile, = args
sortedgff = opts.outfile
if opts.inplace:
if opts.method == "topo" or (opts.method == "unix" and gffile in ("-", "stdin")):
logging.error("Cannot perform inplace sort when method is `topo`" + \
" or method is `unix` and input is `stdin` stream")
sys.exit()
if opts.method == "unix":
cmd = "sort"
cmd += " -k1,1 -k4,4n {0}".format(gffile)
if opts.tmpdir:
cmd += " -T {0}".format(opts.tmpdir)
if opts.inplace:
cmd += " -o {0}".gffile
sortedgff = None
sh(cmd, outfile=sortedgff)
elif opts.method == "topo":
GT_HOME = opts.gt_home
if not op.isdir(GT_HOME):
logging.error("GT_HOME={0} directory does not exist".format(GT_HOME))
sys.exit()
cmd = "{0}".format(op.join(GT_HOME, "bin", "gt"))
cmd += " gff3 -sort -tidy -retainids -addids no {0}".format(gffile)
sh(cmd, outfile=sortedgff) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:sort_layout; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:thread; 5, identifier:listfile; 6, default_parameter; 6, 7; 6, 8; 7, identifier:column; 8, integer:0; 9, block; 9, 10; 9, 17; 9, 31; 9, 37; 9, 45; 9, 58; 9, 62; 9, 68; 9, 104; 9, 114; 9, 127; 9, 143; 9, 150; 9, 181; 9, 198; 9, 204; 10, import_from_statement; 10, 11; 10, 15; 11, dotted_name; 11, 12; 11, 13; 11, 14; 12, identifier:jcvi; 13, identifier:formats; 14, identifier:base; 15, dotted_name; 15, 16; 16, identifier:DictFile; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:outfile; 20, binary_operator:+; 20, 21; 20, 30; 21, subscript; 21, 22; 21, 29; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:listfile; 25, identifier:rsplit; 26, argument_list; 26, 27; 26, 28; 27, string:"."; 28, integer:1; 29, integer:0; 30, string:".sorted.list"; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:threadorder; 34, attribute; 34, 35; 34, 36; 35, identifier:thread; 36, identifier:order; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:fw; 40, call; 40, 41; 40, 42; 41, identifier:open; 42, argument_list; 42, 43; 42, 44; 43, identifier:outfile; 44, string:"w"; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:lt; 48, call; 48, 49; 48, 50; 49, identifier:DictFile; 50, argument_list; 50, 51; 50, 52; 50, 55; 51, identifier:listfile; 52, keyword_argument; 52, 53; 52, 54; 53, identifier:keypos; 54, identifier:column; 55, keyword_argument; 55, 56; 55, 57; 56, identifier:valuepos; 57, None; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:threaded; 61, list:[]; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:imported; 65, call; 65, 66; 65, 67; 66, identifier:set; 67, argument_list; 68, for_statement; 68, 69; 68, 70; 68, 71; 69, identifier:t; 70, identifier:thread; 71, block; 71, 72; 71, 78; 71, 84; 71, 91; 71, 97; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:accn; 75, attribute; 75, 76; 75, 77; 76, identifier:t; 77, identifier:accn; 78, if_statement; 78, 79; 78, 82; 79, comparison_operator:not; 79, 80; 79, 81; 80, identifier:accn; 81, identifier:lt; 82, block; 82, 83; 83, continue_statement; 84, expression_statement; 84, 85; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:imported; 88, identifier:add; 89, argument_list; 89, 90; 90, identifier:accn; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:atoms; 94, subscript; 94, 95; 94, 96; 95, identifier:lt; 96, identifier:accn; 97, expression_statement; 97, 98; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:threaded; 101, identifier:append; 102, argument_list; 102, 103; 103, identifier:atoms; 104, assert_statement; 104, 105; 105, comparison_operator:==; 105, 106; 105, 110; 106, call; 106, 107; 106, 108; 107, identifier:len; 108, argument_list; 108, 109; 109, identifier:threaded; 110, call; 110, 111; 110, 112; 111, identifier:len; 112, argument_list; 112, 113; 113, identifier:imported; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:total; 117, call; 117, 118; 117, 119; 118, identifier:sum; 119, generator_expression; 119, 120; 119, 121; 120, integer:1; 121, for_in_clause; 121, 122; 121, 123; 122, identifier:x; 123, call; 123, 124; 123, 125; 124, identifier:open; 125, argument_list; 125, 126; 126, identifier:listfile; 127, expression_statement; 127, 128; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:logging; 131, identifier:debug; 132, argument_list; 132, 133; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, string:"Total: {0}, currently threaded: {1}"; 136, identifier:format; 137, argument_list; 137, 138; 137, 139; 138, identifier:total; 139, call; 139, 140; 139, 141; 140, identifier:len; 141, argument_list; 141, 142; 142, identifier:threaded; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 146; 145, identifier:fp; 146, call; 146, 147; 146, 148; 147, identifier:open; 148, argument_list; 148, 149; 149, identifier:listfile; 150, for_statement; 150, 151; 150, 152; 150, 153; 151, identifier:row; 152, identifier:fp; 153, block; 153, 154; 153, 162; 153, 168; 153, 174; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 157; 156, identifier:atoms; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:row; 160, identifier:split; 161, argument_list; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:accn; 165, subscript; 165, 166; 165, 167; 166, identifier:atoms; 167, integer:0; 168, if_statement; 168, 169; 168, 172; 169, comparison_operator:in; 169, 170; 169, 171; 170, identifier:accn; 171, identifier:imported; 172, block; 172, 173; 173, continue_statement; 174, expression_statement; 174, 175; 175, call; 175, 176; 175, 177; 176, identifier:insert_into_threaded; 177, argument_list; 177, 178; 177, 179; 177, 180; 178, identifier:atoms; 179, identifier:threaded; 180, identifier:threadorder; 181, for_statement; 181, 182; 181, 183; 181, 184; 182, identifier:atoms; 183, identifier:threaded; 184, block; 184, 185; 185, expression_statement; 185, 186; 186, call; 186, 187; 186, 188; 187, identifier:print; 188, argument_list; 188, 189; 188, 195; 189, call; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, string:"\t"; 192, identifier:join; 193, argument_list; 193, 194; 194, identifier:atoms; 195, keyword_argument; 195, 196; 195, 197; 196, identifier:file; 197, identifier:fw; 198, expression_statement; 198, 199; 199, call; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:fw; 202, identifier:close; 203, argument_list; 204, expression_statement; 204, 205; 205, call; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:logging; 208, identifier:debug; 209, argument_list; 209, 210; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, string:"File `{0}` sorted to `{1}`."; 213, identifier:format; 214, argument_list; 214, 215; 214, 216; 215, identifier:outfile; 216, attribute; 216, 217; 216, 218; 217, identifier:thread; 218, identifier:filename | def sort_layout(thread, listfile, column=0):
from jcvi.formats.base import DictFile
outfile = listfile.rsplit(".", 1)[0] + ".sorted.list"
threadorder = thread.order
fw = open(outfile, "w")
lt = DictFile(listfile, keypos=column, valuepos=None)
threaded = []
imported = set()
for t in thread:
accn = t.accn
if accn not in lt:
continue
imported.add(accn)
atoms = lt[accn]
threaded.append(atoms)
assert len(threaded) == len(imported)
total = sum(1 for x in open(listfile))
logging.debug("Total: {0}, currently threaded: {1}".format(total, len(threaded)))
fp = open(listfile)
for row in fp:
atoms = row.split()
accn = atoms[0]
if accn in imported:
continue
insert_into_threaded(atoms, threaded, threadorder)
for atoms in threaded:
print("\t".join(atoms), file=fw)
fw.close()
logging.debug("File `{0}` sorted to `{1}`.".format(outfile, thread.filename)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:fromgroups; 3, parameters; 3, 4; 4, identifier:args; 5, block; 5, 6; 5, 13; 5, 22; 5, 33; 5, 53; 5, 59; 5, 67; 5, 78; 5, 85; 5, 102; 6, import_from_statement; 6, 7; 6, 11; 7, dotted_name; 7, 8; 7, 9; 7, 10; 8, identifier:jcvi; 9, identifier:formats; 10, identifier:bed; 11, dotted_name; 11, 12; 12, identifier:Bed; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:p; 16, call; 16, 17; 16, 18; 17, identifier:OptionParser; 18, argument_list; 18, 19; 19, attribute; 19, 20; 19, 21; 20, identifier:fromgroups; 21, identifier:__doc__; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 27; 24, pattern_list; 24, 25; 24, 26; 25, identifier:opts; 26, identifier:args; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:p; 30, identifier:parse_args; 31, argument_list; 31, 32; 32, identifier:args; 33, if_statement; 33, 34; 33, 40; 34, comparison_operator:<; 34, 35; 34, 39; 35, call; 35, 36; 35, 37; 36, identifier:len; 37, argument_list; 37, 38; 38, identifier:args; 39, integer:2; 40, block; 40, 41; 41, expression_statement; 41, 42; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:sys; 45, identifier:exit; 46, argument_list; 46, 47; 47, not_operator; 47, 48; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:p; 51, identifier:print_help; 52, argument_list; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:groupsfile; 56, subscript; 56, 57; 56, 58; 57, identifier:args; 58, integer:0; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:bedfiles; 62, subscript; 62, 63; 62, 64; 63, identifier:args; 64, slice; 64, 65; 64, 66; 65, integer:1; 66, colon; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:beds; 70, list_comprehension; 70, 71; 70, 75; 71, call; 71, 72; 71, 73; 72, identifier:Bed; 73, argument_list; 73, 74; 74, identifier:x; 75, for_in_clause; 75, 76; 75, 77; 76, identifier:x; 77, identifier:bedfiles; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:fp; 81, call; 81, 82; 81, 83; 82, identifier:open; 83, argument_list; 83, 84; 84, identifier:groupsfile; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:groups; 88, list_comprehension; 88, 89; 88, 99; 89, call; 89, 90; 89, 97; 90, attribute; 90, 91; 90, 96; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:row; 94, identifier:strip; 95, argument_list; 96, identifier:split; 97, argument_list; 97, 98; 98, string:","; 99, for_in_clause; 99, 100; 99, 101; 100, identifier:row; 101, identifier:fp; 102, for_statement; 102, 103; 102, 106; 102, 113; 103, pattern_list; 103, 104; 103, 105; 104, identifier:b1; 105, identifier:b2; 106, call; 106, 107; 106, 108; 107, identifier:product; 108, argument_list; 108, 109; 108, 110; 109, identifier:beds; 110, keyword_argument; 110, 111; 110, 112; 111, identifier:repeat; 112, integer:2; 113, block; 113, 114; 114, expression_statement; 114, 115; 115, call; 115, 116; 115, 117; 116, identifier:extract_pairs; 117, argument_list; 117, 118; 117, 119; 117, 120; 118, identifier:b1; 119, identifier:b2; 120, identifier:groups | def fromgroups(args):
from jcvi.formats.bed import Bed
p = OptionParser(fromgroups.__doc__)
opts, args = p.parse_args(args)
if len(args) < 2:
sys.exit(not p.print_help())
groupsfile = args[0]
bedfiles = args[1:]
beds = [Bed(x) for x in bedfiles]
fp = open(groupsfile)
groups = [row.strip().split(",") for row in fp]
for b1, b2 in product(beds, repeat=2):
extract_pairs(b1, b2, groups) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:merge_paths; 3, parameters; 3, 4; 3, 5; 4, identifier:paths; 5, default_parameter; 5, 6; 5, 7; 6, identifier:weights; 7, None; 8, block; 8, 9; 8, 19; 8, 26; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:G; 12, call; 12, 13; 12, 14; 13, identifier:make_paths; 14, argument_list; 14, 15; 14, 16; 15, identifier:paths; 16, keyword_argument; 16, 17; 16, 18; 17, identifier:weights; 18, identifier:weights; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:G; 22, call; 22, 23; 22, 24; 23, identifier:reduce_paths; 24, argument_list; 24, 25; 25, identifier:G; 26, return_statement; 26, 27; 27, identifier:G | def merge_paths(paths, weights=None):
G = make_paths(paths, weights=weights)
G = reduce_paths(G)
return G |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:build; 3, parameters; 3, 4; 4, identifier:args; 5, block; 5, 6; 5, 13; 5, 20; 5, 27; 5, 36; 5, 52; 5, 63; 5, 83; 5, 90; 5, 106; 5, 115; 5, 123; 5, 132; 5, 138; 5, 147; 5, 153; 5, 163; 5, 168; 5, 174; 6, import_from_statement; 6, 7; 6, 11; 7, dotted_name; 7, 8; 7, 9; 7, 10; 8, identifier:jcvi; 9, identifier:apps; 10, identifier:cdhit; 11, dotted_name; 11, 12; 12, identifier:deduplicate; 13, import_from_statement; 13, 14; 13, 18; 14, dotted_name; 14, 15; 14, 16; 14, 17; 15, identifier:jcvi; 16, identifier:apps; 17, identifier:vecscreen; 18, dotted_name; 18, 19; 19, identifier:mask; 20, import_from_statement; 20, 21; 20, 25; 21, dotted_name; 21, 22; 21, 23; 21, 24; 22, identifier:jcvi; 23, identifier:formats; 24, identifier:fasta; 25, dotted_name; 25, 26; 26, identifier:sort; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:p; 30, call; 30, 31; 30, 32; 31, identifier:OptionParser; 32, argument_list; 32, 33; 33, attribute; 33, 34; 33, 35; 34, identifier:build; 35, identifier:__doc__; 36, expression_statement; 36, 37; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:p; 40, identifier:add_option; 41, argument_list; 41, 42; 41, 43; 41, 46; 41, 49; 42, string:"--nodedup"; 43, keyword_argument; 43, 44; 43, 45; 44, identifier:default; 45, False; 46, keyword_argument; 46, 47; 46, 48; 47, identifier:action; 48, string:"store_true"; 49, keyword_argument; 49, 50; 49, 51; 50, identifier:help; 51, string:"Do not deduplicate [default: deduplicate]"; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 57; 54, pattern_list; 54, 55; 54, 56; 55, identifier:opts; 56, identifier:args; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:p; 60, identifier:parse_args; 61, argument_list; 61, 62; 62, identifier:args; 63, if_statement; 63, 64; 63, 70; 64, comparison_operator:!=; 64, 65; 64, 69; 65, call; 65, 66; 65, 67; 66, identifier:len; 67, argument_list; 67, 68; 68, identifier:args; 69, integer:3; 70, block; 70, 71; 71, expression_statement; 71, 72; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:sys; 75, identifier:exit; 76, argument_list; 76, 77; 77, not_operator; 77, 78; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:p; 81, identifier:print_help; 82, argument_list; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 89; 85, pattern_list; 85, 86; 85, 87; 85, 88; 86, identifier:fastafile; 87, identifier:bacteria; 88, identifier:pf; 89, identifier:args; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:dd; 93, conditional_expression:if; 93, 94; 93, 100; 93, 101; 93, 105; 94, call; 94, 95; 94, 96; 95, identifier:deduplicate; 96, argument_list; 96, 97; 97, list:[fastafile, "--pctid=100"]; 97, 98; 97, 99; 98, identifier:fastafile; 99, string:"--pctid=100"; 100, line_continuation:\; 101, not_operator; 101, 102; 102, attribute; 102, 103; 102, 104; 103, identifier:opts; 104, identifier:nodedup; 105, identifier:fastafile; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:screenfasta; 109, call; 109, 110; 109, 111; 110, identifier:screen; 111, argument_list; 111, 112; 112, list:[dd, bacteria]; 112, 113; 112, 114; 113, identifier:dd; 114, identifier:bacteria; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:tidyfasta; 118, call; 118, 119; 118, 120; 119, identifier:mask; 120, argument_list; 120, 121; 121, list:[screenfasta]; 121, 122; 122, identifier:screenfasta; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 126; 125, identifier:sortedfasta; 126, call; 126, 127; 126, 128; 127, identifier:sort; 128, argument_list; 128, 129; 129, list:[tidyfasta, "--sizes"]; 129, 130; 129, 131; 130, identifier:tidyfasta; 131, string:"--sizes"; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:scaffoldfasta; 135, binary_operator:+; 135, 136; 135, 137; 136, identifier:pf; 137, string:".assembly.fasta"; 138, expression_statement; 138, 139; 139, call; 139, 140; 139, 141; 140, identifier:format; 141, argument_list; 141, 142; 142, list:[sortedfasta, scaffoldfasta, "--prefix=scaffold_", "--sequential"]; 142, 143; 142, 144; 142, 145; 142, 146; 143, identifier:sortedfasta; 144, identifier:scaffoldfasta; 145, string:"--prefix=scaffold_"; 146, string:"--sequential"; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 150; 149, identifier:gapsplitfasta; 150, binary_operator:+; 150, 151; 150, 152; 151, identifier:pf; 152, string:".gapSplit.fasta"; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 156; 155, identifier:cmd; 156, call; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, string:"gapSplit -minGap=10 {0} {1}"; 159, identifier:format; 160, argument_list; 160, 161; 160, 162; 161, identifier:scaffoldfasta; 162, identifier:gapsplitfasta; 163, expression_statement; 163, 164; 164, call; 164, 165; 164, 166; 165, identifier:sh; 166, argument_list; 166, 167; 167, identifier:cmd; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:contigsfasta; 171, binary_operator:+; 171, 172; 171, 173; 172, identifier:pf; 173, string:".contigs.fasta"; 174, expression_statement; 174, 175; 175, call; 175, 176; 175, 177; 176, identifier:format; 177, argument_list; 177, 178; 178, list:[gapsplitfasta, contigsfasta, "--prefix=contig_", "--sequential"]; 178, 179; 178, 180; 178, 181; 178, 182; 179, identifier:gapsplitfasta; 180, identifier:contigsfasta; 181, string:"--prefix=contig_"; 182, string:"--sequential" | def build(args):
from jcvi.apps.cdhit import deduplicate
from jcvi.apps.vecscreen import mask
from jcvi.formats.fasta import sort
p = OptionParser(build.__doc__)
p.add_option("--nodedup", default=False, action="store_true",
help="Do not deduplicate [default: deduplicate]")
opts, args = p.parse_args(args)
if len(args) != 3:
sys.exit(not p.print_help())
fastafile, bacteria, pf = args
dd = deduplicate([fastafile, "--pctid=100"]) \
if not opts.nodedup else fastafile
screenfasta = screen([dd, bacteria])
tidyfasta = mask([screenfasta])
sortedfasta = sort([tidyfasta, "--sizes"])
scaffoldfasta = pf + ".assembly.fasta"
format([sortedfasta, scaffoldfasta, "--prefix=scaffold_", "--sequential"])
gapsplitfasta = pf + ".gapSplit.fasta"
cmd = "gapSplit -minGap=10 {0} {1}".format(scaffoldfasta, gapsplitfasta)
sh(cmd)
contigsfasta = pf + ".contigs.fasta"
format([gapsplitfasta, contigsfasta, "--prefix=contig_", "--sequential"]) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort; 3, parameters; 3, 4; 4, identifier:args; 5, block; 5, 6; 5, 11; 6, import_statement; 6, 7; 7, dotted_name; 7, 8; 7, 9; 7, 10; 8, identifier:jcvi; 9, identifier:formats; 10, identifier:blast; 11, return_statement; 11, 12; 12, call; 12, 13; 12, 20; 13, attribute; 13, 14; 13, 19; 14, attribute; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:jcvi; 17, identifier:formats; 18, identifier:blast; 19, identifier:sort; 20, argument_list; 20, 21; 21, binary_operator:+; 21, 22; 21, 23; 22, identifier:args; 23, list:["--coords"]; 23, 24; 24, string:"--coords" | def sort(args):
import jcvi.formats.blast
return jcvi.formats.blast.sort(args + ["--coords"]) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:coverage; 3, parameters; 3, 4; 4, identifier:args; 5, block; 5, 6; 5, 15; 5, 34; 5, 50; 5, 56; 5, 67; 5, 87; 5, 93; 5, 99; 5, 127; 5, 139; 5, 148; 5, 158; 5, 215; 5, 221; 5, 236; 5, 243; 5, 253; 5, 283; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:p; 9, call; 9, 10; 9, 11; 10, identifier:OptionParser; 11, argument_list; 11, 12; 12, attribute; 12, 13; 12, 14; 13, identifier:coverage; 14, identifier:__doc__; 15, expression_statement; 15, 16; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:p; 19, identifier:add_option; 20, argument_list; 20, 21; 20, 22; 20, 25; 20, 31; 21, string:"--format"; 22, keyword_argument; 22, 23; 22, 24; 23, identifier:default; 24, string:"bigwig"; 25, keyword_argument; 25, 26; 25, 27; 26, identifier:choices; 27, tuple; 27, 28; 27, 29; 27, 30; 28, string:"bedgraph"; 29, string:"bigwig"; 30, string:"coverage"; 31, keyword_argument; 31, 32; 31, 33; 32, identifier:help; 33, string:"Output format"; 34, expression_statement; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:p; 38, identifier:add_option; 39, argument_list; 39, 40; 39, 41; 39, 44; 39, 47; 40, string:"--nosort"; 41, keyword_argument; 41, 42; 41, 43; 42, identifier:default; 43, False; 44, keyword_argument; 44, 45; 44, 46; 45, identifier:action; 46, string:"store_true"; 47, keyword_argument; 47, 48; 47, 49; 48, identifier:help; 49, string:"Do not sort BAM"; 50, expression_statement; 50, 51; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:p; 54, identifier:set_outfile; 55, argument_list; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 61; 58, pattern_list; 58, 59; 58, 60; 59, identifier:opts; 60, identifier:args; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:p; 64, identifier:parse_args; 65, argument_list; 65, 66; 66, identifier:args; 67, if_statement; 67, 68; 67, 74; 68, comparison_operator:!=; 68, 69; 68, 73; 69, call; 69, 70; 69, 71; 70, identifier:len; 71, argument_list; 71, 72; 72, identifier:args; 73, integer:2; 74, block; 74, 75; 75, expression_statement; 75, 76; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:sys; 79, identifier:exit; 80, argument_list; 80, 81; 81, not_operator; 81, 82; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:p; 85, identifier:print_help; 86, argument_list; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 92; 89, pattern_list; 89, 90; 89, 91; 90, identifier:fastafile; 91, identifier:bamfile; 92, identifier:args; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:format; 96, attribute; 96, 97; 96, 98; 97, identifier:opts; 98, identifier:format; 99, if_statement; 99, 100; 99, 103; 99, 111; 100, attribute; 100, 101; 100, 102; 101, identifier:opts; 102, identifier:nosort; 103, block; 103, 104; 104, expression_statement; 104, 105; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:logging; 108, identifier:debug; 109, argument_list; 109, 110; 110, string:"BAM sorting skipped"; 111, else_clause; 111, 112; 112, block; 112, 113; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:bamfile; 116, call; 116, 117; 116, 118; 117, identifier:index; 118, argument_list; 118, 119; 119, list:[bamfile, "--fasta={0}".format(fastafile)]; 119, 120; 119, 121; 120, identifier:bamfile; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, string:"--fasta={0}"; 124, identifier:format; 125, argument_list; 125, 126; 126, identifier:fastafile; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:pf; 130, subscript; 130, 131; 130, 138; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:bamfile; 134, identifier:rsplit; 135, argument_list; 135, 136; 135, 137; 136, string:"."; 137, integer:2; 138, integer:0; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:sizesfile; 142, attribute; 142, 143; 142, 147; 143, call; 143, 144; 143, 145; 144, identifier:Sizes; 145, argument_list; 145, 146; 146, identifier:fastafile; 147, identifier:filename; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 151; 150, identifier:cmd; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, string:"genomeCoverageBed -ibam {0} -g {1}"; 154, identifier:format; 155, argument_list; 155, 156; 155, 157; 156, identifier:bamfile; 157, identifier:sizesfile; 158, if_statement; 158, 159; 158, 164; 159, comparison_operator:in; 159, 160; 159, 161; 160, identifier:format; 161, tuple; 161, 162; 161, 163; 162, string:"bedgraph"; 163, string:"bigwig"; 164, block; 164, 165; 164, 169; 164, 175; 164, 183; 164, 190; 164, 196; 164, 208; 164, 213; 165, expression_statement; 165, 166; 166, augmented_assignment:+=; 166, 167; 166, 168; 167, identifier:cmd; 168, string:" -bg"; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 172; 171, identifier:bedgraphfile; 172, binary_operator:+; 172, 173; 172, 174; 173, identifier:pf; 174, string:".bedgraph"; 175, expression_statement; 175, 176; 176, call; 176, 177; 176, 178; 177, identifier:sh; 178, argument_list; 178, 179; 178, 180; 179, identifier:cmd; 180, keyword_argument; 180, 181; 180, 182; 181, identifier:outfile; 182, identifier:bedgraphfile; 183, if_statement; 183, 184; 183, 187; 184, comparison_operator:==; 184, 185; 184, 186; 185, identifier:format; 186, string:"bedgraph"; 187, block; 187, 188; 188, return_statement; 188, 189; 189, identifier:bedgraphfile; 190, expression_statement; 190, 191; 191, assignment; 191, 192; 191, 193; 192, identifier:bigwigfile; 193, binary_operator:+; 193, 194; 193, 195; 194, identifier:pf; 195, string:".bigwig"; 196, expression_statement; 196, 197; 197, assignment; 197, 198; 197, 199; 198, identifier:cmd; 199, call; 199, 200; 199, 204; 200, attribute; 200, 201; 200, 202; 200, 203; 201, string:"bedGraphToBigWig {0} {1} {2}"; 202, line_continuation:\; 203, identifier:format; 204, argument_list; 204, 205; 204, 206; 204, 207; 205, identifier:bedgraphfile; 206, identifier:sizesfile; 207, identifier:bigwigfile; 208, expression_statement; 208, 209; 209, call; 209, 210; 209, 211; 210, identifier:sh; 211, argument_list; 211, 212; 212, identifier:cmd; 213, return_statement; 213, 214; 214, identifier:bigwigfile; 215, expression_statement; 215, 216; 216, assignment; 216, 217; 216, 218; 217, identifier:coveragefile; 218, binary_operator:+; 218, 219; 218, 220; 219, identifier:pf; 220, string:".coverage"; 221, if_statement; 221, 222; 221, 227; 222, call; 222, 223; 222, 224; 223, identifier:need_update; 224, argument_list; 224, 225; 224, 226; 225, identifier:fastafile; 226, identifier:coveragefile; 227, block; 227, 228; 228, expression_statement; 228, 229; 229, call; 229, 230; 229, 231; 230, identifier:sh; 231, argument_list; 231, 232; 231, 233; 232, identifier:cmd; 233, keyword_argument; 233, 234; 233, 235; 234, identifier:outfile; 235, identifier:coveragefile; 236, expression_statement; 236, 237; 237, assignment; 237, 238; 237, 239; 238, identifier:gcf; 239, call; 239, 240; 239, 241; 240, identifier:GenomeCoverageFile; 241, argument_list; 241, 242; 242, identifier:coveragefile; 243, expression_statement; 243, 244; 244, assignment; 244, 245; 244, 246; 245, identifier:fw; 246, call; 246, 247; 246, 248; 247, identifier:must_open; 248, argument_list; 248, 249; 248, 252; 249, attribute; 249, 250; 249, 251; 250, identifier:opts; 251, identifier:outfile; 252, string:"w"; 253, for_statement; 253, 254; 253, 257; 253, 262; 254, pattern_list; 254, 255; 254, 256; 255, identifier:seqid; 256, identifier:cov; 257, call; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, identifier:gcf; 260, identifier:iter_coverage_seqid; 261, argument_list; 262, block; 262, 263; 263, expression_statement; 263, 264; 264, call; 264, 265; 264, 266; 265, identifier:print; 266, argument_list; 266, 267; 266, 280; 267, call; 267, 268; 267, 271; 268, attribute; 268, 269; 268, 270; 269, string:"\t"; 270, identifier:join; 271, argument_list; 271, 272; 272, tuple; 272, 273; 272, 274; 273, identifier:seqid; 274, call; 274, 275; 274, 278; 275, attribute; 275, 276; 275, 277; 276, string:"{0:.1f}"; 277, identifier:format; 278, argument_list; 278, 279; 279, identifier:cov; 280, keyword_argument; 280, 281; 280, 282; 281, identifier:file; 282, identifier:fw; 283, expression_statement; 283, 284; 284, call; 284, 285; 284, 288; 285, attribute; 285, 286; 285, 287; 286, identifier:fw; 287, identifier:close; 288, argument_list | def coverage(args):
p = OptionParser(coverage.__doc__)
p.add_option("--format", default="bigwig",
choices=("bedgraph", "bigwig", "coverage"),
help="Output format")
p.add_option("--nosort", default=False, action="store_true",
help="Do not sort BAM")
p.set_outfile()
opts, args = p.parse_args(args)
if len(args) != 2:
sys.exit(not p.print_help())
fastafile, bamfile = args
format = opts.format
if opts.nosort:
logging.debug("BAM sorting skipped")
else:
bamfile = index([bamfile, "--fasta={0}".format(fastafile)])
pf = bamfile.rsplit(".", 2)[0]
sizesfile = Sizes(fastafile).filename
cmd = "genomeCoverageBed -ibam {0} -g {1}".format(bamfile, sizesfile)
if format in ("bedgraph", "bigwig"):
cmd += " -bg"
bedgraphfile = pf + ".bedgraph"
sh(cmd, outfile=bedgraphfile)
if format == "bedgraph":
return bedgraphfile
bigwigfile = pf + ".bigwig"
cmd = "bedGraphToBigWig {0} {1} {2}".\
format(bedgraphfile, sizesfile, bigwigfile)
sh(cmd)
return bigwigfile
coveragefile = pf + ".coverage"
if need_update(fastafile, coveragefile):
sh(cmd, outfile=coveragefile)
gcf = GenomeCoverageFile(coveragefile)
fw = must_open(opts.outfile, "w")
for seqid, cov in gcf.iter_coverage_seqid():
print("\t".join((seqid, "{0:.1f}".format(cov))), file=fw)
fw.close() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_number_finder; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:s; 5, identifier:regex; 6, identifier:numconv; 7, block; 7, 8; 7, 17; 7, 30; 7, 37; 7, 64; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:s; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:regex; 14, identifier:split; 15, argument_list; 15, 16; 16, identifier:s; 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:s; 23, integer:1; 24, block; 24, 25; 25, return_statement; 25, 26; 26, call; 26, 27; 26, 28; 27, identifier:tuple; 28, argument_list; 28, 29; 29, identifier:s; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:s; 33, call; 33, 34; 33, 35; 34, identifier:remove_empty; 35, argument_list; 35, 36; 36, identifier:s; 37, for_statement; 37, 38; 37, 39; 37, 46; 38, identifier:i; 39, call; 39, 40; 39, 41; 40, identifier:range; 41, argument_list; 41, 42; 42, call; 42, 43; 42, 44; 43, identifier:len; 44, argument_list; 44, 45; 45, identifier:s; 46, block; 46, 47; 47, try_statement; 47, 48; 47, 60; 48, block; 48, 49; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 54; 51, subscript; 51, 52; 51, 53; 52, identifier:s; 53, identifier:i; 54, call; 54, 55; 54, 56; 55, identifier:numconv; 56, argument_list; 56, 57; 57, subscript; 57, 58; 57, 59; 58, identifier:s; 59, identifier:i; 60, except_clause; 60, 61; 60, 62; 61, identifier:ValueError; 62, block; 62, 63; 63, pass_statement; 64, if_statement; 64, 65; 64, 75; 64, 81; 65, not_operator; 65, 66; 66, call; 66, 67; 66, 68; 67, identifier:isinstance; 68, argument_list; 68, 69; 68, 72; 69, subscript; 69, 70; 69, 71; 70, identifier:s; 71, integer:0; 72, attribute; 72, 73; 72, 74; 73, identifier:six; 74, identifier:string_types; 75, block; 75, 76; 76, return_statement; 76, 77; 77, binary_operator:+; 77, 78; 77, 80; 78, list:['']; 78, 79; 79, string:''; 80, identifier:s; 81, else_clause; 81, 82; 82, block; 82, 83; 83, return_statement; 83, 84; 84, identifier:s | def _number_finder(s, regex, numconv):
s = regex.split(s)
if len(s) == 1:
return tuple(s)
s = remove_empty(s)
for i in range(len(s)):
try:
s[i] = numconv(s[i])
except ValueError:
pass
if not isinstance(s[0], six.string_types):
return [''] + s
else:
return s |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:index_natsorted; 3, parameters; 3, 4; 3, 5; 3, 11; 3, 14; 3, 17; 4, identifier:seq; 5, default_parameter; 5, 6; 5, 7; 6, identifier:key; 7, lambda; 7, 8; 7, 10; 8, lambda_parameters; 8, 9; 9, identifier:x; 10, identifier:x; 11, default_parameter; 11, 12; 11, 13; 12, identifier:number_type; 13, identifier:float; 14, default_parameter; 14, 15; 14, 16; 15, identifier:signed; 16, True; 17, default_parameter; 17, 18; 17, 19; 18, identifier:exp; 19, True; 20, block; 20, 21; 20, 26; 20, 33; 20, 58; 20, 85; 21, import_from_statement; 21, 22; 21, 24; 22, dotted_name; 22, 23; 23, identifier:operator; 24, dotted_name; 24, 25; 25, identifier:itemgetter; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:item1; 29, call; 29, 30; 29, 31; 30, identifier:itemgetter; 31, argument_list; 31, 32; 32, integer:1; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:index_seq_pair; 36, list_comprehension; 36, 37; 36, 43; 37, list:[x, key(y)]; 37, 38; 37, 39; 38, identifier:x; 39, call; 39, 40; 39, 41; 40, identifier:key; 41, argument_list; 41, 42; 42, identifier:y; 43, for_in_clause; 43, 44; 43, 47; 44, pattern_list; 44, 45; 44, 46; 45, identifier:x; 46, identifier:y; 47, call; 47, 48; 47, 49; 48, identifier:zip; 49, argument_list; 49, 50; 49, 57; 50, call; 50, 51; 50, 52; 51, identifier:range; 52, argument_list; 52, 53; 53, call; 53, 54; 53, 55; 54, identifier:len; 55, argument_list; 55, 56; 56, identifier:seq; 57, identifier:seq; 58, expression_statement; 58, 59; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:index_seq_pair; 62, identifier:sort; 63, argument_list; 63, 64; 64, keyword_argument; 64, 65; 64, 66; 65, identifier:key; 66, lambda; 66, 67; 66, 69; 67, lambda_parameters; 67, 68; 68, identifier:x; 69, call; 69, 70; 69, 71; 70, identifier:natsort_key; 71, argument_list; 71, 72; 71, 76; 71, 79; 71, 82; 72, call; 72, 73; 72, 74; 73, identifier:item1; 74, argument_list; 74, 75; 75, identifier:x; 76, keyword_argument; 76, 77; 76, 78; 77, identifier:number_type; 78, identifier:number_type; 79, keyword_argument; 79, 80; 79, 81; 80, identifier:signed; 81, identifier:signed; 82, keyword_argument; 82, 83; 82, 84; 83, identifier:exp; 84, identifier:exp; 85, return_statement; 85, 86; 86, list_comprehension; 86, 87; 86, 90; 87, subscript; 87, 88; 87, 89; 88, identifier:x; 89, integer:0; 90, for_in_clause; 90, 91; 90, 92; 91, identifier:x; 92, identifier:index_seq_pair | def index_natsorted(seq, key=lambda x: x, number_type=float, signed=True, exp=True):
from operator import itemgetter
item1 = itemgetter(1)
index_seq_pair = [[x, key(y)] for x, y in zip(range(len(seq)), seq)]
index_seq_pair.sort(key=lambda x: natsort_key(item1(x),
number_type=number_type,
signed=signed, exp=exp))
return [x[0] for x in index_seq_pair] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort; 3, parameters; 3, 4; 4, identifier:args; 5, block; 5, 6; 5, 15; 5, 35; 5, 54; 5, 70; 5, 79; 5, 85; 5, 96; 5, 116; 5, 121; 5, 127; 5, 137; 5, 143; 5, 182; 5, 192; 5, 196; 5, 212; 5, 221; 5, 232; 5, 246; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:p; 9, call; 9, 10; 9, 11; 10, identifier:OptionParser; 11, argument_list; 11, 12; 12, attribute; 12, 13; 12, 14; 13, identifier:sort; 14, identifier:__doc__; 15, expression_statement; 15, 16; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:p; 19, identifier:add_option; 20, argument_list; 20, 21; 20, 22; 20, 23; 20, 26; 20, 29; 20, 32; 21, string:"-i"; 22, string:"--inplace"; 23, keyword_argument; 23, 24; 23, 25; 24, identifier:dest; 25, string:"inplace"; 26, keyword_argument; 26, 27; 26, 28; 27, identifier:default; 28, False; 29, keyword_argument; 29, 30; 29, 31; 30, identifier:action; 31, string:"store_true"; 32, keyword_argument; 32, 33; 32, 34; 33, identifier:help; 34, string:"Sort bed file in place [default: %default]"; 35, expression_statement; 35, 36; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:p; 39, identifier:add_option; 40, argument_list; 40, 41; 40, 42; 40, 45; 40, 48; 40, 51; 41, string:"-u"; 42, keyword_argument; 42, 43; 42, 44; 43, identifier:dest; 44, string:"unique"; 45, keyword_argument; 45, 46; 45, 47; 46, identifier:default; 47, False; 48, keyword_argument; 48, 49; 48, 50; 49, identifier:action; 50, string:"store_true"; 51, keyword_argument; 51, 52; 51, 53; 52, identifier:help; 53, string:"Uniqify the bed file"; 54, expression_statement; 54, 55; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:p; 58, identifier:add_option; 59, argument_list; 59, 60; 59, 61; 59, 64; 59, 67; 60, string:"--accn"; 61, keyword_argument; 61, 62; 61, 63; 62, identifier:default; 63, False; 64, keyword_argument; 64, 65; 64, 66; 65, identifier:action; 66, string:"store_true"; 67, keyword_argument; 67, 68; 67, 69; 68, identifier:help; 69, string:"Sort based on the accessions [default: %default]"; 70, expression_statement; 70, 71; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:p; 74, identifier:set_outfile; 75, argument_list; 75, 76; 76, keyword_argument; 76, 77; 76, 78; 77, identifier:outfile; 78, None; 79, expression_statement; 79, 80; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:p; 83, identifier:set_tmpdir; 84, argument_list; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 90; 87, pattern_list; 87, 88; 87, 89; 88, identifier:opts; 89, identifier:args; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:p; 93, identifier:parse_args; 94, argument_list; 94, 95; 95, identifier:args; 96, if_statement; 96, 97; 96, 103; 97, comparison_operator:!=; 97, 98; 97, 102; 98, call; 98, 99; 98, 100; 99, identifier:len; 100, argument_list; 100, 101; 101, identifier:args; 102, integer:1; 103, block; 103, 104; 104, expression_statement; 104, 105; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:sys; 108, identifier:exit; 109, argument_list; 109, 110; 110, not_operator; 110, 111; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:p; 114, identifier:print_help; 115, argument_list; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 120; 118, pattern_list; 118, 119; 119, identifier:bedfile; 120, identifier:args; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:inplace; 124, attribute; 124, 125; 124, 126; 125, identifier:opts; 126, identifier:inplace; 127, if_statement; 127, 128; 127, 134; 128, boolean_operator:and; 128, 129; 128, 131; 129, not_operator; 129, 130; 130, identifier:inplace; 131, comparison_operator:in; 131, 132; 131, 133; 132, string:".sorted."; 133, identifier:bedfile; 134, block; 134, 135; 135, return_statement; 135, 136; 136, identifier:bedfile; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:sortedbed; 140, attribute; 140, 141; 140, 142; 141, identifier:opts; 142, identifier:outfile; 143, if_statement; 143, 144; 143, 145; 143, 150; 144, identifier:inplace; 145, block; 145, 146; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:sortedbed; 149, identifier:bedfile; 150, elif_clause; 150, 151; 150, 156; 151, comparison_operator:is; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:opts; 154, identifier:outfile; 155, None; 156, block; 156, 157; 156, 174; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 162; 159, pattern_list; 159, 160; 159, 161; 160, identifier:pf; 161, identifier:sf; 162, call; 162, 163; 162, 171; 163, attribute; 163, 164; 163, 170; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:op; 167, identifier:basename; 168, argument_list; 168, 169; 169, identifier:bedfile; 170, identifier:rsplit; 171, argument_list; 171, 172; 171, 173; 172, string:"."; 173, integer:1; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 177; 176, identifier:sortedbed; 177, binary_operator:+; 177, 178; 177, 181; 178, binary_operator:+; 178, 179; 178, 180; 179, identifier:pf; 180, string:".sorted."; 181, identifier:sf; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 185; 184, identifier:sortopt; 185, conditional_expression:if; 185, 186; 185, 187; 185, 191; 186, string:"-k1,1 -k2,2n -k3,3n -k4,4"; 187, not_operator; 187, 188; 188, attribute; 188, 189; 188, 190; 189, identifier:opts; 190, identifier:accn; 191, string:"-k4,4 -k1,1 -k2,2n -k3,3n"; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 195; 194, identifier:cmd; 195, string:"sort"; 196, if_statement; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:opts; 199, identifier:tmpdir; 200, block; 200, 201; 201, expression_statement; 201, 202; 202, augmented_assignment:+=; 202, 203; 202, 204; 203, identifier:cmd; 204, call; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, string:" -T {0}"; 207, identifier:format; 208, argument_list; 208, 209; 209, attribute; 209, 210; 209, 211; 210, identifier:opts; 211, identifier:tmpdir; 212, if_statement; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:opts; 215, identifier:unique; 216, block; 216, 217; 217, expression_statement; 217, 218; 218, augmented_assignment:+=; 218, 219; 218, 220; 219, identifier:cmd; 220, string:" -u"; 221, expression_statement; 221, 222; 222, augmented_assignment:+=; 222, 223; 222, 224; 223, identifier:cmd; 224, call; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, string:" {0} {1} -o {2}"; 227, identifier:format; 228, argument_list; 228, 229; 228, 230; 228, 231; 229, identifier:sortopt; 230, identifier:bedfile; 231, identifier:sortedbed; 232, if_statement; 232, 233; 232, 240; 233, boolean_operator:or; 233, 234; 233, 235; 234, identifier:inplace; 235, call; 235, 236; 235, 237; 236, identifier:need_update; 237, argument_list; 237, 238; 237, 239; 238, identifier:bedfile; 239, identifier:sortedbed; 240, block; 240, 241; 241, expression_statement; 241, 242; 242, call; 242, 243; 242, 244; 243, identifier:sh; 244, argument_list; 244, 245; 245, identifier:cmd; 246, return_statement; 246, 247; 247, identifier:sortedbed | def sort(args):
p = OptionParser(sort.__doc__)
p.add_option("-i", "--inplace", dest="inplace",
default=False, action="store_true",
help="Sort bed file in place [default: %default]")
p.add_option("-u", dest="unique",
default=False, action="store_true",
help="Uniqify the bed file")
p.add_option("--accn", default=False, action="store_true",
help="Sort based on the accessions [default: %default]")
p.set_outfile(outfile=None)
p.set_tmpdir()
opts, args = p.parse_args(args)
if len(args) != 1:
sys.exit(not p.print_help())
bedfile, = args
inplace = opts.inplace
if not inplace and ".sorted." in bedfile:
return bedfile
sortedbed = opts.outfile
if inplace:
sortedbed = bedfile
elif opts.outfile is None:
pf, sf = op.basename(bedfile).rsplit(".", 1)
sortedbed = pf + ".sorted." + sf
sortopt = "-k1,1 -k2,2n -k3,3n -k4,4" if not opts.accn else \
"-k4,4 -k1,1 -k2,2n -k3,3n"
cmd = "sort"
if opts.tmpdir:
cmd += " -T {0}".format(opts.tmpdir)
if opts.unique:
cmd += " -u"
cmd += " {0} {1} -o {2}".format(sortopt, bedfile, sortedbed)
if inplace or need_update(bedfile, sortedbed):
sh(cmd)
return sortedbed |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:by_image_seq; 3, parameters; 3, 4; 3, 5; 4, identifier:blocks; 5, identifier:image_seq; 6, block; 6, 7; 7, return_statement; 7, 8; 8, call; 8, 9; 8, 10; 9, identifier:list; 10, argument_list; 10, 11; 11, call; 11, 12; 11, 13; 12, identifier:filter; 13, argument_list; 13, 14; 13, 26; 14, lambda; 14, 15; 14, 17; 15, lambda_parameters; 15, 16; 16, identifier:block; 17, comparison_operator:==; 17, 18; 17, 25; 18, attribute; 18, 19; 18, 24; 19, attribute; 19, 20; 19, 23; 20, subscript; 20, 21; 20, 22; 21, identifier:blocks; 22, identifier:block; 23, identifier:ec_hdr; 24, identifier:image_seq; 25, identifier:image_seq; 26, identifier:blocks | def by_image_seq(blocks, image_seq):
return list(filter(lambda block: blocks[block].ec_hdr.image_seq == image_seq, blocks)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:by_vol_id; 3, parameters; 3, 4; 3, 5; 4, identifier:blocks; 5, default_parameter; 5, 6; 5, 7; 6, identifier:slist; 7, None; 8, block; 8, 9; 8, 13; 8, 76; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:vol_blocks; 12, dictionary; 13, for_statement; 13, 14; 13, 15; 13, 16; 14, identifier:i; 15, identifier:blocks; 16, block; 16, 17; 16, 34; 16, 57; 17, if_statement; 17, 18; 17, 23; 17, 25; 18, boolean_operator:and; 18, 19; 18, 20; 19, identifier:slist; 20, comparison_operator:not; 20, 21; 20, 22; 21, identifier:i; 22, identifier:slist; 23, block; 23, 24; 24, continue_statement; 25, elif_clause; 25, 26; 25, 32; 26, not_operator; 26, 27; 27, attribute; 27, 28; 27, 31; 28, subscript; 28, 29; 28, 30; 29, identifier:blocks; 30, identifier:i; 31, identifier:is_valid; 32, block; 32, 33; 33, continue_statement; 34, if_statement; 34, 35; 34, 44; 35, comparison_operator:not; 35, 36; 35, 43; 36, attribute; 36, 37; 36, 42; 37, attribute; 37, 38; 37, 41; 38, subscript; 38, 39; 38, 40; 39, identifier:blocks; 40, identifier:i; 41, identifier:vid_hdr; 42, identifier:vol_id; 43, identifier:vol_blocks; 44, block; 44, 45; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 56; 47, subscript; 47, 48; 47, 49; 48, identifier:vol_blocks; 49, attribute; 49, 50; 49, 55; 50, attribute; 50, 51; 50, 54; 51, subscript; 51, 52; 51, 53; 52, identifier:blocks; 53, identifier:i; 54, identifier:vid_hdr; 55, identifier:vol_id; 56, list:[]; 57, expression_statement; 57, 58; 58, call; 58, 59; 58, 70; 59, attribute; 59, 60; 59, 69; 60, subscript; 60, 61; 60, 62; 61, identifier:vol_blocks; 62, attribute; 62, 63; 62, 68; 63, attribute; 63, 64; 63, 67; 64, subscript; 64, 65; 64, 66; 65, identifier:blocks; 66, identifier:i; 67, identifier:vid_hdr; 68, identifier:vol_id; 69, identifier:append; 70, argument_list; 70, 71; 71, attribute; 71, 72; 71, 75; 72, subscript; 72, 73; 72, 74; 73, identifier:blocks; 74, identifier:i; 75, identifier:peb_num; 76, return_statement; 76, 77; 77, identifier:vol_blocks | def by_vol_id(blocks, slist=None):
vol_blocks = {}
for i in blocks:
if slist and i not in slist:
continue
elif not blocks[i].is_valid:
continue
if blocks[i].vid_hdr.vol_id not in vol_blocks:
vol_blocks[blocks[i].vid_hdr.vol_id] = []
vol_blocks[blocks[i].vid_hdr.vol_id].append(blocks[i].peb_num)
return vol_blocks |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:by_type; 3, parameters; 3, 4; 3, 5; 4, identifier:blocks; 5, default_parameter; 5, 6; 5, 7; 6, identifier:slist; 7, None; 8, block; 8, 9; 8, 13; 8, 17; 8, 21; 8, 25; 8, 100; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:layout; 12, list:[]; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:data; 16, list:[]; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:int_vol; 20, list:[]; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:unknown; 24, list:[]; 25, for_statement; 25, 26; 25, 27; 25, 28; 26, identifier:i; 27, identifier:blocks; 28, block; 28, 29; 28, 37; 29, if_statement; 29, 30; 29, 35; 30, boolean_operator:and; 30, 31; 30, 32; 31, identifier:slist; 32, comparison_operator:not; 32, 33; 32, 34; 33, identifier:i; 34, identifier:slist; 35, block; 35, 36; 36, continue_statement; 37, if_statement; 37, 38; 37, 49; 37, 57; 37, 77; 37, 91; 38, boolean_operator:and; 38, 39; 38, 44; 39, attribute; 39, 40; 39, 43; 40, subscript; 40, 41; 40, 42; 41, identifier:blocks; 42, identifier:i; 43, identifier:is_vtbl; 44, attribute; 44, 45; 44, 48; 45, subscript; 45, 46; 45, 47; 46, identifier:blocks; 47, identifier:i; 48, identifier:is_valid; 49, block; 49, 50; 50, expression_statement; 50, 51; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:layout; 54, identifier:append; 55, argument_list; 55, 56; 56, identifier:i; 57, elif_clause; 57, 58; 57, 69; 58, boolean_operator:and; 58, 59; 58, 64; 59, attribute; 59, 60; 59, 63; 60, subscript; 60, 61; 60, 62; 61, identifier:blocks; 62, identifier:i; 63, identifier:is_internal_vol; 64, attribute; 64, 65; 64, 68; 65, subscript; 65, 66; 65, 67; 66, identifier:blocks; 67, identifier:i; 68, identifier:is_valid; 69, block; 69, 70; 70, expression_statement; 70, 71; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:int_vol; 74, identifier:append; 75, argument_list; 75, 76; 76, identifier:i; 77, elif_clause; 77, 78; 77, 83; 78, attribute; 78, 79; 78, 82; 79, subscript; 79, 80; 79, 81; 80, identifier:blocks; 81, identifier:i; 82, identifier:is_valid; 83, block; 83, 84; 84, expression_statement; 84, 85; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:data; 88, identifier:append; 89, argument_list; 89, 90; 90, identifier:i; 91, else_clause; 91, 92; 92, block; 92, 93; 93, expression_statement; 93, 94; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:unknown; 97, identifier:append; 98, argument_list; 98, 99; 99, identifier:i; 100, return_statement; 100, 101; 101, expression_list; 101, 102; 101, 103; 101, 104; 101, 105; 102, identifier:layout; 103, identifier:data; 104, identifier:int_vol; 105, identifier:unknown | def by_type(blocks, slist=None):
layout = []
data = []
int_vol = []
unknown = []
for i in blocks:
if slist and i not in slist:
continue
if blocks[i].is_vtbl and blocks[i].is_valid:
layout.append(i)
elif blocks[i].is_internal_vol and blocks[i].is_valid:
int_vol.append(i)
elif blocks[i].is_valid:
data.append(i)
else:
unknown.append(i)
return layout, data, int_vol, unknown |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:group_pairs; 3, parameters; 3, 4; 3, 5; 4, identifier:blocks; 5, identifier:layout_blocks_list; 6, block; 6, 7; 6, 11; 6, 48; 6, 63; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:image_dict; 10, dictionary; 11, for_statement; 11, 12; 11, 13; 11, 14; 12, identifier:block_id; 13, identifier:layout_blocks_list; 14, block; 14, 15; 14, 25; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:image_seq; 18, attribute; 18, 19; 18, 24; 19, attribute; 19, 20; 19, 23; 20, subscript; 20, 21; 20, 22; 21, identifier:blocks; 22, identifier:block_id; 23, identifier:ec_hdr; 24, identifier:image_seq; 25, if_statement; 25, 26; 25, 29; 25, 37; 26, comparison_operator:not; 26, 27; 26, 28; 27, identifier:image_seq; 28, identifier:image_dict; 29, block; 29, 30; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 35; 32, subscript; 32, 33; 32, 34; 33, identifier:image_dict; 34, identifier:image_seq; 35, list:[block_id]; 35, 36; 36, identifier:block_id; 37, else_clause; 37, 38; 38, block; 38, 39; 39, expression_statement; 39, 40; 40, call; 40, 41; 40, 46; 41, attribute; 41, 42; 41, 45; 42, subscript; 42, 43; 42, 44; 43, identifier:image_dict; 44, identifier:image_seq; 45, identifier:append; 46, argument_list; 46, 47; 47, identifier:block_id; 48, expression_statement; 48, 49; 49, call; 49, 50; 49, 51; 50, identifier:log; 51, argument_list; 51, 52; 51, 53; 52, identifier:group_pairs; 53, binary_operator:%; 53, 54; 53, 55; 54, string:'Layout blocks found at PEBs: %s'; 55, call; 55, 56; 55, 57; 56, identifier:list; 57, argument_list; 57, 58; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:image_dict; 61, identifier:values; 62, argument_list; 63, return_statement; 63, 64; 64, call; 64, 65; 64, 66; 65, identifier:list; 66, argument_list; 66, 67; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:image_dict; 70, identifier:values; 71, argument_list | def group_pairs(blocks, layout_blocks_list):
image_dict={}
for block_id in layout_blocks_list:
image_seq=blocks[block_id].ec_hdr.image_seq
if image_seq not in image_dict:
image_dict[image_seq]=[block_id]
else:
image_dict[image_seq].append(block_id)
log(group_pairs, 'Layout blocks found at PEBs: %s' % list(image_dict.values()))
return list(image_dict.values()) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:read_cBpack; 3, parameters; 3, 4; 4, identifier:filename; 5, block; 5, 6; 5, 32; 5, 38; 5, 72; 6, with_statement; 6, 7; 6, 19; 7, with_clause; 7, 8; 8, with_item; 8, 9; 9, as_pattern; 9, 10; 9, 17; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:gzip; 13, identifier:open; 14, argument_list; 14, 15; 14, 16; 15, identifier:filename; 16, string:'rb'; 17, as_pattern_target; 17, 18; 18, identifier:infile; 19, block; 19, 20; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:data; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:msgpack; 26, identifier:load; 27, argument_list; 27, 28; 27, 29; 28, identifier:infile; 29, keyword_argument; 29, 30; 29, 31; 30, identifier:raw; 31, False; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:header; 35, subscript; 35, 36; 35, 37; 36, identifier:data; 37, integer:0; 38, if_statement; 38, 39; 38, 64; 39, parenthesized_expression; 39, 40; 40, boolean_operator:or; 40, 41; 40, 56; 41, boolean_operator:or; 41, 42; 41, 48; 42, not_operator; 42, 43; 43, call; 43, 44; 43, 45; 44, identifier:isinstance; 45, argument_list; 45, 46; 45, 47; 46, identifier:header; 47, identifier:dict; 48, comparison_operator:!=; 48, 49; 48, 55; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:header; 52, identifier:get; 53, argument_list; 53, 54; 54, string:'format'; 55, string:'cB'; 56, comparison_operator:!=; 56, 57; 56, 63; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:header; 60, identifier:get; 61, argument_list; 61, 62; 62, string:'version'; 63, integer:1; 64, block; 64, 65; 65, raise_statement; 65, 66; 66, call; 66, 67; 66, 68; 67, identifier:ValueError; 68, argument_list; 68, 69; 69, binary_operator:%; 69, 70; 69, 71; 70, string:"Unexpected header: %r"; 71, identifier:header; 72, return_statement; 72, 73; 73, subscript; 73, 74; 73, 75; 74, identifier:data; 75, slice; 75, 76; 75, 77; 76, integer:1; 77, colon | def read_cBpack(filename):
with gzip.open(filename, 'rb') as infile:
data = msgpack.load(infile, raw=False)
header = data[0]
if (
not isinstance(header, dict) or header.get('format') != 'cB'
or header.get('version') != 1
):
raise ValueError("Unexpected header: %r" % header)
return data[1:] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:addDiscreteOutcomeConstantMean; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:distribution; 5, identifier:x; 6, identifier:p; 7, default_parameter; 7, 8; 7, 9; 8, identifier:sort; 9, False; 10, block; 10, 11; 10, 13; 10, 37; 10, 54; 10, 78; 11, expression_statement; 11, 12; 12, string:'''
Adds a discrete outcome of x with probability p to an existing distribution,
holding constant the relative probabilities of other outcomes and overall mean.
Parameters
----------
distribution : [np.array]
Two element list containing a list of probabilities and a list of outcomes.
x : float
The new value to be added to the distribution.
p : float
The probability of the discrete outcome x occuring.
sort: bool
Whether or not to sort X before returning it
Returns
-------
X : np.array
Discrete points for discrete probability mass function.
pmf : np.array
Probability associated with each point in X.
Written by Matthew N. White
Latest update: 08 December 2015 by David Low
'''; 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:np; 19, identifier:append; 20, argument_list; 20, 21; 20, 22; 21, identifier:x; 22, binary_operator:/; 22, 23; 22, 33; 23, binary_operator:*; 23, 24; 23, 27; 24, subscript; 24, 25; 24, 26; 25, identifier:distribution; 26, integer:1; 27, parenthesized_expression; 27, 28; 28, binary_operator:-; 28, 29; 28, 30; 29, integer:1; 30, binary_operator:*; 30, 31; 30, 32; 31, identifier:p; 32, identifier:x; 33, parenthesized_expression; 33, 34; 34, binary_operator:-; 34, 35; 34, 36; 35, integer:1; 36, identifier:p; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:pmf; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:np; 43, identifier:append; 44, argument_list; 44, 45; 44, 46; 45, identifier:p; 46, binary_operator:*; 46, 47; 46, 50; 47, subscript; 47, 48; 47, 49; 48, identifier:distribution; 49, integer:0; 50, parenthesized_expression; 50, 51; 51, binary_operator:-; 51, 52; 51, 53; 52, integer:1; 53, identifier:p; 54, if_statement; 54, 55; 54, 56; 55, identifier:sort; 56, block; 56, 57; 56, 66; 56, 72; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:indices; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:np; 63, identifier:argsort; 64, argument_list; 64, 65; 65, identifier:X; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:X; 69, subscript; 69, 70; 69, 71; 70, identifier:X; 71, identifier:indices; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:pmf; 75, subscript; 75, 76; 75, 77; 76, identifier:pmf; 77, identifier:indices; 78, return_statement; 78, 79; 79, parenthesized_expression; 79, 80; 80, list:[pmf,X]; 80, 81; 80, 82; 81, identifier:pmf; 82, identifier:X | def addDiscreteOutcomeConstantMean(distribution, x, p, sort = False):
'''
Adds a discrete outcome of x with probability p to an existing distribution,
holding constant the relative probabilities of other outcomes and overall mean.
Parameters
----------
distribution : [np.array]
Two element list containing a list of probabilities and a list of outcomes.
x : float
The new value to be added to the distribution.
p : float
The probability of the discrete outcome x occuring.
sort: bool
Whether or not to sort X before returning it
Returns
-------
X : np.array
Discrete points for discrete probability mass function.
pmf : np.array
Probability associated with each point in X.
Written by Matthew N. White
Latest update: 08 December 2015 by David Low
'''
X = np.append(x,distribution[1]*(1-p*x)/(1-p))
pmf = np.append(p,distribution[0]*(1-p))
if sort:
indices = np.argsort(X)
X = X[indices]
pmf = pmf[indices]
return([pmf,X]) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:runStickyEregressionsInStata; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 4, identifier:infile_name; 5, identifier:interval_size; 6, identifier:meas_err; 7, identifier:sticky; 8, identifier:all_specs; 9, identifier:stata_exe; 10, block; 10, 11; 10, 13; 10, 17; 10, 32; 10, 45; 10, 58; 10, 75; 10, 87; 10, 97; 10, 112; 10, 157; 11, expression_statement; 11, 12; 12, string:'''
Runs regressions for the main tables of the StickyC paper in Stata and produces a
LaTeX table with results for one "panel". Running in Stata allows production of
the KP-statistic, for which there is currently no command in statsmodels.api.
Parameters
----------
infile_name : str
Name of tab-delimited text file with simulation data. Assumed to be in
the results directory, and was almost surely generated by makeStickyEdataFile
unless we resort to fabricating simulated data. THAT'S A JOKE, FUTURE REFEREES.
interval_size : int
Number of periods in each regression sample (or interval).
meas_err : bool
Indicator for whether to add measurement error to DeltaLogC.
sticky : bool
Indicator for whether these results used sticky expectations.
all_specs : bool
Indicator for whether this panel should include all specifications or
just the OLS on lagged consumption growth.
stata_exe : str
Absolute location where the Stata executable can be found on the computer
running this code. Usually set at the top of StickyEparams.py.
Returns
-------
panel_text : str
String with one panel's worth of LaTeX input.
'''; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:dofile; 16, string:"StickyETimeSeries.do"; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:infile_name_full; 20, call; 20, 21; 20, 26; 21, attribute; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:os; 24, identifier:path; 25, identifier:abspath; 26, argument_list; 26, 27; 27, binary_operator:+; 27, 28; 27, 31; 28, binary_operator:+; 28, 29; 28, 30; 29, identifier:results_dir; 30, identifier:infile_name; 31, string:".txt"; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:temp_name_full; 35, call; 35, 36; 35, 41; 36, attribute; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:os; 39, identifier:path; 40, identifier:abspath; 41, argument_list; 41, 42; 42, binary_operator:+; 42, 43; 42, 44; 43, identifier:results_dir; 44, string:"temp.txt"; 45, if_statement; 45, 46; 45, 47; 45, 52; 46, identifier:meas_err; 47, block; 47, 48; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:meas_err_stata; 51, integer:1; 52, else_clause; 52, 53; 53, block; 53, 54; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:meas_err_stata; 57, integer:0; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:cmd; 61, list:[stata_exe, "do", dofile, infile_name_full, temp_name_full, str(interval_size), str(meas_err_stata)]; 61, 62; 61, 63; 61, 64; 61, 65; 61, 66; 61, 67; 61, 71; 62, identifier:stata_exe; 63, string:"do"; 64, identifier:dofile; 65, identifier:infile_name_full; 66, identifier:temp_name_full; 67, call; 67, 68; 67, 69; 68, identifier:str; 69, argument_list; 69, 70; 70, identifier:interval_size; 71, call; 71, 72; 71, 73; 72, identifier:str; 73, argument_list; 73, 74; 74, identifier:meas_err_stata; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:stata_status; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:subprocess; 81, identifier:call; 82, argument_list; 82, 83; 82, 84; 83, identifier:cmd; 84, keyword_argument; 84, 85; 84, 86; 85, identifier:shell; 86, string:'true'; 87, if_statement; 87, 88; 87, 91; 88, comparison_operator:!=; 88, 89; 88, 90; 89, identifier:stata_status; 90, integer:0; 91, block; 91, 92; 92, raise_statement; 92, 93; 93, call; 93, 94; 93, 95; 94, identifier:ValueError; 95, argument_list; 95, 96; 96, string:'Stata code could not run. Check the stata_exe in StickyEparams.py'; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:stata_output; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:pd; 103, identifier:read_csv; 104, argument_list; 104, 105; 104, 106; 104, 109; 105, identifier:temp_name_full; 106, keyword_argument; 106, 107; 106, 108; 107, identifier:sep; 108, string:','; 109, keyword_argument; 109, 110; 109, 111; 110, identifier:header; 111, integer:0; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:panel_text; 115, call; 115, 116; 115, 117; 116, identifier:makeResultsPanel; 117, argument_list; 117, 118; 117, 123; 117, 128; 117, 133; 117, 138; 117, 143; 117, 148; 117, 151; 117, 154; 118, keyword_argument; 118, 119; 118, 120; 119, identifier:Coeffs; 120, attribute; 120, 121; 120, 122; 121, identifier:stata_output; 122, identifier:CoeffsArray; 123, keyword_argument; 123, 124; 123, 125; 124, identifier:StdErrs; 125, attribute; 125, 126; 125, 127; 126, identifier:stata_output; 127, identifier:StdErrArray; 128, keyword_argument; 128, 129; 128, 130; 129, identifier:Rsq; 130, attribute; 130, 131; 130, 132; 131, identifier:stata_output; 132, identifier:RsqArray; 133, keyword_argument; 133, 134; 133, 135; 134, identifier:Pvals; 135, attribute; 135, 136; 135, 137; 136, identifier:stata_output; 137, identifier:PvalArray; 138, keyword_argument; 138, 139; 138, 140; 139, identifier:OID; 140, attribute; 140, 141; 140, 142; 141, identifier:stata_output; 142, identifier:OIDarray; 143, keyword_argument; 143, 144; 143, 145; 144, identifier:Counts; 145, attribute; 145, 146; 145, 147; 146, identifier:stata_output; 147, identifier:ExtraInfo; 148, keyword_argument; 148, 149; 148, 150; 149, identifier:meas_err; 150, identifier:meas_err; 151, keyword_argument; 151, 152; 151, 153; 152, identifier:sticky; 153, identifier:sticky; 154, keyword_argument; 154, 155; 154, 156; 155, identifier:all_specs; 156, identifier:all_specs; 157, return_statement; 157, 158; 158, identifier:panel_text | def runStickyEregressionsInStata(infile_name,interval_size,meas_err,sticky,all_specs,stata_exe):
'''
Runs regressions for the main tables of the StickyC paper in Stata and produces a
LaTeX table with results for one "panel". Running in Stata allows production of
the KP-statistic, for which there is currently no command in statsmodels.api.
Parameters
----------
infile_name : str
Name of tab-delimited text file with simulation data. Assumed to be in
the results directory, and was almost surely generated by makeStickyEdataFile
unless we resort to fabricating simulated data. THAT'S A JOKE, FUTURE REFEREES.
interval_size : int
Number of periods in each regression sample (or interval).
meas_err : bool
Indicator for whether to add measurement error to DeltaLogC.
sticky : bool
Indicator for whether these results used sticky expectations.
all_specs : bool
Indicator for whether this panel should include all specifications or
just the OLS on lagged consumption growth.
stata_exe : str
Absolute location where the Stata executable can be found on the computer
running this code. Usually set at the top of StickyEparams.py.
Returns
-------
panel_text : str
String with one panel's worth of LaTeX input.
'''
dofile = "StickyETimeSeries.do"
infile_name_full = os.path.abspath(results_dir + infile_name + ".txt")
temp_name_full = os.path.abspath(results_dir + "temp.txt")
if meas_err:
meas_err_stata = 1
else:
meas_err_stata = 0
cmd = [stata_exe, "do", dofile, infile_name_full, temp_name_full, str(interval_size), str(meas_err_stata)]
stata_status = subprocess.call(cmd,shell = 'true')
if stata_status!=0:
raise ValueError('Stata code could not run. Check the stata_exe in StickyEparams.py')
stata_output = pd.read_csv(temp_name_full, sep=',',header=0)
panel_text = makeResultsPanel(Coeffs=stata_output.CoeffsArray,
StdErrs=stata_output.StdErrArray,
Rsq=stata_output.RsqArray,
Pvals=stata_output.PvalArray,
OID=stata_output.OIDarray,
Counts=stata_output.ExtraInfo,
meas_err=meas_err,
sticky=sticky,
all_specs=all_specs)
return panel_text |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:capability_functions; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:fn; 6, block; 6, 7; 6, 18; 6, 22; 6, 66; 6, 80; 6, 91; 7, if_statement; 7, 8; 7, 9; 8, identifier:_debug; 9, block; 9, 10; 10, expression_statement; 10, 11; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:Collector; 14, identifier:_debug; 15, argument_list; 15, 16; 15, 17; 16, string:"capability_functions %r"; 17, identifier:fn; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:fns; 21, list:[]; 22, for_statement; 22, 23; 22, 24; 22, 27; 23, identifier:cls; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:capabilities; 27, block; 27, 28; 27, 37; 27, 49; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:xfn; 31, call; 31, 32; 31, 33; 32, identifier:getattr; 33, argument_list; 33, 34; 33, 35; 33, 36; 34, identifier:cls; 35, identifier:fn; 36, None; 37, if_statement; 37, 38; 37, 39; 38, identifier:_debug; 39, block; 39, 40; 40, expression_statement; 40, 41; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:Collector; 44, identifier:_debug; 45, argument_list; 45, 46; 45, 47; 45, 48; 46, string:" - cls, xfn: %r, %r"; 47, identifier:cls; 48, identifier:xfn; 49, if_statement; 49, 50; 49, 51; 50, identifier:xfn; 51, block; 51, 52; 52, expression_statement; 52, 53; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:fns; 56, identifier:append; 57, argument_list; 57, 58; 58, tuple; 58, 59; 58, 65; 59, call; 59, 60; 59, 61; 60, identifier:getattr; 61, argument_list; 61, 62; 61, 63; 61, 64; 62, identifier:cls; 63, string:'_zindex'; 64, None; 65, identifier:xfn; 66, expression_statement; 66, 67; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:fns; 70, identifier:sort; 71, argument_list; 71, 72; 72, keyword_argument; 72, 73; 72, 74; 73, identifier:key; 74, lambda; 74, 75; 74, 77; 75, lambda_parameters; 75, 76; 76, identifier:v; 77, subscript; 77, 78; 77, 79; 78, identifier:v; 79, integer:0; 80, if_statement; 80, 81; 80, 82; 81, identifier:_debug; 82, block; 82, 83; 83, expression_statement; 83, 84; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:Collector; 87, identifier:_debug; 88, argument_list; 88, 89; 88, 90; 89, string:" - fns: %r"; 90, identifier:fns; 91, for_statement; 91, 92; 91, 95; 91, 96; 92, pattern_list; 92, 93; 92, 94; 93, identifier:xindx; 94, identifier:xfn; 95, identifier:fns; 96, block; 96, 97; 96, 108; 97, if_statement; 97, 98; 97, 99; 98, identifier:_debug; 99, block; 99, 100; 100, expression_statement; 100, 101; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:Collector; 104, identifier:_debug; 105, argument_list; 105, 106; 105, 107; 106, string:" - yield xfn: %r"; 107, identifier:xfn; 108, expression_statement; 108, 109; 109, yield; 109, 110; 110, identifier:xfn | def capability_functions(self, fn):
if _debug: Collector._debug("capability_functions %r", fn)
fns = []
for cls in self.capabilities:
xfn = getattr(cls, fn, None)
if _debug: Collector._debug(" - cls, xfn: %r, %r", cls, xfn)
if xfn:
fns.append( (getattr(cls, '_zindex', None), xfn) )
fns.sort(key=lambda v: v[0])
if _debug: Collector._debug(" - fns: %r", fns)
for xindx, xfn in fns:
if _debug: Collector._debug(" - yield xfn: %r", xfn)
yield xfn |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:add; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, list_splat_pattern; 5, 6; 6, identifier:items; 7, block; 7, 8; 7, 35; 8, for_statement; 8, 9; 8, 10; 8, 11; 9, identifier:item; 10, identifier:items; 11, block; 11, 12; 11, 21; 11, 27; 12, expression_statement; 12, 13; 13, call; 13, 14; 13, 19; 14, attribute; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:unsorted; 18, identifier:append; 19, argument_list; 19, 20; 20, identifier:item; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:key; 24, subscript; 24, 25; 24, 26; 25, identifier:item; 26, integer:0; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 34; 29, subscript; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:index; 33, identifier:key; 34, identifier:item; 35, return_statement; 35, 36; 36, identifier:self | def add(self, *items):
for item in items:
self.unsorted.append(item)
key = item[0]
self.index[key] = item
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; 5, 14; 5, 22; 5, 129; 5, 137; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:sorted; 11, call; 11, 12; 11, 13; 12, identifier:list; 13, argument_list; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:pushed; 19, call; 19, 20; 19, 21; 20, identifier:set; 21, argument_list; 22, for_statement; 22, 23; 22, 24; 22, 27; 23, identifier:item; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:unsorted; 27, block; 27, 28; 27, 32; 27, 39; 27, 116; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:popped; 31, list:[]; 32, expression_statement; 32, 33; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:push; 37, argument_list; 37, 38; 38, identifier:item; 39, while_statement; 39, 40; 39, 46; 40, call; 40, 41; 40, 42; 41, identifier:len; 42, argument_list; 42, 43; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:stack; 46, block; 46, 47; 47, try_statement; 47, 48; 47, 101; 48, block; 48, 49; 48, 57; 48, 66; 48, 77; 48, 94; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:top; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:top; 56, argument_list; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:ref; 60, call; 60, 61; 60, 62; 61, identifier:next; 62, argument_list; 62, 63; 63, subscript; 63, 64; 63, 65; 64, identifier:top; 65, integer:1; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:refd; 69, call; 69, 70; 69, 75; 70, attribute; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:index; 74, identifier:get; 75, argument_list; 75, 76; 76, identifier:ref; 77, if_statement; 77, 78; 77, 81; 78, comparison_operator:is; 78, 79; 78, 80; 79, identifier:refd; 80, None; 81, block; 81, 82; 81, 93; 82, expression_statement; 82, 83; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:log; 86, identifier:debug; 87, argument_list; 87, 88; 87, 89; 88, string:'"%s" not found, skipped'; 89, call; 89, 90; 89, 91; 90, identifier:Repr; 91, argument_list; 91, 92; 92, identifier:ref; 93, continue_statement; 94, expression_statement; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:self; 98, identifier:push; 99, argument_list; 99, 100; 100, identifier:refd; 101, except_clause; 101, 102; 101, 103; 102, identifier:StopIteration; 103, block; 103, 104; 103, 115; 104, expression_statement; 104, 105; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:popped; 108, identifier:append; 109, argument_list; 109, 110; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:self; 113, identifier:pop; 114, argument_list; 115, continue_statement; 116, for_statement; 116, 117; 116, 118; 116, 119; 117, identifier:p; 118, identifier:popped; 119, block; 119, 120; 120, expression_statement; 120, 121; 121, call; 121, 122; 121, 127; 122, attribute; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:self; 125, identifier:sorted; 126, identifier:append; 127, argument_list; 127, 128; 128, identifier:p; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:self; 133, identifier:unsorted; 134, attribute; 134, 135; 134, 136; 135, identifier:self; 136, identifier:sorted; 137, return_statement; 137, 138; 138, attribute; 138, 139; 138, 140; 139, identifier:self; 140, identifier:sorted | def sort(self):
self.sorted = list()
self.pushed = set()
for item in self.unsorted:
popped = []
self.push(item)
while len(self.stack):
try:
top = self.top()
ref = next(top[1])
refd = self.index.get(ref)
if refd is None:
log.debug('"%s" not found, skipped', Repr(ref))
continue
self.push(refd)
except StopIteration:
popped.append(self.pop())
continue
for p in popped:
self.sorted.append(p)
self.unsorted = self.sorted
return self.sorted |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:push; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:item; 6, block; 6, 7; 6, 15; 6, 26; 6, 35; 7, if_statement; 7, 8; 7, 13; 8, comparison_operator:in; 8, 9; 8, 10; 9, identifier:item; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:pushed; 13, block; 13, 14; 14, return_statement; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:frame; 18, tuple; 18, 19; 18, 20; 19, identifier:item; 20, call; 20, 21; 20, 22; 21, identifier:iter; 22, argument_list; 22, 23; 23, subscript; 23, 24; 23, 25; 24, identifier:item; 25, integer:1; 26, expression_statement; 26, 27; 27, call; 27, 28; 27, 33; 28, attribute; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:stack; 32, identifier:append; 33, argument_list; 33, 34; 34, identifier:frame; 35, expression_statement; 35, 36; 36, call; 36, 37; 36, 42; 37, attribute; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:pushed; 41, identifier:add; 42, argument_list; 42, 43; 43, identifier:item | def push(self, item):
if item in self.pushed:
return
frame = (item, iter(item[1]))
self.stack.append(frame)
self.pushed.add(item) |
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:content; 6, block; 6, 7; 6, 13; 6, 39; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:v; 10, attribute; 10, 11; 10, 12; 11, identifier:content; 12, identifier:value; 13, if_statement; 13, 14; 13, 19; 14, call; 14, 15; 14, 16; 15, identifier:isinstance; 16, argument_list; 16, 17; 16, 18; 17, identifier:v; 18, identifier:Object; 19, block; 19, 20; 19, 26; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:md; 23, attribute; 23, 24; 23, 25; 24, identifier:v; 25, identifier:__metadata__; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:md; 30, identifier:ordering; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:ordering; 35, argument_list; 35, 36; 36, attribute; 36, 37; 36, 38; 37, identifier:content; 38, identifier:real; 39, return_statement; 39, 40; 40, identifier:self | def sort(self, content):
v = content.value
if isinstance(v, Object):
md = v.__metadata__
md.ordering = self.ordering(content.real)
return self |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:alerts; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:alert_level; 7, string:'High'; 8, block; 8, 9; 8, 21; 8, 29; 8, 65; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:alerts; 12, call; 12, 13; 12, 20; 13, attribute; 13, 14; 13, 19; 14, attribute; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:zap; 18, identifier:core; 19, identifier:alerts; 20, argument_list; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:alert_level_value; 24, subscript; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:alert_levels; 28, identifier:alert_level; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:alerts; 32, call; 32, 33; 32, 34; 33, identifier:sorted; 34, argument_list; 34, 35; 34, 50; 34, 62; 35, generator_expression; 35, 36; 35, 37; 35, 40; 36, identifier:a; 37, for_in_clause; 37, 38; 37, 39; 38, identifier:a; 39, identifier:alerts; 40, if_clause; 40, 41; 41, comparison_operator:>=; 41, 42; 41, 49; 42, subscript; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:alert_levels; 46, subscript; 46, 47; 46, 48; 47, identifier:a; 48, string:'risk'; 49, identifier:alert_level_value; 50, keyword_argument; 50, 51; 50, 52; 51, identifier:key; 52, lambda; 52, 53; 52, 55; 53, lambda_parameters; 53, 54; 54, identifier:k; 55, subscript; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:self; 58, identifier:alert_levels; 59, subscript; 59, 60; 59, 61; 60, identifier:k; 61, string:'risk'; 62, keyword_argument; 62, 63; 62, 64; 63, identifier:reverse; 64, True; 65, return_statement; 65, 66; 66, identifier:alerts | def alerts(self, alert_level='High'):
alerts = self.zap.core.alerts()
alert_level_value = self.alert_levels[alert_level]
alerts = sorted((a for a in alerts if self.alert_levels[a['risk']] >= alert_level_value),
key=lambda k: self.alert_levels[k['risk']], reverse=True)
return alerts |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:assortativity_bin; 3, parameters; 3, 4; 3, 5; 4, identifier:CIJ; 5, default_parameter; 5, 6; 5, 7; 6, identifier:flag; 7, integer:0; 8, block; 8, 9; 8, 11; 8, 168; 8, 181; 8, 202; 8, 222; 8, 234; 9, expression_statement; 9, 10; 10, string:'''
The assortativity coefficient is a correlation coefficient between the
degrees of all nodes on two opposite ends of a link. A positive
assortativity coefficient indicates that nodes tend to link to other
nodes with the same or similar degree.
Parameters
----------
CIJ : NxN np.ndarray
binary directed/undirected connection matrix
flag : int
0 : undirected graph; degree/degree correlation
1 : directed graph; out-degree/in-degree correlation
2 : directed graph; in-degree/out-degree correlation
3 : directed graph; out-degree/out-degree correlation
4 : directed graph; in-degree/in-degreen correlation
Returns
-------
r : float
assortativity coefficient
Notes
-----
The function accepts weighted networks, but all connection
weights are ignored. The main diagonal should be empty. For flag 1
the function computes the directed assortativity described in Rubinov
and Sporns (2010) NeuroImage.
'''; 11, if_statement; 11, 12; 11, 15; 11, 61; 12, comparison_operator:==; 12, 13; 12, 14; 13, identifier:flag; 14, integer:0; 15, block; 15, 16; 15, 23; 15, 42; 15, 49; 15, 55; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:deg; 19, call; 19, 20; 19, 21; 20, identifier:degrees_und; 21, argument_list; 21, 22; 22, identifier:CIJ; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 28; 25, pattern_list; 25, 26; 25, 27; 26, identifier:i; 27, identifier:j; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:np; 31, identifier:where; 32, argument_list; 32, 33; 33, comparison_operator:>; 33, 34; 33, 41; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:np; 37, identifier:triu; 38, argument_list; 38, 39; 38, 40; 39, identifier:CIJ; 40, integer:1; 41, integer:0; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:K; 45, call; 45, 46; 45, 47; 46, identifier:len; 47, argument_list; 47, 48; 48, identifier:i; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:degi; 52, subscript; 52, 53; 52, 54; 53, identifier:deg; 54, identifier:i; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:degj; 58, subscript; 58, 59; 58, 60; 59, identifier:deg; 60, identifier:j; 61, else_clause; 61, 62; 62, block; 62, 63; 62, 73; 62, 86; 62, 93; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 69; 65, pattern_list; 65, 66; 65, 67; 65, 68; 66, identifier:id; 67, identifier:od; 68, identifier:deg; 69, call; 69, 70; 69, 71; 70, identifier:degrees_dir; 71, argument_list; 71, 72; 72, identifier:CIJ; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 78; 75, pattern_list; 75, 76; 75, 77; 76, identifier:i; 77, identifier:j; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:np; 81, identifier:where; 82, argument_list; 82, 83; 83, comparison_operator:>; 83, 84; 83, 85; 84, identifier:CIJ; 85, integer:0; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:K; 89, call; 89, 90; 89, 91; 90, identifier:len; 91, argument_list; 91, 92; 92, identifier:i; 93, if_statement; 93, 94; 93, 97; 93, 110; 93, 127; 93, 144; 93, 161; 94, comparison_operator:==; 94, 95; 94, 96; 95, identifier:flag; 96, integer:1; 97, block; 97, 98; 97, 104; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:degi; 101, subscript; 101, 102; 101, 103; 102, identifier:od; 103, identifier:i; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:degj; 107, subscript; 107, 108; 107, 109; 108, identifier:id; 109, identifier:j; 110, elif_clause; 110, 111; 110, 114; 111, comparison_operator:==; 111, 112; 111, 113; 112, identifier:flag; 113, integer:2; 114, block; 114, 115; 114, 121; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:degi; 118, subscript; 118, 119; 118, 120; 119, identifier:id; 120, identifier:i; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:degj; 124, subscript; 124, 125; 124, 126; 125, identifier:od; 126, identifier:j; 127, elif_clause; 127, 128; 127, 131; 128, comparison_operator:==; 128, 129; 128, 130; 129, identifier:flag; 130, integer:3; 131, block; 131, 132; 131, 138; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:degi; 135, subscript; 135, 136; 135, 137; 136, identifier:od; 137, identifier:i; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:degj; 141, subscript; 141, 142; 141, 143; 142, identifier:od; 143, identifier:j; 144, elif_clause; 144, 145; 144, 148; 145, comparison_operator:==; 145, 146; 145, 147; 146, identifier:flag; 147, integer:4; 148, block; 148, 149; 148, 155; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 152; 151, identifier:degi; 152, subscript; 152, 153; 152, 154; 153, identifier:id; 154, identifier:i; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:degj; 158, subscript; 158, 159; 158, 160; 159, identifier:id; 160, identifier:j; 161, else_clause; 161, 162; 162, block; 162, 163; 163, raise_statement; 163, 164; 164, call; 164, 165; 164, 166; 165, identifier:ValueError; 166, argument_list; 166, 167; 167, string:'Flag must be 0-4'; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:term1; 171, binary_operator:/; 171, 172; 171, 180; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:np; 175, identifier:sum; 176, argument_list; 176, 177; 177, binary_operator:*; 177, 178; 177, 179; 178, identifier:degi; 179, identifier:degj; 180, identifier:K; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 184; 183, identifier:term2; 184, call; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:np; 187, identifier:square; 188, argument_list; 188, 189; 189, binary_operator:/; 189, 190; 189, 201; 190, call; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:np; 193, identifier:sum; 194, argument_list; 194, 195; 195, binary_operator:*; 195, 196; 195, 197; 196, float:.5; 197, parenthesized_expression; 197, 198; 198, binary_operator:+; 198, 199; 198, 200; 199, identifier:degi; 200, identifier:degj; 201, identifier:K; 202, expression_statement; 202, 203; 203, assignment; 203, 204; 203, 205; 204, identifier:term3; 205, binary_operator:/; 205, 206; 205, 221; 206, call; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:np; 209, identifier:sum; 210, argument_list; 210, 211; 211, binary_operator:*; 211, 212; 211, 213; 212, float:.5; 213, parenthesized_expression; 213, 214; 214, binary_operator:+; 214, 215; 214, 218; 215, binary_operator:*; 215, 216; 215, 217; 216, identifier:degi; 217, identifier:degi; 218, binary_operator:*; 218, 219; 218, 220; 219, identifier:degj; 220, identifier:degj; 221, identifier:K; 222, expression_statement; 222, 223; 223, assignment; 223, 224; 223, 225; 224, identifier:r; 225, binary_operator:/; 225, 226; 225, 230; 226, parenthesized_expression; 226, 227; 227, binary_operator:-; 227, 228; 227, 229; 228, identifier:term1; 229, identifier:term2; 230, parenthesized_expression; 230, 231; 231, binary_operator:-; 231, 232; 231, 233; 232, identifier:term3; 233, identifier:term2; 234, return_statement; 234, 235; 235, identifier:r | def assortativity_bin(CIJ, flag=0):
'''
The assortativity coefficient is a correlation coefficient between the
degrees of all nodes on two opposite ends of a link. A positive
assortativity coefficient indicates that nodes tend to link to other
nodes with the same or similar degree.
Parameters
----------
CIJ : NxN np.ndarray
binary directed/undirected connection matrix
flag : int
0 : undirected graph; degree/degree correlation
1 : directed graph; out-degree/in-degree correlation
2 : directed graph; in-degree/out-degree correlation
3 : directed graph; out-degree/out-degree correlation
4 : directed graph; in-degree/in-degreen correlation
Returns
-------
r : float
assortativity coefficient
Notes
-----
The function accepts weighted networks, but all connection
weights are ignored. The main diagonal should be empty. For flag 1
the function computes the directed assortativity described in Rubinov
and Sporns (2010) NeuroImage.
'''
if flag == 0:
deg = degrees_und(CIJ)
i, j = np.where(np.triu(CIJ, 1) > 0)
K = len(i)
degi = deg[i]
degj = deg[j]
else:
id, od, deg = degrees_dir(CIJ)
i, j = np.where(CIJ > 0)
K = len(i)
if flag == 1:
degi = od[i]
degj = id[j]
elif flag == 2:
degi = id[i]
degj = od[j]
elif flag == 3:
degi = od[i]
degj = od[j]
elif flag == 4:
degi = id[i]
degj = id[j]
else:
raise ValueError('Flag must be 0-4')
term1 = np.sum(degi * degj) / K
term2 = np.square(np.sum(.5 * (degi + degj)) / K)
term3 = np.sum(.5 * (degi * degi + degj * degj)) / K
r = (term1 - term2) / (term3 - term2)
return r |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort_coords; 3, parameters; 3, 4; 4, identifier:coord; 5, block; 5, 6; 5, 9; 5, 27; 5, 38; 6, import_statement; 6, 7; 7, dotted_name; 7, 8; 8, identifier:iris; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:order; 12, dictionary; 12, 13; 12, 17; 12, 21; 12, 24; 13, pair; 13, 14; 13, 15; 14, string:'T'; 15, unary_operator:-; 15, 16; 16, integer:2; 17, pair; 17, 18; 17, 19; 18, string:'Z'; 19, unary_operator:-; 19, 20; 20, integer:1; 21, pair; 21, 22; 21, 23; 22, string:'X'; 23, integer:1; 24, pair; 24, 25; 24, 26; 25, string:'Y'; 26, integer:2; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:axis; 30, call; 30, 31; 30, 36; 31, attribute; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:iris; 34, identifier:util; 35, identifier:guess_coord_axis; 36, argument_list; 36, 37; 37, identifier:coord; 38, return_statement; 38, 39; 39, tuple; 39, 40; 39, 47; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:order; 43, identifier:get; 44, argument_list; 44, 45; 44, 46; 45, identifier:axis; 46, integer:0; 47, boolean_operator:and; 47, 48; 47, 49; 48, identifier:coord; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:coord; 52, identifier:name; 53, argument_list | def sort_coords(coord):
import iris
order = {'T': -2, 'Z': -1, 'X': 1, 'Y': 2}
axis = iris.util.guess_coord_axis(coord)
return (order.get(axis, 0), coord and coord.name()) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:separate_groups; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:groups; 5, identifier:key; 6, identifier:total; 7, block; 7, 8; 7, 21; 7, 33; 7, 41; 7, 56; 7, 71; 7, 77; 7, 83; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 13; 10, pattern_list; 10, 11; 10, 12; 11, identifier:optimum; 12, identifier:extra; 13, call; 13, 14; 13, 15; 14, identifier:compute_optimum; 15, argument_list; 15, 16; 15, 20; 16, call; 16, 17; 16, 18; 17, identifier:len; 18, argument_list; 18, 19; 19, identifier:groups; 20, identifier:total; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 27; 23, pattern_list; 23, 24; 23, 25; 23, 26; 24, identifier:over_loaded; 25, identifier:under_loaded; 26, identifier:optimal; 27, call; 27, 28; 27, 29; 28, identifier:_smart_separate_groups; 29, argument_list; 29, 30; 29, 31; 29, 32; 30, identifier:groups; 31, identifier:key; 32, identifier:total; 33, if_statement; 33, 34; 33, 36; 34, not_operator; 34, 35; 35, identifier:extra; 36, block; 36, 37; 37, return_statement; 37, 38; 38, expression_list; 38, 39; 38, 40; 39, identifier:over_loaded; 40, identifier:under_loaded; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:potential_under_loaded; 44, list_comprehension; 44, 45; 44, 46; 44, 49; 45, identifier:group; 46, for_in_clause; 46, 47; 46, 48; 47, identifier:group; 48, identifier:optimal; 49, if_clause; 49, 50; 50, comparison_operator:==; 50, 51; 50, 55; 51, call; 51, 52; 51, 53; 52, identifier:key; 53, argument_list; 53, 54; 54, identifier:group; 55, identifier:optimum; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:potential_over_loaded; 59, list_comprehension; 59, 60; 59, 61; 59, 64; 60, identifier:group; 61, for_in_clause; 61, 62; 61, 63; 62, identifier:group; 63, identifier:optimal; 64, if_clause; 64, 65; 65, comparison_operator:>; 65, 66; 65, 70; 66, call; 66, 67; 66, 68; 67, identifier:key; 68, argument_list; 68, 69; 69, identifier:group; 70, identifier:optimum; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:revised_under_loaded; 74, binary_operator:+; 74, 75; 74, 76; 75, identifier:under_loaded; 76, identifier:potential_under_loaded; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:revised_over_loaded; 80, binary_operator:+; 80, 81; 80, 82; 81, identifier:over_loaded; 82, identifier:potential_over_loaded; 83, return_statement; 83, 84; 84, tuple; 84, 85; 84, 95; 85, call; 85, 86; 85, 87; 86, identifier:sorted; 87, argument_list; 87, 88; 87, 89; 87, 92; 88, identifier:revised_over_loaded; 89, keyword_argument; 89, 90; 89, 91; 90, identifier:key; 91, identifier:key; 92, keyword_argument; 92, 93; 92, 94; 93, identifier:reverse; 94, True; 95, call; 95, 96; 95, 97; 96, identifier:sorted; 97, argument_list; 97, 98; 97, 99; 98, identifier:revised_under_loaded; 99, keyword_argument; 99, 100; 99, 101; 100, identifier:key; 101, identifier:key | def separate_groups(groups, key, total):
optimum, extra = compute_optimum(len(groups), total)
over_loaded, under_loaded, optimal = _smart_separate_groups(groups, key, total)
if not extra:
return over_loaded, under_loaded
potential_under_loaded = [
group for group in optimal
if key(group) == optimum
]
potential_over_loaded = [
group for group in optimal
if key(group) > optimum
]
revised_under_loaded = under_loaded + potential_under_loaded
revised_over_loaded = over_loaded + potential_over_loaded
return (
sorted(revised_over_loaded, key=key, reverse=True),
sorted(revised_under_loaded, key=key),
) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:zrange; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 11; 3, 14; 4, identifier:self; 5, identifier:name; 6, identifier:start; 7, identifier:end; 8, default_parameter; 8, 9; 8, 10; 9, identifier:desc; 10, False; 11, default_parameter; 11, 12; 11, 13; 12, identifier:withscores; 13, False; 14, default_parameter; 14, 15; 14, 16; 15, identifier:score_cast_func; 16, identifier:float; 17, block; 17, 18; 17, 33; 17, 41; 17, 54; 17, 64; 18, if_statement; 18, 19; 18, 20; 19, identifier:desc; 20, block; 20, 21; 21, return_statement; 21, 22; 22, await; 22, 23; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:zrevrange; 27, argument_list; 27, 28; 27, 29; 27, 30; 27, 31; 27, 32; 28, identifier:name; 29, identifier:start; 30, identifier:end; 31, identifier:withscores; 32, identifier:score_cast_func; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:pieces; 36, list:['ZRANGE', name, start, end]; 36, 37; 36, 38; 36, 39; 36, 40; 37, string:'ZRANGE'; 38, identifier:name; 39, identifier:start; 40, identifier:end; 41, if_statement; 41, 42; 41, 43; 42, identifier:withscores; 43, block; 43, 44; 44, expression_statement; 44, 45; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:pieces; 48, identifier:append; 49, argument_list; 49, 50; 50, call; 50, 51; 50, 52; 51, identifier:b; 52, argument_list; 52, 53; 53, string:'WITHSCORES'; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:options; 57, dictionary; 57, 58; 57, 61; 58, pair; 58, 59; 58, 60; 59, string:'withscores'; 60, identifier:withscores; 61, pair; 61, 62; 61, 63; 62, string:'score_cast_func'; 63, identifier:score_cast_func; 64, return_statement; 64, 65; 65, await; 65, 66; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:execute_command; 70, argument_list; 70, 71; 70, 73; 71, list_splat; 71, 72; 72, identifier:pieces; 73, dictionary_splat; 73, 74; 74, identifier:options | async def zrange(self, name, start, end, desc=False, withscores=False,
score_cast_func=float):
if desc:
return await self.zrevrange(name, start, end, withscores,
score_cast_func)
pieces = ['ZRANGE', name, start, end]
if withscores:
pieces.append(b('WITHSCORES'))
options = {
'withscores': withscores,
'score_cast_func': score_cast_func
}
return await self.execute_command(*pieces, **options) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:zremrangebyscore; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:name; 6, identifier:min; 7, identifier:max; 8, block; 8, 9; 9, return_statement; 9, 10; 10, await; 10, 11; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:execute_command; 15, argument_list; 15, 16; 15, 17; 15, 18; 15, 19; 16, string:'ZREMRANGEBYSCORE'; 17, identifier:name; 18, identifier:min; 19, identifier:max | async def zremrangebyscore(self, name, min, max):
return await self.execute_command('ZREMRANGEBYSCORE', name, min, max) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 33; 2, function_name:georadius; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 3, 24; 3, 27; 3, 30; 4, identifier:self; 5, identifier:name; 6, identifier:longitude; 7, identifier:latitude; 8, identifier:radius; 9, default_parameter; 9, 10; 9, 11; 10, identifier:unit; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:withdist; 14, False; 15, default_parameter; 15, 16; 15, 17; 16, identifier:withcoord; 17, False; 18, default_parameter; 18, 19; 18, 20; 19, identifier:withhash; 20, False; 21, default_parameter; 21, 22; 21, 23; 22, identifier:count; 23, None; 24, default_parameter; 24, 25; 24, 26; 25, identifier:sort; 26, None; 27, default_parameter; 27, 28; 27, 29; 28, identifier:store; 29, None; 30, default_parameter; 30, 31; 30, 32; 31, identifier:store_dist; 32, None; 33, block; 33, 34; 34, return_statement; 34, 35; 35, await; 35, 36; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:_georadiusgeneric; 40, argument_list; 40, 41; 40, 42; 40, 43; 40, 44; 40, 45; 40, 46; 40, 49; 40, 52; 40, 55; 40, 58; 40, 61; 40, 64; 40, 67; 41, string:'GEORADIUS'; 42, identifier:name; 43, identifier:longitude; 44, identifier:latitude; 45, identifier:radius; 46, keyword_argument; 46, 47; 46, 48; 47, identifier:unit; 48, identifier:unit; 49, keyword_argument; 49, 50; 49, 51; 50, identifier:withdist; 51, identifier:withdist; 52, keyword_argument; 52, 53; 52, 54; 53, identifier:withcoord; 54, identifier:withcoord; 55, keyword_argument; 55, 56; 55, 57; 56, identifier:withhash; 57, identifier:withhash; 58, keyword_argument; 58, 59; 58, 60; 59, identifier:count; 60, identifier:count; 61, keyword_argument; 61, 62; 61, 63; 62, identifier:sort; 63, identifier:sort; 64, keyword_argument; 64, 65; 64, 66; 65, identifier:store; 66, identifier:store; 67, keyword_argument; 67, 68; 67, 69; 68, identifier:store_dist; 69, identifier:store_dist | async def georadius(self, name, longitude, latitude, radius, unit=None,
withdist=False, withcoord=False, withhash=False, count=None,
sort=None, store=None, store_dist=None):
return await self._georadiusgeneric('GEORADIUS',
name, longitude, latitude, radius,
unit=unit, withdist=withdist,
withcoord=withcoord, withhash=withhash,
count=count, sort=sort, store=store,
store_dist=store_dist) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 32; 2, function_name:georadiusbymember; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 3, 29; 4, identifier:self; 5, identifier:name; 6, identifier:member; 7, identifier:radius; 8, default_parameter; 8, 9; 8, 10; 9, identifier:unit; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:withdist; 13, False; 14, default_parameter; 14, 15; 14, 16; 15, identifier:withcoord; 16, False; 17, default_parameter; 17, 18; 17, 19; 18, identifier:withhash; 19, False; 20, default_parameter; 20, 21; 20, 22; 21, identifier:count; 22, None; 23, default_parameter; 23, 24; 23, 25; 24, identifier:sort; 25, None; 26, default_parameter; 26, 27; 26, 28; 27, identifier:store; 28, None; 29, default_parameter; 29, 30; 29, 31; 30, identifier:store_dist; 31, None; 32, block; 32, 33; 33, return_statement; 33, 34; 34, await; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:_georadiusgeneric; 39, argument_list; 39, 40; 39, 41; 39, 42; 39, 43; 39, 44; 39, 47; 39, 50; 39, 53; 39, 56; 39, 59; 39, 62; 39, 65; 40, string:'GEORADIUSBYMEMBER'; 41, identifier:name; 42, identifier:member; 43, identifier:radius; 44, keyword_argument; 44, 45; 44, 46; 45, identifier:unit; 46, identifier:unit; 47, keyword_argument; 47, 48; 47, 49; 48, identifier:withdist; 49, identifier:withdist; 50, keyword_argument; 50, 51; 50, 52; 51, identifier:withcoord; 52, identifier:withcoord; 53, keyword_argument; 53, 54; 53, 55; 54, identifier:withhash; 55, identifier:withhash; 56, keyword_argument; 56, 57; 56, 58; 57, identifier:count; 58, identifier:count; 59, keyword_argument; 59, 60; 59, 61; 60, identifier:sort; 61, identifier:sort; 62, keyword_argument; 62, 63; 62, 64; 63, identifier:store; 64, identifier:store; 65, keyword_argument; 65, 66; 65, 67; 66, identifier:store_dist; 67, identifier:store_dist | async def georadiusbymember(self, name, member, radius, unit=None,
withdist=False, withcoord=False, withhash=False,
count=None, sort=None, store=None, store_dist=None):
return await self._georadiusgeneric('GEORADIUSBYMEMBER',
name, member, radius, unit=unit,
withdist=withdist, withcoord=withcoord,
withhash=withhash, count=count,
sort=sort, store=store,
store_dist=store_dist) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 32; 2, function_name:search; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 3, 29; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:page; 7, integer:0; 8, default_parameter; 8, 9; 8, 10; 9, identifier:per_page; 10, integer:50; 11, default_parameter; 11, 12; 11, 13; 12, identifier:sort; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:q; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:include_totals; 19, True; 20, default_parameter; 20, 21; 20, 22; 21, identifier:fields; 22, None; 23, default_parameter; 23, 24; 23, 25; 24, identifier:from_param; 25, None; 26, default_parameter; 26, 27; 26, 28; 27, identifier:take; 28, None; 29, default_parameter; 29, 30; 29, 31; 30, identifier:include_fields; 31, True; 32, block; 32, 33; 32, 87; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:params; 36, dictionary; 36, 37; 36, 40; 36, 43; 36, 53; 36, 56; 36, 68; 36, 78; 36, 81; 36, 84; 37, pair; 37, 38; 37, 39; 38, string:'per_page'; 39, identifier:per_page; 40, pair; 40, 41; 40, 42; 41, string:'page'; 42, identifier:page; 43, pair; 43, 44; 43, 45; 44, string:'include_totals'; 45, call; 45, 46; 45, 52; 46, attribute; 46, 47; 46, 51; 47, call; 47, 48; 47, 49; 48, identifier:str; 49, argument_list; 49, 50; 50, identifier:include_totals; 51, identifier:lower; 52, argument_list; 53, pair; 53, 54; 53, 55; 54, string:'sort'; 55, identifier:sort; 56, pair; 56, 57; 56, 58; 57, string:'fields'; 58, boolean_operator:or; 58, 59; 58, 67; 59, boolean_operator:and; 59, 60; 59, 61; 60, identifier:fields; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, string:','; 64, identifier:join; 65, argument_list; 65, 66; 66, identifier:fields; 67, None; 68, pair; 68, 69; 68, 70; 69, string:'include_fields'; 70, call; 70, 71; 70, 77; 71, attribute; 71, 72; 71, 76; 72, call; 72, 73; 72, 74; 73, identifier:str; 74, argument_list; 74, 75; 75, identifier:include_fields; 76, identifier:lower; 77, argument_list; 78, pair; 78, 79; 78, 80; 79, string:'q'; 80, identifier:q; 81, pair; 81, 82; 81, 83; 82, string:'from'; 83, identifier:from_param; 84, pair; 84, 85; 84, 86; 85, string:'take'; 86, identifier:take; 87, return_statement; 87, 88; 88, call; 88, 89; 88, 94; 89, attribute; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:self; 92, identifier:client; 93, identifier:get; 94, argument_list; 94, 95; 94, 100; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:self; 98, identifier:_url; 99, argument_list; 100, keyword_argument; 100, 101; 100, 102; 101, identifier:params; 102, identifier:params | def search(self, page=0, per_page=50, sort=None, q=None,
include_totals=True, fields=None, from_param=None, take=None,
include_fields=True):
params = {
'per_page': per_page,
'page': page,
'include_totals': str(include_totals).lower(),
'sort': sort,
'fields': fields and ','.join(fields) or None,
'include_fields': str(include_fields).lower(),
'q': q,
'from': from_param,
'take': take
}
return self.client.get(self._url(), params=params) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 32; 2, function_name:list; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 3, 29; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:page; 7, integer:0; 8, default_parameter; 8, 9; 8, 10; 9, identifier:per_page; 10, integer:25; 11, default_parameter; 11, 12; 11, 13; 12, identifier:sort; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:connection; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:q; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:search_engine; 22, None; 23, default_parameter; 23, 24; 23, 25; 24, identifier:include_totals; 25, True; 26, default_parameter; 26, 27; 26, 28; 27, identifier:fields; 28, None; 29, default_parameter; 29, 30; 29, 31; 30, identifier:include_fields; 31, True; 32, block; 32, 33; 32, 87; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:params; 36, dictionary; 36, 37; 36, 40; 36, 43; 36, 53; 36, 56; 36, 59; 36, 71; 36, 81; 36, 84; 37, pair; 37, 38; 37, 39; 38, string:'per_page'; 39, identifier:per_page; 40, pair; 40, 41; 40, 42; 41, string:'page'; 42, identifier:page; 43, pair; 43, 44; 43, 45; 44, string:'include_totals'; 45, call; 45, 46; 45, 52; 46, attribute; 46, 47; 46, 51; 47, call; 47, 48; 47, 49; 48, identifier:str; 49, argument_list; 49, 50; 50, identifier:include_totals; 51, identifier:lower; 52, argument_list; 53, pair; 53, 54; 53, 55; 54, string:'sort'; 55, identifier:sort; 56, pair; 56, 57; 56, 58; 57, string:'connection'; 58, identifier:connection; 59, pair; 59, 60; 59, 61; 60, string:'fields'; 61, boolean_operator:or; 61, 62; 61, 70; 62, boolean_operator:and; 62, 63; 62, 64; 63, identifier:fields; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, string:','; 67, identifier:join; 68, argument_list; 68, 69; 69, identifier:fields; 70, None; 71, pair; 71, 72; 71, 73; 72, string:'include_fields'; 73, call; 73, 74; 73, 80; 74, attribute; 74, 75; 74, 79; 75, call; 75, 76; 75, 77; 76, identifier:str; 77, argument_list; 77, 78; 78, identifier:include_fields; 79, identifier:lower; 80, argument_list; 81, pair; 81, 82; 81, 83; 82, string:'q'; 83, identifier:q; 84, pair; 84, 85; 84, 86; 85, string:'search_engine'; 86, identifier:search_engine; 87, return_statement; 87, 88; 88, call; 88, 89; 88, 94; 89, attribute; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:self; 92, identifier:client; 93, identifier:get; 94, argument_list; 94, 95; 94, 100; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:self; 98, identifier:_url; 99, argument_list; 100, keyword_argument; 100, 101; 100, 102; 101, identifier:params; 102, identifier:params | def list(self, page=0, per_page=25, sort=None, connection=None, q=None,
search_engine=None, include_totals=True, fields=None,
include_fields=True):
params = {
'per_page': per_page,
'page': page,
'include_totals': str(include_totals).lower(),
'sort': sort,
'connection': connection,
'fields': fields and ','.join(fields) or None,
'include_fields': str(include_fields).lower(),
'q': q,
'search_engine': search_engine
}
return self.client.get(self._url(), params=params) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 2, function_name:get_log_events; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 4, identifier:self; 5, identifier:user_id; 6, default_parameter; 6, 7; 6, 8; 7, identifier:page; 8, integer:0; 9, default_parameter; 9, 10; 9, 11; 10, identifier:per_page; 11, integer:50; 12, default_parameter; 12, 13; 12, 14; 13, identifier:sort; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:include_totals; 17, False; 18, block; 18, 19; 18, 42; 18, 56; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:params; 22, dictionary; 22, 23; 22, 26; 22, 29; 22, 39; 23, pair; 23, 24; 23, 25; 24, string:'per_page'; 25, identifier:per_page; 26, pair; 26, 27; 26, 28; 27, string:'page'; 28, identifier:page; 29, pair; 29, 30; 29, 31; 30, string:'include_totals'; 31, call; 31, 32; 31, 38; 32, attribute; 32, 33; 32, 37; 33, call; 33, 34; 33, 35; 34, identifier:str; 35, argument_list; 35, 36; 36, identifier:include_totals; 37, identifier:lower; 38, argument_list; 39, pair; 39, 40; 39, 41; 40, string:'sort'; 41, identifier:sort; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:url; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:_url; 49, argument_list; 49, 50; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, string:'{}/logs'; 53, identifier:format; 54, argument_list; 54, 55; 55, identifier:user_id; 56, return_statement; 56, 57; 57, call; 57, 58; 57, 63; 58, attribute; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:client; 62, identifier:get; 63, argument_list; 63, 64; 63, 65; 64, identifier:url; 65, keyword_argument; 65, 66; 65, 67; 66, identifier:params; 67, identifier:params | def get_log_events(self, user_id, page=0, per_page=50, sort=None,
include_totals=False):
params = {
'per_page': per_page,
'page': page,
'include_totals': str(include_totals).lower(),
'sort': sort
}
url = self._url('{}/logs'.format(user_id))
return self.client.get(url, params=params) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:get_activities; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:before; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:after; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:limit; 13, None; 14, block; 14, 15; 14, 27; 14, 39; 14, 51; 14, 67; 15, if_statement; 15, 16; 15, 17; 16, identifier:before; 17, block; 17, 18; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:before; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:_utc_datetime_to_epoch; 25, argument_list; 25, 26; 26, identifier:before; 27, if_statement; 27, 28; 27, 29; 28, identifier:after; 29, block; 29, 30; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:after; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:_utc_datetime_to_epoch; 37, argument_list; 37, 38; 38, identifier:after; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:params; 42, call; 42, 43; 42, 44; 43, identifier:dict; 44, argument_list; 44, 45; 44, 48; 45, keyword_argument; 45, 46; 45, 47; 46, identifier:before; 47, identifier:before; 48, keyword_argument; 48, 49; 48, 50; 49, identifier:after; 50, identifier:after; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:result_fetcher; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:functools; 57, identifier:partial; 58, argument_list; 58, 59; 58, 64; 58, 65; 59, attribute; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:protocol; 63, identifier:get; 64, string:'/athlete/activities'; 65, dictionary_splat; 65, 66; 66, identifier:params; 67, return_statement; 67, 68; 68, call; 68, 69; 68, 70; 69, identifier:BatchedResultsIterator; 70, argument_list; 70, 71; 70, 76; 70, 79; 70, 82; 71, keyword_argument; 71, 72; 71, 73; 72, identifier:entity; 73, attribute; 73, 74; 73, 75; 74, identifier:model; 75, identifier:Activity; 76, keyword_argument; 76, 77; 76, 78; 77, identifier:bind_client; 78, identifier:self; 79, keyword_argument; 79, 80; 79, 81; 80, identifier:result_fetcher; 81, identifier:result_fetcher; 82, keyword_argument; 82, 83; 82, 84; 83, identifier:limit; 84, identifier:limit | def get_activities(self, before=None, after=None, limit=None):
if before:
before = self._utc_datetime_to_epoch(before)
if after:
after = self._utc_datetime_to_epoch(after)
params = dict(before=before, after=after)
result_fetcher = functools.partial(self.protocol.get,
'/athlete/activities',
**params)
return BatchedResultsIterator(entity=model.Activity,
bind_client=self,
result_fetcher=result_fetcher,
limit=limit) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 33; 2, function_name:get_segment_leaderboard; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 3, 24; 3, 27; 3, 30; 4, identifier:self; 5, identifier:segment_id; 6, default_parameter; 6, 7; 6, 8; 7, identifier:gender; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:age_group; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:weight_class; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:following; 17, None; 18, default_parameter; 18, 19; 18, 20; 19, identifier:club_id; 20, None; 21, default_parameter; 21, 22; 21, 23; 22, identifier:timeframe; 23, None; 24, default_parameter; 24, 25; 24, 26; 25, identifier:top_results_limit; 26, None; 27, default_parameter; 27, 28; 27, 29; 28, identifier:page; 29, None; 30, default_parameter; 30, 31; 30, 32; 31, identifier:context_entries; 32, None; 33, block; 33, 34; 33, 38; 33, 70; 33, 80; 33, 108; 33, 124; 33, 152; 33, 166; 33, 177; 33, 213; 33, 224; 33, 235; 33, 246; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:params; 37, dictionary; 38, if_statement; 38, 39; 38, 42; 39, comparison_operator:is; 39, 40; 39, 41; 40, identifier:gender; 41, None; 42, block; 42, 43; 42, 64; 43, if_statement; 43, 44; 43, 53; 44, comparison_operator:not; 44, 45; 44, 50; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:gender; 48, identifier:upper; 49, argument_list; 50, tuple; 50, 51; 50, 52; 51, string:'M'; 52, string:'F'; 53, block; 53, 54; 54, raise_statement; 54, 55; 55, call; 55, 56; 55, 57; 56, identifier:ValueError; 57, argument_list; 57, 58; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, string:"Invalid gender: {0}. Possible values: 'M' or 'F'"; 61, identifier:format; 62, argument_list; 62, 63; 63, identifier:gender; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 69; 66, subscript; 66, 67; 66, 68; 67, identifier:params; 68, string:'gender'; 69, identifier:gender; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:valid_age_groups; 73, tuple; 73, 74; 73, 75; 73, 76; 73, 77; 73, 78; 73, 79; 74, string:'0_24'; 75, string:'25_34'; 76, string:'35_44'; 77, string:'45_54'; 78, string:'55_64'; 79, string:'65_plus'; 80, if_statement; 80, 81; 80, 84; 81, comparison_operator:is; 81, 82; 81, 83; 82, identifier:age_group; 83, None; 84, block; 84, 85; 84, 102; 85, if_statement; 85, 86; 85, 90; 86, not_operator; 86, 87; 87, comparison_operator:in; 87, 88; 87, 89; 88, identifier:age_group; 89, identifier:valid_age_groups; 90, block; 90, 91; 91, raise_statement; 91, 92; 92, call; 92, 93; 92, 94; 93, identifier:ValueError; 94, argument_list; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, string:"Invalid age group: {0}. Possible values: {1!r}"; 98, identifier:format; 99, argument_list; 99, 100; 99, 101; 100, identifier:age_group; 101, identifier:valid_age_groups; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 107; 104, subscript; 104, 105; 104, 106; 105, identifier:params; 106, string:'age_group'; 107, identifier:age_group; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:valid_weight_classes; 111, tuple; 111, 112; 111, 113; 111, 114; 111, 115; 111, 116; 111, 117; 111, 118; 111, 119; 111, 120; 111, 121; 111, 122; 111, 123; 112, string:'0_124'; 113, string:'125_149'; 114, string:'150_164'; 115, string:'165_179'; 116, string:'180_199'; 117, string:'200_plus'; 118, string:'0_54'; 119, string:'55_64'; 120, string:'65_74'; 121, string:'75_84'; 122, string:'85_94'; 123, string:'95_plus'; 124, if_statement; 124, 125; 124, 128; 125, comparison_operator:is; 125, 126; 125, 127; 126, identifier:weight_class; 127, None; 128, block; 128, 129; 128, 146; 129, if_statement; 129, 130; 129, 134; 130, not_operator; 130, 131; 131, comparison_operator:in; 131, 132; 131, 133; 132, identifier:weight_class; 133, identifier:valid_weight_classes; 134, block; 134, 135; 135, raise_statement; 135, 136; 136, call; 136, 137; 136, 138; 137, identifier:ValueError; 138, argument_list; 138, 139; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, string:"Invalid weight class: {0}. Possible values: {1!r}"; 142, identifier:format; 143, argument_list; 143, 144; 143, 145; 144, identifier:weight_class; 145, identifier:valid_weight_classes; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 151; 148, subscript; 148, 149; 148, 150; 149, identifier:params; 150, string:'weight_class'; 151, identifier:weight_class; 152, if_statement; 152, 153; 152, 156; 153, comparison_operator:is; 153, 154; 153, 155; 154, identifier:following; 155, None; 156, block; 156, 157; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 162; 159, subscript; 159, 160; 159, 161; 160, identifier:params; 161, string:'following'; 162, call; 162, 163; 162, 164; 163, identifier:int; 164, argument_list; 164, 165; 165, identifier:following; 166, if_statement; 166, 167; 166, 170; 167, comparison_operator:is; 167, 168; 167, 169; 168, identifier:club_id; 169, None; 170, block; 170, 171; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 176; 173, subscript; 173, 174; 173, 175; 174, identifier:params; 175, string:'club_id'; 176, identifier:club_id; 177, if_statement; 177, 178; 177, 181; 178, comparison_operator:is; 178, 179; 178, 180; 179, identifier:timeframe; 180, None; 181, block; 181, 182; 181, 190; 181, 207; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 185; 184, identifier:valid_timeframes; 185, expression_list; 185, 186; 185, 187; 185, 188; 185, 189; 186, string:'this_year'; 187, string:'this_month'; 188, string:'this_week'; 189, string:'today'; 190, if_statement; 190, 191; 190, 195; 191, not_operator; 191, 192; 192, comparison_operator:in; 192, 193; 192, 194; 193, identifier:timeframe; 194, identifier:valid_timeframes; 195, block; 195, 196; 196, raise_statement; 196, 197; 197, call; 197, 198; 197, 199; 198, identifier:ValueError; 199, argument_list; 199, 200; 200, call; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, string:"Invalid timeframe: {0}. Possible values: {1!r}"; 203, identifier:format; 204, argument_list; 204, 205; 204, 206; 205, identifier:timeframe; 206, identifier:valid_timeframes; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 212; 209, subscript; 209, 210; 209, 211; 210, identifier:params; 211, string:'date_range'; 212, identifier:timeframe; 213, if_statement; 213, 214; 213, 217; 214, comparison_operator:is; 214, 215; 214, 216; 215, identifier:top_results_limit; 216, None; 217, block; 217, 218; 218, expression_statement; 218, 219; 219, assignment; 219, 220; 219, 223; 220, subscript; 220, 221; 220, 222; 221, identifier:params; 222, string:'per_page'; 223, identifier:top_results_limit; 224, if_statement; 224, 225; 224, 228; 225, comparison_operator:is; 225, 226; 225, 227; 226, identifier:page; 227, None; 228, block; 228, 229; 229, expression_statement; 229, 230; 230, assignment; 230, 231; 230, 234; 231, subscript; 231, 232; 231, 233; 232, identifier:params; 233, string:'page'; 234, identifier:page; 235, if_statement; 235, 236; 235, 239; 236, comparison_operator:is; 236, 237; 236, 238; 237, identifier:context_entries; 238, None; 239, block; 239, 240; 240, expression_statement; 240, 241; 241, assignment; 241, 242; 241, 245; 242, subscript; 242, 243; 242, 244; 243, identifier:params; 244, string:'context_entries'; 245, identifier:context_entries; 246, return_statement; 246, 247; 247, call; 247, 248; 247, 253; 248, attribute; 248, 249; 248, 252; 249, attribute; 249, 250; 249, 251; 250, identifier:model; 251, identifier:SegmentLeaderboard; 252, identifier:deserialize; 253, argument_list; 253, 254; 253, 267; 254, call; 254, 255; 254, 260; 255, attribute; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:self; 258, identifier:protocol; 259, identifier:get; 260, argument_list; 260, 261; 260, 262; 260, 265; 261, string:'/segments/{id}/leaderboard'; 262, keyword_argument; 262, 263; 262, 264; 263, identifier:id; 264, identifier:segment_id; 265, dictionary_splat; 265, 266; 266, identifier:params; 267, keyword_argument; 267, 268; 267, 269; 268, identifier:bind_client; 269, identifier:self | def get_segment_leaderboard(self, segment_id, gender=None, age_group=None, weight_class=None,
following=None, club_id=None, timeframe=None, top_results_limit=None,
page=None, context_entries = None):
params = {}
if gender is not None:
if gender.upper() not in ('M', 'F'):
raise ValueError("Invalid gender: {0}. Possible values: 'M' or 'F'".format(gender))
params['gender'] = gender
valid_age_groups = ('0_24', '25_34', '35_44', '45_54', '55_64', '65_plus')
if age_group is not None:
if not age_group in valid_age_groups:
raise ValueError("Invalid age group: {0}. Possible values: {1!r}".format(age_group, valid_age_groups))
params['age_group'] = age_group
valid_weight_classes = ('0_124', '125_149', '150_164', '165_179', '180_199', '200_plus',
'0_54', '55_64', '65_74', '75_84', '85_94', '95_plus')
if weight_class is not None:
if not weight_class in valid_weight_classes:
raise ValueError("Invalid weight class: {0}. Possible values: {1!r}".format(weight_class, valid_weight_classes))
params['weight_class'] = weight_class
if following is not None:
params['following'] = int(following)
if club_id is not None:
params['club_id'] = club_id
if timeframe is not None:
valid_timeframes = 'this_year', 'this_month', 'this_week', 'today'
if not timeframe in valid_timeframes:
raise ValueError("Invalid timeframe: {0}. Possible values: {1!r}".format(timeframe, valid_timeframes))
params['date_range'] = timeframe
if top_results_limit is not None:
params['per_page'] = top_results_limit
if page is not None:
params['page'] = page
if context_entries is not None:
params['context_entries'] = context_entries
return model.SegmentLeaderboard.deserialize(self.protocol.get('/segments/{id}/leaderboard',
id=segment_id,
**params),
bind_client=self) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 2, function_name:get_segment_efforts; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 4, identifier:self; 5, identifier:segment_id; 6, default_parameter; 6, 7; 6, 8; 7, identifier:athlete_id; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:start_date_local; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:end_date_local; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:limit; 17, None; 18, block; 18, 19; 18, 26; 18, 37; 18, 71; 18, 105; 18, 116; 18, 132; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:params; 22, dictionary; 22, 23; 23, pair; 23, 24; 23, 25; 24, string:"segment_id"; 25, identifier:segment_id; 26, if_statement; 26, 27; 26, 30; 27, comparison_operator:is; 27, 28; 27, 29; 28, identifier:athlete_id; 29, None; 30, block; 30, 31; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 36; 33, subscript; 33, 34; 33, 35; 34, identifier:params; 35, string:'athlete_id'; 36, identifier:athlete_id; 37, if_statement; 37, 38; 37, 39; 38, identifier:start_date_local; 39, block; 39, 40; 39, 60; 40, if_statement; 40, 41; 40, 48; 41, call; 41, 42; 41, 43; 42, identifier:isinstance; 43, argument_list; 43, 44; 43, 45; 44, identifier:start_date_local; 45, attribute; 45, 46; 45, 47; 46, identifier:six; 47, identifier:string_types; 48, block; 48, 49; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:start_date_local; 52, attribute; 52, 53; 52, 59; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:arrow; 56, identifier:get; 57, argument_list; 57, 58; 58, identifier:start_date_local; 59, identifier:naive; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 65; 62, subscript; 62, 63; 62, 64; 63, identifier:params; 64, string:"start_date_local"; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:start_date_local; 68, identifier:strftime; 69, argument_list; 69, 70; 70, string:"%Y-%m-%dT%H:%M:%SZ"; 71, if_statement; 71, 72; 71, 73; 72, identifier:end_date_local; 73, block; 73, 74; 73, 94; 74, if_statement; 74, 75; 74, 82; 75, call; 75, 76; 75, 77; 76, identifier:isinstance; 77, argument_list; 77, 78; 77, 79; 78, identifier:end_date_local; 79, attribute; 79, 80; 79, 81; 80, identifier:six; 81, identifier:string_types; 82, block; 82, 83; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:end_date_local; 86, attribute; 86, 87; 86, 93; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:arrow; 90, identifier:get; 91, argument_list; 91, 92; 92, identifier:end_date_local; 93, identifier:naive; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 99; 96, subscript; 96, 97; 96, 98; 97, identifier:params; 98, string:"end_date_local"; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:end_date_local; 102, identifier:strftime; 103, argument_list; 103, 104; 104, string:"%Y-%m-%dT%H:%M:%SZ"; 105, if_statement; 105, 106; 105, 109; 106, comparison_operator:is; 106, 107; 106, 108; 107, identifier:limit; 108, None; 109, block; 109, 110; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 115; 112, subscript; 112, 113; 112, 114; 113, identifier:params; 114, string:"limit"; 115, identifier:limit; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 119; 118, identifier:result_fetcher; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:functools; 122, identifier:partial; 123, argument_list; 123, 124; 123, 129; 123, 130; 124, attribute; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:self; 127, identifier:protocol; 128, identifier:get; 129, string:'/segments/{segment_id}/all_efforts'; 130, dictionary_splat; 130, 131; 131, identifier:params; 132, return_statement; 132, 133; 133, call; 133, 134; 133, 135; 134, identifier:BatchedResultsIterator; 135, argument_list; 135, 136; 135, 141; 135, 144; 135, 147; 136, keyword_argument; 136, 137; 136, 138; 137, identifier:entity; 138, attribute; 138, 139; 138, 140; 139, identifier:model; 140, identifier:BaseEffort; 141, keyword_argument; 141, 142; 141, 143; 142, identifier:bind_client; 143, identifier:self; 144, keyword_argument; 144, 145; 144, 146; 145, identifier:result_fetcher; 146, identifier:result_fetcher; 147, keyword_argument; 147, 148; 147, 149; 148, identifier:limit; 149, identifier:limit | def get_segment_efforts(self, segment_id, athlete_id=None,
start_date_local=None, end_date_local=None,
limit=None):
params = {"segment_id": segment_id}
if athlete_id is not None:
params['athlete_id'] = athlete_id
if start_date_local:
if isinstance(start_date_local, six.string_types):
start_date_local = arrow.get(start_date_local).naive
params["start_date_local"] = start_date_local.strftime("%Y-%m-%dT%H:%M:%SZ")
if end_date_local:
if isinstance(end_date_local, six.string_types):
end_date_local = arrow.get(end_date_local).naive
params["end_date_local"] = end_date_local.strftime("%Y-%m-%dT%H:%M:%SZ")
if limit is not None:
params["limit"] = limit
result_fetcher = functools.partial(self.protocol.get,
'/segments/{segment_id}/all_efforts',
**params)
return BatchedResultsIterator(entity=model.BaseEffort, bind_client=self,
result_fetcher=result_fetcher, limit=limit) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 16; 2, function_name:range; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 3, 13; 4, identifier:self; 5, identifier:low; 6, identifier:high; 7, default_parameter; 7, 8; 7, 9; 8, identifier:with_scores; 9, False; 10, default_parameter; 10, 11; 10, 12; 11, identifier:desc; 12, False; 13, default_parameter; 13, 14; 13, 15; 14, identifier:reverse; 15, False; 16, block; 16, 17; 17, if_statement; 17, 18; 17, 19; 17, 34; 18, identifier:reverse; 19, block; 19, 20; 20, return_statement; 20, 21; 21, call; 21, 22; 21, 27; 22, attribute; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:database; 26, identifier:zrevrange; 27, argument_list; 27, 28; 27, 31; 27, 32; 27, 33; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:key; 31, identifier:low; 32, identifier:high; 33, identifier:with_scores; 34, else_clause; 34, 35; 35, block; 35, 36; 36, return_statement; 36, 37; 37, call; 37, 38; 37, 43; 38, attribute; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:database; 42, identifier:zrange; 43, argument_list; 43, 44; 43, 47; 43, 48; 43, 49; 43, 50; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:key; 47, identifier:low; 48, identifier:high; 49, identifier:desc; 50, identifier:with_scores | def range(self, low, high, with_scores=False, desc=False, reverse=False):
if reverse:
return self.database.zrevrange(self.key, low, high, with_scores)
else:
return self.database.zrange(self.key, low, high, desc, with_scores) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sfiles_to_event; 3, parameters; 3, 4; 4, identifier:sfile_list; 5, block; 5, 6; 5, 10; 5, 29; 5, 43; 5, 53; 5, 59; 5, 87; 5, 92; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:event_list; 9, list:[]; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:sort_list; 13, list_comprehension; 13, 14; 13, 26; 14, tuple; 14, 15; 14, 25; 15, attribute; 15, 16; 15, 24; 16, subscript; 16, 17; 16, 23; 17, attribute; 17, 18; 17, 22; 18, call; 18, 19; 18, 20; 19, identifier:readheader; 20, argument_list; 20, 21; 21, identifier:sfile; 22, identifier:origins; 23, integer:0; 24, identifier:time; 25, identifier:sfile; 26, for_in_clause; 26, 27; 26, 28; 27, identifier:sfile; 28, identifier:sfile_list; 29, expression_statement; 29, 30; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:sort_list; 33, identifier:sort; 34, argument_list; 34, 35; 35, keyword_argument; 35, 36; 35, 37; 36, identifier:key; 37, lambda; 37, 38; 37, 40; 38, lambda_parameters; 38, 39; 39, identifier:tup; 40, subscript; 40, 41; 40, 42; 41, identifier:tup; 42, integer:0; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:sfile_list; 46, list_comprehension; 46, 47; 46, 50; 47, subscript; 47, 48; 47, 49; 48, identifier:sfile; 49, integer:1; 50, for_in_clause; 50, 51; 50, 52; 51, identifier:sfile; 52, identifier:sort_list; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:catalog; 56, call; 56, 57; 56, 58; 57, identifier:Catalog; 58, argument_list; 59, for_statement; 59, 60; 59, 63; 59, 67; 60, pattern_list; 60, 61; 60, 62; 61, identifier:i; 62, identifier:sfile; 63, call; 63, 64; 63, 65; 64, identifier:enumerate; 65, argument_list; 65, 66; 66, identifier:sfile_list; 67, block; 67, 68; 67, 77; 68, expression_statement; 68, 69; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:event_list; 72, identifier:append; 73, argument_list; 73, 74; 74, tuple; 74, 75; 74, 76; 75, identifier:i; 76, identifier:sfile; 77, expression_statement; 77, 78; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:catalog; 81, identifier:append; 82, argument_list; 82, 83; 83, call; 83, 84; 83, 85; 84, identifier:readheader; 85, argument_list; 85, 86; 86, identifier:sfile; 87, expression_statement; 87, 88; 88, call; 88, 89; 88, 90; 89, identifier:write_event; 90, argument_list; 90, 91; 91, identifier:catalog; 92, return_statement; 92, 93; 93, identifier:event_list | def sfiles_to_event(sfile_list):
event_list = []
sort_list = [(readheader(sfile).origins[0].time, sfile)
for sfile in sfile_list]
sort_list.sort(key=lambda tup: tup[0])
sfile_list = [sfile[1] for sfile in sort_list]
catalog = Catalog()
for i, sfile in enumerate(sfile_list):
event_list.append((i, sfile))
catalog.append(readheader(sfile))
write_event(catalog)
return event_list |
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; 5, 24; 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:families; 12, identifier:sort; 13, argument_list; 13, 14; 14, keyword_argument; 14, 15; 14, 16; 15, identifier:key; 16, lambda; 16, 17; 16, 19; 17, lambda_parameters; 17, 18; 18, identifier:x; 19, attribute; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:x; 22, identifier:template; 23, identifier:name; 24, return_statement; 24, 25; 25, identifier:self | def sort(self):
self.families.sort(key=lambda x: x.template.name)
return self |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:decluster; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:self; 5, identifier:trig_int; 6, default_parameter; 6, 7; 6, 8; 7, identifier:timing; 8, string:'detect'; 9, default_parameter; 9, 10; 9, 11; 10, identifier:metric; 11, string:'avg_cor'; 12, block; 12, 13; 12, 17; 12, 32; 12, 157; 12, 172; 12, 187; 12, 210; 12, 229; 12, 233; 12, 283; 12, 299; 12, 303; 12, 354; 12, 360; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:all_detections; 16, list:[]; 17, for_statement; 17, 18; 17, 19; 17, 22; 18, identifier:fam; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:families; 22, block; 22, 23; 23, expression_statement; 23, 24; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:all_detections; 27, identifier:extend; 28, argument_list; 28, 29; 29, attribute; 29, 30; 29, 31; 30, identifier:fam; 31, identifier:detections; 32, if_statement; 32, 33; 32, 36; 32, 86; 32, 150; 33, comparison_operator:==; 33, 34; 33, 35; 34, identifier:timing; 35, string:'detect'; 36, block; 36, 37; 37, if_statement; 37, 38; 37, 41; 37, 60; 37, 79; 38, comparison_operator:==; 38, 39; 38, 40; 39, identifier:metric; 40, string:'avg_cor'; 41, block; 41, 42; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:detect_info; 45, list_comprehension; 45, 46; 45, 57; 46, tuple; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:d; 49, identifier:detect_time; 50, binary_operator:/; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:d; 53, identifier:detect_val; 54, attribute; 54, 55; 54, 56; 55, identifier:d; 56, identifier:no_chans; 57, for_in_clause; 57, 58; 57, 59; 58, identifier:d; 59, identifier:all_detections; 60, elif_clause; 60, 61; 60, 64; 61, comparison_operator:==; 61, 62; 61, 63; 62, identifier:metric; 63, string:'cor_sum'; 64, block; 64, 65; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:detect_info; 68, list_comprehension; 68, 69; 68, 76; 69, tuple; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:d; 72, identifier:detect_time; 73, attribute; 73, 74; 73, 75; 74, identifier:d; 75, identifier:detect_val; 76, for_in_clause; 76, 77; 76, 78; 77, identifier:d; 78, identifier:all_detections; 79, else_clause; 79, 80; 80, block; 80, 81; 81, raise_statement; 81, 82; 82, call; 82, 83; 82, 84; 83, identifier:MatchFilterError; 84, argument_list; 84, 85; 85, string:'metric is not cor_sum or avg_cor'; 86, elif_clause; 86, 87; 86, 90; 87, comparison_operator:==; 87, 88; 87, 89; 88, identifier:timing; 89, string:'origin'; 90, block; 90, 91; 91, if_statement; 91, 92; 91, 95; 91, 119; 91, 143; 92, comparison_operator:==; 92, 93; 92, 94; 93, identifier:metric; 94, string:'avg_cor'; 95, block; 95, 96; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:detect_info; 99, list_comprehension; 99, 100; 99, 116; 100, tuple; 100, 101; 100, 109; 101, attribute; 101, 102; 101, 108; 102, call; 102, 103; 102, 104; 103, identifier:_get_origin; 104, argument_list; 104, 105; 105, attribute; 105, 106; 105, 107; 106, identifier:d; 107, identifier:event; 108, identifier:time; 109, binary_operator:/; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:d; 112, identifier:detect_val; 113, attribute; 113, 114; 113, 115; 114, identifier:d; 115, identifier:no_chans; 116, for_in_clause; 116, 117; 116, 118; 117, identifier:d; 118, identifier:all_detections; 119, elif_clause; 119, 120; 119, 123; 120, comparison_operator:==; 120, 121; 120, 122; 121, identifier:metric; 122, string:'cor_sum'; 123, block; 123, 124; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:detect_info; 127, list_comprehension; 127, 128; 127, 140; 128, tuple; 128, 129; 128, 137; 129, attribute; 129, 130; 129, 136; 130, call; 130, 131; 130, 132; 131, identifier:_get_origin; 132, argument_list; 132, 133; 133, attribute; 133, 134; 133, 135; 134, identifier:d; 135, identifier:event; 136, identifier:time; 137, attribute; 137, 138; 137, 139; 138, identifier:d; 139, identifier:detect_val; 140, for_in_clause; 140, 141; 140, 142; 141, identifier:d; 142, identifier:all_detections; 143, else_clause; 143, 144; 144, block; 144, 145; 145, raise_statement; 145, 146; 146, call; 146, 147; 146, 148; 147, identifier:MatchFilterError; 148, argument_list; 148, 149; 149, string:'metric is not cor_sum or avg_cor'; 150, else_clause; 150, 151; 151, block; 151, 152; 152, raise_statement; 152, 153; 153, call; 153, 154; 153, 155; 154, identifier:MatchFilterError; 155, argument_list; 155, 156; 156, string:'timing is not detect or origin'; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:min_det; 160, subscript; 160, 161; 160, 171; 161, call; 161, 162; 161, 163; 162, identifier:sorted; 163, argument_list; 163, 164; 164, list_comprehension; 164, 165; 164, 168; 165, subscript; 165, 166; 165, 167; 166, identifier:d; 167, integer:0; 168, for_in_clause; 168, 169; 168, 170; 169, identifier:d; 170, identifier:detect_info; 171, integer:0; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:detect_vals; 175, call; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:np; 178, identifier:array; 179, argument_list; 179, 180; 180, list_comprehension; 180, 181; 180, 184; 181, subscript; 181, 182; 181, 183; 182, identifier:d; 183, integer:1; 184, for_in_clause; 184, 185; 184, 186; 185, identifier:d; 186, identifier:detect_info; 187, expression_statement; 187, 188; 188, assignment; 188, 189; 188, 190; 189, identifier:detect_times; 190, call; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:np; 193, identifier:array; 194, argument_list; 194, 195; 195, list_comprehension; 195, 196; 195, 207; 196, call; 196, 197; 196, 198; 197, identifier:_total_microsec; 198, argument_list; 198, 199; 198, 204; 199, attribute; 199, 200; 199, 203; 200, subscript; 200, 201; 200, 202; 201, identifier:d; 202, integer:0; 203, identifier:datetime; 204, attribute; 204, 205; 204, 206; 205, identifier:min_det; 206, identifier:datetime; 207, for_in_clause; 207, 208; 207, 209; 208, identifier:d; 209, identifier:detect_info; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 213; 212, identifier:peaks_out; 213, call; 213, 214; 213, 215; 214, identifier:decluster; 215, argument_list; 215, 216; 215, 219; 215, 222; 216, keyword_argument; 216, 217; 216, 218; 217, identifier:peaks; 218, identifier:detect_vals; 219, keyword_argument; 219, 220; 219, 221; 220, identifier:index; 221, identifier:detect_times; 222, keyword_argument; 222, 223; 222, 224; 223, identifier:trig_int; 224, binary_operator:*; 224, 225; 224, 226; 225, identifier:trig_int; 226, binary_operator:**; 226, 227; 226, 228; 227, integer:10; 228, integer:6; 229, expression_statement; 229, 230; 230, assignment; 230, 231; 230, 232; 231, identifier:declustered_detections; 232, list:[]; 233, for_statement; 233, 234; 233, 235; 233, 236; 234, identifier:ind; 235, identifier:peaks_out; 236, block; 236, 237; 236, 253; 236, 274; 237, expression_statement; 237, 238; 238, assignment; 238, 239; 238, 240; 239, identifier:matching_time_indeces; 240, subscript; 240, 241; 240, 252; 241, call; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:np; 244, identifier:where; 245, argument_list; 245, 246; 246, comparison_operator:==; 246, 247; 246, 248; 247, identifier:detect_times; 248, subscript; 248, 249; 248, 250; 249, identifier:ind; 250, unary_operator:-; 250, 251; 251, integer:1; 252, integer:0; 253, expression_statement; 253, 254; 254, assignment; 254, 255; 254, 256; 255, identifier:matches; 256, subscript; 256, 257; 256, 258; 257, identifier:matching_time_indeces; 258, subscript; 258, 259; 258, 273; 259, subscript; 259, 260; 259, 272; 260, call; 260, 261; 260, 264; 261, attribute; 261, 262; 261, 263; 262, identifier:np; 263, identifier:where; 264, argument_list; 264, 265; 265, comparison_operator:==; 265, 266; 265, 269; 266, subscript; 266, 267; 266, 268; 267, identifier:detect_vals; 268, identifier:matching_time_indeces; 269, subscript; 269, 270; 269, 271; 270, identifier:ind; 271, integer:0; 272, integer:0; 273, integer:0; 274, expression_statement; 274, 275; 275, call; 275, 276; 275, 279; 276, attribute; 276, 277; 276, 278; 277, identifier:declustered_detections; 278, identifier:append; 279, argument_list; 279, 280; 280, subscript; 280, 281; 280, 282; 281, identifier:all_detections; 282, identifier:matches; 283, expression_statement; 283, 284; 284, assignment; 284, 285; 284, 286; 285, identifier:template_names; 286, call; 286, 287; 286, 288; 287, identifier:list; 288, argument_list; 288, 289; 289, call; 289, 290; 289, 291; 290, identifier:set; 291, argument_list; 291, 292; 292, list_comprehension; 292, 293; 292, 296; 293, attribute; 293, 294; 293, 295; 294, identifier:d; 295, identifier:template_name; 296, for_in_clause; 296, 297; 296, 298; 297, identifier:d; 298, identifier:declustered_detections; 299, expression_statement; 299, 300; 300, assignment; 300, 301; 300, 302; 301, identifier:new_families; 302, list:[]; 303, for_statement; 303, 304; 303, 305; 303, 306; 304, identifier:template_name; 305, identifier:template_names; 306, block; 306, 307; 306, 329; 307, expression_statement; 307, 308; 308, assignment; 308, 309; 308, 310; 309, identifier:template; 310, subscript; 310, 311; 310, 328; 311, list_comprehension; 311, 312; 311, 315; 311, 320; 312, attribute; 312, 313; 312, 314; 313, identifier:fam; 314, identifier:template; 315, for_in_clause; 315, 316; 315, 317; 316, identifier:fam; 317, attribute; 317, 318; 317, 319; 318, identifier:self; 319, identifier:families; 320, if_clause; 320, 321; 321, comparison_operator:==; 321, 322; 321, 327; 322, attribute; 322, 323; 322, 326; 323, attribute; 323, 324; 323, 325; 324, identifier:fam; 325, identifier:template; 326, identifier:name; 327, identifier:template_name; 328, integer:0; 329, expression_statement; 329, 330; 330, call; 330, 331; 330, 334; 331, attribute; 331, 332; 331, 333; 332, identifier:new_families; 333, identifier:append; 334, argument_list; 334, 335; 335, call; 335, 336; 335, 337; 336, identifier:Family; 337, argument_list; 337, 338; 337, 341; 338, keyword_argument; 338, 339; 338, 340; 339, identifier:template; 340, identifier:template; 341, keyword_argument; 341, 342; 341, 343; 342, identifier:detections; 343, list_comprehension; 343, 344; 343, 345; 343, 348; 344, identifier:d; 345, for_in_clause; 345, 346; 345, 347; 346, identifier:d; 347, identifier:declustered_detections; 348, if_clause; 348, 349; 349, comparison_operator:==; 349, 350; 349, 353; 350, attribute; 350, 351; 350, 352; 351, identifier:d; 352, identifier:template_name; 353, identifier:template_name; 354, expression_statement; 354, 355; 355, assignment; 355, 356; 355, 359; 356, attribute; 356, 357; 356, 358; 357, identifier:self; 358, identifier:families; 359, identifier:new_families; 360, return_statement; 360, 361; 361, identifier:self | def decluster(self, trig_int, timing='detect', metric='avg_cor'):
all_detections = []
for fam in self.families:
all_detections.extend(fam.detections)
if timing == 'detect':
if metric == 'avg_cor':
detect_info = [(d.detect_time, d.detect_val / d.no_chans)
for d in all_detections]
elif metric == 'cor_sum':
detect_info = [(d.detect_time, d.detect_val)
for d in all_detections]
else:
raise MatchFilterError('metric is not cor_sum or avg_cor')
elif timing == 'origin':
if metric == 'avg_cor':
detect_info = [(_get_origin(d.event).time,
d.detect_val / d.no_chans)
for d in all_detections]
elif metric == 'cor_sum':
detect_info = [(_get_origin(d.event).time, d.detect_val)
for d in all_detections]
else:
raise MatchFilterError('metric is not cor_sum or avg_cor')
else:
raise MatchFilterError('timing is not detect or origin')
min_det = sorted([d[0] for d in detect_info])[0]
detect_vals = np.array([d[1] for d in detect_info])
detect_times = np.array([
_total_microsec(d[0].datetime, min_det.datetime)
for d in detect_info])
peaks_out = decluster(
peaks=detect_vals, index=detect_times, trig_int=trig_int * 10 ** 6)
declustered_detections = []
for ind in peaks_out:
matching_time_indeces = np.where(detect_times == ind[-1])[0]
matches = matching_time_indeces[
np.where(detect_vals[matching_time_indeces] == ind[0])[0][0]]
declustered_detections.append(all_detections[matches])
template_names = list(set([d.template_name
for d in declustered_detections]))
new_families = []
for template_name in template_names:
template = [fam.template for fam in self.families
if fam.template.name == template_name][0]
new_families.append(Family(
template=template,
detections=[d for d in declustered_detections
if d.template_name == template_name]))
self.families = new_families
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; 5, 25; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:detections; 11, call; 11, 12; 11, 13; 12, identifier:sorted; 13, argument_list; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:detections; 17, keyword_argument; 17, 18; 17, 19; 18, identifier:key; 19, lambda; 19, 20; 19, 22; 20, lambda_parameters; 20, 21; 21, identifier:d; 22, attribute; 22, 23; 22, 24; 23, identifier:d; 24, identifier:detect_time; 25, return_statement; 25, 26; 26, identifier:self | def sort(self):
self.detections = sorted(self.detections, key=lambda d: d.detect_time)
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; 5, 25; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:templates; 11, call; 11, 12; 11, 13; 12, identifier:sorted; 13, argument_list; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:templates; 17, keyword_argument; 17, 18; 17, 19; 18, identifier:key; 19, lambda; 19, 20; 19, 22; 20, lambda_parameters; 20, 21; 21, identifier:x; 22, attribute; 22, 23; 22, 24; 23, identifier:x; 24, identifier:name; 25, return_statement; 25, 26; 26, identifier:self | def sort(self):
self.templates = sorted(self.templates, key=lambda x: x.name)
return self |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 23; 2, function_name:filter_picks; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 4, identifier:catalog; 5, default_parameter; 5, 6; 5, 7; 6, identifier:stations; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:channels; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:networks; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:locations; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:top_n_picks; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:evaluation_mode; 22, string:'all'; 23, block; 23, 24; 23, 32; 23, 70; 23, 108; 23, 146; 23, 184; 23, 252; 23, 421; 23, 427; 23, 448; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:filtered_catalog; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:catalog; 30, identifier:copy; 31, argument_list; 32, if_statement; 32, 33; 32, 34; 33, identifier:stations; 34, block; 34, 35; 35, for_statement; 35, 36; 35, 37; 35, 38; 36, identifier:event; 37, identifier:filtered_catalog; 38, block; 38, 39; 38, 50; 39, if_statement; 39, 40; 39, 48; 40, comparison_operator:==; 40, 41; 40, 47; 41, call; 41, 42; 41, 43; 42, identifier:len; 43, argument_list; 43, 44; 44, attribute; 44, 45; 44, 46; 45, identifier:event; 46, identifier:picks; 47, integer:0; 48, block; 48, 49; 49, continue_statement; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:event; 54, identifier:picks; 55, list_comprehension; 55, 56; 55, 57; 55, 62; 56, identifier:pick; 57, for_in_clause; 57, 58; 57, 59; 58, identifier:pick; 59, attribute; 59, 60; 59, 61; 60, identifier:event; 61, identifier:picks; 62, if_clause; 62, 63; 63, comparison_operator:in; 63, 64; 63, 69; 64, attribute; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:pick; 67, identifier:waveform_id; 68, identifier:station_code; 69, identifier:stations; 70, if_statement; 70, 71; 70, 72; 71, identifier:channels; 72, block; 72, 73; 73, for_statement; 73, 74; 73, 75; 73, 76; 74, identifier:event; 75, identifier:filtered_catalog; 76, block; 76, 77; 76, 88; 77, if_statement; 77, 78; 77, 86; 78, comparison_operator:==; 78, 79; 78, 85; 79, call; 79, 80; 79, 81; 80, identifier:len; 81, argument_list; 81, 82; 82, attribute; 82, 83; 82, 84; 83, identifier:event; 84, identifier:picks; 85, integer:0; 86, block; 86, 87; 87, continue_statement; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:event; 92, identifier:picks; 93, list_comprehension; 93, 94; 93, 95; 93, 100; 94, identifier:pick; 95, for_in_clause; 95, 96; 95, 97; 96, identifier:pick; 97, attribute; 97, 98; 97, 99; 98, identifier:event; 99, identifier:picks; 100, if_clause; 100, 101; 101, comparison_operator:in; 101, 102; 101, 107; 102, attribute; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:pick; 105, identifier:waveform_id; 106, identifier:channel_code; 107, identifier:channels; 108, if_statement; 108, 109; 108, 110; 109, identifier:networks; 110, block; 110, 111; 111, for_statement; 111, 112; 111, 113; 111, 114; 112, identifier:event; 113, identifier:filtered_catalog; 114, block; 114, 115; 114, 126; 115, if_statement; 115, 116; 115, 124; 116, comparison_operator:==; 116, 117; 116, 123; 117, call; 117, 118; 117, 119; 118, identifier:len; 119, argument_list; 119, 120; 120, attribute; 120, 121; 120, 122; 121, identifier:event; 122, identifier:picks; 123, integer:0; 124, block; 124, 125; 125, continue_statement; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:event; 130, identifier:picks; 131, list_comprehension; 131, 132; 131, 133; 131, 138; 132, identifier:pick; 133, for_in_clause; 133, 134; 133, 135; 134, identifier:pick; 135, attribute; 135, 136; 135, 137; 136, identifier:event; 137, identifier:picks; 138, if_clause; 138, 139; 139, comparison_operator:in; 139, 140; 139, 145; 140, attribute; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:pick; 143, identifier:waveform_id; 144, identifier:network_code; 145, identifier:networks; 146, if_statement; 146, 147; 146, 148; 147, identifier:locations; 148, block; 148, 149; 149, for_statement; 149, 150; 149, 151; 149, 152; 150, identifier:event; 151, identifier:filtered_catalog; 152, block; 152, 153; 152, 164; 153, if_statement; 153, 154; 153, 162; 154, comparison_operator:==; 154, 155; 154, 161; 155, call; 155, 156; 155, 157; 156, identifier:len; 157, argument_list; 157, 158; 158, attribute; 158, 159; 158, 160; 159, identifier:event; 160, identifier:picks; 161, integer:0; 162, block; 162, 163; 163, continue_statement; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:event; 168, identifier:picks; 169, list_comprehension; 169, 170; 169, 171; 169, 176; 170, identifier:pick; 171, for_in_clause; 171, 172; 171, 173; 172, identifier:pick; 173, attribute; 173, 174; 173, 175; 174, identifier:event; 175, identifier:picks; 176, if_clause; 176, 177; 177, comparison_operator:in; 177, 178; 177, 183; 178, attribute; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:pick; 181, identifier:waveform_id; 182, identifier:location_code; 183, identifier:locations; 184, if_statement; 184, 185; 184, 188; 184, 211; 184, 238; 185, comparison_operator:==; 185, 186; 185, 187; 186, identifier:evaluation_mode; 187, string:'manual'; 188, block; 188, 189; 189, for_statement; 189, 190; 189, 191; 189, 192; 190, identifier:event; 191, identifier:filtered_catalog; 192, block; 192, 193; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:event; 197, identifier:picks; 198, list_comprehension; 198, 199; 198, 200; 198, 205; 199, identifier:pick; 200, for_in_clause; 200, 201; 200, 202; 201, identifier:pick; 202, attribute; 202, 203; 202, 204; 203, identifier:event; 204, identifier:picks; 205, if_clause; 205, 206; 206, comparison_operator:==; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:pick; 209, identifier:evaluation_mode; 210, string:'manual'; 211, elif_clause; 211, 212; 211, 215; 212, comparison_operator:==; 212, 213; 212, 214; 213, identifier:evaluation_mode; 214, string:'automatic'; 215, block; 215, 216; 216, for_statement; 216, 217; 216, 218; 216, 219; 217, identifier:event; 218, identifier:filtered_catalog; 219, block; 219, 220; 220, expression_statement; 220, 221; 221, assignment; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:event; 224, identifier:picks; 225, list_comprehension; 225, 226; 225, 227; 225, 232; 226, identifier:pick; 227, for_in_clause; 227, 228; 227, 229; 228, identifier:pick; 229, attribute; 229, 230; 229, 231; 230, identifier:event; 231, identifier:picks; 232, if_clause; 232, 233; 233, comparison_operator:==; 233, 234; 233, 237; 234, attribute; 234, 235; 234, 236; 235, identifier:pick; 236, identifier:evaluation_mode; 237, string:'automatic'; 238, elif_clause; 238, 239; 238, 242; 239, comparison_operator:!=; 239, 240; 239, 241; 240, identifier:evaluation_mode; 241, string:'all'; 242, block; 242, 243; 243, expression_statement; 243, 244; 244, call; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, identifier:warnings; 247, identifier:warn; 248, argument_list; 248, 249; 249, binary_operator:%; 249, 250; 249, 251; 250, string:'Unrecognised evaluation_mode: %s, using all picks'; 251, identifier:evaluation_mode; 252, if_statement; 252, 253; 252, 254; 253, identifier:top_n_picks; 254, block; 254, 255; 254, 259; 254, 283; 254, 294; 254, 298; 254, 380; 255, expression_statement; 255, 256; 256, assignment; 256, 257; 256, 258; 257, identifier:all_picks; 258, list:[]; 259, for_statement; 259, 260; 259, 261; 259, 262; 260, identifier:event; 261, identifier:filtered_catalog; 262, block; 262, 263; 263, expression_statement; 263, 264; 264, augmented_assignment:+=; 264, 265; 264, 266; 265, identifier:all_picks; 266, list_comprehension; 266, 267; 266, 278; 267, tuple; 267, 268; 267, 273; 268, attribute; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:pick; 271, identifier:waveform_id; 272, identifier:station_code; 273, attribute; 273, 274; 273, 277; 274, attribute; 274, 275; 274, 276; 275, identifier:pick; 276, identifier:waveform_id; 277, identifier:channel_code; 278, for_in_clause; 278, 279; 278, 280; 279, identifier:pick; 280, attribute; 280, 281; 280, 282; 281, identifier:event; 282, identifier:picks; 283, expression_statement; 283, 284; 284, assignment; 284, 285; 284, 286; 285, identifier:counted; 286, call; 286, 287; 286, 293; 287, attribute; 287, 288; 287, 292; 288, call; 288, 289; 288, 290; 289, identifier:Counter; 290, argument_list; 290, 291; 291, identifier:all_picks; 292, identifier:most_common; 293, argument_list; 294, expression_statement; 294, 295; 295, assignment; 295, 296; 295, 297; 296, identifier:all_picks; 297, list:[]; 298, for_statement; 298, 299; 298, 300; 298, 308; 299, identifier:i; 300, call; 300, 301; 300, 302; 301, identifier:range; 302, argument_list; 302, 303; 303, subscript; 303, 304; 303, 307; 304, subscript; 304, 305; 304, 306; 305, identifier:counted; 306, integer:0; 307, integer:1; 308, block; 308, 309; 308, 331; 308, 346; 308, 362; 309, expression_statement; 309, 310; 310, assignment; 310, 311; 310, 312; 311, identifier:highest; 312, list_comprehension; 312, 313; 312, 316; 312, 319; 313, subscript; 313, 314; 313, 315; 314, identifier:item; 315, integer:0; 316, for_in_clause; 316, 317; 316, 318; 317, identifier:item; 318, identifier:counted; 319, if_clause; 319, 320; 320, comparison_operator:>=; 320, 321; 320, 324; 321, subscript; 321, 322; 321, 323; 322, identifier:item; 323, integer:1; 324, binary_operator:-; 324, 325; 324, 330; 325, subscript; 325, 326; 325, 329; 326, subscript; 326, 327; 326, 328; 327, identifier:counted; 328, integer:0; 329, integer:1; 330, identifier:i; 331, expression_statement; 331, 332; 332, assignment; 332, 333; 332, 334; 333, identifier:highest; 334, call; 334, 335; 334, 336; 335, identifier:sorted; 336, argument_list; 336, 337; 336, 338; 337, identifier:highest; 338, keyword_argument; 338, 339; 338, 340; 339, identifier:key; 340, lambda; 340, 341; 340, 343; 341, lambda_parameters; 341, 342; 342, identifier:tup; 343, subscript; 343, 344; 343, 345; 344, identifier:tup; 345, integer:0; 346, for_statement; 346, 347; 346, 348; 346, 349; 347, identifier:stachan; 348, identifier:highest; 349, block; 349, 350; 350, if_statement; 350, 351; 350, 354; 351, comparison_operator:not; 351, 352; 351, 353; 352, identifier:stachan; 353, identifier:all_picks; 354, block; 354, 355; 355, expression_statement; 355, 356; 356, call; 356, 357; 356, 360; 357, attribute; 357, 358; 357, 359; 358, identifier:all_picks; 359, identifier:append; 360, argument_list; 360, 361; 361, identifier:stachan; 362, if_statement; 362, 363; 362, 369; 363, comparison_operator:>; 363, 364; 363, 368; 364, call; 364, 365; 364, 366; 365, identifier:len; 366, argument_list; 366, 367; 367, identifier:all_picks; 368, identifier:top_n_picks; 369, block; 369, 370; 369, 379; 370, expression_statement; 370, 371; 371, assignment; 371, 372; 371, 373; 372, identifier:all_picks; 373, subscript; 373, 374; 373, 375; 374, identifier:all_picks; 375, slice; 375, 376; 375, 377; 375, 378; 376, integer:0; 377, colon; 378, identifier:top_n_picks; 379, break_statement; 380, for_statement; 380, 381; 380, 382; 380, 383; 381, identifier:event; 382, identifier:filtered_catalog; 383, block; 383, 384; 383, 395; 384, if_statement; 384, 385; 384, 393; 385, comparison_operator:==; 385, 386; 385, 392; 386, call; 386, 387; 386, 388; 387, identifier:len; 388, argument_list; 388, 389; 389, attribute; 389, 390; 389, 391; 390, identifier:event; 391, identifier:picks; 392, integer:0; 393, block; 393, 394; 394, continue_statement; 395, expression_statement; 395, 396; 396, assignment; 396, 397; 396, 400; 397, attribute; 397, 398; 397, 399; 398, identifier:event; 399, identifier:picks; 400, list_comprehension; 400, 401; 400, 402; 400, 407; 401, identifier:pick; 402, for_in_clause; 402, 403; 402, 404; 403, identifier:pick; 404, attribute; 404, 405; 404, 406; 405, identifier:event; 406, identifier:picks; 407, if_clause; 407, 408; 408, comparison_operator:in; 408, 409; 408, 420; 409, tuple; 409, 410; 409, 415; 410, attribute; 410, 411; 410, 414; 411, attribute; 411, 412; 411, 413; 412, identifier:pick; 413, identifier:waveform_id; 414, identifier:station_code; 415, attribute; 415, 416; 415, 419; 416, attribute; 416, 417; 416, 418; 417, identifier:pick; 418, identifier:waveform_id; 419, identifier:channel_code; 420, identifier:all_picks; 421, expression_statement; 421, 422; 422, assignment; 422, 423; 422, 424; 423, identifier:tmp_catalog; 424, call; 424, 425; 424, 426; 425, identifier:Catalog; 426, argument_list; 427, for_statement; 427, 428; 427, 429; 427, 430; 428, identifier:event; 429, identifier:filtered_catalog; 430, block; 430, 431; 431, if_statement; 431, 432; 431, 440; 432, comparison_operator:>; 432, 433; 432, 439; 433, call; 433, 434; 433, 435; 434, identifier:len; 435, argument_list; 435, 436; 436, attribute; 436, 437; 436, 438; 437, identifier:event; 438, identifier:picks; 439, integer:0; 440, block; 440, 441; 441, expression_statement; 441, 442; 442, call; 442, 443; 442, 446; 443, attribute; 443, 444; 443, 445; 444, identifier:tmp_catalog; 445, identifier:append; 446, argument_list; 446, 447; 447, identifier:event; 448, return_statement; 448, 449; 449, identifier:tmp_catalog | def filter_picks(catalog, stations=None, channels=None, networks=None,
locations=None, top_n_picks=None, evaluation_mode='all'):
filtered_catalog = catalog.copy()
if stations:
for event in filtered_catalog:
if len(event.picks) == 0:
continue
event.picks = [pick for pick in event.picks
if pick.waveform_id.station_code in stations]
if channels:
for event in filtered_catalog:
if len(event.picks) == 0:
continue
event.picks = [pick for pick in event.picks
if pick.waveform_id.channel_code in channels]
if networks:
for event in filtered_catalog:
if len(event.picks) == 0:
continue
event.picks = [pick for pick in event.picks
if pick.waveform_id.network_code in networks]
if locations:
for event in filtered_catalog:
if len(event.picks) == 0:
continue
event.picks = [pick for pick in event.picks
if pick.waveform_id.location_code in locations]
if evaluation_mode == 'manual':
for event in filtered_catalog:
event.picks = [pick for pick in event.picks
if pick.evaluation_mode == 'manual']
elif evaluation_mode == 'automatic':
for event in filtered_catalog:
event.picks = [pick for pick in event.picks
if pick.evaluation_mode == 'automatic']
elif evaluation_mode != 'all':
warnings.warn('Unrecognised evaluation_mode: %s, using all picks' %
evaluation_mode)
if top_n_picks:
all_picks = []
for event in filtered_catalog:
all_picks += [(pick.waveform_id.station_code,
pick.waveform_id.channel_code)
for pick in event.picks]
counted = Counter(all_picks).most_common()
all_picks = []
for i in range(counted[0][1]):
highest = [item[0] for item in counted
if item[1] >= counted[0][1] - i]
highest = sorted(highest, key=lambda tup: tup[0])
for stachan in highest:
if stachan not in all_picks:
all_picks.append(stachan)
if len(all_picks) > top_n_picks:
all_picks = all_picks[0:top_n_picks]
break
for event in filtered_catalog:
if len(event.picks) == 0:
continue
event.picks = [pick for pick in event.picks
if (pick.waveform_id.station_code,
pick.waveform_id.channel_code) in all_picks]
tmp_catalog = Catalog()
for event in filtered_catalog:
if len(event.picks) > 0:
tmp_catalog.append(event)
return tmp_catalog |
Subsets and Splits