sequence
stringlengths 492
15.9k
| code
stringlengths 75
8.58k
|
---|---|
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:values; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 20; 6, function_definition; 6, 7; 6, 8; 6, 10; 7, function_name:key; 8, parameters; 8, 9; 9, identifier:th; 10, block; 10, 11; 11, return_statement; 11, 12; 12, call; 12, 13; 12, 14; 13, identifier:len; 14, argument_list; 14, 15; 15, attribute; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:th; 18, identifier:__class__; 19, identifier:__mro__; 20, return_statement; 20, 21; 21, call; 21, 22; 21, 23; 22, identifier:sorted; 23, argument_list; 23, 24; 23, 30; 23, 33; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:dict; 27, identifier:values; 28, argument_list; 28, 29; 29, identifier:self; 30, keyword_argument; 30, 31; 30, 32; 31, identifier:key; 32, identifier:key; 33, keyword_argument; 33, 34; 33, 35; 34, identifier:reverse; 35, True | def values(self):
def key(th):
return len(th.__class__.__mro__)
return sorted(dict.values(self), key=key, reverse=True) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:topological_sort; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 12; 5, 16; 5, 26; 5, 42; 5, 48; 5, 66; 5, 70; 5, 117; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:graph; 9, attribute; 9, 10; 9, 11; 10, identifier:self; 11, identifier:graph; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:in_degree; 15, dictionary; 16, for_statement; 16, 17; 16, 18; 16, 19; 17, identifier:u; 18, identifier:graph; 19, block; 19, 20; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 25; 22, subscript; 22, 23; 22, 24; 23, identifier:in_degree; 24, identifier:u; 25, integer:0; 26, for_statement; 26, 27; 26, 28; 26, 29; 27, identifier:u; 28, identifier:graph; 29, block; 29, 30; 30, for_statement; 30, 31; 30, 32; 30, 35; 31, identifier:v; 32, subscript; 32, 33; 32, 34; 33, identifier:graph; 34, identifier:u; 35, block; 35, 36; 36, expression_statement; 36, 37; 37, augmented_assignment:+=; 37, 38; 37, 41; 38, subscript; 38, 39; 38, 40; 39, identifier:in_degree; 40, identifier:v; 41, integer:1; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:queue; 45, call; 45, 46; 45, 47; 46, identifier:deque; 47, argument_list; 48, for_statement; 48, 49; 48, 50; 48, 51; 49, identifier:u; 50, identifier:in_degree; 51, block; 51, 52; 52, if_statement; 52, 53; 52, 58; 53, comparison_operator:==; 53, 54; 53, 57; 54, subscript; 54, 55; 54, 56; 55, identifier:in_degree; 56, identifier:u; 57, integer:0; 58, block; 58, 59; 59, expression_statement; 59, 60; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:queue; 63, identifier:appendleft; 64, argument_list; 64, 65; 65, identifier:u; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:sorted_graph; 69, list:[]; 70, while_statement; 70, 71; 70, 72; 71, identifier:queue; 72, block; 72, 73; 72, 81; 72, 88; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:u; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:queue; 79, identifier:pop; 80, argument_list; 81, expression_statement; 81, 82; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:sorted_graph; 85, identifier:append; 86, argument_list; 86, 87; 87, identifier:u; 88, for_statement; 88, 89; 88, 90; 88, 96; 89, identifier:v; 90, call; 90, 91; 90, 92; 91, identifier:sorted; 92, argument_list; 92, 93; 93, subscript; 93, 94; 93, 95; 94, identifier:graph; 95, identifier:u; 96, block; 96, 97; 96, 103; 97, expression_statement; 97, 98; 98, augmented_assignment:-=; 98, 99; 98, 102; 99, subscript; 99, 100; 99, 101; 100, identifier:in_degree; 101, identifier:v; 102, integer:1; 103, if_statement; 103, 104; 103, 109; 104, comparison_operator:==; 104, 105; 104, 108; 105, subscript; 105, 106; 105, 107; 106, identifier:in_degree; 107, identifier:v; 108, integer:0; 109, block; 109, 110; 110, expression_statement; 110, 111; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:queue; 114, identifier:appendleft; 115, argument_list; 115, 116; 116, identifier:v; 117, if_statement; 117, 118; 117, 127; 117, 130; 118, comparison_operator:==; 118, 119; 118, 123; 119, call; 119, 120; 119, 121; 120, identifier:len; 121, argument_list; 121, 122; 122, identifier:sorted_graph; 123, call; 123, 124; 123, 125; 124, identifier:len; 125, argument_list; 125, 126; 126, identifier:graph; 127, block; 127, 128; 128, return_statement; 128, 129; 129, identifier:sorted_graph; 130, else_clause; 130, 131; 131, block; 131, 132; 132, raise_statement; 132, 133; 133, call; 133, 134; 133, 135; 134, identifier:ValueError; 135, argument_list; 135, 136; 136, string:'graph is not acyclic' | def topological_sort(self):
graph = self.graph
in_degree = {}
for u in graph:
in_degree[u] = 0
for u in graph:
for v in graph[u]:
in_degree[v] += 1
queue = deque()
for u in in_degree:
if in_degree[u] == 0:
queue.appendleft(u)
sorted_graph = []
while queue:
u = queue.pop()
sorted_graph.append(u)
for v in sorted(graph[u]):
in_degree[v] -= 1
if in_degree[v] == 0:
queue.appendleft(v)
if len(sorted_graph) == len(graph):
return sorted_graph
else:
raise ValueError('graph is not acyclic') |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_music_lib_search; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:search; 6, identifier:start; 7, identifier:max_items; 8, block; 8, 9; 8, 38; 8, 42; 8, 63; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:response; 12, call; 12, 13; 12, 18; 13, attribute; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:contentDirectory; 17, identifier:Browse; 18, argument_list; 18, 19; 19, list:[
('ObjectID', search),
('BrowseFlag', 'BrowseDirectChildren'),
('Filter', '*'),
('StartingIndex', start),
('RequestedCount', max_items),
('SortCriteria', '')
]; 19, 20; 19, 23; 19, 26; 19, 29; 19, 32; 19, 35; 20, tuple; 20, 21; 20, 22; 21, string:'ObjectID'; 22, identifier:search; 23, tuple; 23, 24; 23, 25; 24, string:'BrowseFlag'; 25, string:'BrowseDirectChildren'; 26, tuple; 26, 27; 26, 28; 27, string:'Filter'; 28, string:'*'; 29, tuple; 29, 30; 29, 31; 30, string:'StartingIndex'; 31, identifier:start; 32, tuple; 32, 33; 32, 34; 33, string:'RequestedCount'; 34, identifier:max_items; 35, tuple; 35, 36; 35, 37; 36, string:'SortCriteria'; 37, string:''; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:metadata; 41, dictionary; 42, for_statement; 42, 43; 42, 44; 42, 48; 43, identifier:tag; 44, list:['NumberReturned', 'TotalMatches', 'UpdateID']; 44, 45; 44, 46; 44, 47; 45, string:'NumberReturned'; 46, string:'TotalMatches'; 47, string:'UpdateID'; 48, block; 48, 49; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 57; 51, subscript; 51, 52; 51, 53; 52, identifier:metadata; 53, call; 53, 54; 53, 55; 54, identifier:camel_to_underscore; 55, argument_list; 55, 56; 56, identifier:tag; 57, call; 57, 58; 57, 59; 58, identifier:int; 59, argument_list; 59, 60; 60, subscript; 60, 61; 60, 62; 61, identifier:response; 62, identifier:tag; 63, return_statement; 63, 64; 64, expression_list; 64, 65; 64, 66; 65, identifier:response; 66, identifier:metadata | def _music_lib_search(self, search, start, max_items):
response = self.contentDirectory.Browse([
('ObjectID', search),
('BrowseFlag', 'BrowseDirectChildren'),
('Filter', '*'),
('StartingIndex', start),
('RequestedCount', max_items),
('SortCriteria', '')
])
metadata = {}
for tag in ['NumberReturned', 'TotalMatches', 'UpdateID']:
metadata[camel_to_underscore(tag)] = int(response[tag])
return response, metadata |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:unique; 3, parameters; 3, 4; 4, identifier:seq; 5, block; 5, 6; 5, 10; 5, 26; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:cleaned; 9, list:[]; 10, for_statement; 10, 11; 10, 12; 10, 13; 11, identifier:each; 12, identifier:seq; 13, block; 13, 14; 14, if_statement; 14, 15; 14, 18; 15, comparison_operator:not; 15, 16; 15, 17; 16, identifier:each; 17, identifier:cleaned; 18, block; 18, 19; 19, expression_statement; 19, 20; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:cleaned; 23, identifier:append; 24, argument_list; 24, 25; 25, identifier:each; 26, return_statement; 26, 27; 27, identifier:cleaned | def unique(seq):
cleaned = []
for each in seq:
if each not in cleaned:
cleaned.append(each)
return cleaned |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:build_schema_info; 3, parameters; 3, 4; 4, identifier:connection_alias; 5, block; 5, 6; 5, 13; 5, 17; 5, 127; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:connection; 9, call; 9, 10; 9, 11; 10, identifier:get_valid_connection; 11, argument_list; 11, 12; 12, identifier:connection_alias; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:ret; 16, list:[]; 17, with_statement; 17, 18; 17, 28; 18, with_clause; 18, 19; 19, with_item; 19, 20; 20, as_pattern; 20, 21; 20, 26; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:connection; 24, identifier:cursor; 25, argument_list; 26, as_pattern_target; 26, 27; 27, identifier:cursor; 28, block; 28, 29; 28, 45; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:tables_to_introspect; 32, call; 32, 33; 32, 38; 33, attribute; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:connection; 36, identifier:introspection; 37, identifier:table_names; 38, argument_list; 38, 39; 38, 40; 39, identifier:cursor; 40, keyword_argument; 40, 41; 40, 42; 41, identifier:include_views; 42, call; 42, 43; 42, 44; 43, identifier:_include_views; 44, argument_list; 45, for_statement; 45, 46; 45, 47; 45, 48; 46, identifier:table_name; 47, identifier:tables_to_introspect; 48, block; 48, 49; 48, 57; 48, 61; 48, 73; 48, 118; 49, if_statement; 49, 50; 49, 55; 50, not_operator; 50, 51; 51, call; 51, 52; 51, 53; 52, identifier:_include_table; 53, argument_list; 53, 54; 54, identifier:table_name; 55, block; 55, 56; 56, continue_statement; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:td; 60, list:[]; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:table_description; 64, call; 64, 65; 64, 70; 65, attribute; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:connection; 68, identifier:introspection; 69, identifier:get_table_description; 70, argument_list; 70, 71; 70, 72; 71, identifier:cursor; 72, identifier:table_name; 73, for_statement; 73, 74; 73, 75; 73, 76; 74, identifier:row; 75, identifier:table_description; 76, block; 76, 77; 76, 83; 76, 109; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:column_name; 80, subscript; 80, 81; 80, 82; 81, identifier:row; 82, integer:0; 83, try_statement; 83, 84; 83, 99; 84, block; 84, 85; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:field_type; 88, call; 88, 89; 88, 94; 89, attribute; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:connection; 92, identifier:introspection; 93, identifier:get_field_type; 94, argument_list; 94, 95; 94, 98; 95, subscript; 95, 96; 95, 97; 96, identifier:row; 97, integer:1; 98, identifier:row; 99, except_clause; 99, 100; 99, 104; 100, as_pattern; 100, 101; 100, 102; 101, identifier:KeyError; 102, as_pattern_target; 102, 103; 103, identifier:e; 104, block; 104, 105; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:field_type; 108, string:'Unknown'; 109, expression_statement; 109, 110; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:td; 113, identifier:append; 114, argument_list; 114, 115; 115, tuple; 115, 116; 115, 117; 116, identifier:column_name; 117, identifier:field_type; 118, expression_statement; 118, 119; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:ret; 122, identifier:append; 123, argument_list; 123, 124; 124, tuple; 124, 125; 124, 126; 125, identifier:table_name; 126, identifier:td; 127, return_statement; 127, 128; 128, identifier:ret | def build_schema_info(connection_alias):
connection = get_valid_connection(connection_alias)
ret = []
with connection.cursor() as cursor:
tables_to_introspect = connection.introspection.table_names(cursor, include_views=_include_views())
for table_name in tables_to_introspect:
if not _include_table(table_name):
continue
td = []
table_description = connection.introspection.get_table_description(cursor, table_name)
for row in table_description:
column_name = row[0]
try:
field_type = connection.introspection.get_field_type(row[1], row)
except KeyError as e:
field_type = 'Unknown'
td.append((column_name, field_type))
ret.append((table_name, td))
return ret |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:fetchThreads; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:self; 5, identifier:thread_location; 6, default_parameter; 6, 7; 6, 8; 7, identifier:before; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:after; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:limit; 14, None; 15, block; 15, 16; 15, 20; 15, 24; 15, 106; 15, 154; 15, 170; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:threads; 19, list:[]; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:last_thread_timestamp; 23, None; 24, while_statement; 24, 25; 24, 26; 25, True; 26, block; 26, 27; 26, 38; 26, 52; 26, 71; 26, 80; 27, if_statement; 27, 28; 27, 36; 28, boolean_operator:and; 28, 29; 28, 30; 29, identifier:limit; 30, comparison_operator:>=; 30, 31; 30, 35; 31, call; 31, 32; 31, 33; 32, identifier:len; 33, argument_list; 33, 34; 34, identifier:threads; 35, identifier:limit; 36, block; 36, 37; 37, break_statement; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:candidates; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:fetchThreadList; 45, argument_list; 45, 46; 45, 49; 46, keyword_argument; 46, 47; 46, 48; 47, identifier:before; 48, identifier:last_thread_timestamp; 49, keyword_argument; 49, 50; 49, 51; 50, identifier:thread_location; 51, identifier:thread_location; 52, if_statement; 52, 53; 52, 59; 52, 68; 53, comparison_operator:>; 53, 54; 53, 58; 54, call; 54, 55; 54, 56; 55, identifier:len; 56, argument_list; 56, 57; 57, identifier:candidates; 58, integer:1; 59, block; 59, 60; 60, expression_statement; 60, 61; 61, augmented_assignment:+=; 61, 62; 61, 63; 62, identifier:threads; 63, subscript; 63, 64; 63, 65; 64, identifier:candidates; 65, slice; 65, 66; 65, 67; 66, integer:1; 67, colon; 68, else_clause; 68, 69; 69, block; 69, 70; 70, break_statement; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:last_thread_timestamp; 74, attribute; 74, 75; 74, 79; 75, subscript; 75, 76; 75, 77; 76, identifier:threads; 77, unary_operator:-; 77, 78; 78, integer:1; 79, identifier:last_message_timestamp; 80, if_statement; 80, 81; 80, 104; 81, boolean_operator:or; 81, 82; 81, 93; 82, parenthesized_expression; 82, 83; 83, boolean_operator:and; 83, 84; 83, 87; 84, comparison_operator:is; 84, 85; 84, 86; 85, identifier:before; 86, None; 87, comparison_operator:>; 87, 88; 87, 92; 88, call; 88, 89; 88, 90; 89, identifier:int; 90, argument_list; 90, 91; 91, identifier:last_thread_timestamp; 92, identifier:before; 93, parenthesized_expression; 93, 94; 94, boolean_operator:and; 94, 95; 94, 98; 95, comparison_operator:is; 95, 96; 95, 97; 96, identifier:after; 97, None; 98, comparison_operator:<; 98, 99; 98, 103; 99, call; 99, 100; 99, 101; 100, identifier:int; 101, argument_list; 101, 102; 102, identifier:last_thread_timestamp; 103, identifier:after; 104, block; 104, 105; 105, break_statement; 106, if_statement; 106, 107; 106, 114; 107, boolean_operator:or; 107, 108; 107, 111; 108, comparison_operator:is; 108, 109; 108, 110; 109, identifier:before; 110, None; 111, comparison_operator:is; 111, 112; 111, 113; 112, identifier:after; 113, None; 114, block; 114, 115; 115, for_statement; 115, 116; 115, 117; 115, 118; 116, identifier:t; 117, identifier:threads; 118, block; 118, 119; 118, 128; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:last_message_timestamp; 122, call; 122, 123; 122, 124; 123, identifier:int; 124, argument_list; 124, 125; 125, attribute; 125, 126; 125, 127; 126, identifier:t; 127, identifier:last_message_timestamp; 128, if_statement; 128, 129; 128, 146; 129, boolean_operator:or; 129, 130; 129, 138; 130, parenthesized_expression; 130, 131; 131, boolean_operator:and; 131, 132; 131, 135; 132, comparison_operator:is; 132, 133; 132, 134; 133, identifier:before; 134, None; 135, comparison_operator:>; 135, 136; 135, 137; 136, identifier:last_message_timestamp; 137, identifier:before; 138, parenthesized_expression; 138, 139; 139, boolean_operator:and; 139, 140; 139, 143; 140, comparison_operator:is; 140, 141; 140, 142; 141, identifier:after; 142, None; 143, comparison_operator:<; 143, 144; 143, 145; 144, identifier:last_message_timestamp; 145, identifier:after; 146, block; 146, 147; 147, expression_statement; 147, 148; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:threads; 151, identifier:remove; 152, argument_list; 152, 153; 153, identifier:t; 154, if_statement; 154, 155; 154, 163; 155, boolean_operator:and; 155, 156; 155, 157; 156, identifier:limit; 157, comparison_operator:>; 157, 158; 157, 162; 158, call; 158, 159; 158, 160; 159, identifier:len; 160, argument_list; 160, 161; 161, identifier:threads; 162, identifier:limit; 163, block; 163, 164; 164, return_statement; 164, 165; 165, subscript; 165, 166; 165, 167; 166, identifier:threads; 167, slice; 167, 168; 167, 169; 168, colon; 169, identifier:limit; 170, return_statement; 170, 171; 171, identifier:threads | def fetchThreads(self, thread_location, before=None, after=None, limit=None):
threads = []
last_thread_timestamp = None
while True:
if limit and len(threads) >= limit:
break
candidates = self.fetchThreadList(
before=last_thread_timestamp, thread_location=thread_location
)
if len(candidates) > 1:
threads += candidates[1:]
else:
break
last_thread_timestamp = threads[-1].last_message_timestamp
if (before is not None and int(last_thread_timestamp) > before) or (
after is not None and int(last_thread_timestamp) < after
):
break
if before is not None or after is not None:
for t in threads:
last_message_timestamp = int(t.last_message_timestamp)
if (before is not None and last_message_timestamp > before) or (
after is not None and last_message_timestamp < after
):
threads.remove(t)
if limit and len(threads) > limit:
return threads[:limit]
return threads |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:_get_key_value; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:key; 6, default_parameter; 6, 7; 6, 8; 7, identifier:is_hll; 8, False; 9, block; 9, 10; 9, 12; 10, expression_statement; 10, 11; 11, string:'''
Returns the proper key value for the stats
@param key: the redis key
@param is_hll: the key is a HyperLogLog, else is a sorted set
'''; 12, if_statement; 12, 13; 12, 14; 12, 25; 13, identifier:is_hll; 14, block; 14, 15; 15, return_statement; 15, 16; 16, call; 16, 17; 16, 22; 17, attribute; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:redis_conn; 21, identifier:execute_command; 22, argument_list; 22, 23; 22, 24; 23, string:"PFCOUNT"; 24, identifier:key; 25, else_clause; 25, 26; 26, block; 26, 27; 27, return_statement; 27, 28; 28, call; 28, 29; 28, 34; 29, attribute; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:redis_conn; 33, identifier:zcard; 34, argument_list; 34, 35; 35, identifier:key | def _get_key_value(self, key, is_hll=False):
'''
Returns the proper key value for the stats
@param key: the redis key
@param is_hll: the key is a HyperLogLog, else is a sorted set
'''
if is_hll:
return self.redis_conn.execute_command("PFCOUNT", key)
else:
return self.redis_conn.zcard(key) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_get_bin; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:key; 6, block; 6, 7; 6, 9; 6, 13; 6, 62; 7, expression_statement; 7, 8; 8, string:'''
Returns a binned dictionary based on redis zscore
@return: The sorted dict
'''; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:sortedDict; 12, dictionary; 13, for_statement; 13, 14; 13, 15; 13, 23; 14, identifier:item; 15, call; 15, 16; 15, 21; 16, attribute; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:redis_conn; 20, identifier:zscan_iter; 21, argument_list; 21, 22; 22, identifier:key; 23, block; 23, 24; 23, 35; 23, 42; 23, 53; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:my_item; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:ujson; 30, identifier:loads; 31, argument_list; 31, 32; 32, subscript; 32, 33; 32, 34; 33, identifier:item; 34, integer:0; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:my_score; 38, unary_operator:-; 38, 39; 39, subscript; 39, 40; 39, 41; 40, identifier:item; 41, integer:1; 42, if_statement; 42, 43; 42, 46; 43, comparison_operator:not; 43, 44; 43, 45; 44, identifier:my_score; 45, identifier:sortedDict; 46, block; 46, 47; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 52; 49, subscript; 49, 50; 49, 51; 50, identifier:sortedDict; 51, identifier:my_score; 52, list:[]; 53, expression_statement; 53, 54; 54, call; 54, 55; 54, 60; 55, attribute; 55, 56; 55, 59; 56, subscript; 56, 57; 56, 58; 57, identifier:sortedDict; 58, identifier:my_score; 59, identifier:append; 60, argument_list; 60, 61; 61, identifier:my_item; 62, return_statement; 62, 63; 63, identifier:sortedDict | def _get_bin(self, key):
'''
Returns a binned dictionary based on redis zscore
@return: The sorted dict
'''
sortedDict = {}
for item in self.redis_conn.zscan_iter(key):
my_item = ujson.loads(item[0])
my_score = -item[1]
if my_score not in sortedDict:
sortedDict[my_score] = []
sortedDict[my_score].append(my_item)
return sortedDict |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_is_viable_phone_number; 3, parameters; 3, 4; 4, identifier:number; 5, block; 5, 6; 5, 16; 5, 24; 6, if_statement; 6, 7; 6, 13; 7, comparison_operator:<; 7, 8; 7, 12; 8, call; 8, 9; 8, 10; 9, identifier:len; 10, argument_list; 10, 11; 11, identifier:number; 12, identifier:_MIN_LENGTH_FOR_NSN; 13, block; 13, 14; 14, return_statement; 14, 15; 15, False; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:match; 19, call; 19, 20; 19, 21; 20, identifier:fullmatch; 21, argument_list; 21, 22; 21, 23; 22, identifier:_VALID_PHONE_NUMBER_PATTERN; 23, identifier:number; 24, return_statement; 24, 25; 25, call; 25, 26; 25, 27; 26, identifier:bool; 27, argument_list; 27, 28; 28, identifier:match | def _is_viable_phone_number(number):
if len(number) < _MIN_LENGTH_FOR_NSN:
return False
match = fullmatch(_VALID_PHONE_NUMBER_PATTERN, number)
return bool(match) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:__encoded_params_for_signature; 3, parameters; 3, 4; 3, 5; 4, identifier:cls; 5, identifier:params; 6, block; 6, 7; 6, 109; 7, function_definition; 7, 8; 7, 9; 7, 11; 8, function_name:encoded_pairs; 9, parameters; 9, 10; 10, identifier:params; 11, block; 11, 12; 12, for_statement; 12, 13; 12, 16; 12, 22; 13, pattern_list; 13, 14; 13, 15; 14, identifier:k; 15, identifier:v; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:six; 19, identifier:iteritems; 20, argument_list; 20, 21; 21, identifier:params; 22, block; 22, 23; 22, 29; 22, 62; 22, 81; 22, 94; 23, if_statement; 23, 24; 23, 27; 24, comparison_operator:==; 24, 25; 24, 26; 25, identifier:k; 26, string:'hmac'; 27, block; 27, 28; 28, continue_statement; 29, if_statement; 29, 30; 29, 36; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:k; 33, identifier:endswith; 34, argument_list; 34, 35; 35, string:'[]'; 36, block; 36, 37; 36, 46; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:k; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:k; 43, identifier:rstrip; 44, argument_list; 44, 45; 45, string:'[]'; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:v; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:json; 52, identifier:dumps; 53, argument_list; 53, 54; 54, call; 54, 55; 54, 56; 55, identifier:list; 56, argument_list; 56, 57; 57, call; 57, 58; 57, 59; 58, identifier:map; 59, argument_list; 59, 60; 59, 61; 60, identifier:str; 61, identifier:v; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:k; 65, call; 65, 66; 65, 78; 66, attribute; 66, 67; 66, 77; 67, call; 67, 68; 67, 74; 68, attribute; 68, 69; 68, 73; 69, call; 69, 70; 69, 71; 70, identifier:str; 71, argument_list; 71, 72; 72, identifier:k; 73, identifier:replace; 74, argument_list; 74, 75; 74, 76; 75, string:"%"; 76, string:"%25"; 77, identifier:replace; 78, argument_list; 78, 79; 78, 80; 79, string:"="; 80, string:"%3D"; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:v; 84, call; 84, 85; 84, 91; 85, attribute; 85, 86; 85, 90; 86, call; 86, 87; 86, 88; 87, identifier:str; 88, argument_list; 88, 89; 89, identifier:v; 90, identifier:replace; 91, argument_list; 91, 92; 91, 93; 92, string:"%"; 93, string:"%25"; 94, expression_statement; 94, 95; 95, yield; 95, 96; 96, call; 96, 97; 96, 106; 97, attribute; 97, 98; 97, 105; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, string:'{0}={1}'; 101, identifier:format; 102, argument_list; 102, 103; 102, 104; 103, identifier:k; 104, identifier:v; 105, identifier:replace; 106, argument_list; 106, 107; 106, 108; 107, string:"&"; 108, string:"%26"; 109, return_statement; 109, 110; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, string:"&"; 113, identifier:join; 114, argument_list; 114, 115; 115, call; 115, 116; 115, 117; 116, identifier:sorted; 117, argument_list; 117, 118; 118, call; 118, 119; 118, 120; 119, identifier:encoded_pairs; 120, argument_list; 120, 121; 121, identifier:params | def __encoded_params_for_signature(cls, params):
def encoded_pairs(params):
for k, v in six.iteritems(params):
if k == 'hmac':
continue
if k.endswith('[]'):
k = k.rstrip('[]')
v = json.dumps(list(map(str, v)))
k = str(k).replace("%", "%25").replace("=", "%3D")
v = str(v).replace("%", "%25")
yield '{0}={1}'.format(k, v).replace("&", "%26")
return "&".join(sorted(encoded_pairs(params))) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:group_keys; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 6, for_statement; 6, 7; 6, 8; 6, 20; 7, identifier:key; 8, call; 8, 9; 8, 10; 9, identifier:sorted; 10, argument_list; 10, 11; 11, call; 11, 12; 11, 13; 12, identifier:listdir; 13, argument_list; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:_store; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:_path; 20, block; 20, 21; 20, 29; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:path; 24, binary_operator:+; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:_key_prefix; 28, identifier:key; 29, if_statement; 29, 30; 29, 37; 30, call; 30, 31; 30, 32; 31, identifier:contains_group; 32, argument_list; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:_store; 36, identifier:path; 37, block; 37, 38; 38, expression_statement; 38, 39; 39, yield; 39, 40; 40, identifier:key | def group_keys(self):
for key in sorted(listdir(self._store, self._path)):
path = self._key_prefix + key
if contains_group(self._store, path):
yield key |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:array_keys; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 6, for_statement; 6, 7; 6, 8; 6, 20; 7, identifier:key; 8, call; 8, 9; 8, 10; 9, identifier:sorted; 10, argument_list; 10, 11; 11, call; 11, 12; 11, 13; 12, identifier:listdir; 13, argument_list; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:_store; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:_path; 20, block; 20, 21; 20, 29; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:path; 24, binary_operator:+; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:_key_prefix; 28, identifier:key; 29, if_statement; 29, 30; 29, 37; 30, call; 30, 31; 30, 32; 31, identifier:contains_array; 32, argument_list; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:_store; 36, identifier:path; 37, block; 37, 38; 38, expression_statement; 38, 39; 39, yield; 39, 40; 40, identifier:key | def array_keys(self):
for key in sorted(listdir(self._store, self._path)):
path = self._key_prefix + key
if contains_array(self._store, path):
yield key |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 36; 2, function_name:init_array; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 3, 24; 3, 27; 3, 30; 3, 33; 4, identifier:store; 5, identifier:shape; 6, default_parameter; 6, 7; 6, 8; 7, identifier:chunks; 8, True; 9, default_parameter; 9, 10; 9, 11; 10, identifier:dtype; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:compressor; 14, string:'default'; 15, default_parameter; 15, 16; 15, 17; 16, identifier:fill_value; 17, None; 18, default_parameter; 18, 19; 18, 20; 19, identifier:order; 20, string:'C'; 21, default_parameter; 21, 22; 21, 23; 22, identifier:overwrite; 23, False; 24, default_parameter; 24, 25; 24, 26; 25, identifier:path; 26, None; 27, default_parameter; 27, 28; 27, 29; 28, identifier:chunk_store; 29, None; 30, default_parameter; 30, 31; 30, 32; 31, identifier:filters; 32, None; 33, default_parameter; 33, 34; 33, 35; 34, identifier:object_codec; 35, None; 36, block; 36, 37; 36, 44; 36, 58; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:path; 40, call; 40, 41; 40, 42; 41, identifier:normalize_storage_path; 42, argument_list; 42, 43; 43, identifier:path; 44, expression_statement; 44, 45; 45, call; 45, 46; 45, 47; 46, identifier:_require_parent_group; 47, argument_list; 47, 48; 47, 49; 47, 52; 47, 55; 48, identifier:path; 49, keyword_argument; 49, 50; 49, 51; 50, identifier:store; 51, identifier:store; 52, keyword_argument; 52, 53; 52, 54; 53, identifier:chunk_store; 54, identifier:chunk_store; 55, keyword_argument; 55, 56; 55, 57; 56, identifier:overwrite; 57, identifier:overwrite; 58, expression_statement; 58, 59; 59, call; 59, 60; 59, 61; 60, identifier:_init_array_metadata; 61, argument_list; 61, 62; 61, 63; 61, 66; 61, 69; 61, 72; 61, 75; 61, 78; 61, 81; 61, 84; 61, 87; 61, 90; 61, 93; 62, identifier:store; 63, keyword_argument; 63, 64; 63, 65; 64, identifier:shape; 65, identifier:shape; 66, keyword_argument; 66, 67; 66, 68; 67, identifier:chunks; 68, identifier:chunks; 69, keyword_argument; 69, 70; 69, 71; 70, identifier:dtype; 71, identifier:dtype; 72, keyword_argument; 72, 73; 72, 74; 73, identifier:compressor; 74, identifier:compressor; 75, keyword_argument; 75, 76; 75, 77; 76, identifier:fill_value; 77, identifier:fill_value; 78, keyword_argument; 78, 79; 78, 80; 79, identifier:order; 80, identifier:order; 81, keyword_argument; 81, 82; 81, 83; 82, identifier:overwrite; 83, identifier:overwrite; 84, keyword_argument; 84, 85; 84, 86; 85, identifier:path; 86, identifier:path; 87, keyword_argument; 87, 88; 87, 89; 88, identifier:chunk_store; 89, identifier:chunk_store; 90, keyword_argument; 90, 91; 90, 92; 91, identifier:filters; 92, identifier:filters; 93, keyword_argument; 93, 94; 93, 95; 94, identifier:object_codec; 95, identifier:object_codec | def init_array(store, shape, chunks=True, dtype=None, compressor='default',
fill_value=None, order='C', overwrite=False, path=None,
chunk_store=None, filters=None, object_codec=None):
path = normalize_storage_path(path)
_require_parent_group(path, store=store, chunk_store=chunk_store, overwrite=overwrite)
_init_array_metadata(store, shape=shape, chunks=chunks, dtype=dtype,
compressor=compressor, fill_value=fill_value,
order=order, overwrite=overwrite, path=path,
chunk_store=chunk_store, filters=filters,
object_codec=object_codec) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 26; 2, function_name:view; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:shape; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:chunks; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:dtype; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:fill_value; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:filters; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:read_only; 22, None; 23, default_parameter; 23, 24; 23, 25; 24, identifier:synchronizer; 25, None; 26, block; 26, 27; 26, 33; 26, 39; 26, 45; 26, 56; 26, 67; 26, 91; 26, 97; 26, 125; 26, 151; 26, 173; 26, 184; 26, 195; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:store; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:_store; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:chunk_store; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:_chunk_store; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:path; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:_path; 45, if_statement; 45, 46; 45, 49; 46, comparison_operator:is; 46, 47; 46, 48; 47, identifier:read_only; 48, None; 49, block; 49, 50; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:read_only; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:_read_only; 56, if_statement; 56, 57; 56, 60; 57, comparison_operator:is; 57, 58; 57, 59; 58, identifier:synchronizer; 59, None; 60, block; 60, 61; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:synchronizer; 64, attribute; 64, 65; 64, 66; 65, identifier:self; 66, identifier:_synchronizer; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:a; 70, call; 70, 71; 70, 72; 71, identifier:Array; 72, argument_list; 72, 73; 72, 76; 72, 79; 72, 82; 72, 85; 72, 88; 73, keyword_argument; 73, 74; 73, 75; 74, identifier:store; 75, identifier:store; 76, keyword_argument; 76, 77; 76, 78; 77, identifier:path; 78, identifier:path; 79, keyword_argument; 79, 80; 79, 81; 80, identifier:chunk_store; 81, identifier:chunk_store; 82, keyword_argument; 82, 83; 82, 84; 83, identifier:read_only; 84, identifier:read_only; 85, keyword_argument; 85, 86; 85, 87; 86, identifier:synchronizer; 87, identifier:synchronizer; 88, keyword_argument; 88, 89; 88, 90; 89, identifier:cache_metadata; 90, True; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:a; 95, identifier:_is_view; 96, True; 97, if_statement; 97, 98; 97, 101; 97, 108; 98, comparison_operator:is; 98, 99; 98, 100; 99, identifier:dtype; 100, None; 101, block; 101, 102; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:dtype; 105, attribute; 105, 106; 105, 107; 106, identifier:self; 107, identifier:_dtype; 108, else_clause; 108, 109; 109, block; 109, 110; 109, 119; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:dtype; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:np; 116, identifier:dtype; 117, argument_list; 117, 118; 118, identifier:dtype; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:a; 123, identifier:_dtype; 124, identifier:dtype; 125, if_statement; 125, 126; 125, 129; 125, 136; 126, comparison_operator:is; 126, 127; 126, 128; 127, identifier:shape; 128, None; 129, block; 129, 130; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 133; 132, identifier:shape; 133, attribute; 133, 134; 133, 135; 134, identifier:self; 135, identifier:_shape; 136, else_clause; 136, 137; 137, block; 137, 138; 137, 145; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:shape; 141, call; 141, 142; 141, 143; 142, identifier:normalize_shape; 143, argument_list; 143, 144; 144, identifier:shape; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:a; 149, identifier:_shape; 150, identifier:shape; 151, if_statement; 151, 152; 151, 155; 152, comparison_operator:is; 152, 153; 152, 154; 153, identifier:chunks; 154, None; 155, block; 155, 156; 155, 167; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 159; 158, identifier:chunks; 159, call; 159, 160; 159, 161; 160, identifier:normalize_chunks; 161, argument_list; 161, 162; 161, 163; 161, 164; 162, identifier:chunks; 163, identifier:shape; 164, attribute; 164, 165; 164, 166; 165, identifier:dtype; 166, identifier:itemsize; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:a; 171, identifier:_chunks; 172, identifier:chunks; 173, if_statement; 173, 174; 173, 177; 174, comparison_operator:is; 174, 175; 174, 176; 175, identifier:fill_value; 176, None; 177, block; 177, 178; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:a; 182, identifier:_fill_value; 183, identifier:fill_value; 184, if_statement; 184, 185; 184, 188; 185, comparison_operator:is; 185, 186; 185, 187; 186, identifier:filters; 187, None; 188, block; 188, 189; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:a; 193, identifier:_filters; 194, identifier:filters; 195, return_statement; 195, 196; 196, identifier:a | def view(self, shape=None, chunks=None, dtype=None,
fill_value=None, filters=None, read_only=None,
synchronizer=None):
store = self._store
chunk_store = self._chunk_store
path = self._path
if read_only is None:
read_only = self._read_only
if synchronizer is None:
synchronizer = self._synchronizer
a = Array(store=store, path=path, chunk_store=chunk_store, read_only=read_only,
synchronizer=synchronizer, cache_metadata=True)
a._is_view = True
if dtype is None:
dtype = self._dtype
else:
dtype = np.dtype(dtype)
a._dtype = dtype
if shape is None:
shape = self._shape
else:
shape = normalize_shape(shape)
a._shape = shape
if chunks is not None:
chunks = normalize_chunks(chunks, shape, dtype.itemsize)
a._chunks = chunks
if fill_value is not None:
a._fill_value = fill_value
if filters is not None:
a._filters = filters
return a |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:image_field_data; 3, parameters; 3, 4; 3, 5; 4, identifier:request; 5, default_parameter; 5, 6; 5, 7; 6, identifier:include_empty_option; 7, False; 8, block; 8, 9; 8, 37; 8, 51; 8, 61; 8, 93; 8, 105; 9, try_statement; 9, 10; 9, 23; 10, block; 10, 11; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:images; 14, call; 14, 15; 14, 16; 15, identifier:get_available_images; 16, argument_list; 16, 17; 16, 18; 17, identifier:request; 18, attribute; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:request; 21, identifier:user; 22, identifier:project_id; 23, except_clause; 23, 24; 23, 25; 24, identifier:Exception; 25, block; 25, 26; 26, expression_statement; 26, 27; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:exceptions; 30, identifier:handle; 31, argument_list; 31, 32; 31, 33; 32, identifier:request; 33, call; 33, 34; 33, 35; 34, identifier:_; 35, argument_list; 35, 36; 36, string:'Unable to retrieve images'; 37, expression_statement; 37, 38; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:images; 41, identifier:sort; 42, argument_list; 42, 43; 43, keyword_argument; 43, 44; 43, 45; 44, identifier:key; 45, lambda; 45, 46; 45, 48; 46, lambda_parameters; 46, 47; 47, identifier:c; 48, attribute; 48, 49; 48, 50; 49, identifier:c; 50, identifier:name; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:images_list; 54, list:[('', _('Select Image'))]; 54, 55; 55, tuple; 55, 56; 55, 57; 56, string:''; 57, call; 57, 58; 57, 59; 58, identifier:_; 59, argument_list; 59, 60; 60, string:'Select Image'; 61, for_statement; 61, 62; 61, 63; 61, 64; 62, identifier:image; 63, identifier:images; 64, block; 64, 65; 64, 82; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:image_label; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, string:u"{} ({})"; 71, identifier:format; 72, argument_list; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:image; 75, identifier:name; 76, call; 76, 77; 76, 78; 77, identifier:filesizeformat; 78, argument_list; 78, 79; 79, attribute; 79, 80; 79, 81; 80, identifier:image; 81, identifier:size; 82, expression_statement; 82, 83; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:images_list; 86, identifier:append; 87, argument_list; 87, 88; 88, tuple; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:image; 91, identifier:id; 92, identifier:image_label; 93, if_statement; 93, 94; 93, 96; 94, not_operator; 94, 95; 95, identifier:images; 96, block; 96, 97; 97, return_statement; 97, 98; 98, list:[("", _("No images available")), ]; 98, 99; 99, tuple; 99, 100; 99, 101; 100, string:""; 101, call; 101, 102; 101, 103; 102, identifier:_; 103, argument_list; 103, 104; 104, string:"No images available"; 105, return_statement; 105, 106; 106, identifier:images_list | def image_field_data(request, include_empty_option=False):
try:
images = get_available_images(request, request.user.project_id)
except Exception:
exceptions.handle(request, _('Unable to retrieve images'))
images.sort(key=lambda c: c.name)
images_list = [('', _('Select Image'))]
for image in images:
image_label = u"{} ({})".format(image.name, filesizeformat(image.size))
images_list.append((image.id, image_label))
if not images:
return [("", _("No images available")), ]
return images_list |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:sort_flavor_list; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:request; 5, identifier:flavors; 6, default_parameter; 6, 7; 6, 8; 7, identifier:with_menu_label; 8, True; 9, block; 9, 10; 9, 43; 10, function_definition; 10, 11; 10, 12; 10, 15; 11, function_name:get_key; 12, parameters; 12, 13; 12, 14; 13, identifier:flavor; 14, identifier:sort_key; 15, block; 15, 16; 16, try_statement; 16, 17; 16, 24; 17, block; 17, 18; 18, return_statement; 18, 19; 19, call; 19, 20; 19, 21; 20, identifier:getattr; 21, argument_list; 21, 22; 21, 23; 22, identifier:flavor; 23, identifier:sort_key; 24, except_clause; 24, 25; 24, 26; 25, identifier:AttributeError; 26, block; 26, 27; 26, 37; 27, expression_statement; 27, 28; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:LOG; 31, identifier:warning; 32, argument_list; 32, 33; 32, 36; 33, concatenated_string; 33, 34; 33, 35; 34, string:'Could not find sort key "%s". Using the default '; 35, string:'"ram" instead.'; 36, identifier:sort_key; 37, return_statement; 37, 38; 38, call; 38, 39; 38, 40; 39, identifier:getattr; 40, argument_list; 40, 41; 40, 42; 41, identifier:flavor; 42, string:'ram'; 43, try_statement; 43, 44; 43, 143; 44, block; 44, 45; 44, 54; 44, 64; 44, 74; 44, 98; 44, 141; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:flavor_sort; 48, call; 48, 49; 48, 50; 49, identifier:getattr; 50, argument_list; 50, 51; 50, 52; 50, 53; 51, identifier:settings; 52, string:'CREATE_INSTANCE_FLAVOR_SORT'; 53, dictionary; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:sort_key; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:flavor_sort; 60, identifier:get; 61, argument_list; 61, 62; 61, 63; 62, string:'key'; 63, string:'ram'; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:rev; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:flavor_sort; 70, identifier:get; 71, argument_list; 71, 72; 71, 73; 72, string:'reverse'; 73, False; 74, if_statement; 74, 75; 74, 80; 74, 92; 75, not_operator; 75, 76; 76, call; 76, 77; 76, 78; 77, identifier:callable; 78, argument_list; 78, 79; 79, identifier:sort_key; 80, block; 80, 81; 81, function_definition; 81, 82; 81, 83; 81, 85; 82, function_name:key; 83, parameters; 83, 84; 84, identifier:flavor; 85, block; 85, 86; 86, return_statement; 86, 87; 87, call; 87, 88; 87, 89; 88, identifier:get_key; 89, argument_list; 89, 90; 89, 91; 90, identifier:flavor; 91, identifier:sort_key; 92, else_clause; 92, 93; 93, block; 93, 94; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:key; 97, identifier:sort_key; 98, if_statement; 98, 99; 98, 100; 98, 126; 99, identifier:with_menu_label; 100, block; 100, 101; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:flavor_list; 104, list_comprehension; 104, 105; 104, 114; 105, tuple; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:flavor; 108, identifier:id; 109, binary_operator:%; 109, 110; 109, 111; 110, string:'%s'; 111, attribute; 111, 112; 111, 113; 112, identifier:flavor; 113, identifier:name; 114, for_in_clause; 114, 115; 114, 116; 115, identifier:flavor; 116, call; 116, 117; 116, 118; 117, identifier:sorted; 118, argument_list; 118, 119; 118, 120; 118, 123; 119, identifier:flavors; 120, keyword_argument; 120, 121; 120, 122; 121, identifier:key; 122, identifier:key; 123, keyword_argument; 123, 124; 123, 125; 124, identifier:reverse; 125, identifier:rev; 126, else_clause; 126, 127; 127, block; 127, 128; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:flavor_list; 131, call; 131, 132; 131, 133; 132, identifier:sorted; 133, argument_list; 133, 134; 133, 135; 133, 138; 134, identifier:flavors; 135, keyword_argument; 135, 136; 135, 137; 136, identifier:key; 137, identifier:key; 138, keyword_argument; 138, 139; 138, 140; 139, identifier:reverse; 140, identifier:rev; 141, return_statement; 141, 142; 142, identifier:flavor_list; 143, except_clause; 143, 144; 143, 145; 144, identifier:Exception; 145, block; 145, 146; 145, 157; 146, expression_statement; 146, 147; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:exceptions; 150, identifier:handle; 151, argument_list; 151, 152; 151, 153; 152, identifier:request; 153, call; 153, 154; 153, 155; 154, identifier:_; 155, argument_list; 155, 156; 156, string:'Unable to sort instance flavors.'; 157, return_statement; 157, 158; 158, list:[] | def sort_flavor_list(request, flavors, with_menu_label=True):
def get_key(flavor, sort_key):
try:
return getattr(flavor, sort_key)
except AttributeError:
LOG.warning('Could not find sort key "%s". Using the default '
'"ram" instead.', sort_key)
return getattr(flavor, 'ram')
try:
flavor_sort = getattr(settings, 'CREATE_INSTANCE_FLAVOR_SORT', {})
sort_key = flavor_sort.get('key', 'ram')
rev = flavor_sort.get('reverse', False)
if not callable(sort_key):
def key(flavor):
return get_key(flavor, sort_key)
else:
key = sort_key
if with_menu_label:
flavor_list = [(flavor.id, '%s' % flavor.name)
for flavor in sorted(flavors, key=key, reverse=rev)]
else:
flavor_list = sorted(flavors, key=key, reverse=rev)
return flavor_list
except Exception:
exceptions.handle(request,
_('Unable to sort instance flavors.'))
return [] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 25; 2, function_name:image_list_detailed; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 4, identifier:request; 5, default_parameter; 5, 6; 5, 7; 6, identifier:marker; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:sort_dir; 10, string:'desc'; 11, default_parameter; 11, 12; 11, 13; 12, identifier:sort_key; 13, string:'created_at'; 14, default_parameter; 14, 15; 14, 16; 15, identifier:filters; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:paginate; 19, False; 20, default_parameter; 20, 21; 20, 22; 21, identifier:reversed_order; 22, False; 23, dictionary_splat_pattern; 23, 24; 24, identifier:kwargs; 25, block; 25, 26; 25, 35; 25, 44; 25, 59; 25, 66; 25, 75; 25, 84; 25, 90; 25, 113; 25, 134; 25, 138; 25, 142; 25, 249; 25, 253; 25, 267; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:limit; 29, call; 29, 30; 29, 31; 30, identifier:getattr; 31, argument_list; 31, 32; 31, 33; 31, 34; 32, identifier:settings; 33, string:'API_RESULT_LIMIT'; 34, integer:1000; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:page_size; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:utils; 41, identifier:get_page_size; 42, argument_list; 42, 43; 43, identifier:request; 44, if_statement; 44, 45; 44, 46; 44, 53; 45, identifier:paginate; 46, block; 46, 47; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:request_size; 50, binary_operator:+; 50, 51; 50, 52; 51, identifier:page_size; 52, integer:1; 53, else_clause; 53, 54; 54, block; 54, 55; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:request_size; 58, identifier:limit; 59, expression_statement; 59, 60; 60, call; 60, 61; 60, 62; 61, identifier:_normalize_list_input; 62, argument_list; 62, 63; 62, 64; 63, identifier:filters; 64, dictionary_splat; 64, 65; 65, identifier:kwargs; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:kwargs; 69, dictionary; 69, 70; 70, pair; 70, 71; 70, 72; 71, string:'filters'; 72, boolean_operator:or; 72, 73; 72, 74; 73, identifier:filters; 74, dictionary; 75, if_statement; 75, 76; 75, 77; 76, identifier:marker; 77, block; 77, 78; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 83; 80, subscript; 80, 81; 80, 82; 81, identifier:kwargs; 82, string:'marker'; 83, identifier:marker; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 89; 86, subscript; 86, 87; 86, 88; 87, identifier:kwargs; 88, string:'sort_key'; 89, identifier:sort_key; 90, if_statement; 90, 91; 90, 93; 90, 100; 91, not_operator; 91, 92; 92, identifier:reversed_order; 93, block; 93, 94; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 99; 96, subscript; 96, 97; 96, 98; 97, identifier:kwargs; 98, string:'sort_dir'; 99, identifier:sort_dir; 100, else_clause; 100, 101; 101, block; 101, 102; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 107; 104, subscript; 104, 105; 104, 106; 105, identifier:kwargs; 106, string:'sort_dir'; 107, conditional_expression:if; 107, 108; 107, 109; 107, 112; 108, string:'desc'; 109, comparison_operator:==; 109, 110; 109, 111; 110, identifier:sort_dir; 111, string:'asc'; 112, string:'asc'; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:images_iter; 116, call; 116, 117; 116, 125; 117, attribute; 117, 118; 117, 124; 118, attribute; 118, 119; 118, 123; 119, call; 119, 120; 119, 121; 120, identifier:glanceclient; 121, argument_list; 121, 122; 122, identifier:request; 123, identifier:images; 124, identifier:list; 125, argument_list; 125, 126; 125, 129; 125, 132; 126, keyword_argument; 126, 127; 126, 128; 127, identifier:page_size; 128, identifier:request_size; 129, keyword_argument; 129, 130; 129, 131; 130, identifier:limit; 131, identifier:limit; 132, dictionary_splat; 132, 133; 133, identifier:kwargs; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:has_prev_data; 137, False; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:has_more_data; 141, False; 142, if_statement; 142, 143; 142, 144; 142, 240; 143, identifier:paginate; 144, block; 144, 145; 144, 158; 144, 207; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 148; 147, identifier:images; 148, call; 148, 149; 148, 150; 149, identifier:list; 150, argument_list; 150, 151; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:itertools; 154, identifier:islice; 155, argument_list; 155, 156; 155, 157; 156, identifier:images_iter; 157, identifier:request_size; 158, if_statement; 158, 159; 158, 165; 158, 187; 158, 198; 159, comparison_operator:>; 159, 160; 159, 164; 160, call; 160, 161; 160, 162; 161, identifier:len; 162, argument_list; 162, 163; 163, identifier:images; 164, identifier:page_size; 165, block; 165, 166; 165, 174; 165, 178; 166, expression_statement; 166, 167; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:images; 170, identifier:pop; 171, argument_list; 171, 172; 172, unary_operator:-; 172, 173; 173, integer:1; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 177; 176, identifier:has_more_data; 177, True; 178, if_statement; 178, 179; 178, 182; 179, comparison_operator:is; 179, 180; 179, 181; 180, identifier:marker; 181, None; 182, block; 182, 183; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 186; 185, identifier:has_prev_data; 186, True; 187, elif_clause; 187, 188; 187, 193; 188, boolean_operator:and; 188, 189; 188, 190; 189, identifier:reversed_order; 190, comparison_operator:is; 190, 191; 190, 192; 191, identifier:marker; 192, None; 193, block; 193, 194; 194, expression_statement; 194, 195; 195, assignment; 195, 196; 195, 197; 196, identifier:has_more_data; 197, True; 198, elif_clause; 198, 199; 198, 202; 199, comparison_operator:is; 199, 200; 199, 201; 200, identifier:marker; 201, None; 202, block; 202, 203; 203, expression_statement; 203, 204; 204, assignment; 204, 205; 204, 206; 205, identifier:has_prev_data; 206, True; 207, if_statement; 207, 208; 207, 209; 208, identifier:reversed_order; 209, block; 209, 210; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 213; 212, identifier:images; 213, call; 213, 214; 213, 215; 214, identifier:sorted; 215, argument_list; 215, 216; 215, 217; 215, 234; 216, identifier:images; 217, keyword_argument; 217, 218; 217, 219; 218, identifier:key; 219, lambda; 219, 220; 219, 222; 220, lambda_parameters; 220, 221; 221, identifier:image; 222, call; 222, 223; 222, 233; 223, attribute; 223, 224; 223, 232; 224, parenthesized_expression; 224, 225; 225, boolean_operator:or; 225, 226; 225, 231; 226, call; 226, 227; 226, 228; 227, identifier:getattr; 228, argument_list; 228, 229; 228, 230; 229, identifier:image; 230, identifier:sort_key; 231, string:''; 232, identifier:lower; 233, argument_list; 234, keyword_argument; 234, 235; 234, 236; 235, identifier:reverse; 236, parenthesized_expression; 236, 237; 237, comparison_operator:==; 237, 238; 237, 239; 238, identifier:sort_dir; 239, string:'desc'; 240, else_clause; 240, 241; 241, block; 241, 242; 242, expression_statement; 242, 243; 243, assignment; 243, 244; 243, 245; 244, identifier:images; 245, call; 245, 246; 245, 247; 246, identifier:list; 247, argument_list; 247, 248; 248, identifier:images_iter; 249, expression_statement; 249, 250; 250, assignment; 250, 251; 250, 252; 251, identifier:wrapped_images; 252, list:[]; 253, for_statement; 253, 254; 253, 255; 253, 256; 254, identifier:image; 255, identifier:images; 256, block; 256, 257; 257, expression_statement; 257, 258; 258, call; 258, 259; 258, 262; 259, attribute; 259, 260; 259, 261; 260, identifier:wrapped_images; 261, identifier:append; 262, argument_list; 262, 263; 263, call; 263, 264; 263, 265; 264, identifier:Image; 265, argument_list; 265, 266; 266, identifier:image; 267, return_statement; 267, 268; 268, expression_list; 268, 269; 268, 270; 268, 271; 269, identifier:wrapped_images; 270, identifier:has_more_data; 271, identifier:has_prev_data | def image_list_detailed(request, marker=None, sort_dir='desc',
sort_key='created_at', filters=None, paginate=False,
reversed_order=False, **kwargs):
limit = getattr(settings, 'API_RESULT_LIMIT', 1000)
page_size = utils.get_page_size(request)
if paginate:
request_size = page_size + 1
else:
request_size = limit
_normalize_list_input(filters, **kwargs)
kwargs = {'filters': filters or {}}
if marker:
kwargs['marker'] = marker
kwargs['sort_key'] = sort_key
if not reversed_order:
kwargs['sort_dir'] = sort_dir
else:
kwargs['sort_dir'] = 'desc' if sort_dir == 'asc' else 'asc'
images_iter = glanceclient(request).images.list(page_size=request_size,
limit=limit,
**kwargs)
has_prev_data = False
has_more_data = False
if paginate:
images = list(itertools.islice(images_iter, request_size))
if len(images) > page_size:
images.pop(-1)
has_more_data = True
if marker is not None:
has_prev_data = True
elif reversed_order and marker is not None:
has_more_data = True
elif marker is not None:
has_prev_data = True
if reversed_order:
images = sorted(images, key=lambda image:
(getattr(image, sort_key) or '').lower(),
reverse=(sort_dir == 'desc'))
else:
images = list(images_iter)
wrapped_images = []
for image in images:
wrapped_images.append(Image(image))
return wrapped_images, has_more_data, has_prev_data |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:metadefs_namespace_list; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:request; 5, default_parameter; 5, 6; 5, 7; 6, identifier:filters; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:sort_dir; 10, string:'asc'; 11, default_parameter; 11, 12; 11, 13; 12, identifier:sort_key; 13, string:'namespace'; 14, default_parameter; 14, 15; 14, 16; 15, identifier:marker; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:paginate; 19, False; 20, block; 20, 21; 20, 33; 20, 42; 20, 51; 20, 60; 20, 75; 20, 82; 20, 91; 20, 97; 20, 103; 20, 125; 20, 134; 20, 143; 20, 157; 20, 161; 20, 165; 20, 241; 20, 252; 21, if_statement; 21, 22; 21, 27; 22, comparison_operator:<; 22, 23; 22, 26; 23, call; 23, 24; 23, 25; 24, identifier:get_version; 25, argument_list; 26, integer:2; 27, block; 27, 28; 28, return_statement; 28, 29; 29, expression_list; 29, 30; 29, 31; 29, 32; 30, list:[]; 31, False; 32, False; 33, if_statement; 33, 34; 33, 37; 34, comparison_operator:is; 34, 35; 34, 36; 35, identifier:filters; 36, None; 37, block; 37, 38; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:filters; 41, dictionary; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:limit; 45, call; 45, 46; 45, 47; 46, identifier:getattr; 47, argument_list; 47, 48; 47, 49; 47, 50; 48, identifier:settings; 49, string:'API_RESULT_LIMIT'; 50, integer:1000; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:page_size; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:utils; 57, identifier:get_page_size; 58, argument_list; 58, 59; 59, identifier:request; 60, if_statement; 60, 61; 60, 62; 60, 69; 61, identifier:paginate; 62, block; 62, 63; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:request_size; 66, binary_operator:+; 66, 67; 66, 68; 67, identifier:page_size; 68, integer:1; 69, else_clause; 69, 70; 70, block; 70, 71; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:request_size; 74, identifier:limit; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:kwargs; 78, dictionary; 78, 79; 79, pair; 79, 80; 79, 81; 80, string:'filters'; 81, identifier:filters; 82, if_statement; 82, 83; 82, 84; 83, identifier:marker; 84, block; 84, 85; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 90; 87, subscript; 87, 88; 87, 89; 88, identifier:kwargs; 89, string:'marker'; 90, identifier:marker; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 96; 93, subscript; 93, 94; 93, 95; 94, identifier:kwargs; 95, string:'sort_dir'; 96, identifier:sort_dir; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 102; 99, subscript; 99, 100; 99, 101; 100, identifier:kwargs; 101, string:'sort_key'; 102, identifier:sort_key; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:namespaces_iter; 106, call; 106, 107; 106, 116; 107, attribute; 107, 108; 107, 115; 108, attribute; 108, 109; 108, 114; 109, call; 109, 110; 109, 111; 110, identifier:glanceclient; 111, argument_list; 111, 112; 111, 113; 112, identifier:request; 113, string:'2'; 114, identifier:metadefs_namespace; 115, identifier:list; 116, argument_list; 116, 117; 116, 120; 116, 123; 117, keyword_argument; 117, 118; 117, 119; 118, identifier:page_size; 119, identifier:request_size; 120, keyword_argument; 120, 121; 120, 122; 121, identifier:limit; 122, identifier:limit; 123, dictionary_splat; 123, 124; 124, identifier:kwargs; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:resource_types; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:filters; 131, identifier:get; 132, argument_list; 132, 133; 133, string:'resource_types'; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:properties_target; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:filters; 140, identifier:get; 141, argument_list; 141, 142; 142, string:'properties_target'; 143, if_statement; 143, 144; 143, 147; 144, boolean_operator:and; 144, 145; 144, 146; 145, identifier:resource_types; 146, identifier:properties_target; 147, block; 147, 148; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 151; 150, identifier:namespaces_iter; 151, call; 151, 152; 151, 153; 152, identifier:filter_properties_target; 153, argument_list; 153, 154; 153, 155; 153, 156; 154, identifier:namespaces_iter; 155, identifier:resource_types; 156, identifier:properties_target; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:has_prev_data; 160, False; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:has_more_data; 164, False; 165, if_statement; 165, 166; 165, 167; 165, 232; 166, identifier:paginate; 167, block; 167, 168; 167, 181; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:namespaces; 171, call; 171, 172; 171, 173; 172, identifier:list; 173, argument_list; 173, 174; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:itertools; 177, identifier:islice; 178, argument_list; 178, 179; 178, 180; 179, identifier:namespaces_iter; 180, identifier:request_size; 181, if_statement; 181, 182; 181, 188; 181, 210; 181, 223; 182, comparison_operator:>; 182, 183; 182, 187; 183, call; 183, 184; 183, 185; 184, identifier:len; 185, argument_list; 185, 186; 186, identifier:namespaces; 187, identifier:page_size; 188, block; 188, 189; 188, 197; 188, 201; 189, expression_statement; 189, 190; 190, call; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:namespaces; 193, identifier:pop; 194, argument_list; 194, 195; 195, unary_operator:-; 195, 196; 196, integer:1; 197, expression_statement; 197, 198; 198, assignment; 198, 199; 198, 200; 199, identifier:has_more_data; 200, True; 201, if_statement; 201, 202; 201, 205; 202, comparison_operator:is; 202, 203; 202, 204; 203, identifier:marker; 204, None; 205, block; 205, 206; 206, expression_statement; 206, 207; 207, assignment; 207, 208; 207, 209; 208, identifier:has_prev_data; 209, True; 210, elif_clause; 210, 211; 210, 218; 211, boolean_operator:and; 211, 212; 211, 215; 212, comparison_operator:==; 212, 213; 212, 214; 213, identifier:sort_dir; 214, string:'desc'; 215, comparison_operator:is; 215, 216; 215, 217; 216, identifier:marker; 217, None; 218, block; 218, 219; 219, expression_statement; 219, 220; 220, assignment; 220, 221; 220, 222; 221, identifier:has_more_data; 222, True; 223, elif_clause; 223, 224; 223, 227; 224, comparison_operator:is; 224, 225; 224, 226; 225, identifier:marker; 226, None; 227, block; 227, 228; 228, expression_statement; 228, 229; 229, assignment; 229, 230; 229, 231; 230, identifier:has_prev_data; 231, True; 232, else_clause; 232, 233; 233, block; 233, 234; 234, expression_statement; 234, 235; 235, assignment; 235, 236; 235, 237; 236, identifier:namespaces; 237, call; 237, 238; 237, 239; 238, identifier:list; 239, argument_list; 239, 240; 240, identifier:namespaces_iter; 241, expression_statement; 241, 242; 242, assignment; 242, 243; 242, 244; 243, identifier:namespaces; 244, list_comprehension; 244, 245; 244, 249; 245, call; 245, 246; 245, 247; 246, identifier:Namespace; 247, argument_list; 247, 248; 248, identifier:namespace; 249, for_in_clause; 249, 250; 249, 251; 250, identifier:namespace; 251, identifier:namespaces; 252, return_statement; 252, 253; 253, expression_list; 253, 254; 253, 255; 253, 256; 254, identifier:namespaces; 255, identifier:has_more_data; 256, identifier:has_prev_data | def metadefs_namespace_list(request,
filters=None,
sort_dir='asc',
sort_key='namespace',
marker=None,
paginate=False):
if get_version() < 2:
return [], False, False
if filters is None:
filters = {}
limit = getattr(settings, 'API_RESULT_LIMIT', 1000)
page_size = utils.get_page_size(request)
if paginate:
request_size = page_size + 1
else:
request_size = limit
kwargs = {'filters': filters}
if marker:
kwargs['marker'] = marker
kwargs['sort_dir'] = sort_dir
kwargs['sort_key'] = sort_key
namespaces_iter = glanceclient(request, '2').metadefs_namespace.list(
page_size=request_size, limit=limit, **kwargs)
resource_types = filters.get('resource_types')
properties_target = filters.get('properties_target')
if resource_types and properties_target:
namespaces_iter = filter_properties_target(namespaces_iter,
resource_types,
properties_target)
has_prev_data = False
has_more_data = False
if paginate:
namespaces = list(itertools.islice(namespaces_iter, request_size))
if len(namespaces) > page_size:
namespaces.pop(-1)
has_more_data = True
if marker is not None:
has_prev_data = True
elif sort_dir == 'desc' and marker is not None:
has_more_data = True
elif marker is not None:
has_prev_data = True
else:
namespaces = list(namespaces_iter)
namespaces = [Namespace(namespace) for namespace in namespaces]
return namespaces, has_more_data, has_prev_data |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort_js_files; 3, parameters; 3, 4; 4, identifier:js_files; 5, block; 5, 6; 5, 21; 5, 36; 5, 51; 5, 84; 5, 90; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:modules; 9, list_comprehension; 9, 10; 9, 11; 9, 14; 10, identifier:f; 11, for_in_clause; 11, 12; 11, 13; 12, identifier:f; 13, identifier:js_files; 14, if_clause; 14, 15; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:f; 18, identifier:endswith; 19, argument_list; 19, 20; 20, identifier:MODULE_EXT; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:mocks; 24, list_comprehension; 24, 25; 24, 26; 24, 29; 25, identifier:f; 26, for_in_clause; 26, 27; 26, 28; 27, identifier:f; 28, identifier:js_files; 29, if_clause; 29, 30; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:f; 33, identifier:endswith; 34, argument_list; 34, 35; 35, identifier:MOCK_EXT; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:specs; 39, list_comprehension; 39, 40; 39, 41; 39, 44; 40, identifier:f; 41, for_in_clause; 41, 42; 41, 43; 42, identifier:f; 43, identifier:js_files; 44, if_clause; 44, 45; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:f; 48, identifier:endswith; 49, argument_list; 49, 50; 50, identifier:SPEC_EXT; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:other_sources; 54, list_comprehension; 54, 55; 54, 56; 54, 59; 55, identifier:f; 56, for_in_clause; 56, 57; 56, 58; 57, identifier:f; 58, identifier:js_files; 59, if_clause; 59, 60; 60, parenthesized_expression; 60, 61; 61, boolean_operator:and; 61, 62; 61, 77; 62, boolean_operator:and; 62, 63; 62, 70; 63, not_operator; 63, 64; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:f; 67, identifier:endswith; 68, argument_list; 68, 69; 69, identifier:MODULE_EXT; 70, not_operator; 70, 71; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:f; 74, identifier:endswith; 75, argument_list; 75, 76; 76, identifier:MOCK_EXT; 77, not_operator; 77, 78; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:f; 81, identifier:endswith; 82, argument_list; 82, 83; 83, identifier:SPEC_EXT; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:sources; 87, binary_operator:+; 87, 88; 87, 89; 88, identifier:modules; 89, identifier:other_sources; 90, return_statement; 90, 91; 91, expression_list; 91, 92; 91, 93; 91, 94; 92, identifier:sources; 93, identifier:mocks; 94, identifier:specs | def sort_js_files(js_files):
modules = [f for f in js_files if f.endswith(MODULE_EXT)]
mocks = [f for f in js_files if f.endswith(MOCK_EXT)]
specs = [f for f in js_files if f.endswith(SPEC_EXT)]
other_sources = [f for f in js_files
if (not f.endswith(MODULE_EXT) and
not f.endswith(MOCK_EXT) and
not f.endswith(SPEC_EXT))]
sources = modules + other_sources
return sources, mocks, specs |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:_slice_mostly_sorted; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:array; 5, identifier:keep; 6, identifier:rest; 7, default_parameter; 7, 8; 7, 9; 8, identifier:ind; 9, None; 10, block; 10, 11; 10, 28; 10, 46; 10, 50; 10, 70; 10, 80; 10, 97; 10, 131; 10, 160; 10, 177; 11, if_statement; 11, 12; 11, 15; 12, comparison_operator:is; 12, 13; 12, 14; 13, identifier:ind; 14, None; 15, block; 15, 16; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:ind; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:np; 22, identifier:arange; 23, argument_list; 23, 24; 24, call; 24, 25; 24, 26; 25, identifier:len; 26, argument_list; 26, 27; 27, identifier:array; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:idx; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:np; 34, identifier:argsort; 35, argument_list; 35, 36; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:np; 39, identifier:concatenate; 40, argument_list; 40, 41; 41, list:[keep, ind[rest]]; 41, 42; 41, 43; 42, identifier:keep; 43, subscript; 43, 44; 43, 45; 44, identifier:ind; 45, identifier:rest; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:slices; 49, list:[]; 50, if_statement; 50, 51; 50, 56; 51, comparison_operator:>; 51, 52; 51, 55; 52, subscript; 52, 53; 52, 54; 53, identifier:keep; 54, integer:0; 55, integer:0; 56, block; 56, 57; 57, expression_statement; 57, 58; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:slices; 61, identifier:append; 62, argument_list; 62, 63; 63, call; 63, 64; 63, 65; 64, identifier:slice; 65, argument_list; 65, 66; 65, 67; 66, None; 67, subscript; 67, 68; 67, 69; 68, identifier:keep; 69, integer:0; 70, expression_statement; 70, 71; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:slices; 74, identifier:append; 75, argument_list; 75, 76; 76, list:[keep[0]]; 76, 77; 77, subscript; 77, 78; 77, 79; 78, identifier:keep; 79, integer:0; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:windows; 83, call; 83, 84; 83, 85; 84, identifier:zip; 85, argument_list; 85, 86; 85, 92; 86, subscript; 86, 87; 86, 88; 87, identifier:keep; 88, slice; 88, 89; 88, 90; 89, colon; 90, unary_operator:-; 90, 91; 91, integer:1; 92, subscript; 92, 93; 92, 94; 93, identifier:keep; 94, slice; 94, 95; 94, 96; 95, integer:1; 96, colon; 97, for_statement; 97, 98; 97, 101; 97, 102; 98, pattern_list; 98, 99; 98, 100; 99, identifier:l; 100, identifier:r; 101, identifier:windows; 102, block; 102, 103; 102, 123; 103, if_statement; 103, 104; 103, 109; 104, comparison_operator:>; 104, 105; 104, 106; 105, identifier:r; 106, binary_operator:+; 106, 107; 106, 108; 107, identifier:l; 108, integer:1; 109, block; 109, 110; 110, expression_statement; 110, 111; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:slices; 114, identifier:append; 115, argument_list; 115, 116; 116, call; 116, 117; 116, 118; 117, identifier:slice; 118, argument_list; 118, 119; 118, 122; 119, binary_operator:+; 119, 120; 119, 121; 120, identifier:l; 121, integer:1; 122, identifier:r; 123, expression_statement; 123, 124; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:slices; 127, identifier:append; 128, argument_list; 128, 129; 129, list:[r]; 129, 130; 130, identifier:r; 131, if_statement; 131, 132; 131, 143; 132, comparison_operator:<; 132, 133; 132, 137; 133, subscript; 133, 134; 133, 135; 134, identifier:keep; 135, unary_operator:-; 135, 136; 136, integer:1; 137, binary_operator:-; 137, 138; 137, 142; 138, call; 138, 139; 138, 140; 139, identifier:len; 140, argument_list; 140, 141; 141, identifier:array; 142, integer:1; 143, block; 143, 144; 144, expression_statement; 144, 145; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:slices; 148, identifier:append; 149, argument_list; 149, 150; 150, call; 150, 151; 150, 152; 151, identifier:slice; 152, argument_list; 152, 153; 152, 159; 153, binary_operator:+; 153, 154; 153, 158; 154, subscript; 154, 155; 154, 156; 155, identifier:keep; 156, unary_operator:-; 156, 157; 157, integer:1; 158, integer:1; 159, None; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:result; 163, call; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:da; 166, identifier:concatenate; 167, argument_list; 167, 168; 168, list_comprehension; 168, 169; 168, 174; 169, subscript; 169, 170; 169, 171; 170, identifier:array; 171, subscript; 171, 172; 171, 173; 172, identifier:idx; 173, identifier:slice_; 174, for_in_clause; 174, 175; 174, 176; 175, identifier:slice_; 176, identifier:slices; 177, return_statement; 177, 178; 178, identifier:result | def _slice_mostly_sorted(array, keep, rest, ind=None):
if ind is None:
ind = np.arange(len(array))
idx = np.argsort(np.concatenate([keep, ind[rest]]))
slices = []
if keep[0] > 0:
slices.append(slice(None, keep[0]))
slices.append([keep[0]])
windows = zip(keep[:-1], keep[1:])
for l, r in windows:
if r > l + 1:
slices.append(slice(l + 1, r))
slices.append([r])
if keep[-1] < len(array) - 1:
slices.append(slice(keep[-1] + 1, None))
result = da.concatenate([array[idx[slice_]] for slice_ in slices])
return result |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 1, 24; 2, function_name:sort_servers_closest; 3, parameters; 3, 4; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:servers; 6, type; 6, 7; 7, generic_type; 7, 8; 7, 9; 8, identifier:Sequence; 9, type_parameter; 9, 10; 10, type; 10, 11; 11, identifier:str; 12, type; 12, 13; 13, generic_type; 13, 14; 13, 15; 14, identifier:Sequence; 15, type_parameter; 15, 16; 16, type; 16, 17; 17, generic_type; 17, 18; 17, 19; 18, identifier:Tuple; 19, type_parameter; 19, 20; 19, 22; 20, type; 20, 21; 21, identifier:str; 22, type; 22, 23; 23, identifier:float; 24, block; 24, 25; 24, 50; 24, 74; 24, 84; 24, 123; 24, 133; 25, if_statement; 25, 26; 25, 44; 26, not_operator; 26, 27; 27, call; 27, 28; 27, 40; 28, attribute; 28, 29; 28, 39; 29, set_comprehension; 29, 30; 29, 36; 30, attribute; 30, 31; 30, 35; 31, call; 31, 32; 31, 33; 32, identifier:urlparse; 33, argument_list; 33, 34; 34, identifier:url; 35, identifier:scheme; 36, for_in_clause; 36, 37; 36, 38; 37, identifier:url; 38, identifier:servers; 39, identifier:issubset; 40, argument_list; 40, 41; 41, set; 41, 42; 41, 43; 42, string:'http'; 43, string:'https'; 44, block; 44, 45; 45, raise_statement; 45, 46; 46, call; 46, 47; 46, 48; 47, identifier:TransportError; 48, argument_list; 48, 49; 49, string:'Invalid server urls'; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:get_rtt_jobs; 53, call; 53, 54; 53, 55; 54, identifier:set; 55, generator_expression; 55, 56; 55, 71; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:gevent; 59, identifier:spawn; 60, argument_list; 60, 61; 60, 70; 61, lambda; 61, 62; 61, 64; 62, lambda_parameters; 62, 63; 63, identifier:url; 64, tuple; 64, 65; 64, 66; 65, identifier:url; 66, call; 66, 67; 66, 68; 67, identifier:get_http_rtt; 68, argument_list; 68, 69; 69, identifier:url; 70, identifier:server_url; 71, for_in_clause; 71, 72; 71, 73; 72, identifier:server_url; 73, identifier:servers; 74, expression_statement; 74, 75; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:gevent; 78, identifier:joinall; 79, argument_list; 79, 80; 79, 81; 80, identifier:get_rtt_jobs; 81, keyword_argument; 81, 82; 81, 83; 82, identifier:raise_error; 83, False; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 85, 99; 86, identifier:sorted_servers; 87, type; 87, 88; 88, generic_type; 88, 89; 88, 90; 89, identifier:List; 90, type_parameter; 90, 91; 91, type; 91, 92; 92, generic_type; 92, 93; 92, 94; 93, identifier:Tuple; 94, type_parameter; 94, 95; 94, 97; 95, type; 95, 96; 96, identifier:str; 97, type; 97, 98; 98, identifier:float; 99, call; 99, 100; 99, 101; 100, identifier:sorted; 101, argument_list; 101, 102; 101, 117; 102, generator_expression; 102, 103; 102, 106; 102, 109; 103, attribute; 103, 104; 103, 105; 104, identifier:job; 105, identifier:value; 106, for_in_clause; 106, 107; 106, 108; 107, identifier:job; 108, identifier:get_rtt_jobs; 109, if_clause; 109, 110; 110, comparison_operator:is; 110, 111; 110, 116; 111, subscript; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:job; 114, identifier:value; 115, integer:1; 116, None; 117, keyword_argument; 117, 118; 117, 119; 118, identifier:key; 119, call; 119, 120; 119, 121; 120, identifier:itemgetter; 121, argument_list; 121, 122; 122, integer:1; 123, expression_statement; 123, 124; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:log; 127, identifier:debug; 128, argument_list; 128, 129; 128, 130; 129, string:'Matrix homeserver RTT times'; 130, keyword_argument; 130, 131; 130, 132; 131, identifier:rtt_times; 132, identifier:sorted_servers; 133, return_statement; 133, 134; 134, identifier:sorted_servers | def sort_servers_closest(servers: Sequence[str]) -> Sequence[Tuple[str, float]]:
if not {urlparse(url).scheme for url in servers}.issubset({'http', 'https'}):
raise TransportError('Invalid server urls')
get_rtt_jobs = set(
gevent.spawn(lambda url: (url, get_http_rtt(url)), server_url)
for server_url
in servers
)
gevent.joinall(get_rtt_jobs, raise_error=False)
sorted_servers: List[Tuple[str, float]] = sorted(
(job.value for job in get_rtt_jobs if job.value[1] is not None),
key=itemgetter(1),
)
log.debug('Matrix homeserver RTT times', rtt_times=sorted_servers)
return sorted_servers |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:get_runs_by_id; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:config_id; 6, block; 6, 7; 6, 15; 6, 19; 6, 108; 6, 122; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:d; 10, subscript; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:data; 14, identifier:config_id; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:runs; 18, list:[]; 19, for_statement; 19, 20; 19, 21; 19, 28; 20, identifier:b; 21, call; 21, 22; 21, 27; 22, attribute; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:d; 25, identifier:results; 26, identifier:keys; 27, argument_list; 28, block; 28, 29; 29, try_statement; 29, 30; 29, 105; 30, block; 30, 31; 30, 43; 30, 98; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:err_logs; 34, call; 34, 35; 34, 40; 35, attribute; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:d; 38, identifier:exceptions; 39, identifier:get; 40, argument_list; 40, 41; 40, 42; 41, identifier:b; 42, None; 43, if_statement; 43, 44; 43, 51; 43, 68; 44, comparison_operator:is; 44, 45; 44, 50; 45, subscript; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:d; 48, identifier:results; 49, identifier:b; 50, None; 51, block; 51, 52; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:r; 55, call; 55, 56; 55, 57; 56, identifier:Run; 57, argument_list; 57, 58; 57, 59; 57, 60; 57, 61; 57, 62; 57, 67; 58, identifier:config_id; 59, identifier:b; 60, None; 61, None; 62, subscript; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:d; 65, identifier:time_stamps; 66, identifier:b; 67, identifier:err_logs; 68, else_clause; 68, 69; 69, block; 69, 70; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:r; 73, call; 73, 74; 73, 75; 74, identifier:Run; 75, argument_list; 75, 76; 75, 77; 75, 78; 75, 85; 75, 92; 75, 97; 76, identifier:config_id; 77, identifier:b; 78, subscript; 78, 79; 78, 84; 79, subscript; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:d; 82, identifier:results; 83, identifier:b; 84, string:'loss'; 85, subscript; 85, 86; 85, 91; 86, subscript; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:d; 89, identifier:results; 90, identifier:b; 91, string:'info'; 92, subscript; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:d; 95, identifier:time_stamps; 96, identifier:b; 97, identifier:err_logs; 98, expression_statement; 98, 99; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:runs; 102, identifier:append; 103, argument_list; 103, 104; 104, identifier:r; 105, except_clause; 105, 106; 106, block; 106, 107; 107, raise_statement; 108, expression_statement; 108, 109; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:runs; 112, identifier:sort; 113, argument_list; 113, 114; 114, keyword_argument; 114, 115; 114, 116; 115, identifier:key; 116, lambda; 116, 117; 116, 119; 117, lambda_parameters; 117, 118; 118, identifier:r; 119, attribute; 119, 120; 119, 121; 120, identifier:r; 121, identifier:budget; 122, return_statement; 122, 123; 123, parenthesized_expression; 123, 124; 124, identifier:runs | def get_runs_by_id(self, config_id):
d = self.data[config_id]
runs = []
for b in d.results.keys():
try:
err_logs = d.exceptions.get(b, None)
if d.results[b] is None:
r = Run(config_id, b, None, None , d.time_stamps[b], err_logs)
else:
r = Run(config_id, b, d.results[b]['loss'], d.results[b]['info'] , d.time_stamps[b], err_logs)
runs.append(r)
except:
raise
runs.sort(key=lambda r: r.budget)
return(runs) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 1, 15; 2, function_name:spell; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, typed_parameter; 5, 6; 5, 7; 6, identifier:word; 7, type; 7, 8; 8, identifier:str; 9, type; 9, 10; 10, generic_type; 10, 11; 10, 12; 11, identifier:List; 12, type_parameter; 12, 13; 13, type; 13, 14; 14, identifier:str; 15, block; 15, 16; 15, 22; 15, 56; 15, 70; 16, if_statement; 16, 17; 16, 19; 17, not_operator; 17, 18; 18, identifier:word; 19, block; 19, 20; 20, return_statement; 20, 21; 21, string:""; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:candidates; 25, parenthesized_expression; 25, 26; 26, boolean_operator:or; 26, 27; 26, 54; 27, boolean_operator:or; 27, 28; 27, 45; 28, boolean_operator:or; 28, 29; 28, 36; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:known; 33, argument_list; 33, 34; 34, list:[word]; 34, 35; 35, identifier:word; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:known; 40, argument_list; 40, 41; 41, call; 41, 42; 41, 43; 42, identifier:_edits1; 43, argument_list; 43, 44; 44, identifier:word; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:known; 49, argument_list; 49, 50; 50, call; 50, 51; 50, 52; 51, identifier:_edits2; 52, argument_list; 52, 53; 53, identifier:word; 54, list:[word]; 54, 55; 55, identifier:word; 56, expression_statement; 56, 57; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:candidates; 60, identifier:sort; 61, argument_list; 61, 62; 61, 67; 62, keyword_argument; 62, 63; 62, 64; 63, identifier:key; 64, attribute; 64, 65; 64, 66; 65, identifier:self; 66, identifier:freq; 67, keyword_argument; 67, 68; 67, 69; 68, identifier:reverse; 69, True; 70, return_statement; 70, 71; 71, identifier:candidates | def spell(self, word: str) -> List[str]:
if not word:
return ""
candidates = (
self.known([word])
or self.known(_edits1(word))
or self.known(_edits2(word))
or [word]
)
candidates.sort(key=self.freq, reverse=True)
return candidates |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 1, 19; 2, function_name:rank; 3, parameters; 3, 4; 3, 12; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:words; 6, type; 6, 7; 7, generic_type; 7, 8; 7, 9; 8, identifier:List; 9, type_parameter; 9, 10; 10, type; 10, 11; 11, identifier:str; 12, typed_default_parameter; 12, 13; 12, 14; 12, 16; 13, identifier:exclude_stopwords; 14, type; 14, 15; 15, identifier:bool; 16, False; 17, type; 17, 18; 18, identifier:Counter; 19, block; 19, 20; 19, 26; 19, 41; 20, if_statement; 20, 21; 20, 23; 21, not_operator; 21, 22; 22, identifier:words; 23, block; 23, 24; 24, return_statement; 24, 25; 25, None; 26, if_statement; 26, 27; 26, 28; 27, identifier:exclude_stopwords; 28, block; 28, 29; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:words; 32, list_comprehension; 32, 33; 32, 34; 32, 37; 33, identifier:word; 34, for_in_clause; 34, 35; 34, 36; 35, identifier:word; 36, identifier:words; 37, if_clause; 37, 38; 38, comparison_operator:not; 38, 39; 38, 40; 39, identifier:word; 40, identifier:_STOPWORDS; 41, return_statement; 41, 42; 42, call; 42, 43; 42, 44; 43, identifier:Counter; 44, argument_list; 44, 45; 45, identifier:words | def rank(words: List[str], exclude_stopwords: bool = False) -> Counter:
if not words:
return None
if exclude_stopwords:
words = [word for word in words if word not in _STOPWORDS]
return Counter(words) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 16; 2, function_name:iter; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:offset; 7, integer:0; 8, default_parameter; 8, 9; 8, 10; 9, identifier:count; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:pagesize; 13, None; 14, dictionary_splat_pattern; 14, 15; 15, identifier:kwargs; 16, block; 16, 17; 16, 25; 16, 36; 16, 40; 17, assert_statement; 17, 18; 18, boolean_operator:or; 18, 19; 18, 22; 19, comparison_operator:is; 19, 20; 19, 21; 20, identifier:pagesize; 21, None; 22, comparison_operator:>; 22, 23; 22, 24; 23, identifier:pagesize; 24, integer:0; 25, if_statement; 25, 26; 25, 29; 26, comparison_operator:is; 26, 27; 26, 28; 27, identifier:count; 28, None; 29, block; 29, 30; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:count; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:null_count; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:fetched; 39, integer:0; 40, while_statement; 40, 41; 40, 50; 41, boolean_operator:or; 41, 42; 41, 47; 42, comparison_operator:==; 42, 43; 42, 44; 43, identifier:count; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:null_count; 47, comparison_operator:<; 47, 48; 47, 49; 48, identifier:fetched; 49, identifier:count; 50, block; 50, 51; 50, 69; 50, 78; 50, 85; 50, 89; 50, 96; 50, 106; 50, 110; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:response; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:get; 58, argument_list; 58, 59; 58, 64; 58, 67; 59, keyword_argument; 59, 60; 59, 61; 60, identifier:count; 61, boolean_operator:or; 61, 62; 61, 63; 62, identifier:pagesize; 63, identifier:count; 64, keyword_argument; 64, 65; 64, 66; 65, identifier:offset; 66, identifier:offset; 67, dictionary_splat; 67, 68; 68, identifier:kwargs; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:items; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:self; 75, identifier:_load_list; 76, argument_list; 76, 77; 77, identifier:response; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:N; 81, call; 81, 82; 81, 83; 82, identifier:len; 83, argument_list; 83, 84; 84, identifier:items; 85, expression_statement; 85, 86; 86, augmented_assignment:+=; 86, 87; 86, 88; 87, identifier:fetched; 88, identifier:N; 89, for_statement; 89, 90; 89, 91; 89, 92; 90, identifier:item; 91, identifier:items; 92, block; 92, 93; 93, expression_statement; 93, 94; 94, yield; 94, 95; 95, identifier:item; 96, if_statement; 96, 97; 96, 104; 97, boolean_operator:or; 97, 98; 97, 101; 98, comparison_operator:is; 98, 99; 98, 100; 99, identifier:pagesize; 100, None; 101, comparison_operator:<; 101, 102; 101, 103; 102, identifier:N; 103, identifier:pagesize; 104, block; 104, 105; 105, break_statement; 106, expression_statement; 106, 107; 107, augmented_assignment:+=; 107, 108; 107, 109; 108, identifier:offset; 109, identifier:N; 110, expression_statement; 110, 111; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:logging; 114, identifier:debug; 115, argument_list; 115, 116; 115, 117; 115, 118; 115, 119; 115, 120; 115, 121; 116, string:"pagesize=%d, fetched=%d, offset=%d, N=%d, kwargs=%s"; 117, identifier:pagesize; 118, identifier:fetched; 119, identifier:offset; 120, identifier:N; 121, identifier:kwargs | def iter(self, offset=0, count=None, pagesize=None, **kwargs):
assert pagesize is None or pagesize > 0
if count is None:
count = self.null_count
fetched = 0
while count == self.null_count or fetched < count:
response = self.get(count=pagesize or count, offset=offset, **kwargs)
items = self._load_list(response)
N = len(items)
fetched += N
for item in items:
yield item
if pagesize is None or N < pagesize:
break
offset += N
logging.debug("pagesize=%d, fetched=%d, offset=%d, N=%d, kwargs=%s", pagesize, fetched, offset, N, kwargs) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:list; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:count; 7, None; 8, dictionary_splat_pattern; 8, 9; 9, identifier:kwargs; 10, block; 10, 11; 11, return_statement; 11, 12; 12, call; 12, 13; 12, 14; 13, identifier:list; 14, argument_list; 14, 15; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:iter; 19, argument_list; 19, 20; 19, 23; 20, keyword_argument; 20, 21; 20, 22; 21, identifier:count; 22, identifier:count; 23, dictionary_splat; 23, 24; 24, identifier:kwargs | def list(self, count=None, **kwargs):
return list(self.iter(count=count, **kwargs)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:query; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, dictionary_splat_pattern; 5, 6; 6, identifier:query; 7, block; 7, 8; 8, return_statement; 8, 9; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:json; 12, identifier:loads; 13, argument_list; 13, 14; 14, call; 14, 15; 14, 31; 15, attribute; 15, 16; 15, 30; 16, call; 16, 17; 16, 29; 17, attribute; 17, 18; 17, 28; 18, attribute; 18, 19; 18, 27; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:_get; 23, argument_list; 23, 24; 23, 25; 24, string:''; 25, dictionary_splat; 25, 26; 26, identifier:query; 27, identifier:body; 28, identifier:read; 29, argument_list; 30, identifier:decode; 31, argument_list; 31, 32; 32, string:'utf-8' | def query(self, **query):
return json.loads(self._get('', **query).body.read().decode('utf-8')) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 28; 2, function_name:query; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:area; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:date; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:raw; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:area_relation; 16, string:'Intersects'; 17, default_parameter; 17, 18; 17, 19; 18, identifier:order_by; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:limit; 22, None; 23, default_parameter; 23, 24; 23, 25; 24, identifier:offset; 25, integer:0; 26, dictionary_splat_pattern; 26, 27; 27, identifier:keywords; 28, block; 28, 29; 28, 43; 28, 56; 28, 63; 28, 77; 28, 87; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:query; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:format_query; 36, argument_list; 36, 37; 36, 38; 36, 39; 36, 40; 36, 41; 37, identifier:area; 38, identifier:date; 39, identifier:raw; 40, identifier:area_relation; 41, dictionary_splat; 41, 42; 42, identifier:keywords; 43, expression_statement; 43, 44; 44, call; 44, 45; 44, 50; 45, attribute; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:logger; 49, identifier:debug; 50, argument_list; 50, 51; 50, 52; 50, 53; 50, 54; 50, 55; 51, string:"Running query: order_by=%s, limit=%s, offset=%s, query=%s"; 52, identifier:order_by; 53, identifier:limit; 54, identifier:offset; 55, identifier:query; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:formatted_order_by; 59, call; 59, 60; 59, 61; 60, identifier:_format_order_by; 61, argument_list; 61, 62; 62, identifier:order_by; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 68; 65, pattern_list; 65, 66; 65, 67; 66, identifier:response; 67, identifier:count; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:self; 71, identifier:_load_query; 72, argument_list; 72, 73; 72, 74; 72, 75; 72, 76; 73, identifier:query; 74, identifier:formatted_order_by; 75, identifier:limit; 76, identifier:offset; 77, expression_statement; 77, 78; 78, call; 78, 79; 78, 84; 79, attribute; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:self; 82, identifier:logger; 83, identifier:info; 84, argument_list; 84, 85; 84, 86; 85, string:"Found %s products"; 86, identifier:count; 87, return_statement; 87, 88; 88, call; 88, 89; 88, 90; 89, identifier:_parse_opensearch_response; 90, argument_list; 90, 91; 91, identifier:response | def query(self, area=None, date=None, raw=None, area_relation='Intersects',
order_by=None, limit=None, offset=0, **keywords):
query = self.format_query(area, date, raw, area_relation, **keywords)
self.logger.debug("Running query: order_by=%s, limit=%s, offset=%s, query=%s",
order_by, limit, offset, query)
formatted_order_by = _format_order_by(order_by)
response, count = self._load_query(query, formatted_order_by, limit, offset)
self.logger.info("Found %s products", count)
return _parse_opensearch_response(response) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:get_suggested_type_names; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:schema; 5, identifier:output_type; 6, identifier:field_name; 7, block; 7, 8; 7, 128; 8, if_statement; 8, 9; 8, 16; 9, call; 9, 10; 9, 11; 10, identifier:isinstance; 11, argument_list; 11, 12; 11, 13; 12, identifier:output_type; 13, tuple; 13, 14; 13, 15; 14, identifier:GraphQLInterfaceType; 15, identifier:GraphQLUnionType; 16, block; 16, 17; 16, 21; 16, 27; 16, 94; 16, 119; 16, 126; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:suggested_object_types; 20, list:[]; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:interface_usage_count; 24, call; 24, 25; 24, 26; 25, identifier:OrderedDict; 26, argument_list; 27, for_statement; 27, 28; 27, 29; 27, 35; 28, identifier:possible_type; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:schema; 32, identifier:get_possible_types; 33, argument_list; 33, 34; 34, identifier:output_type; 35, block; 35, 36; 35, 48; 35, 57; 36, if_statement; 36, 37; 36, 46; 37, not_operator; 37, 38; 38, call; 38, 39; 38, 44; 39, attribute; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:possible_type; 42, identifier:fields; 43, identifier:get; 44, argument_list; 44, 45; 45, identifier:field_name; 46, block; 46, 47; 47, return_statement; 48, expression_statement; 48, 49; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:suggested_object_types; 52, identifier:append; 53, argument_list; 53, 54; 54, attribute; 54, 55; 54, 56; 55, identifier:possible_type; 56, identifier:name; 57, for_statement; 57, 58; 57, 59; 57, 62; 58, identifier:possible_interface; 59, attribute; 59, 60; 59, 61; 60, identifier:possible_type; 61, identifier:interfaces; 62, block; 62, 63; 62, 75; 63, if_statement; 63, 64; 63, 73; 64, not_operator; 64, 65; 65, call; 65, 66; 65, 71; 66, attribute; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:possible_interface; 69, identifier:fields; 70, identifier:get; 71, argument_list; 71, 72; 72, identifier:field_name; 73, block; 73, 74; 74, continue_statement; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 82; 77, subscript; 77, 78; 77, 79; 78, identifier:interface_usage_count; 79, attribute; 79, 80; 79, 81; 80, identifier:possible_interface; 81, identifier:name; 82, parenthesized_expression; 82, 83; 83, binary_operator:+; 83, 84; 83, 93; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:interface_usage_count; 87, identifier:get; 88, argument_list; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:possible_interface; 91, identifier:name; 92, integer:0; 93, integer:1; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:suggested_interface_types; 97, call; 97, 98; 97, 99; 98, identifier:sorted; 99, argument_list; 99, 100; 99, 108; 99, 116; 100, call; 100, 101; 100, 102; 101, identifier:list; 102, argument_list; 102, 103; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:interface_usage_count; 106, identifier:keys; 107, argument_list; 108, keyword_argument; 108, 109; 108, 110; 109, identifier:key; 110, lambda; 110, 111; 110, 113; 111, lambda_parameters; 111, 112; 112, identifier:k; 113, subscript; 113, 114; 113, 115; 114, identifier:interface_usage_count; 115, identifier:k; 116, keyword_argument; 116, 117; 116, 118; 117, identifier:reverse; 118, True; 119, expression_statement; 119, 120; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:suggested_interface_types; 123, identifier:extend; 124, argument_list; 124, 125; 125, identifier:suggested_object_types; 126, return_statement; 126, 127; 127, identifier:suggested_interface_types; 128, return_statement; 128, 129; 129, list:[] | def get_suggested_type_names(schema, output_type, field_name):
if isinstance(output_type, (GraphQLInterfaceType, GraphQLUnionType)):
suggested_object_types = []
interface_usage_count = OrderedDict()
for possible_type in schema.get_possible_types(output_type):
if not possible_type.fields.get(field_name):
return
suggested_object_types.append(possible_type.name)
for possible_interface in possible_type.interfaces:
if not possible_interface.fields.get(field_name):
continue
interface_usage_count[possible_interface.name] = (
interface_usage_count.get(possible_interface.name, 0) + 1
)
suggested_interface_types = sorted(
list(interface_usage_count.keys()),
key=lambda k: interface_usage_count[k],
reverse=True,
)
suggested_interface_types.extend(suggested_object_types)
return suggested_interface_types
return [] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:suggestion_list; 3, parameters; 3, 4; 3, 5; 4, identifier:inp; 5, identifier:options; 6, block; 6, 7; 6, 13; 6, 22; 6, 59; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:options_by_distance; 10, call; 10, 11; 10, 12; 11, identifier:OrderedDict; 12, argument_list; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:input_threshold; 16, binary_operator:/; 16, 17; 16, 21; 17, call; 17, 18; 17, 19; 18, identifier:len; 19, argument_list; 19, 20; 20, identifier:inp; 21, integer:2; 22, for_statement; 22, 23; 22, 24; 22, 25; 23, identifier:option; 24, identifier:options; 25, block; 25, 26; 25, 34; 25, 48; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:distance; 29, call; 29, 30; 29, 31; 30, identifier:lexical_distance; 31, argument_list; 31, 32; 31, 33; 32, identifier:inp; 33, identifier:option; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:threshold; 37, call; 37, 38; 37, 39; 38, identifier:max; 39, argument_list; 39, 40; 39, 41; 39, 47; 40, identifier:input_threshold; 41, binary_operator:/; 41, 42; 41, 46; 42, call; 42, 43; 42, 44; 43, identifier:len; 44, argument_list; 44, 45; 45, identifier:option; 46, integer:2; 47, integer:1; 48, if_statement; 48, 49; 48, 52; 49, comparison_operator:<=; 49, 50; 49, 51; 50, identifier:distance; 51, identifier:threshold; 52, block; 52, 53; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 58; 55, subscript; 55, 56; 55, 57; 56, identifier:options_by_distance; 57, identifier:option; 58, identifier:distance; 59, return_statement; 59, 60; 60, call; 60, 61; 60, 62; 61, identifier:sorted; 62, argument_list; 62, 63; 62, 71; 63, call; 63, 64; 63, 65; 64, identifier:list; 65, argument_list; 65, 66; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:options_by_distance; 69, identifier:keys; 70, argument_list; 71, keyword_argument; 71, 72; 71, 73; 72, identifier:key; 73, lambda; 73, 74; 73, 76; 74, lambda_parameters; 74, 75; 75, identifier:k; 76, subscript; 76, 77; 76, 78; 77, identifier:options_by_distance; 78, identifier:k | def suggestion_list(inp, options):
options_by_distance = OrderedDict()
input_threshold = len(inp) / 2
for option in options:
distance = lexical_distance(inp, option)
threshold = max(input_threshold, len(option) / 2, 1)
if distance <= threshold:
options_by_distance[option] = distance
return sorted(
list(options_by_distance.keys()), key=lambda k: options_by_distance[k]
) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:lexical_distance; 3, parameters; 3, 4; 3, 5; 4, identifier:a; 5, identifier:b; 6, block; 6, 7; 6, 26; 6, 35; 6, 80; 6, 221; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:d; 10, boolean_operator:or; 10, 11; 10, 25; 11, list_comprehension; 11, 12; 11, 14; 12, list:[i]; 12, 13; 13, identifier:i; 14, for_in_clause; 14, 15; 14, 16; 15, identifier:i; 16, call; 16, 17; 16, 18; 17, identifier:range; 18, argument_list; 18, 19; 19, binary_operator:+; 19, 20; 19, 24; 20, call; 20, 21; 20, 22; 21, identifier:len; 22, argument_list; 22, 23; 23, identifier:a; 24, integer:1; 25, list:[]; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:d_len; 29, boolean_operator:or; 29, 30; 29, 34; 30, call; 30, 31; 30, 32; 31, identifier:len; 32, argument_list; 32, 33; 33, identifier:d; 34, integer:1; 35, for_statement; 35, 36; 35, 37; 35, 41; 36, identifier:i; 37, call; 37, 38; 37, 39; 38, identifier:range; 39, argument_list; 39, 40; 40, identifier:d_len; 41, block; 41, 42; 42, for_statement; 42, 43; 42, 44; 42, 54; 43, identifier:j; 44, call; 44, 45; 44, 46; 45, identifier:range; 46, argument_list; 46, 47; 46, 48; 47, integer:1; 48, binary_operator:+; 48, 49; 48, 53; 49, call; 49, 50; 49, 51; 50, identifier:len; 51, argument_list; 51, 52; 52, identifier:b; 53, integer:1; 54, block; 54, 55; 55, if_statement; 55, 56; 55, 59; 55, 69; 56, comparison_operator:==; 56, 57; 56, 58; 57, identifier:i; 58, integer:0; 59, block; 59, 60; 60, expression_statement; 60, 61; 61, call; 61, 62; 61, 67; 62, attribute; 62, 63; 62, 66; 63, subscript; 63, 64; 63, 65; 64, identifier:d; 65, identifier:i; 66, identifier:append; 67, argument_list; 67, 68; 68, identifier:j; 69, else_clause; 69, 70; 70, block; 70, 71; 71, expression_statement; 71, 72; 72, call; 72, 73; 72, 78; 73, attribute; 73, 74; 73, 77; 74, subscript; 74, 75; 74, 76; 75, identifier:d; 76, identifier:i; 77, identifier:append; 78, argument_list; 78, 79; 79, integer:0; 80, for_statement; 80, 81; 80, 82; 80, 92; 81, identifier:i; 82, call; 82, 83; 82, 84; 83, identifier:range; 84, argument_list; 84, 85; 84, 86; 85, integer:1; 86, binary_operator:+; 86, 87; 86, 91; 87, call; 87, 88; 87, 89; 88, identifier:len; 89, argument_list; 89, 90; 90, identifier:a; 91, integer:1; 92, block; 92, 93; 93, for_statement; 93, 94; 93, 95; 93, 105; 94, identifier:j; 95, call; 95, 96; 95, 97; 96, identifier:range; 97, argument_list; 97, 98; 97, 99; 98, integer:1; 99, binary_operator:+; 99, 100; 99, 104; 100, call; 100, 101; 100, 102; 101, identifier:len; 102, argument_list; 102, 103; 103, identifier:b; 104, integer:1; 105, block; 105, 106; 105, 123; 105, 162; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:cost; 109, conditional_expression:if; 109, 110; 109, 111; 109, 122; 110, integer:0; 111, comparison_operator:==; 111, 112; 111, 117; 112, subscript; 112, 113; 112, 114; 113, identifier:a; 114, binary_operator:-; 114, 115; 114, 116; 115, identifier:i; 116, integer:1; 117, subscript; 117, 118; 117, 119; 118, identifier:b; 119, binary_operator:-; 119, 120; 119, 121; 120, identifier:j; 121, integer:1; 122, integer:1; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 130; 125, subscript; 125, 126; 125, 129; 126, subscript; 126, 127; 126, 128; 127, identifier:d; 128, identifier:i; 129, identifier:j; 130, call; 130, 131; 130, 132; 131, identifier:min; 132, argument_list; 132, 133; 132, 142; 132, 151; 133, binary_operator:+; 133, 134; 133, 141; 134, subscript; 134, 135; 134, 140; 135, subscript; 135, 136; 135, 137; 136, identifier:d; 137, binary_operator:-; 137, 138; 137, 139; 138, identifier:i; 139, integer:1; 140, identifier:j; 141, integer:1; 142, binary_operator:+; 142, 143; 142, 150; 143, subscript; 143, 144; 143, 147; 144, subscript; 144, 145; 144, 146; 145, identifier:d; 146, identifier:i; 147, binary_operator:-; 147, 148; 147, 149; 148, identifier:j; 149, integer:1; 150, integer:1; 151, binary_operator:+; 151, 152; 151, 161; 152, subscript; 152, 153; 152, 158; 153, subscript; 153, 154; 153, 155; 154, identifier:d; 155, binary_operator:-; 155, 156; 155, 157; 156, identifier:i; 157, integer:1; 158, binary_operator:-; 158, 159; 158, 160; 159, identifier:j; 160, integer:1; 161, identifier:cost; 162, if_statement; 162, 163; 162, 194; 163, boolean_operator:and; 163, 164; 163, 183; 164, boolean_operator:and; 164, 165; 164, 172; 165, boolean_operator:and; 165, 166; 165, 169; 166, comparison_operator:>; 166, 167; 166, 168; 167, identifier:i; 168, integer:1; 169, comparison_operator:<; 169, 170; 169, 171; 170, identifier:j; 171, integer:1; 172, comparison_operator:==; 172, 173; 172, 178; 173, subscript; 173, 174; 173, 175; 174, identifier:a; 175, binary_operator:-; 175, 176; 175, 177; 176, identifier:i; 177, integer:1; 178, subscript; 178, 179; 178, 180; 179, identifier:b; 180, binary_operator:-; 180, 181; 180, 182; 181, identifier:j; 182, integer:2; 183, comparison_operator:==; 183, 184; 183, 189; 184, subscript; 184, 185; 184, 186; 185, identifier:a; 186, binary_operator:-; 186, 187; 186, 188; 187, identifier:i; 188, integer:2; 189, subscript; 189, 190; 189, 191; 190, identifier:b; 191, binary_operator:-; 191, 192; 191, 193; 192, identifier:j; 193, integer:1; 194, block; 194, 195; 195, expression_statement; 195, 196; 196, assignment; 196, 197; 196, 202; 197, subscript; 197, 198; 197, 201; 198, subscript; 198, 199; 198, 200; 199, identifier:d; 200, identifier:i; 201, identifier:j; 202, call; 202, 203; 202, 204; 203, identifier:min; 204, argument_list; 204, 205; 204, 210; 205, subscript; 205, 206; 205, 209; 206, subscript; 206, 207; 206, 208; 207, identifier:d; 208, identifier:i; 209, identifier:j; 210, binary_operator:+; 210, 211; 210, 220; 211, subscript; 211, 212; 211, 217; 212, subscript; 212, 213; 212, 214; 213, identifier:d; 214, binary_operator:-; 214, 215; 214, 216; 215, identifier:i; 216, integer:2; 217, binary_operator:-; 217, 218; 217, 219; 218, identifier:j; 219, integer:2; 220, identifier:cost; 221, return_statement; 221, 222; 222, subscript; 222, 223; 222, 229; 223, subscript; 223, 224; 223, 225; 224, identifier:d; 225, call; 225, 226; 225, 227; 226, identifier:len; 227, argument_list; 227, 228; 228, identifier:a; 229, call; 229, 230; 229, 231; 230, identifier:len; 231, argument_list; 231, 232; 232, identifier:b | def lexical_distance(a, b):
d = [[i] for i in range(len(a) + 1)] or []
d_len = len(d) or 1
for i in range(d_len):
for j in range(1, len(b) + 1):
if i == 0:
d[i].append(j)
else:
d[i].append(0)
for i in range(1, len(a) + 1):
for j in range(1, len(b) + 1):
cost = 0 if a[i - 1] == b[j - 1] else 1
d[i][j] = min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost)
if i > 1 and j < 1 and a[i - 1] == b[j - 2] and a[i - 2] == b[j - 1]:
d[i][j] = min(d[i][j], d[i - 2][j - 2] + cost)
return d[len(a)][len(b)] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:arrange; 3, parameters; 3, 4; 3, 5; 3, 7; 4, identifier:df; 5, list_splat_pattern; 5, 6; 6, identifier:args; 7, dictionary_splat_pattern; 7, 8; 8, identifier:kwargs; 9, block; 9, 10; 9, 21; 9, 56; 9, 75; 9, 92; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:flat_args; 13, list_comprehension; 13, 14; 13, 15; 14, identifier:a; 15, for_in_clause; 15, 16; 15, 17; 16, identifier:a; 17, call; 17, 18; 17, 19; 18, identifier:flatten; 19, argument_list; 19, 20; 20, identifier:args; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:series; 24, list_comprehension; 24, 25; 24, 53; 25, conditional_expression:if; 25, 26; 25, 29; 25, 34; 26, subscript; 26, 27; 26, 28; 27, identifier:df; 28, identifier:arg; 29, call; 29, 30; 29, 31; 30, identifier:isinstance; 31, argument_list; 31, 32; 31, 33; 32, identifier:arg; 33, identifier:str; 34, conditional_expression:if; 34, 35; 34, 42; 34, 47; 35, subscript; 35, 36; 35, 39; 35, 41; 36, attribute; 36, 37; 36, 38; 37, identifier:df; 38, identifier:iloc; 39, slice; 39, 40; 40, colon; 41, identifier:arg; 42, call; 42, 43; 42, 44; 43, identifier:isinstance; 44, argument_list; 44, 45; 44, 46; 45, identifier:arg; 46, identifier:int; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:pd; 50, identifier:Series; 51, argument_list; 51, 52; 52, identifier:arg; 53, for_in_clause; 53, 54; 53, 55; 54, identifier:arg; 55, identifier:flat_args; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:sorter; 59, call; 59, 60; 59, 71; 60, attribute; 60, 61; 60, 70; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:pd; 64, identifier:concat; 65, argument_list; 65, 66; 65, 67; 66, identifier:series; 67, keyword_argument; 67, 68; 67, 69; 68, identifier:axis; 69, integer:1; 70, identifier:reset_index; 71, argument_list; 71, 72; 72, keyword_argument; 72, 73; 72, 74; 73, identifier:drop; 74, True; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:sorter; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:sorter; 81, identifier:sort_values; 82, argument_list; 82, 83; 82, 90; 83, call; 83, 84; 83, 89; 84, attribute; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:sorter; 87, identifier:columns; 88, identifier:tolist; 89, argument_list; 90, dictionary_splat; 90, 91; 91, identifier:kwargs; 92, return_statement; 92, 93; 93, subscript; 93, 94; 93, 97; 93, 100; 94, attribute; 94, 95; 94, 96; 95, identifier:df; 96, identifier:iloc; 97, attribute; 97, 98; 97, 99; 98, identifier:sorter; 99, identifier:index; 100, slice; 100, 101; 101, colon | def arrange(df, *args, **kwargs):
flat_args = [a for a in flatten(args)]
series = [df[arg] if isinstance(arg, str) else
df.iloc[:, arg] if isinstance(arg, int) else
pd.Series(arg) for arg in flat_args]
sorter = pd.concat(series, axis=1).reset_index(drop=True)
sorter = sorter.sort_values(sorter.columns.tolist(), **kwargs)
return df.iloc[sorter.index, :] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:csort; 3, parameters; 3, 4; 3, 5; 4, identifier:objs; 5, identifier:key; 6, block; 6, 7; 6, 24; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:idxs; 10, call; 10, 11; 10, 12; 11, identifier:dict; 12, generator_expression; 12, 13; 12, 16; 13, tuple; 13, 14; 13, 15; 14, identifier:obj; 15, identifier:i; 16, for_in_clause; 16, 17; 16, 20; 17, tuple_pattern; 17, 18; 17, 19; 18, identifier:i; 19, identifier:obj; 20, call; 20, 21; 20, 22; 21, identifier:enumerate; 22, argument_list; 22, 23; 23, identifier:objs; 24, return_statement; 24, 25; 25, call; 25, 26; 25, 27; 26, identifier:sorted; 27, argument_list; 27, 28; 27, 29; 28, identifier:objs; 29, keyword_argument; 29, 30; 29, 31; 30, identifier:key; 31, lambda; 31, 32; 31, 34; 32, lambda_parameters; 32, 33; 33, identifier:obj; 34, tuple; 34, 35; 34, 39; 35, call; 35, 36; 35, 37; 36, identifier:key; 37, argument_list; 37, 38; 38, identifier:obj; 39, subscript; 39, 40; 39, 41; 40, identifier:idxs; 41, identifier:obj | def csort(objs, key):
idxs = dict((obj, i) for (i, obj) in enumerate(objs))
return sorted(objs, key=lambda obj: (key(obj), idxs[obj])) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:fast_combine_pairs; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:files; 5, identifier:force_single; 6, identifier:full_name; 7, identifier:separators; 8, block; 8, 9; 8, 16; 8, 26; 8, 40; 8, 51; 8, 58; 8, 85; 8, 103; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:files; 12, call; 12, 13; 12, 14; 13, identifier:sort_filenames; 14, argument_list; 14, 15; 15, identifier:files; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:chunks; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:tz; 22, identifier:sliding_window; 23, argument_list; 23, 24; 23, 25; 24, integer:10; 25, identifier:files; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:pairs; 29, list_comprehension; 29, 30; 29, 37; 30, call; 30, 31; 30, 32; 31, identifier:combine_pairs; 32, argument_list; 32, 33; 32, 34; 32, 35; 32, 36; 33, identifier:chunk; 34, identifier:force_single; 35, identifier:full_name; 36, identifier:separators; 37, for_in_clause; 37, 38; 37, 39; 38, identifier:chunk; 39, identifier:chunks; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:pairs; 43, list_comprehension; 43, 44; 43, 45; 43, 48; 44, identifier:y; 45, for_in_clause; 45, 46; 45, 47; 46, identifier:x; 47, identifier:pairs; 48, for_in_clause; 48, 49; 48, 50; 49, identifier:y; 50, identifier:x; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:longest; 54, call; 54, 55; 54, 56; 55, identifier:defaultdict; 56, argument_list; 56, 57; 57, identifier:list; 58, for_statement; 58, 59; 58, 60; 58, 61; 59, identifier:pair; 60, identifier:pairs; 61, block; 61, 62; 62, for_statement; 62, 63; 62, 64; 62, 65; 63, identifier:file; 64, identifier:pair; 65, block; 65, 66; 66, if_statement; 66, 67; 66, 78; 67, comparison_operator:<; 67, 68; 67, 74; 68, call; 68, 69; 68, 70; 69, identifier:len; 70, argument_list; 70, 71; 71, subscript; 71, 72; 71, 73; 72, identifier:longest; 73, identifier:file; 74, call; 74, 75; 74, 76; 75, identifier:len; 76, argument_list; 76, 77; 77, identifier:pair; 78, block; 78, 79; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 84; 81, subscript; 81, 82; 81, 83; 82, identifier:longest; 83, identifier:file; 84, identifier:pair; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:longest; 88, set_comprehension; 88, 89; 88, 96; 89, call; 89, 90; 89, 91; 90, identifier:tuple; 91, argument_list; 91, 92; 92, call; 92, 93; 92, 94; 93, identifier:sort_filenames; 94, argument_list; 94, 95; 95, identifier:x; 96, for_in_clause; 96, 97; 96, 98; 97, identifier:x; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:longest; 101, identifier:values; 102, argument_list; 103, return_statement; 103, 104; 104, list_comprehension; 104, 105; 104, 112; 105, call; 105, 106; 105, 107; 106, identifier:sort_filenames; 107, argument_list; 107, 108; 108, call; 108, 109; 108, 110; 109, identifier:list; 110, argument_list; 110, 111; 111, identifier:x; 112, for_in_clause; 112, 113; 112, 114; 113, identifier:x; 114, identifier:longest | def fast_combine_pairs(files, force_single, full_name, separators):
files = sort_filenames(files)
chunks = tz.sliding_window(10, files)
pairs = [combine_pairs(chunk, force_single, full_name, separators) for chunk in chunks]
pairs = [y for x in pairs for y in x]
longest = defaultdict(list)
for pair in pairs:
for file in pair:
if len(longest[file]) < len(pair):
longest[file] = pair
longest = {tuple(sort_filenames(x)) for x in longest.values()}
return [sort_filenames(list(x)) for x in longest] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:align_bam; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:in_bam; 5, identifier:ref_file; 6, identifier:names; 7, identifier:align_dir; 8, identifier:data; 9, block; 9, 10; 9, 16; 9, 35; 9, 45; 9, 55; 9, 65; 9, 77; 9, 98; 9, 219; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:config; 13, subscript; 13, 14; 13, 15; 14, identifier:data; 15, string:"config"; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:out_file; 19, call; 19, 20; 19, 25; 20, attribute; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:os; 23, identifier:path; 24, identifier:join; 25, argument_list; 25, 26; 25, 27; 26, identifier:align_dir; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, string:"{0}-sort.bam"; 30, identifier:format; 31, argument_list; 31, 32; 32, subscript; 32, 33; 32, 34; 33, identifier:names; 34, string:"lane"; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:samtools; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:config_utils; 41, identifier:get_program; 42, argument_list; 42, 43; 42, 44; 43, string:"samtools"; 44, identifier:config; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:bedtools; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:config_utils; 51, identifier:get_program; 52, argument_list; 52, 53; 52, 54; 53, string:"bedtools"; 54, identifier:config; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:resources; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:config_utils; 61, identifier:get_resources; 62, argument_list; 62, 63; 62, 64; 63, string:"samtools"; 64, identifier:config; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:num_cores; 68, call; 68, 69; 68, 74; 69, attribute; 69, 70; 69, 73; 70, subscript; 70, 71; 70, 72; 71, identifier:config; 72, string:"algorithm"; 73, identifier:get; 74, argument_list; 74, 75; 74, 76; 75, string:"num_cores"; 76, integer:1; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:max_mem; 80, call; 80, 81; 80, 97; 81, attribute; 81, 82; 81, 96; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:config_utils; 85, identifier:adjust_memory; 86, argument_list; 86, 87; 86, 94; 86, 95; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:resources; 90, identifier:get; 91, argument_list; 91, 92; 91, 93; 92, string:"memory"; 93, string:"1G"; 94, integer:3; 95, string:"decrease"; 96, identifier:upper; 97, argument_list; 98, if_statement; 98, 99; 98, 106; 99, not_operator; 99, 100; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:utils; 103, identifier:file_exists; 104, argument_list; 104, 105; 105, identifier:out_file; 106, block; 106, 107; 107, with_statement; 107, 108; 107, 117; 108, with_clause; 108, 109; 109, with_item; 109, 110; 110, as_pattern; 110, 111; 110, 115; 111, call; 111, 112; 111, 113; 112, identifier:tx_tmpdir; 113, argument_list; 113, 114; 114, identifier:data; 115, as_pattern_target; 115, 116; 116, identifier:work_dir; 117, block; 117, 118; 118, with_statement; 118, 119; 118, 139; 119, with_clause; 119, 120; 120, with_item; 120, 121; 121, as_pattern; 121, 122; 121, 135; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:postalign; 125, identifier:tobam_cl; 126, argument_list; 126, 127; 126, 128; 126, 129; 127, identifier:data; 128, identifier:out_file; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:bam; 132, identifier:is_paired; 133, argument_list; 133, 134; 134, identifier:in_bam; 135, as_pattern_target; 135, 136; 136, tuple; 136, 137; 136, 138; 137, identifier:tobam_cl; 138, identifier:tx_out_file; 139, block; 139, 140; 139, 150; 139, 163; 139, 169; 139, 178; 139, 192; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:bwa_cmd; 143, call; 143, 144; 143, 145; 144, identifier:_get_bwa_mem_cmd; 145, argument_list; 145, 146; 145, 147; 145, 148; 145, 149; 146, identifier:data; 147, identifier:out_file; 148, identifier:ref_file; 149, string:"-"; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 153; 152, identifier:tx_out_prefix; 153, subscript; 153, 154; 153, 162; 154, call; 154, 155; 154, 160; 155, attribute; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:os; 158, identifier:path; 159, identifier:splitext; 160, argument_list; 160, 161; 161, identifier:tx_out_file; 162, integer:0; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 166; 165, identifier:prefix1; 166, binary_operator:%; 166, 167; 166, 168; 167, string:"%s-in1"; 168, identifier:tx_out_prefix; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 172; 171, identifier:cmd; 172, parenthesized_expression; 172, 173; 173, concatenated_string; 173, 174; 173, 175; 173, 176; 173, 177; 174, string:"unset JAVA_HOME && "; 175, string:"{samtools} sort -n -o -l 1 -@ {num_cores} -m {max_mem} {in_bam} {prefix1} "; 176, string:"| {bedtools} bamtofastq -i /dev/stdin -fq /dev/stdout -fq2 /dev/stdout "; 177, string:"| {bwa_cmd} | "; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 181; 180, identifier:cmd; 181, binary_operator:+; 181, 182; 181, 191; 182, call; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, identifier:cmd; 185, identifier:format; 186, argument_list; 186, 187; 187, dictionary_splat; 187, 188; 188, call; 188, 189; 188, 190; 189, identifier:locals; 190, argument_list; 191, identifier:tobam_cl; 192, expression_statement; 192, 193; 193, call; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:do; 196, identifier:run; 197, argument_list; 197, 198; 197, 199; 197, 204; 197, 205; 198, identifier:cmd; 199, binary_operator:%; 199, 200; 199, 201; 200, string:"bwa mem alignment from BAM: %s"; 201, subscript; 201, 202; 201, 203; 202, identifier:names; 203, string:"sample"; 204, None; 205, list:[do.file_nonempty(tx_out_file), do.file_reasonable_size(tx_out_file, in_bam)]; 205, 206; 205, 212; 206, call; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:do; 209, identifier:file_nonempty; 210, argument_list; 210, 211; 211, identifier:tx_out_file; 212, call; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:do; 215, identifier:file_reasonable_size; 216, argument_list; 216, 217; 216, 218; 217, identifier:tx_out_file; 218, identifier:in_bam; 219, return_statement; 219, 220; 220, identifier:out_file | def align_bam(in_bam, ref_file, names, align_dir, data):
config = data["config"]
out_file = os.path.join(align_dir, "{0}-sort.bam".format(names["lane"]))
samtools = config_utils.get_program("samtools", config)
bedtools = config_utils.get_program("bedtools", config)
resources = config_utils.get_resources("samtools", config)
num_cores = config["algorithm"].get("num_cores", 1)
max_mem = config_utils.adjust_memory(resources.get("memory", "1G"),
3, "decrease").upper()
if not utils.file_exists(out_file):
with tx_tmpdir(data) as work_dir:
with postalign.tobam_cl(data, out_file, bam.is_paired(in_bam)) as (tobam_cl, tx_out_file):
bwa_cmd = _get_bwa_mem_cmd(data, out_file, ref_file, "-")
tx_out_prefix = os.path.splitext(tx_out_file)[0]
prefix1 = "%s-in1" % tx_out_prefix
cmd = ("unset JAVA_HOME && "
"{samtools} sort -n -o -l 1 -@ {num_cores} -m {max_mem} {in_bam} {prefix1} "
"| {bedtools} bamtofastq -i /dev/stdin -fq /dev/stdout -fq2 /dev/stdout "
"| {bwa_cmd} | ")
cmd = cmd.format(**locals()) + tobam_cl
do.run(cmd, "bwa mem alignment from BAM: %s" % names["sample"], None,
[do.file_nonempty(tx_out_file), do.file_reasonable_size(tx_out_file, in_bam)])
return out_file |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_combine_regions; 3, parameters; 3, 4; 3, 5; 4, identifier:all_regions; 5, identifier:ref_regions; 6, block; 6, 7; 6, 11; 6, 28; 6, 47; 6, 51; 6, 81; 6, 90; 6, 106; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:chrom_order; 10, dictionary; 11, for_statement; 11, 12; 11, 15; 11, 19; 12, pattern_list; 12, 13; 12, 14; 13, identifier:i; 14, identifier:x; 15, call; 15, 16; 15, 17; 16, identifier:enumerate; 17, argument_list; 17, 18; 18, identifier:ref_regions; 19, block; 19, 20; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 27; 22, subscript; 22, 23; 22, 24; 23, identifier:chrom_order; 24, attribute; 24, 25; 24, 26; 25, identifier:x; 26, identifier:chrom; 27, identifier:i; 28, function_definition; 28, 29; 28, 30; 28, 32; 29, function_name:wchrom_key; 30, parameters; 30, 31; 31, identifier:x; 32, block; 32, 33; 32, 40; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 39; 35, pattern_list; 35, 36; 35, 37; 35, 38; 36, identifier:chrom; 37, identifier:start; 38, identifier:end; 39, identifier:x; 40, return_statement; 40, 41; 41, tuple; 41, 42; 41, 45; 41, 46; 42, subscript; 42, 43; 42, 44; 43, identifier:chrom_order; 44, identifier:chrom; 45, identifier:start; 46, identifier:end; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:all_intervals; 50, list:[]; 51, for_statement; 51, 52; 51, 53; 51, 54; 52, identifier:region_group; 53, identifier:all_regions; 54, block; 54, 55; 55, for_statement; 55, 56; 55, 57; 55, 58; 56, identifier:region; 57, identifier:region_group; 58, block; 58, 59; 59, expression_statement; 59, 60; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:all_intervals; 63, identifier:append; 64, argument_list; 64, 65; 65, tuple; 65, 66; 65, 69; 65, 75; 66, attribute; 66, 67; 66, 68; 67, identifier:region; 68, identifier:chrom; 69, call; 69, 70; 69, 71; 70, identifier:int; 71, argument_list; 71, 72; 72, attribute; 72, 73; 72, 74; 73, identifier:region; 74, identifier:start; 75, call; 75, 76; 75, 77; 76, identifier:int; 77, argument_list; 77, 78; 78, attribute; 78, 79; 78, 80; 79, identifier:region; 80, identifier:stop; 81, expression_statement; 81, 82; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:all_intervals; 85, identifier:sort; 86, argument_list; 86, 87; 87, keyword_argument; 87, 88; 87, 89; 88, identifier:key; 89, identifier:wchrom_key; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:bed_lines; 93, list_comprehension; 93, 94; 93, 100; 94, binary_operator:%; 94, 95; 94, 96; 95, string:"%s\t%s\t%s"; 96, tuple; 96, 97; 96, 98; 96, 99; 97, identifier:c; 98, identifier:s; 99, identifier:e; 100, for_in_clause; 100, 101; 100, 105; 101, tuple_pattern; 101, 102; 101, 103; 101, 104; 102, identifier:c; 103, identifier:s; 104, identifier:e; 105, identifier:all_intervals; 106, return_statement; 106, 107; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:pybedtools; 110, identifier:BedTool; 111, argument_list; 111, 112; 111, 118; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, string:"\n"; 115, identifier:join; 116, argument_list; 116, 117; 117, identifier:bed_lines; 118, keyword_argument; 118, 119; 118, 120; 119, identifier:from_string; 120, True | def _combine_regions(all_regions, ref_regions):
chrom_order = {}
for i, x in enumerate(ref_regions):
chrom_order[x.chrom] = i
def wchrom_key(x):
chrom, start, end = x
return (chrom_order[chrom], start, end)
all_intervals = []
for region_group in all_regions:
for region in region_group:
all_intervals.append((region.chrom, int(region.start), int(region.stop)))
all_intervals.sort(key=wchrom_key)
bed_lines = ["%s\t%s\t%s" % (c, s, e) for (c, s, e) in all_intervals]
return pybedtools.BedTool("\n".join(bed_lines), from_string=True) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:_add_meta; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:xs; 5, default_parameter; 5, 6; 5, 7; 6, identifier:sample; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:config; 10, None; 11, block; 11, 12; 11, 16; 11, 153; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:out; 15, list:[]; 16, for_statement; 16, 17; 16, 18; 16, 19; 17, identifier:x; 18, identifier:xs; 19, block; 19, 20; 19, 51; 19, 64; 19, 100; 19, 146; 20, if_statement; 20, 21; 20, 43; 21, boolean_operator:or; 21, 22; 21, 32; 22, not_operator; 22, 23; 23, call; 23, 24; 23, 25; 24, identifier:isinstance; 25, argument_list; 25, 26; 25, 29; 26, subscript; 26, 27; 26, 28; 27, identifier:x; 28, string:"path"; 29, attribute; 29, 30; 29, 31; 30, identifier:six; 31, identifier:string_types; 32, not_operator; 32, 33; 33, call; 33, 34; 33, 39; 34, attribute; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:os; 37, identifier:path; 38, identifier:exists; 39, argument_list; 39, 40; 40, subscript; 40, 41; 40, 42; 41, identifier:x; 42, string:"path"; 43, block; 43, 44; 44, raise_statement; 44, 45; 45, call; 45, 46; 45, 47; 46, identifier:ValueError; 47, argument_list; 47, 48; 48, binary_operator:%; 48, 49; 48, 50; 49, string:"Unexpected path for upload: %s"; 50, identifier:x; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 56; 53, subscript; 53, 54; 53, 55; 54, identifier:x; 55, string:"mtime"; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:shared; 59, identifier:get_file_timestamp; 60, argument_list; 60, 61; 61, subscript; 61, 62; 61, 63; 62, identifier:x; 63, string:"path"; 64, if_statement; 64, 65; 64, 66; 65, identifier:sample; 66, block; 66, 67; 66, 76; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:sample_name; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:dd; 73, identifier:get_sample_name; 74, argument_list; 74, 75; 75, identifier:sample; 76, if_statement; 76, 77; 76, 80; 76, 87; 77, comparison_operator:not; 77, 78; 77, 79; 78, string:"sample"; 79, identifier:x; 80, block; 80, 81; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 86; 83, subscript; 83, 84; 83, 85; 84, identifier:x; 85, string:"sample"; 86, identifier:sample_name; 87, elif_clause; 87, 88; 87, 93; 88, comparison_operator:!=; 88, 89; 88, 92; 89, subscript; 89, 90; 89, 91; 90, identifier:x; 91, string:"sample"; 92, identifier:sample_name; 93, block; 93, 94; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 99; 96, subscript; 96, 97; 96, 98; 97, identifier:x; 98, string:"run"; 99, identifier:sample_name; 100, if_statement; 100, 101; 100, 102; 101, identifier:config; 102, block; 102, 103; 102, 114; 102, 136; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:fc_name; 106, boolean_operator:or; 106, 107; 106, 113; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:config; 110, identifier:get; 111, argument_list; 111, 112; 112, string:"fc_name"; 113, string:"project"; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:fc_date; 117, boolean_operator:or; 117, 118; 117, 124; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:config; 121, identifier:get; 122, argument_list; 122, 123; 123, string:"fc_date"; 124, call; 124, 125; 124, 134; 125, attribute; 125, 126; 125, 133; 126, call; 126, 127; 126, 132; 127, attribute; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:datetime; 130, identifier:datetime; 131, identifier:now; 132, argument_list; 133, identifier:strftime; 134, argument_list; 134, 135; 135, string:"%Y-%m-%d"; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 141; 138, subscript; 138, 139; 138, 140; 139, identifier:x; 140, string:"run"; 141, binary_operator:%; 141, 142; 141, 143; 142, string:"%s_%s"; 143, tuple; 143, 144; 143, 145; 144, identifier:fc_date; 145, identifier:fc_name; 146, expression_statement; 146, 147; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:out; 150, identifier:append; 151, argument_list; 151, 152; 152, identifier:x; 153, return_statement; 153, 154; 154, identifier:out | def _add_meta(xs, sample=None, config=None):
out = []
for x in xs:
if not isinstance(x["path"], six.string_types) or not os.path.exists(x["path"]):
raise ValueError("Unexpected path for upload: %s" % x)
x["mtime"] = shared.get_file_timestamp(x["path"])
if sample:
sample_name = dd.get_sample_name(sample)
if "sample" not in x:
x["sample"] = sample_name
elif x["sample"] != sample_name:
x["run"] = sample_name
if config:
fc_name = config.get("fc_name") or "project"
fc_date = config.get("fc_date") or datetime.datetime.now().strftime("%Y-%m-%d")
x["run"] = "%s_%s" % (fc_date, fc_name)
out.append(x)
return out |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:report; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 4, identifier:self; 5, identifier:align_bam; 6, identifier:ref_file; 7, identifier:is_paired; 8, identifier:bait_file; 9, identifier:target_file; 10, identifier:variant_region_file; 11, identifier:config; 12, block; 12, 13; 12, 22; 12, 32; 12, 36; 12, 46; 12, 60; 12, 144; 12, 153; 12, 168; 12, 172; 12, 193; 12, 214; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:dup_metrics; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:_get_current_dup_metrics; 20, argument_list; 20, 21; 21, identifier:align_bam; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:align_metrics; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:_collect_align_metrics; 29, argument_list; 29, 30; 29, 31; 30, identifier:align_bam; 31, identifier:ref_file; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:gc_graph; 35, None; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 42; 38, pattern_list; 38, 39; 38, 40; 38, 41; 39, identifier:insert_graph; 40, identifier:insert_metrics; 41, identifier:hybrid_metrics; 42, tuple; 42, 43; 42, 44; 42, 45; 43, None; 44, None; 45, None; 46, if_statement; 46, 47; 46, 48; 47, identifier:is_paired; 48, block; 48, 49; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 54; 51, pattern_list; 51, 52; 51, 53; 52, identifier:insert_graph; 53, identifier:insert_metrics; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:_insert_sizes; 58, argument_list; 58, 59; 59, identifier:align_bam; 60, if_statement; 60, 61; 60, 64; 60, 100; 61, boolean_operator:and; 61, 62; 61, 63; 62, identifier:bait_file; 63, identifier:target_file; 64, block; 64, 65; 64, 77; 64, 89; 65, assert_statement; 65, 66; 65, 74; 66, call; 66, 67; 66, 72; 67, attribute; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:os; 70, identifier:path; 71, identifier:exists; 72, argument_list; 72, 73; 73, identifier:bait_file; 74, tuple; 74, 75; 74, 76; 75, identifier:bait_file; 76, string:"does not exist!"; 77, assert_statement; 77, 78; 77, 86; 78, call; 78, 79; 78, 84; 79, attribute; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:os; 82, identifier:path; 83, identifier:exists; 84, argument_list; 84, 85; 85, identifier:target_file; 86, tuple; 86, 87; 86, 88; 87, identifier:target_file; 88, string:"does not exist!"; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:hybrid_metrics; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:self; 95, identifier:_hybrid_select_metrics; 96, argument_list; 96, 97; 96, 98; 96, 99; 97, identifier:align_bam; 98, identifier:bait_file; 99, identifier:target_file; 100, elif_clause; 100, 101; 100, 120; 101, parenthesized_expression; 101, 102; 102, boolean_operator:and; 102, 103; 102, 104; 103, identifier:variant_region_file; 104, comparison_operator:in; 104, 105; 104, 118; 105, call; 105, 106; 105, 117; 106, attribute; 106, 107; 106, 116; 107, call; 107, 108; 107, 113; 108, attribute; 108, 109; 108, 112; 109, subscript; 109, 110; 109, 111; 110, identifier:config; 111, string:"algorithm"; 112, identifier:get; 113, argument_list; 113, 114; 113, 115; 114, string:"coverage_interval"; 115, string:""; 116, identifier:lower; 117, argument_list; 118, list:["exome"]; 118, 119; 119, string:"exome"; 120, block; 120, 121; 120, 133; 121, assert_statement; 121, 122; 121, 130; 122, call; 122, 123; 122, 128; 123, attribute; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:os; 126, identifier:path; 127, identifier:exists; 128, argument_list; 128, 129; 129, identifier:variant_region_file; 130, tuple; 130, 131; 130, 132; 131, identifier:variant_region_file; 132, string:"does not exist"; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:hybrid_metrics; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:self; 139, identifier:_hybrid_select_metrics; 140, argument_list; 140, 141; 140, 142; 140, 143; 141, identifier:align_bam; 142, identifier:variant_region_file; 143, identifier:variant_region_file; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:vrn_vals; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:self; 150, identifier:_variant_eval_metrics; 151, argument_list; 151, 152; 152, identifier:align_bam; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 156; 155, identifier:summary_info; 156, call; 156, 157; 156, 162; 157, attribute; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:self; 160, identifier:_parser; 161, identifier:get_summary_metrics; 162, argument_list; 162, 163; 162, 164; 162, 165; 162, 166; 162, 167; 163, identifier:align_metrics; 164, identifier:dup_metrics; 165, identifier:insert_metrics; 166, identifier:hybrid_metrics; 167, identifier:vrn_vals; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:graphs; 171, list:[]; 172, if_statement; 172, 173; 172, 183; 173, boolean_operator:and; 173, 174; 173, 175; 174, identifier:gc_graph; 175, call; 175, 176; 175, 181; 176, attribute; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:os; 179, identifier:path; 180, identifier:exists; 181, argument_list; 181, 182; 182, identifier:gc_graph; 183, block; 183, 184; 184, expression_statement; 184, 185; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:graphs; 188, identifier:append; 189, argument_list; 189, 190; 190, tuple; 190, 191; 190, 192; 191, identifier:gc_graph; 192, string:"Distribution of GC content across reads"; 193, if_statement; 193, 194; 193, 204; 194, boolean_operator:and; 194, 195; 194, 196; 195, identifier:insert_graph; 196, call; 196, 197; 196, 202; 197, attribute; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:os; 200, identifier:path; 201, identifier:exists; 202, argument_list; 202, 203; 203, identifier:insert_graph; 204, block; 204, 205; 205, expression_statement; 205, 206; 206, call; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:graphs; 209, identifier:append; 210, argument_list; 210, 211; 211, tuple; 211, 212; 211, 213; 212, identifier:insert_graph; 213, string:"Distribution of paired end insert sizes"; 214, return_statement; 214, 215; 215, expression_list; 215, 216; 215, 217; 216, identifier:summary_info; 217, identifier:graphs | def report(self, align_bam, ref_file, is_paired, bait_file, target_file,
variant_region_file, config):
dup_metrics = self._get_current_dup_metrics(align_bam)
align_metrics = self._collect_align_metrics(align_bam, ref_file)
gc_graph = None
insert_graph, insert_metrics, hybrid_metrics = (None, None, None)
if is_paired:
insert_graph, insert_metrics = self._insert_sizes(align_bam)
if bait_file and target_file:
assert os.path.exists(bait_file), (bait_file, "does not exist!")
assert os.path.exists(target_file), (target_file, "does not exist!")
hybrid_metrics = self._hybrid_select_metrics(align_bam,
bait_file, target_file)
elif (variant_region_file and
config["algorithm"].get("coverage_interval", "").lower() in ["exome"]):
assert os.path.exists(variant_region_file), (variant_region_file, "does not exist")
hybrid_metrics = self._hybrid_select_metrics(
align_bam, variant_region_file, variant_region_file)
vrn_vals = self._variant_eval_metrics(align_bam)
summary_info = self._parser.get_summary_metrics(align_metrics,
dup_metrics, insert_metrics, hybrid_metrics,
vrn_vals)
graphs = []
if gc_graph and os.path.exists(gc_graph):
graphs.append((gc_graph, "Distribution of GC content across reads"))
if insert_graph and os.path.exists(insert_graph):
graphs.append((insert_graph, "Distribution of paired end insert sizes"))
return summary_info, graphs |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:report; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 11; 4, identifier:self; 5, identifier:align_bam; 6, identifier:ref_file; 7, identifier:gtf_file; 8, default_parameter; 8, 9; 8, 10; 9, identifier:is_paired; 10, False; 11, default_parameter; 11, 12; 11, 13; 12, identifier:rrna_file; 13, string:"null"; 14, block; 14, 15; 14, 24; 14, 34; 14, 42; 14, 56; 14, 67; 14, 85; 14, 89; 14, 106; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:dup_metrics; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:_get_current_dup_metrics; 22, argument_list; 22, 23; 23, identifier:align_bam; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:align_metrics; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:_collect_align_metrics; 31, argument_list; 31, 32; 31, 33; 32, identifier:align_bam; 33, identifier:ref_file; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 39; 36, pattern_list; 36, 37; 36, 38; 37, identifier:insert_graph; 38, identifier:insert_metrics; 39, tuple; 39, 40; 39, 41; 40, None; 41, None; 42, if_statement; 42, 43; 42, 44; 43, identifier:is_paired; 44, block; 44, 45; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 50; 47, pattern_list; 47, 48; 47, 49; 48, identifier:insert_graph; 49, identifier:insert_metrics; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:self; 53, identifier:_insert_sizes; 54, argument_list; 54, 55; 55, identifier:align_bam; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:rnaseq_metrics; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:_rnaseq_metrics; 63, argument_list; 63, 64; 63, 65; 63, 66; 64, identifier:align_bam; 65, identifier:gtf_file; 66, identifier:rrna_file; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:summary_info; 70, call; 70, 71; 70, 76; 71, attribute; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:self; 74, identifier:_parser; 75, identifier:get_summary_metrics; 76, argument_list; 76, 77; 76, 78; 76, 79; 76, 82; 77, identifier:align_metrics; 78, identifier:dup_metrics; 79, keyword_argument; 79, 80; 79, 81; 80, identifier:insert_metrics; 81, identifier:insert_metrics; 82, keyword_argument; 82, 83; 82, 84; 83, identifier:rnaseq_metrics; 84, identifier:rnaseq_metrics; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:graphs; 88, list:[]; 89, if_statement; 89, 90; 89, 96; 90, boolean_operator:and; 90, 91; 90, 92; 91, identifier:insert_graph; 92, call; 92, 93; 92, 94; 93, identifier:file_exists; 94, argument_list; 94, 95; 95, identifier:insert_graph; 96, block; 96, 97; 97, expression_statement; 97, 98; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:graphs; 101, identifier:append; 102, argument_list; 102, 103; 103, tuple; 103, 104; 103, 105; 104, identifier:insert_graph; 105, string:"Distribution of paired end insert sizes"; 106, return_statement; 106, 107; 107, expression_list; 107, 108; 107, 109; 108, identifier:summary_info; 109, identifier:graphs | def report(self, align_bam, ref_file, gtf_file, is_paired=False, rrna_file="null"):
dup_metrics = self._get_current_dup_metrics(align_bam)
align_metrics = self._collect_align_metrics(align_bam, ref_file)
insert_graph, insert_metrics = (None, None)
if is_paired:
insert_graph, insert_metrics = self._insert_sizes(align_bam)
rnaseq_metrics = self._rnaseq_metrics(align_bam, gtf_file, rrna_file)
summary_info = self._parser.get_summary_metrics(align_metrics,
dup_metrics,
insert_metrics=insert_metrics,
rnaseq_metrics=rnaseq_metrics)
graphs = []
if insert_graph and file_exists(insert_graph):
graphs.append((insert_graph,
"Distribution of paired end insert sizes"))
return summary_info, graphs |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:apply_recal; 3, parameters; 3, 4; 4, identifier:data; 5, block; 5, 6; 5, 22; 5, 28; 5, 141; 5, 163; 5, 200; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:orig_bam; 9, boolean_operator:or; 9, 10; 9, 16; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:dd; 13, identifier:get_align_bam; 14, argument_list; 14, 15; 15, identifier:data; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:dd; 19, identifier:get_work_bam; 20, argument_list; 20, 21; 21, identifier:data; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:had_work_bam; 25, comparison_operator:in; 25, 26; 25, 27; 26, string:"work_bam"; 27, identifier:data; 28, if_statement; 28, 29; 28, 39; 28, 74; 28, 120; 29, comparison_operator:in; 29, 30; 29, 36; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:dd; 33, identifier:get_recalibrate; 34, argument_list; 34, 35; 35, identifier:data; 36, list:[True, "gatk"]; 36, 37; 36, 38; 37, True; 38, string:"gatk"; 39, block; 39, 40; 40, if_statement; 40, 41; 40, 47; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:data; 44, identifier:get; 45, argument_list; 45, 46; 46, string:"prep_recal"; 47, block; 47, 48; 47, 65; 48, expression_statement; 48, 49; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:logger; 52, identifier:info; 53, argument_list; 53, 54; 54, binary_operator:%; 54, 55; 54, 56; 55, string:"Applying BQSR recalibration with GATK: %s "; 56, call; 56, 57; 56, 58; 57, identifier:str; 58, argument_list; 58, 59; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:dd; 62, identifier:get_sample_name; 63, argument_list; 63, 64; 64, identifier:data; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 70; 67, subscript; 67, 68; 67, 69; 68, identifier:data; 69, string:"work_bam"; 70, call; 70, 71; 70, 72; 71, identifier:_gatk_apply_bqsr; 72, argument_list; 72, 73; 73, identifier:data; 74, elif_clause; 74, 75; 74, 83; 75, comparison_operator:==; 75, 76; 75, 82; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:dd; 79, identifier:get_recalibrate; 80, argument_list; 80, 81; 81, identifier:data; 82, string:"sentieon"; 83, block; 83, 84; 84, if_statement; 84, 85; 84, 91; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:data; 88, identifier:get; 89, argument_list; 89, 90; 90, string:"prep_recal"; 91, block; 91, 92; 91, 109; 92, expression_statement; 92, 93; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:logger; 96, identifier:info; 97, argument_list; 97, 98; 98, binary_operator:%; 98, 99; 98, 100; 99, string:"Applying BQSR recalibration with sentieon: %s "; 100, call; 100, 101; 100, 102; 101, identifier:str; 102, argument_list; 102, 103; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:dd; 106, identifier:get_sample_name; 107, argument_list; 107, 108; 108, identifier:data; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 114; 111, subscript; 111, 112; 111, 113; 112, identifier:data; 113, string:"work_bam"; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:sentieon; 117, identifier:apply_bqsr; 118, argument_list; 118, 119; 119, identifier:data; 120, elif_clause; 120, 121; 120, 127; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:dd; 124, identifier:get_recalibrate; 125, argument_list; 125, 126; 126, identifier:data; 127, block; 127, 128; 128, raise_statement; 128, 129; 129, call; 129, 130; 129, 131; 130, identifier:NotImplementedError; 131, argument_list; 131, 132; 132, binary_operator:%; 132, 133; 132, 134; 133, string:"Unsupported recalibration type: %s"; 134, parenthesized_expression; 134, 135; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:dd; 138, identifier:get_recalibrate; 139, argument_list; 139, 140; 140, identifier:data; 141, if_statement; 141, 142; 141, 151; 142, boolean_operator:and; 142, 143; 142, 145; 143, not_operator; 143, 144; 144, identifier:had_work_bam; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:dd; 148, identifier:get_work_bam; 149, argument_list; 149, 150; 150, identifier:data; 151, block; 151, 152; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 157; 154, subscript; 154, 155; 154, 156; 155, identifier:data; 156, string:"align_bam"; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:dd; 160, identifier:get_work_bam; 161, argument_list; 161, 162; 162, identifier:data; 163, if_statement; 163, 164; 163, 181; 164, boolean_operator:and; 164, 165; 164, 173; 165, comparison_operator:!=; 165, 166; 165, 167; 166, identifier:orig_bam; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:dd; 170, identifier:get_work_bam; 171, argument_list; 171, 172; 172, identifier:data; 173, comparison_operator:!=; 173, 174; 173, 175; 174, identifier:orig_bam; 175, call; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:dd; 178, identifier:get_align_bam; 179, argument_list; 179, 180; 180, identifier:data; 181, block; 181, 182; 182, expression_statement; 182, 183; 183, call; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:utils; 186, identifier:save_diskspace; 187, argument_list; 187, 188; 187, 189; 187, 197; 188, identifier:orig_bam; 189, binary_operator:%; 189, 190; 189, 191; 190, string:"BAM recalibrated to %s"; 191, call; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:dd; 194, identifier:get_work_bam; 195, argument_list; 195, 196; 196, identifier:data; 197, subscript; 197, 198; 197, 199; 198, identifier:data; 199, string:"config"; 200, return_statement; 200, 201; 201, identifier:data | def apply_recal(data):
orig_bam = dd.get_align_bam(data) or dd.get_work_bam(data)
had_work_bam = "work_bam" in data
if dd.get_recalibrate(data) in [True, "gatk"]:
if data.get("prep_recal"):
logger.info("Applying BQSR recalibration with GATK: %s " % str(dd.get_sample_name(data)))
data["work_bam"] = _gatk_apply_bqsr(data)
elif dd.get_recalibrate(data) == "sentieon":
if data.get("prep_recal"):
logger.info("Applying BQSR recalibration with sentieon: %s " % str(dd.get_sample_name(data)))
data["work_bam"] = sentieon.apply_bqsr(data)
elif dd.get_recalibrate(data):
raise NotImplementedError("Unsupported recalibration type: %s" % (dd.get_recalibrate(data)))
if not had_work_bam and dd.get_work_bam(data):
data["align_bam"] = dd.get_work_bam(data)
if orig_bam != dd.get_work_bam(data) and orig_bam != dd.get_align_bam(data):
utils.save_diskspace(orig_bam, "BAM recalibrated to %s" % dd.get_work_bam(data), data["config"])
return data |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_prep_callable_bed; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:in_file; 5, identifier:work_dir; 6, identifier:stats; 7, identifier:data; 8, block; 8, 9; 8, 37; 8, 47; 8, 106; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:out_file; 12, call; 12, 13; 12, 18; 13, attribute; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:os; 16, identifier:path; 17, identifier:join; 18, argument_list; 18, 19; 18, 20; 19, identifier:work_dir; 20, binary_operator:%; 20, 21; 20, 22; 21, string:"%s-merge.bed.gz"; 22, subscript; 22, 23; 22, 36; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:utils; 26, identifier:splitext_plus; 27, argument_list; 27, 28; 28, call; 28, 29; 28, 34; 29, attribute; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:os; 32, identifier:path; 33, identifier:basename; 34, argument_list; 34, 35; 35, identifier:in_file; 36, integer:0; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:gsort; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:config_utils; 43, identifier:get_program; 44, argument_list; 44, 45; 44, 46; 45, string:"gsort"; 46, identifier:data; 47, if_statement; 47, 48; 47, 56; 48, not_operator; 48, 49; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:utils; 52, identifier:file_uptodate; 53, argument_list; 53, 54; 53, 55; 54, identifier:out_file; 55, identifier:in_file; 56, block; 56, 57; 57, with_statement; 57, 58; 57, 68; 58, with_clause; 58, 59; 59, with_item; 59, 60; 60, as_pattern; 60, 61; 60, 66; 61, call; 61, 62; 61, 63; 62, identifier:file_transaction; 63, argument_list; 63, 64; 63, 65; 64, identifier:data; 65, identifier:out_file; 66, as_pattern_target; 66, 67; 67, identifier:tx_out_file; 68, block; 68, 69; 68, 83; 68, 90; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:fai_file; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:ref; 75, identifier:fasta_idx; 76, argument_list; 76, 77; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:dd; 80, identifier:get_ref_file; 81, argument_list; 81, 82; 82, identifier:data; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:cmd; 86, parenthesized_expression; 86, 87; 87, concatenated_string; 87, 88; 87, 89; 88, string:"{gsort} {in_file} {fai_file} | bedtools merge -i - -d {stats[merge_size]} | "; 89, string:"bgzip -c > {tx_out_file}"; 90, expression_statement; 90, 91; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:do; 94, identifier:run; 95, argument_list; 95, 96; 95, 105; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:cmd; 99, identifier:format; 100, argument_list; 100, 101; 101, dictionary_splat; 101, 102; 102, call; 102, 103; 102, 104; 103, identifier:locals; 104, argument_list; 105, string:"Prepare SV callable BED regions"; 106, return_statement; 106, 107; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:vcfutils; 110, identifier:bgzip_and_index; 111, argument_list; 111, 112; 111, 113; 112, identifier:out_file; 113, subscript; 113, 114; 113, 115; 114, identifier:data; 115, string:"config" | def _prep_callable_bed(in_file, work_dir, stats, data):
out_file = os.path.join(work_dir, "%s-merge.bed.gz" % utils.splitext_plus(os.path.basename(in_file))[0])
gsort = config_utils.get_program("gsort", data)
if not utils.file_uptodate(out_file, in_file):
with file_transaction(data, out_file) as tx_out_file:
fai_file = ref.fasta_idx(dd.get_ref_file(data))
cmd = ("{gsort} {in_file} {fai_file} | bedtools merge -i - -d {stats[merge_size]} | "
"bgzip -c > {tx_out_file}")
do.run(cmd.format(**locals()), "Prepare SV callable BED regions")
return vcfutils.bgzip_and_index(out_file, data["config"]) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:fake_index; 3, parameters; 3, 4; 3, 5; 4, identifier:in_bam; 5, identifier:data; 6, block; 6, 7; 6, 13; 6, 53; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:index_file; 10, binary_operator:%; 10, 11; 10, 12; 11, string:"%s.bai"; 12, identifier:in_bam; 13, if_statement; 13, 14; 13, 21; 14, not_operator; 14, 15; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:utils; 18, identifier:file_exists; 19, argument_list; 19, 20; 20, identifier:index_file; 21, block; 21, 22; 22, with_statement; 22, 23; 22, 33; 23, with_clause; 23, 24; 24, with_item; 24, 25; 25, as_pattern; 25, 26; 25, 31; 26, call; 26, 27; 26, 28; 27, identifier:file_transaction; 28, argument_list; 28, 29; 28, 30; 29, identifier:data; 30, identifier:index_file; 31, as_pattern_target; 31, 32; 32, identifier:tx_out_file; 33, block; 33, 34; 34, with_statement; 34, 35; 34, 45; 35, with_clause; 35, 36; 36, with_item; 36, 37; 37, as_pattern; 37, 38; 37, 43; 38, call; 38, 39; 38, 40; 39, identifier:open; 40, argument_list; 40, 41; 40, 42; 41, identifier:tx_out_file; 42, string:"w"; 43, as_pattern_target; 43, 44; 44, identifier:out_handle; 45, block; 45, 46; 46, expression_statement; 46, 47; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:out_handle; 50, identifier:write; 51, argument_list; 51, 52; 52, string:"name sorted -- no index"; 53, return_statement; 53, 54; 54, identifier:index_file | def fake_index(in_bam, data):
index_file = "%s.bai" % in_bam
if not utils.file_exists(index_file):
with file_transaction(data, index_file) as tx_out_file:
with open(tx_out_file, "w") as out_handle:
out_handle.write("name sorted -- no index")
return index_file |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:sort; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:in_bam; 5, identifier:config; 6, default_parameter; 6, 7; 6, 8; 7, identifier:order; 8, string:"coordinate"; 9, default_parameter; 9, 10; 9, 11; 10, identifier:out_dir; 11, None; 12, block; 12, 13; 12, 21; 12, 31; 12, 40; 12, 46; 12, 203; 13, assert_statement; 13, 14; 13, 18; 14, call; 14, 15; 14, 16; 15, identifier:is_bam; 16, argument_list; 16, 17; 17, identifier:in_bam; 18, binary_operator:%; 18, 19; 18, 20; 19, string:"%s in not a BAM file"; 20, identifier:in_bam; 21, if_statement; 21, 22; 21, 28; 22, call; 22, 23; 22, 24; 23, identifier:bam_already_sorted; 24, argument_list; 24, 25; 24, 26; 24, 27; 25, identifier:in_bam; 26, identifier:config; 27, identifier:order; 28, block; 28, 29; 29, return_statement; 29, 30; 30, identifier:in_bam; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:sort_stem; 34, call; 34, 35; 34, 36; 35, identifier:_get_sort_stem; 36, argument_list; 36, 37; 36, 38; 36, 39; 37, identifier:in_bam; 38, identifier:order; 39, identifier:out_dir; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:sort_file; 43, binary_operator:+; 43, 44; 43, 45; 44, identifier:sort_stem; 45, string:".bam"; 46, if_statement; 46, 47; 46, 54; 47, not_operator; 47, 48; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:utils; 51, identifier:file_exists; 52, argument_list; 52, 53; 53, identifier:sort_file; 54, block; 54, 55; 54, 65; 54, 77; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:samtools; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:config_utils; 61, identifier:get_program; 62, argument_list; 62, 63; 62, 64; 63, string:"samtools"; 64, identifier:config; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:cores; 68, call; 68, 69; 68, 74; 69, attribute; 69, 70; 69, 73; 70, subscript; 70, 71; 70, 72; 71, identifier:config; 72, string:"algorithm"; 73, identifier:get; 74, argument_list; 74, 75; 74, 76; 75, string:"num_cores"; 76, integer:1; 77, with_statement; 77, 78; 77, 88; 78, with_clause; 78, 79; 79, with_item; 79, 80; 80, as_pattern; 80, 81; 80, 86; 81, call; 81, 82; 81, 83; 82, identifier:file_transaction; 83, argument_list; 83, 84; 83, 85; 84, identifier:config; 85, identifier:sort_file; 86, as_pattern_target; 86, 87; 87, identifier:tx_sort_file; 88, block; 88, 89; 88, 102; 88, 118; 88, 127; 88, 137; 88, 161; 88, 168; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:tx_sort_stem; 92, subscript; 92, 93; 92, 101; 93, call; 93, 94; 93, 99; 94, attribute; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:os; 97, identifier:path; 98, identifier:splitext; 99, argument_list; 99, 100; 100, identifier:tx_sort_file; 101, integer:0; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:tx_dir; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:utils; 108, identifier:safe_makedir; 109, argument_list; 109, 110; 110, call; 110, 111; 110, 116; 111, attribute; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:os; 114, identifier:path; 115, identifier:dirname; 116, argument_list; 116, 117; 117, identifier:tx_sort_file; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:order_flag; 121, conditional_expression:if; 121, 122; 121, 123; 121, 126; 122, string:"-n"; 123, comparison_operator:==; 123, 124; 123, 125; 124, identifier:order; 125, string:"queryname"; 126, string:""; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:resources; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:config_utils; 133, identifier:get_resources; 134, argument_list; 134, 135; 134, 136; 135, string:"samtools"; 136, identifier:config; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:mem; 140, call; 140, 141; 140, 160; 141, attribute; 141, 142; 141, 159; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:config_utils; 145, identifier:adjust_memory; 146, argument_list; 146, 147; 146, 154; 146, 155; 146, 156; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:resources; 150, identifier:get; 151, argument_list; 151, 152; 151, 153; 152, string:"memory"; 153, string:"2G"; 154, float:1.25; 155, string:"decrease"; 156, keyword_argument; 156, 157; 156, 158; 157, identifier:out_modifier; 158, string:"M"; 159, identifier:upper; 160, argument_list; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:cmd; 164, parenthesized_expression; 164, 165; 165, concatenated_string; 165, 166; 165, 167; 166, string:"{samtools} sort -@ {cores} -m {mem} -O BAM {order_flag} "; 167, string:"-T {tx_sort_stem}-sort -o {tx_sort_file} {in_bam}"; 168, expression_statement; 168, 169; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:do; 172, identifier:run; 173, argument_list; 173, 174; 173, 183; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:cmd; 177, identifier:format; 178, argument_list; 178, 179; 179, dictionary_splat; 179, 180; 180, call; 180, 181; 180, 182; 181, identifier:locals; 182, argument_list; 183, binary_operator:%; 183, 184; 183, 185; 184, string:"Sort BAM file %s: %s to %s"; 185, tuple; 185, 186; 185, 187; 185, 195; 186, identifier:order; 187, call; 187, 188; 187, 193; 188, attribute; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:os; 191, identifier:path; 192, identifier:basename; 193, argument_list; 193, 194; 194, identifier:in_bam; 195, call; 195, 196; 195, 201; 196, attribute; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:os; 199, identifier:path; 200, identifier:basename; 201, argument_list; 201, 202; 202, identifier:sort_file; 203, return_statement; 203, 204; 204, identifier:sort_file | def sort(in_bam, config, order="coordinate", out_dir=None):
assert is_bam(in_bam), "%s in not a BAM file" % in_bam
if bam_already_sorted(in_bam, config, order):
return in_bam
sort_stem = _get_sort_stem(in_bam, order, out_dir)
sort_file = sort_stem + ".bam"
if not utils.file_exists(sort_file):
samtools = config_utils.get_program("samtools", config)
cores = config["algorithm"].get("num_cores", 1)
with file_transaction(config, sort_file) as tx_sort_file:
tx_sort_stem = os.path.splitext(tx_sort_file)[0]
tx_dir = utils.safe_makedir(os.path.dirname(tx_sort_file))
order_flag = "-n" if order == "queryname" else ""
resources = config_utils.get_resources("samtools", config)
mem = config_utils.adjust_memory(resources.get("memory", "2G"),
1.25, "decrease", out_modifier="M").upper()
cmd = ("{samtools} sort -@ {cores} -m {mem} -O BAM {order_flag} "
"-T {tx_sort_stem}-sort -o {tx_sort_file} {in_bam}")
do.run(cmd.format(**locals()), "Sort BAM file %s: %s to %s" %
(order, os.path.basename(in_bam), os.path.basename(sort_file)))
return sort_file |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:tobam_cl; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:data; 5, identifier:out_file; 6, default_parameter; 6, 7; 6, 8; 7, identifier:is_paired; 8, False; 9, block; 9, 10; 9, 17; 9, 26; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:do_dedup; 13, call; 13, 14; 13, 15; 14, identifier:_check_dedup; 15, argument_list; 15, 16; 16, identifier:data; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:umi_consensus; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:dd; 23, identifier:get_umi_consensus; 24, argument_list; 24, 25; 25, identifier:data; 26, with_statement; 26, 27; 26, 37; 27, with_clause; 27, 28; 28, with_item; 28, 29; 29, as_pattern; 29, 30; 29, 35; 30, call; 30, 31; 30, 32; 31, identifier:file_transaction; 32, argument_list; 32, 33; 32, 34; 33, identifier:data; 34, identifier:out_file; 35, as_pattern_target; 35, 36; 36, identifier:tx_out_file; 37, block; 37, 38; 38, if_statement; 38, 39; 38, 41; 38, 51; 38, 64; 38, 148; 39, not_operator; 39, 40; 40, identifier:do_dedup; 41, block; 41, 42; 42, expression_statement; 42, 43; 43, yield; 43, 44; 44, tuple; 44, 45; 44, 50; 45, call; 45, 46; 45, 47; 46, identifier:sam_to_sortbam_cl; 47, argument_list; 47, 48; 47, 49; 48, identifier:data; 49, identifier:tx_out_file; 50, identifier:tx_out_file; 51, elif_clause; 51, 52; 51, 53; 52, identifier:umi_consensus; 53, block; 53, 54; 54, expression_statement; 54, 55; 55, yield; 55, 56; 56, tuple; 56, 57; 56, 63; 57, call; 57, 58; 57, 59; 58, identifier:_sam_to_grouped_umi_cl; 59, argument_list; 59, 60; 59, 61; 59, 62; 60, identifier:data; 61, identifier:umi_consensus; 62, identifier:tx_out_file; 63, identifier:tx_out_file; 64, elif_clause; 64, 65; 64, 82; 65, boolean_operator:and; 65, 66; 65, 72; 66, boolean_operator:and; 66, 67; 66, 68; 67, identifier:is_paired; 68, call; 68, 69; 68, 70; 69, identifier:_need_sr_disc_reads; 70, argument_list; 70, 71; 71, identifier:data; 72, not_operator; 72, 73; 73, call; 73, 74; 73, 75; 74, identifier:_too_many_contigs; 75, argument_list; 75, 76; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:dd; 79, identifier:get_ref_file; 80, argument_list; 80, 81; 81, identifier:data; 82, block; 82, 83; 82, 98; 82, 113; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:sr_file; 86, binary_operator:%; 86, 87; 86, 88; 87, string:"%s-sr.bam"; 88, subscript; 88, 89; 88, 97; 89, call; 89, 90; 89, 95; 90, attribute; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:os; 93, identifier:path; 94, identifier:splitext; 95, argument_list; 95, 96; 96, identifier:out_file; 97, integer:0; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:disc_file; 101, binary_operator:%; 101, 102; 101, 103; 102, string:"%s-disc.bam"; 103, subscript; 103, 104; 103, 112; 104, call; 104, 105; 104, 110; 105, attribute; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:os; 108, identifier:path; 109, identifier:splitext; 110, argument_list; 110, 111; 111, identifier:out_file; 112, integer:0; 113, with_statement; 113, 114; 113, 124; 114, with_clause; 114, 115; 115, with_item; 115, 116; 116, as_pattern; 116, 117; 116, 122; 117, call; 117, 118; 117, 119; 118, identifier:file_transaction; 119, argument_list; 119, 120; 119, 121; 120, identifier:data; 121, identifier:sr_file; 122, as_pattern_target; 122, 123; 123, identifier:tx_sr_file; 124, block; 124, 125; 125, with_statement; 125, 126; 125, 136; 126, with_clause; 126, 127; 127, with_item; 127, 128; 128, as_pattern; 128, 129; 128, 134; 129, call; 129, 130; 129, 131; 130, identifier:file_transaction; 131, argument_list; 131, 132; 131, 133; 132, identifier:data; 133, identifier:disc_file; 134, as_pattern_target; 134, 135; 135, identifier:tx_disc_file; 136, block; 136, 137; 137, expression_statement; 137, 138; 138, yield; 138, 139; 139, tuple; 139, 140; 139, 147; 140, call; 140, 141; 140, 142; 141, identifier:samblaster_dedup_sort; 142, argument_list; 142, 143; 142, 144; 142, 145; 142, 146; 143, identifier:data; 144, identifier:tx_out_file; 145, identifier:tx_sr_file; 146, identifier:tx_disc_file; 147, identifier:tx_out_file; 148, else_clause; 148, 149; 149, block; 149, 150; 150, expression_statement; 150, 151; 151, yield; 151, 152; 152, tuple; 152, 153; 152, 158; 153, call; 153, 154; 153, 155; 154, identifier:_biobambam_dedup_sort; 155, argument_list; 155, 156; 155, 157; 156, identifier:data; 157, identifier:tx_out_file; 158, identifier:tx_out_file | def tobam_cl(data, out_file, is_paired=False):
do_dedup = _check_dedup(data)
umi_consensus = dd.get_umi_consensus(data)
with file_transaction(data, out_file) as tx_out_file:
if not do_dedup:
yield (sam_to_sortbam_cl(data, tx_out_file), tx_out_file)
elif umi_consensus:
yield (_sam_to_grouped_umi_cl(data, umi_consensus, tx_out_file), tx_out_file)
elif is_paired and _need_sr_disc_reads(data) and not _too_many_contigs(dd.get_ref_file(data)):
sr_file = "%s-sr.bam" % os.path.splitext(out_file)[0]
disc_file = "%s-disc.bam" % os.path.splitext(out_file)[0]
with file_transaction(data, sr_file) as tx_sr_file:
with file_transaction(data, disc_file) as tx_disc_file:
yield (samblaster_dedup_sort(data, tx_out_file, tx_sr_file, tx_disc_file),
tx_out_file)
else:
yield (_biobambam_dedup_sort(data, tx_out_file), tx_out_file) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:sam_to_sortbam_cl; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:data; 5, identifier:tx_out_file; 6, default_parameter; 6, 7; 6, 8; 7, identifier:name_sort; 8, False; 9, block; 9, 10; 9, 22; 9, 34; 9, 47; 9, 54; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:samtools; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:config_utils; 16, identifier:get_program; 17, argument_list; 17, 18; 17, 19; 18, string:"samtools"; 19, subscript; 19, 20; 19, 21; 20, identifier:data; 21, string:"config"; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 27; 24, pattern_list; 24, 25; 24, 26; 25, identifier:cores; 26, identifier:mem; 27, call; 27, 28; 27, 29; 28, identifier:_get_cores_memory; 29, argument_list; 29, 30; 29, 31; 30, identifier:data; 31, keyword_argument; 31, 32; 31, 33; 32, identifier:downscale; 33, integer:2; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:tmp_file; 37, binary_operator:%; 37, 38; 37, 39; 38, string:"%s-sorttmp"; 39, subscript; 39, 40; 39, 46; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:utils; 43, identifier:splitext_plus; 44, argument_list; 44, 45; 45, identifier:tx_out_file; 46, integer:0; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:sort_flag; 50, conditional_expression:if; 50, 51; 50, 52; 50, 53; 51, string:"-n"; 52, identifier:name_sort; 53, string:""; 54, return_statement; 54, 55; 55, parenthesized_expression; 55, 56; 56, call; 56, 57; 56, 62; 57, attribute; 57, 58; 57, 61; 58, concatenated_string; 58, 59; 58, 60; 59, string:"{samtools} sort -@ {cores} -m {mem} {sort_flag} "; 60, string:"-T {tmp_file} -o {tx_out_file} /dev/stdin"; 61, identifier:format; 62, argument_list; 62, 63; 63, dictionary_splat; 63, 64; 64, call; 64, 65; 64, 66; 65, identifier:locals; 66, argument_list | def sam_to_sortbam_cl(data, tx_out_file, name_sort=False):
samtools = config_utils.get_program("samtools", data["config"])
cores, mem = _get_cores_memory(data, downscale=2)
tmp_file = "%s-sorttmp" % utils.splitext_plus(tx_out_file)[0]
sort_flag = "-n" if name_sort else ""
return ("{samtools} sort -@ {cores} -m {mem} {sort_flag} "
"-T {tmp_file} -o {tx_out_file} /dev/stdin".format(**locals())) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:samblaster_dedup_sort; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:data; 5, identifier:tx_out_file; 6, identifier:tx_sr_file; 7, identifier:tx_disc_file; 8, block; 8, 9; 8, 21; 8, 33; 8, 46; 8, 51; 8, 63; 8, 81; 8, 100; 8, 148; 8, 152; 8, 164; 8, 184; 8, 204; 8, 211; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:samblaster; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:config_utils; 15, identifier:get_program; 16, argument_list; 16, 17; 16, 18; 17, string:"samblaster"; 18, subscript; 18, 19; 18, 20; 19, identifier:data; 20, string:"config"; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:samtools; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:config_utils; 27, identifier:get_program; 28, argument_list; 28, 29; 28, 30; 29, string:"samtools"; 30, subscript; 30, 31; 30, 32; 31, identifier:data; 32, string:"config"; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:tmp_prefix; 36, binary_operator:%; 36, 37; 36, 38; 37, string:"%s-sorttmp"; 38, subscript; 38, 39; 38, 45; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:utils; 42, identifier:splitext_plus; 43, argument_list; 43, 44; 44, identifier:tx_out_file; 45, integer:0; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:tobam_cmd; 49, parenthesized_expression; 49, 50; 50, string:"{samtools} sort {sort_opt} -@ {cores} -m {mem} -T {tmp_prefix}-{dext} {out_file} -"; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 56; 53, pattern_list; 53, 54; 53, 55; 54, identifier:cores; 55, identifier:mem; 56, call; 56, 57; 56, 58; 57, identifier:_get_cores_memory; 58, argument_list; 58, 59; 58, 60; 59, identifier:data; 60, keyword_argument; 60, 61; 60, 62; 61, identifier:downscale; 62, integer:2; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:ds_cmd; 66, conditional_expression:if; 66, 67; 66, 68; 66, 74; 67, None; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:data; 71, identifier:get; 72, argument_list; 72, 73; 73, string:"align_split"; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:bam; 77, identifier:get_maxcov_downsample_cl; 78, argument_list; 78, 79; 78, 80; 79, identifier:data; 80, string:"samtools"; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:sort_opt; 84, conditional_expression:if; 84, 85; 84, 86; 84, 99; 85, string:"-n"; 86, boolean_operator:and; 86, 87; 86, 93; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:data; 90, identifier:get; 91, argument_list; 91, 92; 92, string:"align_split"; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:dd; 96, identifier:get_mark_duplicates; 97, argument_list; 97, 98; 98, identifier:data; 99, string:""; 100, if_statement; 100, 101; 100, 102; 100, 126; 101, identifier:ds_cmd; 102, block; 102, 103; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:dedup_cmd; 106, binary_operator:%; 106, 107; 106, 108; 107, string:"%s %s > %s"; 108, tuple; 108, 109; 108, 124; 108, 125; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:tobam_cmd; 112, identifier:format; 113, argument_list; 113, 114; 113, 117; 113, 120; 114, keyword_argument; 114, 115; 114, 116; 115, identifier:out_file; 116, string:""; 117, keyword_argument; 117, 118; 117, 119; 118, identifier:dext; 119, string:"full"; 120, dictionary_splat; 120, 121; 121, call; 121, 122; 121, 123; 122, identifier:locals; 123, argument_list; 124, identifier:ds_cmd; 125, identifier:tx_out_file; 126, else_clause; 126, 127; 127, block; 127, 128; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:dedup_cmd; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:tobam_cmd; 134, identifier:format; 135, argument_list; 135, 136; 135, 141; 135, 144; 136, keyword_argument; 136, 137; 136, 138; 137, identifier:out_file; 138, binary_operator:%; 138, 139; 138, 140; 139, string:"-o %s"; 140, identifier:tx_out_file; 141, keyword_argument; 141, 142; 141, 143; 142, identifier:dext; 143, string:"full"; 144, dictionary_splat; 144, 145; 145, call; 145, 146; 145, 147; 146, identifier:locals; 147, argument_list; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 151; 150, identifier:sort_opt; 151, string:""; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 157; 154, pattern_list; 154, 155; 154, 156; 155, identifier:cores; 156, identifier:mem; 157, call; 157, 158; 157, 159; 158, identifier:_get_cores_memory; 159, argument_list; 159, 160; 159, 161; 160, identifier:data; 161, keyword_argument; 161, 162; 161, 163; 162, identifier:downscale; 163, integer:4; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 167; 166, identifier:splitter_cmd; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:tobam_cmd; 170, identifier:format; 171, argument_list; 171, 172; 171, 177; 171, 180; 172, keyword_argument; 172, 173; 172, 174; 173, identifier:out_file; 174, binary_operator:%; 174, 175; 174, 176; 175, string:"-o %s"; 176, identifier:tx_sr_file; 177, keyword_argument; 177, 178; 177, 179; 178, identifier:dext; 179, string:"spl"; 180, dictionary_splat; 180, 181; 181, call; 181, 182; 181, 183; 182, identifier:locals; 183, argument_list; 184, expression_statement; 184, 185; 185, assignment; 185, 186; 185, 187; 186, identifier:discordant_cmd; 187, call; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:tobam_cmd; 190, identifier:format; 191, argument_list; 191, 192; 191, 197; 191, 200; 192, keyword_argument; 192, 193; 192, 194; 193, identifier:out_file; 194, binary_operator:%; 194, 195; 194, 196; 195, string:"-o %s"; 196, identifier:tx_disc_file; 197, keyword_argument; 197, 198; 197, 199; 198, identifier:dext; 199, string:"disc"; 200, dictionary_splat; 200, 201; 201, call; 201, 202; 201, 203; 202, identifier:locals; 203, argument_list; 204, expression_statement; 204, 205; 205, assignment; 205, 206; 205, 207; 206, identifier:cmd; 207, parenthesized_expression; 207, 208; 208, concatenated_string; 208, 209; 208, 210; 209, string:"{samblaster} --addMateTags -M --splitterFile >({splitter_cmd}) --discordantFile >({discordant_cmd}) "; 210, string:"| {dedup_cmd}"; 211, return_statement; 211, 212; 212, call; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:cmd; 215, identifier:format; 216, argument_list; 216, 217; 217, dictionary_splat; 217, 218; 218, call; 218, 219; 218, 220; 219, identifier:locals; 220, argument_list | def samblaster_dedup_sort(data, tx_out_file, tx_sr_file, tx_disc_file):
samblaster = config_utils.get_program("samblaster", data["config"])
samtools = config_utils.get_program("samtools", data["config"])
tmp_prefix = "%s-sorttmp" % utils.splitext_plus(tx_out_file)[0]
tobam_cmd = ("{samtools} sort {sort_opt} -@ {cores} -m {mem} -T {tmp_prefix}-{dext} {out_file} -")
cores, mem = _get_cores_memory(data, downscale=2)
ds_cmd = None if data.get("align_split") else bam.get_maxcov_downsample_cl(data, "samtools")
sort_opt = "-n" if data.get("align_split") and dd.get_mark_duplicates(data) else ""
if ds_cmd:
dedup_cmd = "%s %s > %s" % (tobam_cmd.format(out_file="", dext="full", **locals()), ds_cmd, tx_out_file)
else:
dedup_cmd = tobam_cmd.format(out_file="-o %s" % tx_out_file, dext="full", **locals())
sort_opt = ""
cores, mem = _get_cores_memory(data, downscale=4)
splitter_cmd = tobam_cmd.format(out_file="-o %s" % tx_sr_file, dext="spl", **locals())
discordant_cmd = tobam_cmd.format(out_file="-o %s" % tx_disc_file, dext="disc", **locals())
cmd = ("{samblaster} --addMateTags -M --splitterFile >({splitter_cmd}) --discordantFile >({discordant_cmd}) "
"| {dedup_cmd}")
return cmd.format(**locals()) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_biobambam_dedup_sort; 3, parameters; 3, 4; 3, 5; 4, identifier:data; 5, identifier:tx_out_file; 6, block; 6, 7; 6, 19; 6, 31; 6, 44; 6, 124; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:samtools; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:config_utils; 13, identifier:get_program; 14, argument_list; 14, 15; 14, 16; 15, string:"samtools"; 16, subscript; 16, 17; 16, 18; 17, identifier:data; 18, string:"config"; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 24; 21, pattern_list; 21, 22; 21, 23; 22, identifier:cores; 23, identifier:mem; 24, call; 24, 25; 24, 26; 25, identifier:_get_cores_memory; 26, argument_list; 26, 27; 26, 28; 27, identifier:data; 28, keyword_argument; 28, 29; 28, 30; 29, identifier:downscale; 30, integer:2; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:tmp_file; 34, binary_operator:%; 34, 35; 34, 36; 35, string:"%s-sorttmp"; 36, subscript; 36, 37; 36, 43; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:utils; 40, identifier:splitext_plus; 41, argument_list; 41, 42; 42, identifier:tx_out_file; 43, integer:0; 44, if_statement; 44, 45; 44, 51; 44, 75; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:data; 48, identifier:get; 49, argument_list; 49, 50; 50, string:"align_split"; 51, block; 51, 52; 51, 69; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:sort_opt; 55, conditional_expression:if; 55, 56; 55, 57; 55, 68; 56, string:"-n"; 57, boolean_operator:and; 57, 58; 57, 64; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:data; 61, identifier:get; 62, argument_list; 62, 63; 63, string:"align_split"; 64, call; 64, 65; 64, 66; 65, identifier:_check_dedup; 66, argument_list; 66, 67; 67, identifier:data; 68, string:""; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:cmd; 72, binary_operator:%; 72, 73; 72, 74; 73, string:"{samtools} sort %s -@ {cores} -m {mem} -O bam -T {tmp_file}-namesort -o {tx_out_file} -"; 74, identifier:sort_opt; 75, else_clause; 75, 76; 76, block; 76, 77; 76, 95; 76, 105; 76, 115; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:cores; 80, call; 80, 81; 80, 82; 81, identifier:max; 82, argument_list; 82, 83; 82, 84; 83, integer:1; 84, call; 84, 85; 84, 86; 85, identifier:int; 86, argument_list; 86, 87; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:math; 90, identifier:ceil; 91, argument_list; 91, 92; 92, binary_operator:*; 92, 93; 92, 94; 93, identifier:cores; 94, float:0.75; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:ds_cmd; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:bam; 101, identifier:get_maxcov_downsample_cl; 102, argument_list; 102, 103; 102, 104; 103, identifier:data; 104, string:"bamsormadup"; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:bamsormadup; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:config_utils; 111, identifier:get_program; 112, argument_list; 112, 113; 112, 114; 113, string:"bamsormadup"; 114, identifier:data; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:cmd; 118, parenthesized_expression; 118, 119; 119, binary_operator:%; 119, 120; 119, 123; 120, concatenated_string; 120, 121; 120, 122; 121, string:"{bamsormadup} inputformat=sam threads={cores} tmpfile={tmp_file}-markdup "; 122, string:"SO=coordinate %s > {tx_out_file}"; 123, identifier:ds_cmd; 124, return_statement; 124, 125; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:cmd; 128, identifier:format; 129, argument_list; 129, 130; 130, dictionary_splat; 130, 131; 131, call; 131, 132; 131, 133; 132, identifier:locals; 133, argument_list | def _biobambam_dedup_sort(data, tx_out_file):
samtools = config_utils.get_program("samtools", data["config"])
cores, mem = _get_cores_memory(data, downscale=2)
tmp_file = "%s-sorttmp" % utils.splitext_plus(tx_out_file)[0]
if data.get("align_split"):
sort_opt = "-n" if data.get("align_split") and _check_dedup(data) else ""
cmd = "{samtools} sort %s -@ {cores} -m {mem} -O bam -T {tmp_file}-namesort -o {tx_out_file} -" % sort_opt
else:
cores = max(1, int(math.ceil(cores * 0.75)))
ds_cmd = bam.get_maxcov_downsample_cl(data, "bamsormadup")
bamsormadup = config_utils.get_program("bamsormadup", data)
cmd = ("{bamsormadup} inputformat=sam threads={cores} tmpfile={tmp_file}-markdup "
"SO=coordinate %s > {tx_out_file}" % ds_cmd)
return cmd.format(**locals()) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_prepare_bam_file; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:bam_file; 5, identifier:tmp_dir; 6, identifier:config; 7, block; 7, 8; 7, 16; 7, 30; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:sort_mode; 11, call; 11, 12; 11, 13; 12, identifier:_get_sort_order; 13, argument_list; 13, 14; 13, 15; 14, identifier:bam_file; 15, identifier:config; 16, if_statement; 16, 17; 16, 20; 17, comparison_operator:!=; 17, 18; 17, 19; 18, identifier:sort_mode; 19, string:"queryname"; 20, block; 20, 21; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:bam_file; 24, call; 24, 25; 24, 26; 25, identifier:sort; 26, argument_list; 26, 27; 26, 28; 26, 29; 27, identifier:bam_file; 28, identifier:config; 29, string:"queryname"; 30, return_statement; 30, 31; 31, identifier:bam_file | def _prepare_bam_file(bam_file, tmp_dir, config):
sort_mode = _get_sort_order(bam_file, config)
if sort_mode != "queryname":
bam_file = sort(bam_file, config, "queryname")
return bam_file |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_concat_records; 3, parameters; 3, 4; 3, 5; 4, identifier:items_by_key; 5, identifier:input_order; 6, block; 6, 7; 6, 11; 6, 33; 6, 42; 6, 51; 6, 99; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:all_records; 10, list:[]; 11, for_statement; 11, 12; 11, 15; 11, 20; 12, tuple_pattern; 12, 13; 12, 14; 13, identifier:k; 14, identifier:t; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:input_order; 18, identifier:items; 19, argument_list; 20, block; 20, 21; 21, if_statement; 21, 22; 21, 25; 22, comparison_operator:==; 22, 23; 22, 24; 23, identifier:t; 24, string:"record"; 25, block; 25, 26; 26, expression_statement; 26, 27; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:all_records; 30, identifier:append; 31, argument_list; 31, 32; 32, identifier:k; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:out_items_by_key; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:utils; 39, identifier:deepish_copy; 40, argument_list; 40, 41; 41, identifier:items_by_key; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:out_input_order; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:utils; 48, identifier:deepish_copy; 49, argument_list; 49, 50; 50, identifier:input_order; 51, if_statement; 51, 52; 51, 58; 52, comparison_operator:>; 52, 53; 52, 57; 53, call; 53, 54; 53, 55; 54, identifier:len; 55, argument_list; 55, 56; 56, identifier:all_records; 57, integer:1; 58, block; 58, 59; 58, 65; 58, 71; 58, 93; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:final_k; 62, subscript; 62, 63; 62, 64; 63, identifier:all_records; 64, integer:0; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:final_v; 68, subscript; 68, 69; 68, 70; 69, identifier:items_by_key; 70, identifier:final_k; 71, for_statement; 71, 72; 71, 73; 71, 78; 72, identifier:k; 73, subscript; 73, 74; 73, 75; 74, identifier:all_records; 75, slice; 75, 76; 75, 77; 76, integer:1; 77, colon; 78, block; 78, 79; 78, 85; 78, 89; 79, expression_statement; 79, 80; 80, augmented_assignment:+=; 80, 81; 80, 82; 81, identifier:final_v; 82, subscript; 82, 83; 82, 84; 83, identifier:items_by_key; 84, identifier:k; 85, delete_statement; 85, 86; 86, subscript; 86, 87; 86, 88; 87, identifier:out_items_by_key; 88, identifier:k; 89, delete_statement; 89, 90; 90, subscript; 90, 91; 90, 92; 91, identifier:out_input_order; 92, identifier:k; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 98; 95, subscript; 95, 96; 95, 97; 96, identifier:out_items_by_key; 97, identifier:final_k; 98, identifier:final_v; 99, return_statement; 99, 100; 100, expression_list; 100, 101; 100, 102; 101, identifier:out_items_by_key; 102, identifier:out_input_order | def _concat_records(items_by_key, input_order):
all_records = []
for (k, t) in input_order.items():
if t == "record":
all_records.append(k)
out_items_by_key = utils.deepish_copy(items_by_key)
out_input_order = utils.deepish_copy(input_order)
if len(all_records) > 1:
final_k = all_records[0]
final_v = items_by_key[final_k]
for k in all_records[1:]:
final_v += items_by_key[k]
del out_items_by_key[k]
del out_input_order[k]
out_items_by_key[final_k] = final_v
return out_items_by_key, out_input_order |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_combine_files; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:tsv_files; 5, identifier:work_dir; 6, identifier:data; 7, block; 7, 8; 7, 28; 7, 37; 7, 52; 7, 122; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:header; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, string:"\t"; 14, identifier:join; 15, argument_list; 15, 16; 16, list:["caller", "sample", "chrom", "start", "end", "svtype",
"lof", "annotation", "split_read_support", "paired_support_PE", "paired_support_PR"]; 16, 17; 16, 18; 16, 19; 16, 20; 16, 21; 16, 22; 16, 23; 16, 24; 16, 25; 16, 26; 16, 27; 17, string:"caller"; 18, string:"sample"; 19, string:"chrom"; 20, string:"start"; 21, string:"end"; 22, string:"svtype"; 23, string:"lof"; 24, string:"annotation"; 25, string:"split_read_support"; 26, string:"paired_support_PE"; 27, string:"paired_support_PR"; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:sample; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:dd; 34, identifier:get_sample_name; 35, argument_list; 35, 36; 36, identifier:data; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:out_file; 40, call; 40, 41; 40, 46; 41, attribute; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:os; 44, identifier:path; 45, identifier:join; 46, argument_list; 46, 47; 46, 48; 47, identifier:work_dir; 48, binary_operator:%; 48, 49; 48, 50; 49, string:"%s-prioritize.tsv"; 50, parenthesized_expression; 50, 51; 51, identifier:sample; 52, if_statement; 52, 53; 52, 60; 53, not_operator; 53, 54; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:utils; 57, identifier:file_exists; 58, argument_list; 58, 59; 59, identifier:out_file; 60, block; 60, 61; 61, with_statement; 61, 62; 61, 72; 62, with_clause; 62, 63; 63, with_item; 63, 64; 64, as_pattern; 64, 65; 64, 70; 65, call; 65, 66; 65, 67; 66, identifier:file_transaction; 67, argument_list; 67, 68; 67, 69; 68, identifier:data; 69, identifier:out_file; 70, as_pattern_target; 70, 71; 71, identifier:tx_out_file; 72, block; 72, 73; 72, 84; 72, 93; 72, 102; 72, 106; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:tmpdir; 76, call; 76, 77; 76, 82; 77, attribute; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:os; 80, identifier:path; 81, identifier:dirname; 82, argument_list; 82, 83; 83, identifier:tx_out_file; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:input_files; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, string:" "; 90, identifier:join; 91, argument_list; 91, 92; 92, identifier:tsv_files; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:sort_cmd; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:bedutils; 99, identifier:get_sort_cmd; 100, argument_list; 100, 101; 101, identifier:tmpdir; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:cmd; 105, string:"{{ echo '{header}'; cat {input_files} | {sort_cmd} -k3,3 -k4,4n; }} > {tx_out_file}"; 106, expression_statement; 106, 107; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:do; 110, identifier:run; 111, argument_list; 111, 112; 111, 121; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:cmd; 115, identifier:format; 116, argument_list; 116, 117; 117, dictionary_splat; 117, 118; 118, call; 118, 119; 118, 120; 119, identifier:locals; 120, argument_list; 121, string:"Combine prioritized from multiple callers"; 122, return_statement; 122, 123; 123, identifier:out_file | def _combine_files(tsv_files, work_dir, data):
header = "\t".join(["caller", "sample", "chrom", "start", "end", "svtype",
"lof", "annotation", "split_read_support", "paired_support_PE", "paired_support_PR"])
sample = dd.get_sample_name(data)
out_file = os.path.join(work_dir, "%s-prioritize.tsv" % (sample))
if not utils.file_exists(out_file):
with file_transaction(data, out_file) as tx_out_file:
tmpdir = os.path.dirname(tx_out_file)
input_files = " ".join(tsv_files)
sort_cmd = bedutils.get_sort_cmd(tmpdir)
cmd = "{{ echo '{header}'; cat {input_files} | {sort_cmd} -k3,3 -k4,4n; }} > {tx_out_file}"
do.run(cmd.format(**locals()), "Combine prioritized from multiple callers")
return out_file |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort_filenames; 3, parameters; 3, 4; 4, identifier:filenames; 5, block; 5, 6; 5, 21; 5, 45; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:basenames; 9, list_comprehension; 9, 10; 9, 18; 10, call; 10, 11; 10, 16; 11, attribute; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:os; 14, identifier:path; 15, identifier:basename; 16, argument_list; 16, 17; 17, identifier:x; 18, for_in_clause; 18, 19; 18, 20; 19, identifier:x; 20, identifier:filenames; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:indexes; 24, list_comprehension; 24, 25; 24, 28; 25, subscript; 25, 26; 25, 27; 26, identifier:i; 27, integer:0; 28, for_in_clause; 28, 29; 28, 30; 29, identifier:i; 30, call; 30, 31; 30, 32; 31, identifier:sorted; 32, argument_list; 32, 33; 32, 37; 33, call; 33, 34; 33, 35; 34, identifier:enumerate; 35, argument_list; 35, 36; 36, identifier:basenames; 37, keyword_argument; 37, 38; 37, 39; 38, identifier:key; 39, lambda; 39, 40; 39, 42; 40, lambda_parameters; 40, 41; 41, identifier:x; 42, subscript; 42, 43; 42, 44; 43, identifier:x; 44, integer:1; 45, return_statement; 45, 46; 46, list_comprehension; 46, 47; 46, 50; 47, subscript; 47, 48; 47, 49; 48, identifier:filenames; 49, identifier:x; 50, for_in_clause; 50, 51; 50, 52; 51, identifier:x; 52, identifier:indexes | def sort_filenames(filenames):
basenames = [os.path.basename(x) for x in filenames]
indexes = [i[0] for i in sorted(enumerate(basenames), key=lambda x:x[1])]
return [filenames[x] for x in indexes] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort_csv; 3, parameters; 3, 4; 4, identifier:in_file; 5, block; 5, 6; 5, 12; 5, 73; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:out_file; 9, binary_operator:%; 9, 10; 9, 11; 10, string:"%s.sort"; 11, identifier:in_file; 12, if_statement; 12, 13; 12, 34; 13, not_operator; 13, 14; 14, parenthesized_expression; 14, 15; 15, boolean_operator:and; 15, 16; 15, 24; 16, call; 16, 17; 16, 22; 17, attribute; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:os; 20, identifier:path; 21, identifier:exists; 22, argument_list; 22, 23; 23, identifier:out_file; 24, comparison_operator:>; 24, 25; 24, 33; 25, call; 25, 26; 25, 31; 26, attribute; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:os; 29, identifier:path; 30, identifier:getsize; 31, argument_list; 31, 32; 32, identifier:out_file; 33, integer:0; 34, block; 34, 35; 34, 43; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:cl; 38, list:["sort", "-k", "1,1", in_file]; 38, 39; 38, 40; 38, 41; 38, 42; 39, string:"sort"; 40, string:"-k"; 41, string:"1,1"; 42, identifier:in_file; 43, with_statement; 43, 44; 43, 54; 44, with_clause; 44, 45; 45, with_item; 45, 46; 46, as_pattern; 46, 47; 46, 52; 47, call; 47, 48; 47, 49; 48, identifier:open; 49, argument_list; 49, 50; 49, 51; 50, identifier:out_file; 51, string:"w"; 52, as_pattern_target; 52, 53; 53, identifier:out_handle; 54, block; 54, 55; 54, 67; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:child; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:subprocess; 61, identifier:Popen; 62, argument_list; 62, 63; 62, 64; 63, identifier:cl; 64, keyword_argument; 64, 65; 64, 66; 65, identifier:stdout; 66, identifier:out_handle; 67, expression_statement; 67, 68; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:child; 71, identifier:wait; 72, argument_list; 73, return_statement; 73, 74; 74, identifier:out_file | def sort_csv(in_file):
out_file = "%s.sort" % in_file
if not (os.path.exists(out_file) and os.path.getsize(out_file) > 0):
cl = ["sort", "-k", "1,1", in_file]
with open(out_file, "w") as out_handle:
child = subprocess.Popen(cl, stdout=out_handle)
child.wait()
return out_file |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:hydra_to_vcf_writer; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:hydra_file; 5, identifier:genome_2bit; 6, identifier:options; 7, identifier:out_handle; 8, block; 8, 9; 8, 14; 8, 26; 8, 39; 9, expression_statement; 9, 10; 10, call; 10, 11; 10, 12; 11, identifier:_write_vcf_header; 12, argument_list; 12, 13; 13, identifier:out_handle; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:brends; 17, call; 17, 18; 17, 19; 18, identifier:list; 19, argument_list; 19, 20; 20, call; 20, 21; 20, 22; 21, identifier:_get_vcf_breakends; 22, argument_list; 22, 23; 22, 24; 22, 25; 23, identifier:hydra_file; 24, identifier:genome_2bit; 25, identifier:options; 26, expression_statement; 26, 27; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:brends; 30, identifier:sort; 31, argument_list; 31, 32; 32, keyword_argument; 32, 33; 32, 34; 33, identifier:key; 34, call; 34, 35; 34, 36; 35, identifier:attrgetter; 36, argument_list; 36, 37; 36, 38; 37, string:"chrom"; 38, string:"pos"; 39, for_statement; 39, 40; 39, 41; 39, 42; 40, identifier:brend; 41, identifier:brends; 42, block; 42, 43; 43, expression_statement; 43, 44; 44, call; 44, 45; 44, 46; 45, identifier:_write_vcf_breakend; 46, argument_list; 46, 47; 46, 48; 47, identifier:brend; 48, identifier:out_handle | def hydra_to_vcf_writer(hydra_file, genome_2bit, options, out_handle):
_write_vcf_header(out_handle)
brends = list(_get_vcf_breakends(hydra_file, genome_2bit, options))
brends.sort(key=attrgetter("chrom", "pos"))
for brend in brends:
_write_vcf_breakend(brend, out_handle) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_split_by_ready_regions; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:ext; 5, identifier:file_key; 6, identifier:dir_ext_fn; 7, block; 7, 8; 7, 30; 7, 103; 7, 251; 8, function_definition; 8, 9; 8, 10; 8, 12; 9, function_name:_sort_by_size; 10, parameters; 10, 11; 11, identifier:region_w_bams; 12, block; 12, 13; 12, 19; 12, 26; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 18; 15, pattern_list; 15, 16; 15, 17; 16, identifier:region; 17, identifier:_; 18, identifier:region_w_bams; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 25; 21, pattern_list; 21, 22; 21, 23; 21, 24; 22, identifier:_; 23, identifier:start; 24, identifier:end; 25, identifier:region; 26, return_statement; 26, 27; 27, binary_operator:-; 27, 28; 27, 29; 28, identifier:end; 29, identifier:start; 30, function_definition; 30, 31; 30, 32; 30, 34; 31, function_name:_assign_bams_to_regions; 32, parameters; 32, 33; 33, identifier:data; 34, block; 34, 35; 35, for_statement; 35, 36; 35, 39; 35, 45; 36, pattern_list; 36, 37; 36, 38; 37, identifier:i; 38, identifier:region; 39, call; 39, 40; 39, 41; 40, identifier:enumerate; 41, argument_list; 41, 42; 42, subscript; 42, 43; 42, 44; 43, identifier:data; 44, string:"region"; 45, block; 45, 46; 45, 50; 45, 84; 45, 98; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:work_bams; 49, list:[]; 50, for_statement; 50, 51; 50, 52; 50, 55; 51, identifier:xs; 52, subscript; 52, 53; 52, 54; 53, identifier:data; 54, string:"region_bams"; 55, block; 55, 56; 56, if_statement; 56, 57; 56, 63; 56, 73; 57, comparison_operator:==; 57, 58; 57, 62; 58, call; 58, 59; 58, 60; 59, identifier:len; 60, argument_list; 60, 61; 61, identifier:xs; 62, integer:1; 63, block; 63, 64; 64, expression_statement; 64, 65; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:work_bams; 68, identifier:append; 69, argument_list; 69, 70; 70, subscript; 70, 71; 70, 72; 71, identifier:xs; 72, integer:0; 73, else_clause; 73, 74; 74, block; 74, 75; 75, expression_statement; 75, 76; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:work_bams; 79, identifier:append; 80, argument_list; 80, 81; 81, subscript; 81, 82; 81, 83; 82, identifier:xs; 83, identifier:i; 84, for_statement; 84, 85; 84, 86; 84, 87; 85, identifier:work_bam; 86, identifier:work_bams; 87, block; 87, 88; 88, assert_statement; 88, 89; 88, 97; 89, call; 89, 90; 89, 95; 90, attribute; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:os; 93, identifier:path; 94, identifier:exists; 95, argument_list; 95, 96; 96, identifier:work_bam; 97, identifier:work_bam; 98, expression_statement; 98, 99; 99, yield; 99, 100; 100, expression_list; 100, 101; 100, 102; 101, identifier:region; 102, identifier:work_bams; 103, function_definition; 103, 104; 103, 105; 103, 107; 104, function_name:_do_work; 105, parameters; 105, 106; 106, identifier:data; 107, block; 107, 108; 108, if_statement; 108, 109; 108, 112; 108, 245; 109, comparison_operator:in; 109, 110; 109, 111; 110, string:"region"; 111, identifier:data; 112, block; 112, 113; 112, 128; 112, 147; 112, 163; 112, 173; 112, 177; 112, 241; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:name; 116, conditional_expression:if; 116, 117; 116, 122; 116, 125; 117, subscript; 117, 118; 117, 121; 118, subscript; 118, 119; 118, 120; 119, identifier:data; 120, string:"group"; 121, integer:0; 122, comparison_operator:in; 122, 123; 122, 124; 123, string:"group"; 124, identifier:data; 125, subscript; 125, 126; 125, 127; 126, identifier:data; 127, string:"description"; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:out_dir; 131, call; 131, 132; 131, 137; 132, attribute; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:os; 135, identifier:path; 136, identifier:join; 137, argument_list; 137, 138; 137, 143; 138, subscript; 138, 139; 138, 142; 139, subscript; 139, 140; 139, 141; 140, identifier:data; 141, string:"dirs"; 142, string:"work"; 143, call; 143, 144; 143, 145; 144, identifier:dir_ext_fn; 145, argument_list; 145, 146; 146, identifier:data; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 150; 149, identifier:out_file; 150, call; 150, 151; 150, 156; 151, attribute; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:os; 154, identifier:path; 155, identifier:join; 156, argument_list; 156, 157; 156, 158; 157, identifier:out_dir; 158, binary_operator:%; 158, 159; 158, 160; 159, string:"%s%s"; 160, tuple; 160, 161; 160, 162; 161, identifier:name; 162, identifier:ext; 163, assert_statement; 163, 164; 164, call; 164, 165; 164, 166; 165, identifier:isinstance; 166, argument_list; 166, 167; 166, 170; 167, subscript; 167, 168; 167, 169; 168, identifier:data; 169, string:"region"; 170, tuple; 170, 171; 170, 172; 171, identifier:list; 172, identifier:tuple; 173, expression_statement; 173, 174; 174, assignment; 174, 175; 174, 176; 175, identifier:out_parts; 176, list:[]; 177, for_statement; 177, 178; 177, 181; 177, 194; 178, pattern_list; 178, 179; 178, 180; 179, identifier:r; 180, identifier:work_bams; 181, call; 181, 182; 181, 183; 182, identifier:sorted; 183, argument_list; 183, 184; 183, 188; 183, 191; 184, call; 184, 185; 184, 186; 185, identifier:_assign_bams_to_regions; 186, argument_list; 186, 187; 187, identifier:data; 188, keyword_argument; 188, 189; 188, 190; 189, identifier:key; 190, identifier:_sort_by_size; 191, keyword_argument; 191, 192; 191, 193; 192, identifier:reverse; 193, True; 194, block; 194, 195; 194, 209; 194, 231; 195, expression_statement; 195, 196; 196, assignment; 196, 197; 196, 198; 197, identifier:out_region_dir; 198, call; 198, 199; 198, 204; 199, attribute; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:os; 202, identifier:path; 203, identifier:join; 204, argument_list; 204, 205; 204, 206; 205, identifier:out_dir; 206, subscript; 206, 207; 206, 208; 207, identifier:r; 208, integer:0; 209, expression_statement; 209, 210; 210, assignment; 210, 211; 210, 212; 211, identifier:out_region_file; 212, call; 212, 213; 212, 218; 213, attribute; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:os; 216, identifier:path; 217, identifier:join; 218, argument_list; 218, 219; 218, 220; 219, identifier:out_region_dir; 220, binary_operator:%; 220, 221; 220, 222; 221, string:"%s-%s%s"; 222, tuple; 222, 223; 222, 224; 222, 230; 223, identifier:name; 224, call; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, identifier:pregion; 227, identifier:to_safestr; 228, argument_list; 228, 229; 229, identifier:r; 230, identifier:ext; 231, expression_statement; 231, 232; 232, call; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:out_parts; 235, identifier:append; 236, argument_list; 236, 237; 237, tuple; 237, 238; 237, 239; 237, 240; 238, identifier:r; 239, identifier:work_bams; 240, identifier:out_region_file; 241, return_statement; 241, 242; 242, expression_list; 242, 243; 242, 244; 243, identifier:out_file; 244, identifier:out_parts; 245, else_clause; 245, 246; 246, block; 246, 247; 247, return_statement; 247, 248; 248, expression_list; 248, 249; 248, 250; 249, None; 250, list:[]; 251, return_statement; 251, 252; 252, identifier:_do_work | def _split_by_ready_regions(ext, file_key, dir_ext_fn):
def _sort_by_size(region_w_bams):
region, _ = region_w_bams
_, start, end = region
return end - start
def _assign_bams_to_regions(data):
for i, region in enumerate(data["region"]):
work_bams = []
for xs in data["region_bams"]:
if len(xs) == 1:
work_bams.append(xs[0])
else:
work_bams.append(xs[i])
for work_bam in work_bams:
assert os.path.exists(work_bam), work_bam
yield region, work_bams
def _do_work(data):
if "region" in data:
name = data["group"][0] if "group" in data else data["description"]
out_dir = os.path.join(data["dirs"]["work"], dir_ext_fn(data))
out_file = os.path.join(out_dir, "%s%s" % (name, ext))
assert isinstance(data["region"], (list, tuple))
out_parts = []
for r, work_bams in sorted(_assign_bams_to_regions(data), key=_sort_by_size, reverse=True):
out_region_dir = os.path.join(out_dir, r[0])
out_region_file = os.path.join(out_region_dir,
"%s-%s%s" % (name, pregion.to_safestr(r), ext))
out_parts.append((r, work_bams, out_region_file))
return out_file, out_parts
else:
return None, []
return _do_work |
0, module; 0, 1; 1, ERROR; 1, 2; 1, 137; 2, function_definition; 2, 3; 2, 4; 2, 9; 3, function_name:_combine_variants; 4, parameters; 4, 5; 4, 6; 4, 7; 4, 8; 5, identifier:in_vcfs; 6, identifier:out_file; 7, identifier:ref_file; 8, identifier:config; 9, block; 9, 10; 9, 16; 9, 20; 9, 121; 10, expression_statement; 10, 11; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:in_vcfs; 14, identifier:sort; 15, argument_list; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:wrote_header; 19, False; 20, with_statement; 20, 21; 20, 31; 21, with_clause; 21, 22; 22, with_item; 22, 23; 23, as_pattern; 23, 24; 23, 29; 24, call; 24, 25; 24, 26; 25, identifier:open; 26, argument_list; 26, 27; 26, 28; 27, identifier:out_file; 28, string:"w"; 29, as_pattern_target; 29, 30; 30, identifier:out_handle; 31, block; 31, 32; 32, for_statement; 32, 33; 32, 34; 32, 42; 33, identifier:in_vcf; 34, generator_expression; 34, 35; 34, 39; 35, subscript; 35, 36; 35, 37; 36, identifier:x; 37, unary_operator:-; 37, 38; 38, integer:1; 39, for_in_clause; 39, 40; 39, 41; 40, identifier:x; 41, identifier:in_vcfs; 42, block; 42, 43; 43, with_statement; 43, 44; 43, 53; 43, 93; 44, with_clause; 44, 45; 45, with_item; 45, 46; 46, as_pattern; 46, 47; 46, 51; 47, call; 47, 48; 47, 49; 48, identifier:open; 49, argument_list; 49, 50; 50, identifier:in_vcf; 51, as_pattern_target; 51, 52; 52, identifier:in_handle; 53, ERROR; 53, 54; 53, 55; 53, 56; 53, 71; 54, identifier:header; 55, identifier:list; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:itertools; 59, identifier:takewhile; 60, argument_list; 60, 61; 61, lambda; 61, 62; 61, 64; 62, lambda_parameters; 62, 63; 63, identifier:x; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:x; 67, identifier:startswith; 68, argument_list; 68, 69; 68, 70; 69, ERROR; 70, identifier:in_handle; 71, not_operator; 71, 72; 72, comparison_operator:in; 72, 73; 72, 89; 72, 92; 73, call; 73, 74; 73, 79; 74, attribute; 74, 75; 74, 78; 75, subscript; 75, 76; 75, 77; 76, identifier:header; 77, integer:0; 78, identifier:startswith; 79, argument_list; 79, 80; 80, binary_operator:%; 80, 81; 80, 82; 80, 86; 80, 88; 81, string:"
raise ValueError("; 82, ERROR; 82, 83; 82, 84; 82, 85; 83, identifier:Unexpected; 84, identifier:VCF; 85, identifier:file; 86, ERROR; 86, 87; 87, identifier:s; 88, identifier:in_vcf; 89, ERROR; 89, 90; 89, 91; 90, identifier:for; 91, identifier:line; 92, identifier:in_handle; 93, block; 93, 94; 93, 114; 94, if_statement; 94, 95; 94, 97; 95, not_operator; 95, 96; 96, identifier:wrote_header; 97, block; 97, 98; 97, 102; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:wrote_header; 101, True; 102, expression_statement; 102, 103; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:out_handle; 106, identifier:write; 107, argument_list; 107, 108; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, string:""; 111, identifier:join; 112, argument_list; 112, 113; 113, identifier:header; 114, expression_statement; 114, 115; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:out_handle; 118, identifier:write; 119, argument_list; 119, 120; 120, identifier:line; 121, if_statement; 121, 122; 121, 124; 122, not_operator; 122, 123; 123, identifier:wrote_header; 124, block; 124, 125; 125, expression_statement; 125, 126; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:out_handle; 129, identifier:write; 130, argument_list; 130, 131; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, string:""; 134, identifier:join; 135, argument_list; 135, 136; 136, identifier:header; 137, return_statement; 137, 138; 138, identifier:out_file | def _combine_variants(in_vcfs, out_file, ref_file, config):
in_vcfs.sort()
wrote_header = False
with open(out_file, "w") as out_handle:
for in_vcf in (x[-1] for x in in_vcfs):
with open(in_vcf) as in_handle:
header = list(itertools.takewhile(lambda x: x.startswith("
in_handle))
if not header[0].startswith("
raise ValueError("Unexpected VCF file: %s" % in_vcf)
for line in in_handle:
if not wrote_header:
wrote_header = True
out_handle.write("".join(header))
out_handle.write(line)
if not wrote_header:
out_handle.write("".join(header))
return out_file |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 2, function_name:picard_sort; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 4, identifier:picard; 5, identifier:align_bam; 6, default_parameter; 6, 7; 6, 8; 7, identifier:sort_order; 8, string:"coordinate"; 9, default_parameter; 9, 10; 9, 11; 10, identifier:out_file; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:compression_level; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:pipe; 17, False; 18, block; 18, 19; 18, 32; 18, 45; 18, 121; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 24; 21, pattern_list; 21, 22; 21, 23; 22, identifier:base; 23, identifier:ext; 24, call; 24, 25; 24, 30; 25, attribute; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:os; 28, identifier:path; 29, identifier:splitext; 30, argument_list; 30, 31; 31, identifier:align_bam; 32, if_statement; 32, 33; 32, 36; 33, comparison_operator:is; 33, 34; 33, 35; 34, identifier:out_file; 35, None; 36, block; 36, 37; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:out_file; 40, binary_operator:%; 40, 41; 40, 42; 41, string:"%s-sort%s"; 42, tuple; 42, 43; 42, 44; 43, identifier:base; 44, identifier:ext; 45, if_statement; 45, 46; 45, 51; 46, not_operator; 46, 47; 47, call; 47, 48; 47, 49; 48, identifier:file_exists; 49, argument_list; 49, 50; 50, identifier:out_file; 51, block; 51, 52; 52, with_statement; 52, 53; 52, 64; 53, with_clause; 53, 54; 54, with_item; 54, 55; 55, as_pattern; 55, 56; 55, 62; 56, call; 56, 57; 56, 58; 57, identifier:tx_tmpdir; 58, argument_list; 58, 59; 59, attribute; 59, 60; 59, 61; 60, identifier:picard; 61, identifier:_config; 62, as_pattern_target; 62, 63; 63, identifier:tmp_dir; 64, block; 64, 65; 65, with_statement; 65, 66; 65, 78; 66, with_clause; 66, 67; 67, with_item; 67, 68; 68, as_pattern; 68, 69; 68, 76; 69, call; 69, 70; 69, 71; 70, identifier:file_transaction; 71, argument_list; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:picard; 74, identifier:_config; 75, identifier:out_file; 76, as_pattern_target; 76, 77; 77, identifier:tx_out_file; 78, block; 78, 79; 78, 98; 78, 110; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:opts; 82, list:[("INPUT", align_bam),
("OUTPUT", out_file if pipe else tx_out_file),
("TMP_DIR", tmp_dir),
("SORT_ORDER", sort_order)]; 82, 83; 82, 86; 82, 92; 82, 95; 83, tuple; 83, 84; 83, 85; 84, string:"INPUT"; 85, identifier:align_bam; 86, tuple; 86, 87; 86, 88; 87, string:"OUTPUT"; 88, conditional_expression:if; 88, 89; 88, 90; 88, 91; 89, identifier:out_file; 90, identifier:pipe; 91, identifier:tx_out_file; 92, tuple; 92, 93; 92, 94; 93, string:"TMP_DIR"; 94, identifier:tmp_dir; 95, tuple; 95, 96; 95, 97; 96, string:"SORT_ORDER"; 97, identifier:sort_order; 98, if_statement; 98, 99; 98, 100; 99, identifier:compression_level; 100, block; 100, 101; 101, expression_statement; 101, 102; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:opts; 105, identifier:append; 106, argument_list; 106, 107; 107, tuple; 107, 108; 107, 109; 108, string:"COMPRESSION_LEVEL"; 109, identifier:compression_level; 110, expression_statement; 110, 111; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:picard; 114, identifier:run; 115, argument_list; 115, 116; 115, 117; 115, 118; 116, string:"SortSam"; 117, identifier:opts; 118, keyword_argument; 118, 119; 118, 120; 119, identifier:pipe; 120, identifier:pipe; 121, return_statement; 121, 122; 122, identifier:out_file | def picard_sort(picard, align_bam, sort_order="coordinate",
out_file=None, compression_level=None, pipe=False):
base, ext = os.path.splitext(align_bam)
if out_file is None:
out_file = "%s-sort%s" % (base, ext)
if not file_exists(out_file):
with tx_tmpdir(picard._config) as tmp_dir:
with file_transaction(picard._config, out_file) as tx_out_file:
opts = [("INPUT", align_bam),
("OUTPUT", out_file if pipe else tx_out_file),
("TMP_DIR", tmp_dir),
("SORT_ORDER", sort_order)]
if compression_level:
opts.append(("COMPRESSION_LEVEL", compression_level))
picard.run("SortSam", opts, pipe=pipe)
return out_file |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:picard_fix_rgs; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:picard; 5, identifier:in_bam; 6, identifier:names; 7, block; 7, 8; 7, 23; 7, 110; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:out_file; 11, binary_operator:%; 11, 12; 11, 13; 12, string:"%s-fixrgs.bam"; 13, subscript; 13, 14; 13, 22; 14, call; 14, 15; 14, 20; 15, attribute; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:os; 18, identifier:path; 19, identifier:splitext; 20, argument_list; 20, 21; 21, identifier:in_bam; 22, integer:0; 23, if_statement; 23, 24; 23, 29; 24, not_operator; 24, 25; 25, call; 25, 26; 25, 27; 26, identifier:file_exists; 27, argument_list; 27, 28; 28, identifier:out_file; 29, block; 29, 30; 30, with_statement; 30, 31; 30, 42; 31, with_clause; 31, 32; 32, with_item; 32, 33; 33, as_pattern; 33, 34; 33, 40; 34, call; 34, 35; 34, 36; 35, identifier:tx_tmpdir; 36, argument_list; 36, 37; 37, attribute; 37, 38; 37, 39; 38, identifier:picard; 39, identifier:_config; 40, as_pattern_target; 40, 41; 41, identifier:tmp_dir; 42, block; 42, 43; 43, with_statement; 43, 44; 43, 56; 44, with_clause; 44, 45; 45, with_item; 45, 46; 46, as_pattern; 46, 47; 46, 54; 47, call; 47, 48; 47, 49; 48, identifier:file_transaction; 49, argument_list; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:picard; 52, identifier:_config; 53, identifier:out_file; 54, as_pattern_target; 54, 55; 55, identifier:tx_out_file; 56, block; 56, 57; 56, 102; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:opts; 60, list:[("INPUT", in_bam),
("OUTPUT", tx_out_file),
("SORT_ORDER", "coordinate"),
("RGID", names["rg"]),
("RGLB", names.get("lb", "unknown")),
("RGPL", names["pl"]),
("RGPU", names["pu"]),
("RGSM", names["sample"]),
("TMP_DIR", tmp_dir)]; 60, 61; 60, 64; 60, 67; 60, 70; 60, 75; 60, 84; 60, 89; 60, 94; 60, 99; 61, tuple; 61, 62; 61, 63; 62, string:"INPUT"; 63, identifier:in_bam; 64, tuple; 64, 65; 64, 66; 65, string:"OUTPUT"; 66, identifier:tx_out_file; 67, tuple; 67, 68; 67, 69; 68, string:"SORT_ORDER"; 69, string:"coordinate"; 70, tuple; 70, 71; 70, 72; 71, string:"RGID"; 72, subscript; 72, 73; 72, 74; 73, identifier:names; 74, string:"rg"; 75, tuple; 75, 76; 75, 77; 76, string:"RGLB"; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:names; 80, identifier:get; 81, argument_list; 81, 82; 81, 83; 82, string:"lb"; 83, string:"unknown"; 84, tuple; 84, 85; 84, 86; 85, string:"RGPL"; 86, subscript; 86, 87; 86, 88; 87, identifier:names; 88, string:"pl"; 89, tuple; 89, 90; 89, 91; 90, string:"RGPU"; 91, subscript; 91, 92; 91, 93; 92, identifier:names; 93, string:"pu"; 94, tuple; 94, 95; 94, 96; 95, string:"RGSM"; 96, subscript; 96, 97; 96, 98; 97, identifier:names; 98, string:"sample"; 99, tuple; 99, 100; 99, 101; 100, string:"TMP_DIR"; 101, identifier:tmp_dir; 102, expression_statement; 102, 103; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:picard; 106, identifier:run; 107, argument_list; 107, 108; 107, 109; 108, string:"AddOrReplaceReadGroups"; 109, identifier:opts; 110, return_statement; 110, 111; 111, identifier:out_file | def picard_fix_rgs(picard, in_bam, names):
out_file = "%s-fixrgs.bam" % os.path.splitext(in_bam)[0]
if not file_exists(out_file):
with tx_tmpdir(picard._config) as tmp_dir:
with file_transaction(picard._config, out_file) as tx_out_file:
opts = [("INPUT", in_bam),
("OUTPUT", tx_out_file),
("SORT_ORDER", "coordinate"),
("RGID", names["rg"]),
("RGLB", names.get("lb", "unknown")),
("RGPL", names["pl"]),
("RGPU", names["pu"]),
("RGSM", names["sample"]),
("TMP_DIR", tmp_dir)]
picard.run("AddOrReplaceReadGroups", opts)
return out_file |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_enforce_max_region_size; 3, parameters; 3, 4; 3, 5; 4, identifier:in_file; 5, identifier:data; 6, block; 6, 7; 6, 11; 6, 15; 6, 41; 6, 52; 6, 120; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:max_size; 10, integer:20000; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:overlap_size; 14, integer:250; 15, function_definition; 15, 16; 15, 17; 15, 19; 16, function_name:_has_larger_regions; 17, parameters; 17, 18; 18, identifier:f; 19, block; 19, 20; 20, return_statement; 20, 21; 21, call; 21, 22; 21, 23; 22, identifier:any; 23, generator_expression; 23, 24; 23, 33; 24, comparison_operator:>; 24, 25; 24, 32; 25, binary_operator:-; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:r; 28, identifier:stop; 29, attribute; 29, 30; 29, 31; 30, identifier:r; 31, identifier:start; 32, identifier:max_size; 33, for_in_clause; 33, 34; 33, 35; 34, identifier:r; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:pybedtools; 38, identifier:BedTool; 39, argument_list; 39, 40; 40, identifier:f; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:out_file; 44, binary_operator:%; 44, 45; 44, 46; 45, string:"%s-regionlimit%s"; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:utils; 49, identifier:splitext_plus; 50, argument_list; 50, 51; 51, identifier:in_file; 52, if_statement; 52, 53; 52, 60; 53, not_operator; 53, 54; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:utils; 57, identifier:file_exists; 58, argument_list; 58, 59; 59, identifier:out_file; 60, block; 60, 61; 61, if_statement; 61, 62; 61, 66; 61, 110; 62, call; 62, 63; 62, 64; 63, identifier:_has_larger_regions; 64, argument_list; 64, 65; 65, identifier:in_file; 66, block; 66, 67; 67, with_statement; 67, 68; 67, 78; 68, with_clause; 68, 69; 69, with_item; 69, 70; 70, as_pattern; 70, 71; 70, 76; 71, call; 71, 72; 71, 73; 72, identifier:file_transaction; 73, argument_list; 73, 74; 73, 75; 74, identifier:data; 75, identifier:out_file; 76, as_pattern_target; 76, 77; 77, identifier:tx_out_file; 78, block; 78, 79; 79, expression_statement; 79, 80; 80, call; 80, 81; 80, 108; 81, attribute; 81, 82; 81, 107; 82, call; 82, 83; 82, 90; 83, attribute; 83, 84; 83, 89; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:pybedtools; 87, identifier:BedTool; 88, argument_list; 89, identifier:window_maker; 90, argument_list; 90, 91; 90, 94; 90, 99; 91, keyword_argument; 91, 92; 91, 93; 92, identifier:w; 93, identifier:max_size; 94, keyword_argument; 94, 95; 94, 96; 95, identifier:s; 96, binary_operator:-; 96, 97; 96, 98; 97, identifier:max_size; 98, identifier:overlap_size; 99, keyword_argument; 99, 100; 99, 101; 100, identifier:b; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:pybedtools; 104, identifier:BedTool; 105, argument_list; 105, 106; 106, identifier:in_file; 107, identifier:saveas; 108, argument_list; 108, 109; 109, identifier:tx_out_file; 110, else_clause; 110, 111; 111, block; 111, 112; 112, expression_statement; 112, 113; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:utils; 116, identifier:symlink_plus; 117, argument_list; 117, 118; 117, 119; 118, identifier:in_file; 119, identifier:out_file; 120, return_statement; 120, 121; 121, identifier:out_file | def _enforce_max_region_size(in_file, data):
max_size = 20000
overlap_size = 250
def _has_larger_regions(f):
return any(r.stop - r.start > max_size for r in pybedtools.BedTool(f))
out_file = "%s-regionlimit%s" % utils.splitext_plus(in_file)
if not utils.file_exists(out_file):
if _has_larger_regions(in_file):
with file_transaction(data, out_file) as tx_out_file:
pybedtools.BedTool().window_maker(w=max_size,
s=max_size - overlap_size,
b=pybedtools.BedTool(in_file)).saveas(tx_out_file)
else:
utils.symlink_plus(in_file, out_file)
return out_file |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:_prep_vrn_file; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 4, identifier:in_file; 5, identifier:vcaller; 6, identifier:work_dir; 7, identifier:somatic_info; 8, identifier:ignore_file; 9, identifier:config; 10, block; 10, 11; 10, 41; 10, 71; 10, 289; 11, if_statement; 11, 12; 11, 18; 11, 23; 11, 32; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:vcaller; 15, identifier:startswith; 16, argument_list; 16, 17; 17, string:"vardict"; 18, block; 18, 19; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:variant_type; 22, string:"vardict"; 23, elif_clause; 23, 24; 23, 27; 24, comparison_operator:==; 24, 25; 24, 26; 25, identifier:vcaller; 26, string:"mutect"; 27, block; 27, 28; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:variant_type; 31, string:"mutect-smchet"; 32, else_clause; 32, 33; 33, block; 33, 34; 34, raise_statement; 34, 35; 35, call; 35, 36; 35, 37; 36, identifier:ValueError; 37, argument_list; 37, 38; 38, binary_operator:%; 38, 39; 38, 40; 39, string:"Unexpected variant caller for PhyloWGS prep: %s"; 40, identifier:vcaller; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:out_file; 44, call; 44, 45; 44, 50; 45, attribute; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:os; 48, identifier:path; 49, identifier:join; 50, argument_list; 50, 51; 50, 52; 51, identifier:work_dir; 52, binary_operator:%; 52, 53; 52, 54; 53, string:"%s-%s-prep.vcf"; 54, tuple; 54, 55; 54, 70; 55, subscript; 55, 56; 55, 69; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:utils; 59, identifier:splitext_plus; 60, argument_list; 60, 61; 61, call; 61, 62; 61, 67; 62, attribute; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:os; 65, identifier:path; 66, identifier:basename; 67, argument_list; 67, 68; 68, identifier:in_file; 69, integer:0; 70, identifier:vcaller; 71, if_statement; 71, 72; 71, 80; 72, not_operator; 72, 73; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:utils; 76, identifier:file_uptodate; 77, argument_list; 77, 78; 77, 79; 78, identifier:out_file; 79, identifier:in_file; 80, block; 80, 81; 80, 88; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:check_fn; 84, call; 84, 85; 84, 86; 85, identifier:_min_sample_pass; 86, argument_list; 86, 87; 87, identifier:ignore_file; 88, with_statement; 88, 89; 88, 101; 89, with_clause; 89, 90; 90, with_item; 90, 91; 91, as_pattern; 91, 92; 91, 99; 92, call; 92, 93; 92, 94; 93, identifier:file_transaction; 94, argument_list; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:somatic_info; 97, identifier:tumor_data; 98, identifier:out_file; 99, as_pattern_target; 99, 100; 100, identifier:tx_out_file; 101, block; 101, 102; 101, 113; 101, 167; 101, 228; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:tx_out_file_raw; 105, binary_operator:%; 105, 106; 105, 107; 106, string:"%s-raw%s"; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:utils; 110, identifier:splitext_plus; 111, argument_list; 111, 112; 112, identifier:tx_out_file; 113, with_statement; 113, 114; 113, 123; 114, with_clause; 114, 115; 115, with_item; 115, 116; 116, as_pattern; 116, 117; 116, 121; 117, call; 117, 118; 117, 119; 118, identifier:VariantFile; 119, argument_list; 119, 120; 120, identifier:in_file; 121, as_pattern_target; 121, 122; 122, identifier:bcf_in; 123, block; 123, 124; 123, 142; 123, 151; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:depths; 127, list_comprehension; 127, 128; 127, 135; 128, call; 128, 129; 128, 130; 129, identifier:_sample_depth; 130, argument_list; 130, 131; 130, 132; 131, identifier:rec; 132, attribute; 132, 133; 132, 134; 133, identifier:somatic_info; 134, identifier:tumor_name; 135, for_in_clause; 135, 136; 135, 137; 136, identifier:rec; 137, call; 137, 138; 137, 139; 138, identifier:filter; 139, argument_list; 139, 140; 139, 141; 140, identifier:check_fn; 141, identifier:bcf_in; 142, expression_statement; 142, 143; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:depths; 146, identifier:sort; 147, argument_list; 147, 148; 148, keyword_argument; 148, 149; 148, 150; 149, identifier:reverse; 150, True; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 154; 153, identifier:depth_thresh; 154, conditional_expression:if; 154, 155; 154, 165; 154, 166; 155, subscript; 155, 156; 155, 163; 156, subscript; 156, 157; 156, 158; 157, identifier:depths; 158, slice; 158, 159; 158, 160; 159, colon; 160, subscript; 160, 161; 160, 162; 161, identifier:config; 162, string:"sample_size"; 163, unary_operator:-; 163, 164; 164, integer:1; 165, identifier:depths; 166, integer:0; 167, with_statement; 167, 168; 167, 177; 168, with_clause; 168, 169; 169, with_item; 169, 170; 170, as_pattern; 170, 171; 170, 175; 171, call; 171, 172; 171, 173; 172, identifier:VariantFile; 173, argument_list; 173, 174; 174, identifier:in_file; 175, as_pattern_target; 175, 176; 176, identifier:bcf_in; 177, block; 177, 178; 178, with_statement; 178, 179; 178, 194; 179, with_clause; 179, 180; 180, with_item; 180, 181; 181, as_pattern; 181, 182; 181, 192; 182, call; 182, 183; 182, 184; 183, identifier:VariantFile; 184, argument_list; 184, 185; 184, 186; 184, 187; 185, identifier:tx_out_file_raw; 186, string:"w"; 187, keyword_argument; 187, 188; 187, 189; 188, identifier:header; 189, attribute; 189, 190; 189, 191; 190, identifier:bcf_in; 191, identifier:header; 192, as_pattern_target; 192, 193; 193, identifier:bcf_out; 194, block; 194, 195; 195, for_statement; 195, 196; 195, 197; 195, 198; 196, identifier:rec; 197, identifier:bcf_in; 198, block; 198, 199; 199, if_statement; 199, 200; 199, 220; 200, parenthesized_expression; 200, 201; 201, boolean_operator:and; 201, 202; 201, 206; 202, call; 202, 203; 202, 204; 203, identifier:check_fn; 204, argument_list; 204, 205; 205, identifier:rec; 206, parenthesized_expression; 206, 207; 207, boolean_operator:or; 207, 208; 207, 211; 208, comparison_operator:<; 208, 209; 208, 210; 209, identifier:depth_thresh; 210, integer:5; 211, comparison_operator:>=; 211, 212; 211, 219; 212, call; 212, 213; 212, 214; 213, identifier:_sample_depth; 214, argument_list; 214, 215; 214, 216; 215, identifier:rec; 216, attribute; 216, 217; 216, 218; 217, identifier:somatic_info; 218, identifier:tumor_name; 219, identifier:depth_thresh; 220, block; 220, 221; 221, expression_statement; 221, 222; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:bcf_out; 225, identifier:write; 226, argument_list; 226, 227; 227, identifier:rec; 228, with_statement; 228, 229; 228, 238; 229, with_clause; 229, 230; 230, with_item; 230, 231; 231, as_pattern; 231, 232; 231, 236; 232, call; 232, 233; 232, 234; 233, identifier:open; 234, argument_list; 234, 235; 235, identifier:tx_out_file_raw; 236, as_pattern_target; 236, 237; 237, identifier:in_handle; 238, block; 238, 239; 239, with_statement; 239, 240; 239, 250; 240, with_clause; 240, 241; 241, with_item; 241, 242; 242, as_pattern; 242, 243; 242, 248; 243, call; 243, 244; 243, 245; 244, identifier:open; 245, argument_list; 245, 246; 245, 247; 246, identifier:tx_out_file; 247, string:"w"; 248, as_pattern_target; 248, 249; 249, identifier:out_handle; 250, block; 250, 251; 251, for_statement; 251, 252; 251, 253; 251, 254; 251, 288; 252, identifier:line; 253, identifier:in_handle; 254, ERROR; 254, 255; 254, 282; 255, ERROR; 255, 256; 255, 269; 255, 275; 255, 276; 256, not_operator; 256, 257; 257, subscript; 257, 258; 257, 266; 257, 268; 258, call; 258, 259; 258, 262; 259, attribute; 259, 260; 259, 261; 260, identifier:line; 261, identifier:startswith; 262, argument_list; 262, 263; 262, 264; 263, string:"
parts = line.split("; 264, ERROR; 264, 265; 265, escape_sequence:\t; 266, ERROR; 266, 267; 267, identifier:parts; 268, integer:0; 269, call; 269, 270; 269, 271; 270, identifier:_phylowgs_compatible_chroms; 271, argument_list; 271, 272; 272, subscript; 272, 273; 272, 274; 273, identifier:parts; 274, integer:0; 275, identifier:line; 276, call; 276, 277; 276, 280; 277, attribute; 277, 278; 277, 279; 278, string:"\t"; 279, identifier:join; 280, argument_list; 280, 281; 281, identifier:parts; 282, call; 282, 283; 282, 286; 283, attribute; 283, 284; 283, 285; 284, identifier:out_handle; 285, identifier:write; 286, argument_list; 286, 287; 287, identifier:line; 288, block:; 289, return_statement; 289, 290; 290, expression_list; 290, 291; 290, 292; 291, identifier:variant_type; 292, identifier:out_file | def _prep_vrn_file(in_file, vcaller, work_dir, somatic_info, ignore_file, config):
if vcaller.startswith("vardict"):
variant_type = "vardict"
elif vcaller == "mutect":
variant_type = "mutect-smchet"
else:
raise ValueError("Unexpected variant caller for PhyloWGS prep: %s" % vcaller)
out_file = os.path.join(work_dir, "%s-%s-prep.vcf" % (utils.splitext_plus(os.path.basename(in_file))[0],
vcaller))
if not utils.file_uptodate(out_file, in_file):
check_fn = _min_sample_pass(ignore_file)
with file_transaction(somatic_info.tumor_data, out_file) as tx_out_file:
tx_out_file_raw = "%s-raw%s" % utils.splitext_plus(tx_out_file)
with VariantFile(in_file) as bcf_in:
depths = [_sample_depth(rec, somatic_info.tumor_name) for rec in
filter(check_fn, bcf_in)]
depths.sort(reverse=True)
depth_thresh = depths[:config["sample_size"]][-1] if depths else 0
with VariantFile(in_file) as bcf_in:
with VariantFile(tx_out_file_raw, "w", header=bcf_in.header) as bcf_out:
for rec in bcf_in:
if (check_fn(rec) and
(depth_thresh < 5 or _sample_depth(rec, somatic_info.tumor_name) >= depth_thresh)):
bcf_out.write(rec)
with open(tx_out_file_raw) as in_handle:
with open(tx_out_file, "w") as out_handle:
for line in in_handle:
if not line.startswith("
parts = line.split("\t")
parts[0] = _phylowgs_compatible_chroms(parts[0])
line = "\t".join(parts)
out_handle.write(line)
return variant_type, out_file |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:concat; 3, parameters; 3, 4; 3, 5; 4, identifier:bed_files; 5, default_parameter; 5, 6; 5, 7; 6, identifier:catted; 7, None; 8, block; 8, 9; 8, 19; 8, 68; 8, 113; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:bed_files; 12, list_comprehension; 12, 13; 12, 14; 12, 17; 13, identifier:x; 14, for_in_clause; 14, 15; 14, 16; 15, identifier:x; 16, identifier:bed_files; 17, if_clause; 17, 18; 18, identifier:x; 19, if_statement; 19, 20; 19, 26; 20, comparison_operator:==; 20, 21; 20, 25; 21, call; 21, 22; 21, 23; 22, identifier:len; 23, argument_list; 23, 24; 24, identifier:bed_files; 25, integer:0; 26, block; 26, 27; 27, if_statement; 27, 28; 27, 29; 27, 64; 28, identifier:catted; 29, block; 29, 30; 29, 38; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:sorted_bed; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:catted; 36, identifier:sort; 37, argument_list; 38, if_statement; 38, 39; 38, 48; 38, 60; 39, not_operator; 39, 40; 40, call; 40, 41; 40, 46; 41, attribute; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:sorted_bed; 44, identifier:fn; 45, identifier:endswith; 46, argument_list; 46, 47; 47, string:".bed"; 48, block; 48, 49; 49, return_statement; 49, 50; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:sorted_bed; 53, identifier:moveto; 54, argument_list; 54, 55; 55, binary_operator:+; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:sorted_bed; 58, identifier:fn; 59, string:".bed"; 60, else_clause; 60, 61; 61, block; 61, 62; 62, return_statement; 62, 63; 63, identifier:sorted_bed; 64, else_clause; 64, 65; 65, block; 65, 66; 66, return_statement; 66, 67; 67, identifier:catted; 68, if_statement; 68, 69; 68, 71; 68, 92; 69, not_operator; 69, 70; 70, identifier:catted; 71, block; 71, 72; 71, 79; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:bed_files; 75, call; 75, 76; 75, 77; 76, identifier:list; 77, argument_list; 77, 78; 78, identifier:bed_files; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:catted; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:bt; 85, identifier:BedTool; 86, argument_list; 86, 87; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:bed_files; 90, identifier:pop; 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:catted; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:catted; 100, identifier:cat; 101, argument_list; 101, 102; 101, 107; 101, 110; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:bed_files; 105, identifier:pop; 106, argument_list; 107, keyword_argument; 107, 108; 107, 109; 108, identifier:postmerge; 109, False; 110, keyword_argument; 110, 111; 110, 112; 111, identifier:force_truncate; 112, False; 113, return_statement; 113, 114; 114, call; 114, 115; 114, 116; 115, identifier:concat; 116, argument_list; 116, 117; 116, 118; 117, identifier:bed_files; 118, identifier:catted | def concat(bed_files, catted=None):
bed_files = [x for x in bed_files if x]
if len(bed_files) == 0:
if catted:
sorted_bed = catted.sort()
if not sorted_bed.fn.endswith(".bed"):
return sorted_bed.moveto(sorted_bed.fn + ".bed")
else:
return sorted_bed
else:
return catted
if not catted:
bed_files = list(bed_files)
catted = bt.BedTool(bed_files.pop())
else:
catted = catted.cat(bed_files.pop(), postmerge=False,
force_truncate=False)
return concat(bed_files, catted) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_get_sv_callers; 3, parameters; 3, 4; 4, identifier:items; 5, block; 5, 6; 5, 10; 5, 33; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:callers; 9, list:[]; 10, for_statement; 10, 11; 10, 12; 10, 13; 11, identifier:data; 12, identifier:items; 13, block; 13, 14; 14, for_statement; 14, 15; 14, 16; 14, 23; 15, identifier:sv; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:data; 19, identifier:get; 20, argument_list; 20, 21; 20, 22; 21, string:"sv"; 22, list:[]; 23, block; 23, 24; 24, expression_statement; 24, 25; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:callers; 28, identifier:append; 29, argument_list; 29, 30; 30, subscript; 30, 31; 30, 32; 31, identifier:sv; 32, string:"variantcaller"; 33, return_statement; 33, 34; 34, call; 34, 35; 34, 52; 35, attribute; 35, 36; 35, 51; 36, call; 36, 37; 36, 38; 37, identifier:list; 38, argument_list; 38, 39; 39, call; 39, 40; 39, 41; 40, identifier:set; 41, argument_list; 41, 42; 42, list_comprehension; 42, 43; 42, 44; 42, 47; 43, identifier:x; 44, for_in_clause; 44, 45; 44, 46; 45, identifier:x; 46, identifier:callers; 47, if_clause; 47, 48; 48, comparison_operator:!=; 48, 49; 48, 50; 49, identifier:x; 50, string:"sv-ensemble"; 51, identifier:sort; 52, argument_list | def _get_sv_callers(items):
callers = []
for data in items:
for sv in data.get("sv", []):
callers.append(sv["variantcaller"])
return list(set([x for x in callers if x != "sv-ensemble"])).sort() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:get_sort_cmd; 3, parameters; 3, 4; 4, default_parameter; 4, 5; 4, 6; 5, identifier:tmp_dir; 6, None; 7, block; 7, 8; 7, 24; 7, 37; 7, 64; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:has_versionsort; 11, call; 11, 12; 11, 23; 12, attribute; 12, 13; 12, 22; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:subprocess; 16, identifier:check_output; 17, argument_list; 17, 18; 17, 19; 18, string:"sort --help | grep version-sort; exit 0"; 19, keyword_argument; 19, 20; 19, 21; 20, identifier:shell; 21, True; 22, identifier:strip; 23, argument_list; 24, if_statement; 24, 25; 24, 26; 24, 31; 25, identifier:has_versionsort; 26, block; 26, 27; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:cmd; 30, string:"sort -V"; 31, else_clause; 31, 32; 32, block; 32, 33; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:cmd; 36, string:"sort"; 37, if_statement; 37, 38; 37, 57; 38, boolean_operator:and; 38, 39; 38, 49; 39, boolean_operator:and; 39, 40; 39, 41; 40, identifier:tmp_dir; 41, call; 41, 42; 41, 47; 42, attribute; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:os; 45, identifier:path; 46, identifier:exists; 47, argument_list; 47, 48; 48, identifier:tmp_dir; 49, call; 49, 50; 49, 55; 50, attribute; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:os; 53, identifier:path; 54, identifier:isdir; 55, argument_list; 55, 56; 56, identifier:tmp_dir; 57, block; 57, 58; 58, expression_statement; 58, 59; 59, augmented_assignment:+=; 59, 60; 59, 61; 60, identifier:cmd; 61, binary_operator:%; 61, 62; 61, 63; 62, string:" -T %s"; 63, identifier:tmp_dir; 64, return_statement; 64, 65; 65, identifier:cmd | def get_sort_cmd(tmp_dir=None):
has_versionsort = subprocess.check_output("sort --help | grep version-sort; exit 0", shell=True).strip()
if has_versionsort:
cmd = "sort -V"
else:
cmd = "sort"
if tmp_dir and os.path.exists(tmp_dir) and os.path.isdir(tmp_dir):
cmd += " -T %s" % tmp_dir
return cmd |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:clean_file; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:in_file; 5, identifier:data; 6, default_parameter; 6, 7; 6, 8; 7, identifier:prefix; 8, string:""; 9, default_parameter; 9, 10; 9, 11; 10, identifier:bedprep_dir; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:simple; 14, None; 15, block; 15, 16; 15, 23; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:simple; 19, conditional_expression:if; 19, 20; 19, 21; 19, 22; 20, string:"iconv -c -f utf-8 -t ascii | sed 's/ //g' |"; 21, identifier:simple; 22, string:""; 23, if_statement; 23, 24; 23, 25; 24, identifier:in_file; 25, block; 25, 26; 25, 51; 25, 70; 25, 93; 25, 103; 25, 120; 25, 216; 25, 233; 26, if_statement; 26, 27; 26, 29; 27, not_operator; 27, 28; 28, identifier:bedprep_dir; 29, block; 29, 30; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:bedprep_dir; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:utils; 36, identifier:safe_makedir; 37, argument_list; 37, 38; 38, call; 38, 39; 38, 44; 39, attribute; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:os; 42, identifier:path; 43, identifier:join; 44, argument_list; 44, 45; 44, 50; 45, subscript; 45, 46; 45, 49; 46, subscript; 46, 47; 46, 48; 47, identifier:data; 48, string:"dirs"; 49, string:"work"; 50, string:"bedprep"; 51, if_statement; 51, 52; 51, 67; 52, boolean_operator:and; 52, 53; 52, 54; 53, identifier:prefix; 54, call; 54, 55; 54, 65; 55, attribute; 55, 56; 55, 64; 56, call; 56, 57; 56, 62; 57, attribute; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:os; 60, identifier:path; 61, identifier:basename; 62, argument_list; 62, 63; 63, identifier:in_file; 64, identifier:startswith; 65, argument_list; 65, 66; 66, identifier:prefix; 67, block; 67, 68; 68, return_statement; 68, 69; 69, identifier:in_file; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:out_file; 73, call; 73, 74; 73, 79; 74, attribute; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:os; 77, identifier:path; 78, identifier:join; 79, argument_list; 79, 80; 79, 81; 80, identifier:bedprep_dir; 81, binary_operator:%; 81, 82; 81, 83; 82, string:"%s%s"; 83, tuple; 83, 84; 83, 85; 84, identifier:prefix; 85, call; 85, 86; 85, 91; 86, attribute; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:os; 89, identifier:path; 90, identifier:basename; 91, argument_list; 91, 92; 92, identifier:in_file; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:out_file; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:out_file; 99, identifier:replace; 100, argument_list; 100, 101; 100, 102; 101, string:".interval_list"; 102, string:".bed"; 103, if_statement; 103, 104; 103, 110; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:out_file; 107, identifier:endswith; 108, argument_list; 108, 109; 109, string:".gz"; 110, block; 110, 111; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:out_file; 114, subscript; 114, 115; 114, 116; 115, identifier:out_file; 116, slice; 116, 117; 116, 118; 117, colon; 118, unary_operator:-; 118, 119; 119, integer:3; 120, if_statement; 120, 121; 120, 129; 121, not_operator; 121, 122; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:utils; 125, identifier:file_uptodate; 126, argument_list; 126, 127; 126, 128; 127, identifier:out_file; 128, identifier:in_file; 129, block; 129, 130; 129, 136; 129, 142; 130, expression_statement; 130, 131; 131, call; 131, 132; 131, 133; 132, identifier:check_bed_contigs; 133, argument_list; 133, 134; 133, 135; 134, identifier:in_file; 135, identifier:data; 136, expression_statement; 136, 137; 137, call; 137, 138; 137, 139; 138, identifier:check_bed_coords; 139, argument_list; 139, 140; 139, 141; 140, identifier:in_file; 141, identifier:data; 142, with_statement; 142, 143; 142, 153; 143, with_clause; 143, 144; 144, with_item; 144, 145; 145, as_pattern; 145, 146; 145, 151; 146, call; 146, 147; 146, 148; 147, identifier:file_transaction; 148, argument_list; 148, 149; 148, 150; 149, identifier:data; 150, identifier:out_file; 151, as_pattern_target; 151, 152; 152, identifier:tx_out_file; 153, block; 153, 154; 153, 160; 153, 172; 153, 186; 153, 199; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 157; 156, identifier:bcbio_py; 157, attribute; 157, 158; 157, 159; 158, identifier:sys; 159, identifier:executable; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:cat_cmd; 163, conditional_expression:if; 163, 164; 163, 165; 163, 171; 164, string:"zcat"; 165, call; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:in_file; 168, identifier:endswith; 169, argument_list; 169, 170; 170, string:".gz"; 171, string:"cat"; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:sort_cmd; 175, call; 175, 176; 175, 177; 176, identifier:get_sort_cmd; 177, argument_list; 177, 178; 178, call; 178, 179; 178, 184; 179, attribute; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:os; 182, identifier:path; 183, identifier:dirname; 184, argument_list; 184, 185; 185, identifier:tx_out_file; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 189; 188, identifier:cmd; 189, parenthesized_expression; 189, 190; 190, binary_operator:^; 190, 191; 190, 196; 191, binary_operator:-; 191, 192; 191, 193; 191, 195; 192, string:"{cat_cmd} {in_file} | grep -v ^track | grep -v ^browser | grep -v ^@ | "; 193, ERROR; 193, 194; 194, identifier:grep; 195, identifier:v; 196, concatenated_string; 196, 197; 196, 198; 197, string:"{bcbio_py} -c 'from bcbio.variation import bedutils; bedutils.remove_bad()' | "; 198, string:"{sort_cmd} -k1,1 -k2,2n > {tx_out_file}"; 199, expression_statement; 199, 200; 200, call; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:do; 203, identifier:run; 204, argument_list; 204, 205; 204, 214; 204, 215; 205, call; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:cmd; 208, identifier:format; 209, argument_list; 209, 210; 210, dictionary_splat; 210, 211; 211, call; 211, 212; 211, 213; 212, identifier:locals; 213, argument_list; 214, string:"Prepare cleaned BED file"; 215, identifier:data; 216, expression_statement; 216, 217; 217, call; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:vcfutils; 220, identifier:bgzip_and_index; 221, argument_list; 221, 222; 221, 223; 221, 230; 222, identifier:out_file; 223, call; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:data; 226, identifier:get; 227, argument_list; 227, 228; 227, 229; 228, string:"config"; 229, dictionary; 230, keyword_argument; 230, 231; 230, 232; 231, identifier:remove_orig; 232, False; 233, return_statement; 233, 234; 234, identifier:out_file | def clean_file(in_file, data, prefix="", bedprep_dir=None, simple=None):
simple = "iconv -c -f utf-8 -t ascii | sed 's/ //g' |" if simple else ""
if in_file:
if not bedprep_dir:
bedprep_dir = utils.safe_makedir(os.path.join(data["dirs"]["work"], "bedprep"))
if prefix and os.path.basename(in_file).startswith(prefix):
return in_file
out_file = os.path.join(bedprep_dir, "%s%s" % (prefix, os.path.basename(in_file)))
out_file = out_file.replace(".interval_list", ".bed")
if out_file.endswith(".gz"):
out_file = out_file[:-3]
if not utils.file_uptodate(out_file, in_file):
check_bed_contigs(in_file, data)
check_bed_coords(in_file, data)
with file_transaction(data, out_file) as tx_out_file:
bcbio_py = sys.executable
cat_cmd = "zcat" if in_file.endswith(".gz") else "cat"
sort_cmd = get_sort_cmd(os.path.dirname(tx_out_file))
cmd = ("{cat_cmd} {in_file} | grep -v ^track | grep -v ^browser | grep -v ^@ | "
"grep -v ^
"{bcbio_py} -c 'from bcbio.variation import bedutils; bedutils.remove_bad()' | "
"{sort_cmd} -k1,1 -k2,2n > {tx_out_file}")
do.run(cmd.format(**locals()), "Prepare cleaned BED file", data)
vcfutils.bgzip_and_index(out_file, data.get("config", {}), remove_orig=False)
return out_file |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_sort_by_region; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:fnames; 5, identifier:regions; 6, identifier:ref_file; 7, identifier:config; 8, block; 8, 9; 8, 13; 8, 36; 8, 40; 8, 53; 8, 60; 8, 174; 8, 180; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:contig_order; 12, dictionary; 13, for_statement; 13, 14; 13, 17; 13, 27; 14, pattern_list; 14, 15; 14, 16; 15, identifier:i; 16, identifier:sq; 17, call; 17, 18; 17, 19; 18, identifier:enumerate; 19, argument_list; 19, 20; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:ref; 23, identifier:file_contigs; 24, argument_list; 24, 25; 24, 26; 25, identifier:ref_file; 26, identifier:config; 27, block; 27, 28; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 35; 30, subscript; 30, 31; 30, 32; 31, identifier:contig_order; 32, attribute; 32, 33; 32, 34; 33, identifier:sq; 34, identifier:name; 35, identifier:i; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:sitems; 39, list:[]; 40, assert_statement; 40, 41; 40, 50; 41, comparison_operator:==; 41, 42; 41, 46; 42, call; 42, 43; 42, 44; 43, identifier:len; 44, argument_list; 44, 45; 45, identifier:regions; 46, call; 46, 47; 46, 48; 47, identifier:len; 48, argument_list; 48, 49; 49, identifier:fnames; 50, tuple; 50, 51; 50, 52; 51, identifier:regions; 52, identifier:fnames; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:added_fnames; 56, call; 56, 57; 56, 58; 57, identifier:set; 58, argument_list; 58, 59; 59, list:[]; 60, for_statement; 60, 61; 60, 64; 60, 69; 61, pattern_list; 61, 62; 61, 63; 62, identifier:region; 63, identifier:fname; 64, call; 64, 65; 64, 66; 65, identifier:zip; 66, argument_list; 66, 67; 66, 68; 67, identifier:regions; 68, identifier:fnames; 69, block; 69, 70; 70, if_statement; 70, 71; 70, 74; 71, comparison_operator:not; 71, 72; 71, 73; 72, identifier:fname; 73, identifier:added_fnames; 74, block; 74, 75; 74, 152; 74, 167; 75, if_statement; 75, 76; 75, 83; 75, 91; 75, 138; 76, call; 76, 77; 76, 78; 77, identifier:isinstance; 78, argument_list; 78, 79; 78, 80; 79, identifier:region; 80, tuple; 80, 81; 80, 82; 81, identifier:list; 82, identifier:tuple; 83, block; 83, 84; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 90; 86, pattern_list; 86, 87; 86, 88; 86, 89; 87, identifier:c; 88, identifier:s; 89, identifier:e; 90, identifier:region; 91, elif_clause; 91, 92; 91, 108; 92, boolean_operator:and; 92, 93; 92, 100; 93, call; 93, 94; 93, 95; 94, identifier:isinstance; 95, argument_list; 95, 96; 95, 97; 96, identifier:region; 97, attribute; 97, 98; 97, 99; 98, identifier:six; 99, identifier:string_types; 100, comparison_operator:>=; 100, 101; 100, 107; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:region; 104, identifier:find; 105, argument_list; 105, 106; 106, string:":"; 107, integer:0; 108, block; 108, 109; 108, 120; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 114; 111, pattern_list; 111, 112; 111, 113; 112, identifier:c; 113, identifier:coords; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:region; 117, identifier:split; 118, argument_list; 118, 119; 119, string:":"; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 125; 122, pattern_list; 122, 123; 122, 124; 123, identifier:s; 124, identifier:e; 125, list_comprehension; 125, 126; 125, 130; 126, call; 126, 127; 126, 128; 127, identifier:int; 128, argument_list; 128, 129; 129, identifier:x; 130, for_in_clause; 130, 131; 130, 132; 131, identifier:x; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:coords; 135, identifier:split; 136, argument_list; 136, 137; 137, string:"-"; 138, else_clause; 138, 139; 139, block; 139, 140; 139, 144; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:c; 143, identifier:region; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 149; 146, pattern_list; 146, 147; 146, 148; 147, identifier:s; 148, identifier:e; 149, expression_list; 149, 150; 149, 151; 150, integer:0; 151, integer:0; 152, expression_statement; 152, 153; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:sitems; 156, identifier:append; 157, argument_list; 157, 158; 158, tuple; 158, 159; 158, 165; 158, 166; 159, tuple; 159, 160; 159, 163; 159, 164; 160, subscript; 160, 161; 160, 162; 161, identifier:contig_order; 162, identifier:c; 163, identifier:s; 164, identifier:e; 165, identifier:c; 166, identifier:fname; 167, expression_statement; 167, 168; 168, call; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:added_fnames; 171, identifier:add; 172, argument_list; 172, 173; 173, identifier:fname; 174, expression_statement; 174, 175; 175, call; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:sitems; 178, identifier:sort; 179, argument_list; 180, return_statement; 180, 181; 181, list_comprehension; 181, 182; 181, 189; 182, tuple; 182, 183; 182, 186; 183, subscript; 183, 184; 183, 185; 184, identifier:x; 185, integer:1; 186, subscript; 186, 187; 186, 188; 187, identifier:x; 188, integer:2; 189, for_in_clause; 189, 190; 189, 191; 190, identifier:x; 191, identifier:sitems | def _sort_by_region(fnames, regions, ref_file, config):
contig_order = {}
for i, sq in enumerate(ref.file_contigs(ref_file, config)):
contig_order[sq.name] = i
sitems = []
assert len(regions) == len(fnames), (regions, fnames)
added_fnames = set([])
for region, fname in zip(regions, fnames):
if fname not in added_fnames:
if isinstance(region, (list, tuple)):
c, s, e = region
elif isinstance(region, six.string_types) and region.find(":") >= 0:
c, coords = region.split(":")
s, e = [int(x) for x in coords.split("-")]
else:
c = region
s, e = 0, 0
sitems.append(((contig_order[c], s, e), c, fname))
added_fnames.add(fname)
sitems.sort()
return [(x[1], x[2]) for x in sitems] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:_get_file_list; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:orig_files; 5, identifier:out_file; 6, identifier:regions; 7, identifier:ref_file; 8, identifier:config; 9, block; 9, 10; 9, 20; 9, 46; 9, 102; 9, 117; 9, 130; 9, 155; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:sorted_files; 13, call; 13, 14; 13, 15; 14, identifier:_sort_by_region; 15, argument_list; 15, 16; 15, 17; 15, 18; 15, 19; 16, identifier:orig_files; 17, identifier:regions; 18, identifier:ref_file; 19, identifier:config; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:exist_files; 23, list_comprehension; 23, 24; 23, 27; 23, 32; 24, tuple; 24, 25; 24, 26; 25, identifier:c; 26, identifier:x; 27, for_in_clause; 27, 28; 27, 31; 28, pattern_list; 28, 29; 28, 30; 29, identifier:c; 30, identifier:x; 31, identifier:sorted_files; 32, if_clause; 32, 33; 33, boolean_operator:and; 33, 34; 33, 42; 34, call; 34, 35; 34, 40; 35, attribute; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:os; 38, identifier:path; 39, identifier:exists; 40, argument_list; 40, 41; 41, identifier:x; 42, call; 42, 43; 42, 44; 43, identifier:vcf_has_variants; 44, argument_list; 44, 45; 45, identifier:x; 46, if_statement; 46, 47; 46, 53; 46, 73; 46, 90; 47, comparison_operator:==; 47, 48; 47, 52; 48, call; 48, 49; 48, 50; 49, identifier:len; 50, argument_list; 50, 51; 51, identifier:exist_files; 52, integer:0; 53, block; 53, 54; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:exist_files; 57, list_comprehension; 57, 58; 57, 59; 57, 64; 58, identifier:x; 59, for_in_clause; 59, 60; 59, 63; 60, pattern_list; 60, 61; 60, 62; 61, identifier:c; 62, identifier:x; 63, identifier:sorted_files; 64, if_clause; 64, 65; 65, call; 65, 66; 65, 71; 66, attribute; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:os; 69, identifier:path; 70, identifier:exists; 71, argument_list; 71, 72; 72, identifier:x; 73, elif_clause; 73, 74; 73, 80; 74, comparison_operator:>; 74, 75; 74, 79; 75, call; 75, 76; 75, 77; 76, identifier:len; 77, argument_list; 77, 78; 78, identifier:exist_files; 79, integer:1; 80, block; 80, 81; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:exist_files; 84, call; 84, 85; 84, 86; 85, identifier:_fix_gatk_header; 86, argument_list; 86, 87; 86, 88; 86, 89; 87, identifier:exist_files; 88, identifier:out_file; 89, identifier:config; 90, else_clause; 90, 91; 91, block; 91, 92; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:exist_files; 95, list_comprehension; 95, 96; 95, 97; 96, identifier:x; 97, for_in_clause; 97, 98; 97, 101; 98, pattern_list; 98, 99; 98, 100; 99, identifier:c; 100, identifier:x; 101, identifier:exist_files; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:ready_files; 105, call; 105, 106; 105, 107; 106, identifier:run_multicore; 107, argument_list; 107, 108; 107, 109; 107, 116; 108, identifier:p_bgzip_and_index; 109, list_comprehension; 109, 110; 109, 113; 110, list:[x, config]; 110, 111; 110, 112; 111, identifier:x; 112, identifier:config; 113, for_in_clause; 113, 114; 113, 115; 114, identifier:x; 115, identifier:exist_files; 116, identifier:config; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:input_file_list; 120, binary_operator:%; 120, 121; 120, 122; 121, string:"%s-files.list"; 122, subscript; 122, 123; 122, 129; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:utils; 126, identifier:splitext_plus; 127, argument_list; 127, 128; 128, identifier:out_file; 129, integer:0; 130, with_statement; 130, 131; 130, 141; 131, with_clause; 131, 132; 132, with_item; 132, 133; 133, as_pattern; 133, 134; 133, 139; 134, call; 134, 135; 134, 136; 135, identifier:open; 136, argument_list; 136, 137; 136, 138; 137, identifier:input_file_list; 138, string:"w"; 139, as_pattern_target; 139, 140; 140, identifier:out_handle; 141, block; 141, 142; 142, for_statement; 142, 143; 142, 144; 142, 145; 143, identifier:fname; 144, identifier:ready_files; 145, block; 145, 146; 146, expression_statement; 146, 147; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:out_handle; 150, identifier:write; 151, argument_list; 151, 152; 152, binary_operator:+; 152, 153; 152, 154; 153, identifier:fname; 154, string:"\n"; 155, return_statement; 155, 156; 156, identifier:input_file_list | def _get_file_list(orig_files, out_file, regions, ref_file, config):
sorted_files = _sort_by_region(orig_files, regions, ref_file, config)
exist_files = [(c, x) for c, x in sorted_files if os.path.exists(x) and vcf_has_variants(x)]
if len(exist_files) == 0:
exist_files = [x for c, x in sorted_files if os.path.exists(x)]
elif len(exist_files) > 1:
exist_files = _fix_gatk_header(exist_files, out_file, config)
else:
exist_files = [x for c, x in exist_files]
ready_files = run_multicore(p_bgzip_and_index, [[x, config] for x in exist_files], config)
input_file_list = "%s-files.list" % utils.splitext_plus(out_file)[0]
with open(input_file_list, "w") as out_handle:
for fname in ready_files:
out_handle.write(fname + "\n")
return input_file_list |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:sort_by_ref; 3, parameters; 3, 4; 3, 5; 4, identifier:vcf_file; 5, identifier:data; 6, block; 6, 7; 6, 20; 6, 148; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:out_file; 10, binary_operator:%; 10, 11; 10, 12; 11, string:"%s-prep.vcf.gz"; 12, subscript; 12, 13; 12, 19; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:utils; 16, identifier:splitext_plus; 17, argument_list; 17, 18; 18, identifier:vcf_file; 19, integer:0; 20, if_statement; 20, 21; 20, 29; 21, not_operator; 21, 22; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:utils; 25, identifier:file_uptodate; 26, argument_list; 26, 27; 26, 28; 27, identifier:out_file; 28, identifier:vcf_file; 29, block; 29, 30; 30, with_statement; 30, 31; 30, 41; 31, with_clause; 31, 32; 32, with_item; 32, 33; 33, as_pattern; 33, 34; 33, 39; 34, call; 34, 35; 34, 36; 35, identifier:file_transaction; 36, argument_list; 36, 37; 36, 38; 37, identifier:data; 38, identifier:out_file; 39, as_pattern_target; 39, 40; 40, identifier:tx_out_file; 41, block; 41, 42; 41, 55; 41, 115; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:header_file; 45, binary_operator:%; 45, 46; 45, 47; 46, string:"%s-header.txt"; 47, subscript; 47, 48; 47, 54; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:utils; 51, identifier:splitext_plus; 52, argument_list; 52, 53; 53, identifier:tx_out_file; 54, integer:0; 55, with_statement; 55, 56; 55, 66; 56, with_clause; 56, 57; 57, with_item; 57, 58; 58, as_pattern; 58, 59; 58, 64; 59, call; 59, 60; 59, 61; 60, identifier:open; 61, argument_list; 61, 62; 61, 63; 62, identifier:header_file; 63, string:"w"; 64, as_pattern_target; 64, 65; 65, identifier:out_handle; 66, block; 66, 67; 67, for_statement; 67, 68; 67, 69; 67, 83; 68, identifier:region; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:ref; 72, identifier:file_contigs; 73, argument_list; 73, 74; 73, 80; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:dd; 77, identifier:get_ref_file; 78, argument_list; 78, 79; 79, identifier:data; 80, subscript; 80, 81; 80, 82; 81, identifier:data; 82, string:"config"; 83, block; 83, 84; 84, expression_statement; 84, 85; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:out_handle; 88, identifier:write; 89, argument_list; 89, 90; 89, 107; 90, ERROR; 90, 91; 90, 100; 90, 105; 91, attribute; 91, 92; 91, 97; 91, 99; 92, concatenated_string; 92, 93; 92, 94; 92, 96; 93, string:"
cat_cmd = "; 94, ERROR; 94, 95; 95, identifier:zcat; 96, string:" if vcf_file.endswith("; 97, ERROR; 97, 98; 98, identifier:vcf; 99, identifier:gz; 100, concatenated_string; 100, 101; 100, 102; 100, 104; 101, string:") else "; 102, ERROR; 102, 103; 103, identifier:cat; 104, string:"
cmd = ("; 105, set; 105, 106; 106, identifier:cat_cmd; 107, binary_operator:|; 107, 108; 107, 110; 108, set; 108, 109; 109, identifier:vcf_file; 110, binary_operator:^; 110, 111; 110, 114; 111, binary_operator:-; 111, 112; 111, 113; 112, identifier:grep; 113, identifier:v; 114, string:"vt sort -m full -o {tx_out_file} -"; 115, with_statement; 115, 116; 115, 131; 116, with_clause; 116, 117; 117, with_item; 117, 118; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:utils; 121, identifier:chdir; 122, argument_list; 122, 123; 123, call; 123, 124; 123, 129; 124, attribute; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:os; 127, identifier:path; 128, identifier:dirname; 129, argument_list; 129, 130; 130, identifier:tx_out_file; 131, block; 131, 132; 132, expression_statement; 132, 133; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:do; 136, identifier:run; 137, argument_list; 137, 138; 137, 147; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:cmd; 141, identifier:format; 142, argument_list; 142, 143; 143, dictionary_splat; 143, 144; 144, call; 144, 145; 144, 146; 145, identifier:locals; 146, argument_list; 147, string:"Sort VCF by reference"; 148, return_statement; 148, 149; 149, call; 149, 150; 149, 151; 150, identifier:bgzip_and_index; 151, argument_list; 151, 152; 151, 153; 152, identifier:out_file; 153, subscript; 153, 154; 153, 155; 154, identifier:data; 155, string:"config" | def sort_by_ref(vcf_file, data):
out_file = "%s-prep.vcf.gz" % utils.splitext_plus(vcf_file)[0]
if not utils.file_uptodate(out_file, vcf_file):
with file_transaction(data, out_file) as tx_out_file:
header_file = "%s-header.txt" % utils.splitext_plus(tx_out_file)[0]
with open(header_file, "w") as out_handle:
for region in ref.file_contigs(dd.get_ref_file(data), data["config"]):
out_handle.write("
cat_cmd = "zcat" if vcf_file.endswith("vcf.gz") else "cat"
cmd = ("{cat_cmd} {vcf_file} | grep -v ^
"vt sort -m full -o {tx_out_file} -")
with utils.chdir(os.path.dirname(tx_out_file)):
do.run(cmd.format(**locals()), "Sort VCF by reference")
return bgzip_and_index(out_file, data["config"]) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:align_to_sort_bam; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:fastq1; 5, identifier:fastq2; 6, identifier:aligner; 7, identifier:data; 8, block; 8, 9; 8, 15; 8, 28; 8, 47; 8, 55; 8, 72; 8, 85; 8, 122; 8, 211; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:names; 12, subscript; 12, 13; 12, 14; 13, identifier:data; 14, string:"rgnames"; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:align_dir_parts; 18, list:[data["dirs"]["work"], "align", names["sample"]]; 18, 19; 18, 24; 18, 25; 19, subscript; 19, 20; 19, 23; 20, subscript; 20, 21; 20, 22; 21, identifier:data; 22, string:"dirs"; 23, string:"work"; 24, string:"align"; 25, subscript; 25, 26; 25, 27; 26, identifier:names; 27, string:"sample"; 28, if_statement; 28, 29; 28, 35; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:data; 32, identifier:get; 33, argument_list; 33, 34; 34, string:"disambiguate"; 35, block; 35, 36; 36, expression_statement; 36, 37; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:align_dir_parts; 40, identifier:append; 41, argument_list; 41, 42; 42, subscript; 42, 43; 42, 46; 43, subscript; 43, 44; 43, 45; 44, identifier:data; 45, string:"disambiguate"; 46, string:"genome_build"; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:aligner_index; 50, call; 50, 51; 50, 52; 51, identifier:_get_aligner_index; 52, argument_list; 52, 53; 52, 54; 53, identifier:aligner; 54, identifier:data; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:align_dir; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:utils; 61, identifier:safe_makedir; 62, argument_list; 62, 63; 63, call; 63, 64; 63, 69; 64, attribute; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:os; 67, identifier:path; 68, identifier:join; 69, argument_list; 69, 70; 70, list_splat; 70, 71; 71, identifier:align_dir_parts; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:ref_file; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:tz; 78, identifier:get_in; 79, argument_list; 79, 80; 79, 84; 80, tuple; 80, 81; 80, 82; 80, 83; 81, string:"reference"; 82, string:"fasta"; 83, string:"base"; 84, identifier:data; 85, if_statement; 85, 86; 85, 92; 85, 106; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:fastq1; 89, identifier:endswith; 90, argument_list; 90, 91; 91, string:".bam"; 92, block; 92, 93; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:data; 96, call; 96, 97; 96, 98; 97, identifier:_align_from_bam; 98, argument_list; 98, 99; 98, 100; 98, 101; 98, 102; 98, 103; 98, 104; 98, 105; 99, identifier:fastq1; 100, identifier:aligner; 101, identifier:aligner_index; 102, identifier:ref_file; 103, identifier:names; 104, identifier:align_dir; 105, identifier:data; 106, else_clause; 106, 107; 107, block; 107, 108; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:data; 111, call; 111, 112; 111, 113; 112, identifier:_align_from_fastq; 113, argument_list; 113, 114; 113, 115; 113, 116; 113, 117; 113, 118; 113, 119; 113, 120; 113, 121; 114, identifier:fastq1; 115, identifier:fastq2; 116, identifier:aligner; 117, identifier:aligner_index; 118, identifier:ref_file; 119, identifier:names; 120, identifier:align_dir; 121, identifier:data; 122, if_statement; 122, 123; 122, 135; 123, boolean_operator:and; 123, 124; 123, 127; 124, subscript; 124, 125; 124, 126; 125, identifier:data; 126, string:"work_bam"; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:utils; 130, identifier:file_exists; 131, argument_list; 131, 132; 132, subscript; 132, 133; 132, 134; 133, identifier:data; 134, string:"work_bam"; 135, block; 135, 136; 135, 175; 136, if_statement; 136, 137; 136, 150; 136, 161; 137, boolean_operator:and; 137, 138; 137, 144; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:data; 141, identifier:get; 142, argument_list; 142, 143; 143, string:"align_split"; 144, call; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:dd; 147, identifier:get_mark_duplicates; 148, argument_list; 148, 149; 149, identifier:data; 150, block; 150, 151; 151, expression_statement; 151, 152; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:bam; 155, identifier:fake_index; 156, argument_list; 156, 157; 156, 160; 157, subscript; 157, 158; 157, 159; 158, identifier:data; 159, string:"work_bam"; 160, identifier:data; 161, else_clause; 161, 162; 162, block; 162, 163; 163, expression_statement; 163, 164; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:bam; 167, identifier:index; 168, argument_list; 168, 169; 168, 172; 169, subscript; 169, 170; 169, 171; 170, identifier:data; 171, string:"work_bam"; 172, subscript; 172, 173; 172, 174; 173, identifier:data; 174, string:"config"; 175, for_statement; 175, 176; 175, 177; 175, 180; 176, identifier:extra; 177, list:["-sr", "-disc"]; 177, 178; 177, 179; 178, string:"-sr"; 179, string:"-disc"; 180, block; 180, 181; 180, 193; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 184; 183, identifier:extra_bam; 184, call; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:utils; 187, identifier:append_stem; 188, argument_list; 188, 189; 188, 192; 189, subscript; 189, 190; 189, 191; 190, identifier:data; 191, string:'work_bam'; 192, identifier:extra; 193, if_statement; 193, 194; 193, 200; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:utils; 197, identifier:file_exists; 198, argument_list; 198, 199; 199, identifier:extra_bam; 200, block; 200, 201; 201, expression_statement; 201, 202; 202, call; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:bam; 205, identifier:index; 206, argument_list; 206, 207; 206, 208; 207, identifier:extra_bam; 208, subscript; 208, 209; 208, 210; 209, identifier:data; 210, string:"config"; 211, return_statement; 211, 212; 212, identifier:data | def align_to_sort_bam(fastq1, fastq2, aligner, data):
names = data["rgnames"]
align_dir_parts = [data["dirs"]["work"], "align", names["sample"]]
if data.get("disambiguate"):
align_dir_parts.append(data["disambiguate"]["genome_build"])
aligner_index = _get_aligner_index(aligner, data)
align_dir = utils.safe_makedir(os.path.join(*align_dir_parts))
ref_file = tz.get_in(("reference", "fasta", "base"), data)
if fastq1.endswith(".bam"):
data = _align_from_bam(fastq1, aligner, aligner_index, ref_file,
names, align_dir, data)
else:
data = _align_from_fastq(fastq1, fastq2, aligner, aligner_index, ref_file,
names, align_dir, data)
if data["work_bam"] and utils.file_exists(data["work_bam"]):
if data.get("align_split") and dd.get_mark_duplicates(data):
bam.fake_index(data["work_bam"], data)
else:
bam.index(data["work_bam"], data["config"])
for extra in ["-sr", "-disc"]:
extra_bam = utils.append_stem(data['work_bam'], extra)
if utils.file_exists(extra_bam):
bam.index(extra_bam, data["config"])
return data |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:_align_from_fastq; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 4, identifier:fastq1; 5, identifier:fastq2; 6, identifier:aligner; 7, identifier:align_ref; 8, identifier:sam_ref; 9, identifier:names; 10, identifier:align_dir; 11, identifier:data; 12, block; 12, 13; 12, 19; 12, 27; 12, 39; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:config; 16, subscript; 16, 17; 16, 18; 17, identifier:data; 18, string:"config"; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:align_fn; 22, attribute; 22, 23; 22, 26; 23, subscript; 23, 24; 23, 25; 24, identifier:TOOLS; 25, identifier:aligner; 26, identifier:align_fn; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:out; 30, call; 30, 31; 30, 32; 31, identifier:align_fn; 32, argument_list; 32, 33; 32, 34; 32, 35; 32, 36; 32, 37; 32, 38; 33, identifier:fastq1; 34, identifier:fastq2; 35, identifier:align_ref; 36, identifier:names; 37, identifier:align_dir; 38, identifier:data; 39, if_statement; 39, 40; 39, 45; 39, 68; 40, call; 40, 41; 40, 42; 41, identifier:isinstance; 42, argument_list; 42, 43; 42, 44; 43, identifier:out; 44, identifier:dict; 45, block; 45, 46; 45, 66; 46, assert_statement; 46, 47; 46, 53; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:out; 50, identifier:get; 51, argument_list; 51, 52; 52, string:"work_bam"; 53, tuple; 53, 54; 53, 60; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:dd; 57, identifier:get_sample_name; 58, argument_list; 58, 59; 59, identifier:data; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:out; 63, identifier:get; 64, argument_list; 64, 65; 65, string:"work_bam"; 66, return_statement; 66, 67; 67, identifier:out; 68, else_clause; 68, 69; 69, block; 69, 70; 69, 80; 69, 92; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:work_bam; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:bam; 76, identifier:sam_to_bam; 77, argument_list; 77, 78; 77, 79; 78, identifier:out; 79, identifier:config; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 85; 82, subscript; 82, 83; 82, 84; 83, identifier:data; 84, string:"work_bam"; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:bam; 88, identifier:sort; 89, argument_list; 89, 90; 89, 91; 90, identifier:work_bam; 91, identifier:config; 92, return_statement; 92, 93; 93, identifier:data | def _align_from_fastq(fastq1, fastq2, aligner, align_ref, sam_ref, names,
align_dir, data):
config = data["config"]
align_fn = TOOLS[aligner].align_fn
out = align_fn(fastq1, fastq2, align_ref, names, align_dir, data)
if isinstance(out, dict):
assert out.get("work_bam"), (dd.get_sample_name(data), out.get("work_bam"))
return out
else:
work_bam = bam.sam_to_bam(out, config)
data["work_bam"] = bam.sort(work_bam, config)
return data |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:picard_prep; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:in_bam; 5, identifier:names; 6, identifier:ref_file; 7, identifier:dirs; 8, identifier:data; 9, block; 9, 10; 9, 22; 9, 44; 9, 52; 9, 82; 9, 110; 9, 122; 9, 133; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:runner; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:broad; 16, identifier:runner_from_path; 17, argument_list; 17, 18; 17, 19; 18, string:"picard"; 19, subscript; 19, 20; 19, 21; 20, identifier:data; 21, string:"config"; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:work_dir; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:utils; 28, identifier:safe_makedir; 29, argument_list; 29, 30; 30, call; 30, 31; 30, 36; 31, attribute; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:os; 34, identifier:path; 35, identifier:join; 36, argument_list; 36, 37; 36, 40; 36, 41; 37, subscript; 37, 38; 37, 39; 38, identifier:dirs; 39, string:"work"; 40, string:"bamclean"; 41, subscript; 41, 42; 41, 43; 42, identifier:names; 43, string:"sample"; 44, expression_statement; 44, 45; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:runner; 48, identifier:run_fn; 49, argument_list; 49, 50; 49, 51; 50, string:"picard_index_ref"; 51, identifier:ref_file; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:reorder_bam; 55, call; 55, 56; 55, 61; 56, attribute; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:os; 59, identifier:path; 60, identifier:join; 61, argument_list; 61, 62; 61, 63; 62, identifier:work_dir; 63, binary_operator:%; 63, 64; 63, 65; 64, string:"%s-reorder.bam"; 65, subscript; 65, 66; 65, 81; 66, call; 66, 67; 66, 72; 67, attribute; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:os; 70, identifier:path; 71, identifier:splitext; 72, argument_list; 72, 73; 73, call; 73, 74; 73, 79; 74, attribute; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:os; 77, identifier:path; 78, identifier:basename; 79, argument_list; 79, 80; 80, identifier:in_bam; 81, integer:0; 82, if_statement; 82, 83; 82, 90; 83, not_operator; 83, 84; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:utils; 87, identifier:file_exists; 88, argument_list; 88, 89; 89, identifier:reorder_bam; 90, block; 90, 91; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:reorder_bam; 94, call; 94, 95; 94, 100; 95, attribute; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:os; 98, identifier:path; 99, identifier:join; 100, argument_list; 100, 101; 100, 102; 101, identifier:work_dir; 102, binary_operator:%; 102, 103; 102, 104; 103, string:"%s-reorder.bam"; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:dd; 107, identifier:get_sample_name; 108, argument_list; 108, 109; 109, identifier:data; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:reorder_bam; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:runner; 116, identifier:run_fn; 117, argument_list; 117, 118; 117, 119; 117, 120; 117, 121; 118, string:"picard_reorder"; 119, identifier:in_bam; 120, identifier:ref_file; 121, identifier:reorder_bam; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:rg_bam; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:runner; 128, identifier:run_fn; 129, argument_list; 129, 130; 129, 131; 129, 132; 130, string:"picard_fix_rgs"; 131, identifier:reorder_bam; 132, identifier:names; 133, return_statement; 133, 134; 134, call; 134, 135; 134, 136; 135, identifier:_filter_bad_reads; 136, argument_list; 136, 137; 136, 138; 136, 139; 137, identifier:rg_bam; 138, identifier:ref_file; 139, identifier:data | def picard_prep(in_bam, names, ref_file, dirs, data):
runner = broad.runner_from_path("picard", data["config"])
work_dir = utils.safe_makedir(os.path.join(dirs["work"], "bamclean", names["sample"]))
runner.run_fn("picard_index_ref", ref_file)
reorder_bam = os.path.join(work_dir, "%s-reorder.bam" %
os.path.splitext(os.path.basename(in_bam))[0])
if not utils.file_exists(reorder_bam):
reorder_bam = os.path.join(work_dir, "%s-reorder.bam" % dd.get_sample_name(data))
reorder_bam = runner.run_fn("picard_reorder", in_bam, ref_file, reorder_bam)
rg_bam = runner.run_fn("picard_fix_rgs", reorder_bam, names)
return _filter_bad_reads(rg_bam, ref_file, data) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:iterate_flattened_separately; 3, parameters; 3, 4; 3, 5; 4, identifier:dictionary; 5, default_parameter; 5, 6; 5, 7; 6, identifier:manually_sorted_keys; 7, None; 8, block; 8, 9; 8, 18; 8, 34; 8, 65; 8, 79; 8, 108; 9, if_statement; 9, 10; 9, 13; 10, comparison_operator:is; 10, 11; 10, 12; 11, identifier:manually_sorted_keys; 12, None; 13, block; 13, 14; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:manually_sorted_keys; 17, list:[]; 18, for_statement; 18, 19; 18, 20; 18, 21; 19, identifier:key; 20, identifier:manually_sorted_keys; 21, block; 21, 22; 22, if_statement; 22, 23; 22, 26; 23, comparison_operator:in; 23, 24; 23, 25; 24, identifier:key; 25, identifier:dictionary; 26, block; 26, 27; 27, expression_statement; 27, 28; 28, yield; 28, 29; 29, expression_list; 29, 30; 29, 31; 30, identifier:key; 31, subscript; 31, 32; 31, 33; 32, identifier:dictionary; 33, identifier:key; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:single_line_keys; 37, list_comprehension; 37, 38; 37, 39; 37, 46; 38, identifier:key; 39, for_in_clause; 39, 40; 39, 41; 40, identifier:key; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:dictionary; 44, identifier:keys; 45, argument_list; 46, if_clause; 46, 47; 47, boolean_operator:and; 47, 48; 47, 51; 48, comparison_operator:not; 48, 49; 48, 50; 49, identifier:key; 50, identifier:manually_sorted_keys; 51, parenthesized_expression; 51, 52; 52, boolean_operator:or; 52, 53; 52, 57; 53, not_operator; 53, 54; 54, subscript; 54, 55; 54, 56; 55, identifier:dictionary; 56, identifier:key; 57, not_operator; 57, 58; 58, call; 58, 59; 58, 60; 59, identifier:isinstance; 60, argument_list; 60, 61; 60, 64; 61, subscript; 61, 62; 61, 63; 62, identifier:dictionary; 63, identifier:key; 64, identifier:dict; 65, for_statement; 65, 66; 65, 67; 65, 71; 66, identifier:key; 67, call; 67, 68; 67, 69; 68, identifier:sorted; 69, argument_list; 69, 70; 70, identifier:single_line_keys; 71, block; 71, 72; 72, expression_statement; 72, 73; 73, yield; 73, 74; 74, expression_list; 74, 75; 74, 76; 75, identifier:key; 76, subscript; 76, 77; 76, 78; 77, identifier:dictionary; 78, identifier:key; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:multi_line_keys; 82, list_comprehension; 82, 83; 82, 84; 82, 91; 83, identifier:key; 84, for_in_clause; 84, 85; 84, 86; 85, identifier:key; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:dictionary; 89, identifier:keys; 90, argument_list; 91, if_clause; 91, 92; 92, boolean_operator:and; 92, 93; 92, 96; 93, comparison_operator:not; 93, 94; 93, 95; 94, identifier:key; 95, identifier:manually_sorted_keys; 96, parenthesized_expression; 96, 97; 97, boolean_operator:and; 97, 98; 97, 101; 98, subscript; 98, 99; 98, 100; 99, identifier:dictionary; 100, identifier:key; 101, call; 101, 102; 101, 103; 102, identifier:isinstance; 103, argument_list; 103, 104; 103, 107; 104, subscript; 104, 105; 104, 106; 105, identifier:dictionary; 106, identifier:key; 107, identifier:dict; 108, for_statement; 108, 109; 108, 110; 108, 114; 109, identifier:key; 110, call; 110, 111; 110, 112; 111, identifier:sorted; 112, argument_list; 112, 113; 113, identifier:multi_line_keys; 114, block; 114, 115; 114, 120; 115, expression_statement; 115, 116; 116, yield; 116, 117; 117, expression_list; 117, 118; 117, 119; 118, identifier:key; 119, identifier:PATHCHANGE; 120, for_statement; 120, 121; 120, 124; 120, 131; 121, pattern_list; 121, 122; 121, 123; 122, identifier:k; 123, identifier:val; 124, call; 124, 125; 124, 126; 125, identifier:iterate_flattened_separately; 126, argument_list; 126, 127; 126, 130; 127, subscript; 127, 128; 127, 129; 128, identifier:dictionary; 129, identifier:key; 130, identifier:manually_sorted_keys; 131, block; 131, 132; 132, expression_statement; 132, 133; 133, yield; 133, 134; 134, expression_list; 134, 135; 134, 140; 135, call; 135, 136; 135, 137; 136, identifier:join_paths; 137, argument_list; 137, 138; 137, 139; 138, identifier:key; 139, identifier:k; 140, identifier:val | def iterate_flattened_separately(dictionary, manually_sorted_keys=None):
if manually_sorted_keys is None:
manually_sorted_keys = []
for key in manually_sorted_keys:
if key in dictionary:
yield key, dictionary[key]
single_line_keys = [key for key in dictionary.keys() if
key not in manually_sorted_keys and
(not dictionary[key] or
not isinstance(dictionary[key], dict))]
for key in sorted(single_line_keys):
yield key, dictionary[key]
multi_line_keys = [key for key in dictionary.keys() if
key not in manually_sorted_keys and
(dictionary[key] and
isinstance(dictionary[key], dict))]
for key in sorted(multi_line_keys):
yield key, PATHCHANGE
for k, val in iterate_flattened_separately(dictionary[key],
manually_sorted_keys):
yield join_paths(key, k), val |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:gather_command_line_options; 3, parameters; 3, 4; 4, default_parameter; 4, 5; 4, 6; 5, identifier:filter_disabled; 6, None; 7, block; 7, 8; 7, 22; 7, 40; 8, if_statement; 8, 9; 8, 12; 9, comparison_operator:is; 9, 10; 9, 11; 10, identifier:filter_disabled; 11, None; 12, block; 12, 13; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:filter_disabled; 16, not_operator; 16, 17; 17, attribute; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:SETTINGS; 20, identifier:COMMAND_LINE; 21, identifier:SHOW_DISABLED_OPTIONS; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:options; 25, list_comprehension; 25, 26; 25, 27; 25, 33; 26, identifier:opt; 27, for_in_clause; 27, 28; 27, 29; 28, identifier:opt; 29, call; 29, 30; 29, 31; 30, identifier:get_inheritors; 31, argument_list; 31, 32; 32, identifier:CommandLineOption; 33, if_clause; 33, 34; 34, boolean_operator:or; 34, 35; 34, 37; 35, not_operator; 35, 36; 36, identifier:filter_disabled; 37, attribute; 37, 38; 37, 39; 38, identifier:opt; 39, identifier:_enabled; 40, return_statement; 40, 41; 41, call; 41, 42; 41, 43; 42, identifier:sorted; 43, argument_list; 43, 44; 43, 45; 44, identifier:options; 45, keyword_argument; 45, 46; 45, 47; 46, identifier:key; 47, lambda; 47, 48; 47, 50; 48, lambda_parameters; 48, 49; 49, identifier:opt; 50, attribute; 50, 51; 50, 52; 51, identifier:opt; 52, identifier:__name__ | def gather_command_line_options(filter_disabled=None):
if filter_disabled is None:
filter_disabled = not SETTINGS.COMMAND_LINE.SHOW_DISABLED_OPTIONS
options = [opt for opt in get_inheritors(CommandLineOption)
if not filter_disabled or opt._enabled]
return sorted(options, key=lambda opt: opt.__name__) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 37; 2, function_name:bar; 3, parameters; 3, 4; 3, 5; 3, 10; 3, 13; 3, 16; 3, 19; 3, 22; 3, 25; 3, 28; 3, 31; 3, 34; 4, identifier:df; 5, default_parameter; 5, 6; 5, 7; 6, identifier:figsize; 7, tuple; 7, 8; 7, 9; 8, integer:24; 9, integer:10; 10, default_parameter; 10, 11; 10, 12; 11, identifier:fontsize; 12, integer:16; 13, default_parameter; 13, 14; 13, 15; 14, identifier:labels; 15, None; 16, default_parameter; 16, 17; 16, 18; 17, identifier:log; 18, False; 19, default_parameter; 19, 20; 19, 21; 20, identifier:color; 21, string:'dimgray'; 22, default_parameter; 22, 23; 22, 24; 23, identifier:inline; 24, False; 25, default_parameter; 25, 26; 25, 27; 26, identifier:filter; 27, None; 28, default_parameter; 28, 29; 28, 30; 29, identifier:n; 30, integer:0; 31, default_parameter; 31, 32; 31, 33; 32, identifier:p; 33, integer:0; 34, default_parameter; 34, 35; 34, 36; 35, identifier:sort; 36, None; 37, block; 37, 38; 37, 55; 37, 71; 37, 81; 37, 90; 37, 117; 37, 125; 37, 130; 37, 287; 37, 295; 37, 302; 37, 313; 37, 324; 37, 342; 37, 349; 37, 415; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:nullity_counts; 41, binary_operator:-; 41, 42; 41, 46; 42, call; 42, 43; 42, 44; 43, identifier:len; 44, argument_list; 44, 45; 45, identifier:df; 46, call; 46, 47; 46, 54; 47, attribute; 47, 48; 47, 53; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:df; 51, identifier:isnull; 52, argument_list; 53, identifier:sum; 54, argument_list; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:df; 58, call; 58, 59; 58, 60; 59, identifier:nullity_filter; 60, argument_list; 60, 61; 60, 62; 60, 65; 60, 68; 61, identifier:df; 62, keyword_argument; 62, 63; 62, 64; 63, identifier:filter; 64, identifier:filter; 65, keyword_argument; 65, 66; 65, 67; 66, identifier:n; 67, identifier:n; 68, keyword_argument; 68, 69; 68, 70; 69, identifier:p; 70, identifier:p; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:df; 74, call; 74, 75; 74, 76; 75, identifier:nullity_sort; 76, argument_list; 76, 77; 76, 78; 77, identifier:df; 78, keyword_argument; 78, 79; 78, 80; 79, identifier:sort; 80, identifier:sort; 81, expression_statement; 81, 82; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:plt; 85, identifier:figure; 86, argument_list; 86, 87; 87, keyword_argument; 87, 88; 87, 89; 88, identifier:figsize; 89, identifier:figsize; 90, expression_statement; 90, 91; 91, call; 91, 92; 91, 101; 92, attribute; 92, 93; 92, 100; 93, parenthesized_expression; 93, 94; 94, binary_operator:/; 94, 95; 94, 96; 95, identifier:nullity_counts; 96, call; 96, 97; 96, 98; 97, identifier:len; 98, argument_list; 98, 99; 99, identifier:df; 100, identifier:plot; 101, argument_list; 101, 102; 101, 105; 101, 108; 101, 111; 101, 114; 102, keyword_argument; 102, 103; 102, 104; 103, identifier:kind; 104, string:'bar'; 105, keyword_argument; 105, 106; 105, 107; 106, identifier:figsize; 107, identifier:figsize; 108, keyword_argument; 108, 109; 108, 110; 109, identifier:fontsize; 110, identifier:fontsize; 111, keyword_argument; 111, 112; 111, 113; 112, identifier:log; 113, identifier:log; 114, keyword_argument; 114, 115; 114, 116; 115, identifier:color; 116, identifier:color; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:ax1; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:plt; 123, identifier:gca; 124, argument_list; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:axes; 128, list:[ax1]; 128, 129; 129, identifier:ax1; 130, if_statement; 130, 131; 130, 146; 130, 278; 131, boolean_operator:or; 131, 132; 131, 133; 132, identifier:labels; 133, parenthesized_expression; 133, 134; 134, boolean_operator:and; 134, 135; 134, 138; 135, comparison_operator:is; 135, 136; 135, 137; 136, identifier:labels; 137, None; 138, comparison_operator:<=; 138, 139; 138, 145; 139, call; 139, 140; 139, 141; 140, identifier:len; 141, argument_list; 141, 142; 142, attribute; 142, 143; 142, 144; 143, identifier:df; 144, identifier:columns; 145, integer:50; 146, block; 146, 147; 146, 167; 146, 175; 146, 182; 147, expression_statement; 147, 148; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:ax1; 151, identifier:set_xticklabels; 152, argument_list; 152, 153; 152, 158; 152, 161; 152, 164; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:ax1; 156, identifier:get_xticklabels; 157, argument_list; 158, keyword_argument; 158, 159; 158, 160; 159, identifier:rotation; 160, integer:45; 161, keyword_argument; 161, 162; 161, 163; 162, identifier:ha; 163, string:'right'; 164, keyword_argument; 164, 165; 164, 166; 165, identifier:fontsize; 166, identifier:fontsize; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 170; 169, identifier:ax2; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:ax1; 173, identifier:twinx; 174, argument_list; 175, expression_statement; 175, 176; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:axes; 179, identifier:append; 180, argument_list; 180, 181; 181, identifier:ax2; 182, if_statement; 182, 183; 182, 185; 182, 232; 183, not_operator; 183, 184; 184, identifier:log; 185, block; 185, 186; 185, 195; 185, 206; 186, expression_statement; 186, 187; 187, call; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:ax1; 190, identifier:set_ylim; 191, argument_list; 191, 192; 192, list:[0, 1]; 192, 193; 192, 194; 193, integer:0; 194, integer:1; 195, expression_statement; 195, 196; 196, call; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:ax2; 199, identifier:set_yticks; 200, argument_list; 200, 201; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:ax1; 204, identifier:get_yticks; 205, argument_list; 206, expression_statement; 206, 207; 207, call; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:ax2; 210, identifier:set_yticklabels; 211, argument_list; 211, 212; 211, 229; 212, list_comprehension; 212, 213; 212, 222; 213, call; 213, 214; 213, 215; 214, identifier:int; 215, argument_list; 215, 216; 216, binary_operator:*; 216, 217; 216, 218; 217, identifier:n; 218, call; 218, 219; 218, 220; 219, identifier:len; 220, argument_list; 220, 221; 221, identifier:df; 222, for_in_clause; 222, 223; 222, 224; 223, identifier:n; 224, call; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, identifier:ax1; 227, identifier:get_yticks; 228, argument_list; 229, keyword_argument; 229, 230; 229, 231; 230, identifier:fontsize; 231, identifier:fontsize; 232, else_clause; 232, 233; 233, block; 233, 234; 233, 241; 233, 252; 234, expression_statement; 234, 235; 235, call; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:ax2; 238, identifier:set_yscale; 239, argument_list; 239, 240; 240, string:'log'; 241, expression_statement; 241, 242; 242, call; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, identifier:ax2; 245, identifier:set_ylim; 246, argument_list; 246, 247; 247, call; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, identifier:ax1; 250, identifier:get_ylim; 251, argument_list; 252, expression_statement; 252, 253; 253, call; 253, 254; 253, 257; 254, attribute; 254, 255; 254, 256; 255, identifier:ax2; 256, identifier:set_yticklabels; 257, argument_list; 257, 258; 257, 275; 258, list_comprehension; 258, 259; 258, 268; 259, call; 259, 260; 259, 261; 260, identifier:int; 261, argument_list; 261, 262; 262, binary_operator:*; 262, 263; 262, 264; 263, identifier:n; 264, call; 264, 265; 264, 266; 265, identifier:len; 266, argument_list; 266, 267; 267, identifier:df; 268, for_in_clause; 268, 269; 268, 270; 269, identifier:n; 270, call; 270, 271; 270, 274; 271, attribute; 271, 272; 271, 273; 272, identifier:ax1; 273, identifier:get_yticks; 274, argument_list; 275, keyword_argument; 275, 276; 275, 277; 276, identifier:fontsize; 277, identifier:fontsize; 278, else_clause; 278, 279; 279, block; 279, 280; 280, expression_statement; 280, 281; 281, call; 281, 282; 281, 285; 282, attribute; 282, 283; 282, 284; 283, identifier:ax1; 284, identifier:set_xticks; 285, argument_list; 285, 286; 286, list:[]; 287, expression_statement; 287, 288; 288, assignment; 288, 289; 288, 290; 289, identifier:ax3; 290, call; 290, 291; 290, 294; 291, attribute; 291, 292; 291, 293; 292, identifier:ax1; 293, identifier:twiny; 294, argument_list; 295, expression_statement; 295, 296; 296, call; 296, 297; 296, 300; 297, attribute; 297, 298; 297, 299; 298, identifier:axes; 299, identifier:append; 300, argument_list; 300, 301; 301, identifier:ax3; 302, expression_statement; 302, 303; 303, call; 303, 304; 303, 307; 304, attribute; 304, 305; 304, 306; 305, identifier:ax3; 306, identifier:set_xticks; 307, argument_list; 307, 308; 308, call; 308, 309; 308, 312; 309, attribute; 309, 310; 309, 311; 310, identifier:ax1; 311, identifier:get_xticks; 312, argument_list; 313, expression_statement; 313, 314; 314, call; 314, 315; 314, 318; 315, attribute; 315, 316; 315, 317; 316, identifier:ax3; 317, identifier:set_xlim; 318, argument_list; 318, 319; 319, call; 319, 320; 319, 323; 320, attribute; 320, 321; 320, 322; 321, identifier:ax1; 322, identifier:get_xlim; 323, argument_list; 324, expression_statement; 324, 325; 325, call; 325, 326; 325, 329; 326, attribute; 326, 327; 326, 328; 327, identifier:ax3; 328, identifier:set_xticklabels; 329, argument_list; 329, 330; 329, 333; 329, 336; 329, 339; 330, attribute; 330, 331; 330, 332; 331, identifier:nullity_counts; 332, identifier:values; 333, keyword_argument; 333, 334; 333, 335; 334, identifier:fontsize; 335, identifier:fontsize; 336, keyword_argument; 336, 337; 336, 338; 337, identifier:rotation; 338, integer:45; 339, keyword_argument; 339, 340; 339, 341; 340, identifier:ha; 341, string:'left'; 342, expression_statement; 342, 343; 343, call; 343, 344; 343, 347; 344, attribute; 344, 345; 344, 346; 345, identifier:ax3; 346, identifier:grid; 347, argument_list; 347, 348; 348, False; 349, for_statement; 349, 350; 349, 351; 349, 352; 350, identifier:ax; 351, identifier:axes; 352, block; 352, 353; 352, 364; 352, 375; 352, 386; 352, 397; 352, 406; 353, expression_statement; 353, 354; 354, call; 354, 355; 354, 362; 355, attribute; 355, 356; 355, 361; 356, subscript; 356, 357; 356, 360; 357, attribute; 357, 358; 357, 359; 358, identifier:ax; 359, identifier:spines; 360, string:'top'; 361, identifier:set_visible; 362, argument_list; 362, 363; 363, False; 364, expression_statement; 364, 365; 365, call; 365, 366; 365, 373; 366, attribute; 366, 367; 366, 372; 367, subscript; 367, 368; 367, 371; 368, attribute; 368, 369; 368, 370; 369, identifier:ax; 370, identifier:spines; 371, string:'right'; 372, identifier:set_visible; 373, argument_list; 373, 374; 374, False; 375, expression_statement; 375, 376; 376, call; 376, 377; 376, 384; 377, attribute; 377, 378; 377, 383; 378, subscript; 378, 379; 378, 382; 379, attribute; 379, 380; 379, 381; 380, identifier:ax; 381, identifier:spines; 382, string:'bottom'; 383, identifier:set_visible; 384, argument_list; 384, 385; 385, False; 386, expression_statement; 386, 387; 387, call; 387, 388; 387, 395; 388, attribute; 388, 389; 388, 394; 389, subscript; 389, 390; 389, 393; 390, attribute; 390, 391; 390, 392; 391, identifier:ax; 392, identifier:spines; 393, string:'left'; 394, identifier:set_visible; 395, argument_list; 395, 396; 396, False; 397, expression_statement; 397, 398; 398, call; 398, 399; 398, 404; 399, attribute; 399, 400; 399, 403; 400, attribute; 400, 401; 400, 402; 401, identifier:ax; 402, identifier:xaxis; 403, identifier:set_ticks_position; 404, argument_list; 404, 405; 405, string:'none'; 406, expression_statement; 406, 407; 407, call; 407, 408; 407, 413; 408, attribute; 408, 409; 408, 412; 409, attribute; 409, 410; 409, 411; 410, identifier:ax; 411, identifier:yaxis; 412, identifier:set_ticks_position; 413, argument_list; 413, 414; 414, string:'none'; 415, if_statement; 415, 416; 415, 417; 415, 424; 416, identifier:inline; 417, block; 417, 418; 418, expression_statement; 418, 419; 419, call; 419, 420; 419, 423; 420, attribute; 420, 421; 420, 422; 421, identifier:plt; 422, identifier:show; 423, argument_list; 424, else_clause; 424, 425; 425, block; 425, 426; 426, return_statement; 426, 427; 427, identifier:ax1 | def bar(df, figsize=(24, 10), fontsize=16, labels=None, log=False, color='dimgray', inline=False,
filter=None, n=0, p=0, sort=None):
nullity_counts = len(df) - df.isnull().sum()
df = nullity_filter(df, filter=filter, n=n, p=p)
df = nullity_sort(df, sort=sort)
plt.figure(figsize=figsize)
(nullity_counts / len(df)).plot(kind='bar', figsize=figsize, fontsize=fontsize, log=log, color=color)
ax1 = plt.gca()
axes = [ax1]
if labels or (labels is None and len(df.columns) <= 50):
ax1.set_xticklabels(ax1.get_xticklabels(), rotation=45, ha='right', fontsize=fontsize)
ax2 = ax1.twinx()
axes.append(ax2)
if not log:
ax1.set_ylim([0, 1])
ax2.set_yticks(ax1.get_yticks())
ax2.set_yticklabels([int(n*len(df)) for n in ax1.get_yticks()], fontsize=fontsize)
else:
ax2.set_yscale('log')
ax2.set_ylim(ax1.get_ylim())
ax2.set_yticklabels([int(n*len(df)) for n in ax1.get_yticks()], fontsize=fontsize)
else:
ax1.set_xticks([])
ax3 = ax1.twiny()
axes.append(ax3)
ax3.set_xticks(ax1.get_xticks())
ax3.set_xlim(ax1.get_xlim())
ax3.set_xticklabels(nullity_counts.values, fontsize=fontsize, rotation=45, ha='left')
ax3.grid(False)
for ax in axes:
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['bottom'].set_visible(False)
ax.spines['left'].set_visible(False)
ax.xaxis.set_ticks_position('none')
ax.yaxis.set_ticks_position('none')
if inline:
plt.show()
else:
return ax1 |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 44; 2, function_name:heatmap; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 25; 3, 28; 3, 31; 3, 34; 3, 38; 3, 41; 4, identifier:df; 5, default_parameter; 5, 6; 5, 7; 6, identifier:inline; 7, False; 8, default_parameter; 8, 9; 8, 10; 9, identifier:filter; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:n; 13, integer:0; 14, default_parameter; 14, 15; 14, 16; 15, identifier:p; 16, integer:0; 17, default_parameter; 17, 18; 17, 19; 18, identifier:sort; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:figsize; 22, tuple; 22, 23; 22, 24; 23, integer:20; 24, integer:12; 25, default_parameter; 25, 26; 25, 27; 26, identifier:fontsize; 27, integer:16; 28, default_parameter; 28, 29; 28, 30; 29, identifier:labels; 30, True; 31, default_parameter; 31, 32; 31, 33; 32, identifier:cmap; 33, string:'RdBu'; 34, default_parameter; 34, 35; 34, 36; 35, identifier:vmin; 36, unary_operator:-; 36, 37; 37, integer:1; 38, default_parameter; 38, 39; 38, 40; 39, identifier:vmax; 40, integer:1; 41, default_parameter; 41, 42; 41, 43; 42, identifier:cbar; 43, True; 44, block; 44, 45; 44, 61; 44, 71; 44, 80; 44, 90; 44, 101; 44, 136; 44, 148; 44, 157; 44, 168; 44, 234; 44, 242; 44, 264; 44, 283; 44, 302; 44, 311; 44, 320; 44, 329; 44, 426; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:df; 48, call; 48, 49; 48, 50; 49, identifier:nullity_filter; 50, argument_list; 50, 51; 50, 52; 50, 55; 50, 58; 51, identifier:df; 52, keyword_argument; 52, 53; 52, 54; 53, identifier:filter; 54, identifier:filter; 55, keyword_argument; 55, 56; 55, 57; 56, identifier:n; 57, identifier:n; 58, keyword_argument; 58, 59; 58, 60; 59, identifier:p; 60, identifier:p; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:df; 64, call; 64, 65; 64, 66; 65, identifier:nullity_sort; 66, argument_list; 66, 67; 66, 68; 67, identifier:df; 68, keyword_argument; 68, 69; 68, 70; 69, identifier:sort; 70, identifier:sort; 71, expression_statement; 71, 72; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:plt; 75, identifier:figure; 76, argument_list; 76, 77; 77, keyword_argument; 77, 78; 77, 79; 78, identifier:figsize; 79, identifier:figsize; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:gs; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:gridspec; 86, identifier:GridSpec; 87, argument_list; 87, 88; 87, 89; 88, integer:1; 89, integer:1; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:ax0; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:plt; 96, identifier:subplot; 97, argument_list; 97, 98; 98, subscript; 98, 99; 98, 100; 99, identifier:gs; 100, integer:0; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:df; 104, subscript; 104, 105; 104, 108; 104, 110; 105, attribute; 105, 106; 105, 107; 106, identifier:df; 107, identifier:iloc; 108, slice; 108, 109; 109, colon; 110, list_comprehension; 110, 111; 110, 112; 110, 132; 111, identifier:i; 112, for_in_clause; 112, 113; 112, 116; 113, pattern_list; 113, 114; 113, 115; 114, identifier:i; 115, identifier:n; 116, call; 116, 117; 116, 118; 117, identifier:enumerate; 118, argument_list; 118, 119; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:np; 122, identifier:var; 123, argument_list; 123, 124; 123, 129; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:df; 127, identifier:isnull; 128, argument_list; 129, keyword_argument; 129, 130; 129, 131; 130, identifier:axis; 131, string:'rows'; 132, if_clause; 132, 133; 133, comparison_operator:>; 133, 134; 133, 135; 134, identifier:n; 135, integer:0; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 139; 138, identifier:corr_mat; 139, call; 139, 140; 139, 147; 140, attribute; 140, 141; 140, 146; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:df; 144, identifier:isnull; 145, argument_list; 146, identifier:corr; 147, argument_list; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 151; 150, identifier:mask; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:np; 154, identifier:zeros_like; 155, argument_list; 155, 156; 156, identifier:corr_mat; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 167; 159, subscript; 159, 160; 159, 161; 160, identifier:mask; 161, call; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:np; 164, identifier:triu_indices_from; 165, argument_list; 165, 166; 166, identifier:mask; 167, True; 168, if_statement; 168, 169; 168, 170; 168, 207; 169, identifier:labels; 170, block; 170, 171; 171, expression_statement; 171, 172; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:sns; 175, identifier:heatmap; 176, argument_list; 176, 177; 176, 178; 176, 181; 176, 184; 176, 187; 176, 190; 176, 193; 176, 201; 176, 204; 177, identifier:corr_mat; 178, keyword_argument; 178, 179; 178, 180; 179, identifier:mask; 180, identifier:mask; 181, keyword_argument; 181, 182; 181, 183; 182, identifier:cmap; 183, identifier:cmap; 184, keyword_argument; 184, 185; 184, 186; 185, identifier:ax; 186, identifier:ax0; 187, keyword_argument; 187, 188; 187, 189; 188, identifier:cbar; 189, identifier:cbar; 190, keyword_argument; 190, 191; 190, 192; 191, identifier:annot; 192, True; 193, keyword_argument; 193, 194; 193, 195; 194, identifier:annot_kws; 195, dictionary; 195, 196; 196, pair; 196, 197; 196, 198; 197, string:'size'; 198, binary_operator:-; 198, 199; 198, 200; 199, identifier:fontsize; 200, integer:2; 201, keyword_argument; 201, 202; 201, 203; 202, identifier:vmin; 203, identifier:vmin; 204, keyword_argument; 204, 205; 204, 206; 205, identifier:vmax; 206, identifier:vmax; 207, else_clause; 207, 208; 208, block; 208, 209; 209, expression_statement; 209, 210; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:sns; 213, identifier:heatmap; 214, argument_list; 214, 215; 214, 216; 214, 219; 214, 222; 214, 225; 214, 228; 214, 231; 215, identifier:corr_mat; 216, keyword_argument; 216, 217; 216, 218; 217, identifier:mask; 218, identifier:mask; 219, keyword_argument; 219, 220; 219, 221; 220, identifier:cmap; 221, identifier:cmap; 222, keyword_argument; 222, 223; 222, 224; 223, identifier:ax; 224, identifier:ax0; 225, keyword_argument; 225, 226; 225, 227; 226, identifier:cbar; 227, identifier:cbar; 228, keyword_argument; 228, 229; 228, 230; 229, identifier:vmin; 230, identifier:vmin; 231, keyword_argument; 231, 232; 231, 233; 232, identifier:vmax; 233, identifier:vmax; 234, expression_statement; 234, 235; 235, call; 235, 236; 235, 241; 236, attribute; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, identifier:ax0; 239, identifier:xaxis; 240, identifier:tick_bottom; 241, argument_list; 242, expression_statement; 242, 243; 243, call; 243, 244; 243, 247; 244, attribute; 244, 245; 244, 246; 245, identifier:ax0; 246, identifier:set_xticklabels; 247, argument_list; 247, 248; 247, 255; 247, 258; 247, 261; 248, call; 248, 249; 248, 254; 249, attribute; 249, 250; 249, 253; 250, attribute; 250, 251; 250, 252; 251, identifier:ax0; 252, identifier:xaxis; 253, identifier:get_majorticklabels; 254, argument_list; 255, keyword_argument; 255, 256; 255, 257; 256, identifier:rotation; 257, integer:45; 258, keyword_argument; 258, 259; 258, 260; 259, identifier:ha; 260, string:'right'; 261, keyword_argument; 261, 262; 261, 263; 262, identifier:fontsize; 263, identifier:fontsize; 264, expression_statement; 264, 265; 265, call; 265, 266; 265, 269; 266, attribute; 266, 267; 266, 268; 267, identifier:ax0; 268, identifier:set_yticklabels; 269, argument_list; 269, 270; 269, 277; 269, 280; 270, call; 270, 271; 270, 276; 271, attribute; 271, 272; 271, 275; 272, attribute; 272, 273; 272, 274; 273, identifier:ax0; 274, identifier:yaxis; 275, identifier:get_majorticklabels; 276, argument_list; 277, keyword_argument; 277, 278; 277, 279; 278, identifier:fontsize; 279, identifier:fontsize; 280, keyword_argument; 280, 281; 280, 282; 281, identifier:rotation; 282, integer:0; 283, expression_statement; 283, 284; 284, call; 284, 285; 284, 288; 285, attribute; 285, 286; 285, 287; 286, identifier:ax0; 287, identifier:set_yticklabels; 288, argument_list; 288, 289; 288, 296; 288, 299; 289, call; 289, 290; 289, 295; 290, attribute; 290, 291; 290, 294; 291, attribute; 291, 292; 291, 293; 292, identifier:ax0; 293, identifier:yaxis; 294, identifier:get_majorticklabels; 295, argument_list; 296, keyword_argument; 296, 297; 296, 298; 297, identifier:rotation; 298, integer:0; 299, keyword_argument; 299, 300; 299, 301; 300, identifier:fontsize; 301, identifier:fontsize; 302, expression_statement; 302, 303; 303, call; 303, 304; 303, 309; 304, attribute; 304, 305; 304, 308; 305, attribute; 305, 306; 305, 307; 306, identifier:ax0; 307, identifier:xaxis; 308, identifier:set_ticks_position; 309, argument_list; 309, 310; 310, string:'none'; 311, expression_statement; 311, 312; 312, call; 312, 313; 312, 318; 313, attribute; 313, 314; 313, 317; 314, attribute; 314, 315; 314, 316; 315, identifier:ax0; 316, identifier:yaxis; 317, identifier:set_ticks_position; 318, argument_list; 318, 319; 319, string:'none'; 320, expression_statement; 320, 321; 321, call; 321, 322; 321, 327; 322, attribute; 322, 323; 322, 326; 323, attribute; 323, 324; 323, 325; 324, identifier:ax0; 325, identifier:patch; 326, identifier:set_visible; 327, argument_list; 327, 328; 328, False; 329, for_statement; 329, 330; 329, 331; 329, 334; 330, identifier:text; 331, attribute; 331, 332; 331, 333; 332, identifier:ax0; 333, identifier:texts; 334, block; 334, 335; 334, 346; 335, expression_statement; 335, 336; 336, assignment; 336, 337; 336, 338; 337, identifier:t; 338, call; 338, 339; 338, 340; 339, identifier:float; 340, argument_list; 340, 341; 341, call; 341, 342; 341, 345; 342, attribute; 342, 343; 342, 344; 343, identifier:text; 344, identifier:get_text; 345, argument_list; 346, if_statement; 346, 347; 346, 351; 346, 359; 346, 374; 346, 386; 346, 399; 346, 413; 347, comparison_operator:<=; 347, 348; 347, 349; 347, 350; 348, float:0.95; 349, identifier:t; 350, integer:1; 351, block; 351, 352; 352, expression_statement; 352, 353; 353, call; 353, 354; 353, 357; 354, attribute; 354, 355; 354, 356; 355, identifier:text; 356, identifier:set_text; 357, argument_list; 357, 358; 358, string:'<1'; 359, elif_clause; 359, 360; 359, 366; 360, comparison_operator:<; 360, 361; 360, 363; 360, 364; 361, unary_operator:-; 361, 362; 362, integer:1; 363, identifier:t; 364, unary_operator:-; 364, 365; 365, float:0.95; 366, block; 366, 367; 367, expression_statement; 367, 368; 368, call; 368, 369; 368, 372; 369, attribute; 369, 370; 369, 371; 370, identifier:text; 371, identifier:set_text; 372, argument_list; 372, 373; 373, string:'>-1'; 374, elif_clause; 374, 375; 374, 378; 375, comparison_operator:==; 375, 376; 375, 377; 376, identifier:t; 377, integer:1; 378, block; 378, 379; 379, expression_statement; 379, 380; 380, call; 380, 381; 380, 384; 381, attribute; 381, 382; 381, 383; 382, identifier:text; 383, identifier:set_text; 384, argument_list; 384, 385; 385, string:'1'; 386, elif_clause; 386, 387; 386, 391; 387, comparison_operator:==; 387, 388; 387, 389; 388, identifier:t; 389, unary_operator:-; 389, 390; 390, integer:1; 391, block; 391, 392; 392, expression_statement; 392, 393; 393, call; 393, 394; 393, 397; 394, attribute; 394, 395; 394, 396; 395, identifier:text; 396, identifier:set_text; 397, argument_list; 397, 398; 398, string:'-1'; 399, elif_clause; 399, 400; 399, 405; 400, comparison_operator:<; 400, 401; 400, 403; 400, 404; 401, unary_operator:-; 401, 402; 402, float:0.05; 403, identifier:t; 404, float:0.05; 405, block; 405, 406; 406, expression_statement; 406, 407; 407, call; 407, 408; 407, 411; 408, attribute; 408, 409; 408, 410; 409, identifier:text; 410, identifier:set_text; 411, argument_list; 411, 412; 412, string:''; 413, else_clause; 413, 414; 414, block; 414, 415; 415, expression_statement; 415, 416; 416, call; 416, 417; 416, 420; 417, attribute; 417, 418; 417, 419; 418, identifier:text; 419, identifier:set_text; 420, argument_list; 420, 421; 421, call; 421, 422; 421, 423; 422, identifier:round; 423, argument_list; 423, 424; 423, 425; 424, identifier:t; 425, integer:1; 426, if_statement; 426, 427; 426, 428; 426, 435; 427, identifier:inline; 428, block; 428, 429; 429, expression_statement; 429, 430; 430, call; 430, 431; 430, 434; 431, attribute; 431, 432; 431, 433; 432, identifier:plt; 433, identifier:show; 434, argument_list; 435, else_clause; 435, 436; 436, block; 436, 437; 437, return_statement; 437, 438; 438, identifier:ax0 | def heatmap(df, inline=False,
filter=None, n=0, p=0, sort=None,
figsize=(20, 12), fontsize=16, labels=True,
cmap='RdBu', vmin=-1, vmax=1, cbar=True
):
df = nullity_filter(df, filter=filter, n=n, p=p)
df = nullity_sort(df, sort=sort)
plt.figure(figsize=figsize)
gs = gridspec.GridSpec(1, 1)
ax0 = plt.subplot(gs[0])
df = df.iloc[:,[i for i, n in enumerate(np.var(df.isnull(), axis='rows')) if n > 0]]
corr_mat = df.isnull().corr()
mask = np.zeros_like(corr_mat)
mask[np.triu_indices_from(mask)] = True
if labels:
sns.heatmap(corr_mat, mask=mask, cmap=cmap, ax=ax0, cbar=cbar,
annot=True, annot_kws={'size': fontsize - 2},
vmin=vmin, vmax=vmax)
else:
sns.heatmap(corr_mat, mask=mask, cmap=cmap, ax=ax0, cbar=cbar,
vmin=vmin, vmax=vmax)
ax0.xaxis.tick_bottom()
ax0.set_xticklabels(ax0.xaxis.get_majorticklabels(), rotation=45, ha='right', fontsize=fontsize)
ax0.set_yticklabels(ax0.yaxis.get_majorticklabels(), fontsize=fontsize, rotation=0)
ax0.set_yticklabels(ax0.yaxis.get_majorticklabels(), rotation=0, fontsize=fontsize)
ax0.xaxis.set_ticks_position('none')
ax0.yaxis.set_ticks_position('none')
ax0.patch.set_visible(False)
for text in ax0.texts:
t = float(text.get_text())
if 0.95 <= t < 1:
text.set_text('<1')
elif -1 < t <= -0.95:
text.set_text('>-1')
elif t == 1:
text.set_text('1')
elif t == -1:
text.set_text('-1')
elif -0.05 < t < 0.05:
text.set_text('')
else:
text.set_text(round(t, 1))
if inline:
plt.show()
else:
return ax0 |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 32; 2, function_name:dendrogram; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 3, 29; 4, identifier:df; 5, default_parameter; 5, 6; 5, 7; 6, identifier:method; 7, string:'average'; 8, default_parameter; 8, 9; 8, 10; 9, identifier:filter; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:n; 13, integer:0; 14, default_parameter; 14, 15; 14, 16; 15, identifier:p; 16, integer:0; 17, default_parameter; 17, 18; 17, 19; 18, identifier:sort; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:orientation; 22, None; 23, default_parameter; 23, 24; 23, 25; 24, identifier:figsize; 25, None; 26, default_parameter; 26, 27; 26, 28; 27, identifier:fontsize; 28, integer:16; 29, default_parameter; 29, 30; 29, 31; 30, identifier:inline; 31, False; 32, block; 32, 33; 32, 81; 32, 90; 32, 100; 32, 111; 32, 127; 32, 137; 32, 157; 32, 167; 32, 191; 32, 225; 32, 232; 32, 241; 32, 254; 32, 263; 32, 272; 32, 283; 32, 294; 32, 305; 32, 316; 32, 325; 32, 373; 32, 422; 33, if_statement; 33, 34; 33, 36; 34, not_operator; 34, 35; 35, identifier:figsize; 36, block; 36, 37; 37, if_statement; 37, 38; 37, 54; 37, 61; 38, boolean_operator:or; 38, 39; 38, 51; 39, boolean_operator:or; 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:df; 46, identifier:columns; 47, integer:50; 48, comparison_operator:==; 48, 49; 48, 50; 49, identifier:orientation; 50, string:'top'; 51, comparison_operator:==; 51, 52; 51, 53; 52, identifier:orientation; 53, string:'bottom'; 54, block; 54, 55; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:figsize; 58, tuple; 58, 59; 58, 60; 59, integer:25; 60, integer:10; 61, else_clause; 61, 62; 62, block; 62, 63; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:figsize; 66, tuple; 66, 67; 66, 68; 67, integer:25; 68, binary_operator:*; 68, 69; 68, 80; 69, parenthesized_expression; 69, 70; 70, binary_operator:-; 70, 71; 70, 79; 71, binary_operator:+; 71, 72; 71, 73; 72, integer:25; 73, call; 73, 74; 73, 75; 74, identifier:len; 75, argument_list; 75, 76; 76, attribute; 76, 77; 76, 78; 77, identifier:df; 78, identifier:columns; 79, integer:50; 80, float:0.5; 81, expression_statement; 81, 82; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:plt; 85, identifier:figure; 86, argument_list; 86, 87; 87, keyword_argument; 87, 88; 87, 89; 88, identifier:figsize; 89, identifier:figsize; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:gs; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:gridspec; 96, identifier:GridSpec; 97, argument_list; 97, 98; 97, 99; 98, integer:1; 99, integer:1; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:ax0; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:plt; 106, identifier:subplot; 107, argument_list; 107, 108; 108, subscript; 108, 109; 108, 110; 109, identifier:gs; 110, integer:0; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:df; 114, call; 114, 115; 114, 116; 115, identifier:nullity_filter; 116, argument_list; 116, 117; 116, 118; 116, 121; 116, 124; 117, identifier:df; 118, keyword_argument; 118, 119; 118, 120; 119, identifier:filter; 120, identifier:filter; 121, keyword_argument; 121, 122; 121, 123; 122, identifier:n; 123, identifier:n; 124, keyword_argument; 124, 125; 124, 126; 125, identifier:p; 126, identifier:p; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:df; 130, call; 130, 131; 130, 132; 131, identifier:nullity_sort; 132, argument_list; 132, 133; 132, 134; 133, identifier:df; 134, keyword_argument; 134, 135; 134, 136; 135, identifier:sort; 136, identifier:sort; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:x; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:np; 143, identifier:transpose; 144, argument_list; 144, 145; 145, attribute; 145, 146; 145, 156; 146, call; 146, 147; 146, 154; 147, attribute; 147, 148; 147, 153; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:df; 151, identifier:isnull; 152, argument_list; 153, identifier:astype; 154, argument_list; 154, 155; 155, identifier:int; 156, identifier:values; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:z; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:hierarchy; 163, identifier:linkage; 164, argument_list; 164, 165; 164, 166; 165, identifier:x; 166, identifier:method; 167, if_statement; 167, 168; 167, 170; 168, not_operator; 168, 169; 169, identifier:orientation; 170, block; 170, 171; 171, if_statement; 171, 172; 171, 180; 171, 185; 172, comparison_operator:>; 172, 173; 172, 179; 173, call; 173, 174; 173, 175; 174, identifier:len; 175, argument_list; 175, 176; 176, attribute; 176, 177; 176, 178; 177, identifier:df; 178, identifier:columns; 179, integer:50; 180, block; 180, 181; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 184; 183, identifier:orientation; 184, string:'left'; 185, else_clause; 185, 186; 186, block; 186, 187; 187, expression_statement; 187, 188; 188, assignment; 188, 189; 188, 190; 189, identifier:orientation; 190, string:'bottom'; 191, expression_statement; 191, 192; 192, call; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:hierarchy; 195, identifier:dendrogram; 196, argument_list; 196, 197; 196, 198; 196, 201; 196, 210; 196, 213; 196, 219; 196, 222; 197, identifier:z; 198, keyword_argument; 198, 199; 198, 200; 199, identifier:orientation; 200, identifier:orientation; 201, keyword_argument; 201, 202; 201, 203; 202, identifier:labels; 203, call; 203, 204; 203, 209; 204, attribute; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:df; 207, identifier:columns; 208, identifier:tolist; 209, argument_list; 210, keyword_argument; 210, 211; 210, 212; 211, identifier:distance_sort; 212, string:'descending'; 213, keyword_argument; 213, 214; 213, 215; 214, identifier:link_color_func; 215, lambda; 215, 216; 215, 218; 216, lambda_parameters; 216, 217; 217, identifier:c; 218, string:'black'; 219, keyword_argument; 219, 220; 219, 221; 220, identifier:leaf_font_size; 221, identifier:fontsize; 222, keyword_argument; 222, 223; 222, 224; 223, identifier:ax; 224, identifier:ax0; 225, expression_statement; 225, 226; 226, call; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:ax0; 229, identifier:set_aspect; 230, argument_list; 230, 231; 231, string:'auto'; 232, expression_statement; 232, 233; 233, call; 233, 234; 233, 237; 234, attribute; 234, 235; 234, 236; 235, identifier:ax0; 236, identifier:grid; 237, argument_list; 237, 238; 238, keyword_argument; 238, 239; 238, 240; 239, identifier:b; 240, False; 241, if_statement; 241, 242; 241, 245; 242, comparison_operator:==; 242, 243; 242, 244; 243, identifier:orientation; 244, string:'bottom'; 245, block; 245, 246; 246, expression_statement; 246, 247; 247, call; 247, 248; 247, 253; 248, attribute; 248, 249; 248, 252; 249, attribute; 249, 250; 249, 251; 250, identifier:ax0; 251, identifier:xaxis; 252, identifier:tick_top; 253, argument_list; 254, expression_statement; 254, 255; 255, call; 255, 256; 255, 261; 256, attribute; 256, 257; 256, 260; 257, attribute; 257, 258; 257, 259; 258, identifier:ax0; 259, identifier:xaxis; 260, identifier:set_ticks_position; 261, argument_list; 261, 262; 262, string:'none'; 263, expression_statement; 263, 264; 264, call; 264, 265; 264, 270; 265, attribute; 265, 266; 265, 269; 266, attribute; 266, 267; 266, 268; 267, identifier:ax0; 268, identifier:yaxis; 269, identifier:set_ticks_position; 270, argument_list; 270, 271; 271, string:'none'; 272, expression_statement; 272, 273; 273, call; 273, 274; 273, 281; 274, attribute; 274, 275; 274, 280; 275, subscript; 275, 276; 275, 279; 276, attribute; 276, 277; 276, 278; 277, identifier:ax0; 278, identifier:spines; 279, string:'top'; 280, identifier:set_visible; 281, argument_list; 281, 282; 282, False; 283, expression_statement; 283, 284; 284, call; 284, 285; 284, 292; 285, attribute; 285, 286; 285, 291; 286, subscript; 286, 287; 286, 290; 287, attribute; 287, 288; 287, 289; 288, identifier:ax0; 289, identifier:spines; 290, string:'right'; 291, identifier:set_visible; 292, argument_list; 292, 293; 293, False; 294, expression_statement; 294, 295; 295, call; 295, 296; 295, 303; 296, attribute; 296, 297; 296, 302; 297, subscript; 297, 298; 297, 301; 298, attribute; 298, 299; 298, 300; 299, identifier:ax0; 300, identifier:spines; 301, string:'bottom'; 302, identifier:set_visible; 303, argument_list; 303, 304; 304, False; 305, expression_statement; 305, 306; 306, call; 306, 307; 306, 314; 307, attribute; 307, 308; 307, 313; 308, subscript; 308, 309; 308, 312; 309, attribute; 309, 310; 309, 311; 310, identifier:ax0; 311, identifier:spines; 312, string:'left'; 313, identifier:set_visible; 314, argument_list; 314, 315; 315, False; 316, expression_statement; 316, 317; 317, call; 317, 318; 317, 323; 318, attribute; 318, 319; 318, 322; 319, attribute; 319, 320; 319, 321; 320, identifier:ax0; 321, identifier:patch; 322, identifier:set_visible; 323, argument_list; 323, 324; 324, False; 325, if_statement; 325, 326; 325, 329; 325, 349; 326, comparison_operator:==; 326, 327; 326, 328; 327, identifier:orientation; 328, string:'bottom'; 329, block; 329, 330; 330, expression_statement; 330, 331; 331, call; 331, 332; 331, 335; 332, attribute; 332, 333; 332, 334; 333, identifier:ax0; 334, identifier:set_xticklabels; 335, argument_list; 335, 336; 335, 343; 335, 346; 336, call; 336, 337; 336, 342; 337, attribute; 337, 338; 337, 341; 338, attribute; 338, 339; 338, 340; 339, identifier:ax0; 340, identifier:xaxis; 341, identifier:get_majorticklabels; 342, argument_list; 343, keyword_argument; 343, 344; 343, 345; 344, identifier:rotation; 345, integer:45; 346, keyword_argument; 346, 347; 346, 348; 347, identifier:ha; 348, string:'left'; 349, elif_clause; 349, 350; 349, 353; 350, comparison_operator:==; 350, 351; 350, 352; 351, identifier:orientation; 352, string:'top'; 353, block; 353, 354; 354, expression_statement; 354, 355; 355, call; 355, 356; 355, 359; 356, attribute; 356, 357; 356, 358; 357, identifier:ax0; 358, identifier:set_xticklabels; 359, argument_list; 359, 360; 359, 367; 359, 370; 360, call; 360, 361; 360, 366; 361, attribute; 361, 362; 361, 365; 362, attribute; 362, 363; 362, 364; 363, identifier:ax0; 364, identifier:xaxis; 365, identifier:get_majorticklabels; 366, argument_list; 367, keyword_argument; 367, 368; 367, 369; 368, identifier:rotation; 369, integer:45; 370, keyword_argument; 370, 371; 370, 372; 371, identifier:ha; 372, string:'right'; 373, if_statement; 373, 374; 373, 381; 373, 401; 374, boolean_operator:or; 374, 375; 374, 378; 375, comparison_operator:==; 375, 376; 375, 377; 376, identifier:orientation; 377, string:'bottom'; 378, comparison_operator:==; 378, 379; 378, 380; 379, identifier:orientation; 380, string:'top'; 381, block; 381, 382; 382, expression_statement; 382, 383; 383, call; 383, 384; 383, 387; 384, attribute; 384, 385; 384, 386; 385, identifier:ax0; 386, identifier:tick_params; 387, argument_list; 387, 388; 387, 391; 388, keyword_argument; 388, 389; 388, 390; 389, identifier:axis; 390, string:'y'; 391, keyword_argument; 391, 392; 391, 393; 392, identifier:labelsize; 393, call; 393, 394; 393, 395; 394, identifier:int; 395, argument_list; 395, 396; 396, binary_operator:*; 396, 397; 396, 400; 397, binary_operator:/; 397, 398; 397, 399; 398, identifier:fontsize; 399, integer:16; 400, integer:20; 401, else_clause; 401, 402; 402, block; 402, 403; 403, expression_statement; 403, 404; 404, call; 404, 405; 404, 408; 405, attribute; 405, 406; 405, 407; 406, identifier:ax0; 407, identifier:tick_params; 408, argument_list; 408, 409; 408, 412; 409, keyword_argument; 409, 410; 409, 411; 410, identifier:axis; 411, string:'x'; 412, keyword_argument; 412, 413; 412, 414; 413, identifier:labelsize; 414, call; 414, 415; 414, 416; 415, identifier:int; 416, argument_list; 416, 417; 417, binary_operator:*; 417, 418; 417, 421; 418, binary_operator:/; 418, 419; 418, 420; 419, identifier:fontsize; 420, integer:16; 421, integer:20; 422, if_statement; 422, 423; 422, 424; 422, 431; 423, identifier:inline; 424, block; 424, 425; 425, expression_statement; 425, 426; 426, call; 426, 427; 426, 430; 427, attribute; 427, 428; 427, 429; 428, identifier:plt; 429, identifier:show; 430, argument_list; 431, else_clause; 431, 432; 432, block; 432, 433; 433, return_statement; 433, 434; 434, identifier:ax0 | def dendrogram(df, method='average',
filter=None, n=0, p=0, sort=None,
orientation=None, figsize=None,
fontsize=16, inline=False
):
if not figsize:
if len(df.columns) <= 50 or orientation == 'top' or orientation == 'bottom':
figsize = (25, 10)
else:
figsize = (25, (25 + len(df.columns) - 50)*0.5)
plt.figure(figsize=figsize)
gs = gridspec.GridSpec(1, 1)
ax0 = plt.subplot(gs[0])
df = nullity_filter(df, filter=filter, n=n, p=p)
df = nullity_sort(df, sort=sort)
x = np.transpose(df.isnull().astype(int).values)
z = hierarchy.linkage(x, method)
if not orientation:
if len(df.columns) > 50:
orientation = 'left'
else:
orientation = 'bottom'
hierarchy.dendrogram(z,
orientation=orientation,
labels=df.columns.tolist(),
distance_sort='descending',
link_color_func=lambda c: 'black',
leaf_font_size=fontsize,
ax=ax0
)
ax0.set_aspect('auto')
ax0.grid(b=False)
if orientation == 'bottom':
ax0.xaxis.tick_top()
ax0.xaxis.set_ticks_position('none')
ax0.yaxis.set_ticks_position('none')
ax0.spines['top'].set_visible(False)
ax0.spines['right'].set_visible(False)
ax0.spines['bottom'].set_visible(False)
ax0.spines['left'].set_visible(False)
ax0.patch.set_visible(False)
if orientation == 'bottom':
ax0.set_xticklabels(ax0.xaxis.get_majorticklabels(), rotation=45, ha='left')
elif orientation == 'top':
ax0.set_xticklabels(ax0.xaxis.get_majorticklabels(), rotation=45, ha='right')
if orientation == 'bottom' or orientation == 'top':
ax0.tick_params(axis='y', labelsize=int(fontsize / 16 * 20))
else:
ax0.tick_params(axis='x', labelsize=int(fontsize / 16 * 20))
if inline:
plt.show()
else:
return ax0 |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:nullity_sort; 3, parameters; 3, 4; 3, 5; 4, identifier:df; 5, default_parameter; 5, 6; 5, 7; 6, identifier:sort; 7, None; 8, block; 8, 9; 9, if_statement; 9, 10; 9, 13; 9, 36; 9, 68; 10, comparison_operator:==; 10, 11; 10, 12; 11, identifier:sort; 12, string:'ascending'; 13, block; 13, 14; 14, return_statement; 14, 15; 15, subscript; 15, 16; 15, 19; 15, 34; 16, attribute; 16, 17; 16, 18; 17, identifier:df; 18, identifier:iloc; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:np; 22, identifier:argsort; 23, argument_list; 23, 24; 24, attribute; 24, 25; 24, 33; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:df; 28, identifier:count; 29, argument_list; 29, 30; 30, keyword_argument; 30, 31; 30, 32; 31, identifier:axis; 32, string:'columns'; 33, identifier:values; 34, slice; 34, 35; 35, colon; 36, elif_clause; 36, 37; 36, 40; 37, comparison_operator:==; 37, 38; 37, 39; 38, identifier:sort; 39, string:'descending'; 40, block; 40, 41; 41, return_statement; 41, 42; 42, subscript; 42, 43; 42, 46; 42, 66; 43, attribute; 43, 44; 43, 45; 44, identifier:df; 45, identifier:iloc; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:np; 49, identifier:flipud; 50, argument_list; 50, 51; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:np; 54, identifier:argsort; 55, argument_list; 55, 56; 56, attribute; 56, 57; 56, 65; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:df; 60, identifier:count; 61, argument_list; 61, 62; 62, keyword_argument; 62, 63; 62, 64; 63, identifier:axis; 64, string:'columns'; 65, identifier:values; 66, slice; 66, 67; 67, colon; 68, else_clause; 68, 69; 69, block; 69, 70; 70, return_statement; 70, 71; 71, identifier:df | def nullity_sort(df, sort=None):
if sort == 'ascending':
return df.iloc[np.argsort(df.count(axis='columns').values), :]
elif sort == 'descending':
return df.iloc[np.flipud(np.argsort(df.count(axis='columns').values)), :]
else:
return df |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:sortino_ratio; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:returns; 5, default_parameter; 5, 6; 5, 7; 6, identifier:required_return; 7, integer:0; 8, default_parameter; 8, 9; 8, 10; 9, identifier:period; 10, identifier:DAILY; 11, default_parameter; 11, 12; 11, 13; 12, identifier:annualization; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:out; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:_downside_risk; 19, None; 20, block; 20, 21; 20, 27; 20, 45; 20, 53; 20, 82; 20, 95; 20, 103; 20, 115; 20, 131; 20, 142; 20, 171; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:allocated_output; 24, comparison_operator:is; 24, 25; 24, 26; 25, identifier:out; 26, None; 27, if_statement; 27, 28; 27, 29; 28, identifier:allocated_output; 29, block; 29, 30; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:out; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:np; 36, identifier:empty; 37, argument_list; 37, 38; 38, subscript; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:returns; 41, identifier:shape; 42, slice; 42, 43; 42, 44; 43, integer:1; 44, colon; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:return_1d; 48, comparison_operator:==; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:returns; 51, identifier:ndim; 52, integer:1; 53, if_statement; 53, 54; 53, 60; 54, comparison_operator:<; 54, 55; 54, 59; 55, call; 55, 56; 55, 57; 56, identifier:len; 57, argument_list; 57, 58; 58, identifier:returns; 59, integer:2; 60, block; 60, 61; 60, 69; 60, 80; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 66; 63, subscript; 63, 64; 63, 65; 64, identifier:out; 65, tuple; 66, attribute; 66, 67; 66, 68; 67, identifier:np; 68, identifier:nan; 69, if_statement; 69, 70; 69, 71; 70, identifier:return_1d; 71, block; 71, 72; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:out; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:out; 78, identifier:item; 79, argument_list; 80, return_statement; 80, 81; 81, identifier:out; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:adj_returns; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:np; 88, identifier:asanyarray; 89, argument_list; 89, 90; 90, call; 90, 91; 90, 92; 91, identifier:_adjust_returns; 92, argument_list; 92, 93; 92, 94; 93, identifier:returns; 94, identifier:required_return; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:ann_factor; 98, call; 98, 99; 98, 100; 99, identifier:annualization_factor; 100, argument_list; 100, 101; 100, 102; 101, identifier:period; 102, identifier:annualization; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:average_annual_return; 106, binary_operator:*; 106, 107; 106, 114; 107, call; 107, 108; 107, 109; 108, identifier:nanmean; 109, argument_list; 109, 110; 109, 111; 110, identifier:adj_returns; 111, keyword_argument; 111, 112; 111, 113; 112, identifier:axis; 113, integer:0; 114, identifier:ann_factor; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:annualized_downside_risk; 118, parenthesized_expression; 118, 119; 119, conditional_expression:if; 119, 120; 119, 121; 119, 124; 120, identifier:_downside_risk; 121, comparison_operator:is; 121, 122; 121, 123; 122, identifier:_downside_risk; 123, None; 124, call; 124, 125; 124, 126; 125, identifier:downside_risk; 126, argument_list; 126, 127; 126, 128; 126, 129; 126, 130; 127, identifier:returns; 128, identifier:required_return; 129, identifier:period; 130, identifier:annualization; 131, expression_statement; 131, 132; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:np; 135, identifier:divide; 136, argument_list; 136, 137; 136, 138; 136, 139; 137, identifier:average_annual_return; 138, identifier:annualized_downside_risk; 139, keyword_argument; 139, 140; 139, 141; 140, identifier:out; 141, identifier:out; 142, if_statement; 142, 143; 142, 144; 142, 153; 143, identifier:return_1d; 144, block; 144, 145; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 148; 147, identifier:out; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:out; 151, identifier:item; 152, argument_list; 153, elif_clause; 153, 154; 153, 161; 154, call; 154, 155; 154, 156; 155, identifier:isinstance; 156, argument_list; 156, 157; 156, 158; 157, identifier:returns; 158, attribute; 158, 159; 158, 160; 159, identifier:pd; 160, identifier:DataFrame; 161, block; 161, 162; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:out; 165, call; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:pd; 168, identifier:Series; 169, argument_list; 169, 170; 170, identifier:out; 171, return_statement; 171, 172; 172, identifier:out | def sortino_ratio(returns,
required_return=0,
period=DAILY,
annualization=None,
out=None,
_downside_risk=None):
allocated_output = out is None
if allocated_output:
out = np.empty(returns.shape[1:])
return_1d = returns.ndim == 1
if len(returns) < 2:
out[()] = np.nan
if return_1d:
out = out.item()
return out
adj_returns = np.asanyarray(_adjust_returns(returns, required_return))
ann_factor = annualization_factor(period, annualization)
average_annual_return = nanmean(adj_returns, axis=0) * ann_factor
annualized_downside_risk = (
_downside_risk
if _downside_risk is not None else
downside_risk(returns, required_return, period, annualization)
)
np.divide(average_annual_return, annualized_downside_risk, out=out)
if return_1d:
out = out.item()
elif isinstance(returns, pd.DataFrame):
out = pd.Series(out)
return out |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:downside_risk; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:returns; 5, default_parameter; 5, 6; 5, 7; 6, identifier:required_return; 7, integer:0; 8, default_parameter; 8, 9; 8, 10; 9, identifier:period; 10, identifier:DAILY; 11, default_parameter; 11, 12; 11, 13; 12, identifier:annualization; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:out; 16, None; 17, block; 17, 18; 17, 24; 17, 42; 17, 50; 17, 79; 17, 87; 17, 114; 17, 124; 17, 135; 17, 145; 17, 161; 17, 195; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:allocated_output; 21, comparison_operator:is; 21, 22; 21, 23; 22, identifier:out; 23, None; 24, if_statement; 24, 25; 24, 26; 25, identifier:allocated_output; 26, block; 26, 27; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:out; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:np; 33, identifier:empty; 34, argument_list; 34, 35; 35, subscript; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:returns; 38, identifier:shape; 39, slice; 39, 40; 39, 41; 40, integer:1; 41, colon; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:returns_1d; 45, comparison_operator:==; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:returns; 48, identifier:ndim; 49, integer:1; 50, if_statement; 50, 51; 50, 57; 51, comparison_operator:<; 51, 52; 51, 56; 52, call; 52, 53; 52, 54; 53, identifier:len; 54, argument_list; 54, 55; 55, identifier:returns; 56, integer:1; 57, block; 57, 58; 57, 66; 57, 77; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 63; 60, subscript; 60, 61; 60, 62; 61, identifier:out; 62, tuple; 63, attribute; 63, 64; 63, 65; 64, identifier:np; 65, identifier:nan; 66, if_statement; 66, 67; 66, 68; 67, identifier:returns_1d; 68, block; 68, 69; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:out; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:out; 75, identifier:item; 76, argument_list; 77, return_statement; 77, 78; 78, identifier:out; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:ann_factor; 82, call; 82, 83; 82, 84; 83, identifier:annualization_factor; 84, argument_list; 84, 85; 84, 86; 85, identifier:period; 86, identifier:annualization; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:downside_diff; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:np; 93, identifier:clip; 94, argument_list; 94, 95; 94, 110; 94, 113; 95, call; 95, 96; 95, 97; 96, identifier:_adjust_returns; 97, argument_list; 97, 98; 97, 104; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:np; 101, identifier:asanyarray; 102, argument_list; 102, 103; 103, identifier:returns; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:np; 107, identifier:asanyarray; 108, argument_list; 108, 109; 109, identifier:required_return; 110, attribute; 110, 111; 110, 112; 111, identifier:np; 112, identifier:NINF; 113, integer:0; 114, expression_statement; 114, 115; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:np; 118, identifier:square; 119, argument_list; 119, 120; 119, 121; 120, identifier:downside_diff; 121, keyword_argument; 121, 122; 121, 123; 122, identifier:out; 123, identifier:downside_diff; 124, expression_statement; 124, 125; 125, call; 125, 126; 125, 127; 126, identifier:nanmean; 127, argument_list; 127, 128; 127, 129; 127, 132; 128, identifier:downside_diff; 129, keyword_argument; 129, 130; 129, 131; 130, identifier:axis; 131, integer:0; 132, keyword_argument; 132, 133; 132, 134; 133, identifier:out; 134, identifier:out; 135, expression_statement; 135, 136; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:np; 139, identifier:sqrt; 140, argument_list; 140, 141; 140, 142; 141, identifier:out; 142, keyword_argument; 142, 143; 142, 144; 143, identifier:out; 144, identifier:out; 145, expression_statement; 145, 146; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:np; 149, identifier:multiply; 150, argument_list; 150, 151; 150, 152; 150, 158; 151, identifier:out; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:np; 155, identifier:sqrt; 156, argument_list; 156, 157; 157, identifier:ann_factor; 158, keyword_argument; 158, 159; 158, 160; 159, identifier:out; 160, identifier:out; 161, if_statement; 161, 162; 161, 163; 161, 172; 162, identifier:returns_1d; 163, block; 163, 164; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 167; 166, identifier:out; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:out; 170, identifier:item; 171, argument_list; 172, elif_clause; 172, 173; 172, 180; 173, call; 173, 174; 173, 175; 174, identifier:isinstance; 175, argument_list; 175, 176; 175, 177; 176, identifier:returns; 177, attribute; 177, 178; 177, 179; 178, identifier:pd; 179, identifier:DataFrame; 180, block; 180, 181; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 184; 183, identifier:out; 184, call; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:pd; 187, identifier:Series; 188, argument_list; 188, 189; 188, 190; 189, identifier:out; 190, keyword_argument; 190, 191; 190, 192; 191, identifier:index; 192, attribute; 192, 193; 192, 194; 193, identifier:returns; 194, identifier:columns; 195, return_statement; 195, 196; 196, identifier:out | def downside_risk(returns,
required_return=0,
period=DAILY,
annualization=None,
out=None):
allocated_output = out is None
if allocated_output:
out = np.empty(returns.shape[1:])
returns_1d = returns.ndim == 1
if len(returns) < 1:
out[()] = np.nan
if returns_1d:
out = out.item()
return out
ann_factor = annualization_factor(period, annualization)
downside_diff = np.clip(
_adjust_returns(
np.asanyarray(returns),
np.asanyarray(required_return),
),
np.NINF,
0,
)
np.square(downside_diff, out=downside_diff)
nanmean(downside_diff, axis=0, out=out)
np.sqrt(out, out=out)
np.multiply(out, np.sqrt(ann_factor), out=out)
if returns_1d:
out = out.item()
elif isinstance(returns, pd.DataFrame):
out = pd.Series(out, index=returns.columns)
return out |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:GetLoadingOrder; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 10; 5, 39; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:result; 9, dictionary; 10, for_statement; 10, 11; 10, 14; 10, 21; 11, pattern_list; 11, 12; 11, 13; 12, identifier:filename; 13, identifier:mapping; 14, call; 14, 15; 14, 20; 15, attribute; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:_file_mapping; 19, identifier:iteritems; 20, argument_list; 21, block; 21, 22; 21, 28; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:loading_order; 25, subscript; 25, 26; 25, 27; 26, identifier:mapping; 27, string:'loading_order'; 28, if_statement; 28, 29; 28, 32; 29, comparison_operator:is; 29, 30; 29, 31; 30, identifier:loading_order; 31, None; 32, block; 32, 33; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 38; 35, subscript; 35, 36; 35, 37; 36, identifier:result; 37, identifier:loading_order; 38, identifier:filename; 39, return_statement; 39, 40; 40, call; 40, 41; 40, 42; 41, identifier:list; 42, generator_expression; 42, 43; 42, 46; 43, subscript; 43, 44; 43, 45; 44, identifier:result; 45, identifier:key; 46, for_in_clause; 46, 47; 46, 48; 47, identifier:key; 48, call; 48, 49; 48, 50; 49, identifier:sorted; 50, argument_list; 50, 51; 51, identifier:result | def GetLoadingOrder(self):
result = {}
for filename, mapping in self._file_mapping.iteritems():
loading_order = mapping['loading_order']
if loading_order is not None:
result[loading_order] = filename
return list(result[key] for key in sorted(result)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:GetOrderKey; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 11; 5, 20; 5, 31; 5, 35; 5, 51; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:context_attributes; 9, list:['_type']; 9, 10; 10, string:'_type'; 11, expression_statement; 11, 12; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:context_attributes; 15, identifier:extend; 16, argument_list; 16, 17; 17, attribute; 17, 18; 17, 19; 18, identifier:ExceptionWithContext; 19, identifier:CONTEXT_PARTS; 20, expression_statement; 20, 21; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:context_attributes; 24, identifier:extend; 25, argument_list; 25, 26; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:_GetExtraOrderAttributes; 30, argument_list; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:tokens; 34, list:[]; 35, for_statement; 35, 36; 35, 37; 35, 38; 36, identifier:context_attribute; 37, identifier:context_attributes; 38, block; 38, 39; 39, expression_statement; 39, 40; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:tokens; 43, identifier:append; 44, argument_list; 44, 45; 45, call; 45, 46; 45, 47; 46, identifier:getattr; 47, argument_list; 47, 48; 47, 49; 47, 50; 48, identifier:self; 49, identifier:context_attribute; 50, None; 51, return_statement; 51, 52; 52, identifier:tokens | def GetOrderKey(self):
context_attributes = ['_type']
context_attributes.extend(ExceptionWithContext.CONTEXT_PARTS)
context_attributes.extend(self._GetExtraOrderAttributes())
tokens = []
for context_attribute in context_attributes:
tokens.append(getattr(self, context_attribute, None))
return tokens |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:AddShapePointObjectUnsorted; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:shapepoint; 6, identifier:problems; 7, block; 7, 8; 7, 70; 7, 100; 7, 199; 7, 216; 7, 228; 7, 240; 8, if_statement; 8, 9; 8, 29; 8, 39; 8, 54; 9, parenthesized_expression; 9, 10; 10, boolean_operator:or; 10, 11; 10, 19; 11, comparison_operator:==; 11, 12; 11, 18; 12, call; 12, 13; 12, 14; 13, identifier:len; 14, argument_list; 14, 15; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:sequence; 18, integer:0; 19, comparison_operator:>=; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:shapepoint; 22, identifier:shape_pt_sequence; 23, subscript; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:sequence; 27, unary_operator:-; 27, 28; 28, integer:1; 29, block; 29, 30; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:index; 33, call; 33, 34; 33, 35; 34, identifier:len; 35, argument_list; 35, 36; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:sequence; 39, elif_clause; 39, 40; 39, 49; 40, comparison_operator:<=; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:shapepoint; 43, identifier:shape_pt_sequence; 44, subscript; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:sequence; 48, integer:0; 49, block; 49, 50; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:index; 53, integer:0; 54, else_clause; 54, 55; 55, block; 55, 56; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:index; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:bisect; 62, identifier:bisect; 63, argument_list; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:self; 66, identifier:sequence; 67, attribute; 67, 68; 67, 69; 68, identifier:shapepoint; 69, identifier:shape_pt_sequence; 70, if_statement; 70, 71; 70, 78; 71, comparison_operator:in; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:shapepoint; 74, identifier:shape_pt_sequence; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:sequence; 78, block; 78, 79; 79, expression_statement; 79, 80; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:problems; 83, identifier:InvalidValue; 84, argument_list; 84, 85; 84, 86; 84, 89; 85, string:'shape_pt_sequence'; 86, attribute; 86, 87; 86, 88; 87, identifier:shapepoint; 88, identifier:shape_pt_sequence; 89, binary_operator:%; 89, 90; 89, 93; 90, concatenated_string; 90, 91; 90, 92; 91, string:'The sequence number %d occurs more than once in '; 92, string:'shape %s.'; 93, tuple; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:shapepoint; 96, identifier:shape_pt_sequence; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:shape_id; 100, if_statement; 100, 101; 100, 115; 101, boolean_operator:and; 101, 102; 101, 107; 102, comparison_operator:is; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:shapepoint; 105, identifier:shape_dist_traveled; 106, None; 107, comparison_operator:>; 107, 108; 107, 114; 108, call; 108, 109; 108, 110; 109, identifier:len; 110, argument_list; 110, 111; 111, attribute; 111, 112; 111, 113; 112, identifier:self; 113, identifier:sequence; 114, integer:0; 115, block; 115, 116; 115, 158; 116, if_statement; 116, 117; 116, 136; 117, parenthesized_expression; 117, 118; 118, boolean_operator:and; 118, 119; 118, 127; 119, comparison_operator:!=; 119, 120; 119, 121; 120, identifier:index; 121, call; 121, 122; 121, 123; 122, identifier:len; 123, argument_list; 123, 124; 124, attribute; 124, 125; 124, 126; 125, identifier:self; 126, identifier:sequence; 127, comparison_operator:>; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:shapepoint; 130, identifier:shape_dist_traveled; 131, subscript; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:self; 134, identifier:distance; 135, identifier:index; 136, block; 136, 137; 137, expression_statement; 137, 138; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:problems; 141, identifier:InvalidValue; 142, argument_list; 142, 143; 142, 144; 142, 147; 143, string:'shape_dist_traveled'; 144, attribute; 144, 145; 144, 146; 145, identifier:shapepoint; 146, identifier:shape_dist_traveled; 147, binary_operator:%; 147, 148; 147, 153; 148, concatenated_string; 148, 149; 148, 150; 148, 151; 148, 152; 149, string:'Each subsequent point in a shape should have '; 150, string:'a distance value that shouldn\'t be larger '; 151, string:'than the next ones. In this case, the next '; 152, string:'distance was %f.'; 153, subscript; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:self; 156, identifier:distance; 157, identifier:index; 158, if_statement; 158, 159; 158, 175; 159, parenthesized_expression; 159, 160; 160, boolean_operator:and; 160, 161; 160, 164; 161, comparison_operator:>; 161, 162; 161, 163; 162, identifier:index; 163, integer:0; 164, comparison_operator:<; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:shapepoint; 167, identifier:shape_dist_traveled; 168, subscript; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:self; 171, identifier:distance; 172, binary_operator:-; 172, 173; 172, 174; 173, identifier:index; 174, integer:1; 175, block; 175, 176; 176, expression_statement; 176, 177; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:problems; 180, identifier:InvalidValue; 181, argument_list; 181, 182; 181, 183; 181, 186; 182, string:'shape_dist_traveled'; 183, attribute; 183, 184; 183, 185; 184, identifier:shapepoint; 185, identifier:shape_dist_traveled; 186, binary_operator:%; 186, 187; 186, 192; 187, concatenated_string; 187, 188; 187, 189; 187, 190; 187, 191; 188, string:'Each subsequent point in a shape should have '; 189, string:'a distance value that\'s at least as large as '; 190, string:'the previous ones. In this case, the previous '; 191, string:'distance was %f.'; 192, subscript; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:self; 195, identifier:distance; 196, binary_operator:-; 196, 197; 196, 198; 197, identifier:index; 198, integer:1; 199, if_statement; 199, 200; 199, 207; 200, comparison_operator:>; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:shapepoint; 203, identifier:shape_dist_traveled; 204, attribute; 204, 205; 204, 206; 205, identifier:self; 206, identifier:max_distance; 207, block; 207, 208; 208, expression_statement; 208, 209; 209, assignment; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:self; 212, identifier:max_distance; 213, attribute; 213, 214; 213, 215; 214, identifier:shapepoint; 215, identifier:shape_dist_traveled; 216, expression_statement; 216, 217; 217, call; 217, 218; 217, 223; 218, attribute; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:self; 221, identifier:sequence; 222, identifier:insert; 223, argument_list; 223, 224; 223, 225; 224, identifier:index; 225, attribute; 225, 226; 225, 227; 226, identifier:shapepoint; 227, identifier:shape_pt_sequence; 228, expression_statement; 228, 229; 229, call; 229, 230; 229, 235; 230, attribute; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:self; 233, identifier:distance; 234, identifier:insert; 235, argument_list; 235, 236; 235, 237; 236, identifier:index; 237, attribute; 237, 238; 237, 239; 238, identifier:shapepoint; 239, identifier:shape_dist_traveled; 240, expression_statement; 240, 241; 241, call; 241, 242; 241, 247; 242, attribute; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, identifier:self; 245, identifier:points; 246, identifier:insert; 247, argument_list; 247, 248; 247, 249; 248, identifier:index; 249, tuple; 249, 250; 249, 253; 249, 256; 250, attribute; 250, 251; 250, 252; 251, identifier:shapepoint; 252, identifier:shape_pt_lat; 253, attribute; 253, 254; 253, 255; 254, identifier:shapepoint; 255, identifier:shape_pt_lon; 256, attribute; 256, 257; 256, 258; 257, identifier:shapepoint; 258, identifier:shape_dist_traveled | def AddShapePointObjectUnsorted(self, shapepoint, problems):
if (len(self.sequence) == 0 or
shapepoint.shape_pt_sequence >= self.sequence[-1]):
index = len(self.sequence)
elif shapepoint.shape_pt_sequence <= self.sequence[0]:
index = 0
else:
index = bisect.bisect(self.sequence, shapepoint.shape_pt_sequence)
if shapepoint.shape_pt_sequence in self.sequence:
problems.InvalidValue('shape_pt_sequence', shapepoint.shape_pt_sequence,
'The sequence number %d occurs more than once in '
'shape %s.' %
(shapepoint.shape_pt_sequence, self.shape_id))
if shapepoint.shape_dist_traveled is not None and len(self.sequence) > 0:
if (index != len(self.sequence) and
shapepoint.shape_dist_traveled > self.distance[index]):
problems.InvalidValue('shape_dist_traveled',
shapepoint.shape_dist_traveled,
'Each subsequent point in a shape should have '
'a distance value that shouldn\'t be larger '
'than the next ones. In this case, the next '
'distance was %f.' % self.distance[index])
if (index > 0 and
shapepoint.shape_dist_traveled < self.distance[index - 1]):
problems.InvalidValue('shape_dist_traveled',
shapepoint.shape_dist_traveled,
'Each subsequent point in a shape should have '
'a distance value that\'s at least as large as '
'the previous ones. In this case, the previous '
'distance was %f.' % self.distance[index - 1])
if shapepoint.shape_dist_traveled > self.max_distance:
self.max_distance = shapepoint.shape_dist_traveled
self.sequence.insert(index, shapepoint.shape_pt_sequence)
self.distance.insert(index, shapepoint.shape_dist_traveled)
self.points.insert(index, (shapepoint.shape_pt_lat,
shapepoint.shape_pt_lon,
shapepoint.shape_dist_traveled)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:GetStopTimes; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:problems; 7, None; 8, block; 8, 9; 8, 21; 8, 37; 8, 41; 8, 51; 8, 62; 8, 138; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:cursor; 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:_schedule; 18, identifier:_connection; 19, identifier:cursor; 20, argument_list; 21, expression_statement; 21, 22; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:cursor; 25, identifier:execute; 26, argument_list; 26, 27; 26, 33; 27, concatenated_string; 27, 28; 27, 29; 27, 30; 27, 31; 27, 32; 28, string:'SELECT arrival_secs,departure_secs,stop_headsign,pickup_type,'; 29, string:'drop_off_type,shape_dist_traveled,stop_id,stop_sequence,timepoint '; 30, string:'FROM stop_times '; 31, string:'WHERE trip_id=? '; 32, string:'ORDER BY stop_sequence'; 33, tuple; 33, 34; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:trip_id; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:stop_times; 40, list:[]; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:stoptime_class; 44, attribute; 44, 45; 44, 50; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:GetGtfsFactory; 49, argument_list; 50, identifier:StopTime; 51, if_statement; 51, 52; 51, 55; 52, comparison_operator:is; 52, 53; 52, 54; 53, identifier:problems; 54, None; 55, block; 55, 56; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:problems; 59, attribute; 59, 60; 59, 61; 60, identifier:problems_module; 61, identifier:default_problem_reporter; 62, for_statement; 62, 63; 62, 64; 62, 69; 63, identifier:row; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:cursor; 67, identifier:fetchall; 68, argument_list; 69, block; 69, 70; 69, 83; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:stop; 73, call; 73, 74; 73, 79; 74, attribute; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:_schedule; 78, identifier:GetStop; 79, argument_list; 79, 80; 80, subscript; 80, 81; 80, 82; 81, identifier:row; 82, integer:6; 83, expression_statement; 83, 84; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:stop_times; 87, identifier:append; 88, argument_list; 88, 89; 89, call; 89, 90; 89, 91; 90, identifier:stoptime_class; 91, argument_list; 91, 92; 91, 95; 91, 98; 91, 103; 91, 108; 91, 113; 91, 118; 91, 123; 91, 128; 91, 133; 92, keyword_argument; 92, 93; 92, 94; 93, identifier:problems; 94, identifier:problems; 95, keyword_argument; 95, 96; 95, 97; 96, identifier:stop; 97, identifier:stop; 98, keyword_argument; 98, 99; 98, 100; 99, identifier:arrival_secs; 100, subscript; 100, 101; 100, 102; 101, identifier:row; 102, integer:0; 103, keyword_argument; 103, 104; 103, 105; 104, identifier:departure_secs; 105, subscript; 105, 106; 105, 107; 106, identifier:row; 107, integer:1; 108, keyword_argument; 108, 109; 108, 110; 109, identifier:stop_headsign; 110, subscript; 110, 111; 110, 112; 111, identifier:row; 112, integer:2; 113, keyword_argument; 113, 114; 113, 115; 114, identifier:pickup_type; 115, subscript; 115, 116; 115, 117; 116, identifier:row; 117, integer:3; 118, keyword_argument; 118, 119; 118, 120; 119, identifier:drop_off_type; 120, subscript; 120, 121; 120, 122; 121, identifier:row; 122, integer:4; 123, keyword_argument; 123, 124; 123, 125; 124, identifier:shape_dist_traveled; 125, subscript; 125, 126; 125, 127; 126, identifier:row; 127, integer:5; 128, keyword_argument; 128, 129; 128, 130; 129, identifier:stop_sequence; 130, subscript; 130, 131; 130, 132; 131, identifier:row; 132, integer:7; 133, keyword_argument; 133, 134; 133, 135; 134, identifier:timepoint; 135, subscript; 135, 136; 135, 137; 136, identifier:row; 137, integer:8; 138, return_statement; 138, 139; 139, identifier:stop_times | def GetStopTimes(self, problems=None):
cursor = self._schedule._connection.cursor()
cursor.execute(
'SELECT arrival_secs,departure_secs,stop_headsign,pickup_type,'
'drop_off_type,shape_dist_traveled,stop_id,stop_sequence,timepoint '
'FROM stop_times '
'WHERE trip_id=? '
'ORDER BY stop_sequence', (self.trip_id,))
stop_times = []
stoptime_class = self.GetGtfsFactory().StopTime
if problems is None:
problems = problems_module.default_problem_reporter
for row in cursor.fetchall():
stop = self._schedule.GetStop(row[6])
stop_times.append(stoptime_class(problems=problems,
stop=stop,
arrival_secs=row[0],
departure_secs=row[1],
stop_headsign=row[2],
pickup_type=row[3],
drop_off_type=row[4],
shape_dist_traveled=row[5],
stop_sequence=row[7],
timepoint=row[8]))
return stop_times |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:GetFrequencyStartTimes; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 10; 5, 50; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:start_times; 9, list:[]; 10, for_statement; 10, 11; 10, 12; 10, 17; 11, identifier:freq_tuple; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:GetFrequencyTuples; 16, argument_list; 17, block; 17, 18; 17, 30; 17, 34; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 24; 20, tuple_pattern; 20, 21; 20, 22; 20, 23; 21, identifier:start_secs; 22, identifier:end_secs; 23, identifier:headway_secs; 24, subscript; 24, 25; 24, 26; 25, identifier:freq_tuple; 26, slice; 26, 27; 26, 28; 26, 29; 27, integer:0; 28, colon; 29, integer:3; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:run_secs; 33, identifier:start_secs; 34, while_statement; 34, 35; 34, 38; 35, comparison_operator:<; 35, 36; 35, 37; 36, identifier:run_secs; 37, identifier:end_secs; 38, block; 38, 39; 38, 46; 39, expression_statement; 39, 40; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:start_times; 43, identifier:append; 44, argument_list; 44, 45; 45, identifier:run_secs; 46, expression_statement; 46, 47; 47, augmented_assignment:+=; 47, 48; 47, 49; 48, identifier:run_secs; 49, identifier:headway_secs; 50, return_statement; 50, 51; 51, identifier:start_times | def GetFrequencyStartTimes(self):
start_times = []
for freq_tuple in self.GetFrequencyTuples():
(start_secs, end_secs, headway_secs) = freq_tuple[0:3]
run_secs = start_secs
while run_secs < end_secs:
start_times.append(run_secs)
run_secs += headway_secs
return start_times |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:create; 3, parameters; 3, 4; 3, 5; 4, identifier:filename; 5, identifier:spec; 6, block; 6, 7; 6, 12; 6, 50; 6, 63; 6, 74; 6, 90; 6, 103; 6, 112; 6, 146; 6, 162; 6, 191; 6, 228; 6, 234; 6, 280; 6, 301; 6, 338; 6, 381; 7, import_from_statement; 7, 8; 7, 10; 8, relative_import; 8, 9; 9, import_prefix; 10, dotted_name; 10, 11; 11, identifier:_segyio; 12, if_statement; 12, 13; 12, 18; 12, 25; 13, not_operator; 13, 14; 14, call; 14, 15; 14, 16; 15, identifier:structured; 16, argument_list; 16, 17; 17, identifier:spec; 18, block; 18, 19; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:tracecount; 22, attribute; 22, 23; 22, 24; 23, identifier:spec; 24, identifier:tracecount; 25, else_clause; 25, 26; 26, block; 26, 27; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:tracecount; 30, binary_operator:*; 30, 31; 30, 44; 31, binary_operator:*; 31, 32; 31, 38; 32, call; 32, 33; 32, 34; 33, identifier:len; 34, argument_list; 34, 35; 35, attribute; 35, 36; 35, 37; 36, identifier:spec; 37, identifier:ilines; 38, call; 38, 39; 38, 40; 39, identifier:len; 40, argument_list; 40, 41; 41, attribute; 41, 42; 41, 43; 42, identifier:spec; 43, identifier:xlines; 44, call; 44, 45; 44, 46; 45, identifier:len; 46, argument_list; 46, 47; 47, attribute; 47, 48; 47, 49; 48, identifier:spec; 49, identifier:offsets; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:ext_headers; 53, conditional_expression:if; 53, 54; 53, 57; 53, 62; 54, attribute; 54, 55; 54, 56; 55, identifier:spec; 56, identifier:ext_headers; 57, call; 57, 58; 57, 59; 58, identifier:hasattr; 59, argument_list; 59, 60; 59, 61; 60, identifier:spec; 61, string:'ext_headers'; 62, integer:0; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:samples; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:numpy; 69, identifier:asarray; 70, argument_list; 70, 71; 71, attribute; 71, 72; 71, 73; 72, identifier:spec; 73, identifier:samples; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:endians; 77, dictionary; 77, 78; 77, 81; 77, 84; 77, 87; 78, pair; 78, 79; 78, 80; 79, string:'lsb'; 80, integer:256; 81, pair; 81, 82; 81, 83; 82, string:'little'; 83, integer:256; 84, pair; 84, 85; 84, 86; 85, string:'msb'; 86, integer:0; 87, pair; 87, 88; 87, 89; 88, string:'big'; 89, integer:0; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:endian; 93, conditional_expression:if; 93, 94; 93, 97; 93, 102; 94, attribute; 94, 95; 94, 96; 95, identifier:spec; 96, identifier:endian; 97, call; 97, 98; 97, 99; 98, identifier:hasattr; 99, argument_list; 99, 100; 99, 101; 100, identifier:spec; 101, string:'endian'; 102, string:'big'; 103, if_statement; 103, 104; 103, 107; 104, comparison_operator:is; 104, 105; 104, 106; 105, identifier:endian; 106, None; 107, block; 107, 108; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:endian; 111, string:'big'; 112, if_statement; 112, 113; 112, 116; 113, comparison_operator:not; 113, 114; 113, 115; 114, identifier:endian; 115, identifier:endians; 116, block; 116, 117; 116, 121; 116, 134; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:problem; 120, string:'unknown endianness {}, expected one of: '; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:opts; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, string:' '; 127, identifier:join; 128, argument_list; 128, 129; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:endians; 132, identifier:keys; 133, argument_list; 134, raise_statement; 134, 135; 135, call; 135, 136; 135, 137; 136, identifier:ValueError; 137, argument_list; 137, 138; 138, binary_operator:+; 138, 139; 138, 145; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:problem; 142, identifier:format; 143, argument_list; 143, 144; 144, identifier:endian; 145, identifier:opts; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:fd; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:_segyio; 152, identifier:segyiofd; 153, argument_list; 153, 154; 153, 158; 153, 159; 154, call; 154, 155; 154, 156; 155, identifier:str; 156, argument_list; 156, 157; 157, identifier:filename; 158, string:'w+'; 159, subscript; 159, 160; 159, 161; 160, identifier:endians; 161, identifier:endian; 162, expression_statement; 162, 163; 163, call; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:fd; 166, identifier:segymake; 167, argument_list; 167, 168; 167, 174; 167, 177; 167, 185; 168, keyword_argument; 168, 169; 168, 170; 169, identifier:samples; 170, call; 170, 171; 170, 172; 171, identifier:len; 172, argument_list; 172, 173; 173, identifier:samples; 174, keyword_argument; 174, 175; 174, 176; 175, identifier:tracecount; 176, identifier:tracecount; 177, keyword_argument; 177, 178; 177, 179; 178, identifier:format; 179, call; 179, 180; 179, 181; 180, identifier:int; 181, argument_list; 181, 182; 182, attribute; 182, 183; 182, 184; 183, identifier:spec; 184, identifier:format; 185, keyword_argument; 185, 186; 185, 187; 186, identifier:ext_headers; 187, call; 187, 188; 187, 189; 188, identifier:int; 189, argument_list; 189, 190; 190, identifier:ext_headers; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:f; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:segyio; 197, identifier:SegyFile; 198, argument_list; 198, 199; 198, 200; 198, 206; 198, 209; 198, 217; 198, 225; 199, identifier:fd; 200, keyword_argument; 200, 201; 200, 202; 201, identifier:filename; 202, call; 202, 203; 202, 204; 203, identifier:str; 204, argument_list; 204, 205; 205, identifier:filename; 206, keyword_argument; 206, 207; 206, 208; 207, identifier:mode; 208, string:'w+'; 209, keyword_argument; 209, 210; 209, 211; 210, identifier:iline; 211, call; 211, 212; 211, 213; 212, identifier:int; 213, argument_list; 213, 214; 214, attribute; 214, 215; 214, 216; 215, identifier:spec; 216, identifier:iline; 217, keyword_argument; 217, 218; 217, 219; 218, identifier:xline; 219, call; 219, 220; 219, 221; 220, identifier:int; 221, argument_list; 221, 222; 222, attribute; 222, 223; 222, 224; 223, identifier:spec; 224, identifier:xline; 225, keyword_argument; 225, 226; 225, 227; 226, identifier:endian; 227, identifier:endian; 228, expression_statement; 228, 229; 229, assignment; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:f; 232, identifier:_samples; 233, identifier:samples; 234, if_statement; 234, 235; 234, 239; 235, call; 235, 236; 235, 237; 236, identifier:structured; 237, argument_list; 237, 238; 238, identifier:spec; 239, block; 239, 240; 239, 253; 239, 264; 240, expression_statement; 240, 241; 241, assignment; 241, 242; 241, 243; 242, identifier:sorting; 243, conditional_expression:if; 243, 244; 243, 247; 243, 252; 244, attribute; 244, 245; 244, 246; 245, identifier:spec; 246, identifier:sorting; 247, call; 247, 248; 247, 249; 248, identifier:hasattr; 249, argument_list; 249, 250; 249, 251; 250, identifier:spec; 251, string:'sorting'; 252, None; 253, if_statement; 253, 254; 253, 257; 254, comparison_operator:is; 254, 255; 254, 256; 255, identifier:sorting; 256, None; 257, block; 257, 258; 258, expression_statement; 258, 259; 259, assignment; 259, 260; 259, 261; 260, identifier:sorting; 261, attribute; 261, 262; 261, 263; 262, identifier:TraceSortingFormat; 263, identifier:INLINE_SORTING; 264, expression_statement; 264, 265; 265, call; 265, 266; 265, 269; 266, attribute; 266, 267; 266, 268; 267, identifier:f; 268, identifier:interpret; 269, argument_list; 269, 270; 269, 273; 269, 276; 269, 279; 270, attribute; 270, 271; 270, 272; 271, identifier:spec; 272, identifier:ilines; 273, attribute; 273, 274; 273, 275; 274, identifier:spec; 275, identifier:xlines; 276, attribute; 276, 277; 276, 278; 277, identifier:spec; 278, identifier:offsets; 279, identifier:sorting; 280, expression_statement; 280, 281; 281, assignment; 281, 282; 281, 287; 282, subscript; 282, 283; 282, 286; 283, attribute; 283, 284; 283, 285; 284, identifier:f; 285, identifier:text; 286, integer:0; 287, call; 287, 288; 287, 289; 288, identifier:default_text_header; 289, argument_list; 289, 290; 289, 293; 289, 296; 290, attribute; 290, 291; 290, 292; 291, identifier:f; 292, identifier:_il; 293, attribute; 293, 294; 293, 295; 294, identifier:f; 295, identifier:_xl; 296, attribute; 296, 297; 296, 300; 297, attribute; 297, 298; 297, 299; 298, identifier:segyio; 299, identifier:TraceField; 300, identifier:offset; 301, if_statement; 301, 302; 301, 308; 301, 320; 302, comparison_operator:==; 302, 303; 302, 307; 303, call; 303, 304; 303, 305; 304, identifier:len; 305, argument_list; 305, 306; 306, identifier:samples; 307, integer:1; 308, block; 308, 309; 309, expression_statement; 309, 310; 310, assignment; 310, 311; 310, 312; 311, identifier:interval; 312, call; 312, 313; 312, 314; 313, identifier:int; 314, argument_list; 314, 315; 315, binary_operator:*; 315, 316; 315, 319; 316, subscript; 316, 317; 316, 318; 317, identifier:samples; 318, integer:0; 319, integer:1000; 320, else_clause; 320, 321; 321, block; 321, 322; 322, expression_statement; 322, 323; 323, assignment; 323, 324; 323, 325; 324, identifier:interval; 325, call; 325, 326; 325, 327; 326, identifier:int; 327, argument_list; 327, 328; 328, binary_operator:*; 328, 329; 328, 337; 329, parenthesized_expression; 329, 330; 330, binary_operator:-; 330, 331; 330, 334; 331, subscript; 331, 332; 331, 333; 332, identifier:samples; 333, integer:1; 334, subscript; 334, 335; 334, 336; 335, identifier:samples; 336, integer:0; 337, integer:1000; 338, expression_statement; 338, 339; 339, call; 339, 340; 339, 345; 340, attribute; 340, 341; 340, 344; 341, attribute; 341, 342; 341, 343; 342, identifier:f; 343, identifier:bin; 344, identifier:update; 345, argument_list; 345, 346; 345, 349; 345, 352; 345, 355; 345, 358; 345, 364; 345, 370; 345, 378; 346, keyword_argument; 346, 347; 346, 348; 347, identifier:ntrpr; 348, identifier:tracecount; 349, keyword_argument; 349, 350; 349, 351; 350, identifier:nart; 351, identifier:tracecount; 352, keyword_argument; 352, 353; 352, 354; 353, identifier:hdt; 354, identifier:interval; 355, keyword_argument; 355, 356; 355, 357; 356, identifier:dto; 357, identifier:interval; 358, keyword_argument; 358, 359; 358, 360; 359, identifier:hns; 360, call; 360, 361; 360, 362; 361, identifier:len; 362, argument_list; 362, 363; 363, identifier:samples; 364, keyword_argument; 364, 365; 364, 366; 365, identifier:nso; 366, call; 366, 367; 366, 368; 367, identifier:len; 368, argument_list; 368, 369; 369, identifier:samples; 370, keyword_argument; 370, 371; 370, 372; 371, identifier:format; 372, call; 372, 373; 372, 374; 373, identifier:int; 374, argument_list; 374, 375; 375, attribute; 375, 376; 375, 377; 376, identifier:spec; 377, identifier:format; 378, keyword_argument; 378, 379; 378, 380; 379, identifier:exth; 380, identifier:ext_headers; 381, return_statement; 381, 382; 382, identifier:f | def create(filename, spec):
from . import _segyio
if not structured(spec):
tracecount = spec.tracecount
else:
tracecount = len(spec.ilines) * len(spec.xlines) * len(spec.offsets)
ext_headers = spec.ext_headers if hasattr(spec, 'ext_headers') else 0
samples = numpy.asarray(spec.samples)
endians = {
'lsb': 256,
'little': 256,
'msb': 0,
'big': 0,
}
endian = spec.endian if hasattr(spec, 'endian') else 'big'
if endian is None:
endian = 'big'
if endian not in endians:
problem = 'unknown endianness {}, expected one of: '
opts = ' '.join(endians.keys())
raise ValueError(problem.format(endian) + opts)
fd = _segyio.segyiofd(str(filename), 'w+', endians[endian])
fd.segymake(
samples = len(samples),
tracecount = tracecount,
format = int(spec.format),
ext_headers = int(ext_headers),
)
f = segyio.SegyFile(fd,
filename = str(filename),
mode = 'w+',
iline = int(spec.iline),
xline = int(spec.xline),
endian = endian,
)
f._samples = samples
if structured(spec):
sorting = spec.sorting if hasattr(spec, 'sorting') else None
if sorting is None:
sorting = TraceSortingFormat.INLINE_SORTING
f.interpret(spec.ilines, spec.xlines, spec.offsets, sorting)
f.text[0] = default_text_header(f._il, f._xl, segyio.TraceField.offset)
if len(samples) == 1:
interval = int(samples[0] * 1000)
else:
interval = int((samples[1] - samples[0]) * 1000)
f.bin.update(
ntrpr = tracecount,
nart = tracecount,
hdt = interval,
dto = interval,
hns = len(samples),
nso = len(samples),
format = int(spec.format),
exth = ext_headers,
)
return f |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:rotation; 3, parameters; 3, 4; 3, 5; 4, identifier:f; 5, default_parameter; 5, 6; 5, 7; 6, identifier:line; 7, string:'fast'; 8, block; 8, 9; 8, 19; 8, 43; 8, 86; 8, 92; 8, 111; 8, 131; 8, 169; 9, if_statement; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:f; 12, identifier:unstructured; 13, block; 13, 14; 14, raise_statement; 14, 15; 15, call; 15, 16; 15, 17; 16, identifier:ValueError; 17, argument_list; 17, 18; 18, string:"Rotation requires a structured file"; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:lines; 22, dictionary; 22, 23; 22, 28; 22, 33; 22, 38; 23, pair; 23, 24; 23, 25; 24, string:'fast'; 25, attribute; 25, 26; 25, 27; 26, identifier:f; 27, identifier:fast; 28, pair; 28, 29; 28, 30; 29, string:'slow'; 30, attribute; 30, 31; 30, 32; 31, identifier:f; 32, identifier:slow; 33, pair; 33, 34; 33, 35; 34, string:'iline'; 35, attribute; 35, 36; 35, 37; 36, identifier:f; 37, identifier:iline; 38, pair; 38, 39; 38, 40; 39, string:'xline'; 40, attribute; 40, 41; 40, 42; 41, identifier:f; 42, identifier:xline; 43, if_statement; 43, 44; 43, 47; 44, comparison_operator:not; 44, 45; 44, 46; 45, identifier:line; 46, identifier:lines; 47, block; 47, 48; 47, 57; 47, 75; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:error; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, string:"Unknown line {}"; 54, identifier:format; 55, argument_list; 55, 56; 56, identifier:line; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:solution; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, string:"Must be any of: {}"; 63, identifier:format; 64, argument_list; 64, 65; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, string:' '; 68, identifier:join; 69, argument_list; 69, 70; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:lines; 73, identifier:keys; 74, argument_list; 75, raise_statement; 75, 76; 76, call; 76, 77; 76, 78; 77, identifier:ValueError; 78, argument_list; 78, 79; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, string:'{} {}'; 82, identifier:format; 83, argument_list; 83, 84; 83, 85; 84, identifier:error; 85, identifier:solution; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:l; 89, subscript; 89, 90; 89, 91; 90, identifier:lines; 91, identifier:line; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:origin; 95, subscript; 95, 96; 95, 101; 95, 106; 96, subscript; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:f; 99, identifier:header; 100, integer:0; 101, attribute; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:segyio; 104, identifier:su; 105, identifier:cdpx; 106, attribute; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:segyio; 109, identifier:su; 110, identifier:cdpy; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 116; 113, pattern_list; 113, 114; 113, 115; 114, identifier:cdpx; 115, identifier:cdpy; 116, expression_list; 116, 117; 116, 124; 117, subscript; 117, 118; 117, 119; 118, identifier:origin; 119, attribute; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:segyio; 122, identifier:su; 123, identifier:cdpx; 124, subscript; 124, 125; 124, 126; 125, identifier:origin; 126, attribute; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:segyio; 129, identifier:su; 130, identifier:cdpy; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:rot; 134, call; 134, 135; 134, 140; 135, attribute; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:f; 138, identifier:xfd; 139, identifier:rotation; 140, argument_list; 140, 141; 140, 145; 140, 148; 140, 154; 141, call; 141, 142; 141, 143; 142, identifier:len; 143, argument_list; 143, 144; 144, identifier:l; 145, attribute; 145, 146; 145, 147; 146, identifier:l; 147, identifier:stride; 148, call; 148, 149; 148, 150; 149, identifier:len; 150, argument_list; 150, 151; 151, attribute; 151, 152; 151, 153; 152, identifier:f; 153, identifier:offsets; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:np; 157, identifier:fromiter; 158, argument_list; 158, 159; 158, 164; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:l; 162, identifier:keys; 163, argument_list; 164, keyword_argument; 164, 165; 164, 166; 165, identifier:dtype; 166, attribute; 166, 167; 166, 168; 167, identifier:np; 168, identifier:intc; 169, return_statement; 169, 170; 170, expression_list; 170, 171; 170, 172; 170, 173; 171, identifier:rot; 172, identifier:cdpx; 173, identifier:cdpy | def rotation(f, line = 'fast'):
if f.unstructured:
raise ValueError("Rotation requires a structured file")
lines = { 'fast': f.fast,
'slow': f.slow,
'iline': f.iline,
'xline': f.xline,
}
if line not in lines:
error = "Unknown line {}".format(line)
solution = "Must be any of: {}".format(' '.join(lines.keys()))
raise ValueError('{} {}'.format(error, solution))
l = lines[line]
origin = f.header[0][segyio.su.cdpx, segyio.su.cdpy]
cdpx, cdpy = origin[segyio.su.cdpx], origin[segyio.su.cdpy]
rot = f.xfd.rotation( len(l),
l.stride,
len(f.offsets),
np.fromiter(l.keys(), dtype = np.intc) )
return rot, cdpx, cdpy |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 23; 2, function_name:from_array3D; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 17; 3, 20; 4, identifier:filename; 5, identifier:data; 6, default_parameter; 6, 7; 6, 8; 7, identifier:iline; 8, integer:189; 9, default_parameter; 9, 10; 9, 11; 10, identifier:xline; 11, integer:193; 12, default_parameter; 12, 13; 12, 14; 13, identifier:format; 14, attribute; 14, 15; 14, 16; 15, identifier:SegySampleFormat; 16, identifier:IBM_FLOAT_4_BYTE; 17, default_parameter; 17, 18; 17, 19; 18, identifier:dt; 19, integer:4000; 20, default_parameter; 20, 21; 20, 22; 21, identifier:delrt; 22, integer:0; 23, block; 23, 24; 23, 33; 23, 42; 23, 61; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:data; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:np; 30, identifier:asarray; 31, argument_list; 31, 32; 32, identifier:data; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:dimensions; 36, call; 36, 37; 36, 38; 37, identifier:len; 38, argument_list; 38, 39; 39, attribute; 39, 40; 39, 41; 40, identifier:data; 41, identifier:shape; 42, if_statement; 42, 43; 42, 46; 43, comparison_operator:!=; 43, 44; 43, 45; 44, identifier:dimensions; 45, integer:3; 46, block; 46, 47; 46, 56; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:problem; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, string:"Expected 3 dimensions, {} was given"; 53, identifier:format; 54, argument_list; 54, 55; 55, identifier:dimensions; 56, raise_statement; 56, 57; 57, call; 57, 58; 57, 59; 58, identifier:ValueError; 59, argument_list; 59, 60; 60, identifier:problem; 61, expression_statement; 61, 62; 62, call; 62, 63; 62, 64; 63, identifier:from_array; 64, argument_list; 64, 65; 64, 66; 64, 67; 64, 70; 64, 73; 64, 76; 64, 79; 65, identifier:filename; 66, identifier:data; 67, keyword_argument; 67, 68; 67, 69; 68, identifier:iline; 69, identifier:iline; 70, keyword_argument; 70, 71; 70, 72; 71, identifier:xline; 72, identifier:xline; 73, keyword_argument; 73, 74; 73, 75; 74, identifier:format; 75, identifier:format; 76, keyword_argument; 76, 77; 76, 78; 77, identifier:dt; 78, identifier:dt; 79, keyword_argument; 79, 80; 79, 81; 80, identifier:delrt; 81, identifier:delrt | def from_array3D(filename, data, iline=189,
xline=193,
format=SegySampleFormat.IBM_FLOAT_4_BYTE,
dt=4000,
delrt=0):
data = np.asarray(data)
dimensions = len(data.shape)
if dimensions != 3:
problem = "Expected 3 dimensions, {} was given".format(dimensions)
raise ValueError(problem)
from_array(filename, data, iline=iline, xline=xline, format=format,
dt=dt,
delrt=delrt) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 23; 2, function_name:open; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 4, identifier:filename; 5, default_parameter; 5, 6; 5, 7; 6, identifier:mode; 7, string:"r"; 8, default_parameter; 8, 9; 8, 10; 9, identifier:iline; 10, integer:189; 11, default_parameter; 11, 12; 11, 13; 12, identifier:xline; 13, integer:193; 14, default_parameter; 14, 15; 14, 16; 15, identifier:strict; 16, True; 17, default_parameter; 17, 18; 17, 19; 18, identifier:ignore_geometry; 19, False; 20, default_parameter; 20, 21; 20, 22; 21, identifier:endian; 22, string:'big'; 23, block; 23, 24; 23, 49; 23, 65; 23, 99; 23, 104; 23, 120; 23, 126; 23, 134; 23, 161; 23, 224; 23, 229; 24, if_statement; 24, 25; 24, 28; 25, comparison_operator:in; 25, 26; 25, 27; 26, string:'w'; 27, identifier:mode; 28, block; 28, 29; 28, 33; 28, 37; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:problem; 32, string:'w in mode would truncate the file'; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:solution; 36, string:'use r+ to open in read-write'; 37, raise_statement; 37, 38; 38, call; 38, 39; 38, 40; 39, identifier:ValueError; 40, argument_list; 40, 41; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, string:', '; 44, identifier:join; 45, argument_list; 45, 46; 46, tuple; 46, 47; 46, 48; 47, identifier:problem; 48, identifier:solution; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:endians; 52, dictionary; 52, 53; 52, 56; 52, 59; 52, 62; 53, pair; 53, 54; 53, 55; 54, string:'little'; 55, integer:256; 56, pair; 56, 57; 56, 58; 57, string:'lsb'; 58, integer:256; 59, pair; 59, 60; 59, 61; 60, string:'big'; 61, integer:0; 62, pair; 62, 63; 62, 64; 63, string:'msb'; 64, integer:0; 65, if_statement; 65, 66; 65, 69; 66, comparison_operator:not; 66, 67; 66, 68; 67, identifier:endian; 68, identifier:endians; 69, block; 69, 70; 69, 74; 69, 87; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:problem; 73, string:'unknown endianness {}, expected one of: '; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:opts; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, string:' '; 80, identifier:join; 81, argument_list; 81, 82; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:endians; 85, identifier:keys; 86, argument_list; 87, raise_statement; 87, 88; 88, call; 88, 89; 88, 90; 89, identifier:ValueError; 90, argument_list; 90, 91; 91, binary_operator:+; 91, 92; 91, 98; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:problem; 95, identifier:format; 96, argument_list; 96, 97; 97, identifier:endian; 98, identifier:opts; 99, import_from_statement; 99, 100; 99, 102; 100, relative_import; 100, 101; 101, import_prefix; 102, dotted_name; 102, 103; 103, identifier:_segyio; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:fd; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:_segyio; 110, identifier:segyiofd; 111, argument_list; 111, 112; 111, 116; 111, 117; 112, call; 112, 113; 112, 114; 113, identifier:str; 114, argument_list; 114, 115; 115, identifier:filename; 116, identifier:mode; 117, subscript; 117, 118; 117, 119; 118, identifier:endians; 119, identifier:endian; 120, expression_statement; 120, 121; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:fd; 124, identifier:segyopen; 125, argument_list; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 129; 128, identifier:metrics; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:fd; 132, identifier:metrics; 133, argument_list; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:f; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:segyio; 140, identifier:SegyFile; 141, argument_list; 141, 142; 141, 143; 141, 149; 141, 152; 141, 155; 141, 158; 142, identifier:fd; 143, keyword_argument; 143, 144; 143, 145; 144, identifier:filename; 145, call; 145, 146; 145, 147; 146, identifier:str; 147, argument_list; 147, 148; 148, identifier:filename; 149, keyword_argument; 149, 150; 149, 151; 150, identifier:mode; 151, identifier:mode; 152, keyword_argument; 152, 153; 152, 154; 153, identifier:iline; 154, identifier:iline; 155, keyword_argument; 155, 156; 155, 157; 156, identifier:xline; 157, identifier:xline; 158, keyword_argument; 158, 159; 158, 160; 159, identifier:endian; 160, identifier:endian; 161, try_statement; 161, 162; 161, 215; 162, block; 162, 163; 162, 179; 162, 193; 162, 199; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 166; 165, identifier:dt; 166, binary_operator:/; 166, 167; 166, 178; 167, call; 167, 168; 167, 173; 168, attribute; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:segyio; 171, identifier:tools; 172, identifier:dt; 173, argument_list; 173, 174; 173, 175; 174, identifier:f; 175, keyword_argument; 175, 176; 175, 177; 176, identifier:fallback_dt; 177, float:4000.0; 178, float:1000.0; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 182; 181, identifier:t0; 182, subscript; 182, 183; 182, 188; 183, subscript; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:f; 186, identifier:header; 187, integer:0; 188, attribute; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:segyio; 191, identifier:TraceField; 192, identifier:DelayRecordingTime; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 196; 195, identifier:samples; 196, subscript; 196, 197; 196, 198; 197, identifier:metrics; 198, string:'samplecount'; 199, expression_statement; 199, 200; 200, assignment; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:f; 203, identifier:_samples; 204, binary_operator:+; 204, 205; 204, 214; 205, parenthesized_expression; 205, 206; 206, binary_operator:*; 206, 207; 206, 213; 207, call; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:numpy; 210, identifier:arange; 211, argument_list; 211, 212; 212, identifier:samples; 213, identifier:dt; 214, identifier:t0; 215, except_clause; 215, 216; 216, block; 216, 217; 216, 223; 217, expression_statement; 217, 218; 218, call; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:f; 221, identifier:close; 222, argument_list; 223, raise_statement; 224, if_statement; 224, 225; 224, 226; 225, identifier:ignore_geometry; 226, block; 226, 227; 227, return_statement; 227, 228; 228, identifier:f; 229, return_statement; 229, 230; 230, call; 230, 231; 230, 232; 231, identifier:infer_geometry; 232, argument_list; 232, 233; 232, 234; 232, 235; 232, 236; 232, 237; 233, identifier:f; 234, identifier:metrics; 235, identifier:iline; 236, identifier:xline; 237, identifier:strict | def open(filename, mode="r", iline = 189,
xline = 193,
strict = True,
ignore_geometry = False,
endian = 'big'):
if 'w' in mode:
problem = 'w in mode would truncate the file'
solution = 'use r+ to open in read-write'
raise ValueError(', '.join((problem, solution)))
endians = {
'little': 256,
'lsb': 256,
'big': 0,
'msb': 0,
}
if endian not in endians:
problem = 'unknown endianness {}, expected one of: '
opts = ' '.join(endians.keys())
raise ValueError(problem.format(endian) + opts)
from . import _segyio
fd = _segyio.segyiofd(str(filename), mode, endians[endian])
fd.segyopen()
metrics = fd.metrics()
f = segyio.SegyFile(fd,
filename = str(filename),
mode = mode,
iline = iline,
xline = xline,
endian = endian,
)
try:
dt = segyio.tools.dt(f, fallback_dt = 4000.0) / 1000.0
t0 = f.header[0][segyio.TraceField.DelayRecordingTime]
samples = metrics['samplecount']
f._samples = (numpy.arange(samples) * dt) + t0
except:
f.close()
raise
if ignore_geometry:
return f
return infer_geometry(f, metrics, iline, xline, strict) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:calc_min_interval; 3, parameters; 3, 4; 3, 5; 4, identifier:x; 5, identifier:alpha; 6, block; 6, 7; 6, 14; 6, 20; 6, 34; 6, 40; 6, 54; 6, 71; 6, 80; 6, 86; 6, 94; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:n; 10, call; 10, 11; 10, 12; 11, identifier:len; 12, argument_list; 12, 13; 13, identifier:x; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:cred_mass; 17, binary_operator:-; 17, 18; 17, 19; 18, float:1.0; 19, identifier:alpha; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:interval_idx_inc; 23, call; 23, 24; 23, 25; 24, identifier:int; 25, argument_list; 25, 26; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:np; 29, identifier:floor; 30, argument_list; 30, 31; 31, binary_operator:*; 31, 32; 31, 33; 32, identifier:cred_mass; 33, identifier:n; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:n_intervals; 37, binary_operator:-; 37, 38; 37, 39; 38, identifier:n; 39, identifier:interval_idx_inc; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:interval_width; 43, binary_operator:-; 43, 44; 43, 49; 44, subscript; 44, 45; 44, 46; 45, identifier:x; 46, slice; 46, 47; 46, 48; 47, identifier:interval_idx_inc; 48, colon; 49, subscript; 49, 50; 49, 51; 50, identifier:x; 51, slice; 51, 52; 51, 53; 52, colon; 53, identifier:n_intervals; 54, if_statement; 54, 55; 54, 61; 55, comparison_operator:==; 55, 56; 55, 60; 56, call; 56, 57; 56, 58; 57, identifier:len; 58, argument_list; 58, 59; 59, identifier:interval_width; 60, integer:0; 61, block; 61, 62; 61, 67; 62, expression_statement; 62, 63; 63, call; 63, 64; 63, 65; 64, identifier:print_; 65, argument_list; 65, 66; 66, string:'Too few elements for interval calculation'; 67, return_statement; 67, 68; 68, list:[None, None]; 68, 69; 68, 70; 69, None; 70, None; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:min_idx; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:np; 77, identifier:argmin; 78, argument_list; 78, 79; 79, identifier:interval_width; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:hdi_min; 83, subscript; 83, 84; 83, 85; 84, identifier:x; 85, identifier:min_idx; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:hdi_max; 89, subscript; 89, 90; 89, 91; 90, identifier:x; 91, binary_operator:+; 91, 92; 91, 93; 92, identifier:min_idx; 93, identifier:interval_idx_inc; 94, return_statement; 94, 95; 95, list:[hdi_min, hdi_max]; 95, 96; 95, 97; 96, identifier:hdi_min; 97, identifier:hdi_max | def calc_min_interval(x, alpha):
n = len(x)
cred_mass = 1.0 - alpha
interval_idx_inc = int(np.floor(cred_mass * n))
n_intervals = n - interval_idx_inc
interval_width = x[interval_idx_inc:] - x[:n_intervals]
if len(interval_width) == 0:
print_('Too few elements for interval calculation')
return [None, None]
min_idx = np.argmin(interval_width)
hdi_min = x[min_idx]
hdi_max = x[min_idx + interval_idx_inc]
return [hdi_min, hdi_max] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_compute_gas_price; 3, parameters; 3, 4; 3, 5; 4, identifier:probabilities; 5, identifier:desired_probability; 6, block; 6, 7; 6, 13; 6, 20; 6, 48; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:first; 10, subscript; 10, 11; 10, 12; 11, identifier:probabilities; 12, integer:0; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:last; 16, subscript; 16, 17; 16, 18; 17, identifier:probabilities; 18, unary_operator:-; 18, 19; 19, integer:1; 20, if_statement; 20, 21; 20, 26; 20, 34; 21, comparison_operator:>=; 21, 22; 21, 23; 22, identifier:desired_probability; 23, attribute; 23, 24; 23, 25; 24, identifier:first; 25, identifier:prob; 26, block; 26, 27; 27, return_statement; 27, 28; 28, call; 28, 29; 28, 30; 29, identifier:int; 30, argument_list; 30, 31; 31, attribute; 31, 32; 31, 33; 32, identifier:first; 33, identifier:gas_price; 34, elif_clause; 34, 35; 34, 40; 35, comparison_operator:<=; 35, 36; 35, 37; 36, identifier:desired_probability; 37, attribute; 37, 38; 37, 39; 38, identifier:last; 39, identifier:prob; 40, block; 40, 41; 41, return_statement; 41, 42; 42, call; 42, 43; 42, 44; 43, identifier:int; 44, argument_list; 44, 45; 45, attribute; 45, 46; 45, 47; 46, identifier:last; 47, identifier:gas_price; 48, for_statement; 48, 49; 48, 52; 48, 57; 48, 132; 49, pattern_list; 49, 50; 49, 51; 50, identifier:left; 51, identifier:right; 52, call; 52, 53; 52, 54; 53, identifier:sliding_window; 54, argument_list; 54, 55; 54, 56; 55, integer:2; 56, identifier:probabilities; 57, block; 57, 58; 57, 78; 57, 86; 57, 96; 57, 102; 57, 112; 57, 130; 58, if_statement; 58, 59; 58, 64; 58, 66; 59, comparison_operator:<; 59, 60; 59, 61; 60, identifier:desired_probability; 61, attribute; 61, 62; 61, 63; 62, identifier:right; 63, identifier:prob; 64, block; 64, 65; 65, continue_statement; 66, elif_clause; 66, 67; 66, 72; 67, comparison_operator:>; 67, 68; 67, 69; 68, identifier:desired_probability; 69, attribute; 69, 70; 69, 71; 70, identifier:left; 71, identifier:prob; 72, block; 72, 73; 73, raise_statement; 73, 74; 74, call; 74, 75; 74, 76; 75, identifier:Exception; 76, argument_list; 76, 77; 77, string:'Invariant'; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:adj_prob; 81, binary_operator:-; 81, 82; 81, 83; 82, identifier:desired_probability; 83, attribute; 83, 84; 83, 85; 84, identifier:right; 85, identifier:prob; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:window_size; 89, binary_operator:-; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:left; 92, identifier:prob; 93, attribute; 93, 94; 93, 95; 94, identifier:right; 95, identifier:prob; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:position; 99, binary_operator:/; 99, 100; 99, 101; 100, identifier:adj_prob; 101, identifier:window_size; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:gas_window_size; 105, binary_operator:-; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:left; 108, identifier:gas_price; 109, attribute; 109, 110; 109, 111; 110, identifier:right; 111, identifier:gas_price; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:gas_price; 115, call; 115, 116; 115, 117; 116, identifier:int; 117, argument_list; 117, 118; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:math; 121, identifier:ceil; 122, argument_list; 122, 123; 123, binary_operator:+; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:right; 126, identifier:gas_price; 127, binary_operator:*; 127, 128; 127, 129; 128, identifier:gas_window_size; 129, identifier:position; 130, return_statement; 130, 131; 131, identifier:gas_price; 132, else_clause; 132, 133; 133, block; 133, 134; 134, raise_statement; 134, 135; 135, call; 135, 136; 135, 137; 136, identifier:Exception; 137, argument_list; 137, 138; 138, string:'Invariant' | def _compute_gas_price(probabilities, desired_probability):
first = probabilities[0]
last = probabilities[-1]
if desired_probability >= first.prob:
return int(first.gas_price)
elif desired_probability <= last.prob:
return int(last.gas_price)
for left, right in sliding_window(2, probabilities):
if desired_probability < right.prob:
continue
elif desired_probability > left.prob:
raise Exception('Invariant')
adj_prob = desired_probability - right.prob
window_size = left.prob - right.prob
position = adj_prob / window_size
gas_window_size = left.gas_price - right.gas_price
gas_price = int(math.ceil(right.gas_price + gas_window_size * position))
return gas_price
else:
raise Exception('Invariant') |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:generate_X_grid; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:self; 5, identifier:term; 6, default_parameter; 6, 7; 6, 8; 7, identifier:n; 8, integer:100; 9, default_parameter; 9, 10; 9, 11; 10, identifier:meshgrid; 11, False; 12, block; 12, 13; 12, 24; 12, 38; 13, if_statement; 13, 14; 13, 18; 14, not_operator; 14, 15; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:_is_fitted; 18, block; 18, 19; 19, raise_statement; 19, 20; 20, call; 20, 21; 20, 22; 21, identifier:AttributeError; 22, argument_list; 22, 23; 23, string:'GAM has not been fitted. Call fit first.'; 24, if_statement; 24, 25; 24, 32; 25, attribute; 25, 26; 25, 31; 26, subscript; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:terms; 30, identifier:term; 31, identifier:isintercept; 32, block; 32, 33; 33, raise_statement; 33, 34; 34, call; 34, 35; 34, 36; 35, identifier:ValueError; 36, argument_list; 36, 37; 37, string:'cannot create grid for intercept term'; 38, if_statement; 38, 39; 38, 46; 38, 116; 38, 221; 39, attribute; 39, 40; 39, 45; 40, subscript; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:terms; 44, identifier:term; 45, identifier:istensor; 46, block; 46, 47; 46, 51; 46, 83; 46, 96; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:Xs; 50, list:[]; 51, for_statement; 51, 52; 51, 53; 51, 58; 52, identifier:term_; 53, subscript; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:terms; 57, identifier:term; 58, block; 58, 59; 59, expression_statement; 59, 60; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:Xs; 63, identifier:append; 64, argument_list; 64, 65; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:np; 68, identifier:linspace; 69, argument_list; 69, 70; 69, 75; 69, 80; 70, subscript; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:term_; 73, identifier:edge_knots_; 74, integer:0; 75, subscript; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:term_; 78, identifier:edge_knots_; 79, integer:1; 80, keyword_argument; 80, 81; 80, 82; 81, identifier:num; 82, identifier:n; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:Xs; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:np; 89, identifier:meshgrid; 90, argument_list; 90, 91; 90, 93; 91, list_splat; 91, 92; 92, identifier:Xs; 93, keyword_argument; 93, 94; 93, 95; 94, identifier:indexing; 95, string:'ij'; 96, if_statement; 96, 97; 96, 98; 96, 104; 97, identifier:meshgrid; 98, block; 98, 99; 99, return_statement; 99, 100; 100, call; 100, 101; 100, 102; 101, identifier:tuple; 102, argument_list; 102, 103; 103, identifier:Xs; 104, else_clause; 104, 105; 105, block; 105, 106; 106, return_statement; 106, 107; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:self; 110, identifier:_flatten_mesh; 111, argument_list; 111, 112; 111, 113; 112, identifier:Xs; 113, keyword_argument; 113, 114; 113, 115; 114, identifier:term; 115, identifier:term; 116, elif_clause; 116, 117; 116, 126; 117, call; 117, 118; 117, 119; 118, identifier:hasattr; 119, argument_list; 119, 120; 119, 125; 120, subscript; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:self; 123, identifier:terms; 124, identifier:term; 125, string:'edge_knots_'; 126, block; 126, 127; 126, 156; 126, 162; 126, 177; 126, 191; 126, 219; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:x; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:np; 133, identifier:linspace; 134, argument_list; 134, 135; 134, 144; 134, 153; 135, subscript; 135, 136; 135, 143; 136, attribute; 136, 137; 136, 142; 137, subscript; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:self; 140, identifier:terms; 141, identifier:term; 142, identifier:edge_knots_; 143, integer:0; 144, subscript; 144, 145; 144, 152; 145, attribute; 145, 146; 145, 151; 146, subscript; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:self; 149, identifier:terms; 150, identifier:term; 151, identifier:edge_knots_; 152, integer:1; 153, keyword_argument; 153, 154; 153, 155; 154, identifier:num; 155, identifier:n; 156, if_statement; 156, 157; 156, 158; 157, identifier:meshgrid; 158, block; 158, 159; 159, return_statement; 159, 160; 160, tuple; 160, 161; 161, identifier:x; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:X; 165, call; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:np; 168, identifier:zeros; 169, argument_list; 169, 170; 170, tuple; 170, 171; 170, 172; 171, identifier:n; 172, subscript; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:self; 175, identifier:statistics_; 176, string:'m_features'; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 190; 179, subscript; 179, 180; 179, 181; 179, 183; 180, identifier:X; 181, slice; 181, 182; 182, colon; 183, attribute; 183, 184; 183, 189; 184, subscript; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:self; 187, identifier:terms; 188, identifier:term; 189, identifier:feature; 190, identifier:x; 191, if_statement; 191, 192; 191, 204; 192, comparison_operator:is; 192, 193; 192, 203; 193, call; 193, 194; 193, 195; 194, identifier:getattr; 195, argument_list; 195, 196; 195, 201; 195, 202; 196, subscript; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:self; 199, identifier:terms; 200, identifier:term; 201, string:'by'; 202, None; 203, None; 204, block; 204, 205; 205, expression_statement; 205, 206; 206, assignment; 206, 207; 206, 218; 207, subscript; 207, 208; 207, 209; 207, 211; 208, identifier:X; 209, slice; 209, 210; 210, colon; 211, attribute; 211, 212; 211, 217; 212, subscript; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:self; 215, identifier:terms; 216, identifier:term; 217, identifier:by; 218, float:1.; 219, return_statement; 219, 220; 220, identifier:X; 221, else_clause; 221, 222; 222, block; 222, 223; 223, raise_statement; 223, 224; 224, call; 224, 225; 224, 226; 225, identifier:TypeError; 226, argument_list; 226, 227; 227, call; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, string:'Unexpected term type: {}'; 230, identifier:format; 231, argument_list; 231, 232; 232, subscript; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:self; 235, identifier:terms; 236, identifier:term | def generate_X_grid(self, term, n=100, meshgrid=False):
if not self._is_fitted:
raise AttributeError('GAM has not been fitted. Call fit first.')
if self.terms[term].isintercept:
raise ValueError('cannot create grid for intercept term')
if self.terms[term].istensor:
Xs = []
for term_ in self.terms[term]:
Xs.append(np.linspace(term_.edge_knots_[0],
term_.edge_knots_[1],
num=n))
Xs = np.meshgrid(*Xs, indexing='ij')
if meshgrid:
return tuple(Xs)
else:
return self._flatten_mesh(Xs, term=term)
elif hasattr(self.terms[term], 'edge_knots_'):
x = np.linspace(self.terms[term].edge_knots_[0],
self.terms[term].edge_knots_[1],
num=n)
if meshgrid:
return (x,)
X = np.zeros((n, self.statistics_['m_features']))
X[:, self.terms[term].feature] = x
if getattr(self.terms[term], 'by', None) is not None:
X[:, self.terms[term].by] = 1.
return X
else:
raise TypeError('Unexpected term type: {}'.format(self.terms[term])) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:build_from_info; 3, parameters; 3, 4; 3, 5; 4, identifier:cls; 5, identifier:info; 6, block; 6, 7; 6, 11; 6, 29; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:terms; 10, list:[]; 11, for_statement; 11, 12; 11, 13; 11, 16; 12, identifier:term_info; 13, subscript; 13, 14; 13, 15; 14, identifier:info; 15, string:'terms'; 16, block; 16, 17; 17, expression_statement; 17, 18; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:terms; 21, identifier:append; 22, argument_list; 22, 23; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:SplineTerm; 26, identifier:build_from_info; 27, argument_list; 27, 28; 28, identifier:term_info; 29, return_statement; 29, 30; 30, call; 30, 31; 30, 32; 31, identifier:cls; 32, argument_list; 32, 33; 33, list_splat; 33, 34; 34, identifier:terms | def build_from_info(cls, info):
terms = []
for term_info in info['terms']:
terms.append(SplineTerm.build_from_info(term_info))
return cls(*terms) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:sort_kate_imports; 3, parameters; 3, 4; 3, 7; 4, default_parameter; 4, 5; 4, 6; 5, identifier:add_imports; 6, tuple; 7, default_parameter; 7, 8; 7, 9; 8, identifier:remove_imports; 9, tuple; 10, block; 10, 11; 10, 19; 10, 27; 10, 35; 10, 43; 10, 90; 10, 99; 10, 114; 10, 178; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:document; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:kate; 17, identifier:activeDocument; 18, argument_list; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:view; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:document; 25, identifier:activeView; 26, argument_list; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:position; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:view; 33, identifier:cursorPosition; 34, argument_list; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:selection; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:view; 41, identifier:selectionRange; 42, argument_list; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:sorter; 46, call; 46, 47; 46, 48; 47, identifier:SortImports; 48, argument_list; 48, 49; 48, 56; 48, 59; 48, 62; 49, keyword_argument; 49, 50; 49, 51; 50, identifier:file_contents; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:document; 54, identifier:text; 55, argument_list; 56, keyword_argument; 56, 57; 56, 58; 57, identifier:add_imports; 58, identifier:add_imports; 59, keyword_argument; 59, 60; 59, 61; 60, identifier:remove_imports; 61, identifier:remove_imports; 62, keyword_argument; 62, 63; 62, 64; 63, identifier:settings_path; 64, call; 64, 65; 64, 70; 65, attribute; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:os; 68, identifier:path; 69, identifier:dirname; 70, argument_list; 70, 71; 71, call; 71, 72; 71, 77; 72, attribute; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:os; 75, identifier:path; 76, identifier:abspath; 77, argument_list; 77, 78; 78, call; 78, 79; 78, 80; 79, identifier:str; 80, argument_list; 80, 81; 81, call; 81, 82; 81, 89; 82, attribute; 82, 83; 82, 88; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:document; 86, identifier:url; 87, argument_list; 88, identifier:path; 89, argument_list; 90, expression_statement; 90, 91; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:document; 94, identifier:setText; 95, argument_list; 95, 96; 96, attribute; 96, 97; 96, 98; 97, identifier:sorter; 98, identifier:output; 99, expression_statement; 99, 100; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:position; 103, identifier:setLine; 104, argument_list; 104, 105; 105, binary_operator:+; 105, 106; 105, 111; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:position; 109, identifier:line; 110, argument_list; 111, attribute; 111, 112; 111, 113; 112, identifier:sorter; 113, identifier:length_change; 114, if_statement; 114, 115; 114, 116; 115, identifier:selection; 116, block; 116, 117; 116, 125; 116, 140; 116, 148; 116, 163; 116, 171; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:start; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:selection; 123, identifier:start; 124, argument_list; 125, expression_statement; 125, 126; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:start; 129, identifier:setLine; 130, argument_list; 130, 131; 131, binary_operator:+; 131, 132; 131, 137; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:start; 135, identifier:line; 136, argument_list; 137, attribute; 137, 138; 137, 139; 138, identifier:sorter; 139, identifier:length_change; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:end; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:selection; 146, identifier:end; 147, argument_list; 148, expression_statement; 148, 149; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:end; 152, identifier:setLine; 153, argument_list; 153, 154; 154, binary_operator:+; 154, 155; 154, 160; 155, call; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:end; 158, identifier:line; 159, argument_list; 160, attribute; 160, 161; 160, 162; 161, identifier:sorter; 162, identifier:length_change; 163, expression_statement; 163, 164; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:selection; 167, identifier:setRange; 168, argument_list; 168, 169; 168, 170; 169, identifier:start; 170, identifier:end; 171, expression_statement; 171, 172; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:view; 175, identifier:setSelection; 176, argument_list; 176, 177; 177, identifier:selection; 178, expression_statement; 178, 179; 179, call; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:view; 182, identifier:setCursorPosition; 183, argument_list; 183, 184; 184, identifier:position | def sort_kate_imports(add_imports=(), remove_imports=()):
document = kate.activeDocument()
view = document.activeView()
position = view.cursorPosition()
selection = view.selectionRange()
sorter = SortImports(file_contents=document.text(), add_imports=add_imports, remove_imports=remove_imports,
settings_path=os.path.dirname(os.path.abspath(str(document.url().path()))))
document.setText(sorter.output)
position.setLine(position.line() + sorter.length_change)
if selection:
start = selection.start()
start.setLine(start.line() + sorter.length_change)
end = selection.end()
end.setLine(end.line() + sorter.length_change)
selection.setRange(start, end)
view.setSelection(selection)
view.setCursorPosition(position) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 1, 7; 2, function_name:_get_line; 3, parameters; 3, 4; 4, identifier:self; 5, type; 5, 6; 6, identifier:str; 7, block; 7, 8; 7, 18; 7, 24; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:line; 11, subscript; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:in_lines; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:index; 18, expression_statement; 18, 19; 19, augmented_assignment:+=; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:index; 23, integer:1; 24, return_statement; 24, 25; 25, identifier:line | def _get_line(self) -> str:
line = self.in_lines[self.index]
self.index += 1
return line |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 22; 1, 24; 2, function_name:_add_comments; 3, parameters; 3, 4; 3, 5; 3, 17; 4, identifier:self; 5, typed_parameter; 5, 6; 5, 7; 6, identifier:comments; 7, type; 7, 8; 8, generic_type; 8, 9; 8, 10; 9, identifier:Optional; 10, type_parameter; 10, 11; 11, type; 11, 12; 12, generic_type; 12, 13; 12, 14; 13, identifier:Sequence; 14, type_parameter; 14, 15; 15, type; 15, 16; 16, identifier:str; 17, typed_default_parameter; 17, 18; 17, 19; 17, 21; 18, identifier:original_string; 19, type; 19, 20; 20, identifier:str; 21, string:""; 22, type; 22, 23; 23, identifier:str; 24, block; 24, 25; 24, 41; 25, if_statement; 25, 26; 25, 31; 26, subscript; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:config; 30, string:'ignore_comments'; 31, block; 31, 32; 32, return_statement; 32, 33; 33, subscript; 33, 34; 33, 40; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:_strip_comments; 38, argument_list; 38, 39; 39, identifier:original_string; 40, integer:0; 41, if_statement; 41, 42; 41, 44; 41, 47; 42, not_operator; 42, 43; 43, identifier:comments; 44, block; 44, 45; 45, return_statement; 45, 46; 46, identifier:original_string; 47, else_clause; 47, 48; 48, block; 48, 49; 49, return_statement; 49, 50; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, string:"{0}{1} {2}"; 53, identifier:format; 54, argument_list; 54, 55; 54, 63; 54, 68; 55, subscript; 55, 56; 55, 62; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:_strip_comments; 60, argument_list; 60, 61; 61, identifier:original_string; 62, integer:0; 63, subscript; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:self; 66, identifier:config; 67, string:'comment_prefix'; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, string:"; "; 71, identifier:join; 72, argument_list; 72, 73; 73, identifier:comments | def _add_comments(
self,
comments: Optional[Sequence[str]],
original_string: str = ""
) -> str:
if self.config['ignore_comments']:
return self._strip_comments(original_string)[0]
if not comments:
return original_string
else:
return "{0}{1} {2}".format(self._strip_comments(original_string)[0],
self.config['comment_prefix'],
"; ".join(comments)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 1, 11; 2, function_name:_wrap; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, typed_parameter; 5, 6; 5, 7; 6, identifier:line; 7, type; 7, 8; 8, identifier:str; 9, type; 9, 10; 10, identifier:str; 11, block; 11, 12; 11, 20; 11, 370; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:wrap_mode; 15, subscript; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:config; 19, string:'multi_line_output'; 20, if_statement; 20, 21; 20, 37; 20, 333; 21, boolean_operator:and; 21, 22; 21, 32; 22, comparison_operator:>; 22, 23; 22, 27; 23, call; 23, 24; 23, 25; 24, identifier:len; 25, argument_list; 25, 26; 26, identifier:line; 27, subscript; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:config; 31, string:'line_length'; 32, comparison_operator:!=; 32, 33; 32, 34; 33, identifier:wrap_mode; 34, attribute; 34, 35; 34, 36; 35, identifier:WrapModes; 36, identifier:NOQA; 37, block; 37, 38; 37, 42; 37, 46; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:line_without_comment; 41, identifier:line; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:comment; 45, None; 46, if_statement; 46, 47; 46, 56; 47, comparison_operator:in; 47, 48; 47, 49; 47, 52; 48, string:'
line_without_comment, comment = line.split('; 49, ERROR; 49, 50; 49, 51; 50, identifier:for; 51, identifier:splitter; 52, tuple; 52, 53; 52, 54; 52, 55; 53, string:"import "; 54, string:"."; 55, string:"as "; 56, block; 56, 57; 56, 70; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:exp; 60, binary_operator:+; 60, 61; 60, 69; 61, binary_operator:+; 61, 62; 61, 63; 62, string:r"\b"; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:re; 66, identifier:escape; 67, argument_list; 67, 68; 68, identifier:splitter; 69, string:r"\b"; 70, if_statement; 70, 71; 70, 90; 71, boolean_operator:and; 71, 72; 71, 79; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:re; 75, identifier:search; 76, argument_list; 76, 77; 76, 78; 77, identifier:exp; 78, identifier:line_without_comment; 79, not_operator; 79, 80; 80, call; 80, 81; 80, 88; 81, attribute; 81, 82; 81, 87; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:line_without_comment; 85, identifier:strip; 86, argument_list; 87, identifier:startswith; 88, argument_list; 88, 89; 89, identifier:splitter; 90, block; 90, 91; 90, 101; 90, 115; 90, 159; 90, 171; 90, 195; 90, 321; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:line_parts; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:re; 97, identifier:split; 98, argument_list; 98, 99; 98, 100; 99, identifier:exp; 100, identifier:line_without_comment; 101, if_statement; 101, 102; 101, 103; 102, identifier:comment; 103, block; 103, 104; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 110; 105, 114; 106, subscript; 106, 107; 106, 108; 107, identifier:line_parts; 108, unary_operator:-; 108, 109; 109, integer:1; 110, ERROR; 110, 111; 110, 113; 111, interpolation; 111, 112; 112, integer:0; 113, identifier:next_line; 114, list:[]; 115, while_statement; 115, 116; 115, 138; 116, boolean_operator:and; 116, 117; 116, 137; 117, comparison_operator:>; 117, 118; 117, 125; 118, parenthesized_expression; 118, 119; 119, binary_operator:+; 119, 120; 119, 124; 120, call; 120, 121; 120, 122; 121, identifier:len; 122, argument_list; 122, 123; 123, identifier:line; 124, integer:2; 125, parenthesized_expression; 125, 126; 126, boolean_operator:or; 126, 127; 126, 132; 127, subscript; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:self; 130, identifier:config; 131, string:'wrap_length'; 132, subscript; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:self; 135, identifier:config; 136, string:'line_length'; 137, identifier:line_parts; 138, block; 138, 139; 138, 150; 139, expression_statement; 139, 140; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:next_line; 143, identifier:append; 144, argument_list; 144, 145; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:line_parts; 148, identifier:pop; 149, argument_list; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 153; 152, identifier:line; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:splitter; 156, identifier:join; 157, argument_list; 157, 158; 158, identifier:line_parts; 159, if_statement; 159, 160; 159, 162; 160, not_operator; 160, 161; 161, identifier:line; 162, block; 162, 163; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 166; 165, identifier:line; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:next_line; 169, identifier:pop; 170, argument_list; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:cont_line; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:self; 177, identifier:_wrap; 178, argument_list; 178, 179; 179, binary_operator:+; 179, 180; 179, 185; 180, subscript; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:self; 183, identifier:config; 184, string:'indent'; 185, call; 185, 186; 185, 194; 186, attribute; 186, 187; 186, 193; 187, call; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:splitter; 190, identifier:join; 191, argument_list; 191, 192; 192, identifier:next_line; 193, identifier:lstrip; 194, argument_list; 195, if_statement; 195, 196; 195, 201; 196, subscript; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:self; 199, identifier:config; 200, string:'use_parentheses'; 201, block; 201, 202; 201, 238; 201, 249; 201, 312; 202, expression_statement; 202, 203; 203, assignment; 203, 204; 203, 205; 204, identifier:output; 205, call; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, string:"{0}{1}({2}{3}{4}{5})"; 208, identifier:format; 209, argument_list; 209, 210; 209, 211; 209, 212; 209, 215; 209, 216; 209, 224; 210, identifier:line; 211, identifier:splitter; 212, attribute; 212, 213; 212, 214; 213, identifier:self; 214, identifier:line_separator; 215, identifier:cont_line; 216, conditional_expression:if; 216, 217; 216, 218; 216, 223; 217, string:","; 218, subscript; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:self; 221, identifier:config; 222, string:'include_trailing_comma'; 223, string:""; 224, conditional_expression:if; 224, 225; 224, 228; 224, 237; 225, attribute; 225, 226; 225, 227; 226, identifier:self; 227, identifier:line_separator; 228, comparison_operator:in; 228, 229; 228, 230; 229, identifier:wrap_mode; 230, set; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:WrapModes; 233, identifier:VERTICAL_HANGING_INDENT; 234, attribute; 234, 235; 234, 236; 235, identifier:WrapModes; 236, identifier:VERTICAL_GRID_GROUPED; 237, string:""; 238, expression_statement; 238, 239; 239, assignment; 239, 240; 239, 241; 240, identifier:lines; 241, call; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:output; 244, identifier:split; 245, argument_list; 245, 246; 246, attribute; 246, 247; 246, 248; 247, identifier:self; 248, identifier:line_separator; 249, if_statement; 249, 250; 249, 270; 250, boolean_operator:and; 250, 251; 250, 261; 251, comparison_operator:in; 251, 252; 251, 257; 252, subscript; 252, 253; 252, 256; 253, attribute; 253, 254; 253, 255; 254, identifier:self; 255, identifier:config; 256, string:'comment_prefix'; 257, subscript; 257, 258; 257, 259; 258, identifier:lines; 259, unary_operator:-; 259, 260; 260, integer:1; 261, call; 261, 262; 261, 268; 262, attribute; 262, 263; 262, 267; 263, subscript; 263, 264; 263, 265; 264, identifier:lines; 265, unary_operator:-; 265, 266; 266, integer:1; 267, identifier:endswith; 268, argument_list; 268, 269; 269, string:')'; 270, block; 270, 271; 270, 290; 271, expression_statement; 271, 272; 272, assignment; 272, 273; 272, 276; 273, pattern_list; 273, 274; 273, 275; 274, identifier:line; 275, identifier:comment; 276, call; 276, 277; 276, 283; 277, attribute; 277, 278; 277, 282; 278, subscript; 278, 279; 278, 280; 279, identifier:lines; 280, unary_operator:-; 280, 281; 281, integer:1; 282, identifier:split; 283, argument_list; 283, 284; 283, 289; 284, subscript; 284, 285; 284, 288; 285, attribute; 285, 286; 285, 287; 286, identifier:self; 287, identifier:config; 288, string:'comment_prefix'; 289, integer:1; 290, expression_statement; 290, 291; 291, assignment; 291, 292; 291, 296; 292, subscript; 292, 293; 292, 294; 293, identifier:lines; 294, unary_operator:-; 294, 295; 295, integer:1; 296, binary_operator:+; 296, 297; 296, 306; 297, binary_operator:+; 297, 298; 297, 301; 298, binary_operator:+; 298, 299; 298, 300; 299, identifier:line; 300, string:')'; 301, subscript; 301, 302; 301, 305; 302, attribute; 302, 303; 302, 304; 303, identifier:self; 304, identifier:config; 305, string:'comment_prefix'; 306, subscript; 306, 307; 306, 308; 307, identifier:comment; 308, slice; 308, 309; 308, 310; 309, colon; 310, unary_operator:-; 310, 311; 311, integer:1; 312, return_statement; 312, 313; 313, call; 313, 314; 313, 319; 314, attribute; 314, 315; 314, 318; 315, attribute; 315, 316; 315, 317; 316, identifier:self; 317, identifier:line_separator; 318, identifier:join; 319, argument_list; 319, 320; 320, identifier:lines; 321, return_statement; 321, 322; 322, call; 322, 323; 322, 326; 323, attribute; 323, 324; 323, 325; 324, string:"{0}{1}\\{2}{3}"; 325, identifier:format; 326, argument_list; 326, 327; 326, 328; 326, 329; 326, 332; 327, identifier:line; 328, identifier:splitter; 329, attribute; 329, 330; 329, 331; 330, identifier:self; 331, identifier:line_separator; 332, identifier:cont_line; 333, elif_clause; 333, 334; 333, 352; 333, 369; 334, boolean_operator:and; 334, 335; 334, 345; 335, comparison_operator:>; 335, 336; 335, 340; 336, call; 336, 337; 336, 338; 337, identifier:len; 338, argument_list; 338, 339; 339, identifier:line; 340, subscript; 340, 341; 340, 344; 341, attribute; 341, 342; 341, 343; 342, identifier:self; 343, identifier:config; 344, string:'line_length'; 345, comparison_operator:==; 345, 346; 345, 347; 346, identifier:wrap_mode; 347, attribute; 347, 348; 347, 351; 348, attribute; 348, 349; 348, 350; 349, identifier:settings; 350, identifier:WrapModes; 351, identifier:NOQA; 352, ERROR; 352, 353; 352, 360; 353, ERROR; 353, 354; 353, 355; 353, 357; 353, 359; 354, string:"
return "; 355, set; 355, 356; 356, integer:0; 357, set; 357, 358; 358, integer:1; 359, identifier:NOQA; 360, call; 360, 361; 360, 362; 361, identifier:format; 362, argument_list; 362, 363; 362, 364; 363, identifier:line; 364, subscript; 364, 365; 364, 368; 365, attribute; 365, 366; 365, 367; 366, identifier:self; 367, identifier:config; 368, string:'comment_prefix'; 369, block:; 370, return_statement; 370, 371; 371, identifier:line | def _wrap(self, line: str) -> str:
wrap_mode = self.config['multi_line_output']
if len(line) > self.config['line_length'] and wrap_mode != WrapModes.NOQA:
line_without_comment = line
comment = None
if '
line_without_comment, comment = line.split('
for splitter in ("import ", ".", "as "):
exp = r"\b" + re.escape(splitter) + r"\b"
if re.search(exp, line_without_comment) and not line_without_comment.strip().startswith(splitter):
line_parts = re.split(exp, line_without_comment)
if comment:
line_parts[-1] = '{0}
next_line = []
while (len(line) + 2) > (self.config['wrap_length'] or self.config['line_length']) and line_parts:
next_line.append(line_parts.pop())
line = splitter.join(line_parts)
if not line:
line = next_line.pop()
cont_line = self._wrap(self.config['indent'] + splitter.join(next_line).lstrip())
if self.config['use_parentheses']:
output = "{0}{1}({2}{3}{4}{5})".format(
line, splitter, self.line_separator, cont_line,
"," if self.config['include_trailing_comma'] else "",
self.line_separator if wrap_mode in {WrapModes.VERTICAL_HANGING_INDENT,
WrapModes.VERTICAL_GRID_GROUPED}
else "")
lines = output.split(self.line_separator)
if self.config['comment_prefix'] in lines[-1] and lines[-1].endswith(')'):
line, comment = lines[-1].split(self.config['comment_prefix'], 1)
lines[-1] = line + ')' + self.config['comment_prefix'] + comment[:-1]
return self.line_separator.join(lines)
return "{0}{1}\\{2}{3}".format(line, splitter, self.line_separator, cont_line)
elif len(line) > self.config['line_length'] and wrap_mode == settings.WrapModes.NOQA:
if "
return "{0}{1} NOQA".format(line, self.config['comment_prefix'])
return line |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_formatter; 3, parameters; 3, 4; 4, identifier:name; 5, block; 5, 6; 6, for_statement; 6, 7; 6, 8; 6, 12; 7, identifier:k; 8, call; 8, 9; 8, 10; 9, identifier:sorted; 10, argument_list; 10, 11; 11, identifier:_FORMATTERS; 12, block; 12, 13; 13, if_statement; 13, 14; 13, 20; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:k; 17, identifier:startswith; 18, argument_list; 18, 19; 19, identifier:name; 20, block; 20, 21; 21, return_statement; 21, 22; 22, subscript; 22, 23; 22, 24; 23, identifier:_FORMATTERS; 24, identifier:k | def get_formatter(name):
for k in sorted(_FORMATTERS):
if k.startswith(name):
return _FORMATTERS[k] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:call_once; 3, parameters; 3, 4; 4, identifier:func; 5, block; 5, 6; 5, 15; 5, 35; 5, 73; 5, 79; 5, 88; 5, 100; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:argspec; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:inspect; 12, identifier:getargspec; 13, argument_list; 13, 14; 14, identifier:func; 15, if_statement; 15, 16; 15, 27; 16, boolean_operator:or; 16, 17; 16, 24; 17, boolean_operator:or; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:argspec; 20, identifier:args; 21, attribute; 21, 22; 21, 23; 22, identifier:argspec; 23, identifier:varargs; 24, attribute; 24, 25; 24, 26; 25, identifier:argspec; 26, identifier:keywords; 27, block; 27, 28; 28, raise_statement; 28, 29; 29, call; 29, 30; 29, 31; 30, identifier:ValueError; 31, argument_list; 31, 32; 31, 33; 31, 34; 32, string:'Can only decorate functions with no args'; 33, identifier:func; 34, identifier:argspec; 35, decorated_definition; 35, 36; 35, 43; 36, decorator; 36, 37; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:functools; 40, identifier:wraps; 41, argument_list; 41, 42; 42, identifier:func; 43, function_definition; 43, 44; 43, 45; 43, 46; 44, function_name:_wrapper; 45, parameters; 46, block; 46, 47; 46, 69; 47, if_statement; 47, 48; 47, 54; 48, not_operator; 48, 49; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:_wrapper; 52, identifier:HasRun; 53, argument_list; 54, block; 54, 55; 54, 61; 55, expression_statement; 55, 56; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:_wrapper; 59, identifier:MarkAsRun; 60, argument_list; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:_wrapper; 65, identifier:return_value; 66, call; 66, 67; 66, 68; 67, identifier:func; 68, argument_list; 69, return_statement; 69, 70; 70, attribute; 70, 71; 70, 72; 71, identifier:_wrapper; 72, identifier:return_value; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:_wrapper; 77, identifier:has_run; 78, False; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:_wrapper; 83, identifier:HasRun; 84, lambda; 84, 85; 85, attribute; 85, 86; 85, 87; 86, identifier:_wrapper; 87, identifier:has_run; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:_wrapper; 92, identifier:MarkAsRun; 93, lambda; 93, 94; 94, call; 94, 95; 94, 96; 95, identifier:setattr; 96, argument_list; 96, 97; 96, 98; 96, 99; 97, identifier:_wrapper; 98, string:'has_run'; 99, True; 100, return_statement; 100, 101; 101, identifier:_wrapper | def call_once(func):
argspec = inspect.getargspec(func)
if argspec.args or argspec.varargs or argspec.keywords:
raise ValueError('Can only decorate functions with no args', func, argspec)
@functools.wraps(func)
def _wrapper():
if not _wrapper.HasRun():
_wrapper.MarkAsRun()
_wrapper.return_value = func()
return _wrapper.return_value
_wrapper.has_run = False
_wrapper.HasRun = lambda: _wrapper.has_run
_wrapper.MarkAsRun = lambda: setattr(_wrapper, 'has_run', True)
return _wrapper |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 19; 2, function_name:paginate; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 3, 13; 3, 16; 4, identifier:self; 5, identifier:model_class; 6, identifier:order_by; 7, default_parameter; 7, 8; 7, 9; 8, identifier:page_num; 9, integer:1; 10, default_parameter; 10, 11; 10, 12; 11, identifier:page_size; 12, integer:100; 13, default_parameter; 13, 14; 13, 15; 14, identifier:conditions; 15, None; 16, default_parameter; 16, 17; 16, 18; 17, identifier:settings; 18, None; 19, block; 19, 20; 19, 22; 19, 32; 19, 47; 19, 73; 19, 82; 19, 86; 19, 95; 19, 101; 19, 109; 19, 119; 20, expression_statement; 20, 21; 21, string:'''
Selects records and returns a single page of model instances.
- `model_class`: the model class matching the query's table,
or `None` for getting back instances of an ad-hoc model.
- `order_by`: columns to use for sorting the query (contents of the ORDER BY clause).
- `page_num`: the page number (1-based), or -1 to get the last page.
- `page_size`: number of records to return per page.
- `conditions`: optional SQL conditions (contents of the WHERE clause).
- `settings`: query settings to send as HTTP GET parameters
The result is a namedtuple containing `objects` (list), `number_of_objects`,
`pages_total`, `number` (of the current page), and `page_size`.
'''; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:count; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:count; 29, argument_list; 29, 30; 29, 31; 30, identifier:model_class; 31, identifier:conditions; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:pages_total; 35, call; 35, 36; 35, 37; 36, identifier:int; 37, argument_list; 37, 38; 38, call; 38, 39; 38, 40; 39, identifier:ceil; 40, argument_list; 40, 41; 41, binary_operator:/; 41, 42; 41, 43; 42, identifier:count; 43, call; 43, 44; 43, 45; 44, identifier:float; 45, argument_list; 45, 46; 46, identifier:page_size; 47, if_statement; 47, 48; 47, 52; 47, 61; 48, comparison_operator:==; 48, 49; 48, 50; 49, identifier:page_num; 50, unary_operator:-; 50, 51; 51, integer:1; 52, block; 52, 53; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:page_num; 56, call; 56, 57; 56, 58; 57, identifier:max; 58, argument_list; 58, 59; 58, 60; 59, identifier:pages_total; 60, integer:1; 61, elif_clause; 61, 62; 61, 65; 62, comparison_operator:<; 62, 63; 62, 64; 63, identifier:page_num; 64, integer:1; 65, block; 65, 66; 66, raise_statement; 66, 67; 67, call; 67, 68; 67, 69; 68, identifier:ValueError; 69, argument_list; 69, 70; 70, binary_operator:%; 70, 71; 70, 72; 71, string:'Invalid page number: %d'; 72, identifier:page_num; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:offset; 76, binary_operator:*; 76, 77; 76, 81; 77, parenthesized_expression; 77, 78; 78, binary_operator:-; 78, 79; 78, 80; 79, identifier:page_num; 80, integer:1; 81, identifier:page_size; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:query; 85, string:'SELECT * FROM $table'; 86, if_statement; 86, 87; 86, 88; 87, identifier:conditions; 88, block; 88, 89; 89, expression_statement; 89, 90; 90, augmented_assignment:+=; 90, 91; 90, 92; 91, identifier:query; 92, binary_operator:+; 92, 93; 92, 94; 93, string:' WHERE '; 94, identifier:conditions; 95, expression_statement; 95, 96; 96, augmented_assignment:+=; 96, 97; 96, 98; 97, identifier:query; 98, binary_operator:%; 98, 99; 98, 100; 99, string:' ORDER BY %s'; 100, identifier:order_by; 101, expression_statement; 101, 102; 102, augmented_assignment:+=; 102, 103; 102, 104; 103, identifier:query; 104, binary_operator:%; 104, 105; 104, 106; 105, string:' LIMIT %d, %d'; 106, tuple; 106, 107; 106, 108; 107, identifier:offset; 108, identifier:page_size; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:query; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:self; 115, identifier:_substitute; 116, argument_list; 116, 117; 116, 118; 117, identifier:query; 118, identifier:model_class; 119, return_statement; 119, 120; 120, call; 120, 121; 120, 122; 121, identifier:Page; 122, argument_list; 122, 123; 122, 139; 122, 142; 122, 145; 122, 148; 123, keyword_argument; 123, 124; 123, 125; 124, identifier:objects; 125, conditional_expression:if; 125, 126; 125, 137; 125, 138; 126, call; 126, 127; 126, 128; 127, identifier:list; 128, argument_list; 128, 129; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:self; 132, identifier:select; 133, argument_list; 133, 134; 133, 135; 133, 136; 134, identifier:query; 135, identifier:model_class; 136, identifier:settings; 137, identifier:count; 138, list:[]; 139, keyword_argument; 139, 140; 139, 141; 140, identifier:number_of_objects; 141, identifier:count; 142, keyword_argument; 142, 143; 142, 144; 143, identifier:pages_total; 144, identifier:pages_total; 145, keyword_argument; 145, 146; 145, 147; 146, identifier:number; 147, identifier:page_num; 148, keyword_argument; 148, 149; 148, 150; 149, identifier:page_size; 150, identifier:page_size | def paginate(self, model_class, order_by, page_num=1, page_size=100, conditions=None, settings=None):
'''
Selects records and returns a single page of model instances.
- `model_class`: the model class matching the query's table,
or `None` for getting back instances of an ad-hoc model.
- `order_by`: columns to use for sorting the query (contents of the ORDER BY clause).
- `page_num`: the page number (1-based), or -1 to get the last page.
- `page_size`: number of records to return per page.
- `conditions`: optional SQL conditions (contents of the WHERE clause).
- `settings`: query settings to send as HTTP GET parameters
The result is a namedtuple containing `objects` (list), `number_of_objects`,
`pages_total`, `number` (of the current page), and `page_size`.
'''
count = self.count(model_class, conditions)
pages_total = int(ceil(count / float(page_size)))
if page_num == -1:
page_num = max(pages_total, 1)
elif page_num < 1:
raise ValueError('Invalid page number: %d' % page_num)
offset = (page_num - 1) * page_size
query = 'SELECT * FROM $table'
if conditions:
query += ' WHERE ' + conditions
query += ' ORDER BY %s' % order_by
query += ' LIMIT %d, %d' % (offset, page_size)
query = self._substitute(query, model_class)
return Page(
objects=list(self.select(query, model_class, settings)) if count else [],
number_of_objects=count,
pages_total=pages_total,
number=page_num,
page_size=page_size
) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:compute_memory_contents_under_schedule; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:schedule; 6, block; 6, 7; 6, 15; 6, 21; 6, 25; 6, 117; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:out_degree; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:_compute_initial_out_degree; 14, argument_list; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:curr_memory_contents; 18, call; 18, 19; 18, 20; 19, identifier:set; 20, argument_list; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:memory_contents_for_each_operation; 24, list:[]; 25, for_statement; 25, 26; 25, 27; 25, 28; 26, identifier:operation_id; 27, identifier:schedule; 28, block; 28, 29; 28, 39; 28, 55; 28, 65; 28, 88; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:operation_name; 32, attribute; 32, 33; 32, 38; 33, subscript; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:_operations; 37, identifier:operation_id; 38, identifier:name; 39, for_statement; 39, 40; 39, 41; 39, 47; 40, identifier:output_name; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:get_operation_output_names; 45, argument_list; 45, 46; 46, identifier:operation_name; 47, block; 47, 48; 48, expression_statement; 48, 49; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:curr_memory_contents; 52, identifier:add; 53, argument_list; 53, 54; 54, identifier:output_name; 55, expression_statement; 55, 56; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:memory_contents_for_each_operation; 59, identifier:append; 60, argument_list; 60, 61; 61, call; 61, 62; 61, 63; 62, identifier:frozenset; 63, argument_list; 63, 64; 64, identifier:curr_memory_contents; 65, for_statement; 65, 66; 65, 67; 65, 73; 66, identifier:output_name; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:get_operation_output_names; 71, argument_list; 71, 72; 72, identifier:operation_name; 73, block; 73, 74; 74, if_statement; 74, 75; 74, 80; 75, comparison_operator:==; 75, 76; 75, 79; 76, subscript; 76, 77; 76, 78; 77, identifier:out_degree; 78, identifier:output_name; 79, integer:0; 80, block; 80, 81; 81, expression_statement; 81, 82; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:curr_memory_contents; 85, identifier:remove; 86, argument_list; 86, 87; 87, identifier:output_name; 88, for_statement; 88, 89; 88, 90; 88, 96; 89, identifier:input_name; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:self; 93, identifier:get_operation_input_names; 94, argument_list; 94, 95; 95, identifier:operation_name; 96, block; 96, 97; 96, 103; 97, expression_statement; 97, 98; 98, augmented_assignment:-=; 98, 99; 98, 102; 99, subscript; 99, 100; 99, 101; 100, identifier:out_degree; 101, identifier:input_name; 102, integer:1; 103, if_statement; 103, 104; 103, 109; 104, comparison_operator:==; 104, 105; 104, 108; 105, subscript; 105, 106; 105, 107; 106, identifier:out_degree; 107, identifier:input_name; 108, integer:0; 109, block; 109, 110; 110, expression_statement; 110, 111; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:curr_memory_contents; 114, identifier:remove; 115, argument_list; 115, 116; 116, identifier:input_name; 117, return_statement; 117, 118; 118, identifier:memory_contents_for_each_operation | def compute_memory_contents_under_schedule(self, schedule):
out_degree = self._compute_initial_out_degree()
curr_memory_contents = set()
memory_contents_for_each_operation = []
for operation_id in schedule:
operation_name = self._operations[operation_id].name
for output_name in self.get_operation_output_names(operation_name):
curr_memory_contents.add(output_name)
memory_contents_for_each_operation.append(frozenset(curr_memory_contents))
for output_name in self.get_operation_output_names(operation_name):
if out_degree[output_name] == 0:
curr_memory_contents.remove(output_name)
for input_name in self.get_operation_input_names(operation_name):
out_degree[input_name] -= 1
if out_degree[input_name] == 0:
curr_memory_contents.remove(input_name)
return memory_contents_for_each_operation |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 16; 1, 18; 2, function_name:sort; 3, parameters; 3, 4; 3, 5; 3, 9; 3, 14; 4, identifier:self; 5, typed_parameter; 5, 6; 5, 7; 6, identifier:by; 7, type; 7, 8; 8, identifier:str; 9, typed_default_parameter; 9, 10; 9, 11; 9, 13; 10, identifier:out; 11, type; 11, 12; 12, identifier:object; 13, string:''; 14, dictionary_splat_pattern; 14, 15; 15, identifier:kwargs; 16, type; 16, 17; 17, string:'SASdata'; 18, block; 18, 19; 18, 23; 18, 27; 18, 117; 18, 128; 18, 147; 18, 153; 18, 157; 18, 161; 18, 177; 18, 185; 18, 192; 18, 252; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:outstr; 22, string:''; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:options; 26, string:''; 27, if_statement; 27, 28; 27, 29; 28, identifier:out; 29, block; 29, 30; 30, if_statement; 30, 31; 30, 36; 30, 91; 31, call; 31, 32; 31, 33; 32, identifier:isinstance; 33, argument_list; 33, 34; 33, 35; 34, identifier:out; 35, identifier:str; 36, block; 36, 37; 36, 46; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:fn; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:out; 43, identifier:partition; 44, argument_list; 44, 45; 45, string:'.'; 46, if_statement; 46, 47; 46, 52; 46, 73; 47, comparison_operator:==; 47, 48; 47, 51; 48, subscript; 48, 49; 48, 50; 49, identifier:fn; 50, integer:1; 51, string:'.'; 52, block; 52, 53; 52, 59; 52, 65; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:libref; 56, subscript; 56, 57; 56, 58; 57, identifier:fn; 58, integer:0; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:table; 62, subscript; 62, 63; 62, 64; 63, identifier:fn; 64, integer:2; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:outstr; 68, binary_operator:%; 68, 69; 68, 70; 69, string:"out=%s.%s"; 70, tuple; 70, 71; 70, 72; 71, identifier:libref; 72, identifier:table; 73, else_clause; 73, 74; 74, block; 74, 75; 74, 79; 74, 85; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:libref; 78, string:''; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:table; 82, subscript; 82, 83; 82, 84; 83, identifier:fn; 84, integer:0; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:outstr; 88, binary_operator:+; 88, 89; 88, 90; 89, string:"out="; 90, identifier:table; 91, else_clause; 91, 92; 92, block; 92, 93; 92, 99; 92, 105; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:libref; 96, attribute; 96, 97; 96, 98; 97, identifier:out; 98, identifier:libref; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:table; 102, attribute; 102, 103; 102, 104; 103, identifier:out; 104, identifier:table; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:outstr; 108, binary_operator:%; 108, 109; 108, 110; 109, string:"out=%s.%s"; 110, tuple; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:out; 113, identifier:libref; 114, attribute; 114, 115; 114, 116; 115, identifier:out; 116, identifier:table; 117, if_statement; 117, 118; 117, 121; 118, comparison_operator:in; 118, 119; 118, 120; 119, string:'options'; 120, identifier:kwargs; 121, block; 121, 122; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:options; 125, subscript; 125, 126; 125, 127; 126, identifier:kwargs; 127, string:'options'; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:code; 131, binary_operator:%; 131, 132; 131, 133; 132, string:"proc sort data=%s.%s%s %s %s ;\n"; 133, tuple; 133, 134; 133, 137; 133, 140; 133, 145; 133, 146; 134, attribute; 134, 135; 134, 136; 135, identifier:self; 136, identifier:libref; 137, attribute; 137, 138; 137, 139; 138, identifier:self; 139, identifier:table; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:self; 143, identifier:_dsopts; 144, argument_list; 145, identifier:outstr; 146, identifier:options; 147, expression_statement; 147, 148; 148, augmented_assignment:+=; 148, 149; 148, 150; 149, identifier:code; 150, binary_operator:%; 150, 151; 150, 152; 151, string:"by %s;"; 152, identifier:by; 153, expression_statement; 153, 154; 154, augmented_assignment:+=; 154, 155; 154, 156; 155, identifier:code; 156, string:"run\n;"; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:runcode; 160, True; 161, if_statement; 161, 162; 161, 167; 162, attribute; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:self; 165, identifier:sas; 166, identifier:nosub; 167, block; 167, 168; 167, 173; 168, expression_statement; 168, 169; 169, call; 169, 170; 169, 171; 170, identifier:print; 171, argument_list; 171, 172; 172, identifier:code; 173, expression_statement; 173, 174; 174, assignment; 174, 175; 174, 176; 175, identifier:runcode; 176, False; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 180; 179, identifier:ll; 180, call; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:self; 183, identifier:_is_valid; 184, argument_list; 185, if_statement; 185, 186; 185, 187; 186, identifier:ll; 187, block; 187, 188; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 191; 190, identifier:runcode; 191, False; 192, if_statement; 192, 193; 192, 194; 193, identifier:runcode; 194, block; 194, 195; 194, 207; 194, 211; 194, 236; 195, expression_statement; 195, 196; 196, assignment; 196, 197; 196, 198; 197, identifier:ll; 198, call; 198, 199; 198, 204; 199, attribute; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:self; 202, identifier:sas; 203, identifier:submit; 204, argument_list; 204, 205; 204, 206; 205, identifier:code; 206, string:"text"; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 210; 209, identifier:elog; 210, list:[]; 211, for_statement; 211, 212; 211, 213; 211, 220; 212, identifier:line; 213, call; 213, 214; 213, 219; 214, attribute; 214, 215; 214, 218; 215, subscript; 215, 216; 215, 217; 216, identifier:ll; 217, string:'LOG'; 218, identifier:splitlines; 219, argument_list; 220, block; 220, 221; 221, if_statement; 221, 222; 221, 228; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:line; 225, identifier:startswith; 226, argument_list; 226, 227; 227, string:'ERROR'; 228, block; 228, 229; 229, expression_statement; 229, 230; 230, call; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:elog; 233, identifier:append; 234, argument_list; 234, 235; 235, identifier:line; 236, if_statement; 236, 237; 236, 241; 237, call; 237, 238; 237, 239; 238, identifier:len; 239, argument_list; 239, 240; 240, identifier:elog; 241, block; 241, 242; 242, raise_statement; 242, 243; 243, call; 243, 244; 243, 245; 244, identifier:RuntimeError; 245, argument_list; 245, 246; 246, call; 246, 247; 246, 250; 247, attribute; 247, 248; 247, 249; 248, string:"\n"; 249, identifier:join; 250, argument_list; 250, 251; 251, identifier:elog; 252, if_statement; 252, 253; 252, 254; 252, 280; 253, identifier:out; 254, block; 254, 255; 255, if_statement; 255, 256; 255, 262; 255, 265; 256, not_operator; 256, 257; 257, call; 257, 258; 257, 259; 258, identifier:isinstance; 259, argument_list; 259, 260; 259, 261; 260, identifier:out; 261, identifier:str; 262, block; 262, 263; 263, return_statement; 263, 264; 264, identifier:out; 265, else_clause; 265, 266; 266, block; 266, 267; 267, return_statement; 267, 268; 268, call; 268, 269; 268, 274; 269, attribute; 269, 270; 269, 273; 270, attribute; 270, 271; 270, 272; 271, identifier:self; 272, identifier:sas; 273, identifier:sasdata; 274, argument_list; 274, 275; 274, 276; 274, 277; 275, identifier:table; 276, identifier:libref; 277, attribute; 277, 278; 277, 279; 278, identifier:self; 279, identifier:results; 280, else_clause; 280, 281; 281, block; 281, 282; 282, return_statement; 282, 283; 283, identifier:self | def sort(self, by: str, out: object = '', **kwargs) -> 'SASdata':
outstr = ''
options = ''
if out:
if isinstance(out, str):
fn = out.partition('.')
if fn[1] == '.':
libref = fn[0]
table = fn[2]
outstr = "out=%s.%s" % (libref, table)
else:
libref = ''
table = fn[0]
outstr = "out=" + table
else:
libref = out.libref
table = out.table
outstr = "out=%s.%s" % (out.libref, out.table)
if 'options' in kwargs:
options = kwargs['options']
code = "proc sort data=%s.%s%s %s %s ;\n" % (self.libref, self.table, self._dsopts(), outstr, options)
code += "by %s;" % by
code += "run\n;"
runcode = True
if self.sas.nosub:
print(code)
runcode = False
ll = self._is_valid()
if ll:
runcode = False
if runcode:
ll = self.sas.submit(code, "text")
elog = []
for line in ll['LOG'].splitlines():
if line.startswith('ERROR'):
elog.append(line)
if len(elog):
raise RuntimeError("\n".join(elog))
if out:
if not isinstance(out, str):
return out
else:
return self.sas.sasdata(table, libref, self.results)
else:
return self |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 30; 2, function_name:find_items; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 3, 24; 3, 27; 4, identifier:self; 5, identifier:q; 6, default_parameter; 6, 7; 6, 8; 7, identifier:shape; 8, identifier:ID_ONLY; 9, default_parameter; 9, 10; 9, 11; 10, identifier:depth; 11, identifier:SHALLOW; 12, default_parameter; 12, 13; 12, 14; 13, identifier:additional_fields; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:order_fields; 17, None; 18, default_parameter; 18, 19; 18, 20; 19, identifier:calendar_view; 20, None; 21, default_parameter; 21, 22; 21, 23; 22, identifier:page_size; 23, None; 24, default_parameter; 24, 25; 24, 26; 25, identifier:max_items; 26, None; 27, default_parameter; 27, 28; 27, 29; 28, identifier:offset; 29, integer:0; 30, block; 30, 31; 30, 45; 30, 59; 30, 73; 30, 111; 30, 130; 30, 194; 30, 216; 30, 271; 31, if_statement; 31, 32; 31, 35; 32, comparison_operator:not; 32, 33; 32, 34; 33, identifier:shape; 34, identifier:SHAPE_CHOICES; 35, block; 35, 36; 36, raise_statement; 36, 37; 37, call; 37, 38; 37, 39; 38, identifier:ValueError; 39, argument_list; 39, 40; 40, binary_operator:%; 40, 41; 40, 42; 41, string:"'shape' %s must be one of %s"; 42, tuple; 42, 43; 42, 44; 43, identifier:shape; 44, identifier:SHAPE_CHOICES; 45, if_statement; 45, 46; 45, 49; 46, comparison_operator:not; 46, 47; 46, 48; 47, identifier:depth; 48, identifier:ITEM_TRAVERSAL_CHOICES; 49, block; 49, 50; 50, raise_statement; 50, 51; 51, call; 51, 52; 51, 53; 52, identifier:ValueError; 53, argument_list; 53, 54; 54, binary_operator:%; 54, 55; 54, 56; 55, string:"'depth' %s must be one of %s"; 56, tuple; 56, 57; 56, 58; 57, identifier:depth; 58, identifier:ITEM_TRAVERSAL_CHOICES; 59, if_statement; 59, 60; 59, 64; 60, not_operator; 60, 61; 61, attribute; 61, 62; 61, 63; 62, identifier:self; 63, identifier:folders; 64, block; 64, 65; 64, 72; 65, expression_statement; 65, 66; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:log; 69, identifier:debug; 70, argument_list; 70, 71; 71, string:'Folder list is empty'; 72, return_statement; 73, if_statement; 73, 74; 73, 75; 74, identifier:additional_fields; 75, block; 75, 76; 75, 89; 76, for_statement; 76, 77; 76, 78; 76, 79; 77, identifier:f; 78, identifier:additional_fields; 79, block; 79, 80; 80, expression_statement; 80, 81; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:self; 84, identifier:validate_item_field; 85, argument_list; 85, 86; 86, keyword_argument; 86, 87; 86, 88; 87, identifier:field; 88, identifier:f; 89, for_statement; 89, 90; 89, 91; 89, 92; 90, identifier:f; 91, identifier:additional_fields; 92, block; 92, 93; 93, if_statement; 93, 94; 93, 99; 94, attribute; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:f; 97, identifier:field; 98, identifier:is_complex; 99, block; 99, 100; 100, raise_statement; 100, 101; 101, call; 101, 102; 101, 103; 102, identifier:ValueError; 103, argument_list; 103, 104; 104, binary_operator:%; 104, 105; 104, 106; 105, string:"find_items() does not support field '%s'. Use fetch() instead"; 106, attribute; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:f; 109, identifier:field; 110, identifier:name; 111, if_statement; 111, 112; 111, 122; 112, boolean_operator:and; 112, 113; 112, 116; 113, comparison_operator:is; 113, 114; 113, 115; 114, identifier:calendar_view; 115, None; 116, not_operator; 116, 117; 117, call; 117, 118; 117, 119; 118, identifier:isinstance; 119, argument_list; 119, 120; 119, 121; 120, identifier:calendar_view; 121, identifier:CalendarView; 122, block; 122, 123; 123, raise_statement; 123, 124; 124, call; 124, 125; 124, 126; 125, identifier:ValueError; 126, argument_list; 126, 127; 127, binary_operator:%; 127, 128; 127, 129; 128, string:"'calendar_view' %s must be a CalendarView instance"; 129, identifier:calendar_view; 130, if_statement; 130, 131; 130, 136; 130, 145; 130, 171; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:q; 134, identifier:is_empty; 135, argument_list; 136, block; 136, 137; 136, 141; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:restriction; 140, None; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:query_string; 144, None; 145, elif_clause; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:q; 148, identifier:query_string; 149, block; 149, 150; 149, 154; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 153; 152, identifier:restriction; 153, None; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 157; 156, identifier:query_string; 157, call; 157, 158; 157, 159; 158, identifier:Restriction; 159, argument_list; 159, 160; 159, 161; 159, 166; 160, identifier:q; 161, keyword_argument; 161, 162; 161, 163; 162, identifier:folders; 163, attribute; 163, 164; 163, 165; 164, identifier:self; 165, identifier:folders; 166, keyword_argument; 166, 167; 166, 168; 167, identifier:applies_to; 168, attribute; 168, 169; 168, 170; 169, identifier:Restriction; 170, identifier:ITEMS; 171, else_clause; 171, 172; 172, block; 172, 173; 172, 190; 173, expression_statement; 173, 174; 174, assignment; 174, 175; 174, 176; 175, identifier:restriction; 176, call; 176, 177; 176, 178; 177, identifier:Restriction; 178, argument_list; 178, 179; 178, 180; 178, 185; 179, identifier:q; 180, keyword_argument; 180, 181; 180, 182; 181, identifier:folders; 182, attribute; 182, 183; 182, 184; 183, identifier:self; 184, identifier:folders; 185, keyword_argument; 185, 186; 185, 187; 186, identifier:applies_to; 187, attribute; 187, 188; 187, 189; 188, identifier:Restriction; 189, identifier:ITEMS; 190, expression_statement; 190, 191; 191, assignment; 191, 192; 191, 193; 192, identifier:query_string; 193, None; 194, expression_statement; 194, 195; 195, call; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:log; 198, identifier:debug; 199, argument_list; 199, 200; 199, 201; 199, 204; 199, 207; 199, 208; 199, 209; 199, 210; 200, string:'Finding %s items in folders %s (shape: %s, depth: %s, additional_fields: %s, restriction: %s)'; 201, attribute; 201, 202; 201, 203; 202, identifier:self; 203, identifier:folders; 204, attribute; 204, 205; 204, 206; 205, identifier:self; 206, identifier:account; 207, identifier:shape; 208, identifier:depth; 209, identifier:additional_fields; 210, conditional_expression:if; 210, 211; 210, 214; 210, 215; 211, attribute; 211, 212; 211, 213; 212, identifier:restriction; 213, identifier:q; 214, identifier:restriction; 215, None; 216, expression_statement; 216, 217; 217, assignment; 217, 218; 217, 219; 218, identifier:items; 219, call; 219, 220; 219, 238; 220, attribute; 220, 221; 220, 237; 221, call; 221, 222; 221, 223; 222, identifier:FindItem; 223, argument_list; 223, 224; 223, 229; 223, 234; 224, keyword_argument; 224, 225; 224, 226; 225, identifier:account; 226, attribute; 226, 227; 226, 228; 227, identifier:self; 228, identifier:account; 229, keyword_argument; 229, 230; 229, 231; 230, identifier:folders; 231, attribute; 231, 232; 231, 233; 232, identifier:self; 233, identifier:folders; 234, keyword_argument; 234, 235; 234, 236; 235, identifier:chunk_size; 236, identifier:page_size; 237, identifier:call; 238, argument_list; 238, 239; 238, 242; 238, 245; 238, 248; 238, 251; 238, 254; 238, 257; 238, 260; 238, 268; 239, keyword_argument; 239, 240; 239, 241; 240, identifier:additional_fields; 241, identifier:additional_fields; 242, keyword_argument; 242, 243; 242, 244; 243, identifier:restriction; 244, identifier:restriction; 245, keyword_argument; 245, 246; 245, 247; 246, identifier:order_fields; 247, identifier:order_fields; 248, keyword_argument; 248, 249; 248, 250; 249, identifier:shape; 250, identifier:shape; 251, keyword_argument; 251, 252; 251, 253; 252, identifier:query_string; 253, identifier:query_string; 254, keyword_argument; 254, 255; 254, 256; 255, identifier:depth; 256, identifier:depth; 257, keyword_argument; 257, 258; 257, 259; 258, identifier:calendar_view; 259, identifier:calendar_view; 260, keyword_argument; 260, 261; 260, 262; 261, identifier:max_items; 262, conditional_expression:if; 262, 263; 262, 266; 262, 267; 263, attribute; 263, 264; 263, 265; 264, identifier:calendar_view; 265, identifier:max_items; 266, identifier:calendar_view; 267, identifier:max_items; 268, keyword_argument; 268, 269; 268, 270; 269, identifier:offset; 270, identifier:offset; 271, if_statement; 271, 272; 271, 279; 271, 299; 272, boolean_operator:and; 272, 273; 272, 276; 273, comparison_operator:==; 273, 274; 273, 275; 274, identifier:shape; 275, identifier:ID_ONLY; 276, comparison_operator:is; 276, 277; 276, 278; 277, identifier:additional_fields; 278, None; 279, block; 279, 280; 280, for_statement; 280, 281; 280, 282; 280, 283; 281, identifier:i; 282, identifier:items; 283, block; 283, 284; 284, expression_statement; 284, 285; 285, yield; 285, 286; 286, conditional_expression:if; 286, 287; 286, 288; 286, 293; 287, identifier:i; 288, call; 288, 289; 288, 290; 289, identifier:isinstance; 290, argument_list; 290, 291; 290, 292; 291, identifier:i; 292, identifier:Exception; 293, call; 293, 294; 293, 297; 294, attribute; 294, 295; 294, 296; 295, identifier:Item; 296, identifier:id_from_xml; 297, argument_list; 297, 298; 298, identifier:i; 299, else_clause; 299, 300; 300, block; 300, 301; 301, for_statement; 301, 302; 301, 303; 301, 304; 302, identifier:i; 303, identifier:items; 304, block; 304, 305; 305, if_statement; 305, 306; 305, 311; 305, 315; 306, call; 306, 307; 306, 308; 307, identifier:isinstance; 308, argument_list; 308, 309; 308, 310; 309, identifier:i; 310, identifier:Exception; 311, block; 311, 312; 312, expression_statement; 312, 313; 313, yield; 313, 314; 314, identifier:i; 315, else_clause; 315, 316; 316, block; 316, 317; 317, expression_statement; 317, 318; 318, yield; 318, 319; 319, call; 319, 320; 319, 330; 320, attribute; 320, 321; 320, 329; 321, call; 321, 322; 321, 325; 322, attribute; 322, 323; 322, 324; 323, identifier:Folder; 324, identifier:item_model_from_tag; 325, argument_list; 325, 326; 326, attribute; 326, 327; 326, 328; 327, identifier:i; 328, identifier:tag; 329, identifier:from_xml; 330, argument_list; 330, 331; 330, 334; 331, keyword_argument; 331, 332; 331, 333; 332, identifier:elem; 333, identifier:i; 334, keyword_argument; 334, 335; 334, 336; 335, identifier:account; 336, attribute; 336, 337; 336, 338; 337, identifier:self; 338, identifier:account | def find_items(self, q, shape=ID_ONLY, depth=SHALLOW, additional_fields=None, order_fields=None,
calendar_view=None, page_size=None, max_items=None, offset=0):
if shape not in SHAPE_CHOICES:
raise ValueError("'shape' %s must be one of %s" % (shape, SHAPE_CHOICES))
if depth not in ITEM_TRAVERSAL_CHOICES:
raise ValueError("'depth' %s must be one of %s" % (depth, ITEM_TRAVERSAL_CHOICES))
if not self.folders:
log.debug('Folder list is empty')
return
if additional_fields:
for f in additional_fields:
self.validate_item_field(field=f)
for f in additional_fields:
if f.field.is_complex:
raise ValueError("find_items() does not support field '%s'. Use fetch() instead" % f.field.name)
if calendar_view is not None and not isinstance(calendar_view, CalendarView):
raise ValueError("'calendar_view' %s must be a CalendarView instance" % calendar_view)
if q.is_empty():
restriction = None
query_string = None
elif q.query_string:
restriction = None
query_string = Restriction(q, folders=self.folders, applies_to=Restriction.ITEMS)
else:
restriction = Restriction(q, folders=self.folders, applies_to=Restriction.ITEMS)
query_string = None
log.debug(
'Finding %s items in folders %s (shape: %s, depth: %s, additional_fields: %s, restriction: %s)',
self.folders,
self.account,
shape,
depth,
additional_fields,
restriction.q if restriction else None,
)
items = FindItem(account=self.account, folders=self.folders, chunk_size=page_size).call(
additional_fields=additional_fields,
restriction=restriction,
order_fields=order_fields,
shape=shape,
query_string=query_string,
depth=depth,
calendar_view=calendar_view,
max_items=calendar_view.max_items if calendar_view else max_items,
offset=offset,
)
if shape == ID_ONLY and additional_fields is None:
for i in items:
yield i if isinstance(i, Exception) else Item.id_from_xml(i)
else:
for i in items:
if isinstance(i, Exception):
yield i
else:
yield Folder.item_model_from_tag(i.tag).from_xml(elem=i, account=self.account) |
Subsets and Splits