nodes
stringlengths
501
22.4k
edges
stringlengths
138
5.07k
code
stringlengths
108
19.3k
0, module; 1, function_definition; 2, function_name:intersect_range_array; 3, parameters; 4, block; 5, identifier:bed1; 6, identifier:beds2; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, if_statement; 11, expression_statement; 12, for_statement; 13, if_statement; 14, return_statement; 15, identifier:payload; 16, None; 17, identifier:is_sorted; 18, False; 19, comment:""" Does not do a merge if the payload has been set :param bed1: :param bed2: :param payload: payload=1 return the payload of bed1 on each of the intersect set, payload=2 return the payload of bed2 on each of the union set, payload=3 return the payload of bed1 and bed2 on each of the union set :param is_sorted: :type bed1: GenomicRange :type bed2: GenomicRange :type payload: int :type is_sorted: bool """; 20, not_operator; 21, block; 22, assignment; 23, identifier:bed2; 24, identifier:beds2; 25, block; 26, identifier:payload; 27, block; 28, call; 29, identifier:is_sorted; 30, expression_statement; 31, identifier:output; 32, list; 33, expression_statement; 34, comment:#print str(cval)+" "+bed1.get_range_string()+" "+bed2.get_range_string(); 35, if_statement; 36, return_statement; 37, identifier:merge_ranges; 38, argument_list; 39, assignment; 40, assignment; 41, comparison_operator:cval == -1; 42, block; 43, elif_clause; 44, elif_clause; 45, call; 46, identifier:output; 47, identifier:beds2; 48, call; 49, identifier:cval; 50, call; 51, identifier:cval; 52, unary_operator; 53, continue_statement; 54, comparison_operator:cval == 0; 55, block; 56, comparison_operator:cval == 1; 57, block; 58, identifier:sort_ranges; 59, argument_list; 60, identifier:sort_ranges; 61, argument_list; 62, attribute; 63, argument_list; 64, integer:1; 65, identifier:cval; 66, integer:0; 67, expression_statement; 68, if_statement; 69, if_statement; 70, identifier:cval; 71, integer:1; 72, break_statement; 73, identifier:output; 74, identifier:beds2; 75, identifier:bed2; 76, identifier:cmp; 77, identifier:bed1; 78, call; 79, comparison_operator:payload==1; 80, block; 81, comparison_operator:payload==2; 82, block; 83, attribute; 84, argument_list; 85, identifier:payload; 86, integer:1; 87, expression_statement; 88, identifier:payload; 89, integer:2; 90, expression_statement; 91, identifier:output; 92, identifier:append; 93, call; 94, call; 95, call; 96, attribute; 97, argument_list; 98, attribute; 99, argument_list; 100, attribute; 101, argument_list; 102, identifier:bed1; 103, identifier:intersect; 104, identifier:bed2; 105, subscript; 106, identifier:set_payload; 107, attribute; 108, subscript; 109, identifier:set_payload; 110, attribute; 111, identifier:output; 112, unary_operator; 113, identifier:bed1; 114, identifier:payload; 115, identifier:output; 116, unary_operator; 117, identifier:bed2; 118, identifier:payload; 119, integer:1; 120, integer:1
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 7, 15; 7, 16; 8, 17; 8, 18; 9, 19; 10, 20; 10, 21; 11, 22; 12, 23; 12, 24; 12, 25; 13, 26; 13, 27; 14, 28; 20, 29; 21, 30; 22, 31; 22, 32; 25, 33; 25, 34; 25, 35; 27, 36; 28, 37; 28, 38; 30, 39; 33, 40; 35, 41; 35, 42; 35, 43; 35, 44; 36, 45; 38, 46; 39, 47; 39, 48; 40, 49; 40, 50; 41, 51; 41, 52; 42, 53; 43, 54; 43, 55; 44, 56; 44, 57; 45, 58; 45, 59; 48, 60; 48, 61; 50, 62; 50, 63; 52, 64; 54, 65; 54, 66; 55, 67; 55, 68; 55, 69; 56, 70; 56, 71; 57, 72; 59, 73; 61, 74; 62, 75; 62, 76; 63, 77; 67, 78; 68, 79; 68, 80; 69, 81; 69, 82; 78, 83; 78, 84; 79, 85; 79, 86; 80, 87; 81, 88; 81, 89; 82, 90; 83, 91; 83, 92; 84, 93; 87, 94; 90, 95; 93, 96; 93, 97; 94, 98; 94, 99; 95, 100; 95, 101; 96, 102; 96, 103; 97, 104; 98, 105; 98, 106; 99, 107; 100, 108; 100, 109; 101, 110; 105, 111; 105, 112; 107, 113; 107, 114; 108, 115; 108, 116; 110, 117; 110, 118; 112, 119; 116, 120
def intersect_range_array(bed1,beds2,payload=None,is_sorted=False): """ Does not do a merge if the payload has been set :param bed1: :param bed2: :param payload: payload=1 return the payload of bed1 on each of the intersect set, payload=2 return the payload of bed2 on each of the union set, payload=3 return the payload of bed1 and bed2 on each of the union set :param is_sorted: :type bed1: GenomicRange :type bed2: GenomicRange :type payload: int :type is_sorted: bool """ if not is_sorted: beds2 = sort_ranges(beds2) output = [] for bed2 in beds2: cval = bed2.cmp(bed1) #print str(cval)+" "+bed1.get_range_string()+" "+bed2.get_range_string() if cval == -1: continue elif cval == 0: output.append(bed1.intersect(bed2)) if payload==1: output[-1].set_payload(bed1.payload) if payload==2: output[-1].set_payload(bed2.payload) elif cval == 1: break if payload: return sort_ranges(output) return merge_ranges(output)
0, module; 1, function_definition; 2, function_name:sort_genomic_ranges; 3, parameters; 4, block; 5, identifier:rngs; 6, expression_statement; 7, return_statement; 8, comment:"""sort multiple ranges"""; 9, call; 10, identifier:sorted; 11, argument_list; 12, identifier:rngs; 13, keyword_argument; 14, identifier:key; 15, lambda; 16, lambda_parameters; 17, tuple; 18, identifier:x; 19, attribute; 20, attribute; 21, attribute; 22, identifier:x; 23, identifier:chr; 24, identifier:x; 25, identifier:start; 26, identifier:x; 27, identifier:end
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 6, 8; 7, 9; 9, 10; 9, 11; 11, 12; 11, 13; 13, 14; 13, 15; 15, 16; 15, 17; 16, 18; 17, 19; 17, 20; 17, 21; 19, 22; 19, 23; 20, 24; 20, 25; 21, 26; 21, 27
def sort_genomic_ranges(rngs): """sort multiple ranges""" return sorted(rngs, key=lambda x: (x.chr, x.start, x.end))
0, module; 1, function_definition; 2, function_name:topological_sort; 3, parameters; 4, block; 5, identifier:dependencies; 6, identifier:start_nodes; 7, expression_statement; 8, expression_statement; 9, function_definition; 10, function_definition; 11, function_definition; 12, while_statement; 13, expression_statement; 14, if_statement; 15, comment:""" Perform a topological sort on the dependency graph `dependencies`, starting from list `start_nodes`. """; 16, assignment; 17, function_name:edges; 18, parameters; 19, block; 20, function_name:in_degree; 21, parameters; 22, block; 23, function_name:remove_incoming; 24, parameters; 25, block; 26, identifier:start_nodes; 27, block; 28, assignment; 29, identifier:leftover_nodes; 30, block; 31, else_clause; 32, identifier:retval; 33, list; 34, identifier:node; 35, return_statement; 36, identifier:node; 37, return_statement; 38, identifier:node; 39, expression_statement; 40, expression_statement; 41, expression_statement; 42, for_statement; 43, identifier:leftover_nodes; 44, list_comprehension; 45, raise_statement; 46, block; 47, subscript; 48, subscript; 49, assignment; 50, assignment; 51, call; 52, identifier:child; 53, call; 54, block; 55, identifier:node; 56, for_in_clause; 57, if_clause; 58, call; 59, return_statement; 60, subscript; 61, integer:1; 62, subscript; 63, integer:0; 64, subscript; 65, binary_operator:in_degree(node) - 1; 66, identifier:node; 67, call; 68, attribute; 69, argument_list; 70, identifier:edges; 71, argument_list; 72, expression_statement; 73, if_statement; 74, identifier:node; 75, call; 76, comparison_operator:in_degree(node) > 0; 77, identifier:CyclicDependency; 78, argument_list; 79, identifier:retval; 80, identifier:dependencies; 81, identifier:node; 82, identifier:dependencies; 83, identifier:node; 84, subscript; 85, integer:0; 86, call; 87, integer:1; 88, attribute; 89, argument_list; 90, identifier:retval; 91, identifier:append; 92, identifier:node; 93, identifier:node; 94, call; 95, not_operator; 96, block; 97, identifier:list; 98, argument_list; 99, call; 100, integer:0; 101, identifier:leftover_nodes; 102, identifier:dependencies; 103, identifier:node; 104, identifier:in_degree; 105, argument_list; 106, identifier:start_nodes; 107, identifier:pop; 108, identifier:remove_incoming; 109, argument_list; 110, call; 111, expression_statement; 112, call; 113, identifier:in_degree; 114, argument_list; 115, identifier:node; 116, identifier:child; 117, identifier:in_degree; 118, argument_list; 119, call; 120, attribute; 121, argument_list; 122, identifier:node; 123, identifier:child; 124, attribute; 125, argument_list; 126, identifier:dependencies; 127, identifier:keys; 128, identifier:start_nodes; 129, identifier:append; 130, identifier:child
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 7, 15; 8, 16; 9, 17; 9, 18; 9, 19; 10, 20; 10, 21; 10, 22; 11, 23; 11, 24; 11, 25; 12, 26; 12, 27; 13, 28; 14, 29; 14, 30; 14, 31; 16, 32; 16, 33; 18, 34; 19, 35; 21, 36; 22, 37; 24, 38; 25, 39; 27, 40; 27, 41; 27, 42; 28, 43; 28, 44; 30, 45; 31, 46; 35, 47; 37, 48; 39, 49; 40, 50; 41, 51; 42, 52; 42, 53; 42, 54; 44, 55; 44, 56; 44, 57; 45, 58; 46, 59; 47, 60; 47, 61; 48, 62; 48, 63; 49, 64; 49, 65; 50, 66; 50, 67; 51, 68; 51, 69; 53, 70; 53, 71; 54, 72; 54, 73; 56, 74; 56, 75; 57, 76; 58, 77; 58, 78; 59, 79; 60, 80; 60, 81; 62, 82; 62, 83; 64, 84; 64, 85; 65, 86; 65, 87; 67, 88; 67, 89; 68, 90; 68, 91; 69, 92; 71, 93; 72, 94; 73, 95; 73, 96; 75, 97; 75, 98; 76, 99; 76, 100; 78, 101; 84, 102; 84, 103; 86, 104; 86, 105; 88, 106; 88, 107; 94, 108; 94, 109; 95, 110; 96, 111; 98, 112; 99, 113; 99, 114; 105, 115; 109, 116; 110, 117; 110, 118; 111, 119; 112, 120; 112, 121; 114, 122; 118, 123; 119, 124; 119, 125; 120, 126; 120, 127; 124, 128; 124, 129; 125, 130
def topological_sort(dependencies, start_nodes): """ Perform a topological sort on the dependency graph `dependencies`, starting from list `start_nodes`. """ retval = [] def edges(node): return dependencies[node][1] def in_degree(node): return dependencies[node][0] def remove_incoming(node): dependencies[node][0] = in_degree(node) - 1 while start_nodes: node = start_nodes.pop() retval.append(node) for child in edges(node): remove_incoming(child) if not in_degree(child): start_nodes.append(child) leftover_nodes = [node for node in list(dependencies.keys()) if in_degree(node) > 0] if leftover_nodes: raise CyclicDependency(leftover_nodes) else: return retval
0, module; 1, function_definition; 2, function_name:_do_parse; 3, parameters; 4, block; 5, identifier:inp; 6, identifier:fmt; 7, identifier:encoding; 8, identifier:force_types; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, if_statement; 13, comment:# make sure it's all unicode and all int/float values were parsed correctly; 14, comment:# the unicode part is here because of yaml on PY2 and also as workaround for; 15, comment:# https://github.com/DiffSK/configobj/issues/18#issuecomment-76391689; 16, return_statement; 17, comment:"""Actually parse input. Args: inp: bytes yielding file-like object fmt: format to use for parsing encoding: encoding of `inp` force_types: if `True`, integers, floats, booleans and none/null are recognized and returned as proper types instead of strings; if `False`, everything is converted to strings if `None`, backend return value is used Returns: parsed `inp` (dict or list) containing unicode values Raises: various sorts of errors raised by used libraries while parsing """; 18, assignment; 19, call; 20, comparison_operator:fmt == 'ini'; 21, block; 22, elif_clause; 23, elif_clause; 24, elif_clause; 25, elif_clause; 26, elif_clause; 27, else_clause; 28, call; 29, identifier:res; 30, dictionary; 31, identifier:_check_lib_installed; 32, argument_list; 33, identifier:fmt; 34, string; 35, expression_statement; 36, expression_statement; 37, comparison_operator:fmt == 'json'; 38, block; 39, comparison_operator:fmt == 'json5'; 40, block; 41, comparison_operator:fmt == 'toml'; 42, block; 43, comparison_operator:fmt == 'xml'; 44, block; 45, comparison_operator:fmt == 'yaml'; 46, comment:# guesses encoding by its own, there seems to be no way to pass; 47, comment:# it explicitly; 48, block; 49, block; 50, identifier:_ensure_proper_types; 51, argument_list; 52, identifier:fmt; 53, string; 54, string_content:ini; 55, assignment; 56, assignment; 57, identifier:fmt; 58, string; 59, if_statement; 60, expression_statement; 61, identifier:fmt; 62, string; 63, if_statement; 64, expression_statement; 65, identifier:fmt; 66, string; 67, if_statement; 68, if_statement; 69, expression_statement; 70, identifier:fmt; 71, string; 72, expression_statement; 73, identifier:fmt; 74, string; 75, expression_statement; 76, raise_statement; 77, comment:# unknown format; 78, identifier:res; 79, identifier:encoding; 80, identifier:force_types; 81, string_content:parse; 82, identifier:cfg; 83, call; 84, identifier:res; 85, call; 86, string_content:json; 87, attribute; 88, comment:# python 3 json only reads from unicode objects; 89, block; 90, assignment; 91, string_content:json5; 92, attribute; 93, block; 94, assignment; 95, string_content:toml; 96, not_operator; 97, block; 98, attribute; 99, comment:# python 3 toml prefers unicode objects; 100, block; 101, assignment; 102, string_content:xml; 103, assignment; 104, string_content:yaml; 105, assignment; 106, attribute; 107, argument_list; 108, attribute; 109, argument_list; 110, identifier:six; 111, identifier:PY3; 112, expression_statement; 113, identifier:res; 114, call; 115, identifier:six; 116, identifier:PY3; 117, expression_statement; 118, identifier:res; 119, call; 120, call; 121, raise_statement; 122, identifier:six; 123, identifier:PY3; 124, expression_statement; 125, identifier:res; 126, call; 127, identifier:res; 128, call; 129, identifier:res; 130, call; 131, identifier:configobj; 132, identifier:ConfigObj; 133, identifier:inp; 134, keyword_argument; 135, identifier:cfg; 136, identifier:dict; 137, assignment; 138, attribute; 139, argument_list; 140, assignment; 141, attribute; 142, argument_list; 143, identifier:_is_utf8; 144, argument_list; 145, call; 146, assignment; 147, attribute; 148, argument_list; 149, attribute; 150, argument_list; 151, attribute; 152, argument_list; 153, identifier:encoding; 154, identifier:encoding; 155, identifier:inp; 156, call; 157, identifier:json; 158, identifier:load; 159, identifier:inp; 160, keyword_argument; 161, identifier:inp; 162, call; 163, identifier:json5; 164, identifier:load; 165, identifier:inp; 166, keyword_argument; 167, identifier:encoding; 168, identifier:AnyMarkupError; 169, argument_list; 170, identifier:inp; 171, call; 172, identifier:toml; 173, identifier:load; 174, identifier:inp; 175, identifier:xmltodict; 176, identifier:parse; 177, identifier:inp; 178, keyword_argument; 179, identifier:yaml; 180, identifier:safe_load; 181, identifier:inp; 182, attribute; 183, argument_list; 184, identifier:encoding; 185, identifier:encoding; 186, attribute; 187, argument_list; 188, identifier:encoding; 189, identifier:encoding; 190, string; 191, attribute; 192, argument_list; 193, identifier:encoding; 194, identifier:encoding; 195, identifier:io; 196, identifier:TextIOWrapper; 197, identifier:inp; 198, keyword_argument; 199, identifier:io; 200, identifier:TextIOWrapper; 201, identifier:inp; 202, keyword_argument; 203, string_content:toml is always utf-8 encoded according to specification; 204, identifier:io; 205, identifier:TextIOWrapper; 206, identifier:inp; 207, keyword_argument; 208, identifier:encoding; 209, identifier:encoding; 210, identifier:encoding; 211, identifier:encoding; 212, identifier:encoding; 213, identifier:encoding
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 9, 17; 10, 18; 11, 19; 12, 20; 12, 21; 12, 22; 12, 23; 12, 24; 12, 25; 12, 26; 12, 27; 16, 28; 18, 29; 18, 30; 19, 31; 19, 32; 20, 33; 20, 34; 21, 35; 21, 36; 22, 37; 22, 38; 23, 39; 23, 40; 24, 41; 24, 42; 25, 43; 25, 44; 26, 45; 26, 46; 26, 47; 26, 48; 27, 49; 28, 50; 28, 51; 32, 52; 32, 53; 34, 54; 35, 55; 36, 56; 37, 57; 37, 58; 38, 59; 38, 60; 39, 61; 39, 62; 40, 63; 40, 64; 41, 65; 41, 66; 42, 67; 42, 68; 42, 69; 43, 70; 43, 71; 44, 72; 45, 73; 45, 74; 48, 75; 49, 76; 49, 77; 51, 78; 51, 79; 51, 80; 53, 81; 55, 82; 55, 83; 56, 84; 56, 85; 58, 86; 59, 87; 59, 88; 59, 89; 60, 90; 62, 91; 63, 92; 63, 93; 64, 94; 66, 95; 67, 96; 67, 97; 68, 98; 68, 99; 68, 100; 69, 101; 71, 102; 72, 103; 74, 104; 75, 105; 83, 106; 83, 107; 85, 108; 85, 109; 87, 110; 87, 111; 89, 112; 90, 113; 90, 114; 92, 115; 92, 116; 93, 117; 94, 118; 94, 119; 96, 120; 97, 121; 98, 122; 98, 123; 100, 124; 101, 125; 101, 126; 103, 127; 103, 128; 105, 129; 105, 130; 106, 131; 106, 132; 107, 133; 107, 134; 108, 135; 108, 136; 112, 137; 114, 138; 114, 139; 117, 140; 119, 141; 119, 142; 120, 143; 120, 144; 121, 145; 124, 146; 126, 147; 126, 148; 128, 149; 128, 150; 130, 151; 130, 152; 134, 153; 134, 154; 137, 155; 137, 156; 138, 157; 138, 158; 139, 159; 139, 160; 140, 161; 140, 162; 141, 163; 141, 164; 142, 165; 142, 166; 144, 167; 145, 168; 145, 169; 146, 170; 146, 171; 147, 172; 147, 173; 148, 174; 149, 175; 149, 176; 150, 177; 150, 178; 151, 179; 151, 180; 152, 181; 156, 182; 156, 183; 160, 184; 160, 185; 162, 186; 162, 187; 166, 188; 166, 189; 169, 190; 171, 191; 171, 192; 178, 193; 178, 194; 182, 195; 182, 196; 183, 197; 183, 198; 186, 199; 186, 200; 187, 201; 187, 202; 190, 203; 191, 204; 191, 205; 192, 206; 192, 207; 198, 208; 198, 209; 202, 210; 202, 211; 207, 212; 207, 213
def _do_parse(inp, fmt, encoding, force_types): """Actually parse input. Args: inp: bytes yielding file-like object fmt: format to use for parsing encoding: encoding of `inp` force_types: if `True`, integers, floats, booleans and none/null are recognized and returned as proper types instead of strings; if `False`, everything is converted to strings if `None`, backend return value is used Returns: parsed `inp` (dict or list) containing unicode values Raises: various sorts of errors raised by used libraries while parsing """ res = {} _check_lib_installed(fmt, 'parse') if fmt == 'ini': cfg = configobj.ConfigObj(inp, encoding=encoding) res = cfg.dict() elif fmt == 'json': if six.PY3: # python 3 json only reads from unicode objects inp = io.TextIOWrapper(inp, encoding=encoding) res = json.load(inp, encoding=encoding) elif fmt == 'json5': if six.PY3: inp = io.TextIOWrapper(inp, encoding=encoding) res = json5.load(inp, encoding=encoding) elif fmt == 'toml': if not _is_utf8(encoding): raise AnyMarkupError('toml is always utf-8 encoded according to specification') if six.PY3: # python 3 toml prefers unicode objects inp = io.TextIOWrapper(inp, encoding=encoding) res = toml.load(inp) elif fmt == 'xml': res = xmltodict.parse(inp, encoding=encoding) elif fmt == 'yaml': # guesses encoding by its own, there seems to be no way to pass # it explicitly res = yaml.safe_load(inp) else: raise # unknown format # make sure it's all unicode and all int/float values were parsed correctly # the unicode part is here because of yaml on PY2 and also as workaround for # https://github.com/DiffSK/configobj/issues/18#issuecomment-76391689 return _ensure_proper_types(res, encoding, force_types)
0, module; 1, function_definition; 2, function_name:_do_serialize; 3, parameters; 4, block; 5, identifier:struct; 6, identifier:fmt; 7, identifier:encoding; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, if_statement; 12, return_statement; 13, comment:"""Actually serialize input. Args: struct: structure to serialize to fmt: format to serialize to encoding: encoding to use while serializing Returns: encoded serialized structure Raises: various sorts of errors raised by libraries while serializing """; 14, assignment; 15, call; 16, comparison_operator:fmt == 'ini'; 17, block; 18, elif_clause; 19, elif_clause; 20, elif_clause; 21, elif_clause; 22, else_clause; 23, identifier:res; 24, identifier:res; 25, None; 26, identifier:_check_lib_installed; 27, argument_list; 28, identifier:fmt; 29, string; 30, expression_statement; 31, for_statement; 32, expression_statement; 33, comparison_operator:fmt in ['json', 'json5']; 34, comment:# specify separators to get rid of trailing whitespace; 35, comment:# specify ensure_ascii to make sure unicode is serialized in \x... sequences,; 36, comment:# not in \u sequences; 37, block; 38, comparison_operator:fmt == 'toml'; 39, block; 40, comparison_operator:fmt == 'xml'; 41, comment:# passing encoding argument doesn't encode, just sets the xml property; 42, block; 43, comparison_operator:fmt == 'yaml'; 44, block; 45, block; 46, identifier:fmt; 47, string; 48, string_content:ini; 49, assignment; 50, pattern_list; 51, call; 52, block; 53, assignment; 54, identifier:fmt; 55, list; 56, expression_statement; 57, identifier:fmt; 58, string; 59, if_statement; 60, expression_statement; 61, identifier:fmt; 62, string; 63, expression_statement; 64, identifier:fmt; 65, string; 66, expression_statement; 67, raise_statement; 68, comment:# unknown format; 69, string_content:serialize; 70, identifier:config; 71, call; 72, identifier:k; 73, identifier:v; 74, attribute; 75, argument_list; 76, expression_statement; 77, identifier:res; 78, call; 79, string; 80, string; 81, assignment; 82, string_content:toml; 83, not_operator; 84, block; 85, assignment; 86, string_content:xml; 87, assignment; 88, string_content:yaml; 89, assignment; 90, attribute; 91, argument_list; 92, identifier:struct; 93, identifier:items; 94, assignment; 95, attribute; 96, argument_list; 97, string_content:json; 98, string_content:json5; 99, identifier:res; 100, call; 101, call; 102, raise_statement; 103, identifier:res; 104, call; 105, identifier:res; 106, call; 107, identifier:res; 108, call; 109, identifier:configobj; 110, identifier:ConfigObj; 111, keyword_argument; 112, subscript; 113, identifier:v; 114, string; 115, identifier:join; 116, call; 117, attribute; 118, argument_list; 119, identifier:_is_utf8; 120, argument_list; 121, call; 122, attribute; 123, argument_list; 124, attribute; 125, argument_list; 126, attribute; 127, argument_list; 128, identifier:encoding; 129, identifier:encoding; 130, identifier:config; 131, identifier:k; 132, string_content; 133, attribute; 134, argument_list; 135, call; 136, identifier:encode; 137, identifier:encoding; 138, identifier:encoding; 139, identifier:AnyMarkupError; 140, argument_list; 141, call; 142, identifier:encode; 143, identifier:encoding; 144, call; 145, identifier:encode; 146, string; 147, identifier:yaml; 148, identifier:safe_dump; 149, identifier:struct; 150, keyword_argument; 151, keyword_argument; 152, escape_sequence:\n; 153, identifier:config; 154, identifier:write; 155, attribute; 156, argument_list; 157, string; 158, attribute; 159, argument_list; 160, attribute; 161, argument_list; 162, string_content:utf-8; 163, identifier:encoding; 164, string; 165, identifier:default_flow_style; 166, False; 167, parenthesized_expression; 168, identifier:dumps; 169, identifier:struct; 170, keyword_argument; 171, keyword_argument; 172, keyword_argument; 173, string_content:toml must always be utf-8 encoded according to specification; 174, identifier:toml; 175, identifier:dumps; 176, identifier:struct; 177, identifier:xmltodict; 178, identifier:unparse; 179, identifier:struct; 180, keyword_argument; 181, keyword_argument; 182, string_content:utf-8; 183, conditional_expression:json if fmt == 'json' else json5; 184, identifier:indent; 185, integer:2; 186, identifier:separators; 187, tuple; 188, identifier:ensure_ascii; 189, False; 190, identifier:pretty; 191, True; 192, identifier:encoding; 193, string; 194, identifier:json; 195, comparison_operator:fmt == 'json'; 196, identifier:json5; 197, string; 198, string; 199, string_content:utf-8; 200, identifier:fmt; 201, string; 202, string_content:,; 203, string_content::; 204, string_content:json
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 8, 13; 9, 14; 10, 15; 11, 16; 11, 17; 11, 18; 11, 19; 11, 20; 11, 21; 11, 22; 12, 23; 14, 24; 14, 25; 15, 26; 15, 27; 16, 28; 16, 29; 17, 30; 17, 31; 17, 32; 18, 33; 18, 34; 18, 35; 18, 36; 18, 37; 19, 38; 19, 39; 20, 40; 20, 41; 20, 42; 21, 43; 21, 44; 22, 45; 27, 46; 27, 47; 29, 48; 30, 49; 31, 50; 31, 51; 31, 52; 32, 53; 33, 54; 33, 55; 37, 56; 38, 57; 38, 58; 39, 59; 39, 60; 40, 61; 40, 62; 42, 63; 43, 64; 43, 65; 44, 66; 45, 67; 45, 68; 47, 69; 49, 70; 49, 71; 50, 72; 50, 73; 51, 74; 51, 75; 52, 76; 53, 77; 53, 78; 55, 79; 55, 80; 56, 81; 58, 82; 59, 83; 59, 84; 60, 85; 62, 86; 63, 87; 65, 88; 66, 89; 71, 90; 71, 91; 74, 92; 74, 93; 76, 94; 78, 95; 78, 96; 79, 97; 80, 98; 81, 99; 81, 100; 83, 101; 84, 102; 85, 103; 85, 104; 87, 105; 87, 106; 89, 107; 89, 108; 90, 109; 90, 110; 91, 111; 94, 112; 94, 113; 95, 114; 95, 115; 96, 116; 100, 117; 100, 118; 101, 119; 101, 120; 102, 121; 104, 122; 104, 123; 106, 124; 106, 125; 108, 126; 108, 127; 111, 128; 111, 129; 112, 130; 112, 131; 114, 132; 116, 133; 116, 134; 117, 135; 117, 136; 118, 137; 120, 138; 121, 139; 121, 140; 122, 141; 122, 142; 123, 143; 124, 144; 124, 145; 125, 146; 126, 147; 126, 148; 127, 149; 127, 150; 127, 151; 132, 152; 133, 153; 133, 154; 135, 155; 135, 156; 140, 157; 141, 158; 141, 159; 144, 160; 144, 161; 146, 162; 150, 163; 150, 164; 151, 165; 151, 166; 155, 167; 155, 168; 156, 169; 156, 170; 156, 171; 156, 172; 157, 173; 158, 174; 158, 175; 159, 176; 160, 177; 160, 178; 161, 179; 161, 180; 161, 181; 164, 182; 167, 183; 170, 184; 170, 185; 171, 186; 171, 187; 172, 188; 172, 189; 180, 190; 180, 191; 181, 192; 181, 193; 183, 194; 183, 195; 183, 196; 187, 197; 187, 198; 193, 199; 195, 200; 195, 201; 197, 202; 198, 203; 201, 204
def _do_serialize(struct, fmt, encoding): """Actually serialize input. Args: struct: structure to serialize to fmt: format to serialize to encoding: encoding to use while serializing Returns: encoded serialized structure Raises: various sorts of errors raised by libraries while serializing """ res = None _check_lib_installed(fmt, 'serialize') if fmt == 'ini': config = configobj.ConfigObj(encoding=encoding) for k, v in struct.items(): config[k] = v res = b'\n'.join(config.write()) elif fmt in ['json', 'json5']: # specify separators to get rid of trailing whitespace # specify ensure_ascii to make sure unicode is serialized in \x... sequences, # not in \u sequences res = (json if fmt == 'json' else json5).dumps(struct, indent=2, separators=(',', ': '), ensure_ascii=False).encode(encoding) elif fmt == 'toml': if not _is_utf8(encoding): raise AnyMarkupError('toml must always be utf-8 encoded according to specification') res = toml.dumps(struct).encode(encoding) elif fmt == 'xml': # passing encoding argument doesn't encode, just sets the xml property res = xmltodict.unparse(struct, pretty=True, encoding='utf-8').encode('utf-8') elif fmt == 'yaml': res = yaml.safe_dump(struct, encoding='utf-8', default_flow_style=False) else: raise # unknown format return res
0, module; 1, function_definition; 2, function_name:sort_header; 3, parameters; 4, block; 5, identifier:header_text; 6, expression_statement; 7, expression_statement; 8, expression_statement; 9, for_statement; 10, expression_statement; 11, expression_statement; 12, for_statement; 13, return_statement; 14, comment:"""sort the chromosomes in a header text"""; 15, assignment; 16, assignment; 17, identifier:ln; 18, identifier:lines; 19, block; 20, assignment; 21, assignment; 22, identifier:ln; 23, identifier:lines; 24, block; 25, identifier:output; 26, identifier:lines; 27, call; 28, identifier:rlens; 29, dictionary; 30, expression_statement; 31, if_statement; 32, identifier:output; 33, string; 34, identifier:done_lens; 35, False; 36, if_statement; 37, attribute; 38, argument_list; 39, assignment; 40, identifier:m; 41, block; 42, call; 43, block; 44, else_clause; 45, call; 46, identifier:split; 47, string:"\n"; 48, identifier:m; 49, call; 50, expression_statement; 51, attribute; 52, argument_list; 53, if_statement; 54, block; 55, attribute; 56, argument_list; 57, attribute; 58, argument_list; 59, assignment; 60, identifier:re; 61, identifier:match; 62, string; 63, identifier:ln; 64, not_operator; 65, block; 66, expression_statement; 67, identifier:header_text; 68, identifier:rstrip; 69, identifier:re; 70, identifier:match; 71, string; 72, identifier:ln; 73, subscript; 74, call; 75, string_content; 76, identifier:done_lens; 77, expression_statement; 78, for_statement; 79, augmented_assignment; 80, string_content; 81, identifier:rlens; 82, call; 83, attribute; 84, argument_list; 85, escape_sequence:\t; 86, assignment; 87, identifier:chr; 88, call; 89, block; 90, identifier:output; 91, binary_operator:ln.rstrip("\n")+"\n"; 92, escape_sequence:\t; 93, escape_sequence:\t; 94, attribute; 95, argument_list; 96, identifier:m; 97, identifier:group; 98, integer:2; 99, identifier:done_lens; 100, True; 101, identifier:sorted; 102, argument_list; 103, expression_statement; 104, call; 105, string:"\n"; 106, identifier:m; 107, identifier:group; 108, integer:1; 109, call; 110, augmented_assignment; 111, attribute; 112, argument_list; 113, attribute; 114, argument_list; 115, identifier:output; 116, binary_operator:"@SQ\tSN:"+chr+"\tLN:"+str(rlens[chr])+"\n"; 117, identifier:ln; 118, identifier:rstrip; 119, string:"\n"; 120, identifier:rlens; 121, identifier:keys; 122, binary_operator:"@SQ\tSN:"+chr+"\tLN:"+str(rlens[chr]); 123, string:"\n"; 124, binary_operator:"@SQ\tSN:"+chr+"\tLN:"; 125, call; 126, binary_operator:"@SQ\tSN:"+chr; 127, string:"\tLN:"; 128, identifier:str; 129, argument_list; 130, string:"@SQ\tSN:"; 131, identifier:chr; 132, subscript; 133, identifier:rlens; 134, identifier:chr
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 6, 14; 7, 15; 8, 16; 9, 17; 9, 18; 9, 19; 10, 20; 11, 21; 12, 22; 12, 23; 12, 24; 13, 25; 15, 26; 15, 27; 16, 28; 16, 29; 19, 30; 19, 31; 20, 32; 20, 33; 21, 34; 21, 35; 24, 36; 27, 37; 27, 38; 30, 39; 31, 40; 31, 41; 36, 42; 36, 43; 36, 44; 37, 45; 37, 46; 38, 47; 39, 48; 39, 49; 41, 50; 42, 51; 42, 52; 43, 53; 44, 54; 45, 55; 45, 56; 49, 57; 49, 58; 50, 59; 51, 60; 51, 61; 52, 62; 52, 63; 53, 64; 53, 65; 54, 66; 55, 67; 55, 68; 57, 69; 57, 70; 58, 71; 58, 72; 59, 73; 59, 74; 62, 75; 64, 76; 65, 77; 65, 78; 66, 79; 71, 80; 73, 81; 73, 82; 74, 83; 74, 84; 75, 85; 77, 86; 78, 87; 78, 88; 78, 89; 79, 90; 79, 91; 80, 92; 80, 93; 82, 94; 82, 95; 83, 96; 83, 97; 84, 98; 86, 99; 86, 100; 88, 101; 88, 102; 89, 103; 91, 104; 91, 105; 94, 106; 94, 107; 95, 108; 102, 109; 103, 110; 104, 111; 104, 112; 109, 113; 109, 114; 110, 115; 110, 116; 111, 117; 111, 118; 112, 119; 113, 120; 113, 121; 116, 122; 116, 123; 122, 124; 122, 125; 124, 126; 124, 127; 125, 128; 125, 129; 126, 130; 126, 131; 129, 132; 132, 133; 132, 134
def sort_header(header_text): """sort the chromosomes in a header text""" lines = header_text.rstrip().split("\n") rlens = {} for ln in lines: m = re.match('@SQ\tSN:(\S+)\tLN:(\S+)',ln) if m: rlens[m.group(1)] = m.group(2) output = '' done_lens = False for ln in lines: if re.match('@SQ\tSN:',ln): if not done_lens: done_lens = True for chr in sorted(rlens.keys()): output += "@SQ\tSN:"+chr+"\tLN:"+str(rlens[chr])+"\n" else: output += ln.rstrip("\n")+"\n" return output
0, module; 1, function_definition; 2, function_name:sort; 3, parameters; 4, block; 5, identifier:self; 6, identifier:field; 7, default_parameter; 8, expression_statement; 9, if_statement; 10, if_statement; 11, expression_statement; 12, identifier:direction; 13, string:"asc"; 14, comment:""" Adds sort criteria. """; 15, not_operator; 16, block; 17, comparison_operator:direction not in ["asc", "desc"]; 18, block; 19, call; 20, call; 21, raise_statement; 22, identifier:direction; 23, list; 24, raise_statement; 25, attribute; 26, argument_list; 27, identifier:isinstance; 28, argument_list; 29, call; 30, string:"asc"; 31, string:"desc"; 32, call; 33, attribute; 34, identifier:append; 35, dictionary; 36, identifier:field; 37, identifier:basestring; 38, identifier:ValueError; 39, argument_list; 40, identifier:ValueError; 41, argument_list; 42, identifier:self; 43, identifier:sorts; 44, pair; 45, string:"Field should be a string"; 46, string:"Sort direction should be `asc` or `desc`"; 47, identifier:field; 48, identifier:direction
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 4, 11; 7, 12; 7, 13; 8, 14; 9, 15; 9, 16; 10, 17; 10, 18; 11, 19; 15, 20; 16, 21; 17, 22; 17, 23; 18, 24; 19, 25; 19, 26; 20, 27; 20, 28; 21, 29; 23, 30; 23, 31; 24, 32; 25, 33; 25, 34; 26, 35; 28, 36; 28, 37; 29, 38; 29, 39; 32, 40; 32, 41; 33, 42; 33, 43; 35, 44; 39, 45; 41, 46; 44, 47; 44, 48
def sort(self, field, direction="asc"): """ Adds sort criteria. """ if not isinstance(field, basestring): raise ValueError("Field should be a string") if direction not in ["asc", "desc"]: raise ValueError("Sort direction should be `asc` or `desc`") self.sorts.append({field: direction})
0, module; 1, function_definition; 2, function_name:remove_sort; 3, parameters; 4, block; 5, identifier:self; 6, identifier:field_name; 7, expression_statement; 8, expression_statement; 9, comment:""" Clears sorting criteria affecting ``field_name``. """; 10, assignment; 11, attribute; 12, list_comprehension; 13, identifier:self; 14, identifier:sorts; 15, call; 16, for_in_clause; 17, if_clause; 18, identifier:dict; 19, argument_list; 20, pattern_list; 21, attribute; 22, comparison_operator:field is not field_name; 23, keyword_argument; 24, identifier:field; 25, identifier:value; 26, identifier:self; 27, identifier:sorts; 28, identifier:field; 29, identifier:field_name; 30, identifier:field; 31, identifier:value
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 7, 9; 8, 10; 10, 11; 10, 12; 11, 13; 11, 14; 12, 15; 12, 16; 12, 17; 15, 18; 15, 19; 16, 20; 16, 21; 17, 22; 19, 23; 20, 24; 20, 25; 21, 26; 21, 27; 22, 28; 22, 29; 23, 30; 23, 31
def remove_sort(self, field_name): """ Clears sorting criteria affecting ``field_name``. """ self.sorts = [dict(field=value) for field, value in self.sorts if field is not field_name]
0, module; 1, function_definition; 2, function_name:aggregate_registry_timers; 3, parameters; 4, block; 5, expression_statement; 6, import_statement; 7, expression_statement; 8, expression_statement; 9, for_statement; 10, expression_statement; 11, return_statement; 12, comment:"""Returns a list of aggregate timing information for registered timers. Each element is a 3-tuple of - timer description - aggregate elapsed time - number of calls The list is sorted by the first start time of each aggregate timer. """; 13, dotted_name; 14, assignment; 15, assignment; 16, pattern_list; 17, call; 18, block; 19, call; 20, subscript; 21, identifier:itertools; 22, identifier:timers; 23, call; 24, identifier:aggregate_timers; 25, list; 26, identifier:k; 27, identifier:g; 28, attribute; 29, argument_list; 30, expression_statement; 31, expression_statement; 32, expression_statement; 33, expression_statement; 34, comment:# We'll use the first start time as a sort key.; 35, expression_statement; 36, attribute; 37, argument_list; 38, call; 39, integer:1; 40, identifier:sorted; 41, argument_list; 42, identifier:itertools; 43, identifier:groupby; 44, identifier:timers; 45, keyword_argument; 46, assignment; 47, assignment; 48, assignment; 49, assignment; 50, call; 51, identifier:aggregate_timers; 52, identifier:sort; 53, identifier:zip; 54, argument_list; 55, call; 56, keyword_argument; 57, identifier:key; 58, lambda; 59, identifier:group; 60, call; 61, identifier:num_calls; 62, call; 63, identifier:total_elapsed_ms; 64, call; 65, identifier:first_start_time; 66, call; 67, attribute; 68, argument_list; 69, list_splat; 70, attribute; 71, argument_list; 72, identifier:key; 73, lambda; 74, lambda_parameters; 75, attribute; 76, identifier:list; 77, argument_list; 78, identifier:len; 79, argument_list; 80, identifier:sum; 81, generator_expression; 82, identifier:min; 83, generator_expression; 84, identifier:aggregate_timers; 85, identifier:append; 86, tuple; 87, identifier:aggregate_timers; 88, identifier:shared_registry; 89, identifier:values; 90, lambda_parameters; 91, attribute; 92, identifier:t; 93, identifier:t; 94, identifier:desc; 95, identifier:g; 96, identifier:group; 97, attribute; 98, for_in_clause; 99, attribute; 100, for_in_clause; 101, identifier:first_start_time; 102, tuple; 103, identifier:t; 104, identifier:t; 105, identifier:desc; 106, identifier:t; 107, identifier:elapsed_time_ms; 108, identifier:t; 109, identifier:group; 110, identifier:t; 111, identifier:start_time; 112, identifier:t; 113, identifier:group; 114, identifier:k; 115, identifier:total_elapsed_ms; 116, identifier:num_calls
0, 1; 1, 2; 1, 3; 1, 4; 4, 5; 4, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 5, 12; 6, 13; 7, 14; 8, 15; 9, 16; 9, 17; 9, 18; 10, 19; 11, 20; 13, 21; 14, 22; 14, 23; 15, 24; 15, 25; 16, 26; 16, 27; 17, 28; 17, 29; 18, 30; 18, 31; 18, 32; 18, 33; 18, 34; 18, 35; 19, 36; 19, 37; 20, 38; 20, 39; 23, 40; 23, 41; 28, 42; 28, 43; 29, 44; 29, 45; 30, 46; 31, 47; 32, 48; 33, 49; 35, 50; 36, 51; 36, 52; 38, 53; 38, 54; 41, 55; 41, 56; 45, 57; 45, 58; 46, 59; 46, 60; 47, 61; 47, 62; 48, 63; 48, 64; 49, 65; 49, 66; 50, 67; 50, 68; 54, 69; 55, 70; 55, 71; 56, 72; 56, 73; 58, 74; 58, 75; 60, 76; 60, 77; 62, 78; 62, 79; 64, 80; 64, 81; 66, 82; 66, 83; 67, 84; 67, 85; 68, 86; 69, 87; 70, 88; 70, 89; 73, 90; 73, 91; 74, 92; 75, 93; 75, 94; 77, 95; 79, 96; 81, 97; 81, 98; 83, 99; 83, 100; 86, 101; 86, 102; 90, 103; 91, 104; 91, 105; 97, 106; 97, 107; 98, 108; 98, 109; 99, 110; 99, 111; 100, 112; 100, 113; 102, 114; 102, 115; 102, 116
def aggregate_registry_timers(): """Returns a list of aggregate timing information for registered timers. Each element is a 3-tuple of - timer description - aggregate elapsed time - number of calls The list is sorted by the first start time of each aggregate timer. """ import itertools timers = sorted(shared_registry.values(), key=lambda t: t.desc) aggregate_timers = [] for k, g in itertools.groupby(timers, key=lambda t: t.desc): group = list(g) num_calls = len(group) total_elapsed_ms = sum(t.elapsed_time_ms for t in group) first_start_time = min(t.start_time for t in group) # We'll use the first start time as a sort key. aggregate_timers.append( (first_start_time, (k, total_elapsed_ms, num_calls))) aggregate_timers.sort() return zip(*aggregate_timers)[1]
0, module; 1, function_definition; 2, function_name:spread; 3, parameters; 4, block; 5, identifier:iterable; 6, expression_statement; 7, if_statement; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, return_statement; 12, comment:"""Returns the maximal spread of a sorted list of numbers. Parameters ---------- iterable A list of numbers. Returns ------- max_diff The maximal difference when the iterable is sorted. Examples ------- >>> spread([1, 11, 13, 15]) 10 >>> spread([1, 15, 11, 13]) 10 """; 13, comparison_operator:len(iterable) == 1; 14, block; 15, assignment; 16, call; 17, assignment; 18, identifier:max_diff; 19, call; 20, integer:1; 21, return_statement; 22, identifier:iterable; 23, call; 24, attribute; 25, argument_list; 26, identifier:max_diff; 27, call; 28, identifier:len; 29, argument_list; 30, integer:0; 31, attribute; 32, argument_list; 33, identifier:iterable; 34, identifier:sort; 35, identifier:max; 36, generator_expression; 37, identifier:iterable; 38, identifier:iterable; 39, identifier:copy; 40, call; 41, for_in_clause; 42, identifier:abs; 43, argument_list; 44, tuple_pattern; 45, call; 46, binary_operator:i - j; 47, identifier:i; 48, identifier:j; 49, identifier:zip; 50, argument_list; 51, identifier:i; 52, identifier:j; 53, subscript; 54, subscript; 55, identifier:iterable; 56, slice; 57, identifier:iterable; 58, slice; 59, integer:1; 60, unary_operator; 61, integer:1
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 6, 12; 7, 13; 7, 14; 8, 15; 9, 16; 10, 17; 11, 18; 13, 19; 13, 20; 14, 21; 15, 22; 15, 23; 16, 24; 16, 25; 17, 26; 17, 27; 19, 28; 19, 29; 21, 30; 23, 31; 23, 32; 24, 33; 24, 34; 27, 35; 27, 36; 29, 37; 31, 38; 31, 39; 36, 40; 36, 41; 40, 42; 40, 43; 41, 44; 41, 45; 43, 46; 44, 47; 44, 48; 45, 49; 45, 50; 46, 51; 46, 52; 50, 53; 50, 54; 53, 55; 53, 56; 54, 57; 54, 58; 56, 59; 58, 60; 60, 61
def spread(iterable): """Returns the maximal spread of a sorted list of numbers. Parameters ---------- iterable A list of numbers. Returns ------- max_diff The maximal difference when the iterable is sorted. Examples ------- >>> spread([1, 11, 13, 15]) 10 >>> spread([1, 15, 11, 13]) 10 """ if len(iterable) == 1: return 0 iterable = iterable.copy() iterable.sort() max_diff = max(abs(i - j) for (i, j) in zip(iterable[1:], iterable[:-1])) return max_diff
0, module; 1, function_definition; 2, function_name:sort_transcripts; 3, parameters; 4, block; 5, identifier:self; 6, expression_statement; 7, expression_statement; 8, expression_statement; 9, comment:"""Sort the transcripts stored here"""; 10, assignment; 11, assignment; 12, identifier:txs; 13, call; 14, attribute; 15, identifier:txs; 16, identifier:sorted; 17, argument_list; 18, identifier:self; 19, identifier:_transcripts; 20, attribute; 21, keyword_argument; 22, identifier:self; 23, identifier:transcripts; 24, identifier:key; 25, lambda; 26, lambda_parameters; 27, tuple; 28, identifier:x; 29, attribute; 30, attribute; 31, attribute; 32, attribute; 33, identifier:chr; 34, attribute; 35, identifier:start; 36, attribute; 37, identifier:end; 38, identifier:x; 39, identifier:range; 40, identifier:x; 41, identifier:range; 42, identifier:x; 43, identifier:range
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 4, 8; 6, 9; 7, 10; 8, 11; 10, 12; 10, 13; 11, 14; 11, 15; 13, 16; 13, 17; 14, 18; 14, 19; 17, 20; 17, 21; 20, 22; 20, 23; 21, 24; 21, 25; 25, 26; 25, 27; 26, 28; 27, 29; 27, 30; 27, 31; 29, 32; 29, 33; 30, 34; 30, 35; 31, 36; 31, 37; 32, 38; 32, 39; 34, 40; 34, 41; 36, 42; 36, 43
def sort_transcripts(self): """Sort the transcripts stored here""" txs = sorted(self.transcripts,key=lambda x: (x.range.chr, x.range.start, x.range.end)) self._transcripts = txs
0, module; 1, function_definition; 2, function_name:in1d_events; 3, parameters; 4, block; 5, identifier:ar1; 6, identifier:ar2; 7, expression_statement; 8, expression_statement; 9, comment:# change memory alignement for c++ library; 10, expression_statement; 11, comment:# change memory alignement for c++ library; 12, expression_statement; 13, comment:# temporary result array filled by c++ library, bool type is not supported with cython/numpy; 14, return_statement; 15, comment:""" Does the same than np.in1d but uses the fact that ar1 and ar2 are sorted and the c++ library. Is therefore much much faster. """; 16, assignment; 17, assignment; 18, assignment; 19, call; 20, identifier:ar1; 21, call; 22, identifier:ar2; 23, call; 24, identifier:tmp; 25, call; 26, attribute; 27, argument_list; 28, attribute; 29, argument_list; 30, attribute; 31, argument_list; 32, attribute; 33, argument_list; 34, identifier:analysis_functions; 35, identifier:get_in1d_sorted; 36, identifier:ar1; 37, identifier:ar2; 38, identifier:tmp; 39, identifier:np; 40, identifier:ascontiguousarray; 41, identifier:ar1; 42, identifier:np; 43, identifier:ascontiguousarray; 44, identifier:ar2; 45, identifier:np; 46, identifier:empty_like; 47, identifier:ar1; 48, keyword_argument; 49, identifier:dtype; 50, attribute; 51, identifier:np; 52, identifier:uint8
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 7, 15; 8, 16; 10, 17; 12, 18; 14, 19; 16, 20; 16, 21; 17, 22; 17, 23; 18, 24; 18, 25; 19, 26; 19, 27; 21, 28; 21, 29; 23, 30; 23, 31; 25, 32; 25, 33; 26, 34; 26, 35; 27, 36; 27, 37; 27, 38; 28, 39; 28, 40; 29, 41; 30, 42; 30, 43; 31, 44; 32, 45; 32, 46; 33, 47; 33, 48; 48, 49; 48, 50; 50, 51; 50, 52
def in1d_events(ar1, ar2): """ Does the same than np.in1d but uses the fact that ar1 and ar2 are sorted and the c++ library. Is therefore much much faster. """ ar1 = np.ascontiguousarray(ar1) # change memory alignement for c++ library ar2 = np.ascontiguousarray(ar2) # change memory alignement for c++ library tmp = np.empty_like(ar1, dtype=np.uint8) # temporary result array filled by c++ library, bool type is not supported with cython/numpy return analysis_functions.get_in1d_sorted(ar1, ar2, tmp)
0, module; 1, function_definition; 2, function_name:sort_by_priority; 3, parameters; 4, block; 5, identifier:iterable; 6, default_parameter; 7, default_parameter; 8, expression_statement; 9, return_statement; 10, identifier:reverse; 11, False; 12, identifier:default_priority; 13, integer:10; 14, comment:""" Return a list or objects sorted by a priority value. """; 15, call; 16, identifier:sorted; 17, argument_list; 18, identifier:iterable; 19, keyword_argument; 20, keyword_argument; 21, identifier:reverse; 22, identifier:reverse; 23, identifier:key; 24, lambda; 25, lambda_parameters; 26, call; 27, identifier:o; 28, identifier:getattr; 29, argument_list; 30, identifier:o; 31, string; 32, identifier:default_priority; 33, string_content:priority
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 6, 10; 6, 11; 7, 12; 7, 13; 8, 14; 9, 15; 15, 16; 15, 17; 17, 18; 17, 19; 17, 20; 19, 21; 19, 22; 20, 23; 20, 24; 24, 25; 24, 26; 25, 27; 26, 28; 26, 29; 29, 30; 29, 31; 29, 32; 31, 33
def sort_by_priority(iterable, reverse=False, default_priority=10): """ Return a list or objects sorted by a priority value. """ return sorted(iterable, reverse=reverse, key=lambda o: getattr(o, 'priority', default_priority))
0, module; 1, function_definition; 2, function_name:apply; 3, parameters; 4, block; 5, identifier:self; 6, identifier:func; 7, default_parameter; 8, default_parameter; 9, dictionary_splat_pattern; 10, expression_statement; 11, if_statement; 12, identifier:mapping; 13, None; 14, identifier:new_dtype; 15, None; 16, identifier:kwargs; 17, comment:"""Apply an element-wise UDF to the Series. There are currently 6 options for using a UDF. First 4 are lazy, other 2 are eager and require the use of the raw decorator: - One of the predefined functions in baloo.functions. - Implementing a function which encodes the result. kwargs are automatically passed to it. - Pure Weld code and mapping. - Weld code and mapping along with a dynamically linked C++ lib containing the UDF. - Using a NumPy function, which however is EAGER and hence requires self.values to be raw. Additionally, NumPy does not support kwargs in (all) functions so must use raw decorator to strip away weld_type. - Implementing an eager function with the same precondition as above. Use the raw decorator to check this. Parameters ---------- func : function or str Weld code as a str to encode or function from baloo.functions. mapping : dict, optional Additional mappings in the weld_template to replace on execution. self is added by default to reference to this Series. new_dtype : numpy.dtype, optional Specify the new dtype of the result Series. If None, it assumes it's the same dtype as before the apply. Returns ------- Series With UDF result. Examples -------- >>> import baloo as bl >>> sr = bl.Series([1, 2, 3]) >>> weld_template = 'map({self}, |e| e + {scalar})' >>> mapping = {'scalar': '2L'} >>> print(sr.apply(weld_template, mapping).evaluate()) <BLANKLINE> --- -- 0 3 1 4 2 5 >>> weld_template2 = 'map({self}, |e| e + 3L)' >>> print(sr.apply(weld_template2).evaluate()) <BLANKLINE> --- -- 0 4 1 5 2 6 >>> print(bl.Series([1., 4., 100.]).apply(bl.sqrt).evaluate()) # lazy predefined function <BLANKLINE> --- -- 0 1 1 2 2 10 >>> sr = bl.Series([4, 2, 3, 1]) >>> print(sr.apply(bl.sort, kind='q').evaluate()) # eager wrapper over np.sort (which uses raw decorator) <BLANKLINE> --- -- 0 1 1 2 2 3 3 4 >>> print(sr.apply(bl.raw(np.sort, kind='q')).evaluate()) # np.sort directly <BLANKLINE> --- -- 0 1 1 2 2 3 3 4 >>> print(sr.apply(bl.raw(lambda x: np.sort(x, kind='q'))).evaluate()) # lambda also works, with x = np.array <BLANKLINE> --- -- 0 1 1 2 2 3 3 4 # check tests/core/cudf/* and tests/core/test_series.test_cudf for C UDF example """; 18, call; 19, block; 20, elif_clause; 21, else_clause; 22, identifier:callable; 23, argument_list; 24, return_statement; 25, call; 26, block; 27, block; 28, identifier:func; 29, call; 30, identifier:isinstance; 31, argument_list; 32, expression_statement; 33, expression_statement; 34, expression_statement; 35, if_statement; 36, if_statement; 37, return_statement; 38, raise_statement; 39, identifier:Series; 40, argument_list; 41, identifier:func; 42, identifier:str; 43, call; 44, call; 45, assignment; 46, comparison_operator:mapping is None; 47, block; 48, else_clause; 49, comparison_operator:new_dtype is None; 50, block; 51, call; 52, call; 53, call; 54, attribute; 55, attribute; 56, attribute; 57, identifier:check_type; 58, argument_list; 59, identifier:check_dtype; 60, argument_list; 61, identifier:default_mapping; 62, dictionary; 63, identifier:mapping; 64, None; 65, expression_statement; 66, block; 67, identifier:new_dtype; 68, None; 69, expression_statement; 70, identifier:Series; 71, argument_list; 72, identifier:TypeError; 73, argument_list; 74, identifier:func; 75, argument_list; 76, identifier:self; 77, identifier:index; 78, identifier:self; 79, identifier:dtype; 80, identifier:self; 81, identifier:name; 82, identifier:mapping; 83, identifier:dict; 84, identifier:new_dtype; 85, pair; 86, assignment; 87, expression_statement; 88, assignment; 89, call; 90, attribute; 91, identifier:new_dtype; 92, attribute; 93, string; 94, attribute; 95, keyword_argument; 96, dictionary_splat; 97, string; 98, attribute; 99, identifier:mapping; 100, identifier:default_mapping; 101, call; 102, identifier:new_dtype; 103, attribute; 104, identifier:weld_udf; 105, argument_list; 106, identifier:self; 107, identifier:index; 108, identifier:self; 109, identifier:name; 110, string_content:Expected function or str defining a weld_template; 111, identifier:self; 112, identifier:values; 113, identifier:weld_type; 114, attribute; 115, identifier:kwargs; 116, string_content:self; 117, identifier:self; 118, identifier:values; 119, attribute; 120, argument_list; 121, identifier:self; 122, identifier:dtype; 123, identifier:func; 124, identifier:mapping; 125, identifier:self; 126, identifier:weld_type; 127, identifier:mapping; 128, identifier:update; 129, identifier:default_mapping
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 4, 10; 4, 11; 7, 12; 7, 13; 8, 14; 8, 15; 9, 16; 10, 17; 11, 18; 11, 19; 11, 20; 11, 21; 18, 22; 18, 23; 19, 24; 20, 25; 20, 26; 21, 27; 23, 28; 24, 29; 25, 30; 25, 31; 26, 32; 26, 33; 26, 34; 26, 35; 26, 36; 26, 37; 27, 38; 29, 39; 29, 40; 31, 41; 31, 42; 32, 43; 33, 44; 34, 45; 35, 46; 35, 47; 35, 48; 36, 49; 36, 50; 37, 51; 38, 52; 40, 53; 40, 54; 40, 55; 40, 56; 43, 57; 43, 58; 44, 59; 44, 60; 45, 61; 45, 62; 46, 63; 46, 64; 47, 65; 48, 66; 49, 67; 49, 68; 50, 69; 51, 70; 51, 71; 52, 72; 52, 73; 53, 74; 53, 75; 54, 76; 54, 77; 55, 78; 55, 79; 56, 80; 56, 81; 58, 82; 58, 83; 60, 84; 62, 85; 65, 86; 66, 87; 69, 88; 71, 89; 71, 90; 71, 91; 71, 92; 73, 93; 75, 94; 75, 95; 75, 96; 85, 97; 85, 98; 86, 99; 86, 100; 87, 101; 88, 102; 88, 103; 89, 104; 89, 105; 90, 106; 90, 107; 92, 108; 92, 109; 93, 110; 94, 111; 94, 112; 95, 113; 95, 114; 96, 115; 97, 116; 98, 117; 98, 118; 101, 119; 101, 120; 103, 121; 103, 122; 105, 123; 105, 124; 114, 125; 114, 126; 119, 127; 119, 128; 120, 129
def apply(self, func, mapping=None, new_dtype=None, **kwargs): """Apply an element-wise UDF to the Series. There are currently 6 options for using a UDF. First 4 are lazy, other 2 are eager and require the use of the raw decorator: - One of the predefined functions in baloo.functions. - Implementing a function which encodes the result. kwargs are automatically passed to it. - Pure Weld code and mapping. - Weld code and mapping along with a dynamically linked C++ lib containing the UDF. - Using a NumPy function, which however is EAGER and hence requires self.values to be raw. Additionally, NumPy does not support kwargs in (all) functions so must use raw decorator to strip away weld_type. - Implementing an eager function with the same precondition as above. Use the raw decorator to check this. Parameters ---------- func : function or str Weld code as a str to encode or function from baloo.functions. mapping : dict, optional Additional mappings in the weld_template to replace on execution. self is added by default to reference to this Series. new_dtype : numpy.dtype, optional Specify the new dtype of the result Series. If None, it assumes it's the same dtype as before the apply. Returns ------- Series With UDF result. Examples -------- >>> import baloo as bl >>> sr = bl.Series([1, 2, 3]) >>> weld_template = 'map({self}, |e| e + {scalar})' >>> mapping = {'scalar': '2L'} >>> print(sr.apply(weld_template, mapping).evaluate()) <BLANKLINE> --- -- 0 3 1 4 2 5 >>> weld_template2 = 'map({self}, |e| e + 3L)' >>> print(sr.apply(weld_template2).evaluate()) <BLANKLINE> --- -- 0 4 1 5 2 6 >>> print(bl.Series([1., 4., 100.]).apply(bl.sqrt).evaluate()) # lazy predefined function <BLANKLINE> --- -- 0 1 1 2 2 10 >>> sr = bl.Series([4, 2, 3, 1]) >>> print(sr.apply(bl.sort, kind='q').evaluate()) # eager wrapper over np.sort (which uses raw decorator) <BLANKLINE> --- -- 0 1 1 2 2 3 3 4 >>> print(sr.apply(bl.raw(np.sort, kind='q')).evaluate()) # np.sort directly <BLANKLINE> --- -- 0 1 1 2 2 3 3 4 >>> print(sr.apply(bl.raw(lambda x: np.sort(x, kind='q'))).evaluate()) # lambda also works, with x = np.array <BLANKLINE> --- -- 0 1 1 2 2 3 3 4 # check tests/core/cudf/* and tests/core/test_series.test_cudf for C UDF example """ if callable(func): return Series(func(self.values, weld_type=self.weld_type, **kwargs), self.index, self.dtype, self.name) elif isinstance(func, str): check_type(mapping, dict) check_dtype(new_dtype) default_mapping = {'self': self.values} if mapping is None: mapping = default_mapping else: mapping.update(default_mapping) if new_dtype is None: new_dtype = self.dtype return Series(weld_udf(func, mapping), self.index, new_dtype, self.name) else: raise TypeError('Expected function or str defining a weld_template')
0, module; 1, function_definition; 2, function_name:weld_sort; 3, parameters; 4, block; 5, identifier:arrays; 6, identifier:weld_types; 7, identifier:readable_text; 8, default_parameter; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, expression_statement; 14, expression_statement; 15, expression_statement; 16, expression_statement; 17, expression_statement; 18, expression_statement; 19, return_statement; 20, identifier:ascending; 21, True; 22, comment:"""Sort the arrays. Parameters ---------- arrays : list of (numpy.ndarray or WeldObject) Arrays to put in a struct. weld_types : list of WeldType The Weld types of the arrays in the same order. readable_text : str Explanatory string to add in the Weld placeholder. ascending : bool, optional Returns ------- list of WeldObject Representation of this computation. """; 23, assignment; 24, assignment; 25, assignment; 26, assignment; 27, assignment; 28, assignment; 29, assignment; 30, assignment; 31, call; 32, identifier:weld_obj; 33, identifier:weld_obj_sort; 34, call; 35, identifier:weld_obj_struct; 36, call; 37, identifier:weld_obj_indices; 38, call; 39, identifier:intermediate_result; 40, call; 41, identifier:dependency_name; 42, call; 43, identifier:fake_weld_input; 44, call; 45, pattern_list; 46, call; 47, attribute; 48, call; 49, attribute; 50, argument_list; 51, identifier:_weld_sort; 52, argument_list; 53, identifier:weld_vec_of_struct_to_struct_of_vec; 54, argument_list; 55, identifier:weld_select_from_struct; 56, argument_list; 57, identifier:LazyArrayResult; 58, argument_list; 59, attribute; 60, argument_list; 61, attribute; 62, argument_list; 63, identifier:obj_id; 64, identifier:weld_obj; 65, identifier:create_weld_object; 66, argument_list; 67, identifier:weld_obj; 68, identifier:weld_code; 69, attribute; 70, argument_list; 71, identifier:Cache; 72, identifier:cache_fake_input; 73, identifier:obj_id; 74, identifier:fake_weld_input; 75, identifier:arrays; 76, identifier:weld_types; 77, identifier:ascending; 78, identifier:weld_obj_sort; 79, identifier:weld_types; 80, identifier:weld_obj_struct; 81, integer:0; 82, identifier:weld_obj_indices; 83, call; 84, identifier:Cache; 85, identifier:cache_intermediate_result; 86, identifier:intermediate_result; 87, identifier:readable_text; 88, identifier:Cache; 89, identifier:create_fake_array_input; 90, identifier:dependency_name; 91, binary_operator:readable_text + '_indices'; 92, identifier:fake_weld_input; 93, string; 94, identifier:format; 95, identifier:obj_id; 96, identifier:WeldLong; 97, argument_list; 98, identifier:readable_text; 99, string; 100, string_content:{}; 101, string_content:_indices
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 4, 17; 4, 18; 4, 19; 8, 20; 8, 21; 9, 22; 10, 23; 11, 24; 12, 25; 13, 26; 14, 27; 15, 28; 16, 29; 17, 30; 18, 31; 19, 32; 23, 33; 23, 34; 24, 35; 24, 36; 25, 37; 25, 38; 26, 39; 26, 40; 27, 41; 27, 42; 28, 43; 28, 44; 29, 45; 29, 46; 30, 47; 30, 48; 31, 49; 31, 50; 34, 51; 34, 52; 36, 53; 36, 54; 38, 55; 38, 56; 40, 57; 40, 58; 42, 59; 42, 60; 44, 61; 44, 62; 45, 63; 45, 64; 46, 65; 46, 66; 47, 67; 47, 68; 48, 69; 48, 70; 49, 71; 49, 72; 50, 73; 50, 74; 52, 75; 52, 76; 52, 77; 54, 78; 54, 79; 56, 80; 56, 81; 58, 82; 58, 83; 59, 84; 59, 85; 60, 86; 60, 87; 61, 88; 61, 89; 62, 90; 62, 91; 66, 92; 69, 93; 69, 94; 70, 95; 83, 96; 83, 97; 91, 98; 91, 99; 93, 100; 99, 101
def weld_sort(arrays, weld_types, readable_text, ascending=True): """Sort the arrays. Parameters ---------- arrays : list of (numpy.ndarray or WeldObject) Arrays to put in a struct. weld_types : list of WeldType The Weld types of the arrays in the same order. readable_text : str Explanatory string to add in the Weld placeholder. ascending : bool, optional Returns ------- list of WeldObject Representation of this computation. """ weld_obj_sort = _weld_sort(arrays, weld_types, ascending) weld_obj_struct = weld_vec_of_struct_to_struct_of_vec(weld_obj_sort, weld_types) weld_obj_indices = weld_select_from_struct(weld_obj_struct, 0) intermediate_result = LazyArrayResult(weld_obj_indices, WeldLong()) dependency_name = Cache.cache_intermediate_result(intermediate_result, readable_text) fake_weld_input = Cache.create_fake_array_input(dependency_name, readable_text + '_indices') obj_id, weld_obj = create_weld_object(fake_weld_input) weld_obj.weld_code = '{}'.format(obj_id) Cache.cache_fake_input(obj_id, fake_weld_input) return weld_obj
0, module; 1, function_definition; 2, function_name:chooseBestDuplicates; 3, parameters; 4, block; 5, identifier:tped; 6, identifier:samples; 7, identifier:oldSamples; 8, identifier:completion; 9, identifier:concordance_all; 10, identifier:prefix; 11, expression_statement; 12, comment:# The output files; 13, expression_statement; 14, try_statement; 15, print_statement; 16, expression_statement; 17, try_statement; 18, print_statement; 19, comment:# For each duplicated sample; 20, expression_statement; 21, expression_statement; 22, for_statement; 23, comment:# Closing the output files; 24, expression_statement; 25, expression_statement; 26, return_statement; 27, comment:"""Choose the best duplicates according to the completion rate. :param tped: the ``tped`` containing the duplicated samples. :param samples: the updated position of the samples in the tped containing only duplicated samples. :param oldSamples: the original duplicated sample positions. :param completion: the completion of each of the duplicated samples. :param concordance_all: the concordance of every duplicated samples. :param prefix: the prefix of all the files. :type tped: :py:class:`numpy.array` :type samples: dict :type oldSamples: dict :type completion: :py:class:`numpy.array` :type concordance_all: dict :type prefix: str :returns: a tuple where the first element is a list of the chosen samples' indexes, the second on is the completion and the last one is the concordance (a map). These are the steps to find the best duplicated sample: 1. Sort the list of concordances. 2. Sort the list of completions. 3. Choose the best of the concordance and put in a set. 4. Choose the best of the completion and put it in a set. 5. Compute the intersection of the two sets. If there is one sample or more, then randomly choose one sample. 6. If the intersection doesn't contain at least one sample, redo steps 3 and 4, but increase the number of chosen best by one. Redo step 5 and 6 (if required). The chosen samples are written in ``prefix.chosen_samples.info``. The rest are written in ``prefix.excluded_samples.info``. """; 28, assignment; 29, block; 30, except_clause; 31, chevron; 32, call; 33, assignment; 34, block; 35, except_clause; 36, chevron; 37, call; 38, assignment; 39, assignment; 40, pattern_list; 41, call; 42, comment:# Getting the completion for those duplicated samples; 43, block; 44, call; 45, call; 46, expression_list; 47, identifier:chosenFile; 48, None; 49, expression_statement; 50, identifier:IOError; 51, block; 52, identifier:chosenFile; 53, attribute; 54, argument_list; 55, identifier:excludedFile; 56, None; 57, expression_statement; 58, identifier:IOError; 59, block; 60, identifier:excludedFile; 61, attribute; 62, argument_list; 63, identifier:chosenIndexes; 64, dictionary; 65, identifier:sampleConcordance; 66, dictionary; 67, identifier:sample; 68, identifier:indexes; 69, attribute; 70, argument_list; 71, expression_statement; 72, comment:# Sorting those completion; 73, expression_statement; 74, comment:# Getting the concordance; 75, expression_statement; 76, expression_statement; 77, for_statement; 78, expression_statement; 79, if_statement; 80, comment:# Sorting the concordance; 81, expression_statement; 82, comment:# Trying to find the best duplicate to keep; 83, expression_statement; 84, expression_statement; 85, while_statement; 86, if_statement; 87, comment:# Printing the chosen samples; 88, print_statement; 89, comment:# Printing the excluded samples; 90, for_statement; 91, expression_statement; 92, attribute; 93, argument_list; 94, attribute; 95, argument_list; 96, identifier:chosenIndexes; 97, identifier:completion; 98, identifier:sampleConcordance; 99, assignment; 100, expression_statement; 101, raise_statement; 102, string:"\t"; 103, identifier:join; 104, list; 105, assignment; 106, expression_statement; 107, raise_statement; 108, string:"\t"; 109, identifier:join; 110, list; 111, identifier:samples; 112, identifier:iteritems; 113, assignment; 114, assignment; 115, assignment; 116, assignment; 117, identifier:i; 118, call; 119, block; 120, assignment; 121, comparison_operator:sample not in sampleConcordance; 122, block; 123, assignment; 124, assignment; 125, assignment; 126, comparison_operator:nbToCheck <= len(indexes); 127, comment:# Getting the `nbToCheck` best value (higher to lower); 128, block; 129, comparison_operator:chosenIndex is None; 130, block; 131, chevron; 132, call; 133, pattern_list; 134, call; 135, block; 136, assignment; 137, identifier:chosenFile; 138, identifier:close; 139, identifier:excludedFile; 140, identifier:close; 141, identifier:chosenFile; 142, call; 143, assignment; 144, call; 145, string:"origIndex"; 146, string:"dupIndex"; 147, string:"famID"; 148, string:"indID"; 149, identifier:excludedFile; 150, call; 151, assignment; 152, call; 153, string:"origIndex"; 154, string:"dupIndex"; 155, string:"famID"; 156, string:"indID"; 157, identifier:currCompletion; 158, subscript; 159, identifier:sortedCompletionIndexes; 160, call; 161, identifier:concordance; 162, subscript; 163, identifier:currConcordance; 164, list_comprehension; 165, identifier:xrange; 166, argument_list; 167, expression_statement; 168, expression_statement; 169, identifier:currConcordance; 170, call; 171, identifier:sample; 172, identifier:sampleConcordance; 173, expression_statement; 174, identifier:sortedConcordanceIndexes; 175, call; 176, identifier:nbToCheck; 177, integer:1; 178, identifier:chosenIndex; 179, None; 180, identifier:nbToCheck; 181, call; 182, expression_statement; 183, expression_statement; 184, comment:# Getting the indexes to consider; 185, expression_statement; 186, expression_statement; 187, comment:# Getting the intersection of the indexes; 188, expression_statement; 189, if_statement; 190, expression_statement; 191, identifier:chosenIndex; 192, None; 193, expression_statement; 194, raise_statement; 195, identifier:chosenFile; 196, attribute; 197, argument_list; 198, identifier:i; 199, identifier:index; 200, identifier:enumerate; 201, argument_list; 202, if_statement; 203, subscript; 204, subscript; 205, identifier:open; 206, argument_list; 207, identifier:msg; 208, binary_operator:"%(prefix)s.chosen_samples.info: can't write file" % locals(); 209, identifier:ProgramError; 210, argument_list; 211, identifier:open; 212, argument_list; 213, identifier:msg; 214, binary_operator:"%(prefix)s.excluded_samples.info: can't write file" % locals(); 215, identifier:ProgramError; 216, argument_list; 217, identifier:completion; 218, identifier:indexes; 219, attribute; 220, argument_list; 221, identifier:concordance_all; 222, identifier:sample; 223, list; 224, for_in_clause; 225, call; 226, assignment; 227, assignment; 228, attribute; 229, argument_list; 230, assignment; 231, attribute; 232, argument_list; 233, identifier:len; 234, argument_list; 235, assignment; 236, assignment; 237, assignment; 238, assignment; 239, assignment; 240, comparison_operator:len(toConsider) >= 1; 241, block; 242, augmented_assignment; 243, assignment; 244, call; 245, string:"\t"; 246, identifier:join; 247, list; 248, identifier:indexes; 249, comparison_operator:i != chosenIndex; 250, block; 251, identifier:chosenIndexes; 252, identifier:sample; 253, identifier:indexes; 254, identifier:chosenIndex; 255, binary_operator:prefix + ".chosen_samples.info"; 256, string:"w"; 257, string:"%(prefix)s.chosen_samples.info: can't write file"; 258, call; 259, identifier:msg; 260, binary_operator:prefix + ".excluded_samples.info"; 261, string:"w"; 262, string:"%(prefix)s.excluded_samples.info: can't write file"; 263, call; 264, identifier:msg; 265, identifier:np; 266, identifier:argsort; 267, identifier:currCompletion; 268, identifier:i; 269, call; 270, identifier:len; 271, argument_list; 272, identifier:indexToKeep; 273, call; 274, subscript; 275, call; 276, identifier:np; 277, identifier:array; 278, identifier:currConcordance; 279, subscript; 280, identifier:currConcordance; 281, identifier:np; 282, identifier:argsort; 283, identifier:currConcordance; 284, identifier:indexes; 285, identifier:completionValue; 286, subscript; 287, identifier:concordanceValue; 288, subscript; 289, identifier:completionToConsider; 290, call; 291, identifier:concordanceToConsider; 292, call; 293, identifier:toConsider; 294, binary_operator:concordanceToConsider & completionToConsider; 295, call; 296, integer:1; 297, expression_statement; 298, break_statement; 299, identifier:nbToCheck; 300, integer:1; 301, identifier:msg; 302, call; 303, identifier:ProgramError; 304, argument_list; 305, call; 306, call; 307, subscript; 308, subscript; 309, identifier:i; 310, identifier:chosenIndex; 311, print_statement; 312, identifier:prefix; 313, string:".chosen_samples.info"; 314, identifier:locals; 315, argument_list; 316, identifier:prefix; 317, string:".excluded_samples.info"; 318, identifier:locals; 319, argument_list; 320, identifier:xrange; 321, argument_list; 322, identifier:indexes; 323, identifier:list; 324, argument_list; 325, identifier:currConcordance; 326, identifier:i; 327, attribute; 328, argument_list; 329, identifier:sampleConcordance; 330, identifier:sample; 331, identifier:currCompletion; 332, subscript; 333, identifier:currConcordance; 334, subscript; 335, identifier:set; 336, argument_list; 337, identifier:set; 338, argument_list; 339, identifier:concordanceToConsider; 340, identifier:completionToConsider; 341, identifier:len; 342, argument_list; 343, assignment; 344, attribute; 345, argument_list; 346, identifier:msg; 347, identifier:str; 348, argument_list; 349, identifier:str; 350, argument_list; 351, identifier:sample; 352, integer:0; 353, identifier:sample; 354, integer:1; 355, chevron; 356, call; 357, call; 358, binary_operator:set(range(len(indexes))) - set([i]); 359, identifier:np; 360, identifier:mean; 361, subscript; 362, identifier:sortedCompletionIndexes; 363, binary_operator:nbToCheck*-1; 364, identifier:sortedConcordanceIndexes; 365, binary_operator:nbToCheck*-1; 366, subscript; 367, subscript; 368, identifier:toConsider; 369, identifier:chosenIndex; 370, call; 371, string:"Could not choose the best sample ID for {}"; 372, identifier:format; 373, identifier:sample; 374, binary_operator:oldSamples[sample][chosenIndex]+1; 375, binary_operator:indexes[chosenIndex]+1; 376, identifier:excludedFile; 377, attribute; 378, argument_list; 379, identifier:len; 380, argument_list; 381, call; 382, call; 383, identifier:concordance; 384, identifier:i; 385, identifier:indexToKeep; 386, identifier:nbToCheck; 387, unary_operator; 388, identifier:nbToCheck; 389, unary_operator; 390, call; 391, integer:0; 392, call; 393, integer:0; 394, attribute; 395, argument_list; 396, subscript; 397, integer:1; 398, subscript; 399, integer:1; 400, string:"\t"; 401, identifier:join; 402, list; 403, identifier:indexes; 404, identifier:set; 405, argument_list; 406, identifier:set; 407, argument_list; 408, integer:1; 409, integer:1; 410, attribute; 411, argument_list; 412, attribute; 413, argument_list; 414, identifier:random; 415, identifier:choice; 416, call; 417, subscript; 418, identifier:chosenIndex; 419, identifier:indexes; 420, identifier:chosenIndex; 421, call; 422, call; 423, subscript; 424, subscript; 425, call; 426, list; 427, identifier:np; 428, identifier:where; 429, comparison_operator:currCompletion >= completionValue; 430, identifier:np; 431, identifier:where; 432, comparison_operator:currConcordance >= concordanceValue; 433, identifier:list; 434, argument_list; 435, identifier:oldSamples; 436, identifier:sample; 437, identifier:str; 438, argument_list; 439, identifier:str; 440, argument_list; 441, identifier:sample; 442, integer:0; 443, identifier:sample; 444, integer:1; 445, identifier:range; 446, argument_list; 447, identifier:i; 448, identifier:currCompletion; 449, identifier:completionValue; 450, identifier:currConcordance; 451, identifier:concordanceValue; 452, identifier:toConsider; 453, binary_operator:oldSamples[sample][i]+1; 454, binary_operator:index+1; 455, call; 456, subscript; 457, integer:1; 458, identifier:index; 459, integer:1; 460, identifier:len; 461, argument_list; 462, subscript; 463, identifier:i; 464, identifier:indexes; 465, identifier:oldSamples; 466, identifier:sample
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 4, 17; 4, 18; 4, 19; 4, 20; 4, 21; 4, 22; 4, 23; 4, 24; 4, 25; 4, 26; 11, 27; 13, 28; 14, 29; 14, 30; 15, 31; 15, 32; 16, 33; 17, 34; 17, 35; 18, 36; 18, 37; 20, 38; 21, 39; 22, 40; 22, 41; 22, 42; 22, 43; 24, 44; 25, 45; 26, 46; 28, 47; 28, 48; 29, 49; 30, 50; 30, 51; 31, 52; 32, 53; 32, 54; 33, 55; 33, 56; 34, 57; 35, 58; 35, 59; 36, 60; 37, 61; 37, 62; 38, 63; 38, 64; 39, 65; 39, 66; 40, 67; 40, 68; 41, 69; 41, 70; 43, 71; 43, 72; 43, 73; 43, 74; 43, 75; 43, 76; 43, 77; 43, 78; 43, 79; 43, 80; 43, 81; 43, 82; 43, 83; 43, 84; 43, 85; 43, 86; 43, 87; 43, 88; 43, 89; 43, 90; 43, 91; 44, 92; 44, 93; 45, 94; 45, 95; 46, 96; 46, 97; 46, 98; 49, 99; 51, 100; 51, 101; 53, 102; 53, 103; 54, 104; 57, 105; 59, 106; 59, 107; 61, 108; 61, 109; 62, 110; 69, 111; 69, 112; 71, 113; 73, 114; 75, 115; 76, 116; 77, 117; 77, 118; 77, 119; 78, 120; 79, 121; 79, 122; 81, 123; 83, 124; 84, 125; 85, 126; 85, 127; 85, 128; 86, 129; 86, 130; 88, 131; 88, 132; 90, 133; 90, 134; 90, 135; 91, 136; 92, 137; 92, 138; 94, 139; 94, 140; 99, 141; 99, 142; 100, 143; 101, 144; 104, 145; 104, 146; 104, 147; 104, 148; 105, 149; 105, 150; 106, 151; 107, 152; 110, 153; 110, 154; 110, 155; 110, 156; 113, 157; 113, 158; 114, 159; 114, 160; 115, 161; 115, 162; 116, 163; 116, 164; 118, 165; 118, 166; 119, 167; 119, 168; 120, 169; 120, 170; 121, 171; 121, 172; 122, 173; 123, 174; 123, 175; 124, 176; 124, 177; 125, 178; 125, 179; 126, 180; 126, 181; 128, 182; 128, 183; 128, 184; 128, 185; 128, 186; 128, 187; 128, 188; 128, 189; 128, 190; 129, 191; 129, 192; 130, 193; 130, 194; 131, 195; 132, 196; 132, 197; 133, 198; 133, 199; 134, 200; 134, 201; 135, 202; 136, 203; 136, 204; 142, 205; 142, 206; 143, 207; 143, 208; 144, 209; 144, 210; 150, 211; 150, 212; 151, 213; 151, 214; 152, 215; 152, 216; 158, 217; 158, 218; 160, 219; 160, 220; 162, 221; 162, 222; 164, 223; 164, 224; 166, 225; 167, 226; 168, 227; 170, 228; 170, 229; 173, 230; 175, 231; 175, 232; 181, 233; 181, 234; 182, 235; 183, 236; 185, 237; 186, 238; 188, 239; 189, 240; 189, 241; 190, 242; 193, 243; 194, 244; 196, 245; 196, 246; 197, 247; 201, 248; 202, 249; 202, 250; 203, 251; 203, 252; 204, 253; 204, 254; 206, 255; 206, 256; 208, 257; 208, 258; 210, 259; 212, 260; 212, 261; 214, 262; 214, 263; 216, 264; 219, 265; 219, 266; 220, 267; 224, 268; 224, 269; 225, 270; 225, 271; 226, 272; 226, 273; 227, 274; 227, 275; 228, 276; 228, 277; 229, 278; 230, 279; 230, 280; 231, 281; 231, 282; 232, 283; 234, 284; 235, 285; 235, 286; 236, 287; 236, 288; 237, 289; 237, 290; 238, 291; 238, 292; 239, 293; 239, 294; 240, 295; 240, 296; 241, 297; 241, 298; 242, 299; 242, 300; 243, 301; 243, 302; 244, 303; 244, 304; 247, 305; 247, 306; 247, 307; 247, 308; 249, 309; 249, 310; 250, 311; 255, 312; 255, 313; 258, 314; 258, 315; 260, 316; 260, 317; 263, 318; 263, 319; 269, 320; 269, 321; 271, 322; 273, 323; 273, 324; 274, 325; 274, 326; 275, 327; 275, 328; 279, 329; 279, 330; 286, 331; 286, 332; 288, 333; 288, 334; 290, 335; 290, 336; 292, 337; 292, 338; 294, 339; 294, 340; 295, 341; 295, 342; 297, 343; 302, 344; 302, 345; 304, 346; 305, 347; 305, 348; 306, 349; 306, 350; 307, 351; 307, 352; 308, 353; 308, 354; 311, 355; 311, 356; 321, 357; 324, 358; 327, 359; 327, 360; 328, 361; 332, 362; 332, 363; 334, 364; 334, 365; 336, 366; 338, 367; 342, 368; 343, 369; 343, 370; 344, 371; 344, 372; 345, 373; 348, 374; 350, 375; 355, 376; 356, 377; 356, 378; 357, 379; 357, 380; 358, 381; 358, 382; 361, 383; 361, 384; 361, 385; 363, 386; 363, 387; 365, 388; 365, 389; 366, 390; 366, 391; 367, 392; 367, 393; 370, 394; 370, 395; 374, 396; 374, 397; 375, 398; 375, 399; 377, 400; 377, 401; 378, 402; 380, 403; 381, 404; 381, 405; 382, 406; 382, 407; 387, 408; 389, 409; 390, 410; 390, 411; 392, 412; 392, 413; 394, 414; 394, 415; 395, 416; 396, 417; 396, 418; 398, 419; 398, 420; 402, 421; 402, 422; 402, 423; 402, 424; 405, 425; 407, 426; 410, 427; 410, 428; 411, 429; 412, 430; 412, 431; 413, 432; 416, 433; 416, 434; 417, 435; 417, 436; 421, 437; 421, 438; 422, 439; 422, 440; 423, 441; 423, 442; 424, 443; 424, 444; 425, 445; 425, 446; 426, 447; 429, 448; 429, 449; 432, 450; 432, 451; 434, 452; 438, 453; 440, 454; 446, 455; 453, 456; 453, 457; 454, 458; 454, 459; 455, 460; 455, 461; 456, 462; 456, 463; 461, 464; 462, 465; 462, 466
def chooseBestDuplicates(tped, samples, oldSamples, completion, concordance_all, prefix): """Choose the best duplicates according to the completion rate. :param tped: the ``tped`` containing the duplicated samples. :param samples: the updated position of the samples in the tped containing only duplicated samples. :param oldSamples: the original duplicated sample positions. :param completion: the completion of each of the duplicated samples. :param concordance_all: the concordance of every duplicated samples. :param prefix: the prefix of all the files. :type tped: :py:class:`numpy.array` :type samples: dict :type oldSamples: dict :type completion: :py:class:`numpy.array` :type concordance_all: dict :type prefix: str :returns: a tuple where the first element is a list of the chosen samples' indexes, the second on is the completion and the last one is the concordance (a map). These are the steps to find the best duplicated sample: 1. Sort the list of concordances. 2. Sort the list of completions. 3. Choose the best of the concordance and put in a set. 4. Choose the best of the completion and put it in a set. 5. Compute the intersection of the two sets. If there is one sample or more, then randomly choose one sample. 6. If the intersection doesn't contain at least one sample, redo steps 3 and 4, but increase the number of chosen best by one. Redo step 5 and 6 (if required). The chosen samples are written in ``prefix.chosen_samples.info``. The rest are written in ``prefix.excluded_samples.info``. """ # The output files chosenFile = None try: chosenFile = open(prefix + ".chosen_samples.info", "w") except IOError: msg = "%(prefix)s.chosen_samples.info: can't write file" % locals() raise ProgramError(msg) print >>chosenFile, "\t".join(["origIndex", "dupIndex", "famID", "indID"]) excludedFile = None try: excludedFile = open(prefix + ".excluded_samples.info", "w") except IOError: msg = "%(prefix)s.excluded_samples.info: can't write file" % locals() raise ProgramError(msg) print >>excludedFile, "\t".join(["origIndex", "dupIndex", "famID", "indID"]) # For each duplicated sample chosenIndexes = {} sampleConcordance = {} for sample, indexes in samples.iteritems(): # Getting the completion for those duplicated samples currCompletion = completion[indexes] # Sorting those completion sortedCompletionIndexes = np.argsort(currCompletion) # Getting the concordance concordance = concordance_all[sample] currConcordance = [[] for i in xrange(len(indexes))] for i in xrange(len(indexes)): indexToKeep = list(set(range(len(indexes))) - set([i])) currConcordance[i] = np.mean(concordance[i, indexToKeep]) currConcordance = np.array(currConcordance) if sample not in sampleConcordance: sampleConcordance[sample] = currConcordance # Sorting the concordance sortedConcordanceIndexes = np.argsort(currConcordance) # Trying to find the best duplicate to keep nbToCheck = 1 chosenIndex = None while nbToCheck <= len(indexes): # Getting the `nbToCheck` best value (higher to lower) completionValue = currCompletion[ sortedCompletionIndexes[nbToCheck*-1] ] concordanceValue = currConcordance[ sortedConcordanceIndexes[nbToCheck*-1] ] # Getting the indexes to consider completionToConsider = set( np.where(currCompletion >= completionValue)[0] ) concordanceToConsider = set( np.where(currConcordance >= concordanceValue)[0]) # Getting the intersection of the indexes toConsider = concordanceToConsider & completionToConsider if len(toConsider) >= 1: chosenIndex = random.choice(list(toConsider)) break nbToCheck += 1 if chosenIndex is None: msg = "Could not choose the best sample ID for {}".format(sample) raise ProgramError(msg) # Printing the chosen samples print >>chosenFile, "\t".join([str(oldSamples[sample][chosenIndex]+1), str(indexes[chosenIndex]+1), sample[0], sample[1]]) # Printing the excluded samples for i, index in enumerate(indexes): if i != chosenIndex: print >>excludedFile, "\t".join([str(oldSamples[sample][i]+1), str(index+1), sample[0], sample[1]]) chosenIndexes[sample] = indexes[chosenIndex] # Closing the output files chosenFile.close() excludedFile.close() return chosenIndexes, completion, sampleConcordance
0, module; 1, function_definition; 2, function_name:order_qc_dir; 3, parameters; 4, block; 5, identifier:dirnames; 6, expression_statement; 7, return_statement; 8, comment:"""Order the QC directory names according to their date. :param dirnames: the list of directories to merge data from. :type dirnames: list :returns: the sorted list of directories :rtype: list """; 9, call; 10, identifier:sorted; 11, argument_list; 12, identifier:dirnames; 13, keyword_argument; 14, identifier:key; 15, lambda; 16, lambda_parameters; 17, call; 18, identifier:dn; 19, attribute; 20, argument_list; 21, identifier:time; 22, identifier:strptime; 23, subscript; 24, string:"%Y-%m-%d_%H.%M.%S"; 25, call; 26, slice; 27, attribute; 28, argument_list; 29, integer:14; 30, attribute; 31, identifier:basename; 32, call; 33, identifier:os; 34, identifier:path; 35, attribute; 36, argument_list; 37, identifier:dn; 38, identifier:rstrip; 39, string:"/"
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 6, 8; 7, 9; 9, 10; 9, 11; 11, 12; 11, 13; 13, 14; 13, 15; 15, 16; 15, 17; 16, 18; 17, 19; 17, 20; 19, 21; 19, 22; 20, 23; 20, 24; 23, 25; 23, 26; 25, 27; 25, 28; 26, 29; 27, 30; 27, 31; 28, 32; 30, 33; 30, 34; 32, 35; 32, 36; 35, 37; 35, 38; 36, 39
def order_qc_dir(dirnames): """Order the QC directory names according to their date. :param dirnames: the list of directories to merge data from. :type dirnames: list :returns: the sorted list of directories :rtype: list """ return sorted( dirnames, key=lambda dn: time.strptime( os.path.basename(dn.rstrip("/"))[14:], "%Y-%m-%d_%H.%M.%S", ) )
0, module; 1, function_definition; 2, function_name:fetch; 3, parameters; 4, block; 5, identifier:self; 6, identifier:webfonts; 7, expression_statement; 8, expression_statement; 9, for_statement; 10, comment:""" Store every defined webfonts. Webfont are stored with sort on their name. Args: webfonts (dict): Dictionnary of webfont settings from ``settings.ICOMOON_WEBFONTS``. """; 11, assignment; 12, identifier:webfont_name; 13, identifier:sorted_keys; 14, block; 15, identifier:sorted_keys; 16, call; 17, expression_statement; 18, identifier:sorted; 19, argument_list; 20, call; 21, call; 22, attribute; 23, argument_list; 24, attribute; 25, argument_list; 26, identifier:self; 27, identifier:get; 28, identifier:webfont_name; 29, subscript; 30, identifier:webfonts; 31, identifier:keys; 32, identifier:webfonts; 33, identifier:webfont_name
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 7, 10; 8, 11; 9, 12; 9, 13; 9, 14; 11, 15; 11, 16; 14, 17; 16, 18; 16, 19; 17, 20; 19, 21; 20, 22; 20, 23; 21, 24; 21, 25; 22, 26; 22, 27; 23, 28; 23, 29; 24, 30; 24, 31; 29, 32; 29, 33
def fetch(self, webfonts): """ Store every defined webfonts. Webfont are stored with sort on their name. Args: webfonts (dict): Dictionnary of webfont settings from ``settings.ICOMOON_WEBFONTS``. """ sorted_keys = sorted(webfonts.keys()) for webfont_name in sorted_keys: self.get(webfont_name, webfonts[webfont_name])
0, module; 1, function_definition; 2, function_name:sort_index; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, expression_statement; 8, if_statement; 9, return_statement; 10, identifier:ascending; 11, True; 12, comment:"""Sort the index of the DataFrame. Currently MultiIndex is not supported since Weld is missing multiple-column sort. Note this is an expensive operation (brings all data to Weld). Parameters ---------- ascending : bool, optional Returns ------- DataFrame DataFrame sorted according to the index. """; 13, call; 14, block; 15, call; 16, identifier:isinstance; 17, argument_list; 18, raise_statement; 19, attribute; 20, argument_list; 21, attribute; 22, identifier:MultiIndex; 23, call; 24, identifier:self; 25, identifier:sort_values; 26, call; 27, identifier:ascending; 28, identifier:self; 29, identifier:index; 30, identifier:NotImplementedError; 31, argument_list; 32, attribute; 33, argument_list; 34, string; 35, attribute; 36, identifier:_gather_names; 37, string_content:Weld does not yet support sorting on multiple columns; 38, identifier:self; 39, identifier:index
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 6, 10; 6, 11; 7, 12; 8, 13; 8, 14; 9, 15; 13, 16; 13, 17; 14, 18; 15, 19; 15, 20; 17, 21; 17, 22; 18, 23; 19, 24; 19, 25; 20, 26; 20, 27; 21, 28; 21, 29; 23, 30; 23, 31; 26, 32; 26, 33; 31, 34; 32, 35; 32, 36; 34, 37; 35, 38; 35, 39
def sort_index(self, ascending=True): """Sort the index of the DataFrame. Currently MultiIndex is not supported since Weld is missing multiple-column sort. Note this is an expensive operation (brings all data to Weld). Parameters ---------- ascending : bool, optional Returns ------- DataFrame DataFrame sorted according to the index. """ if isinstance(self.index, MultiIndex): raise NotImplementedError('Weld does not yet support sorting on multiple columns') return self.sort_values(self.index._gather_names(), ascending)
0, module; 1, function_definition; 2, function_name:sort_values; 3, parameters; 4, block; 5, identifier:self; 6, identifier:by; 7, default_parameter; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, if_statement; 13, expression_statement; 14, expression_statement; 15, expression_statement; 16, expression_statement; 17, expression_statement; 18, expression_statement; 19, expression_statement; 20, expression_statement; 21, return_statement; 22, identifier:ascending; 23, True; 24, comment:"""Sort the DataFrame based on a column. Unlike Pandas, one can sort by data from both index and regular columns. Currently possible to sort only on a single column since Weld is missing multiple-column sort. Note this is an expensive operation (brings all data to Weld). Parameters ---------- by : str or list of str Column names to sort. ascending : bool, optional Returns ------- DataFrame DataFrame sorted according to the column. """; 25, call; 26, call; 27, assignment; 28, comparison_operator:len(by) > 1; 29, block; 30, assignment; 31, assignment; 32, assignment; 33, assignment; 34, assignment; 35, assignment; 36, assignment; 37, assignment; 38, call; 39, identifier:check_type; 40, argument_list; 41, identifier:check_str_or_list_str; 42, argument_list; 43, identifier:by; 44, call; 45, call; 46, integer:1; 47, raise_statement; 48, identifier:all_data; 49, call; 50, identifier:by_data; 51, subscript; 52, identifier:sorted_indices; 53, call; 54, identifier:new_index; 55, call; 56, identifier:new_columns; 57, call; 58, identifier:new_column_names; 59, list_comprehension; 60, identifier:new_columns; 61, list_comprehension; 62, identifier:new_data; 63, call; 64, identifier:DataFrame; 65, argument_list; 66, identifier:ascending; 67, identifier:bool; 68, identifier:by; 69, identifier:as_list; 70, argument_list; 71, identifier:len; 72, argument_list; 73, call; 74, attribute; 75, argument_list; 76, identifier:all_data; 77, identifier:by; 78, identifier:weld_sort; 79, argument_list; 80, attribute; 81, argument_list; 82, identifier:list; 83, argument_list; 84, attribute; 85, for_in_clause; 86, call; 87, for_in_clause; 88, identifier:OrderedDict; 89, argument_list; 90, identifier:new_data; 91, identifier:new_index; 92, identifier:by; 93, identifier:by; 94, identifier:NotImplementedError; 95, argument_list; 96, identifier:self; 97, identifier:reset_index; 98, call; 99, call; 100, string; 101, keyword_argument; 102, attribute; 103, identifier:_iloc_indices; 104, identifier:sorted_indices; 105, call; 106, identifier:column; 107, identifier:name; 108, identifier:column; 109, identifier:new_columns; 110, identifier:_series_iloc; 111, argument_list; 112, identifier:column; 113, identifier:new_columns; 114, call; 115, string; 116, attribute; 117, argument_list; 118, attribute; 119, argument_list; 120, string_content:sort_index; 121, identifier:ascending; 122, identifier:ascending; 123, identifier:self; 124, identifier:index; 125, attribute; 126, argument_list; 127, identifier:column; 128, identifier:sorted_indices; 129, identifier:new_index; 130, identifier:zip; 131, argument_list; 132, string_content:Weld does not yet support sorting on multiple columns; 133, identifier:by_data; 134, identifier:_gather_data_for_weld; 135, identifier:by_data; 136, identifier:_gather_weld_types; 137, identifier:self; 138, identifier:_iter; 139, identifier:new_column_names; 140, identifier:new_columns
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 4, 17; 4, 18; 4, 19; 4, 20; 4, 21; 7, 22; 7, 23; 8, 24; 9, 25; 10, 26; 11, 27; 12, 28; 12, 29; 13, 30; 14, 31; 15, 32; 16, 33; 17, 34; 18, 35; 19, 36; 20, 37; 21, 38; 25, 39; 25, 40; 26, 41; 26, 42; 27, 43; 27, 44; 28, 45; 28, 46; 29, 47; 30, 48; 30, 49; 31, 50; 31, 51; 32, 52; 32, 53; 33, 54; 33, 55; 34, 56; 34, 57; 35, 58; 35, 59; 36, 60; 36, 61; 37, 62; 37, 63; 38, 64; 38, 65; 40, 66; 40, 67; 42, 68; 44, 69; 44, 70; 45, 71; 45, 72; 47, 73; 49, 74; 49, 75; 51, 76; 51, 77; 53, 78; 53, 79; 55, 80; 55, 81; 57, 82; 57, 83; 59, 84; 59, 85; 61, 86; 61, 87; 63, 88; 63, 89; 65, 90; 65, 91; 70, 92; 72, 93; 73, 94; 73, 95; 74, 96; 74, 97; 79, 98; 79, 99; 79, 100; 79, 101; 80, 102; 80, 103; 81, 104; 83, 105; 84, 106; 84, 107; 85, 108; 85, 109; 86, 110; 86, 111; 87, 112; 87, 113; 89, 114; 95, 115; 98, 116; 98, 117; 99, 118; 99, 119; 100, 120; 101, 121; 101, 122; 102, 123; 102, 124; 105, 125; 105, 126; 111, 127; 111, 128; 111, 129; 114, 130; 114, 131; 115, 132; 116, 133; 116, 134; 118, 135; 118, 136; 125, 137; 125, 138; 131, 139; 131, 140
def sort_values(self, by, ascending=True): """Sort the DataFrame based on a column. Unlike Pandas, one can sort by data from both index and regular columns. Currently possible to sort only on a single column since Weld is missing multiple-column sort. Note this is an expensive operation (brings all data to Weld). Parameters ---------- by : str or list of str Column names to sort. ascending : bool, optional Returns ------- DataFrame DataFrame sorted according to the column. """ check_type(ascending, bool) check_str_or_list_str(by) by = as_list(by) if len(by) > 1: raise NotImplementedError('Weld does not yet support sorting on multiple columns') all_data = self.reset_index() by_data = all_data[by] sorted_indices = weld_sort(by_data._gather_data_for_weld(), by_data._gather_weld_types(), 'sort_index', ascending=ascending) new_index = self.index._iloc_indices(sorted_indices) new_columns = list(self._iter()) new_column_names = [column.name for column in new_columns] new_columns = [_series_iloc(column, sorted_indices, new_index) for column in new_columns] new_data = OrderedDict(zip(new_column_names, new_columns)) return DataFrame(new_data, new_index)
0, module; 1, function_definition; 2, function_name:optimize_with_repeates; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, expression_statement; 13, expression_statement; 14, if_statement; 15, expression_statement; 16, expression_statement; 17, comment:# minimize n_times; 18, for_statement; 19, comment:# sort by LML; 20, expression_statement; 21, expression_statement; 22, expression_statement; 23, if_statement; 24, for_statement; 25, return_statement; 26, identifier:fast; 27, None; 28, identifier:verbose; 29, None; 30, identifier:n_times; 31, integer:10; 32, identifier:lambd; 33, None; 34, identifier:lambd_g; 35, None; 36, identifier:lambd_n; 37, None; 38, comment:""" Train the model repeadly up to a number specified by the users with random restarts and return a list of all relative minima that have been found. This list is sorted according to least likelihood. Each list term is a dictionary with keys "counter", "LML", and "scales". After running this function, the vc object will be set at the last iteration. Thus, if you wish to get the vc object of one of the repeats, then set the scales. For example: vc.setScales(scales=optimize_with_repeates_output[0]["scales"]) Args: fast: Boolean. if set to True initalize kronSumGP verbose: Boolean. If set to True, verbose output is produced. (default True) n_times: number of re-starts of the optimization. (default 10) """; 39, assignment; 40, not_operator; 41, block; 42, assignment; 43, assignment; 44, identifier:i; 45, call; 46, block; 47, assignment; 48, assignment; 49, assignment; 50, identifier:verbose; 51, block; 52, identifier:i; 53, call; 54, block; 55, identifier:out; 56, identifier:verbose; 57, call; 58, attribute; 59, expression_statement; 60, identifier:opt_list; 61, list; 62, identifier:fixed0; 63, call; 64, identifier:range; 65, argument_list; 66, expression_statement; 67, expression_statement; 68, expression_statement; 69, if_statement; 70, identifier:LML; 71, call; 72, identifier:index; 73, subscript; 74, identifier:out; 75, list; 76, expression_statement; 77, expression_statement; 78, expression_statement; 79, identifier:range; 80, argument_list; 81, expression_statement; 82, if_statement; 83, attribute; 84, argument_list; 85, identifier:self; 86, identifier:init; 87, call; 88, attribute; 89, argument_list; 90, identifier:n_times; 91, assignment; 92, assignment; 93, assignment; 94, identifier:conv; 95, comment:# compare with previous minima; 96, block; 97, attribute; 98, argument_list; 99, call; 100, slice; 101, call; 102, call; 103, call; 104, call; 105, call; 106, identifier:verbose; 107, block; 108, identifier:dlimix; 109, identifier:getVerbose; 110, identifier:verbose; 111, attribute; 112, argument_list; 113, identifier:sp; 114, identifier:zeros_like; 115, subscript; 116, identifier:scales1; 117, call; 118, identifier:fixed1; 119, binary_operator:1e-1*sp.randn(fixed0.shape[0],fixed0.shape[1]); 120, identifier:conv; 121, call; 122, expression_statement; 123, for_statement; 124, if_statement; 125, identifier:sp; 126, identifier:array; 127, list_comprehension; 128, attribute; 129, argument_list; 130, unary_operator; 131, identifier:print; 132, argument_list; 133, identifier:print; 134, argument_list; 135, identifier:print; 136, argument_list; 137, identifier:len; 138, argument_list; 139, attribute; 140, argument_list; 141, expression_statement; 142, expression_statement; 143, identifier:self; 144, identifier:_initGP; 145, identifier:fast; 146, call; 147, string; 148, attribute; 149, argument_list; 150, float:1e-1; 151, call; 152, attribute; 153, argument_list; 154, assignment; 155, identifier:j; 156, call; 157, block; 158, comparison_operator:temp==1; 159, block; 160, subscript; 161, for_in_clause; 162, identifier:LML; 163, identifier:argsort; 164, integer:1; 165, string:"\nLocal mimima\n"; 166, string:"n_times\t\tLML"; 167, string:"------------------------------------"; 168, identifier:opt_list; 169, identifier:out; 170, identifier:append; 171, subscript; 172, call; 173, call; 174, attribute; 175, argument_list; 176, string_content:dataTerm; 177, identifier:self; 178, identifier:_getScalesRand; 179, attribute; 180, argument_list; 181, identifier:self; 182, identifier:trainGP; 183, keyword_argument; 184, keyword_argument; 185, keyword_argument; 186, keyword_argument; 187, keyword_argument; 188, keyword_argument; 189, identifier:temp; 190, integer:1; 191, identifier:range; 192, argument_list; 193, if_statement; 194, identifier:temp; 195, integer:1; 196, expression_statement; 197, expression_statement; 198, expression_statement; 199, expression_statement; 200, expression_statement; 201, subscript; 202, string; 203, identifier:i; 204, call; 205, identifier:opt_list; 206, subscript; 207, identifier:print; 208, argument_list; 209, identifier:print; 210, argument_list; 211, attribute; 212, identifier:getParams; 213, identifier:sp; 214, identifier:randn; 215, subscript; 216, subscript; 217, identifier:fast; 218, identifier:fast; 219, identifier:scales0; 220, identifier:scales1; 221, identifier:fixed0; 222, identifier:fixed1; 223, identifier:lambd; 224, identifier:lambd; 225, identifier:lambd_g; 226, identifier:lambd_g; 227, identifier:lambd_n; 228, identifier:lambd_n; 229, call; 230, call; 231, block; 232, assignment; 233, assignment; 234, assignment; 235, assignment; 236, call; 237, identifier:opt_list; 238, identifier:i; 239, string_content:LML; 240, identifier:range; 241, argument_list; 242, identifier:index; 243, identifier:i; 244, parenthesized_expression; 245, string:""; 246, identifier:self; 247, identifier:gp; 248, attribute; 249, integer:0; 250, attribute; 251, integer:1; 252, identifier:len; 253, argument_list; 254, attribute; 255, argument_list; 256, expression_statement; 257, expression_statement; 258, break_statement; 259, identifier:opt; 260, dictionary; 261, subscript; 262, integer:1; 263, subscript; 264, call; 265, subscript; 266, call; 267, attribute; 268, argument_list; 269, call; 270, binary_operator:"%d\t\t%f" % (opt_list[index[i]]['counter'], opt_list[index[i]]['LML']); 271, identifier:fixed0; 272, identifier:shape; 273, identifier:fixed0; 274, identifier:shape; 275, identifier:opt_list; 276, identifier:sp; 277, identifier:allclose; 278, call; 279, call; 280, assignment; 281, augmented_assignment; 282, identifier:opt; 283, string; 284, identifier:opt; 285, string; 286, attribute; 287, argument_list; 288, identifier:opt; 289, string; 290, attribute; 291, argument_list; 292, identifier:opt_list; 293, identifier:append; 294, identifier:opt; 295, identifier:len; 296, argument_list; 297, string:"%d\t\t%f"; 298, tuple; 299, identifier:abs; 300, argument_list; 301, identifier:abs; 302, argument_list; 303, identifier:temp; 304, integer:0; 305, subscript; 306, integer:1; 307, string_content:counter; 308, string_content:LML; 309, identifier:self; 310, identifier:getLML; 311, string_content:scales; 312, identifier:self; 313, identifier:getScales; 314, identifier:opt_list; 315, subscript; 316, subscript; 317, call; 318, subscript; 319, subscript; 320, string; 321, subscript; 322, string; 323, subscript; 324, string; 325, attribute; 326, argument_list; 327, subscript; 328, string; 329, identifier:opt_list; 330, identifier:j; 331, string_content:counter; 332, identifier:opt_list; 333, subscript; 334, string_content:counter; 335, identifier:opt_list; 336, subscript; 337, string_content:LML; 338, identifier:self; 339, identifier:getScales; 340, identifier:opt_list; 341, identifier:j; 342, string_content:scales; 343, identifier:index; 344, identifier:i; 345, identifier:index; 346, identifier:i
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 4, 17; 4, 18; 4, 19; 4, 20; 4, 21; 4, 22; 4, 23; 4, 24; 4, 25; 6, 26; 6, 27; 7, 28; 7, 29; 8, 30; 8, 31; 9, 32; 9, 33; 10, 34; 10, 35; 11, 36; 11, 37; 12, 38; 13, 39; 14, 40; 14, 41; 15, 42; 16, 43; 18, 44; 18, 45; 18, 46; 20, 47; 21, 48; 22, 49; 23, 50; 23, 51; 24, 52; 24, 53; 24, 54; 25, 55; 39, 56; 39, 57; 40, 58; 41, 59; 42, 60; 42, 61; 43, 62; 43, 63; 45, 64; 45, 65; 46, 66; 46, 67; 46, 68; 46, 69; 47, 70; 47, 71; 48, 72; 48, 73; 49, 74; 49, 75; 51, 76; 51, 77; 51, 78; 53, 79; 53, 80; 54, 81; 54, 82; 57, 83; 57, 84; 58, 85; 58, 86; 59, 87; 63, 88; 63, 89; 65, 90; 66, 91; 67, 92; 68, 93; 69, 94; 69, 95; 69, 96; 71, 97; 71, 98; 73, 99; 73, 100; 76, 101; 77, 102; 78, 103; 80, 104; 81, 105; 82, 106; 82, 107; 83, 108; 83, 109; 84, 110; 87, 111; 87, 112; 88, 113; 88, 114; 89, 115; 91, 116; 91, 117; 92, 118; 92, 119; 93, 120; 93, 121; 96, 122; 96, 123; 96, 124; 97, 125; 97, 126; 98, 127; 99, 128; 99, 129; 100, 130; 101, 131; 101, 132; 102, 133; 102, 134; 103, 135; 103, 136; 104, 137; 104, 138; 105, 139; 105, 140; 107, 141; 107, 142; 111, 143; 111, 144; 112, 145; 115, 146; 115, 147; 117, 148; 117, 149; 119, 150; 119, 151; 121, 152; 121, 153; 122, 154; 123, 155; 123, 156; 123, 157; 124, 158; 124, 159; 127, 160; 127, 161; 128, 162; 128, 163; 130, 164; 132, 165; 134, 166; 136, 167; 138, 168; 139, 169; 139, 170; 140, 171; 141, 172; 142, 173; 146, 174; 146, 175; 147, 176; 148, 177; 148, 178; 151, 179; 151, 180; 152, 181; 152, 182; 153, 183; 153, 184; 153, 185; 153, 186; 153, 187; 153, 188; 154, 189; 154, 190; 156, 191; 156, 192; 157, 193; 158, 194; 158, 195; 159, 196; 159, 197; 159, 198; 159, 199; 159, 200; 160, 201; 160, 202; 161, 203; 161, 204; 171, 205; 171, 206; 172, 207; 172, 208; 173, 209; 173, 210; 174, 211; 174, 212; 179, 213; 179, 214; 180, 215; 180, 216; 183, 217; 183, 218; 184, 219; 184, 220; 185, 221; 185, 222; 186, 223; 186, 224; 187, 225; 187, 226; 188, 227; 188, 228; 192, 229; 193, 230; 193, 231; 196, 232; 197, 233; 198, 234; 199, 235; 200, 236; 201, 237; 201, 238; 202, 239; 204, 240; 204, 241; 206, 242; 206, 243; 208, 244; 210, 245; 211, 246; 211, 247; 215, 248; 215, 249; 216, 250; 216, 251; 229, 252; 229, 253; 230, 254; 230, 255; 231, 256; 231, 257; 231, 258; 232, 259; 232, 260; 233, 261; 233, 262; 234, 263; 234, 264; 235, 265; 235, 266; 236, 267; 236, 268; 241, 269; 244, 270; 248, 271; 248, 272; 250, 273; 250, 274; 253, 275; 254, 276; 254, 277; 255, 278; 255, 279; 256, 280; 257, 281; 261, 282; 261, 283; 263, 284; 263, 285; 264, 286; 264, 287; 265, 288; 265, 289; 266, 290; 266, 291; 267, 292; 267, 293; 268, 294; 269, 295; 269, 296; 270, 297; 270, 298; 278, 299; 278, 300; 279, 301; 279, 302; 280, 303; 280, 304; 281, 305; 281, 306; 283, 307; 285, 308; 286, 309; 286, 310; 289, 311; 290, 312; 290, 313; 296, 314; 298, 315; 298, 316; 300, 317; 302, 318; 305, 319; 305, 320; 315, 321; 315, 322; 316, 323; 316, 324; 317, 325; 317, 326; 318, 327; 318, 328; 319, 329; 319, 330; 320, 331; 321, 332; 321, 333; 322, 334; 323, 335; 323, 336; 324, 337; 325, 338; 325, 339; 327, 340; 327, 341; 328, 342; 333, 343; 333, 344; 336, 345; 336, 346
def optimize_with_repeates(self,fast=None,verbose=None,n_times=10,lambd=None,lambd_g=None,lambd_n=None): """ Train the model repeadly up to a number specified by the users with random restarts and return a list of all relative minima that have been found. This list is sorted according to least likelihood. Each list term is a dictionary with keys "counter", "LML", and "scales". After running this function, the vc object will be set at the last iteration. Thus, if you wish to get the vc object of one of the repeats, then set the scales. For example: vc.setScales(scales=optimize_with_repeates_output[0]["scales"]) Args: fast: Boolean. if set to True initalize kronSumGP verbose: Boolean. If set to True, verbose output is produced. (default True) n_times: number of re-starts of the optimization. (default 10) """ verbose = dlimix.getVerbose(verbose) if not self.init: self._initGP(fast) opt_list = [] fixed0 = sp.zeros_like(self.gp.getParams()['dataTerm']) # minimize n_times for i in range(n_times): scales1 = self._getScalesRand() fixed1 = 1e-1*sp.randn(fixed0.shape[0],fixed0.shape[1]) conv = self.trainGP(fast=fast,scales0=scales1,fixed0=fixed1,lambd=lambd,lambd_g=lambd_g,lambd_n=lambd_n) if conv: # compare with previous minima temp=1 for j in range(len(opt_list)): if sp.allclose(abs(self.getScales()),abs(opt_list[j]['scales'])): temp=0 opt_list[j]['counter']+=1 break if temp==1: opt = {} opt['counter'] = 1 opt['LML'] = self.getLML() opt['scales'] = self.getScales() opt_list.append(opt) # sort by LML LML = sp.array([opt_list[i]['LML'] for i in range(len(opt_list))]) index = LML.argsort()[::-1] out = [] if verbose: print("\nLocal mimima\n") print("n_times\t\tLML") print("------------------------------------") for i in range(len(opt_list)): out.append(opt_list[index[i]]) if verbose: print(("%d\t\t%f" % (opt_list[index[i]]['counter'], opt_list[index[i]]['LML']))) print("") return out
0, module; 1, function_definition; 2, function_name:sort_prefixes; 3, parameters; 4, block; 5, identifier:orig; 6, default_parameter; 7, expression_statement; 8, expression_statement; 9, for_statement; 10, return_statement; 11, identifier:prefixes; 12, string; 13, comment:"""Returns a sorted list of prefixes. Args: orig (str): Unsorted list of prefixes. prefixes (str): List of prefixes, from highest-priv to lowest. """; 14, assignment; 15, identifier:prefix; 16, identifier:prefixes; 17, block; 18, identifier:new; 19, string_content:@+; 20, identifier:new; 21, string; 22, if_statement; 23, comparison_operator:prefix in orig; 24, block; 25, identifier:prefix; 26, identifier:orig; 27, expression_statement; 28, augmented_assignment; 29, identifier:new; 30, identifier:prefix
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 6, 11; 6, 12; 7, 13; 8, 14; 9, 15; 9, 16; 9, 17; 10, 18; 12, 19; 14, 20; 14, 21; 17, 22; 22, 23; 22, 24; 23, 25; 23, 26; 24, 27; 27, 28; 28, 29; 28, 30
def sort_prefixes(orig, prefixes='@+'): """Returns a sorted list of prefixes. Args: orig (str): Unsorted list of prefixes. prefixes (str): List of prefixes, from highest-priv to lowest. """ new = '' for prefix in prefixes: if prefix in orig: new += prefix return new
0, module; 1, function_definition; 2, function_name:sort_children; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, default_parameter; 8, expression_statement; 9, expression_statement; 10, if_statement; 11, expression_statement; 12, for_statement; 13, return_statement; 14, identifier:attribute; 15, None; 16, identifier:reverse_order; 17, False; 18, comment:""" Sorts the children using either the given attribute or the Node name. :param attribute: Attribute name used for sorting. :type attribute: unicode :param reverse_order: Sort in reverse order. :type reverse_order: bool :return: Method success. :rtype: bool """; 19, assignment; 20, identifier:attribute; 21, block; 22, else_clause; 23, assignment; 24, identifier:child; 25, attribute; 26, block; 27, True; 28, identifier:sorted_children; 29, list; 30, expression_statement; 31, expression_statement; 32, for_statement; 33, expression_statement; 34, expression_statement; 35, block; 36, attribute; 37, identifier:sorted_children; 38, identifier:self; 39, identifier:__children; 40, expression_statement; 41, assignment; 42, assignment; 43, identifier:child; 44, attribute; 45, block; 46, assignment; 47, call; 48, expression_statement; 49, identifier:self; 50, identifier:__children; 51, call; 52, identifier:sortable_children; 53, list; 54, identifier:unsortable_children; 55, list; 56, identifier:self; 57, identifier:__children; 58, if_statement; 59, identifier:sorted_children; 60, call; 61, attribute; 62, argument_list; 63, assignment; 64, attribute; 65, argument_list; 66, call; 67, block; 68, else_clause; 69, identifier:sorted; 70, argument_list; 71, identifier:sorted_children; 72, identifier:extend; 73, identifier:unsortable_children; 74, identifier:sorted_children; 75, call; 76, identifier:child; 77, identifier:sort_children; 78, identifier:attribute; 79, identifier:reverse_order; 80, attribute; 81, argument_list; 82, expression_statement; 83, block; 84, identifier:sortable_children; 85, keyword_argument; 86, keyword_argument; 87, identifier:sorted; 88, argument_list; 89, identifier:child; 90, identifier:attribute_exists; 91, identifier:attribute; 92, call; 93, expression_statement; 94, identifier:key; 95, lambda; 96, identifier:reverse; 97, boolean_operator; 98, attribute; 99, keyword_argument; 100, keyword_argument; 101, attribute; 102, argument_list; 103, call; 104, lambda_parameters; 105, attribute; 106, identifier:reverse_order; 107, False; 108, identifier:self; 109, identifier:children; 110, identifier:key; 111, lambda; 112, identifier:reverse; 113, boolean_operator; 114, identifier:sortable_children; 115, identifier:append; 116, identifier:child; 117, attribute; 118, argument_list; 119, identifier:x; 120, call; 121, identifier:value; 122, lambda_parameters; 123, parenthesized_expression; 124, identifier:reverse_order; 125, False; 126, identifier:unsortable_children; 127, identifier:append; 128, identifier:child; 129, identifier:getattr; 130, argument_list; 131, identifier:x; 132, attribute; 133, identifier:x; 134, identifier:attribute; 135, identifier:x; 136, identifier:name
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 6, 14; 6, 15; 7, 16; 7, 17; 8, 18; 9, 19; 10, 20; 10, 21; 10, 22; 11, 23; 12, 24; 12, 25; 12, 26; 13, 27; 19, 28; 19, 29; 21, 30; 21, 31; 21, 32; 21, 33; 21, 34; 22, 35; 23, 36; 23, 37; 25, 38; 25, 39; 26, 40; 30, 41; 31, 42; 32, 43; 32, 44; 32, 45; 33, 46; 34, 47; 35, 48; 36, 49; 36, 50; 40, 51; 41, 52; 41, 53; 42, 54; 42, 55; 44, 56; 44, 57; 45, 58; 46, 59; 46, 60; 47, 61; 47, 62; 48, 63; 51, 64; 51, 65; 58, 66; 58, 67; 58, 68; 60, 69; 60, 70; 61, 71; 61, 72; 62, 73; 63, 74; 63, 75; 64, 76; 64, 77; 65, 78; 65, 79; 66, 80; 66, 81; 67, 82; 68, 83; 70, 84; 70, 85; 70, 86; 75, 87; 75, 88; 80, 89; 80, 90; 81, 91; 82, 92; 83, 93; 85, 94; 85, 95; 86, 96; 86, 97; 88, 98; 88, 99; 88, 100; 92, 101; 92, 102; 93, 103; 95, 104; 95, 105; 97, 106; 97, 107; 98, 108; 98, 109; 99, 110; 99, 111; 100, 112; 100, 113; 101, 114; 101, 115; 102, 116; 103, 117; 103, 118; 104, 119; 105, 120; 105, 121; 111, 122; 111, 123; 113, 124; 113, 125; 117, 126; 117, 127; 118, 128; 120, 129; 120, 130; 122, 131; 123, 132; 130, 133; 130, 134; 132, 135; 132, 136
def sort_children(self, attribute=None, reverse_order=False): """ Sorts the children using either the given attribute or the Node name. :param attribute: Attribute name used for sorting. :type attribute: unicode :param reverse_order: Sort in reverse order. :type reverse_order: bool :return: Method success. :rtype: bool """ sorted_children = [] if attribute: sortable_children = [] unsortable_children = [] for child in self.__children: if child.attribute_exists(attribute): sortable_children.append(child) else: unsortable_children.append(child) sorted_children = sorted(sortable_children, key=lambda x: getattr( x, attribute).value, reverse=reverse_order or False) sorted_children.extend(unsortable_children) else: sorted_children = sorted(self.children, key=lambda x: (x.name), reverse=reverse_order or False) self.__children = sorted_children for child in self.__children: child.sort_children(attribute, reverse_order) return True
0, module; 1, function_definition; 2, function_name:_sort_kw_matches; 3, parameters; 4, block; 5, identifier:skw_matches; 6, default_parameter; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, return_statement; 11, identifier:limit; 12, integer:0; 13, comment:"""Return a resized version of keywords to the given length."""; 14, assignment; 15, call; 16, boolean_operator; 17, identifier:sorted_keywords; 18, call; 19, identifier:sorted; 20, argument_list; 21, boolean_operator; 22, identifier:sorted_keywords; 23, identifier:list; 24, argument_list; 25, identifier:sorted_keywords; 26, keyword_argument; 27, identifier:limit; 28, subscript; 29, call; 30, identifier:key; 31, call; 32, identifier:sorted_keywords; 33, slice; 34, attribute; 35, argument_list; 36, identifier:cmp_to_key; 37, argument_list; 38, identifier:limit; 39, identifier:skw_matches; 40, identifier:items; 41, identifier:_skw_matches_comparator
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 6, 11; 6, 12; 7, 13; 8, 14; 9, 15; 10, 16; 14, 17; 14, 18; 15, 19; 15, 20; 16, 21; 16, 22; 18, 23; 18, 24; 20, 25; 20, 26; 21, 27; 21, 28; 24, 29; 26, 30; 26, 31; 28, 32; 28, 33; 29, 34; 29, 35; 31, 36; 31, 37; 33, 38; 34, 39; 34, 40; 37, 41
def _sort_kw_matches(skw_matches, limit=0): """Return a resized version of keywords to the given length.""" sorted_keywords = list(skw_matches.items()) sorted(sorted_keywords, key=cmp_to_key(_skw_matches_comparator)) return limit and sorted_keywords[:limit] or sorted_keywords
0, module; 1, function_definition; 2, function_name:trim; 3, parameters; 4, block; 5, identifier:self; 6, identifier:n_peaks; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, comment:""" Sorts mass and intensities arrays in descending intensity order, then removes low-intensity peaks from the spectrum. :param n_peaks: number of peaks to keep """; 11, call; 12, call; 13, attribute; 14, argument_list; 15, attribute; 16, argument_list; 17, identifier:self; 18, identifier:sortByIntensity; 19, identifier:ims; 20, identifier:spectrum_trim; 21, attribute; 22, identifier:n_peaks; 23, identifier:self; 24, identifier:ptr
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 7, 10; 8, 11; 9, 12; 11, 13; 11, 14; 12, 15; 12, 16; 13, 17; 13, 18; 15, 19; 15, 20; 16, 21; 16, 22; 21, 23; 21, 24
def trim(self, n_peaks): """ Sorts mass and intensities arrays in descending intensity order, then removes low-intensity peaks from the spectrum. :param n_peaks: number of peaks to keep """ self.sortByIntensity() ims.spectrum_trim(self.ptr, n_peaks)
0, module; 1, function_definition; 2, function_name:centroids; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, return_statement; 14, identifier:window_size; 15, integer:5; 16, comment:""" Detects peaks in raw data. :param mzs: sorted array of m/z values :param intensities: array of corresponding intensities :param window_size: size of m/z averaging window :returns: isotope pattern containing the centroids :rtype: CentroidedSpectrum """; 17, call; 18, assignment; 19, assignment; 20, assignment; 21, assignment; 22, call; 23, attribute; 24, argument_list; 25, identifier:mzs; 26, call; 27, identifier:intensities; 28, call; 29, identifier:n; 30, attribute; 31, identifier:p; 32, call; 33, identifier:_new_spectrum; 34, argument_list; 35, identifier:self; 36, identifier:sortByMass; 37, identifier:_cffi_buffer; 38, argument_list; 39, identifier:_cffi_buffer; 40, argument_list; 41, identifier:self; 42, identifier:size; 43, attribute; 44, argument_list; 45, identifier:CentroidedSpectrum; 46, identifier:p; 47, attribute; 48, string; 49, attribute; 50, string; 51, identifier:ims; 52, identifier:spectrum_new_from_raw; 53, identifier:n; 54, attribute; 55, attribute; 56, call; 57, identifier:self; 58, identifier:masses; 59, string_content:d; 60, identifier:self; 61, identifier:intensities; 62, string_content:f; 63, identifier:mzs; 64, identifier:ptr; 65, identifier:intensities; 66, identifier:ptr; 67, identifier:int; 68, argument_list; 69, identifier:window_size
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 6, 14; 6, 15; 7, 16; 8, 17; 9, 18; 10, 19; 11, 20; 12, 21; 13, 22; 17, 23; 17, 24; 18, 25; 18, 26; 19, 27; 19, 28; 20, 29; 20, 30; 21, 31; 21, 32; 22, 33; 22, 34; 23, 35; 23, 36; 26, 37; 26, 38; 28, 39; 28, 40; 30, 41; 30, 42; 32, 43; 32, 44; 34, 45; 34, 46; 38, 47; 38, 48; 40, 49; 40, 50; 43, 51; 43, 52; 44, 53; 44, 54; 44, 55; 44, 56; 47, 57; 47, 58; 48, 59; 49, 60; 49, 61; 50, 62; 54, 63; 54, 64; 55, 65; 55, 66; 56, 67; 56, 68; 68, 69
def centroids(self, window_size=5): """ Detects peaks in raw data. :param mzs: sorted array of m/z values :param intensities: array of corresponding intensities :param window_size: size of m/z averaging window :returns: isotope pattern containing the centroids :rtype: CentroidedSpectrum """ self.sortByMass() mzs = _cffi_buffer(self.masses, 'd') intensities = _cffi_buffer(self.intensities, 'f') n = self.size p = ims.spectrum_new_from_raw(n, mzs.ptr, intensities.ptr, int(window_size)) return _new_spectrum(CentroidedSpectrum, p)
0, module; 1, function_definition; 2, function_name:list_engines_by_priority; 3, parameters; 4, block; 5, default_parameter; 6, expression_statement; 7, if_statement; 8, return_statement; 9, identifier:engines; 10, None; 11, comment:""" Return a list of engines supported sorted by each priority. """; 12, comparison_operator:engines is None; 13, block; 14, call; 15, identifier:engines; 16, None; 17, expression_statement; 18, identifier:sorted; 19, argument_list; 20, assignment; 21, identifier:engines; 22, keyword_argument; 23, identifier:engines; 24, identifier:ENGINES; 25, identifier:key; 26, call; 27, attribute; 28, argument_list; 29, identifier:operator; 30, identifier:methodcaller; 31, string:"priority"
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 4, 8; 5, 9; 5, 10; 6, 11; 7, 12; 7, 13; 8, 14; 12, 15; 12, 16; 13, 17; 14, 18; 14, 19; 17, 20; 19, 21; 19, 22; 20, 23; 20, 24; 22, 25; 22, 26; 26, 27; 26, 28; 27, 29; 27, 30; 28, 31
def list_engines_by_priority(engines=None): """ Return a list of engines supported sorted by each priority. """ if engines is None: engines = ENGINES return sorted(engines, key=operator.methodcaller("priority"))
0, module; 1, function_definition; 2, function_name:union; 3, parameters; 4, block; 5, identifier:dict1; 6, identifier:dict2; 7, expression_statement; 8, for_statement; 9, return_statement; 10, comment:""" Deep merge of dict2 into dict1. May be dictionaries or dictobj's. Values in dict2 will replace values in dict1 where they vary but have the same key. When lists are encountered, the dict2 list will replace the dict1 list. This will alter the first dictionary. The returned result is dict1, but it will have references to both dictionaries. If you do not want this, use union_copy(), which is less efficient but data-safe. >>> a = dict(a=dict(b=dict(c=1))) >>> b = dict(a=dict(b=dict(d=2)),e=[1,2]) >>> # sorted json so that it is predictably the same >>> import json >>> json.dumps(union(a, b), sort_keys=True) '{"a": {"b": {"c": 1, "d": 2}}, "e": [1, 2]}' >>> json.dumps(a, sort_keys=True) '{"a": {"b": {"c": 1, "d": 2}}, "e": [1, 2]}' >>> json.dumps(b, sort_keys=True) '{"a": {"b": {"d": 2}}, "e": [1, 2]}' >>> a['e'][0] = 3 >>> json.dumps(a, sort_keys=True) '{"a": {"b": {"c": 1, "d": 2}}, "e": [3, 2]}' >>> json.dumps(b, sort_keys=True) '{"a": {"b": {"d": 2}}, "e": [3, 2]}' """; 11, pattern_list; 12, call; 13, block; 14, identifier:dict1; 15, identifier:key; 16, identifier:value; 17, attribute; 18, argument_list; 19, if_statement; 20, identifier:dict2; 21, identifier:items; 22, boolean_operator; 23, block; 24, else_clause; 25, comparison_operator:key in dict1; 26, call; 27, expression_statement; 28, block; 29, identifier:key; 30, identifier:dict1; 31, identifier:isinstance; 32, argument_list; 33, assignment; 34, expression_statement; 35, identifier:value; 36, identifier:dict; 37, subscript; 38, call; 39, assignment; 40, identifier:dict1; 41, identifier:key; 42, identifier:union; 43, argument_list; 44, subscript; 45, identifier:value; 46, subscript; 47, identifier:value; 48, identifier:dict1; 49, identifier:key; 50, identifier:dict1; 51, identifier:key
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 7, 10; 8, 11; 8, 12; 8, 13; 9, 14; 11, 15; 11, 16; 12, 17; 12, 18; 13, 19; 17, 20; 17, 21; 19, 22; 19, 23; 19, 24; 22, 25; 22, 26; 23, 27; 24, 28; 25, 29; 25, 30; 26, 31; 26, 32; 27, 33; 28, 34; 32, 35; 32, 36; 33, 37; 33, 38; 34, 39; 37, 40; 37, 41; 38, 42; 38, 43; 39, 44; 39, 45; 43, 46; 43, 47; 44, 48; 44, 49; 46, 50; 46, 51
def union(dict1, dict2): """ Deep merge of dict2 into dict1. May be dictionaries or dictobj's. Values in dict2 will replace values in dict1 where they vary but have the same key. When lists are encountered, the dict2 list will replace the dict1 list. This will alter the first dictionary. The returned result is dict1, but it will have references to both dictionaries. If you do not want this, use union_copy(), which is less efficient but data-safe. >>> a = dict(a=dict(b=dict(c=1))) >>> b = dict(a=dict(b=dict(d=2)),e=[1,2]) >>> # sorted json so that it is predictably the same >>> import json >>> json.dumps(union(a, b), sort_keys=True) '{"a": {"b": {"c": 1, "d": 2}}, "e": [1, 2]}' >>> json.dumps(a, sort_keys=True) '{"a": {"b": {"c": 1, "d": 2}}, "e": [1, 2]}' >>> json.dumps(b, sort_keys=True) '{"a": {"b": {"d": 2}}, "e": [1, 2]}' >>> a['e'][0] = 3 >>> json.dumps(a, sort_keys=True) '{"a": {"b": {"c": 1, "d": 2}}, "e": [3, 2]}' >>> json.dumps(b, sort_keys=True) '{"a": {"b": {"d": 2}}, "e": [3, 2]}' """ for key, value in dict2.items(): if key in dict1 and isinstance(value, dict): dict1[key] = union(dict1[key], value) else: dict1[key] = value return dict1
0, module; 1, function_definition; 2, function_name:_format_data; 3, parameters; 4, block; 5, identifier:self; 6, identifier:data; 7, expression_statement; 8, return_statement; 9, comment:""" Sort the data in blue wavelengths to red, and ignore any spectra that have entirely non-finite or negative fluxes. """; 10, list_comprehension; 11, identifier:spectrum; 12, for_in_clause; 13, if_clause; 14, identifier:spectrum; 15, line_continuation:\; 16, call; 17, call; 18, identifier:sorted; 19, argument_list; 20, attribute; 21, argument_list; 22, conditional_expression:data if isinstance(data, (list, tuple)) else [data]; 23, keyword_argument; 24, identifier:np; 25, identifier:any; 26, call; 27, identifier:data; 28, call; 29, list; 30, identifier:key; 31, lambda; 32, attribute; 33, argument_list; 34, identifier:isinstance; 35, argument_list; 36, identifier:data; 37, lambda_parameters; 38, subscript; 39, identifier:np; 40, identifier:isfinite; 41, attribute; 42, identifier:data; 43, tuple; 44, identifier:x; 45, attribute; 46, integer:0; 47, identifier:spectrum; 48, identifier:flux; 49, identifier:list; 50, identifier:tuple; 51, identifier:x; 52, identifier:disp
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 7, 9; 8, 10; 10, 11; 10, 12; 10, 13; 12, 14; 12, 15; 12, 16; 13, 17; 16, 18; 16, 19; 17, 20; 17, 21; 19, 22; 19, 23; 20, 24; 20, 25; 21, 26; 22, 27; 22, 28; 22, 29; 23, 30; 23, 31; 26, 32; 26, 33; 28, 34; 28, 35; 29, 36; 31, 37; 31, 38; 32, 39; 32, 40; 33, 41; 35, 42; 35, 43; 37, 44; 38, 45; 38, 46; 41, 47; 41, 48; 43, 49; 43, 50; 45, 51; 45, 52
def _format_data(self, data): """ Sort the data in blue wavelengths to red, and ignore any spectra that have entirely non-finite or negative fluxes. """ return [spectrum for spectrum in \ sorted(data if isinstance(data, (list, tuple)) else [data], key=lambda x: x.disp[0]) if np.any(np.isfinite(spectrum.flux))]
0, module; 1, function_definition; 2, function_name:get_sorting; 3, parameters; 4, block; 5, identifier:self; 6, identifier:request; 7, dictionary_splat_pattern; 8, expression_statement; 9, expression_statement; 10, if_statement; 11, expression_statement; 12, return_statement; 13, identifier:resources; 14, comment:""" Get sorting options. :return list: sorting order """; 15, assignment; 16, not_operator; 17, block; 18, assignment; 19, call; 20, identifier:sorting; 21, list; 22, attribute; 23, return_statement; 24, identifier:prefix; 25, binary_operator:self._meta.dyn_prefix + 'sort'; 26, attribute; 27, argument_list; 28, identifier:request; 29, identifier:GET; 30, identifier:sorting; 31, attribute; 32, string; 33, attribute; 34, identifier:getlist; 35, identifier:prefix; 36, attribute; 37, identifier:dyn_prefix; 38, string_content:sort; 39, identifier:request; 40, identifier:GET; 41, identifier:self; 42, identifier:_meta
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 7, 13; 8, 14; 9, 15; 10, 16; 10, 17; 11, 18; 12, 19; 15, 20; 15, 21; 16, 22; 17, 23; 18, 24; 18, 25; 19, 26; 19, 27; 22, 28; 22, 29; 23, 30; 25, 31; 25, 32; 26, 33; 26, 34; 27, 35; 31, 36; 31, 37; 32, 38; 33, 39; 33, 40; 36, 41; 36, 42
def get_sorting(self, request, **resources): """ Get sorting options. :return list: sorting order """ sorting = [] if not request.GET: return sorting prefix = self._meta.dyn_prefix + 'sort' return request.GET.getlist(prefix)
0, module; 1, function_definition; 2, function_name:sort; 3, parameters; 4, block; 5, identifier:self; 6, list_splat_pattern; 7, expression_statement; 8, expression_statement; 9, for_statement; 10, return_statement; 11, identifier:sort_tuples; 12, string; 13, assignment; 14, pattern_list; 15, identifier:sort_tuples; 16, block; 17, identifier:query; 18, string_content:pymongo-style sorting. Accepts a list of tuples. :param sort_tuples: varargs of sort tuples.; 19, identifier:query; 20, identifier:self; 21, identifier:name; 22, identifier:direction; 23, expression_statement; 24, if_statement; 25, assignment; 26, comparison_operator:direction in (ASCENDING, 1); 27, block; 28, elif_clause; 29, else_clause; 30, identifier:field; 31, call; 32, identifier:direction; 33, tuple; 34, expression_statement; 35, comparison_operator:direction in (DESCENDING, -1); 36, block; 37, block; 38, identifier:resolve_name; 39, argument_list; 40, identifier:ASCENDING; 41, integer:1; 42, assignment; 43, identifier:direction; 44, tuple; 45, expression_statement; 46, raise_statement; 47, attribute; 48, identifier:name; 49, identifier:query; 50, call; 51, identifier:DESCENDING; 52, unary_operator; 53, assignment; 54, call; 55, identifier:self; 56, identifier:type; 57, attribute; 58, argument_list; 59, integer:1; 60, identifier:query; 61, call; 62, identifier:BadQueryException; 63, argument_list; 64, identifier:query; 65, identifier:ascending; 66, identifier:field; 67, attribute; 68, argument_list; 69, binary_operator:'Bad sort direction: %s' % direction; 70, identifier:query; 71, identifier:descending; 72, identifier:field; 73, string; 74, identifier:direction; 75, string_content:Bad sort direction: %s
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 6, 11; 7, 12; 8, 13; 9, 14; 9, 15; 9, 16; 10, 17; 12, 18; 13, 19; 13, 20; 14, 21; 14, 22; 16, 23; 16, 24; 23, 25; 24, 26; 24, 27; 24, 28; 24, 29; 25, 30; 25, 31; 26, 32; 26, 33; 27, 34; 28, 35; 28, 36; 29, 37; 31, 38; 31, 39; 33, 40; 33, 41; 34, 42; 35, 43; 35, 44; 36, 45; 37, 46; 39, 47; 39, 48; 42, 49; 42, 50; 44, 51; 44, 52; 45, 53; 46, 54; 47, 55; 47, 56; 50, 57; 50, 58; 52, 59; 53, 60; 53, 61; 54, 62; 54, 63; 57, 64; 57, 65; 58, 66; 61, 67; 61, 68; 63, 69; 67, 70; 67, 71; 68, 72; 69, 73; 69, 74; 73, 75
def sort(self, *sort_tuples): ''' pymongo-style sorting. Accepts a list of tuples. :param sort_tuples: varargs of sort tuples. ''' query = self for name, direction in sort_tuples: field = resolve_name(self.type, name) if direction in (ASCENDING, 1): query = query.ascending(field) elif direction in (DESCENDING, -1): query = query.descending(field) else: raise BadQueryException('Bad sort direction: %s' % direction) return query
0, module; 1, function_definition; 2, function_name:_has_bad_coords; 3, parameters; 4, block; 5, identifier:root; 6, identifier:stream; 7, expression_statement; 8, if_statement; 9, if_statement; 10, expression_statement; 11, if_statement; 12, return_statement; 13, comment:""" Predicate function encapsulating 'data clean up' filter code. Currently minimal, but these sort of functions tend to grow over time. Problem 1: Some of the GCN packets have an RA /Dec equal to (0,0) in the WhereWhen, and a flag in the What signifying that those are actually dummy co-ords. (This is used for time-stamping an event which is not localised). So, we don't load those positions, to avoid muddying the database corpus. Problem 2: com.dc3/dc3.broker#BrokerTest packets have dummy RA/Dec values, with no units specified. (They're also marked role=test, so it's not such a big deal, but it generates a lot of debug-log churn.) """; 14, comparison_operator:stream == "com.dc3/dc3.broker"; 15, block; 16, not_operator; 17, block; 18, assignment; 19, comparison_operator:"Coords_String" in toplevel_params; 20, block; 21, False; 22, identifier:stream; 23, string:"com.dc3/dc3.broker"; 24, return_statement; 25, comparison_operator:stream.split('/')[0] == 'nasa.gsfc.gcn'; 26, return_statement; 27, identifier:toplevel_params; 28, call; 29, string:"Coords_String"; 30, identifier:toplevel_params; 31, if_statement; 32, True; 33, subscript; 34, string; 35, False; 36, attribute; 37, argument_list; 38, parenthesized_expression; 39, block; 40, call; 41, integer:0; 42, string_content:nasa.gsfc.gcn; 43, identifier:vp; 44, identifier:get_toplevel_params; 45, identifier:root; 46, comparison_operator:toplevel_params["Coords_String"]['value'] == "unavailable/inappropriate"; 47, return_statement; 48, attribute; 49, argument_list; 50, subscript; 51, string:"unavailable/inappropriate"; 52, True; 53, identifier:stream; 54, identifier:split; 55, string; 56, subscript; 57, string; 58, string_content:/; 59, identifier:toplevel_params; 60, string:"Coords_String"; 61, string_content:value
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 7, 13; 8, 14; 8, 15; 9, 16; 9, 17; 10, 18; 11, 19; 11, 20; 12, 21; 14, 22; 14, 23; 15, 24; 16, 25; 17, 26; 18, 27; 18, 28; 19, 29; 19, 30; 20, 31; 24, 32; 25, 33; 25, 34; 26, 35; 28, 36; 28, 37; 31, 38; 31, 39; 33, 40; 33, 41; 34, 42; 36, 43; 36, 44; 37, 45; 38, 46; 39, 47; 40, 48; 40, 49; 46, 50; 46, 51; 47, 52; 48, 53; 48, 54; 49, 55; 50, 56; 50, 57; 55, 58; 56, 59; 56, 60; 57, 61
def _has_bad_coords(root, stream): """ Predicate function encapsulating 'data clean up' filter code. Currently minimal, but these sort of functions tend to grow over time. Problem 1: Some of the GCN packets have an RA /Dec equal to (0,0) in the WhereWhen, and a flag in the What signifying that those are actually dummy co-ords. (This is used for time-stamping an event which is not localised). So, we don't load those positions, to avoid muddying the database corpus. Problem 2: com.dc3/dc3.broker#BrokerTest packets have dummy RA/Dec values, with no units specified. (They're also marked role=test, so it's not such a big deal, but it generates a lot of debug-log churn.) """ if stream == "com.dc3/dc3.broker": return True if not stream.split('/')[0] == 'nasa.gsfc.gcn': return False toplevel_params = vp.get_toplevel_params(root) if "Coords_String" in toplevel_params: if (toplevel_params["Coords_String"]['value'] == "unavailable/inappropriate"): return True return False
0, module; 1, function_definition; 2, function_name:sorted_chain; 3, parameters; 4, type; 5, block; 6, typed_parameter; 7, generic_type; 8, expression_statement; 9, return_statement; 10, list_splat_pattern; 11, type; 12, identifier:List; 13, type_parameter; 14, comment:"""Chain & sort ranges."""; 15, call; 16, identifier:ranges; 17, generic_type; 18, type; 19, identifier:sorted; 20, argument_list; 21, identifier:Iterable; 22, type_parameter; 23, generic_type; 24, call; 25, type; 26, identifier:Tuple; 27, type_parameter; 28, attribute; 29, argument_list; 30, generic_type; 31, type; 32, type; 33, identifier:itertools; 34, identifier:chain; 35, list_splat; 36, identifier:Tuple; 37, type_parameter; 38, identifier:int; 39, identifier:int; 40, identifier:ranges; 41, type; 42, type; 43, identifier:int; 44, identifier:int
0, 1; 1, 2; 1, 3; 1, 4; 1, 5; 3, 6; 4, 7; 5, 8; 5, 9; 6, 10; 6, 11; 7, 12; 7, 13; 8, 14; 9, 15; 10, 16; 11, 17; 13, 18; 15, 19; 15, 20; 17, 21; 17, 22; 18, 23; 20, 24; 22, 25; 23, 26; 23, 27; 24, 28; 24, 29; 25, 30; 27, 31; 27, 32; 28, 33; 28, 34; 29, 35; 30, 36; 30, 37; 31, 38; 32, 39; 35, 40; 37, 41; 37, 42; 41, 43; 42, 44
def sorted_chain(*ranges: Iterable[Tuple[int, int]]) -> List[Tuple[int, int]]: """Chain & sort ranges.""" return sorted(itertools.chain(*ranges))
0, module; 1, function_definition; 2, function_name:partition_range; 3, parameters; 4, block; 5, identifier:stop; 6, default_parameter; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, comment:# We loop over the range, only touching positions where levels potentially; 12, comment:# change.; 13, for_statement; 14, return_statement; 15, identifier:annotations; 16, None; 17, comment:""" Partition the range from 0 to `stop` based on annotations. >>> partition_range(50, annotations=[[(0, 21), (30, 35)], ... [(15, 32), (40, 46)]]) [(0, 15, {0}), (15, 21, {0, 1}), (21, 30, {1}), (30, 32, {0, 1}), (32, 35, {0}), (35, 40, set()), (40, 46, {1}), (46, 50, set())] :arg stop: End point (not included) of the range (similar to the `stop` argument of the built-in :func:`range` function). :type stop: int :arg annotations: For each annotation level, a list of (`start`, `stop`) pairs defining an annotated region. :type annotations: list :return: Partitioning of the range as (`start`, `stop`, `levels`) tuples defining a region with a set of annotation levels. :rtype: list All regions (`start`, `stop`) are defined as in slicing notation, so zero-based and `stop` is not included. The `annotations` argument is a list of annotations. An annotation is a list of regions as (`start`, `stop`) tuples. The level of each annotation is its index in `annotations`. Annotation regions can overlap (overlap within one level is ignored) and do not need to be sorted. """; 18, assignment; 19, assignment; 20, assignment; 21, identifier:p; 22, call; 23, block; 24, identifier:partitioning; 25, identifier:annotations; 26, boolean_operator; 27, identifier:partitioning; 28, list; 29, pattern_list; 30, expression_list; 31, identifier:sorted; 32, argument_list; 33, if_statement; 34, comment:# Annotation levels for position p.; 35, expression_statement; 36, if_statement; 37, if_statement; 38, identifier:annotations; 39, list; 40, identifier:part_start; 41, identifier:part_levels; 42, integer:0; 43, None; 44, call; 45, comparison_operator:p == stop; 46, block; 47, assignment; 48, comparison_operator:p == 0; 49, block; 50, comparison_operator:levels != part_levels; 51, block; 52, identifier:set; 53, argument_list; 54, identifier:p; 55, identifier:stop; 56, expression_statement; 57, break_statement; 58, identifier:levels; 59, set_comprehension; 60, identifier:p; 61, integer:0; 62, expression_statement; 63, continue_statement; 64, identifier:levels; 65, identifier:part_levels; 66, expression_statement; 67, expression_statement; 68, call; 69, call; 70, identifier:level; 71, for_in_clause; 72, if_clause; 73, assignment; 74, call; 75, assignment; 76, attribute; 77, argument_list; 78, attribute; 79, argument_list; 80, pattern_list; 81, call; 82, call; 83, identifier:part_levels; 84, identifier:levels; 85, attribute; 86, argument_list; 87, pattern_list; 88, expression_list; 89, identifier:itertools; 90, identifier:chain; 91, list; 92, list_splat; 93, identifier:partitioning; 94, identifier:append; 95, tuple; 96, identifier:level; 97, identifier:regions; 98, identifier:enumerate; 99, argument_list; 100, identifier:any; 101, generator_expression; 102, identifier:partitioning; 103, identifier:append; 104, tuple; 105, identifier:part_start; 106, identifier:part_levels; 107, identifier:p; 108, identifier:levels; 109, integer:0; 110, identifier:stop; 111, call; 112, identifier:part_start; 113, identifier:p; 114, identifier:part_levels; 115, identifier:annotations; 116, comparison_operator:x <= p < y; 117, for_in_clause; 118, identifier:part_start; 119, identifier:p; 120, identifier:part_levels; 121, attribute; 122, argument_list; 123, identifier:x; 124, identifier:p; 125, identifier:y; 126, pattern_list; 127, identifier:regions; 128, identifier:itertools; 129, identifier:chain; 130, list_splat; 131, identifier:x; 132, identifier:y; 133, identifier:annotations
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 6, 15; 6, 16; 7, 17; 8, 18; 9, 19; 10, 20; 13, 21; 13, 22; 13, 23; 14, 24; 18, 25; 18, 26; 19, 27; 19, 28; 20, 29; 20, 30; 22, 31; 22, 32; 23, 33; 23, 34; 23, 35; 23, 36; 23, 37; 26, 38; 26, 39; 29, 40; 29, 41; 30, 42; 30, 43; 32, 44; 33, 45; 33, 46; 35, 47; 36, 48; 36, 49; 37, 50; 37, 51; 44, 52; 44, 53; 45, 54; 45, 55; 46, 56; 46, 57; 47, 58; 47, 59; 48, 60; 48, 61; 49, 62; 49, 63; 50, 64; 50, 65; 51, 66; 51, 67; 53, 68; 56, 69; 59, 70; 59, 71; 59, 72; 62, 73; 66, 74; 67, 75; 68, 76; 68, 77; 69, 78; 69, 79; 71, 80; 71, 81; 72, 82; 73, 83; 73, 84; 74, 85; 74, 86; 75, 87; 75, 88; 76, 89; 76, 90; 77, 91; 77, 92; 78, 93; 78, 94; 79, 95; 80, 96; 80, 97; 81, 98; 81, 99; 82, 100; 82, 101; 85, 102; 85, 103; 86, 104; 87, 105; 87, 106; 88, 107; 88, 108; 91, 109; 91, 110; 92, 111; 95, 112; 95, 113; 95, 114; 99, 115; 101, 116; 101, 117; 104, 118; 104, 119; 104, 120; 111, 121; 111, 122; 116, 123; 116, 124; 116, 125; 117, 126; 117, 127; 121, 128; 121, 129; 122, 130; 126, 131; 126, 132; 130, 133
def partition_range(stop, annotations=None): """ Partition the range from 0 to `stop` based on annotations. >>> partition_range(50, annotations=[[(0, 21), (30, 35)], ... [(15, 32), (40, 46)]]) [(0, 15, {0}), (15, 21, {0, 1}), (21, 30, {1}), (30, 32, {0, 1}), (32, 35, {0}), (35, 40, set()), (40, 46, {1}), (46, 50, set())] :arg stop: End point (not included) of the range (similar to the `stop` argument of the built-in :func:`range` function). :type stop: int :arg annotations: For each annotation level, a list of (`start`, `stop`) pairs defining an annotated region. :type annotations: list :return: Partitioning of the range as (`start`, `stop`, `levels`) tuples defining a region with a set of annotation levels. :rtype: list All regions (`start`, `stop`) are defined as in slicing notation, so zero-based and `stop` is not included. The `annotations` argument is a list of annotations. An annotation is a list of regions as (`start`, `stop`) tuples. The level of each annotation is its index in `annotations`. Annotation regions can overlap (overlap within one level is ignored) and do not need to be sorted. """ annotations = annotations or [] partitioning = [] part_start, part_levels = 0, None # We loop over the range, only touching positions where levels potentially # change. for p in sorted(set(itertools.chain([0, stop], *itertools.chain(*annotations)))): if p == stop: partitioning.append( (part_start, p, part_levels) ) break # Annotation levels for position p. levels = {level for level, regions in enumerate(annotations) if any(x <= p < y for x, y in regions)} if p == 0: part_levels = levels continue if levels != part_levels: partitioning.append( (part_start, p, part_levels) ) part_start, part_levels = p, levels return partitioning
0, module; 1, function_definition; 2, function_name:pprint_sequence; 3, parameters; 4, block; 5, identifier:sequence; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, comment:# The maximum length for positions is the 10_log of the length of the; 14, comment:# sequence.; 15, expression_statement; 16, expression_statement; 17, for_statement; 18, return_statement; 19, identifier:annotations; 20, None; 21, identifier:block_length; 22, integer:10; 23, identifier:blocks_per_line; 24, integer:6; 25, identifier:format; 26, identifier:PlaintextFormat; 27, comment:""" Pretty-print sequence for use with a monospace font. >>> sequence = 'MIMANQPLWLDSEVEMNHYQQSHIKSKSPYFPEDKHICWIKIFKAFGT' * 4 >>> print pprint_sequence(sequence, format=PlaintextFormat) 1 MIMANQPLWL DSEVEMNHYQ QSHIKSKSPY FPEDKHICWI KIFKAFGTMI MANQPLWLDS 61 EVEMNHYQQS HIKSKSPYFP EDKHICWIKI FKAFGTMIMA NQPLWLDSEV EMNHYQQSHI 121 KSKSPYFPED KHICWIKIFK AFGTMIMANQ PLWLDSEVEM NHYQQSHIKS KSPYFPEDKH 181 ICWIKIFKAF GT :arg sequence: Sequence to pretty-print. :type sequence: str or any sliceable yielding slices representable as strings. :arg annotations: For each annotation level, a list of (`start`, `stop`) pairs defining an annotated region. :type annotations: list :arg block_length: Length of space-separated blocks. :type block_length: int :arg blocks_per_line: Number of blocks per line. :type blocks_per_line: int :arg format: Output format to use for pretty-printing. Some formats are pre-defined as :data:`HtmlFormat`, :data:`AnsiFormat`, and :data:`PlaintextFormat`. :type format: :class:`Format` :return: Pretty-printed version of `sequence`. :rtype: str All regions (`start`, `stop`) are defined as in slicing notation, so zero-based and `stop` is not included. The `annotations` argument is a list of annotations. An annotation is a list of regions as (`start`, `stop`) tuples. The level of each annotation is its index in `annotations`. Annotation regions can overlap (overlap within one level is ignored) and do not need to be sorted. The number of annotation levels supported depends on `format`. :data:`HtmlFormat` supports 10 levels, :data:`AnsiFormat` supports 3 levels and annotations are ignored completely with :data:`PlaintextFormat`. """; 28, assignment; 29, assignment; 30, assignment; 31, assignment; 32, identifier:p; 33, call; 34, comment:# Partitioning of the block starting at position p.; 35, block; 36, identifier:result; 37, identifier:annotations; 38, boolean_operator; 39, identifier:partitioning; 40, call; 41, identifier:margin; 42, binary_operator:int(math.floor(math.log(max(len(sequence), 1), 10)) + 1) + len(format.margin[0]); 43, identifier:result; 44, binary_operator:(format.margin[0] + '1').rjust(margin) + format.margin[1] + ' '; 45, identifier:range; 46, argument_list; 47, expression_statement; 48, expression_statement; 49, for_statement; 50, if_statement; 51, identifier:annotations; 52, list; 53, identifier:partition_range; 54, argument_list; 55, call; 56, call; 57, binary_operator:(format.margin[0] + '1').rjust(margin) + format.margin[1]; 58, string; 59, integer:0; 60, call; 61, identifier:block_length; 62, assignment; 63, augmented_assignment; 64, pattern_list; 65, identifier:block; 66, block; 67, parenthesized_expression; 68, block; 69, call; 70, identifier:annotations; 71, identifier:int; 72, argument_list; 73, identifier:len; 74, argument_list; 75, call; 76, subscript; 77, string_content:; 78, identifier:len; 79, argument_list; 80, identifier:block; 81, list_comprehension; 82, identifier:result; 83, string; 84, identifier:start; 85, identifier:stop; 86, identifier:levels; 87, expression_statement; 88, expression_statement; 89, boolean_operator; 90, expression_statement; 91, identifier:len; 92, argument_list; 93, binary_operator:math.floor(math.log(max(len(sequence), 1), 10)) + 1; 94, subscript; 95, attribute; 96, argument_list; 97, attribute; 98, integer:1; 99, identifier:sequence; 100, tuple; 101, for_in_clause; 102, if_clause; 103, string_content:; 104, assignment; 105, augmented_assignment; 106, not_operator; 107, comparison_operator:p + block_length < len(sequence); 108, augmented_assignment; 109, identifier:sequence; 110, call; 111, integer:1; 112, attribute; 113, integer:0; 114, parenthesized_expression; 115, identifier:rjust; 116, identifier:margin; 117, identifier:format; 118, identifier:margin; 119, call; 120, call; 121, identifier:levels; 122, pattern_list; 123, identifier:partitioning; 124, boolean_operator; 125, identifier:delimiters; 126, list_comprehension; 127, identifier:result; 128, parenthesized_expression; 129, binary_operator:(p + block_length) % (block_length * blocks_per_line); 130, binary_operator:p + block_length; 131, call; 132, identifier:result; 133, parenthesized_expression; 134, attribute; 135, argument_list; 136, identifier:format; 137, identifier:margin; 138, binary_operator:format.margin[0] + '1'; 139, identifier:max; 140, argument_list; 141, identifier:min; 142, argument_list; 143, identifier:start; 144, identifier:stop; 145, identifier:levels; 146, comparison_operator:start < p + block_length; 147, comparison_operator:stop > p; 148, tuple; 149, for_in_clause; 150, if_clause; 151, binary_operator:''.join(left for left, right in reversed(delimiters)) + str(sequence[start:stop]) + ''.join(right for left, right in delimiters); 152, parenthesized_expression; 153, parenthesized_expression; 154, identifier:p; 155, identifier:block_length; 156, identifier:len; 157, argument_list; 158, binary_operator:'\n' + (format.margin[0] + str(p + block_length + 1)).rjust(margin) + format.margin[1] + ' '; 159, identifier:math; 160, identifier:floor; 161, call; 162, subscript; 163, string; 164, identifier:start; 165, identifier:p; 166, identifier:stop; 167, binary_operator:p + block_length; 168, identifier:start; 169, binary_operator:p + block_length; 170, identifier:stop; 171, identifier:p; 172, identifier:left; 173, identifier:right; 174, pattern_list; 175, call; 176, comparison_operator:level in levels; 177, binary_operator:''.join(left for left, right in reversed(delimiters)) + str(sequence[start:stop]); 178, call; 179, binary_operator:p + block_length; 180, binary_operator:block_length * blocks_per_line; 181, identifier:sequence; 182, binary_operator:'\n' + (format.margin[0] + str(p + block_length + 1)).rjust(margin) + format.margin[1]; 183, string; 184, attribute; 185, argument_list; 186, attribute; 187, integer:0; 188, string_content:1; 189, identifier:p; 190, identifier:block_length; 191, identifier:p; 192, identifier:block_length; 193, identifier:level; 194, tuple_pattern; 195, identifier:enumerate; 196, argument_list; 197, identifier:level; 198, identifier:levels; 199, call; 200, call; 201, attribute; 202, generator_expression; 203, identifier:p; 204, identifier:block_length; 205, identifier:block_length; 206, identifier:blocks_per_line; 207, binary_operator:'\n' + (format.margin[0] + str(p + block_length + 1)).rjust(margin); 208, subscript; 209, string_content:; 210, identifier:math; 211, identifier:log; 212, call; 213, integer:10; 214, identifier:format; 215, identifier:margin; 216, identifier:left; 217, identifier:right; 218, attribute; 219, attribute; 220, generator_expression; 221, identifier:str; 222, argument_list; 223, string; 224, identifier:join; 225, identifier:right; 226, for_in_clause; 227, string; 228, call; 229, attribute; 230, integer:1; 231, identifier:max; 232, argument_list; 233, identifier:format; 234, identifier:annotations; 235, string; 236, identifier:join; 237, identifier:left; 238, for_in_clause; 239, subscript; 240, pattern_list; 241, identifier:delimiters; 242, string_content; 243, attribute; 244, argument_list; 245, identifier:format; 246, identifier:margin; 247, call; 248, integer:1; 249, pattern_list; 250, call; 251, identifier:sequence; 252, slice; 253, identifier:left; 254, identifier:right; 255, escape_sequence:\n; 256, parenthesized_expression; 257, identifier:rjust; 258, identifier:margin; 259, identifier:len; 260, argument_list; 261, identifier:left; 262, identifier:right; 263, identifier:reversed; 264, argument_list; 265, identifier:start; 266, identifier:stop; 267, binary_operator:format.margin[0] + str(p + block_length + 1); 268, identifier:sequence; 269, identifier:delimiters; 270, subscript; 271, call; 272, attribute; 273, integer:0; 274, identifier:str; 275, argument_list; 276, identifier:format; 277, identifier:margin; 278, binary_operator:p + block_length + 1; 279, binary_operator:p + block_length; 280, integer:1; 281, identifier:p; 282, identifier:block_length
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 4, 17; 4, 18; 6, 19; 6, 20; 7, 21; 7, 22; 8, 23; 8, 24; 9, 25; 9, 26; 10, 27; 11, 28; 12, 29; 15, 30; 16, 31; 17, 32; 17, 33; 17, 34; 17, 35; 18, 36; 28, 37; 28, 38; 29, 39; 29, 40; 30, 41; 30, 42; 31, 43; 31, 44; 33, 45; 33, 46; 35, 47; 35, 48; 35, 49; 35, 50; 38, 51; 38, 52; 40, 53; 40, 54; 42, 55; 42, 56; 44, 57; 44, 58; 46, 59; 46, 60; 46, 61; 47, 62; 48, 63; 49, 64; 49, 65; 49, 66; 50, 67; 50, 68; 54, 69; 54, 70; 55, 71; 55, 72; 56, 73; 56, 74; 57, 75; 57, 76; 58, 77; 60, 78; 60, 79; 62, 80; 62, 81; 63, 82; 63, 83; 64, 84; 64, 85; 64, 86; 66, 87; 66, 88; 67, 89; 68, 90; 69, 91; 69, 92; 72, 93; 74, 94; 75, 95; 75, 96; 76, 97; 76, 98; 79, 99; 81, 100; 81, 101; 81, 102; 83, 103; 87, 104; 88, 105; 89, 106; 89, 107; 90, 108; 92, 109; 93, 110; 93, 111; 94, 112; 94, 113; 95, 114; 95, 115; 96, 116; 97, 117; 97, 118; 100, 119; 100, 120; 100, 121; 101, 122; 101, 123; 102, 124; 104, 125; 104, 126; 105, 127; 105, 128; 106, 129; 107, 130; 107, 131; 108, 132; 108, 133; 110, 134; 110, 135; 112, 136; 112, 137; 114, 138; 119, 139; 119, 140; 120, 141; 120, 142; 122, 143; 122, 144; 122, 145; 124, 146; 124, 147; 126, 148; 126, 149; 126, 150; 128, 151; 129, 152; 129, 153; 130, 154; 130, 155; 131, 156; 131, 157; 133, 158; 134, 159; 134, 160; 135, 161; 138, 162; 138, 163; 140, 164; 140, 165; 142, 166; 142, 167; 146, 168; 146, 169; 147, 170; 147, 171; 148, 172; 148, 173; 149, 174; 149, 175; 150, 176; 151, 177; 151, 178; 152, 179; 153, 180; 157, 181; 158, 182; 158, 183; 161, 184; 161, 185; 162, 186; 162, 187; 163, 188; 167, 189; 167, 190; 169, 191; 169, 192; 174, 193; 174, 194; 175, 195; 175, 196; 176, 197; 176, 198; 177, 199; 177, 200; 178, 201; 178, 202; 179, 203; 179, 204; 180, 205; 180, 206; 182, 207; 182, 208; 183, 209; 184, 210; 184, 211; 185, 212; 185, 213; 186, 214; 186, 215; 194, 216; 194, 217; 196, 218; 199, 219; 199, 220; 200, 221; 200, 222; 201, 223; 201, 224; 202, 225; 202, 226; 207, 227; 207, 228; 208, 229; 208, 230; 212, 231; 212, 232; 218, 233; 218, 234; 219, 235; 219, 236; 220, 237; 220, 238; 222, 239; 226, 240; 226, 241; 227, 242; 228, 243; 228, 244; 229, 245; 229, 246; 232, 247; 232, 248; 238, 249; 238, 250; 239, 251; 239, 252; 240, 253; 240, 254; 242, 255; 243, 256; 243, 257; 244, 258; 247, 259; 247, 260; 249, 261; 249, 262; 250, 263; 250, 264; 252, 265; 252, 266; 256, 267; 260, 268; 264, 269; 267, 270; 267, 271; 270, 272; 270, 273; 271, 274; 271, 275; 272, 276; 272, 277; 275, 278; 278, 279; 278, 280; 279, 281; 279, 282
def pprint_sequence(sequence, annotations=None, block_length=10, blocks_per_line=6, format=PlaintextFormat): """ Pretty-print sequence for use with a monospace font. >>> sequence = 'MIMANQPLWLDSEVEMNHYQQSHIKSKSPYFPEDKHICWIKIFKAFGT' * 4 >>> print pprint_sequence(sequence, format=PlaintextFormat) 1 MIMANQPLWL DSEVEMNHYQ QSHIKSKSPY FPEDKHICWI KIFKAFGTMI MANQPLWLDS 61 EVEMNHYQQS HIKSKSPYFP EDKHICWIKI FKAFGTMIMA NQPLWLDSEV EMNHYQQSHI 121 KSKSPYFPED KHICWIKIFK AFGTMIMANQ PLWLDSEVEM NHYQQSHIKS KSPYFPEDKH 181 ICWIKIFKAF GT :arg sequence: Sequence to pretty-print. :type sequence: str or any sliceable yielding slices representable as strings. :arg annotations: For each annotation level, a list of (`start`, `stop`) pairs defining an annotated region. :type annotations: list :arg block_length: Length of space-separated blocks. :type block_length: int :arg blocks_per_line: Number of blocks per line. :type blocks_per_line: int :arg format: Output format to use for pretty-printing. Some formats are pre-defined as :data:`HtmlFormat`, :data:`AnsiFormat`, and :data:`PlaintextFormat`. :type format: :class:`Format` :return: Pretty-printed version of `sequence`. :rtype: str All regions (`start`, `stop`) are defined as in slicing notation, so zero-based and `stop` is not included. The `annotations` argument is a list of annotations. An annotation is a list of regions as (`start`, `stop`) tuples. The level of each annotation is its index in `annotations`. Annotation regions can overlap (overlap within one level is ignored) and do not need to be sorted. The number of annotation levels supported depends on `format`. :data:`HtmlFormat` supports 10 levels, :data:`AnsiFormat` supports 3 levels and annotations are ignored completely with :data:`PlaintextFormat`. """ annotations = annotations or [] partitioning = partition_range(len(sequence), annotations) # The maximum length for positions is the 10_log of the length of the # sequence. margin = int(math.floor(math.log(max(len(sequence), 1), 10)) + 1) + len(format.margin[0]) result = (format.margin[0] + '1').rjust(margin) + format.margin[1] + ' ' for p in range(0, len(sequence), block_length): # Partitioning of the block starting at position p. block = [(max(start, p), min(stop, p + block_length), levels) for start, stop, levels in partitioning if start < p + block_length and stop > p] result += ' ' for start, stop, levels in block: delimiters = [(left, right) for level, (left, right) in enumerate(format.annotations) if level in levels] result += (''.join(left for left, right in reversed(delimiters)) + str(sequence[start:stop]) + ''.join(right for left, right in delimiters)) if (not (p + block_length) % (block_length * blocks_per_line) and p + block_length < len(sequence)): result += ('\n' + (format.margin[0] + str(p + block_length + 1)).rjust(margin) + format.margin[1] + ' ') return result
0, module; 1, function_definition; 2, function_name:tabulate; 3, parameters; 4, block; 5, identifier:obj; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, default_parameter; 13, default_parameter; 14, default_parameter; 15, expression_statement; 16, expression_statement; 17, expression_statement; 18, if_statement; 19, if_statement; 20, expression_statement; 21, expression_statement; 22, expression_statement; 23, expression_statement; 24, expression_statement; 25, return_statement; 26, identifier:v_level_indexes; 27, None; 28, identifier:h_level_indexes; 29, None; 30, identifier:v_level_visibility; 31, None; 32, identifier:h_level_visibility; 33, None; 34, identifier:v_level_sort_keys; 35, None; 36, identifier:h_level_sort_keys; 37, None; 38, identifier:v_level_titles; 39, None; 40, identifier:h_level_titles; 41, None; 42, identifier:empty; 43, string:""; 44, comment:"""Render a nested data structure into a two-dimensional table. Args: obj: The indexable data structure to be rendered, which can either be a non-string sequence or a mapping containing other sequences and mappings nested to arbitrarily many levels, with all the leaf items (which are neither sequences nor mappings, excluding strings). v_level_indexes: An iterable of the zero-based indexes of the levels for which the keys/indexes will be displayed along the vertical axis of the table. Taken together with the levels in h_levels these must represent the complete set of levels in the obj data structure. No level index should appear in both v_level_indexes and h_level_indexes, but all level indexes must appear in either v_level_indexes or h_level_indexes. If None, the levels not used in h_level_indexes will be used. If both v_level_indexes and h_level_indexes are not alternate indexes will be used as v_level and h_level indexes. h_level_indexes: An iterable of the zero-based indexes of the levels for which the keys/indexes will be displayed along the horizontal axis of the table. Taken together with the levels in v_levels these must represent the complete set of levels in the obj data structure. No level index should appear in both h_level_indexes and v_level_indexes, but all level indexes must appear in either h_level_indexes or v_level_indexes. If None, the levels not used in v_level_indexes will be used. If both v_level_indexes and h_level_indexes are not alternate indexes will be used as v_level and h_level indexes. v_level_visibility: An optional iterable of booleans, where each item corresponds to a level in v_level_indexes, and controls whether than level of index is included in the table stub columns. This iterable must contain the same number of items as v_level_indexes. h_level_visibility: An optional iterable of booleans, where each item corresponds to a level in h_level_indexes, and controls whether than level of index is included in the table header rows. This iterable must contain the same number of items as h_level_indexes. v_level_sort_keys: An optional iterable of Keys, where each key corresponds to a level in v_level_indexes, and controls how that key is sorted. If None, keys are sorted as-is. h_level_sort_keys: An optional iterable of Keys, where each key corresponds to a level in v_level_indexes, and controls how that key is sorted. If None, keys are sorted as-is. v_level_titles: An optional iterable of strings, where each string is a title which corresponds to a level in v_level_indexes, and which will be displayed against the row keys for that level. If None, no titles will be included. h_level_titles: An optional iterable of strings, where each string is a title which corresponds to a level in h_level_indexes, and which will be displayed against the column keys for that level. If None, no titles will be included. empty: An optional string value to use for empty cells. Returns: A list of lists representing the rows of cells. Example: tabulate(dict_of_dicts, [0, 1], []) """; 45, assignment; 46, assignment; 47, comparison_operator:v_level_visibility is None; 48, block; 49, comparison_operator:h_level_visibility is None; 50, block; 51, assignment; 52, assignment; 53, assignment; 54, assignment; 55, assignment; 56, call; 57, identifier:level_keys; 58, call; 59, pattern_list; 60, call; 61, identifier:v_level_visibility; 62, None; 63, expression_statement; 64, identifier:h_level_visibility; 65, None; 66, expression_statement; 67, pattern_list; 68, call; 69, pattern_list; 70, call; 71, pattern_list; 72, call; 73, identifier:v_key_tuples; 74, call; 75, identifier:h_key_tuples; 76, call; 77, identifier:assemble_table; 78, argument_list; 79, identifier:breadth_first; 80, argument_list; 81, identifier:v_level_indexes; 82, identifier:h_level_indexes; 83, identifier:validate_level_indexes; 84, argument_list; 85, assignment; 86, assignment; 87, identifier:table; 88, identifier:v_key_tuples; 89, identifier:h_key_tuples; 90, identifier:tabulate_body; 91, argument_list; 92, identifier:table; 93, identifier:v_key_tuples; 94, identifier:strip_missing_rows; 95, argument_list; 96, identifier:table; 97, identifier:h_key_tuples; 98, identifier:strip_missing_columns; 99, argument_list; 100, identifier:strip_hidden; 101, argument_list; 102, identifier:strip_hidden; 103, argument_list; 104, identifier:table; 105, identifier:v_key_tuples; 106, identifier:h_key_tuples; 107, identifier:v_level_titles; 108, identifier:h_level_titles; 109, keyword_argument; 110, identifier:obj; 111, call; 112, identifier:v_level_indexes; 113, identifier:h_level_indexes; 114, identifier:v_level_visibility; 115, binary_operator:[True] * len(v_level_indexes); 116, identifier:h_level_visibility; 117, binary_operator:[True] * len(h_level_indexes); 118, identifier:obj; 119, identifier:level_keys; 120, identifier:v_level_indexes; 121, identifier:h_level_indexes; 122, identifier:v_level_sort_keys; 123, identifier:h_level_sort_keys; 124, identifier:table; 125, identifier:v_key_tuples; 126, identifier:table; 127, identifier:h_key_tuples; 128, identifier:v_key_tuples; 129, identifier:v_level_visibility; 130, identifier:h_key_tuples; 131, identifier:h_level_visibility; 132, identifier:empty; 133, identifier:empty; 134, identifier:len; 135, argument_list; 136, list; 137, call; 138, list; 139, call; 140, identifier:level_keys; 141, True; 142, identifier:len; 143, argument_list; 144, True; 145, identifier:len; 146, argument_list; 147, identifier:v_level_indexes; 148, identifier:h_level_indexes
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 3, 12; 3, 13; 3, 14; 4, 15; 4, 16; 4, 17; 4, 18; 4, 19; 4, 20; 4, 21; 4, 22; 4, 23; 4, 24; 4, 25; 6, 26; 6, 27; 7, 28; 7, 29; 8, 30; 8, 31; 9, 32; 9, 33; 10, 34; 10, 35; 11, 36; 11, 37; 12, 38; 12, 39; 13, 40; 13, 41; 14, 42; 14, 43; 15, 44; 16, 45; 17, 46; 18, 47; 18, 48; 19, 49; 19, 50; 20, 51; 21, 52; 22, 53; 23, 54; 24, 55; 25, 56; 45, 57; 45, 58; 46, 59; 46, 60; 47, 61; 47, 62; 48, 63; 49, 64; 49, 65; 50, 66; 51, 67; 51, 68; 52, 69; 52, 70; 53, 71; 53, 72; 54, 73; 54, 74; 55, 75; 55, 76; 56, 77; 56, 78; 58, 79; 58, 80; 59, 81; 59, 82; 60, 83; 60, 84; 63, 85; 66, 86; 67, 87; 67, 88; 67, 89; 68, 90; 68, 91; 69, 92; 69, 93; 70, 94; 70, 95; 71, 96; 71, 97; 72, 98; 72, 99; 74, 100; 74, 101; 76, 102; 76, 103; 78, 104; 78, 105; 78, 106; 78, 107; 78, 108; 78, 109; 80, 110; 84, 111; 84, 112; 84, 113; 85, 114; 85, 115; 86, 116; 86, 117; 91, 118; 91, 119; 91, 120; 91, 121; 91, 122; 91, 123; 95, 124; 95, 125; 99, 126; 99, 127; 101, 128; 101, 129; 103, 130; 103, 131; 109, 132; 109, 133; 111, 134; 111, 135; 115, 136; 115, 137; 117, 138; 117, 139; 135, 140; 136, 141; 137, 142; 137, 143; 138, 144; 139, 145; 139, 146; 143, 147; 146, 148
def tabulate( obj, v_level_indexes=None, h_level_indexes=None, v_level_visibility=None, h_level_visibility=None, v_level_sort_keys=None, h_level_sort_keys=None, v_level_titles=None, h_level_titles=None, empty="", ): """Render a nested data structure into a two-dimensional table. Args: obj: The indexable data structure to be rendered, which can either be a non-string sequence or a mapping containing other sequences and mappings nested to arbitrarily many levels, with all the leaf items (which are neither sequences nor mappings, excluding strings). v_level_indexes: An iterable of the zero-based indexes of the levels for which the keys/indexes will be displayed along the vertical axis of the table. Taken together with the levels in h_levels these must represent the complete set of levels in the obj data structure. No level index should appear in both v_level_indexes and h_level_indexes, but all level indexes must appear in either v_level_indexes or h_level_indexes. If None, the levels not used in h_level_indexes will be used. If both v_level_indexes and h_level_indexes are not alternate indexes will be used as v_level and h_level indexes. h_level_indexes: An iterable of the zero-based indexes of the levels for which the keys/indexes will be displayed along the horizontal axis of the table. Taken together with the levels in v_levels these must represent the complete set of levels in the obj data structure. No level index should appear in both h_level_indexes and v_level_indexes, but all level indexes must appear in either h_level_indexes or v_level_indexes. If None, the levels not used in v_level_indexes will be used. If both v_level_indexes and h_level_indexes are not alternate indexes will be used as v_level and h_level indexes. v_level_visibility: An optional iterable of booleans, where each item corresponds to a level in v_level_indexes, and controls whether than level of index is included in the table stub columns. This iterable must contain the same number of items as v_level_indexes. h_level_visibility: An optional iterable of booleans, where each item corresponds to a level in h_level_indexes, and controls whether than level of index is included in the table header rows. This iterable must contain the same number of items as h_level_indexes. v_level_sort_keys: An optional iterable of Keys, where each key corresponds to a level in v_level_indexes, and controls how that key is sorted. If None, keys are sorted as-is. h_level_sort_keys: An optional iterable of Keys, where each key corresponds to a level in v_level_indexes, and controls how that key is sorted. If None, keys are sorted as-is. v_level_titles: An optional iterable of strings, where each string is a title which corresponds to a level in v_level_indexes, and which will be displayed against the row keys for that level. If None, no titles will be included. h_level_titles: An optional iterable of strings, where each string is a title which corresponds to a level in h_level_indexes, and which will be displayed against the column keys for that level. If None, no titles will be included. empty: An optional string value to use for empty cells. Returns: A list of lists representing the rows of cells. Example: tabulate(dict_of_dicts, [0, 1], []) """ level_keys = breadth_first(obj) v_level_indexes, h_level_indexes = validate_level_indexes( len(level_keys), v_level_indexes, h_level_indexes ) if v_level_visibility is None: v_level_visibility = [True] * len(v_level_indexes) if h_level_visibility is None: h_level_visibility = [True] * len(h_level_indexes) table, v_key_tuples, h_key_tuples = tabulate_body( obj, level_keys, v_level_indexes, h_level_indexes, v_level_sort_keys, h_level_sort_keys ) table, v_key_tuples = strip_missing_rows(table, v_key_tuples) table, h_key_tuples = strip_missing_columns(table, h_key_tuples) v_key_tuples = strip_hidden(v_key_tuples, v_level_visibility) h_key_tuples = strip_hidden(h_key_tuples, h_level_visibility) return assemble_table( table, v_key_tuples, h_key_tuples, v_level_titles, h_level_titles, empty=empty )
0, module; 1, function_definition; 2, function_name:get_ordered_entries; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, expression_statement; 8, if_statement; 9, if_statement; 10, return_statement; 11, identifier:queryset; 12, False; 13, comment:""" Custom ordering. First we get the average views and rating for the categories's entries. Second we created a rank by multiplying both. Last, we sort categories by this rank from top to bottom. Example: - Cat_1 - Entry_1 (500 Views, Rating 2) - Entry_2 (200 Views, Rating -4) - Entry_3 (100 Views, Rating 3) - Cat_2 - Entry_1 (200 Views, Rating 7) - Entry_2 (50 Views, Rating 2) Result: Cat_1 has a rank by: 88.88 (avg. views: 266.66, avg. rating: 0.33) Cat_2 has a rank by: 562.5 (avg. views: 125, avg. rating: 4.5) Cat_2 will be displayed at the top. The algorithm is quality-oriented, as you can see. """; 14, identifier:queryset; 15, block; 16, else_clause; 17, attribute; 18, block; 19, attribute; 20, expression_statement; 21, block; 22, identifier:self; 23, identifier:queryset; 24, for_statement; 25, expression_statement; 26, identifier:self; 27, identifier:queryset; 28, assignment; 29, expression_statement; 30, identifier:category; 31, attribute; 32, block; 33, assignment; 34, attribute; 35, identifier:queryset; 36, assignment; 37, identifier:self; 38, identifier:queryset; 39, expression_statement; 40, if_statement; 41, attribute; 42, call; 43, identifier:self; 44, identifier:queryset; 45, attribute; 46, call; 47, assignment; 48, identifier:entries; 49, block; 50, else_clause; 51, identifier:self; 52, identifier:queryset; 53, identifier:sorted; 54, argument_list; 55, identifier:self; 56, identifier:queryset; 57, attribute; 58, argument_list; 59, identifier:entries; 60, call; 61, expression_statement; 62, expression_statement; 63, expression_statement; 64, expression_statement; 65, expression_statement; 66, expression_statement; 67, block; 68, attribute; 69, keyword_argument; 70, keyword_argument; 71, attribute; 72, identifier:all; 73, attribute; 74, argument_list; 75, assignment; 76, assignment; 77, assignment; 78, assignment; 79, assignment; 80, call; 81, expression_statement; 82, identifier:self; 83, identifier:queryset; 84, identifier:key; 85, lambda; 86, identifier:reverse; 87, True; 88, identifier:EntryCategory; 89, identifier:objects; 90, identifier:category; 91, identifier:get_entries; 92, identifier:amount_list; 93, list_comprehension; 94, identifier:rating_list; 95, list_comprehension; 96, identifier:views_per_entry; 97, binary_operator:fsum(amount_list) / len(amount_list); 98, identifier:rating_per_entry; 99, binary_operator:fsum(rating_list) / len(rating_list); 100, attribute; 101, binary_operator:views_per_entry * rating_per_entry; 102, attribute; 103, argument_list; 104, assignment; 105, lambda_parameters; 106, attribute; 107, attribute; 108, for_in_clause; 109, call; 110, for_in_clause; 111, call; 112, call; 113, call; 114, call; 115, identifier:category; 116, identifier:last_rank; 117, identifier:views_per_entry; 118, identifier:rating_per_entry; 119, identifier:category; 120, identifier:save; 121, attribute; 122, call; 123, identifier:c; 124, identifier:c; 125, identifier:last_rank; 126, identifier:e; 127, identifier:amount_of_views; 128, identifier:e; 129, identifier:entries; 130, attribute; 131, argument_list; 132, identifier:e; 133, identifier:entries; 134, identifier:fsum; 135, argument_list; 136, identifier:len; 137, argument_list; 138, identifier:fsum; 139, argument_list; 140, identifier:len; 141, argument_list; 142, identifier:self; 143, identifier:queryset; 144, attribute; 145, argument_list; 146, identifier:e; 147, identifier:rating; 148, identifier:amount_list; 149, identifier:amount_list; 150, identifier:rating_list; 151, identifier:rating_list; 152, attribute; 153, identifier:exclude; 154, keyword_argument; 155, identifier:self; 156, identifier:queryset; 157, identifier:pk; 158, attribute; 159, identifier:category; 160, identifier:pk
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 6, 11; 6, 12; 7, 13; 8, 14; 8, 15; 8, 16; 9, 17; 9, 18; 10, 19; 15, 20; 16, 21; 17, 22; 17, 23; 18, 24; 18, 25; 19, 26; 19, 27; 20, 28; 21, 29; 24, 30; 24, 31; 24, 32; 25, 33; 28, 34; 28, 35; 29, 36; 31, 37; 31, 38; 32, 39; 32, 40; 33, 41; 33, 42; 34, 43; 34, 44; 36, 45; 36, 46; 39, 47; 40, 48; 40, 49; 40, 50; 41, 51; 41, 52; 42, 53; 42, 54; 45, 55; 45, 56; 46, 57; 46, 58; 47, 59; 47, 60; 49, 61; 49, 62; 49, 63; 49, 64; 49, 65; 49, 66; 50, 67; 54, 68; 54, 69; 54, 70; 57, 71; 57, 72; 60, 73; 60, 74; 61, 75; 62, 76; 63, 77; 64, 78; 65, 79; 66, 80; 67, 81; 68, 82; 68, 83; 69, 84; 69, 85; 70, 86; 70, 87; 71, 88; 71, 89; 73, 90; 73, 91; 75, 92; 75, 93; 76, 94; 76, 95; 77, 96; 77, 97; 78, 98; 78, 99; 79, 100; 79, 101; 80, 102; 80, 103; 81, 104; 85, 105; 85, 106; 93, 107; 93, 108; 95, 109; 95, 110; 97, 111; 97, 112; 99, 113; 99, 114; 100, 115; 100, 116; 101, 117; 101, 118; 102, 119; 102, 120; 104, 121; 104, 122; 105, 123; 106, 124; 106, 125; 107, 126; 107, 127; 108, 128; 108, 129; 109, 130; 109, 131; 110, 132; 110, 133; 111, 134; 111, 135; 112, 136; 112, 137; 113, 138; 113, 139; 114, 140; 114, 141; 121, 142; 121, 143; 122, 144; 122, 145; 130, 146; 130, 147; 135, 148; 137, 149; 139, 150; 141, 151; 144, 152; 144, 153; 145, 154; 152, 155; 152, 156; 154, 157; 154, 158; 158, 159; 158, 160
def get_ordered_entries(self, queryset=False): """ Custom ordering. First we get the average views and rating for the categories's entries. Second we created a rank by multiplying both. Last, we sort categories by this rank from top to bottom. Example: - Cat_1 - Entry_1 (500 Views, Rating 2) - Entry_2 (200 Views, Rating -4) - Entry_3 (100 Views, Rating 3) - Cat_2 - Entry_1 (200 Views, Rating 7) - Entry_2 (50 Views, Rating 2) Result: Cat_1 has a rank by: 88.88 (avg. views: 266.66, avg. rating: 0.33) Cat_2 has a rank by: 562.5 (avg. views: 125, avg. rating: 4.5) Cat_2 will be displayed at the top. The algorithm is quality-oriented, as you can see. """ if queryset: self.queryset = queryset else: self.queryset = EntryCategory.objects.all() if self.queryset: for category in self.queryset: entries = category.get_entries() if entries: amount_list = [e.amount_of_views for e in entries] rating_list = [e.rating() for e in entries] views_per_entry = fsum(amount_list) / len(amount_list) rating_per_entry = fsum(rating_list) / len(rating_list) category.last_rank = views_per_entry * rating_per_entry category.save() else: self.queryset = self.queryset.exclude(pk=category.pk) self.queryset = sorted(self.queryset, key=lambda c: c.last_rank, reverse=True) return self.queryset
0, module; 1, function_definition; 2, function_name:parallel_progbar; 3, parameters; 4, block; 5, identifier:mapper; 6, identifier:iterable; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, default_parameter; 13, dictionary_splat_pattern; 14, expression_statement; 15, expression_statement; 16, return_statement; 17, identifier:nprocs; 18, None; 19, identifier:starmap; 20, False; 21, identifier:flatmap; 22, False; 23, identifier:shuffle; 24, False; 25, identifier:verbose; 26, True; 27, identifier:verbose_flatmap; 28, None; 29, identifier:kwargs; 30, comment:"""Performs a parallel mapping of the given iterable, reporting a progress bar as values get returned :param mapper: The mapping function to apply to elements of the iterable :param iterable: The iterable to map :param nprocs: The number of processes (defaults to the number of cpu's) :param starmap: If true, the iterable is expected to contain tuples and the mapper function gets each element of a tuple as an argument :param flatmap: If true, flatten out the returned values if the mapper function returns a list of objects :param shuffle: If true, randomly sort the elements before processing them. This might help provide more uniform runtimes if processing different objects takes different amounts of time. :param verbose: Whether or not to print the progress bar :param verbose_flatmap: If performing a flatmap, whether or not to report each object as it's returned :param kwargs: Any other keyword arguments to pass to the progress bar (see ``progbar``) :return: A list of the returned objects, in the same order as provided """; 31, assignment; 32, list_comprehension; 33, identifier:results; 34, call; 35, identifier:x; 36, for_in_clause; 37, identifier:_parallel_progbar_launch; 38, argument_list; 39, pattern_list; 40, call; 41, identifier:mapper; 42, identifier:iterable; 43, identifier:nprocs; 44, identifier:starmap; 45, identifier:flatmap; 46, identifier:shuffle; 47, identifier:verbose; 48, identifier:verbose_flatmap; 49, dictionary_splat; 50, identifier:i; 51, identifier:x; 52, identifier:sorted; 53, argument_list; 54, identifier:kwargs; 55, identifier:results; 56, keyword_argument; 57, identifier:key; 58, lambda; 59, lambda_parameters; 60, subscript; 61, identifier:p; 62, identifier:p; 63, integer:0
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 3, 12; 3, 13; 4, 14; 4, 15; 4, 16; 7, 17; 7, 18; 8, 19; 8, 20; 9, 21; 9, 22; 10, 23; 10, 24; 11, 25; 11, 26; 12, 27; 12, 28; 13, 29; 14, 30; 15, 31; 16, 32; 31, 33; 31, 34; 32, 35; 32, 36; 34, 37; 34, 38; 36, 39; 36, 40; 38, 41; 38, 42; 38, 43; 38, 44; 38, 45; 38, 46; 38, 47; 38, 48; 38, 49; 39, 50; 39, 51; 40, 52; 40, 53; 49, 54; 53, 55; 53, 56; 56, 57; 56, 58; 58, 59; 58, 60; 59, 61; 60, 62; 60, 63
def parallel_progbar(mapper, iterable, nprocs=None, starmap=False, flatmap=False, shuffle=False, verbose=True, verbose_flatmap=None, **kwargs): """Performs a parallel mapping of the given iterable, reporting a progress bar as values get returned :param mapper: The mapping function to apply to elements of the iterable :param iterable: The iterable to map :param nprocs: The number of processes (defaults to the number of cpu's) :param starmap: If true, the iterable is expected to contain tuples and the mapper function gets each element of a tuple as an argument :param flatmap: If true, flatten out the returned values if the mapper function returns a list of objects :param shuffle: If true, randomly sort the elements before processing them. This might help provide more uniform runtimes if processing different objects takes different amounts of time. :param verbose: Whether or not to print the progress bar :param verbose_flatmap: If performing a flatmap, whether or not to report each object as it's returned :param kwargs: Any other keyword arguments to pass to the progress bar (see ``progbar``) :return: A list of the returned objects, in the same order as provided """ results = _parallel_progbar_launch(mapper, iterable, nprocs, starmap, flatmap, shuffle, verbose, verbose_flatmap, **kwargs) return [x for i, x in sorted(results, key=lambda p: p[0])]
0, module; 1, function_definition; 2, function_name:iparallel_progbar; 3, parameters; 4, block; 5, identifier:mapper; 6, identifier:iterable; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, default_parameter; 13, default_parameter; 14, dictionary_splat_pattern; 15, expression_statement; 16, expression_statement; 17, return_statement; 18, identifier:nprocs; 19, None; 20, identifier:starmap; 21, False; 22, identifier:flatmap; 23, False; 24, identifier:shuffle; 25, False; 26, identifier:verbose; 27, True; 28, identifier:verbose_flatmap; 29, None; 30, identifier:max_cache; 31, unary_operator; 32, identifier:kwargs; 33, comment:"""Performs a parallel mapping of the given iterable, reporting a progress bar as values get returned. Yields objects as soon as they're computed, but does not guarantee that they'll be in the correct order. :param mapper: The mapping function to apply to elements of the iterable :param iterable: The iterable to map :param nprocs: The number of processes (defaults to the number of cpu's) :param starmap: If true, the iterable is expected to contain tuples and the mapper function gets each element of a tuple as an argument :param flatmap: If true, flatten out the returned values if the mapper function returns a list of objects :param shuffle: If true, randomly sort the elements before processing them. This might help provide more uniform runtimes if processing different objects takes different amounts of time. :param verbose: Whether or not to print the progress bar :param verbose_flatmap: If performing a flatmap, whether or not to report each object as it's returned :param max_cache: Maximum number of mapped objects to permit in the queue at once :param kwargs: Any other keyword arguments to pass to the progress bar (see ``progbar``) :return: A list of the returned objects, in whatever order they're done being computed """; 34, assignment; 35, generator_expression; 36, integer:1; 37, identifier:results; 38, call; 39, identifier:x; 40, for_in_clause; 41, identifier:_parallel_progbar_launch; 42, argument_list; 43, pattern_list; 44, identifier:results; 45, identifier:mapper; 46, identifier:iterable; 47, identifier:nprocs; 48, identifier:starmap; 49, identifier:flatmap; 50, identifier:shuffle; 51, identifier:verbose; 52, identifier:verbose_flatmap; 53, identifier:max_cache; 54, dictionary_splat; 55, identifier:i; 56, identifier:x; 57, identifier:kwargs
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 3, 12; 3, 13; 3, 14; 4, 15; 4, 16; 4, 17; 7, 18; 7, 19; 8, 20; 8, 21; 9, 22; 9, 23; 10, 24; 10, 25; 11, 26; 11, 27; 12, 28; 12, 29; 13, 30; 13, 31; 14, 32; 15, 33; 16, 34; 17, 35; 31, 36; 34, 37; 34, 38; 35, 39; 35, 40; 38, 41; 38, 42; 40, 43; 40, 44; 42, 45; 42, 46; 42, 47; 42, 48; 42, 49; 42, 50; 42, 51; 42, 52; 42, 53; 42, 54; 43, 55; 43, 56; 54, 57
def iparallel_progbar(mapper, iterable, nprocs=None, starmap=False, flatmap=False, shuffle=False, verbose=True, verbose_flatmap=None, max_cache=-1, **kwargs): """Performs a parallel mapping of the given iterable, reporting a progress bar as values get returned. Yields objects as soon as they're computed, but does not guarantee that they'll be in the correct order. :param mapper: The mapping function to apply to elements of the iterable :param iterable: The iterable to map :param nprocs: The number of processes (defaults to the number of cpu's) :param starmap: If true, the iterable is expected to contain tuples and the mapper function gets each element of a tuple as an argument :param flatmap: If true, flatten out the returned values if the mapper function returns a list of objects :param shuffle: If true, randomly sort the elements before processing them. This might help provide more uniform runtimes if processing different objects takes different amounts of time. :param verbose: Whether or not to print the progress bar :param verbose_flatmap: If performing a flatmap, whether or not to report each object as it's returned :param max_cache: Maximum number of mapped objects to permit in the queue at once :param kwargs: Any other keyword arguments to pass to the progress bar (see ``progbar``) :return: A list of the returned objects, in whatever order they're done being computed """ results = _parallel_progbar_launch(mapper, iterable, nprocs, starmap, flatmap, shuffle, verbose, verbose_flatmap, max_cache, **kwargs) return (x for i, x in results)
0, module; 1, function_definition; 2, function_name:get_creation_date_tags; 3, parameters; 4, block; 5, identifier:url; 6, identifier:domain; 7, default_parameter; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, if_statement; 12, return_statement; 13, identifier:as_dicts; 14, False; 15, comment:""" Put together all data sources in this module and return it's output. Args: url (str): URL of the web. With relative paths and so on. domain (str): Just the domain of the web. as_dicts (bool, default False): Convert output to dictionaries compatible with :class:`.SourceString`? Returns: list: Sorted list of :class:`TimeResource` objects or dicts. """; 16, assignment; 17, assignment; 18, not_operator; 19, block; 20, list_comprehension; 21, identifier:creation_date_tags; 22, list; 23, identifier:creation_date_tags; 24, call; 25, identifier:as_dicts; 26, return_statement; 27, call; 28, for_in_clause; 29, call; 30, call; 31, identifier:sorted; 32, argument_list; 33, identifier:creation_date_tags; 34, attribute; 35, argument_list; 36, identifier:item; 37, identifier:creation_date_tags; 38, identifier:mementoweb_api_tags; 39, argument_list; 40, identifier:get_whois_tags; 41, argument_list; 42, call; 43, keyword_argument; 44, identifier:item; 45, identifier:_as_dict; 46, identifier:url; 47, identifier:domain; 48, identifier:sum; 49, argument_list; 50, identifier:key; 51, lambda; 52, identifier:creation_date_tags; 53, list; 54, lambda_parameters; 55, attribute; 56, identifier:x; 57, identifier:x; 58, identifier:date
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 7, 13; 7, 14; 8, 15; 9, 16; 10, 17; 11, 18; 11, 19; 12, 20; 16, 21; 16, 22; 17, 23; 17, 24; 18, 25; 19, 26; 20, 27; 20, 28; 22, 29; 22, 30; 24, 31; 24, 32; 26, 33; 27, 34; 27, 35; 28, 36; 28, 37; 29, 38; 29, 39; 30, 40; 30, 41; 32, 42; 32, 43; 34, 44; 34, 45; 39, 46; 41, 47; 42, 48; 42, 49; 43, 50; 43, 51; 49, 52; 49, 53; 51, 54; 51, 55; 54, 56; 55, 57; 55, 58
def get_creation_date_tags(url, domain, as_dicts=False): """ Put together all data sources in this module and return it's output. Args: url (str): URL of the web. With relative paths and so on. domain (str): Just the domain of the web. as_dicts (bool, default False): Convert output to dictionaries compatible with :class:`.SourceString`? Returns: list: Sorted list of :class:`TimeResource` objects or dicts. """ creation_date_tags = [ mementoweb_api_tags(url), get_whois_tags(domain), ] creation_date_tags = sorted( sum(creation_date_tags, []), key=lambda x: x.date ) if not as_dicts: return creation_date_tags return [ item._as_dict() for item in creation_date_tags ]
0, module; 1, function_definition; 2, function_name:image_from_name; 3, parameters; 4, block; 5, identifier:name; 6, identifier:images; 7, expression_statement; 8, expression_statement; 9, if_statement; 10, expression_statement; 11, return_statement; 12, comment:"""Return an image from a list of images. If the name is an exact match, return the last exactly matching image. Otherwise, sort images by 'natural' order, using decorate-sort-undecorate, and return the largest. see: http://code.activestate.com/recipes/285264-natural-string-sorting/ """; 13, assignment; 14, comparison_operator:name in [i.name for i in prefixed_images]; 15, block; 16, assignment; 17, subscript; 18, identifier:prefixed_images; 19, list_comprehension; 20, identifier:name; 21, list_comprehension; 22, return_statement; 23, identifier:decorated; 24, call; 25, list_comprehension; 26, unary_operator; 27, identifier:i; 28, for_in_clause; 29, if_clause; 30, attribute; 31, for_in_clause; 32, subscript; 33, identifier:sorted; 34, argument_list; 35, subscript; 36, for_in_clause; 37, integer:1; 38, identifier:i; 39, identifier:images; 40, call; 41, identifier:i; 42, identifier:name; 43, identifier:i; 44, identifier:prefixed_images; 45, list_comprehension; 46, unary_operator; 47, list_comprehension; 48, identifier:i; 49, integer:1; 50, identifier:i; 51, identifier:decorated; 52, attribute; 53, argument_list; 54, identifier:i; 55, for_in_clause; 56, if_clause; 57, integer:1; 58, tuple; 59, for_in_clause; 60, attribute; 61, identifier:startswith; 62, identifier:name; 63, identifier:i; 64, identifier:prefixed_images; 65, comparison_operator:i.name == name; 66, call; 67, identifier:i; 68, identifier:i; 69, identifier:prefixed_images; 70, identifier:i; 71, identifier:name; 72, attribute; 73, identifier:name; 74, identifier:int; 75, argument_list; 76, identifier:i; 77, identifier:name; 78, call; 79, attribute; 80, argument_list; 81, call; 82, identifier:group; 83, integer:0; 84, attribute; 85, argument_list; 86, identifier:re; 87, identifier:search; 88, string; 89, attribute; 90, string_content; 91, identifier:i; 92, identifier:name
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 7, 12; 8, 13; 9, 14; 9, 15; 10, 16; 11, 17; 13, 18; 13, 19; 14, 20; 14, 21; 15, 22; 16, 23; 16, 24; 17, 25; 17, 26; 19, 27; 19, 28; 19, 29; 21, 30; 21, 31; 22, 32; 24, 33; 24, 34; 25, 35; 25, 36; 26, 37; 28, 38; 28, 39; 29, 40; 30, 41; 30, 42; 31, 43; 31, 44; 32, 45; 32, 46; 34, 47; 35, 48; 35, 49; 36, 50; 36, 51; 40, 52; 40, 53; 45, 54; 45, 55; 45, 56; 46, 57; 47, 58; 47, 59; 52, 60; 52, 61; 53, 62; 55, 63; 55, 64; 56, 65; 58, 66; 58, 67; 59, 68; 59, 69; 60, 70; 60, 71; 65, 72; 65, 73; 66, 74; 66, 75; 72, 76; 72, 77; 75, 78; 78, 79; 78, 80; 79, 81; 79, 82; 80, 83; 81, 84; 81, 85; 84, 86; 84, 87; 85, 88; 85, 89; 88, 90; 89, 91; 89, 92
def image_from_name(name, images): """Return an image from a list of images. If the name is an exact match, return the last exactly matching image. Otherwise, sort images by 'natural' order, using decorate-sort-undecorate, and return the largest. see: http://code.activestate.com/recipes/285264-natural-string-sorting/ """ prefixed_images = [i for i in images if i.name.startswith(name)] if name in [i.name for i in prefixed_images]: return [i for i in prefixed_images if i.name == name][-1] decorated = sorted( [(int(re.search('\d+', i.name).group(0)), i) for i in prefixed_images]) return [i[1] for i in decorated][-1]
0, module; 1, function_definition; 2, function_name:func_on_enter; 3, parameters; 4, block; 5, identifier:func; 6, expression_statement; 7, function_definition; 8, return_statement; 9, comment:""" Register the `func` as a callback reacting only to ENTER. Note: This function doesn't bind the key to the element, just creates sort of filter, which ignores all other events. """; 10, function_name:function_after_enter_pressed; 11, parameters; 12, block; 13, identifier:function_after_enter_pressed; 14, identifier:ev; 15, expression_statement; 16, comment:# if the key was `enter` ..; 17, if_statement; 18, call; 19, comparison_operator:ev.keyCode == 13; 20, block; 21, attribute; 22, argument_list; 23, attribute; 24, integer:13; 25, expression_statement; 26, identifier:ev; 27, identifier:stopPropagation; 28, identifier:ev; 29, identifier:keyCode; 30, call; 31, identifier:func; 32, argument_list; 33, identifier:ev
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 4, 8; 6, 9; 7, 10; 7, 11; 7, 12; 8, 13; 11, 14; 12, 15; 12, 16; 12, 17; 15, 18; 17, 19; 17, 20; 18, 21; 18, 22; 19, 23; 19, 24; 20, 25; 21, 26; 21, 27; 23, 28; 23, 29; 25, 30; 30, 31; 30, 32; 32, 33
def func_on_enter(func): """ Register the `func` as a callback reacting only to ENTER. Note: This function doesn't bind the key to the element, just creates sort of filter, which ignores all other events. """ def function_after_enter_pressed(ev): ev.stopPropagation() # if the key was `enter` .. if ev.keyCode == 13: func(ev) return function_after_enter_pressed
0, module; 1, function_definition; 2, function_name:prev_next_group; 3, parameters; 4, block; 5, identifier:project; 6, identifier:group; 7, expression_statement; 8, comment:# TODO: Profile and optimize this query if necessary; 9, expression_statement; 10, try_statement; 11, expression_statement; 12, expression_statement; 13, return_statement; 14, comment:"""Return adjacent group objects or None for the given project and group. The previous and next group objects are relative to sort order of the project's groups with respect to the passed in group. """; 15, assignment; 16, block; 17, except_clause; 18, assignment; 19, assignment; 20, expression_list; 21, identifier:groups; 22, call; 23, expression_statement; 24, identifier:ValueError; 25, block; 26, identifier:prev_group; 27, conditional_expression:groups[index - 1] if index > 0 else None; 28, identifier:next_group; 29, conditional_expression:groups[index + 1] if index + 1 < len(groups) else None; 30, identifier:prev_group; 31, identifier:next_group; 32, identifier:sorted; 33, generator_expression; 34, assignment; 35, return_statement; 36, subscript; 37, comparison_operator:index > 0; 38, None; 39, subscript; 40, comparison_operator:index + 1 < len(groups); 41, None; 42, identifier:x; 43, for_in_clause; 44, if_clause; 45, identifier:index; 46, call; 47, expression_list; 48, identifier:groups; 49, binary_operator:index - 1; 50, identifier:index; 51, integer:0; 52, identifier:groups; 53, binary_operator:index + 1; 54, binary_operator:index + 1; 55, call; 56, identifier:x; 57, attribute; 58, attribute; 59, attribute; 60, argument_list; 61, None; 62, None; 63, identifier:index; 64, integer:1; 65, identifier:index; 66, integer:1; 67, identifier:index; 68, integer:1; 69, identifier:len; 70, argument_list; 71, identifier:project; 72, identifier:groups; 73, identifier:x; 74, identifier:submissions; 75, identifier:groups; 76, identifier:index; 77, identifier:group; 78, identifier:groups
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 7, 14; 9, 15; 10, 16; 10, 17; 11, 18; 12, 19; 13, 20; 15, 21; 15, 22; 16, 23; 17, 24; 17, 25; 18, 26; 18, 27; 19, 28; 19, 29; 20, 30; 20, 31; 22, 32; 22, 33; 23, 34; 25, 35; 27, 36; 27, 37; 27, 38; 29, 39; 29, 40; 29, 41; 33, 42; 33, 43; 33, 44; 34, 45; 34, 46; 35, 47; 36, 48; 36, 49; 37, 50; 37, 51; 39, 52; 39, 53; 40, 54; 40, 55; 43, 56; 43, 57; 44, 58; 46, 59; 46, 60; 47, 61; 47, 62; 49, 63; 49, 64; 53, 65; 53, 66; 54, 67; 54, 68; 55, 69; 55, 70; 57, 71; 57, 72; 58, 73; 58, 74; 59, 75; 59, 76; 60, 77; 70, 78
def prev_next_group(project, group): """Return adjacent group objects or None for the given project and group. The previous and next group objects are relative to sort order of the project's groups with respect to the passed in group. """ # TODO: Profile and optimize this query if necessary groups = sorted(x for x in project.groups if x.submissions) try: index = groups.index(group) except ValueError: return None, None prev_group = groups[index - 1] if index > 0 else None next_group = groups[index + 1] if index + 1 < len(groups) else None return prev_group, next_group
0, module; 1, function_definition; 2, function_name:do_minus; 3, parameters; 4, block; 5, identifier:self; 6, identifier:parser; 7, identifier:group; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, for_statement; 12, if_statement; 13, return_statement; 14, string:'''This filter sorts nodes in a flat group into "required", "default", and "banned" subgroups based on the presence of plus and minus nodes. '''; 15, assignment; 16, assignment; 17, identifier:node; 18, identifier:group; 19, block; 20, comparison_operator:next_not is not None; 21, comment:# Remove the empty NotGroup; 22, block; 23, identifier:grouper; 24, identifier:grouper; 25, call; 26, identifier:next_not; 27, None; 28, if_statement; 29, identifier:next_not; 30, None; 31, expression_statement; 32, attribute; 33, argument_list; 34, call; 35, block; 36, else_clause; 37, call; 38, identifier:group; 39, identifier:__class__; 40, identifier:isinstance; 41, argument_list; 42, if_statement; 43, expression_statement; 44, expression_statement; 45, comment:# Nodes with children: search for nested Minus nodes; 46, block; 47, attribute; 48, argument_list; 49, identifier:node; 50, attribute; 51, comparison_operator:next_not is not None; 52, comment:# Two Minuses in a row; skip the second one; 53, block; 54, assignment; 55, call; 56, if_statement; 57, if_statement; 58, identifier:grouper; 59, identifier:pop; 60, identifier:self; 61, identifier:Minus; 62, identifier:next_not; 63, None; 64, continue_statement; 65, identifier:next_not; 66, call; 67, attribute; 68, argument_list; 69, call; 70, block; 71, comparison_operator:next_not is not None; 72, block; 73, else_clause; 74, attribute; 75, argument_list; 76, identifier:grouper; 77, identifier:append; 78, identifier:next_not; 79, identifier:isinstance; 80, argument_list; 81, expression_statement; 82, identifier:next_not; 83, None; 84, expression_statement; 85, expression_statement; 86, block; 87, attribute; 88, identifier:NotGroup; 89, identifier:node; 90, attribute; 91, assignment; 92, call; 93, assignment; 94, expression_statement; 95, attribute; 96, identifier:syntax; 97, attribute; 98, identifier:GroupNode; 99, identifier:node; 100, call; 101, attribute; 102, argument_list; 103, identifier:next_not; 104, None; 105, call; 106, identifier:whoosh; 107, identifier:qparser; 108, attribute; 109, identifier:syntax; 110, attribute; 111, argument_list; 112, identifier:next_not; 113, identifier:append; 114, identifier:node; 115, attribute; 116, argument_list; 117, identifier:whoosh; 118, identifier:qparser; 119, identifier:self; 120, identifier:do_minus; 121, identifier:parser; 122, identifier:node; 123, identifier:grouper; 124, identifier:append; 125, identifier:node
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 8, 14; 9, 15; 10, 16; 11, 17; 11, 18; 11, 19; 12, 20; 12, 21; 12, 22; 13, 23; 15, 24; 15, 25; 16, 26; 16, 27; 19, 28; 20, 29; 20, 30; 22, 31; 25, 32; 25, 33; 28, 34; 28, 35; 28, 36; 31, 37; 32, 38; 32, 39; 34, 40; 34, 41; 35, 42; 35, 43; 35, 44; 36, 45; 36, 46; 37, 47; 37, 48; 41, 49; 41, 50; 42, 51; 42, 52; 42, 53; 43, 54; 44, 55; 46, 56; 46, 57; 47, 58; 47, 59; 50, 60; 50, 61; 51, 62; 51, 63; 53, 64; 54, 65; 54, 66; 55, 67; 55, 68; 56, 69; 56, 70; 57, 71; 57, 72; 57, 73; 66, 74; 66, 75; 67, 76; 67, 77; 68, 78; 69, 79; 69, 80; 70, 81; 71, 82; 71, 83; 72, 84; 72, 85; 73, 86; 74, 87; 74, 88; 80, 89; 80, 90; 81, 91; 84, 92; 85, 93; 86, 94; 87, 95; 87, 96; 90, 97; 90, 98; 91, 99; 91, 100; 92, 101; 92, 102; 93, 103; 93, 104; 94, 105; 95, 106; 95, 107; 97, 108; 97, 109; 100, 110; 100, 111; 101, 112; 101, 113; 102, 114; 105, 115; 105, 116; 108, 117; 108, 118; 110, 119; 110, 120; 111, 121; 111, 122; 115, 123; 115, 124; 116, 125
def do_minus(self, parser, group): '''This filter sorts nodes in a flat group into "required", "default", and "banned" subgroups based on the presence of plus and minus nodes. ''' grouper = group.__class__() next_not = None for node in group: if isinstance(node, self.Minus): if next_not is not None: # Two Minuses in a row; skip the second one continue next_not = whoosh.qparser.syntax.NotGroup() grouper.append(next_not) else: # Nodes with children: search for nested Minus nodes if isinstance(node, whoosh.qparser.syntax.GroupNode): node = self.do_minus(parser, node) if next_not is not None: next_not.append(node) next_not = None else: grouper.append(node) if next_not is not None: # Remove the empty NotGroup grouper.pop() return grouper
0, module; 1, function_definition; 2, function_name:topological_sort; 3, parameters; 4, block; 5, identifier:dependency_pairs; 6, expression_statement; 7, expression_statement; 8, comment:# num arrows pointing in; 9, expression_statement; 10, comment:# list of arrows going out; 11, expression_statement; 12, comment:# unique list of heads in order first seen; 13, for_statement; 14, expression_statement; 15, for_statement; 16, expression_statement; 17, return_statement; 18, string:"Sort values subject to dependency constraints"; 19, assignment; 20, assignment; 21, assignment; 22, pattern_list; 23, identifier:dependency_pairs; 24, block; 25, assignment; 26, identifier:h; 27, identifier:ordered; 28, block; 29, assignment; 30, call; 31, identifier:num_heads; 32, call; 33, identifier:tails; 34, call; 35, identifier:heads; 36, list; 37, identifier:h; 38, identifier:t; 39, expression_statement; 40, if_statement; 41, identifier:ordered; 42, list_comprehension; 43, for_statement; 44, identifier:cyclic; 45, list_comprehension; 46, identifier:Results; 47, argument_list; 48, identifier:defaultdict; 49, argument_list; 50, identifier:defaultdict; 51, argument_list; 52, augmented_assignment; 53, comparison_operator:h in tails; 54, block; 55, else_clause; 56, identifier:h; 57, for_in_clause; 58, if_clause; 59, identifier:t; 60, subscript; 61, block; 62, identifier:n; 63, for_in_clause; 64, if_clause; 65, identifier:ordered; 66, identifier:cyclic; 67, identifier:int; 68, identifier:list; 69, subscript; 70, integer:1; 71, identifier:h; 72, identifier:tails; 73, expression_statement; 74, block; 75, identifier:h; 76, identifier:heads; 77, comparison_operator:h not in num_heads; 78, identifier:tails; 79, identifier:h; 80, expression_statement; 81, if_statement; 82, pattern_list; 83, call; 84, identifier:heads; 85, identifier:num_heads; 86, identifier:t; 87, call; 88, expression_statement; 89, expression_statement; 90, identifier:h; 91, identifier:num_heads; 92, augmented_assignment; 93, not_operator; 94, block; 95, identifier:n; 96, identifier:heads; 97, attribute; 98, argument_list; 99, attribute; 100, argument_list; 101, assignment; 102, call; 103, subscript; 104, integer:1; 105, subscript; 106, expression_statement; 107, identifier:num_heads; 108, identifier:items; 109, subscript; 110, identifier:append; 111, identifier:t; 112, subscript; 113, list; 114, attribute; 115, argument_list; 116, identifier:num_heads; 117, identifier:t; 118, identifier:num_heads; 119, identifier:t; 120, call; 121, identifier:tails; 122, identifier:h; 123, identifier:tails; 124, identifier:h; 125, identifier:t; 126, identifier:heads; 127, identifier:append; 128, identifier:h; 129, attribute; 130, argument_list; 131, identifier:ordered; 132, identifier:append; 133, identifier:t
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 4, 17; 6, 18; 7, 19; 9, 20; 11, 21; 13, 22; 13, 23; 13, 24; 14, 25; 15, 26; 15, 27; 15, 28; 16, 29; 17, 30; 19, 31; 19, 32; 20, 33; 20, 34; 21, 35; 21, 36; 22, 37; 22, 38; 24, 39; 24, 40; 25, 41; 25, 42; 28, 43; 29, 44; 29, 45; 30, 46; 30, 47; 32, 48; 32, 49; 34, 50; 34, 51; 39, 52; 40, 53; 40, 54; 40, 55; 42, 56; 42, 57; 42, 58; 43, 59; 43, 60; 43, 61; 45, 62; 45, 63; 45, 64; 47, 65; 47, 66; 49, 67; 51, 68; 52, 69; 52, 70; 53, 71; 53, 72; 54, 73; 55, 74; 57, 75; 57, 76; 58, 77; 60, 78; 60, 79; 61, 80; 61, 81; 63, 82; 63, 83; 64, 84; 69, 85; 69, 86; 73, 87; 74, 88; 74, 89; 77, 90; 77, 91; 80, 92; 81, 93; 81, 94; 82, 95; 82, 96; 83, 97; 83, 98; 87, 99; 87, 100; 88, 101; 89, 102; 92, 103; 92, 104; 93, 105; 94, 106; 97, 107; 97, 108; 99, 109; 99, 110; 100, 111; 101, 112; 101, 113; 102, 114; 102, 115; 103, 116; 103, 117; 105, 118; 105, 119; 106, 120; 109, 121; 109, 122; 112, 123; 112, 124; 113, 125; 114, 126; 114, 127; 115, 128; 120, 129; 120, 130; 129, 131; 129, 132; 130, 133
def topological_sort(dependency_pairs): "Sort values subject to dependency constraints" num_heads = defaultdict(int) # num arrows pointing in tails = defaultdict(list) # list of arrows going out heads = [] # unique list of heads in order first seen for h, t in dependency_pairs: num_heads[t] += 1 if h in tails: tails[h].append(t) else: tails[h] = [t] heads.append(h) ordered = [h for h in heads if h not in num_heads] for h in ordered: for t in tails[h]: num_heads[t] -= 1 if not num_heads[t]: ordered.append(t) cyclic = [n for n, heads in num_heads.items() if heads] return Results(ordered, cyclic)
0, module; 1, function_definition; 2, function_name:multisorted; 3, parameters; 4, block; 5, identifier:items; 6, list_splat_pattern; 7, expression_statement; 8, if_statement; 9, for_statement; 10, return_statement; 11, identifier:keys; 12, comment:"""Sort by multiple attributes. Args: items: An iterable series to be sorted. *keys: Key objects which extract key values from the items. The first key will be the most significant, and the last key the least significant. If no key functions are provided, the items will be sorted in ascending natural order. Returns: A list of items sorted according to keys. """; 13, comparison_operator:len(keys) == 0; 14, block; 15, identifier:key; 16, call; 17, block; 18, identifier:items; 19, call; 20, integer:0; 21, expression_statement; 22, identifier:reversed; 23, argument_list; 24, expression_statement; 25, identifier:len; 26, argument_list; 27, assignment; 28, identifier:keys; 29, assignment; 30, identifier:keys; 31, identifier:keys; 32, list; 33, identifier:items; 34, call; 35, call; 36, identifier:sorted; 37, argument_list; 38, identifier:asc; 39, argument_list; 40, identifier:items; 41, keyword_argument; 42, keyword_argument; 43, identifier:key; 44, attribute; 45, identifier:reverse; 46, attribute; 47, identifier:key; 48, identifier:func; 49, identifier:key; 50, identifier:reverse
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 6, 11; 7, 12; 8, 13; 8, 14; 9, 15; 9, 16; 9, 17; 10, 18; 13, 19; 13, 20; 14, 21; 16, 22; 16, 23; 17, 24; 19, 25; 19, 26; 21, 27; 23, 28; 24, 29; 26, 30; 27, 31; 27, 32; 29, 33; 29, 34; 32, 35; 34, 36; 34, 37; 35, 38; 35, 39; 37, 40; 37, 41; 37, 42; 41, 43; 41, 44; 42, 45; 42, 46; 44, 47; 44, 48; 46, 49; 46, 50
def multisorted(items, *keys): """Sort by multiple attributes. Args: items: An iterable series to be sorted. *keys: Key objects which extract key values from the items. The first key will be the most significant, and the last key the least significant. If no key functions are provided, the items will be sorted in ascending natural order. Returns: A list of items sorted according to keys. """ if len(keys) == 0: keys = [asc()] for key in reversed(keys): items = sorted(items, key=key.func, reverse=key.reverse) return items
0, module; 1, function_definition; 2, function_name:tuplesorted; 3, parameters; 4, block; 5, identifier:items; 6, list_splat_pattern; 7, expression_statement; 8, comment:# Transform the keys so each works on one item of the tuple; 9, expression_statement; 10, return_statement; 11, identifier:keys; 12, comment:"""Sort by tuples with a different key for each item. Args: items: An iterable series of sequences (typically tuples) *keys: Key objects which transform individual elements of each tuple into sort keys. The zeroth object transforms the zeroth element of each tuple, the first key object transforms the first element of each tuple, and so on. Returns: A list of items sorted according to keys. """; 13, assignment; 14, call; 15, identifier:tuple_keys; 16, list_comprehension; 17, identifier:multisorted; 18, argument_list; 19, call; 20, for_in_clause; 21, identifier:items; 22, list_splat; 23, identifier:Key; 24, argument_list; 25, pattern_list; 26, call; 27, identifier:tuple_keys; 28, keyword_argument; 29, keyword_argument; 30, identifier:index; 31, identifier:key; 32, identifier:enumerate; 33, argument_list; 34, identifier:func; 35, lambda; 36, identifier:reverse; 37, attribute; 38, identifier:keys; 39, lambda_parameters; 40, call; 41, identifier:key; 42, identifier:reverse; 43, identifier:t; 44, default_parameter; 45, default_parameter; 46, attribute; 47, argument_list; 48, identifier:i; 49, identifier:index; 50, identifier:k; 51, identifier:key; 52, identifier:k; 53, identifier:func; 54, subscript; 55, identifier:t; 56, identifier:i
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 6, 11; 7, 12; 9, 13; 10, 14; 13, 15; 13, 16; 14, 17; 14, 18; 16, 19; 16, 20; 18, 21; 18, 22; 19, 23; 19, 24; 20, 25; 20, 26; 22, 27; 24, 28; 24, 29; 25, 30; 25, 31; 26, 32; 26, 33; 28, 34; 28, 35; 29, 36; 29, 37; 33, 38; 35, 39; 35, 40; 37, 41; 37, 42; 39, 43; 39, 44; 39, 45; 40, 46; 40, 47; 44, 48; 44, 49; 45, 50; 45, 51; 46, 52; 46, 53; 47, 54; 54, 55; 54, 56
def tuplesorted(items, *keys): """Sort by tuples with a different key for each item. Args: items: An iterable series of sequences (typically tuples) *keys: Key objects which transform individual elements of each tuple into sort keys. The zeroth object transforms the zeroth element of each tuple, the first key object transforms the first element of each tuple, and so on. Returns: A list of items sorted according to keys. """ # Transform the keys so each works on one item of the tuple tuple_keys = [ Key(func=lambda t, i=index, k=key: k.func(t[i]), reverse=key.reverse) for index, key in enumerate(keys) ] return multisorted(items, *tuple_keys)
0, module; 1, function_definition; 2, function_name:list_formats; 3, parameters; 4, block; 5, identifier:self; 6, identifier:node; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, if_statement; 11, for_statement; 12, expression_statement; 13, return_statement; 14, identifier:path; 15, tuple; 16, identifier:formats; 17, None; 18, comment:""" Lists the object formats in sorted order. :param node: Root node to start listing the formats from. :type node: AbstractCompositeNode :param path: Walked paths. :type path: tuple :param formats: Formats. :type formats: list :return: Formats. :rtype: list """; 19, comparison_operator:formats == None; 20, block; 21, identifier:child; 22, attribute; 23, block; 24, boolean_operator; 25, call; 26, identifier:formats; 27, None; 28, expression_statement; 29, identifier:node; 30, identifier:children; 31, expression_statement; 32, identifier:path; 33, call; 34, identifier:sorted; 35, argument_list; 36, assignment; 37, call; 38, attribute; 39, argument_list; 40, identifier:formats; 41, identifier:formats; 42, list; 43, attribute; 44, argument_list; 45, identifier:formats; 46, identifier:append; 47, call; 48, identifier:self; 49, identifier:list_formats; 50, identifier:child; 51, binary_operator:path + (child.name,); 52, identifier:formats; 53, attribute; 54, argument_list; 55, identifier:path; 56, tuple; 57, string:"."; 58, identifier:join; 59, identifier:path; 60, attribute; 61, identifier:child; 62, identifier:name
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 7, 14; 7, 15; 8, 16; 8, 17; 9, 18; 10, 19; 10, 20; 11, 21; 11, 22; 11, 23; 12, 24; 13, 25; 19, 26; 19, 27; 20, 28; 22, 29; 22, 30; 23, 31; 24, 32; 24, 33; 25, 34; 25, 35; 28, 36; 31, 37; 33, 38; 33, 39; 35, 40; 36, 41; 36, 42; 37, 43; 37, 44; 38, 45; 38, 46; 39, 47; 43, 48; 43, 49; 44, 50; 44, 51; 44, 52; 47, 53; 47, 54; 51, 55; 51, 56; 53, 57; 53, 58; 54, 59; 56, 60; 60, 61; 60, 62
def list_formats(self, node, path=(), formats=None): """ Lists the object formats in sorted order. :param node: Root node to start listing the formats from. :type node: AbstractCompositeNode :param path: Walked paths. :type path: tuple :param formats: Formats. :type formats: list :return: Formats. :rtype: list """ if formats == None: formats = [] for child in node.children: self.list_formats(child, path + (child.name,), formats) path and formats.append(".".join(path)) return sorted(formats)
0, module; 1, function_definition; 2, function_name:ls; 3, parameters; 4, block; 5, default_parameter; 6, default_parameter; 7, default_parameter; 8, expression_statement; 9, function_definition; 10, if_statement; 11, identifier:root; 12, string:"."; 13, identifier:abspaths; 14, False; 15, identifier:recursive; 16, False; 17, comment:""" Return a list of files in directory. Directory listings are sorted alphabetically. If the named directory is a file, return it's path. Examples: >>> fs.ls("foo") ["a", "b", "c"] >>> fs.ls("foo/a") ["foo/a"] >>> fs.ls("foo", abspaths=True) ["/home/test/foo/a", "/home/test/foo/b", "/home/test/foo/c"] >>> fs.ls("foo", recursive=True) ["a", "b", "b/d", "b/d/e", "c"] Arguments: root (str): Path to directory. Can be relative or absolute. abspaths (bool, optional): Return absolute paths if true. recursive (bool, optional): Recursively list subdirectories if true. Returns: list of str: A list of paths. Raises: OSError: If root directory does not exist. """; 18, function_name:_expand_subdirs; 19, parameters; 20, block; 21, call; 22, comment:# If argument is a file, return path.; 23, block; 24, elif_clause; 25, elif_clause; 26, else_clause; 27, identifier:file; 28, if_statement; 29, identifier:isfile; 30, argument_list; 31, return_statement; 32, identifier:abspaths; 33, comment:# Get relative names.; 34, block; 35, identifier:recursive; 36, comment:# Recursively expand subdirectories.; 37, block; 38, comment:# List directory contents.; 39, block; 40, call; 41, block; 42, else_clause; 43, identifier:root; 44, conditional_expression:[abspath(root)] if abspaths else [basename(root)]; 45, expression_statement; 46, comment:# Prepend the absolute path to each relative name.; 47, expression_statement; 48, return_statement; 49, expression_statement; 50, return_statement; 51, return_statement; 52, identifier:isdir; 53, argument_list; 54, return_statement; 55, block; 56, list; 57, identifier:abspaths; 58, list; 59, assignment; 60, assignment; 61, list_comprehension; 62, assignment; 63, call; 64, call; 65, call; 66, binary_operator:[file] + [path(file, x) for x in ls(path(root, file), recursive=True)]; 67, return_statement; 68, call; 69, call; 70, identifier:relpaths; 71, call; 72, identifier:base; 73, call; 74, call; 75, for_in_clause; 76, identifier:paths; 77, call; 78, attribute; 79, argument_list; 80, identifier:list; 81, argument_list; 82, identifier:path; 83, argument_list; 84, list; 85, list_comprehension; 86, list; 87, identifier:abspath; 88, argument_list; 89, identifier:basename; 90, argument_list; 91, identifier:ls; 92, argument_list; 93, identifier:abspath; 94, argument_list; 95, identifier:path; 96, argument_list; 97, identifier:relpath; 98, identifier:relpaths; 99, identifier:ls; 100, argument_list; 101, identifier:labtypes; 102, identifier:flatten; 103, list_comprehension; 104, call; 105, identifier:root; 106, identifier:file; 107, identifier:file; 108, call; 109, for_in_clause; 110, identifier:file; 111, identifier:root; 112, identifier:root; 113, identifier:root; 114, keyword_argument; 115, keyword_argument; 116, identifier:root; 117, identifier:base; 118, identifier:relpath; 119, identifier:root; 120, keyword_argument; 121, keyword_argument; 122, call; 123, for_in_clause; 124, identifier:sorted; 125, argument_list; 126, identifier:path; 127, argument_list; 128, identifier:x; 129, call; 130, identifier:recursive; 131, identifier:recursive; 132, identifier:abspaths; 133, False; 134, identifier:abspaths; 135, identifier:abspaths; 136, identifier:recursive; 137, False; 138, identifier:_expand_subdirs; 139, argument_list; 140, identifier:file; 141, identifier:paths; 142, call; 143, identifier:file; 144, identifier:x; 145, identifier:ls; 146, argument_list; 147, identifier:file; 148, attribute; 149, argument_list; 150, call; 151, keyword_argument; 152, identifier:os; 153, identifier:listdir; 154, identifier:root; 155, identifier:path; 156, argument_list; 157, identifier:recursive; 158, True; 159, identifier:root; 160, identifier:file
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 5, 11; 5, 12; 6, 13; 6, 14; 7, 15; 7, 16; 8, 17; 9, 18; 9, 19; 9, 20; 10, 21; 10, 22; 10, 23; 10, 24; 10, 25; 10, 26; 19, 27; 20, 28; 21, 29; 21, 30; 23, 31; 24, 32; 24, 33; 24, 34; 25, 35; 25, 36; 25, 37; 26, 38; 26, 39; 28, 40; 28, 41; 28, 42; 30, 43; 31, 44; 34, 45; 34, 46; 34, 47; 34, 48; 37, 49; 37, 50; 39, 51; 40, 52; 40, 53; 41, 54; 42, 55; 44, 56; 44, 57; 44, 58; 45, 59; 47, 60; 48, 61; 49, 62; 50, 63; 51, 64; 53, 65; 54, 66; 55, 67; 56, 68; 58, 69; 59, 70; 59, 71; 60, 72; 60, 73; 61, 74; 61, 75; 62, 76; 62, 77; 63, 78; 63, 79; 64, 80; 64, 81; 65, 82; 65, 83; 66, 84; 66, 85; 67, 86; 68, 87; 68, 88; 69, 89; 69, 90; 71, 91; 71, 92; 73, 93; 73, 94; 74, 95; 74, 96; 75, 97; 75, 98; 77, 99; 77, 100; 78, 101; 78, 102; 79, 103; 81, 104; 83, 105; 83, 106; 84, 107; 85, 108; 85, 109; 86, 110; 88, 111; 90, 112; 92, 113; 92, 114; 92, 115; 94, 116; 96, 117; 96, 118; 100, 119; 100, 120; 100, 121; 103, 122; 103, 123; 104, 124; 104, 125; 108, 126; 108, 127; 109, 128; 109, 129; 114, 130; 114, 131; 115, 132; 115, 133; 120, 134; 120, 135; 121, 136; 121, 137; 122, 138; 122, 139; 123, 140; 123, 141; 125, 142; 127, 143; 127, 144; 129, 145; 129, 146; 139, 147; 142, 148; 142, 149; 146, 150; 146, 151; 148, 152; 148, 153; 149, 154; 150, 155; 150, 156; 151, 157; 151, 158; 156, 159; 156, 160
def ls(root=".", abspaths=False, recursive=False): """ Return a list of files in directory. Directory listings are sorted alphabetically. If the named directory is a file, return it's path. Examples: >>> fs.ls("foo") ["a", "b", "c"] >>> fs.ls("foo/a") ["foo/a"] >>> fs.ls("foo", abspaths=True) ["/home/test/foo/a", "/home/test/foo/b", "/home/test/foo/c"] >>> fs.ls("foo", recursive=True) ["a", "b", "b/d", "b/d/e", "c"] Arguments: root (str): Path to directory. Can be relative or absolute. abspaths (bool, optional): Return absolute paths if true. recursive (bool, optional): Recursively list subdirectories if true. Returns: list of str: A list of paths. Raises: OSError: If root directory does not exist. """ def _expand_subdirs(file): if isdir(path(root, file)): return [file] + [path(file, x) for x in ls(path(root, file), recursive=True)] else: return [file] if isfile(root): # If argument is a file, return path. return [abspath(root)] if abspaths else [basename(root)] elif abspaths: # Get relative names. relpaths = ls(root, recursive=recursive, abspaths=False) # Prepend the absolute path to each relative name. base = abspath(root) return [path(base, relpath) for relpath in relpaths] elif recursive: # Recursively expand subdirectories. paths = ls(root, abspaths=abspaths, recursive=False) return labtypes.flatten([_expand_subdirs(file) for file in paths]) else: # List directory contents. return list(sorted(os.listdir(root)))
0, module; 1, function_definition; 2, function_name:list; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, dictionary_splat_pattern; 11, expression_statement; 12, try_statement; 13, identifier:offset; 14, integer:0; 15, identifier:limit; 16, integer:0; 17, identifier:fields; 18, None; 19, identifier:sort; 20, None; 21, identifier:kwargs; 22, comment:"""Return filtered list of documents in a collection. For text-based search, we support searching on a name/string field by regex and text index. So strings passed in to a r=text search are used to filter collections by text index and regex on a named field. :param offset: for pagination, which record to start attribute :param limit: for pagination, how many records to return :param fields: list of field names to return (otherwise returns all) :param sort: list of fields to sort by (prefix with '-' for descending) :param kwargs: key/values to find (only supports equality for now) :returns: a tuple of the list of documents and the total count """; 23, block; 24, except_clause; 25, expression_statement; 26, return_statement; 27, as_pattern; 28, comment:# This is workaround for mongodb v2.4 and 'q' filter params; 29, block; 30, assignment; 31, expression_list; 32, attribute; 33, as_pattern_target; 34, try_statement; 35, expression_statement; 36, expression_statement; 37, expression_statement; 38, expression_statement; 39, return_statement; 40, identifier:cursor; 41, call; 42, call; 43, call; 44, attribute; 45, identifier:OperationFailure; 46, identifier:exc; 47, block; 48, except_clause; 49, call; 50, assignment; 51, call; 52, assignment; 53, expression_list; 54, attribute; 55, argument_list; 56, identifier:list; 57, argument_list; 58, attribute; 59, argument_list; 60, identifier:pymongo; 61, identifier:errors; 62, expression_statement; 63, tuple; 64, block; 65, attribute; 66, argument_list; 67, identifier:kwargs; 68, call; 69, attribute; 70, argument_list; 71, identifier:cursor; 72, call; 73, call; 74, call; 75, identifier:self; 76, identifier:_cursor; 77, keyword_argument; 78, keyword_argument; 79, keyword_argument; 80, keyword_argument; 81, dictionary_splat; 82, identifier:cursor; 83, identifier:cursor; 84, identifier:count; 85, subscript; 86, identifier:KeyError; 87, identifier:IndexError; 88, raise_statement; 89, identifier:LOG; 90, identifier:warn; 91, string:"Falling back to hard-coded mongo v2.4 search behavior"; 92, attribute; 93, argument_list; 94, identifier:LOG; 95, identifier:debug; 96, string:"Modified kwargs: %s"; 97, identifier:kwargs; 98, attribute; 99, argument_list; 100, identifier:list; 101, argument_list; 102, attribute; 103, argument_list; 104, identifier:offset; 105, identifier:offset; 106, identifier:limit; 107, identifier:limit; 108, identifier:fields; 109, identifier:fields; 110, identifier:sort; 111, identifier:sort; 112, identifier:kwargs; 113, subscript; 114, string; 115, identifier:exc; 116, identifier:self; 117, identifier:search_alternative; 118, identifier:limit; 119, dictionary_splat; 120, identifier:self; 121, identifier:_cursor; 122, keyword_argument; 123, keyword_argument; 124, keyword_argument; 125, keyword_argument; 126, dictionary_splat; 127, identifier:cursor; 128, identifier:cursor; 129, identifier:count; 130, subscript; 131, string; 132, string_content:$search; 133, identifier:kwargs; 134, identifier:offset; 135, identifier:offset; 136, identifier:limit; 137, identifier:limit; 138, identifier:fields; 139, identifier:fields; 140, identifier:sort; 141, identifier:sort; 142, identifier:kwargs; 143, subscript; 144, integer:0; 145, string_content:$text; 146, identifier:kwargs; 147, string; 148, string_content:$or
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 4, 11; 4, 12; 6, 13; 6, 14; 7, 15; 7, 16; 8, 17; 8, 18; 9, 19; 9, 20; 10, 21; 11, 22; 12, 23; 12, 24; 23, 25; 23, 26; 24, 27; 24, 28; 24, 29; 25, 30; 26, 31; 27, 32; 27, 33; 29, 34; 29, 35; 29, 36; 29, 37; 29, 38; 29, 39; 30, 40; 30, 41; 31, 42; 31, 43; 32, 44; 32, 45; 33, 46; 34, 47; 34, 48; 35, 49; 36, 50; 37, 51; 38, 52; 39, 53; 41, 54; 41, 55; 42, 56; 42, 57; 43, 58; 43, 59; 44, 60; 44, 61; 47, 62; 48, 63; 48, 64; 49, 65; 49, 66; 50, 67; 50, 68; 51, 69; 51, 70; 52, 71; 52, 72; 53, 73; 53, 74; 54, 75; 54, 76; 55, 77; 55, 78; 55, 79; 55, 80; 55, 81; 57, 82; 58, 83; 58, 84; 62, 85; 63, 86; 63, 87; 64, 88; 65, 89; 65, 90; 66, 91; 68, 92; 68, 93; 69, 94; 69, 95; 70, 96; 70, 97; 72, 98; 72, 99; 73, 100; 73, 101; 74, 102; 74, 103; 77, 104; 77, 105; 78, 106; 78, 107; 79, 108; 79, 109; 80, 110; 80, 111; 81, 112; 85, 113; 85, 114; 88, 115; 92, 116; 92, 117; 93, 118; 93, 119; 98, 120; 98, 121; 99, 122; 99, 123; 99, 124; 99, 125; 99, 126; 101, 127; 102, 128; 102, 129; 113, 130; 113, 131; 114, 132; 119, 133; 122, 134; 122, 135; 123, 136; 123, 137; 124, 138; 124, 139; 125, 140; 125, 141; 126, 142; 130, 143; 130, 144; 131, 145; 143, 146; 143, 147; 147, 148
def list(self, offset=0, limit=0, fields=None, sort=None, **kwargs): """Return filtered list of documents in a collection. For text-based search, we support searching on a name/string field by regex and text index. So strings passed in to a r=text search are used to filter collections by text index and regex on a named field. :param offset: for pagination, which record to start attribute :param limit: for pagination, how many records to return :param fields: list of field names to return (otherwise returns all) :param sort: list of fields to sort by (prefix with '-' for descending) :param kwargs: key/values to find (only supports equality for now) :returns: a tuple of the list of documents and the total count """ try: cursor = self._cursor(offset=offset, limit=limit, fields=fields, sort=sort, **kwargs) return list(cursor), cursor.count() except pymongo.errors.OperationFailure as exc: # This is workaround for mongodb v2.4 and 'q' filter params try: kwargs['$or'][0]['$text']['$search'] except (KeyError, IndexError): raise exc LOG.warn("Falling back to hard-coded mongo v2.4 search behavior") kwargs = self.search_alternative(limit, **kwargs) LOG.debug("Modified kwargs: %s", kwargs) cursor = self._cursor(offset=offset, limit=limit, fields=fields, sort=sort, **kwargs) return list(cursor), cursor.count()
0, module; 1, function_definition; 2, function_name:_cursor; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, dictionary_splat_pattern; 11, expression_statement; 12, expression_statement; 13, if_statement; 14, expression_statement; 15, if_statement; 16, expression_statement; 17, return_statement; 18, identifier:offset; 19, integer:0; 20, identifier:limit; 21, integer:0; 22, identifier:fields; 23, None; 24, identifier:sort; 25, None; 26, identifier:kwargs; 27, comment:"""Return a cursor on a filtered list of documents in a collection. :param offset: for pagination, which record to start attribute :param limit: for pagination, how many records to return :param fields: list of field names to return (otherwise returns all) :param sort: list of fields to sort by (prefix with '-' for descending) :param kwargs: key/values to find (only supports equality for now) :returns: a tuple of a cursor on documents and the total count Note: close the cursor after using it if you don't exhaust it """; 28, assignment; 29, identifier:fields; 30, block; 31, assignment; 32, identifier:sort; 33, block; 34, call; 35, identifier:results; 36, identifier:projection; 37, dictionary; 38, expression_statement; 39, identifier:results; 40, call; 41, expression_statement; 42, for_statement; 43, expression_statement; 44, attribute; 45, argument_list; 46, pair; 47, call; 48, attribute; 49, argument_list; 50, assignment; 51, pattern_list; 52, call; 53, block; 54, call; 55, call; 56, identifier:limit; 57, boolean_operator; 58, string; 59, False; 60, attribute; 61, argument_list; 62, attribute; 63, identifier:find; 64, identifier:kwargs; 65, identifier:projection; 66, identifier:sort_pairs; 67, subscript; 68, identifier:index; 69, identifier:field; 70, identifier:enumerate; 71, argument_list; 72, if_statement; 73, attribute; 74, argument_list; 75, attribute; 76, argument_list; 77, identifier:limit; 78, integer:0; 79, string_content:_id; 80, identifier:projection; 81, identifier:update; 82, dictionary_comprehension; 83, identifier:self; 84, identifier:_collection; 85, identifier:sort; 86, slice; 87, identifier:sort; 88, comparison_operator:field[0] == "-"; 89, block; 90, else_clause; 91, identifier:results; 92, identifier:sort; 93, identifier:sort_pairs; 94, identifier:results; 95, identifier:skip; 96, boolean_operator; 97, pair; 98, for_in_clause; 99, subscript; 100, string:"-"; 101, expression_statement; 102, block; 103, identifier:offset; 104, integer:0; 105, identifier:field; 106, True; 107, identifier:field; 108, identifier:fields; 109, identifier:field; 110, integer:0; 111, assignment; 112, expression_statement; 113, subscript; 114, tuple; 115, assignment; 116, identifier:sort_pairs; 117, identifier:index; 118, subscript; 119, attribute; 120, subscript; 121, tuple; 122, identifier:field; 123, slice; 124, identifier:pymongo; 125, identifier:DESCENDING; 126, identifier:sort_pairs; 127, identifier:index; 128, identifier:field; 129, attribute; 130, integer:1; 131, identifier:pymongo; 132, identifier:ASCENDING
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 4, 17; 6, 18; 6, 19; 7, 20; 7, 21; 8, 22; 8, 23; 9, 24; 9, 25; 10, 26; 11, 27; 12, 28; 13, 29; 13, 30; 14, 31; 15, 32; 15, 33; 16, 34; 17, 35; 28, 36; 28, 37; 30, 38; 31, 39; 31, 40; 33, 41; 33, 42; 33, 43; 34, 44; 34, 45; 37, 46; 38, 47; 40, 48; 40, 49; 41, 50; 42, 51; 42, 52; 42, 53; 43, 54; 44, 55; 44, 56; 45, 57; 46, 58; 46, 59; 47, 60; 47, 61; 48, 62; 48, 63; 49, 64; 49, 65; 50, 66; 50, 67; 51, 68; 51, 69; 52, 70; 52, 71; 53, 72; 54, 73; 54, 74; 55, 75; 55, 76; 57, 77; 57, 78; 58, 79; 60, 80; 60, 81; 61, 82; 62, 83; 62, 84; 67, 85; 67, 86; 71, 87; 72, 88; 72, 89; 72, 90; 73, 91; 73, 92; 74, 93; 75, 94; 75, 95; 76, 96; 82, 97; 82, 98; 88, 99; 88, 100; 89, 101; 90, 102; 96, 103; 96, 104; 97, 105; 97, 106; 98, 107; 98, 108; 99, 109; 99, 110; 101, 111; 102, 112; 111, 113; 111, 114; 112, 115; 113, 116; 113, 117; 114, 118; 114, 119; 115, 120; 115, 121; 118, 122; 118, 123; 119, 124; 119, 125; 120, 126; 120, 127; 121, 128; 121, 129; 123, 130; 129, 131; 129, 132
def _cursor(self, offset=0, limit=0, fields=None, sort=None, **kwargs): """Return a cursor on a filtered list of documents in a collection. :param offset: for pagination, which record to start attribute :param limit: for pagination, how many records to return :param fields: list of field names to return (otherwise returns all) :param sort: list of fields to sort by (prefix with '-' for descending) :param kwargs: key/values to find (only supports equality for now) :returns: a tuple of a cursor on documents and the total count Note: close the cursor after using it if you don't exhaust it """ projection = {'_id': False} if fields: projection.update({field: True for field in fields}) results = self._collection.find(kwargs, projection) if sort: sort_pairs = sort[:] for index, field in enumerate(sort): if field[0] == "-": sort_pairs[index] = (field[1:], pymongo.DESCENDING) else: sort_pairs[index] = (field, pymongo.ASCENDING) results.sort(sort_pairs) results.skip(offset or 0).limit(limit or 0) return results
0, module; 1, function_definition; 2, function_name:insert; 3, parameters; 4, block; 5, identifier:self; 6, identifier:item; 7, identifier:low_value; 8, expression_statement; 9, return_statement; 10, comment:""" Create a new node and insert it into a sorted list. Calls the item duplicator, if any, on the item. If low_value is true, starts searching from the start of the list, otherwise searches from the end. Use the item comparator, if any, to find where to place the new node. Returns a handle to the new node, or NULL if memory was exhausted. Resets the cursor to the list head. """; 11, call; 12, identifier:c_void_p; 13, argument_list; 14, call; 15, attribute; 16, argument_list; 17, identifier:lib; 18, identifier:zlistx_insert; 19, attribute; 20, identifier:item; 21, identifier:low_value; 22, identifier:self; 23, identifier:_as_parameter_
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 8, 10; 9, 11; 11, 12; 11, 13; 13, 14; 14, 15; 14, 16; 15, 17; 15, 18; 16, 19; 16, 20; 16, 21; 19, 22; 19, 23
def insert(self, item, low_value): """ Create a new node and insert it into a sorted list. Calls the item duplicator, if any, on the item. If low_value is true, starts searching from the start of the list, otherwise searches from the end. Use the item comparator, if any, to find where to place the new node. Returns a handle to the new node, or NULL if memory was exhausted. Resets the cursor to the list head. """ return c_void_p(lib.zlistx_insert(self._as_parameter_, item, low_value))
0, module; 1, function_definition; 2, function_name:reorder; 3, parameters; 4, block; 5, identifier:self; 6, identifier:handle; 7, identifier:low_value; 8, expression_statement; 9, return_statement; 10, comment:""" Move an item, specified by handle, into position in a sorted list. Uses the item comparator, if any, to determine the new location. If low_value is true, starts searching from the start of the list, otherwise searches from the end. """; 11, call; 12, attribute; 13, argument_list; 14, identifier:lib; 15, identifier:zlistx_reorder; 16, attribute; 17, identifier:handle; 18, identifier:low_value; 19, identifier:self; 20, identifier:_as_parameter_
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 8, 10; 9, 11; 11, 12; 11, 13; 12, 14; 12, 15; 13, 16; 13, 17; 13, 18; 16, 19; 16, 20
def reorder(self, handle, low_value): """ Move an item, specified by handle, into position in a sorted list. Uses the item comparator, if any, to determine the new location. If low_value is true, starts searching from the start of the list, otherwise searches from the end. """ return lib.zlistx_reorder(self._as_parameter_, handle, low_value)
0, module; 1, function_definition; 2, function_name:process_params; 3, parameters; 4, block; 5, identifier:request; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, if_statement; 11, expression_statement; 12, if_statement; 13, expression_statement; 14, for_statement; 15, if_statement; 16, if_statement; 17, return_statement; 18, identifier:standard_params; 19, identifier:STANDARD_QUERY_PARAMS; 20, identifier:filter_fields; 21, None; 22, identifier:defaults; 23, None; 24, comment:"""Parse query params. Parses, validates, and converts query into a consistent format. :keyword request: the bottle request :keyword standard_params: query params that are present in most of our (opinionated) APIs (ex. limit, offset, sort, q, and facets) :keyword filter_fields: list of field names to allow filtering on :keyword defaults: dict of params and their default values :retuns: dict of query params with supplied values (string or list) """; 25, not_operator; 26, block; 27, assignment; 28, identifier:unfilterable; 29, block; 30, assignment; 31, identifier:key; 32, attribute; 33, block; 34, comparison_operator:'sort' in request.query; 35, block; 36, comparison_operator:'q' in request.query; 37, block; 38, identifier:query_fields; 39, identifier:filter_fields; 40, expression_statement; 41, identifier:unfilterable; 42, parenthesized_expression; 43, expression_statement; 44, identifier:query_fields; 45, boolean_operator; 46, identifier:request; 47, identifier:query; 48, if_statement; 49, string; 50, attribute; 51, expression_statement; 52, expression_statement; 53, expression_statement; 54, string; 55, attribute; 56, expression_statement; 57, expression_statement; 58, expression_statement; 59, assignment; 60, binary_operator:set(request.query.keys()) - set(filter_fields) - set(standard_params); 61, call; 62, identifier:defaults; 63, dictionary; 64, comparison_operator:key in filter_fields; 65, comment:# turns ?netloc=this.com&netloc=that.com,what.net into; 66, comment:# {'netloc': ['this.com', 'that.com', 'what.net']}; 67, block; 68, string_content:sort; 69, identifier:request; 70, identifier:query; 71, assignment; 72, assignment; 73, assignment; 74, string_content:q; 75, identifier:request; 76, identifier:query; 77, assignment; 78, assignment; 79, assignment; 80, identifier:filter_fields; 81, list; 82, binary_operator:set(request.query.keys()) - set(filter_fields); 83, call; 84, attribute; 85, argument_list; 86, identifier:key; 87, identifier:filter_fields; 88, expression_statement; 89, expression_statement; 90, if_statement; 91, identifier:sort; 92, call; 93, identifier:sort; 94, call; 95, subscript; 96, identifier:sort; 97, identifier:search; 98, call; 99, identifier:search; 100, call; 101, subscript; 102, identifier:search; 103, call; 104, call; 105, identifier:set; 106, argument_list; 107, identifier:bottle; 108, identifier:abort; 109, integer:400; 110, binary_operator:"The following query params were invalid: %s. " "Try one (or more) of %s." % (", ".join(unfilterable), ", ".join(filter_fields)); 111, assignment; 112, assignment; 113, comparison_operator:len(matches) > 1; 114, block; 115, else_clause; 116, attribute; 117, argument_list; 118, identifier:list; 119, argument_list; 120, identifier:query_fields; 121, string; 122, attribute; 123, argument_list; 124, identifier:list; 125, argument_list; 126, identifier:query_fields; 127, string; 128, identifier:set; 129, argument_list; 130, identifier:set; 131, argument_list; 132, identifier:standard_params; 133, concatenated_string; 134, tuple; 135, identifier:matches; 136, call; 137, identifier:matches; 138, call; 139, call; 140, integer:1; 141, expression_statement; 142, block; 143, attribute; 144, identifier:getall; 145, string; 146, call; 147, string_content:sort; 148, attribute; 149, identifier:getall; 150, string; 151, call; 152, string_content:q; 153, call; 154, identifier:filter_fields; 155, string:"The following query params were invalid: %s. "; 156, string:"Try one (or more) of %s."; 157, call; 158, call; 159, attribute; 160, argument_list; 161, identifier:list; 162, argument_list; 163, identifier:len; 164, argument_list; 165, assignment; 166, expression_statement; 167, identifier:request; 168, identifier:query; 169, string_content:sort; 170, attribute; 171, argument_list; 172, identifier:request; 173, identifier:query; 174, string_content:q; 175, attribute; 176, argument_list; 177, attribute; 178, argument_list; 179, attribute; 180, argument_list; 181, attribute; 182, argument_list; 183, attribute; 184, identifier:getall; 185, identifier:key; 186, call; 187, identifier:matches; 188, subscript; 189, identifier:matches; 190, assignment; 191, identifier:itertools; 192, identifier:chain; 193, list_splat; 194, identifier:itertools; 195, identifier:chain; 196, list_splat; 197, attribute; 198, identifier:keys; 199, string:", "; 200, identifier:join; 201, identifier:unfilterable; 202, string:", "; 203, identifier:join; 204, identifier:filter_fields; 205, identifier:request; 206, identifier:query; 207, attribute; 208, argument_list; 209, identifier:query_fields; 210, identifier:key; 211, subscript; 212, subscript; 213, generator_expression; 214, generator_expression; 215, identifier:request; 216, identifier:query; 217, identifier:itertools; 218, identifier:chain; 219, list_splat; 220, identifier:query_fields; 221, identifier:key; 222, identifier:matches; 223, integer:0; 224, call; 225, for_in_clause; 226, call; 227, for_in_clause; 228, if_clause; 229, generator_expression; 230, identifier:comma_separated_strings; 231, argument_list; 232, identifier:k; 233, identifier:sort; 234, identifier:comma_separated_strings; 235, argument_list; 236, identifier:k; 237, identifier:search; 238, identifier:k; 239, call; 240, for_in_clause; 241, call; 242, identifier:k; 243, attribute; 244, argument_list; 245, identifier:k; 246, identifier:matches; 247, identifier:str; 248, argument_list; 249, identifier:k; 250, identifier:split; 251, string; 252, identifier:k; 253, string_content:,
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 4, 17; 6, 18; 6, 19; 7, 20; 7, 21; 8, 22; 8, 23; 9, 24; 10, 25; 10, 26; 11, 27; 12, 28; 12, 29; 13, 30; 14, 31; 14, 32; 14, 33; 15, 34; 15, 35; 16, 36; 16, 37; 17, 38; 25, 39; 26, 40; 27, 41; 27, 42; 29, 43; 30, 44; 30, 45; 32, 46; 32, 47; 33, 48; 34, 49; 34, 50; 35, 51; 35, 52; 35, 53; 36, 54; 36, 55; 37, 56; 37, 57; 37, 58; 40, 59; 42, 60; 43, 61; 45, 62; 45, 63; 48, 64; 48, 65; 48, 66; 48, 67; 49, 68; 50, 69; 50, 70; 51, 71; 52, 72; 53, 73; 54, 74; 55, 75; 55, 76; 56, 77; 57, 78; 58, 79; 59, 80; 59, 81; 60, 82; 60, 83; 61, 84; 61, 85; 64, 86; 64, 87; 67, 88; 67, 89; 67, 90; 71, 91; 71, 92; 72, 93; 72, 94; 73, 95; 73, 96; 77, 97; 77, 98; 78, 99; 78, 100; 79, 101; 79, 102; 82, 103; 82, 104; 83, 105; 83, 106; 84, 107; 84, 108; 85, 109; 85, 110; 88, 111; 89, 112; 90, 113; 90, 114; 90, 115; 92, 116; 92, 117; 94, 118; 94, 119; 95, 120; 95, 121; 98, 122; 98, 123; 100, 124; 100, 125; 101, 126; 101, 127; 103, 128; 103, 129; 104, 130; 104, 131; 106, 132; 110, 133; 110, 134; 111, 135; 111, 136; 112, 137; 112, 138; 113, 139; 113, 140; 114, 141; 115, 142; 116, 143; 116, 144; 117, 145; 119, 146; 121, 147; 122, 148; 122, 149; 123, 150; 125, 151; 127, 152; 129, 153; 131, 154; 133, 155; 133, 156; 134, 157; 134, 158; 136, 159; 136, 160; 138, 161; 138, 162; 139, 163; 139, 164; 141, 165; 142, 166; 143, 167; 143, 168; 145, 169; 146, 170; 146, 171; 148, 172; 148, 173; 150, 174; 151, 175; 151, 176; 153, 177; 153, 178; 157, 179; 157, 180; 158, 181; 158, 182; 159, 183; 159, 184; 160, 185; 162, 186; 164, 187; 165, 188; 165, 189; 166, 190; 170, 191; 170, 192; 171, 193; 175, 194; 175, 195; 176, 196; 177, 197; 177, 198; 179, 199; 179, 200; 180, 201; 181, 202; 181, 203; 182, 204; 183, 205; 183, 206; 186, 207; 186, 208; 188, 209; 188, 210; 190, 211; 190, 212; 193, 213; 196, 214; 197, 215; 197, 216; 207, 217; 207, 218; 208, 219; 211, 220; 211, 221; 212, 222; 212, 223; 213, 224; 213, 225; 214, 226; 214, 227; 214, 228; 219, 229; 224, 230; 224, 231; 225, 232; 225, 233; 226, 234; 226, 235; 227, 236; 227, 237; 228, 238; 229, 239; 229, 240; 231, 241; 235, 242; 239, 243; 239, 244; 240, 245; 240, 246; 241, 247; 241, 248; 243, 249; 243, 250; 244, 251; 248, 252; 251, 253
def process_params(request, standard_params=STANDARD_QUERY_PARAMS, filter_fields=None, defaults=None): """Parse query params. Parses, validates, and converts query into a consistent format. :keyword request: the bottle request :keyword standard_params: query params that are present in most of our (opinionated) APIs (ex. limit, offset, sort, q, and facets) :keyword filter_fields: list of field names to allow filtering on :keyword defaults: dict of params and their default values :retuns: dict of query params with supplied values (string or list) """ if not filter_fields: filter_fields = [] unfilterable = (set(request.query.keys()) - set(filter_fields) - set(standard_params)) if unfilterable: bottle.abort(400, "The following query params were invalid: %s. " "Try one (or more) of %s." % (", ".join(unfilterable), ", ".join(filter_fields))) query_fields = defaults or {} for key in request.query: if key in filter_fields: # turns ?netloc=this.com&netloc=that.com,what.net into # {'netloc': ['this.com', 'that.com', 'what.net']} matches = request.query.getall(key) matches = list(itertools.chain(*(k.split(',') for k in matches))) if len(matches) > 1: query_fields[key] = matches else: query_fields[key] = matches[0] if 'sort' in request.query: sort = request.query.getall('sort') sort = list(itertools.chain(*( comma_separated_strings(str(k)) for k in sort))) query_fields['sort'] = sort if 'q' in request.query: search = request.query.getall('q') search = list(itertools.chain(*( comma_separated_strings(k) for k in search if k))) query_fields['q'] = search return query_fields
0, module; 1, function_definition; 2, function_name:_weave_dohist; 3, parameters; 4, block; 5, identifier:data; 6, identifier:s; 7, identifier:binsize; 8, identifier:hist; 9, identifier:rev; 10, default_parameter; 11, default_parameter; 12, if_statement; 13, expression_statement; 14, expression_statement; 15, expression_statement; 16, return_statement; 17, identifier:dorev; 18, False; 19, identifier:verbose; 20, integer:0; 21, identifier:dorev; 22, block; 23, else_clause; 24, comment:""" Weave version of histogram with reverse_indices s is an index into data, sorted and possibly a subset """; 25, assignment; 26, call; 27, expression_statement; 28, block; 29, identifier:code; 30, comment:""" int64_t nbin = hist.size(); int64_t binnum_old = -1; // index of minimum value int64_t imin = s(0); for (int64_t i=0; i<s.size(); i++) { int64_t offset = i+nbin+1; int64_t data_index = s(i); if (dorev) { rev(offset) = data_index; } int64_t binnum = (int64_t) ( (data(data_index)-data(imin))/binsize); if (binnum >= 0 && binnum < nbin) { if (dorev && (binnum > binnum_old) ) { int64_t tbin = binnum_old + 1; while (tbin <= binnum) { rev(tbin) = offset; tbin++; } } hist(binnum) = hist(binnum) + 1; binnum_old = binnum; } } int64_t tbin = binnum_old + 1; while (tbin <= nbin) { if (dorev) { rev(tbin) = rev.size(); } tbin++; } """; 31, attribute; 32, argument_list; 33, assignment; 34, expression_statement; 35, attribute; 36, identifier:inline; 37, identifier:code; 38, list; 39, keyword_argument; 40, keyword_argument; 41, identifier:dorev; 42, integer:1; 43, assignment; 44, identifier:scipy; 45, identifier:weave; 46, string; 47, string; 48, string; 49, string; 50, string; 51, string; 52, identifier:type_converters; 53, attribute; 54, identifier:verbose; 55, identifier:verbose; 56, identifier:dorev; 57, integer:0; 58, string_content:data; 59, string_content:s; 60, string_content:binsize; 61, string_content:hist; 62, string_content:rev; 63, string_content:dorev; 64, attribute; 65, identifier:blitz; 66, attribute; 67, identifier:converters; 68, identifier:scipy; 69, identifier:weave
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 10, 17; 10, 18; 11, 19; 11, 20; 12, 21; 12, 22; 12, 23; 13, 24; 14, 25; 15, 26; 22, 27; 23, 28; 25, 29; 25, 30; 26, 31; 26, 32; 27, 33; 28, 34; 31, 35; 31, 36; 32, 37; 32, 38; 32, 39; 32, 40; 33, 41; 33, 42; 34, 43; 35, 44; 35, 45; 38, 46; 38, 47; 38, 48; 38, 49; 38, 50; 38, 51; 39, 52; 39, 53; 40, 54; 40, 55; 43, 56; 43, 57; 46, 58; 47, 59; 48, 60; 49, 61; 50, 62; 51, 63; 53, 64; 53, 65; 64, 66; 64, 67; 66, 68; 66, 69
def _weave_dohist(data, s, binsize, hist, rev, dorev=False, verbose=0): if dorev: dorev=1 else: dorev=0 """ Weave version of histogram with reverse_indices s is an index into data, sorted and possibly a subset """ code = """ int64_t nbin = hist.size(); int64_t binnum_old = -1; // index of minimum value int64_t imin = s(0); for (int64_t i=0; i<s.size(); i++) { int64_t offset = i+nbin+1; int64_t data_index = s(i); if (dorev) { rev(offset) = data_index; } int64_t binnum = (int64_t) ( (data(data_index)-data(imin))/binsize); if (binnum >= 0 && binnum < nbin) { if (dorev && (binnum > binnum_old) ) { int64_t tbin = binnum_old + 1; while (tbin <= binnum) { rev(tbin) = offset; tbin++; } } hist(binnum) = hist(binnum) + 1; binnum_old = binnum; } } int64_t tbin = binnum_old + 1; while (tbin <= nbin) { if (dorev) { rev(tbin) = rev.size(); } tbin++; } """ scipy.weave.inline(code, ['data','s','binsize','hist','rev','dorev'], type_converters = scipy.weave.converters.blitz, verbose=verbose) return
0, module; 1, function_definition; 2, function_name:loose_search; 3, parameters; 4, block; 5, identifier:self; 6, identifier:asset_manager_id; 7, default_parameter; 8, dictionary_splat_pattern; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, for_statement; 14, expression_statement; 15, if_statement; 16, identifier:query; 17, string; 18, identifier:kwargs; 19, comment:""" Asset search API. Possible kwargs: * threshold: int (default = 0) * page_no: int (default = 1) * page_size: int (default = 100) * sort_fields: list (default = []) * asset_types: list (default = []) * include_public: bool (default = True) * include_data_sources: bool (default = True) """; 20, call; 21, assignment; 22, assignment; 23, pattern_list; 24, call; 25, block; 26, assignment; 27, attribute; 28, block; 29, else_clause; 30, attribute; 31, argument_list; 32, identifier:url; 33, call; 34, identifier:params; 35, dictionary; 36, identifier:k; 37, identifier:v; 38, attribute; 39, argument_list; 40, if_statement; 41, expression_statement; 42, identifier:response; 43, call; 44, identifier:response; 45, identifier:ok; 46, expression_statement; 47, expression_statement; 48, expression_statement; 49, return_statement; 50, block; 51, attribute; 52, identifier:info; 53, string; 54, identifier:asset_manager_id; 55, attribute; 56, argument_list; 57, pair; 58, identifier:kwargs; 59, identifier:items; 60, boolean_operator; 61, block; 62, assignment; 63, attribute; 64, argument_list; 65, assignment; 66, assignment; 67, call; 68, identifier:assets; 69, expression_statement; 70, expression_statement; 71, identifier:self; 72, identifier:logger; 73, string_content:Asset Search - Asset Manager: %s; 74, string; 75, identifier:format; 76, keyword_argument; 77, keyword_argument; 78, string; 79, identifier:query; 80, not_operator; 81, call; 82, expression_statement; 83, subscript; 84, identifier:v; 85, attribute; 86, identifier:get; 87, identifier:url; 88, keyword_argument; 89, identifier:data; 90, call; 91, identifier:assets; 92, list_comprehension; 93, attribute; 94, argument_list; 95, call; 96, call; 97, string_content:{endpoint}/assets/search/{asset_manager_id}; 98, identifier:asset_manager_id; 99, identifier:asset_manager_id; 100, identifier:endpoint; 101, attribute; 102, string_content:query; 103, call; 104, identifier:isinstance; 105, argument_list; 106, assignment; 107, identifier:params; 108, identifier:k; 109, identifier:self; 110, identifier:session; 111, identifier:params; 112, identifier:params; 113, attribute; 114, argument_list; 115, call; 116, for_in_clause; 117, attribute; 118, identifier:info; 119, string; 120, call; 121, attribute; 122, argument_list; 123, attribute; 124, argument_list; 125, identifier:self; 126, identifier:endpoint; 127, identifier:isinstance; 128, argument_list; 129, identifier:v; 130, identifier:Iterable; 131, identifier:v; 132, call; 133, identifier:response; 134, identifier:json; 135, identifier:json_to_asset; 136, argument_list; 137, identifier:json_asset; 138, call; 139, identifier:self; 140, identifier:logger; 141, string_content:Returned %s Assets.; 142, identifier:len; 143, argument_list; 144, attribute; 145, identifier:error; 146, attribute; 147, identifier:response; 148, identifier:raise_for_status; 149, identifier:v; 150, identifier:str; 151, attribute; 152, generator_expression; 153, identifier:json_asset; 154, attribute; 155, argument_list; 156, identifier:assets; 157, identifier:self; 158, identifier:logger; 159, identifier:response; 160, identifier:text; 161, string; 162, identifier:join; 163, call; 164, for_in_clause; 165, identifier:data; 166, identifier:get; 167, string; 168, list; 169, string_content:,; 170, identifier:str; 171, argument_list; 172, identifier:i; 173, identifier:v; 174, string_content:hits; 175, identifier:i
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 7, 16; 7, 17; 8, 18; 9, 19; 10, 20; 11, 21; 12, 22; 13, 23; 13, 24; 13, 25; 14, 26; 15, 27; 15, 28; 15, 29; 20, 30; 20, 31; 21, 32; 21, 33; 22, 34; 22, 35; 23, 36; 23, 37; 24, 38; 24, 39; 25, 40; 25, 41; 26, 42; 26, 43; 27, 44; 27, 45; 28, 46; 28, 47; 28, 48; 28, 49; 29, 50; 30, 51; 30, 52; 31, 53; 31, 54; 33, 55; 33, 56; 35, 57; 38, 58; 38, 59; 40, 60; 40, 61; 41, 62; 43, 63; 43, 64; 46, 65; 47, 66; 48, 67; 49, 68; 50, 69; 50, 70; 51, 71; 51, 72; 53, 73; 55, 74; 55, 75; 56, 76; 56, 77; 57, 78; 57, 79; 60, 80; 60, 81; 61, 82; 62, 83; 62, 84; 63, 85; 63, 86; 64, 87; 64, 88; 65, 89; 65, 90; 66, 91; 66, 92; 67, 93; 67, 94; 69, 95; 70, 96; 74, 97; 76, 98; 76, 99; 77, 100; 77, 101; 78, 102; 80, 103; 81, 104; 81, 105; 82, 106; 83, 107; 83, 108; 85, 109; 85, 110; 88, 111; 88, 112; 90, 113; 90, 114; 92, 115; 92, 116; 93, 117; 93, 118; 94, 119; 94, 120; 95, 121; 95, 122; 96, 123; 96, 124; 101, 125; 101, 126; 103, 127; 103, 128; 105, 129; 105, 130; 106, 131; 106, 132; 113, 133; 113, 134; 115, 135; 115, 136; 116, 137; 116, 138; 117, 139; 117, 140; 119, 141; 120, 142; 120, 143; 121, 144; 121, 145; 122, 146; 123, 147; 123, 148; 128, 149; 128, 150; 132, 151; 132, 152; 136, 153; 138, 154; 138, 155; 143, 156; 144, 157; 144, 158; 146, 159; 146, 160; 151, 161; 151, 162; 152, 163; 152, 164; 154, 165; 154, 166; 155, 167; 155, 168; 161, 169; 163, 170; 163, 171; 164, 172; 164, 173; 167, 174; 171, 175
def loose_search(self, asset_manager_id, query='', **kwargs): """ Asset search API. Possible kwargs: * threshold: int (default = 0) * page_no: int (default = 1) * page_size: int (default = 100) * sort_fields: list (default = []) * asset_types: list (default = []) * include_public: bool (default = True) * include_data_sources: bool (default = True) """ self.logger.info('Asset Search - Asset Manager: %s', asset_manager_id) url = '{endpoint}/assets/search/{asset_manager_id}'.format( asset_manager_id=asset_manager_id, endpoint=self.endpoint, ) params = {'query': query} for k, v in kwargs.items(): if not isinstance(v, str) and isinstance(v, Iterable): v = ','.join(str(i) for i in v) params[k] = v response = self.session.get(url, params=params) if response.ok: data = response.json() assets = [json_to_asset(json_asset) for json_asset in data.get('hits', [])] self.logger.info('Returned %s Assets.', len(assets)) return assets else: self.logger.error(response.text) response.raise_for_status()
0, module; 1, function_definition; 2, function_name:natural_sort; 3, parameters; 4, block; 5, identifier:item; 6, expression_statement; 7, if_statement; 8, function_definition; 9, return_statement; 10, comment:""" Sort strings that contain numbers correctly. >>> l = ['v1.3.12', 'v1.3.3', 'v1.2.5', 'v1.2.15', 'v1.2.3', 'v1.2.1'] >>> l.sort(key=natural_sort) >>> print l "['v1.2.1', 'v1.2.3', 'v1.2.5', 'v1.2.15', 'v1.3.3', 'v1.3.12']" """; 11, comparison_operator:item is None; 12, block; 13, function_name:try_int; 14, parameters; 15, block; 16, call; 17, identifier:item; 18, None; 19, return_statement; 20, identifier:s; 21, try_statement; 22, identifier:tuple; 23, argument_list; 24, integer:0; 25, block; 26, except_clause; 27, call; 28, return_statement; 29, identifier:ValueError; 30, block; 31, identifier:map; 32, argument_list; 33, call; 34, return_statement; 35, identifier:try_int; 36, call; 37, identifier:int; 38, argument_list; 39, identifier:s; 40, attribute; 41, argument_list; 42, identifier:s; 43, identifier:re; 44, identifier:findall; 45, string; 46, identifier:item; 47, string_content:(\d+|\D+)
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 4, 8; 4, 9; 6, 10; 7, 11; 7, 12; 8, 13; 8, 14; 8, 15; 9, 16; 11, 17; 11, 18; 12, 19; 14, 20; 15, 21; 16, 22; 16, 23; 19, 24; 21, 25; 21, 26; 23, 27; 25, 28; 26, 29; 26, 30; 27, 31; 27, 32; 28, 33; 30, 34; 32, 35; 32, 36; 33, 37; 33, 38; 34, 39; 36, 40; 36, 41; 38, 42; 40, 43; 40, 44; 41, 45; 41, 46; 45, 47
def natural_sort(item): """ Sort strings that contain numbers correctly. >>> l = ['v1.3.12', 'v1.3.3', 'v1.2.5', 'v1.2.15', 'v1.2.3', 'v1.2.1'] >>> l.sort(key=natural_sort) >>> print l "['v1.2.1', 'v1.2.3', 'v1.2.5', 'v1.2.15', 'v1.3.3', 'v1.3.12']" """ if item is None: return 0 def try_int(s): try: return int(s) except ValueError: return s return tuple(map(try_int, re.findall(r'(\d+|\D+)', item)))
0, module; 1, function_definition; 2, function_name:get_html_attrs; 3, parameters; 4, block; 5, default_parameter; 6, expression_statement; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, if_statement; 12, try_statement; 13, for_statement; 14, expression_statement; 15, expression_statement; 16, expression_statement; 17, return_statement; 18, identifier:kwargs; 19, None; 20, comment:"""Generate HTML attributes from the provided keyword arguments. The output value is sorted by the passed keys, to provide consistent output. Because of the frequent use of the normally reserved keyword `class`, `classes` is used instead. Also, all underscores are translated to regular dashes. Set any property with a `True` value. >>> _get_html_attrs({'id': 'text1', 'classes': 'myclass', 'data_id': 1, 'checked': True}) u'class="myclass" data-id="1" id="text1" checked' """; 21, assignment; 22, assignment; 23, assignment; 24, assignment; 25, identifier:classes; 26, block; 27, block; 28, except_clause; 29, pattern_list; 30, call; 31, block; 32, call; 33, call; 34, call; 35, call; 36, identifier:kwargs; 37, boolean_operator; 38, identifier:attrs; 39, list; 40, identifier:props; 41, list; 42, identifier:classes; 43, call; 44, expression_statement; 45, expression_statement; 46, expression_statement; 47, delete_statement; 48, identifier:KeyError; 49, block; 50, identifier:key; 51, identifier:value; 52, identifier:iteritems; 53, argument_list; 54, expression_statement; 55, expression_statement; 56, if_statement; 57, attribute; 58, argument_list; 59, attribute; 60, argument_list; 61, attribute; 62, argument_list; 63, attribute; 64, argument_list; 65, identifier:kwargs; 66, dictionary; 67, attribute; 68, argument_list; 69, assignment; 70, assignment; 71, call; 72, subscript; 73, pass_statement; 74, identifier:kwargs; 75, assignment; 76, assignment; 77, call; 78, block; 79, else_clause; 80, identifier:attrs; 81, identifier:sort; 82, identifier:props; 83, identifier:sort; 84, identifier:attrs; 85, identifier:extend; 86, identifier:props; 87, string; 88, identifier:join; 89, identifier:attrs; 90, call; 91, identifier:strip; 92, identifier:classes; 93, call; 94, identifier:classes; 95, call; 96, attribute; 97, argument_list; 98, identifier:kwargs; 99, string; 100, identifier:key; 101, call; 102, identifier:key; 103, call; 104, identifier:isinstance; 105, argument_list; 106, if_statement; 107, block; 108, string_content:; 109, attribute; 110, argument_list; 111, attribute; 112, argument_list; 113, identifier:to_unicode; 114, argument_list; 115, identifier:attrs; 116, identifier:append; 117, binary_operator:'class=%s' % classes; 118, string_content:classes; 119, attribute; 120, argument_list; 121, identifier:to_unicode; 122, argument_list; 123, identifier:value; 124, identifier:bool; 125, comparison_operator:value is True; 126, block; 127, expression_statement; 128, expression_statement; 129, identifier:kwargs; 130, identifier:get; 131, string; 132, string; 133, string; 134, identifier:join; 135, call; 136, call; 137, string; 138, identifier:classes; 139, identifier:key; 140, identifier:replace; 141, string; 142, string; 143, identifier:key; 144, identifier:value; 145, True; 146, expression_statement; 147, assignment; 148, call; 149, string_content:classes; 150, string_content:; 151, attribute; 152, argument_list; 153, identifier:quoteattr; 154, argument_list; 155, string_content:class=%s; 156, string_content:_; 157, string_content:-; 158, call; 159, identifier:value; 160, call; 161, attribute; 162, argument_list; 163, identifier:re; 164, identifier:split; 165, string; 166, identifier:classes; 167, identifier:classes; 168, attribute; 169, argument_list; 170, identifier:quoteattr; 171, argument_list; 172, identifier:attrs; 173, identifier:append; 174, binary_operator:u'%s=%s' % (key, value); 175, string_content:\s+; 176, identifier:props; 177, identifier:append; 178, identifier:key; 179, call; 180, string; 181, tuple; 182, identifier:Markup; 183, argument_list; 184, string_content:%s=%s; 185, identifier:key; 186, identifier:value; 187, identifier:value
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 4, 17; 5, 18; 5, 19; 6, 20; 7, 21; 8, 22; 9, 23; 10, 24; 11, 25; 11, 26; 12, 27; 12, 28; 13, 29; 13, 30; 13, 31; 14, 32; 15, 33; 16, 34; 17, 35; 21, 36; 21, 37; 22, 38; 22, 39; 23, 40; 23, 41; 24, 42; 24, 43; 26, 44; 26, 45; 26, 46; 27, 47; 28, 48; 28, 49; 29, 50; 29, 51; 30, 52; 30, 53; 31, 54; 31, 55; 31, 56; 32, 57; 32, 58; 33, 59; 33, 60; 34, 61; 34, 62; 35, 63; 35, 64; 37, 65; 37, 66; 43, 67; 43, 68; 44, 69; 45, 70; 46, 71; 47, 72; 49, 73; 53, 74; 54, 75; 55, 76; 56, 77; 56, 78; 56, 79; 57, 80; 57, 81; 59, 82; 59, 83; 61, 84; 61, 85; 62, 86; 63, 87; 63, 88; 64, 89; 67, 90; 67, 91; 69, 92; 69, 93; 70, 94; 70, 95; 71, 96; 71, 97; 72, 98; 72, 99; 75, 100; 75, 101; 76, 102; 76, 103; 77, 104; 77, 105; 78, 106; 79, 107; 87, 108; 90, 109; 90, 110; 93, 111; 93, 112; 95, 113; 95, 114; 96, 115; 96, 116; 97, 117; 99, 118; 101, 119; 101, 120; 103, 121; 103, 122; 105, 123; 105, 124; 106, 125; 106, 126; 107, 127; 107, 128; 109, 129; 109, 130; 110, 131; 110, 132; 111, 133; 111, 134; 112, 135; 114, 136; 117, 137; 117, 138; 119, 139; 119, 140; 120, 141; 120, 142; 122, 143; 125, 144; 125, 145; 126, 146; 127, 147; 128, 148; 131, 149; 133, 150; 135, 151; 135, 152; 136, 153; 136, 154; 137, 155; 141, 156; 142, 157; 146, 158; 147, 159; 147, 160; 148, 161; 148, 162; 151, 163; 151, 164; 152, 165; 152, 166; 154, 167; 158, 168; 158, 169; 160, 170; 160, 171; 161, 172; 161, 173; 162, 174; 165, 175; 168, 176; 168, 177; 169, 178; 171, 179; 174, 180; 174, 181; 179, 182; 179, 183; 180, 184; 181, 185; 181, 186; 183, 187
def get_html_attrs(kwargs=None): """Generate HTML attributes from the provided keyword arguments. The output value is sorted by the passed keys, to provide consistent output. Because of the frequent use of the normally reserved keyword `class`, `classes` is used instead. Also, all underscores are translated to regular dashes. Set any property with a `True` value. >>> _get_html_attrs({'id': 'text1', 'classes': 'myclass', 'data_id': 1, 'checked': True}) u'class="myclass" data-id="1" id="text1" checked' """ kwargs = kwargs or {} attrs = [] props = [] classes = kwargs.get('classes', '').strip() if classes: classes = ' '.join(re.split(r'\s+', classes)) classes = to_unicode(quoteattr(classes)) attrs.append('class=%s' % classes) try: del kwargs['classes'] except KeyError: pass for key, value in iteritems(kwargs): key = key.replace('_', '-') key = to_unicode(key) if isinstance(value, bool): if value is True: props.append(key) else: value = quoteattr(Markup(value)) attrs.append(u'%s=%s' % (key, value)) attrs.sort() props.sort() attrs.extend(props) return u' '.join(attrs)
0, module; 1, function_definition; 2, function_name:sort_dependencies; 3, parameters; 4, block; 5, identifier:objects; 6, expression_statement; 7, import_from_statement; 8, comment:# Process the list of models, and get the list of dependencies; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, for_statement; 14, for_statement; 15, expression_statement; 16, comment:# Now sort the models to ensure that dependencies are met. This; 17, comment:# is done by repeatedly iterating over the input list of models.; 18, comment:# If all the dependencies of a given model are in the final list,; 19, comment:# that model is promoted to the end of the final list. This process; 20, comment:# continues until the input list is empty, or we do a full iteration; 21, comment:# over the input models without promoting a model to the final list.; 22, comment:# If we do a full iteration without a promotion, that means there are; 23, comment:# circular dependencies in the list.; 24, expression_statement; 25, while_statement; 26, expression_statement; 27, for_statement; 28, return_statement; 29, comment:""" Sort a list of instances by their model dependancy graph. This is very similar to Django's sort_dependencies method except for two big differences: 1. We graph dependencies unrelated to natural_key. 2. We take a list of objects, and return a sorted list of objects. """; 30, dotted_name; 31, dotted_name; 32, assignment; 33, assignment; 34, assignment; 35, assignment; 36, identifier:o; 37, identifier:objects; 38, block; 39, identifier:model; 40, identifier:model_list; 41, block; 42, call; 43, assignment; 44, identifier:model_dependencies; 45, block; 46, assignment; 47, identifier:model; 48, identifier:model_list; 49, block; 50, identifier:sorted_results; 51, identifier:django; 52, identifier:db; 53, identifier:models; 54, identifier:get_model; 55, identifier:model_dependencies; 56, list; 57, identifier:models; 58, call; 59, identifier:model_list; 60, call; 61, identifier:objs_by_model; 62, call; 63, expression_statement; 64, expression_statement; 65, expression_statement; 66, expression_statement; 67, comment:# Add any explicitly defined dependencies; 68, if_statement; 69, comment:# Now add a dependency for any FK or M2M relation with; 70, comment:# a model that defines a natural key; 71, for_statement; 72, expression_statement; 73, attribute; 74, argument_list; 75, identifier:model_list; 76, list; 77, expression_statement; 78, expression_statement; 79, while_statement; 80, if_statement; 81, expression_statement; 82, identifier:sorted_results; 83, list; 84, expression_statement; 85, identifier:set; 86, argument_list; 87, identifier:set; 88, argument_list; 89, identifier:defaultdict; 90, argument_list; 91, assignment; 92, call; 93, call; 94, call; 95, call; 96, block; 97, else_clause; 98, identifier:field; 99, call; 100, block; 101, call; 102, identifier:model_dependencies; 103, identifier:reverse; 104, assignment; 105, assignment; 106, identifier:model_dependencies; 107, block; 108, not_operator; 109, block; 110, assignment; 111, call; 112, identifier:list; 113, identifier:model; 114, attribute; 115, attribute; 116, argument_list; 117, attribute; 118, argument_list; 119, attribute; 120, argument_list; 121, identifier:hasattr; 122, argument_list; 123, expression_statement; 124, if_statement; 125, block; 126, attribute; 127, argument_list; 128, if_statement; 129, attribute; 130, argument_list; 131, identifier:skipped; 132, list; 133, identifier:changed; 134, False; 135, expression_statement; 136, comment:# If all of the models in the dependency list are either already; 137, comment:# on the final model list, or not on the original serialization list,; 138, comment:# then we've found another model with all it's dependencies satisfied.; 139, expression_statement; 140, for_statement; 141, if_statement; 142, identifier:changed; 143, raise_statement; 144, identifier:model_dependencies; 145, identifier:skipped; 146, attribute; 147, argument_list; 148, identifier:o; 149, identifier:__class__; 150, subscript; 151, identifier:append; 152, identifier:o; 153, identifier:model_list; 154, identifier:add; 155, identifier:model; 156, identifier:models; 157, identifier:add; 158, identifier:model; 159, identifier:model; 160, string; 161, assignment; 162, identifier:deps; 163, block; 164, expression_statement; 165, identifier:itertools; 166, identifier:chain; 167, attribute; 168, attribute; 169, boolean_operator; 170, block; 171, identifier:model_dependencies; 172, identifier:append; 173, tuple; 174, assignment; 175, assignment; 176, identifier:candidate; 177, generator_expression; 178, block; 179, identifier:found; 180, block; 181, else_clause; 182, call; 183, identifier:sorted_results; 184, identifier:extend; 185, subscript; 186, identifier:objs_by_model; 187, identifier:model; 188, string_content:natural_key; 189, identifier:deps; 190, call; 191, expression_statement; 192, assignment; 193, attribute; 194, identifier:fields; 195, attribute; 196, identifier:many_to_many; 197, call; 198, comparison_operator:field.rel.to != model; 199, expression_statement; 200, identifier:model; 201, identifier:deps; 202, pattern_list; 203, call; 204, identifier:found; 205, True; 206, parenthesized_expression; 207, for_in_clause; 208, if_statement; 209, expression_statement; 210, expression_statement; 211, block; 212, identifier:CommandError; 213, argument_list; 214, identifier:objs_by_model; 215, identifier:model; 216, identifier:getattr; 217, argument_list; 218, assignment; 219, identifier:deps; 220, list; 221, identifier:model; 222, identifier:_meta; 223, identifier:model; 224, identifier:_meta; 225, identifier:hasattr; 226, argument_list; 227, attribute; 228, identifier:model; 229, call; 230, identifier:model; 231, identifier:deps; 232, attribute; 233, argument_list; 234, boolean_operator; 235, identifier:d; 236, identifier:deps; 237, not_operator; 238, block; 239, call; 240, assignment; 241, expression_statement; 242, binary_operator:"Can't resolve dependencies for %s in serialized app list." % ', '.join('%s.%s' % (model._meta.app_label, model._meta.object_name) for model, deps in sorted(skipped, key=lambda obj: obj[0].__name__)); 243, attribute; 244, string; 245, list; 246, identifier:deps; 247, list_comprehension; 248, attribute; 249, string; 250, attribute; 251, identifier:to; 252, attribute; 253, argument_list; 254, identifier:model_dependencies; 255, identifier:pop; 256, comparison_operator:d not in models; 257, comparison_operator:d in model_list; 258, identifier:candidate; 259, expression_statement; 260, attribute; 261, argument_list; 262, identifier:changed; 263, True; 264, call; 265, string:"Can't resolve dependencies for %s in serialized app list."; 266, call; 267, identifier:model; 268, identifier:natural_key; 269, string_content:dependencies; 270, call; 271, for_in_clause; 272, identifier:field; 273, identifier:rel; 274, string_content:to; 275, identifier:field; 276, identifier:rel; 277, identifier:deps; 278, identifier:append; 279, attribute; 280, identifier:d; 281, identifier:models; 282, identifier:d; 283, identifier:model_list; 284, assignment; 285, identifier:model_list; 286, identifier:append; 287, identifier:model; 288, attribute; 289, argument_list; 290, attribute; 291, generator_expression; 292, identifier:get_model; 293, argument_list; 294, identifier:d; 295, identifier:deps; 296, attribute; 297, identifier:to; 298, identifier:found; 299, False; 300, identifier:skipped; 301, identifier:append; 302, tuple; 303, string; 304, identifier:join; 305, binary_operator:'%s.%s' % (model._meta.app_label, model._meta.object_name); 306, for_in_clause; 307, list_splat; 308, identifier:field; 309, identifier:rel; 310, identifier:model; 311, identifier:deps; 312, string_content:,; 313, string; 314, tuple; 315, pattern_list; 316, call; 317, call; 318, string_content:%s.%s; 319, attribute; 320, attribute; 321, identifier:model; 322, identifier:deps; 323, identifier:sorted; 324, argument_list; 325, attribute; 326, argument_list; 327, attribute; 328, identifier:app_label; 329, attribute; 330, identifier:object_name; 331, identifier:skipped; 332, keyword_argument; 333, identifier:d; 334, identifier:split; 335, string; 336, identifier:model; 337, identifier:_meta; 338, identifier:model; 339, identifier:_meta; 340, identifier:key; 341, lambda; 342, string_content:.; 343, lambda_parameters; 344, attribute; 345, identifier:obj; 346, subscript; 347, identifier:__name__; 348, identifier:obj; 349, integer:0
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 4, 17; 4, 18; 4, 19; 4, 20; 4, 21; 4, 22; 4, 23; 4, 24; 4, 25; 4, 26; 4, 27; 4, 28; 6, 29; 7, 30; 7, 31; 9, 32; 10, 33; 11, 34; 12, 35; 13, 36; 13, 37; 13, 38; 14, 39; 14, 40; 14, 41; 15, 42; 24, 43; 25, 44; 25, 45; 26, 46; 27, 47; 27, 48; 27, 49; 28, 50; 30, 51; 30, 52; 30, 53; 31, 54; 32, 55; 32, 56; 33, 57; 33, 58; 34, 59; 34, 60; 35, 61; 35, 62; 38, 63; 38, 64; 38, 65; 41, 66; 41, 67; 41, 68; 41, 69; 41, 70; 41, 71; 41, 72; 42, 73; 42, 74; 43, 75; 43, 76; 45, 77; 45, 78; 45, 79; 45, 80; 45, 81; 46, 82; 46, 83; 49, 84; 58, 85; 58, 86; 60, 87; 60, 88; 62, 89; 62, 90; 63, 91; 64, 92; 65, 93; 66, 94; 68, 95; 68, 96; 68, 97; 71, 98; 71, 99; 71, 100; 72, 101; 73, 102; 73, 103; 77, 104; 78, 105; 79, 106; 79, 107; 80, 108; 80, 109; 81, 110; 84, 111; 90, 112; 91, 113; 91, 114; 92, 115; 92, 116; 93, 117; 93, 118; 94, 119; 94, 120; 95, 121; 95, 122; 96, 123; 96, 124; 97, 125; 99, 126; 99, 127; 100, 128; 101, 129; 101, 130; 104, 131; 104, 132; 105, 133; 105, 134; 107, 135; 107, 136; 107, 137; 107, 138; 107, 139; 107, 140; 107, 141; 108, 142; 109, 143; 110, 144; 110, 145; 111, 146; 111, 147; 114, 148; 114, 149; 115, 150; 115, 151; 116, 152; 117, 153; 117, 154; 118, 155; 119, 156; 119, 157; 120, 158; 122, 159; 122, 160; 123, 161; 124, 162; 124, 163; 125, 164; 126, 165; 126, 166; 127, 167; 127, 168; 128, 169; 128, 170; 129, 171; 129, 172; 130, 173; 135, 174; 139, 175; 140, 176; 140, 177; 140, 178; 141, 179; 141, 180; 141, 181; 143, 182; 146, 183; 146, 184; 147, 185; 150, 186; 150, 187; 160, 188; 161, 189; 161, 190; 163, 191; 164, 192; 167, 193; 167, 194; 168, 195; 168, 196; 169, 197; 169, 198; 170, 199; 173, 200; 173, 201; 174, 202; 174, 203; 175, 204; 175, 205; 177, 206; 177, 207; 178, 208; 180, 209; 180, 210; 181, 211; 182, 212; 182, 213; 185, 214; 185, 215; 190, 216; 190, 217; 191, 218; 192, 219; 192, 220; 193, 221; 193, 222; 195, 223; 195, 224; 197, 225; 197, 226; 198, 227; 198, 228; 199, 229; 202, 230; 202, 231; 203, 232; 203, 233; 206, 234; 207, 235; 207, 236; 208, 237; 208, 238; 209, 239; 210, 240; 211, 241; 213, 242; 217, 243; 217, 244; 217, 245; 218, 246; 218, 247; 226, 248; 226, 249; 227, 250; 227, 251; 229, 252; 229, 253; 232, 254; 232, 255; 234, 256; 234, 257; 237, 258; 238, 259; 239, 260; 239, 261; 240, 262; 240, 263; 241, 264; 242, 265; 242, 266; 243, 267; 243, 268; 244, 269; 247, 270; 247, 271; 248, 272; 248, 273; 249, 274; 250, 275; 250, 276; 252, 277; 252, 278; 253, 279; 256, 280; 256, 281; 257, 282; 257, 283; 259, 284; 260, 285; 260, 286; 261, 287; 264, 288; 264, 289; 266, 290; 266, 291; 270, 292; 270, 293; 271, 294; 271, 295; 279, 296; 279, 297; 284, 298; 284, 299; 288, 300; 288, 301; 289, 302; 290, 303; 290, 304; 291, 305; 291, 306; 293, 307; 296, 308; 296, 309; 302, 310; 302, 311; 303, 312; 305, 313; 305, 314; 306, 315; 306, 316; 307, 317; 313, 318; 314, 319; 314, 320; 315, 321; 315, 322; 316, 323; 316, 324; 317, 325; 317, 326; 319, 327; 319, 328; 320, 329; 320, 330; 324, 331; 324, 332; 325, 333; 325, 334; 326, 335; 327, 336; 327, 337; 329, 338; 329, 339; 332, 340; 332, 341; 335, 342; 341, 343; 341, 344; 343, 345; 344, 346; 344, 347; 346, 348; 346, 349
def sort_dependencies(objects): """ Sort a list of instances by their model dependancy graph. This is very similar to Django's sort_dependencies method except for two big differences: 1. We graph dependencies unrelated to natural_key. 2. We take a list of objects, and return a sorted list of objects. """ from django.db.models import get_model # Process the list of models, and get the list of dependencies model_dependencies = [] models = set() model_list = set() objs_by_model = defaultdict(list) for o in objects: model = o.__class__ objs_by_model[model].append(o) model_list.add(model) for model in model_list: models.add(model) # Add any explicitly defined dependencies if hasattr(model, 'natural_key'): deps = getattr(model.natural_key, 'dependencies', []) if deps: deps = [get_model(*d.split('.')) for d in deps] else: deps = [] # Now add a dependency for any FK or M2M relation with # a model that defines a natural key for field in itertools.chain(model._meta.fields, model._meta.many_to_many): if hasattr(field.rel, 'to') and field.rel.to != model: deps.append(field.rel.to) model_dependencies.append((model, deps)) model_dependencies.reverse() # Now sort the models to ensure that dependencies are met. This # is done by repeatedly iterating over the input list of models. # If all the dependencies of a given model are in the final list, # that model is promoted to the end of the final list. This process # continues until the input list is empty, or we do a full iteration # over the input models without promoting a model to the final list. # If we do a full iteration without a promotion, that means there are # circular dependencies in the list. model_list = [] while model_dependencies: skipped = [] changed = False while model_dependencies: model, deps = model_dependencies.pop() # If all of the models in the dependency list are either already # on the final model list, or not on the original serialization list, # then we've found another model with all it's dependencies satisfied. found = True for candidate in ((d not in models or d in model_list) for d in deps): if not candidate: found = False if found: model_list.append(model) changed = True else: skipped.append((model, deps)) if not changed: raise CommandError("Can't resolve dependencies for %s in serialized app list." % ', '.join('%s.%s' % (model._meta.app_label, model._meta.object_name) for model, deps in sorted(skipped, key=lambda obj: obj[0].__name__)) ) model_dependencies = skipped sorted_results = [] for model in model_list: sorted_results.extend(objs_by_model[model]) return sorted_results
0, module; 1, function_definition; 2, function_name:sort_languages; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, identifier:order; 12, attribute; 13, comment:""" Sorts the Model languages. :param order: Order. ( Qt.SortOrder ) """; 14, call; 15, assignment; 16, call; 17, identifier:Qt; 18, identifier:AscendingOrder; 19, attribute; 20, argument_list; 21, attribute; 22, call; 23, attribute; 24, argument_list; 25, identifier:self; 26, identifier:beginResetModel; 27, identifier:self; 28, identifier:__languages; 29, identifier:sorted; 30, argument_list; 31, identifier:self; 32, identifier:endResetModel; 33, attribute; 34, keyword_argument; 35, keyword_argument; 36, identifier:self; 37, identifier:__languages; 38, identifier:key; 39, lambda; 40, identifier:reverse; 41, identifier:order; 42, lambda_parameters; 43, parenthesized_expression; 44, identifier:x; 45, attribute; 46, identifier:x; 47, identifier:name
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 6, 11; 6, 12; 7, 13; 8, 14; 9, 15; 10, 16; 12, 17; 12, 18; 14, 19; 14, 20; 15, 21; 15, 22; 16, 23; 16, 24; 19, 25; 19, 26; 21, 27; 21, 28; 22, 29; 22, 30; 23, 31; 23, 32; 30, 33; 30, 34; 30, 35; 33, 36; 33, 37; 34, 38; 34, 39; 35, 40; 35, 41; 39, 42; 39, 43; 42, 44; 43, 45; 45, 46; 45, 47
def sort_languages(self, order=Qt.AscendingOrder): """ Sorts the Model languages. :param order: Order. ( Qt.SortOrder ) """ self.beginResetModel() self.__languages = sorted(self.__languages, key=lambda x: (x.name), reverse=order) self.endResetModel()
0, module; 1, function_definition; 2, function_name:fmt_pairs; 3, parameters; 4, block; 5, identifier:obj; 6, default_parameter; 7, default_parameter; 8, expression_statement; 9, expression_statement; 10, if_statement; 11, expression_statement; 12, expression_statement; 13, expression_statement; 14, expression_statement; 15, return_statement; 16, identifier:indent; 17, integer:4; 18, identifier:sort_key; 19, None; 20, comment:"""Format and sort a list of pairs, usually for printing. If sort_key is provided, the value will be passed as the 'key' keyword argument of the sorted() function when sorting the items. This allows for the input such as [('A', 3), ('B', 5), ('Z', 1)] to be sorted by the ints but formatted like so: l = [('A', 3), ('B', 5), ('Z', 1)] print(fmt_pairs(l, sort_key=lambda x: x[1])) Z 1 A 3 B 5 where the default behavior would be: print(fmt_pairs(l)) A 3 B 5 Z 1 """; 21, assignment; 22, not_operator; 23, block; 24, assignment; 25, assignment; 26, assignment; 27, assignment; 28, identifier:string; 29, identifier:lengths; 30, list_comprehension; 31, identifier:lengths; 32, return_statement; 33, identifier:longest; 34, call; 35, identifier:obj; 36, call; 37, identifier:formatter; 38, binary_operator:'%s{: <%d} {}' % (' ' * indent, longest); 39, identifier:string; 40, call; 41, call; 42, for_in_clause; 43, string; 44, identifier:max; 45, argument_list; 46, identifier:sorted; 47, argument_list; 48, string; 49, tuple; 50, attribute; 51, argument_list; 52, identifier:len; 53, argument_list; 54, identifier:x; 55, identifier:obj; 56, identifier:lengths; 57, identifier:obj; 58, keyword_argument; 59, string_content:%s{: <%d} {}; 60, binary_operator:' ' * indent; 61, identifier:longest; 62, string; 63, identifier:join; 64, list_comprehension; 65, subscript; 66, identifier:key; 67, identifier:sort_key; 68, string; 69, identifier:indent; 70, string_content; 71, call; 72, for_in_clause; 73, identifier:x; 74, integer:0; 75, string_content:; 76, escape_sequence:\n; 77, attribute; 78, argument_list; 79, pattern_list; 80, identifier:obj; 81, identifier:formatter; 82, identifier:format; 83, identifier:k; 84, identifier:v; 85, identifier:k; 86, identifier:v
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 6, 16; 6, 17; 7, 18; 7, 19; 8, 20; 9, 21; 10, 22; 10, 23; 11, 24; 12, 25; 13, 26; 14, 27; 15, 28; 21, 29; 21, 30; 22, 31; 23, 32; 24, 33; 24, 34; 25, 35; 25, 36; 26, 37; 26, 38; 27, 39; 27, 40; 30, 41; 30, 42; 32, 43; 34, 44; 34, 45; 36, 46; 36, 47; 38, 48; 38, 49; 40, 50; 40, 51; 41, 52; 41, 53; 42, 54; 42, 55; 45, 56; 47, 57; 47, 58; 48, 59; 49, 60; 49, 61; 50, 62; 50, 63; 51, 64; 53, 65; 58, 66; 58, 67; 60, 68; 60, 69; 62, 70; 64, 71; 64, 72; 65, 73; 65, 74; 68, 75; 70, 76; 71, 77; 71, 78; 72, 79; 72, 80; 77, 81; 77, 82; 78, 83; 78, 84; 79, 85; 79, 86
def fmt_pairs(obj, indent=4, sort_key=None): """Format and sort a list of pairs, usually for printing. If sort_key is provided, the value will be passed as the 'key' keyword argument of the sorted() function when sorting the items. This allows for the input such as [('A', 3), ('B', 5), ('Z', 1)] to be sorted by the ints but formatted like so: l = [('A', 3), ('B', 5), ('Z', 1)] print(fmt_pairs(l, sort_key=lambda x: x[1])) Z 1 A 3 B 5 where the default behavior would be: print(fmt_pairs(l)) A 3 B 5 Z 1 """ lengths = [len(x[0]) for x in obj] if not lengths: return '' longest = max(lengths) obj = sorted(obj, key=sort_key) formatter = '%s{: <%d} {}' % (' ' * indent, longest) string = '\n'.join([formatter.format(k, v) for k, v in obj]) return string
0, module; 1, function_definition; 2, function_name:serialize; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, default_parameter; 8, expression_statement; 9, expression_statement; 10, if_statement; 11, comment:# generate a list; 12, expression_statement; 13, if_statement; 14, return_statement; 15, identifier:as_dict; 16, False; 17, identifier:sort; 18, None; 19, comment:""" Dump built files as a list or dictionary, for JSON or other serialization. sort: a key function to sort a list, or simply True """; 20, assignment; 21, identifier:as_dict; 22, block; 23, assignment; 24, call; 25, block; 26, elif_clause; 27, call; 28, identifier:files; 29, call; 30, return_statement; 31, identifier:data; 32, generator_expression; 33, identifier:callable; 34, argument_list; 35, return_statement; 36, comparison_operator:sort is True; 37, block; 38, identifier:list; 39, argument_list; 40, identifier:getattr; 41, argument_list; 42, call; 43, call; 44, for_in_clause; 45, identifier:sort; 46, call; 47, identifier:sort; 48, True; 49, return_statement; 50, identifier:data; 51, identifier:self; 52, string; 53, call; 54, identifier:dict; 55, generator_expression; 56, attribute; 57, argument_list; 58, identifier:p; 59, call; 60, identifier:sorted; 61, argument_list; 62, call; 63, string_content:files; 64, attribute; 65, argument_list; 66, tuple; 67, for_in_clause; 68, identifier:p; 69, identifier:to_dict; 70, attribute; 71, argument_list; 72, identifier:data; 73, keyword_argument; 74, identifier:sorted; 75, argument_list; 76, identifier:self; 77, identifier:run; 78, identifier:fn; 79, call; 80, pattern_list; 81, call; 82, identifier:files; 83, identifier:values; 84, identifier:key; 85, identifier:sort; 86, identifier:data; 87, attribute; 88, argument_list; 89, identifier:fn; 90, identifier:p; 91, attribute; 92, argument_list; 93, identifier:p; 94, identifier:to_dict; 95, identifier:files; 96, identifier:items
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 6, 15; 6, 16; 7, 17; 7, 18; 8, 19; 9, 20; 10, 21; 10, 22; 12, 23; 13, 24; 13, 25; 13, 26; 14, 27; 20, 28; 20, 29; 22, 30; 23, 31; 23, 32; 24, 33; 24, 34; 25, 35; 26, 36; 26, 37; 27, 38; 27, 39; 29, 40; 29, 41; 30, 42; 32, 43; 32, 44; 34, 45; 35, 46; 36, 47; 36, 48; 37, 49; 39, 50; 41, 51; 41, 52; 41, 53; 42, 54; 42, 55; 43, 56; 43, 57; 44, 58; 44, 59; 46, 60; 46, 61; 49, 62; 52, 63; 53, 64; 53, 65; 55, 66; 55, 67; 56, 68; 56, 69; 59, 70; 59, 71; 61, 72; 61, 73; 62, 74; 62, 75; 64, 76; 64, 77; 66, 78; 66, 79; 67, 80; 67, 81; 70, 82; 70, 83; 73, 84; 73, 85; 75, 86; 79, 87; 79, 88; 80, 89; 80, 90; 81, 91; 81, 92; 87, 93; 87, 94; 91, 95; 91, 96
def serialize(self, as_dict=False, sort=None): """ Dump built files as a list or dictionary, for JSON or other serialization. sort: a key function to sort a list, or simply True """ files = getattr(self, 'files', self.run()) if as_dict: return dict((fn, p.to_dict()) for fn, p in files.items()) # generate a list data = (p.to_dict() for p in files.values()) if callable(sort): return sorted(data, key=sort) elif sort is True: return sorted(data) return list(data)
0, module; 1, function_definition; 2, function_name:iteritems; 3, parameters; 4, block; 5, identifier:self; 6, expression_statement; 7, expression_statement; 8, for_statement; 9, comment:""" Sort and then iterate the dictionary """; 10, assignment; 11, pattern_list; 12, identifier:sorted_data; 13, block; 14, identifier:sorted_data; 15, call; 16, identifier:k; 17, identifier:v; 18, expression_statement; 19, identifier:sorted; 20, argument_list; 21, yield; 22, call; 23, attribute; 24, attribute; 25, attribute; 26, expression_list; 27, attribute; 28, argument_list; 29, identifier:self; 30, identifier:cmp; 31, identifier:self; 32, identifier:key; 33, identifier:self; 34, identifier:reverse; 35, identifier:k; 36, identifier:v; 37, attribute; 38, identifier:iteritems; 39, identifier:self; 40, identifier:data
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 4, 8; 6, 9; 7, 10; 8, 11; 8, 12; 8, 13; 10, 14; 10, 15; 11, 16; 11, 17; 13, 18; 15, 19; 15, 20; 18, 21; 20, 22; 20, 23; 20, 24; 20, 25; 21, 26; 22, 27; 22, 28; 23, 29; 23, 30; 24, 31; 24, 32; 25, 33; 25, 34; 26, 35; 26, 36; 27, 37; 27, 38; 37, 39; 37, 40
def iteritems(self): """ Sort and then iterate the dictionary """ sorted_data = sorted(self.data.iteritems(), self.cmp, self.key, self.reverse) for k,v in sorted_data: yield k,v
0, module; 1, function_definition; 2, function_name:get_posts; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, expression_statement; 11, if_statement; 12, if_statement; 13, if_statement; 14, return_statement; 15, identifier:num; 16, None; 17, identifier:tag; 18, None; 19, identifier:private; 20, False; 21, comment:""" Get all the posts added to the blog. Args: num (int): Optional. If provided, only return N posts (sorted by date, most recent first). tag (Tag): Optional. If provided, only return posts that have a specific tag. private (bool): By default (if False), private posts are not included. If set to True, private posts will also be included. """; 22, assignment; 23, not_operator; 24, block; 25, identifier:tag; 26, block; 27, identifier:num; 28, block; 29, identifier:posts; 30, identifier:posts; 31, attribute; 32, identifier:private; 33, expression_statement; 34, expression_statement; 35, return_statement; 36, identifier:self; 37, identifier:posts; 38, assignment; 39, assignment; 40, subscript; 41, identifier:posts; 42, list_comprehension; 43, identifier:posts; 44, list_comprehension; 45, identifier:posts; 46, slice; 47, identifier:post; 48, for_in_clause; 49, if_clause; 50, identifier:post; 51, for_in_clause; 52, if_clause; 53, identifier:num; 54, identifier:post; 55, identifier:posts; 56, attribute; 57, identifier:post; 58, identifier:posts; 59, comparison_operator:tag in post.tags; 60, identifier:post; 61, identifier:public; 62, identifier:tag; 63, attribute; 64, identifier:post; 65, identifier:tags
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 6, 15; 6, 16; 7, 17; 7, 18; 8, 19; 8, 20; 9, 21; 10, 22; 11, 23; 11, 24; 12, 25; 12, 26; 13, 27; 13, 28; 14, 29; 22, 30; 22, 31; 23, 32; 24, 33; 26, 34; 28, 35; 31, 36; 31, 37; 33, 38; 34, 39; 35, 40; 38, 41; 38, 42; 39, 43; 39, 44; 40, 45; 40, 46; 42, 47; 42, 48; 42, 49; 44, 50; 44, 51; 44, 52; 46, 53; 48, 54; 48, 55; 49, 56; 51, 57; 51, 58; 52, 59; 56, 60; 56, 61; 59, 62; 59, 63; 63, 64; 63, 65
def get_posts(self, num=None, tag=None, private=False): """ Get all the posts added to the blog. Args: num (int): Optional. If provided, only return N posts (sorted by date, most recent first). tag (Tag): Optional. If provided, only return posts that have a specific tag. private (bool): By default (if False), private posts are not included. If set to True, private posts will also be included. """ posts = self.posts if not private: posts = [post for post in posts if post.public] if tag: posts = [post for post in posts if tag in post.tags] if num: return posts[:num] return posts
0, module; 1, function_definition; 2, function_name:get_sort_function; 3, parameters; 4, block; 5, identifier:order; 6, expression_statement; 7, expression_statement; 8, function_definition; 9, return_statement; 10, comment:""" Returns a callable similar to the built-in `cmp`, to be used on objects. Takes a list of dictionaries. In each, 'key' must be a string that is used to get an attribute of the objects to compare, and 'reverse' must be a boolean indicating whether the result should be reversed. """; 11, assignment; 12, function_name:sort_function; 13, parameters; 14, block; 15, identifier:sort_function; 16, identifier:stable; 17, call; 18, identifier:a; 19, identifier:b; 20, for_statement; 21, return_statement; 22, identifier:tuple; 23, generator_expression; 24, pattern_list; 25, identifier:stable; 26, block; 27, integer:0; 28, tuple; 29, for_in_clause; 30, identifier:name; 31, identifier:direction; 32, expression_statement; 33, if_statement; 34, subscript; 35, conditional_expression:-1 if d['reverse'] else 1; 36, identifier:d; 37, identifier:order; 38, assignment; 39, comparison_operator:v != 0; 40, block; 41, identifier:d; 42, string; 43, unary_operator; 44, subscript; 45, integer:1; 46, identifier:v; 47, call; 48, identifier:v; 49, integer:0; 50, return_statement; 51, string_content:key; 52, integer:1; 53, identifier:d; 54, string; 55, identifier:cmp; 56, argument_list; 57, binary_operator:v * direction; 58, string_content:reverse; 59, conditional_expression:getattr(a, name) if a else a; 60, conditional_expression:getattr(b, name) if b else b; 61, identifier:v; 62, identifier:direction; 63, call; 64, identifier:a; 65, identifier:a; 66, call; 67, identifier:b; 68, identifier:b; 69, identifier:getattr; 70, argument_list; 71, identifier:getattr; 72, argument_list; 73, identifier:a; 74, identifier:name; 75, identifier:b; 76, identifier:name
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 4, 8; 4, 9; 6, 10; 7, 11; 8, 12; 8, 13; 8, 14; 9, 15; 11, 16; 11, 17; 13, 18; 13, 19; 14, 20; 14, 21; 17, 22; 17, 23; 20, 24; 20, 25; 20, 26; 21, 27; 23, 28; 23, 29; 24, 30; 24, 31; 26, 32; 26, 33; 28, 34; 28, 35; 29, 36; 29, 37; 32, 38; 33, 39; 33, 40; 34, 41; 34, 42; 35, 43; 35, 44; 35, 45; 38, 46; 38, 47; 39, 48; 39, 49; 40, 50; 42, 51; 43, 52; 44, 53; 44, 54; 47, 55; 47, 56; 50, 57; 54, 58; 56, 59; 56, 60; 57, 61; 57, 62; 59, 63; 59, 64; 59, 65; 60, 66; 60, 67; 60, 68; 63, 69; 63, 70; 66, 71; 66, 72; 70, 73; 70, 74; 72, 75; 72, 76
def get_sort_function(order): """ Returns a callable similar to the built-in `cmp`, to be used on objects. Takes a list of dictionaries. In each, 'key' must be a string that is used to get an attribute of the objects to compare, and 'reverse' must be a boolean indicating whether the result should be reversed. """ stable = tuple((d['key'], -1 if d['reverse'] else 1) for d in order) def sort_function(a, b): for name, direction in stable: v = cmp(getattr(a, name) if a else a, getattr(b, name) if b else b) if v != 0: return v * direction return 0 return sort_function
0, module; 1, function_definition; 2, function_name:create_proxy_model; 3, parameters; 4, block; 5, identifier:self; 6, identifier:model; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, return_statement; 12, comment:"""Create a sort filter proxy model for the given model :param model: the model to wrap in a proxy :type model: :class:`QtGui.QAbstractItemModel` :returns: a new proxy model that can be used for sorting and filtering :rtype: :class:`QtGui.QAbstractItemModel` :raises: None """; 13, assignment; 14, call; 15, call; 16, identifier:proxy; 17, identifier:proxy; 18, call; 19, attribute; 20, argument_list; 21, attribute; 22, argument_list; 23, identifier:ReftrackSortFilterModel; 24, argument_list; 25, identifier:proxy; 26, identifier:setSourceModel; 27, identifier:model; 28, attribute; 29, identifier:connect; 30, attribute; 31, identifier:self; 32, identifier:model; 33, identifier:rowsInserted; 34, identifier:self; 35, identifier:sort_model
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 7, 12; 8, 13; 9, 14; 10, 15; 11, 16; 13, 17; 13, 18; 14, 19; 14, 20; 15, 21; 15, 22; 18, 23; 18, 24; 19, 25; 19, 26; 20, 27; 21, 28; 21, 29; 22, 30; 24, 31; 28, 32; 28, 33; 30, 34; 30, 35
def create_proxy_model(self, model): """Create a sort filter proxy model for the given model :param model: the model to wrap in a proxy :type model: :class:`QtGui.QAbstractItemModel` :returns: a new proxy model that can be used for sorting and filtering :rtype: :class:`QtGui.QAbstractItemModel` :raises: None """ proxy = ReftrackSortFilterModel(self) proxy.setSourceModel(model) model.rowsInserted.connect(self.sort_model) return proxy
0, module; 1, function_definition; 2, function_name:sort_model; 3, parameters; 4, block; 5, identifier:self; 6, list_splat_pattern; 7, dictionary_splat_pattern; 8, expression_statement; 9, expression_statement; 10, comment:# sort the identifier; 11, expression_statement; 12, comment:# sort the element; 13, expression_statement; 14, comment:# sort the elementgrp; 15, expression_statement; 16, identifier:args; 17, identifier:kwargs; 18, comment:"""Sort the proxy model :returns: None :rtype: None :raises: None """; 19, call; 20, call; 21, call; 22, call; 23, attribute; 24, argument_list; 25, attribute; 26, argument_list; 27, attribute; 28, argument_list; 29, attribute; 30, argument_list; 31, attribute; 32, identifier:sort; 33, integer:17; 34, attribute; 35, identifier:sort; 36, integer:2; 37, attribute; 38, identifier:sort; 39, integer:1; 40, attribute; 41, identifier:sort; 42, integer:0; 43, identifier:self; 44, identifier:proxy; 45, identifier:self; 46, identifier:proxy; 47, identifier:self; 48, identifier:proxy; 49, identifier:self; 50, identifier:proxy
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 6, 16; 7, 17; 8, 18; 9, 19; 11, 20; 13, 21; 15, 22; 19, 23; 19, 24; 20, 25; 20, 26; 21, 27; 21, 28; 22, 29; 22, 30; 23, 31; 23, 32; 24, 33; 25, 34; 25, 35; 26, 36; 27, 37; 27, 38; 28, 39; 29, 40; 29, 41; 30, 42; 31, 43; 31, 44; 34, 45; 34, 46; 37, 47; 37, 48; 40, 49; 40, 50
def sort_model(self, *args, **kwargs): """Sort the proxy model :returns: None :rtype: None :raises: None """ self.proxy.sort(17) # sort the identifier self.proxy.sort(2) # sort the element self.proxy.sort(1) # sort the elementgrp self.proxy.sort(0)
0, module; 1, function_definition; 2, function_name:prepare_value; 3, parameters; 4, block; 5, identifier:self; 6, identifier:value; 7, expression_statement; 8, if_statement; 9, return_statement; 10, comment:""" To avoid evaluating the lazysorted callable more than necessary to establish a potential initial value for the field, we do it here. If there's - only one template choice, and - the field is required, and - there's no prior initial set (either by being bound or by being set higher up the stack then forcibly select the only "good" value as the default. """; 11, boolean_operator; 12, block; 13, call; 14, comparison_operator:value is None; 15, attribute; 16, expression_statement; 17, if_statement; 18, attribute; 19, argument_list; 20, identifier:value; 21, None; 22, identifier:self; 23, identifier:required; 24, assignment; 25, comparison_operator:len(choices) == 1; 26, block; 27, call; 28, identifier:prepare_value; 29, identifier:value; 30, identifier:choices; 31, call; 32, call; 33, integer:1; 34, expression_statement; 35, identifier:super; 36, argument_list; 37, identifier:list; 38, argument_list; 39, identifier:len; 40, argument_list; 41, assignment; 42, identifier:TemplateChoiceField; 43, identifier:self; 44, attribute; 45, identifier:choices; 46, identifier:value; 47, subscript; 48, identifier:self; 49, identifier:choices; 50, subscript; 51, integer:0; 52, identifier:choices; 53, integer:0
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 7, 10; 8, 11; 8, 12; 9, 13; 11, 14; 11, 15; 12, 16; 12, 17; 13, 18; 13, 19; 14, 20; 14, 21; 15, 22; 15, 23; 16, 24; 17, 25; 17, 26; 18, 27; 18, 28; 19, 29; 24, 30; 24, 31; 25, 32; 25, 33; 26, 34; 27, 35; 27, 36; 31, 37; 31, 38; 32, 39; 32, 40; 34, 41; 36, 42; 36, 43; 38, 44; 40, 45; 41, 46; 41, 47; 44, 48; 44, 49; 47, 50; 47, 51; 50, 52; 50, 53
def prepare_value(self, value): """ To avoid evaluating the lazysorted callable more than necessary to establish a potential initial value for the field, we do it here. If there's - only one template choice, and - the field is required, and - there's no prior initial set (either by being bound or by being set higher up the stack then forcibly select the only "good" value as the default. """ if value is None and self.required: choices =list(self.choices) if len(choices) == 1: value = choices[0][0] return super(TemplateChoiceField, self).prepare_value(value)
0, module; 1, function_definition; 2, function_name:_sort; 3, parameters; 4, block; 5, identifier:self; 6, expression_statement; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, comment:""" Sort the response dictionaries priority levels for ordered iteration """; 11, call; 12, assignment; 13, assignment; 14, attribute; 15, argument_list; 16, attribute; 17, call; 18, attribute; 19, True; 20, attribute; 21, identifier:debug; 22, string; 23, identifier:self; 24, identifier:_responses; 25, identifier:OrderedDict; 26, argument_list; 27, identifier:self; 28, identifier:sorted; 29, identifier:self; 30, identifier:_log; 31, string_content:Sorting responses by priority; 32, call; 33, identifier:sorted; 34, argument_list; 35, call; 36, keyword_argument; 37, identifier:list; 38, argument_list; 39, identifier:reverse; 40, True; 41, call; 42, attribute; 43, argument_list; 44, attribute; 45, identifier:items; 46, identifier:self; 47, identifier:_responses
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 4, 8; 4, 9; 6, 10; 7, 11; 8, 12; 9, 13; 11, 14; 11, 15; 12, 16; 12, 17; 13, 18; 13, 19; 14, 20; 14, 21; 15, 22; 16, 23; 16, 24; 17, 25; 17, 26; 18, 27; 18, 28; 20, 29; 20, 30; 22, 31; 26, 32; 32, 33; 32, 34; 34, 35; 34, 36; 35, 37; 35, 38; 36, 39; 36, 40; 38, 41; 41, 42; 41, 43; 42, 44; 42, 45; 44, 46; 44, 47
def _sort(self): """ Sort the response dictionaries priority levels for ordered iteration """ self._log.debug('Sorting responses by priority') self._responses = OrderedDict(sorted(list(self._responses.items()), reverse=True)) self.sorted = True
0, module; 1, function_definition; 2, function_name:csv_row_to_transaction; 3, parameters; 4, block; 5, identifier:index; 6, identifier:row; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, expression_statement; 12, expression_statement; 13, expression_statement; 14, expression_statement; 15, expression_statement; 16, expression_statement; 17, expression_statement; 18, return_statement; 19, identifier:source_encoding; 20, string:"latin1"; 21, identifier:date_format; 22, string:"%d-%m-%Y"; 23, identifier:thousand_sep; 24, string:"."; 25, identifier:decimal_sep; 26, string:","; 27, comment:""" Parses a row of strings to a ``Transaction`` object. Args: index: The index of this row in the original CSV file. Used for sorting ``Transaction``s by their order of appearance. row: The row containing strings for [transfer_date, posted_date, message, money_amount, money_total]. source_encoding: The encoding that will be used to decode strings to UTF-8. date_format: The format of dates in this row. thousand_sep: The thousand separator in money amounts. decimal_sep: The decimal separator in money amounts. Returns: A ``Transaction`` object. """; 28, assignment; 29, assignment; 30, assignment; 31, assignment; 32, assignment; 33, assignment; 34, call; 35, pattern_list; 36, identifier:row; 37, identifier:xfer; 38, call; 39, identifier:posted; 40, call; 41, identifier:message; 42, call; 43, identifier:amount; 44, call; 45, identifier:total; 46, call; 47, identifier:Transaction; 48, argument_list; 49, identifier:xfer; 50, identifier:posted; 51, identifier:message; 52, identifier:amount; 53, identifier:total; 54, attribute; 55, argument_list; 56, attribute; 57, argument_list; 58, attribute; 59, argument_list; 60, attribute; 61, argument_list; 62, attribute; 63, argument_list; 64, identifier:index; 65, identifier:xfer; 66, identifier:posted; 67, identifier:message; 68, identifier:amount; 69, identifier:total; 70, identifier:Parse; 71, identifier:date; 72, identifier:xfer; 73, identifier:Parse; 74, identifier:date; 75, identifier:posted; 76, identifier:Parse; 77, identifier:to_utf8; 78, identifier:message; 79, identifier:source_encoding; 80, identifier:Parse; 81, identifier:money; 82, identifier:amount; 83, identifier:Parse; 84, identifier:money; 85, identifier:total
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 4, 17; 4, 18; 7, 19; 7, 20; 8, 21; 8, 22; 9, 23; 9, 24; 10, 25; 10, 26; 11, 27; 12, 28; 13, 29; 14, 30; 15, 31; 16, 32; 17, 33; 18, 34; 28, 35; 28, 36; 29, 37; 29, 38; 30, 39; 30, 40; 31, 41; 31, 42; 32, 43; 32, 44; 33, 45; 33, 46; 34, 47; 34, 48; 35, 49; 35, 50; 35, 51; 35, 52; 35, 53; 38, 54; 38, 55; 40, 56; 40, 57; 42, 58; 42, 59; 44, 60; 44, 61; 46, 62; 46, 63; 48, 64; 48, 65; 48, 66; 48, 67; 48, 68; 48, 69; 54, 70; 54, 71; 55, 72; 56, 73; 56, 74; 57, 75; 58, 76; 58, 77; 59, 78; 59, 79; 60, 80; 60, 81; 61, 82; 62, 83; 62, 84; 63, 85
def csv_row_to_transaction(index, row, source_encoding="latin1", date_format="%d-%m-%Y", thousand_sep=".", decimal_sep=","): """ Parses a row of strings to a ``Transaction`` object. Args: index: The index of this row in the original CSV file. Used for sorting ``Transaction``s by their order of appearance. row: The row containing strings for [transfer_date, posted_date, message, money_amount, money_total]. source_encoding: The encoding that will be used to decode strings to UTF-8. date_format: The format of dates in this row. thousand_sep: The thousand separator in money amounts. decimal_sep: The decimal separator in money amounts. Returns: A ``Transaction`` object. """ xfer, posted, message, amount, total = row xfer = Parse.date(xfer) posted = Parse.date(posted) message = Parse.to_utf8(message, source_encoding) amount = Parse.money(amount) total = Parse.money(total) return Transaction(index, xfer, posted, message, amount, total)
0, module; 1, function_definition; 2, function_name:csv_to_transactions; 3, parameters; 4, block; 5, identifier:handle; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, for_statement; 14, return_statement; 15, identifier:source_encoding; 16, string:"latin1"; 17, identifier:date_format; 18, string:"%d-%m-%Y"; 19, identifier:thousand_sep; 20, string:"."; 21, identifier:decimal_sep; 22, string:","; 23, comment:""" Parses CSV data from stream and returns ``Transactions``. Args: index: The index of this row in the original CSV file. Used for sorting ``Transaction``s by their order of appearance. row: The row containing strings for [transfer_date, posted_date, message, money_amount, money_total]. source_encoding: The encoding that will be used to decode strings to UTF-8. date_format: The format of dates in this row. thousand_sep: The thousand separator in money amounts. decimal_sep: The decimal separator in money amounts. Returns: A ``Transactions`` object. """; 24, assignment; 25, assignment; 26, pattern_list; 27, call; 28, block; 29, identifier:trans; 30, identifier:trans; 31, call; 32, identifier:rows; 33, call; 34, identifier:index; 35, identifier:row; 36, identifier:enumerate; 37, argument_list; 38, expression_statement; 39, identifier:Transactions; 40, argument_list; 41, attribute; 42, argument_list; 43, identifier:rows; 44, call; 45, identifier:csv; 46, identifier:reader; 47, identifier:handle; 48, keyword_argument; 49, keyword_argument; 50, attribute; 51, argument_list; 52, identifier:delimiter; 53, string:";"; 54, identifier:quotechar; 55, string:"\""; 56, identifier:trans; 57, identifier:append; 58, call; 59, attribute; 60, argument_list; 61, identifier:Parse; 62, identifier:csv_row_to_transaction; 63, identifier:index; 64, identifier:row
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 6, 15; 6, 16; 7, 17; 7, 18; 8, 19; 8, 20; 9, 21; 9, 22; 10, 23; 11, 24; 12, 25; 13, 26; 13, 27; 13, 28; 14, 29; 24, 30; 24, 31; 25, 32; 25, 33; 26, 34; 26, 35; 27, 36; 27, 37; 28, 38; 31, 39; 31, 40; 33, 41; 33, 42; 37, 43; 38, 44; 41, 45; 41, 46; 42, 47; 42, 48; 42, 49; 44, 50; 44, 51; 48, 52; 48, 53; 49, 54; 49, 55; 50, 56; 50, 57; 51, 58; 58, 59; 58, 60; 59, 61; 59, 62; 60, 63; 60, 64
def csv_to_transactions(handle, source_encoding="latin1", date_format="%d-%m-%Y", thousand_sep=".", decimal_sep=","): """ Parses CSV data from stream and returns ``Transactions``. Args: index: The index of this row in the original CSV file. Used for sorting ``Transaction``s by their order of appearance. row: The row containing strings for [transfer_date, posted_date, message, money_amount, money_total]. source_encoding: The encoding that will be used to decode strings to UTF-8. date_format: The format of dates in this row. thousand_sep: The thousand separator in money amounts. decimal_sep: The decimal separator in money amounts. Returns: A ``Transactions`` object. """ trans = Transactions() rows = csv.reader(handle, delimiter=";", quotechar="\"") for index, row in enumerate(rows): trans.append(Parse.csv_row_to_transaction(index, row)) return trans
0, module; 1, function_definition; 2, function_name:filterAcceptsRow; 3, parameters; 4, block; 5, identifier:self; 6, identifier:row; 7, identifier:parentindex; 8, expression_statement; 9, if_statement; 10, if_statement; 11, expression_statement; 12, expression_statement; 13, if_statement; 14, comment:"""Return True, if the filter accepts the given row of the parent :param row: the row to filter :type row: :class:`int` :param parentindex: the parent index :type parentindex: :class:`QtCore.QModelIndex` :returns: True, if the filter accepts the row :rtype: :class:`bool` :raises: None """; 15, not_operator; 16, block; 17, call; 18, block; 19, else_clause; 20, assignment; 21, assignment; 22, not_operator; 23, block; 24, else_clause; 25, call; 26, return_statement; 27, attribute; 28, argument_list; 29, expression_statement; 30, block; 31, identifier:i; 32, call; 33, identifier:reftrack; 34, call; 35, identifier:reftrack; 36, return_statement; 37, block; 38, attribute; 39, argument_list; 40, False; 41, identifier:parentindex; 42, identifier:isValid; 43, assignment; 44, expression_statement; 45, attribute; 46, argument_list; 47, attribute; 48, argument_list; 49, True; 50, return_statement; 51, call; 52, identifier:filterAcceptsRow; 53, identifier:row; 54, identifier:parentindex; 55, identifier:m; 56, call; 57, assignment; 58, identifier:m; 59, identifier:index; 60, identifier:row; 61, integer:18; 62, identifier:parentindex; 63, identifier:i; 64, identifier:data; 65, identifier:REFTRACK_OBJECT_ROLE; 66, call; 67, identifier:super; 68, argument_list; 69, attribute; 70, argument_list; 71, identifier:m; 72, call; 73, attribute; 74, argument_list; 75, identifier:ReftrackSortFilterModel; 76, identifier:self; 77, identifier:parentindex; 78, identifier:model; 79, attribute; 80, argument_list; 81, identifier:self; 82, identifier:filter_accept_reftrack; 83, identifier:reftrack; 84, identifier:self; 85, identifier:sourceModel
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 8, 14; 9, 15; 9, 16; 10, 17; 10, 18; 10, 19; 11, 20; 12, 21; 13, 22; 13, 23; 13, 24; 15, 25; 16, 26; 17, 27; 17, 28; 18, 29; 19, 30; 20, 31; 20, 32; 21, 33; 21, 34; 22, 35; 23, 36; 24, 37; 25, 38; 25, 39; 26, 40; 27, 41; 27, 42; 29, 43; 30, 44; 32, 45; 32, 46; 34, 47; 34, 48; 36, 49; 37, 50; 38, 51; 38, 52; 39, 53; 39, 54; 43, 55; 43, 56; 44, 57; 45, 58; 45, 59; 46, 60; 46, 61; 46, 62; 47, 63; 47, 64; 48, 65; 50, 66; 51, 67; 51, 68; 56, 69; 56, 70; 57, 71; 57, 72; 66, 73; 66, 74; 68, 75; 68, 76; 69, 77; 69, 78; 72, 79; 72, 80; 73, 81; 73, 82; 74, 83; 79, 84; 79, 85
def filterAcceptsRow(self, row, parentindex): """Return True, if the filter accepts the given row of the parent :param row: the row to filter :type row: :class:`int` :param parentindex: the parent index :type parentindex: :class:`QtCore.QModelIndex` :returns: True, if the filter accepts the row :rtype: :class:`bool` :raises: None """ if not super(ReftrackSortFilterModel, self).filterAcceptsRow(row, parentindex): return False if parentindex.isValid(): m = parentindex.model() else: m = self.sourceModel() i = m.index(row, 18, parentindex) reftrack = i.data(REFTRACK_OBJECT_ROLE) if not reftrack: return True else: return self.filter_accept_reftrack(reftrack)
0, module; 1, function_definition; 2, function_name:load_grid_data; 3, parameters; 4, block; 5, identifier:file_list; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, comment:# If there's only one file, we pretend it's a list; 11, if_statement; 12, expression_statement; 13, comment:# Initialize empty data array; 14, expression_statement; 15, comment:# Loop through file list, reading in data; 16, for_statement; 17, return_statement; 18, identifier:data_type; 19, string:"binary"; 20, identifier:sort; 21, True; 22, identifier:delim; 23, string:" "; 24, comment:""" Loads data from one or multiple grid_task files. Arguments: file_list - either a string or a list of strings indicating files to load data from. Files are assumed to be in grid_task.dat format (space delimited values, one per cell). data_type - a string representing what type of data is in the file. Either "binary", "int", "float", or "string". sort - If you're making a movie, you want the files to be in chronological order. By default, they will be sorted. If for some reason you don't want them in chronological order, set sort to False. Returns: A three-dimensional array. The first dimension is columns, the second is rows. At each row,column index in the array is another list which holds the values that each of the requested files has at that location in the grid. If you want this list collapsed to a single representative number, you should use agg_niche_grid. """; 25, not_operator; 26, block; 27, elif_clause; 28, assignment; 29, assignment; 30, identifier:f; 31, identifier:file_list; 32, block; 33, identifier:data; 34, comparison_operator:type(file_list) is list; 35, expression_statement; 36, identifier:sort; 37, comment:# put file_list in chronological order; 38, block; 39, identifier:world_size; 40, call; 41, identifier:data; 42, call; 43, expression_statement; 44, expression_statement; 45, for_statement; 46, expression_statement; 47, call; 48, identifier:list; 49, assignment; 50, expression_statement; 51, identifier:get_world_dimensions; 52, argument_list; 53, identifier:initialize_grid; 54, argument_list; 55, assignment; 56, assignment; 57, identifier:i; 58, call; 59, block; 60, call; 61, identifier:type; 62, argument_list; 63, identifier:file_list; 64, list; 65, call; 66, subscript; 67, identifier:delim; 68, identifier:world_size; 69, list; 70, identifier:infile; 71, call; 72, identifier:lines; 73, call; 74, identifier:range; 75, argument_list; 76, expression_statement; 77, for_statement; 78, attribute; 79, argument_list; 80, identifier:file_list; 81, identifier:file_list; 82, attribute; 83, argument_list; 84, identifier:file_list; 85, integer:0; 86, identifier:open; 87, argument_list; 88, attribute; 89, argument_list; 90, subscript; 91, assignment; 92, identifier:j; 93, call; 94, block; 95, identifier:infile; 96, identifier:close; 97, identifier:file_list; 98, identifier:sort; 99, keyword_argument; 100, identifier:f; 101, identifier:infile; 102, identifier:readlines; 103, identifier:world_size; 104, integer:1; 105, subscript; 106, call; 107, identifier:range; 108, argument_list; 109, if_statement; 110, expression_statement; 111, identifier:key; 112, lambda; 113, identifier:lines; 114, identifier:i; 115, attribute; 116, argument_list; 117, subscript; 118, comparison_operator:data_type == "binary"; 119, block; 120, elif_clause; 121, elif_clause; 122, elif_clause; 123, else_clause; 124, call; 125, lambda_parameters; 126, call; 127, call; 128, identifier:split; 129, identifier:delim; 130, identifier:world_size; 131, integer:0; 132, identifier:data_type; 133, string:"binary"; 134, expression_statement; 135, comparison_operator:data_type == "float"; 136, block; 137, comparison_operator:data_type == "int"; 138, block; 139, comparison_operator:data_type == "string"; 140, block; 141, block; 142, attribute; 143, argument_list; 144, identifier:f; 145, identifier:int; 146, argument_list; 147, attribute; 148, argument_list; 149, assignment; 150, identifier:data_type; 151, string:"float"; 152, expression_statement; 153, identifier:data_type; 154, string:"int"; 155, expression_statement; 156, identifier:data_type; 157, string:"string"; 158, expression_statement; 159, expression_statement; 160, return_statement; 161, subscript; 162, identifier:append; 163, identifier:val; 164, call; 165, subscript; 166, identifier:strip; 167, identifier:val; 168, call; 169, assignment; 170, assignment; 171, assignment; 172, call; 173, subscript; 174, identifier:j; 175, attribute; 176, argument_list; 177, identifier:lines; 178, identifier:i; 179, identifier:bin; 180, argument_list; 181, identifier:val; 182, call; 183, identifier:val; 184, call; 185, identifier:val; 186, call; 187, identifier:print; 188, argument_list; 189, identifier:data; 190, identifier:i; 191, identifier:re; 192, identifier:sub; 193, string:"[^0-9]"; 194, string:""; 195, identifier:f; 196, call; 197, identifier:float; 198, argument_list; 199, identifier:int; 200, argument_list; 201, identifier:str; 202, argument_list; 203, string:"Unsupported data_type passed to load_grid"; 204, identifier:int; 205, argument_list; 206, subscript; 207, subscript; 208, subscript; 209, subscript; 210, subscript; 211, identifier:j; 212, subscript; 213, identifier:j; 214, subscript; 215, identifier:j; 216, subscript; 217, identifier:j; 218, identifier:lines; 219, identifier:i; 220, identifier:lines; 221, identifier:i; 222, identifier:lines; 223, identifier:i; 224, identifier:lines; 225, identifier:i
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 4, 17; 6, 18; 6, 19; 7, 20; 7, 21; 8, 22; 8, 23; 9, 24; 11, 25; 11, 26; 11, 27; 12, 28; 14, 29; 16, 30; 16, 31; 16, 32; 17, 33; 25, 34; 26, 35; 27, 36; 27, 37; 27, 38; 28, 39; 28, 40; 29, 41; 29, 42; 32, 43; 32, 44; 32, 45; 32, 46; 34, 47; 34, 48; 35, 49; 38, 50; 40, 51; 40, 52; 42, 53; 42, 54; 43, 55; 44, 56; 45, 57; 45, 58; 45, 59; 46, 60; 47, 61; 47, 62; 49, 63; 49, 64; 50, 65; 52, 66; 52, 67; 54, 68; 54, 69; 55, 70; 55, 71; 56, 72; 56, 73; 58, 74; 58, 75; 59, 76; 59, 77; 60, 78; 60, 79; 62, 80; 64, 81; 65, 82; 65, 83; 66, 84; 66, 85; 71, 86; 71, 87; 73, 88; 73, 89; 75, 90; 76, 91; 77, 92; 77, 93; 77, 94; 78, 95; 78, 96; 82, 97; 82, 98; 83, 99; 87, 100; 88, 101; 88, 102; 90, 103; 90, 104; 91, 105; 91, 106; 93, 107; 93, 108; 94, 109; 94, 110; 99, 111; 99, 112; 105, 113; 105, 114; 106, 115; 106, 116; 108, 117; 109, 118; 109, 119; 109, 120; 109, 121; 109, 122; 109, 123; 110, 124; 112, 125; 112, 126; 115, 127; 115, 128; 116, 129; 117, 130; 117, 131; 118, 132; 118, 133; 119, 134; 120, 135; 120, 136; 121, 137; 121, 138; 122, 139; 122, 140; 123, 141; 124, 142; 124, 143; 125, 144; 126, 145; 126, 146; 127, 147; 127, 148; 134, 149; 135, 150; 135, 151; 136, 152; 137, 153; 137, 154; 138, 155; 139, 156; 139, 157; 140, 158; 141, 159; 141, 160; 142, 161; 142, 162; 143, 163; 146, 164; 147, 165; 147, 166; 149, 167; 149, 168; 152, 169; 155, 170; 158, 171; 159, 172; 161, 173; 161, 174; 164, 175; 164, 176; 165, 177; 165, 178; 168, 179; 168, 180; 169, 181; 169, 182; 170, 183; 170, 184; 171, 185; 171, 186; 172, 187; 172, 188; 173, 189; 173, 190; 175, 191; 175, 192; 176, 193; 176, 194; 176, 195; 180, 196; 182, 197; 182, 198; 184, 199; 184, 200; 186, 201; 186, 202; 188, 203; 196, 204; 196, 205; 198, 206; 200, 207; 202, 208; 205, 209; 206, 210; 206, 211; 207, 212; 207, 213; 208, 214; 208, 215; 209, 216; 209, 217; 210, 218; 210, 219; 212, 220; 212, 221; 214, 222; 214, 223; 216, 224; 216, 225
def load_grid_data(file_list, data_type="binary", sort=True, delim=" "): """ Loads data from one or multiple grid_task files. Arguments: file_list - either a string or a list of strings indicating files to load data from. Files are assumed to be in grid_task.dat format (space delimited values, one per cell). data_type - a string representing what type of data is in the file. Either "binary", "int", "float", or "string". sort - If you're making a movie, you want the files to be in chronological order. By default, they will be sorted. If for some reason you don't want them in chronological order, set sort to False. Returns: A three-dimensional array. The first dimension is columns, the second is rows. At each row,column index in the array is another list which holds the values that each of the requested files has at that location in the grid. If you want this list collapsed to a single representative number, you should use agg_niche_grid. """ # If there's only one file, we pretend it's a list if not type(file_list) is list: file_list = [file_list] elif sort: # put file_list in chronological order file_list.sort(key=lambda f: int(re.sub("[^0-9]", "", f))) world_size = get_world_dimensions(file_list[0], delim) # Initialize empty data array data = initialize_grid(world_size, []) # Loop through file list, reading in data for f in file_list: infile = open(f) lines = infile.readlines() for i in range(world_size[1]): lines[i] = lines[i].strip().split(delim) for j in range(world_size[0]): if data_type == "binary": val = bin(int(lines[i][j])) elif data_type == "float": val = float(lines[i][j]) elif data_type == "int": val = int(lines[i][j]) elif data_type == "string": val = str(lines[i][j]) else: print("Unsupported data_type passed to load_grid") return data[i][j].append(val) infile.close() return data
0, module; 1, function_definition; 2, function_name:sort; 3, parameters; 4, block; 5, identifier:self; 6, expression_statement; 7, comment:# Sort triggers by word and character length first; 8, for_statement; 9, comment:# Finally, sort triggers by priority; 10, expression_statement; 11, for_statement; 12, expression_statement; 13, comment:""" Sort triggers and their associated responses """; 14, pattern_list; 15, call; 16, block; 17, assignment; 18, identifier:triggers; 19, list_comprehension; 20, block; 21, assignment; 22, identifier:priority; 23, identifier:triggers; 24, attribute; 25, argument_list; 26, expression_statement; 27, comment:# Get and sort our atomic and wildcard patterns; 28, expression_statement; 29, expression_statement; 30, expression_statement; 31, expression_statement; 32, comment:# Replace our sorted triggers; 33, expression_statement; 34, attribute; 35, list; 36, subscript; 37, for_in_clause; 38, for_statement; 39, attribute; 40, True; 41, attribute; 42, identifier:items; 43, call; 44, assignment; 45, assignment; 46, assignment; 47, assignment; 48, assignment; 49, identifier:self; 50, identifier:_sorted_triggers; 51, attribute; 52, identifier:priority; 53, identifier:priority; 54, call; 55, identifier:trigger; 56, identifier:triggers; 57, block; 58, identifier:self; 59, identifier:sorted; 60, identifier:self; 61, identifier:_triggers; 62, attribute; 63, argument_list; 64, identifier:atomics; 65, list_comprehension; 66, identifier:wildcards; 67, list_comprehension; 68, identifier:atomics; 69, call; 70, identifier:wildcards; 71, call; 72, subscript; 73, binary_operator:atomics + wildcards; 74, identifier:self; 75, identifier:_triggers; 76, identifier:sorted; 77, argument_list; 78, expression_statement; 79, attribute; 80, identifier:debug; 81, call; 82, identifier:trigger; 83, for_in_clause; 84, if_clause; 85, identifier:trigger; 86, for_in_clause; 87, if_clause; 88, identifier:sorted; 89, argument_list; 90, identifier:sorted; 91, argument_list; 92, attribute; 93, identifier:priority; 94, identifier:atomics; 95, identifier:wildcards; 96, call; 97, keyword_argument; 98, call; 99, identifier:self; 100, identifier:_log; 101, attribute; 102, argument_list; 103, identifier:trigger; 104, identifier:triggers; 105, attribute; 106, identifier:trigger; 107, identifier:triggers; 108, not_operator; 109, identifier:atomics; 110, keyword_argument; 111, keyword_argument; 112, identifier:wildcards; 113, keyword_argument; 114, keyword_argument; 115, identifier:self; 116, identifier:_triggers; 117, attribute; 118, argument_list; 119, identifier:reverse; 120, True; 121, attribute; 122, argument_list; 123, string; 124, identifier:format; 125, keyword_argument; 126, identifier:trigger; 127, identifier:pattern_is_atomic; 128, attribute; 129, identifier:key; 130, lambda; 131, identifier:reverse; 132, True; 133, identifier:key; 134, lambda; 135, identifier:reverse; 136, True; 137, attribute; 138, identifier:keys; 139, attribute; 140, identifier:append; 141, identifier:trigger; 142, string_content:Sorting priority {priority} triggers; 143, identifier:priority; 144, identifier:priority; 145, identifier:trigger; 146, identifier:pattern_is_atomic; 147, lambda_parameters; 148, tuple; 149, lambda_parameters; 150, tuple; 151, identifier:self; 152, identifier:_triggers; 153, identifier:self; 154, identifier:_sorted_triggers; 155, identifier:trigger; 156, attribute; 157, attribute; 158, identifier:trigger; 159, attribute; 160, attribute; 161, identifier:trigger; 162, identifier:pattern_words; 163, identifier:trigger; 164, identifier:pattern_len; 165, identifier:trigger; 166, identifier:pattern_words; 167, identifier:trigger; 168, identifier:pattern_len
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 6, 13; 8, 14; 8, 15; 8, 16; 10, 17; 11, 18; 11, 19; 11, 20; 12, 21; 14, 22; 14, 23; 15, 24; 15, 25; 16, 26; 16, 27; 16, 28; 16, 29; 16, 30; 16, 31; 16, 32; 16, 33; 17, 34; 17, 35; 19, 36; 19, 37; 20, 38; 21, 39; 21, 40; 24, 41; 24, 42; 26, 43; 28, 44; 29, 45; 30, 46; 31, 47; 33, 48; 34, 49; 34, 50; 36, 51; 36, 52; 37, 53; 37, 54; 38, 55; 38, 56; 38, 57; 39, 58; 39, 59; 41, 60; 41, 61; 43, 62; 43, 63; 44, 64; 44, 65; 45, 66; 45, 67; 46, 68; 46, 69; 47, 70; 47, 71; 48, 72; 48, 73; 51, 74; 51, 75; 54, 76; 54, 77; 57, 78; 62, 79; 62, 80; 63, 81; 65, 82; 65, 83; 65, 84; 67, 85; 67, 86; 67, 87; 69, 88; 69, 89; 71, 90; 71, 91; 72, 92; 72, 93; 73, 94; 73, 95; 77, 96; 77, 97; 78, 98; 79, 99; 79, 100; 81, 101; 81, 102; 83, 103; 83, 104; 84, 105; 86, 106; 86, 107; 87, 108; 89, 109; 89, 110; 89, 111; 91, 112; 91, 113; 91, 114; 92, 115; 92, 116; 96, 117; 96, 118; 97, 119; 97, 120; 98, 121; 98, 122; 101, 123; 101, 124; 102, 125; 105, 126; 105, 127; 108, 128; 110, 129; 110, 130; 111, 131; 111, 132; 113, 133; 113, 134; 114, 135; 114, 136; 117, 137; 117, 138; 121, 139; 121, 140; 122, 141; 123, 142; 125, 143; 125, 144; 128, 145; 128, 146; 130, 147; 130, 148; 134, 149; 134, 150; 137, 151; 137, 152; 139, 153; 139, 154; 147, 155; 148, 156; 148, 157; 149, 158; 150, 159; 150, 160; 156, 161; 156, 162; 157, 163; 157, 164; 159, 165; 159, 166; 160, 167; 160, 168
def sort(self): """ Sort triggers and their associated responses """ # Sort triggers by word and character length first for priority, triggers in self._triggers.items(): self._log.debug('Sorting priority {priority} triggers'.format(priority=priority)) # Get and sort our atomic and wildcard patterns atomics = [trigger for trigger in triggers if trigger.pattern_is_atomic] wildcards = [trigger for trigger in triggers if not trigger.pattern_is_atomic] atomics = sorted(atomics, key=lambda trigger: (trigger.pattern_words, trigger.pattern_len), reverse=True) wildcards = sorted(wildcards, key=lambda trigger: (trigger.pattern_words, trigger.pattern_len), reverse=True) # Replace our sorted triggers self._triggers[priority] = atomics + wildcards # Finally, sort triggers by priority self._sorted_triggers = [] for triggers in [self._triggers[priority] for priority in sorted(self._triggers.keys(), reverse=True)]: for trigger in triggers: self._sorted_triggers.append(trigger) self.sorted = True
0, module; 1, function_definition; 2, function_name:log_message; 3, parameters; 4, block; 5, identifier:self; 6, identifier:user; 7, identifier:message; 8, expression_statement; 9, if_statement; 10, expression_statement; 11, expression_statement; 12, while_statement; 13, comment:"""Log a channel message. This log acts as a sort of cache so that recent activity can be searched by the bot and command modules without querying the database. """; 14, call; 15, block; 16, elif_clause; 17, assignment; 18, call; 19, comparison_operator:len(self.message_log) > self._log_size; 20, block; 21, identifier:isinstance; 22, argument_list; 23, expression_statement; 24, not_operator; 25, block; 26, identifier:time; 27, call; 28, attribute; 29, argument_list; 30, call; 31, attribute; 32, delete_statement; 33, identifier:user; 34, identifier:SeshetUser; 35, assignment; 36, call; 37, expression_statement; 38, attribute; 39, argument_list; 40, attribute; 41, identifier:append; 42, tuple; 43, identifier:len; 44, argument_list; 45, identifier:self; 46, identifier:_log_size; 47, subscript; 48, identifier:user; 49, attribute; 50, identifier:isinstance; 51, argument_list; 52, assignment; 53, identifier:datetime; 54, identifier:utcnow; 55, identifier:self; 56, identifier:message_log; 57, identifier:time; 58, identifier:user; 59, identifier:message; 60, attribute; 61, attribute; 62, integer:0; 63, identifier:user; 64, identifier:nick; 65, identifier:user; 66, identifier:IRCstr; 67, identifier:user; 68, call; 69, identifier:self; 70, identifier:message_log; 71, identifier:self; 72, identifier:message_log; 73, identifier:IRCstr; 74, argument_list; 75, identifier:user
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 8, 13; 9, 14; 9, 15; 9, 16; 10, 17; 11, 18; 12, 19; 12, 20; 14, 21; 14, 22; 15, 23; 16, 24; 16, 25; 17, 26; 17, 27; 18, 28; 18, 29; 19, 30; 19, 31; 20, 32; 22, 33; 22, 34; 23, 35; 24, 36; 25, 37; 27, 38; 27, 39; 28, 40; 28, 41; 29, 42; 30, 43; 30, 44; 31, 45; 31, 46; 32, 47; 35, 48; 35, 49; 36, 50; 36, 51; 37, 52; 38, 53; 38, 54; 40, 55; 40, 56; 42, 57; 42, 58; 42, 59; 44, 60; 47, 61; 47, 62; 49, 63; 49, 64; 51, 65; 51, 66; 52, 67; 52, 68; 60, 69; 60, 70; 61, 71; 61, 72; 68, 73; 68, 74; 74, 75
def log_message(self, user, message): """Log a channel message. This log acts as a sort of cache so that recent activity can be searched by the bot and command modules without querying the database. """ if isinstance(user, SeshetUser): user = user.nick elif not isinstance(user, IRCstr): user = IRCstr(user) time = datetime.utcnow() self.message_log.append((time, user, message)) while len(self.message_log) > self._log_size: del self.message_log[0]
0, module; 1, function_definition; 2, function_name:add_item; 3, parameters; 4, block; 5, identifier:self; 6, identifier:path; 7, identifier:name; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, default_parameter; 13, expression_statement; 14, if_statement; 15, expression_statement; 16, expression_statement; 17, for_statement; 18, expression_statement; 19, expression_statement; 20, if_statement; 21, identifier:icon; 22, None; 23, identifier:url; 24, None; 25, identifier:order; 26, None; 27, identifier:permission; 28, None; 29, identifier:active_regex; 30, None; 31, comment:""" Add new menu item to menu :param path: Path of menu :param name: Display name :param icon: CSS icon :param url: link to page :param order: Sort order :param permission: :return: """; 32, comparison_operator:self.root_item is None; 33, block; 34, assignment; 35, assignment; 36, identifier:node; 37, subscript; 38, block; 39, assignment; 40, assignment; 41, identifier:current_item; 42, block; 43, else_clause; 44, attribute; 45, None; 46, expression_statement; 47, identifier:root_item; 48, attribute; 49, identifier:current_path; 50, string; 51, call; 52, slice; 53, if_statement; 54, expression_statement; 55, expression_statement; 56, if_statement; 57, expression_statement; 58, identifier:new_item; 59, call; 60, identifier:current_item; 61, call; 62, expression_statement; 63, block; 64, identifier:self; 65, identifier:root_item; 66, assignment; 67, identifier:self; 68, identifier:root_item; 69, attribute; 70, argument_list; 71, unary_operator; 72, not_operator; 73, block; 74, assignment; 75, assignment; 76, not_operator; 77, comment:# Create menu item if not exists; 78, block; 79, assignment; 80, identifier:MenuItem; 81, argument_list; 82, attribute; 83, argument_list; 84, call; 85, expression_statement; 86, attribute; 87, call; 88, identifier:path; 89, identifier:split; 90, string; 91, integer:1; 92, identifier:node; 93, continue_statement; 94, identifier:current_path; 95, binary_operator:'/' + '{}/{}'.format(current_path, node).strip('/'); 96, identifier:new_root; 97, call; 98, identifier:new_root; 99, expression_statement; 100, expression_statement; 101, identifier:root_item; 102, identifier:new_root; 103, identifier:path; 104, identifier:name; 105, identifier:icon; 106, identifier:url; 107, identifier:order; 108, identifier:permission; 109, identifier:active_regex; 110, identifier:root_item; 111, identifier:child_by_code; 112, subscript; 113, attribute; 114, argument_list; 115, call; 116, identifier:self; 117, identifier:root_item; 118, identifier:MenuItem; 119, argument_list; 120, string_content:/; 121, string; 122, call; 123, attribute; 124, argument_list; 125, assignment; 126, call; 127, call; 128, unary_operator; 129, identifier:current_item; 130, identifier:merge; 131, identifier:new_item; 132, attribute; 133, argument_list; 134, string; 135, string; 136, string_content:/; 137, attribute; 138, argument_list; 139, identifier:root_item; 140, identifier:child_by_code; 141, identifier:node; 142, identifier:new_root; 143, call; 144, attribute; 145, argument_list; 146, attribute; 147, argument_list; 148, integer:1; 149, identifier:root_item; 150, identifier:add_child; 151, identifier:new_item; 152, string_content:ROOT; 153, string_content:ROOT; 154, call; 155, identifier:strip; 156, string; 157, identifier:MenuItem; 158, argument_list; 159, identifier:root_item; 160, identifier:add_child; 161, identifier:new_root; 162, identifier:path; 163, identifier:split; 164, string; 165, attribute; 166, argument_list; 167, string_content:/; 168, identifier:current_path; 169, keyword_argument; 170, string_content:/; 171, string; 172, identifier:format; 173, identifier:current_path; 174, identifier:node; 175, identifier:name; 176, call; 177, string_content:{}/{}; 178, attribute; 179, argument_list; 180, call; 181, identifier:capitalize; 182, identifier:str; 183, argument_list; 184, identifier:node
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 3, 12; 4, 13; 4, 14; 4, 15; 4, 16; 4, 17; 4, 18; 4, 19; 4, 20; 8, 21; 8, 22; 9, 23; 9, 24; 10, 25; 10, 26; 11, 27; 11, 28; 12, 29; 12, 30; 13, 31; 14, 32; 14, 33; 15, 34; 16, 35; 17, 36; 17, 37; 17, 38; 18, 39; 19, 40; 20, 41; 20, 42; 20, 43; 32, 44; 32, 45; 33, 46; 34, 47; 34, 48; 35, 49; 35, 50; 37, 51; 37, 52; 38, 53; 38, 54; 38, 55; 38, 56; 38, 57; 39, 58; 39, 59; 40, 60; 40, 61; 42, 62; 43, 63; 44, 64; 44, 65; 46, 66; 48, 67; 48, 68; 51, 69; 51, 70; 52, 71; 53, 72; 53, 73; 54, 74; 55, 75; 56, 76; 56, 77; 56, 78; 57, 79; 59, 80; 59, 81; 61, 82; 61, 83; 62, 84; 63, 85; 66, 86; 66, 87; 69, 88; 69, 89; 70, 90; 71, 91; 72, 92; 73, 93; 74, 94; 74, 95; 75, 96; 75, 97; 76, 98; 78, 99; 78, 100; 79, 101; 79, 102; 81, 103; 81, 104; 81, 105; 81, 106; 81, 107; 81, 108; 81, 109; 82, 110; 82, 111; 83, 112; 84, 113; 84, 114; 85, 115; 86, 116; 86, 117; 87, 118; 87, 119; 90, 120; 95, 121; 95, 122; 97, 123; 97, 124; 99, 125; 100, 126; 112, 127; 112, 128; 113, 129; 113, 130; 114, 131; 115, 132; 115, 133; 119, 134; 119, 135; 121, 136; 122, 137; 122, 138; 123, 139; 123, 140; 124, 141; 125, 142; 125, 143; 126, 144; 126, 145; 127, 146; 127, 147; 128, 148; 132, 149; 132, 150; 133, 151; 134, 152; 135, 153; 137, 154; 137, 155; 138, 156; 143, 157; 143, 158; 144, 159; 144, 160; 145, 161; 146, 162; 146, 163; 147, 164; 154, 165; 154, 166; 156, 167; 158, 168; 158, 169; 164, 170; 165, 171; 165, 172; 166, 173; 166, 174; 169, 175; 169, 176; 171, 177; 176, 178; 176, 179; 178, 180; 178, 181; 180, 182; 180, 183; 183, 184
def add_item(self, path, name, icon=None, url=None, order=None, permission=None, active_regex=None): """ Add new menu item to menu :param path: Path of menu :param name: Display name :param icon: CSS icon :param url: link to page :param order: Sort order :param permission: :return: """ if self.root_item is None: self.root_item = MenuItem('ROOT', 'ROOT') root_item = self.root_item current_path = '' for node in path.split('/')[:-1]: if not node: continue current_path = '/' + '{}/{}'.format(current_path, node).strip('/') new_root = root_item.child_by_code(node) if not new_root: # Create menu item if not exists new_root = MenuItem(current_path, name=str(node).capitalize()) root_item.add_child(new_root) root_item = new_root new_item = MenuItem(path, name, icon, url, order, permission, active_regex) current_item = root_item.child_by_code(path.split('/')[-1]) if current_item: current_item.merge(new_item) else: root_item.add_child(new_item)
0, module; 1, function_definition; 2, function_name:assist; 3, parameters; 4, block; 5, identifier:self; 6, identifier:project_path; 7, identifier:source; 8, identifier:position; 9, identifier:filename; 10, expression_statement; 11, return_statement; 12, comment:"""Return completion match and list of completion proposals :param project_path: absolute project path :param source: unicode or byte string code source :param position: character or byte cursor position :param filename: absolute path of file with source code :returns: tuple (completion match, sorted list of proposals) """; 13, call; 14, attribute; 15, argument_list; 16, identifier:self; 17, identifier:_call; 18, string; 19, identifier:project_path; 20, identifier:source; 21, identifier:position; 22, identifier:filename; 23, string_content:assist
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 4, 10; 4, 11; 10, 12; 11, 13; 13, 14; 13, 15; 14, 16; 14, 17; 15, 18; 15, 19; 15, 20; 15, 21; 15, 22; 18, 23
def assist(self, project_path, source, position, filename): """Return completion match and list of completion proposals :param project_path: absolute project path :param source: unicode or byte string code source :param position: character or byte cursor position :param filename: absolute path of file with source code :returns: tuple (completion match, sorted list of proposals) """ return self._call('assist', project_path, source, position, filename)
0, module; 1, function_definition; 2, function_name:sorted_key_list; 3, parameters; 4, block; 5, identifier:self; 6, expression_statement; 7, if_statement; 8, expression_statement; 9, expression_statement; 10, return_statement; 11, comment:"""Returns list of keys sorted according to their absolute time."""; 12, not_operator; 13, block; 14, assignment; 15, assignment; 16, identifier:skl; 17, attribute; 18, expression_statement; 19, identifier:key_value_tuple; 20, call; 21, identifier:skl; 22, list_comprehension; 23, identifier:self; 24, identifier:is_baked; 25, call; 26, identifier:sorted; 27, argument_list; 28, subscript; 29, for_in_clause; 30, attribute; 31, argument_list; 32, call; 33, keyword_argument; 34, identifier:k; 35, integer:0; 36, identifier:k; 37, identifier:key_value_tuple; 38, identifier:self; 39, identifier:bake; 40, attribute; 41, argument_list; 42, identifier:key; 43, lambda; 44, attribute; 45, identifier:items; 46, lambda_parameters; 47, subscript; 48, identifier:self; 49, identifier:dct; 50, identifier:x; 51, subscript; 52, string; 53, identifier:x; 54, integer:1; 55, string_content:__abs_time__
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 4, 8; 4, 9; 4, 10; 6, 11; 7, 12; 7, 13; 8, 14; 9, 15; 10, 16; 12, 17; 13, 18; 14, 19; 14, 20; 15, 21; 15, 22; 17, 23; 17, 24; 18, 25; 20, 26; 20, 27; 22, 28; 22, 29; 25, 30; 25, 31; 27, 32; 27, 33; 28, 34; 28, 35; 29, 36; 29, 37; 30, 38; 30, 39; 32, 40; 32, 41; 33, 42; 33, 43; 40, 44; 40, 45; 43, 46; 43, 47; 44, 48; 44, 49; 46, 50; 47, 51; 47, 52; 51, 53; 51, 54; 52, 55
def sorted_key_list(self): """Returns list of keys sorted according to their absolute time.""" if not self.is_baked: self.bake() key_value_tuple = sorted(self.dct.items(), key=lambda x: x[1]['__abs_time__']) skl = [k[0] for k in key_value_tuple] return skl
0, module; 1, function_definition; 2, function_name:get_used_key_frames; 3, parameters; 4, block; 5, identifier:self; 6, expression_statement; 7, expression_statement; 8, comment:# each element in used_key_frames is a tuple (key_name, key_dict); 9, expression_statement; 10, for_statement; 11, return_statement; 12, comment:"""Returns a list of the keyframes used by this channel, sorted with time. Each element in the list is a tuple. The first element is the key_name and the second is the channel data at that keyframe."""; 13, assignment; 14, assignment; 15, identifier:kf; 16, identifier:skl; 17, block; 18, identifier:used_key_frames; 19, identifier:skl; 20, call; 21, identifier:used_key_frames; 22, list; 23, if_statement; 24, attribute; 25, argument_list; 26, comparison_operator:kf in self.dct['keys']; 27, block; 28, attribute; 29, identifier:sorted_key_list; 30, identifier:kf; 31, subscript; 32, expression_statement; 33, identifier:self; 34, identifier:key_frame_list; 35, attribute; 36, string; 37, call; 38, identifier:self; 39, identifier:dct; 40, string_content:keys; 41, attribute; 42, argument_list; 43, identifier:used_key_frames; 44, identifier:append; 45, tuple; 46, identifier:kf; 47, subscript; 48, subscript; 49, identifier:kf; 50, attribute; 51, string; 52, identifier:self; 53, identifier:dct; 54, string_content:keys
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 6, 12; 7, 13; 9, 14; 10, 15; 10, 16; 10, 17; 11, 18; 13, 19; 13, 20; 14, 21; 14, 22; 17, 23; 20, 24; 20, 25; 23, 26; 23, 27; 24, 28; 24, 29; 26, 30; 26, 31; 27, 32; 28, 33; 28, 34; 31, 35; 31, 36; 32, 37; 35, 38; 35, 39; 36, 40; 37, 41; 37, 42; 41, 43; 41, 44; 42, 45; 45, 46; 45, 47; 47, 48; 47, 49; 48, 50; 48, 51; 50, 52; 50, 53; 51, 54
def get_used_key_frames(self): """Returns a list of the keyframes used by this channel, sorted with time. Each element in the list is a tuple. The first element is the key_name and the second is the channel data at that keyframe.""" skl = self.key_frame_list.sorted_key_list() # each element in used_key_frames is a tuple (key_name, key_dict) used_key_frames = [] for kf in skl: if kf in self.dct['keys']: used_key_frames.append((kf, self.dct['keys'][kf])) return used_key_frames
0, module; 1, function_definition; 2, function_name:flds_firstsort; 3, parameters; 4, block; 5, identifier:d; 6, expression_statement; 7, expression_statement; 8, expression_statement; 9, return_statement; 10, string; 11, assignment; 12, assignment; 13, expression_list; 14, string_content:Perform a lexsort and return the sort indices and shape as a tuple.; 15, identifier:shape; 16, list_comprehension; 17, identifier:si; 18, call; 19, identifier:si; 20, identifier:shape; 21, call; 22, for_in_clause; 23, attribute; 24, argument_list; 25, identifier:len; 26, argument_list; 27, identifier:l; 28, list; 29, identifier:np; 30, identifier:lexsort; 31, tuple; 32, call; 33, string; 34, string; 35, string; 36, subscript; 37, subscript; 38, subscript; 39, attribute; 40, argument_list; 41, string_content:xs; 42, string_content:ys; 43, string_content:zs; 44, identifier:d; 45, string; 46, identifier:d; 47, string; 48, identifier:d; 49, string; 50, identifier:np; 51, identifier:unique; 52, subscript; 53, string_content:z; 54, string_content:y; 55, string_content:x; 56, identifier:d; 57, identifier:l
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 4, 8; 4, 9; 6, 10; 7, 11; 8, 12; 9, 13; 10, 14; 11, 15; 11, 16; 12, 17; 12, 18; 13, 19; 13, 20; 16, 21; 16, 22; 18, 23; 18, 24; 21, 25; 21, 26; 22, 27; 22, 28; 23, 29; 23, 30; 24, 31; 26, 32; 28, 33; 28, 34; 28, 35; 31, 36; 31, 37; 31, 38; 32, 39; 32, 40; 33, 41; 34, 42; 35, 43; 36, 44; 36, 45; 37, 46; 37, 47; 38, 48; 38, 49; 39, 50; 39, 51; 40, 52; 45, 53; 47, 54; 49, 55; 52, 56; 52, 57
def flds_firstsort(d): ''' Perform a lexsort and return the sort indices and shape as a tuple. ''' shape = [ len( np.unique(d[l]) ) for l in ['xs', 'ys', 'zs'] ]; si = np.lexsort((d['z'],d['y'],d['x'])); return si,shape;
0, module; 1, function_definition; 2, function_name:flds_sort; 3, parameters; 4, block; 5, identifier:d; 6, identifier:s; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, for_statement; 11, return_statement; 12, string; 13, assignment; 14, assignment; 15, identifier:l; 16, identifier:labels; 17, block; 18, identifier:d; 19, string_content:Sort based on position. Sort with s as a tuple of the sort indices and shape from first sort. Parameters: ----------- d -- the flds/sclr data s -- (si, shape) sorting and shaping data from firstsort.; 20, identifier:labels; 21, list_comprehension; 22, pattern_list; 23, identifier:s; 24, expression_statement; 25, expression_statement; 26, identifier:key; 27, for_in_clause; 28, if_clause; 29, identifier:si; 30, identifier:shape; 31, assignment; 32, assignment; 33, identifier:key; 34, call; 35, comparison_operator:key not in ['t', 'xs', 'ys', 'zs', 'fd', 'sd']; 36, subscript; 37, call; 38, subscript; 39, call; 40, attribute; 41, argument_list; 42, identifier:key; 43, list; 44, identifier:d; 45, identifier:l; 46, attribute; 47, argument_list; 48, identifier:d; 49, identifier:l; 50, attribute; 51, argument_list; 52, identifier:d; 53, identifier:keys; 54, string; 55, string; 56, string; 57, string; 58, string; 59, string; 60, subscript; 61, identifier:reshape; 62, identifier:shape; 63, identifier:np; 64, identifier:squeeze; 65, subscript; 66, string_content:t; 67, string_content:xs; 68, string_content:ys; 69, string_content:zs; 70, string_content:fd; 71, string_content:sd; 72, subscript; 73, identifier:si; 74, identifier:d; 75, identifier:l; 76, identifier:d; 77, identifier:l
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 7, 12; 8, 13; 9, 14; 10, 15; 10, 16; 10, 17; 11, 18; 12, 19; 13, 20; 13, 21; 14, 22; 14, 23; 17, 24; 17, 25; 21, 26; 21, 27; 21, 28; 22, 29; 22, 30; 24, 31; 25, 32; 27, 33; 27, 34; 28, 35; 31, 36; 31, 37; 32, 38; 32, 39; 34, 40; 34, 41; 35, 42; 35, 43; 36, 44; 36, 45; 37, 46; 37, 47; 38, 48; 38, 49; 39, 50; 39, 51; 40, 52; 40, 53; 43, 54; 43, 55; 43, 56; 43, 57; 43, 58; 43, 59; 46, 60; 46, 61; 47, 62; 50, 63; 50, 64; 51, 65; 54, 66; 55, 67; 56, 68; 57, 69; 58, 70; 59, 71; 60, 72; 60, 73; 65, 74; 65, 75; 72, 76; 72, 77
def flds_sort(d,s): ''' Sort based on position. Sort with s as a tuple of the sort indices and shape from first sort. Parameters: ----------- d -- the flds/sclr data s -- (si, shape) sorting and shaping data from firstsort. ''' labels = [ key for key in d.keys() if key not in ['t', 'xs', 'ys', 'zs', 'fd', 'sd'] ]; si,shape = s; for l in labels: d[l] = d[l][si].reshape(shape); d[l] = np.squeeze(d[l]); return d;
0, module; 1, function_definition; 2, function_name:read; 3, parameters; 4, block; 5, identifier:fname; 6, dictionary_splat_pattern; 7, expression_statement; 8, if_statement; 9, expression_statement; 10, with_statement; 11, return_statement; 12, identifier:kw; 13, string; 14, boolean_operator; 15, block; 16, assignment; 17, with_clause; 18, block; 19, identifier:d; 20, string_content:Reads an lsp output file and returns a raw dump of data, sectioned into quantities either as an dictionary or a typed numpy array. Parameters: ----------- fname -- filename of thing to read Keyword Arguments: ------------------ vprint -- Verbose printer. Used in scripts override -- (type, start) => A tuple of a dump type and a place to start in the passed file, useful to attempting to read semicorrupted files. gzip -- Read as a gzip file. flds/sclr Specific Arguments: ----------------------------- var -- list of quantities to be read. For fields, this can consist of strings that include vector components, e.g., 'Ex'. If None (default), read all quantities. keep_edges -- If set to truthy, then don't remove the edges from domains before concatenation and don't reshape the flds data. sort -- If not None, sort using these indices, useful for avoiding resorting. If True and not an ndarray, just sort. first_sort -- If truthy, sort, and return the sort data for future flds that should have the same shape. keep_xs -- Keep the xs's, that is, the grid information. Usually redundant with x,y,z returned. return_array -- If set to truthy, then try to return a numpy array with a dtype. Requires of course that the quantities have the same shape.; 21, call; 22, comparison_operator:kw['gzip'] == 'guess'; 23, expression_statement; 24, identifier:openf; 25, conditional_expression:gzip.open if test(kw, 'gzip') else open; 26, with_item; 27, if_statement; 28, expression_statement; 29, if_statement; 30, expression_statement; 31, try_statement; 32, identifier:test; 33, argument_list; 34, subscript; 35, string; 36, assignment; 37, attribute; 38, call; 39, identifier:open; 40, as_pattern; 41, call; 42, block; 43, else_clause; 44, assignment; 45, comparison_operator:2 <= header['dump_type'] <= 3; 46, block; 47, assignment; 48, block; 49, except_clause; 50, identifier:kw; 51, string; 52, identifier:kw; 53, string; 54, string_content:guess; 55, subscript; 56, comparison_operator:re.search(r'\.gz$', fname) is not None; 57, identifier:gzip; 58, identifier:open; 59, identifier:test; 60, argument_list; 61, call; 62, as_pattern_target; 63, identifier:test; 64, argument_list; 65, expression_statement; 66, expression_statement; 67, expression_statement; 68, if_statement; 69, block; 70, identifier:vprint; 71, conditional_expression:kw['vprint'] if test(kw, 'vprint') else lambda s: None; 72, integer:2; 73, subscript; 74, integer:3; 75, if_statement; 76, expression_statement; 77, expression_statement; 78, if_statement; 79, expression_statement; 80, expression_statement; 81, identifier:readers; 82, dictionary; 83, expression_statement; 84, identifier:KeyError; 85, block; 86, string_content:gzip; 87, string_content:gzip; 88, identifier:kw; 89, string; 90, call; 91, None; 92, identifier:kw; 93, string; 94, identifier:openf; 95, argument_list; 96, identifier:file; 97, identifier:kw; 98, string; 99, assignment; 100, call; 101, assignment; 102, boolean_operator; 103, block; 104, expression_statement; 105, subscript; 106, call; 107, lambda; 108, identifier:header; 109, string; 110, not_operator; 111, block; 112, else_clause; 113, assignment; 114, assignment; 115, call; 116, block; 117, else_clause; 118, assignment; 119, assignment; 120, pair; 121, pair; 122, pair; 123, pair; 124, pair; 125, assignment; 126, raise_statement; 127, string_content:gzip; 128, attribute; 129, argument_list; 130, string_content:gzip; 131, identifier:fname; 132, string; 133, string_content:override; 134, pattern_list; 135, subscript; 136, attribute; 137, argument_list; 138, identifier:header; 139, dictionary; 140, not_operator; 141, comparison_operator:2 <= header['dump_type'] <= 3; 142, raise_statement; 143, assignment; 144, identifier:kw; 145, string; 146, identifier:test; 147, argument_list; 148, lambda_parameters; 149, None; 150, string_content:dump_type; 151, call; 152, expression_statement; 153, block; 154, identifier:keep_edges; 155, call; 156, identifier:first_sort; 157, call; 158, identifier:test; 159, argument_list; 160, expression_statement; 161, block; 162, identifier:keep_xs; 163, call; 164, identifier:return_array; 165, call; 166, integer:1; 167, lambda; 168, integer:2; 169, lambda; 170, integer:3; 171, lambda; 172, integer:6; 173, lambda; 174, integer:10; 175, lambda; 176, identifier:d; 177, call; 178, call; 179, identifier:re; 180, identifier:search; 181, string; 182, identifier:fname; 183, string_content:rb; 184, identifier:dump; 185, identifier:start; 186, identifier:kw; 187, string; 188, identifier:file; 189, identifier:seek; 190, identifier:start; 191, pair; 192, call; 193, integer:2; 194, subscript; 195, integer:3; 196, call; 197, identifier:header; 198, call; 199, string_content:vprint; 200, identifier:kw; 201, string; 202, identifier:s; 203, identifier:test; 204, argument_list; 205, assignment; 206, expression_statement; 207, identifier:test; 208, argument_list; 209, identifier:test; 210, argument_list; 211, identifier:kw; 212, string; 213, assignment; 214, expression_statement; 215, identifier:test; 216, argument_list; 217, identifier:test; 218, argument_list; 219, call; 220, call; 221, call; 222, call; 223, call; 224, subscript; 225, argument_list; 226, identifier:NotImplementedError; 227, argument_list; 228, string_content:\.gz$; 229, string_content:override; 230, string; 231, identifier:dump; 232, identifier:test; 233, argument_list; 234, identifier:header; 235, string; 236, identifier:ValueError; 237, argument_list; 238, identifier:get_header; 239, argument_list; 240, string_content:vprint; 241, identifier:kw; 242, string; 243, identifier:var; 244, list_comprehension; 245, assignment; 246, identifier:kw; 247, string; 248, identifier:kw; 249, string; 250, string_content:sort; 251, identifier:sort; 252, subscript; 253, assignment; 254, identifier:kw; 255, string; 256, identifier:kw; 257, string; 258, identifier:read_particles; 259, argument_list; 260, identifier:read_flds; 261, argument_list; 262, identifier:read_flds; 263, argument_list; 264, identifier:read_movie; 265, argument_list; 266, identifier:read_pext; 267, argument_list; 268, identifier:readers; 269, subscript; 270, string:"Other file types not implemented yet!"; 271, string_content:dump_type; 272, identifier:kw; 273, string; 274, string_content:dump_type; 275, string:"If you want to force to read as a scalar, you need to supply the quantities"; 276, identifier:file; 277, string_content:var; 278, subscript; 279, for_in_clause; 280, identifier:var; 281, subscript; 282, string_content:keep_edges; 283, string_content:first_sort; 284, identifier:kw; 285, string; 286, identifier:sort; 287, None; 288, string_content:keep_xs; 289, string_content:return_array; 290, identifier:file; 291, identifier:header; 292, identifier:file; 293, identifier:header; 294, identifier:var; 295, identifier:vprint; 296, keyword_argument; 297, keyword_argument; 298, keyword_argument; 299, keyword_argument; 300, keyword_argument; 301, identifier:file; 302, identifier:header; 303, identifier:var; 304, identifier:vprint; 305, keyword_argument; 306, keyword_argument; 307, keyword_argument; 308, keyword_argument; 309, keyword_argument; 310, keyword_argument; 311, identifier:file; 312, identifier:header; 313, identifier:file; 314, identifier:header; 315, identifier:header; 316, string; 317, string_content:var; 318, identifier:i; 319, integer:0; 320, identifier:i; 321, subscript; 322, identifier:kw; 323, string; 324, string_content:sort; 325, identifier:keep_edges; 326, identifier:keep_edges; 327, identifier:first_sort; 328, identifier:first_sort; 329, identifier:sort; 330, identifier:sort; 331, identifier:keep_xs; 332, identifier:keep_xs; 333, identifier:return_array; 334, identifier:return_array; 335, identifier:keep_edges; 336, identifier:keep_edges; 337, identifier:first_sort; 338, identifier:first_sort; 339, identifier:sort; 340, identifier:sort; 341, identifier:keep_xs; 342, identifier:keep_xs; 343, identifier:return_array; 344, identifier:return_array; 345, identifier:vector; 346, False; 347, string_content:dump_type; 348, identifier:header; 349, string; 350, string_content:var; 351, string_content:quantities
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 6, 12; 7, 13; 8, 14; 8, 15; 9, 16; 10, 17; 10, 18; 11, 19; 13, 20; 14, 21; 14, 22; 15, 23; 16, 24; 16, 25; 17, 26; 18, 27; 18, 28; 18, 29; 18, 30; 18, 31; 21, 32; 21, 33; 22, 34; 22, 35; 23, 36; 25, 37; 25, 38; 25, 39; 26, 40; 27, 41; 27, 42; 27, 43; 28, 44; 29, 45; 29, 46; 30, 47; 31, 48; 31, 49; 33, 50; 33, 51; 34, 52; 34, 53; 35, 54; 36, 55; 36, 56; 37, 57; 37, 58; 38, 59; 38, 60; 40, 61; 40, 62; 41, 63; 41, 64; 42, 65; 42, 66; 42, 67; 42, 68; 43, 69; 44, 70; 44, 71; 45, 72; 45, 73; 45, 74; 46, 75; 46, 76; 46, 77; 46, 78; 46, 79; 46, 80; 47, 81; 47, 82; 48, 83; 49, 84; 49, 85; 51, 86; 53, 87; 55, 88; 55, 89; 56, 90; 56, 91; 60, 92; 60, 93; 61, 94; 61, 95; 62, 96; 64, 97; 64, 98; 65, 99; 66, 100; 67, 101; 68, 102; 68, 103; 69, 104; 71, 105; 71, 106; 71, 107; 73, 108; 73, 109; 75, 110; 75, 111; 75, 112; 76, 113; 77, 114; 78, 115; 78, 116; 78, 117; 79, 118; 80, 119; 82, 120; 82, 121; 82, 122; 82, 123; 82, 124; 83, 125; 85, 126; 89, 127; 90, 128; 90, 129; 93, 130; 95, 131; 95, 132; 98, 133; 99, 134; 99, 135; 100, 136; 100, 137; 101, 138; 101, 139; 102, 140; 102, 141; 103, 142; 104, 143; 105, 144; 105, 145; 106, 146; 106, 147; 107, 148; 107, 149; 109, 150; 110, 151; 111, 152; 112, 153; 113, 154; 113, 155; 114, 156; 114, 157; 115, 158; 115, 159; 116, 160; 117, 161; 118, 162; 118, 163; 119, 164; 119, 165; 120, 166; 120, 167; 121, 168; 121, 169; 122, 170; 122, 171; 123, 172; 123, 173; 124, 174; 124, 175; 125, 176; 125, 177; 126, 178; 128, 179; 128, 180; 129, 181; 129, 182; 132, 183; 134, 184; 134, 185; 135, 186; 135, 187; 136, 188; 136, 189; 137, 190; 139, 191; 140, 192; 141, 193; 141, 194; 141, 195; 142, 196; 143, 197; 143, 198; 145, 199; 147, 200; 147, 201; 148, 202; 151, 203; 151, 204; 152, 205; 153, 206; 155, 207; 155, 208; 157, 209; 157, 210; 159, 211; 159, 212; 160, 213; 161, 214; 163, 215; 163, 216; 165, 217; 165, 218; 167, 219; 169, 220; 171, 221; 173, 222; 175, 223; 177, 224; 177, 225; 178, 226; 178, 227; 181, 228; 187, 229; 191, 230; 191, 231; 192, 232; 192, 233; 194, 234; 194, 235; 196, 236; 196, 237; 198, 238; 198, 239; 201, 240; 204, 241; 204, 242; 205, 243; 205, 244; 206, 245; 208, 246; 208, 247; 210, 248; 210, 249; 212, 250; 213, 251; 213, 252; 214, 253; 216, 254; 216, 255; 218, 256; 218, 257; 219, 258; 219, 259; 220, 260; 220, 261; 221, 262; 221, 263; 222, 264; 222, 265; 223, 266; 223, 267; 224, 268; 224, 269; 227, 270; 230, 271; 233, 272; 233, 273; 235, 274; 237, 275; 239, 276; 242, 277; 244, 278; 244, 279; 245, 280; 245, 281; 247, 282; 249, 283; 252, 284; 252, 285; 253, 286; 253, 287; 255, 288; 257, 289; 259, 290; 259, 291; 261, 292; 261, 293; 261, 294; 261, 295; 261, 296; 261, 297; 261, 298; 261, 299; 261, 300; 263, 301; 263, 302; 263, 303; 263, 304; 263, 305; 263, 306; 263, 307; 263, 308; 263, 309; 263, 310; 265, 311; 265, 312; 267, 313; 267, 314; 269, 315; 269, 316; 273, 317; 278, 318; 278, 319; 279, 320; 279, 321; 281, 322; 281, 323; 285, 324; 296, 325; 296, 326; 297, 327; 297, 328; 298, 329; 298, 330; 299, 331; 299, 332; 300, 333; 300, 334; 305, 335; 305, 336; 306, 337; 306, 338; 307, 339; 307, 340; 308, 341; 308, 342; 309, 343; 309, 344; 310, 345; 310, 346; 316, 347; 321, 348; 321, 349; 323, 350; 349, 351
def read(fname,**kw): ''' Reads an lsp output file and returns a raw dump of data, sectioned into quantities either as an dictionary or a typed numpy array. Parameters: ----------- fname -- filename of thing to read Keyword Arguments: ------------------ vprint -- Verbose printer. Used in scripts override -- (type, start) => A tuple of a dump type and a place to start in the passed file, useful to attempting to read semicorrupted files. gzip -- Read as a gzip file. flds/sclr Specific Arguments: ----------------------------- var -- list of quantities to be read. For fields, this can consist of strings that include vector components, e.g., 'Ex'. If None (default), read all quantities. keep_edges -- If set to truthy, then don't remove the edges from domains before concatenation and don't reshape the flds data. sort -- If not None, sort using these indices, useful for avoiding resorting. If True and not an ndarray, just sort. first_sort -- If truthy, sort, and return the sort data for future flds that should have the same shape. keep_xs -- Keep the xs's, that is, the grid information. Usually redundant with x,y,z returned. return_array -- If set to truthy, then try to return a numpy array with a dtype. Requires of course that the quantities have the same shape. ''' if test(kw,'gzip') and kw['gzip'] == 'guess': kw['gzip'] = re.search(r'\.gz$', fname) is not None; openf = gzip.open if test(kw, 'gzip') else open; with openf(fname,'rb') as file: if test(kw,'override'): dump, start = kw['override']; file.seek(start); header = {'dump_type': dump}; if not test(kw, 'var') and 2 <= header['dump_type'] <= 3 : raise ValueError( "If you want to force to read as a scalar, you need to supply the quantities" ); else: header = get_header(file); vprint = kw['vprint'] if test(kw, 'vprint') else lambda s: None; if 2 <= header['dump_type'] <= 3 : if not test(kw, 'var'): var=[i[0] for i in header['quantities']]; else: var=kw['var']; keep_edges = test(kw, 'keep_edges'); first_sort = test(kw, 'first_sort'); if test(kw,'sort'): sort = kw['sort'] else: sort = None; keep_xs = test(kw, 'keep_xs'); return_array = test(kw, 'return_array'); readers = { 1: lambda: read_particles(file, header), 2: lambda: read_flds( file,header,var,vprint, keep_edges=keep_edges, first_sort=first_sort, sort=sort, keep_xs=keep_xs, return_array=return_array), 3: lambda: read_flds( file,header,var, vprint, keep_edges=keep_edges, first_sort=first_sort, sort=sort, keep_xs=keep_xs, return_array=return_array, vector=False), 6: lambda: read_movie(file, header), 10:lambda: read_pext(file,header) }; try: d = readers[header['dump_type']](); except KeyError: raise NotImplementedError("Other file types not implemented yet!"); return d;
0, module; 1, function_definition; 2, function_name:get_region_nt_counts; 3, parameters; 4, block; 5, identifier:region; 6, identifier:bam; 7, default_parameter; 8, expression_statement; 9, comment:# TODO: I should figure out what the different possible values are that; 10, comment:# pysam could give me back (so far I only have ATCGN). Can I get deletions; 11, comment:# and insertions?; 12, comment:# TODO: This could probably be parallelized.; 13, if_statement; 14, if_statement; 15, expression_statement; 16, if_statement; 17, expression_statement; 18, for_statement; 19, return_statement; 20, identifier:stranded; 21, False; 22, comment:""" Get counts of each nucleotide from a bam file for a given region. If R1 and R2 reads both overlap a position, only one count will be added. If the R1 and R2 reads disagree at a position they both overlap, that read pair is not used for that position. Can optionally output strand-specific counts. Parameters ---------- region : str or list Region of type chrom:start-end, chrom:start-end:strand, or [chrom, start, end]. The strand is ignored for chrom:start-end:strand. For chrom:start-end, the coordinates are one-based inclusive. For example, the query chr1:10-11 will give you the counts for the 10th and 11th bases of chr1. For [chrom, start, end], the coordinates are zero-based and end exclusive (like a bed file). The query [chr1, 9, 11] will give you the coverage of the 10th and 11th bases of chr1. The region value is passed directly to pysam's pileup function. bam : pysam.calignmentfile.AlignmentFile or str Bam file opened with pysam or path to bam file (must be sorted and indexed). stranded : boolean Boolean indicating whether read data is stranded and stranded nucleotide counts should be returned. Assumes R1 read on reverse strand implies + strand coverage etc. Returns ------- counts : pandas.DataFrame Data frame with the counts for each base in the region. The index of this data frame is one-based for compatibility with VCF files. """; 23, comparison_operator:type(bam) == str; 24, block; 25, comparison_operator:type(region) is str; 26, block; 27, elif_clause; 28, assignment; 29, identifier:stranded; 30, block; 31, assignment; 32, identifier:pc; 33, identifier:pp; 34, comment:# Most of this code deals with R1 and R2 reads that overlap so that we; 35, comment:# don't get two counts from one fragment.; 36, block; 37, identifier:counts; 38, call; 39, identifier:str; 40, expression_statement; 41, call; 42, identifier:str; 43, expression_statement; 44, if_statement; 45, expression_statement; 46, expression_statement; 47, expression_statement; 48, expression_statement; 49, comparison_operator:type(region) is (list or tuple); 50, block; 51, identifier:cols; 52, list; 53, expression_statement; 54, identifier:counts; 55, call; 56, expression_statement; 57, expression_statement; 58, expression_statement; 59, expression_statement; 60, expression_statement; 61, for_statement; 62, expression_statement; 63, expression_statement; 64, expression_statement; 65, expression_statement; 66, expression_statement; 67, expression_statement; 68, expression_statement; 69, expression_statement; 70, expression_statement; 71, expression_statement; 72, for_statement; 73, identifier:type; 74, argument_list; 75, assignment; 76, identifier:type; 77, argument_list; 78, assignment; 79, comparison_operator:len(r) == 3; 80, block; 81, elif_clause; 82, assignment; 83, assignment; 84, assignment; 85, assignment; 86, call; 87, parenthesized_expression; 88, expression_statement; 89, expression_statement; 90, expression_statement; 91, string; 92, string; 93, string; 94, string; 95, string; 96, assignment; 97, attribute; 98, argument_list; 99, assignment; 100, assignment; 101, assignment; 102, assignment; 103, assignment; 104, identifier:pr; 105, attribute; 106, block; 107, assignment; 108, assignment; 109, assignment; 110, assignment; 111, assignment; 112, assignment; 113, call; 114, call; 115, assignment; 116, call; 117, identifier:vc; 118, identifier:vcs; 119, block; 120, identifier:bam; 121, identifier:bam; 122, call; 123, identifier:region; 124, identifier:r; 125, call; 126, call; 127, integer:3; 128, expression_statement; 129, comparison_operator:len(r) == 4; 130, block; 131, identifier:start; 132, call; 133, identifier:end; 134, call; 135, identifier:ind; 136, list_comprehension; 137, identifier:pp; 138, call; 139, identifier:type; 140, argument_list; 141, boolean_operator; 142, assignment; 143, assignment; 144, assignment; 145, string_content:A; 146, string_content:T; 147, string_content:C; 148, string_content:G; 149, string_content:N; 150, identifier:cols; 151, binary_operator:['{}+'.format(x) for x in cols] + ['{}-'.format(x) for x in cols]; 152, identifier:pd; 153, identifier:DataFrame; 154, integer:0; 155, keyword_argument; 156, keyword_argument; 157, identifier:pos; 158, binary_operator:pc.reference_pos + 1; 159, identifier:r1_qnames; 160, list; 161, identifier:r1_nts; 162, list; 163, identifier:r2_qnames; 164, list; 165, identifier:r2_nts; 166, list; 167, identifier:pc; 168, identifier:pileups; 169, expression_statement; 170, expression_statement; 171, expression_statement; 172, if_statement; 173, identifier:r1; 174, call; 175, identifier:r2; 176, call; 177, identifier:df; 178, attribute; 179, identifier:singles; 180, subscript; 181, identifier:doubles; 182, call; 183, identifier:vcs; 184, list; 185, attribute; 186, argument_list; 187, attribute; 188, argument_list; 189, identifier:doubles; 190, subscript; 191, attribute; 192, argument_list; 193, expression_statement; 194, attribute; 195, argument_list; 196, identifier:parse_region; 197, argument_list; 198, identifier:len; 199, argument_list; 200, assignment; 201, call; 202, integer:4; 203, expression_statement; 204, identifier:int; 205, argument_list; 206, identifier:int; 207, argument_list; 208, call; 209, for_in_clause; 210, attribute; 211, argument_list; 212, identifier:region; 213, identifier:list; 214, identifier:tuple; 215, pattern_list; 216, identifier:region; 217, identifier:ind; 218, list_comprehension; 219, identifier:pp; 220, call; 221, list_comprehension; 222, list_comprehension; 223, identifier:index; 224, identifier:ind; 225, identifier:columns; 226, identifier:cols; 227, attribute; 228, integer:1; 229, assignment; 230, assignment; 231, assignment; 232, identifier:nt; 233, block; 234, attribute; 235, argument_list; 236, attribute; 237, argument_list; 238, call; 239, identifier:T; 240, identifier:df; 241, comparison_operator:df.isnull().sum(axis=1) == 1; 242, attribute; 243, argument_list; 244, identifier:vcs; 245, identifier:append; 246, call; 247, identifier:vcs; 248, identifier:append; 249, call; 250, identifier:doubles; 251, comparison_operator:doubles.R1 == doubles.R2; 252, identifier:vcs; 253, identifier:append; 254, call; 255, augmented_assignment; 256, identifier:pysam; 257, identifier:AlignmentFile; 258, identifier:bam; 259, string; 260, identifier:region; 261, identifier:r; 262, pattern_list; 263, identifier:r; 264, identifier:len; 265, argument_list; 266, assignment; 267, identifier:start; 268, identifier:end; 269, attribute; 270, argument_list; 271, identifier:x; 272, call; 273, identifier:bam; 274, identifier:pileup; 275, keyword_argument; 276, keyword_argument; 277, identifier:chrom; 278, identifier:start; 279, identifier:end; 280, call; 281, for_in_clause; 282, attribute; 283, argument_list; 284, call; 285, for_in_clause; 286, call; 287, for_in_clause; 288, identifier:pc; 289, identifier:reference_pos; 290, identifier:qnames; 291, subscript; 292, identifier:nts; 293, subscript; 294, identifier:nt; 295, call; 296, expression_statement; 297, expression_statement; 298, identifier:pd; 299, identifier:Series; 300, identifier:r1_nts; 301, keyword_argument; 302, identifier:pd; 303, identifier:Series; 304, identifier:r2_nts; 305, keyword_argument; 306, attribute; 307, argument_list; 308, call; 309, integer:1; 310, identifier:df; 311, identifier:dropna; 312, attribute; 313, argument_list; 314, attribute; 315, argument_list; 316, attribute; 317, attribute; 318, attribute; 319, argument_list; 320, subscript; 321, identifier:vc; 322, string_content:rb; 323, identifier:chrom; 324, identifier:start; 325, identifier:end; 326, identifier:r; 327, pattern_list; 328, identifier:r; 329, string; 330, identifier:format; 331, identifier:chrom; 332, identifier:x; 333, identifier:range; 334, argument_list; 335, identifier:region; 336, identifier:region; 337, identifier:truncate; 338, True; 339, attribute; 340, argument_list; 341, identifier:x; 342, call; 343, identifier:bam; 344, identifier:pileup; 345, identifier:chrom; 346, identifier:start; 347, identifier:end; 348, keyword_argument; 349, attribute; 350, argument_list; 351, identifier:x; 352, identifier:cols; 353, attribute; 354, argument_list; 355, identifier:x; 356, identifier:cols; 357, list; 358, attribute; 359, list; 360, attribute; 361, identifier:_pos_nt; 362, argument_list; 363, call; 364, call; 365, identifier:index; 366, identifier:r1_qnames; 367, identifier:index; 368, identifier:r2_qnames; 369, identifier:pd; 370, identifier:DataFrame; 371, list; 372, keyword_argument; 373, attribute; 374, argument_list; 375, subscript; 376, identifier:value_counts; 377, subscript; 378, identifier:value_counts; 379, identifier:doubles; 380, identifier:R1; 381, identifier:doubles; 382, identifier:R2; 383, attribute; 384, identifier:value_counts; 385, attribute; 386, call; 387, attribute; 388, identifier:chrom; 389, identifier:start; 390, identifier:end; 391, identifier:strand; 392, string_content:{}:{}; 393, identifier:start; 394, binary_operator:end + 1; 395, string; 396, identifier:format; 397, identifier:chrom; 398, identifier:x; 399, identifier:range; 400, argument_list; 401, identifier:truncate; 402, True; 403, string; 404, identifier:format; 405, identifier:x; 406, string; 407, identifier:format; 408, identifier:x; 409, identifier:r1_qnames; 410, identifier:r2_qnames; 411, attribute; 412, identifier:is_read2; 413, identifier:r1_nts; 414, identifier:r2_nts; 415, attribute; 416, identifier:is_read2; 417, identifier:pr; 418, attribute; 419, identifier:stranded; 420, attribute; 421, argument_list; 422, attribute; 423, argument_list; 424, identifier:r1; 425, identifier:r2; 426, identifier:index; 427, list; 428, call; 429, identifier:sum; 430, keyword_argument; 431, identifier:singles; 432, string; 433, identifier:singles; 434, string; 435, identifier:doubles; 436, identifier:R1; 437, identifier:counts; 438, identifier:ix; 439, attribute; 440, argument_list; 441, identifier:vc; 442, identifier:index; 443, identifier:end; 444, integer:1; 445, string_content:{}:{}; 446, binary_operator:int(start) + 1; 447, binary_operator:int(end) + 1; 448, string_content:{}+; 449, string_content:{}-; 450, identifier:pr; 451, identifier:alignment; 452, identifier:pr; 453, identifier:alignment; 454, identifier:pc; 455, identifier:reference_pos; 456, identifier:qnames; 457, identifier:append; 458, attribute; 459, identifier:nts; 460, identifier:append; 461, identifier:nt; 462, string; 463, string; 464, attribute; 465, argument_list; 466, identifier:axis; 467, integer:1; 468, string_content:R1; 469, string_content:R2; 470, string; 471, identifier:format; 472, identifier:chrom; 473, identifier:pos; 474, call; 475, integer:1; 476, call; 477, integer:1; 478, attribute; 479, identifier:qname; 480, string_content:R1; 481, string_content:R2; 482, identifier:df; 483, identifier:isnull; 484, string_content:{}:{}; 485, identifier:int; 486, argument_list; 487, identifier:int; 488, argument_list; 489, identifier:pr; 490, identifier:alignment; 491, identifier:start; 492, identifier:end
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 4, 17; 4, 18; 4, 19; 7, 20; 7, 21; 8, 22; 13, 23; 13, 24; 14, 25; 14, 26; 14, 27; 15, 28; 16, 29; 16, 30; 17, 31; 18, 32; 18, 33; 18, 34; 18, 35; 18, 36; 19, 37; 23, 38; 23, 39; 24, 40; 25, 41; 25, 42; 26, 43; 26, 44; 26, 45; 26, 46; 26, 47; 26, 48; 27, 49; 27, 50; 28, 51; 28, 52; 30, 53; 31, 54; 31, 55; 36, 56; 36, 57; 36, 58; 36, 59; 36, 60; 36, 61; 36, 62; 36, 63; 36, 64; 36, 65; 36, 66; 36, 67; 36, 68; 36, 69; 36, 70; 36, 71; 36, 72; 38, 73; 38, 74; 40, 75; 41, 76; 41, 77; 43, 78; 44, 79; 44, 80; 44, 81; 45, 82; 46, 83; 47, 84; 48, 85; 49, 86; 49, 87; 50, 88; 50, 89; 50, 90; 52, 91; 52, 92; 52, 93; 52, 94; 52, 95; 53, 96; 55, 97; 55, 98; 56, 99; 57, 100; 58, 101; 59, 102; 60, 103; 61, 104; 61, 105; 61, 106; 62, 107; 63, 108; 64, 109; 65, 110; 66, 111; 67, 112; 68, 113; 69, 114; 70, 115; 71, 116; 72, 117; 72, 118; 72, 119; 74, 120; 75, 121; 75, 122; 77, 123; 78, 124; 78, 125; 79, 126; 79, 127; 80, 128; 81, 129; 81, 130; 82, 131; 82, 132; 83, 133; 83, 134; 84, 135; 84, 136; 85, 137; 85, 138; 86, 139; 86, 140; 87, 141; 88, 142; 89, 143; 90, 144; 91, 145; 92, 146; 93, 147; 94, 148; 95, 149; 96, 150; 96, 151; 97, 152; 97, 153; 98, 154; 98, 155; 98, 156; 99, 157; 99, 158; 100, 159; 100, 160; 101, 161; 101, 162; 102, 163; 102, 164; 103, 165; 103, 166; 105, 167; 105, 168; 106, 169; 106, 170; 106, 171; 106, 172; 107, 173; 107, 174; 108, 175; 108, 176; 109, 177; 109, 178; 110, 179; 110, 180; 111, 181; 111, 182; 112, 183; 112, 184; 113, 185; 113, 186; 114, 187; 114, 188; 115, 189; 115, 190; 116, 191; 116, 192; 119, 193; 122, 194; 122, 195; 125, 196; 125, 197; 126, 198; 126, 199; 128, 200; 129, 201; 129, 202; 130, 203; 132, 204; 132, 205; 134, 206; 134, 207; 136, 208; 136, 209; 138, 210; 138, 211; 140, 212; 141, 213; 141, 214; 142, 215; 142, 216; 143, 217; 143, 218; 144, 219; 144, 220; 151, 221; 151, 222; 155, 223; 155, 224; 156, 225; 156, 226; 158, 227; 158, 228; 169, 229; 170, 230; 171, 231; 172, 232; 172, 233; 174, 234; 174, 235; 176, 236; 176, 237; 178, 238; 178, 239; 180, 240; 180, 241; 182, 242; 182, 243; 185, 244; 185, 245; 186, 246; 187, 247; 187, 248; 188, 249; 190, 250; 190, 251; 191, 252; 191, 253; 192, 254; 193, 255; 194, 256; 194, 257; 195, 258; 195, 259; 197, 260; 199, 261; 200, 262; 200, 263; 201, 264; 201, 265; 203, 266; 205, 267; 207, 268; 208, 269; 208, 270; 209, 271; 209, 272; 210, 273; 210, 274; 211, 275; 211, 276; 215, 277; 215, 278; 215, 279; 218, 280; 218, 281; 220, 282; 220, 283; 221, 284; 221, 285; 222, 286; 222, 287; 227, 288; 227, 289; 229, 290; 229, 291; 230, 292; 230, 293; 231, 294; 231, 295; 233, 296; 233, 297; 234, 298; 234, 299; 235, 300; 235, 301; 236, 302; 236, 303; 237, 304; 237, 305; 238, 306; 238, 307; 241, 308; 241, 309; 242, 310; 242, 311; 246, 312; 246, 313; 249, 314; 249, 315; 251, 316; 251, 317; 254, 318; 254, 319; 255, 320; 255, 321; 259, 322; 262, 323; 262, 324; 262, 325; 265, 326; 266, 327; 266, 328; 269, 329; 269, 330; 270, 331; 270, 332; 272, 333; 272, 334; 275, 335; 275, 336; 276, 337; 276, 338; 280, 339; 280, 340; 281, 341; 281, 342; 282, 343; 282, 344; 283, 345; 283, 346; 283, 347; 283, 348; 284, 349; 284, 350; 285, 351; 285, 352; 286, 353; 286, 354; 287, 355; 287, 356; 291, 357; 291, 358; 293, 359; 293, 360; 295, 361; 295, 362; 296, 363; 297, 364; 301, 365; 301, 366; 305, 367; 305, 368; 306, 369; 306, 370; 307, 371; 307, 372; 308, 373; 308, 374; 312, 375; 312, 376; 314, 377; 314, 378; 316, 379; 316, 380; 317, 381; 317, 382; 318, 383; 318, 384; 320, 385; 320, 386; 320, 387; 327, 388; 327, 389; 327, 390; 327, 391; 329, 392; 334, 393; 334, 394; 339, 395; 339, 396; 340, 397; 340, 398; 342, 399; 342, 400; 348, 401; 348, 402; 349, 403; 349, 404; 350, 405; 353, 406; 353, 407; 354, 408; 357, 409; 357, 410; 358, 411; 358, 412; 359, 413; 359, 414; 360, 415; 360, 416; 362, 417; 362, 418; 362, 419; 363, 420; 363, 421; 364, 422; 364, 423; 371, 424; 371, 425; 372, 426; 372, 427; 373, 428; 373, 429; 374, 430; 375, 431; 375, 432; 377, 433; 377, 434; 383, 435; 383, 436; 385, 437; 385, 438; 386, 439; 386, 440; 387, 441; 387, 442; 394, 443; 394, 444; 395, 445; 400, 446; 400, 447; 403, 448; 406, 449; 411, 450; 411, 451; 415, 452; 415, 453; 418, 454; 418, 455; 420, 456; 420, 457; 421, 458; 422, 459; 422, 460; 423, 461; 427, 462; 427, 463; 428, 464; 428, 465; 430, 466; 430, 467; 432, 468; 434, 469; 439, 470; 439, 471; 440, 472; 440, 473; 446, 474; 446, 475; 447, 476; 447, 477; 458, 478; 458, 479; 462, 480; 463, 481; 464, 482; 464, 483; 470, 484; 474, 485; 474, 486; 476, 487; 476, 488; 478, 489; 478, 490; 486, 491; 488, 492
def get_region_nt_counts(region, bam, stranded=False): """ Get counts of each nucleotide from a bam file for a given region. If R1 and R2 reads both overlap a position, only one count will be added. If the R1 and R2 reads disagree at a position they both overlap, that read pair is not used for that position. Can optionally output strand-specific counts. Parameters ---------- region : str or list Region of type chrom:start-end, chrom:start-end:strand, or [chrom, start, end]. The strand is ignored for chrom:start-end:strand. For chrom:start-end, the coordinates are one-based inclusive. For example, the query chr1:10-11 will give you the counts for the 10th and 11th bases of chr1. For [chrom, start, end], the coordinates are zero-based and end exclusive (like a bed file). The query [chr1, 9, 11] will give you the coverage of the 10th and 11th bases of chr1. The region value is passed directly to pysam's pileup function. bam : pysam.calignmentfile.AlignmentFile or str Bam file opened with pysam or path to bam file (must be sorted and indexed). stranded : boolean Boolean indicating whether read data is stranded and stranded nucleotide counts should be returned. Assumes R1 read on reverse strand implies + strand coverage etc. Returns ------- counts : pandas.DataFrame Data frame with the counts for each base in the region. The index of this data frame is one-based for compatibility with VCF files. """ # TODO: I should figure out what the different possible values are that # pysam could give me back (so far I only have ATCGN). Can I get deletions # and insertions? # TODO: This could probably be parallelized. if type(bam) == str: bam = pysam.AlignmentFile(bam, 'rb') if type(region) is str: r = parse_region(region) if len(r) == 3: chrom, start, end = r elif len(r) == 4: chrom, start, end, strand = r start = int(start) end = int(end) ind = ['{}:{}'.format(chrom, x) for x in range(start, end + 1)] pp = bam.pileup(region=region, truncate=True) elif type(region) is (list or tuple): chrom, start, end = region ind = ['{}:{}'.format(chrom, x) for x in range(int(start) + 1, int(end) + 1)] pp = bam.pileup(chrom, start, end, truncate=True) cols = ['A', 'T', 'C', 'G', 'N'] if stranded: cols = ['{}+'.format(x) for x in cols] + ['{}-'.format(x) for x in cols] counts = pd.DataFrame(0, index=ind, columns=cols) for pc in pp: # Most of this code deals with R1 and R2 reads that overlap so that we # don't get two counts from one fragment. pos = pc.reference_pos + 1 r1_qnames = [] r1_nts = [] r2_qnames = [] r2_nts = [] for pr in pc.pileups: qnames = [r1_qnames, r2_qnames][pr.alignment.is_read2] nts = [r1_nts, r2_nts][pr.alignment.is_read2] nt = _pos_nt(pr, pc.reference_pos, stranded) if nt: qnames.append(pr.alignment.qname) nts.append(nt) r1 = pd.Series(r1_nts, index=r1_qnames) r2 = pd.Series(r2_nts, index=r2_qnames) df = pd.DataFrame([r1, r2], index=['R1', 'R2']).T singles = df[df.isnull().sum(axis=1) == 1] doubles = df.dropna() vcs = [] vcs.append(singles['R1'].value_counts()) vcs.append(singles['R2'].value_counts()) doubles = doubles[doubles.R1 == doubles.R2] vcs.append(doubles.R1.value_counts()) for vc in vcs: counts.ix['{}:{}'.format(chrom, pos), vc.index] += vc return counts
0, module; 1, function_definition; 2, function_name:nt_counts; 3, parameters; 4, block; 5, identifier:bam; 6, identifier:positions; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, expression_statement; 11, if_statement; 12, if_statement; 13, expression_statement; 14, for_statement; 15, expression_statement; 16, return_statement; 17, identifier:stranded; 18, False; 19, identifier:vcf; 20, False; 21, identifier:bed; 22, False; 23, comment:""" Find the number of nucleotides covered at all positions in a bed or vcf file. Parameters ---------- bam : str or pysam.calignmentfile.AlignmentFile Bam file opened with pysam or path to bam file (must be sorted and indexed). positions : str or pybedtools.BedTool Path to bed or vcf file or pybedtools.BedTool object. The extension is used to determine whether the file is a bed or vcf (.bed vs .vcf). stranded : boolean Boolean indicating whether read data is stranded and stranded nucleotide counts should be returned. Assumes R1 read on reverse strand implies + strand coverage etc. vcf : boolean Set to True if you are providing a vcf file that doesn't have a .vcf suffix. bed : boolean Set to True if you are providing a bed file that doesn't have a .bed suffix. Returns ------- counts : pandas.DataFrame Data frame with the counts for each base in the region. The index of this data frame is one-based for compatibility with VCF files. """; 24, boolean_operator; 25, block; 26, identifier:bed; 27, block; 28, elif_clause; 29, assignment; 30, identifier:i; 31, attribute; 32, block; 33, assignment; 34, identifier:res; 35, not_operator; 36, not_operator; 37, if_statement; 38, expression_statement; 39, identifier:vcf; 40, block; 41, identifier:res; 42, list; 43, identifier:df; 44, identifier:index; 45, expression_statement; 46, expression_statement; 47, identifier:res; 48, call; 49, identifier:bed; 50, identifier:vcf; 51, comparison_operator:type(positions) == pbt.bedtool.BedTool; 52, block; 53, elif_clause; 54, elif_clause; 55, else_clause; 56, assignment; 57, import_from_statement; 58, expression_statement; 59, expression_statement; 60, expression_statement; 61, expression_statement; 62, expression_statement; 63, assignment; 64, call; 65, attribute; 66, argument_list; 67, call; 68, attribute; 69, expression_statement; 70, comparison_operator:positions[-4:] == '.bed'; 71, block; 72, comparison_operator:positions[-4:] == '.vcf'; 73, block; 74, block; 75, identifier:df; 76, call; 77, dotted_name; 78, dotted_name; 79, assignment; 80, assignment; 81, assignment; 82, assignment; 83, assignment; 84, identifier:region; 85, list; 86, attribute; 87, argument_list; 88, identifier:pd; 89, identifier:concat; 90, identifier:res; 91, identifier:type; 92, argument_list; 93, attribute; 94, identifier:BedTool; 95, assignment; 96, subscript; 97, string; 98, expression_statement; 99, subscript; 100, string; 101, expression_statement; 102, expression_statement; 103, attribute; 104, argument_list; 105, identifier:variants; 106, identifier:vcf_as_df; 107, identifier:tdf; 108, call; 109, identifier:df; 110, call; 111, subscript; 112, attribute; 113, subscript; 114, binary_operator:tdf.POS - 1; 115, subscript; 116, attribute; 117, subscript; 118, subscript; 119, subscript; 120, identifier:res; 121, identifier:append; 122, call; 123, identifier:positions; 124, identifier:pbt; 125, identifier:bedtool; 126, identifier:df; 127, call; 128, identifier:positions; 129, slice; 130, string_content:.bed; 131, assignment; 132, identifier:positions; 133, slice; 134, string_content:.vcf; 135, assignment; 136, call; 137, call; 138, identifier:to_dataframe; 139, identifier:vcf_as_df; 140, argument_list; 141, attribute; 142, argument_list; 143, identifier:df; 144, string; 145, identifier:tdf; 146, identifier:CHROM; 147, identifier:df; 148, string; 149, attribute; 150, integer:1; 151, identifier:df; 152, string; 153, identifier:tdf; 154, identifier:POS; 155, attribute; 156, identifier:i; 157, string; 158, attribute; 159, identifier:i; 160, string; 161, attribute; 162, identifier:i; 163, string; 164, identifier:get_region_nt_counts; 165, argument_list; 166, attribute; 167, argument_list; 168, unary_operator; 169, identifier:bed; 170, True; 171, unary_operator; 172, identifier:vcf; 173, True; 174, attribute; 175, argument_list; 176, attribute; 177, argument_list; 178, identifier:positions; 179, identifier:pd; 180, identifier:DataFrame; 181, keyword_argument; 182, string_content:chrom; 183, string_content:start; 184, identifier:tdf; 185, identifier:POS; 186, string_content:end; 187, identifier:df; 188, identifier:ix; 189, string_content:chrom; 190, identifier:df; 191, identifier:ix; 192, string_content:start; 193, identifier:df; 194, identifier:ix; 195, string_content:end; 196, identifier:region; 197, identifier:bam; 198, identifier:stranded; 199, identifier:positions; 200, identifier:to_dataframe; 201, integer:4; 202, integer:4; 203, attribute; 204, identifier:write; 205, concatenated_string; 206, identifier:pbt; 207, identifier:BedTool; 208, identifier:positions; 209, identifier:index; 210, attribute; 211, identifier:sys; 212, identifier:stderr; 213, string; 214, string; 215, identifier:tdf; 216, identifier:index; 217, string_content:Positions must be BedTool, bed file, or vcf; 218, string_content; 219, escape_sequence:\n
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 7, 17; 7, 18; 8, 19; 8, 20; 9, 21; 9, 22; 10, 23; 11, 24; 11, 25; 12, 26; 12, 27; 12, 28; 13, 29; 14, 30; 14, 31; 14, 32; 15, 33; 16, 34; 24, 35; 24, 36; 25, 37; 27, 38; 28, 39; 28, 40; 29, 41; 29, 42; 31, 43; 31, 44; 32, 45; 32, 46; 33, 47; 33, 48; 35, 49; 36, 50; 37, 51; 37, 52; 37, 53; 37, 54; 37, 55; 38, 56; 40, 57; 40, 58; 40, 59; 40, 60; 40, 61; 40, 62; 45, 63; 46, 64; 48, 65; 48, 66; 51, 67; 51, 68; 52, 69; 53, 70; 53, 71; 54, 72; 54, 73; 55, 74; 56, 75; 56, 76; 57, 77; 57, 78; 58, 79; 59, 80; 60, 81; 61, 82; 62, 83; 63, 84; 63, 85; 64, 86; 64, 87; 65, 88; 65, 89; 66, 90; 67, 91; 67, 92; 68, 93; 68, 94; 69, 95; 70, 96; 70, 97; 71, 98; 72, 99; 72, 100; 73, 101; 74, 102; 76, 103; 76, 104; 77, 105; 78, 106; 79, 107; 79, 108; 80, 109; 80, 110; 81, 111; 81, 112; 82, 113; 82, 114; 83, 115; 83, 116; 85, 117; 85, 118; 85, 119; 86, 120; 86, 121; 87, 122; 92, 123; 93, 124; 93, 125; 95, 126; 95, 127; 96, 128; 96, 129; 97, 130; 98, 131; 99, 132; 99, 133; 100, 134; 101, 135; 102, 136; 103, 137; 103, 138; 108, 139; 108, 140; 110, 141; 110, 142; 111, 143; 111, 144; 112, 145; 112, 146; 113, 147; 113, 148; 114, 149; 114, 150; 115, 151; 115, 152; 116, 153; 116, 154; 117, 155; 117, 156; 117, 157; 118, 158; 118, 159; 118, 160; 119, 161; 119, 162; 119, 163; 122, 164; 122, 165; 127, 166; 127, 167; 129, 168; 131, 169; 131, 170; 133, 171; 135, 172; 135, 173; 136, 174; 136, 175; 137, 176; 137, 177; 140, 178; 141, 179; 141, 180; 142, 181; 144, 182; 148, 183; 149, 184; 149, 185; 152, 186; 155, 187; 155, 188; 157, 189; 158, 190; 158, 191; 160, 192; 161, 193; 161, 194; 163, 195; 165, 196; 165, 197; 165, 198; 166, 199; 166, 200; 168, 201; 171, 202; 174, 203; 174, 204; 175, 205; 176, 206; 176, 207; 177, 208; 181, 209; 181, 210; 203, 211; 203, 212; 205, 213; 205, 214; 210, 215; 210, 216; 213, 217; 214, 218; 218, 219
def nt_counts(bam, positions, stranded=False, vcf=False, bed=False): """ Find the number of nucleotides covered at all positions in a bed or vcf file. Parameters ---------- bam : str or pysam.calignmentfile.AlignmentFile Bam file opened with pysam or path to bam file (must be sorted and indexed). positions : str or pybedtools.BedTool Path to bed or vcf file or pybedtools.BedTool object. The extension is used to determine whether the file is a bed or vcf (.bed vs .vcf). stranded : boolean Boolean indicating whether read data is stranded and stranded nucleotide counts should be returned. Assumes R1 read on reverse strand implies + strand coverage etc. vcf : boolean Set to True if you are providing a vcf file that doesn't have a .vcf suffix. bed : boolean Set to True if you are providing a bed file that doesn't have a .bed suffix. Returns ------- counts : pandas.DataFrame Data frame with the counts for each base in the region. The index of this data frame is one-based for compatibility with VCF files. """ if not bed and not vcf: if type(positions) == pbt.bedtool.BedTool: df = positions.to_dataframe() elif positions[-4:] == '.bed': bed = True elif positions[-4:] == '.vcf': vcf = True else: sys.stderr.write('Positions must be BedTool, bed file, or vcf ' 'file.\n') if bed: df = pbt.BedTool(positions).to_dataframe() elif vcf: from variants import vcf_as_df tdf = vcf_as_df(positions) df = pd.DataFrame(index=tdf.index) df['chrom'] = tdf.CHROM df['start'] = tdf.POS - 1 df['end'] = tdf.POS res = [] for i in df.index: region = [df.ix[i, 'chrom'], df.ix[i, 'start'], df.ix[i, 'end']] res.append(get_region_nt_counts(region, bam, stranded)) res = pd.concat(res) return res
0, module; 1, function_definition; 2, function_name:add_host; 3, parameters; 4, block; 5, identifier:self; 6, identifier:host; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, comment:# Add in ansible's magic variables. Assign them here because this is; 13, comment:# just about the earliest point we can calculate them before anything; 14, comment:# ansible-related (e.g. Stack.configure(), ``bang --host``) executes.; 15, expression_statement; 16, expression_statement; 17, expression_statement; 18, expression_statement; 19, expression_statement; 20, for_statement; 21, identifier:group_names; 22, None; 23, identifier:host_vars; 24, None; 25, comment:""" Used by deployers to add hosts to the inventory. :param str host: The host identifier (e.g. hostname, IP address) to use in the inventory. :param list group_names: A list of group names to which the host belongs. **Note: This list will be sorted in-place.** :param dict host_vars: A mapping object of host *variables*. This can be a nested structure, and is used as the source of all the variables provided to the ansible playbooks. **Note: Additional key-value pairs (e.g. dynamic ansible values like ``inventory_hostname``) will be inserted into this mapping object.** """; 26, assignment; 27, assignment; 28, call; 29, assignment; 30, assignment; 31, assignment; 32, call; 33, identifier:gname; 34, identifier:group_names; 35, block; 36, identifier:gnames; 37, conditional_expression:group_names if group_names else []; 38, identifier:hvars; 39, conditional_expression:host_vars if host_vars else {}; 40, attribute; 41, argument_list; 42, subscript; 43, identifier:gnames; 44, subscript; 45, identifier:host; 46, subscript; 47, subscript; 48, attribute; 49, argument_list; 50, expression_statement; 51, identifier:group_names; 52, identifier:group_names; 53, list; 54, identifier:host_vars; 55, identifier:host_vars; 56, dictionary; 57, identifier:gnames; 58, identifier:sort; 59, identifier:hvars; 60, attribute; 61, identifier:hvars; 62, attribute; 63, identifier:hvars; 64, attribute; 65, call; 66, integer:0; 67, attribute; 68, identifier:merge; 69, identifier:host; 70, identifier:hvars; 71, call; 72, attribute; 73, identifier:GROUP_NAMES; 74, attribute; 75, identifier:INV_NAME; 76, attribute; 77, identifier:INV_NAME_SHORT; 78, attribute; 79, argument_list; 80, identifier:self; 81, identifier:groups_and_vars; 82, attribute; 83, argument_list; 84, identifier:A; 85, identifier:server; 86, identifier:A; 87, identifier:server; 88, identifier:A; 89, identifier:server; 90, identifier:host; 91, identifier:split; 92, string; 93, attribute; 94, identifier:append; 95, identifier:gname; 96, identifier:host; 97, string_content:.; 98, identifier:self; 99, identifier:groups_and_vars
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 4, 17; 4, 18; 4, 19; 4, 20; 7, 21; 7, 22; 8, 23; 8, 24; 9, 25; 10, 26; 11, 27; 15, 28; 16, 29; 17, 30; 18, 31; 19, 32; 20, 33; 20, 34; 20, 35; 26, 36; 26, 37; 27, 38; 27, 39; 28, 40; 28, 41; 29, 42; 29, 43; 30, 44; 30, 45; 31, 46; 31, 47; 32, 48; 32, 49; 35, 50; 37, 51; 37, 52; 37, 53; 39, 54; 39, 55; 39, 56; 40, 57; 40, 58; 42, 59; 42, 60; 44, 61; 44, 62; 46, 63; 46, 64; 47, 65; 47, 66; 48, 67; 48, 68; 49, 69; 49, 70; 50, 71; 60, 72; 60, 73; 62, 74; 62, 75; 64, 76; 64, 77; 65, 78; 65, 79; 67, 80; 67, 81; 71, 82; 71, 83; 72, 84; 72, 85; 74, 86; 74, 87; 76, 88; 76, 89; 78, 90; 78, 91; 79, 92; 82, 93; 82, 94; 83, 95; 83, 96; 92, 97; 93, 98; 93, 99
def add_host(self, host, group_names=None, host_vars=None): """ Used by deployers to add hosts to the inventory. :param str host: The host identifier (e.g. hostname, IP address) to use in the inventory. :param list group_names: A list of group names to which the host belongs. **Note: This list will be sorted in-place.** :param dict host_vars: A mapping object of host *variables*. This can be a nested structure, and is used as the source of all the variables provided to the ansible playbooks. **Note: Additional key-value pairs (e.g. dynamic ansible values like ``inventory_hostname``) will be inserted into this mapping object.** """ gnames = group_names if group_names else [] hvars = host_vars if host_vars else {} # Add in ansible's magic variables. Assign them here because this is # just about the earliest point we can calculate them before anything # ansible-related (e.g. Stack.configure(), ``bang --host``) executes. gnames.sort() hvars[A.server.GROUP_NAMES] = gnames hvars[A.server.INV_NAME] = host hvars[A.server.INV_NAME_SHORT] = host.split('.')[0] self.groups_and_vars.merge(host, hvars) for gname in group_names: self.groups_and_vars.append(gname, host)
0, module; 1, function_definition; 2, function_name:beds_to_boolean; 3, parameters; 4, block; 5, identifier:beds; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, dictionary_splat_pattern; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, for_statement; 14, expression_statement; 15, if_statement; 16, expression_statement; 17, for_statement; 18, expression_statement; 19, for_statement; 20, return_statement; 21, identifier:ref; 22, None; 23, identifier:beds_sorted; 24, False; 25, identifier:ref_sorted; 26, False; 27, identifier:kwargs; 28, comment:""" Compare a list of bed files or BedTool objects to a reference bed file and create a boolean matrix where each row is an interval and each column is a 1 if that file has an interval that overlaps the row interval and a 0 otherwise. If no reference bed is provided, the provided bed files will be merged into a single bed and compared to that. Parameters ---------- beds : list List of paths to bed files or BedTool objects. ref : str or BedTool Reference bed file to compare against. If no reference bed is provided, the provided bed files will be merged into a single bed and compared to that. beds_sorted : boolean Whether the bed files in beds are already sorted. If False, all bed files in beds will be sorted. ref_sorted : boolean Whether the reference bed file is sorted. If False, ref will be sorted. names : list of strings Names to use for columns of output files. Overrides define_sample_name if provided. define_sample_name : function that takes string as input Function mapping filename to sample name (or basename). For instance, you may have the basename in the path and use a regex to extract it. The basenames will be used as the column names. If this is not provided, the columns will be named as the input files. Returns ------- out : pandas.DataFrame Boolean data frame indicating whether each bed file has an interval that overlaps each interval in the reference bed file. """; 29, assignment; 30, assignment; 31, pattern_list; 32, call; 33, block; 34, assignment; 35, identifier:ref; 36, block; 37, else_clause; 38, assignment; 39, identifier:r; 40, identifier:ref; 41, block; 42, assignment; 43, pattern_list; 44, call; 45, block; 46, identifier:bdf; 47, identifier:beds; 48, call; 49, identifier:fns; 50, list; 51, identifier:i; 52, identifier:v; 53, identifier:enumerate; 54, argument_list; 55, if_statement; 56, if_statement; 57, identifier:names; 58, call; 59, if_statement; 60, if_statement; 61, block; 62, identifier:ind; 63, list; 64, expression_statement; 65, identifier:bdf; 66, call; 67, identifier:i; 68, identifier:bed; 69, identifier:enumerate; 70, argument_list; 71, expression_statement; 72, expression_statement; 73, for_statement; 74, expression_statement; 75, attribute; 76, argument_list; 77, identifier:beds; 78, comparison_operator:type(v) == str; 79, block; 80, else_clause; 81, not_operator; 82, block; 83, identifier:_sample_names; 84, argument_list; 85, comparison_operator:type(ref) == str; 86, block; 87, not_operator; 88, block; 89, expression_statement; 90, call; 91, attribute; 92, argument_list; 93, identifier:beds; 94, assignment; 95, assignment; 96, identifier:r; 97, identifier:res; 98, block; 99, assignment; 100, identifier:copy; 101, identifier:deepcopy; 102, identifier:beds; 103, call; 104, identifier:str; 105, expression_statement; 106, expression_statement; 107, block; 108, identifier:beds_sorted; 109, expression_statement; 110, identifier:fns; 111, identifier:kwargs; 112, call; 113, identifier:str; 114, expression_statement; 115, identifier:ref_sorted; 116, expression_statement; 117, assignment; 118, attribute; 119, argument_list; 120, identifier:pd; 121, identifier:DataFrame; 122, integer:0; 123, keyword_argument; 124, keyword_argument; 125, identifier:res; 126, call; 127, identifier:ind; 128, list; 129, expression_statement; 130, subscript; 131, integer:1; 132, identifier:type; 133, argument_list; 134, call; 135, assignment; 136, expression_statement; 137, assignment; 138, identifier:type; 139, argument_list; 140, assignment; 141, assignment; 142, identifier:ref; 143, call; 144, identifier:ind; 145, identifier:append; 146, call; 147, identifier:index; 148, identifier:ind; 149, identifier:columns; 150, identifier:names; 151, attribute; 152, argument_list; 153, call; 154, attribute; 155, identifier:ind; 156, subscript; 157, identifier:v; 158, attribute; 159, argument_list; 160, subscript; 161, call; 162, call; 163, subscript; 164, call; 165, identifier:ref; 166, identifier:ref; 167, call; 168, identifier:ref; 169, call; 170, identifier:combine; 171, argument_list; 172, attribute; 173, argument_list; 174, identifier:ref; 175, identifier:intersect; 176, identifier:bed; 177, keyword_argument; 178, keyword_argument; 179, attribute; 180, argument_list; 181, identifier:bdf; 182, identifier:ix; 183, identifier:names; 184, identifier:i; 185, identifier:fns; 186, identifier:append; 187, identifier:v; 188, identifier:beds; 189, identifier:i; 190, attribute; 191, argument_list; 192, attribute; 193, argument_list; 194, identifier:beds; 195, identifier:i; 196, attribute; 197, argument_list; 198, attribute; 199, argument_list; 200, attribute; 201, argument_list; 202, identifier:beds; 203, string; 204, identifier:format; 205, attribute; 206, attribute; 207, attribute; 208, identifier:sorted; 209, True; 210, identifier:wa; 211, True; 212, identifier:ind; 213, identifier:append; 214, call; 215, identifier:pbt; 216, identifier:BedTool; 217, identifier:v; 218, identifier:fns; 219, identifier:append; 220, attribute; 221, subscript; 222, identifier:sort; 223, identifier:pbt; 224, identifier:BedTool; 225, identifier:ref; 226, identifier:ref; 227, identifier:sort; 228, string_content:{}:{}-{}; 229, identifier:r; 230, identifier:chrom; 231, identifier:r; 232, identifier:start; 233, identifier:r; 234, identifier:stop; 235, attribute; 236, argument_list; 237, identifier:v; 238, identifier:fn; 239, identifier:beds; 240, identifier:i; 241, string; 242, identifier:format; 243, attribute; 244, attribute; 245, attribute; 246, string_content:{}:{}-{}; 247, identifier:r; 248, identifier:chrom; 249, identifier:r; 250, identifier:start; 251, identifier:r; 252, identifier:stop
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 4, 17; 4, 18; 4, 19; 4, 20; 6, 21; 6, 22; 7, 23; 7, 24; 8, 25; 8, 26; 9, 27; 10, 28; 11, 29; 12, 30; 13, 31; 13, 32; 13, 33; 14, 34; 15, 35; 15, 36; 15, 37; 16, 38; 17, 39; 17, 40; 17, 41; 18, 42; 19, 43; 19, 44; 19, 45; 20, 46; 29, 47; 29, 48; 30, 49; 30, 50; 31, 51; 31, 52; 32, 53; 32, 54; 33, 55; 33, 56; 34, 57; 34, 58; 36, 59; 36, 60; 37, 61; 38, 62; 38, 63; 41, 64; 42, 65; 42, 66; 43, 67; 43, 68; 44, 69; 44, 70; 45, 71; 45, 72; 45, 73; 45, 74; 48, 75; 48, 76; 54, 77; 55, 78; 55, 79; 55, 80; 56, 81; 56, 82; 58, 83; 58, 84; 59, 85; 59, 86; 60, 87; 60, 88; 61, 89; 64, 90; 66, 91; 66, 92; 70, 93; 71, 94; 72, 95; 73, 96; 73, 97; 73, 98; 74, 99; 75, 100; 75, 101; 76, 102; 78, 103; 78, 104; 79, 105; 79, 106; 80, 107; 81, 108; 82, 109; 84, 110; 84, 111; 85, 112; 85, 113; 86, 114; 87, 115; 88, 116; 89, 117; 90, 118; 90, 119; 91, 120; 91, 121; 92, 122; 92, 123; 92, 124; 94, 125; 94, 126; 95, 127; 95, 128; 98, 129; 99, 130; 99, 131; 103, 132; 103, 133; 105, 134; 106, 135; 107, 136; 109, 137; 112, 138; 112, 139; 114, 140; 116, 141; 117, 142; 117, 143; 118, 144; 118, 145; 119, 146; 123, 147; 123, 148; 124, 149; 124, 150; 126, 151; 126, 152; 129, 153; 130, 154; 130, 155; 130, 156; 133, 157; 134, 158; 134, 159; 135, 160; 135, 161; 136, 162; 137, 163; 137, 164; 139, 165; 140, 166; 140, 167; 141, 168; 141, 169; 143, 170; 143, 171; 146, 172; 146, 173; 151, 174; 151, 175; 152, 176; 152, 177; 152, 178; 153, 179; 153, 180; 154, 181; 154, 182; 156, 183; 156, 184; 158, 185; 158, 186; 159, 187; 160, 188; 160, 189; 161, 190; 161, 191; 162, 192; 162, 193; 163, 194; 163, 195; 164, 196; 164, 197; 167, 198; 167, 199; 169, 200; 169, 201; 171, 202; 172, 203; 172, 204; 173, 205; 173, 206; 173, 207; 177, 208; 177, 209; 178, 210; 178, 211; 179, 212; 179, 213; 180, 214; 190, 215; 190, 216; 191, 217; 192, 218; 192, 219; 193, 220; 196, 221; 196, 222; 198, 223; 198, 224; 199, 225; 200, 226; 200, 227; 203, 228; 205, 229; 205, 230; 206, 231; 206, 232; 207, 233; 207, 234; 214, 235; 214, 236; 220, 237; 220, 238; 221, 239; 221, 240; 235, 241; 235, 242; 236, 243; 236, 244; 236, 245; 241, 246; 243, 247; 243, 248; 244, 249; 244, 250; 245, 251; 245, 252
def beds_to_boolean(beds, ref=None, beds_sorted=False, ref_sorted=False, **kwargs): """ Compare a list of bed files or BedTool objects to a reference bed file and create a boolean matrix where each row is an interval and each column is a 1 if that file has an interval that overlaps the row interval and a 0 otherwise. If no reference bed is provided, the provided bed files will be merged into a single bed and compared to that. Parameters ---------- beds : list List of paths to bed files or BedTool objects. ref : str or BedTool Reference bed file to compare against. If no reference bed is provided, the provided bed files will be merged into a single bed and compared to that. beds_sorted : boolean Whether the bed files in beds are already sorted. If False, all bed files in beds will be sorted. ref_sorted : boolean Whether the reference bed file is sorted. If False, ref will be sorted. names : list of strings Names to use for columns of output files. Overrides define_sample_name if provided. define_sample_name : function that takes string as input Function mapping filename to sample name (or basename). For instance, you may have the basename in the path and use a regex to extract it. The basenames will be used as the column names. If this is not provided, the columns will be named as the input files. Returns ------- out : pandas.DataFrame Boolean data frame indicating whether each bed file has an interval that overlaps each interval in the reference bed file. """ beds = copy.deepcopy(beds) fns = [] for i,v in enumerate(beds): if type(v) == str: fns.append(v) beds[i] = pbt.BedTool(v) else: fns.append(v.fn) if not beds_sorted: beds[i] = beds[i].sort() names = _sample_names(fns, kwargs) if ref: if type(ref) == str: ref = pbt.BedTool(ref) if not ref_sorted: ref = ref.sort() else: ref = combine(beds) ind = [] for r in ref: ind.append('{}:{}-{}'.format(r.chrom, r.start, r.stop)) bdf = pd.DataFrame(0, index=ind, columns=names) for i,bed in enumerate(beds): res = ref.intersect(bed, sorted=True, wa=True) ind = [] for r in res: ind.append('{}:{}-{}'.format(r.chrom, r.start, r.stop)) bdf.ix[ind, names[i]] = 1 return bdf
0, module; 1, function_definition; 2, function_name:combine; 3, parameters; 4, block; 5, identifier:beds; 6, default_parameter; 7, default_parameter; 8, expression_statement; 9, expression_statement; 10, for_statement; 11, comment:# For some reason, doing the merging in the reduce statement doesn't work. I; 12, comment:# think this might be a pybedtools bug. In any fashion, I can merge; 13, comment:# afterward although I think it makes a performance hit because the combined; 14, comment:# bed file grows larger than it needs to.; 15, expression_statement; 16, expression_statement; 17, if_statement; 18, return_statement; 19, identifier:beds_sorted; 20, False; 21, identifier:postmerge; 22, True; 23, comment:""" Combine a list of bed files or BedTool objects into a single BedTool object. Parameters ---------- beds : list List of paths to bed files or BedTool objects. beds_sorted : boolean Whether the bed files in beds are already sorted. If False, all bed files in beds will be sorted. postmerge : boolean Whether to merge intervals after combining beds together. Returns ------- out : pybedtools.BedTool New sorted BedTool with intervals from all input beds. """; 24, assignment; 25, pattern_list; 26, call; 27, block; 28, assignment; 29, assignment; 30, identifier:postmerge; 31, block; 32, identifier:out; 33, identifier:beds; 34, call; 35, identifier:i; 36, identifier:v; 37, identifier:enumerate; 38, argument_list; 39, if_statement; 40, if_statement; 41, identifier:out; 42, call; 43, identifier:out; 44, call; 45, expression_statement; 46, attribute; 47, argument_list; 48, identifier:beds; 49, comparison_operator:type(v) == str; 50, block; 51, not_operator; 52, block; 53, identifier:reduce; 54, argument_list; 55, attribute; 56, argument_list; 57, assignment; 58, identifier:copy; 59, identifier:deepcopy; 60, identifier:beds; 61, call; 62, identifier:str; 63, expression_statement; 64, identifier:beds_sorted; 65, expression_statement; 66, lambda; 67, identifier:beds; 68, identifier:out; 69, identifier:sort; 70, identifier:out; 71, call; 72, identifier:type; 73, argument_list; 74, assignment; 75, assignment; 76, lambda_parameters; 77, call; 78, attribute; 79, argument_list; 80, identifier:v; 81, subscript; 82, call; 83, subscript; 84, call; 85, identifier:x; 86, identifier:y; 87, attribute; 88, argument_list; 89, identifier:out; 90, identifier:merge; 91, identifier:beds; 92, identifier:i; 93, attribute; 94, argument_list; 95, identifier:beds; 96, identifier:i; 97, attribute; 98, argument_list; 99, identifier:x; 100, identifier:cat; 101, identifier:y; 102, keyword_argument; 103, identifier:pbt; 104, identifier:BedTool; 105, identifier:v; 106, subscript; 107, identifier:sort; 108, identifier:postmerge; 109, False; 110, identifier:beds; 111, identifier:i
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 4, 17; 4, 18; 6, 19; 6, 20; 7, 21; 7, 22; 8, 23; 9, 24; 10, 25; 10, 26; 10, 27; 15, 28; 16, 29; 17, 30; 17, 31; 18, 32; 24, 33; 24, 34; 25, 35; 25, 36; 26, 37; 26, 38; 27, 39; 27, 40; 28, 41; 28, 42; 29, 43; 29, 44; 31, 45; 34, 46; 34, 47; 38, 48; 39, 49; 39, 50; 40, 51; 40, 52; 42, 53; 42, 54; 44, 55; 44, 56; 45, 57; 46, 58; 46, 59; 47, 60; 49, 61; 49, 62; 50, 63; 51, 64; 52, 65; 54, 66; 54, 67; 55, 68; 55, 69; 57, 70; 57, 71; 61, 72; 61, 73; 63, 74; 65, 75; 66, 76; 66, 77; 71, 78; 71, 79; 73, 80; 74, 81; 74, 82; 75, 83; 75, 84; 76, 85; 76, 86; 77, 87; 77, 88; 78, 89; 78, 90; 81, 91; 81, 92; 82, 93; 82, 94; 83, 95; 83, 96; 84, 97; 84, 98; 87, 99; 87, 100; 88, 101; 88, 102; 93, 103; 93, 104; 94, 105; 97, 106; 97, 107; 102, 108; 102, 109; 106, 110; 106, 111
def combine(beds, beds_sorted=False, postmerge=True): """ Combine a list of bed files or BedTool objects into a single BedTool object. Parameters ---------- beds : list List of paths to bed files or BedTool objects. beds_sorted : boolean Whether the bed files in beds are already sorted. If False, all bed files in beds will be sorted. postmerge : boolean Whether to merge intervals after combining beds together. Returns ------- out : pybedtools.BedTool New sorted BedTool with intervals from all input beds. """ beds = copy.deepcopy(beds) for i,v in enumerate(beds): if type(v) == str: beds[i] = pbt.BedTool(v) if not beds_sorted: beds[i] = beds[i].sort() # For some reason, doing the merging in the reduce statement doesn't work. I # think this might be a pybedtools bug. In any fashion, I can merge # afterward although I think it makes a performance hit because the combined # bed file grows larger than it needs to. out = reduce(lambda x,y : x.cat(y, postmerge=False), beds) out = out.sort() if postmerge: out = out.merge() return out
0, module; 1, function_definition; 2, function_name:sanitize_config_loglevel; 3, parameters; 4, block; 5, identifier:level; 6, expression_statement; 7, if_statement; 8, expression_statement; 9, if_statement; 10, if_statement; 11, return_statement; 12, string; 13, boolean_operator; 14, block; 15, assignment; 16, call; 17, block; 18, not_operator; 19, block; 20, identifier:lvl; 21, string_content:Kinda sorta backport of loglevel sanitization for Python 2.6.; 22, comparison_operator:sys.version_info[:2] != (2, 6); 23, call; 24, return_statement; 25, identifier:lvl; 26, None; 27, identifier:isinstance; 28, argument_list; 29, expression_statement; 30, identifier:lvl; 31, raise_statement; 32, subscript; 33, tuple; 34, identifier:isinstance; 35, argument_list; 36, identifier:level; 37, identifier:level; 38, identifier:basestring; 39, assignment; 40, call; 41, attribute; 42, slice; 43, integer:2; 44, integer:6; 45, identifier:level; 46, tuple; 47, identifier:lvl; 48, call; 49, identifier:ValueError; 50, argument_list; 51, identifier:sys; 52, identifier:version_info; 53, integer:2; 54, identifier:int; 55, identifier:long; 56, attribute; 57, argument_list; 58, binary_operator:'Invalid log level, %s' % level; 59, attribute; 60, identifier:get; 61, identifier:level; 62, string; 63, identifier:level; 64, identifier:logging; 65, identifier:_levelNames; 66, string_content:Invalid log level, %s
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 6, 12; 7, 13; 7, 14; 8, 15; 9, 16; 9, 17; 10, 18; 10, 19; 11, 20; 12, 21; 13, 22; 13, 23; 14, 24; 15, 25; 15, 26; 16, 27; 16, 28; 17, 29; 18, 30; 19, 31; 22, 32; 22, 33; 23, 34; 23, 35; 24, 36; 28, 37; 28, 38; 29, 39; 31, 40; 32, 41; 32, 42; 33, 43; 33, 44; 35, 45; 35, 46; 39, 47; 39, 48; 40, 49; 40, 50; 41, 51; 41, 52; 42, 53; 46, 54; 46, 55; 48, 56; 48, 57; 50, 58; 56, 59; 56, 60; 57, 61; 58, 62; 58, 63; 59, 64; 59, 65; 62, 66
def sanitize_config_loglevel(level): ''' Kinda sorta backport of loglevel sanitization for Python 2.6. ''' if sys.version_info[:2] != (2, 6) or isinstance(level, (int, long)): return level lvl = None if isinstance(level, basestring): lvl = logging._levelNames.get(level) if not lvl: raise ValueError('Invalid log level, %s' % level) return lvl
0, module; 1, function_definition; 2, function_name:prt_js; 3, parameters; 4, block; 5, identifier:js; 6, default_parameter; 7, default_parameter; 8, expression_statement; 9, expression_statement; 10, identifier:sort_keys; 11, True; 12, identifier:indent; 13, integer:4; 14, comment:"""Print Json in pretty format. There's a standard module pprint, can pretty print python dict and list. But it doesn't support sorted key. That why we need this func. Usage:: >>> from weatherlab.lib.dataIO.js import prt_js >>> prt_js({"a": 1, "b": 2}) { "a": 1, "b": 2 } **中文文档** 以人类可读的方式打印可Json化的Python对象。 """; 15, call; 16, identifier:print; 17, argument_list; 18, call; 19, identifier:js2str; 20, argument_list; 21, identifier:js; 22, identifier:sort_keys; 23, identifier:indent
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 6, 10; 6, 11; 7, 12; 7, 13; 8, 14; 9, 15; 15, 16; 15, 17; 17, 18; 18, 19; 18, 20; 20, 21; 20, 22; 20, 23
def prt_js(js, sort_keys=True, indent=4): """Print Json in pretty format. There's a standard module pprint, can pretty print python dict and list. But it doesn't support sorted key. That why we need this func. Usage:: >>> from weatherlab.lib.dataIO.js import prt_js >>> prt_js({"a": 1, "b": 2}) { "a": 1, "b": 2 } **中文文档** 以人类可读的方式打印可Json化的Python对象。 """ print(js2str(js, sort_keys, indent))
0, module; 1, function_definition; 2, function_name:find_field_names; 3, parameters; 4, block; 5, identifier:fields; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, expression_statement; 14, expression_statement; 15, for_statement; 16, return_statement; 17, identifier:model; 18, identifier:DEFAULT_MODEL; 19, identifier:app; 20, identifier:DEFAULT_APP; 21, identifier:score_cutoff; 22, integer:50; 23, identifier:pad_with_none; 24, False; 25, comment:"""Use fuzzy string matching to find similar model field names without consulting a synonyms list Returns: list: A list model field names (strings) sorted from most likely to least likely. [] If no similar field names could be found in the indicated model [None] If none found and and `pad_with_none` set Examples: >>> find_field_names(['date_time', 'title_prefix', 'sales'], model='WikiItem') ['date', 'model', 'net_sales'] """; 26, assignment; 27, assignment; 28, assignment; 29, assignment; 30, identifier:field_name; 31, identifier:fields; 32, block; 33, identifier:matched_fields; 34, identifier:fields; 35, call; 36, identifier:model; 37, call; 38, identifier:available_field_names; 39, call; 40, identifier:matched_fields; 41, list; 42, expression_statement; 43, if_statement; 44, attribute; 45, argument_list; 46, identifier:get_model; 47, argument_list; 48, attribute; 49, argument_list; 50, assignment; 51, boolean_operator; 52, block; 53, elif_clause; 54, identifier:util; 55, identifier:listify; 56, identifier:fields; 57, identifier:model; 58, identifier:app; 59, attribute; 60, identifier:get_all_field_names; 61, identifier:match; 62, call; 63, boolean_operator; 64, comparison_operator:match[1] >= score_cutoff; 65, expression_statement; 66, identifier:pad_with_none; 67, block; 68, identifier:model; 69, identifier:_meta; 70, attribute; 71, argument_list; 72, identifier:match; 73, comparison_operator:match[1] is not None; 74, subscript; 75, identifier:score_cutoff; 76, augmented_assignment; 77, expression_statement; 78, identifier:fuzzy; 79, identifier:extractOne; 80, call; 81, identifier:available_field_names; 82, subscript; 83, None; 84, identifier:match; 85, integer:1; 86, identifier:matched_fields; 87, list; 88, augmented_assignment; 89, identifier:str; 90, argument_list; 91, identifier:match; 92, integer:1; 93, subscript; 94, identifier:matched_fields; 95, list; 96, identifier:field_name; 97, identifier:match; 98, integer:0; 99, None
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 6, 17; 6, 18; 7, 19; 7, 20; 8, 21; 8, 22; 9, 23; 9, 24; 10, 25; 11, 26; 12, 27; 13, 28; 14, 29; 15, 30; 15, 31; 15, 32; 16, 33; 26, 34; 26, 35; 27, 36; 27, 37; 28, 38; 28, 39; 29, 40; 29, 41; 32, 42; 32, 43; 35, 44; 35, 45; 37, 46; 37, 47; 39, 48; 39, 49; 42, 50; 43, 51; 43, 52; 43, 53; 44, 54; 44, 55; 45, 56; 47, 57; 47, 58; 48, 59; 48, 60; 50, 61; 50, 62; 51, 63; 51, 64; 52, 65; 53, 66; 53, 67; 59, 68; 59, 69; 62, 70; 62, 71; 63, 72; 63, 73; 64, 74; 64, 75; 65, 76; 67, 77; 70, 78; 70, 79; 71, 80; 71, 81; 73, 82; 73, 83; 74, 84; 74, 85; 76, 86; 76, 87; 77, 88; 80, 89; 80, 90; 82, 91; 82, 92; 87, 93; 88, 94; 88, 95; 90, 96; 93, 97; 93, 98; 95, 99
def find_field_names(fields, model=DEFAULT_MODEL, app=DEFAULT_APP, score_cutoff=50, pad_with_none=False): """Use fuzzy string matching to find similar model field names without consulting a synonyms list Returns: list: A list model field names (strings) sorted from most likely to least likely. [] If no similar field names could be found in the indicated model [None] If none found and and `pad_with_none` set Examples: >>> find_field_names(['date_time', 'title_prefix', 'sales'], model='WikiItem') ['date', 'model', 'net_sales'] """ fields = util.listify(fields) model = get_model(model, app) available_field_names = model._meta.get_all_field_names() matched_fields = [] for field_name in fields: match = fuzzy.extractOne(str(field_name), available_field_names) if match and match[1] is not None and match[1] >= score_cutoff: matched_fields += [match[0]] elif pad_with_none: matched_fields += [None] return matched_fields
0, module; 1, function_definition; 2, function_name:lagged_in_date; 3, parameters; 4, block; 5, default_parameter; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, default_parameter; 13, default_parameter; 14, default_parameter; 15, expression_statement; 16, expression_statement; 17, comment:#print 'X, Y:', x, y; 18, if_statement; 19, if_statement; 20, if_statement; 21, return_statement; 22, identifier:x; 23, None; 24, identifier:y; 25, None; 26, identifier:filter_dict; 27, None; 28, identifier:model; 29, string; 30, identifier:app; 31, identifier:DEFAULT_APP; 32, identifier:sort; 33, True; 34, identifier:limit; 35, integer:30000; 36, identifier:lag; 37, integer:1; 38, identifier:pad; 39, integer:0; 40, identifier:truncate; 41, True; 42, comment:""" Lag the y values by the specified number of samples. FIXME: sort has no effect when sequences provided in x, y instead of field names >>> lagged_in_date(x=[.1,.2,.3,.4], y=[1,2,3,4], limit=4, lag=1) ([0.1, 0.2, 0.3, 0.4], [0, 1, 2, 3]) >>> lagged_in_date(x=[.1,.2,.3,.4], y=[1,2,3,4], lag=1, truncate=True) ([0.1, 0.2, 0.3, 0.4], [0, 1, 2, 3]) """; 43, assignment; 44, boolean_operator; 45, block; 46, boolean_operator; 47, block; 48, boolean_operator; 49, comment:#print 'X:', x; 50, block; 51, expression_list; 52, string_content:WikiItem; 53, identifier:lag; 54, call; 55, call; 56, call; 57, expression_statement; 58, identifier:y; 59, comparison_operator:len(y) == len(x); 60, if_statement; 61, return_statement; 62, boolean_operator; 63, comparison_operator:2 == len(x) <= len(x[0]); 64, expression_statement; 65, if_statement; 66, comment:#print x, y; 67, identifier:x; 68, identifier:y; 69, identifier:int; 70, argument_list; 71, identifier:isinstance; 72, argument_list; 73, identifier:isinstance; 74, argument_list; 75, assignment; 76, call; 77, call; 78, identifier:sort; 79, block; 80, expression_list; 81, identifier:x; 82, call; 83, integer:2; 84, call; 85, call; 86, assignment; 87, identifier:truncate; 88, block; 89, boolean_operator; 90, identifier:x; 91, identifier:basestring; 92, identifier:y; 93, identifier:basestring; 94, pattern_list; 95, call; 96, identifier:len; 97, argument_list; 98, identifier:len; 99, argument_list; 100, expression_statement; 101, expression_statement; 102, identifier:x; 103, call; 104, identifier:len; 105, argument_list; 106, identifier:len; 107, argument_list; 108, identifier:len; 109, argument_list; 110, pattern_list; 111, expression_list; 112, print_statement; 113, if_statement; 114, identifier:lag; 115, integer:0; 116, identifier:x; 117, identifier:y; 118, identifier:sequence_from_filter_spec; 119, argument_list; 120, identifier:y; 121, identifier:x; 122, assignment; 123, assignment; 124, identifier:lagged_seq; 125, argument_list; 126, identifier:x; 127, identifier:x; 128, subscript; 129, identifier:x; 130, identifier:y; 131, subscript; 132, call; 133, identifier:truncate; 134, identifier:lag; 135, comparison_operator:lag >= 0; 136, block; 137, else_clause; 138, list; 139, identifier:filter_dict; 140, keyword_argument; 141, keyword_argument; 142, keyword_argument; 143, keyword_argument; 144, identifier:xy; 145, call; 146, pattern_list; 147, expression_list; 148, identifier:y; 149, keyword_argument; 150, keyword_argument; 151, keyword_argument; 152, identifier:x; 153, integer:0; 154, identifier:x; 155, integer:0; 156, identifier:lagged_seq; 157, argument_list; 158, identifier:lag; 159, integer:0; 160, expression_statement; 161, block; 162, call; 163, call; 164, identifier:model; 165, identifier:model; 166, identifier:app; 167, identifier:app; 168, identifier:sort; 169, identifier:sort; 170, identifier:limit; 171, identifier:limit; 172, identifier:sorted; 173, argument_list; 174, identifier:x; 175, identifier:y; 176, list_comprehension; 177, list_comprehension; 178, identifier:lag; 179, identifier:lag; 180, identifier:pad; 181, identifier:pad; 182, identifier:truncate; 183, identifier:truncate; 184, subscript; 185, keyword_argument; 186, keyword_argument; 187, keyword_argument; 188, assignment; 189, expression_statement; 190, identifier:find_synonymous_field; 191, argument_list; 192, identifier:find_synonymous_field; 193, argument_list; 194, call; 195, keyword_argument; 196, identifier:col1; 197, for_in_clause; 198, identifier:col2; 199, for_in_clause; 200, identifier:x; 201, integer:1; 202, identifier:lag; 203, identifier:lag; 204, identifier:pad; 205, identifier:pad; 206, identifier:truncate; 207, identifier:truncate; 208, identifier:x; 209, subscript; 210, assignment; 211, identifier:x; 212, identifier:y; 213, identifier:zip; 214, argument_list; 215, identifier:reverse; 216, call; 217, pattern_list; 218, identifier:xy; 219, pattern_list; 220, identifier:xy; 221, identifier:x; 222, slice; 223, identifier:x; 224, subscript; 225, identifier:x; 226, identifier:y; 227, identifier:bool; 228, argument_list; 229, identifier:col1; 230, identifier:col2; 231, identifier:col1; 232, identifier:col2; 233, identifier:lag; 234, identifier:x; 235, slice; 236, comparison_operator:int(sort) < 0; 237, identifier:lag; 238, call; 239, integer:0; 240, identifier:int; 241, argument_list; 242, identifier:sort
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 3, 12; 3, 13; 3, 14; 4, 15; 4, 16; 4, 17; 4, 18; 4, 19; 4, 20; 4, 21; 5, 22; 5, 23; 6, 24; 6, 25; 7, 26; 7, 27; 8, 28; 8, 29; 9, 30; 9, 31; 10, 32; 10, 33; 11, 34; 11, 35; 12, 36; 12, 37; 13, 38; 13, 39; 14, 40; 14, 41; 15, 42; 16, 43; 18, 44; 18, 45; 19, 46; 19, 47; 20, 48; 20, 49; 20, 50; 21, 51; 29, 52; 43, 53; 43, 54; 44, 55; 44, 56; 45, 57; 46, 58; 46, 59; 47, 60; 47, 61; 48, 62; 48, 63; 50, 64; 50, 65; 50, 66; 51, 67; 51, 68; 54, 69; 54, 70; 55, 71; 55, 72; 56, 73; 56, 74; 57, 75; 59, 76; 59, 77; 60, 78; 60, 79; 61, 80; 62, 81; 62, 82; 63, 83; 63, 84; 63, 85; 64, 86; 65, 87; 65, 88; 70, 89; 72, 90; 72, 91; 74, 92; 74, 93; 75, 94; 75, 95; 76, 96; 76, 97; 77, 98; 77, 99; 79, 100; 79, 101; 80, 102; 80, 103; 82, 104; 82, 105; 84, 106; 84, 107; 85, 108; 85, 109; 86, 110; 86, 111; 88, 112; 88, 113; 89, 114; 89, 115; 94, 116; 94, 117; 95, 118; 95, 119; 97, 120; 99, 121; 100, 122; 101, 123; 103, 124; 103, 125; 105, 126; 107, 127; 109, 128; 110, 129; 110, 130; 111, 131; 111, 132; 112, 133; 112, 134; 113, 135; 113, 136; 113, 137; 119, 138; 119, 139; 119, 140; 119, 141; 119, 142; 119, 143; 122, 144; 122, 145; 123, 146; 123, 147; 125, 148; 125, 149; 125, 150; 125, 151; 128, 152; 128, 153; 131, 154; 131, 155; 132, 156; 132, 157; 135, 158; 135, 159; 136, 160; 137, 161; 138, 162; 138, 163; 140, 164; 140, 165; 141, 166; 141, 167; 142, 168; 142, 169; 143, 170; 143, 171; 145, 172; 145, 173; 146, 174; 146, 175; 147, 176; 147, 177; 149, 178; 149, 179; 150, 180; 150, 181; 151, 182; 151, 183; 157, 184; 157, 185; 157, 186; 157, 187; 160, 188; 161, 189; 162, 190; 162, 191; 163, 192; 163, 193; 173, 194; 173, 195; 176, 196; 176, 197; 177, 198; 177, 199; 184, 200; 184, 201; 185, 202; 185, 203; 186, 204; 186, 205; 187, 206; 187, 207; 188, 208; 188, 209; 189, 210; 191, 211; 193, 212; 194, 213; 194, 214; 195, 215; 195, 216; 197, 217; 197, 218; 199, 219; 199, 220; 209, 221; 209, 222; 210, 223; 210, 224; 214, 225; 214, 226; 216, 227; 216, 228; 217, 229; 217, 230; 219, 231; 219, 232; 222, 233; 224, 234; 224, 235; 228, 236; 235, 237; 236, 238; 236, 239; 238, 240; 238, 241; 241, 242
def lagged_in_date(x=None, y=None, filter_dict=None, model='WikiItem', app=DEFAULT_APP, sort=True, limit=30000, lag=1, pad=0, truncate=True): """ Lag the y values by the specified number of samples. FIXME: sort has no effect when sequences provided in x, y instead of field names >>> lagged_in_date(x=[.1,.2,.3,.4], y=[1,2,3,4], limit=4, lag=1) ([0.1, 0.2, 0.3, 0.4], [0, 1, 2, 3]) >>> lagged_in_date(x=[.1,.2,.3,.4], y=[1,2,3,4], lag=1, truncate=True) ([0.1, 0.2, 0.3, 0.4], [0, 1, 2, 3]) """ lag = int(lag or 0) #print 'X, Y:', x, y if isinstance(x, basestring) and isinstance(y, basestring): x, y = sequence_from_filter_spec([find_synonymous_field(x), find_synonymous_field(y)], filter_dict, model=model, app=app, sort=sort, limit=limit) if y and len(y) == len(x): if sort: xy = sorted(zip(x,y), reverse=bool(int(sort) < 0)) x, y = [col1 for col1, col2 in xy], [col2 for col1, col2 in xy] return x, lagged_seq(y, lag=lag, pad=pad, truncate=truncate) if x and len(x) and 2 == len(x) <= len(x[0]): #print 'X:', x x, y = x[0], lagged_seq(x[1], lag=lag, pad=pad, truncate=truncate) if truncate: print truncate, lag if lag >= 0: x = x[lag:] else: x = x[:lag] #print x, y return x, y
0, module; 1, function_definition; 2, function_name:percentile; 3, parameters; 4, block; 5, identifier:sorted_list; 6, identifier:percent; 7, default_parameter; 8, expression_statement; 9, if_statement; 10, if_statement; 11, if_statement; 12, expression_statement; 13, expression_statement; 14, if_statement; 15, return_statement; 16, identifier:key; 17, lambda; 18, comment:"""Find the percentile of a sorted list of values. Arguments --------- sorted_list : list A sorted (ascending) list of values. percent : float A float value from 0.0 to 1.0. key : function, optional An optional function to compute a value from each element of N. Returns ------- float The desired percentile of the value list. Examples -------- >>> sorted_list = [4,6,8,9,11] >>> percentile(sorted_list, 0.4) 7.0 >>> percentile(sorted_list, 0.44) 8.0 >>> percentile(sorted_list, 0.6) 8.5 >>> percentile(sorted_list, 0.99) 11.0 >>> percentile(sorted_list, 1) 11.0 >>> percentile(sorted_list, 0) 4.0 """; 19, not_operator; 20, block; 21, comparison_operator:percent == 1; 22, block; 23, comparison_operator:percent == 0; 24, block; 25, assignment; 26, assignment; 27, comparison_operator:ceil(i) == i; 28, block; 29, call; 30, lambda_parameters; 31, identifier:x; 32, identifier:sorted_list; 33, return_statement; 34, identifier:percent; 35, integer:1; 36, return_statement; 37, identifier:percent; 38, integer:0; 39, return_statement; 40, identifier:n; 41, call; 42, identifier:i; 43, binary_operator:percent * n; 44, call; 45, identifier:i; 46, expression_statement; 47, return_statement; 48, identifier:float; 49, argument_list; 50, identifier:x; 51, None; 52, call; 53, call; 54, identifier:len; 55, argument_list; 56, identifier:percent; 57, identifier:n; 58, identifier:ceil; 59, argument_list; 60, assignment; 61, binary_operator:(sorted_list[i-1] + sorted_list[i]) / 2; 62, subscript; 63, identifier:float; 64, argument_list; 65, identifier:float; 66, argument_list; 67, identifier:sorted_list; 68, identifier:i; 69, identifier:i; 70, call; 71, parenthesized_expression; 72, integer:2; 73, identifier:sorted_list; 74, binary_operator:ceil(i)-1; 75, subscript; 76, subscript; 77, identifier:int; 78, argument_list; 79, binary_operator:sorted_list[i-1] + sorted_list[i]; 80, call; 81, integer:1; 82, identifier:sorted_list; 83, unary_operator; 84, identifier:sorted_list; 85, integer:0; 86, identifier:i; 87, subscript; 88, subscript; 89, identifier:ceil; 90, argument_list; 91, integer:1; 92, identifier:sorted_list; 93, binary_operator:i-1; 94, identifier:sorted_list; 95, identifier:i; 96, identifier:i; 97, identifier:i; 98, integer:1
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 7, 16; 7, 17; 8, 18; 9, 19; 9, 20; 10, 21; 10, 22; 11, 23; 11, 24; 12, 25; 13, 26; 14, 27; 14, 28; 15, 29; 17, 30; 17, 31; 19, 32; 20, 33; 21, 34; 21, 35; 22, 36; 23, 37; 23, 38; 24, 39; 25, 40; 25, 41; 26, 42; 26, 43; 27, 44; 27, 45; 28, 46; 28, 47; 29, 48; 29, 49; 30, 50; 33, 51; 36, 52; 39, 53; 41, 54; 41, 55; 43, 56; 43, 57; 44, 58; 44, 59; 46, 60; 47, 61; 49, 62; 52, 63; 52, 64; 53, 65; 53, 66; 55, 67; 59, 68; 60, 69; 60, 70; 61, 71; 61, 72; 62, 73; 62, 74; 64, 75; 66, 76; 70, 77; 70, 78; 71, 79; 74, 80; 74, 81; 75, 82; 75, 83; 76, 84; 76, 85; 78, 86; 79, 87; 79, 88; 80, 89; 80, 90; 83, 91; 87, 92; 87, 93; 88, 94; 88, 95; 90, 96; 93, 97; 93, 98
def percentile(sorted_list, percent, key=lambda x: x): """Find the percentile of a sorted list of values. Arguments --------- sorted_list : list A sorted (ascending) list of values. percent : float A float value from 0.0 to 1.0. key : function, optional An optional function to compute a value from each element of N. Returns ------- float The desired percentile of the value list. Examples -------- >>> sorted_list = [4,6,8,9,11] >>> percentile(sorted_list, 0.4) 7.0 >>> percentile(sorted_list, 0.44) 8.0 >>> percentile(sorted_list, 0.6) 8.5 >>> percentile(sorted_list, 0.99) 11.0 >>> percentile(sorted_list, 1) 11.0 >>> percentile(sorted_list, 0) 4.0 """ if not sorted_list: return None if percent == 1: return float(sorted_list[-1]) if percent == 0: return float(sorted_list[0]) n = len(sorted_list) i = percent * n if ceil(i) == i: i = int(i) return (sorted_list[i-1] + sorted_list[i]) / 2 return float(sorted_list[ceil(i)-1])
0, module; 1, function_definition; 2, function_name:tags; 3, parameters; 4, block; 5, identifier:self; 6, expression_statement; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, comment:# q = q.filter_by(state='active'); 11, expression_statement; 12, expression_statement; 13, return_statement; 14, string; 15, assignment; 16, assignment; 17, assignment; 18, assignment; 19, assignment; 20, identifier:tags; 21, string_content:Return a list of all tags that have this semantic tag, sorted by name. :rtype: list of ckan.model.tag.Tag objects; 22, identifier:q; 23, call; 24, identifier:q; 25, call; 26, identifier:q; 27, call; 28, identifier:q; 29, call; 30, identifier:tags; 31, call; 32, attribute; 33, argument_list; 34, attribute; 35, argument_list; 36, attribute; 37, argument_list; 38, attribute; 39, argument_list; 40, attribute; 41, argument_list; 42, attribute; 43, identifier:query; 44, attribute; 45, identifier:q; 46, identifier:join; 47, identifier:TagSemanticTag; 48, identifier:q; 49, identifier:filter_by; 50, keyword_argument; 51, identifier:q; 52, identifier:order_by; 53, attribute; 54, identifier:q; 55, identifier:all; 56, identifier:meta; 57, identifier:Session; 58, identifier:_tag; 59, identifier:Tag; 60, identifier:tag_id; 61, attribute; 62, attribute; 63, identifier:name; 64, identifier:self; 65, identifier:id; 66, identifier:_tag; 67, identifier:Tag
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 6, 14; 7, 15; 8, 16; 9, 17; 11, 18; 12, 19; 13, 20; 14, 21; 15, 22; 15, 23; 16, 24; 16, 25; 17, 26; 17, 27; 18, 28; 18, 29; 19, 30; 19, 31; 23, 32; 23, 33; 25, 34; 25, 35; 27, 36; 27, 37; 29, 38; 29, 39; 31, 40; 31, 41; 32, 42; 32, 43; 33, 44; 34, 45; 34, 46; 35, 47; 36, 48; 36, 49; 37, 50; 38, 51; 38, 52; 39, 53; 40, 54; 40, 55; 42, 56; 42, 57; 44, 58; 44, 59; 50, 60; 50, 61; 53, 62; 53, 63; 61, 64; 61, 65; 62, 66; 62, 67
def tags(self): '''Return a list of all tags that have this semantic tag, sorted by name. :rtype: list of ckan.model.tag.Tag objects ''' q = meta.Session.query(_tag.Tag) q = q.join(TagSemanticTag) q = q.filter_by(tag_id=self.id) # q = q.filter_by(state='active') q = q.order_by(_tag.Tag.name) tags = q.all() return tags
0, module; 1, function_definition; 2, function_name:make_feature_bed; 3, parameters; 4, block; 5, identifier:gtf; 6, identifier:feature; 7, default_parameter; 8, expression_statement; 9, expression_statement; 10, with_statement; 11, expression_statement; 12, comment:# We'll sort so bedtools operations can be done faster.; 13, expression_statement; 14, if_statement; 15, return_statement; 16, identifier:out; 17, None; 18, comment:""" Make a bed file with the start and stop coordinates for all of a particular feature in Gencode. Valid features are the features present in the third column of the Gencode GTF file. Parameters ---------- gtf : str Filename of the Gencode gtf file. feature : str Feature from third column of Gencode GTF file. As of v19, these include CDS, exon, gene, Selenocysteine, start_codon, stop_codon, transcript, and UTR. out : str If provided, the bed file will be written to a file with this name. Returns ------- bed : pybedtools.BedTool A sorted pybedtools BedTool object. """; 19, assignment; 20, with_clause; 21, block; 22, assignment; 23, assignment; 24, identifier:out; 25, block; 26, identifier:bt; 27, identifier:bed_lines; 28, list; 29, with_item; 30, expression_statement; 31, while_statement; 32, identifier:bt; 33, call; 34, identifier:bt; 35, call; 36, expression_statement; 37, as_pattern; 38, assignment; 39, comparison_operator:line != ''; 40, block; 41, attribute; 42, argument_list; 43, attribute; 44, argument_list; 45, call; 46, call; 47, as_pattern_target; 48, identifier:line; 49, call; 50, identifier:line; 51, string; 52, if_statement; 53, expression_statement; 54, identifier:pbt; 55, identifier:BedTool; 56, call; 57, keyword_argument; 58, identifier:bt; 59, identifier:sort; 60, attribute; 61, argument_list; 62, identifier:open; 63, argument_list; 64, identifier:f; 65, attribute; 66, argument_list; 67, comparison_operator:line[0] != '#'; 68, block; 69, assignment; 70, attribute; 71, argument_list; 72, identifier:from_string; 73, True; 74, identifier:bt; 75, identifier:saveas; 76, identifier:out; 77, identifier:gtf; 78, call; 79, identifier:strip; 80, subscript; 81, string; 82, expression_statement; 83, if_statement; 84, identifier:line; 85, call; 86, string; 87, identifier:join; 88, identifier:bed_lines; 89, attribute; 90, argument_list; 91, identifier:line; 92, integer:0; 93, string_content:#; 94, assignment; 95, comparison_operator:line[2] == feature; 96, block; 97, attribute; 98, argument_list; 99, identifier:f; 100, identifier:readline; 101, identifier:line; 102, call; 103, subscript; 104, identifier:feature; 105, expression_statement; 106, expression_statement; 107, expression_statement; 108, if_statement; 109, expression_statement; 110, expression_statement; 111, call; 112, identifier:strip; 113, attribute; 114, argument_list; 115, identifier:line; 116, integer:2; 117, assignment; 118, assignment; 119, assignment; 120, comparison_operator:feature == 'gene'; 121, block; 122, else_clause; 123, assignment; 124, call; 125, attribute; 126, argument_list; 127, identifier:line; 128, identifier:split; 129, string; 130, identifier:chrom; 131, subscript; 132, identifier:start; 133, call; 134, identifier:end; 135, subscript; 136, identifier:feature; 137, string; 138, expression_statement; 139, comment:# TODO: I may want to have some smarter naming for; 140, comment:# things that aren't genes or transcripts.; 141, block; 142, identifier:strand; 143, subscript; 144, attribute; 145, argument_list; 146, identifier:f; 147, identifier:readline; 148, string_content; 149, identifier:line; 150, integer:0; 151, identifier:str; 152, argument_list; 153, identifier:line; 154, integer:4; 155, string_content:gene; 156, assignment; 157, expression_statement; 158, identifier:line; 159, integer:6; 160, identifier:bed_lines; 161, identifier:append; 162, binary_operator:'\t'.join([chrom, start, end, name, '.', strand]) + '\n'; 163, escape_sequence:\t; 164, binary_operator:int(line[3]) - 1; 165, identifier:name; 166, call; 167, assignment; 168, call; 169, string; 170, call; 171, integer:1; 172, attribute; 173, argument_list; 174, identifier:name; 175, call; 176, attribute; 177, argument_list; 178, string_content; 179, identifier:int; 180, argument_list; 181, subscript; 182, identifier:strip; 183, string:'"'; 184, attribute; 185, argument_list; 186, string; 187, identifier:join; 188, list; 189, escape_sequence:\n; 190, subscript; 191, call; 192, integer:1; 193, subscript; 194, identifier:strip; 195, string:'"'; 196, string_content; 197, identifier:chrom; 198, identifier:start; 199, identifier:end; 200, identifier:name; 201, string; 202, identifier:strand; 203, identifier:line; 204, integer:3; 205, attribute; 206, argument_list; 207, call; 208, integer:2; 209, escape_sequence:\t; 210, string_content:.; 211, subscript; 212, identifier:split; 213, string; 214, attribute; 215, argument_list; 216, call; 217, integer:0; 218, string_content:; 219, subscript; 220, identifier:split; 221, string; 222, attribute; 223, argument_list; 224, call; 225, integer:1; 226, string_content:; 227, subscript; 228, identifier:split; 229, string; 230, attribute; 231, argument_list; 232, identifier:line; 233, integer:8; 234, string_content:;; 235, subscript; 236, identifier:split; 237, string; 238, identifier:line; 239, integer:8; 240, string_content:;
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 7, 16; 7, 17; 8, 18; 9, 19; 10, 20; 10, 21; 11, 22; 13, 23; 14, 24; 14, 25; 15, 26; 19, 27; 19, 28; 20, 29; 21, 30; 21, 31; 22, 32; 22, 33; 23, 34; 23, 35; 25, 36; 29, 37; 30, 38; 31, 39; 31, 40; 33, 41; 33, 42; 35, 43; 35, 44; 36, 45; 37, 46; 37, 47; 38, 48; 38, 49; 39, 50; 39, 51; 40, 52; 40, 53; 41, 54; 41, 55; 42, 56; 42, 57; 43, 58; 43, 59; 45, 60; 45, 61; 46, 62; 46, 63; 47, 64; 49, 65; 49, 66; 52, 67; 52, 68; 53, 69; 56, 70; 56, 71; 57, 72; 57, 73; 60, 74; 60, 75; 61, 76; 63, 77; 65, 78; 65, 79; 67, 80; 67, 81; 68, 82; 68, 83; 69, 84; 69, 85; 70, 86; 70, 87; 71, 88; 78, 89; 78, 90; 80, 91; 80, 92; 81, 93; 82, 94; 83, 95; 83, 96; 85, 97; 85, 98; 89, 99; 89, 100; 94, 101; 94, 102; 95, 103; 95, 104; 96, 105; 96, 106; 96, 107; 96, 108; 96, 109; 96, 110; 97, 111; 97, 112; 102, 113; 102, 114; 103, 115; 103, 116; 105, 117; 106, 118; 107, 119; 108, 120; 108, 121; 108, 122; 109, 123; 110, 124; 111, 125; 111, 126; 113, 127; 113, 128; 114, 129; 117, 130; 117, 131; 118, 132; 118, 133; 119, 134; 119, 135; 120, 136; 120, 137; 121, 138; 122, 139; 122, 140; 122, 141; 123, 142; 123, 143; 124, 144; 124, 145; 125, 146; 125, 147; 129, 148; 131, 149; 131, 150; 133, 151; 133, 152; 135, 153; 135, 154; 137, 155; 138, 156; 141, 157; 143, 158; 143, 159; 144, 160; 144, 161; 145, 162; 148, 163; 152, 164; 156, 165; 156, 166; 157, 167; 162, 168; 162, 169; 164, 170; 164, 171; 166, 172; 166, 173; 167, 174; 167, 175; 168, 176; 168, 177; 169, 178; 170, 179; 170, 180; 172, 181; 172, 182; 173, 183; 175, 184; 175, 185; 176, 186; 176, 187; 177, 188; 178, 189; 180, 190; 181, 191; 181, 192; 184, 193; 184, 194; 185, 195; 186, 196; 188, 197; 188, 198; 188, 199; 188, 200; 188, 201; 188, 202; 190, 203; 190, 204; 191, 205; 191, 206; 193, 207; 193, 208; 196, 209; 201, 210; 205, 211; 205, 212; 206, 213; 207, 214; 207, 215; 211, 216; 211, 217; 213, 218; 214, 219; 214, 220; 215, 221; 216, 222; 216, 223; 219, 224; 219, 225; 221, 226; 222, 227; 222, 228; 223, 229; 224, 230; 224, 231; 227, 232; 227, 233; 229, 234; 230, 235; 230, 236; 231, 237; 235, 238; 235, 239; 237, 240
def make_feature_bed(gtf, feature, out=None): """ Make a bed file with the start and stop coordinates for all of a particular feature in Gencode. Valid features are the features present in the third column of the Gencode GTF file. Parameters ---------- gtf : str Filename of the Gencode gtf file. feature : str Feature from third column of Gencode GTF file. As of v19, these include CDS, exon, gene, Selenocysteine, start_codon, stop_codon, transcript, and UTR. out : str If provided, the bed file will be written to a file with this name. Returns ------- bed : pybedtools.BedTool A sorted pybedtools BedTool object. """ bed_lines = [] with open(gtf) as f: line = f.readline().strip() while line != '': if line[0] != '#': line = line.split('\t') if line[2] == feature: chrom = line[0] start = str(int(line[3]) - 1) end = line[4] if feature == 'gene': name = line[8].split(';')[0].split(' ')[1].strip('"') else: # TODO: I may want to have some smarter naming for # things that aren't genes or transcripts. name = line[8].split(';')[1].split(' ')[2].strip('"') strand = line[6] bed_lines.append('\t'.join([chrom, start, end, name, '.', strand]) + '\n') line = f.readline().strip() bt = pbt.BedTool(''.join(bed_lines), from_string=True) # We'll sort so bedtools operations can be done faster. bt = bt.sort() if out: bt.saveas(out) return bt
0, module; 1, function_definition; 2, function_name:filter; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, default_parameter; 8, dictionary_splat_pattern; 9, expression_statement; 10, with_statement; 11, identifier:order_by; 12, None; 13, identifier:limit; 14, integer:0; 15, identifier:kwargs; 16, comment:""" Fetch a list of instances. :param order_by: column on which to order the results. \ To change the sort, prepend with < or >. :param limit: How many rows to fetch. :param kwargs: keyword args on which to filter, column=value """; 17, with_clause; 18, block; 19, with_item; 20, if_statement; 21, try_statement; 22, as_pattern; 23, comparison_operator:len(kwargs) == 0; 24, block; 25, block; 26, except_clause; 27, except_clause; 28, else_clause; 29, call; 30, as_pattern_target; 31, call; 32, integer:0; 33, raise_statement; 34, expression_statement; 35, expression_statement; 36, if_statement; 37, if_statement; 38, expression_statement; 39, expression_statement; 40, as_pattern; 41, block; 42, as_pattern; 43, block; 44, block; 45, identifier:rconnect; 46, argument_list; 47, identifier:conn; 48, identifier:len; 49, argument_list; 50, identifier:ValueError; 51, assignment; 52, assignment; 53, comparison_operator:order_by is not None; 54, block; 55, comparison_operator:limit > 0; 56, block; 57, call; 58, assignment; 59, identifier:ReqlOpFailedError; 60, as_pattern_target; 61, expression_statement; 62, raise_statement; 63, identifier:Exception; 64, as_pattern_target; 65, expression_statement; 66, raise_statement; 67, expression_statement; 68, return_statement; 69, identifier:kwargs; 70, identifier:query; 71, call; 72, identifier:query; 73, call; 74, identifier:order_by; 75, None; 76, expression_statement; 77, identifier:limit; 78, integer:0; 79, expression_statement; 80, attribute; 81, argument_list; 82, identifier:rv; 83, call; 84, identifier:e; 85, call; 86, identifier:e; 87, call; 88, assignment; 89, identifier:data; 90, attribute; 91, argument_list; 92, attribute; 93, argument_list; 94, assignment; 95, assignment; 96, identifier:log; 97, identifier:debug; 98, identifier:query; 99, attribute; 100, argument_list; 101, attribute; 102, argument_list; 103, attribute; 104, argument_list; 105, identifier:data; 106, list_comprehension; 107, identifier:self; 108, identifier:_base; 109, identifier:query; 110, identifier:filter; 111, identifier:kwargs; 112, identifier:query; 113, call; 114, identifier:query; 115, call; 116, identifier:query; 117, identifier:run; 118, identifier:conn; 119, identifier:log; 120, identifier:warn; 121, identifier:e; 122, identifier:log; 123, identifier:warn; 124, identifier:e; 125, call; 126, for_in_clause; 127, attribute; 128, argument_list; 129, attribute; 130, argument_list; 131, attribute; 132, argument_list; 133, identifier:_; 134, identifier:rv; 135, identifier:self; 136, identifier:_order_by; 137, identifier:query; 138, identifier:order_by; 139, identifier:self; 140, identifier:_limit; 141, identifier:query; 142, identifier:limit; 143, identifier:self; 144, identifier:_model; 145, identifier:_
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, 9; 4, 10; 6, 11; 6, 12; 7, 13; 7, 14; 8, 15; 9, 16; 10, 17; 10, 18; 17, 19; 18, 20; 18, 21; 19, 22; 20, 23; 20, 24; 21, 25; 21, 26; 21, 27; 21, 28; 22, 29; 22, 30; 23, 31; 23, 32; 24, 33; 25, 34; 25, 35; 25, 36; 25, 37; 25, 38; 25, 39; 26, 40; 26, 41; 27, 42; 27, 43; 28, 44; 29, 45; 29, 46; 30, 47; 31, 48; 31, 49; 33, 50; 34, 51; 35, 52; 36, 53; 36, 54; 37, 55; 37, 56; 38, 57; 39, 58; 40, 59; 40, 60; 41, 61; 41, 62; 42, 63; 42, 64; 43, 65; 43, 66; 44, 67; 44, 68; 49, 69; 51, 70; 51, 71; 52, 72; 52, 73; 53, 74; 53, 75; 54, 76; 55, 77; 55, 78; 56, 79; 57, 80; 57, 81; 58, 82; 58, 83; 60, 84; 61, 85; 64, 86; 65, 87; 67, 88; 68, 89; 71, 90; 71, 91; 73, 92; 73, 93; 76, 94; 79, 95; 80, 96; 80, 97; 81, 98; 83, 99; 83, 100; 85, 101; 85, 102; 87, 103; 87, 104; 88, 105; 88, 106; 90, 107; 90, 108; 92, 109; 92, 110; 93, 111; 94, 112; 94, 113; 95, 114; 95, 115; 99, 116; 99, 117; 100, 118; 101, 119; 101, 120; 102, 121; 103, 122; 103, 123; 104, 124; 106, 125; 106, 126; 113, 127; 113, 128; 115, 129; 115, 130; 125, 131; 125, 132; 126, 133; 126, 134; 127, 135; 127, 136; 128, 137; 128, 138; 129, 139; 129, 140; 130, 141; 130, 142; 131, 143; 131, 144; 132, 145
def filter(self, order_by=None, limit=0, **kwargs): """ Fetch a list of instances. :param order_by: column on which to order the results. \ To change the sort, prepend with < or >. :param limit: How many rows to fetch. :param kwargs: keyword args on which to filter, column=value """ with rconnect() as conn: if len(kwargs) == 0: raise ValueError try: query = self._base() query = query.filter(kwargs) if order_by is not None: query = self._order_by(query, order_by) if limit > 0: query = self._limit(query, limit) log.debug(query) rv = query.run(conn) except ReqlOpFailedError as e: log.warn(e) raise except Exception as e: log.warn(e) raise else: data = [self._model(_) for _ in rv] return data
0, module; 1, function_definition; 2, function_name:all; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, default_parameter; 8, expression_statement; 9, with_statement; 10, identifier:order_by; 11, None; 12, identifier:limit; 13, integer:0; 14, comment:""" Fetch all items. :param limit: How many rows to fetch. :param order_by: column on which to order the results. \ To change the sort, prepend with < or >. """; 15, with_clause; 16, block; 17, with_item; 18, try_statement; 19, as_pattern; 20, block; 21, except_clause; 22, else_clause; 23, call; 24, as_pattern_target; 25, expression_statement; 26, if_statement; 27, if_statement; 28, expression_statement; 29, expression_statement; 30, as_pattern; 31, block; 32, block; 33, identifier:rconnect; 34, argument_list; 35, identifier:conn; 36, assignment; 37, comparison_operator:order_by is not None; 38, block; 39, comparison_operator:limit > 0; 40, block; 41, call; 42, assignment; 43, identifier:Exception; 44, as_pattern_target; 45, expression_statement; 46, raise_statement; 47, expression_statement; 48, return_statement; 49, identifier:query; 50, call; 51, identifier:order_by; 52, None; 53, expression_statement; 54, identifier:limit; 55, integer:0; 56, expression_statement; 57, attribute; 58, argument_list; 59, identifier:rv; 60, call; 61, identifier:e; 62, call; 63, assignment; 64, identifier:data; 65, attribute; 66, argument_list; 67, assignment; 68, assignment; 69, identifier:log; 70, identifier:debug; 71, identifier:query; 72, attribute; 73, argument_list; 74, attribute; 75, argument_list; 76, identifier:data; 77, list_comprehension; 78, identifier:self; 79, identifier:_base; 80, identifier:query; 81, call; 82, identifier:query; 83, call; 84, identifier:query; 85, identifier:run; 86, identifier:conn; 87, identifier:log; 88, identifier:warn; 89, identifier:e; 90, call; 91, for_in_clause; 92, attribute; 93, argument_list; 94, attribute; 95, argument_list; 96, attribute; 97, argument_list; 98, identifier:_; 99, identifier:rv; 100, identifier:self; 101, identifier:_order_by; 102, identifier:query; 103, identifier:order_by; 104, identifier:self; 105, identifier:_limit; 106, identifier:query; 107, identifier:limit; 108, identifier:self; 109, identifier:_model; 110, identifier:_
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 6, 10; 6, 11; 7, 12; 7, 13; 8, 14; 9, 15; 9, 16; 15, 17; 16, 18; 17, 19; 18, 20; 18, 21; 18, 22; 19, 23; 19, 24; 20, 25; 20, 26; 20, 27; 20, 28; 20, 29; 21, 30; 21, 31; 22, 32; 23, 33; 23, 34; 24, 35; 25, 36; 26, 37; 26, 38; 27, 39; 27, 40; 28, 41; 29, 42; 30, 43; 30, 44; 31, 45; 31, 46; 32, 47; 32, 48; 36, 49; 36, 50; 37, 51; 37, 52; 38, 53; 39, 54; 39, 55; 40, 56; 41, 57; 41, 58; 42, 59; 42, 60; 44, 61; 45, 62; 47, 63; 48, 64; 50, 65; 50, 66; 53, 67; 56, 68; 57, 69; 57, 70; 58, 71; 60, 72; 60, 73; 62, 74; 62, 75; 63, 76; 63, 77; 65, 78; 65, 79; 67, 80; 67, 81; 68, 82; 68, 83; 72, 84; 72, 85; 73, 86; 74, 87; 74, 88; 75, 89; 77, 90; 77, 91; 81, 92; 81, 93; 83, 94; 83, 95; 90, 96; 90, 97; 91, 98; 91, 99; 92, 100; 92, 101; 93, 102; 93, 103; 94, 104; 94, 105; 95, 106; 95, 107; 96, 108; 96, 109; 97, 110
def all(self, order_by=None, limit=0): """ Fetch all items. :param limit: How many rows to fetch. :param order_by: column on which to order the results. \ To change the sort, prepend with < or >. """ with rconnect() as conn: try: query = self._base() if order_by is not None: query = self._order_by(query, order_by) if limit > 0: query = self._limit(query, limit) log.debug(query) rv = query.run(conn) except Exception as e: log.warn(e) raise else: data = [self._model(_) for _ in rv] return data
0, module; 1, function_definition; 2, function_name:safe_dump_js; 3, parameters; 4, block; 5, identifier:js; 6, identifier:abspath; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, expression_statement; 11, expression_statement; 12, comment:# try stringlize; 13, expression_statement; 14, expression_statement; 15, expression_statement; 16, identifier:fastmode; 17, False; 18, identifier:compress; 19, False; 20, identifier:enable_verbose; 21, True; 22, comment:"""A stable version of dump_js, silently overwrite existing file. When your program been interrupted, you lose nothing. Typically if your program is interrupted by any reason, it only leaves a incomplete file. If you use replace=True, then you also lose your old file. So a bettr way is to: 1. dump json to a temp file. 2. when it's done, rename it to #abspath, overwrite the old one. This way guarantee atomic write. :param js: Serializable python object. :type js: dict or list :param abspath: ``save as`` path, file extension has to be ``.json`` or ``.gz`` (for compressed json). :type abspath: string :param fastmode: (default False) If ``True``, then dumping json without sorted keys and pretty indent, and it's faster and smaller in size. :type fastmode: boolean :param compress: (default False) If ``True``, use GNU program gzip to compress the json file. Disk usage can be greatly reduced. But you have to use :func:`load_js(abspath, compress=True)<load_js>` in loading. :type compress: boolean :param enable_verbose: (default True) Trigger for message. :type enable_verbose: boolean Usage:: >>> from weatherlab.lib.dataIO.js import dump_js >>> js = {"a": 1, "b": 2} >>> safe_dump_js(js, "test.json") Dumping to test.json... Complete! Elapse 0.002432 sec **中文文档** 在对文件进行写入时, 如果程序中断, 则会留下一个不完整的文件。如果你使用了覆盖式 写入, 则你同时也丢失了原文件。所以为了保证写操作的原子性(要么全部完成, 要么全部 都不完成), 更好的方法是: 首先将文件写入一个临时文件中, 完成后再讲文件重命名, 覆盖旧文件。这样即使中途程序被中断, 也仅仅是留下了一个未完成的临时文件而已, 不会 影响原文件。 参数列表 :param js: 可Json化的Python对象 :type js: ``字典`` 或 ``列表`` :param abspath: 写入文件的路径。扩展名必须为 ``.json`` 或 ``.gz``, 其中gz用于被压 缩的Json :type abspath: ``字符串`` :param replace: (默认 False) 当为``True``时, 如果写入路径已经存在, 则会自动覆盖 原文件。而为``False``时, 则会抛出异常。防止误操作覆盖源文件。 :type replace: ``布尔值`` :param compress: (默认 False) 当为``True``时, 使用开源压缩标准gzip压缩Json文件。 通常能让文件大小缩小10-20倍不等。如要读取文件, 则需要使用函数 :func:`load_js(abspath, compress=True)<load_js>`. :type compress: ``布尔值`` :param enable_verbose: (默认 True) 是否打开信息提示开关, 批处理时建议关闭. :type enable_verbose: ``布尔值`` """; 23, assignment; 24, assignment; 25, call; 26, call; 27, identifier:abspath; 28, call; 29, identifier:temp_abspath; 30, binary_operator:"%s.tmp" % abspath; 31, identifier:dump_js; 32, argument_list; 33, attribute; 34, argument_list; 35, identifier:str; 36, argument_list; 37, string:"%s.tmp"; 38, identifier:abspath; 39, identifier:js; 40, identifier:temp_abspath; 41, keyword_argument; 42, keyword_argument; 43, keyword_argument; 44, keyword_argument; 45, identifier:shutil; 46, identifier:move; 47, identifier:temp_abspath; 48, identifier:abspath; 49, identifier:abspath; 50, identifier:fastmode; 51, identifier:fastmode; 52, identifier:replace; 53, True; 54, identifier:compress; 55, identifier:compress; 56, identifier:enable_verbose; 57, identifier:enable_verbose
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 7, 16; 7, 17; 8, 18; 8, 19; 9, 20; 9, 21; 10, 22; 11, 23; 13, 24; 14, 25; 15, 26; 23, 27; 23, 28; 24, 29; 24, 30; 25, 31; 25, 32; 26, 33; 26, 34; 28, 35; 28, 36; 30, 37; 30, 38; 32, 39; 32, 40; 32, 41; 32, 42; 32, 43; 32, 44; 33, 45; 33, 46; 34, 47; 34, 48; 36, 49; 41, 50; 41, 51; 42, 52; 42, 53; 43, 54; 43, 55; 44, 56; 44, 57
def safe_dump_js(js, abspath, fastmode=False, compress=False, enable_verbose=True): """A stable version of dump_js, silently overwrite existing file. When your program been interrupted, you lose nothing. Typically if your program is interrupted by any reason, it only leaves a incomplete file. If you use replace=True, then you also lose your old file. So a bettr way is to: 1. dump json to a temp file. 2. when it's done, rename it to #abspath, overwrite the old one. This way guarantee atomic write. :param js: Serializable python object. :type js: dict or list :param abspath: ``save as`` path, file extension has to be ``.json`` or ``.gz`` (for compressed json). :type abspath: string :param fastmode: (default False) If ``True``, then dumping json without sorted keys and pretty indent, and it's faster and smaller in size. :type fastmode: boolean :param compress: (default False) If ``True``, use GNU program gzip to compress the json file. Disk usage can be greatly reduced. But you have to use :func:`load_js(abspath, compress=True)<load_js>` in loading. :type compress: boolean :param enable_verbose: (default True) Trigger for message. :type enable_verbose: boolean Usage:: >>> from weatherlab.lib.dataIO.js import dump_js >>> js = {"a": 1, "b": 2} >>> safe_dump_js(js, "test.json") Dumping to test.json... Complete! Elapse 0.002432 sec **中文文档** 在对文件进行写入时, 如果程序中断, 则会留下一个不完整的文件。如果你使用了覆盖式 写入, 则你同时也丢失了原文件。所以为了保证写操作的原子性(要么全部完成, 要么全部 都不完成), 更好的方法是: 首先将文件写入一个临时文件中, 完成后再讲文件重命名, 覆盖旧文件。这样即使中途程序被中断, 也仅仅是留下了一个未完成的临时文件而已, 不会 影响原文件。 参数列表 :param js: 可Json化的Python对象 :type js: ``字典`` 或 ``列表`` :param abspath: 写入文件的路径。扩展名必须为 ``.json`` 或 ``.gz``, 其中gz用于被压 缩的Json :type abspath: ``字符串`` :param replace: (默认 False) 当为``True``时, 如果写入路径已经存在, 则会自动覆盖 原文件。而为``False``时, 则会抛出异常。防止误操作覆盖源文件。 :type replace: ``布尔值`` :param compress: (默认 False) 当为``True``时, 使用开源压缩标准gzip压缩Json文件。 通常能让文件大小缩小10-20倍不等。如要读取文件, 则需要使用函数 :func:`load_js(abspath, compress=True)<load_js>`. :type compress: ``布尔值`` :param enable_verbose: (默认 True) 是否打开信息提示开关, 批处理时建议关闭. :type enable_verbose: ``布尔值`` """ abspath = str(abspath) # try stringlize temp_abspath = "%s.tmp" % abspath dump_js(js, temp_abspath, fastmode=fastmode, replace=True, compress=compress, enable_verbose=enable_verbose) shutil.move(temp_abspath, abspath)
0, module; 1, function_definition; 2, function_name:all_selectors; 3, parameters; 4, block; 5, identifier:Class; 6, identifier:fn; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, for_statement; 12, expression_statement; 13, return_statement; 14, comment:"""return a sorted list of selectors that occur in the stylesheet"""; 15, assignment; 16, assignment; 17, assignment; 18, identifier:rule; 19, list_comprehension; 20, block; 21, assignment; 22, identifier:selectors; 23, identifier:selectors; 24, list; 25, identifier:cssparser; 26, call; 27, identifier:css; 28, call; 29, identifier:r; 30, for_in_clause; 31, if_clause; 32, expression_statement; 33, identifier:selectors; 34, call; 35, attribute; 36, argument_list; 37, attribute; 38, argument_list; 39, identifier:r; 40, attribute; 41, comparison_operator:type(r)==cssutils.css.CSSStyleRule; 42, augmented_assignment; 43, identifier:sorted; 44, argument_list; 45, identifier:cssutils; 46, identifier:CSSParser; 47, keyword_argument; 48, identifier:cssparser; 49, identifier:parseFile; 50, identifier:fn; 51, identifier:css; 52, identifier:cssRules; 53, call; 54, attribute; 55, identifier:selectors; 56, list_comprehension; 57, call; 58, identifier:validate; 59, False; 60, identifier:type; 61, argument_list; 62, attribute; 63, identifier:CSSStyleRule; 64, attribute; 65, for_in_clause; 66, identifier:list; 67, argument_list; 68, identifier:r; 69, identifier:cssutils; 70, identifier:css; 71, identifier:sel; 72, identifier:selectorText; 73, identifier:sel; 74, attribute; 75, call; 76, identifier:rule; 77, identifier:selectorList; 78, identifier:set; 79, argument_list; 80, identifier:selectors
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 7, 14; 8, 15; 9, 16; 10, 17; 11, 18; 11, 19; 11, 20; 12, 21; 13, 22; 15, 23; 15, 24; 16, 25; 16, 26; 17, 27; 17, 28; 19, 29; 19, 30; 19, 31; 20, 32; 21, 33; 21, 34; 26, 35; 26, 36; 28, 37; 28, 38; 30, 39; 30, 40; 31, 41; 32, 42; 34, 43; 34, 44; 35, 45; 35, 46; 36, 47; 37, 48; 37, 49; 38, 50; 40, 51; 40, 52; 41, 53; 41, 54; 42, 55; 42, 56; 44, 57; 47, 58; 47, 59; 53, 60; 53, 61; 54, 62; 54, 63; 56, 64; 56, 65; 57, 66; 57, 67; 61, 68; 62, 69; 62, 70; 64, 71; 64, 72; 65, 73; 65, 74; 67, 75; 74, 76; 74, 77; 75, 78; 75, 79; 79, 80
def all_selectors(Class, fn): """return a sorted list of selectors that occur in the stylesheet""" selectors = [] cssparser = cssutils.CSSParser(validate=False) css = cssparser.parseFile(fn) for rule in [r for r in css.cssRules if type(r)==cssutils.css.CSSStyleRule]: selectors += [sel.selectorText for sel in rule.selectorList] selectors = sorted(list(set(selectors))) return selectors
0, module; 1, function_definition; 2, function_name:create_logger; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, expression_statement; 8, comment:# Set up logging; 9, expression_statement; 10, expression_statement; 11, if_statement; 12, expression_statement; 13, expression_statement; 14, comment:# Log to stdout; 15, expression_statement; 16, expression_statement; 17, expression_statement; 18, comment:# Log to file if the option is chosen; 19, if_statement; 20, if_statement; 21, expression_statement; 22, identifier:args; 23, dictionary; 24, comment:""" Create and configure the program's logger object. Log levels: DEBUG - Log everything. Hidden unless --debug is used. INFO - information only ERROR - Critical error :param args: Object containing program's parsed command line arguments :return: None """; 25, assignment; 26, assignment; 27, boolean_operator; 28, block; 29, assignment; 30, assignment; 31, assignment; 32, call; 33, call; 34, boolean_operator; 35, block; 36, boolean_operator; 37, block; 38, assignment; 39, identifier:logger; 40, call; 41, attribute; 42, attribute; 43, comparison_operator:'--debug' in args; 44, comparison_operator:args['--debug'] is True; 45, expression_statement; 46, identifier:file_log_formatter; 47, call; 48, identifier:console_log_formatter; 49, call; 50, identifier:stdout_stream; 51, call; 52, attribute; 53, argument_list; 54, attribute; 55, argument_list; 56, comparison_operator:'--log' in args; 57, comparison_operator:args['--log'] is not None; 58, expression_statement; 59, expression_statement; 60, expression_statement; 61, expression_statement; 62, comparison_operator:'--dry-run' in args; 63, comparison_operator:args['--dry-run'] is True; 64, expression_statement; 65, attribute; 66, identifier:logger; 67, attribute; 68, argument_list; 69, identifier:logger; 70, identifier:level; 71, identifier:logging; 72, identifier:INFO; 73, string; 74, identifier:args; 75, subscript; 76, True; 77, call; 78, attribute; 79, argument_list; 80, attribute; 81, argument_list; 82, attribute; 83, argument_list; 84, identifier:stdout_stream; 85, identifier:setFormatter; 86, identifier:console_log_formatter; 87, identifier:logger; 88, identifier:addHandler; 89, identifier:stdout_stream; 90, string; 91, identifier:args; 92, subscript; 93, None; 94, assignment; 95, assignment; 96, call; 97, call; 98, string; 99, identifier:args; 100, subscript; 101, True; 102, call; 103, identifier:self; 104, identifier:logger; 105, identifier:logging; 106, identifier:getLogger; 107, string:"SmartFileSorter"; 108, string_content:--debug; 109, identifier:args; 110, string; 111, attribute; 112, argument_list; 113, identifier:logging; 114, identifier:Formatter; 115, string; 116, string; 117, identifier:logging; 118, identifier:Formatter; 119, string; 120, identifier:logging; 121, identifier:StreamHandler; 122, keyword_argument; 123, string_content:--log; 124, identifier:args; 125, string; 126, identifier:logfile; 127, call; 128, identifier:logfile_stream; 129, call; 130, attribute; 131, argument_list; 132, attribute; 133, argument_list; 134, string_content:--dry-run; 135, identifier:args; 136, string; 137, attribute; 138, argument_list; 139, string_content:--debug; 140, identifier:logger; 141, identifier:setLevel; 142, attribute; 143, string_content:%(asctime)s %(name)s %(levelname)s %(message)s; 144, string_content:%Y-%m-%d %H:%M:%S; 145, string_content:%(message)s; 146, identifier:stream; 147, attribute; 148, string_content:--log; 149, identifier:open; 150, argument_list; 151, attribute; 152, argument_list; 153, identifier:logfile_stream; 154, identifier:setFormatter; 155, identifier:file_log_formatter; 156, identifier:logger; 157, identifier:addHandler; 158, identifier:logfile_stream; 159, string_content:--dry-run; 160, identifier:logger; 161, identifier:info; 162, string; 163, identifier:logging; 164, identifier:DEBUG; 165, identifier:sys; 166, identifier:stdout; 167, subscript; 168, string; 169, identifier:logging; 170, identifier:StreamHandler; 171, keyword_argument; 172, string_content:Running with --dry-run parameter. Actions will not be performed.; 173, identifier:args; 174, string; 175, string_content:w; 176, identifier:stream; 177, identifier:logfile; 178, string_content:--log
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 4, 17; 4, 18; 4, 19; 4, 20; 4, 21; 6, 22; 6, 23; 7, 24; 9, 25; 10, 26; 11, 27; 11, 28; 12, 29; 13, 30; 15, 31; 16, 32; 17, 33; 19, 34; 19, 35; 20, 36; 20, 37; 21, 38; 25, 39; 25, 40; 26, 41; 26, 42; 27, 43; 27, 44; 28, 45; 29, 46; 29, 47; 30, 48; 30, 49; 31, 50; 31, 51; 32, 52; 32, 53; 33, 54; 33, 55; 34, 56; 34, 57; 35, 58; 35, 59; 35, 60; 35, 61; 36, 62; 36, 63; 37, 64; 38, 65; 38, 66; 40, 67; 40, 68; 41, 69; 41, 70; 42, 71; 42, 72; 43, 73; 43, 74; 44, 75; 44, 76; 45, 77; 47, 78; 47, 79; 49, 80; 49, 81; 51, 82; 51, 83; 52, 84; 52, 85; 53, 86; 54, 87; 54, 88; 55, 89; 56, 90; 56, 91; 57, 92; 57, 93; 58, 94; 59, 95; 60, 96; 61, 97; 62, 98; 62, 99; 63, 100; 63, 101; 64, 102; 65, 103; 65, 104; 67, 105; 67, 106; 68, 107; 73, 108; 75, 109; 75, 110; 77, 111; 77, 112; 78, 113; 78, 114; 79, 115; 79, 116; 80, 117; 80, 118; 81, 119; 82, 120; 82, 121; 83, 122; 90, 123; 92, 124; 92, 125; 94, 126; 94, 127; 95, 128; 95, 129; 96, 130; 96, 131; 97, 132; 97, 133; 98, 134; 100, 135; 100, 136; 102, 137; 102, 138; 110, 139; 111, 140; 111, 141; 112, 142; 115, 143; 116, 144; 119, 145; 122, 146; 122, 147; 125, 148; 127, 149; 127, 150; 129, 151; 129, 152; 130, 153; 130, 154; 131, 155; 132, 156; 132, 157; 133, 158; 136, 159; 137, 160; 137, 161; 138, 162; 142, 163; 142, 164; 147, 165; 147, 166; 150, 167; 150, 168; 151, 169; 151, 170; 152, 171; 162, 172; 167, 173; 167, 174; 168, 175; 171, 176; 171, 177; 174, 178
def create_logger(self, args={}): """ Create and configure the program's logger object. Log levels: DEBUG - Log everything. Hidden unless --debug is used. INFO - information only ERROR - Critical error :param args: Object containing program's parsed command line arguments :return: None """ # Set up logging logger = logging.getLogger("SmartFileSorter") logger.level = logging.INFO if '--debug' in args and args['--debug'] is True: logger.setLevel(logging.DEBUG) file_log_formatter = logging.Formatter('%(asctime)s %(name)s %(levelname)s %(message)s', '%Y-%m-%d %H:%M:%S') console_log_formatter = logging.Formatter('%(message)s') # Log to stdout stdout_stream = logging.StreamHandler(stream=sys.stdout) stdout_stream.setFormatter(console_log_formatter) logger.addHandler(stdout_stream) # Log to file if the option is chosen if '--log' in args and args['--log'] is not None: logfile = open(args['--log'], 'w') logfile_stream = logging.StreamHandler(stream=logfile) logfile_stream.setFormatter(file_log_formatter) logger.addHandler(logfile_stream) if '--dry-run' in args and args['--dry-run'] is True: logger.info('Running with --dry-run parameter. Actions will not be performed.') self.logger = logger
0, module; 1, function_definition; 2, function_name:get; 3, parameters; 4, block; 5, identifier:self; 6, identifier:slug; 7, expression_statement; 8, expression_statement; 9, comment:# check if is accessible from api; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, expression_statement; 14, expression_statement; 15, expression_statement; 16, expression_statement; 17, expression_statement; 18, expression_statement; 19, expression_statement; 20, expression_statement; 21, return_statement; 22, comment:"""Get KnwKB. Url parameters: - from: filter "mappings from" - to: filter "mappings to" - page - per_page - match_type: s=substring, e=exact, sw=startswith - sortby: 'from' or 'to' """; 23, assignment; 24, call; 25, assignment; 26, call; 27, call; 28, call; 29, call; 30, call; 31, call; 32, assignment; 33, assignment; 34, assignment; 35, identifier:kb_dict; 36, identifier:kb; 37, call; 38, identifier:check_knowledge_access; 39, argument_list; 40, identifier:parser; 41, call; 42, attribute; 43, argument_list; 44, attribute; 45, argument_list; 46, attribute; 47, argument_list; 48, attribute; 49, argument_list; 50, attribute; 51, argument_list; 52, attribute; 53, argument_list; 54, identifier:args; 55, call; 56, identifier:kb_dict; 57, call; 58, subscript; 59, call; 60, attribute; 61, argument_list; 62, identifier:kb; 63, attribute; 64, argument_list; 65, identifier:parser; 66, identifier:add_argument; 67, string; 68, keyword_argument; 69, keyword_argument; 70, identifier:parser; 71, identifier:add_argument; 72, string; 73, keyword_argument; 74, keyword_argument; 75, identifier:parser; 76, identifier:add_argument; 77, string; 78, keyword_argument; 79, keyword_argument; 80, identifier:parser; 81, identifier:add_argument; 82, string; 83, keyword_argument; 84, keyword_argument; 85, identifier:parser; 86, identifier:add_argument; 87, string; 88, keyword_argument; 89, keyword_argument; 90, identifier:parser; 91, identifier:add_argument; 92, string; 93, keyword_argument; 94, keyword_argument; 95, attribute; 96, argument_list; 97, attribute; 98, argument_list; 99, identifier:kb_dict; 100, string; 101, attribute; 102, argument_list; 103, identifier:api; 104, identifier:get_kb_by_slug; 105, identifier:slug; 106, identifier:reqparse; 107, identifier:RequestParser; 108, string_content:from; 109, identifier:type; 110, identifier:str; 111, identifier:help; 112, string:"Return only entries where key matches this."; 113, string_content:to; 114, identifier:type; 115, identifier:str; 116, identifier:help; 117, string:"Return only entries where value matches this."; 118, string_content:page; 119, identifier:type; 120, identifier:int; 121, identifier:help; 122, string:"Require a specific page"; 123, string_content:per_page; 124, identifier:type; 125, identifier:int; 126, identifier:help; 127, string:"Set how much result per page"; 128, string_content:match_type; 129, identifier:type; 130, identifier:str; 131, identifier:help; 132, string:"s=substring, e=exact, sw=startswith"; 133, string_content:sortby; 134, identifier:type; 135, identifier:str; 136, identifier:help; 137, string:"the sorting criteria ('from' or 'to')"; 138, identifier:parser; 139, identifier:parse_args; 140, identifier:kb; 141, identifier:to_dict; 142, string_content:mappings; 143, identifier:KnwKBMappingsResource; 144, line_continuation:\; 145, identifier:search_mappings; 146, keyword_argument; 147, keyword_argument; 148, keyword_argument; 149, keyword_argument; 150, keyword_argument; 151, keyword_argument; 152, keyword_argument; 153, identifier:kb; 154, identifier:kb; 155, identifier:key; 156, subscript; 157, identifier:value; 158, subscript; 159, identifier:match_type; 160, subscript; 161, identifier:sortby; 162, subscript; 163, identifier:page; 164, subscript; 165, identifier:per_page; 166, subscript; 167, identifier:args; 168, string; 169, identifier:args; 170, string; 171, identifier:args; 172, string; 173, identifier:args; 174, string; 175, identifier:args; 176, string; 177, identifier:args; 178, string; 179, string_content:from; 180, string_content:to; 181, string_content:match_type; 182, string_content:sortby; 183, string_content:page; 184, string_content:per_page
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 4, 17; 4, 18; 4, 19; 4, 20; 4, 21; 7, 22; 8, 23; 10, 24; 11, 25; 12, 26; 13, 27; 14, 28; 15, 29; 16, 30; 17, 31; 18, 32; 19, 33; 20, 34; 21, 35; 23, 36; 23, 37; 24, 38; 24, 39; 25, 40; 25, 41; 26, 42; 26, 43; 27, 44; 27, 45; 28, 46; 28, 47; 29, 48; 29, 49; 30, 50; 30, 51; 31, 52; 31, 53; 32, 54; 32, 55; 33, 56; 33, 57; 34, 58; 34, 59; 37, 60; 37, 61; 39, 62; 41, 63; 41, 64; 42, 65; 42, 66; 43, 67; 43, 68; 43, 69; 44, 70; 44, 71; 45, 72; 45, 73; 45, 74; 46, 75; 46, 76; 47, 77; 47, 78; 47, 79; 48, 80; 48, 81; 49, 82; 49, 83; 49, 84; 50, 85; 50, 86; 51, 87; 51, 88; 51, 89; 52, 90; 52, 91; 53, 92; 53, 93; 53, 94; 55, 95; 55, 96; 57, 97; 57, 98; 58, 99; 58, 100; 59, 101; 59, 102; 60, 103; 60, 104; 61, 105; 63, 106; 63, 107; 67, 108; 68, 109; 68, 110; 69, 111; 69, 112; 72, 113; 73, 114; 73, 115; 74, 116; 74, 117; 77, 118; 78, 119; 78, 120; 79, 121; 79, 122; 82, 123; 83, 124; 83, 125; 84, 126; 84, 127; 87, 128; 88, 129; 88, 130; 89, 131; 89, 132; 92, 133; 93, 134; 93, 135; 94, 136; 94, 137; 95, 138; 95, 139; 97, 140; 97, 141; 100, 142; 101, 143; 101, 144; 101, 145; 102, 146; 102, 147; 102, 148; 102, 149; 102, 150; 102, 151; 102, 152; 146, 153; 146, 154; 147, 155; 147, 156; 148, 157; 148, 158; 149, 159; 149, 160; 150, 161; 150, 162; 151, 163; 151, 164; 152, 165; 152, 166; 156, 167; 156, 168; 158, 169; 158, 170; 160, 171; 160, 172; 162, 173; 162, 174; 164, 175; 164, 176; 166, 177; 166, 178; 168, 179; 170, 180; 172, 181; 174, 182; 176, 183; 178, 184
def get(self, slug): """Get KnwKB. Url parameters: - from: filter "mappings from" - to: filter "mappings to" - page - per_page - match_type: s=substring, e=exact, sw=startswith - sortby: 'from' or 'to' """ kb = api.get_kb_by_slug(slug) # check if is accessible from api check_knowledge_access(kb) parser = reqparse.RequestParser() parser.add_argument( 'from', type=str, help="Return only entries where key matches this.") parser.add_argument( 'to', type=str, help="Return only entries where value matches this.") parser.add_argument('page', type=int, help="Require a specific page") parser.add_argument('per_page', type=int, help="Set how much result per page") parser.add_argument('match_type', type=str, help="s=substring, e=exact, sw=startswith") parser.add_argument('sortby', type=str, help="the sorting criteria ('from' or 'to')") args = parser.parse_args() kb_dict = kb.to_dict() kb_dict['mappings'] = KnwKBMappingsResource \ .search_mappings(kb=kb, key=args['from'], value=args['to'], match_type=args['match_type'], sortby=args['sortby'], page=args['page'], per_page=args['per_page']) return kb_dict