nodes
stringlengths
501
22.4k
edges
stringlengths
138
5.07k
code
stringlengths
108
19.3k
0, module; 1, function_definition; 2, function_name:gather_categories; 3, parameters; 4, block; 5, identifier:imap; 6, identifier:header; 7, default_parameter; 8, expression_statement; 9, comment:# If no categories provided, return all SampleIDs; 10, if_statement; 11, expression_statement; 12, expression_statement; 13, expression_statement; 14, for_statement; 15, comment:# If invalid categories or conditions identified, return all SampleIDs; 16, if_statement; 17, comment:#If only category column given, return column-wise SampleIDs; 18, if_statement; 19, comment:# Collect all condition names; 20, expression_statement; 21, for_statement; 22, expression_statement; 23, comment:# If column name and condition given, return overlapping SampleIDs of column and; 24, comment:# condition combinations; 25, for_statement; 26, try_statement; 27, identifier:categories; 28, None; 29, comment:""" Find the user specified categories in the map and create a dictionary to contain the relevant data for each type within the categories. Multiple categories will have their types combined such that each possible combination will have its own entry in the dictionary. :type imap: dict :param imap: The input mapping file data keyed by SampleID :type header: list :param header: The header line from the input mapping file. This will be searched for the user-specified categories :type categories: list :param categories: The list of user-specified category column name from mapping file :rtype: dict :return: A sorted dictionary keyed on the combinations of all the types found within the user-specified categories. Each entry will contain an empty DataCategory namedtuple. If no categories are specified, a single entry with the key 'default' will be returned """; 30, comparison_operator:categories is None; 31, block; 32, assignment; 33, assignment; 34, assignment; 35, pattern_list; 36, call; 37, block; 38, boolean_operator; 39, block; 40, boolean_operator; 41, block; 42, assignment; 43, identifier:k; 44, identifier:conditions; 45, block; 46, assignment; 47, pattern_list; 48, call; 49, block; 50, block; 51, except_clause; 52, else_clause; 53, identifier:categories; 54, None; 55, return_statement; 56, identifier:cat_ids; 57, list_comprehension; 58, identifier:table; 59, call; 60, identifier:conditions; 61, call; 62, identifier:i; 63, identifier:cat; 64, identifier:enumerate; 65, argument_list; 66, if_statement; 67, not_operator; 68, not_operator; 69, return_statement; 70, identifier:cat_ids; 71, not_operator; 72, for_statement; 73, return_statement; 74, identifier:cond_ids; 75, call; 76, try_statement; 77, identifier:idx_to_test; 78, call; 79, identifier:sid; 80, identifier:row; 81, attribute; 82, argument_list; 83, if_statement; 84, assert_statement; 85, identifier:AssertionError; 86, block; 87, block; 88, dictionary; 89, call; 90, for_in_clause; 91, if_clause; 92, identifier:OrderedDict; 93, argument_list; 94, identifier:defaultdict; 95, argument_list; 96, identifier:categories; 97, boolean_operator; 98, block; 99, identifier:cat_ids; 100, identifier:conditions; 101, dictionary; 102, identifier:conditions; 103, pattern_list; 104, call; 105, block; 106, identifier:table; 107, identifier:set; 108, argument_list; 109, block; 110, except_clause; 111, attribute; 112, argument_list; 113, identifier:imap; 114, identifier:items; 115, call; 116, block; 117, comparison_operator:len(table) > 0; 118, return_statement; 119, return_statement; 120, pair; 121, attribute; 122, argument_list; 123, identifier:cat; 124, identifier:categories; 125, boolean_operator; 126, identifier:set; 127, comparison_operator:"=" in cat; 128, comparison_operator:cat.split("=")[0] in header; 129, expression_statement; 130, expression_statement; 131, pair; 132, identifier:sid; 133, identifier:row; 134, attribute; 135, argument_list; 136, expression_statement; 137, if_statement; 138, expression_statement; 139, expression_statement; 140, identifier:ValueError; 141, block; 142, call; 143, identifier:union; 144, identifier:cond_ids; 145, identifier:all; 146, argument_list; 147, expression_statement; 148, try_statement; 149, expression_statement; 150, call; 151, integer:0; 152, dictionary; 153, identifier:table; 154, string:"default"; 155, call; 156, identifier:header; 157, identifier:index; 158, identifier:cat; 159, comparison_operator:cat in header; 160, comparison_operator:"=" not in cat; 161, string:"="; 162, identifier:cat; 163, subscript; 164, identifier:header; 165, assignment; 166, call; 167, string:"default"; 168, call; 169, identifier:imap; 170, identifier:items; 171, assignment; 172, comparison_operator:cat_name not in table; 173, block; 174, call; 175, call; 176, continue_statement; 177, identifier:set; 178, argument_list; 179, list_comprehension; 180, assignment; 181, block; 182, except_clause; 183, call; 184, identifier:len; 185, argument_list; 186, pair; 187, identifier:DataCategory; 188, argument_list; 189, identifier:cat; 190, identifier:header; 191, string:"="; 192, identifier:cat; 193, call; 194, integer:0; 195, identifier:cat_name; 196, subscript; 197, attribute; 198, argument_list; 199, identifier:DataCategory; 200, argument_list; 201, identifier:cat_name; 202, call; 203, identifier:cat_name; 204, identifier:table; 205, expression_statement; 206, attribute; 207, argument_list; 208, attribute; 209, argument_list; 210, identifier:cat_ids; 211, comparison_operator:row[header.index(c)] in conditions[c]; 212, for_in_clause; 213, identifier:key; 214, call; 215, assert_statement; 216, identifier:AssertionError; 217, block; 218, attribute; 219, argument_list; 220, identifier:table; 221, string:"default"; 222, call; 223, call; 224, dictionary; 225, attribute; 226, argument_list; 227, identifier:header; 228, call; 229, subscript; 230, identifier:add; 231, subscript; 232, call; 233, dictionary; 234, attribute; 235, argument_list; 236, assignment; 237, attribute; 238, identifier:add; 239, identifier:sid; 240, identifier:cond_ids; 241, identifier:add; 242, call; 243, subscript; 244, subscript; 245, identifier:c; 246, identifier:conditions; 247, attribute; 248, argument_list; 249, comparison_operator:key in table.keys(); 250, expression_statement; 251, attribute; 252, identifier:add; 253, identifier:sid; 254, identifier:DataCategory; 255, argument_list; 256, identifier:set; 257, argument_list; 258, identifier:cat; 259, identifier:split; 260, string:"="; 261, attribute; 262, argument_list; 263, identifier:conditions; 264, identifier:cat_name; 265, call; 266, integer:1; 267, identifier:set; 268, argument_list; 269, string:"_"; 270, identifier:join; 271, list_comprehension; 272, subscript; 273, call; 274, subscript; 275, identifier:sids; 276, attribute; 277, argument_list; 278, identifier:row; 279, call; 280, identifier:conditions; 281, identifier:c; 282, string:"_"; 283, identifier:join; 284, list_comprehension; 285, identifier:key; 286, call; 287, assignment; 288, subscript; 289, identifier:sids; 290, call; 291, dictionary; 292, call; 293, identifier:header; 294, identifier:index; 295, subscript; 296, attribute; 297, argument_list; 298, call; 299, subscript; 300, for_in_clause; 301, identifier:table; 302, identifier:cat_name; 303, identifier:DataCategory; 304, argument_list; 305, identifier:table; 306, identifier:cat_name; 307, identifier:header; 308, identifier:index; 309, identifier:k; 310, attribute; 311, argument_list; 312, subscript; 313, for_in_clause; 314, attribute; 315, argument_list; 316, subscript; 317, call; 318, identifier:table; 319, identifier:key; 320, identifier:set; 321, argument_list; 322, attribute; 323, argument_list; 324, call; 325, integer:0; 326, identifier:cat; 327, identifier:split; 328, string:"="; 329, attribute; 330, argument_list; 331, identifier:row; 332, identifier:cid; 333, identifier:cid; 334, identifier:cat_ids; 335, call; 336, dictionary; 337, identifier:header; 338, identifier:index; 339, identifier:c; 340, identifier:row; 341, identifier:idx; 342, identifier:idx; 343, identifier:idx_to_test; 344, identifier:table; 345, identifier:keys; 346, identifier:table; 347, identifier:key; 348, identifier:DataCategory; 349, argument_list; 350, call; 351, identifier:imap; 352, identifier:keys; 353, attribute; 354, argument_list; 355, identifier:imap; 356, identifier:keys; 357, identifier:set; 358, argument_list; 359, call; 360, dictionary; 361, attribute; 362, argument_list; 363, identifier:cat; 364, identifier:split; 365, string:"="; 366, identifier:set; 367, argument_list; 368, identifier:imap; 369, identifier:keys
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; 4, 22; 4, 23; 4, 24; 4, 25; 4, 26; 7, 27; 7, 28; 8, 29; 10, 30; 10, 31; 11, 32; 12, 33; 13, 34; 14, 35; 14, 36; 14, 37; 16, 38; 16, 39; 18, 40; 18, 41; 20, 42; 21, 43; 21, 44; 21, 45; 22, 46; 25, 47; 25, 48; 25, 49; 26, 50; 26, 51; 26, 52; 30, 53; 30, 54; 31, 55; 32, 56; 32, 57; 33, 58; 33, 59; 34, 60; 34, 61; 35, 62; 35, 63; 36, 64; 36, 65; 37, 66; 38, 67; 38, 68; 39, 69; 40, 70; 40, 71; 41, 72; 41, 73; 42, 74; 42, 75; 45, 76; 46, 77; 46, 78; 47, 79; 47, 80; 48, 81; 48, 82; 49, 83; 50, 84; 51, 85; 51, 86; 52, 87; 55, 88; 57, 89; 57, 90; 57, 91; 59, 92; 59, 93; 61, 94; 61, 95; 65, 96; 66, 97; 66, 98; 67, 99; 68, 100; 69, 101; 71, 102; 72, 103; 72, 104; 72, 105; 73, 106; 75, 107; 75, 108; 76, 109; 76, 110; 78, 111; 78, 112; 81, 113; 81, 114; 83, 115; 83, 116; 84, 117; 86, 118; 87, 119; 88, 120; 89, 121; 89, 122; 90, 123; 90, 124; 91, 125; 95, 126; 97, 127; 97, 128; 98, 129; 98, 130; 101, 131; 103, 132; 103, 133; 104, 134; 104, 135; 105, 136; 105, 137; 105, 138; 109, 139; 110, 140; 110, 141; 111, 142; 111, 143; 112, 144; 115, 145; 115, 146; 116, 147; 116, 148; 116, 149; 117, 150; 117, 151; 118, 152; 119, 153; 120, 154; 120, 155; 121, 156; 121, 157; 122, 158; 125, 159; 125, 160; 127, 161; 127, 162; 128, 163; 128, 164; 129, 165; 130, 166; 131, 167; 131, 168; 134, 169; 134, 170; 136, 171; 137, 172; 137, 173; 138, 174; 139, 175; 141, 176; 142, 177; 142, 178; 146, 179; 147, 180; 148, 181; 148, 182; 149, 183; 150, 184; 150, 185; 152, 186; 155, 187; 155, 188; 159, 189; 159, 190; 160, 191; 160, 192; 163, 193; 163, 194; 165, 195; 165, 196; 166, 197; 166, 198; 168, 199; 168, 200; 171, 201; 171, 202; 172, 203; 172, 204; 173, 205; 174, 206; 174, 207; 175, 208; 175, 209; 178, 210; 179, 211; 179, 212; 180, 213; 180, 214; 181, 215; 182, 216; 182, 217; 183, 218; 183, 219; 185, 220; 186, 221; 186, 222; 188, 223; 188, 224; 193, 225; 193, 226; 196, 227; 196, 228; 197, 229; 197, 230; 198, 231; 200, 232; 200, 233; 202, 234; 202, 235; 205, 236; 206, 237; 206, 238; 207, 239; 208, 240; 208, 241; 209, 242; 211, 243; 211, 244; 212, 245; 212, 246; 214, 247; 214, 248; 215, 249; 217, 250; 218, 251; 218, 252; 219, 253; 222, 254; 222, 255; 223, 256; 223, 257; 225, 258; 225, 259; 226, 260; 228, 261; 228, 262; 229, 263; 229, 264; 231, 265; 231, 266; 232, 267; 232, 268; 234, 269; 234, 270; 235, 271; 236, 272; 236, 273; 237, 274; 237, 275; 242, 276; 242, 277; 243, 278; 243, 279; 244, 280; 244, 281; 247, 282; 247, 283; 248, 284; 249, 285; 249, 286; 250, 287; 251, 288; 251, 289; 255, 290; 255, 291; 257, 292; 261, 293; 261, 294; 262, 295; 265, 296; 265, 297; 268, 298; 271, 299; 271, 300; 272, 301; 272, 302; 273, 303; 273, 304; 274, 305; 274, 306; 276, 307; 276, 308; 277, 309; 279, 310; 279, 311; 284, 312; 284, 313; 286, 314; 286, 315; 287, 316; 287, 317; 288, 318; 288, 319; 290, 320; 290, 321; 292, 322; 292, 323; 295, 324; 295, 325; 296, 326; 296, 327; 297, 328; 298, 329; 298, 330; 299, 331; 299, 332; 300, 333; 300, 334; 304, 335; 304, 336; 310, 337; 310, 338; 311, 339; 312, 340; 312, 341; 313, 342; 313, 343; 314, 344; 314, 345; 316, 346; 316, 347; 317, 348; 317, 349; 321, 350; 322, 351; 322, 352; 324, 353; 324, 354; 329, 355; 329, 356; 335, 357; 335, 358; 349, 359; 349, 360; 350, 361; 350, 362; 353, 363; 353, 364; 354, 365; 359, 366; 359, 367; 361, 368; 361, 369
def gather_categories(imap, header, categories=None): """ Find the user specified categories in the map and create a dictionary to contain the relevant data for each type within the categories. Multiple categories will have their types combined such that each possible combination will have its own entry in the dictionary. :type imap: dict :param imap: The input mapping file data keyed by SampleID :type header: list :param header: The header line from the input mapping file. This will be searched for the user-specified categories :type categories: list :param categories: The list of user-specified category column name from mapping file :rtype: dict :return: A sorted dictionary keyed on the combinations of all the types found within the user-specified categories. Each entry will contain an empty DataCategory namedtuple. If no categories are specified, a single entry with the key 'default' will be returned """ # If no categories provided, return all SampleIDs if categories is None: return {"default": DataCategory(set(imap.keys()), {})} cat_ids = [header.index(cat) for cat in categories if cat in header and "=" not in cat] table = OrderedDict() conditions = defaultdict(set) for i, cat in enumerate(categories): if "=" in cat and cat.split("=")[0] in header: cat_name = header[header.index(cat.split("=")[0])] conditions[cat_name].add(cat.split("=")[1]) # If invalid categories or conditions identified, return all SampleIDs if not cat_ids and not conditions: return {"default": DataCategory(set(imap.keys()), {})} #If only category column given, return column-wise SampleIDs if cat_ids and not conditions: for sid, row in imap.items(): cat_name = "_".join([row[cid] for cid in cat_ids]) if cat_name not in table: table[cat_name] = DataCategory(set(), {}) table[cat_name].sids.add(sid) return table # Collect all condition names cond_ids = set() for k in conditions: try: cond_ids.add(header.index(k)) except ValueError: continue idx_to_test = set(cat_ids).union(cond_ids) # If column name and condition given, return overlapping SampleIDs of column and # condition combinations for sid, row in imap.items(): if all([row[header.index(c)] in conditions[c] for c in conditions]): key = "_".join([row[idx] for idx in idx_to_test]) try: assert key in table.keys() except AssertionError: table[key] = DataCategory(set(), {}) table[key].sids.add(sid) try: assert len(table) > 0 except AssertionError: return {"default": DataCategory(set(imap.keys()), {})} else: return table
0, module; 1, function_definition; 2, function_name:sort_sam; 3, parameters; 4, block; 5, identifier:sam; 6, identifier:sort; 7, expression_statement; 8, expression_statement; 9, if_statement; 10, return_statement; 11, comment:""" sort sam file """; 12, assignment; 13, comparison_operator:sort is True; 14, block; 15, else_clause; 16, identifier:mapping; 17, identifier:tempdir; 18, binary_operator:'%s/' % (os.path.abspath(sam).rsplit('/', 1)[0]); 19, identifier:sort; 20, True; 21, expression_statement; 22, if_statement; 23, expression_statement; 24, block; 25, string; 26, parenthesized_expression; 27, assignment; 28, comparison_operator:sam != '-'; 29, block; 30, else_clause; 31, assignment; 32, if_statement; 33, string_content:%s/; 34, subscript; 35, identifier:mapping; 36, binary_operator:'%s.sorted.sam' % (sam.rsplit('.', 1)[0]); 37, identifier:sam; 38, string; 39, if_statement; 40, block; 41, identifier:mapping; 42, call; 43, comparison_operator:sam == '-'; 44, block; 45, else_clause; 46, call; 47, integer:0; 48, string; 49, parenthesized_expression; 50, string_content:-; 51, comparison_operator:os.path.exists(mapping) is False; 52, block; 53, expression_statement; 54, expression_statement; 55, expression_statement; 56, identifier:open; 57, argument_list; 58, identifier:sam; 59, string; 60, expression_statement; 61, block; 62, attribute; 63, argument_list; 64, string_content:%s.sorted.sam; 65, subscript; 66, call; 67, False; 68, expression_statement; 69, assignment; 70, assignment; 71, call; 72, identifier:mapping; 73, string_content:-; 74, assignment; 75, expression_statement; 76, call; 77, identifier:rsplit; 78, string; 79, integer:1; 80, call; 81, integer:0; 82, attribute; 83, argument_list; 84, call; 85, identifier:mapping; 86, string; 87, identifier:p; 88, call; 89, attribute; 90, argument_list; 91, identifier:mapping; 92, attribute; 93, assignment; 94, attribute; 95, argument_list; 96, string_content:/; 97, attribute; 98, argument_list; 99, attribute; 100, identifier:exists; 101, identifier:mapping; 102, attribute; 103, argument_list; 104, string_content:stdin-sam.sorted.sam; 105, identifier:Popen; 106, argument_list; 107, identifier:p; 108, identifier:communicate; 109, identifier:sys; 110, identifier:stdin; 111, identifier:mapping; 112, call; 113, attribute; 114, identifier:abspath; 115, identifier:sam; 116, identifier:sam; 117, identifier:rsplit; 118, string; 119, integer:1; 120, identifier:os; 121, identifier:path; 122, identifier:os; 123, identifier:system; 124, binary_operator:"\ sort -k1 --buffer-size=%sG -T %s -o %s %s\ " % (sbuffer, tempdir, mapping, sam); 125, binary_operator:"sort -k1 --buffer-size=%sG -T %s -o %s" \ % (sbuffer, tempdir, mapping); 126, keyword_argument; 127, keyword_argument; 128, identifier:open; 129, argument_list; 130, identifier:os; 131, identifier:path; 132, string_content:.; 133, string:"\ sort -k1 --buffer-size=%sG -T %s -o %s %s\ "; 134, tuple; 135, string:"sort -k1 --buffer-size=%sG -T %s -o %s"; 136, line_continuation:\; 137, tuple; 138, identifier:stdin; 139, attribute; 140, identifier:shell; 141, True; 142, identifier:sam; 143, identifier:sbuffer; 144, identifier:tempdir; 145, identifier:mapping; 146, identifier:sam; 147, identifier:sbuffer; 148, identifier:tempdir; 149, identifier:mapping; 150, identifier:sys; 151, identifier:stdin
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 7, 11; 8, 12; 9, 13; 9, 14; 9, 15; 10, 16; 12, 17; 12, 18; 13, 19; 13, 20; 14, 21; 14, 22; 14, 23; 15, 24; 18, 25; 18, 26; 21, 27; 22, 28; 22, 29; 22, 30; 23, 31; 24, 32; 25, 33; 26, 34; 27, 35; 27, 36; 28, 37; 28, 38; 29, 39; 30, 40; 31, 41; 31, 42; 32, 43; 32, 44; 32, 45; 34, 46; 34, 47; 36, 48; 36, 49; 38, 50; 39, 51; 39, 52; 40, 53; 40, 54; 40, 55; 42, 56; 42, 57; 43, 58; 43, 59; 44, 60; 45, 61; 46, 62; 46, 63; 48, 64; 49, 65; 51, 66; 51, 67; 52, 68; 53, 69; 54, 70; 55, 71; 57, 72; 59, 73; 60, 74; 61, 75; 62, 76; 62, 77; 63, 78; 63, 79; 65, 80; 65, 81; 66, 82; 66, 83; 68, 84; 69, 85; 69, 86; 70, 87; 70, 88; 71, 89; 71, 90; 74, 91; 74, 92; 75, 93; 76, 94; 76, 95; 78, 96; 80, 97; 80, 98; 82, 99; 82, 100; 83, 101; 84, 102; 84, 103; 86, 104; 88, 105; 88, 106; 89, 107; 89, 108; 92, 109; 92, 110; 93, 111; 93, 112; 94, 113; 94, 114; 95, 115; 97, 116; 97, 117; 98, 118; 98, 119; 99, 120; 99, 121; 102, 122; 102, 123; 103, 124; 106, 125; 106, 126; 106, 127; 112, 128; 112, 129; 113, 130; 113, 131; 118, 132; 124, 133; 124, 134; 125, 135; 125, 136; 125, 137; 126, 138; 126, 139; 127, 140; 127, 141; 129, 142; 134, 143; 134, 144; 134, 145; 134, 146; 137, 147; 137, 148; 137, 149; 139, 150; 139, 151
def sort_sam(sam, sort): """ sort sam file """ tempdir = '%s/' % (os.path.abspath(sam).rsplit('/', 1)[0]) if sort is True: mapping = '%s.sorted.sam' % (sam.rsplit('.', 1)[0]) if sam != '-': if os.path.exists(mapping) is False: os.system("\ sort -k1 --buffer-size=%sG -T %s -o %s %s\ " % (sbuffer, tempdir, mapping, sam)) else: mapping = 'stdin-sam.sorted.sam' p = Popen("sort -k1 --buffer-size=%sG -T %s -o %s" \ % (sbuffer, tempdir, mapping), stdin = sys.stdin, shell = True) p.communicate() mapping = open(mapping) else: if sam == '-': mapping = sys.stdin else: mapping = open(sam) return mapping
0, module; 1, function_definition; 2, function_name:top_hits; 3, parameters; 4, block; 5, identifier:hits; 6, identifier:num; 7, identifier:column; 8, identifier:reverse; 9, expression_statement; 10, expression_statement; 11, for_statement; 12, comment:""" get top hits after sorting by column number """; 13, call; 14, identifier:hit; 15, subscript; 16, block; 17, attribute; 18, argument_list; 19, identifier:hits; 20, slice; 21, expression_statement; 22, identifier:hits; 23, identifier:sort; 24, keyword_argument; 25, keyword_argument; 26, integer:0; 27, identifier:num; 28, yield; 29, identifier:key; 30, call; 31, identifier:reverse; 32, identifier:reverse; 33, identifier:hit; 34, identifier:itemgetter; 35, argument_list; 36, identifier:column
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, 9; 4, 10; 4, 11; 9, 12; 10, 13; 11, 14; 11, 15; 11, 16; 13, 17; 13, 18; 15, 19; 15, 20; 16, 21; 17, 22; 17, 23; 18, 24; 18, 25; 20, 26; 20, 27; 21, 28; 24, 29; 24, 30; 25, 31; 25, 32; 28, 33; 30, 34; 30, 35; 35, 36
def top_hits(hits, num, column, reverse): """ get top hits after sorting by column number """ hits.sort(key = itemgetter(column), reverse = reverse) for hit in hits[0:num]: yield hit
0, module; 1, function_definition; 2, function_name:numBlast_sort; 3, parameters; 4, block; 5, identifier:blast; 6, identifier:numHits; 7, identifier:evalueT; 8, identifier:bitT; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, for_statement; 14, expression_statement; 15, for_statement; 16, comment:""" parse b6 output with sorting """; 17, assignment; 18, yield; 19, assignment; 20, identifier:line; 21, identifier:blast; 22, block; 23, assignment; 24, pattern_list; 25, call; 26, block; 27, identifier:header; 28, list; 29, identifier:header; 30, identifier:hmm; 31, dictionary_comprehension; 32, if_statement; 33, expression_statement; 34, comment:# Evalue and Bitscore thresholds; 35, expression_statement; 36, expression_statement; 37, if_statement; 38, if_statement; 39, for_statement; 40, identifier:hmm; 41, call; 42, identifier:query; 43, identifier:df; 44, attribute; 45, argument_list; 46, expression_statement; 47, for_statement; 48, string; 49, string; 50, string; 51, string; 52, string; 53, string; 54, string; 55, string; 56, string; 57, string; 58, string; 59, string; 60, pair; 61, for_in_clause; 62, call; 63, block; 64, assignment; 65, assignment; 66, assignment; 67, boolean_operator; 68, block; 69, boolean_operator; 70, block; 71, pattern_list; 72, call; 73, block; 74, attribute; 75, argument_list; 76, identifier:hmm; 77, identifier:groupby; 78, keyword_argument; 79, assignment; 80, identifier:hit; 81, subscript; 82, block; 83, string_content:#query; 84, string_content:target; 85, string_content:pident; 86, string_content:alen; 87, string_content:mismatch; 88, string_content:gapopen; 89, string_content:qstart; 90, string_content:qend; 91, string_content:tstart; 92, string_content:tend; 93, string_content:evalue; 94, string_content:bitscore; 95, identifier:h; 96, list; 97, identifier:h; 98, identifier:header; 99, attribute; 100, argument_list; 101, continue_statement; 102, identifier:line; 103, call; 104, pattern_list; 105, expression_list; 106, pattern_list; 107, expression_list; 108, comparison_operator:evalueT is not False; 109, comparison_operator:evalue > evalueT; 110, continue_statement; 111, comparison_operator:bitT is not False; 112, comparison_operator:bit < bitT; 113, continue_statement; 114, identifier:i; 115, identifier:h; 116, identifier:zip; 117, argument_list; 118, expression_statement; 119, identifier:pd; 120, identifier:DataFrame; 121, identifier:hmm; 122, identifier:by; 123, list; 124, identifier:df; 125, call; 126, attribute; 127, slice; 128, expression_statement; 129, identifier:line; 130, identifier:startswith; 131, string; 132, attribute; 133, argument_list; 134, subscript; 135, subscript; 136, call; 137, call; 138, identifier:evalue; 139, identifier:bit; 140, subscript; 141, subscript; 142, identifier:evalueT; 143, False; 144, identifier:evalue; 145, identifier:evalueT; 146, identifier:bitT; 147, False; 148, identifier:bit; 149, identifier:bitT; 150, identifier:line; 151, identifier:header; 152, call; 153, string; 154, attribute; 155, argument_list; 156, subscript; 157, identifier:values; 158, integer:0; 159, identifier:numHits; 160, yield; 161, string_content:#; 162, call; 163, identifier:split; 164, string; 165, identifier:line; 166, integer:10; 167, identifier:line; 168, integer:11; 169, identifier:float; 170, argument_list; 171, identifier:float; 172, argument_list; 173, identifier:line; 174, integer:10; 175, identifier:line; 176, integer:11; 177, attribute; 178, argument_list; 179, string_content:#query; 180, identifier:df; 181, identifier:sort_values; 182, keyword_argument; 183, keyword_argument; 184, identifier:df; 185, identifier:header; 186, identifier:hit; 187, attribute; 188, argument_list; 189, string_content; 190, subscript; 191, subscript; 192, subscript; 193, identifier:append; 194, identifier:i; 195, identifier:by; 196, list; 197, identifier:ascending; 198, False; 199, identifier:line; 200, identifier:strip; 201, escape_sequence:\t; 202, identifier:line; 203, integer:10; 204, identifier:line; 205, integer:11; 206, identifier:hmm; 207, identifier:h; 208, string; 209, string_content:bitscore
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; 9, 16; 10, 17; 11, 18; 12, 19; 13, 20; 13, 21; 13, 22; 14, 23; 15, 24; 15, 25; 15, 26; 17, 27; 17, 28; 18, 29; 19, 30; 19, 31; 22, 32; 22, 33; 22, 34; 22, 35; 22, 36; 22, 37; 22, 38; 22, 39; 23, 40; 23, 41; 24, 42; 24, 43; 25, 44; 25, 45; 26, 46; 26, 47; 28, 48; 28, 49; 28, 50; 28, 51; 28, 52; 28, 53; 28, 54; 28, 55; 28, 56; 28, 57; 28, 58; 28, 59; 31, 60; 31, 61; 32, 62; 32, 63; 33, 64; 35, 65; 36, 66; 37, 67; 37, 68; 38, 69; 38, 70; 39, 71; 39, 72; 39, 73; 41, 74; 41, 75; 44, 76; 44, 77; 45, 78; 46, 79; 47, 80; 47, 81; 47, 82; 48, 83; 49, 84; 50, 85; 51, 86; 52, 87; 53, 88; 54, 89; 55, 90; 56, 91; 57, 92; 58, 93; 59, 94; 60, 95; 60, 96; 61, 97; 61, 98; 62, 99; 62, 100; 63, 101; 64, 102; 64, 103; 65, 104; 65, 105; 66, 106; 66, 107; 67, 108; 67, 109; 68, 110; 69, 111; 69, 112; 70, 113; 71, 114; 71, 115; 72, 116; 72, 117; 73, 118; 74, 119; 74, 120; 75, 121; 78, 122; 78, 123; 79, 124; 79, 125; 81, 126; 81, 127; 82, 128; 99, 129; 99, 130; 100, 131; 103, 132; 103, 133; 104, 134; 104, 135; 105, 136; 105, 137; 106, 138; 106, 139; 107, 140; 107, 141; 108, 142; 108, 143; 109, 144; 109, 145; 111, 146; 111, 147; 112, 148; 112, 149; 117, 150; 117, 151; 118, 152; 123, 153; 125, 154; 125, 155; 126, 156; 126, 157; 127, 158; 127, 159; 128, 160; 131, 161; 132, 162; 132, 163; 133, 164; 134, 165; 134, 166; 135, 167; 135, 168; 136, 169; 136, 170; 137, 171; 137, 172; 140, 173; 140, 174; 141, 175; 141, 176; 152, 177; 152, 178; 153, 179; 154, 180; 154, 181; 155, 182; 155, 183; 156, 184; 156, 185; 160, 186; 162, 187; 162, 188; 164, 189; 170, 190; 172, 191; 177, 192; 177, 193; 178, 194; 182, 195; 182, 196; 183, 197; 183, 198; 187, 199; 187, 200; 189, 201; 190, 202; 190, 203; 191, 204; 191, 205; 192, 206; 192, 207; 196, 208; 208, 209
def numBlast_sort(blast, numHits, evalueT, bitT): """ parse b6 output with sorting """ header = ['#query', 'target', 'pident', 'alen', 'mismatch', 'gapopen', 'qstart', 'qend', 'tstart', 'tend', 'evalue', 'bitscore'] yield header hmm = {h:[] for h in header} for line in blast: if line.startswith('#'): continue line = line.strip().split('\t') # Evalue and Bitscore thresholds line[10], line[11] = float(line[10]), float(line[11]) evalue, bit = line[10], line[11] if evalueT is not False and evalue > evalueT: continue if bitT is not False and bit < bitT: continue for i, h in zip(line, header): hmm[h].append(i) hmm = pd.DataFrame(hmm) for query, df in hmm.groupby(by = ['#query']): df = df.sort_values(by = ['bitscore'], ascending = False) for hit in df[header].values[0:numHits]: yield hit
0, module; 1, function_definition; 2, function_name:numDomtblout; 3, parameters; 4, block; 5, identifier:domtblout; 6, identifier:numHits; 7, identifier:evalueT; 8, identifier:bitT; 9, identifier:sort; 10, expression_statement; 11, if_statement; 12, expression_statement; 13, expression_statement; 14, expression_statement; 15, for_statement; 16, for_statement; 17, comment:""" parse hmm domain table output this version is faster but does not work unless the table is sorted """; 18, comparison_operator:sort is True; 19, block; 20, assignment; 21, yield; 22, assignment; 23, identifier:line; 24, identifier:domtblout; 25, block; 26, identifier:hit; 27, call; 28, block; 29, identifier:sort; 30, True; 31, for_statement; 32, return_statement; 33, identifier:header; 34, list; 35, identifier:header; 36, pattern_list; 37, expression_list; 38, if_statement; 39, comment:# parse line and get description; 40, expression_statement; 41, expression_statement; 42, expression_statement; 43, expression_statement; 44, comment:# create ID based on query name and domain number; 45, expression_statement; 46, comment:# domain c-Evalue and domain score thresholds; 47, expression_statement; 48, expression_statement; 49, expression_statement; 50, if_statement; 51, if_statement; 52, expression_statement; 53, identifier:top_hits; 54, argument_list; 55, expression_statement; 56, identifier:hit; 57, call; 58, block; 59, string; 60, string; 61, string; 62, string; 63, string; 64, string; 65, string; 66, string; 67, string; 68, string; 69, string; 70, string; 71, string; 72, string; 73, string; 74, string; 75, string; 76, string; 77, string; 78, string; 79, string; 80, string; 81, string; 82, identifier:prev; 83, identifier:hits; 84, None; 85, list; 86, call; 87, block; 88, assignment; 89, assignment; 90, assignment; 91, call; 92, assignment; 93, assignment; 94, assignment; 95, assignment; 96, comparison_operator:ID != prev; 97, block; 98, boolean_operator; 99, block; 100, elif_clause; 101, elif_clause; 102, elif_clause; 103, assignment; 104, identifier:hits; 105, identifier:numHits; 106, integer:13; 107, True; 108, yield; 109, identifier:numDomtblout_sort; 110, argument_list; 111, expression_statement; 112, string_content:#target name; 113, string_content:target accession; 114, string_content:tlen; 115, string_content:query name; 116, string_content:query accession; 117, string_content:qlen; 118, string_content:full E-value; 119, string_content:full score; 120, string_content:full bias; 121, string_content:domain #; 122, string_content:# domains; 123, string_content:domain c-Evalue; 124, string_content:domain i-Evalue; 125, string_content:domain score; 126, string_content:domain bias; 127, string_content:hmm from; 128, string_content:hmm to; 129, string_content:seq from; 130, string_content:seq to; 131, string_content:env from; 132, string_content:env to; 133, string_content:acc; 134, string_content:target description; 135, attribute; 136, argument_list; 137, continue_statement; 138, identifier:line; 139, call; 140, identifier:desc; 141, call; 142, identifier:line; 143, subscript; 144, attribute; 145, argument_list; 146, identifier:ID; 147, binary_operator:line[0] + line[9]; 148, pattern_list; 149, expression_list; 150, pattern_list; 151, expression_list; 152, pattern_list; 153, expression_list; 154, identifier:ID; 155, identifier:prev; 156, if_statement; 157, expression_statement; 158, comparison_operator:evalueT == False; 159, comparison_operator:bitT == False; 160, expression_statement; 161, boolean_operator; 162, block; 163, boolean_operator; 164, block; 165, boolean_operator; 166, block; 167, identifier:prev; 168, identifier:ID; 169, identifier:hit; 170, identifier:domtblout; 171, identifier:numHits; 172, identifier:evalueT; 173, identifier:bitT; 174, yield; 175, identifier:line; 176, identifier:startswith; 177, string; 178, attribute; 179, argument_list; 180, attribute; 181, argument_list; 182, identifier:line; 183, slice; 184, identifier:line; 185, identifier:append; 186, identifier:desc; 187, subscript; 188, subscript; 189, subscript; 190, subscript; 191, call; 192, call; 193, identifier:evalue; 194, identifier:bitscore; 195, subscript; 196, subscript; 197, subscript; 198, subscript; 199, identifier:evalue; 200, identifier:bitscore; 201, comparison_operator:len(hits) > 0; 202, block; 203, assignment; 204, identifier:evalueT; 205, False; 206, identifier:bitT; 207, False; 208, call; 209, comparison_operator:evalue <= evalueT; 210, comparison_operator:bitT == False; 211, expression_statement; 212, comparison_operator:evalue <= evalueT; 213, comparison_operator:bit >= bitT; 214, expression_statement; 215, comparison_operator:evalueT == False; 216, comparison_operator:bit >= bitT; 217, expression_statement; 218, identifier:hit; 219, string_content:#; 220, call; 221, identifier:split; 222, string; 223, identifier:join; 224, subscript; 225, integer:0; 226, integer:18; 227, identifier:line; 228, integer:0; 229, identifier:line; 230, integer:9; 231, identifier:line; 232, integer:11; 233, identifier:line; 234, integer:13; 235, identifier:float; 236, argument_list; 237, identifier:float; 238, argument_list; 239, identifier:line; 240, integer:11; 241, identifier:line; 242, integer:13; 243, identifier:line; 244, integer:11; 245, identifier:line; 246, integer:13; 247, call; 248, integer:0; 249, for_statement; 250, identifier:hits; 251, list; 252, attribute; 253, argument_list; 254, identifier:evalue; 255, identifier:evalueT; 256, identifier:bitT; 257, False; 258, call; 259, identifier:evalue; 260, identifier:evalueT; 261, identifier:bit; 262, identifier:bitT; 263, call; 264, identifier:evalueT; 265, False; 266, identifier:bit; 267, identifier:bitT; 268, call; 269, attribute; 270, argument_list; 271, string_content:; 272, identifier:line; 273, slice; 274, subscript; 275, subscript; 276, identifier:len; 277, argument_list; 278, identifier:hit; 279, call; 280, block; 281, identifier:hits; 282, identifier:append; 283, identifier:line; 284, attribute; 285, argument_list; 286, attribute; 287, argument_list; 288, attribute; 289, argument_list; 290, identifier:line; 291, identifier:strip; 292, integer:18; 293, identifier:line; 294, integer:11; 295, identifier:line; 296, integer:13; 297, identifier:hits; 298, identifier:top_hits; 299, argument_list; 300, expression_statement; 301, identifier:hits; 302, identifier:append; 303, identifier:line; 304, identifier:hits; 305, identifier:append; 306, identifier:line; 307, identifier:hits; 308, identifier:append; 309, identifier:line; 310, identifier:hits; 311, identifier:numHits; 312, integer:13; 313, True; 314, yield; 315, identifier:hit
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; 10, 17; 11, 18; 11, 19; 12, 20; 13, 21; 14, 22; 15, 23; 15, 24; 15, 25; 16, 26; 16, 27; 16, 28; 18, 29; 18, 30; 19, 31; 19, 32; 20, 33; 20, 34; 21, 35; 22, 36; 22, 37; 25, 38; 25, 39; 25, 40; 25, 41; 25, 42; 25, 43; 25, 44; 25, 45; 25, 46; 25, 47; 25, 48; 25, 49; 25, 50; 25, 51; 25, 52; 27, 53; 27, 54; 28, 55; 31, 56; 31, 57; 31, 58; 34, 59; 34, 60; 34, 61; 34, 62; 34, 63; 34, 64; 34, 65; 34, 66; 34, 67; 34, 68; 34, 69; 34, 70; 34, 71; 34, 72; 34, 73; 34, 74; 34, 75; 34, 76; 34, 77; 34, 78; 34, 79; 34, 80; 34, 81; 36, 82; 36, 83; 37, 84; 37, 85; 38, 86; 38, 87; 40, 88; 41, 89; 42, 90; 43, 91; 45, 92; 47, 93; 48, 94; 49, 95; 50, 96; 50, 97; 51, 98; 51, 99; 51, 100; 51, 101; 51, 102; 52, 103; 54, 104; 54, 105; 54, 106; 54, 107; 55, 108; 57, 109; 57, 110; 58, 111; 59, 112; 60, 113; 61, 114; 62, 115; 63, 116; 64, 117; 65, 118; 66, 119; 67, 120; 68, 121; 69, 122; 70, 123; 71, 124; 72, 125; 73, 126; 74, 127; 75, 128; 76, 129; 77, 130; 78, 131; 79, 132; 80, 133; 81, 134; 86, 135; 86, 136; 87, 137; 88, 138; 88, 139; 89, 140; 89, 141; 90, 142; 90, 143; 91, 144; 91, 145; 92, 146; 92, 147; 93, 148; 93, 149; 94, 150; 94, 151; 95, 152; 95, 153; 96, 154; 96, 155; 97, 156; 97, 157; 98, 158; 98, 159; 99, 160; 100, 161; 100, 162; 101, 163; 101, 164; 102, 165; 102, 166; 103, 167; 103, 168; 108, 169; 110, 170; 110, 171; 110, 172; 110, 173; 111, 174; 135, 175; 135, 176; 136, 177; 139, 178; 139, 179; 141, 180; 141, 181; 143, 182; 143, 183; 144, 184; 144, 185; 145, 186; 147, 187; 147, 188; 148, 189; 148, 190; 149, 191; 149, 192; 150, 193; 150, 194; 151, 195; 151, 196; 152, 197; 152, 198; 153, 199; 153, 200; 156, 201; 156, 202; 157, 203; 158, 204; 158, 205; 159, 206; 159, 207; 160, 208; 161, 209; 161, 210; 162, 211; 163, 212; 163, 213; 164, 214; 165, 215; 165, 216; 166, 217; 174, 218; 177, 219; 178, 220; 178, 221; 180, 222; 180, 223; 181, 224; 183, 225; 183, 226; 187, 227; 187, 228; 188, 229; 188, 230; 189, 231; 189, 232; 190, 233; 190, 234; 191, 235; 191, 236; 192, 237; 192, 238; 195, 239; 195, 240; 196, 241; 196, 242; 197, 243; 197, 244; 198, 245; 198, 246; 201, 247; 201, 248; 202, 249; 203, 250; 203, 251; 208, 252; 208, 253; 209, 254; 209, 255; 210, 256; 210, 257; 211, 258; 212, 259; 212, 260; 213, 261; 213, 262; 214, 263; 215, 264; 215, 265; 216, 266; 216, 267; 217, 268; 220, 269; 220, 270; 222, 271; 224, 272; 224, 273; 236, 274; 238, 275; 247, 276; 247, 277; 249, 278; 249, 279; 249, 280; 252, 281; 252, 282; 253, 283; 258, 284; 258, 285; 263, 286; 263, 287; 268, 288; 268, 289; 269, 290; 269, 291; 273, 292; 274, 293; 274, 294; 275, 295; 275, 296; 277, 297; 279, 298; 279, 299; 280, 300; 284, 301; 284, 302; 285, 303; 286, 304; 286, 305; 287, 306; 288, 307; 288, 308; 289, 309; 299, 310; 299, 311; 299, 312; 299, 313; 300, 314; 314, 315
def numDomtblout(domtblout, numHits, evalueT, bitT, sort): """ parse hmm domain table output this version is faster but does not work unless the table is sorted """ if sort is True: for hit in numDomtblout_sort(domtblout, numHits, evalueT, bitT): yield hit return header = ['#target name', 'target accession', 'tlen', 'query name', 'query accession', 'qlen', 'full E-value', 'full score', 'full bias', 'domain #', '# domains', 'domain c-Evalue', 'domain i-Evalue', 'domain score', 'domain bias', 'hmm from', 'hmm to', 'seq from', 'seq to', 'env from', 'env to', 'acc', 'target description'] yield header prev, hits = None, [] for line in domtblout: if line.startswith('#'): continue # parse line and get description line = line.strip().split() desc = ' '.join(line[18:]) line = line[0:18] line.append(desc) # create ID based on query name and domain number ID = line[0] + line[9] # domain c-Evalue and domain score thresholds line[11], line[13] = float(line[11]), float(line[13]) evalue, bitscore = line[11], line[13] line[11], line[13] = evalue, bitscore if ID != prev: if len(hits) > 0: for hit in top_hits(hits, numHits, 13, True): yield hit hits = [] if evalueT == False and bitT == False: hits.append(line) elif evalue <= evalueT and bitT == False: hits.append(line) elif evalue <= evalueT and bit >= bitT: hits.append(line) elif evalueT == False and bit >= bitT: hits.append(line) prev = ID for hit in top_hits(hits, numHits, 13, True): yield hit
0, module; 1, function_definition; 2, function_name:S; 3, parameters; 4, block; 5, identifier:Document; 6, list_splat_pattern; 7, expression_statement; 8, expression_statement; 9, for_statement; 10, return_statement; 11, identifier:fields; 12, comment:"""Generate a MongoDB sort order list using the Django ORM style."""; 13, assignment; 14, identifier:field; 15, identifier:fields; 16, block; 17, identifier:result; 18, identifier:result; 19, list; 20, if_statement; 21, expression_statement; 22, if_statement; 23, if_statement; 24, if_statement; 25, expression_statement; 26, expression_statement; 27, call; 28, comment:# Unpack existing tuple.; 29, block; 30, assignment; 31, not_operator; 32, block; 33, comparison_operator:field[0] == '-'; 34, block; 35, comparison_operator:field[0] in ('+', '-'); 36, block; 37, assignment; 38, call; 39, identifier:isinstance; 40, argument_list; 41, expression_statement; 42, expression_statement; 43, continue_statement; 44, identifier:direction; 45, identifier:ASCENDING; 46, call; 47, expression_statement; 48, subscript; 49, string; 50, expression_statement; 51, subscript; 52, tuple; 53, expression_statement; 54, identifier:_field; 55, call; 56, attribute; 57, argument_list; 58, identifier:field; 59, identifier:tuple; 60, assignment; 61, call; 62, attribute; 63, argument_list; 64, assignment; 65, identifier:field; 66, integer:0; 67, string_content:-; 68, assignment; 69, identifier:field; 70, integer:0; 71, string; 72, string; 73, assignment; 74, identifier:traverse; 75, argument_list; 76, identifier:result; 77, identifier:append; 78, tuple; 79, pattern_list; 80, identifier:field; 81, attribute; 82, argument_list; 83, identifier:field; 84, identifier:startswith; 85, string; 86, identifier:field; 87, call; 88, identifier:direction; 89, identifier:DESCENDING; 90, string_content:+; 91, string_content:-; 92, identifier:field; 93, subscript; 94, identifier:Document; 95, identifier:field; 96, keyword_argument; 97, conditional_expression:(~_field) if _field else field; 98, identifier:direction; 99, identifier:field; 100, identifier:direction; 101, identifier:result; 102, identifier:append; 103, tuple; 104, string_content:__; 105, attribute; 106, argument_list; 107, identifier:field; 108, slice; 109, identifier:default; 110, None; 111, parenthesized_expression; 112, identifier:_field; 113, identifier:field; 114, identifier:field; 115, identifier:direction; 116, identifier:field; 117, identifier:replace; 118, string; 119, string; 120, integer:1; 121, unary_operator; 122, string_content:__; 123, string_content:.; 124, identifier:_field
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; 13, 18; 13, 19; 16, 20; 16, 21; 16, 22; 16, 23; 16, 24; 16, 25; 16, 26; 20, 27; 20, 28; 20, 29; 21, 30; 22, 31; 22, 32; 23, 33; 23, 34; 24, 35; 24, 36; 25, 37; 26, 38; 27, 39; 27, 40; 29, 41; 29, 42; 29, 43; 30, 44; 30, 45; 31, 46; 32, 47; 33, 48; 33, 49; 34, 50; 35, 51; 35, 52; 36, 53; 37, 54; 37, 55; 38, 56; 38, 57; 40, 58; 40, 59; 41, 60; 42, 61; 46, 62; 46, 63; 47, 64; 48, 65; 48, 66; 49, 67; 50, 68; 51, 69; 51, 70; 52, 71; 52, 72; 53, 73; 55, 74; 55, 75; 56, 76; 56, 77; 57, 78; 60, 79; 60, 80; 61, 81; 61, 82; 62, 83; 62, 84; 63, 85; 64, 86; 64, 87; 68, 88; 68, 89; 71, 90; 72, 91; 73, 92; 73, 93; 75, 94; 75, 95; 75, 96; 78, 97; 78, 98; 79, 99; 79, 100; 81, 101; 81, 102; 82, 103; 85, 104; 87, 105; 87, 106; 93, 107; 93, 108; 96, 109; 96, 110; 97, 111; 97, 112; 97, 113; 103, 114; 103, 115; 105, 116; 105, 117; 106, 118; 106, 119; 108, 120; 111, 121; 118, 122; 119, 123; 121, 124
def S(Document, *fields): """Generate a MongoDB sort order list using the Django ORM style.""" result = [] for field in fields: if isinstance(field, tuple): # Unpack existing tuple. field, direction = field result.append((field, direction)) continue direction = ASCENDING if not field.startswith('__'): field = field.replace('__', '.') if field[0] == '-': direction = DESCENDING if field[0] in ('+', '-'): field = field[1:] _field = traverse(Document, field, default=None) result.append(((~_field) if _field else field, direction)) return result
0, module; 1, function_definition; 2, function_name:arrayuniqify; 3, parameters; 4, block; 5, identifier:X; 6, default_parameter; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, if_statement; 12, identifier:retainorder; 13, False; 14, comment:""" Very fast uniqify routine for numpy arrays. **Parameters** **X** : numpy array Determine the unique elements of this numpy array. **retainorder** : Boolean, optional Whether or not to return indices corresponding to unique values of `X` that also sort the values. Default value is `False`, in which case `[D,s]` is returned. This can be used to produce a uniqified version of `X` by simply taking:: X[s][D] or:: X[s[D.nonzero()[0]]] **Returns** **D** : numpy array List of "first differences" in the sorted verion of `X`. Returned when `retainorder` is `False` (default). **s** : numpy array Permutation that will sort `X`. Returned when `retainorder` is `False` (default). **ind** : numpy array List of indices that correspond to unique values of `X`, without sorting those values. Returned when `retainorder` is `True`. **See Also:** :func:`tabular.fast.recarrayuniqify` """; 15, assignment; 16, assignment; 17, assignment; 18, identifier:retainorder; 19, block; 20, else_clause; 21, identifier:s; 22, call; 23, identifier:X; 24, subscript; 25, identifier:D; 26, call; 27, expression_statement; 28, expression_statement; 29, expression_statement; 30, return_statement; 31, block; 32, attribute; 33, argument_list; 34, identifier:X; 35, identifier:s; 36, attribute; 37, argument_list; 38, assignment; 39, assignment; 40, call; 41, identifier:ind; 42, return_statement; 43, identifier:X; 44, identifier:argsort; 45, identifier:np; 46, identifier:append; 47, list; 48, comparison_operator:X[1:] != X[:-1]; 49, identifier:DD; 50, call; 51, identifier:ind; 52, list_comprehension; 53, attribute; 54, argument_list; 55, list; 56, True; 57, subscript; 58, subscript; 59, attribute; 60, argument_list; 61, call; 62, for_in_clause; 63, identifier:ind; 64, identifier:sort; 65, identifier:D; 66, identifier:s; 67, identifier:X; 68, slice; 69, identifier:X; 70, slice; 71, identifier:np; 72, identifier:append; 73, subscript; 74, call; 75, identifier:min; 76, argument_list; 77, tuple_pattern; 78, call; 79, integer:1; 80, unary_operator; 81, call; 82, integer:0; 83, identifier:len; 84, argument_list; 85, subscript; 86, identifier:i; 87, identifier:x; 88, identifier:enumerate; 89, argument_list; 90, integer:1; 91, attribute; 92, argument_list; 93, identifier:X; 94, identifier:s; 95, slice; 96, subscript; 97, identifier:D; 98, identifier:nonzero; 99, identifier:x; 100, subscript; 101, identifier:DD; 102, slice; 103, identifier:DD; 104, binary_operator:i+1; 105, unary_operator; 106, identifier:i; 107, integer:1; 108, integer:1
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 6, 12; 6, 13; 7, 14; 8, 15; 9, 16; 10, 17; 11, 18; 11, 19; 11, 20; 15, 21; 15, 22; 16, 23; 16, 24; 17, 25; 17, 26; 19, 27; 19, 28; 19, 29; 19, 30; 20, 31; 22, 32; 22, 33; 24, 34; 24, 35; 26, 36; 26, 37; 27, 38; 28, 39; 29, 40; 30, 41; 31, 42; 32, 43; 32, 44; 36, 45; 36, 46; 37, 47; 37, 48; 38, 49; 38, 50; 39, 51; 39, 52; 40, 53; 40, 54; 42, 55; 47, 56; 48, 57; 48, 58; 50, 59; 50, 60; 52, 61; 52, 62; 53, 63; 53, 64; 55, 65; 55, 66; 57, 67; 57, 68; 58, 69; 58, 70; 59, 71; 59, 72; 60, 73; 60, 74; 61, 75; 61, 76; 62, 77; 62, 78; 68, 79; 70, 80; 73, 81; 73, 82; 74, 83; 74, 84; 76, 85; 77, 86; 77, 87; 78, 88; 78, 89; 80, 90; 81, 91; 81, 92; 84, 93; 85, 94; 85, 95; 89, 96; 91, 97; 91, 98; 95, 99; 95, 100; 96, 101; 96, 102; 100, 103; 100, 104; 102, 105; 104, 106; 104, 107; 105, 108
def arrayuniqify(X, retainorder=False): """ Very fast uniqify routine for numpy arrays. **Parameters** **X** : numpy array Determine the unique elements of this numpy array. **retainorder** : Boolean, optional Whether or not to return indices corresponding to unique values of `X` that also sort the values. Default value is `False`, in which case `[D,s]` is returned. This can be used to produce a uniqified version of `X` by simply taking:: X[s][D] or:: X[s[D.nonzero()[0]]] **Returns** **D** : numpy array List of "first differences" in the sorted verion of `X`. Returned when `retainorder` is `False` (default). **s** : numpy array Permutation that will sort `X`. Returned when `retainorder` is `False` (default). **ind** : numpy array List of indices that correspond to unique values of `X`, without sorting those values. Returned when `retainorder` is `True`. **See Also:** :func:`tabular.fast.recarrayuniqify` """ s = X.argsort() X = X[s] D = np.append([True],X[1:] != X[:-1]) if retainorder: DD = np.append(D.nonzero()[0],len(X)) ind = [min(s[x:DD[i+1]]) for (i,x) in enumerate(DD[:-1])] ind.sort() return ind else: return [D,s]
0, module; 1, function_definition; 2, function_name:equalspairs; 3, parameters; 4, block; 5, identifier:X; 6, identifier:Y; 7, expression_statement; 8, expression_statement; 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, return_statement; 18, comment:""" Indices of elements in a sorted numpy array equal to those in another. Given numpy array `X` and sorted numpy array `Y`, determine the indices in Y equal to indices in X. Returns `[A,B]` where `A` and `B` are numpy arrays of indices in `X` such that:: Y[A[i]:B[i]] = Y[Y == X[i]]` `A[i] = B[i] = 0` if `X[i]` is not in `Y`. **Parameters** **X** : numpy array Numpy array to compare to the sorted numpy array `Y`. **Y** : numpy array Sorted numpy array. Determine the indices of elements of `Y` equal to those in numpy array `X`. **Returns** **A** : numpy array List of indices in `Y`, `len(A) = len(Y)`. **B** : numpy array List of indices in `Y`, `len(B) = len(Y)`. **See Also:** :func:`tabular.fast.recarrayequalspairs` """; 19, assignment; 20, assignment; 21, assignment; 22, assignment; 23, assignment; 24, assignment; 25, assignment; 26, assignment; 27, assignment; 28, list; 29, identifier:T; 30, call; 31, identifier:R; 32, subscript; 33, identifier:R; 34, call; 35, identifier:M; 36, subscript; 37, identifier:D; 38, call; 39, identifier:T; 40, call; 41, identifier:M; 42, call; 43, identifier:A; 44, binary_operator:(T[D] == X) * D; 45, identifier:B; 46, binary_operator:(T[D] == X) * (M[D] + 1); 47, identifier:A; 48, identifier:B; 49, attribute; 50, argument_list; 51, call; 52, integer:0; 53, attribute; 54, argument_list; 55, identifier:R; 56, call; 57, attribute; 58, argument_list; 59, attribute; 60, argument_list; 61, attribute; 62, argument_list; 63, parenthesized_expression; 64, identifier:D; 65, parenthesized_expression; 66, parenthesized_expression; 67, identifier:Y; 68, identifier:copy; 69, attribute; 70, argument_list; 71, identifier:np; 72, identifier:append; 73, identifier:R; 74, call; 75, attribute; 76, argument_list; 77, identifier:T; 78, identifier:searchsorted; 79, identifier:X; 80, identifier:np; 81, identifier:append; 82, identifier:T; 83, call; 84, identifier:np; 85, identifier:append; 86, identifier:M; 87, call; 88, comparison_operator:T[D] == X; 89, comparison_operator:T[D] == X; 90, binary_operator:M[D] + 1; 91, parenthesized_expression; 92, identifier:nonzero; 93, attribute; 94, argument_list; 95, identifier:R; 96, identifier:searchsorted; 97, call; 98, attribute; 99, argument_list; 100, attribute; 101, argument_list; 102, subscript; 103, identifier:X; 104, subscript; 105, identifier:X; 106, subscript; 107, integer:1; 108, comparison_operator:T[1:] != T[:-1]; 109, identifier:np; 110, identifier:array; 111, list; 112, identifier:range; 113, argument_list; 114, identifier:np; 115, identifier:array; 116, list; 117, identifier:np; 118, identifier:array; 119, list; 120, identifier:T; 121, identifier:D; 122, identifier:T; 123, identifier:D; 124, identifier:M; 125, identifier:D; 126, subscript; 127, subscript; 128, binary_operator:len(T)-1; 129, call; 130, integer:0; 131, integer:0; 132, identifier:T; 133, slice; 134, identifier:T; 135, slice; 136, call; 137, integer:1; 138, identifier:len; 139, argument_list; 140, integer:1; 141, unary_operator; 142, identifier:len; 143, argument_list; 144, identifier:T; 145, integer:1; 146, identifier:T
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; 7, 18; 8, 19; 9, 20; 10, 21; 11, 22; 12, 23; 13, 24; 14, 25; 15, 26; 16, 27; 17, 28; 19, 29; 19, 30; 20, 31; 20, 32; 21, 33; 21, 34; 22, 35; 22, 36; 23, 37; 23, 38; 24, 39; 24, 40; 25, 41; 25, 42; 26, 43; 26, 44; 27, 45; 27, 46; 28, 47; 28, 48; 30, 49; 30, 50; 32, 51; 32, 52; 34, 53; 34, 54; 36, 55; 36, 56; 38, 57; 38, 58; 40, 59; 40, 60; 42, 61; 42, 62; 44, 63; 44, 64; 46, 65; 46, 66; 49, 67; 49, 68; 51, 69; 51, 70; 53, 71; 53, 72; 54, 73; 54, 74; 56, 75; 56, 76; 57, 77; 57, 78; 58, 79; 59, 80; 59, 81; 60, 82; 60, 83; 61, 84; 61, 85; 62, 86; 62, 87; 63, 88; 65, 89; 66, 90; 69, 91; 69, 92; 74, 93; 74, 94; 75, 95; 75, 96; 76, 97; 83, 98; 83, 99; 87, 100; 87, 101; 88, 102; 88, 103; 89, 104; 89, 105; 90, 106; 90, 107; 91, 108; 93, 109; 93, 110; 94, 111; 97, 112; 97, 113; 98, 114; 98, 115; 99, 116; 100, 117; 100, 118; 101, 119; 102, 120; 102, 121; 104, 122; 104, 123; 106, 124; 106, 125; 108, 126; 108, 127; 111, 128; 113, 129; 116, 130; 119, 131; 126, 132; 126, 133; 127, 134; 127, 135; 128, 136; 128, 137; 129, 138; 129, 139; 133, 140; 135, 141; 136, 142; 136, 143; 139, 144; 141, 145; 143, 146
def equalspairs(X, Y): """ Indices of elements in a sorted numpy array equal to those in another. Given numpy array `X` and sorted numpy array `Y`, determine the indices in Y equal to indices in X. Returns `[A,B]` where `A` and `B` are numpy arrays of indices in `X` such that:: Y[A[i]:B[i]] = Y[Y == X[i]]` `A[i] = B[i] = 0` if `X[i]` is not in `Y`. **Parameters** **X** : numpy array Numpy array to compare to the sorted numpy array `Y`. **Y** : numpy array Sorted numpy array. Determine the indices of elements of `Y` equal to those in numpy array `X`. **Returns** **A** : numpy array List of indices in `Y`, `len(A) = len(Y)`. **B** : numpy array List of indices in `Y`, `len(B) = len(Y)`. **See Also:** :func:`tabular.fast.recarrayequalspairs` """ T = Y.copy() R = (T[1:] != T[:-1]).nonzero()[0] R = np.append(R,np.array([len(T)-1])) M = R[R.searchsorted(range(len(T)))] D = T.searchsorted(X) T = np.append(T,np.array([0])) M = np.append(M,np.array([0])) A = (T[D] == X) * D B = (T[D] == X) * (M[D] + 1) return [A,B]
0, module; 1, function_definition; 2, function_name:_inplace_sort_by_id; 3, parameters; 4, block; 5, identifier:unsorted_list; 6, expression_statement; 7, if_statement; 8, expression_statement; 9, expression_statement; 10, delete_statement; 11, expression_statement; 12, comment:"""Takes a list of dicts each of which has an '@id' key, sorts the elements in the list by the value of the @id key. Assumes that @id is unique or the dicts have a meaningul < operator """; 13, not_operator; 14, block; 15, assignment; 16, call; 17, subscript; 18, call; 19, call; 20, return_statement; 21, identifier:sorted_list; 22, list_comprehension; 23, attribute; 24, argument_list; 25, identifier:unsorted_list; 26, slice; 27, attribute; 28, argument_list; 29, identifier:isinstance; 30, argument_list; 31, tuple; 32, for_in_clause; 33, identifier:sorted_list; 34, identifier:sort; 35, identifier:unsorted_list; 36, identifier:extend; 37, list_comprehension; 38, identifier:unsorted_list; 39, identifier:list; 40, call; 41, identifier:i; 42, identifier:i; 43, identifier:unsorted_list; 44, subscript; 45, for_in_clause; 46, attribute; 47, argument_list; 48, identifier:i; 49, integer:1; 50, identifier:i; 51, identifier:sorted_list; 52, identifier:i; 53, identifier:get; 54, string; 55, string_content:@id
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; 14, 20; 15, 21; 15, 22; 16, 23; 16, 24; 17, 25; 17, 26; 18, 27; 18, 28; 19, 29; 19, 30; 22, 31; 22, 32; 23, 33; 23, 34; 27, 35; 27, 36; 28, 37; 30, 38; 30, 39; 31, 40; 31, 41; 32, 42; 32, 43; 37, 44; 37, 45; 40, 46; 40, 47; 44, 48; 44, 49; 45, 50; 45, 51; 46, 52; 46, 53; 47, 54; 54, 55
def _inplace_sort_by_id(unsorted_list): """Takes a list of dicts each of which has an '@id' key, sorts the elements in the list by the value of the @id key. Assumes that @id is unique or the dicts have a meaningul < operator """ if not isinstance(unsorted_list, list): return sorted_list = [(i.get('@id'), i) for i in unsorted_list] sorted_list.sort() del unsorted_list[:] unsorted_list.extend([i[1] for i in sorted_list])
0, module; 1, function_definition; 2, function_name:get_schemaloc_string; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, if_statement; 11, if_statement; 12, expression_statement; 13, for_statement; 14, if_statement; 15, return_statement; 16, identifier:ns_uris; 17, None; 18, identifier:sort; 19, False; 20, identifier:delim; 21, string:"\n"; 22, comment:"""Constructs and returns a schemalocation attribute. If no namespaces in this set have any schema locations defined, returns an empty string. Args: ns_uris (iterable): The namespaces to include in the constructed attribute value. If None, all are included. sort (bool): Whether the sort the namespace URIs. delim (str): The delimiter to use between namespace/schemaloc *pairs*. Returns: str: A schemalocation attribute in the format: ``xsi:schemaLocation="nsuri schemaloc<delim>nsuri2 schemaloc2<delim>..."`` """; 23, not_operator; 24, block; 25, identifier:sort; 26, block; 27, assignment; 28, identifier:ns_uri; 29, identifier:ns_uris; 30, block; 31, not_operator; 32, block; 33, call; 34, identifier:ns_uris; 35, expression_statement; 36, expression_statement; 37, identifier:schemalocs; 38, list; 39, expression_statement; 40, if_statement; 41, identifier:schemalocs; 42, return_statement; 43, attribute; 44, argument_list; 45, assignment; 46, assignment; 47, assignment; 48, attribute; 49, block; 50, string:""; 51, string:'xsi:schemaLocation="{0}"'; 52, identifier:format; 53, call; 54, identifier:ns_uris; 55, call; 56, identifier:ns_uris; 57, call; 58, identifier:ni; 59, call; 60, identifier:ni; 61, identifier:schema_location; 62, expression_statement; 63, attribute; 64, argument_list; 65, attribute; 66, argument_list; 67, identifier:sorted; 68, argument_list; 69, attribute; 70, argument_list; 71, call; 72, identifier:delim; 73, identifier:join; 74, identifier:schemalocs; 75, identifier:six; 76, identifier:iterkeys; 77, attribute; 78, identifier:ns_uris; 79, identifier:self; 80, identifier:__lookup_uri; 81, identifier:ns_uri; 82, attribute; 83, argument_list; 84, identifier:self; 85, identifier:__ns_uri_map; 86, identifier:schemalocs; 87, identifier:append; 88, call; 89, attribute; 90, argument_list; 91, string:"{0.uri} {0.schema_location}"; 92, identifier:format; 93, identifier:ni
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; 6, 16; 6, 17; 7, 18; 7, 19; 8, 20; 8, 21; 9, 22; 10, 23; 10, 24; 11, 25; 11, 26; 12, 27; 13, 28; 13, 29; 13, 30; 14, 31; 14, 32; 15, 33; 23, 34; 24, 35; 26, 36; 27, 37; 27, 38; 30, 39; 30, 40; 31, 41; 32, 42; 33, 43; 33, 44; 35, 45; 36, 46; 39, 47; 40, 48; 40, 49; 42, 50; 43, 51; 43, 52; 44, 53; 45, 54; 45, 55; 46, 56; 46, 57; 47, 58; 47, 59; 48, 60; 48, 61; 49, 62; 53, 63; 53, 64; 55, 65; 55, 66; 57, 67; 57, 68; 59, 69; 59, 70; 62, 71; 63, 72; 63, 73; 64, 74; 65, 75; 65, 76; 66, 77; 68, 78; 69, 79; 69, 80; 70, 81; 71, 82; 71, 83; 77, 84; 77, 85; 82, 86; 82, 87; 83, 88; 88, 89; 88, 90; 89, 91; 89, 92; 90, 93
def get_schemaloc_string(self, ns_uris=None, sort=False, delim="\n"): """Constructs and returns a schemalocation attribute. If no namespaces in this set have any schema locations defined, returns an empty string. Args: ns_uris (iterable): The namespaces to include in the constructed attribute value. If None, all are included. sort (bool): Whether the sort the namespace URIs. delim (str): The delimiter to use between namespace/schemaloc *pairs*. Returns: str: A schemalocation attribute in the format: ``xsi:schemaLocation="nsuri schemaloc<delim>nsuri2 schemaloc2<delim>..."`` """ if not ns_uris: ns_uris = six.iterkeys(self.__ns_uri_map) if sort: ns_uris = sorted(ns_uris) schemalocs = [] for ns_uri in ns_uris: ni = self.__lookup_uri(ns_uri) if ni.schema_location: schemalocs.append("{0.uri} {0.schema_location}".format(ni)) if not schemalocs: return "" return 'xsi:schemaLocation="{0}"'.format(delim.join(schemalocs))
0, module; 1, function_definition; 2, function_name:aggregate; 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, default_parameter; 13, expression_statement; 14, if_statement; 15, expression_statement; 16, expression_statement; 17, if_statement; 18, identifier:On; 19, None; 20, identifier:AggFuncDict; 21, None; 22, identifier:AggFunc; 23, None; 24, identifier:AggList; 25, None; 26, identifier:returnsort; 27, False; 28, identifier:KeepOthers; 29, True; 30, identifier:keyfuncdict; 31, None; 32, comment:""" Aggregate a tabarray on columns for given functions. Method wraps:: tabular.spreadsheet.aggregate(self, On, AggFuncDict, AggFunc, returnsort) """; 33, identifier:returnsort; 34, block; 35, else_clause; 36, assignment; 37, assignment; 38, identifier:returnsort; 39, block; 40, else_clause; 41, expression_statement; 42, block; 43, identifier:data; 44, call; 45, attribute; 46, attribute; 47, return_statement; 48, block; 49, assignment; 50, expression_statement; 51, attribute; 52, argument_list; 53, identifier:data; 54, identifier:coloring; 55, identifier:self; 56, identifier:coloring; 57, list; 58, return_statement; 59, list_pattern; 60, call; 61, assignment; 62, identifier:data; 63, identifier:view; 64, identifier:tabarray; 65, identifier:data; 66, identifier:s; 67, identifier:data; 68, identifier:data; 69, identifier:s; 70, attribute; 71, argument_list; 72, identifier:data; 73, call; 74, identifier:spreadsheet; 75, identifier:aggregate; 76, keyword_argument; 77, keyword_argument; 78, keyword_argument; 79, keyword_argument; 80, keyword_argument; 81, keyword_argument; 82, keyword_argument; 83, attribute; 84, argument_list; 85, identifier:X; 86, identifier:self; 87, identifier:On; 88, identifier:On; 89, identifier:AggFuncDict; 90, identifier:AggFuncDict; 91, identifier:AggFunc; 92, identifier:AggFunc; 93, identifier:AggList; 94, identifier:AggList; 95, identifier:returnsort; 96, identifier:returnsort; 97, identifier:keyfuncdict; 98, identifier:keyfuncdict; 99, identifier:spreadsheet; 100, identifier:aggregate; 101, keyword_argument; 102, keyword_argument; 103, keyword_argument; 104, keyword_argument; 105, keyword_argument; 106, keyword_argument; 107, keyword_argument; 108, keyword_argument; 109, identifier:X; 110, identifier:self; 111, identifier:On; 112, identifier:On; 113, identifier:AggFuncDict; 114, identifier:AggFuncDict; 115, identifier:AggFunc; 116, identifier:AggFunc; 117, identifier:AggList; 118, identifier:AggList; 119, identifier:returnsort; 120, identifier:returnsort; 121, identifier:KeepOthers; 122, identifier:KeepOthers; 123, identifier:keyfuncdict; 124, identifier:keyfuncdict
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; 6, 18; 6, 19; 7, 20; 7, 21; 8, 22; 8, 23; 9, 24; 9, 25; 10, 26; 10, 27; 11, 28; 11, 29; 12, 30; 12, 31; 13, 32; 14, 33; 14, 34; 14, 35; 15, 36; 16, 37; 17, 38; 17, 39; 17, 40; 34, 41; 35, 42; 36, 43; 36, 44; 37, 45; 37, 46; 39, 47; 40, 48; 41, 49; 42, 50; 44, 51; 44, 52; 45, 53; 45, 54; 46, 55; 46, 56; 47, 57; 48, 58; 49, 59; 49, 60; 50, 61; 51, 62; 51, 63; 52, 64; 57, 65; 57, 66; 58, 67; 59, 68; 59, 69; 60, 70; 60, 71; 61, 72; 61, 73; 70, 74; 70, 75; 71, 76; 71, 77; 71, 78; 71, 79; 71, 80; 71, 81; 71, 82; 73, 83; 73, 84; 76, 85; 76, 86; 77, 87; 77, 88; 78, 89; 78, 90; 79, 91; 79, 92; 80, 93; 80, 94; 81, 95; 81, 96; 82, 97; 82, 98; 83, 99; 83, 100; 84, 101; 84, 102; 84, 103; 84, 104; 84, 105; 84, 106; 84, 107; 84, 108; 101, 109; 101, 110; 102, 111; 102, 112; 103, 113; 103, 114; 104, 115; 104, 116; 105, 117; 105, 118; 106, 119; 106, 120; 107, 121; 107, 122; 108, 123; 108, 124
def aggregate(self, On=None, AggFuncDict=None, AggFunc=None, AggList = None, returnsort=False,KeepOthers=True, keyfuncdict=None): """ Aggregate a tabarray on columns for given functions. Method wraps:: tabular.spreadsheet.aggregate(self, On, AggFuncDict, AggFunc, returnsort) """ if returnsort: [data, s] = spreadsheet.aggregate(X=self, On=On, AggFuncDict=AggFuncDict, AggFunc=AggFunc, AggList=AggList, returnsort=returnsort, keyfuncdict=keyfuncdict) else: data = spreadsheet.aggregate(X=self, On=On, AggFuncDict=AggFuncDict, AggFunc=AggFunc, AggList = AggList, returnsort=returnsort, KeepOthers=KeepOthers, keyfuncdict=keyfuncdict) data = data.view(tabarray) data.coloring = self.coloring if returnsort: return [data, s] else: return data
0, module; 1, function_definition; 2, function_name:argsort; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, return_statement; 13, identifier:axis; 14, unary_operator; 15, identifier:kind; 16, string; 17, identifier:order; 18, None; 19, comment:""" Returns the indices that would sort an array. .. note:: This method wraps `numpy.argsort`. This documentation is modified from that of `numpy.argsort`. Perform an indirect sort along the given axis using the algorithm specified by the `kind` keyword. It returns an array of indices of the same shape as the original array that index data along the given axis in sorted order. **Parameters** **axis** : int or None, optional Axis along which to sort. The default is -1 (the last axis). If `None`, the flattened array is used. **kind** : {'quicksort', 'mergesort', 'heapsort'}, optional Sorting algorithm. **order** : list, optional This argument specifies which fields to compare first, second, etc. Not all fields need be specified. **Returns** **index_array** : ndarray, int Array of indices that sort the tabarray along the specified axis. In other words, ``a[index_array]`` yields a sorted `a`. **See Also** sort : Describes sorting algorithms used. lexsort : Indirect stable sort with multiple keys. ndarray.sort : Inplace sort. **Notes** See `numpy.sort` for notes on the different sorting algorithms. **Examples** Sorting with keys: >>> x = tabarray([(1, 0), (0, 1)], dtype=[('x', '<i4'), ('y', '<i4')]) >>> x tabarray([(1, 0), (0, 1)], dtype=[('x', '<i4'), ('y', '<i4')]) >>> x.argsort(order=('x','y')) array([1, 0]) >>> x.argsort(order=('y','x')) array([0, 1]) """; 20, assignment; 21, assignment; 22, identifier:index_array; 23, integer:1; 24, string_content:quicksort; 25, identifier:index_array; 26, call; 27, identifier:index_array; 28, call; 29, attribute; 30, argument_list; 31, attribute; 32, argument_list; 33, attribute; 34, identifier:_wrapit; 35, identifier:self; 36, string; 37, identifier:axis; 38, identifier:kind; 39, identifier:order; 40, identifier:index_array; 41, identifier:view; 42, attribute; 43, attribute; 44, identifier:fromnumeric; 45, string_content:argsort; 46, identifier:np; 47, identifier:ndarray; 48, identifier:np; 49, identifier:core
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, 9; 4, 10; 4, 11; 4, 12; 6, 13; 6, 14; 7, 15; 7, 16; 8, 17; 8, 18; 9, 19; 10, 20; 11, 21; 12, 22; 14, 23; 16, 24; 20, 25; 20, 26; 21, 27; 21, 28; 26, 29; 26, 30; 28, 31; 28, 32; 29, 33; 29, 34; 30, 35; 30, 36; 30, 37; 30, 38; 30, 39; 31, 40; 31, 41; 32, 42; 33, 43; 33, 44; 36, 45; 42, 46; 42, 47; 43, 48; 43, 49
def argsort(self, axis=-1, kind='quicksort', order=None): """ Returns the indices that would sort an array. .. note:: This method wraps `numpy.argsort`. This documentation is modified from that of `numpy.argsort`. Perform an indirect sort along the given axis using the algorithm specified by the `kind` keyword. It returns an array of indices of the same shape as the original array that index data along the given axis in sorted order. **Parameters** **axis** : int or None, optional Axis along which to sort. The default is -1 (the last axis). If `None`, the flattened array is used. **kind** : {'quicksort', 'mergesort', 'heapsort'}, optional Sorting algorithm. **order** : list, optional This argument specifies which fields to compare first, second, etc. Not all fields need be specified. **Returns** **index_array** : ndarray, int Array of indices that sort the tabarray along the specified axis. In other words, ``a[index_array]`` yields a sorted `a`. **See Also** sort : Describes sorting algorithms used. lexsort : Indirect stable sort with multiple keys. ndarray.sort : Inplace sort. **Notes** See `numpy.sort` for notes on the different sorting algorithms. **Examples** Sorting with keys: >>> x = tabarray([(1, 0), (0, 1)], dtype=[('x', '<i4'), ('y', '<i4')]) >>> x tabarray([(1, 0), (0, 1)], dtype=[('x', '<i4'), ('y', '<i4')]) >>> x.argsort(order=('x','y')) array([1, 0]) >>> x.argsort(order=('y','x')) array([0, 1]) """ index_array = np.core.fromnumeric._wrapit(self, 'argsort', axis, kind, order) index_array = index_array.view(np.ndarray) return index_array
0, module; 1, function_definition; 2, function_name:blt; 3, parameters; 4, type; 5, block; 6, typed_parameter; 7, typed_parameter; 8, generic_type; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, return_statement; 13, identifier:f; 14, type; 15, identifier:x; 16, type; 17, identifier:Dict; 18, type_parameter; 19, comment:""" Sort equations by dependence """; 20, assignment; 21, assignment; 22, dictionary; 23, generic_type; 24, generic_type; 25, type; 26, type; 27, identifier:J; 28, call; 29, pattern_list; 30, call; 31, pair; 32, pair; 33, pair; 34, pair; 35, pair; 36, pair; 37, pair; 38, pair; 39, identifier:List; 40, type_parameter; 41, identifier:List; 42, type_parameter; 43, identifier:str; 44, identifier:Any; 45, attribute; 46, argument_list; 47, identifier:nblock; 48, identifier:rowperm; 49, identifier:colperm; 50, identifier:rowblock; 51, identifier:colblock; 52, identifier:coarserow; 53, identifier:coarsecol; 54, attribute; 55, argument_list; 56, string; 57, identifier:J; 58, string; 59, identifier:nblock; 60, string; 61, identifier:rowperm; 62, string; 63, identifier:colperm; 64, string; 65, identifier:rowblock; 66, string; 67, identifier:colblock; 68, string; 69, identifier:coarserow; 70, string; 71, identifier:coarsecol; 72, type; 73, type; 74, identifier:ca; 75, identifier:jacobian; 76, identifier:f; 77, identifier:x; 78, call; 79, identifier:btf; 80, string_content:J; 81, string_content:nblock; 82, string_content:rowperm; 83, string_content:colperm; 84, string_content:rowblock; 85, string_content:colblock; 86, string_content:coarserow; 87, string_content:coarsecol; 88, identifier:SYM; 89, identifier:SYM; 90, attribute; 91, argument_list; 92, identifier:J; 93, identifier:sparsity
0, 1; 1, 2; 1, 3; 1, 4; 1, 5; 3, 6; 3, 7; 4, 8; 5, 9; 5, 10; 5, 11; 5, 12; 6, 13; 6, 14; 7, 15; 7, 16; 8, 17; 8, 18; 9, 19; 10, 20; 11, 21; 12, 22; 14, 23; 16, 24; 18, 25; 18, 26; 20, 27; 20, 28; 21, 29; 21, 30; 22, 31; 22, 32; 22, 33; 22, 34; 22, 35; 22, 36; 22, 37; 22, 38; 23, 39; 23, 40; 24, 41; 24, 42; 25, 43; 26, 44; 28, 45; 28, 46; 29, 47; 29, 48; 29, 49; 29, 50; 29, 51; 29, 52; 29, 53; 30, 54; 30, 55; 31, 56; 31, 57; 32, 58; 32, 59; 33, 60; 33, 61; 34, 62; 34, 63; 35, 64; 35, 65; 36, 66; 36, 67; 37, 68; 37, 69; 38, 70; 38, 71; 40, 72; 42, 73; 45, 74; 45, 75; 46, 76; 46, 77; 54, 78; 54, 79; 56, 80; 58, 81; 60, 82; 62, 83; 64, 84; 66, 85; 68, 86; 70, 87; 72, 88; 73, 89; 78, 90; 78, 91; 90, 92; 90, 93
def blt(f: List[SYM], x: List[SYM]) -> Dict[str, Any]: """ Sort equations by dependence """ J = ca.jacobian(f, x) nblock, rowperm, colperm, rowblock, colblock, coarserow, coarsecol = J.sparsity().btf() return { 'J': J, 'nblock': nblock, 'rowperm': rowperm, 'colperm': colperm, 'rowblock': rowblock, 'colblock': colblock, 'coarserow': coarserow, 'coarsecol': coarsecol }
0, module; 1, function_definition; 2, function_name:sort_generators; 3, parameters; 4, block; 5, identifier:self; 6, expression_statement; 7, expression_statement; 8, comment:""" Reorders the list of generators according to bus index. """; 9, call; 10, attribute; 11, argument_list; 12, attribute; 13, identifier:sort; 14, keyword_argument; 15, identifier:self; 16, identifier:generators; 17, identifier:key; 18, lambda; 19, lambda_parameters; 20, attribute; 21, identifier:gn; 22, attribute; 23, identifier:_i; 24, identifier:gn; 25, identifier:bus
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 6, 8; 7, 9; 9, 10; 9, 11; 10, 12; 10, 13; 11, 14; 12, 15; 12, 16; 14, 17; 14, 18; 18, 19; 18, 20; 19, 21; 20, 22; 20, 23; 22, 24; 22, 25
def sort_generators(self): """ Reorders the list of generators according to bus index. """ self.generators.sort(key=lambda gn: gn.bus._i)
0, module; 1, function_definition; 2, function_name:list; 3, parameters; 4, comment:# pylint: disable=redefined-builtin; 5, block; 6, identifier:self; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, expression_statement; 13, expression_statement; 14, expression_statement; 15, expression_statement; 16, return_statement; 17, identifier:filter; 18, None; 19, identifier:type; 20, None; 21, identifier:sort; 22, None; 23, identifier:limit; 24, None; 25, identifier:page; 26, None; 27, comment:"""Get a list of configs. :param filter: (optional) Filters to apply as a string list. :param type: (optional) `union` or `inter` as string. :param sort: (optional) Sort fields to apply as string list. :param limit: (optional) Limit returned list length. :param page: (optional) Page to return. :return: :class:`configs.Page <configs.Page>` object """; 28, assignment; 29, assignment; 30, assignment; 31, call; 32, identifier:schema; 33, attribute; 34, identifier:resp; 35, call; 36, pattern_list; 37, call; 38, identifier:Page; 39, argument_list; 40, identifier:self; 41, identifier:LIST_SCHEMA; 42, attribute; 43, argument_list; 44, identifier:cs; 45, identifier:l; 46, attribute; 47, argument_list; 48, identifier:cs; 49, identifier:l; 50, attribute; 51, identifier:list; 52, attribute; 53, identifier:filter; 54, identifier:type; 55, identifier:sort; 56, identifier:limit; 57, identifier:page; 58, attribute; 59, identifier:decode; 60, identifier:schema; 61, identifier:resp; 62, keyword_argument; 63, keyword_argument; 64, identifier:self; 65, identifier:service; 66, identifier:self; 67, identifier:base; 68, identifier:self; 69, identifier:service; 70, identifier:many; 71, True; 72, identifier:links; 73, True
0, 1; 1, 2; 1, 3; 1, 4; 1, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 5, 12; 5, 13; 5, 14; 5, 15; 5, 16; 7, 17; 7, 18; 8, 19; 8, 20; 9, 21; 9, 22; 10, 23; 10, 24; 11, 25; 11, 26; 12, 27; 13, 28; 14, 29; 15, 30; 16, 31; 28, 32; 28, 33; 29, 34; 29, 35; 30, 36; 30, 37; 31, 38; 31, 39; 33, 40; 33, 41; 35, 42; 35, 43; 36, 44; 36, 45; 37, 46; 37, 47; 39, 48; 39, 49; 42, 50; 42, 51; 43, 52; 43, 53; 43, 54; 43, 55; 43, 56; 43, 57; 46, 58; 46, 59; 47, 60; 47, 61; 47, 62; 47, 63; 50, 64; 50, 65; 52, 66; 52, 67; 58, 68; 58, 69; 62, 70; 62, 71; 63, 72; 63, 73
def list(self, filter=None, type=None, sort=None, limit=None, page=None): # pylint: disable=redefined-builtin """Get a list of configs. :param filter: (optional) Filters to apply as a string list. :param type: (optional) `union` or `inter` as string. :param sort: (optional) Sort fields to apply as string list. :param limit: (optional) Limit returned list length. :param page: (optional) Page to return. :return: :class:`configs.Page <configs.Page>` object """ schema = self.LIST_SCHEMA resp = self.service.list(self.base, filter, type, sort, limit, page) cs, l = self.service.decode(schema, resp, many=True, links=True) return Page(cs, l)
0, module; 1, function_definition; 2, function_name:list_csv; 3, parameters; 4, comment:# pylint: disable=redefined-builtin; 5, block; 6, identifier:self; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, expression_statement; 13, return_statement; 14, identifier:filter; 15, None; 16, identifier:type; 17, None; 18, identifier:sort; 19, None; 20, identifier:limit; 21, None; 22, identifier:page; 23, None; 24, comment:"""Get a list of results as CSV. :param filter: (optional) Filters to apply as a string list. :param type: (optional) `union` or `inter` as string. :param sort: (optional) Sort fields to apply as string list. :param limit: (optional) Limit returned list length. :param page: (optional) Page to return. :rtype: string """; 25, attribute; 26, call; 27, identifier:text; 28, attribute; 29, argument_list; 30, attribute; 31, identifier:list; 32, attribute; 33, identifier:filter; 34, identifier:type; 35, identifier:sort; 36, identifier:limit; 37, identifier:page; 38, keyword_argument; 39, identifier:self; 40, identifier:service; 41, identifier:self; 42, identifier:base; 43, identifier:format; 44, string; 45, string_content:csv
0, 1; 1, 2; 1, 3; 1, 4; 1, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 5, 12; 5, 13; 7, 14; 7, 15; 8, 16; 8, 17; 9, 18; 9, 19; 10, 20; 10, 21; 11, 22; 11, 23; 12, 24; 13, 25; 25, 26; 25, 27; 26, 28; 26, 29; 28, 30; 28, 31; 29, 32; 29, 33; 29, 34; 29, 35; 29, 36; 29, 37; 29, 38; 30, 39; 30, 40; 32, 41; 32, 42; 38, 43; 38, 44; 44, 45
def list_csv(self, filter=None, type=None, sort=None, limit=None, page=None): # pylint: disable=redefined-builtin """Get a list of results as CSV. :param filter: (optional) Filters to apply as a string list. :param type: (optional) `union` or `inter` as string. :param sort: (optional) Sort fields to apply as string list. :param limit: (optional) Limit returned list length. :param page: (optional) Page to return. :rtype: string """ return self.service.list(self.base, filter, type, sort, limit, page, format='csv').text
0, module; 1, function_definition; 2, function_name:list_logdir; 3, parameters; 4, comment:# pylint: disable=invalid-name,redefined-builtin; 5, block; 6, identifier:self; 7, identifier:id; 8, default_parameter; 9, default_parameter; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, return_statement; 14, identifier:filter; 15, None; 16, identifier:sort; 17, None; 18, comment:"""Get a list of logdir files. :param id: Result ID as an int. :param filter: Filter to apply as string. :param sort: Sort field to apply as string. :return: :class:`results.LogDirFile <results.LogDirFile>` list """; 19, assignment; 20, assignment; 21, call; 22, identifier:schema; 23, call; 24, identifier:resp; 25, call; 26, attribute; 27, argument_list; 28, identifier:LogDirFileSchema; 29, argument_list; 30, attribute; 31, argument_list; 32, attribute; 33, identifier:decode; 34, identifier:schema; 35, identifier:resp; 36, keyword_argument; 37, attribute; 38, identifier:list; 39, binary_operator:self.base+str(id)+'/logdir/'; 40, identifier:filter; 41, identifier:sort; 42, identifier:self; 43, identifier:service; 44, identifier:many; 45, True; 46, identifier:self; 47, identifier:service; 48, binary_operator:self.base+str(id); 49, string; 50, attribute; 51, call; 52, string_content:/logdir/; 53, identifier:self; 54, identifier:base; 55, identifier:str; 56, argument_list; 57, identifier:id
0, 1; 1, 2; 1, 3; 1, 4; 1, 5; 3, 6; 3, 7; 3, 8; 3, 9; 5, 10; 5, 11; 5, 12; 5, 13; 8, 14; 8, 15; 9, 16; 9, 17; 10, 18; 11, 19; 12, 20; 13, 21; 19, 22; 19, 23; 20, 24; 20, 25; 21, 26; 21, 27; 23, 28; 23, 29; 25, 30; 25, 31; 26, 32; 26, 33; 27, 34; 27, 35; 27, 36; 30, 37; 30, 38; 31, 39; 31, 40; 31, 41; 32, 42; 32, 43; 36, 44; 36, 45; 37, 46; 37, 47; 39, 48; 39, 49; 48, 50; 48, 51; 49, 52; 50, 53; 50, 54; 51, 55; 51, 56; 56, 57
def list_logdir(self, id, filter=None, sort=None): # pylint: disable=invalid-name,redefined-builtin """Get a list of logdir files. :param id: Result ID as an int. :param filter: Filter to apply as string. :param sort: Sort field to apply as string. :return: :class:`results.LogDirFile <results.LogDirFile>` list """ schema = LogDirFileSchema() resp = self.service.list(self.base+str(id)+'/logdir/', filter, sort) return self.service.decode(schema, resp, many=True)
0, module; 1, function_definition; 2, function_name:list; 3, parameters; 4, comment:# pylint: disable=redefined-builtin; 5, block; 6, identifier:self; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, expression_statement; 13, expression_statement; 14, expression_statement; 15, expression_statement; 16, return_statement; 17, identifier:filter; 18, None; 19, identifier:type; 20, None; 21, identifier:sort; 22, None; 23, identifier:limit; 24, None; 25, identifier:page; 26, None; 27, comment:"""Get a list of packages. :param filter: (optional) Filters to apply as a string list. :param type: (optional) `union` or `inter` as string. :param sort: (optional) Sort fields to apply as string list. :param limit: (optional) Limit returned list length. :param page: (optional) Page to return. :return: :class:`packages.Page <packages.Page>` object """; 28, assignment; 29, assignment; 30, assignment; 31, call; 32, identifier:schema; 33, call; 34, identifier:resp; 35, call; 36, pattern_list; 37, call; 38, identifier:Page; 39, argument_list; 40, identifier:PackageSchema; 41, argument_list; 42, attribute; 43, argument_list; 44, identifier:ps; 45, identifier:l; 46, attribute; 47, argument_list; 48, identifier:ps; 49, identifier:l; 50, keyword_argument; 51, attribute; 52, identifier:list; 53, attribute; 54, identifier:filter; 55, identifier:type; 56, identifier:sort; 57, identifier:limit; 58, identifier:page; 59, attribute; 60, identifier:decode; 61, identifier:schema; 62, identifier:resp; 63, keyword_argument; 64, keyword_argument; 65, identifier:exclude; 66, tuple; 67, identifier:self; 68, identifier:service; 69, identifier:self; 70, identifier:base; 71, identifier:self; 72, identifier:service; 73, identifier:many; 74, True; 75, identifier:links; 76, True; 77, string; 78, string; 79, string; 80, string; 81, string; 82, string_content:testlist; 83, string_content:extra_cli_args; 84, string_content:agent_id; 85, string_content:options; 86, string_content:note
0, 1; 1, 2; 1, 3; 1, 4; 1, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 5, 12; 5, 13; 5, 14; 5, 15; 5, 16; 7, 17; 7, 18; 8, 19; 8, 20; 9, 21; 9, 22; 10, 23; 10, 24; 11, 25; 11, 26; 12, 27; 13, 28; 14, 29; 15, 30; 16, 31; 28, 32; 28, 33; 29, 34; 29, 35; 30, 36; 30, 37; 31, 38; 31, 39; 33, 40; 33, 41; 35, 42; 35, 43; 36, 44; 36, 45; 37, 46; 37, 47; 39, 48; 39, 49; 41, 50; 42, 51; 42, 52; 43, 53; 43, 54; 43, 55; 43, 56; 43, 57; 43, 58; 46, 59; 46, 60; 47, 61; 47, 62; 47, 63; 47, 64; 50, 65; 50, 66; 51, 67; 51, 68; 53, 69; 53, 70; 59, 71; 59, 72; 63, 73; 63, 74; 64, 75; 64, 76; 66, 77; 66, 78; 66, 79; 66, 80; 66, 81; 77, 82; 78, 83; 79, 84; 80, 85; 81, 86
def list(self, filter=None, type=None, sort=None, limit=None, page=None): # pylint: disable=redefined-builtin """Get a list of packages. :param filter: (optional) Filters to apply as a string list. :param type: (optional) `union` or `inter` as string. :param sort: (optional) Sort fields to apply as string list. :param limit: (optional) Limit returned list length. :param page: (optional) Page to return. :return: :class:`packages.Page <packages.Page>` object """ schema = PackageSchema(exclude=('testlist', 'extra_cli_args', 'agent_id', 'options', 'note')) resp = self.service.list(self.base, filter, type, sort, limit, page) ps, l = self.service.decode(schema, resp, many=True, links=True) return Page(ps, l)
0, module; 1, function_definition; 2, function_name:list; 3, parameters; 4, comment:# pylint: disable=invalid-name,redefined-builtin; 5, block; 6, identifier:self; 7, identifier:id; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, default_parameter; 13, expression_statement; 14, expression_statement; 15, expression_statement; 16, expression_statement; 17, return_statement; 18, identifier:filter; 19, None; 20, identifier:type; 21, None; 22, identifier:sort; 23, None; 24, identifier:limit; 25, None; 26, identifier:page; 27, None; 28, comment:"""Get a list of a device's attachments. :param id: Device ID as an int. :param filter: (optional) Filters to apply as a string list. :param type: (optional) `union` or `inter` as string. :param sort: (optional) Sort fields to apply as string list. :param limit: (optional) Limit returned list length. :param page: (optional) Page to return. :return: :class:`attachments.Page <attachments.Page>` object """; 29, assignment; 30, assignment; 31, assignment; 32, call; 33, identifier:schema; 34, call; 35, identifier:resp; 36, call; 37, pattern_list; 38, call; 39, identifier:Page; 40, argument_list; 41, identifier:AttachmentSchema; 42, argument_list; 43, attribute; 44, argument_list; 45, identifier:at; 46, identifier:l; 47, attribute; 48, argument_list; 49, identifier:at; 50, identifier:l; 51, keyword_argument; 52, attribute; 53, identifier:list; 54, call; 55, identifier:filter; 56, identifier:type; 57, identifier:sort; 58, identifier:limit; 59, identifier:page; 60, attribute; 61, identifier:decode; 62, identifier:schema; 63, identifier:resp; 64, keyword_argument; 65, keyword_argument; 66, identifier:exclude; 67, parenthesized_expression; 68, identifier:self; 69, identifier:service; 70, attribute; 71, argument_list; 72, identifier:self; 73, identifier:service; 74, identifier:many; 75, True; 76, identifier:links; 77, True; 78, string; 79, identifier:self; 80, identifier:_base; 81, identifier:id; 82, string_content:path
0, 1; 1, 2; 1, 3; 1, 4; 1, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 3, 12; 5, 13; 5, 14; 5, 15; 5, 16; 5, 17; 8, 18; 8, 19; 9, 20; 9, 21; 10, 22; 10, 23; 11, 24; 11, 25; 12, 26; 12, 27; 13, 28; 14, 29; 15, 30; 16, 31; 17, 32; 29, 33; 29, 34; 30, 35; 30, 36; 31, 37; 31, 38; 32, 39; 32, 40; 34, 41; 34, 42; 36, 43; 36, 44; 37, 45; 37, 46; 38, 47; 38, 48; 40, 49; 40, 50; 42, 51; 43, 52; 43, 53; 44, 54; 44, 55; 44, 56; 44, 57; 44, 58; 44, 59; 47, 60; 47, 61; 48, 62; 48, 63; 48, 64; 48, 65; 51, 66; 51, 67; 52, 68; 52, 69; 54, 70; 54, 71; 60, 72; 60, 73; 64, 74; 64, 75; 65, 76; 65, 77; 67, 78; 70, 79; 70, 80; 71, 81; 78, 82
def list(self, id, filter=None, type=None, sort=None, limit=None, page=None): # pylint: disable=invalid-name,redefined-builtin """Get a list of a device's attachments. :param id: Device ID as an int. :param filter: (optional) Filters to apply as a string list. :param type: (optional) `union` or `inter` as string. :param sort: (optional) Sort fields to apply as string list. :param limit: (optional) Limit returned list length. :param page: (optional) Page to return. :return: :class:`attachments.Page <attachments.Page>` object """ schema = AttachmentSchema(exclude=('path')) resp = self.service.list(self._base(id), filter, type, sort, limit, page) at, l = self.service.decode(schema, resp, many=True, links=True) return Page(at, l)
0, module; 1, function_definition; 2, function_name:_process_value; 3, parameters; 4, block; 5, identifier:self; 6, identifier:value; 7, identifier:type; 8, expression_statement; 9, if_statement; 10, return_statement; 11, comment:""" Process a value that will be sent to backend :param value: the value to return :param type: hint for what sort of value this is :type type: str """; 12, not_operator; 13, block; 14, identifier:value; 15, call; 16, expression_statement; 17, identifier:isinstance; 18, argument_list; 19, assignment; 20, identifier:value; 21, binary_operator:six.string_types + (list,); 22, identifier:value; 23, call; 24, attribute; 25, tuple; 26, attribute; 27, argument_list; 28, identifier:six; 29, identifier:string_types; 30, identifier:list; 31, identifier:json; 32, identifier:dumps; 33, identifier:value
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 8, 11; 9, 12; 9, 13; 10, 14; 12, 15; 13, 16; 15, 17; 15, 18; 16, 19; 18, 20; 18, 21; 19, 22; 19, 23; 21, 24; 21, 25; 23, 26; 23, 27; 24, 28; 24, 29; 25, 30; 26, 31; 26, 32; 27, 33
def _process_value(self, value, type): """ Process a value that will be sent to backend :param value: the value to return :param type: hint for what sort of value this is :type type: str """ if not isinstance(value, six.string_types + (list,)): value = json.dumps(value) return value
0, module; 1, function_definition; 2, function_name:representatives; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, default_parameter; 8, expression_statement; 9, expression_statement; 10, if_statement; 11, if_statement; 12, expression_statement; 13, expression_statement; 14, for_statement; 15, return_statement; 16, identifier:count; 17, None; 18, identifier:sorting; 19, False; 20, comment:""" Returns a list of pairs of representative and its voting weight :param count: Max amount of representatives to return :type count: int :param sorting: If true, sorts by weight :type sorting: bool :raises: :py:exc:`nano.rpc.RPCException` >>> rpc.representatives() { "xrb_1111111111111111111111111111111111111111111111111117353trpda": 3822372327060170000000000000000000000, "xrb_1111111111111111111111111111111111111111111111111awsq94gtecn": 30999999999999999999999999000000, "xrb_114nk4rwjctu6n6tr6g6ps61g1w3hdpjxfas4xj1tq6i8jyomc5d858xr1xi": 0 } """; 21, assignment; 22, comparison_operator:count is not None; 23, block; 24, identifier:sorting; 25, block; 26, assignment; 27, assignment; 28, pattern_list; 29, call; 30, block; 31, identifier:representatives; 32, identifier:payload; 33, dictionary; 34, identifier:count; 35, None; 36, expression_statement; 37, expression_statement; 38, identifier:resp; 39, call; 40, identifier:representatives; 41, boolean_operator; 42, identifier:k; 43, identifier:v; 44, attribute; 45, argument_list; 46, expression_statement; 47, assignment; 48, assignment; 49, attribute; 50, argument_list; 51, call; 52, dictionary; 53, identifier:representatives; 54, identifier:items; 55, assignment; 56, subscript; 57, call; 58, subscript; 59, call; 60, identifier:self; 61, identifier:call; 62, string; 63, identifier:payload; 64, attribute; 65, argument_list; 66, subscript; 67, call; 68, identifier:payload; 69, string; 70, attribute; 71, argument_list; 72, identifier:payload; 73, string; 74, attribute; 75, argument_list; 76, string_content:representatives; 77, identifier:resp; 78, identifier:get; 79, string; 80, identifier:representatives; 81, identifier:k; 82, identifier:int; 83, argument_list; 84, string_content:count; 85, identifier:self; 86, identifier:_process_value; 87, identifier:count; 88, string; 89, string_content:sorting; 90, identifier:self; 91, identifier:_process_value; 92, identifier:sorting; 93, string; 94, string_content:representatives; 95, identifier:v; 96, string_content:int; 97, string_content:strbool
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; 11, 25; 12, 26; 13, 27; 14, 28; 14, 29; 14, 30; 15, 31; 21, 32; 21, 33; 22, 34; 22, 35; 23, 36; 25, 37; 26, 38; 26, 39; 27, 40; 27, 41; 28, 42; 28, 43; 29, 44; 29, 45; 30, 46; 36, 47; 37, 48; 39, 49; 39, 50; 41, 51; 41, 52; 44, 53; 44, 54; 46, 55; 47, 56; 47, 57; 48, 58; 48, 59; 49, 60; 49, 61; 50, 62; 50, 63; 51, 64; 51, 65; 55, 66; 55, 67; 56, 68; 56, 69; 57, 70; 57, 71; 58, 72; 58, 73; 59, 74; 59, 75; 62, 76; 64, 77; 64, 78; 65, 79; 66, 80; 66, 81; 67, 82; 67, 83; 69, 84; 70, 85; 70, 86; 71, 87; 71, 88; 73, 89; 74, 90; 74, 91; 75, 92; 75, 93; 79, 94; 83, 95; 88, 96; 93, 97
def representatives(self, count=None, sorting=False): """ Returns a list of pairs of representative and its voting weight :param count: Max amount of representatives to return :type count: int :param sorting: If true, sorts by weight :type sorting: bool :raises: :py:exc:`nano.rpc.RPCException` >>> rpc.representatives() { "xrb_1111111111111111111111111111111111111111111111111117353trpda": 3822372327060170000000000000000000000, "xrb_1111111111111111111111111111111111111111111111111awsq94gtecn": 30999999999999999999999999000000, "xrb_114nk4rwjctu6n6tr6g6ps61g1w3hdpjxfas4xj1tq6i8jyomc5d858xr1xi": 0 } """ payload = {} if count is not None: payload['count'] = self._process_value(count, 'int') if sorting: payload['sorting'] = self._process_value(sorting, 'strbool') resp = self.call('representatives', payload) representatives = resp.get('representatives') or {} for k, v in representatives.items(): representatives[k] = int(v) return representatives
0, module; 1, function_definition; 2, function_name:iterative_overlap_assembly; 3, parameters; 4, block; 5, identifier:variant_sequences; 6, default_parameter; 7, expression_statement; 8, if_statement; 9, comment:# reduce the number of inputs to the merge algorithm by first collapsing; 10, comment:# shorter sequences onto the longer sequences which contain them; 11, expression_statement; 12, expression_statement; 13, expression_statement; 14, expression_statement; 15, expression_statement; 16, return_statement; 17, identifier:min_overlap_size; 18, identifier:MIN_VARIANT_SEQUENCE_ASSEMBLY_OVERLAP_SIZE; 19, comment:""" Assembles longer sequences from reads centered on a variant by between merging all pairs of overlapping sequences and collapsing shorter sequences onto every longer sequence which contains them. Returns a list of variant sequences, sorted by decreasing read support. """; 20, comparison_operator:len(variant_sequences) <= 1; 21, comment:# if we don't have at least two sequences to start with then; 22, comment:# skip the whole mess below; 23, block; 24, assignment; 25, assignment; 26, assignment; 27, call; 28, assignment; 29, call; 30, call; 31, integer:1; 32, return_statement; 33, identifier:n_before_collapse; 34, call; 35, identifier:variant_sequences; 36, call; 37, identifier:n_after_collapse; 38, call; 39, attribute; 40, argument_list; 41, identifier:merged_variant_sequences; 42, call; 43, identifier:list; 44, argument_list; 45, identifier:len; 46, argument_list; 47, identifier:variant_sequences; 48, identifier:len; 49, argument_list; 50, identifier:collapse_substrings; 51, argument_list; 52, identifier:len; 53, argument_list; 54, identifier:logger; 55, identifier:info; 56, string:"Collapsed %d -> %d sequences"; 57, identifier:n_before_collapse; 58, identifier:n_after_collapse; 59, identifier:greedy_merge; 60, argument_list; 61, call; 62, identifier:variant_sequences; 63, identifier:variant_sequences; 64, identifier:variant_sequences; 65, identifier:variant_sequences; 66, identifier:variant_sequences; 67, identifier:min_overlap_size; 68, identifier:sorted; 69, argument_list; 70, identifier:merged_variant_sequences; 71, keyword_argument; 72, identifier:key; 73, lambda; 74, lambda_parameters; 75, unary_operator; 76, identifier:seq; 77, call; 78, identifier:len; 79, argument_list; 80, attribute; 81, identifier:seq; 82, identifier:reads
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; 6, 17; 6, 18; 7, 19; 8, 20; 8, 21; 8, 22; 8, 23; 11, 24; 12, 25; 13, 26; 14, 27; 15, 28; 16, 29; 20, 30; 20, 31; 23, 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; 30, 45; 30, 46; 32, 47; 34, 48; 34, 49; 36, 50; 36, 51; 38, 52; 38, 53; 39, 54; 39, 55; 40, 56; 40, 57; 40, 58; 42, 59; 42, 60; 44, 61; 46, 62; 49, 63; 51, 64; 53, 65; 60, 66; 60, 67; 61, 68; 61, 69; 69, 70; 69, 71; 71, 72; 71, 73; 73, 74; 73, 75; 74, 76; 75, 77; 77, 78; 77, 79; 79, 80; 80, 81; 80, 82
def iterative_overlap_assembly( variant_sequences, min_overlap_size=MIN_VARIANT_SEQUENCE_ASSEMBLY_OVERLAP_SIZE): """ Assembles longer sequences from reads centered on a variant by between merging all pairs of overlapping sequences and collapsing shorter sequences onto every longer sequence which contains them. Returns a list of variant sequences, sorted by decreasing read support. """ if len(variant_sequences) <= 1: # if we don't have at least two sequences to start with then # skip the whole mess below return variant_sequences # reduce the number of inputs to the merge algorithm by first collapsing # shorter sequences onto the longer sequences which contain them n_before_collapse = len(variant_sequences) variant_sequences = collapse_substrings(variant_sequences) n_after_collapse = len(variant_sequences) logger.info( "Collapsed %d -> %d sequences", n_before_collapse, n_after_collapse) merged_variant_sequences = greedy_merge(variant_sequences, min_overlap_size) return list(sorted( merged_variant_sequences, key=lambda seq: -len(seq.reads)))
0, module; 1, function_definition; 2, function_name:rot_consts; 3, parameters; 4, block; 5, identifier:geom; 6, identifier:masses; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, comment:# Imports; 11, import_statement; 12, import_from_statement; 13, comment:# Ensure units are valid; 14, if_statement; 15, comment:## end if; 16, comment:# Retrieve the moments, axes and top type. Geom and masses are proofed; 17, comment:# internally in this call.; 18, expression_statement; 19, comment:# Check for special cases; 20, if_statement; 21, comment:## end if; 22, comment:# Calculate the values in the indicated units; 23, if_statement; 24, comment:## end if; 25, comment:# Return the result; 26, return_statement; 27, identifier:units; 28, attribute; 29, identifier:on_tol; 30, attribute; 31, comment:"""Rotational constants for a given molecular system. Calculates the rotational constants for the provided system with numerical value given in the units provided in `units`. The orthnormality tolerance `on_tol` is required in order to be passed through to the :func:`principals` function. If the system is linear or a single atom, the effectively-zero principal moments of inertia will be assigned values of :data:`opan.const.PRM.ZERO_MOMENT_TOL` before transformation into the appropriate rotational constant units. The moments of inertia are always sorted in increasing order as :math:`0 \\leq I_A \\leq I_B \\leq I_C`; the rotational constants calculated from these will thus always be in **decreasing** order as :math:`B_A \\geq B_B \\geq B_C`, retaining the ordering and association with the three principal ``axes[:,i]`` generated by :func:`principals`. Parameters ---------- geom length-3N |npfloat_| -- Coordinates of the atoms masses length-N OR length-3N |npfloat_| -- Atomic masses of the atoms. Length-3N option is to allow calculation of a per-coordinate perturbed value. units :class:`~opan.const.EnumUnitsRotConst`, optional -- Enum value indicating the desired units of the output rotational constants. Default is :data:`~opan.const.EnumUnitsRotConst.INV_INERTIA` :math:`\\left(1\\over \\mathrm{uB^2}\\right)` on_tol |npfloat_|, optional -- Tolerance for deviation from unity/zero for principal axis dot products, within which axes are considered orthonormal. Default is :data:`opan.const.DEF.ORTHONORM_TOL` Returns ------- rc length-3 |npfloat_| -- Vector of rotational constants in the indicated units """; 32, aliased_import; 33, relative_import; 34, aliased_import; 35, aliased_import; 36, dotted_name; 37, dotted_name; 38, not_operator; 39, block; 40, assignment; 41, comparison_operator:top == ETT.ATOM; 42, comment:# All moments are zero; set to zero-moment threshold; 43, block; 44, elif_clause; 45, comparison_operator:units == EURC.INV_INERTIA; 46, comment:# 1/(amu*B^2); 47, block; 48, elif_clause; 49, elif_clause; 50, elif_clause; 51, elif_clause; 52, elif_clause; 53, elif_clause; 54, elif_clause; 55, else_clause; 56, identifier:rc; 57, identifier:_EURC; 58, identifier:INV_INERTIA; 59, identifier:_DEF; 60, identifier:ORTHONORM_TOL; 61, dotted_name; 62, identifier:np; 63, import_prefix; 64, dotted_name; 65, dotted_name; 66, identifier:ETT; 67, dotted_name; 68, identifier:EURC; 69, identifier:PRM; 70, identifier:PHYS; 71, comparison_operator:units in EURC; 72, raise_statement; 73, pattern_list; 74, call; 75, identifier:top; 76, attribute; 77, expression_statement; 78, comparison_operator:top == ETT.LINEAR; 79, comment:# First moment is zero; set to zero-moment threshold; 80, block; 81, identifier:units; 82, attribute; 83, expression_statement; 84, comparison_operator:units == EURC.ANGFREQ_ATOMIC; 85, comment:# 1/Ta; 86, block; 87, comparison_operator:units == EURC.ANGFREQ_SECS; 88, comment:# 1/s; 89, block; 90, comparison_operator:units == EURC.CYCFREQ_ATOMIC; 91, comment:# cyc/Ta; 92, block; 93, comparison_operator:units == EURC.CYCFREQ_HZ; 94, comment:# cyc/s; 95, block; 96, comparison_operator:units == EURC.CYCFREQ_MHZ; 97, comment:# Mcyc/s; 98, block; 99, comparison_operator:units == EURC.WAVENUM_ATOMIC; 100, comment:# cyc/B; 101, block; 102, comparison_operator:units == EURC.WAVENUM_CM; 103, comment:# cyc/cm; 104, block; 105, comment:# pragma: no cover -- Valid units; not implemented; 106, block; 107, identifier:numpy; 108, identifier:const; 109, identifier:EnumTopType; 110, identifier:EnumUnitsRotConst; 111, identifier:units; 112, identifier:EURC; 113, call; 114, identifier:mom; 115, identifier:ax; 116, identifier:top; 117, identifier:principals; 118, argument_list; 119, identifier:ETT; 120, identifier:ATOM; 121, assignment; 122, identifier:top; 123, attribute; 124, expression_statement; 125, identifier:EURC; 126, identifier:INV_INERTIA; 127, assignment; 128, identifier:units; 129, attribute; 130, expression_statement; 131, identifier:units; 132, attribute; 133, expression_statement; 134, identifier:units; 135, attribute; 136, expression_statement; 137, identifier:units; 138, attribute; 139, expression_statement; 140, identifier:units; 141, attribute; 142, expression_statement; 143, identifier:units; 144, attribute; 145, expression_statement; 146, identifier:units; 147, attribute; 148, expression_statement; 149, raise_statement; 150, identifier:ValueError; 151, argument_list; 152, identifier:geom; 153, identifier:masses; 154, identifier:on_tol; 155, identifier:mom; 156, call; 157, identifier:ETT; 158, identifier:LINEAR; 159, assignment; 160, identifier:rc; 161, binary_operator:1.0 / (2.0 * mom); 162, identifier:EURC; 163, identifier:ANGFREQ_ATOMIC; 164, assignment; 165, identifier:EURC; 166, identifier:ANGFREQ_SECS; 167, assignment; 168, identifier:EURC; 169, identifier:CYCFREQ_ATOMIC; 170, assignment; 171, identifier:EURC; 172, identifier:CYCFREQ_HZ; 173, assignment; 174, identifier:EURC; 175, identifier:CYCFREQ_MHZ; 176, assignment; 177, identifier:EURC; 178, identifier:WAVENUM_ATOMIC; 179, assignment; 180, identifier:EURC; 181, identifier:WAVENUM_CM; 182, assignment; 183, call; 184, call; 185, attribute; 186, argument_list; 187, subscript; 188, attribute; 189, float:1.0; 190, parenthesized_expression; 191, identifier:rc; 192, binary_operator:PHYS.PLANCK_BAR / (2.0 * mom * PHYS.ME_PER_AMU); 193, identifier:rc; 194, binary_operator:PHYS.PLANCK_BAR / (2.0 * mom * PHYS.ME_PER_AMU) / PHYS.SEC_PER_TA; 195, identifier:rc; 196, binary_operator:PHYS.PLANCK_BAR / (4.0 * np.pi * mom * PHYS.ME_PER_AMU); 197, identifier:rc; 198, binary_operator:PHYS.PLANCK_BAR / (4.0 * np.pi * mom * PHYS.ME_PER_AMU) / \ PHYS.SEC_PER_TA; 199, identifier:rc; 200, binary_operator:PHYS.PLANCK_BAR / (4.0 * np.pi * mom * PHYS.ME_PER_AMU) / \ PHYS.SEC_PER_TA / 1.0e6; 201, identifier:rc; 202, binary_operator:PHYS.PLANCK / (mom * PHYS.ME_PER_AMU) / \ (8.0 * np.pi**2.0 * PHYS.LIGHT_SPEED); 203, identifier:rc; 204, binary_operator:PHYS.PLANCK / (mom * PHYS.ME_PER_AMU) / \ (8.0 * np.pi**2.0 * PHYS.LIGHT_SPEED * PHYS.ANG_PER_BOHR) * 1.0e8; 205, identifier:NotImplementedError; 206, argument_list; 207, attribute; 208, argument_list; 209, identifier:np; 210, identifier:repeat; 211, attribute; 212, integer:3; 213, identifier:mom; 214, integer:0; 215, identifier:PRM; 216, identifier:ZERO_MOMENT_TOL; 217, binary_operator:2.0 * mom; 218, attribute; 219, parenthesized_expression; 220, binary_operator:PHYS.PLANCK_BAR / (2.0 * mom * PHYS.ME_PER_AMU); 221, attribute; 222, attribute; 223, parenthesized_expression; 224, binary_operator:PHYS.PLANCK_BAR / (4.0 * np.pi * mom * PHYS.ME_PER_AMU); 225, line_continuation:\; 226, attribute; 227, binary_operator:PHYS.PLANCK_BAR / (4.0 * np.pi * mom * PHYS.ME_PER_AMU) / \ PHYS.SEC_PER_TA; 228, float:1.0e6; 229, binary_operator:PHYS.PLANCK / (mom * PHYS.ME_PER_AMU); 230, line_continuation:\; 231, parenthesized_expression; 232, binary_operator:PHYS.PLANCK / (mom * PHYS.ME_PER_AMU) / \ (8.0 * np.pi**2.0 * PHYS.LIGHT_SPEED * PHYS.ANG_PER_BOHR); 233, float:1.0e8; 234, string:"Units conversion not yet implemented."; 235, string:"'{0}' is not a valid units value"; 236, identifier:format; 237, identifier:units; 238, identifier:PRM; 239, identifier:ZERO_MOMENT_TOL; 240, float:2.0; 241, identifier:mom; 242, identifier:PHYS; 243, identifier:PLANCK_BAR; 244, binary_operator:2.0 * mom * PHYS.ME_PER_AMU; 245, attribute; 246, parenthesized_expression; 247, identifier:PHYS; 248, identifier:SEC_PER_TA; 249, identifier:PHYS; 250, identifier:PLANCK_BAR; 251, binary_operator:4.0 * np.pi * mom * PHYS.ME_PER_AMU; 252, attribute; 253, parenthesized_expression; 254, identifier:PHYS; 255, identifier:SEC_PER_TA; 256, binary_operator:PHYS.PLANCK_BAR / (4.0 * np.pi * mom * PHYS.ME_PER_AMU); 257, line_continuation:\; 258, attribute; 259, attribute; 260, parenthesized_expression; 261, binary_operator:8.0 * np.pi**2.0 * PHYS.LIGHT_SPEED; 262, binary_operator:PHYS.PLANCK / (mom * PHYS.ME_PER_AMU); 263, line_continuation:\; 264, parenthesized_expression; 265, binary_operator:2.0 * mom; 266, attribute; 267, identifier:PHYS; 268, identifier:PLANCK_BAR; 269, binary_operator:2.0 * mom * PHYS.ME_PER_AMU; 270, binary_operator:4.0 * np.pi * mom; 271, attribute; 272, identifier:PHYS; 273, identifier:PLANCK_BAR; 274, binary_operator:4.0 * np.pi * mom * PHYS.ME_PER_AMU; 275, attribute; 276, parenthesized_expression; 277, identifier:PHYS; 278, identifier:SEC_PER_TA; 279, identifier:PHYS; 280, identifier:PLANCK; 281, binary_operator:mom * PHYS.ME_PER_AMU; 282, binary_operator:8.0 * np.pi**2.0; 283, attribute; 284, attribute; 285, parenthesized_expression; 286, binary_operator:8.0 * np.pi**2.0 * PHYS.LIGHT_SPEED * PHYS.ANG_PER_BOHR; 287, float:2.0; 288, identifier:mom; 289, identifier:PHYS; 290, identifier:ME_PER_AMU; 291, binary_operator:2.0 * mom; 292, attribute; 293, binary_operator:4.0 * np.pi; 294, identifier:mom; 295, identifier:PHYS; 296, identifier:ME_PER_AMU; 297, binary_operator:4.0 * np.pi * mom; 298, attribute; 299, identifier:PHYS; 300, identifier:PLANCK_BAR; 301, binary_operator:4.0 * np.pi * mom * PHYS.ME_PER_AMU; 302, identifier:mom; 303, attribute; 304, float:8.0; 305, binary_operator:np.pi**2.0; 306, identifier:PHYS; 307, identifier:LIGHT_SPEED; 308, identifier:PHYS; 309, identifier:PLANCK; 310, binary_operator:mom * PHYS.ME_PER_AMU; 311, binary_operator:8.0 * np.pi**2.0 * PHYS.LIGHT_SPEED; 312, attribute; 313, float:2.0; 314, identifier:mom; 315, identifier:PHYS; 316, identifier:ME_PER_AMU; 317, float:4.0; 318, attribute; 319, binary_operator:4.0 * np.pi; 320, identifier:mom; 321, identifier:PHYS; 322, identifier:ME_PER_AMU; 323, binary_operator:4.0 * np.pi * mom; 324, attribute; 325, identifier:PHYS; 326, identifier:ME_PER_AMU; 327, attribute; 328, float:2.0; 329, identifier:mom; 330, attribute; 331, binary_operator:8.0 * np.pi**2.0; 332, attribute; 333, identifier:PHYS; 334, identifier:ANG_PER_BOHR; 335, identifier:np; 336, identifier:pi; 337, float:4.0; 338, attribute; 339, binary_operator:4.0 * np.pi; 340, identifier:mom; 341, identifier:PHYS; 342, identifier:ME_PER_AMU; 343, identifier:np; 344, identifier:pi; 345, identifier:PHYS; 346, identifier:ME_PER_AMU; 347, float:8.0; 348, binary_operator:np.pi**2.0; 349, identifier:PHYS; 350, identifier:LIGHT_SPEED; 351, identifier:np; 352, identifier:pi; 353, float:4.0; 354, attribute; 355, attribute; 356, float:2.0; 357, identifier:np; 358, identifier:pi; 359, identifier:np; 360, identifier:pi
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; 4, 21; 4, 22; 4, 23; 4, 24; 4, 25; 4, 26; 7, 27; 7, 28; 8, 29; 8, 30; 9, 31; 11, 32; 12, 33; 12, 34; 12, 35; 12, 36; 12, 37; 14, 38; 14, 39; 18, 40; 20, 41; 20, 42; 20, 43; 20, 44; 23, 45; 23, 46; 23, 47; 23, 48; 23, 49; 23, 50; 23, 51; 23, 52; 23, 53; 23, 54; 23, 55; 26, 56; 28, 57; 28, 58; 30, 59; 30, 60; 32, 61; 32, 62; 33, 63; 33, 64; 34, 65; 34, 66; 35, 67; 35, 68; 36, 69; 37, 70; 38, 71; 39, 72; 40, 73; 40, 74; 41, 75; 41, 76; 43, 77; 44, 78; 44, 79; 44, 80; 45, 81; 45, 82; 47, 83; 48, 84; 48, 85; 48, 86; 49, 87; 49, 88; 49, 89; 50, 90; 50, 91; 50, 92; 51, 93; 51, 94; 51, 95; 52, 96; 52, 97; 52, 98; 53, 99; 53, 100; 53, 101; 54, 102; 54, 103; 54, 104; 55, 105; 55, 106; 61, 107; 64, 108; 65, 109; 67, 110; 71, 111; 71, 112; 72, 113; 73, 114; 73, 115; 73, 116; 74, 117; 74, 118; 76, 119; 76, 120; 77, 121; 78, 122; 78, 123; 80, 124; 82, 125; 82, 126; 83, 127; 84, 128; 84, 129; 86, 130; 87, 131; 87, 132; 89, 133; 90, 134; 90, 135; 92, 136; 93, 137; 93, 138; 95, 139; 96, 140; 96, 141; 98, 142; 99, 143; 99, 144; 101, 145; 102, 146; 102, 147; 104, 148; 106, 149; 113, 150; 113, 151; 118, 152; 118, 153; 118, 154; 121, 155; 121, 156; 123, 157; 123, 158; 124, 159; 127, 160; 127, 161; 129, 162; 129, 163; 130, 164; 132, 165; 132, 166; 133, 167; 135, 168; 135, 169; 136, 170; 138, 171; 138, 172; 139, 173; 141, 174; 141, 175; 142, 176; 144, 177; 144, 178; 145, 179; 147, 180; 147, 181; 148, 182; 149, 183; 151, 184; 156, 185; 156, 186; 159, 187; 159, 188; 161, 189; 161, 190; 164, 191; 164, 192; 167, 193; 167, 194; 170, 195; 170, 196; 173, 197; 173, 198; 176, 199; 176, 200; 179, 201; 179, 202; 182, 203; 182, 204; 183, 205; 183, 206; 184, 207; 184, 208; 185, 209; 185, 210; 186, 211; 186, 212; 187, 213; 187, 214; 188, 215; 188, 216; 190, 217; 192, 218; 192, 219; 194, 220; 194, 221; 196, 222; 196, 223; 198, 224; 198, 225; 198, 226; 200, 227; 200, 228; 202, 229; 202, 230; 202, 231; 204, 232; 204, 233; 206, 234; 207, 235; 207, 236; 208, 237; 211, 238; 211, 239; 217, 240; 217, 241; 218, 242; 218, 243; 219, 244; 220, 245; 220, 246; 221, 247; 221, 248; 222, 249; 222, 250; 223, 251; 224, 252; 224, 253; 226, 254; 226, 255; 227, 256; 227, 257; 227, 258; 229, 259; 229, 260; 231, 261; 232, 262; 232, 263; 232, 264; 244, 265; 244, 266; 245, 267; 245, 268; 246, 269; 251, 270; 251, 271; 252, 272; 252, 273; 253, 274; 256, 275; 256, 276; 258, 277; 258, 278; 259, 279; 259, 280; 260, 281; 261, 282; 261, 283; 262, 284; 262, 285; 264, 286; 265, 287; 265, 288; 266, 289; 266, 290; 269, 291; 269, 292; 270, 293; 270, 294; 271, 295; 271, 296; 274, 297; 274, 298; 275, 299; 275, 300; 276, 301; 281, 302; 281, 303; 282, 304; 282, 305; 283, 306; 283, 307; 284, 308; 284, 309; 285, 310; 286, 311; 286, 312; 291, 313; 291, 314; 292, 315; 292, 316; 293, 317; 293, 318; 297, 319; 297, 320; 298, 321; 298, 322; 301, 323; 301, 324; 303, 325; 303, 326; 305, 327; 305, 328; 310, 329; 310, 330; 311, 331; 311, 332; 312, 333; 312, 334; 318, 335; 318, 336; 319, 337; 319, 338; 323, 339; 323, 340; 324, 341; 324, 342; 327, 343; 327, 344; 330, 345; 330, 346; 331, 347; 331, 348; 332, 349; 332, 350; 338, 351; 338, 352; 339, 353; 339, 354; 348, 355; 348, 356; 354, 357; 354, 358; 355, 359; 355, 360
def rot_consts(geom, masses, units=_EURC.INV_INERTIA, on_tol=_DEF.ORTHONORM_TOL): """Rotational constants for a given molecular system. Calculates the rotational constants for the provided system with numerical value given in the units provided in `units`. The orthnormality tolerance `on_tol` is required in order to be passed through to the :func:`principals` function. If the system is linear or a single atom, the effectively-zero principal moments of inertia will be assigned values of :data:`opan.const.PRM.ZERO_MOMENT_TOL` before transformation into the appropriate rotational constant units. The moments of inertia are always sorted in increasing order as :math:`0 \\leq I_A \\leq I_B \\leq I_C`; the rotational constants calculated from these will thus always be in **decreasing** order as :math:`B_A \\geq B_B \\geq B_C`, retaining the ordering and association with the three principal ``axes[:,i]`` generated by :func:`principals`. Parameters ---------- geom length-3N |npfloat_| -- Coordinates of the atoms masses length-N OR length-3N |npfloat_| -- Atomic masses of the atoms. Length-3N option is to allow calculation of a per-coordinate perturbed value. units :class:`~opan.const.EnumUnitsRotConst`, optional -- Enum value indicating the desired units of the output rotational constants. Default is :data:`~opan.const.EnumUnitsRotConst.INV_INERTIA` :math:`\\left(1\\over \\mathrm{uB^2}\\right)` on_tol |npfloat_|, optional -- Tolerance for deviation from unity/zero for principal axis dot products, within which axes are considered orthonormal. Default is :data:`opan.const.DEF.ORTHONORM_TOL` Returns ------- rc length-3 |npfloat_| -- Vector of rotational constants in the indicated units """ # Imports import numpy as np from ..const import EnumTopType as ETT, EnumUnitsRotConst as EURC, PRM, PHYS # Ensure units are valid if not units in EURC: raise ValueError("'{0}' is not a valid units value".format(units)) ## end if # Retrieve the moments, axes and top type. Geom and masses are proofed # internally in this call. mom, ax, top = principals(geom, masses, on_tol) # Check for special cases if top == ETT.ATOM: # All moments are zero; set to zero-moment threshold mom = np.repeat(PRM.ZERO_MOMENT_TOL, 3) elif top == ETT.LINEAR: # First moment is zero; set to zero-moment threshold mom[0] = PRM.ZERO_MOMENT_TOL ## end if # Calculate the values in the indicated units if units == EURC.INV_INERTIA: # 1/(amu*B^2) rc = 1.0 / (2.0 * mom) elif units == EURC.ANGFREQ_ATOMIC: # 1/Ta rc = PHYS.PLANCK_BAR / (2.0 * mom * PHYS.ME_PER_AMU) elif units == EURC.ANGFREQ_SECS: # 1/s rc = PHYS.PLANCK_BAR / (2.0 * mom * PHYS.ME_PER_AMU) / PHYS.SEC_PER_TA elif units == EURC.CYCFREQ_ATOMIC: # cyc/Ta rc = PHYS.PLANCK_BAR / (4.0 * np.pi * mom * PHYS.ME_PER_AMU) elif units == EURC.CYCFREQ_HZ: # cyc/s rc = PHYS.PLANCK_BAR / (4.0 * np.pi * mom * PHYS.ME_PER_AMU) / \ PHYS.SEC_PER_TA elif units == EURC.CYCFREQ_MHZ: # Mcyc/s rc = PHYS.PLANCK_BAR / (4.0 * np.pi * mom * PHYS.ME_PER_AMU) / \ PHYS.SEC_PER_TA / 1.0e6 elif units == EURC.WAVENUM_ATOMIC: # cyc/B rc = PHYS.PLANCK / (mom * PHYS.ME_PER_AMU) / \ (8.0 * np.pi**2.0 * PHYS.LIGHT_SPEED) elif units == EURC.WAVENUM_CM: # cyc/cm rc = PHYS.PLANCK / (mom * PHYS.ME_PER_AMU) / \ (8.0 * np.pi**2.0 * PHYS.LIGHT_SPEED * PHYS.ANG_PER_BOHR) * 1.0e8 else: # pragma: no cover -- Valid units; not implemented raise NotImplementedError("Units conversion not yet implemented.") ## end if # Return the result return rc
0, module; 1, function_definition; 2, function_name:reference_contexts_for_variants; 3, parameters; 4, block; 5, identifier:variants; 6, identifier:context_size; 7, default_parameter; 8, expression_statement; 9, expression_statement; 10, for_statement; 11, return_statement; 12, identifier:transcript_id_whitelist; 13, None; 14, comment:""" Extract a set of reference contexts for each variant in the collection. Parameters ---------- variants : varcode.VariantCollection context_size : int Max of nucleotides to include to the left and right of the variant in the context sequence. transcript_id_whitelist : set, optional If given, then only consider transcripts whose IDs are in this set. Returns a dictionary from variants to lists of ReferenceContext objects, sorted by max coding sequence length of any transcript. """; 15, assignment; 16, identifier:variant; 17, identifier:variants; 18, block; 19, identifier:result; 20, identifier:result; 21, call; 22, expression_statement; 23, identifier:OrderedDict; 24, argument_list; 25, assignment; 26, subscript; 27, call; 28, identifier:result; 29, identifier:variant; 30, identifier:reference_contexts_for_variant; 31, argument_list; 32, keyword_argument; 33, keyword_argument; 34, keyword_argument; 35, identifier:variant; 36, identifier:variant; 37, identifier:context_size; 38, identifier:context_size; 39, identifier:transcript_id_whitelist; 40, identifier:transcript_id_whitelist
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; 10, 16; 10, 17; 10, 18; 11, 19; 15, 20; 15, 21; 18, 22; 21, 23; 21, 24; 22, 25; 25, 26; 25, 27; 26, 28; 26, 29; 27, 30; 27, 31; 31, 32; 31, 33; 31, 34; 32, 35; 32, 36; 33, 37; 33, 38; 34, 39; 34, 40
def reference_contexts_for_variants( variants, context_size, transcript_id_whitelist=None): """ Extract a set of reference contexts for each variant in the collection. Parameters ---------- variants : varcode.VariantCollection context_size : int Max of nucleotides to include to the left and right of the variant in the context sequence. transcript_id_whitelist : set, optional If given, then only consider transcripts whose IDs are in this set. Returns a dictionary from variants to lists of ReferenceContext objects, sorted by max coding sequence length of any transcript. """ result = OrderedDict() for variant in variants: result[variant] = reference_contexts_for_variant( variant=variant, context_size=context_size, transcript_id_whitelist=transcript_id_whitelist) return result
0, module; 1, function_definition; 2, function_name:ffd; 3, parameters; 4, block; 5, identifier:items; 6, identifier:targets; 7, dictionary_splat_pattern; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, return_statement; 13, identifier:kwargs; 14, comment:"""First-Fit Decreasing This is perhaps the simplest packing heuristic; it simply packs items in the next available bin. This algorithm differs only from Next-Fit Decreasing in having a 'sort'; that is, the items are pre-sorted (largest to smallest). Complexity O(n^2) """; 15, assignment; 16, assignment; 17, assignment; 18, call; 19, identifier:sizes; 20, call; 21, identifier:sizes; 22, call; 23, identifier:items; 24, call; 25, identifier:ff; 26, argument_list; 27, identifier:zip; 28, argument_list; 29, identifier:sorted; 30, argument_list; 31, identifier:map; 32, argument_list; 33, identifier:items; 34, identifier:targets; 35, identifier:items; 36, call; 37, identifier:sizes; 38, keyword_argument; 39, keyword_argument; 40, call; 41, identifier:sizes; 42, identifier:weight; 43, argument_list; 44, identifier:key; 45, call; 46, identifier:reverse; 47, True; 48, attribute; 49, argument_list; 50, identifier:items; 51, dictionary_splat; 52, attribute; 53, argument_list; 54, identifier:operator; 55, identifier:itemgetter; 56, integer:0; 57, identifier:kwargs; 58, identifier:operator; 59, identifier:itemgetter; 60, 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; 7, 13; 8, 14; 9, 15; 10, 16; 11, 17; 12, 18; 15, 19; 15, 20; 16, 21; 16, 22; 17, 23; 17, 24; 18, 25; 18, 26; 20, 27; 20, 28; 22, 29; 22, 30; 24, 31; 24, 32; 26, 33; 26, 34; 28, 35; 28, 36; 30, 37; 30, 38; 30, 39; 32, 40; 32, 41; 36, 42; 36, 43; 38, 44; 38, 45; 39, 46; 39, 47; 40, 48; 40, 49; 43, 50; 43, 51; 45, 52; 45, 53; 48, 54; 48, 55; 49, 56; 51, 57; 52, 58; 52, 59; 53, 60
def ffd(items, targets, **kwargs): """First-Fit Decreasing This is perhaps the simplest packing heuristic; it simply packs items in the next available bin. This algorithm differs only from Next-Fit Decreasing in having a 'sort'; that is, the items are pre-sorted (largest to smallest). Complexity O(n^2) """ sizes = zip(items, weight(items, **kwargs)) sizes = sorted(sizes, key=operator.itemgetter(1), reverse=True) items = map(operator.itemgetter(0), sizes) return ff(items, targets)
0, module; 1, function_definition; 2, function_name:sort_protein_sequences; 3, parameters; 4, block; 5, identifier:protein_sequences; 6, expression_statement; 7, return_statement; 8, comment:""" Sort protein sequences in decreasing order of priority """; 9, call; 10, identifier:list; 11, argument_list; 12, call; 13, identifier:sorted; 14, argument_list; 15, identifier:protein_sequences; 16, keyword_argument; 17, keyword_argument; 18, identifier:key; 19, attribute; 20, identifier:reverse; 21, True; 22, identifier:ProteinSequence; 23, identifier:ascending_sort_key
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 6, 8; 7, 9; 9, 10; 9, 11; 11, 12; 12, 13; 12, 14; 14, 15; 14, 16; 14, 17; 16, 18; 16, 19; 17, 20; 17, 21; 19, 22; 19, 23
def sort_protein_sequences(protein_sequences): """ Sort protein sequences in decreasing order of priority """ return list( sorted( protein_sequences, key=ProteinSequence.ascending_sort_key, reverse=True))
0, module; 1, function_definition; 2, function_name:dump; 3, parameters; 4, block; 5, identifier:obj; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, dictionary_splat_pattern; 10, expression_statement; 11, if_statement; 12, identifier:fp; 13, None; 14, identifier:indent; 15, None; 16, identifier:sort_keys; 17, False; 18, identifier:kw; 19, comment:""" Dump object to a file like object or string. :param obj: :param fp: Open file like object :param int indent: Indent size, default 2 :param bool sort_keys: Optionally sort dictionary keys. :return: Yaml serialized data. """; 20, identifier:fp; 21, block; 22, else_clause; 23, expression_statement; 24, for_statement; 25, block; 26, assignment; 27, identifier:chunk; 28, identifier:iterable; 29, block; 30, return_statement; 31, identifier:iterable; 32, call; 33, expression_statement; 34, call; 35, attribute; 36, argument_list; 37, call; 38, identifier:dumps; 39, argument_list; 40, call; 41, identifier:iterencode; 42, identifier:obj; 43, attribute; 44, argument_list; 45, identifier:obj; 46, keyword_argument; 47, keyword_argument; 48, dictionary_splat; 49, identifier:YAMLEncoder; 50, argument_list; 51, identifier:fp; 52, identifier:write; 53, identifier:chunk; 54, identifier:indent; 55, identifier:indent; 56, identifier:sort_keys; 57, identifier:sort_keys; 58, identifier:kw; 59, keyword_argument; 60, keyword_argument; 61, dictionary_splat; 62, identifier:indent; 63, identifier:indent; 64, identifier:sort_keys; 65, identifier:sort_keys; 66, identifier:kw
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 4, 10; 4, 11; 6, 12; 6, 13; 7, 14; 7, 15; 8, 16; 8, 17; 9, 18; 10, 19; 11, 20; 11, 21; 11, 22; 21, 23; 21, 24; 22, 25; 23, 26; 24, 27; 24, 28; 24, 29; 25, 30; 26, 31; 26, 32; 29, 33; 30, 34; 32, 35; 32, 36; 33, 37; 34, 38; 34, 39; 35, 40; 35, 41; 36, 42; 37, 43; 37, 44; 39, 45; 39, 46; 39, 47; 39, 48; 40, 49; 40, 50; 43, 51; 43, 52; 44, 53; 46, 54; 46, 55; 47, 56; 47, 57; 48, 58; 50, 59; 50, 60; 50, 61; 59, 62; 59, 63; 60, 64; 60, 65; 61, 66
def dump(obj, fp=None, indent=None, sort_keys=False, **kw): """ Dump object to a file like object or string. :param obj: :param fp: Open file like object :param int indent: Indent size, default 2 :param bool sort_keys: Optionally sort dictionary keys. :return: Yaml serialized data. """ if fp: iterable = YAMLEncoder(indent=indent, sort_keys=sort_keys, **kw).iterencode(obj) for chunk in iterable: fp.write(chunk) else: return dumps(obj, indent=indent, sort_keys=sort_keys, **kw)
0, module; 1, function_definition; 2, function_name:sorted_options; 3, parameters; 4, block; 5, identifier:sort_options; 6, expression_statement; 7, return_statement; 8, comment:"""Sort sort options for display. :param sort_options: A dictionary containing the field name as key and asc/desc as value. :returns: A dictionary with sorting options for Invenio-Search-JS. """; 9, list_comprehension; 10, dictionary; 11, for_in_clause; 12, pair; 13, pair; 14, pattern_list; 15, call; 16, string; 17, subscript; 18, string; 19, parenthesized_expression; 20, identifier:k; 21, identifier:v; 22, identifier:sorted; 23, argument_list; 24, string_content:title; 25, identifier:v; 26, string; 27, string_content:value; 28, conditional_expression:'-{0}'.format(k) if v.get('default_order', 'asc') == 'desc' else k; 29, call; 30, keyword_argument; 31, string_content:title; 32, call; 33, comparison_operator:v.get('default_order', 'asc') == 'desc'; 34, identifier:k; 35, attribute; 36, argument_list; 37, identifier:key; 38, lambda; 39, attribute; 40, argument_list; 41, call; 42, string; 43, identifier:sort_options; 44, identifier:items; 45, lambda_parameters; 46, call; 47, string; 48, identifier:format; 49, identifier:k; 50, attribute; 51, argument_list; 52, string_content:desc; 53, identifier:x; 54, attribute; 55, argument_list; 56, string_content:-{0}; 57, identifier:v; 58, identifier:get; 59, string; 60, string; 61, subscript; 62, identifier:get; 63, string; 64, integer:0; 65, string_content:default_order; 66, string_content:asc; 67, identifier:x; 68, integer:1; 69, string_content:order
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 6, 8; 7, 9; 9, 10; 9, 11; 10, 12; 10, 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; 19, 28; 23, 29; 23, 30; 26, 31; 28, 32; 28, 33; 28, 34; 29, 35; 29, 36; 30, 37; 30, 38; 32, 39; 32, 40; 33, 41; 33, 42; 35, 43; 35, 44; 38, 45; 38, 46; 39, 47; 39, 48; 40, 49; 41, 50; 41, 51; 42, 52; 45, 53; 46, 54; 46, 55; 47, 56; 50, 57; 50, 58; 51, 59; 51, 60; 54, 61; 54, 62; 55, 63; 55, 64; 59, 65; 60, 66; 61, 67; 61, 68; 63, 69
def sorted_options(sort_options): """Sort sort options for display. :param sort_options: A dictionary containing the field name as key and asc/desc as value. :returns: A dictionary with sorting options for Invenio-Search-JS. """ return [ { 'title': v['title'], 'value': ('-{0}'.format(k) if v.get('default_order', 'asc') == 'desc' else k), } for k, v in sorted(sort_options.items(), key=lambda x: x[1].get('order', 0)) ]
0, module; 1, function_definition; 2, function_name:info; 3, parameters; 4, block; 5, identifier:self; 6, expression_statement; 7, return_statement; 8, string; 9, call; 10, string_content:Returns information on all the registered checkers. Sorted by namespace and then name :returns a list of CheckerInfo; 11, identifier:sorted; 12, argument_list; 13, call; 14, keyword_argument; 15, attribute; 16, argument_list; 17, identifier:key; 18, lambda; 19, attribute; 20, identifier:values; 21, lambda_parameters; 22, tuple; 23, identifier:self; 24, identifier:_checkers; 25, identifier:x; 26, attribute; 27, attribute; 28, identifier:x; 29, identifier:ns; 30, identifier:x; 31, identifier:name
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 6, 8; 7, 9; 8, 10; 9, 11; 9, 12; 12, 13; 12, 14; 13, 15; 13, 16; 14, 17; 14, 18; 15, 19; 15, 20; 18, 21; 18, 22; 19, 23; 19, 24; 21, 25; 22, 26; 22, 27; 26, 28; 26, 29; 27, 30; 27, 31
def info(self): ''' Returns information on all the registered checkers. Sorted by namespace and then name :returns a list of CheckerInfo ''' return sorted(self._checkers.values(), key=lambda x: (x.ns, x.name))
0, module; 1, function_definition; 2, function_name:extract_from_text; 3, parameters; 4, block; 5, identifier:text; 6, expression_statement; 7, return_statement; 8, comment:""" Extract HAL ids from a text. :param text: The text to extract HAL ids from. :returns: A list of matching HAL ids. >>> sorted(extract_from_text("hal-01258754 hal-01258754v2 foobar")) ['hal-01258754', 'hal-01258754v2'] """; 9, call; 10, attribute; 11, argument_list; 12, identifier:tools; 13, identifier:remove_duplicates; 14, list_comprehension; 15, subscript; 16, for_in_clause; 17, if_clause; 18, identifier:i; 19, integer:0; 20, identifier:i; 21, call; 22, comparison_operator:i != ''; 23, attribute; 24, argument_list; 25, identifier:i; 26, string; 27, identifier:REGEX; 28, identifier:findall; 29, identifier:text
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 6, 8; 7, 9; 9, 10; 9, 11; 10, 12; 10, 13; 11, 14; 14, 15; 14, 16; 14, 17; 15, 18; 15, 19; 16, 20; 16, 21; 17, 22; 21, 23; 21, 24; 22, 25; 22, 26; 23, 27; 23, 28; 24, 29
def extract_from_text(text): """ Extract HAL ids from a text. :param text: The text to extract HAL ids from. :returns: A list of matching HAL ids. >>> sorted(extract_from_text("hal-01258754 hal-01258754v2 foobar")) ['hal-01258754', 'hal-01258754v2'] """ return tools.remove_duplicates([i[0] for i in REGEX.findall(text) if i != ''])
0, module; 1, function_definition; 2, function_name:_show_documentation; 3, parameters; 4, block; 5, identifier:self; 6, expression_statement; 7, expression_statement; 8, for_statement; 9, expression_statement; 10, expression_statement; 11, if_statement; 12, expression_statement; 13, expression_statement; 14, while_statement; 15, comment:""" Shows all documents of the current groundwork app in the console. Documents are sorted bei its names, except "main", which gets set to the beginning. """; 16, assignment; 17, pattern_list; 18, call; 19, block; 20, assignment; 21, assignment; 22, comparison_operator:main is not None; 23, block; 24, assignment; 25, assignment; 26, comparison_operator:user_answer != "X"; 27, block; 28, identifier:documents; 29, list; 30, identifier:key; 31, identifier:document; 32, attribute; 33, argument_list; 34, if_statement; 35, identifier:documents; 36, call; 37, identifier:main; 38, call; 39, identifier:main; 40, None; 41, expression_statement; 42, identifier:user_answer; 43, string:""; 44, identifier:index; 45, integer:0; 46, identifier:user_answer; 47, string:"X"; 48, if_statement; 49, if_statement; 50, expression_statement; 51, expression_statement; 52, expression_statement; 53, expression_statement; 54, expression_statement; 55, expression_statement; 56, expression_statement; 57, expression_statement; 58, if_statement; 59, if_statement; 60, expression_statement; 61, expression_statement; 62, if_statement; 63, expression_statement; 64, if_statement; 65, call; 66, identifier:items; 67, comparison_operator:key != "main"; 68, block; 69, identifier:sorted; 70, argument_list; 71, attribute; 72, argument_list; 73, call; 74, comparison_operator:index < 0; 75, block; 76, comparison_operator:index > len(documents) - 1; 77, block; 78, assignment; 79, call; 80, call; 81, assignment; 82, call; 83, call; 84, call; 85, assignment; 86, comparison_operator:index < len(documents) - 1; 87, block; 88, comparison_operator:index > 0; 89, block; 90, augmented_assignment; 91, call; 92, comparison_operator:index < len(documents) - 1; 93, block; 94, elif_clause; 95, else_clause; 96, assignment; 97, comparison_operator:user_answer == "N"; 98, block; 99, elif_clause; 100, attribute; 101, argument_list; 102, identifier:key; 103, string:"main"; 104, expression_statement; 105, identifier:documents; 106, keyword_argument; 107, attribute; 108, identifier:get; 109, string:"main"; 110, attribute; 111, argument_list; 112, identifier:index; 113, integer:0; 114, expression_statement; 115, identifier:index; 116, binary_operator:len(documents) - 1; 117, expression_statement; 118, identifier:document; 119, subscript; 120, attribute; 121, argument_list; 122, identifier:echo; 123, argument_list; 124, identifier:source; 125, binary_operator:"This document is registered by '%s' under the name '%s'" % (document.plugin.name, document.name); 126, identifier:echo; 127, argument_list; 128, identifier:echo; 129, argument_list; 130, identifier:echo; 131, argument_list; 132, identifier:commands; 133, string:"Actions: "; 134, identifier:index; 135, binary_operator:len(documents) - 1; 136, expression_statement; 137, identifier:index; 138, integer:0; 139, expression_statement; 140, identifier:commands; 141, string:"E[x]it"; 142, identifier:echo; 143, argument_list; 144, identifier:index; 145, binary_operator:len(documents) - 1; 146, expression_statement; 147, comparison_operator:index > 0; 148, block; 149, block; 150, identifier:user_answer; 151, call; 152, identifier:user_answer; 153, string:"N"; 154, expression_statement; 155, comparison_operator:user_answer == "P"; 156, block; 157, attribute; 158, identifier:get; 159, call; 160, identifier:key; 161, lambda; 162, attribute; 163, identifier:documents; 164, identifier:documents; 165, identifier:insert; 166, integer:0; 167, tuple; 168, assignment; 169, call; 170, integer:1; 171, assignment; 172, subscript; 173, integer:1; 174, identifier:os; 175, identifier:system; 176, conditional_expression:'cls' if os.name == 'nt' else 'clear'; 177, call; 178, string:"This document is registered by '%s' under the name '%s'"; 179, tuple; 180, binary_operator:"-" * len(source); 181, identifier:source; 182, binary_operator:"-" * len(source); 183, call; 184, integer:1; 185, augmented_assignment; 186, augmented_assignment; 187, identifier:commands; 188, call; 189, integer:1; 190, assignment; 191, identifier:index; 192, integer:0; 193, expression_statement; 194, expression_statement; 195, attribute; 196, argument_list; 197, augmented_assignment; 198, identifier:user_answer; 199, string:"P"; 200, expression_statement; 201, attribute; 202, identifier:documents; 203, attribute; 204, argument_list; 205, lambda_parameters; 206, subscript; 207, identifier:self; 208, identifier:app; 209, attribute; 210, identifier:main; 211, identifier:index; 212, integer:0; 213, identifier:len; 214, argument_list; 215, identifier:index; 216, binary_operator:len(documents) - 1; 217, identifier:documents; 218, identifier:index; 219, string; 220, comparison_operator:os.name == 'nt'; 221, string; 222, attribute; 223, argument_list; 224, attribute; 225, attribute; 226, string:"-"; 227, call; 228, string:"-"; 229, call; 230, identifier:len; 231, argument_list; 232, identifier:commands; 233, string:"[N]ext, "; 234, identifier:commands; 235, string:"[P]revious, "; 236, identifier:len; 237, argument_list; 238, identifier:default; 239, string:"N"; 240, assignment; 241, assignment; 242, call; 243, identifier:upper; 244, identifier:index; 245, integer:1; 246, augmented_assignment; 247, identifier:self; 248, identifier:app; 249, identifier:documents; 250, identifier:append; 251, tuple; 252, identifier:x; 253, identifier:x; 254, integer:0; 255, identifier:main; 256, identifier:name; 257, identifier:documents; 258, call; 259, integer:1; 260, string_content:cls; 261, attribute; 262, string; 263, string_content:clear; 264, call; 265, identifier:render; 266, keyword_argument; 267, keyword_argument; 268, attribute; 269, identifier:name; 270, identifier:document; 271, identifier:name; 272, identifier:len; 273, argument_list; 274, identifier:len; 275, argument_list; 276, identifier:documents; 277, identifier:documents; 278, identifier:default; 279, string:"P"; 280, identifier:default; 281, string:"X"; 282, identifier:prompt; 283, argument_list; 284, identifier:index; 285, integer:1; 286, identifier:key; 287, identifier:document; 288, identifier:len; 289, argument_list; 290, identifier:os; 291, identifier:name; 292, string_content:nt; 293, attribute; 294, argument_list; 295, identifier:app; 296, attribute; 297, identifier:plugin; 298, attribute; 299, identifier:document; 300, identifier:plugin; 301, identifier:source; 302, identifier:source; 303, string:"Select your action"; 304, keyword_argument; 305, identifier:documents; 306, call; 307, identifier:from_string; 308, attribute; 309, identifier:self; 310, identifier:app; 311, identifier:document; 312, identifier:plugin; 313, identifier:default; 314, identifier:default; 315, identifier:Environment; 316, argument_list; 317, identifier:document; 318, identifier:content
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; 6, 15; 7, 16; 8, 17; 8, 18; 8, 19; 9, 20; 10, 21; 11, 22; 11, 23; 12, 24; 13, 25; 14, 26; 14, 27; 16, 28; 16, 29; 17, 30; 17, 31; 18, 32; 18, 33; 19, 34; 20, 35; 20, 36; 21, 37; 21, 38; 22, 39; 22, 40; 23, 41; 24, 42; 24, 43; 25, 44; 25, 45; 26, 46; 26, 47; 27, 48; 27, 49; 27, 50; 27, 51; 27, 52; 27, 53; 27, 54; 27, 55; 27, 56; 27, 57; 27, 58; 27, 59; 27, 60; 27, 61; 27, 62; 27, 63; 27, 64; 32, 65; 32, 66; 34, 67; 34, 68; 36, 69; 36, 70; 38, 71; 38, 72; 41, 73; 48, 74; 48, 75; 49, 76; 49, 77; 50, 78; 51, 79; 52, 80; 53, 81; 54, 82; 55, 83; 56, 84; 57, 85; 58, 86; 58, 87; 59, 88; 59, 89; 60, 90; 61, 91; 62, 92; 62, 93; 62, 94; 62, 95; 63, 96; 64, 97; 64, 98; 64, 99; 65, 100; 65, 101; 67, 102; 67, 103; 68, 104; 70, 105; 70, 106; 71, 107; 71, 108; 72, 109; 73, 110; 73, 111; 74, 112; 74, 113; 75, 114; 76, 115; 76, 116; 77, 117; 78, 118; 78, 119; 79, 120; 79, 121; 80, 122; 80, 123; 81, 124; 81, 125; 82, 126; 82, 127; 83, 128; 83, 129; 84, 130; 84, 131; 85, 132; 85, 133; 86, 134; 86, 135; 87, 136; 88, 137; 88, 138; 89, 139; 90, 140; 90, 141; 91, 142; 91, 143; 92, 144; 92, 145; 93, 146; 94, 147; 94, 148; 95, 149; 96, 150; 96, 151; 97, 152; 97, 153; 98, 154; 99, 155; 99, 156; 100, 157; 100, 158; 104, 159; 106, 160; 106, 161; 107, 162; 107, 163; 110, 164; 110, 165; 111, 166; 111, 167; 114, 168; 116, 169; 116, 170; 117, 171; 119, 172; 119, 173; 120, 174; 120, 175; 121, 176; 123, 177; 125, 178; 125, 179; 127, 180; 129, 181; 131, 182; 135, 183; 135, 184; 136, 185; 139, 186; 143, 187; 145, 188; 145, 189; 146, 190; 147, 191; 147, 192; 148, 193; 149, 194; 151, 195; 151, 196; 154, 197; 155, 198; 155, 199; 156, 200; 157, 201; 157, 202; 159, 203; 159, 204; 161, 205; 161, 206; 162, 207; 162, 208; 167, 209; 167, 210; 168, 211; 168, 212; 169, 213; 169, 214; 171, 215; 171, 216; 172, 217; 172, 218; 176, 219; 176, 220; 176, 221; 177, 222; 177, 223; 179, 224; 179, 225; 180, 226; 180, 227; 182, 228; 182, 229; 183, 230; 183, 231; 185, 232; 185, 233; 186, 234; 186, 235; 188, 236; 188, 237; 190, 238; 190, 239; 193, 240; 194, 241; 195, 242; 195, 243; 197, 244; 197, 245; 200, 246; 201, 247; 201, 248; 203, 249; 203, 250; 204, 251; 205, 252; 206, 253; 206, 254; 209, 255; 209, 256; 214, 257; 216, 258; 216, 259; 219, 260; 220, 261; 220, 262; 221, 263; 222, 264; 222, 265; 223, 266; 223, 267; 224, 268; 224, 269; 225, 270; 225, 271; 227, 272; 227, 273; 229, 274; 229, 275; 231, 276; 237, 277; 240, 278; 240, 279; 241, 280; 241, 281; 242, 282; 242, 283; 246, 284; 246, 285; 251, 286; 251, 287; 258, 288; 258, 289; 261, 290; 261, 291; 262, 292; 264, 293; 264, 294; 266, 295; 266, 296; 267, 297; 267, 298; 268, 299; 268, 300; 273, 301; 275, 302; 283, 303; 283, 304; 289, 305; 293, 306; 293, 307; 294, 308; 296, 309; 296, 310; 298, 311; 298, 312; 304, 313; 304, 314; 306, 315; 306, 316; 308, 317; 308, 318
def _show_documentation(self): """ Shows all documents of the current groundwork app in the console. Documents are sorted bei its names, except "main", which gets set to the beginning. """ documents = [] for key, document in self.app.documents.get().items(): if key != "main": documents.append((key, document)) documents = sorted(documents, key=lambda x: x[0]) main = self.app.documents.get("main") if main is not None: documents.insert(0, (main.name, main)) user_answer = "" index = 0 while user_answer != "X": if index < 0: index = 0 if index > len(documents) - 1: index = len(documents) - 1 document = documents[index][1] os.system('cls' if os.name == 'nt' else 'clear') echo(Environment().from_string(document.content).render(app=self.app, plugin=document.plugin)) source = "This document is registered by '%s' under the name '%s'" % (document.plugin.name, document.name) echo("-" * len(source)) echo(source) echo("-" * len(source)) commands = "Actions: " if index < len(documents) - 1: commands += "[N]ext, " if index > 0: commands += "[P]revious, " commands += "E[x]it" echo(commands) if index < len(documents) - 1: default = "N" elif index > 0: default = "P" else: default = "X" user_answer = prompt("Select your action", default=default).upper() if user_answer == "N": index += 1 elif user_answer == "P": index -= 1
0, module; 1, function_definition; 2, function_name:dispersion_ranking_NN; 3, parameters; 4, block; 5, identifier:self; 6, identifier:nnm; 7, default_parameter; 8, expression_statement; 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:num_norm_avg; 21, integer:50; 22, comment:"""Computes the spatial dispersion factors for each gene. Parameters ---------- nnm - scipy.sparse, float Square cell-to-cell nearest-neighbor matrix. num_norm_avg - int, optional, default 50 The top 'num_norm_avg' dispersions are averaged to determine the normalization factor when calculating the weights. This ensures that outlier genes do not significantly skew the weight distribution. Returns: ------- indices - ndarray, int The indices corresponding to the gene weights sorted in decreasing order. weights - ndarray, float The vector of gene weights. """; 23, call; 24, assignment; 25, assignment; 26, assignment; 27, assignment; 28, assignment; 29, assignment; 30, assignment; 31, assignment; 32, assignment; 33, identifier:weights; 34, attribute; 35, argument_list; 36, identifier:D_avg; 37, subscript; 38, pattern_list; 39, call; 40, identifier:dispersions; 41, call; 42, subscript; 43, binary_operator:var[mu > 0] / mu[mu > 0]; 44, subscript; 45, call; 46, identifier:ma; 47, call; 48, subscript; 49, identifier:ma; 50, identifier:weights; 51, call; 52, subscript; 53, identifier:weights; 54, identifier:self; 55, identifier:knn_avg; 56, identifier:nnm; 57, attribute; 58, string; 59, identifier:mu; 60, identifier:var; 61, attribute; 62, argument_list; 63, attribute; 64, argument_list; 65, identifier:dispersions; 66, comparison_operator:mu > 0; 67, subscript; 68, subscript; 69, attribute; 70, string; 71, attribute; 72, argument_list; 73, attribute; 74, argument_list; 75, identifier:dispersions; 76, comparison_operator:dispersions >= ma; 77, attribute; 78, argument_list; 79, attribute; 80, string; 81, attribute; 82, identifier:layers; 83, string_content:X_knn_avg; 84, identifier:sf; 85, identifier:mean_variance_axis; 86, identifier:D_avg; 87, keyword_argument; 88, identifier:np; 89, identifier:zeros; 90, attribute; 91, identifier:mu; 92, integer:0; 93, identifier:var; 94, comparison_operator:mu > 0; 95, identifier:mu; 96, comparison_operator:mu > 0; 97, attribute; 98, identifier:var; 99, string_content:spatial_dispersions; 100, identifier:dispersions; 101, identifier:copy; 102, subscript; 103, identifier:mean; 104, identifier:dispersions; 105, identifier:ma; 106, parenthesized_expression; 107, identifier:flatten; 108, attribute; 109, identifier:var; 110, string_content:weights; 111, identifier:self; 112, identifier:adata; 113, identifier:axis; 114, integer:0; 115, identifier:var; 116, identifier:size; 117, identifier:mu; 118, integer:0; 119, identifier:mu; 120, integer:0; 121, identifier:self; 122, identifier:adata; 123, call; 124, slice; 125, binary_operator:(dispersions / dispersions.max())**0.5; 126, identifier:self; 127, identifier:adata; 128, attribute; 129, argument_list; 130, unary_operator; 131, parenthesized_expression; 132, float:0.5; 133, identifier:np; 134, identifier:sort; 135, identifier:dispersions; 136, identifier:num_norm_avg; 137, binary_operator:dispersions / dispersions.max(); 138, identifier:dispersions; 139, call; 140, attribute; 141, argument_list; 142, identifier:dispersions; 143, identifier:max
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; 9, 23; 10, 24; 11, 25; 12, 26; 13, 27; 14, 28; 15, 29; 16, 30; 17, 31; 18, 32; 19, 33; 23, 34; 23, 35; 24, 36; 24, 37; 25, 38; 25, 39; 26, 40; 26, 41; 27, 42; 27, 43; 28, 44; 28, 45; 29, 46; 29, 47; 30, 48; 30, 49; 31, 50; 31, 51; 32, 52; 32, 53; 34, 54; 34, 55; 35, 56; 37, 57; 37, 58; 38, 59; 38, 60; 39, 61; 39, 62; 41, 63; 41, 64; 42, 65; 42, 66; 43, 67; 43, 68; 44, 69; 44, 70; 45, 71; 45, 72; 47, 73; 47, 74; 48, 75; 48, 76; 51, 77; 51, 78; 52, 79; 52, 80; 57, 81; 57, 82; 58, 83; 61, 84; 61, 85; 62, 86; 62, 87; 63, 88; 63, 89; 64, 90; 66, 91; 66, 92; 67, 93; 67, 94; 68, 95; 68, 96; 69, 97; 69, 98; 70, 99; 71, 100; 71, 101; 73, 102; 73, 103; 76, 104; 76, 105; 77, 106; 77, 107; 79, 108; 79, 109; 80, 110; 81, 111; 81, 112; 87, 113; 87, 114; 90, 115; 90, 116; 94, 117; 94, 118; 96, 119; 96, 120; 97, 121; 97, 122; 102, 123; 102, 124; 106, 125; 108, 126; 108, 127; 123, 128; 123, 129; 124, 130; 125, 131; 125, 132; 128, 133; 128, 134; 129, 135; 130, 136; 131, 137; 137, 138; 137, 139; 139, 140; 139, 141; 140, 142; 140, 143
def dispersion_ranking_NN(self, nnm, num_norm_avg=50): """Computes the spatial dispersion factors for each gene. Parameters ---------- nnm - scipy.sparse, float Square cell-to-cell nearest-neighbor matrix. num_norm_avg - int, optional, default 50 The top 'num_norm_avg' dispersions are averaged to determine the normalization factor when calculating the weights. This ensures that outlier genes do not significantly skew the weight distribution. Returns: ------- indices - ndarray, int The indices corresponding to the gene weights sorted in decreasing order. weights - ndarray, float The vector of gene weights. """ self.knn_avg(nnm) D_avg = self.adata.layers['X_knn_avg'] mu, var = sf.mean_variance_axis(D_avg, axis=0) dispersions = np.zeros(var.size) dispersions[mu > 0] = var[mu > 0] / mu[mu > 0] self.adata.var['spatial_dispersions'] = dispersions.copy() ma = np.sort(dispersions)[-num_norm_avg:].mean() dispersions[dispersions >= ma] = ma weights = ((dispersions / dispersions.max())**0.5).flatten() self.adata.var['weights'] = weights return weights
0, module; 1, function_definition; 2, function_name:canonical_ops; 3, parameters; 4, block; 5, identifier:ops; 6, expression_statement; 7, expression_statement; 8, return_statement; 9, string; 10, assignment; 11, identifier:new_ops; 12, string_content:Returns the given operations array sorted with duplicates removed. @param ops checker.Ops @return: checker.Ops; 13, identifier:new_ops; 14, call; 15, identifier:sorted; 16, argument_list; 17, call; 18, keyword_argument; 19, identifier:set; 20, argument_list; 21, identifier:key; 22, lambda; 23, identifier:ops; 24, lambda_parameters; 25, tuple; 26, identifier:x; 27, attribute; 28, attribute; 29, identifier:x; 30, identifier:entity; 31, identifier:x; 32, identifier:action
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 4, 8; 6, 9; 7, 10; 8, 11; 9, 12; 10, 13; 10, 14; 14, 15; 14, 16; 16, 17; 16, 18; 17, 19; 17, 20; 18, 21; 18, 22; 20, 23; 22, 24; 22, 25; 24, 26; 25, 27; 25, 28; 27, 29; 27, 30; 28, 31; 28, 32
def canonical_ops(ops): ''' Returns the given operations array sorted with duplicates removed. @param ops checker.Ops @return: checker.Ops ''' new_ops = sorted(set(ops), key=lambda x: (x.entity, x.action)) return new_ops
0, module; 1, function_definition; 2, function_name:extract_from_text; 3, parameters; 4, block; 5, identifier:text; 6, expression_statement; 7, comment:# Remove the leading "arxiv:".; 8, return_statement; 9, comment:""" Extract arXiv IDs from a text. :param text: The text to extract arXiv IDs from. :returns: A list of matching arXiv IDs, in canonical form. >>> sorted(extract_from_text('1506.06690 1506.06690v1 arXiv:1506.06690 arXiv:1506.06690v1 arxiv:1506.06690 arxiv:1506.06690v1 math.GT/0309136 abcdf bar1506.06690foo mare.GG/0309136')) ['1506.06690', '1506.06690v1', 'math.GT/0309136'] """; 10, call; 11, attribute; 12, argument_list; 13, identifier:tools; 14, identifier:remove_duplicates; 15, list_comprehension; 16, call; 17, for_in_clause; 18, if_clause; 19, attribute; 20, argument_list; 21, identifier:i; 22, call; 23, comparison_operator:i[0] != ''; 24, identifier:re; 25, identifier:sub; 26, string:"arxiv:"; 27, string:""; 28, subscript; 29, keyword_argument; 30, attribute; 31, argument_list; 32, subscript; 33, string; 34, identifier:i; 35, integer:0; 36, identifier:flags; 37, attribute; 38, identifier:REGEX; 39, identifier:findall; 40, identifier:text; 41, identifier:i; 42, integer:0; 43, identifier:re; 44, identifier:IGNORECASE
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 4, 8; 6, 9; 8, 10; 10, 11; 10, 12; 11, 13; 11, 14; 12, 15; 15, 16; 15, 17; 15, 18; 16, 19; 16, 20; 17, 21; 17, 22; 18, 23; 19, 24; 19, 25; 20, 26; 20, 27; 20, 28; 20, 29; 22, 30; 22, 31; 23, 32; 23, 33; 28, 34; 28, 35; 29, 36; 29, 37; 30, 38; 30, 39; 31, 40; 32, 41; 32, 42; 37, 43; 37, 44
def extract_from_text(text): """ Extract arXiv IDs from a text. :param text: The text to extract arXiv IDs from. :returns: A list of matching arXiv IDs, in canonical form. >>> sorted(extract_from_text('1506.06690 1506.06690v1 arXiv:1506.06690 arXiv:1506.06690v1 arxiv:1506.06690 arxiv:1506.06690v1 math.GT/0309136 abcdf bar1506.06690foo mare.GG/0309136')) ['1506.06690', '1506.06690v1', 'math.GT/0309136'] """ # Remove the leading "arxiv:". return tools.remove_duplicates([re.sub("arxiv:", "", i[0], flags=re.IGNORECASE) for i in REGEX.findall(text) if i[0] != ''])
0, module; 1, function_definition; 2, function_name:serialize_text; 3, parameters; 4, block; 5, identifier:self; 6, expression_statement; 7, if_statement; 8, expression_statement; 9, expression_statement; 10, for_statement; 11, return_statement; 12, string; 13, boolean_operator; 14, block; 15, assignment; 16, assignment; 17, identifier:uri; 18, identifier:od; 19, block; 20, call; 21, string_content:Returns a serialized form of the Namepace. All the elements in the namespace are sorted by URI, joined to the associated prefix with a colon and separated with spaces. :return: bytes; 22, comparison_operator:self._uri_to_prefix is None; 23, comparison_operator:len(self._uri_to_prefix) == 0; 24, return_statement; 25, identifier:od; 26, call; 27, identifier:data; 28, list; 29, expression_statement; 30, attribute; 31, argument_list; 32, attribute; 33, None; 34, call; 35, integer:0; 36, string; 37, attribute; 38, argument_list; 39, call; 40, call; 41, identifier:encode; 42, string; 43, identifier:self; 44, identifier:_uri_to_prefix; 45, identifier:len; 46, argument_list; 47, identifier:collections; 48, identifier:OrderedDict; 49, call; 50, attribute; 51, argument_list; 52, attribute; 53, argument_list; 54, string_content:utf-8; 55, attribute; 56, identifier:sorted; 57, argument_list; 58, identifier:data; 59, identifier:append; 60, binary_operator:uri + ':' + od[uri]; 61, string; 62, identifier:join; 63, identifier:data; 64, identifier:self; 65, identifier:_uri_to_prefix; 66, call; 67, binary_operator:uri + ':'; 68, subscript; 69, string_content:; 70, attribute; 71, argument_list; 72, identifier:uri; 73, string; 74, identifier:od; 75, identifier:uri; 76, attribute; 77, identifier:items; 78, string_content::; 79, identifier:self; 80, identifier:_uri_to_prefix
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; 10, 18; 10, 19; 11, 20; 12, 21; 13, 22; 13, 23; 14, 24; 15, 25; 15, 26; 16, 27; 16, 28; 19, 29; 20, 30; 20, 31; 22, 32; 22, 33; 23, 34; 23, 35; 24, 36; 26, 37; 26, 38; 29, 39; 30, 40; 30, 41; 31, 42; 32, 43; 32, 44; 34, 45; 34, 46; 37, 47; 37, 48; 38, 49; 39, 50; 39, 51; 40, 52; 40, 53; 42, 54; 46, 55; 49, 56; 49, 57; 50, 58; 50, 59; 51, 60; 52, 61; 52, 62; 53, 63; 55, 64; 55, 65; 57, 66; 60, 67; 60, 68; 61, 69; 66, 70; 66, 71; 67, 72; 67, 73; 68, 74; 68, 75; 70, 76; 70, 77; 73, 78; 76, 79; 76, 80
def serialize_text(self): '''Returns a serialized form of the Namepace. All the elements in the namespace are sorted by URI, joined to the associated prefix with a colon and separated with spaces. :return: bytes ''' if self._uri_to_prefix is None or len(self._uri_to_prefix) == 0: return b'' od = collections.OrderedDict(sorted(self._uri_to_prefix.items())) data = [] for uri in od: data.append(uri + ':' + od[uri]) return ' '.join(data).encode('utf-8')
0, module; 1, function_definition; 2, function_name:process; 3, parameters; 4, block; 5, identifier:self; 6, identifier:versions; 7, expression_statement; 8, for_statement; 9, comment:"""Logging version sorted ascending by tool name."""; 10, identifier:tool_name; 11, call; 12, block; 13, identifier:sorted; 14, argument_list; 15, expression_statement; 16, expression_statement; 17, call; 18, assignment; 19, call; 20, attribute; 21, argument_list; 22, identifier:version; 23, subscript; 24, attribute; 25, argument_list; 26, identifier:versions; 27, identifier:keys; 28, identifier:versions; 29, identifier:tool_name; 30, identifier:self; 31, identifier:_log; 32, binary_operator:"Using tool '%s', %s" % (tool_name, version); 33, string:"Using tool '%s', %s"; 34, tuple; 35, identifier:tool_name; 36, identifier:version
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 7, 9; 8, 10; 8, 11; 8, 12; 11, 13; 11, 14; 12, 15; 12, 16; 14, 17; 15, 18; 16, 19; 17, 20; 17, 21; 18, 22; 18, 23; 19, 24; 19, 25; 20, 26; 20, 27; 23, 28; 23, 29; 24, 30; 24, 31; 25, 32; 32, 33; 32, 34; 34, 35; 34, 36
def process(self, versions): """Logging version sorted ascending by tool name.""" for tool_name in sorted(versions.keys()): version = versions[tool_name] self._log("Using tool '%s', %s" % (tool_name, version))
0, module; 1, function_definition; 2, function_name:most_similar_catchments; 3, parameters; 4, block; 5, identifier:self; 6, identifier:subject_catchment; 7, identifier:similarity_dist_function; 8, default_parameter; 9, default_parameter; 10, expression_statement; 11, if_statement; 12, expression_statement; 13, comment:# At least 10 AMAX records; 14, expression_statement; 15, comment:# Add subject catchment if required (may not exist in database, so add after querying db; 16, if_statement; 17, comment:# Store the similarity distance as an additional attribute for each catchment; 18, for_statement; 19, comment:# Then simply sort by this attribute; 20, expression_statement; 21, comment:# Limit catchments until total amax_records counts is at least `records_limit`, default 500; 22, expression_statement; 23, expression_statement; 24, for_statement; 25, return_statement; 26, identifier:records_limit; 27, integer:500; 28, identifier:include_subject_catchment; 29, string; 30, comment:""" Return a list of catchments sorted by hydrological similarity defined by `similarity_distance_function` :param subject_catchment: subject catchment to find similar catchments for :type subject_catchment: :class:`floodestimation.entities.Catchment` :param similarity_dist_function: a method returning a similarity distance measure with 2 arguments, both :class:`floodestimation.entities.Catchment` objects :param include_subject_catchment: - `auto`: include subject catchment if suitable for pooling and if urbext < 0.03 - `force`: always include subject catchment having at least 10 years of data - `exclude`: do not include the subject catchment :type include_subject_catchment: str :return: list of catchments sorted by similarity :type: list of :class:`floodestimation.entities.Catchment` """; 31, comparison_operator:include_subject_catchment not in ['auto', 'force', 'exclude']; 32, block; 33, assignment; 34, assignment; 35, comparison_operator:include_subject_catchment == 'force'; 36, block; 37, elif_clause; 38, identifier:catchment; 39, identifier:catchments; 40, block; 41, call; 42, assignment; 43, assignment; 44, identifier:catchment; 45, identifier:catchments; 46, block; 47, identifier:catchments_limited; 48, string_content:auto; 49, identifier:include_subject_catchment; 50, list; 51, raise_statement; 52, identifier:query; 53, parenthesized_expression; 54, identifier:catchments; 55, call; 56, identifier:include_subject_catchment; 57, string; 58, if_statement; 59, comparison_operator:include_subject_catchment == 'auto'; 60, block; 61, expression_statement; 62, attribute; 63, argument_list; 64, identifier:amax_records_count; 65, integer:0; 66, identifier:catchments_limited; 67, list; 68, expression_statement; 69, expression_statement; 70, if_statement; 71, string; 72, string; 73, string; 74, call; 75, call; 76, attribute; 77, argument_list; 78, string_content:force; 79, comparison_operator:len(subject_catchment.amax_records) >= 10; 80, comment:# Never include short-record catchments; 81, block; 82, identifier:include_subject_catchment; 83, string; 84, if_statement; 85, assignment; 86, identifier:catchments; 87, identifier:sort; 88, keyword_argument; 89, call; 90, augmented_assignment; 91, comparison_operator:amax_records_count >= records_limit; 92, block; 93, string_content:auto; 94, string_content:force; 95, string_content:exclude; 96, identifier:ValueError; 97, argument_list; 98, attribute; 99, argument_list; 100, identifier:query; 101, identifier:all; 102, call; 103, integer:10; 104, expression_statement; 105, string_content:auto; 106, boolean_operator; 107, block; 108, attribute; 109, call; 110, identifier:key; 111, call; 112, attribute; 113, argument_list; 114, identifier:amax_records_count; 115, attribute; 116, identifier:amax_records_count; 117, identifier:records_limit; 118, break_statement; 119, binary_operator:"Parameter `include_subject_catchment={}` invalid.".format(include_subject_catchment) + "Must be one of `auto`, `force` or `exclude`."; 120, call; 121, identifier:having; 122, comparison_operator:func.count(AmaxRecord.catchment_id) >= 10; 123, identifier:len; 124, argument_list; 125, call; 126, boolean_operator; 127, line_continuation:\; 128, parenthesized_expression; 129, expression_statement; 130, identifier:catchment; 131, identifier:similarity_dist; 132, identifier:similarity_dist_function; 133, argument_list; 134, identifier:attrgetter; 135, argument_list; 136, identifier:catchments_limited; 137, identifier:append; 138, identifier:catchment; 139, identifier:catchment; 140, identifier:record_length; 141, call; 142, string:"Must be one of `auto`, `force` or `exclude`."; 143, attribute; 144, argument_list; 145, call; 146, integer:10; 147, attribute; 148, attribute; 149, argument_list; 150, comparison_operator:len(subject_catchment.amax_records) >= 10; 151, attribute; 152, boolean_operator; 153, call; 154, identifier:subject_catchment; 155, identifier:catchment; 156, string; 157, attribute; 158, argument_list; 159, call; 160, identifier:group_by; 161, identifier:Catchment; 162, attribute; 163, argument_list; 164, identifier:subject_catchment; 165, identifier:amax_records; 166, identifier:catchments; 167, identifier:append; 168, identifier:subject_catchment; 169, call; 170, integer:10; 171, identifier:subject_catchment; 172, identifier:is_suitable_for_pooling; 173, comparison_operator:subject_catchment.descriptors.urbext2000 < 0.03; 174, comparison_operator:subject_catchment.descriptors.urbext2000 is None; 175, attribute; 176, argument_list; 177, string_content:similarity_dist; 178, string:"Parameter `include_subject_catchment={}` invalid."; 179, identifier:format; 180, identifier:include_subject_catchment; 181, attribute; 182, argument_list; 183, identifier:func; 184, identifier:count; 185, attribute; 186, identifier:len; 187, argument_list; 188, attribute; 189, float:0.03; 190, attribute; 191, None; 192, identifier:catchments; 193, identifier:append; 194, identifier:subject_catchment; 195, call; 196, identifier:filter; 197, comparison_operator:Catchment.id != subject_catchment.id; 198, attribute; 199, call; 200, comparison_operator:AmaxRecord.flag == 0; 201, identifier:AmaxRecord; 202, identifier:catchment_id; 203, attribute; 204, attribute; 205, identifier:urbext2000; 206, attribute; 207, identifier:urbext2000; 208, attribute; 209, argument_list; 210, attribute; 211, attribute; 212, identifier:Catchment; 213, identifier:is_suitable_for_pooling; 214, identifier:or_; 215, argument_list; 216, attribute; 217, integer:0; 218, identifier:subject_catchment; 219, identifier:amax_records; 220, identifier:subject_catchment; 221, identifier:descriptors; 222, identifier:subject_catchment; 223, identifier:descriptors; 224, call; 225, identifier:join; 226, attribute; 227, identifier:Catchment; 228, identifier:id; 229, identifier:subject_catchment; 230, identifier:id; 231, comparison_operator:Descriptors.urbext2000 < 0.03; 232, comparison_operator:Descriptors.urbext2000 == None; 233, identifier:AmaxRecord; 234, identifier:flag; 235, attribute; 236, argument_list; 237, identifier:Catchment; 238, identifier:amax_records; 239, attribute; 240, float:0.03; 241, attribute; 242, None; 243, call; 244, identifier:join; 245, attribute; 246, identifier:Descriptors; 247, identifier:urbext2000; 248, identifier:Descriptors; 249, identifier:urbext2000; 250, attribute; 251, argument_list; 252, identifier:Catchment; 253, identifier:descriptors; 254, attribute; 255, identifier:query; 256, identifier:Catchment; 257, identifier:self; 258, identifier:db_session
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; 4, 21; 4, 22; 4, 23; 4, 24; 4, 25; 8, 26; 8, 27; 9, 28; 9, 29; 10, 30; 11, 31; 11, 32; 12, 33; 14, 34; 16, 35; 16, 36; 16, 37; 18, 38; 18, 39; 18, 40; 20, 41; 22, 42; 23, 43; 24, 44; 24, 45; 24, 46; 25, 47; 29, 48; 31, 49; 31, 50; 32, 51; 33, 52; 33, 53; 34, 54; 34, 55; 35, 56; 35, 57; 36, 58; 37, 59; 37, 60; 40, 61; 41, 62; 41, 63; 42, 64; 42, 65; 43, 66; 43, 67; 46, 68; 46, 69; 46, 70; 50, 71; 50, 72; 50, 73; 51, 74; 53, 75; 55, 76; 55, 77; 57, 78; 58, 79; 58, 80; 58, 81; 59, 82; 59, 83; 60, 84; 61, 85; 62, 86; 62, 87; 63, 88; 68, 89; 69, 90; 70, 91; 70, 92; 71, 93; 72, 94; 73, 95; 74, 96; 74, 97; 75, 98; 75, 99; 76, 100; 76, 101; 79, 102; 79, 103; 81, 104; 83, 105; 84, 106; 84, 107; 85, 108; 85, 109; 88, 110; 88, 111; 89, 112; 89, 113; 90, 114; 90, 115; 91, 116; 91, 117; 92, 118; 97, 119; 98, 120; 98, 121; 99, 122; 102, 123; 102, 124; 104, 125; 106, 126; 106, 127; 106, 128; 107, 129; 108, 130; 108, 131; 109, 132; 109, 133; 111, 134; 111, 135; 112, 136; 112, 137; 113, 138; 115, 139; 115, 140; 119, 141; 119, 142; 120, 143; 120, 144; 122, 145; 122, 146; 124, 147; 125, 148; 125, 149; 126, 150; 126, 151; 128, 152; 129, 153; 133, 154; 133, 155; 135, 156; 141, 157; 141, 158; 143, 159; 143, 160; 144, 161; 145, 162; 145, 163; 147, 164; 147, 165; 148, 166; 148, 167; 149, 168; 150, 169; 150, 170; 151, 171; 151, 172; 152, 173; 152, 174; 153, 175; 153, 176; 156, 177; 157, 178; 157, 179; 158, 180; 159, 181; 159, 182; 162, 183; 162, 184; 163, 185; 169, 186; 169, 187; 173, 188; 173, 189; 174, 190; 174, 191; 175, 192; 175, 193; 176, 194; 181, 195; 181, 196; 182, 197; 182, 198; 182, 199; 182, 200; 185, 201; 185, 202; 187, 203; 188, 204; 188, 205; 190, 206; 190, 207; 195, 208; 195, 209; 197, 210; 197, 211; 198, 212; 198, 213; 199, 214; 199, 215; 200, 216; 200, 217; 203, 218; 203, 219; 204, 220; 204, 221; 206, 222; 206, 223; 208, 224; 208, 225; 209, 226; 210, 227; 210, 228; 211, 229; 211, 230; 215, 231; 215, 232; 216, 233; 216, 234; 224, 235; 224, 236; 226, 237; 226, 238; 231, 239; 231, 240; 232, 241; 232, 242; 235, 243; 235, 244; 236, 245; 239, 246; 239, 247; 241, 248; 241, 249; 243, 250; 243, 251; 245, 252; 245, 253; 250, 254; 250, 255; 251, 256; 254, 257; 254, 258
def most_similar_catchments(self, subject_catchment, similarity_dist_function, records_limit=500, include_subject_catchment='auto'): """ Return a list of catchments sorted by hydrological similarity defined by `similarity_distance_function` :param subject_catchment: subject catchment to find similar catchments for :type subject_catchment: :class:`floodestimation.entities.Catchment` :param similarity_dist_function: a method returning a similarity distance measure with 2 arguments, both :class:`floodestimation.entities.Catchment` objects :param include_subject_catchment: - `auto`: include subject catchment if suitable for pooling and if urbext < 0.03 - `force`: always include subject catchment having at least 10 years of data - `exclude`: do not include the subject catchment :type include_subject_catchment: str :return: list of catchments sorted by similarity :type: list of :class:`floodestimation.entities.Catchment` """ if include_subject_catchment not in ['auto', 'force', 'exclude']: raise ValueError("Parameter `include_subject_catchment={}` invalid.".format(include_subject_catchment) + "Must be one of `auto`, `force` or `exclude`.") query = (self.db_session.query(Catchment). join(Catchment.descriptors). join(Catchment.amax_records). filter(Catchment.id != subject_catchment.id, Catchment.is_suitable_for_pooling, or_(Descriptors.urbext2000 < 0.03, Descriptors.urbext2000 == None), AmaxRecord.flag == 0). group_by(Catchment). having(func.count(AmaxRecord.catchment_id) >= 10)) # At least 10 AMAX records catchments = query.all() # Add subject catchment if required (may not exist in database, so add after querying db if include_subject_catchment == 'force': if len(subject_catchment.amax_records) >= 10: # Never include short-record catchments catchments.append(subject_catchment) elif include_subject_catchment == 'auto': if len(subject_catchment.amax_records) >= 10 and subject_catchment.is_suitable_for_pooling and \ (subject_catchment.descriptors.urbext2000 < 0.03 or subject_catchment.descriptors.urbext2000 is None): catchments.append(subject_catchment) # Store the similarity distance as an additional attribute for each catchment for catchment in catchments: catchment.similarity_dist = similarity_dist_function(subject_catchment, catchment) # Then simply sort by this attribute catchments.sort(key=attrgetter('similarity_dist')) # Limit catchments until total amax_records counts is at least `records_limit`, default 500 amax_records_count = 0 catchments_limited = [] for catchment in catchments: catchments_limited.append(catchment) amax_records_count += catchment.record_length if amax_records_count >= records_limit: break return catchments_limited
0, module; 1, function_definition; 2, function_name:sort_and_index_star; 3, parameters; 4, block; 5, identifier:job; 6, identifier:star_bams; 7, identifier:univ_options; 8, identifier:star_options; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, expression_statement; 14, expression_statement; 15, return_statement; 16, comment:""" A wrapper for sorting and indexing the genomic star bam generated by run_star. It is required since run_star returns a dict of 2 bams :param dict star_bams: The bams from run_star :param dict univ_options: Dict of universal options used by almost all tools :param dict star_options: Options specific to star :return: Dict containing input bam and the generated index (.bam.bai) output_files: |- 'rna_transcriptome.bam': fsID +- 'rna_genome': |- 'rna_sorted.bam': fsID +- 'rna_sorted.bam.bai': fsID +- 'rnaChimeric.out.junction': fsID :rtype: dict """; 17, assignment; 18, assignment; 19, assignment; 20, call; 21, call; 22, dictionary; 23, subscript; 24, subscript; 25, identifier:sort; 26, call; 27, identifier:index; 28, call; 29, attribute; 30, argument_list; 31, attribute; 32, argument_list; 33, pair; 34, pair; 35, pair; 36, subscript; 37, string; 38, identifier:star_options; 39, string; 40, attribute; 41, argument_list; 42, attribute; 43, argument_list; 44, identifier:job; 45, identifier:addChild; 46, identifier:sort; 47, identifier:sort; 48, identifier:addChild; 49, identifier:index; 50, string; 51, call; 52, string; 53, subscript; 54, string; 55, subscript; 56, identifier:star_options; 57, string; 58, string_content:n; 59, string_content:n; 60, identifier:job; 61, identifier:wrapJobFn; 62, identifier:sort_bamfile; 63, subscript; 64, string; 65, identifier:univ_options; 66, keyword_argument; 67, keyword_argument; 68, identifier:job; 69, identifier:wrapJobFn; 70, identifier:index_bamfile; 71, call; 72, string; 73, identifier:univ_options; 74, keyword_argument; 75, keyword_argument; 76, keyword_argument; 77, string_content:rna_genome; 78, attribute; 79, argument_list; 80, string_content:rna_transcriptome.bam; 81, identifier:star_bams; 82, string; 83, string_content:rnaChimeric.out.junction; 84, identifier:star_bams; 85, string; 86, string_content:samtools; 87, identifier:star_bams; 88, string; 89, string_content:rna; 90, identifier:samtools_options; 91, subscript; 92, identifier:disk; 93, call; 94, attribute; 95, argument_list; 96, string_content:rna; 97, identifier:samtools_options; 98, subscript; 99, identifier:sample_info; 100, string; 101, identifier:disk; 102, call; 103, identifier:index; 104, identifier:rv; 105, string_content:rnaAligned.toTranscriptome.out.bam; 106, string_content:rnaChimeric.out.junction; 107, string_content:rnaAligned.out.bam; 108, identifier:star_options; 109, string; 110, identifier:PromisedRequirement; 111, argument_list; 112, identifier:sort; 113, identifier:rv; 114, identifier:star_options; 115, string; 116, string_content:genome_sorted; 117, identifier:PromisedRequirement; 118, argument_list; 119, string_content:samtools; 120, identifier:sort_disk; 121, subscript; 122, string_content:samtools; 123, identifier:index_disk; 124, call; 125, identifier:star_bams; 126, string; 127, attribute; 128, argument_list; 129, string_content:rnaAligned.out.bam; 130, identifier:sort; 131, identifier:rv
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; 9, 16; 10, 17; 11, 18; 12, 19; 13, 20; 14, 21; 15, 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; 22, 35; 23, 36; 23, 37; 24, 38; 24, 39; 26, 40; 26, 41; 28, 42; 28, 43; 29, 44; 29, 45; 30, 46; 31, 47; 31, 48; 32, 49; 33, 50; 33, 51; 34, 52; 34, 53; 35, 54; 35, 55; 36, 56; 36, 57; 37, 58; 39, 59; 40, 60; 40, 61; 41, 62; 41, 63; 41, 64; 41, 65; 41, 66; 41, 67; 42, 68; 42, 69; 43, 70; 43, 71; 43, 72; 43, 73; 43, 74; 43, 75; 43, 76; 50, 77; 51, 78; 51, 79; 52, 80; 53, 81; 53, 82; 54, 83; 55, 84; 55, 85; 57, 86; 63, 87; 63, 88; 64, 89; 66, 90; 66, 91; 67, 92; 67, 93; 71, 94; 71, 95; 72, 96; 74, 97; 74, 98; 75, 99; 75, 100; 76, 101; 76, 102; 78, 103; 78, 104; 82, 105; 85, 106; 88, 107; 91, 108; 91, 109; 93, 110; 93, 111; 94, 112; 94, 113; 98, 114; 98, 115; 100, 116; 102, 117; 102, 118; 109, 119; 111, 120; 111, 121; 115, 122; 118, 123; 118, 124; 121, 125; 121, 126; 124, 127; 124, 128; 126, 129; 127, 130; 127, 131
def sort_and_index_star(job, star_bams, univ_options, star_options): """ A wrapper for sorting and indexing the genomic star bam generated by run_star. It is required since run_star returns a dict of 2 bams :param dict star_bams: The bams from run_star :param dict univ_options: Dict of universal options used by almost all tools :param dict star_options: Options specific to star :return: Dict containing input bam and the generated index (.bam.bai) output_files: |- 'rna_transcriptome.bam': fsID +- 'rna_genome': |- 'rna_sorted.bam': fsID +- 'rna_sorted.bam.bai': fsID +- 'rnaChimeric.out.junction': fsID :rtype: dict """ star_options['samtools']['n'] = star_options['n'] sort = job.wrapJobFn(sort_bamfile, star_bams['rnaAligned.out.bam'], 'rna', univ_options, samtools_options=star_options['samtools'], disk=PromisedRequirement(sort_disk, star_bams['rnaAligned.out.bam'])) index = job.wrapJobFn(index_bamfile, sort.rv(), 'rna', univ_options, samtools_options=star_options['samtools'], sample_info='genome_sorted', disk=PromisedRequirement(index_disk, sort.rv())) job.addChild(sort) sort.addChild(index) return {'rna_genome': index.rv(), 'rna_transcriptome.bam': star_bams['rnaAligned.toTranscriptome.out.bam'], 'rnaChimeric.out.junction': star_bams['rnaChimeric.out.junction']}
0, module; 1, function_definition; 2, function_name:align_dna; 3, parameters; 4, block; 5, identifier:job; 6, identifier:fastqs; 7, identifier:sample_type; 8, identifier:univ_options; 9, identifier:bwa_options; 10, expression_statement; 11, comment:# The mkdup and regroup steps use picard that allots heap space using the Xmx key in the; 12, comment:# univ_options dictionary. This should reflect in the job allotment. Since We want all these; 13, comment:# jobs to occur on the same node, we ened to give them all the same memory requirements.; 14, expression_statement; 15, expression_statement; 16, comment:# reheader takes the same disk as sam2bam so we can serialize this on the same worker.; 17, expression_statement; 18, expression_statement; 19, expression_statement; 20, expression_statement; 21, expression_statement; 22, expression_statement; 23, expression_statement; 24, expression_statement; 25, expression_statement; 26, expression_statement; 27, return_statement; 28, comment:""" A wrapper for the entire dna alignment subgraph. :param list fastqs: The input fastqs for alignment :param str sample_type: Description of the sample to inject into the filename :param dict univ_options: Dict of universal options used by almost all tools :param dict bwa_options: Options specific to bwa :return: Dict containing output bam and bai output_files: |- '<sample_type>_fix_pg_sorted.bam': fsID +- '<sample_type>_fix_pg_sorted.bam.bai': fsID :rtype: dict """; 29, assignment; 30, assignment; 31, assignment; 32, assignment; 33, assignment; 34, assignment; 35, call; 36, call; 37, call; 38, call; 39, call; 40, call; 41, call; 42, identifier:bwa; 43, call; 44, identifier:sam2bam; 45, call; 46, identifier:reheader; 47, call; 48, identifier:regroup; 49, call; 50, identifier:mkdup; 51, call; 52, identifier:index; 53, call; 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, attribute; 65, argument_list; 66, attribute; 67, argument_list; 68, attribute; 69, argument_list; 70, attribute; 71, argument_list; 72, attribute; 73, argument_list; 74, attribute; 75, argument_list; 76, attribute; 77, argument_list; 78, attribute; 79, argument_list; 80, identifier:job; 81, identifier:addChild; 82, identifier:bwa; 83, identifier:bwa; 84, identifier:addChild; 85, identifier:sam2bam; 86, identifier:sam2bam; 87, identifier:addChild; 88, identifier:reheader; 89, identifier:reheader; 90, identifier:addChild; 91, identifier:regroup; 92, identifier:regroup; 93, identifier:addChild; 94, identifier:mkdup; 95, identifier:mkdup; 96, identifier:addChild; 97, identifier:index; 98, identifier:index; 99, identifier:rv; 100, identifier:job; 101, identifier:wrapJobFn; 102, identifier:run_bwa; 103, identifier:fastqs; 104, identifier:sample_type; 105, identifier:univ_options; 106, identifier:bwa_options; 107, keyword_argument; 108, keyword_argument; 109, keyword_argument; 110, identifier:job; 111, identifier:wrapJobFn; 112, identifier:bam_conversion; 113, call; 114, identifier:sample_type; 115, identifier:univ_options; 116, subscript; 117, keyword_argument; 118, keyword_argument; 119, identifier:job; 120, identifier:wrapJobFn; 121, identifier:fix_bam_header; 122, call; 123, identifier:sample_type; 124, identifier:univ_options; 125, subscript; 126, keyword_argument; 127, keyword_argument; 128, identifier:job; 129, identifier:wrapJobFn; 130, identifier:add_readgroups; 131, call; 132, identifier:sample_type; 133, identifier:univ_options; 134, subscript; 135, keyword_argument; 136, keyword_argument; 137, identifier:job; 138, identifier:wrapJobFn; 139, identifier:mark_duplicates; 140, call; 141, identifier:sample_type; 142, identifier:univ_options; 143, subscript; 144, keyword_argument; 145, keyword_argument; 146, identifier:job; 147, identifier:wrapJobFn; 148, identifier:index_bamfile; 149, call; 150, identifier:sample_type; 151, identifier:univ_options; 152, subscript; 153, keyword_argument; 154, keyword_argument; 155, keyword_argument; 156, identifier:disk; 157, call; 158, identifier:memory; 159, subscript; 160, identifier:cores; 161, subscript; 162, attribute; 163, argument_list; 164, identifier:bwa_options; 165, string; 166, identifier:disk; 167, call; 168, identifier:memory; 169, subscript; 170, attribute; 171, argument_list; 172, identifier:bwa_options; 173, string; 174, identifier:disk; 175, call; 176, identifier:memory; 177, subscript; 178, attribute; 179, argument_list; 180, identifier:bwa_options; 181, string; 182, identifier:disk; 183, call; 184, identifier:memory; 185, subscript; 186, attribute; 187, argument_list; 188, identifier:bwa_options; 189, string; 190, identifier:disk; 191, call; 192, identifier:memory; 193, subscript; 194, attribute; 195, argument_list; 196, identifier:bwa_options; 197, string; 198, identifier:sample_info; 199, string; 200, identifier:disk; 201, call; 202, identifier:memory; 203, subscript; 204, identifier:PromisedRequirement; 205, argument_list; 206, identifier:univ_options; 207, string; 208, identifier:bwa_options; 209, string; 210, identifier:bwa; 211, identifier:rv; 212, string_content:samtools; 213, identifier:PromisedRequirement; 214, argument_list; 215, identifier:univ_options; 216, string; 217, identifier:sam2bam; 218, identifier:rv; 219, string_content:samtools; 220, identifier:PromisedRequirement; 221, argument_list; 222, identifier:univ_options; 223, string; 224, identifier:reheader; 225, identifier:rv; 226, string_content:picard; 227, identifier:PromisedRequirement; 228, argument_list; 229, identifier:univ_options; 230, string; 231, identifier:regroup; 232, identifier:rv; 233, string_content:picard; 234, identifier:PromisedRequirement; 235, argument_list; 236, identifier:univ_options; 237, string; 238, identifier:mkdup; 239, identifier:rv; 240, string_content:samtools; 241, string_content:fix_pg_sorted; 242, identifier:PromisedRequirement; 243, argument_list; 244, identifier:univ_options; 245, string; 246, identifier:bwa_disk; 247, identifier:fastqs; 248, subscript; 249, string_content:java_Xmx; 250, string_content:n; 251, identifier:sam2bam_disk; 252, call; 253, string_content:java_Xmx; 254, identifier:sam2bam_disk; 255, call; 256, string_content:java_Xmx; 257, identifier:regroup_disk; 258, call; 259, string_content:java_Xmx; 260, identifier:mkdup_disk; 261, call; 262, string_content:java_Xmx; 263, identifier:index_disk; 264, call; 265, string_content:java_Xmx; 266, identifier:bwa_options; 267, string; 268, attribute; 269, argument_list; 270, attribute; 271, argument_list; 272, attribute; 273, argument_list; 274, attribute; 275, argument_list; 276, attribute; 277, argument_list; 278, string_content:index; 279, identifier:bwa; 280, identifier:rv; 281, identifier:bwa; 282, identifier:rv; 283, identifier:reheader; 284, identifier:rv; 285, identifier:regroup; 286, identifier:rv; 287, identifier:mkdup; 288, identifier:rv
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; 4, 21; 4, 22; 4, 23; 4, 24; 4, 25; 4, 26; 4, 27; 10, 28; 14, 29; 15, 30; 17, 31; 18, 32; 19, 33; 20, 34; 21, 35; 22, 36; 23, 37; 24, 38; 25, 39; 26, 40; 27, 41; 29, 42; 29, 43; 30, 44; 30, 45; 31, 46; 31, 47; 32, 48; 32, 49; 33, 50; 33, 51; 34, 52; 34, 53; 35, 54; 35, 55; 36, 56; 36, 57; 37, 58; 37, 59; 38, 60; 38, 61; 39, 62; 39, 63; 40, 64; 40, 65; 41, 66; 41, 67; 43, 68; 43, 69; 45, 70; 45, 71; 47, 72; 47, 73; 49, 74; 49, 75; 51, 76; 51, 77; 53, 78; 53, 79; 54, 80; 54, 81; 55, 82; 56, 83; 56, 84; 57, 85; 58, 86; 58, 87; 59, 88; 60, 89; 60, 90; 61, 91; 62, 92; 62, 93; 63, 94; 64, 95; 64, 96; 65, 97; 66, 98; 66, 99; 68, 100; 68, 101; 69, 102; 69, 103; 69, 104; 69, 105; 69, 106; 69, 107; 69, 108; 69, 109; 70, 110; 70, 111; 71, 112; 71, 113; 71, 114; 71, 115; 71, 116; 71, 117; 71, 118; 72, 119; 72, 120; 73, 121; 73, 122; 73, 123; 73, 124; 73, 125; 73, 126; 73, 127; 74, 128; 74, 129; 75, 130; 75, 131; 75, 132; 75, 133; 75, 134; 75, 135; 75, 136; 76, 137; 76, 138; 77, 139; 77, 140; 77, 141; 77, 142; 77, 143; 77, 144; 77, 145; 78, 146; 78, 147; 79, 148; 79, 149; 79, 150; 79, 151; 79, 152; 79, 153; 79, 154; 79, 155; 107, 156; 107, 157; 108, 158; 108, 159; 109, 160; 109, 161; 113, 162; 113, 163; 116, 164; 116, 165; 117, 166; 117, 167; 118, 168; 118, 169; 122, 170; 122, 171; 125, 172; 125, 173; 126, 174; 126, 175; 127, 176; 127, 177; 131, 178; 131, 179; 134, 180; 134, 181; 135, 182; 135, 183; 136, 184; 136, 185; 140, 186; 140, 187; 143, 188; 143, 189; 144, 190; 144, 191; 145, 192; 145, 193; 149, 194; 149, 195; 152, 196; 152, 197; 153, 198; 153, 199; 154, 200; 154, 201; 155, 202; 155, 203; 157, 204; 157, 205; 159, 206; 159, 207; 161, 208; 161, 209; 162, 210; 162, 211; 165, 212; 167, 213; 167, 214; 169, 215; 169, 216; 170, 217; 170, 218; 173, 219; 175, 220; 175, 221; 177, 222; 177, 223; 178, 224; 178, 225; 181, 226; 183, 227; 183, 228; 185, 229; 185, 230; 186, 231; 186, 232; 189, 233; 191, 234; 191, 235; 193, 236; 193, 237; 194, 238; 194, 239; 197, 240; 199, 241; 201, 242; 201, 243; 203, 244; 203, 245; 205, 246; 205, 247; 205, 248; 207, 249; 209, 250; 214, 251; 214, 252; 216, 253; 221, 254; 221, 255; 223, 256; 228, 257; 228, 258; 230, 259; 235, 260; 235, 261; 237, 262; 243, 263; 243, 264; 245, 265; 248, 266; 248, 267; 252, 268; 252, 269; 255, 270; 255, 271; 258, 272; 258, 273; 261, 274; 261, 275; 264, 276; 264, 277; 267, 278; 268, 279; 268, 280; 270, 281; 270, 282; 272, 283; 272, 284; 274, 285; 274, 286; 276, 287; 276, 288
def align_dna(job, fastqs, sample_type, univ_options, bwa_options): """ A wrapper for the entire dna alignment subgraph. :param list fastqs: The input fastqs for alignment :param str sample_type: Description of the sample to inject into the filename :param dict univ_options: Dict of universal options used by almost all tools :param dict bwa_options: Options specific to bwa :return: Dict containing output bam and bai output_files: |- '<sample_type>_fix_pg_sorted.bam': fsID +- '<sample_type>_fix_pg_sorted.bam.bai': fsID :rtype: dict """ # The mkdup and regroup steps use picard that allots heap space using the Xmx key in the # univ_options dictionary. This should reflect in the job allotment. Since We want all these # jobs to occur on the same node, we ened to give them all the same memory requirements. bwa = job.wrapJobFn(run_bwa, fastqs, sample_type, univ_options, bwa_options, disk=PromisedRequirement(bwa_disk, fastqs, bwa_options['index']), memory=univ_options['java_Xmx'], cores=bwa_options['n']) sam2bam = job.wrapJobFn(bam_conversion, bwa.rv(), sample_type, univ_options, bwa_options['samtools'], disk=PromisedRequirement(sam2bam_disk, bwa.rv()), memory=univ_options['java_Xmx']) # reheader takes the same disk as sam2bam so we can serialize this on the same worker. reheader = job.wrapJobFn(fix_bam_header, sam2bam.rv(), sample_type, univ_options, bwa_options['samtools'], disk=PromisedRequirement(sam2bam_disk, bwa.rv()), memory=univ_options['java_Xmx']) regroup = job.wrapJobFn(add_readgroups, reheader.rv(), sample_type, univ_options, bwa_options['picard'], disk=PromisedRequirement(regroup_disk, reheader.rv()), memory=univ_options['java_Xmx']) mkdup = job.wrapJobFn(mark_duplicates, regroup.rv(), sample_type, univ_options, bwa_options['picard'], disk=PromisedRequirement(mkdup_disk, regroup.rv()), memory=univ_options['java_Xmx']) index = job.wrapJobFn(index_bamfile, mkdup.rv(), sample_type, univ_options, bwa_options['samtools'], sample_info='fix_pg_sorted', disk=PromisedRequirement(index_disk, mkdup.rv()), memory=univ_options['java_Xmx']) job.addChild(bwa) bwa.addChild(sam2bam) sam2bam.addChild(reheader) reheader.addChild(regroup) regroup.addChild(mkdup) mkdup.addChild(index) return index.rv()
0, module; 1, function_definition; 2, function_name:run_star; 3, parameters; 4, block; 5, identifier:job; 6, identifier:fastqs; 7, identifier:univ_options; 8, identifier:star_options; 9, expression_statement; 10, assert_statement; 11, expression_statement; 12, expression_statement; 13, expression_statement; 14, expression_statement; 15, expression_statement; 16, if_statement; 17, expression_statement; 18, for_statement; 19, expression_statement; 20, expression_statement; 21, expression_statement; 22, expression_statement; 23, expression_statement; 24, return_statement; 25, comment:""" This module uses STAR to align the RNA fastqs to the reference ARGUMENTS 1. fastqs: REFER RETURN VALUE of run_cutadapt() 2. univ_options: Dict of universal arguments used by almost all tools univ_options +- 'dockerhub': <dockerhub to use> 3. star_options: Dict of parameters specific to STAR star_options |- 'index_tar': <JSid for the STAR index tarball> +- 'n': <number of threads to allocate> RETURN VALUES 1. output_files: Dict of aligned bams output_files |- 'rnaAligned.toTranscriptome.out.bam': <JSid> +- 'rnaAligned.sortedByCoord.out.bam': Dict of genome bam + bai |- 'rna_fix_pg_sorted.bam': <JSid> +- 'rna_fix_pg_sorted.bam.bai': <JSid> This module corresponds to node 9 on the tree """; 26, comparison_operator:star_options['type'] in ('star', 'starlong'); 27, call; 28, assignment; 29, assignment; 30, assignment; 31, assignment; 32, comparison_operator:star_options['type'] == 'star'; 33, block; 34, else_clause; 35, assignment; 36, identifier:bam_file; 37, list; 38, block; 39, call; 40, call; 41, assignment; 42, call; 43, assignment; 44, identifier:output_files; 45, subscript; 46, tuple; 47, attribute; 48, argument_list; 49, identifier:work_dir; 50, call; 51, identifier:input_files; 52, dictionary; 53, identifier:input_files; 54, call; 55, identifier:parameters; 56, list; 57, subscript; 58, string; 59, expression_statement; 60, block; 61, identifier:output_files; 62, call; 63, string; 64, string; 65, expression_statement; 66, attribute; 67, argument_list; 68, attribute; 69, argument_list; 70, identifier:index_star; 71, call; 72, attribute; 73, argument_list; 74, subscript; 75, call; 76, identifier:star_options; 77, string; 78, string; 79, string; 80, attribute; 81, identifier:logToMaster; 82, binary_operator:'Running STAR on %s' %univ_options['patient']; 83, attribute; 84, argument_list; 85, pair; 86, pair; 87, pair; 88, identifier:get_files_from_filestore; 89, argument_list; 90, string; 91, call; 92, string; 93, subscript; 94, string; 95, string; 96, string; 97, subscript; 98, subscript; 99, string; 100, string; 101, string; 102, string; 103, string; 104, string; 105, string; 106, string; 107, string; 108, string; 109, string; 110, string; 111, string; 112, identifier:star_options; 113, string; 114, string_content:star; 115, call; 116, expression_statement; 117, identifier:defaultdict; 118, argument_list; 119, string_content:rnaAligned.toTranscriptome.out.bam; 120, string_content:rnaAligned.sortedByCoord.out.bam; 121, assignment; 122, attribute; 123, identifier:deleteGlobalFile; 124, subscript; 125, attribute; 126, identifier:deleteGlobalFile; 127, subscript; 128, attribute; 129, argument_list; 130, identifier:job; 131, identifier:addChild; 132, identifier:index_star; 133, identifier:output_files; 134, string; 135, attribute; 136, argument_list; 137, string_content:type; 138, string_content:star; 139, string_content:starlong; 140, identifier:job; 141, identifier:fileStore; 142, string; 143, subscript; 144, attribute; 145, identifier:getLocalTempDir; 146, string; 147, subscript; 148, string; 149, subscript; 150, string; 151, subscript; 152, identifier:job; 153, identifier:input_files; 154, identifier:work_dir; 155, keyword_argument; 156, string_content:--runThreadN; 157, identifier:str; 158, argument_list; 159, string_content:--genomeDir; 160, identifier:input_files; 161, string; 162, string_content:--outFileNamePrefix; 163, string_content:rna; 164, string_content:--readFilesIn; 165, identifier:input_files; 166, string; 167, identifier:input_files; 168, string; 169, string_content:--outSAMattributes; 170, string_content:NH; 171, string_content:HI; 172, string_content:AS; 173, string_content:NM; 174, string_content:MD; 175, string_content:--outSAMtype; 176, string_content:BAM; 177, string_content:SortedByCoordinate; 178, string_content:--quantMode; 179, string_content:TranscriptomeSAM; 180, string_content:--outSAMunmapped; 181, string_content:Within; 182, string_content:type; 183, identifier:docker_call; 184, argument_list; 185, call; 186, subscript; 187, call; 188, identifier:job; 189, identifier:fileStore; 190, identifier:fastqs; 191, string; 192, identifier:job; 193, identifier:fileStore; 194, identifier:fastqs; 195, string; 196, identifier:job; 197, identifier:wrapJobFn; 198, identifier:index_bamfile; 199, subscript; 200, string; 201, identifier:univ_options; 202, keyword_argument; 203, string_content:rnaAligned.sortedByCoord.out.bam; 204, identifier:index_star; 205, identifier:rv; 206, string_content:Running STAR on %s; 207, identifier:univ_options; 208, string; 209, identifier:job; 210, identifier:fileStore; 211, string_content:rna_cutadapt_1.fastq; 212, identifier:fastqs; 213, string; 214, string_content:rna_cutadapt_2.fastq; 215, identifier:fastqs; 216, string; 217, string_content:star_index.tar.gz; 218, identifier:star_options; 219, string; 220, identifier:docker; 221, True; 222, subscript; 223, string_content:star_index; 224, string_content:rna_cutadapt_1.fastq; 225, string_content:rna_cutadapt_2.fastq; 226, keyword_argument; 227, keyword_argument; 228, keyword_argument; 229, keyword_argument; 230, identifier:docker_call; 231, argument_list; 232, identifier:output_files; 233, identifier:bam_file; 234, attribute; 235, argument_list; 236, string_content:rna_cutadapt_1.fastq; 237, string_content:rna_cutadapt_2.fastq; 238, identifier:output_files; 239, string; 240, string_content:rna; 241, identifier:disk; 242, string; 243, string_content:patient; 244, string_content:rna_cutadapt_1.fastq; 245, string_content:rna_cutadapt_2.fastq; 246, string_content:index_tar; 247, identifier:star_options; 248, string; 249, identifier:tool; 250, string; 251, identifier:tool_parameters; 252, identifier:parameters; 253, identifier:work_dir; 254, identifier:work_dir; 255, identifier:dockerhub; 256, subscript; 257, keyword_argument; 258, keyword_argument; 259, keyword_argument; 260, keyword_argument; 261, attribute; 262, identifier:writeGlobalFile; 263, call; 264, string_content:rnaAligned.sortedByCoord.out.bam; 265, string_content:120G; 266, string_content:n; 267, string_content:star; 268, identifier:univ_options; 269, string; 270, identifier:tool; 271, string; 272, identifier:tool_parameters; 273, identifier:parameters; 274, identifier:work_dir; 275, identifier:work_dir; 276, identifier:dockerhub; 277, subscript; 278, identifier:job; 279, identifier:fileStore; 280, attribute; 281, argument_list; 282, string_content:dockerhub; 283, string_content:starlong; 284, identifier:univ_options; 285, string; 286, string; 287, identifier:join; 288, list; 289, string_content:dockerhub; 290, string_content:/; 291, identifier:work_dir; 292, identifier:bam_file
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; 4, 21; 4, 22; 4, 23; 4, 24; 9, 25; 10, 26; 11, 27; 12, 28; 13, 29; 14, 30; 15, 31; 16, 32; 16, 33; 16, 34; 17, 35; 18, 36; 18, 37; 18, 38; 19, 39; 20, 40; 21, 41; 22, 42; 23, 43; 24, 44; 26, 45; 26, 46; 27, 47; 27, 48; 28, 49; 28, 50; 29, 51; 29, 52; 30, 53; 30, 54; 31, 55; 31, 56; 32, 57; 32, 58; 33, 59; 34, 60; 35, 61; 35, 62; 37, 63; 37, 64; 38, 65; 39, 66; 39, 67; 40, 68; 40, 69; 41, 70; 41, 71; 42, 72; 42, 73; 43, 74; 43, 75; 45, 76; 45, 77; 46, 78; 46, 79; 47, 80; 47, 81; 48, 82; 50, 83; 50, 84; 52, 85; 52, 86; 52, 87; 54, 88; 54, 89; 56, 90; 56, 91; 56, 92; 56, 93; 56, 94; 56, 95; 56, 96; 56, 97; 56, 98; 56, 99; 56, 100; 56, 101; 56, 102; 56, 103; 56, 104; 56, 105; 56, 106; 56, 107; 56, 108; 56, 109; 56, 110; 56, 111; 57, 112; 57, 113; 58, 114; 59, 115; 60, 116; 62, 117; 62, 118; 63, 119; 64, 120; 65, 121; 66, 122; 66, 123; 67, 124; 68, 125; 68, 126; 69, 127; 71, 128; 71, 129; 72, 130; 72, 131; 73, 132; 74, 133; 74, 134; 75, 135; 75, 136; 77, 137; 78, 138; 79, 139; 80, 140; 80, 141; 82, 142; 82, 143; 83, 144; 83, 145; 85, 146; 85, 147; 86, 148; 86, 149; 87, 150; 87, 151; 89, 152; 89, 153; 89, 154; 89, 155; 90, 156; 91, 157; 91, 158; 92, 159; 93, 160; 93, 161; 94, 162; 95, 163; 96, 164; 97, 165; 97, 166; 98, 167; 98, 168; 99, 169; 100, 170; 101, 171; 102, 172; 103, 173; 104, 174; 105, 175; 106, 176; 107, 177; 108, 178; 109, 179; 110, 180; 111, 181; 113, 182; 115, 183; 115, 184; 116, 185; 121, 186; 121, 187; 122, 188; 122, 189; 124, 190; 124, 191; 125, 192; 125, 193; 127, 194; 127, 195; 128, 196; 128, 197; 129, 198; 129, 199; 129, 200; 129, 201; 129, 202; 134, 203; 135, 204; 135, 205; 142, 206; 143, 207; 143, 208; 144, 209; 144, 210; 146, 211; 147, 212; 147, 213; 148, 214; 149, 215; 149, 216; 150, 217; 151, 218; 151, 219; 155, 220; 155, 221; 158, 222; 161, 223; 166, 224; 168, 225; 184, 226; 184, 227; 184, 228; 184, 229; 185, 230; 185, 231; 186, 232; 186, 233; 187, 234; 187, 235; 191, 236; 195, 237; 199, 238; 199, 239; 200, 240; 202, 241; 202, 242; 208, 243; 213, 244; 216, 245; 219, 246; 222, 247; 222, 248; 226, 249; 226, 250; 227, 251; 227, 252; 228, 253; 228, 254; 229, 255; 229, 256; 231, 257; 231, 258; 231, 259; 231, 260; 234, 261; 234, 262; 235, 263; 239, 264; 242, 265; 248, 266; 250, 267; 256, 268; 256, 269; 257, 270; 257, 271; 258, 272; 258, 273; 259, 274; 259, 275; 260, 276; 260, 277; 261, 278; 261, 279; 263, 280; 263, 281; 269, 282; 271, 283; 277, 284; 277, 285; 280, 286; 280, 287; 281, 288; 285, 289; 286, 290; 288, 291; 288, 292
def run_star(job, fastqs, univ_options, star_options): """ This module uses STAR to align the RNA fastqs to the reference ARGUMENTS 1. fastqs: REFER RETURN VALUE of run_cutadapt() 2. univ_options: Dict of universal arguments used by almost all tools univ_options +- 'dockerhub': <dockerhub to use> 3. star_options: Dict of parameters specific to STAR star_options |- 'index_tar': <JSid for the STAR index tarball> +- 'n': <number of threads to allocate> RETURN VALUES 1. output_files: Dict of aligned bams output_files |- 'rnaAligned.toTranscriptome.out.bam': <JSid> +- 'rnaAligned.sortedByCoord.out.bam': Dict of genome bam + bai |- 'rna_fix_pg_sorted.bam': <JSid> +- 'rna_fix_pg_sorted.bam.bai': <JSid> This module corresponds to node 9 on the tree """ assert star_options['type'] in ('star', 'starlong') job.fileStore.logToMaster('Running STAR on %s' %univ_options['patient']) work_dir = job.fileStore.getLocalTempDir() input_files = { 'rna_cutadapt_1.fastq': fastqs['rna_cutadapt_1.fastq'], 'rna_cutadapt_2.fastq': fastqs['rna_cutadapt_2.fastq'], 'star_index.tar.gz': star_options['index_tar']} input_files = get_files_from_filestore(job, input_files, work_dir, docker=True) parameters = ['--runThreadN', str(star_options['n']), '--genomeDir', input_files['star_index'], '--outFileNamePrefix', 'rna', '--readFilesIn', input_files['rna_cutadapt_1.fastq'], input_files['rna_cutadapt_2.fastq'], '--outSAMattributes', 'NH', 'HI', 'AS', 'NM', 'MD', '--outSAMtype', 'BAM', 'SortedByCoordinate', '--quantMode', 'TranscriptomeSAM', '--outSAMunmapped', 'Within'] if star_options['type'] == 'star': docker_call(tool='star', tool_parameters=parameters, work_dir=work_dir, dockerhub=univ_options['dockerhub']) else: docker_call(tool='starlong', tool_parameters=parameters, work_dir=work_dir, dockerhub=univ_options['dockerhub']) output_files = defaultdict() for bam_file in ['rnaAligned.toTranscriptome.out.bam', 'rnaAligned.sortedByCoord.out.bam']: output_files[bam_file] = job.fileStore.writeGlobalFile('/'.join([ work_dir, bam_file])) job.fileStore.deleteGlobalFile(fastqs['rna_cutadapt_1.fastq']) job.fileStore.deleteGlobalFile(fastqs['rna_cutadapt_2.fastq']) index_star = job.wrapJobFn(index_bamfile, output_files['rnaAligned.sortedByCoord.out.bam'], 'rna', univ_options, disk='120G') job.addChild(index_star) output_files['rnaAligned.sortedByCoord.out.bam'] = index_star.rv() return output_files
0, module; 1, function_definition; 2, function_name:run_bwa; 3, parameters; 4, block; 5, identifier:job; 6, identifier:fastqs; 7, identifier:sample_type; 8, identifier:univ_options; 9, identifier:bwa_options; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, expression_statement; 14, expression_statement; 15, expression_statement; 16, expression_statement; 17, with_statement; 18, comment:# samfile.name retains the path info; 19, expression_statement; 20, expression_statement; 21, expression_statement; 22, comment:# Return values get passed up the chain to here. The return value will be a dict with; 23, comment:# SAMPLE_TYPE_fix_pg_sorted.bam: jobStoreID; 24, comment:# SAMPLE_TYPE_fix_pg_sorted.bam.bai: jobStoreID; 25, return_statement; 26, comment:""" This module aligns the SAMPLE_TYPE dna fastqs to the reference ARGUMENTS -- <ST> depicts the sample type. Substitute with 'tumor'/'normal' 1. fastqs: Dict of list of input WGS/WXS fastqs fastqs +- '<ST>_dna': [<JSid for 1.fastq> , <JSid for 2.fastq>] 2. sample_type: string of 'tumor_dna' or 'normal_dna' 3. univ_options: Dict of universal arguments used by almost all tools univ_options +- 'dockerhub': <dockerhub to use> 4. bwa_options: Dict of parameters specific to bwa bwa_options |- 'index_tar': <JSid for the bwa index tarball> +- 'n': <number of threads to allocate> RETURN VALUES 1. output_files: Dict of aligned bam + reference (nested return) output_files |- '<ST>_fix_pg_sorted.bam': <JSid> +- '<ST>_fix_pg_sorted.bam.bai': <JSid> This module corresponds to nodes 3 and 4 on the tree """; 27, call; 28, assignment; 29, assignment; 30, assignment; 31, assignment; 32, assignment; 33, with_clause; 34, block; 35, assignment; 36, assignment; 37, call; 38, call; 39, attribute; 40, argument_list; 41, identifier:work_dir; 42, call; 43, identifier:fq_extn; 44, conditional_expression:'.gz' if fastqs['gzipped'] else ''; 45, identifier:input_files; 46, dictionary; 47, identifier:input_files; 48, call; 49, identifier:parameters; 50, list; 51, with_item; 52, expression_statement; 53, identifier:output_file; 54, call; 55, identifier:samfile_processing; 56, call; 57, attribute; 58, argument_list; 59, attribute; 60, argument_list; 61, attribute; 62, identifier:logToMaster; 63, binary_operator:'Running bwa on %s:%s' % (univ_options['patient'], sample_type); 64, attribute; 65, argument_list; 66, string; 67, subscript; 68, string; 69, pair; 70, pair; 71, pair; 72, identifier:get_files_from_filestore; 73, argument_list; 74, string; 75, string; 76, call; 77, string; 78, string; 79, comment:# Don't print INFO messages to the stderr; 80, call; 81, subscript; 82, subscript; 83, as_pattern; 84, call; 85, attribute; 86, argument_list; 87, attribute; 88, argument_list; 89, identifier:job; 90, identifier:addChild; 91, identifier:samfile_processing; 92, identifier:samfile_processing; 93, identifier:rv; 94, identifier:job; 95, identifier:fileStore; 96, string; 97, tuple; 98, attribute; 99, identifier:getLocalTempDir; 100, string_content:.gz; 101, identifier:fastqs; 102, string; 103, binary_operator:'dna_1.fastq' + fq_extn; 104, subscript; 105, binary_operator:'dna_2.fastq' + fq_extn; 106, subscript; 107, string; 108, subscript; 109, identifier:job; 110, identifier:input_files; 111, identifier:work_dir; 112, keyword_argument; 113, string_content:mem; 114, string_content:-t; 115, identifier:str; 116, argument_list; 117, string_content:-v; 118, string_content:1; 119, attribute; 120, argument_list; 121, identifier:input_files; 122, string; 123, identifier:input_files; 124, string; 125, call; 126, as_pattern_target; 127, identifier:docker_call; 128, argument_list; 129, attribute; 130, identifier:writeGlobalFile; 131, attribute; 132, identifier:job; 133, identifier:wrapJobFn; 134, identifier:bam_conversion; 135, identifier:output_file; 136, identifier:sample_type; 137, identifier:univ_options; 138, keyword_argument; 139, string_content:Running bwa on %s:%s; 140, subscript; 141, identifier:sample_type; 142, identifier:job; 143, identifier:fileStore; 144, string_content:gzipped; 145, string; 146, identifier:fq_extn; 147, subscript; 148, integer:0; 149, string; 150, identifier:fq_extn; 151, subscript; 152, integer:1; 153, string_content:bwa_index.tar.gz; 154, identifier:bwa_options; 155, string; 156, identifier:docker; 157, True; 158, subscript; 159, string; 160, identifier:join; 161, list; 162, string_content:dna_1.fastq; 163, string_content:dna_2.fastq; 164, identifier:open; 165, argument_list; 166, identifier:samfile; 167, keyword_argument; 168, keyword_argument; 169, keyword_argument; 170, keyword_argument; 171, keyword_argument; 172, identifier:job; 173, identifier:fileStore; 174, identifier:samfile; 175, identifier:name; 176, identifier:disk; 177, string; 178, identifier:univ_options; 179, string; 180, string_content:dna_1.fastq; 181, identifier:fastqs; 182, identifier:sample_type; 183, string_content:dna_2.fastq; 184, identifier:fastqs; 185, identifier:sample_type; 186, string_content:index_tar; 187, identifier:bwa_options; 188, string; 189, string_content:/; 190, subscript; 191, string; 192, call; 193, string; 194, identifier:tool; 195, string; 196, identifier:tool_parameters; 197, identifier:parameters; 198, identifier:work_dir; 199, identifier:work_dir; 200, identifier:dockerhub; 201, subscript; 202, identifier:outfile; 203, identifier:samfile; 204, string_content:60G; 205, string_content:patient; 206, string_content:n; 207, identifier:input_files; 208, string; 209, string_content:hg19.fa; 210, attribute; 211, argument_list; 212, string_content:w; 213, string_content:bwa; 214, identifier:univ_options; 215, string; 216, string_content:bwa_index; 217, string; 218, identifier:join; 219, list; 220, string_content:dockerhub; 221, identifier:work_dir; 222, string; 223, identifier:sample_type; 224, string; 225, string_content:/; 226, string_content:_aligned.sam
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; 4, 21; 4, 22; 4, 23; 4, 24; 4, 25; 10, 26; 11, 27; 12, 28; 13, 29; 14, 30; 15, 31; 16, 32; 17, 33; 17, 34; 19, 35; 20, 36; 21, 37; 25, 38; 27, 39; 27, 40; 28, 41; 28, 42; 29, 43; 29, 44; 30, 45; 30, 46; 31, 47; 31, 48; 32, 49; 32, 50; 33, 51; 34, 52; 35, 53; 35, 54; 36, 55; 36, 56; 37, 57; 37, 58; 38, 59; 38, 60; 39, 61; 39, 62; 40, 63; 42, 64; 42, 65; 44, 66; 44, 67; 44, 68; 46, 69; 46, 70; 46, 71; 48, 72; 48, 73; 50, 74; 50, 75; 50, 76; 50, 77; 50, 78; 50, 79; 50, 80; 50, 81; 50, 82; 51, 83; 52, 84; 54, 85; 54, 86; 56, 87; 56, 88; 57, 89; 57, 90; 58, 91; 59, 92; 59, 93; 61, 94; 61, 95; 63, 96; 63, 97; 64, 98; 64, 99; 66, 100; 67, 101; 67, 102; 69, 103; 69, 104; 70, 105; 70, 106; 71, 107; 71, 108; 73, 109; 73, 110; 73, 111; 73, 112; 74, 113; 75, 114; 76, 115; 76, 116; 77, 117; 78, 118; 80, 119; 80, 120; 81, 121; 81, 122; 82, 123; 82, 124; 83, 125; 83, 126; 84, 127; 84, 128; 85, 129; 85, 130; 86, 131; 87, 132; 87, 133; 88, 134; 88, 135; 88, 136; 88, 137; 88, 138; 96, 139; 97, 140; 97, 141; 98, 142; 98, 143; 102, 144; 103, 145; 103, 146; 104, 147; 104, 148; 105, 149; 105, 150; 106, 151; 106, 152; 107, 153; 108, 154; 108, 155; 112, 156; 112, 157; 116, 158; 119, 159; 119, 160; 120, 161; 122, 162; 124, 163; 125, 164; 125, 165; 126, 166; 128, 167; 128, 168; 128, 169; 128, 170; 128, 171; 129, 172; 129, 173; 131, 174; 131, 175; 138, 176; 138, 177; 140, 178; 140, 179; 145, 180; 147, 181; 147, 182; 149, 183; 151, 184; 151, 185; 155, 186; 158, 187; 158, 188; 159, 189; 161, 190; 161, 191; 165, 192; 165, 193; 167, 194; 167, 195; 168, 196; 168, 197; 169, 198; 169, 199; 170, 200; 170, 201; 171, 202; 171, 203; 177, 204; 179, 205; 188, 206; 190, 207; 190, 208; 191, 209; 192, 210; 192, 211; 193, 212; 195, 213; 201, 214; 201, 215; 208, 216; 210, 217; 210, 218; 211, 219; 215, 220; 219, 221; 219, 222; 219, 223; 219, 224; 222, 225; 224, 226
def run_bwa(job, fastqs, sample_type, univ_options, bwa_options): """ This module aligns the SAMPLE_TYPE dna fastqs to the reference ARGUMENTS -- <ST> depicts the sample type. Substitute with 'tumor'/'normal' 1. fastqs: Dict of list of input WGS/WXS fastqs fastqs +- '<ST>_dna': [<JSid for 1.fastq> , <JSid for 2.fastq>] 2. sample_type: string of 'tumor_dna' or 'normal_dna' 3. univ_options: Dict of universal arguments used by almost all tools univ_options +- 'dockerhub': <dockerhub to use> 4. bwa_options: Dict of parameters specific to bwa bwa_options |- 'index_tar': <JSid for the bwa index tarball> +- 'n': <number of threads to allocate> RETURN VALUES 1. output_files: Dict of aligned bam + reference (nested return) output_files |- '<ST>_fix_pg_sorted.bam': <JSid> +- '<ST>_fix_pg_sorted.bam.bai': <JSid> This module corresponds to nodes 3 and 4 on the tree """ job.fileStore.logToMaster('Running bwa on %s:%s' % (univ_options['patient'], sample_type)) work_dir = job.fileStore.getLocalTempDir() fq_extn = '.gz' if fastqs['gzipped'] else '' input_files = { 'dna_1.fastq' + fq_extn: fastqs[sample_type][0], 'dna_2.fastq' + fq_extn: fastqs[sample_type][1], 'bwa_index.tar.gz': bwa_options['index_tar']} input_files = get_files_from_filestore(job, input_files, work_dir, docker=True) parameters = ['mem', '-t', str(bwa_options['n']), '-v', '1', # Don't print INFO messages to the stderr '/'.join([input_files['bwa_index'], 'hg19.fa']), input_files['dna_1.fastq'], input_files['dna_2.fastq']] with open(''.join([work_dir, '/', sample_type, '_aligned.sam']), 'w') as samfile: docker_call(tool='bwa', tool_parameters=parameters, work_dir=work_dir, dockerhub=univ_options['dockerhub'], outfile=samfile) # samfile.name retains the path info output_file = job.fileStore.writeGlobalFile(samfile.name) samfile_processing = job.wrapJobFn(bam_conversion, output_file, sample_type, univ_options, disk='60G') job.addChild(samfile_processing) # Return values get passed up the chain to here. The return value will be a dict with # SAMPLE_TYPE_fix_pg_sorted.bam: jobStoreID # SAMPLE_TYPE_fix_pg_sorted.bam.bai: jobStoreID return samfile_processing.rv()
0, module; 1, function_definition; 2, function_name:make_key_hippie; 3, parameters; 4, block; 5, identifier:obj; 6, default_parameter; 7, expression_statement; 8, expression_statement; 9, if_statement; 10, comment:## should we try to convert to frozen{set,dict} to get the C; 11, comment:## hashing function speed ? But the convertion has a cost also.; 12, if_statement; 13, if_statement; 14, if_statement; 15, raise_statement; 16, identifier:typed; 17, True; 18, comment:"""Return hashable structure from non-hashable structure using hippie means dict and set are sorted and their content subjected to same hippie means. Note that the key identifies the current content of the structure. """; 19, assignment; 20, call; 21, comment:## DO NOT RETURN hash(obj), as hash collision would generate bad; 22, comment:## cache collisions.; 23, block; 24, call; 25, block; 26, call; 27, block; 28, call; 29, block; 30, call; 31, identifier:ftype; 32, conditional_expression:type if typed else lambda o: None; 33, identifier:is_hashable; 34, argument_list; 35, return_statement; 36, identifier:isinstance; 37, argument_list; 38, expression_statement; 39, identifier:isinstance; 40, argument_list; 41, return_statement; 42, identifier:isinstance; 43, argument_list; 44, return_statement; 45, identifier:ValueError; 46, argument_list; 47, identifier:type; 48, identifier:typed; 49, lambda; 50, identifier:obj; 51, expression_list; 52, identifier:obj; 53, identifier:set; 54, assignment; 55, identifier:obj; 56, tuple; 57, call; 58, identifier:obj; 59, identifier:dict; 60, call; 61, binary_operator:"%r can not be hashed. Try providing a custom key function." % obj; 62, lambda_parameters; 63, None; 64, identifier:obj; 65, call; 66, identifier:obj; 67, call; 68, identifier:list; 69, identifier:tuple; 70, identifier:tuple; 71, generator_expression; 72, identifier:tuple; 73, argument_list; 74, string:"%r can not be hashed. Try providing a custom key function."; 75, identifier:obj; 76, identifier:o; 77, identifier:ftype; 78, argument_list; 79, identifier:sorted; 80, argument_list; 81, call; 82, for_in_clause; 83, call; 84, identifier:obj; 85, identifier:obj; 86, identifier:make_key_hippie; 87, argument_list; 88, identifier:e; 89, identifier:obj; 90, identifier:sorted; 91, argument_list; 92, identifier:e; 93, identifier:typed; 94, generator_expression; 95, tuple; 96, for_in_clause; 97, call; 98, call; 99, pattern_list; 100, call; 101, identifier:make_key_hippie; 102, argument_list; 103, identifier:make_key_hippie; 104, argument_list; 105, identifier:k; 106, identifier:v; 107, attribute; 108, argument_list; 109, identifier:k; 110, identifier:typed; 111, identifier:v; 112, identifier:typed; 113, identifier:obj; 114, identifier:items
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; 6, 16; 6, 17; 7, 18; 8, 19; 9, 20; 9, 21; 9, 22; 9, 23; 12, 24; 12, 25; 13, 26; 13, 27; 14, 28; 14, 29; 15, 30; 19, 31; 19, 32; 20, 33; 20, 34; 23, 35; 24, 36; 24, 37; 25, 38; 26, 39; 26, 40; 27, 41; 28, 42; 28, 43; 29, 44; 30, 45; 30, 46; 32, 47; 32, 48; 32, 49; 34, 50; 35, 51; 37, 52; 37, 53; 38, 54; 40, 55; 40, 56; 41, 57; 43, 58; 43, 59; 44, 60; 46, 61; 49, 62; 49, 63; 51, 64; 51, 65; 54, 66; 54, 67; 56, 68; 56, 69; 57, 70; 57, 71; 60, 72; 60, 73; 61, 74; 61, 75; 62, 76; 65, 77; 65, 78; 67, 79; 67, 80; 71, 81; 71, 82; 73, 83; 78, 84; 80, 85; 81, 86; 81, 87; 82, 88; 82, 89; 83, 90; 83, 91; 87, 92; 87, 93; 91, 94; 94, 95; 94, 96; 95, 97; 95, 98; 96, 99; 96, 100; 97, 101; 97, 102; 98, 103; 98, 104; 99, 105; 99, 106; 100, 107; 100, 108; 102, 109; 102, 110; 104, 111; 104, 112; 107, 113; 107, 114
def make_key_hippie(obj, typed=True): """Return hashable structure from non-hashable structure using hippie means dict and set are sorted and their content subjected to same hippie means. Note that the key identifies the current content of the structure. """ ftype = type if typed else lambda o: None if is_hashable(obj): ## DO NOT RETURN hash(obj), as hash collision would generate bad ## cache collisions. return obj, ftype(obj) ## should we try to convert to frozen{set,dict} to get the C ## hashing function speed ? But the convertion has a cost also. if isinstance(obj, set): obj = sorted(obj) if isinstance(obj, (list, tuple)): return tuple(make_key_hippie(e, typed) for e in obj) if isinstance(obj, dict): return tuple(sorted(((make_key_hippie(k, typed), make_key_hippie(v, typed)) for k, v in obj.items()))) raise ValueError( "%r can not be hashed. Try providing a custom key function." % obj)
0, module; 1, function_definition; 2, function_name:run_radia; 3, parameters; 4, block; 5, identifier:job; 6, identifier:rna_bam; 7, identifier:tumor_bam; 8, identifier:normal_bam; 9, identifier:univ_options; 10, identifier:radia_options; 11, expression_statement; 12, if_statement; 13, expression_statement; 14, comment:# Get a list of chromosomes to process; 15, if_statement; 16, expression_statement; 17, for_statement; 18, expression_statement; 19, return_statement; 20, comment:""" Spawn a RADIA job for each chromosome on the input bam trios. :param dict rna_bam: Dict of bam and bai for tumor DNA-Seq. It can be one of two formats rna_bam: # Just the genomic bam and bai |- 'rna_genome_sorted.bam': fsID +- 'rna_genome_sorted.bam.bai': fsID OR rna_bam: # The output from run_star |- 'rna_transcriptome.bam': fsID |- 'rna_genome': # Only this part will be used |- 'rna_genome_sorted.bam': fsID +- 'rna_genome_sorted.bam.bai': fsID :param dict tumor_bam: Dict of bam and bai for tumor DNA-Seq :param dict normal_bam: Dict of bam and bai for normal DNA-Seq :param dict univ_options: Dict of universal options used by almost all tools :param dict radia_options: Options specific to RADIA :return: Dict of results from running RADIA on every chromosome perchrom_radia: |- 'chr1': fsID |- 'chr2' fsID | |-... | +- 'chrM': fsID :rtype: dict """; 21, comparison_operator:'rna_genome' in rna_bam.keys(); 22, block; 23, elif_clause; 24, else_clause; 25, assignment; 26, subscript; 27, block; 28, else_clause; 29, assignment; 30, identifier:chrom; 31, identifier:chromosomes; 32, block; 33, call; 34, identifier:perchrom_radia; 35, string; 36, call; 37, expression_statement; 38, comparison_operator:set(rna_bam.keys()) == {'rna_genome_sorted.bam', 'rna_genome_sorted.bam.bai'}; 39, block; 40, block; 41, identifier:bams; 42, dictionary; 43, identifier:radia_options; 44, string; 45, expression_statement; 46, block; 47, identifier:perchrom_radia; 48, call; 49, expression_statement; 50, expression_statement; 51, expression_statement; 52, attribute; 53, argument_list; 54, string_content:rna_genome; 55, attribute; 56, argument_list; 57, assignment; 58, call; 59, set; 60, pass_statement; 61, raise_statement; 62, pair; 63, pair; 64, pair; 65, pair; 66, pair; 67, pair; 68, string_content:chromosomes; 69, assignment; 70, expression_statement; 71, identifier:defaultdict; 72, argument_list; 73, assignment; 74, assignment; 75, assignment; 76, attribute; 77, identifier:logToMaster; 78, binary_operator:'Ran spawn_radia on %s successfully' % univ_options['patient']; 79, identifier:rna_bam; 80, identifier:keys; 81, identifier:rna_bam; 82, subscript; 83, identifier:set; 84, argument_list; 85, string; 86, string; 87, call; 88, string; 89, subscript; 90, string; 91, subscript; 92, string; 93, subscript; 94, string; 95, subscript; 96, string; 97, subscript; 98, string; 99, subscript; 100, identifier:chromosomes; 101, subscript; 102, assignment; 103, identifier:radia; 104, call; 105, identifier:filter_radia; 106, call; 107, subscript; 108, call; 109, identifier:job; 110, identifier:fileStore; 111, string; 112, subscript; 113, identifier:rna_bam; 114, string; 115, call; 116, string_content:rna_genome_sorted.bam; 117, string_content:rna_genome_sorted.bam.bai; 118, identifier:RuntimeError; 119, argument_list; 120, string_content:tumor_rna; 121, identifier:rna_bam; 122, string; 123, string_content:tumor_rnai; 124, identifier:rna_bam; 125, string; 126, string_content:tumor_dna; 127, identifier:tumor_bam; 128, string; 129, string_content:tumor_dnai; 130, identifier:tumor_bam; 131, string; 132, string_content:normal_dna; 133, identifier:normal_bam; 134, string; 135, string_content:normal_dnai; 136, identifier:normal_bam; 137, string; 138, identifier:radia_options; 139, string; 140, identifier:chromosomes; 141, call; 142, attribute; 143, argument_list; 144, attribute; 145, argument_list; 146, identifier:perchrom_radia; 147, identifier:chrom; 148, attribute; 149, argument_list; 150, string_content:Ran spawn_radia on %s successfully; 151, identifier:univ_options; 152, string; 153, string_content:rna_genome; 154, attribute; 155, argument_list; 156, string; 157, string_content:rna_genome_sorted.bam; 158, string_content:rna_genome_sorted.bam.bai; 159, string_content:tumor_dna_fix_pg_sorted.bam; 160, string_content:tumor_dna_fix_pg_sorted.bam.bai; 161, string_content:normal_dna_fix_pg_sorted.bam; 162, string_content:normal_dna_fix_pg_sorted.bam.bai; 163, string_content:chromosomes; 164, identifier:sample_chromosomes; 165, argument_list; 166, identifier:job; 167, identifier:addChildJobFn; 168, identifier:run_radia_perchrom; 169, identifier:bams; 170, identifier:univ_options; 171, identifier:radia_options; 172, identifier:chrom; 173, keyword_argument; 174, keyword_argument; 175, identifier:radia; 176, identifier:addChildJobFn; 177, identifier:run_filter_radia; 178, identifier:bams; 179, call; 180, identifier:univ_options; 181, identifier:radia_options; 182, identifier:chrom; 183, keyword_argument; 184, keyword_argument; 185, identifier:filter_radia; 186, identifier:rv; 187, string_content:patient; 188, identifier:rna_bam; 189, identifier:keys; 190, string_content:An improperly formatted dict was passed to rna_bam.; 191, identifier:job; 192, subscript; 193, identifier:memory; 194, string; 195, identifier:disk; 196, call; 197, attribute; 198, argument_list; 199, identifier:memory; 200, string; 201, identifier:disk; 202, call; 203, identifier:radia_options; 204, string; 205, string_content:6G; 206, identifier:PromisedRequirement; 207, argument_list; 208, identifier:radia; 209, identifier:rv; 210, string_content:6G; 211, identifier:PromisedRequirement; 212, argument_list; 213, string_content:genome_fai; 214, identifier:radia_disk; 215, subscript; 216, subscript; 217, subscript; 218, subscript; 219, identifier:radia_disk; 220, subscript; 221, subscript; 222, subscript; 223, subscript; 224, identifier:tumor_bam; 225, string; 226, identifier:normal_bam; 227, string; 228, identifier:rna_bam; 229, string; 230, identifier:radia_options; 231, string; 232, identifier:tumor_bam; 233, string; 234, identifier:normal_bam; 235, string; 236, identifier:rna_bam; 237, string; 238, identifier:radia_options; 239, string; 240, string_content:tumor_dna_fix_pg_sorted.bam; 241, string_content:normal_dna_fix_pg_sorted.bam; 242, string_content:rna_genome_sorted.bam; 243, string_content:genome_fasta; 244, string_content:tumor_dna_fix_pg_sorted.bam; 245, string_content:normal_dna_fix_pg_sorted.bam; 246, string_content:rna_genome_sorted.bam; 247, string_content:genome_fasta
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; 11, 20; 12, 21; 12, 22; 12, 23; 12, 24; 13, 25; 15, 26; 15, 27; 15, 28; 16, 29; 17, 30; 17, 31; 17, 32; 18, 33; 19, 34; 21, 35; 21, 36; 22, 37; 23, 38; 23, 39; 24, 40; 25, 41; 25, 42; 26, 43; 26, 44; 27, 45; 28, 46; 29, 47; 29, 48; 32, 49; 32, 50; 32, 51; 33, 52; 33, 53; 35, 54; 36, 55; 36, 56; 37, 57; 38, 58; 38, 59; 39, 60; 40, 61; 42, 62; 42, 63; 42, 64; 42, 65; 42, 66; 42, 67; 44, 68; 45, 69; 46, 70; 48, 71; 48, 72; 49, 73; 50, 74; 51, 75; 52, 76; 52, 77; 53, 78; 55, 79; 55, 80; 57, 81; 57, 82; 58, 83; 58, 84; 59, 85; 59, 86; 61, 87; 62, 88; 62, 89; 63, 90; 63, 91; 64, 92; 64, 93; 65, 94; 65, 95; 66, 96; 66, 97; 67, 98; 67, 99; 69, 100; 69, 101; 70, 102; 73, 103; 73, 104; 74, 105; 74, 106; 75, 107; 75, 108; 76, 109; 76, 110; 78, 111; 78, 112; 82, 113; 82, 114; 84, 115; 85, 116; 86, 117; 87, 118; 87, 119; 88, 120; 89, 121; 89, 122; 90, 123; 91, 124; 91, 125; 92, 126; 93, 127; 93, 128; 94, 129; 95, 130; 95, 131; 96, 132; 97, 133; 97, 134; 98, 135; 99, 136; 99, 137; 101, 138; 101, 139; 102, 140; 102, 141; 104, 142; 104, 143; 106, 144; 106, 145; 107, 146; 107, 147; 108, 148; 108, 149; 111, 150; 112, 151; 112, 152; 114, 153; 115, 154; 115, 155; 119, 156; 122, 157; 125, 158; 128, 159; 131, 160; 134, 161; 137, 162; 139, 163; 141, 164; 141, 165; 142, 166; 142, 167; 143, 168; 143, 169; 143, 170; 143, 171; 143, 172; 143, 173; 143, 174; 144, 175; 144, 176; 145, 177; 145, 178; 145, 179; 145, 180; 145, 181; 145, 182; 145, 183; 145, 184; 148, 185; 148, 186; 152, 187; 154, 188; 154, 189; 156, 190; 165, 191; 165, 192; 173, 193; 173, 194; 174, 195; 174, 196; 179, 197; 179, 198; 183, 199; 183, 200; 184, 201; 184, 202; 192, 203; 192, 204; 194, 205; 196, 206; 196, 207; 197, 208; 197, 209; 200, 210; 202, 211; 202, 212; 204, 213; 207, 214; 207, 215; 207, 216; 207, 217; 207, 218; 212, 219; 212, 220; 212, 221; 212, 222; 212, 223; 215, 224; 215, 225; 216, 226; 216, 227; 217, 228; 217, 229; 218, 230; 218, 231; 220, 232; 220, 233; 221, 234; 221, 235; 222, 236; 222, 237; 223, 238; 223, 239; 225, 240; 227, 241; 229, 242; 231, 243; 233, 244; 235, 245; 237, 246; 239, 247
def run_radia(job, rna_bam, tumor_bam, normal_bam, univ_options, radia_options): """ Spawn a RADIA job for each chromosome on the input bam trios. :param dict rna_bam: Dict of bam and bai for tumor DNA-Seq. It can be one of two formats rna_bam: # Just the genomic bam and bai |- 'rna_genome_sorted.bam': fsID +- 'rna_genome_sorted.bam.bai': fsID OR rna_bam: # The output from run_star |- 'rna_transcriptome.bam': fsID |- 'rna_genome': # Only this part will be used |- 'rna_genome_sorted.bam': fsID +- 'rna_genome_sorted.bam.bai': fsID :param dict tumor_bam: Dict of bam and bai for tumor DNA-Seq :param dict normal_bam: Dict of bam and bai for normal DNA-Seq :param dict univ_options: Dict of universal options used by almost all tools :param dict radia_options: Options specific to RADIA :return: Dict of results from running RADIA on every chromosome perchrom_radia: |- 'chr1': fsID |- 'chr2' fsID | |-... | +- 'chrM': fsID :rtype: dict """ if 'rna_genome' in rna_bam.keys(): rna_bam = rna_bam['rna_genome'] elif set(rna_bam.keys()) == {'rna_genome_sorted.bam', 'rna_genome_sorted.bam.bai'}: pass else: raise RuntimeError('An improperly formatted dict was passed to rna_bam.') bams = {'tumor_rna': rna_bam['rna_genome_sorted.bam'], 'tumor_rnai': rna_bam['rna_genome_sorted.bam.bai'], 'tumor_dna': tumor_bam['tumor_dna_fix_pg_sorted.bam'], 'tumor_dnai': tumor_bam['tumor_dna_fix_pg_sorted.bam.bai'], 'normal_dna': normal_bam['normal_dna_fix_pg_sorted.bam'], 'normal_dnai': normal_bam['normal_dna_fix_pg_sorted.bam.bai']} # Get a list of chromosomes to process if radia_options['chromosomes']: chromosomes = radia_options['chromosomes'] else: chromosomes = sample_chromosomes(job, radia_options['genome_fai']) perchrom_radia = defaultdict() for chrom in chromosomes: radia = job.addChildJobFn(run_radia_perchrom, bams, univ_options, radia_options, chrom, memory='6G', disk=PromisedRequirement( radia_disk, tumor_bam['tumor_dna_fix_pg_sorted.bam'], normal_bam['normal_dna_fix_pg_sorted.bam'], rna_bam['rna_genome_sorted.bam'], radia_options['genome_fasta'])) filter_radia = radia.addChildJobFn(run_filter_radia, bams, radia.rv(), univ_options, radia_options, chrom, memory='6G', disk=PromisedRequirement( radia_disk, tumor_bam['tumor_dna_fix_pg_sorted.bam'], normal_bam['normal_dna_fix_pg_sorted.bam'], rna_bam['rna_genome_sorted.bam'], radia_options['genome_fasta'])) perchrom_radia[chrom] = filter_radia.rv() job.fileStore.logToMaster('Ran spawn_radia on %s successfully' % univ_options['patient']) return perchrom_radia
0, module; 1, function_definition; 2, function_name:sort_bamfile; 3, parameters; 4, block; 5, identifier:job; 6, identifier:bamfile; 7, identifier:sample_type; 8, identifier:univ_options; 9, identifier:samtools_options; 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, return_statement; 21, comment:""" Sort `bamfile` using samtools :param toil.fileStore.FileID bamfile: fsID for the bam file :param str sample_type: Description of the sample to inject into the filename :param dict univ_options: Dict of universal options used by almost all tools :param dict samtools_options: Options specific to samtools :return: fsID for the sorted bamfile :rtype: toil.fileStore.FileID """; 22, assignment; 23, assignment; 24, assignment; 25, assignment; 26, assignment; 27, assignment; 28, call; 29, call; 30, call; 31, call; 32, identifier:work_dir; 33, call; 34, identifier:in_bamfile; 35, call; 36, identifier:out_bamfile; 37, call; 38, identifier:input_files; 39, dictionary; 40, identifier:input_files; 41, call; 42, identifier:parameters; 43, list; 44, identifier:docker_call; 45, argument_list; 46, attribute; 47, argument_list; 48, attribute; 49, argument_list; 50, attribute; 51, argument_list; 52, attribute; 53, argument_list; 54, attribute; 55, argument_list; 56, attribute; 57, argument_list; 58, pair; 59, identifier:get_files_from_filestore; 60, argument_list; 61, string; 62, string; 63, call; 64, string; 65, string; 66, string; 67, string; 68, string; 69, call; 70, subscript; 71, keyword_argument; 72, keyword_argument; 73, keyword_argument; 74, keyword_argument; 75, keyword_argument; 76, attribute; 77, identifier:deleteGlobalFile; 78, identifier:bamfile; 79, attribute; 80, identifier:logToMaster; 81, binary_operator:'Ran samtools-sort on %s:%s successfully' % (univ_options['patient'], sample_type); 82, attribute; 83, identifier:writeGlobalFile; 84, identifier:out_bamfile; 85, identifier:os; 86, identifier:getcwd; 87, string; 88, identifier:join; 89, list; 90, string; 91, identifier:join; 92, list; 93, identifier:in_bamfile; 94, identifier:bamfile; 95, identifier:job; 96, identifier:input_files; 97, identifier:work_dir; 98, keyword_argument; 99, string_content:sort; 100, string_content:-o; 101, identifier:docker_path; 102, argument_list; 103, string_content:-O; 104, string_content:bam; 105, string_content:-T; 106, string_content:temp_sorted; 107, string_content:-@; 108, identifier:str; 109, argument_list; 110, identifier:input_files; 111, identifier:in_bamfile; 112, identifier:tool; 113, string; 114, identifier:tool_parameters; 115, identifier:parameters; 116, identifier:work_dir; 117, identifier:work_dir; 118, identifier:dockerhub; 119, subscript; 120, identifier:tool_version; 121, subscript; 122, identifier:job; 123, identifier:fileStore; 124, identifier:job; 125, identifier:fileStore; 126, string; 127, tuple; 128, identifier:job; 129, identifier:fileStore; 130, identifier:sample_type; 131, string; 132, string_content:_; 133, identifier:sample_type; 134, string; 135, identifier:docker; 136, True; 137, identifier:out_bamfile; 138, subscript; 139, string_content:samtools; 140, identifier:univ_options; 141, string; 142, identifier:samtools_options; 143, string; 144, string_content:Ran samtools-sort on %s:%s successfully; 145, subscript; 146, identifier:sample_type; 147, string_content:.bam; 148, string_content:sorted.bam; 149, identifier:samtools_options; 150, string; 151, string_content:dockerhub; 152, string_content:version; 153, identifier:univ_options; 154, string; 155, string_content:n; 156, string_content:patient
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; 10, 21; 11, 22; 12, 23; 13, 24; 14, 25; 15, 26; 16, 27; 17, 28; 18, 29; 19, 30; 20, 31; 22, 32; 22, 33; 23, 34; 23, 35; 24, 36; 24, 37; 25, 38; 25, 39; 26, 40; 26, 41; 27, 42; 27, 43; 28, 44; 28, 45; 29, 46; 29, 47; 30, 48; 30, 49; 31, 50; 31, 51; 33, 52; 33, 53; 35, 54; 35, 55; 37, 56; 37, 57; 39, 58; 41, 59; 41, 60; 43, 61; 43, 62; 43, 63; 43, 64; 43, 65; 43, 66; 43, 67; 43, 68; 43, 69; 43, 70; 45, 71; 45, 72; 45, 73; 45, 74; 45, 75; 46, 76; 46, 77; 47, 78; 48, 79; 48, 80; 49, 81; 50, 82; 50, 83; 51, 84; 52, 85; 52, 86; 54, 87; 54, 88; 55, 89; 56, 90; 56, 91; 57, 92; 58, 93; 58, 94; 60, 95; 60, 96; 60, 97; 60, 98; 61, 99; 62, 100; 63, 101; 63, 102; 64, 103; 65, 104; 66, 105; 67, 106; 68, 107; 69, 108; 69, 109; 70, 110; 70, 111; 71, 112; 71, 113; 72, 114; 72, 115; 73, 116; 73, 117; 74, 118; 74, 119; 75, 120; 75, 121; 76, 122; 76, 123; 79, 124; 79, 125; 81, 126; 81, 127; 82, 128; 82, 129; 89, 130; 89, 131; 90, 132; 92, 133; 92, 134; 98, 135; 98, 136; 102, 137; 109, 138; 113, 139; 119, 140; 119, 141; 121, 142; 121, 143; 126, 144; 127, 145; 127, 146; 131, 147; 134, 148; 138, 149; 138, 150; 141, 151; 143, 152; 145, 153; 145, 154; 150, 155; 154, 156
def sort_bamfile(job, bamfile, sample_type, univ_options, samtools_options): """ Sort `bamfile` using samtools :param toil.fileStore.FileID bamfile: fsID for the bam file :param str sample_type: Description of the sample to inject into the filename :param dict univ_options: Dict of universal options used by almost all tools :param dict samtools_options: Options specific to samtools :return: fsID for the sorted bamfile :rtype: toil.fileStore.FileID """ work_dir = os.getcwd() in_bamfile = ''.join([sample_type, '.bam']) out_bamfile = '_'.join([sample_type, 'sorted.bam']) input_files = { in_bamfile: bamfile} input_files = get_files_from_filestore(job, input_files, work_dir, docker=True) parameters = ['sort', '-o', docker_path(out_bamfile), '-O', 'bam', '-T', 'temp_sorted', '-@', str(samtools_options['n']), input_files[in_bamfile]] docker_call(tool='samtools', tool_parameters=parameters, work_dir=work_dir, dockerhub=univ_options['dockerhub'], tool_version=samtools_options['version']) job.fileStore.deleteGlobalFile(bamfile) job.fileStore.logToMaster('Ran samtools-sort on %s:%s successfully' % (univ_options['patient'], sample_type)) return job.fileStore.writeGlobalFile(out_bamfile)
0, module; 1, function_definition; 2, function_name:recursive_sort; 3, parameters; 4, block; 5, identifier:data_structure; 6, expression_statement; 7, comment:# We don't sory primitve types; 8, if_statement; 9, return_statement; 10, comment:"""Sort a recursive data_structure. :param data_structure: The structure to convert. data_structure must be already sortable or you must use freeze() or dump(). The function will work with many kinds of input. Dictionaries will be converted to lists of tuples. >>> _py2_to_py3(vformat(recursive_sort(dump( ... [3, 1, {'c' : 'c', 'a' : 'b', 'b' : 'a'}] ... )))) (["<class 'dict'>", (('a', 'b'), ('b', 'a'), ('c', 'c'))], 1, 3) >>> recursive_sort([3, 1, {'c' : 'c', 'a' : 'b', 'b' : 'a'}]) ((('a', 'b'), ('b', 'a'), ('c', 'c')), 1, 3) >>> recursive_sort(_TestClass()) (('a', 'huhu'),) """; 11, not_operator; 12, block; 13, identifier:data_structure; 14, call; 15, expression_statement; 16, expression_statement; 17, if_statement; 18, expression_statement; 19, comment:# If item has a length we sort it; 20, try_statement; 21, if_statement; 22, identifier:isinstance; 23, argument_list; 24, assignment; 25, assignment; 26, not_operator; 27, block; 28, assignment; 29, block; 30, except_clause; 31, comparison_operator:tlen != -1; 32, comment:# Well there are classes out in the wild that answer to len; 33, comment:# but have no indexer.; 34, block; 35, identifier:data_structure; 36, identifier:_primitive_types; 37, identifier:is_meta; 38, call; 39, identifier:was_dict; 40, call; 41, parenthesized_expression; 42, expression_statement; 43, if_statement; 44, comment:# Itemize if possible; 45, try_statement; 46, identifier:tlen; 47, unary_operator; 48, expression_statement; 49, comment:# pragma: no cover; 50, block; 51, identifier:tlen; 52, unary_operator; 53, try_statement; 54, identifier:isinstance; 55, argument_list; 56, identifier:isinstance; 57, argument_list; 58, boolean_operator; 59, assignment; 60, not_operator; 61, comment:# Dictize if possible (support objects); 62, block; 63, block; 64, except_clause; 65, integer:1; 66, assignment; 67, pass_statement; 68, integer:1; 69, block; 70, except_clause; 71, identifier:data_structure; 72, identifier:Meta; 73, identifier:data_structure; 74, identifier:WasDict; 75, identifier:is_meta; 76, identifier:was_dict; 77, identifier:was_dict; 78, call; 79, identifier:was_dict; 80, try_statement; 81, expression_statement; 82, block; 83, identifier:tlen; 84, call; 85, if_statement; 86, comment:# pragma: no cover; 87, block; 88, identifier:isinstance; 89, argument_list; 90, block; 91, except_clause; 92, assignment; 93, pass_statement; 94, identifier:len; 95, argument_list; 96, identifier:was_dict; 97, block; 98, elif_clause; 99, else_clause; 100, pass_statement; 101, identifier:data_structure; 102, identifier:dict; 103, expression_statement; 104, expression_statement; 105, block; 106, identifier:data_structure; 107, call; 108, identifier:data_structure; 109, return_statement; 110, identifier:is_meta; 111, block; 112, block; 113, assignment; 114, assignment; 115, pass_statement; 116, attribute; 117, argument_list; 118, call; 119, return_statement; 120, return_statement; 121, identifier:data_structure; 122, attribute; 123, identifier:was_dict; 124, True; 125, identifier:data_structure; 126, identifier:items; 127, identifier:tuple; 128, argument_list; 129, binary_operator:data_structure[0:-1] + [ recursive_sort( data_structure[-1] ) ]; 130, call; 131, identifier:data_structure; 132, identifier:__dict__; 133, call; 134, subscript; 135, list; 136, identifier:tuple; 137, argument_list; 138, identifier:sorted; 139, argument_list; 140, identifier:data_structure; 141, slice; 142, call; 143, call; 144, list_comprehension; 145, keyword_argument; 146, integer:0; 147, unary_operator; 148, identifier:recursive_sort; 149, argument_list; 150, identifier:sorted; 151, argument_list; 152, tuple; 153, for_in_clause; 154, identifier:key; 155, identifier:TraversalBasedReprCompare; 156, integer:1; 157, subscript; 158, list_comprehension; 159, keyword_argument; 160, call; 161, call; 162, identifier:x; 163, identifier:data_structure; 164, identifier:data_structure; 165, unary_operator; 166, call; 167, for_in_clause; 168, identifier:key; 169, identifier:TraversalBasedReprCompare; 170, identifier:recursive_sort; 171, argument_list; 172, identifier:recursive_sort; 173, argument_list; 174, integer:1; 175, identifier:recursive_sort; 176, argument_list; 177, identifier:x; 178, identifier:data_structure; 179, subscript; 180, subscript; 181, identifier:x; 182, identifier:x; 183, integer:0; 184, identifier:x; 185, integer:1
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 4, 8; 4, 9; 6, 10; 8, 11; 8, 12; 9, 13; 11, 14; 12, 15; 12, 16; 12, 17; 12, 18; 12, 19; 12, 20; 12, 21; 14, 22; 14, 23; 15, 24; 16, 25; 17, 26; 17, 27; 18, 28; 20, 29; 20, 30; 21, 31; 21, 32; 21, 33; 21, 34; 23, 35; 23, 36; 24, 37; 24, 38; 25, 39; 25, 40; 26, 41; 27, 42; 27, 43; 27, 44; 27, 45; 28, 46; 28, 47; 29, 48; 30, 49; 30, 50; 31, 51; 31, 52; 34, 53; 38, 54; 38, 55; 40, 56; 40, 57; 41, 58; 42, 59; 43, 60; 43, 61; 43, 62; 45, 63; 45, 64; 47, 65; 48, 66; 50, 67; 52, 68; 53, 69; 53, 70; 55, 71; 55, 72; 57, 73; 57, 74; 58, 75; 58, 76; 59, 77; 59, 78; 60, 79; 62, 80; 63, 81; 64, 82; 66, 83; 66, 84; 69, 85; 70, 86; 70, 87; 78, 88; 78, 89; 80, 90; 80, 91; 81, 92; 82, 93; 84, 94; 84, 95; 85, 96; 85, 97; 85, 98; 85, 99; 87, 100; 89, 101; 89, 102; 90, 103; 90, 104; 91, 105; 92, 106; 92, 107; 95, 108; 97, 109; 98, 110; 98, 111; 99, 112; 103, 113; 104, 114; 105, 115; 107, 116; 107, 117; 109, 118; 111, 119; 112, 120; 113, 121; 113, 122; 114, 123; 114, 124; 116, 125; 116, 126; 118, 127; 118, 128; 119, 129; 120, 130; 122, 131; 122, 132; 128, 133; 129, 134; 129, 135; 130, 136; 130, 137; 133, 138; 133, 139; 134, 140; 134, 141; 135, 142; 137, 143; 139, 144; 139, 145; 141, 146; 141, 147; 142, 148; 142, 149; 143, 150; 143, 151; 144, 152; 144, 153; 145, 154; 145, 155; 147, 156; 149, 157; 151, 158; 151, 159; 152, 160; 152, 161; 153, 162; 153, 163; 157, 164; 157, 165; 158, 166; 158, 167; 159, 168; 159, 169; 160, 170; 160, 171; 161, 172; 161, 173; 165, 174; 166, 175; 166, 176; 167, 177; 167, 178; 171, 179; 173, 180; 176, 181; 179, 182; 179, 183; 180, 184; 180, 185
def recursive_sort(data_structure): """Sort a recursive data_structure. :param data_structure: The structure to convert. data_structure must be already sortable or you must use freeze() or dump(). The function will work with many kinds of input. Dictionaries will be converted to lists of tuples. >>> _py2_to_py3(vformat(recursive_sort(dump( ... [3, 1, {'c' : 'c', 'a' : 'b', 'b' : 'a'}] ... )))) (["<class 'dict'>", (('a', 'b'), ('b', 'a'), ('c', 'c'))], 1, 3) >>> recursive_sort([3, 1, {'c' : 'c', 'a' : 'b', 'b' : 'a'}]) ((('a', 'b'), ('b', 'a'), ('c', 'c')), 1, 3) >>> recursive_sort(_TestClass()) (('a', 'huhu'),) """ # We don't sory primitve types if not isinstance(data_structure, _primitive_types): is_meta = isinstance(data_structure, Meta) was_dict = isinstance(data_structure, WasDict) if not (is_meta or was_dict): was_dict = isinstance(data_structure, dict) if not was_dict: # Dictize if possible (support objects) try: data_structure = data_structure.__dict__ was_dict = True except: pass # Itemize if possible try: data_structure = data_structure.items() except: pass tlen = -1 # If item has a length we sort it try: tlen = len(data_structure) except: # pragma: no cover pass if tlen != -1: # Well there are classes out in the wild that answer to len # but have no indexer. try: if was_dict: return tuple(sorted( [ ( recursive_sort(x[0]), recursive_sort(x[1]), ) for x in data_structure ], key=TraversalBasedReprCompare )) elif is_meta: return data_structure[0:-1] + [ recursive_sort( data_structure[-1] ) ] else: return tuple(sorted( [recursive_sort( x, ) for x in data_structure], key=TraversalBasedReprCompare, )) except: # pragma: no cover pass return data_structure
0, module; 1, function_definition; 2, function_name:tree_diff; 3, parameters; 4, block; 5, identifier:a; 6, identifier:b; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, if_statement; 13, return_statement; 14, identifier:n; 15, integer:5; 16, identifier:sort; 17, False; 18, comment:"""Dump any data-structure or object, traverse it depth-first in-order and apply a unified diff. Depth-first in-order is just like structure would be printed. :param a: data_structure a :param b: data_structure b :param n: lines of context :type n: int :param sort: sort the data-structure ATTENTION: Sorting means changing the data-structure. The test-result may differ. But in case of dictionaries the results become comparable because the sorting negates the hash-algorithms "de-sorting". >>> a = recursive_sort(freeze([ ... 'a', ... [3, 4], ... {'a': [3, {'w' : set([4, '3', frozenset([3,5,2])])}]}, ... [] ... ])) >>> b = recursive_sort(freeze([ ... 'a', ... [7, 3], ... {'a': [3, {'w' : set([4, '3', frozenset([2,5,3])])}]}, ... [] ... ])) >>> transparent_repr("\\n".join(tree_diff(a, b).split("\\n")[2:])) @@ -7,6 +7,6 @@ 'w'),), 3), 'a'),), 'a', (3, - 4)) + 7)) >>> a = [ ... 'a', ... [3, 4], ... {'a': [3, {'w' : set([4, '3', frozenset([3,5,2])])}]}, ... [] ... ] >>> b = [ ... 'a', ... [7, 3], ... {'a': [3, {'w' : set([4, '3', frozenset([2,5,3])])}]}, ... [] ... ] >>> transparent_repr("\\n".join( ... tree_diff(a, b, sort=True ... ).split("\\n")[2:])) @@ -11,6 +11,6 @@ '3', 4)]),)], 3)),)], 'a', (3, - 4)) + 7)) """; 19, assignment; 20, assignment; 21, not_operator; 22, block; 23, else_clause; 24, call; 25, identifier:a; 26, call; 27, identifier:b; 28, call; 29, identifier:sort; 30, expression_statement; 31, expression_statement; 32, block; 33, attribute; 34, argument_list; 35, identifier:dump; 36, argument_list; 37, identifier:dump; 38, argument_list; 39, assignment; 40, assignment; 41, expression_statement; 42, expression_statement; 43, string:"\n"; 44, identifier:join; 45, call; 46, identifier:a; 47, identifier:b; 48, identifier:a; 49, call; 50, identifier:b; 51, call; 52, assignment; 53, assignment; 54, attribute; 55, argument_list; 56, attribute; 57, argument_list; 58, attribute; 59, argument_list; 60, identifier:a; 61, call; 62, identifier:b; 63, call; 64, identifier:difflib; 65, identifier:unified_diff; 66, identifier:a; 67, identifier:b; 68, keyword_argument; 69, keyword_argument; 70, call; 71, identifier:split; 72, string:"\n"; 73, call; 74, identifier:split; 75, string:"\n"; 76, attribute; 77, argument_list; 78, attribute; 79, argument_list; 80, identifier:n; 81, identifier:n; 82, identifier:lineterm; 83, string:""; 84, identifier:vformat; 85, argument_list; 86, identifier:vformat; 87, argument_list; 88, call; 89, identifier:split; 90, string:"\n"; 91, call; 92, identifier:split; 93, string:"\n"; 94, identifier:a; 95, identifier:b; 96, identifier:vformat; 97, argument_list; 98, identifier:vformat; 99, argument_list; 100, call; 101, call; 102, identifier:recursive_sort; 103, argument_list; 104, identifier:recursive_sort; 105, argument_list; 106, identifier:a; 107, identifier:b
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; 11, 20; 12, 21; 12, 22; 12, 23; 13, 24; 19, 25; 19, 26; 20, 27; 20, 28; 21, 29; 22, 30; 22, 31; 23, 32; 24, 33; 24, 34; 26, 35; 26, 36; 28, 37; 28, 38; 30, 39; 31, 40; 32, 41; 32, 42; 33, 43; 33, 44; 34, 45; 36, 46; 38, 47; 39, 48; 39, 49; 40, 50; 40, 51; 41, 52; 42, 53; 45, 54; 45, 55; 49, 56; 49, 57; 51, 58; 51, 59; 52, 60; 52, 61; 53, 62; 53, 63; 54, 64; 54, 65; 55, 66; 55, 67; 55, 68; 55, 69; 56, 70; 56, 71; 57, 72; 58, 73; 58, 74; 59, 75; 61, 76; 61, 77; 63, 78; 63, 79; 68, 80; 68, 81; 69, 82; 69, 83; 70, 84; 70, 85; 73, 86; 73, 87; 76, 88; 76, 89; 77, 90; 78, 91; 78, 92; 79, 93; 85, 94; 87, 95; 88, 96; 88, 97; 91, 98; 91, 99; 97, 100; 99, 101; 100, 102; 100, 103; 101, 104; 101, 105; 103, 106; 105, 107
def tree_diff(a, b, n=5, sort=False): """Dump any data-structure or object, traverse it depth-first in-order and apply a unified diff. Depth-first in-order is just like structure would be printed. :param a: data_structure a :param b: data_structure b :param n: lines of context :type n: int :param sort: sort the data-structure ATTENTION: Sorting means changing the data-structure. The test-result may differ. But in case of dictionaries the results become comparable because the sorting negates the hash-algorithms "de-sorting". >>> a = recursive_sort(freeze([ ... 'a', ... [3, 4], ... {'a': [3, {'w' : set([4, '3', frozenset([3,5,2])])}]}, ... [] ... ])) >>> b = recursive_sort(freeze([ ... 'a', ... [7, 3], ... {'a': [3, {'w' : set([4, '3', frozenset([2,5,3])])}]}, ... [] ... ])) >>> transparent_repr("\\n".join(tree_diff(a, b).split("\\n")[2:])) @@ -7,6 +7,6 @@ 'w'),), 3), 'a'),), 'a', (3, - 4)) + 7)) >>> a = [ ... 'a', ... [3, 4], ... {'a': [3, {'w' : set([4, '3', frozenset([3,5,2])])}]}, ... [] ... ] >>> b = [ ... 'a', ... [7, 3], ... {'a': [3, {'w' : set([4, '3', frozenset([2,5,3])])}]}, ... [] ... ] >>> transparent_repr("\\n".join( ... tree_diff(a, b, sort=True ... ).split("\\n")[2:])) @@ -11,6 +11,6 @@ '3', 4)]),)], 3)),)], 'a', (3, - 4)) + 7)) """ a = dump(a) b = dump(b) if not sort: a = vformat(a).split("\n") b = vformat(b).split("\n") else: a = vformat(recursive_sort(a)).split("\n") b = vformat(recursive_sort(b)).split("\n") return "\n".join(difflib.unified_diff(a, b, n=n, lineterm=""))
0, module; 1, function_definition; 2, function_name:_add_new; 3, parameters; 4, block; 5, identifier:self; 6, identifier:host_object; 7, expression_statement; 8, expression_statement; 9, for_statement; 10, expression_statement; 11, comment:"""Add a new host to the collection. Before a new hostname can be added, all its subdomains already present in the collection must be removed. Since the collection is sorted, we can limit our search for them to a slice of the collection starting from insertion point and ending with the last detected subdomain. :param host_obj: an object representing value to be added. It is assumed that, during execution of this method, the value to be added is not currently listed. """; 12, assignment; 13, identifier:listed; 14, subscript; 15, block; 16, call; 17, identifier:i; 18, call; 19, identifier:self; 20, slice; 21, if_statement; 22, expression_statement; 23, attribute; 24, argument_list; 25, attribute; 26, argument_list; 27, identifier:i; 28, not_operator; 29, block; 30, call; 31, attribute; 32, identifier:insert; 33, identifier:i; 34, call; 35, identifier:self; 36, identifier:_get_insertion_point; 37, identifier:host_object; 38, call; 39, break_statement; 40, attribute; 41, argument_list; 42, identifier:self; 43, identifier:hosts; 44, attribute; 45, argument_list; 46, attribute; 47, argument_list; 48, attribute; 49, identifier:pop; 50, identifier:i; 51, identifier:host_object; 52, identifier:to_unicode; 53, identifier:listed; 54, identifier:is_subdomain; 55, identifier:host_object; 56, identifier:self; 57, identifier:hosts
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 7, 11; 8, 12; 9, 13; 9, 14; 9, 15; 10, 16; 12, 17; 12, 18; 14, 19; 14, 20; 15, 21; 15, 22; 16, 23; 16, 24; 18, 25; 18, 26; 20, 27; 21, 28; 21, 29; 22, 30; 23, 31; 23, 32; 24, 33; 24, 34; 25, 35; 25, 36; 26, 37; 28, 38; 29, 39; 30, 40; 30, 41; 31, 42; 31, 43; 34, 44; 34, 45; 38, 46; 38, 47; 40, 48; 40, 49; 41, 50; 44, 51; 44, 52; 46, 53; 46, 54; 47, 55; 48, 56; 48, 57
def _add_new(self, host_object): """Add a new host to the collection. Before a new hostname can be added, all its subdomains already present in the collection must be removed. Since the collection is sorted, we can limit our search for them to a slice of the collection starting from insertion point and ending with the last detected subdomain. :param host_obj: an object representing value to be added. It is assumed that, during execution of this method, the value to be added is not currently listed. """ i = self._get_insertion_point(host_object) for listed in self[i:]: if not listed.is_subdomain(host_object): break self.hosts.pop(i) self.hosts.insert(i, host_object.to_unicode())
0, module; 1, function_definition; 2, function_name:sort_by_type; 3, parameters; 4, block; 5, identifier:file_list; 6, expression_statement; 7, expression_statement; 8, for_statement; 9, return_statement; 10, comment:""" Sorts a list of files into types. :param file_list: List of file paths. :return: {extension: [<list of file paths with that extension>]} """; 11, assignment; 12, identifier:filepath; 13, identifier:file_list; 14, block; 15, identifier:ret_dict; 16, identifier:ret_dict; 17, call; 18, expression_statement; 19, expression_statement; 20, identifier:defaultdict; 21, argument_list; 22, assignment; 23, call; 24, identifier:list; 25, pattern_list; 26, call; 27, attribute; 28, argument_list; 29, identifier:_; 30, identifier:ext; 31, attribute; 32, argument_list; 33, subscript; 34, identifier:append; 35, identifier:filepath; 36, attribute; 37, identifier:splitext; 38, identifier:filepath; 39, identifier:ret_dict; 40, call; 41, identifier:os; 42, identifier:path; 43, attribute; 44, argument_list; 45, identifier:ext; 46, identifier:replace; 47, string; 48, string; 49, string_content:.
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; 14, 18; 14, 19; 17, 20; 17, 21; 18, 22; 19, 23; 21, 24; 22, 25; 22, 26; 23, 27; 23, 28; 25, 29; 25, 30; 26, 31; 26, 32; 27, 33; 27, 34; 28, 35; 31, 36; 31, 37; 32, 38; 33, 39; 33, 40; 36, 41; 36, 42; 40, 43; 40, 44; 43, 45; 43, 46; 44, 47; 44, 48; 47, 49
def sort_by_type(file_list): """ Sorts a list of files into types. :param file_list: List of file paths. :return: {extension: [<list of file paths with that extension>]} """ ret_dict = defaultdict(list) for filepath in file_list: _, ext = os.path.splitext(filepath) ret_dict[ext.replace('.', '')].append(filepath) return ret_dict
0, module; 1, function_definition; 2, function_name:search; 3, parameters; 4, block; 5, identifier:self; 6, identifier:query_string; 7, expression_statement; 8, expression_statement; 9, comment:# TODO: should QueryParser be a method of query? should it return one?; 10, expression_statement; 11, expression_statement; 12, return_statement; 13, comment:"""Performs a search against the index using lunr query syntax. Results will be returned sorted by their score, the most relevant results will be returned first. For more programmatic querying use `lunr.Index.query`. Args: query_string (str): A string to parse into a Query. Returns: dict: Results of executing the query. """; 14, assignment; 15, assignment; 16, call; 17, call; 18, identifier:query; 19, call; 20, identifier:parser; 21, call; 22, attribute; 23, argument_list; 24, attribute; 25, argument_list; 26, attribute; 27, argument_list; 28, identifier:QueryParser; 29, argument_list; 30, identifier:parser; 31, identifier:parse; 32, identifier:self; 33, identifier:query; 34, identifier:query; 35, identifier:self; 36, identifier:create_query; 37, identifier:query_string; 38, identifier:query
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; 10, 15; 11, 16; 12, 17; 14, 18; 14, 19; 15, 20; 15, 21; 16, 22; 16, 23; 17, 24; 17, 25; 19, 26; 19, 27; 21, 28; 21, 29; 22, 30; 22, 31; 24, 32; 24, 33; 25, 34; 26, 35; 26, 36; 29, 37; 29, 38
def search(self, query_string): """Performs a search against the index using lunr query syntax. Results will be returned sorted by their score, the most relevant results will be returned first. For more programmatic querying use `lunr.Index.query`. Args: query_string (str): A string to parse into a Query. Returns: dict: Results of executing the query. """ query = self.create_query() # TODO: should QueryParser be a method of query? should it return one? parser = QueryParser(query_string, query) parser.parse() return self.query(query)
0, module; 1, function_definition; 2, function_name:mode_half_sample; 3, parameters; 4, block; 5, identifier:a; 6, default_parameter; 7, expression_statement; 8, expression_statement; 9, if_statement; 10, expression_statement; 11, if_statement; 12, identifier:is_sorted; 13, False; 14, string:''' Estimate the mode using the Half Sample mode. A method to estimate the mode, as described in D. R. Bickel and R. Frühwirth (contributed equally), "On a fast, robust estimator of the mode: Comparisons to other robust estimators with applications," Computational Statistics and Data Analysis 50, 3500-3530 (2006). Example ======= >> import numpy as np >> np.random.seed(1392838) >> a = np.random.normal(1000, 200, size=1000) >> a[:100] = np.random.normal(2000, 300, size=100) >> b = np.sort(a) >> mode_half_sample(b, is_sorted=True) 1041.9327885039545 '''; 15, assignment; 16, not_operator; 17, block; 18, else_clause; 19, assignment; 20, comparison_operator:n == 1; 21, block; 22, elif_clause; 23, elif_clause; 24, else_clause; 25, identifier:a; 26, call; 27, identifier:is_sorted; 28, expression_statement; 29, block; 30, identifier:n; 31, call; 32, identifier:n; 33, integer:1; 34, return_statement; 35, comparison_operator:n == 2; 36, block; 37, comparison_operator:n == 3; 38, block; 39, block; 40, attribute; 41, argument_list; 42, assignment; 43, expression_statement; 44, identifier:len; 45, argument_list; 46, subscript; 47, identifier:n; 48, integer:2; 49, return_statement; 50, identifier:n; 51, integer:3; 52, expression_statement; 53, if_statement; 54, expression_statement; 55, expression_statement; 56, expression_statement; 57, return_statement; 58, identifier:np; 59, identifier:asanyarray; 60, identifier:a; 61, identifier:sdata; 62, call; 63, assignment; 64, identifier:sdata; 65, identifier:sdata; 66, integer:0; 67, binary_operator:0.5 * (sdata[0] + sdata[1]); 68, assignment; 69, comparison_operator:ind < 0; 70, block; 71, elif_clause; 72, else_clause; 73, assignment; 74, assignment; 75, assignment; 76, call; 77, attribute; 78, argument_list; 79, identifier:sdata; 80, identifier:a; 81, float:0.5; 82, parenthesized_expression; 83, identifier:ind; 84, binary_operator:-sdata[0] + 2 * sdata[1] - sdata[2]; 85, identifier:ind; 86, integer:0; 87, return_statement; 88, comparison_operator:ind > 0; 89, block; 90, block; 91, identifier:N; 92, call; 93, identifier:w; 94, binary_operator:sdata[(N-1):] - sdata[:(n-N+1)]; 95, identifier:ar; 96, call; 97, identifier:mode_half_sample; 98, argument_list; 99, identifier:np; 100, identifier:sort; 101, identifier:a; 102, binary_operator:sdata[0] + sdata[1]; 103, binary_operator:-sdata[0] + 2 * sdata[1]; 104, subscript; 105, binary_operator:0.5 * (sdata[0] + sdata[1]); 106, identifier:ind; 107, integer:0; 108, return_statement; 109, return_statement; 110, identifier:int; 111, argument_list; 112, subscript; 113, subscript; 114, attribute; 115, argument_list; 116, subscript; 117, keyword_argument; 118, subscript; 119, subscript; 120, unary_operator; 121, binary_operator:2 * sdata[1]; 122, identifier:sdata; 123, integer:2; 124, float:0.5; 125, parenthesized_expression; 126, binary_operator:0.5 * (sdata[1] + sdata[2]); 127, subscript; 128, call; 129, identifier:sdata; 130, slice; 131, identifier:sdata; 132, slice; 133, identifier:w; 134, identifier:argmin; 135, identifier:sdata; 136, slice; 137, identifier:is_sorted; 138, True; 139, identifier:sdata; 140, integer:0; 141, identifier:sdata; 142, integer:1; 143, subscript; 144, integer:2; 145, subscript; 146, binary_operator:sdata[0] + sdata[1]; 147, float:0.5; 148, parenthesized_expression; 149, identifier:sdata; 150, integer:1; 151, attribute; 152, argument_list; 153, parenthesized_expression; 154, parenthesized_expression; 155, identifier:ar; 156, binary_operator:ar+N; 157, identifier:sdata; 158, integer:0; 159, identifier:sdata; 160, integer:1; 161, subscript; 162, subscript; 163, binary_operator:sdata[1] + sdata[2]; 164, identifier:math; 165, identifier:ceil; 166, binary_operator:n / 2.0; 167, binary_operator:N-1; 168, binary_operator:n-N+1; 169, identifier:ar; 170, identifier:N; 171, identifier:sdata; 172, integer:0; 173, identifier:sdata; 174, integer:1; 175, subscript; 176, subscript; 177, identifier:n; 178, float:2.0; 179, identifier:N; 180, integer:1; 181, binary_operator:n-N; 182, integer:1; 183, identifier:sdata; 184, integer:1; 185, identifier:sdata; 186, integer:2; 187, identifier:n; 188, identifier:N
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 6, 12; 6, 13; 7, 14; 8, 15; 9, 16; 9, 17; 9, 18; 10, 19; 11, 20; 11, 21; 11, 22; 11, 23; 11, 24; 15, 25; 15, 26; 16, 27; 17, 28; 18, 29; 19, 30; 19, 31; 20, 32; 20, 33; 21, 34; 22, 35; 22, 36; 23, 37; 23, 38; 24, 39; 26, 40; 26, 41; 28, 42; 29, 43; 31, 44; 31, 45; 34, 46; 35, 47; 35, 48; 36, 49; 37, 50; 37, 51; 38, 52; 38, 53; 39, 54; 39, 55; 39, 56; 39, 57; 40, 58; 40, 59; 41, 60; 42, 61; 42, 62; 43, 63; 45, 64; 46, 65; 46, 66; 49, 67; 52, 68; 53, 69; 53, 70; 53, 71; 53, 72; 54, 73; 55, 74; 56, 75; 57, 76; 62, 77; 62, 78; 63, 79; 63, 80; 67, 81; 67, 82; 68, 83; 68, 84; 69, 85; 69, 86; 70, 87; 71, 88; 71, 89; 72, 90; 73, 91; 73, 92; 74, 93; 74, 94; 75, 95; 75, 96; 76, 97; 76, 98; 77, 99; 77, 100; 78, 101; 82, 102; 84, 103; 84, 104; 87, 105; 88, 106; 88, 107; 89, 108; 90, 109; 92, 110; 92, 111; 94, 112; 94, 113; 96, 114; 96, 115; 98, 116; 98, 117; 102, 118; 102, 119; 103, 120; 103, 121; 104, 122; 104, 123; 105, 124; 105, 125; 108, 126; 109, 127; 111, 128; 112, 129; 112, 130; 113, 131; 113, 132; 114, 133; 114, 134; 116, 135; 116, 136; 117, 137; 117, 138; 118, 139; 118, 140; 119, 141; 119, 142; 120, 143; 121, 144; 121, 145; 125, 146; 126, 147; 126, 148; 127, 149; 127, 150; 128, 151; 128, 152; 130, 153; 132, 154; 136, 155; 136, 156; 143, 157; 143, 158; 145, 159; 145, 160; 146, 161; 146, 162; 148, 163; 151, 164; 151, 165; 152, 166; 153, 167; 154, 168; 156, 169; 156, 170; 161, 171; 161, 172; 162, 173; 162, 174; 163, 175; 163, 176; 166, 177; 166, 178; 167, 179; 167, 180; 168, 181; 168, 182; 175, 183; 175, 184; 176, 185; 176, 186; 181, 187; 181, 188
def mode_half_sample(a, is_sorted=False): ''' Estimate the mode using the Half Sample mode. A method to estimate the mode, as described in D. R. Bickel and R. Frühwirth (contributed equally), "On a fast, robust estimator of the mode: Comparisons to other robust estimators with applications," Computational Statistics and Data Analysis 50, 3500-3530 (2006). Example ======= >> import numpy as np >> np.random.seed(1392838) >> a = np.random.normal(1000, 200, size=1000) >> a[:100] = np.random.normal(2000, 300, size=100) >> b = np.sort(a) >> mode_half_sample(b, is_sorted=True) 1041.9327885039545 ''' a = np.asanyarray(a) if not is_sorted: sdata = np.sort(a) else: sdata = a n = len(sdata) if n == 1: return sdata[0] elif n == 2: return 0.5 * (sdata[0] + sdata[1]) elif n == 3: ind = -sdata[0] + 2 * sdata[1] - sdata[2] if ind < 0: return 0.5 * (sdata[0] + sdata[1]) elif ind > 0: return 0.5 * (sdata[1] + sdata[2]) else: return sdata[1] else: N = int(math.ceil(n / 2.0)) w = sdata[(N-1):] - sdata[:(n-N+1)] ar = w.argmin() return mode_half_sample(sdata[ar:ar+N], is_sorted=True)
0, module; 1, function_definition; 2, function_name:construct_reference_system; 3, parameters; 4, block; 5, identifier:symbols; 6, default_parameter; 7, default_parameter; 8, expression_statement; 9, if_statement; 10, expression_statement; 11, expression_statement; 12, if_statement; 13, expression_statement; 14, comment:# go symbols in adsorbate; 15, comment:# to add reference species in procedural manner; 16, for_statement; 17, expression_statement; 18, expression_statement; 19, comment:# put references in order so that each reference; 20, comment:# only adds one one additional species in each step; 21, comment:# while references:; 22, comment:# for i, reference in enumerate(references):; 23, comment:# if len(set(ase.symbols.string2symbols(reference[1])) -; 24, comment:# set(x[0] for x in sorted_references)) == 1:; 25, comment:# sorted_references.append(references.pop(i)); 26, comment:# break; 27, return_statement; 28, identifier:candidates; 29, None; 30, identifier:options; 31, None; 32, comment:"""Take a list of symbols and construct gas phase references system, when possible avoiding O2. Candidates can be rearranged, where earlier candidates get higher preference than later candidates assume symbols sorted by atomic number """; 33, boolean_operator; 34, block; 35, else_clause; 36, assignment; 37, assignment; 38, comparison_operator:candidates is None; 39, block; 40, else_clause; 41, assignment; 42, identifier:symbol; 43, identifier:symbols; 44, block; 45, assignment; 46, assignment; 47, identifier:references; 48, call; 49, attribute; 50, expression_statement; 51, block; 52, identifier:references; 53, dictionary; 54, identifier:sorted_candidates; 55, list; 56, identifier:candidates; 57, None; 58, expression_statement; 59, block; 60, identifier:added_symbols; 61, list; 62, expression_statement; 63, for_statement; 64, identifier:sorted_references; 65, list; 66, identifier:references; 67, call; 68, identifier:hasattr; 69, argument_list; 70, identifier:options; 71, identifier:no_hydrogen; 72, assignment; 73, expression_statement; 74, string; 75, string; 76, string; 77, string; 78, string; 79, string; 80, string; 81, string; 82, string; 83, assignment; 84, expression_statement; 85, expression_statement; 86, call; 87, identifier:candidate; 88, identifier:candidates; 89, block; 90, else_clause; 91, identifier:list; 92, argument_list; 93, identifier:options; 94, string; 95, identifier:add_hydrogen; 96, False; 97, assignment; 98, string_content:H2; 99, string_content:H2O; 100, string_content:NH3; 101, string_content:N2; 102, string_content:CH4; 103, string_content:CO; 104, string_content:H2S; 105, string_content:HCl; 106, string_content:O2; 107, identifier:candidates; 108, identifier:sorted_candidates; 109, assignment; 110, assignment; 111, attribute; 112, argument_list; 113, expression_statement; 114, comment:# Add partial adsorbate species; 115, comment:# is subset of reference species; 116, comment:# and reference species; 117, comment:# is subset of full adsorbate species set; 118, if_statement; 119, block; 120, call; 121, string_content:no_hydrogen; 122, identifier:add_hydrogen; 123, True; 124, identifier:odd_candidates; 125, list_comprehension; 126, identifier:candidates; 127, binary_operator:[c for c in sorted_candidates if c in candidates] \ + odd_candidates; 128, identifier:added_symbols; 129, identifier:append; 130, identifier:symbol; 131, assignment; 132, boolean_operator; 133, block; 134, raise_statement; 135, attribute; 136, argument_list; 137, identifier:c; 138, for_in_clause; 139, if_clause; 140, list_comprehension; 141, line_continuation:\; 142, identifier:odd_candidates; 143, identifier:_symbols; 144, call; 145, boolean_operator; 146, line_continuation:\; 147, comparison_operator:candidate not in references.values(); 148, expression_statement; 149, break_statement; 150, call; 151, identifier:references; 152, identifier:items; 153, identifier:c; 154, identifier:candidates; 155, comparison_operator:c not in sorted_candidates; 156, identifier:c; 157, for_in_clause; 158, if_clause; 159, attribute; 160, argument_list; 161, comparison_operator:set(added_symbols) <= set(list(references.keys()) + _symbols); 162, line_continuation:\; 163, comparison_operator:set(list(references.keys()) + _symbols) <= set(symbols); 164, identifier:candidate; 165, call; 166, assignment; 167, identifier:UserWarning; 168, argument_list; 169, identifier:c; 170, identifier:sorted_candidates; 171, identifier:c; 172, identifier:sorted_candidates; 173, comparison_operator:c in candidates; 174, attribute; 175, identifier:string2symbols; 176, identifier:candidate; 177, call; 178, call; 179, call; 180, call; 181, attribute; 182, argument_list; 183, subscript; 184, identifier:candidate; 185, call; 186, identifier:c; 187, identifier:candidates; 188, identifier:ase; 189, identifier:symbols; 190, identifier:set; 191, argument_list; 192, identifier:set; 193, argument_list; 194, identifier:set; 195, argument_list; 196, identifier:set; 197, argument_list; 198, identifier:references; 199, identifier:values; 200, identifier:references; 201, identifier:symbol; 202, attribute; 203, argument_list; 204, identifier:added_symbols; 205, binary_operator:list(references.keys()) + _symbols; 206, binary_operator:list(references.keys()) + _symbols; 207, identifier:symbols; 208, parenthesized_expression; 209, identifier:format; 210, keyword_argument; 211, keyword_argument; 212, keyword_argument; 213, keyword_argument; 214, keyword_argument; 215, call; 216, identifier:_symbols; 217, call; 218, identifier:_symbols; 219, concatenated_string; 220, identifier:symbol; 221, identifier:symbol; 222, identifier:symbols; 223, identifier:symbols; 224, identifier:_symbols; 225, identifier:_symbols; 226, identifier:candidates; 227, identifier:candidates; 228, identifier:references; 229, call; 230, identifier:list; 231, argument_list; 232, identifier:list; 233, argument_list; 234, string:"No candidate satisfied {symbol}. Add more candidates\n"; 235, string:" Symbols {symbols}\n"; 236, string:" _Symbols {_symbols}\n"; 237, string:" References {references}\n"; 238, string:" Candidates {candidates}\n"; 239, identifier:list; 240, argument_list; 241, call; 242, call; 243, call; 244, attribute; 245, argument_list; 246, attribute; 247, argument_list; 248, attribute; 249, argument_list; 250, identifier:references; 251, identifier:keys; 252, identifier:references; 253, identifier:keys; 254, identifier:references; 255, identifier:keys
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; 4, 22; 4, 23; 4, 24; 4, 25; 4, 26; 4, 27; 6, 28; 6, 29; 7, 30; 7, 31; 8, 32; 9, 33; 9, 34; 9, 35; 10, 36; 11, 37; 12, 38; 12, 39; 12, 40; 13, 41; 16, 42; 16, 43; 16, 44; 17, 45; 18, 46; 27, 47; 33, 48; 33, 49; 34, 50; 35, 51; 36, 52; 36, 53; 37, 54; 37, 55; 38, 56; 38, 57; 39, 58; 40, 59; 41, 60; 41, 61; 44, 62; 44, 63; 45, 64; 45, 65; 46, 66; 46, 67; 48, 68; 48, 69; 49, 70; 49, 71; 50, 72; 51, 73; 55, 74; 55, 75; 55, 76; 55, 77; 55, 78; 55, 79; 55, 80; 55, 81; 55, 82; 58, 83; 59, 84; 59, 85; 62, 86; 63, 87; 63, 88; 63, 89; 63, 90; 67, 91; 67, 92; 69, 93; 69, 94; 72, 95; 72, 96; 73, 97; 74, 98; 75, 99; 76, 100; 77, 101; 78, 102; 79, 103; 80, 104; 81, 105; 82, 106; 83, 107; 83, 108; 84, 109; 85, 110; 86, 111; 86, 112; 89, 113; 89, 114; 89, 115; 89, 116; 89, 117; 89, 118; 90, 119; 92, 120; 94, 121; 97, 122; 97, 123; 109, 124; 109, 125; 110, 126; 110, 127; 111, 128; 111, 129; 112, 130; 113, 131; 118, 132; 118, 133; 119, 134; 120, 135; 120, 136; 125, 137; 125, 138; 125, 139; 127, 140; 127, 141; 127, 142; 131, 143; 131, 144; 132, 145; 132, 146; 132, 147; 133, 148; 133, 149; 134, 150; 135, 151; 135, 152; 138, 153; 138, 154; 139, 155; 140, 156; 140, 157; 140, 158; 144, 159; 144, 160; 145, 161; 145, 162; 145, 163; 147, 164; 147, 165; 148, 166; 150, 167; 150, 168; 155, 169; 155, 170; 157, 171; 157, 172; 158, 173; 159, 174; 159, 175; 160, 176; 161, 177; 161, 178; 163, 179; 163, 180; 165, 181; 165, 182; 166, 183; 166, 184; 168, 185; 173, 186; 173, 187; 174, 188; 174, 189; 177, 190; 177, 191; 178, 192; 178, 193; 179, 194; 179, 195; 180, 196; 180, 197; 181, 198; 181, 199; 183, 200; 183, 201; 185, 202; 185, 203; 191, 204; 193, 205; 195, 206; 197, 207; 202, 208; 202, 209; 203, 210; 203, 211; 203, 212; 203, 213; 203, 214; 205, 215; 205, 216; 206, 217; 206, 218; 208, 219; 210, 220; 210, 221; 211, 222; 211, 223; 212, 224; 212, 225; 213, 226; 213, 227; 214, 228; 214, 229; 215, 230; 215, 231; 217, 232; 217, 233; 219, 234; 219, 235; 219, 236; 219, 237; 219, 238; 229, 239; 229, 240; 231, 241; 233, 242; 240, 243; 241, 244; 241, 245; 242, 246; 242, 247; 243, 248; 243, 249; 244, 250; 244, 251; 246, 252; 246, 253; 248, 254; 248, 255
def construct_reference_system( symbols, candidates=None, options=None, ): """Take a list of symbols and construct gas phase references system, when possible avoiding O2. Candidates can be rearranged, where earlier candidates get higher preference than later candidates assume symbols sorted by atomic number """ if hasattr(options, 'no_hydrogen') and options.no_hydrogen: add_hydrogen = False else: add_hydrogen = True references = {} sorted_candidates = [ 'H2', 'H2O', 'NH3', 'N2', 'CH4', 'CO', 'H2S', 'HCl', 'O2'] if candidates is None: candidates = sorted_candidates else: odd_candidates = [c for c in candidates if c not in sorted_candidates] candidates = [c for c in sorted_candidates if c in candidates] \ + odd_candidates added_symbols = [] # go symbols in adsorbate # to add reference species in procedural manner for symbol in symbols: added_symbols.append(symbol) for candidate in candidates: _symbols = ase.symbols.string2symbols(candidate) # Add partial adsorbate species # is subset of reference species # and reference species # is subset of full adsorbate species set if set(added_symbols) <= set(list(references.keys()) + _symbols) \ and set(list(references.keys()) + _symbols) <= set(symbols) \ and candidate not in references.values(): references[symbol] = candidate break else: raise UserWarning(( "No candidate satisfied {symbol}. Add more candidates\n" " Symbols {symbols}\n" " _Symbols {_symbols}\n" " References {references}\n" " Candidates {candidates}\n" ).format( symbol=symbol, symbols=symbols, _symbols=_symbols, candidates=candidates, references=list(references.keys()), )) sorted_references = [] references = list(references.items()) # put references in order so that each reference # only adds one one additional species in each step # while references: # for i, reference in enumerate(references): # if len(set(ase.symbols.string2symbols(reference[1])) - # set(x[0] for x in sorted_references)) == 1: # sorted_references.append(references.pop(i)) # break return references
0, module; 1, function_definition; 2, function_name:gen_triplets_master; 3, parameters; 4, block; 5, identifier:wv_master; 6, default_parameter; 7, default_parameter; 8, expression_statement; 9, expression_statement; 10, comment:# Check that the wavelengths in the master table are sorted; 11, expression_statement; 12, for_statement; 13, comment:# Generate all the possible triplets with the numbers of the lines; 14, comment:# in the master table. Each triplet is defined as a tuple of three; 15, comment:# numbers corresponding to the three line indices in the master; 16, comment:# table. The collection of tuples is stored in an ordinary python; 17, comment:# list.; 18, expression_statement; 19, expression_statement; 20, comment:# Verify that the number of triplets coincides with the expected; 21, comment:# value.; 22, expression_statement; 23, if_statement; 24, comment:# For each triplet, compute the relative position of the central; 25, comment:# line.; 26, expression_statement; 27, for_statement; 28, comment:# Compute the array of indices that index the above ratios in; 29, comment:# sorted order.; 30, expression_statement; 31, comment:# Simultaneous sort of position ratios and triplets.; 32, expression_statement; 33, expression_statement; 34, if_statement; 35, return_statement; 36, identifier:geometry; 37, None; 38, identifier:debugplot; 39, integer:0; 40, comment:"""Compute information associated to triplets in master table. Determine all the possible triplets that can be generated from the array `wv_master`. In addition, the relative position of the central line of each triplet is also computed. Parameters ---------- wv_master : 1d numpy array, float Array with wavelengths corresponding to the master table (Angstroms). geometry : tuple (4 integers) or None x, y, dx, dy values employed to set the window geometry. debugplot : int Determines whether intermediate computations and/or plots are displayed. The valid codes are defined in numina.array.display.pause_debugplot. Returns ------- ntriplets_master : int Number of triplets built from master table. ratios_master_sorted : 1d numpy array, float Array with values of the relative position of the central line of each triplet, sorted in ascending order. triplets_master_sorted_list : list of tuples List with tuples of three numbers, corresponding to the three line indices in the master table. The list is sorted to be in correspondence with `ratios_master_sorted`. """; 41, assignment; 42, assignment; 43, identifier:i; 44, call; 45, block; 46, assignment; 47, assignment; 48, assignment; 49, comparison_operator:ntriplets_master == comb(nlines_master, 3, exact=True); 50, block; 51, else_clause; 52, assignment; 53, pattern_list; 54, call; 55, block; 56, assignment; 57, assignment; 58, assignment; 59, comparison_operator:abs(debugplot) in [21, 22]; 60, comment:# compute and plot histogram with position ratios; 61, block; 62, expression_list; 63, identifier:nlines_master; 64, attribute; 65, identifier:wv_previous; 66, subscript; 67, identifier:range; 68, argument_list; 69, if_statement; 70, expression_statement; 71, identifier:iter_comb_triplets; 72, call; 73, identifier:triplets_master_list; 74, list_comprehension; 75, identifier:ntriplets_master; 76, call; 77, identifier:ntriplets_master; 78, call; 79, if_statement; 80, block; 81, identifier:ratios_master; 82, call; 83, identifier:index; 84, identifier:value; 85, identifier:enumerate; 86, argument_list; 87, expression_statement; 88, expression_statement; 89, expression_statement; 90, expression_statement; 91, identifier:isort_ratios_master; 92, call; 93, identifier:ratios_master_sorted; 94, subscript; 95, identifier:triplets_master_sorted_list; 96, list_comprehension; 97, call; 98, list; 99, expression_statement; 100, expression_statement; 101, comment:#; 102, import_from_statement; 103, expression_statement; 104, expression_statement; 105, expression_statement; 106, expression_statement; 107, expression_statement; 108, expression_statement; 109, expression_statement; 110, expression_statement; 111, comment:# set window geometry; 112, expression_statement; 113, expression_statement; 114, identifier:ntriplets_master; 115, identifier:ratios_master_sorted; 116, identifier:triplets_master_sorted_list; 117, identifier:wv_master; 118, identifier:size; 119, identifier:wv_master; 120, integer:0; 121, integer:1; 122, identifier:nlines_master; 123, comparison_operator:wv_previous >= wv_master[i]; 124, block; 125, assignment; 126, attribute; 127, argument_list; 128, identifier:val; 129, for_in_clause; 130, identifier:len; 131, argument_list; 132, identifier:comb; 133, argument_list; 134, comparison_operator:abs(debugplot) >= 10; 135, block; 136, raise_statement; 137, attribute; 138, argument_list; 139, identifier:triplets_master_list; 140, assignment; 141, assignment; 142, assignment; 143, assignment; 144, attribute; 145, argument_list; 146, identifier:ratios_master; 147, identifier:isort_ratios_master; 148, subscript; 149, for_in_clause; 150, identifier:abs; 151, argument_list; 152, integer:21; 153, integer:22; 154, assignment; 155, assignment; 156, dotted_name; 157, dotted_name; 158, assignment; 159, assignment; 160, assignment; 161, assignment; 162, call; 163, call; 164, call; 165, call; 166, call; 167, call; 168, identifier:wv_previous; 169, subscript; 170, raise_statement; 171, identifier:wv_previous; 172, subscript; 173, identifier:itertools; 174, identifier:combinations; 175, call; 176, integer:3; 177, identifier:val; 178, identifier:iter_comb_triplets; 179, identifier:triplets_master_list; 180, identifier:nlines_master; 181, integer:3; 182, keyword_argument; 183, call; 184, integer:10; 185, expression_statement; 186, expression_statement; 187, call; 188, identifier:np; 189, identifier:zeros; 190, identifier:ntriplets_master; 191, pattern_list; 192, identifier:value; 193, identifier:delta1; 194, binary_operator:wv_master[i2] - wv_master[i1]; 195, identifier:delta2; 196, binary_operator:wv_master[i3] - wv_master[i1]; 197, subscript; 198, binary_operator:delta1 / delta2; 199, identifier:np; 200, identifier:argsort; 201, identifier:ratios_master; 202, identifier:triplets_master_list; 203, identifier:i; 204, identifier:i; 205, identifier:isort_ratios_master; 206, identifier:debugplot; 207, identifier:bins_in; 208, call; 209, pattern_list; 210, call; 211, identifier:numina; 212, identifier:array; 213, identifier:display; 214, identifier:matplotlib_qt; 215, identifier:plt; 216, identifier:fig; 217, call; 218, identifier:ax; 219, call; 220, identifier:width_hist; 221, binary_operator:0.8*(bins_out[1]-bins_out[0]); 222, identifier:center; 223, binary_operator:(bins_out[:-1]+bins_out[1:])/2; 224, attribute; 225, argument_list; 226, attribute; 227, argument_list; 228, attribute; 229, argument_list; 230, attribute; 231, argument_list; 232, identifier:set_window_geometry; 233, argument_list; 234, identifier:pause_debugplot; 235, argument_list; 236, identifier:wv_master; 237, identifier:i; 238, call; 239, identifier:wv_master; 240, identifier:i; 241, identifier:range; 242, argument_list; 243, identifier:exact; 244, True; 245, identifier:abs; 246, argument_list; 247, call; 248, call; 249, identifier:ValueError; 250, argument_list; 251, identifier:i1; 252, identifier:i2; 253, identifier:i3; 254, subscript; 255, subscript; 256, subscript; 257, subscript; 258, identifier:ratios_master; 259, identifier:index; 260, identifier:delta1; 261, identifier:delta2; 262, attribute; 263, argument_list; 264, identifier:hist; 265, identifier:bins_out; 266, attribute; 267, argument_list; 268, attribute; 269, argument_list; 270, attribute; 271, argument_list; 272, float:0.8; 273, parenthesized_expression; 274, parenthesized_expression; 275, integer:2; 276, identifier:ax; 277, identifier:bar; 278, identifier:center; 279, identifier:hist; 280, keyword_argument; 281, keyword_argument; 282, identifier:ax; 283, identifier:set_xlabel; 284, string; 285, identifier:ax; 286, identifier:set_ylabel; 287, string; 288, identifier:ax; 289, identifier:set_title; 290, binary_operator:"Number of lines/triplets: " + str(nlines_master) + "/" + str(ntriplets_master); 291, identifier:geometry; 292, identifier:debugplot; 293, keyword_argument; 294, keyword_argument; 295, identifier:ValueError; 296, argument_list; 297, identifier:nlines_master; 298, identifier:debugplot; 299, identifier:print; 300, argument_list; 301, identifier:print; 302, argument_list; 303, string; 304, identifier:wv_master; 305, identifier:i2; 306, identifier:wv_master; 307, identifier:i1; 308, identifier:wv_master; 309, identifier:i3; 310, identifier:wv_master; 311, identifier:i1; 312, identifier:np; 313, identifier:linspace; 314, float:0.0; 315, float:1.0; 316, integer:41; 317, identifier:np; 318, identifier:histogram; 319, identifier:ratios_master; 320, keyword_argument; 321, identifier:plt; 322, identifier:figure; 323, identifier:fig; 324, identifier:add_subplot; 325, integer:111; 326, binary_operator:bins_out[1]-bins_out[0]; 327, binary_operator:bins_out[:-1]+bins_out[1:]; 328, identifier:align; 329, string; 330, identifier:width; 331, identifier:width_hist; 332, string_content:distance ratio in each triplet; 333, string_content:Number of triplets; 334, binary_operator:"Number of lines/triplets: " + str(nlines_master) + "/"; 335, call; 336, identifier:pltshow; 337, True; 338, identifier:tight_layout; 339, True; 340, binary_operator:'Wavelengths:\n--> ' + str(wv_previous) + '\n--> ' + str(wv_master[i]) + '\nin master table are duplicated or not sorted'; 341, string; 342, identifier:nlines_master; 343, string; 344, identifier:ntriplets_master; 345, string_content:Invalid number of combinations; 346, identifier:bins; 347, identifier:bins_in; 348, subscript; 349, subscript; 350, subscript; 351, subscript; 352, string_content:center; 353, binary_operator:"Number of lines/triplets: " + str(nlines_master); 354, string:"/"; 355, identifier:str; 356, argument_list; 357, binary_operator:'Wavelengths:\n--> ' + str(wv_previous) + '\n--> ' + str(wv_master[i]); 358, string; 359, string_content:>>> Total number of lines in master table:; 360, string_content:>>> Number of triplets in master table...:; 361, identifier:bins_out; 362, integer:1; 363, identifier:bins_out; 364, integer:0; 365, identifier:bins_out; 366, slice; 367, identifier:bins_out; 368, slice; 369, string:"Number of lines/triplets: "; 370, call; 371, identifier:ntriplets_master; 372, binary_operator:'Wavelengths:\n--> ' + str(wv_previous) + '\n--> '; 373, call; 374, string_content; 375, unary_operator; 376, integer:1; 377, identifier:str; 378, argument_list; 379, binary_operator:'Wavelengths:\n--> ' + str(wv_previous); 380, string; 381, identifier:str; 382, argument_list; 383, escape_sequence:\n; 384, integer:1; 385, identifier:nlines_master; 386, string; 387, call; 388, string_content; 389, subscript; 390, string_content; 391, identifier:str; 392, argument_list; 393, escape_sequence:\n; 394, identifier:wv_master; 395, identifier:i; 396, escape_sequence:\n; 397, identifier:wv_previous
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; 4, 22; 4, 23; 4, 24; 4, 25; 4, 26; 4, 27; 4, 28; 4, 29; 4, 30; 4, 31; 4, 32; 4, 33; 4, 34; 4, 35; 6, 36; 6, 37; 7, 38; 7, 39; 8, 40; 9, 41; 11, 42; 12, 43; 12, 44; 12, 45; 18, 46; 19, 47; 22, 48; 23, 49; 23, 50; 23, 51; 26, 52; 27, 53; 27, 54; 27, 55; 30, 56; 32, 57; 33, 58; 34, 59; 34, 60; 34, 61; 35, 62; 41, 63; 41, 64; 42, 65; 42, 66; 44, 67; 44, 68; 45, 69; 45, 70; 46, 71; 46, 72; 47, 73; 47, 74; 48, 75; 48, 76; 49, 77; 49, 78; 50, 79; 51, 80; 52, 81; 52, 82; 53, 83; 53, 84; 54, 85; 54, 86; 55, 87; 55, 88; 55, 89; 55, 90; 56, 91; 56, 92; 57, 93; 57, 94; 58, 95; 58, 96; 59, 97; 59, 98; 61, 99; 61, 100; 61, 101; 61, 102; 61, 103; 61, 104; 61, 105; 61, 106; 61, 107; 61, 108; 61, 109; 61, 110; 61, 111; 61, 112; 61, 113; 62, 114; 62, 115; 62, 116; 64, 117; 64, 118; 66, 119; 66, 120; 68, 121; 68, 122; 69, 123; 69, 124; 70, 125; 72, 126; 72, 127; 74, 128; 74, 129; 76, 130; 76, 131; 78, 132; 78, 133; 79, 134; 79, 135; 80, 136; 82, 137; 82, 138; 86, 139; 87, 140; 88, 141; 89, 142; 90, 143; 92, 144; 92, 145; 94, 146; 94, 147; 96, 148; 96, 149; 97, 150; 97, 151; 98, 152; 98, 153; 99, 154; 100, 155; 102, 156; 102, 157; 103, 158; 104, 159; 105, 160; 106, 161; 107, 162; 108, 163; 109, 164; 110, 165; 112, 166; 113, 167; 123, 168; 123, 169; 124, 170; 125, 171; 125, 172; 126, 173; 126, 174; 127, 175; 127, 176; 129, 177; 129, 178; 131, 179; 133, 180; 133, 181; 133, 182; 134, 183; 134, 184; 135, 185; 135, 186; 136, 187; 137, 188; 137, 189; 138, 190; 140, 191; 140, 192; 141, 193; 141, 194; 142, 195; 142, 196; 143, 197; 143, 198; 144, 199; 144, 200; 145, 201; 148, 202; 148, 203; 149, 204; 149, 205; 151, 206; 154, 207; 154, 208; 155, 209; 155, 210; 156, 211; 156, 212; 156, 213; 156, 214; 157, 215; 158, 216; 158, 217; 159, 218; 159, 219; 160, 220; 160, 221; 161, 222; 161, 223; 162, 224; 162, 225; 163, 226; 163, 227; 164, 228; 164, 229; 165, 230; 165, 231; 166, 232; 166, 233; 167, 234; 167, 235; 169, 236; 169, 237; 170, 238; 172, 239; 172, 240; 175, 241; 175, 242; 182, 243; 182, 244; 183, 245; 183, 246; 185, 247; 186, 248; 187, 249; 187, 250; 191, 251; 191, 252; 191, 253; 194, 254; 194, 255; 196, 256; 196, 257; 197, 258; 197, 259; 198, 260; 198, 261; 208, 262; 208, 263; 209, 264; 209, 265; 210, 266; 210, 267; 217, 268; 217, 269; 219, 270; 219, 271; 221, 272; 221, 273; 223, 274; 223, 275; 224, 276; 224, 277; 225, 278; 225, 279; 225, 280; 225, 281; 226, 282; 226, 283; 227, 284; 228, 285; 228, 286; 229, 287; 230, 288; 230, 289; 231, 290; 233, 291; 235, 292; 235, 293; 235, 294; 238, 295; 238, 296; 242, 297; 246, 298; 247, 299; 247, 300; 248, 301; 248, 302; 250, 303; 254, 304; 254, 305; 255, 306; 255, 307; 256, 308; 256, 309; 257, 310; 257, 311; 262, 312; 262, 313; 263, 314; 263, 315; 263, 316; 266, 317; 266, 318; 267, 319; 267, 320; 268, 321; 268, 322; 270, 323; 270, 324; 271, 325; 273, 326; 274, 327; 280, 328; 280, 329; 281, 330; 281, 331; 284, 332; 287, 333; 290, 334; 290, 335; 293, 336; 293, 337; 294, 338; 294, 339; 296, 340; 300, 341; 300, 342; 302, 343; 302, 344; 303, 345; 320, 346; 320, 347; 326, 348; 326, 349; 327, 350; 327, 351; 329, 352; 334, 353; 334, 354; 335, 355; 335, 356; 340, 357; 340, 358; 341, 359; 343, 360; 348, 361; 348, 362; 349, 363; 349, 364; 350, 365; 350, 366; 351, 367; 351, 368; 353, 369; 353, 370; 356, 371; 357, 372; 357, 373; 358, 374; 366, 375; 368, 376; 370, 377; 370, 378; 372, 379; 372, 380; 373, 381; 373, 382; 374, 383; 375, 384; 378, 385; 379, 386; 379, 387; 380, 388; 382, 389; 386, 390; 387, 391; 387, 392; 388, 393; 389, 394; 389, 395; 390, 396; 392, 397
def gen_triplets_master(wv_master, geometry=None, debugplot=0): """Compute information associated to triplets in master table. Determine all the possible triplets that can be generated from the array `wv_master`. In addition, the relative position of the central line of each triplet is also computed. Parameters ---------- wv_master : 1d numpy array, float Array with wavelengths corresponding to the master table (Angstroms). geometry : tuple (4 integers) or None x, y, dx, dy values employed to set the window geometry. debugplot : int Determines whether intermediate computations and/or plots are displayed. The valid codes are defined in numina.array.display.pause_debugplot. Returns ------- ntriplets_master : int Number of triplets built from master table. ratios_master_sorted : 1d numpy array, float Array with values of the relative position of the central line of each triplet, sorted in ascending order. triplets_master_sorted_list : list of tuples List with tuples of three numbers, corresponding to the three line indices in the master table. The list is sorted to be in correspondence with `ratios_master_sorted`. """ nlines_master = wv_master.size # Check that the wavelengths in the master table are sorted wv_previous = wv_master[0] for i in range(1, nlines_master): if wv_previous >= wv_master[i]: raise ValueError('Wavelengths:\n--> ' + str(wv_previous) + '\n--> ' + str(wv_master[i]) + '\nin master table are duplicated or not sorted') wv_previous = wv_master[i] # Generate all the possible triplets with the numbers of the lines # in the master table. Each triplet is defined as a tuple of three # numbers corresponding to the three line indices in the master # table. The collection of tuples is stored in an ordinary python # list. iter_comb_triplets = itertools.combinations(range(nlines_master), 3) triplets_master_list = [val for val in iter_comb_triplets] # Verify that the number of triplets coincides with the expected # value. ntriplets_master = len(triplets_master_list) if ntriplets_master == comb(nlines_master, 3, exact=True): if abs(debugplot) >= 10: print('>>> Total number of lines in master table:', nlines_master) print('>>> Number of triplets in master table...:', ntriplets_master) else: raise ValueError('Invalid number of combinations') # For each triplet, compute the relative position of the central # line. ratios_master = np.zeros(ntriplets_master) for index, value in enumerate(triplets_master_list): i1, i2, i3 = value delta1 = wv_master[i2] - wv_master[i1] delta2 = wv_master[i3] - wv_master[i1] ratios_master[index] = delta1 / delta2 # Compute the array of indices that index the above ratios in # sorted order. isort_ratios_master = np.argsort(ratios_master) # Simultaneous sort of position ratios and triplets. ratios_master_sorted = ratios_master[isort_ratios_master] triplets_master_sorted_list = [triplets_master_list[i] for i in isort_ratios_master] if abs(debugplot) in [21, 22]: # compute and plot histogram with position ratios bins_in = np.linspace(0.0, 1.0, 41) hist, bins_out = np.histogram(ratios_master, bins=bins_in) # from numina.array.display.matplotlib_qt import plt fig = plt.figure() ax = fig.add_subplot(111) width_hist = 0.8*(bins_out[1]-bins_out[0]) center = (bins_out[:-1]+bins_out[1:])/2 ax.bar(center, hist, align='center', width=width_hist) ax.set_xlabel('distance ratio in each triplet') ax.set_ylabel('Number of triplets') ax.set_title("Number of lines/triplets: " + str(nlines_master) + "/" + str(ntriplets_master)) # set window geometry set_window_geometry(geometry) pause_debugplot(debugplot, pltshow=True, tight_layout=True) return ntriplets_master, ratios_master_sorted, triplets_master_sorted_list
0, module; 1, function_definition; 2, function_name:shortlex; 3, parameters; 4, block; 5, identifier:start; 6, identifier:other; 7, default_parameter; 8, expression_statement; 9, if_statement; 10, expression_statement; 11, while_statement; 12, identifier:excludestart; 13, False; 14, comment:"""Yield all unions of start with other in shortlex order. >>> ['{:03b}'.format(s) for s in shortlex(0, [0b100, 0b010, 0b001])] ['000', '100', '010', '001', '110', '101', '011', '111'] >>> ', '.join(''.join(sorted(s)) ... for s in shortlex(set(), [{'a'}, {'b'}, {'c'}, {'d'}])) ', a, b, c, d, ab, ac, ad, bc, bd, cd, abc, abd, acd, bcd, abcd' >>> assert list(shortlex(set(), [{1}, {2}], excludestart=True)) == \ [{1}, {2}, {1, 2}] """; 15, not_operator; 16, block; 17, assignment; 18, identifier:queue; 19, block; 20, identifier:excludestart; 21, expression_statement; 22, identifier:queue; 23, call; 24, expression_statement; 25, while_statement; 26, yield; 27, attribute; 28, argument_list; 29, assignment; 30, identifier:other; 31, block; 32, identifier:start; 33, identifier:collections; 34, identifier:deque; 35, list; 36, pattern_list; 37, call; 38, expression_statement; 39, expression_statement; 40, expression_statement; 41, if_statement; 42, tuple; 43, identifier:current; 44, identifier:other; 45, attribute; 46, argument_list; 47, assignment; 48, assignment; 49, yield; 50, identifier:other; 51, block; 52, identifier:start; 53, identifier:other; 54, identifier:queue; 55, identifier:popleft; 56, pattern_list; 57, expression_list; 58, identifier:result; 59, binary_operator:current | first; 60, identifier:result; 61, expression_statement; 62, identifier:first; 63, identifier:other; 64, subscript; 65, subscript; 66, identifier:current; 67, identifier:first; 68, call; 69, identifier:other; 70, integer:0; 71, identifier:other; 72, slice; 73, attribute; 74, argument_list; 75, integer:1; 76, identifier:queue; 77, identifier:append; 78, tuple; 79, identifier:result; 80, identifier:other
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; 11, 18; 11, 19; 15, 20; 16, 21; 17, 22; 17, 23; 19, 24; 19, 25; 21, 26; 23, 27; 23, 28; 24, 29; 25, 30; 25, 31; 26, 32; 27, 33; 27, 34; 28, 35; 29, 36; 29, 37; 31, 38; 31, 39; 31, 40; 31, 41; 35, 42; 36, 43; 36, 44; 37, 45; 37, 46; 38, 47; 39, 48; 40, 49; 41, 50; 41, 51; 42, 52; 42, 53; 45, 54; 45, 55; 47, 56; 47, 57; 48, 58; 48, 59; 49, 60; 51, 61; 56, 62; 56, 63; 57, 64; 57, 65; 59, 66; 59, 67; 61, 68; 64, 69; 64, 70; 65, 71; 65, 72; 68, 73; 68, 74; 72, 75; 73, 76; 73, 77; 74, 78; 78, 79; 78, 80
def shortlex(start, other, excludestart=False): """Yield all unions of start with other in shortlex order. >>> ['{:03b}'.format(s) for s in shortlex(0, [0b100, 0b010, 0b001])] ['000', '100', '010', '001', '110', '101', '011', '111'] >>> ', '.join(''.join(sorted(s)) ... for s in shortlex(set(), [{'a'}, {'b'}, {'c'}, {'d'}])) ', a, b, c, d, ab, ac, ad, bc, bd, cd, abc, abd, acd, bcd, abcd' >>> assert list(shortlex(set(), [{1}, {2}], excludestart=True)) == \ [{1}, {2}, {1, 2}] """ if not excludestart: yield start queue = collections.deque([(start, other)]) while queue: current, other = queue.popleft() while other: first, other = other[0], other[1:] result = current | first yield result if other: queue.append((result, other))
0, module; 1, function_definition; 2, function_name:reverse_shortlex; 3, parameters; 4, block; 5, identifier:end; 6, identifier:other; 7, default_parameter; 8, expression_statement; 9, if_statement; 10, expression_statement; 11, while_statement; 12, identifier:excludeend; 13, False; 14, comment:"""Yield all intersections of end with other in reverse shortlex order. >>> ['{:03b}'.format(s) for s in reverse_shortlex(0b111, [0b011, 0b101, 0b110])] ['111', '011', '101', '110', '001', '010', '100', '000'] >>> ', '.join(''.join(sorted(s)) ... for s in reverse_shortlex({'a', 'b', 'c', 'd'}, ... [{'b', 'c', 'd'}, {'a', 'c', 'd'}, {'a', 'b', 'd'}, {'a', 'b', 'c'}])) 'abcd, bcd, acd, abd, abc, cd, bd, bc, ad, ac, ab, d, c, b, a, ' >>> assert list(reverse_shortlex({1, 2}, [{1}, {2}], excludeend=True)) == \ [{1}, {2}, set()] """; 15, not_operator; 16, block; 17, assignment; 18, identifier:queue; 19, block; 20, identifier:excludeend; 21, expression_statement; 22, identifier:queue; 23, call; 24, expression_statement; 25, while_statement; 26, yield; 27, attribute; 28, argument_list; 29, assignment; 30, identifier:other; 31, block; 32, identifier:end; 33, identifier:collections; 34, identifier:deque; 35, list; 36, pattern_list; 37, call; 38, expression_statement; 39, expression_statement; 40, expression_statement; 41, if_statement; 42, tuple; 43, identifier:current; 44, identifier:other; 45, attribute; 46, argument_list; 47, assignment; 48, assignment; 49, yield; 50, identifier:other; 51, block; 52, identifier:end; 53, identifier:other; 54, identifier:queue; 55, identifier:popleft; 56, pattern_list; 57, expression_list; 58, identifier:result; 59, binary_operator:current & first; 60, identifier:result; 61, expression_statement; 62, identifier:first; 63, identifier:other; 64, subscript; 65, subscript; 66, identifier:current; 67, identifier:first; 68, call; 69, identifier:other; 70, integer:0; 71, identifier:other; 72, slice; 73, attribute; 74, argument_list; 75, integer:1; 76, identifier:queue; 77, identifier:append; 78, tuple; 79, identifier:result; 80, identifier:other
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; 11, 18; 11, 19; 15, 20; 16, 21; 17, 22; 17, 23; 19, 24; 19, 25; 21, 26; 23, 27; 23, 28; 24, 29; 25, 30; 25, 31; 26, 32; 27, 33; 27, 34; 28, 35; 29, 36; 29, 37; 31, 38; 31, 39; 31, 40; 31, 41; 35, 42; 36, 43; 36, 44; 37, 45; 37, 46; 38, 47; 39, 48; 40, 49; 41, 50; 41, 51; 42, 52; 42, 53; 45, 54; 45, 55; 47, 56; 47, 57; 48, 58; 48, 59; 49, 60; 51, 61; 56, 62; 56, 63; 57, 64; 57, 65; 59, 66; 59, 67; 61, 68; 64, 69; 64, 70; 65, 71; 65, 72; 68, 73; 68, 74; 72, 75; 73, 76; 73, 77; 74, 78; 78, 79; 78, 80
def reverse_shortlex(end, other, excludeend=False): """Yield all intersections of end with other in reverse shortlex order. >>> ['{:03b}'.format(s) for s in reverse_shortlex(0b111, [0b011, 0b101, 0b110])] ['111', '011', '101', '110', '001', '010', '100', '000'] >>> ', '.join(''.join(sorted(s)) ... for s in reverse_shortlex({'a', 'b', 'c', 'd'}, ... [{'b', 'c', 'd'}, {'a', 'c', 'd'}, {'a', 'b', 'd'}, {'a', 'b', 'c'}])) 'abcd, bcd, acd, abd, abc, cd, bd, bc, ad, ac, ab, d, c, b, a, ' >>> assert list(reverse_shortlex({1, 2}, [{1}, {2}], excludeend=True)) == \ [{1}, {2}, set()] """ if not excludeend: yield end queue = collections.deque([(end, other)]) while queue: current, other = queue.popleft() while other: first, other = other[0], other[1:] result = current & first yield result if other: queue.append((result, other))
0, module; 1, function_definition; 2, function_name:set_sort; 3, parameters; 4, block; 5, identifier:self; 6, identifier:request; 7, expression_statement; 8, comment:# Look for 'sort' in get request. If not available use default.; 9, expression_statement; 10, if_statement; 11, comment:# Invalid sort requests fail silently; 12, if_statement; 13, return_statement; 14, comment:""" Take the sort parameter from the get parameters and split it into the field and the prefix """; 15, assignment; 16, call; 17, block; 18, else_clause; 19, not_operator; 20, block; 21, tuple; 22, identifier:sort_request; 23, call; 24, attribute; 25, argument_list; 26, expression_statement; 27, expression_statement; 28, block; 29, comparison_operator:sort_field in self._allowed_sort_fields; 30, expression_statement; 31, expression_statement; 32, identifier:sort_order; 33, identifier:sort_field; 34, attribute; 35, argument_list; 36, identifier:sort_request; 37, identifier:startswith; 38, string; 39, assignment; 40, assignment; 41, expression_statement; 42, expression_statement; 43, identifier:sort_field; 44, attribute; 45, assignment; 46, assignment; 47, attribute; 48, identifier:get; 49, attribute; 50, attribute; 51, string_content:-; 52, identifier:sort_order; 53, string; 54, identifier:sort_field; 55, subscript; 56, assignment; 57, assignment; 58, identifier:self; 59, identifier:_allowed_sort_fields; 60, identifier:sort_order; 61, attribute; 62, identifier:sort_field; 63, attribute; 64, identifier:request; 65, identifier:GET; 66, identifier:self; 67, identifier:sort_parameter; 68, identifier:self; 69, identifier:default_sort; 70, string_content:-; 71, call; 72, integer:1; 73, identifier:sort_order; 74, string; 75, identifier:sort_field; 76, identifier:sort_request; 77, identifier:self; 78, identifier:default_sort_order; 79, identifier:self; 80, identifier:default_sort_field; 81, attribute; 82, argument_list; 83, identifier:sort_request; 84, identifier:split; 85, string; 86, string_content:-
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; 10, 18; 12, 19; 12, 20; 13, 21; 15, 22; 15, 23; 16, 24; 16, 25; 17, 26; 17, 27; 18, 28; 19, 29; 20, 30; 20, 31; 21, 32; 21, 33; 23, 34; 23, 35; 24, 36; 24, 37; 25, 38; 26, 39; 27, 40; 28, 41; 28, 42; 29, 43; 29, 44; 30, 45; 31, 46; 34, 47; 34, 48; 35, 49; 35, 50; 38, 51; 39, 52; 39, 53; 40, 54; 40, 55; 41, 56; 42, 57; 44, 58; 44, 59; 45, 60; 45, 61; 46, 62; 46, 63; 47, 64; 47, 65; 49, 66; 49, 67; 50, 68; 50, 69; 53, 70; 55, 71; 55, 72; 56, 73; 56, 74; 57, 75; 57, 76; 61, 77; 61, 78; 63, 79; 63, 80; 71, 81; 71, 82; 81, 83; 81, 84; 82, 85; 85, 86
def set_sort(self, request): """ Take the sort parameter from the get parameters and split it into the field and the prefix """ # Look for 'sort' in get request. If not available use default. sort_request = request.GET.get(self.sort_parameter, self.default_sort) if sort_request.startswith('-'): sort_order = '-' sort_field = sort_request.split('-')[1] else: sort_order = '' sort_field = sort_request # Invalid sort requests fail silently if not sort_field in self._allowed_sort_fields: sort_order = self.default_sort_order sort_field = self.default_sort_field return (sort_order, sort_field)
0, module; 1, function_definition; 2, function_name:get_next_sort_string; 3, parameters; 4, block; 5, identifier:self; 6, identifier:field; 7, expression_statement; 8, comment:# self.sort_field is the currect sort field; 9, if_statement; 10, return_statement; 11, comment:""" If we're already sorted by the field then the sort query returned reverses the sort order. """; 12, comparison_operator:field == self.sort_field; 13, block; 14, else_clause; 15, call; 16, identifier:field; 17, attribute; 18, expression_statement; 19, block; 20, attribute; 21, argument_list; 22, identifier:self; 23, identifier:sort_field; 24, assignment; 25, expression_statement; 26, expression_statement; 27, identifier:self; 28, identifier:get_sort_string; 29, identifier:next_sort; 30, identifier:next_sort; 31, binary_operator:self.toggle_sort_order() + field; 32, assignment; 33, assignment; 34, call; 35, identifier:field; 36, identifier:default_order_for_field; 37, line_continuation:\; 38, subscript; 39, identifier:next_sort; 40, binary_operator:default_order_for_field + field; 41, attribute; 42, argument_list; 43, subscript; 44, string; 45, identifier:default_order_for_field; 46, identifier:field; 47, identifier:self; 48, identifier:toggle_sort_order; 49, attribute; 50, identifier:field; 51, string_content:default_direction; 52, identifier:self; 53, identifier:_allowed_sort_fields
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 7, 11; 9, 12; 9, 13; 9, 14; 10, 15; 12, 16; 12, 17; 13, 18; 14, 19; 15, 20; 15, 21; 17, 22; 17, 23; 18, 24; 19, 25; 19, 26; 20, 27; 20, 28; 21, 29; 24, 30; 24, 31; 25, 32; 26, 33; 31, 34; 31, 35; 32, 36; 32, 37; 32, 38; 33, 39; 33, 40; 34, 41; 34, 42; 38, 43; 38, 44; 40, 45; 40, 46; 41, 47; 41, 48; 43, 49; 43, 50; 44, 51; 49, 52; 49, 53
def get_next_sort_string(self, field): """ If we're already sorted by the field then the sort query returned reverses the sort order. """ # self.sort_field is the currect sort field if field == self.sort_field: next_sort = self.toggle_sort_order() + field else: default_order_for_field = \ self._allowed_sort_fields[field]['default_direction'] next_sort = default_order_for_field + field return self.get_sort_string(next_sort)
0, module; 1, function_definition; 2, function_name:get_sort_indicator; 3, parameters; 4, block; 5, identifier:self; 6, identifier:field; 7, expression_statement; 8, expression_statement; 9, if_statement; 10, return_statement; 11, comment:""" Returns a sort class for the active sort only. That is, if field is not sort_field, then nothing will be returned becaues the sort is not active. """; 12, assignment; 13, comparison_operator:field == self.sort_field; 14, block; 15, identifier:indicator; 16, identifier:indicator; 17, string; 18, identifier:field; 19, attribute; 20, expression_statement; 21, if_statement; 22, identifier:self; 23, identifier:sort_field; 24, assignment; 25, comparison_operator:self.sort_order == '-'; 26, block; 27, identifier:indicator; 28, string; 29, attribute; 30, string; 31, expression_statement; 32, string_content:sort-asc; 33, identifier:self; 34, identifier:sort_order; 35, string_content:-; 36, assignment; 37, identifier:indicator; 38, string; 39, string_content:sort-desc
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 7, 11; 8, 12; 9, 13; 9, 14; 10, 15; 12, 16; 12, 17; 13, 18; 13, 19; 14, 20; 14, 21; 19, 22; 19, 23; 20, 24; 21, 25; 21, 26; 24, 27; 24, 28; 25, 29; 25, 30; 26, 31; 28, 32; 29, 33; 29, 34; 30, 35; 31, 36; 36, 37; 36, 38; 38, 39
def get_sort_indicator(self, field): """ Returns a sort class for the active sort only. That is, if field is not sort_field, then nothing will be returned becaues the sort is not active. """ indicator = '' if field == self.sort_field: indicator = 'sort-asc' if self.sort_order == '-': indicator = 'sort-desc' return indicator
0, module; 1, function_definition; 2, function_name:get_basic_sort_link; 3, parameters; 4, block; 5, identifier:self; 6, identifier:request; 7, identifier:field; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, if_statement; 12, return_statement; 13, comment:""" Thanks to del_query_parameters and get_querystring, we build the link with preserving interesting get parameters and removing the others """; 14, assignment; 15, assignment; 16, identifier:sort_string; 17, block; 18, else_clause; 19, identifier:sort_link; 20, identifier:query_string; 21, call; 22, identifier:sort_string; 23, call; 24, expression_statement; 25, if_statement; 26, block; 27, attribute; 28, argument_list; 29, attribute; 30, argument_list; 31, assignment; 32, identifier:query_string; 33, block; 34, expression_statement; 35, if_statement; 36, identifier:self; 37, identifier:get_querystring; 38, identifier:self; 39, identifier:get_next_sort_string; 40, identifier:field; 41, identifier:sort_link; 42, binary_operator:request.path + '?' + sort_string; 43, expression_statement; 44, assignment; 45, identifier:query_string; 46, block; 47, binary_operator:request.path + '?'; 48, identifier:sort_string; 49, augmented_assignment; 50, identifier:sort_link; 51, attribute; 52, expression_statement; 53, attribute; 54, string; 55, identifier:sort_link; 56, binary_operator:'&' + query_string; 57, identifier:request; 58, identifier:path; 59, augmented_assignment; 60, identifier:request; 61, identifier:path; 62, string_content:?; 63, string; 64, identifier:query_string; 65, identifier:sort_link; 66, binary_operator:'?' + query_string; 67, string_content:&; 68, string; 69, identifier:query_string; 70, 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; 8, 13; 9, 14; 10, 15; 11, 16; 11, 17; 11, 18; 12, 19; 14, 20; 14, 21; 15, 22; 15, 23; 17, 24; 17, 25; 18, 26; 21, 27; 21, 28; 23, 29; 23, 30; 24, 31; 25, 32; 25, 33; 26, 34; 26, 35; 27, 36; 27, 37; 29, 38; 29, 39; 30, 40; 31, 41; 31, 42; 33, 43; 34, 44; 35, 45; 35, 46; 42, 47; 42, 48; 43, 49; 44, 50; 44, 51; 46, 52; 47, 53; 47, 54; 49, 55; 49, 56; 51, 57; 51, 58; 52, 59; 53, 60; 53, 61; 54, 62; 56, 63; 56, 64; 59, 65; 59, 66; 63, 67; 66, 68; 66, 69; 68, 70
def get_basic_sort_link(self, request, field): """ Thanks to del_query_parameters and get_querystring, we build the link with preserving interesting get parameters and removing the others """ query_string = self.get_querystring() sort_string = self.get_next_sort_string(field) if sort_string: sort_link = request.path + '?' + sort_string if query_string: sort_link += '&' + query_string else: sort_link = request.path if query_string: sort_link += '?' + query_string return sort_link
0, module; 1, function_definition; 2, function_name:options; 3, parameters; 4, block; 5, identifier:cls; 6, expression_statement; 7, return_statement; 8, comment:"""Provide a sorted list of options."""; 9, call; 10, identifier:sorted; 11, generator_expression; 12, tuple; 13, for_in_clause; 14, if_clause; 15, identifier:value; 16, identifier:name; 17, tuple_pattern; 18, call; 19, not_operator; 20, identifier:name; 21, identifier:value; 22, attribute; 23, argument_list; 24, call; 25, attribute; 26, identifier:items; 27, attribute; 28, argument_list; 29, identifier:cls; 30, identifier:__dict__; 31, identifier:name; 32, identifier:startswith; 33, string; 34, string_content:__
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; 11, 14; 12, 15; 12, 16; 13, 17; 13, 18; 14, 19; 17, 20; 17, 21; 18, 22; 18, 23; 19, 24; 22, 25; 22, 26; 24, 27; 24, 28; 25, 29; 25, 30; 27, 31; 27, 32; 28, 33; 33, 34
def options(cls): """Provide a sorted list of options.""" return sorted((value, name) for (name, value) in cls.__dict__.items() if not name.startswith('__'))
0, module; 1, function_definition; 2, function_name:combine_dicts; 3, parameters; 4, block; 5, list_splat_pattern; 6, default_parameter; 7, default_parameter; 8, expression_statement; 9, if_statement; 10, comment:# Return combined dict.; 11, return_statement; 12, identifier:dicts; 13, identifier:copy; 14, False; 15, identifier:base; 16, None; 17, comment:""" Combines multiple dicts in one. :param dicts: A sequence of dicts. :type dicts: dict :param copy: If True, it returns a deepcopy of input values. :type copy: bool, optional :param base: Base dict where combine multiple dicts in one. :type base: dict, optional :return: A unique dict. :rtype: dict Example:: >>> sorted(combine_dicts({'a': 3, 'c': 3}, {'a': 1, 'b': 2}).items()) [('a', 1), ('b', 2), ('c', 3)] """; 18, boolean_operator; 19, comment:# Only one input dict.; 20, block; 21, else_clause; 22, conditional_expression:{k: _copy.deepcopy(v) for k, v in cd.items()} if copy else cd; 23, comparison_operator:len(dicts) == 1; 24, comparison_operator:base is None; 25, expression_statement; 26, block; 27, dictionary_comprehension; 28, identifier:copy; 29, identifier:cd; 30, call; 31, integer:1; 32, identifier:base; 33, None; 34, assignment; 35, expression_statement; 36, comment:# Initialize empty dict.; 37, for_statement; 38, pair; 39, for_in_clause; 40, identifier:len; 41, argument_list; 42, identifier:cd; 43, call; 44, assignment; 45, identifier:d; 46, identifier:dicts; 47, comment:# Combine dicts.; 48, block; 49, identifier:k; 50, call; 51, pattern_list; 52, call; 53, identifier:dicts; 54, attribute; 55, argument_list; 56, identifier:cd; 57, conditional_expression:{} if base is None else base; 58, if_statement; 59, attribute; 60, argument_list; 61, identifier:k; 62, identifier:v; 63, attribute; 64, argument_list; 65, subscript; 66, identifier:copy; 67, dictionary; 68, comparison_operator:base is None; 69, identifier:base; 70, identifier:d; 71, comment:# noinspection PyTypeChecker; 72, block; 73, identifier:_copy; 74, identifier:deepcopy; 75, identifier:v; 76, identifier:cd; 77, identifier:items; 78, identifier:dicts; 79, integer:0; 80, identifier:base; 81, None; 82, expression_statement; 83, call; 84, attribute; 85, argument_list; 86, identifier:cd; 87, identifier:update; 88, identifier:d
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 4, 11; 5, 12; 6, 13; 6, 14; 7, 15; 7, 16; 8, 17; 9, 18; 9, 19; 9, 20; 9, 21; 11, 22; 18, 23; 18, 24; 20, 25; 21, 26; 22, 27; 22, 28; 22, 29; 23, 30; 23, 31; 24, 32; 24, 33; 25, 34; 26, 35; 26, 36; 26, 37; 27, 38; 27, 39; 30, 40; 30, 41; 34, 42; 34, 43; 35, 44; 37, 45; 37, 46; 37, 47; 37, 48; 38, 49; 38, 50; 39, 51; 39, 52; 41, 53; 43, 54; 43, 55; 44, 56; 44, 57; 48, 58; 50, 59; 50, 60; 51, 61; 51, 62; 52, 63; 52, 64; 54, 65; 54, 66; 57, 67; 57, 68; 57, 69; 58, 70; 58, 71; 58, 72; 59, 73; 59, 74; 60, 75; 63, 76; 63, 77; 65, 78; 65, 79; 68, 80; 68, 81; 72, 82; 82, 83; 83, 84; 83, 85; 84, 86; 84, 87; 85, 88
def combine_dicts(*dicts, copy=False, base=None): """ Combines multiple dicts in one. :param dicts: A sequence of dicts. :type dicts: dict :param copy: If True, it returns a deepcopy of input values. :type copy: bool, optional :param base: Base dict where combine multiple dicts in one. :type base: dict, optional :return: A unique dict. :rtype: dict Example:: >>> sorted(combine_dicts({'a': 3, 'c': 3}, {'a': 1, 'b': 2}).items()) [('a', 1), ('b', 2), ('c', 3)] """ if len(dicts) == 1 and base is None: # Only one input dict. cd = dicts[0].copy() else: cd = {} if base is None else base # Initialize empty dict. for d in dicts: # Combine dicts. if d: # noinspection PyTypeChecker cd.update(d) # Return combined dict. return {k: _copy.deepcopy(v) for k, v in cd.items()} if copy else cd
0, module; 1, function_definition; 2, function_name:kk_dict; 3, parameters; 4, block; 5, list_splat_pattern; 6, dictionary_splat_pattern; 7, expression_statement; 8, for_statement; 9, return_statement; 10, identifier:kk; 11, identifier:adict; 12, comment:""" Merges and defines dictionaries with values identical to keys. :param kk: A sequence of keys and/or dictionaries. :type kk: object | dict, optional :param adict: A dictionary. :type adict: dict, optional :return: Merged dictionary. :rtype: dict Example:: >>> sorted(kk_dict('a', 'b', 'c').items()) [('a', 'a'), ('b', 'b'), ('c', 'c')] >>> sorted(kk_dict('a', 'b', **{'a-c': 'c'}).items()) [('a', 'a'), ('a-c', 'c'), ('b', 'b')] >>> sorted(kk_dict('a', {'b': 'c'}, 'c').items()) [('a', 'a'), ('b', 'c'), ('c', 'c')] >>> sorted(kk_dict('a', 'b', **{'b': 'c'}).items()) Traceback (most recent call last): ... ValueError: keyword argument repeated >>> sorted(kk_dict('a', {'b': 'd'}, **{'b': 'c'}).items()) Traceback (most recent call last): ... ValueError: keyword argument repeated """; 13, identifier:k; 14, identifier:kk; 15, block; 16, identifier:adict; 17, if_statement; 18, call; 19, block; 20, elif_clause; 21, else_clause; 22, identifier:isinstance; 23, argument_list; 24, if_statement; 25, expression_statement; 26, comparison_operator:k in adict; 27, block; 28, block; 29, identifier:k; 30, identifier:dict; 31, not_operator; 32, block; 33, call; 34, identifier:k; 35, identifier:adict; 36, raise_statement; 37, expression_statement; 38, call; 39, raise_statement; 40, attribute; 41, argument_list; 42, call; 43, assignment; 44, attribute; 45, argument_list; 46, call; 47, identifier:adict; 48, identifier:update; 49, identifier:k; 50, identifier:ValueError; 51, argument_list; 52, subscript; 53, identifier:k; 54, call; 55, identifier:isdisjoint; 56, identifier:adict; 57, identifier:ValueError; 58, argument_list; 59, string; 60, identifier:adict; 61, identifier:k; 62, identifier:set; 63, argument_list; 64, string; 65, string_content:keyword argument repeated; 66, identifier:k; 67, string_content:keyword argument repeated
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 5, 10; 6, 11; 7, 12; 8, 13; 8, 14; 8, 15; 9, 16; 15, 17; 17, 18; 17, 19; 17, 20; 17, 21; 18, 22; 18, 23; 19, 24; 19, 25; 20, 26; 20, 27; 21, 28; 23, 29; 23, 30; 24, 31; 24, 32; 25, 33; 26, 34; 26, 35; 27, 36; 28, 37; 31, 38; 32, 39; 33, 40; 33, 41; 36, 42; 37, 43; 38, 44; 38, 45; 39, 46; 40, 47; 40, 48; 41, 49; 42, 50; 42, 51; 43, 52; 43, 53; 44, 54; 44, 55; 45, 56; 46, 57; 46, 58; 51, 59; 52, 60; 52, 61; 54, 62; 54, 63; 58, 64; 59, 65; 63, 66; 64, 67
def kk_dict(*kk, **adict): """ Merges and defines dictionaries with values identical to keys. :param kk: A sequence of keys and/or dictionaries. :type kk: object | dict, optional :param adict: A dictionary. :type adict: dict, optional :return: Merged dictionary. :rtype: dict Example:: >>> sorted(kk_dict('a', 'b', 'c').items()) [('a', 'a'), ('b', 'b'), ('c', 'c')] >>> sorted(kk_dict('a', 'b', **{'a-c': 'c'}).items()) [('a', 'a'), ('a-c', 'c'), ('b', 'b')] >>> sorted(kk_dict('a', {'b': 'c'}, 'c').items()) [('a', 'a'), ('b', 'c'), ('c', 'c')] >>> sorted(kk_dict('a', 'b', **{'b': 'c'}).items()) Traceback (most recent call last): ... ValueError: keyword argument repeated >>> sorted(kk_dict('a', {'b': 'd'}, **{'b': 'c'}).items()) Traceback (most recent call last): ... ValueError: keyword argument repeated """ for k in kk: if isinstance(k, dict): if not set(k).isdisjoint(adict): raise ValueError('keyword argument repeated') adict.update(k) elif k in adict: raise ValueError('keyword argument repeated') else: adict[k] = k return adict
0, module; 1, function_definition; 2, function_name:map_dict; 3, parameters; 4, block; 5, identifier:key_map; 6, list_splat_pattern; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, expression_statement; 11, comment:# Combine dicts.; 12, expression_statement; 13, comment:# Namespace shortcut.; 14, comment:# Return mapped dict.; 15, return_statement; 16, identifier:dicts; 17, identifier:copy; 18, False; 19, identifier:base; 20, None; 21, comment:""" Returns a dict with new key values. :param key_map: A dictionary that maps the dict keys ({old key: new key} :type key_map: dict :param dicts: A sequence of dicts. :type dicts: dict :param copy: If True, it returns a deepcopy of input values. :type copy: bool, optional :param base: Base dict where combine multiple dicts in one. :type base: dict, optional :return: A unique dict with new key values. :rtype: dict Example:: >>> d = map_dict({'a': 'c', 'b': 'd'}, {'a': 1, 'b': 1}, {'b': 2}) >>> sorted(d.items()) [('c', 1), ('d', 2)] """; 22, assignment; 23, assignment; 24, call; 25, identifier:it; 26, call; 27, identifier:get; 28, attribute; 29, identifier:combine_dicts; 30, argument_list; 31, attribute; 32, argument_list; 33, identifier:key_map; 34, identifier:get; 35, dictionary_comprehension; 36, keyword_argument; 37, keyword_argument; 38, call; 39, identifier:items; 40, pair; 41, for_in_clause; 42, identifier:copy; 43, identifier:copy; 44, identifier:base; 45, identifier:base; 46, identifier:combine_dicts; 47, argument_list; 48, call; 49, identifier:v; 50, pattern_list; 51, identifier:it; 52, list_splat; 53, identifier:get; 54, argument_list; 55, identifier:k; 56, identifier:v; 57, identifier:dicts; 58, identifier:k; 59, identifier:k
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; 6, 16; 7, 17; 7, 18; 8, 19; 8, 20; 9, 21; 10, 22; 12, 23; 15, 24; 22, 25; 22, 26; 23, 27; 23, 28; 24, 29; 24, 30; 26, 31; 26, 32; 28, 33; 28, 34; 30, 35; 30, 36; 30, 37; 31, 38; 31, 39; 35, 40; 35, 41; 36, 42; 36, 43; 37, 44; 37, 45; 38, 46; 38, 47; 40, 48; 40, 49; 41, 50; 41, 51; 47, 52; 48, 53; 48, 54; 50, 55; 50, 56; 52, 57; 54, 58; 54, 59
def map_dict(key_map, *dicts, copy=False, base=None): """ Returns a dict with new key values. :param key_map: A dictionary that maps the dict keys ({old key: new key} :type key_map: dict :param dicts: A sequence of dicts. :type dicts: dict :param copy: If True, it returns a deepcopy of input values. :type copy: bool, optional :param base: Base dict where combine multiple dicts in one. :type base: dict, optional :return: A unique dict with new key values. :rtype: dict Example:: >>> d = map_dict({'a': 'c', 'b': 'd'}, {'a': 1, 'b': 1}, {'b': 2}) >>> sorted(d.items()) [('c', 1), ('d', 2)] """ it = combine_dicts(*dicts).items() # Combine dicts. get = key_map.get # Namespace shortcut. # Return mapped dict. return combine_dicts({get(k, k): v for k, v in it}, copy=copy, base=base)
0, module; 1, function_definition; 2, function_name:map_list; 3, parameters; 4, block; 5, identifier:key_map; 6, list_splat_pattern; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, expression_statement; 11, comment:# Initialize empty dict.; 12, for_statement; 13, return_statement; 14, identifier:inputs; 15, identifier:copy; 16, False; 17, identifier:base; 18, None; 19, comment:""" Returns a new dict. :param key_map: A list that maps the dict keys ({old key: new key} :type key_map: list[str | dict | list] :param inputs: A sequence of data. :type inputs: iterable | dict | int | float | list | tuple :param copy: If True, it returns a deepcopy of input values. :type copy: bool, optional :param base: Base dict where combine multiple dicts in one. :type base: dict, optional :return: A unique dict with new values. :rtype: dict Example:: >>> key_map = [ ... 'a', ... {'a': 'c'}, ... [ ... 'a', ... {'a': 'd'} ... ] ... ] >>> inputs = ( ... 2, ... {'a': 3, 'b': 2}, ... [ ... 1, ... {'a': 4} ... ] ... ) >>> d = map_list(key_map, *inputs) >>> sorted(d.items()) [('a', 1), ('b', 2), ('c', 3), ('d', 4)] """; 20, assignment; 21, pattern_list; 22, call; 23, block; 24, call; 25, identifier:d; 26, conditional_expression:{} if base is None else base; 27, identifier:m; 28, identifier:v; 29, identifier:zip; 30, argument_list; 31, if_statement; 32, identifier:combine_dicts; 33, argument_list; 34, dictionary; 35, comparison_operator:base is None; 36, identifier:base; 37, identifier:key_map; 38, identifier:inputs; 39, call; 40, block; 41, elif_clause; 42, else_clause; 43, keyword_argument; 44, keyword_argument; 45, identifier:base; 46, None; 47, identifier:isinstance; 48, argument_list; 49, expression_statement; 50, comment:# Apply a map dict.; 51, call; 52, block; 53, block; 54, identifier:copy; 55, identifier:copy; 56, identifier:base; 57, identifier:d; 58, identifier:m; 59, identifier:dict; 60, call; 61, identifier:isinstance; 62, argument_list; 63, expression_statement; 64, comment:# Apply a map list.; 65, expression_statement; 66, comment:# Apply map.; 67, identifier:map_dict; 68, argument_list; 69, identifier:m; 70, identifier:list; 71, call; 72, assignment; 73, identifier:m; 74, identifier:v; 75, keyword_argument; 76, identifier:map_list; 77, argument_list; 78, subscript; 79, identifier:v; 80, identifier:base; 81, identifier:d; 82, identifier:m; 83, list_splat; 84, keyword_argument; 85, identifier:d; 86, identifier:m; 87, identifier:v; 88, identifier:base; 89, identifier:d
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; 6, 14; 7, 15; 7, 16; 8, 17; 8, 18; 9, 19; 10, 20; 12, 21; 12, 22; 12, 23; 13, 24; 20, 25; 20, 26; 21, 27; 21, 28; 22, 29; 22, 30; 23, 31; 24, 32; 24, 33; 26, 34; 26, 35; 26, 36; 30, 37; 30, 38; 31, 39; 31, 40; 31, 41; 31, 42; 33, 43; 33, 44; 35, 45; 35, 46; 39, 47; 39, 48; 40, 49; 40, 50; 41, 51; 41, 52; 42, 53; 43, 54; 43, 55; 44, 56; 44, 57; 48, 58; 48, 59; 49, 60; 51, 61; 51, 62; 52, 63; 52, 64; 53, 65; 53, 66; 60, 67; 60, 68; 62, 69; 62, 70; 63, 71; 65, 72; 68, 73; 68, 74; 68, 75; 71, 76; 71, 77; 72, 78; 72, 79; 75, 80; 75, 81; 77, 82; 77, 83; 77, 84; 78, 85; 78, 86; 83, 87; 84, 88; 84, 89
def map_list(key_map, *inputs, copy=False, base=None): """ Returns a new dict. :param key_map: A list that maps the dict keys ({old key: new key} :type key_map: list[str | dict | list] :param inputs: A sequence of data. :type inputs: iterable | dict | int | float | list | tuple :param copy: If True, it returns a deepcopy of input values. :type copy: bool, optional :param base: Base dict where combine multiple dicts in one. :type base: dict, optional :return: A unique dict with new values. :rtype: dict Example:: >>> key_map = [ ... 'a', ... {'a': 'c'}, ... [ ... 'a', ... {'a': 'd'} ... ] ... ] >>> inputs = ( ... 2, ... {'a': 3, 'b': 2}, ... [ ... 1, ... {'a': 4} ... ] ... ) >>> d = map_list(key_map, *inputs) >>> sorted(d.items()) [('a', 1), ('b', 2), ('c', 3), ('d', 4)] """ d = {} if base is None else base # Initialize empty dict. for m, v in zip(key_map, inputs): if isinstance(m, dict): map_dict(m, v, base=d) # Apply a map dict. elif isinstance(m, list): map_list(m, *v, base=d) # Apply a map list. else: d[m] = v # Apply map. return combine_dicts(copy=copy, base=d)
0, module; 1, function_definition; 2, function_name:selector; 3, parameters; 4, block; 5, identifier:keys; 6, identifier:dictionary; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, expression_statement; 11, if_statement; 12, if_statement; 13, comment:# Select as dict.; 14, return_statement; 15, identifier:copy; 16, False; 17, identifier:output_type; 18, string; 19, identifier:allow_miss; 20, False; 21, comment:""" Selects the chosen dictionary keys from the given dictionary. :param keys: Keys to select. :type keys: list, tuple, set :param dictionary: A dictionary. :type dictionary: dict :param copy: If True the output contains deep-copies of the values. :type copy: bool :param output_type: Type of function output: + 'list': a list with all values listed in `keys`. + 'dict': a dictionary with any outputs listed in `keys`. + 'values': if output length == 1 return a single value otherwise a tuple with all values listed in `keys`. :type output_type: str, optional :param allow_miss: If True it does not raise when some key is missing in the dictionary. :type allow_miss: bool :return: A dictionary with chosen dictionary keys if present in the sequence of dictionaries. These are combined with :func:`combine_dicts`. :rtype: dict Example:: >>> from functools import partial >>> fun = partial(selector, ['a', 'b']) >>> sorted(fun({'a': 1, 'b': 2, 'c': 3}).items()) [('a', 1), ('b', 2)] """; 22, not_operator; 23, comment:# noinspection PyUnusedLocal; 24, block; 25, else_clause; 26, comparison_operator:output_type == 'list'; 27, comment:# Select as list.; 28, block; 29, elif_clause; 30, call; 31, string_content:dict; 32, identifier:allow_miss; 33, function_definition; 34, block; 35, identifier:output_type; 36, string; 37, expression_statement; 38, return_statement; 39, comparison_operator:output_type == 'values'; 40, block; 41, identifier:bypass; 42, argument_list; 43, function_name:check; 44, parameters; 45, block; 46, function_definition; 47, string_content:list; 48, assignment; 49, conditional_expression:_copy.deepcopy(res) if copy else res; 50, identifier:output_type; 51, string; 52, return_statement; 53, dictionary_comprehension; 54, keyword_argument; 55, identifier:key; 56, return_statement; 57, function_name:check; 58, parameters; 59, block; 60, identifier:res; 61, list_comprehension; 62, call; 63, identifier:copy; 64, identifier:res; 65, string_content:values; 66, call; 67, pair; 68, for_in_clause; 69, if_clause; 70, identifier:copy; 71, identifier:copy; 72, True; 73, identifier:key; 74, return_statement; 75, subscript; 76, for_in_clause; 77, if_clause; 78, attribute; 79, argument_list; 80, identifier:bypass; 81, argument_list; 82, identifier:k; 83, subscript; 84, identifier:k; 85, identifier:keys; 86, call; 87, comparison_operator:key in dictionary; 88, identifier:dictionary; 89, identifier:k; 90, identifier:k; 91, identifier:keys; 92, call; 93, identifier:_copy; 94, identifier:deepcopy; 95, identifier:res; 96, list_splat; 97, keyword_argument; 98, identifier:dictionary; 99, identifier:k; 100, identifier:check; 101, argument_list; 102, identifier:key; 103, identifier:dictionary; 104, identifier:check; 105, argument_list; 106, list_comprehension; 107, identifier:copy; 108, identifier:copy; 109, identifier:k; 110, identifier:k; 111, subscript; 112, for_in_clause; 113, if_clause; 114, identifier:dictionary; 115, identifier:k; 116, identifier:k; 117, identifier:keys; 118, call; 119, identifier:check; 120, argument_list; 121, identifier:k
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; 7, 15; 7, 16; 8, 17; 8, 18; 9, 19; 9, 20; 10, 21; 11, 22; 11, 23; 11, 24; 11, 25; 12, 26; 12, 27; 12, 28; 12, 29; 14, 30; 18, 31; 22, 32; 24, 33; 25, 34; 26, 35; 26, 36; 28, 37; 28, 38; 29, 39; 29, 40; 30, 41; 30, 42; 33, 43; 33, 44; 33, 45; 34, 46; 36, 47; 37, 48; 38, 49; 39, 50; 39, 51; 40, 52; 42, 53; 42, 54; 44, 55; 45, 56; 46, 57; 46, 58; 46, 59; 48, 60; 48, 61; 49, 62; 49, 63; 49, 64; 51, 65; 52, 66; 53, 67; 53, 68; 53, 69; 54, 70; 54, 71; 56, 72; 58, 73; 59, 74; 61, 75; 61, 76; 61, 77; 62, 78; 62, 79; 66, 80; 66, 81; 67, 82; 67, 83; 68, 84; 68, 85; 69, 86; 74, 87; 75, 88; 75, 89; 76, 90; 76, 91; 77, 92; 78, 93; 78, 94; 79, 95; 81, 96; 81, 97; 83, 98; 83, 99; 86, 100; 86, 101; 87, 102; 87, 103; 92, 104; 92, 105; 96, 106; 97, 107; 97, 108; 101, 109; 105, 110; 106, 111; 106, 112; 106, 113; 111, 114; 111, 115; 112, 116; 112, 117; 113, 118; 118, 119; 118, 120; 120, 121
def selector(keys, dictionary, copy=False, output_type='dict', allow_miss=False): """ Selects the chosen dictionary keys from the given dictionary. :param keys: Keys to select. :type keys: list, tuple, set :param dictionary: A dictionary. :type dictionary: dict :param copy: If True the output contains deep-copies of the values. :type copy: bool :param output_type: Type of function output: + 'list': a list with all values listed in `keys`. + 'dict': a dictionary with any outputs listed in `keys`. + 'values': if output length == 1 return a single value otherwise a tuple with all values listed in `keys`. :type output_type: str, optional :param allow_miss: If True it does not raise when some key is missing in the dictionary. :type allow_miss: bool :return: A dictionary with chosen dictionary keys if present in the sequence of dictionaries. These are combined with :func:`combine_dicts`. :rtype: dict Example:: >>> from functools import partial >>> fun = partial(selector, ['a', 'b']) >>> sorted(fun({'a': 1, 'b': 2, 'c': 3}).items()) [('a', 1), ('b', 2)] """ if not allow_miss: # noinspection PyUnusedLocal def check(key): return True else: def check(key): return key in dictionary if output_type == 'list': # Select as list. res = [dictionary[k] for k in keys if check(k)] return _copy.deepcopy(res) if copy else res elif output_type == 'values': return bypass(*[dictionary[k] for k in keys if check(k)], copy=copy) # Select as dict. return bypass({k: dictionary[k] for k in keys if check(k)}, copy=copy)
0, module; 1, function_definition; 2, function_name:difference; 3, parameters; 4, block; 5, identifier:self; 6, list_splat_pattern; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, for_statement; 12, expression_statement; 13, return_statement; 14, identifier:others; 15, comment:r"""Return a new multiset with all elements from the others removed. >>> ms = Multiset('aab') >>> sorted(ms.difference('bc')) ['a', 'a'] You can also use the ``-`` operator for the same effect. However, the operator version will only accept a set as other operator, not any iterable, to avoid errors. >>> ms = Multiset('aabbbc') >>> sorted(ms - Multiset('abd')) ['a', 'b', 'b', 'c'] For a variant of the operation which modifies the multiset in place see :meth:`difference_update`. Args: others: The other sets to remove from the multiset. Can also be any :class:`~typing.Iterable`\[~T] or :class:`~typing.Mapping`\[~T, :class:`int`] which are then converted to :class:`Multiset`\[~T]. Returns: The resulting difference multiset. """; 16, assignment; 17, assignment; 18, assignment; 19, identifier:other; 20, call; 21, block; 22, assignment; 23, identifier:result; 24, identifier:result; 25, call; 26, identifier:_elements; 27, attribute; 28, identifier:_total; 29, attribute; 30, identifier:map; 31, argument_list; 32, for_statement; 33, attribute; 34, identifier:_total; 35, attribute; 36, argument_list; 37, identifier:result; 38, identifier:_elements; 39, identifier:result; 40, identifier:_total; 41, attribute; 42, identifier:others; 43, pattern_list; 44, call; 45, block; 46, identifier:result; 47, identifier:_total; 48, identifier:self; 49, identifier:__copy__; 50, identifier:self; 51, identifier:_as_multiset; 52, identifier:element; 53, identifier:multiplicity; 54, attribute; 55, argument_list; 56, if_statement; 57, identifier:other; 58, identifier:items; 59, comparison_operator:element in _elements; 60, block; 61, identifier:element; 62, identifier:_elements; 63, expression_statement; 64, expression_statement; 65, if_statement; 66, assignment; 67, assignment; 68, comparison_operator:new_multiplicity > 0; 69, block; 70, else_clause; 71, identifier:old_multiplicity; 72, subscript; 73, identifier:new_multiplicity; 74, binary_operator:old_multiplicity - multiplicity; 75, identifier:new_multiplicity; 76, integer:0; 77, expression_statement; 78, expression_statement; 79, block; 80, identifier:_elements; 81, identifier:element; 82, identifier:old_multiplicity; 83, identifier:multiplicity; 84, assignment; 85, augmented_assignment; 86, delete_statement; 87, expression_statement; 88, subscript; 89, identifier:new_multiplicity; 90, identifier:_total; 91, identifier:multiplicity; 92, subscript; 93, augmented_assignment; 94, identifier:_elements; 95, identifier:element; 96, identifier:_elements; 97, identifier:element; 98, identifier:_total; 99, identifier:old_multiplicity
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; 7, 15; 8, 16; 9, 17; 10, 18; 11, 19; 11, 20; 11, 21; 12, 22; 13, 23; 16, 24; 16, 25; 17, 26; 17, 27; 18, 28; 18, 29; 20, 30; 20, 31; 21, 32; 22, 33; 22, 34; 25, 35; 25, 36; 27, 37; 27, 38; 29, 39; 29, 40; 31, 41; 31, 42; 32, 43; 32, 44; 32, 45; 33, 46; 33, 47; 35, 48; 35, 49; 41, 50; 41, 51; 43, 52; 43, 53; 44, 54; 44, 55; 45, 56; 54, 57; 54, 58; 56, 59; 56, 60; 59, 61; 59, 62; 60, 63; 60, 64; 60, 65; 63, 66; 64, 67; 65, 68; 65, 69; 65, 70; 66, 71; 66, 72; 67, 73; 67, 74; 68, 75; 68, 76; 69, 77; 69, 78; 70, 79; 72, 80; 72, 81; 74, 82; 74, 83; 77, 84; 78, 85; 79, 86; 79, 87; 84, 88; 84, 89; 85, 90; 85, 91; 86, 92; 87, 93; 88, 94; 88, 95; 92, 96; 92, 97; 93, 98; 93, 99
def difference(self, *others): r"""Return a new multiset with all elements from the others removed. >>> ms = Multiset('aab') >>> sorted(ms.difference('bc')) ['a', 'a'] You can also use the ``-`` operator for the same effect. However, the operator version will only accept a set as other operator, not any iterable, to avoid errors. >>> ms = Multiset('aabbbc') >>> sorted(ms - Multiset('abd')) ['a', 'b', 'b', 'c'] For a variant of the operation which modifies the multiset in place see :meth:`difference_update`. Args: others: The other sets to remove from the multiset. Can also be any :class:`~typing.Iterable`\[~T] or :class:`~typing.Mapping`\[~T, :class:`int`] which are then converted to :class:`Multiset`\[~T]. Returns: The resulting difference multiset. """ result = self.__copy__() _elements = result._elements _total = result._total for other in map(self._as_multiset, others): for element, multiplicity in other.items(): if element in _elements: old_multiplicity = _elements[element] new_multiplicity = old_multiplicity - multiplicity if new_multiplicity > 0: _elements[element] = new_multiplicity _total -= multiplicity else: del _elements[element] _total -= old_multiplicity result._total = _total return result
0, module; 1, function_definition; 2, function_name:union; 3, parameters; 4, block; 5, identifier:self; 6, list_splat_pattern; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, for_statement; 12, expression_statement; 13, return_statement; 14, identifier:others; 15, comment:r"""Return a new multiset with all elements from the multiset and the others with maximal multiplicities. >>> ms = Multiset('aab') >>> sorted(ms.union('bc')) ['a', 'a', 'b', 'c'] You can also use the ``|`` operator for the same effect. However, the operator version will only accept a set as other operator, not any iterable, to avoid errors. >>> ms = Multiset('aab') >>> sorted(ms | Multiset('aaa')) ['a', 'a', 'a', 'b'] For a variant of the operation which modifies the multiset in place see :meth:`union_update`. Args: *others: The other sets to union the multiset with. Can also be any :class:`~typing.Iterable`\[~T] or :class:`~typing.Mapping`\[~T, :class:`int`] which are then converted to :class:`Multiset`\[~T]. Returns: The multiset resulting from the union. """; 16, assignment; 17, assignment; 18, assignment; 19, identifier:other; 20, call; 21, block; 22, assignment; 23, identifier:result; 24, identifier:result; 25, call; 26, identifier:_elements; 27, attribute; 28, identifier:_total; 29, attribute; 30, identifier:map; 31, argument_list; 32, for_statement; 33, attribute; 34, identifier:_total; 35, attribute; 36, argument_list; 37, identifier:result; 38, identifier:_elements; 39, identifier:result; 40, identifier:_total; 41, attribute; 42, identifier:others; 43, pattern_list; 44, call; 45, block; 46, identifier:result; 47, identifier:_total; 48, identifier:self; 49, identifier:__copy__; 50, identifier:self; 51, identifier:_as_mapping; 52, identifier:element; 53, identifier:multiplicity; 54, attribute; 55, argument_list; 56, expression_statement; 57, if_statement; 58, identifier:other; 59, identifier:items; 60, assignment; 61, comparison_operator:multiplicity > old_multiplicity; 62, block; 63, identifier:old_multiplicity; 64, call; 65, identifier:multiplicity; 66, identifier:old_multiplicity; 67, expression_statement; 68, expression_statement; 69, attribute; 70, argument_list; 71, assignment; 72, augmented_assignment; 73, identifier:_elements; 74, identifier:get; 75, identifier:element; 76, integer:0; 77, subscript; 78, identifier:multiplicity; 79, identifier:_total; 80, binary_operator:multiplicity - old_multiplicity; 81, identifier:_elements; 82, identifier:element; 83, identifier:multiplicity; 84, identifier:old_multiplicity
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; 7, 15; 8, 16; 9, 17; 10, 18; 11, 19; 11, 20; 11, 21; 12, 22; 13, 23; 16, 24; 16, 25; 17, 26; 17, 27; 18, 28; 18, 29; 20, 30; 20, 31; 21, 32; 22, 33; 22, 34; 25, 35; 25, 36; 27, 37; 27, 38; 29, 39; 29, 40; 31, 41; 31, 42; 32, 43; 32, 44; 32, 45; 33, 46; 33, 47; 35, 48; 35, 49; 41, 50; 41, 51; 43, 52; 43, 53; 44, 54; 44, 55; 45, 56; 45, 57; 54, 58; 54, 59; 56, 60; 57, 61; 57, 62; 60, 63; 60, 64; 61, 65; 61, 66; 62, 67; 62, 68; 64, 69; 64, 70; 67, 71; 68, 72; 69, 73; 69, 74; 70, 75; 70, 76; 71, 77; 71, 78; 72, 79; 72, 80; 77, 81; 77, 82; 80, 83; 80, 84
def union(self, *others): r"""Return a new multiset with all elements from the multiset and the others with maximal multiplicities. >>> ms = Multiset('aab') >>> sorted(ms.union('bc')) ['a', 'a', 'b', 'c'] You can also use the ``|`` operator for the same effect. However, the operator version will only accept a set as other operator, not any iterable, to avoid errors. >>> ms = Multiset('aab') >>> sorted(ms | Multiset('aaa')) ['a', 'a', 'a', 'b'] For a variant of the operation which modifies the multiset in place see :meth:`union_update`. Args: *others: The other sets to union the multiset with. Can also be any :class:`~typing.Iterable`\[~T] or :class:`~typing.Mapping`\[~T, :class:`int`] which are then converted to :class:`Multiset`\[~T]. Returns: The multiset resulting from the union. """ result = self.__copy__() _elements = result._elements _total = result._total for other in map(self._as_mapping, others): for element, multiplicity in other.items(): old_multiplicity = _elements.get(element, 0) if multiplicity > old_multiplicity: _elements[element] = multiplicity _total += multiplicity - old_multiplicity result._total = _total return result
0, module; 1, function_definition; 2, function_name:intersection; 3, parameters; 4, block; 5, identifier:self; 6, list_splat_pattern; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, for_statement; 12, expression_statement; 13, return_statement; 14, identifier:others; 15, comment:r"""Return a new multiset with elements common to the multiset and all others. >>> ms = Multiset('aab') >>> sorted(ms.intersection('abc')) ['a', 'b'] You can also use the ``&`` operator for the same effect. However, the operator version will only accept a set as other operator, not any iterable, to avoid errors. >>> ms = Multiset('aab') >>> sorted(ms & Multiset('aaac')) ['a', 'a'] For a variant of the operation which modifies the multiset in place see :meth:`intersection_update`. Args: others: The other sets intersect with the multiset. Can also be any :class:`~typing.Iterable`\[~T] or :class:`~typing.Mapping`\[~T, :class:`int`] which are then converted to :class:`Multiset`\[~T]. Returns: The multiset resulting from the intersection of the sets. """; 16, assignment; 17, assignment; 18, assignment; 19, identifier:other; 20, call; 21, block; 22, assignment; 23, identifier:result; 24, identifier:result; 25, call; 26, identifier:_elements; 27, attribute; 28, identifier:_total; 29, attribute; 30, identifier:map; 31, argument_list; 32, for_statement; 33, attribute; 34, identifier:_total; 35, attribute; 36, argument_list; 37, identifier:result; 38, identifier:_elements; 39, identifier:result; 40, identifier:_total; 41, attribute; 42, identifier:others; 43, pattern_list; 44, call; 45, block; 46, identifier:result; 47, identifier:_total; 48, identifier:self; 49, identifier:__copy__; 50, identifier:self; 51, identifier:_as_mapping; 52, identifier:element; 53, identifier:multiplicity; 54, identifier:list; 55, argument_list; 56, expression_statement; 57, if_statement; 58, call; 59, assignment; 60, comparison_operator:new_multiplicity < multiplicity; 61, block; 62, attribute; 63, argument_list; 64, identifier:new_multiplicity; 65, call; 66, identifier:new_multiplicity; 67, identifier:multiplicity; 68, if_statement; 69, identifier:_elements; 70, identifier:items; 71, attribute; 72, argument_list; 73, comparison_operator:new_multiplicity > 0; 74, block; 75, else_clause; 76, identifier:other; 77, identifier:get; 78, identifier:element; 79, integer:0; 80, identifier:new_multiplicity; 81, integer:0; 82, expression_statement; 83, expression_statement; 84, block; 85, assignment; 86, augmented_assignment; 87, delete_statement; 88, expression_statement; 89, subscript; 90, identifier:new_multiplicity; 91, identifier:_total; 92, binary_operator:multiplicity - new_multiplicity; 93, subscript; 94, augmented_assignment; 95, identifier:_elements; 96, identifier:element; 97, identifier:multiplicity; 98, identifier:new_multiplicity; 99, identifier:_elements; 100, identifier:element; 101, identifier:_total; 102, identifier:multiplicity
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; 7, 15; 8, 16; 9, 17; 10, 18; 11, 19; 11, 20; 11, 21; 12, 22; 13, 23; 16, 24; 16, 25; 17, 26; 17, 27; 18, 28; 18, 29; 20, 30; 20, 31; 21, 32; 22, 33; 22, 34; 25, 35; 25, 36; 27, 37; 27, 38; 29, 39; 29, 40; 31, 41; 31, 42; 32, 43; 32, 44; 32, 45; 33, 46; 33, 47; 35, 48; 35, 49; 41, 50; 41, 51; 43, 52; 43, 53; 44, 54; 44, 55; 45, 56; 45, 57; 55, 58; 56, 59; 57, 60; 57, 61; 58, 62; 58, 63; 59, 64; 59, 65; 60, 66; 60, 67; 61, 68; 62, 69; 62, 70; 65, 71; 65, 72; 68, 73; 68, 74; 68, 75; 71, 76; 71, 77; 72, 78; 72, 79; 73, 80; 73, 81; 74, 82; 74, 83; 75, 84; 82, 85; 83, 86; 84, 87; 84, 88; 85, 89; 85, 90; 86, 91; 86, 92; 87, 93; 88, 94; 89, 95; 89, 96; 92, 97; 92, 98; 93, 99; 93, 100; 94, 101; 94, 102
def intersection(self, *others): r"""Return a new multiset with elements common to the multiset and all others. >>> ms = Multiset('aab') >>> sorted(ms.intersection('abc')) ['a', 'b'] You can also use the ``&`` operator for the same effect. However, the operator version will only accept a set as other operator, not any iterable, to avoid errors. >>> ms = Multiset('aab') >>> sorted(ms & Multiset('aaac')) ['a', 'a'] For a variant of the operation which modifies the multiset in place see :meth:`intersection_update`. Args: others: The other sets intersect with the multiset. Can also be any :class:`~typing.Iterable`\[~T] or :class:`~typing.Mapping`\[~T, :class:`int`] which are then converted to :class:`Multiset`\[~T]. Returns: The multiset resulting from the intersection of the sets. """ result = self.__copy__() _elements = result._elements _total = result._total for other in map(self._as_mapping, others): for element, multiplicity in list(_elements.items()): new_multiplicity = other.get(element, 0) if new_multiplicity < multiplicity: if new_multiplicity > 0: _elements[element] = new_multiplicity _total -= multiplicity - new_multiplicity else: del _elements[element] _total -= multiplicity result._total = _total return result
0, module; 1, function_definition; 2, function_name:symmetric_difference; 3, parameters; 4, block; 5, identifier:self; 6, identifier:other; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, expression_statement; 14, expression_statement; 15, for_statement; 16, expression_statement; 17, return_statement; 18, comment:r"""Return a new set with elements in either the set or other but not both. >>> ms = Multiset('aab') >>> sorted(ms.symmetric_difference('abc')) ['a', 'c'] You can also use the ``^`` operator for the same effect. However, the operator version will only accept a set as other operator, not any iterable, to avoid errors. >>> ms = Multiset('aab') >>> sorted(ms ^ Multiset('aaac')) ['a', 'b', 'c'] For a variant of the operation which modifies the multiset in place see :meth:`symmetric_difference_update`. Args: other: The other set to take the symmetric difference with. Can also be any :class:`~typing.Iterable`\[~T] or :class:`~typing.Mapping`\[~T, :class:`int`] which are then converted to :class:`Multiset`\[~T]. Returns: The resulting symmetric difference multiset. """; 19, assignment; 20, assignment; 21, assignment; 22, assignment; 23, assignment; 24, assignment; 25, assignment; 26, identifier:element; 27, identifier:dist_elements; 28, block; 29, assignment; 30, identifier:result; 31, identifier:other; 32, call; 33, identifier:result; 34, call; 35, identifier:_total; 36, integer:0; 37, identifier:_elements; 38, attribute; 39, identifier:self_elements; 40, attribute; 41, identifier:other_elements; 42, attribute; 43, identifier:dist_elements; 44, binary_operator:set(self_elements.keys()) | set(other_elements.keys()); 45, expression_statement; 46, expression_statement; 47, expression_statement; 48, expression_statement; 49, if_statement; 50, attribute; 51, identifier:_total; 52, attribute; 53, argument_list; 54, attribute; 55, argument_list; 56, identifier:result; 57, identifier:_elements; 58, identifier:self; 59, identifier:_elements; 60, identifier:other; 61, identifier:_elements; 62, call; 63, call; 64, assignment; 65, assignment; 66, assignment; 67, augmented_assignment; 68, comparison_operator:new_multiplicity > 0; 69, block; 70, identifier:result; 71, identifier:_total; 72, identifier:self; 73, identifier:_as_multiset; 74, identifier:other; 75, identifier:self; 76, identifier:__class__; 77, identifier:set; 78, argument_list; 79, identifier:set; 80, argument_list; 81, identifier:multiplicity; 82, call; 83, identifier:other_multiplicity; 84, call; 85, identifier:new_multiplicity; 86, parenthesized_expression; 87, identifier:_total; 88, identifier:new_multiplicity; 89, identifier:new_multiplicity; 90, integer:0; 91, expression_statement; 92, call; 93, call; 94, attribute; 95, argument_list; 96, attribute; 97, argument_list; 98, conditional_expression:multiplicity - other_multiplicity if multiplicity > other_multiplicity else other_multiplicity - multiplicity; 99, assignment; 100, attribute; 101, argument_list; 102, attribute; 103, argument_list; 104, identifier:self_elements; 105, identifier:get; 106, identifier:element; 107, integer:0; 108, identifier:other_elements; 109, identifier:get; 110, identifier:element; 111, integer:0; 112, binary_operator:multiplicity - other_multiplicity; 113, comparison_operator:multiplicity > other_multiplicity; 114, binary_operator:other_multiplicity - multiplicity; 115, subscript; 116, identifier:new_multiplicity; 117, identifier:self_elements; 118, identifier:keys; 119, identifier:other_elements; 120, identifier:keys; 121, identifier:multiplicity; 122, identifier:other_multiplicity; 123, identifier:multiplicity; 124, identifier:other_multiplicity; 125, identifier:other_multiplicity; 126, identifier:multiplicity; 127, identifier:_elements; 128, identifier:element
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; 7, 18; 8, 19; 9, 20; 10, 21; 11, 22; 12, 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; 23, 39; 23, 40; 24, 41; 24, 42; 25, 43; 25, 44; 28, 45; 28, 46; 28, 47; 28, 48; 28, 49; 29, 50; 29, 51; 32, 52; 32, 53; 34, 54; 34, 55; 38, 56; 38, 57; 40, 58; 40, 59; 42, 60; 42, 61; 44, 62; 44, 63; 45, 64; 46, 65; 47, 66; 48, 67; 49, 68; 49, 69; 50, 70; 50, 71; 52, 72; 52, 73; 53, 74; 54, 75; 54, 76; 62, 77; 62, 78; 63, 79; 63, 80; 64, 81; 64, 82; 65, 83; 65, 84; 66, 85; 66, 86; 67, 87; 67, 88; 68, 89; 68, 90; 69, 91; 78, 92; 80, 93; 82, 94; 82, 95; 84, 96; 84, 97; 86, 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; 97, 111; 98, 112; 98, 113; 98, 114; 99, 115; 99, 116; 100, 117; 100, 118; 102, 119; 102, 120; 112, 121; 112, 122; 113, 123; 113, 124; 114, 125; 114, 126; 115, 127; 115, 128
def symmetric_difference(self, other): r"""Return a new set with elements in either the set or other but not both. >>> ms = Multiset('aab') >>> sorted(ms.symmetric_difference('abc')) ['a', 'c'] You can also use the ``^`` operator for the same effect. However, the operator version will only accept a set as other operator, not any iterable, to avoid errors. >>> ms = Multiset('aab') >>> sorted(ms ^ Multiset('aaac')) ['a', 'b', 'c'] For a variant of the operation which modifies the multiset in place see :meth:`symmetric_difference_update`. Args: other: The other set to take the symmetric difference with. Can also be any :class:`~typing.Iterable`\[~T] or :class:`~typing.Mapping`\[~T, :class:`int`] which are then converted to :class:`Multiset`\[~T]. Returns: The resulting symmetric difference multiset. """ other = self._as_multiset(other) result = self.__class__() _total = 0 _elements = result._elements self_elements = self._elements other_elements = other._elements dist_elements = set(self_elements.keys()) | set(other_elements.keys()) for element in dist_elements: multiplicity = self_elements.get(element, 0) other_multiplicity = other_elements.get(element, 0) new_multiplicity = (multiplicity - other_multiplicity if multiplicity > other_multiplicity else other_multiplicity - multiplicity) _total += new_multiplicity if new_multiplicity > 0: _elements[element] = new_multiplicity result._total = _total return result
0, module; 1, function_definition; 2, function_name:times; 3, parameters; 4, block; 5, identifier:self; 6, identifier:factor; 7, expression_statement; 8, if_statement; 9, if_statement; 10, expression_statement; 11, expression_statement; 12, for_statement; 13, expression_statement; 14, return_statement; 15, comment:"""Return a new set with each element's multiplicity multiplied with the given scalar factor. >>> ms = Multiset('aab') >>> sorted(ms.times(2)) ['a', 'a', 'a', 'a', 'b', 'b'] You can also use the ``*`` operator for the same effect: >>> sorted(ms * 3) ['a', 'a', 'a', 'a', 'a', 'a', 'b', 'b', 'b'] For a variant of the operation which modifies the multiset in place see :meth:`times_update`. Args: factor: The factor to multiply each multiplicity with. """; 16, comparison_operator:factor == 0; 17, block; 18, comparison_operator:factor < 0; 19, block; 20, assignment; 21, assignment; 22, identifier:element; 23, identifier:_elements; 24, block; 25, augmented_assignment; 26, identifier:result; 27, identifier:factor; 28, integer:0; 29, return_statement; 30, identifier:factor; 31, integer:0; 32, raise_statement; 33, identifier:result; 34, call; 35, identifier:_elements; 36, attribute; 37, expression_statement; 38, attribute; 39, identifier:factor; 40, call; 41, call; 42, attribute; 43, argument_list; 44, identifier:result; 45, identifier:_elements; 46, augmented_assignment; 47, identifier:result; 48, identifier:_total; 49, attribute; 50, argument_list; 51, identifier:ValueError; 52, argument_list; 53, identifier:self; 54, identifier:__copy__; 55, subscript; 56, identifier:factor; 57, identifier:self; 58, identifier:__class__; 59, string; 60, identifier:_elements; 61, identifier:element; 62, string_content:The factor must no be negative.
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; 8, 17; 9, 18; 9, 19; 10, 20; 11, 21; 12, 22; 12, 23; 12, 24; 13, 25; 14, 26; 16, 27; 16, 28; 17, 29; 18, 30; 18, 31; 19, 32; 20, 33; 20, 34; 21, 35; 21, 36; 24, 37; 25, 38; 25, 39; 29, 40; 32, 41; 34, 42; 34, 43; 36, 44; 36, 45; 37, 46; 38, 47; 38, 48; 40, 49; 40, 50; 41, 51; 41, 52; 42, 53; 42, 54; 46, 55; 46, 56; 49, 57; 49, 58; 52, 59; 55, 60; 55, 61; 59, 62
def times(self, factor): """Return a new set with each element's multiplicity multiplied with the given scalar factor. >>> ms = Multiset('aab') >>> sorted(ms.times(2)) ['a', 'a', 'a', 'a', 'b', 'b'] You can also use the ``*`` operator for the same effect: >>> sorted(ms * 3) ['a', 'a', 'a', 'a', 'a', 'a', 'b', 'b', 'b'] For a variant of the operation which modifies the multiset in place see :meth:`times_update`. Args: factor: The factor to multiply each multiplicity with. """ if factor == 0: return self.__class__() if factor < 0: raise ValueError('The factor must no be negative.') result = self.__copy__() _elements = result._elements for element in _elements: _elements[element] *= factor result._total *= factor return result
0, module; 1, function_definition; 2, function_name:union_update; 3, parameters; 4, block; 5, identifier:self; 6, list_splat_pattern; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, for_statement; 11, expression_statement; 12, identifier:others; 13, comment:r"""Update the multiset, adding elements from all others using the maximum multiplicity. >>> ms = Multiset('aab') >>> ms.union_update('bc') >>> sorted(ms) ['a', 'a', 'b', 'c'] You can also use the ``|=`` operator for the same effect. However, the operator version will only accept a set as other operator, not any iterable, to avoid errors. >>> ms = Multiset('aab') >>> ms |= Multiset('bccd') >>> sorted(ms) ['a', 'a', 'b', 'c', 'c', 'd'] For a variant of the operation which does not modify the multiset, but returns a new multiset instead see :meth:`union`. Args: others: The other sets to union this multiset with. Can also be any :class:`~typing.Iterable`\[~T] or :class:`~typing.Mapping`\[~T, :class:`int`] which are then converted to :class:`Multiset`\[~T]. """; 14, assignment; 15, assignment; 16, identifier:other; 17, call; 18, block; 19, assignment; 20, identifier:_elements; 21, attribute; 22, identifier:_total; 23, attribute; 24, identifier:map; 25, argument_list; 26, for_statement; 27, attribute; 28, identifier:_total; 29, identifier:self; 30, identifier:_elements; 31, identifier:self; 32, identifier:_total; 33, attribute; 34, identifier:others; 35, pattern_list; 36, call; 37, block; 38, identifier:self; 39, identifier:_total; 40, identifier:self; 41, identifier:_as_mapping; 42, identifier:element; 43, identifier:multiplicity; 44, attribute; 45, argument_list; 46, expression_statement; 47, if_statement; 48, identifier:other; 49, identifier:items; 50, assignment; 51, comparison_operator:multiplicity > old_multiplicity; 52, block; 53, identifier:old_multiplicity; 54, call; 55, identifier:multiplicity; 56, identifier:old_multiplicity; 57, expression_statement; 58, expression_statement; 59, attribute; 60, argument_list; 61, assignment; 62, augmented_assignment; 63, identifier:_elements; 64, identifier:get; 65, identifier:element; 66, integer:0; 67, subscript; 68, identifier:multiplicity; 69, identifier:_total; 70, binary_operator:multiplicity - old_multiplicity; 71, identifier:_elements; 72, identifier:element; 73, identifier:multiplicity; 74, identifier:old_multiplicity
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; 9, 15; 10, 16; 10, 17; 10, 18; 11, 19; 14, 20; 14, 21; 15, 22; 15, 23; 17, 24; 17, 25; 18, 26; 19, 27; 19, 28; 21, 29; 21, 30; 23, 31; 23, 32; 25, 33; 25, 34; 26, 35; 26, 36; 26, 37; 27, 38; 27, 39; 33, 40; 33, 41; 35, 42; 35, 43; 36, 44; 36, 45; 37, 46; 37, 47; 44, 48; 44, 49; 46, 50; 47, 51; 47, 52; 50, 53; 50, 54; 51, 55; 51, 56; 52, 57; 52, 58; 54, 59; 54, 60; 57, 61; 58, 62; 59, 63; 59, 64; 60, 65; 60, 66; 61, 67; 61, 68; 62, 69; 62, 70; 67, 71; 67, 72; 70, 73; 70, 74
def union_update(self, *others): r"""Update the multiset, adding elements from all others using the maximum multiplicity. >>> ms = Multiset('aab') >>> ms.union_update('bc') >>> sorted(ms) ['a', 'a', 'b', 'c'] You can also use the ``|=`` operator for the same effect. However, the operator version will only accept a set as other operator, not any iterable, to avoid errors. >>> ms = Multiset('aab') >>> ms |= Multiset('bccd') >>> sorted(ms) ['a', 'a', 'b', 'c', 'c', 'd'] For a variant of the operation which does not modify the multiset, but returns a new multiset instead see :meth:`union`. Args: others: The other sets to union this multiset with. Can also be any :class:`~typing.Iterable`\[~T] or :class:`~typing.Mapping`\[~T, :class:`int`] which are then converted to :class:`Multiset`\[~T]. """ _elements = self._elements _total = self._total for other in map(self._as_mapping, others): for element, multiplicity in other.items(): old_multiplicity = _elements.get(element, 0) if multiplicity > old_multiplicity: _elements[element] = multiplicity _total += multiplicity - old_multiplicity self._total = _total
0, module; 1, function_definition; 2, function_name:intersection_update; 3, parameters; 4, block; 5, identifier:self; 6, list_splat_pattern; 7, expression_statement; 8, for_statement; 9, identifier:others; 10, comment:r"""Update the multiset, keeping only elements found in it and all others. >>> ms = Multiset('aab') >>> ms.intersection_update('bc') >>> sorted(ms) ['b'] You can also use the ``&=`` operator for the same effect. However, the operator version will only accept a set as other operator, not any iterable, to avoid errors. >>> ms = Multiset('aabc') >>> ms &= Multiset('abbd') >>> sorted(ms) ['a', 'b'] For a variant of the operation which does not modify the multiset, but returns a new multiset instead see :meth:`intersection`. Args: others: The other sets to intersect this multiset with. Can also be any :class:`~typing.Iterable`\[~T] or :class:`~typing.Mapping`\[~T, :class:`int`] which are then converted to :class:`Multiset`\[~T]. """; 11, identifier:other; 12, call; 13, block; 14, identifier:map; 15, argument_list; 16, for_statement; 17, attribute; 18, identifier:others; 19, pattern_list; 20, call; 21, block; 22, identifier:self; 23, identifier:_as_mapping; 24, identifier:element; 25, identifier:current_count; 26, identifier:list; 27, argument_list; 28, expression_statement; 29, if_statement; 30, call; 31, assignment; 32, comparison_operator:multiplicity < current_count; 33, block; 34, attribute; 35, argument_list; 36, identifier:multiplicity; 37, call; 38, identifier:multiplicity; 39, identifier:current_count; 40, expression_statement; 41, identifier:self; 42, identifier:items; 43, attribute; 44, argument_list; 45, assignment; 46, identifier:other; 47, identifier:get; 48, identifier:element; 49, integer:0; 50, subscript; 51, identifier:multiplicity; 52, identifier:self; 53, identifier:element
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 6, 9; 7, 10; 8, 11; 8, 12; 8, 13; 12, 14; 12, 15; 13, 16; 15, 17; 15, 18; 16, 19; 16, 20; 16, 21; 17, 22; 17, 23; 19, 24; 19, 25; 20, 26; 20, 27; 21, 28; 21, 29; 27, 30; 28, 31; 29, 32; 29, 33; 30, 34; 30, 35; 31, 36; 31, 37; 32, 38; 32, 39; 33, 40; 34, 41; 34, 42; 37, 43; 37, 44; 40, 45; 43, 46; 43, 47; 44, 48; 44, 49; 45, 50; 45, 51; 50, 52; 50, 53
def intersection_update(self, *others): r"""Update the multiset, keeping only elements found in it and all others. >>> ms = Multiset('aab') >>> ms.intersection_update('bc') >>> sorted(ms) ['b'] You can also use the ``&=`` operator for the same effect. However, the operator version will only accept a set as other operator, not any iterable, to avoid errors. >>> ms = Multiset('aabc') >>> ms &= Multiset('abbd') >>> sorted(ms) ['a', 'b'] For a variant of the operation which does not modify the multiset, but returns a new multiset instead see :meth:`intersection`. Args: others: The other sets to intersect this multiset with. Can also be any :class:`~typing.Iterable`\[~T] or :class:`~typing.Mapping`\[~T, :class:`int`] which are then converted to :class:`Multiset`\[~T]. """ for other in map(self._as_mapping, others): for element, current_count in list(self.items()): multiplicity = other.get(element, 0) if multiplicity < current_count: self[element] = multiplicity
0, module; 1, function_definition; 2, function_name:difference_update; 3, parameters; 4, block; 5, identifier:self; 6, list_splat_pattern; 7, expression_statement; 8, for_statement; 9, identifier:others; 10, comment:r"""Remove all elements contained the others from this multiset. >>> ms = Multiset('aab') >>> ms.difference_update('abc') >>> sorted(ms) ['a'] You can also use the ``-=`` operator for the same effect. However, the operator version will only accept a set as other operator, not any iterable, to avoid errors. >>> ms = Multiset('aabbbc') >>> ms -= Multiset('abd') >>> sorted(ms) ['a', 'b', 'b', 'c'] For a variant of the operation which does not modify the multiset, but returns a new multiset instead see :meth:`difference`. Args: others: The other sets to remove from this multiset. Can also be any :class:`~typing.Iterable`\[~T] or :class:`~typing.Mapping`\[~T, :class:`int`] which are then converted to :class:`Multiset`\[~T]. """; 11, identifier:other; 12, call; 13, block; 14, identifier:map; 15, argument_list; 16, for_statement; 17, attribute; 18, identifier:others; 19, pattern_list; 20, call; 21, block; 22, identifier:self; 23, identifier:_as_multiset; 24, identifier:element; 25, identifier:multiplicity; 26, attribute; 27, argument_list; 28, expression_statement; 29, identifier:other; 30, identifier:items; 31, call; 32, attribute; 33, argument_list; 34, identifier:self; 35, identifier:discard; 36, identifier:element; 37, identifier:multiplicity
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 6, 9; 7, 10; 8, 11; 8, 12; 8, 13; 12, 14; 12, 15; 13, 16; 15, 17; 15, 18; 16, 19; 16, 20; 16, 21; 17, 22; 17, 23; 19, 24; 19, 25; 20, 26; 20, 27; 21, 28; 26, 29; 26, 30; 28, 31; 31, 32; 31, 33; 32, 34; 32, 35; 33, 36; 33, 37
def difference_update(self, *others): r"""Remove all elements contained the others from this multiset. >>> ms = Multiset('aab') >>> ms.difference_update('abc') >>> sorted(ms) ['a'] You can also use the ``-=`` operator for the same effect. However, the operator version will only accept a set as other operator, not any iterable, to avoid errors. >>> ms = Multiset('aabbbc') >>> ms -= Multiset('abd') >>> sorted(ms) ['a', 'b', 'b', 'c'] For a variant of the operation which does not modify the multiset, but returns a new multiset instead see :meth:`difference`. Args: others: The other sets to remove from this multiset. Can also be any :class:`~typing.Iterable`\[~T] or :class:`~typing.Mapping`\[~T, :class:`int`] which are then converted to :class:`Multiset`\[~T]. """ for other in map(self._as_multiset, others): for element, multiplicity in other.items(): self.discard(element, multiplicity)
0, module; 1, function_definition; 2, function_name:symmetric_difference_update; 3, parameters; 4, block; 5, identifier:self; 6, identifier:other; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, for_statement; 11, comment:r"""Update the multiset to contain only elements in either this multiset or the other but not both. >>> ms = Multiset('aab') >>> ms.symmetric_difference_update('abc') >>> sorted(ms) ['a', 'c'] You can also use the ``^=`` operator for the same effect. However, the operator version will only accept a set as other operator, not any iterable, to avoid errors. >>> ms = Multiset('aabbbc') >>> ms ^= Multiset('abd') >>> sorted(ms) ['a', 'b', 'b', 'c', 'd'] For a variant of the operation which does not modify the multiset, but returns a new multiset instead see :meth:`symmetric_difference`. Args: other: The other set to take the symmetric difference with. Can also be any :class:`~typing.Iterable`\[~T] or :class:`~typing.Mapping`\[~T, :class:`int`] which are then converted to :class:`Multiset`\[~T]. """; 12, assignment; 13, assignment; 14, identifier:element; 15, identifier:elements; 16, block; 17, identifier:other; 18, call; 19, identifier:elements; 20, binary_operator:set(self.distinct_elements()) | set(other.distinct_elements()); 21, expression_statement; 22, expression_statement; 23, expression_statement; 24, attribute; 25, argument_list; 26, call; 27, call; 28, assignment; 29, assignment; 30, assignment; 31, identifier:self; 32, identifier:_as_multiset; 33, identifier:other; 34, identifier:set; 35, argument_list; 36, identifier:set; 37, argument_list; 38, identifier:multiplicity; 39, subscript; 40, identifier:other_count; 41, subscript; 42, subscript; 43, parenthesized_expression; 44, call; 45, call; 46, identifier:self; 47, identifier:element; 48, identifier:other; 49, identifier:element; 50, identifier:self; 51, identifier:element; 52, conditional_expression:multiplicity - other_count if multiplicity > other_count else other_count - multiplicity; 53, attribute; 54, argument_list; 55, attribute; 56, argument_list; 57, binary_operator:multiplicity - other_count; 58, comparison_operator:multiplicity > other_count; 59, binary_operator:other_count - multiplicity; 60, identifier:self; 61, identifier:distinct_elements; 62, identifier:other; 63, identifier:distinct_elements; 64, identifier:multiplicity; 65, identifier:other_count; 66, identifier:multiplicity; 67, identifier:other_count; 68, identifier:other_count; 69, identifier:multiplicity
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 7, 11; 8, 12; 9, 13; 10, 14; 10, 15; 10, 16; 12, 17; 12, 18; 13, 19; 13, 20; 16, 21; 16, 22; 16, 23; 18, 24; 18, 25; 20, 26; 20, 27; 21, 28; 22, 29; 23, 30; 24, 31; 24, 32; 25, 33; 26, 34; 26, 35; 27, 36; 27, 37; 28, 38; 28, 39; 29, 40; 29, 41; 30, 42; 30, 43; 35, 44; 37, 45; 39, 46; 39, 47; 41, 48; 41, 49; 42, 50; 42, 51; 43, 52; 44, 53; 44, 54; 45, 55; 45, 56; 52, 57; 52, 58; 52, 59; 53, 60; 53, 61; 55, 62; 55, 63; 57, 64; 57, 65; 58, 66; 58, 67; 59, 68; 59, 69
def symmetric_difference_update(self, other): r"""Update the multiset to contain only elements in either this multiset or the other but not both. >>> ms = Multiset('aab') >>> ms.symmetric_difference_update('abc') >>> sorted(ms) ['a', 'c'] You can also use the ``^=`` operator for the same effect. However, the operator version will only accept a set as other operator, not any iterable, to avoid errors. >>> ms = Multiset('aabbbc') >>> ms ^= Multiset('abd') >>> sorted(ms) ['a', 'b', 'b', 'c', 'd'] For a variant of the operation which does not modify the multiset, but returns a new multiset instead see :meth:`symmetric_difference`. Args: other: The other set to take the symmetric difference with. Can also be any :class:`~typing.Iterable`\[~T] or :class:`~typing.Mapping`\[~T, :class:`int`] which are then converted to :class:`Multiset`\[~T]. """ other = self._as_multiset(other) elements = set(self.distinct_elements()) | set(other.distinct_elements()) for element in elements: multiplicity = self[element] other_count = other[element] self[element] = (multiplicity - other_count if multiplicity > other_count else other_count - multiplicity)
0, module; 1, function_definition; 2, function_name:times_update; 3, parameters; 4, block; 5, identifier:self; 6, identifier:factor; 7, expression_statement; 8, if_statement; 9, comment:"""Update each this multiset by multiplying each element's multiplicity with the given scalar factor. >>> ms = Multiset('aab') >>> ms.times_update(2) >>> sorted(ms) ['a', 'a', 'a', 'a', 'b', 'b'] You can also use the ``*=`` operator for the same effect: >>> ms = Multiset('ac') >>> ms *= 3 >>> sorted(ms) ['a', 'a', 'a', 'c', 'c', 'c'] For a variant of the operation which does not modify the multiset, but returns a new multiset instead see :meth:`times`. Args: factor: The factor to multiply each multiplicity with. """; 10, comparison_operator:factor < 0; 11, block; 12, elif_clause; 13, else_clause; 14, identifier:factor; 15, integer:0; 16, raise_statement; 17, comparison_operator:factor == 0; 18, block; 19, block; 20, call; 21, identifier:factor; 22, integer:0; 23, expression_statement; 24, expression_statement; 25, for_statement; 26, expression_statement; 27, identifier:ValueError; 28, argument_list; 29, call; 30, assignment; 31, identifier:element; 32, identifier:_elements; 33, block; 34, augmented_assignment; 35, string:"The factor must not be negative."; 36, attribute; 37, argument_list; 38, identifier:_elements; 39, attribute; 40, expression_statement; 41, attribute; 42, identifier:factor; 43, identifier:self; 44, identifier:clear; 45, identifier:self; 46, identifier:_elements; 47, augmented_assignment; 48, identifier:self; 49, identifier:_total; 50, subscript; 51, identifier:factor; 52, identifier:_elements; 53, identifier:element
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 7, 9; 8, 10; 8, 11; 8, 12; 8, 13; 10, 14; 10, 15; 11, 16; 12, 17; 12, 18; 13, 19; 16, 20; 17, 21; 17, 22; 18, 23; 19, 24; 19, 25; 19, 26; 20, 27; 20, 28; 23, 29; 24, 30; 25, 31; 25, 32; 25, 33; 26, 34; 28, 35; 29, 36; 29, 37; 30, 38; 30, 39; 33, 40; 34, 41; 34, 42; 36, 43; 36, 44; 39, 45; 39, 46; 40, 47; 41, 48; 41, 49; 47, 50; 47, 51; 50, 52; 50, 53
def times_update(self, factor): """Update each this multiset by multiplying each element's multiplicity with the given scalar factor. >>> ms = Multiset('aab') >>> ms.times_update(2) >>> sorted(ms) ['a', 'a', 'a', 'a', 'b', 'b'] You can also use the ``*=`` operator for the same effect: >>> ms = Multiset('ac') >>> ms *= 3 >>> sorted(ms) ['a', 'a', 'a', 'c', 'c', 'c'] For a variant of the operation which does not modify the multiset, but returns a new multiset instead see :meth:`times`. Args: factor: The factor to multiply each multiplicity with. """ if factor < 0: raise ValueError("The factor must not be negative.") elif factor == 0: self.clear() else: _elements = self._elements for element in _elements: _elements[element] *= factor self._total *= factor
0, module; 1, function_definition; 2, function_name:add; 3, parameters; 4, block; 5, identifier:self; 6, identifier:element; 7, default_parameter; 8, expression_statement; 9, if_statement; 10, expression_statement; 11, expression_statement; 12, identifier:multiplicity; 13, integer:1; 14, comment:"""Adds an element to the multiset. >>> ms = Multiset() >>> ms.add('a') >>> sorted(ms) ['a'] An optional multiplicity can be specified to define how many of the element are added: >>> ms.add('b', 2) >>> sorted(ms) ['a', 'b', 'b'] This extends the :meth:`MutableSet.add` signature to allow specifying the multiplicity. Args: element: The element to add to the multiset. multiplicity: The multiplicity i.e. count of elements to add. """; 15, comparison_operator:multiplicity < 1; 16, block; 17, augmented_assignment; 18, augmented_assignment; 19, identifier:multiplicity; 20, integer:1; 21, raise_statement; 22, subscript; 23, identifier:multiplicity; 24, attribute; 25, identifier:multiplicity; 26, call; 27, attribute; 28, identifier:element; 29, identifier:self; 30, identifier:_total; 31, identifier:ValueError; 32, argument_list; 33, identifier:self; 34, identifier:_elements; 35, string:"Multiplicity must be positive"
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; 11, 18; 15, 19; 15, 20; 16, 21; 17, 22; 17, 23; 18, 24; 18, 25; 21, 26; 22, 27; 22, 28; 24, 29; 24, 30; 26, 31; 26, 32; 27, 33; 27, 34; 32, 35
def add(self, element, multiplicity=1): """Adds an element to the multiset. >>> ms = Multiset() >>> ms.add('a') >>> sorted(ms) ['a'] An optional multiplicity can be specified to define how many of the element are added: >>> ms.add('b', 2) >>> sorted(ms) ['a', 'b', 'b'] This extends the :meth:`MutableSet.add` signature to allow specifying the multiplicity. Args: element: The element to add to the multiset. multiplicity: The multiplicity i.e. count of elements to add. """ if multiplicity < 1: raise ValueError("Multiplicity must be positive") self._elements[element] += multiplicity self._total += multiplicity
0, module; 1, function_definition; 2, function_name:remove; 3, parameters; 4, block; 5, identifier:self; 6, identifier:element; 7, default_parameter; 8, expression_statement; 9, expression_statement; 10, if_statement; 11, expression_statement; 12, if_statement; 13, return_statement; 14, identifier:multiplicity; 15, None; 16, comment:"""Removes an element from the multiset. If no multiplicity is specified, the element is completely removed from the multiset: >>> ms = Multiset('aabbbc') >>> ms.remove('a') 2 >>> sorted(ms) ['b', 'b', 'b', 'c'] If the multiplicity is given, it is subtracted from the element's multiplicity in the multiset: >>> ms.remove('b', 2) 3 >>> sorted(ms) ['b', 'c'] It is not an error to remove more elements than are in the set: >>> ms.remove('b', 2) 1 >>> sorted(ms) ['c'] This extends the :meth:`MutableSet.remove` signature to allow specifying the multiplicity. Args: element: The element to remove from the multiset. multiplicity: An optional multiplicity i.e. count of elements to remove. Returns: The multiplicity of the element in the multiset before the removal. Raises: KeyError: if the element is not contained in the set. Use :meth:`discard` if you do not want an exception to be raised. """; 17, assignment; 18, comparison_operator:element not in _elements; 19, block; 20, assignment; 21, boolean_operator; 22, block; 23, elif_clause; 24, elif_clause; 25, identifier:old_multiplicity; 26, identifier:_elements; 27, attribute; 28, identifier:element; 29, identifier:_elements; 30, raise_statement; 31, identifier:old_multiplicity; 32, call; 33, comparison_operator:multiplicity is None; 34, comparison_operator:multiplicity >= old_multiplicity; 35, delete_statement; 36, expression_statement; 37, comparison_operator:multiplicity < 0; 38, block; 39, comparison_operator:multiplicity > 0; 40, block; 41, identifier:self; 42, identifier:_elements; 43, identifier:KeyError; 44, attribute; 45, argument_list; 46, identifier:multiplicity; 47, None; 48, identifier:multiplicity; 49, identifier:old_multiplicity; 50, subscript; 51, augmented_assignment; 52, identifier:multiplicity; 53, integer:0; 54, raise_statement; 55, identifier:multiplicity; 56, integer:0; 57, expression_statement; 58, expression_statement; 59, identifier:_elements; 60, identifier:get; 61, identifier:element; 62, integer:0; 63, identifier:_elements; 64, identifier:element; 65, attribute; 66, identifier:old_multiplicity; 67, call; 68, augmented_assignment; 69, augmented_assignment; 70, identifier:self; 71, identifier:_total; 72, identifier:ValueError; 73, argument_list; 74, subscript; 75, identifier:multiplicity; 76, attribute; 77, identifier:multiplicity; 78, string:"Multiplicity must be not be negative"; 79, identifier:_elements; 80, identifier:element; 81, identifier:self; 82, identifier:_total
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; 7, 14; 7, 15; 8, 16; 9, 17; 10, 18; 10, 19; 11, 20; 12, 21; 12, 22; 12, 23; 12, 24; 13, 25; 17, 26; 17, 27; 18, 28; 18, 29; 19, 30; 20, 31; 20, 32; 21, 33; 21, 34; 22, 35; 22, 36; 23, 37; 23, 38; 24, 39; 24, 40; 27, 41; 27, 42; 30, 43; 32, 44; 32, 45; 33, 46; 33, 47; 34, 48; 34, 49; 35, 50; 36, 51; 37, 52; 37, 53; 38, 54; 39, 55; 39, 56; 40, 57; 40, 58; 44, 59; 44, 60; 45, 61; 45, 62; 50, 63; 50, 64; 51, 65; 51, 66; 54, 67; 57, 68; 58, 69; 65, 70; 65, 71; 67, 72; 67, 73; 68, 74; 68, 75; 69, 76; 69, 77; 73, 78; 74, 79; 74, 80; 76, 81; 76, 82
def remove(self, element, multiplicity=None): """Removes an element from the multiset. If no multiplicity is specified, the element is completely removed from the multiset: >>> ms = Multiset('aabbbc') >>> ms.remove('a') 2 >>> sorted(ms) ['b', 'b', 'b', 'c'] If the multiplicity is given, it is subtracted from the element's multiplicity in the multiset: >>> ms.remove('b', 2) 3 >>> sorted(ms) ['b', 'c'] It is not an error to remove more elements than are in the set: >>> ms.remove('b', 2) 1 >>> sorted(ms) ['c'] This extends the :meth:`MutableSet.remove` signature to allow specifying the multiplicity. Args: element: The element to remove from the multiset. multiplicity: An optional multiplicity i.e. count of elements to remove. Returns: The multiplicity of the element in the multiset before the removal. Raises: KeyError: if the element is not contained in the set. Use :meth:`discard` if you do not want an exception to be raised. """ _elements = self._elements if element not in _elements: raise KeyError old_multiplicity = _elements.get(element, 0) if multiplicity is None or multiplicity >= old_multiplicity: del _elements[element] self._total -= old_multiplicity elif multiplicity < 0: raise ValueError("Multiplicity must be not be negative") elif multiplicity > 0: _elements[element] -= multiplicity self._total -= multiplicity return old_multiplicity
0, module; 1, function_definition; 2, function_name:discard; 3, parameters; 4, block; 5, identifier:self; 6, identifier:element; 7, default_parameter; 8, expression_statement; 9, expression_statement; 10, if_statement; 11, identifier:multiplicity; 12, None; 13, comment:"""Removes the `element` from the multiset. If multiplicity is ``None``, all occurrences of the element are removed: >>> ms = Multiset('aab') >>> ms.discard('a') 2 >>> sorted(ms) ['b'] Otherwise, the multiplicity is subtracted from the one in the multiset and the old multiplicity is removed: >>> ms = Multiset('aab') >>> ms.discard('a', 1) 2 >>> sorted(ms) ['a', 'b'] In contrast to :meth:`remove`, this does not raise an error if the element is not in the multiset: >>> ms = Multiset('a') >>> ms.discard('b') 0 >>> sorted(ms) ['a'] It is also not an error to remove more elements than are in the set: >>> ms.remove('a', 2) 1 >>> sorted(ms) [] Args: element: The element to remove from the multiset. multiplicity: An optional multiplicity i.e. count of elements to remove. Returns: The multiplicity of the element in the multiset before the removal. """; 14, assignment; 15, comparison_operator:element in _elements; 16, block; 17, else_clause; 18, identifier:_elements; 19, attribute; 20, identifier:element; 21, identifier:_elements; 22, expression_statement; 23, if_statement; 24, return_statement; 25, block; 26, identifier:self; 27, identifier:_elements; 28, assignment; 29, boolean_operator; 30, block; 31, elif_clause; 32, elif_clause; 33, identifier:old_multiplicity; 34, return_statement; 35, identifier:old_multiplicity; 36, subscript; 37, comparison_operator:multiplicity is None; 38, comparison_operator:multiplicity >= old_multiplicity; 39, delete_statement; 40, expression_statement; 41, comparison_operator:multiplicity < 0; 42, block; 43, comparison_operator:multiplicity > 0; 44, block; 45, integer:0; 46, identifier:_elements; 47, identifier:element; 48, identifier:multiplicity; 49, None; 50, identifier:multiplicity; 51, identifier:old_multiplicity; 52, subscript; 53, augmented_assignment; 54, identifier:multiplicity; 55, integer:0; 56, raise_statement; 57, identifier:multiplicity; 58, integer:0; 59, expression_statement; 60, expression_statement; 61, identifier:_elements; 62, identifier:element; 63, attribute; 64, identifier:old_multiplicity; 65, call; 66, augmented_assignment; 67, augmented_assignment; 68, identifier:self; 69, identifier:_total; 70, identifier:ValueError; 71, argument_list; 72, subscript; 73, identifier:multiplicity; 74, attribute; 75, identifier:multiplicity; 76, string:"Multiplicity must not be negative"; 77, identifier:_elements; 78, identifier:element; 79, identifier:self; 80, identifier:_total
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 7, 11; 7, 12; 8, 13; 9, 14; 10, 15; 10, 16; 10, 17; 14, 18; 14, 19; 15, 20; 15, 21; 16, 22; 16, 23; 16, 24; 17, 25; 19, 26; 19, 27; 22, 28; 23, 29; 23, 30; 23, 31; 23, 32; 24, 33; 25, 34; 28, 35; 28, 36; 29, 37; 29, 38; 30, 39; 30, 40; 31, 41; 31, 42; 32, 43; 32, 44; 34, 45; 36, 46; 36, 47; 37, 48; 37, 49; 38, 50; 38, 51; 39, 52; 40, 53; 41, 54; 41, 55; 42, 56; 43, 57; 43, 58; 44, 59; 44, 60; 52, 61; 52, 62; 53, 63; 53, 64; 56, 65; 59, 66; 60, 67; 63, 68; 63, 69; 65, 70; 65, 71; 66, 72; 66, 73; 67, 74; 67, 75; 71, 76; 72, 77; 72, 78; 74, 79; 74, 80
def discard(self, element, multiplicity=None): """Removes the `element` from the multiset. If multiplicity is ``None``, all occurrences of the element are removed: >>> ms = Multiset('aab') >>> ms.discard('a') 2 >>> sorted(ms) ['b'] Otherwise, the multiplicity is subtracted from the one in the multiset and the old multiplicity is removed: >>> ms = Multiset('aab') >>> ms.discard('a', 1) 2 >>> sorted(ms) ['a', 'b'] In contrast to :meth:`remove`, this does not raise an error if the element is not in the multiset: >>> ms = Multiset('a') >>> ms.discard('b') 0 >>> sorted(ms) ['a'] It is also not an error to remove more elements than are in the set: >>> ms.remove('a', 2) 1 >>> sorted(ms) [] Args: element: The element to remove from the multiset. multiplicity: An optional multiplicity i.e. count of elements to remove. Returns: The multiplicity of the element in the multiset before the removal. """ _elements = self._elements if element in _elements: old_multiplicity = _elements[element] if multiplicity is None or multiplicity >= old_multiplicity: del _elements[element] self._total -= old_multiplicity elif multiplicity < 0: raise ValueError("Multiplicity must not be negative") elif multiplicity > 0: _elements[element] -= multiplicity self._total -= multiplicity return old_multiplicity else: return 0
0, module; 1, function_definition; 2, function_name:_see_node; 3, parameters; 4, block; 5, identifier:self; 6, identifier:node_id; 7, identifier:fringe; 8, identifier:dist; 9, default_parameter; 10, expression_statement; 11, comment:# Namespace shortcuts.; 12, expression_statement; 13, expression_statement; 14, comment:# Wait inputs flag.; 15, expression_statement; 16, comment:# Update view distance.; 17, comment:# Check if inputs are satisfied.; 18, if_statement; 19, return_statement; 20, identifier:w_wait_in; 21, integer:0; 22, comment:""" See a node, updating seen and fringe. :param node_id: Node id to see. :type node_id: str :param fringe: Heapq of closest available nodes. :type fringe: list[(float | int, bool, (str, Dispatcher)] :param dist: Distance from the starting node. :type dist: float, int :param w_wait_in: Additional weight for sorting correctly the nodes in the fringe. :type w_wait_in: int, float :return: True if the node is visible, otherwise False. :rtype: bool """; 23, assignment; 24, assignment; 25, call; 26, call; 27, block; 28, elif_clause; 29, elif_clause; 30, False; 31, pattern_list; 32, expression_list; 33, identifier:wait_in; 34, subscript; 35, attribute; 36, argument_list; 37, attribute; 38, argument_list; 39, pass_statement; 40, comment:# Pass the node; 41, comparison_operator:node_id in dists; 42, comment:# The node w already estimated.; 43, block; 44, boolean_operator; 45, comment:# Check min dist.; 46, block; 47, identifier:seen; 48, identifier:dists; 49, attribute; 50, attribute; 51, subscript; 52, string; 53, identifier:self; 54, identifier:_update_meeting; 55, identifier:node_id; 56, identifier:dist; 57, identifier:self; 58, identifier:check_wait_in; 59, identifier:wait_in; 60, identifier:node_id; 61, identifier:node_id; 62, identifier:dists; 63, if_statement; 64, comparison_operator:node_id not in seen; 65, comparison_operator:dist < seen[node_id]; 66, expression_statement; 67, comment:# Update dist.; 68, expression_statement; 69, comment:# Node index.; 70, comment:# Virtual distance.; 71, expression_statement; 72, comment:# Add to heapq.; 73, expression_statement; 74, return_statement; 75, comment:# The node is visible.; 76, identifier:self; 77, identifier:seen; 78, identifier:self; 79, identifier:dist; 80, attribute; 81, identifier:node_id; 82, string_content:wait_inputs; 83, comparison_operator:dist < dists[node_id]; 84, comment:# Error for negative paths.; 85, block; 86, identifier:node_id; 87, identifier:seen; 88, identifier:dist; 89, subscript; 90, assignment; 91, assignment; 92, assignment; 93, call; 94, True; 95, identifier:self; 96, identifier:nodes; 97, identifier:dist; 98, subscript; 99, raise_statement; 100, identifier:seen; 101, identifier:node_id; 102, subscript; 103, identifier:dist; 104, identifier:index; 105, subscript; 106, identifier:vd; 107, tuple; 108, attribute; 109, argument_list; 110, identifier:dists; 111, identifier:node_id; 112, call; 113, identifier:seen; 114, identifier:node_id; 115, subscript; 116, string; 117, binary_operator:w_wait_in + int(wait_in); 118, identifier:node_id; 119, binary_operator:self.index + index; 120, identifier:heapq; 121, identifier:heappush; 122, identifier:fringe; 123, tuple; 124, identifier:DispatcherError; 125, argument_list; 126, attribute; 127, identifier:node_id; 128, string_content:index; 129, identifier:w_wait_in; 130, call; 131, attribute; 132, identifier:index; 133, identifier:dist; 134, identifier:vd; 135, tuple; 136, concatenated_string; 137, keyword_argument; 138, identifier:self; 139, identifier:nodes; 140, identifier:int; 141, argument_list; 142, identifier:self; 143, identifier:index; 144, identifier:node_id; 145, identifier:self; 146, string; 147, string; 148, identifier:sol; 149, identifier:self; 150, identifier:wait_in; 151, string_content:Contradictory paths found:; 152, string_content:negative weights?
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; 9, 20; 9, 21; 10, 22; 12, 23; 13, 24; 15, 25; 18, 26; 18, 27; 18, 28; 18, 29; 19, 30; 23, 31; 23, 32; 24, 33; 24, 34; 25, 35; 25, 36; 26, 37; 26, 38; 27, 39; 27, 40; 28, 41; 28, 42; 28, 43; 29, 44; 29, 45; 29, 46; 31, 47; 31, 48; 32, 49; 32, 50; 34, 51; 34, 52; 35, 53; 35, 54; 36, 55; 36, 56; 37, 57; 37, 58; 38, 59; 38, 60; 41, 61; 41, 62; 43, 63; 44, 64; 44, 65; 46, 66; 46, 67; 46, 68; 46, 69; 46, 70; 46, 71; 46, 72; 46, 73; 46, 74; 46, 75; 49, 76; 49, 77; 50, 78; 50, 79; 51, 80; 51, 81; 52, 82; 63, 83; 63, 84; 63, 85; 64, 86; 64, 87; 65, 88; 65, 89; 66, 90; 68, 91; 71, 92; 73, 93; 74, 94; 80, 95; 80, 96; 83, 97; 83, 98; 85, 99; 89, 100; 89, 101; 90, 102; 90, 103; 91, 104; 91, 105; 92, 106; 92, 107; 93, 108; 93, 109; 98, 110; 98, 111; 99, 112; 102, 113; 102, 114; 105, 115; 105, 116; 107, 117; 107, 118; 107, 119; 108, 120; 108, 121; 109, 122; 109, 123; 112, 124; 112, 125; 115, 126; 115, 127; 116, 128; 117, 129; 117, 130; 119, 131; 119, 132; 123, 133; 123, 134; 123, 135; 125, 136; 125, 137; 126, 138; 126, 139; 130, 140; 130, 141; 131, 142; 131, 143; 135, 144; 135, 145; 136, 146; 136, 147; 137, 148; 137, 149; 141, 150; 146, 151; 147, 152
def _see_node(self, node_id, fringe, dist, w_wait_in=0): """ See a node, updating seen and fringe. :param node_id: Node id to see. :type node_id: str :param fringe: Heapq of closest available nodes. :type fringe: list[(float | int, bool, (str, Dispatcher)] :param dist: Distance from the starting node. :type dist: float, int :param w_wait_in: Additional weight for sorting correctly the nodes in the fringe. :type w_wait_in: int, float :return: True if the node is visible, otherwise False. :rtype: bool """ # Namespace shortcuts. seen, dists = self.seen, self.dist wait_in = self.nodes[node_id]['wait_inputs'] # Wait inputs flag. self._update_meeting(node_id, dist) # Update view distance. # Check if inputs are satisfied. if self.check_wait_in(wait_in, node_id): pass # Pass the node elif node_id in dists: # The node w already estimated. if dist < dists[node_id]: # Error for negative paths. raise DispatcherError('Contradictory paths found: ' 'negative weights?', sol=self) elif node_id not in seen or dist < seen[node_id]: # Check min dist. seen[node_id] = dist # Update dist. index = self.nodes[node_id]['index'] # Node index. # Virtual distance. vd = (w_wait_in + int(wait_in), node_id, self.index + index) # Add to heapq. heapq.heappush(fringe, (dist, vd, (node_id, self))) return True # The node is visible. return False
0, module; 1, function_definition; 2, function_name:_add_compounds; 3, parameters; 4, block; 5, identifier:self; 6, identifier:variant_obj; 7, identifier:info_dict; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, if_statement; 12, comment:#Sort the compounds based on rank score; 13, expression_statement; 14, for_statement; 15, comment:"""Check if there are any compounds and add them to the variant The compounds that are added should be sorted on rank score """; 16, assignment; 17, assignment; 18, identifier:compound_entry; 19, block; 20, call; 21, identifier:compound; 22, identifier:compound_list; 23, block; 24, identifier:compound_list; 25, list; 26, identifier:compound_entry; 27, call; 28, for_statement; 29, attribute; 30, argument_list; 31, expression_statement; 32, attribute; 33, argument_list; 34, identifier:family_annotation; 35, call; 36, block; 37, identifier:compound_list; 38, identifier:sort; 39, keyword_argument; 40, keyword_argument; 41, call; 42, identifier:info_dict; 43, identifier:get; 44, string; 45, attribute; 46, argument_list; 47, expression_statement; 48, for_statement; 49, identifier:key; 50, call; 51, identifier:reverse; 52, True; 53, attribute; 54, argument_list; 55, string_content:Compounds; 56, identifier:compound_entry; 57, identifier:split; 58, string; 59, assignment; 60, identifier:compound; 61, identifier:compounds; 62, block; 63, attribute; 64, argument_list; 65, identifier:variant_obj; 66, identifier:add_compound; 67, identifier:compound; 68, string_content:,; 69, identifier:compounds; 70, call; 71, expression_statement; 72, expression_statement; 73, if_statement; 74, expression_statement; 75, identifier:operator; 76, identifier:attrgetter; 77, string; 78, attribute; 79, argument_list; 80, assignment; 81, assignment; 82, comparison_operator:len(splitted_compound) > 1; 83, block; 84, call; 85, string_content:combined_score; 86, subscript; 87, identifier:split; 88, string; 89, identifier:splitted_compound; 90, call; 91, identifier:compound_score; 92, None; 93, call; 94, integer:1; 95, expression_statement; 96, expression_statement; 97, attribute; 98, argument_list; 99, call; 100, unary_operator; 101, string_content:|; 102, attribute; 103, argument_list; 104, identifier:len; 105, argument_list; 106, assignment; 107, assignment; 108, identifier:compound_list; 109, identifier:append; 110, call; 111, attribute; 112, argument_list; 113, integer:1; 114, identifier:compound; 115, identifier:split; 116, string; 117, identifier:splitted_compound; 118, identifier:compound_id; 119, subscript; 120, identifier:compound_score; 121, call; 122, identifier:Compound; 123, argument_list; 124, identifier:family_annotation; 125, identifier:split; 126, string; 127, string_content:>; 128, identifier:splitted_compound; 129, integer:0; 130, identifier:int; 131, argument_list; 132, keyword_argument; 133, keyword_argument; 134, string_content::; 135, subscript; 136, identifier:variant_id; 137, identifier:compound_id; 138, identifier:combined_score; 139, identifier:compound_score; 140, identifier:splitted_compound; 141, unary_operator; 142, 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; 8, 15; 9, 16; 10, 17; 11, 18; 11, 19; 13, 20; 14, 21; 14, 22; 14, 23; 16, 24; 16, 25; 17, 26; 17, 27; 19, 28; 20, 29; 20, 30; 23, 31; 27, 32; 27, 33; 28, 34; 28, 35; 28, 36; 29, 37; 29, 38; 30, 39; 30, 40; 31, 41; 32, 42; 32, 43; 33, 44; 35, 45; 35, 46; 36, 47; 36, 48; 39, 49; 39, 50; 40, 51; 40, 52; 41, 53; 41, 54; 44, 55; 45, 56; 45, 57; 46, 58; 47, 59; 48, 60; 48, 61; 48, 62; 50, 63; 50, 64; 53, 65; 53, 66; 54, 67; 58, 68; 59, 69; 59, 70; 62, 71; 62, 72; 62, 73; 62, 74; 63, 75; 63, 76; 64, 77; 70, 78; 70, 79; 71, 80; 72, 81; 73, 82; 73, 83; 74, 84; 77, 85; 78, 86; 78, 87; 79, 88; 80, 89; 80, 90; 81, 91; 81, 92; 82, 93; 82, 94; 83, 95; 83, 96; 84, 97; 84, 98; 86, 99; 86, 100; 88, 101; 90, 102; 90, 103; 93, 104; 93, 105; 95, 106; 96, 107; 97, 108; 97, 109; 98, 110; 99, 111; 99, 112; 100, 113; 102, 114; 102, 115; 103, 116; 105, 117; 106, 118; 106, 119; 107, 120; 107, 121; 110, 122; 110, 123; 111, 124; 111, 125; 112, 126; 116, 127; 119, 128; 119, 129; 121, 130; 121, 131; 123, 132; 123, 133; 126, 134; 131, 135; 132, 136; 132, 137; 133, 138; 133, 139; 135, 140; 135, 141; 141, 142
def _add_compounds(self, variant_obj, info_dict): """Check if there are any compounds and add them to the variant The compounds that are added should be sorted on rank score """ compound_list = [] compound_entry = info_dict.get('Compounds') if compound_entry: for family_annotation in compound_entry.split(','): compounds = family_annotation.split(':')[-1].split('|') for compound in compounds: splitted_compound = compound.split('>') compound_score = None if len(splitted_compound) > 1: compound_id = splitted_compound[0] compound_score = int(splitted_compound[-1]) compound_list.append(Compound( variant_id=compound_id, combined_score=compound_score ) ) #Sort the compounds based on rank score compound_list.sort(key = operator.attrgetter('combined_score'), reverse=True) for compound in compound_list: variant_obj.add_compound(compound)
0, module; 1, function_definition; 2, function_name:dump_xml; 3, parameters; 4, block; 5, identifier:props; 6, identifier:fp; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, for_statement; 14, identifier:comment; 15, None; 16, identifier:encoding; 17, string; 18, identifier:sort_keys; 19, False; 20, comment:""" Write a series ``props`` of key-value pairs to a binary filehandle ``fp`` in the format of an XML properties file. The file will include both an XML declaration and a doctype declaration. :param props: A mapping or iterable of ``(key, value)`` pairs to write to ``fp``. All keys and values in ``props`` must be text strings. If ``sort_keys`` is `False`, the entries are output in iteration order. :param fp: a file-like object to write the values of ``props`` to :type fp: binary file-like object :param comment: if non-`None`, ``comment`` will be output as a ``<comment>`` element before the ``<entry>`` elements :type comment: text string or `None` :param string encoding: the name of the encoding to use for the XML document (also included in the XML declaration) :param bool sort_keys: if true, the elements of ``props`` are sorted lexicographically by key in the output :return: `None` """; 21, assignment; 22, call; 23, identifier:s; 24, call; 25, block; 26, string_content:UTF-8; 27, identifier:fp; 28, call; 29, identifier:print; 30, argument_list; 31, identifier:_stream_xml; 32, argument_list; 33, expression_statement; 34, attribute; 35, argument_list; 36, call; 37, keyword_argument; 38, identifier:props; 39, identifier:comment; 40, identifier:sort_keys; 41, call; 42, call; 43, identifier:streamwriter; 44, identifier:fp; 45, keyword_argument; 46, attribute; 47, argument_list; 48, identifier:file; 49, identifier:fp; 50, identifier:print; 51, argument_list; 52, attribute; 53, argument_list; 54, identifier:errors; 55, string; 56, string:'<?xml version="1.0" encoding={0} standalone="no"?>'; 57, identifier:format; 58, call; 59, identifier:s; 60, keyword_argument; 61, identifier:codecs; 62, identifier:lookup; 63, identifier:encoding; 64, string_content:xmlcharrefreplace; 65, identifier:quoteattr; 66, argument_list; 67, identifier:file; 68, identifier:fp; 69, identifier:encoding
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; 7, 14; 7, 15; 8, 16; 8, 17; 9, 18; 9, 19; 10, 20; 11, 21; 12, 22; 13, 23; 13, 24; 13, 25; 17, 26; 21, 27; 21, 28; 22, 29; 22, 30; 24, 31; 24, 32; 25, 33; 28, 34; 28, 35; 30, 36; 30, 37; 32, 38; 32, 39; 32, 40; 33, 41; 34, 42; 34, 43; 35, 44; 35, 45; 36, 46; 36, 47; 37, 48; 37, 49; 41, 50; 41, 51; 42, 52; 42, 53; 45, 54; 45, 55; 46, 56; 46, 57; 47, 58; 51, 59; 51, 60; 52, 61; 52, 62; 53, 63; 55, 64; 58, 65; 58, 66; 60, 67; 60, 68; 66, 69
def dump_xml(props, fp, comment=None, encoding='UTF-8', sort_keys=False): """ Write a series ``props`` of key-value pairs to a binary filehandle ``fp`` in the format of an XML properties file. The file will include both an XML declaration and a doctype declaration. :param props: A mapping or iterable of ``(key, value)`` pairs to write to ``fp``. All keys and values in ``props`` must be text strings. If ``sort_keys`` is `False`, the entries are output in iteration order. :param fp: a file-like object to write the values of ``props`` to :type fp: binary file-like object :param comment: if non-`None`, ``comment`` will be output as a ``<comment>`` element before the ``<entry>`` elements :type comment: text string or `None` :param string encoding: the name of the encoding to use for the XML document (also included in the XML declaration) :param bool sort_keys: if true, the elements of ``props`` are sorted lexicographically by key in the output :return: `None` """ fp = codecs.lookup(encoding).streamwriter(fp, errors='xmlcharrefreplace') print('<?xml version="1.0" encoding={0} standalone="no"?>' .format(quoteattr(encoding)), file=fp) for s in _stream_xml(props, comment, sort_keys): print(s, file=fp)
0, module; 1, function_definition; 2, function_name:dumps_xml; 3, parameters; 4, block; 5, identifier:props; 6, default_parameter; 7, default_parameter; 8, expression_statement; 9, return_statement; 10, identifier:comment; 11, None; 12, identifier:sort_keys; 13, False; 14, comment:""" Convert a series ``props`` of key-value pairs to a text string containing an XML properties document. The document will include a doctype declaration but not an XML declaration. :param props: A mapping or iterable of ``(key, value)`` pairs to serialize. All keys and values in ``props`` must be text strings. If ``sort_keys`` is `False`, the entries are output in iteration order. :param comment: if non-`None`, ``comment`` will be output as a ``<comment>`` element before the ``<entry>`` elements :type comment: text string or `None` :param bool sort_keys: if true, the elements of ``props`` are sorted lexicographically by key in the output :rtype: text string """; 15, call; 16, attribute; 17, generator_expression; 18, string; 19, identifier:join; 20, binary_operator:s + '\n'; 21, for_in_clause; 22, identifier:s; 23, string; 24, identifier:s; 25, call; 26, string_content; 27, identifier:_stream_xml; 28, argument_list; 29, escape_sequence:\n; 30, identifier:props; 31, identifier:comment; 32, identifier:sort_keys
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; 16, 18; 16, 19; 17, 20; 17, 21; 20, 22; 20, 23; 21, 24; 21, 25; 23, 26; 25, 27; 25, 28; 26, 29; 28, 30; 28, 31; 28, 32
def dumps_xml(props, comment=None, sort_keys=False): """ Convert a series ``props`` of key-value pairs to a text string containing an XML properties document. The document will include a doctype declaration but not an XML declaration. :param props: A mapping or iterable of ``(key, value)`` pairs to serialize. All keys and values in ``props`` must be text strings. If ``sort_keys`` is `False`, the entries are output in iteration order. :param comment: if non-`None`, ``comment`` will be output as a ``<comment>`` element before the ``<entry>`` elements :type comment: text string or `None` :param bool sort_keys: if true, the elements of ``props`` are sorted lexicographically by key in the output :rtype: text string """ return ''.join(s + '\n' for s in _stream_xml(props, comment, sort_keys))
0, module; 1, function_definition; 2, function_name:toposort; 3, parameters; 4, block; 5, identifier:graph; 6, default_parameter; 7, expression_statement; 8, expression_statement; 9, for_statement; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, while_statement; 14, comment:# Nodes may not be walked because they don't reach in degree 0.; 15, if_statement; 16, return_statement; 17, identifier:pick_first; 18, string; 19, comment:"""Toplogically sorts a list match graph. Tries to perform a topological sort using as tiebreaker the pick_first argument. If the graph contains cycles, raise ValueError. """; 20, assignment; 21, pattern_list; 22, call; 23, block; 24, assignment; 25, assignment; 26, assignment; 27, identifier:stk; 28, block; 29, comparison_operator:len(ordered) != len(graph) - 1; 30, block; 31, identifier:ordered; 32, string_content:head; 33, identifier:in_deg; 34, dictionary; 35, identifier:node; 36, identifier:next_nodes; 37, attribute; 38, argument_list; 39, for_statement; 40, identifier:stk; 41, list; 42, identifier:ordered; 43, list; 44, identifier:visited; 45, call; 46, expression_statement; 47, expression_statement; 48, if_statement; 49, expression_statement; 50, for_statement; 51, call; 52, binary_operator:len(graph) - 1; 53, raise_statement; 54, identifier:six; 55, identifier:iteritems; 56, identifier:graph; 57, identifier:next_node; 58, list; 59, block; 60, identifier:FIRST; 61, identifier:set; 62, argument_list; 63, assignment; 64, call; 65, comparison_operator:node != FIRST; 66, block; 67, assignment; 68, identifier:next_node; 69, identifier:traversal; 70, block; 71, identifier:len; 72, argument_list; 73, call; 74, integer:1; 75, call; 76, attribute; 77, attribute; 78, if_statement; 79, expression_statement; 80, identifier:node; 81, call; 82, attribute; 83, argument_list; 84, identifier:node; 85, identifier:FIRST; 86, expression_statement; 87, identifier:traversal; 88, call; 89, if_statement; 90, if_statement; 91, expression_statement; 92, if_statement; 93, identifier:ordered; 94, identifier:len; 95, argument_list; 96, identifier:ValueError; 97, argument_list; 98, identifier:next_nodes; 99, identifier:head_node; 100, identifier:next_nodes; 101, identifier:update_node; 102, comparison_operator:next_node is None; 103, block; 104, assignment; 105, attribute; 106, argument_list; 107, identifier:visited; 108, identifier:add; 109, identifier:node; 110, call; 111, identifier:_get_traversal; 112, argument_list; 113, comparison_operator:next_node is None; 114, block; 115, comparison_operator:next_node in visited; 116, block; 117, augmented_assignment; 118, comparison_operator:in_deg[next_node] == 0; 119, block; 120, identifier:graph; 121, string; 122, identifier:next_node; 123, None; 124, continue_statement; 125, subscript; 126, binary_operator:in_deg.get(next_node, 0) + 1; 127, identifier:stk; 128, identifier:pop; 129, attribute; 130, argument_list; 131, call; 132, identifier:pick_first; 133, identifier:next_node; 134, None; 135, continue_statement; 136, identifier:next_node; 137, identifier:visited; 138, raise_statement; 139, subscript; 140, integer:1; 141, subscript; 142, integer:0; 143, expression_statement; 144, string_content:Graph has a cycle; 145, identifier:in_deg; 146, identifier:next_node; 147, call; 148, integer:1; 149, identifier:ordered; 150, identifier:append; 151, identifier:node; 152, attribute; 153, argument_list; 154, call; 155, identifier:in_deg; 156, identifier:next_node; 157, identifier:in_deg; 158, identifier:next_node; 159, call; 160, attribute; 161, argument_list; 162, identifier:graph; 163, identifier:get; 164, identifier:node; 165, call; 166, identifier:ValueError; 167, argument_list; 168, attribute; 169, argument_list; 170, identifier:in_deg; 171, identifier:get; 172, identifier:next_node; 173, integer:0; 174, identifier:BeforeNodes; 175, argument_list; 176, string; 177, identifier:stk; 178, identifier:append; 179, identifier:next_node; 180, string_content:Graph has a cycle
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; 6, 17; 6, 18; 7, 19; 8, 20; 9, 21; 9, 22; 9, 23; 10, 24; 11, 25; 12, 26; 13, 27; 13, 28; 15, 29; 15, 30; 16, 31; 18, 32; 20, 33; 20, 34; 21, 35; 21, 36; 22, 37; 22, 38; 23, 39; 24, 40; 24, 41; 25, 42; 25, 43; 26, 44; 26, 45; 28, 46; 28, 47; 28, 48; 28, 49; 28, 50; 29, 51; 29, 52; 30, 53; 37, 54; 37, 55; 38, 56; 39, 57; 39, 58; 39, 59; 41, 60; 45, 61; 45, 62; 46, 63; 47, 64; 48, 65; 48, 66; 49, 67; 50, 68; 50, 69; 50, 70; 51, 71; 51, 72; 52, 73; 52, 74; 53, 75; 58, 76; 58, 77; 59, 78; 59, 79; 63, 80; 63, 81; 64, 82; 64, 83; 65, 84; 65, 85; 66, 86; 67, 87; 67, 88; 70, 89; 70, 90; 70, 91; 70, 92; 72, 93; 73, 94; 73, 95; 75, 96; 75, 97; 76, 98; 76, 99; 77, 100; 77, 101; 78, 102; 78, 103; 79, 104; 81, 105; 81, 106; 82, 107; 82, 108; 83, 109; 86, 110; 88, 111; 88, 112; 89, 113; 89, 114; 90, 115; 90, 116; 91, 117; 92, 118; 92, 119; 95, 120; 97, 121; 102, 122; 102, 123; 103, 124; 104, 125; 104, 126; 105, 127; 105, 128; 110, 129; 110, 130; 112, 131; 112, 132; 113, 133; 113, 134; 114, 135; 115, 136; 115, 137; 116, 138; 117, 139; 117, 140; 118, 141; 118, 142; 119, 143; 121, 144; 125, 145; 125, 146; 126, 147; 126, 148; 129, 149; 129, 150; 130, 151; 131, 152; 131, 153; 138, 154; 139, 155; 139, 156; 141, 157; 141, 158; 143, 159; 147, 160; 147, 161; 152, 162; 152, 163; 153, 164; 153, 165; 154, 166; 154, 167; 159, 168; 159, 169; 160, 170; 160, 171; 161, 172; 161, 173; 165, 174; 165, 175; 167, 176; 168, 177; 168, 178; 169, 179; 176, 180
def toposort(graph, pick_first='head'): """Toplogically sorts a list match graph. Tries to perform a topological sort using as tiebreaker the pick_first argument. If the graph contains cycles, raise ValueError. """ in_deg = {} for node, next_nodes in six.iteritems(graph): for next_node in [next_nodes.head_node, next_nodes.update_node]: if next_node is None: continue in_deg[next_node] = in_deg.get(next_node, 0) + 1 stk = [FIRST] ordered = [] visited = set() while stk: node = stk.pop() visited.add(node) if node != FIRST: ordered.append(node) traversal = _get_traversal(graph.get(node, BeforeNodes()), pick_first) for next_node in traversal: if next_node is None: continue if next_node in visited: raise ValueError('Graph has a cycle') in_deg[next_node] -= 1 if in_deg[next_node] == 0: stk.append(next_node) # Nodes may not be walked because they don't reach in degree 0. if len(ordered) != len(graph) - 1: raise ValueError('Graph has a cycle') return ordered
0, module; 1, function_definition; 2, function_name:sort_cyclic_graph_best_effort; 3, parameters; 4, block; 5, identifier:graph; 6, default_parameter; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, comment:# Go first on the pick_first chain then go back again on the others; 11, comment:# that were not visited. Given the way the graph is built both chains; 12, comment:# will always contain all the elements.; 13, if_statement; 14, expression_statement; 15, while_statement; 16, expression_statement; 17, while_statement; 18, return_statement; 19, identifier:pick_first; 20, string; 21, comment:"""Fallback for cases in which the graph has cycles."""; 22, assignment; 23, assignment; 24, comparison_operator:pick_first == 'head'; 25, block; 26, else_clause; 27, assignment; 28, comparison_operator:current is not None; 29, block; 30, assignment; 31, comparison_operator:current is not None; 32, block; 33, identifier:ordered; 34, string_content:head; 35, identifier:ordered; 36, list; 37, identifier:visited; 38, call; 39, identifier:pick_first; 40, string; 41, expression_statement; 42, block; 43, identifier:current; 44, identifier:FIRST; 45, identifier:current; 46, None; 47, expression_statement; 48, expression_statement; 49, if_statement; 50, identifier:current; 51, identifier:FIRST; 52, identifier:current; 53, None; 54, expression_statement; 55, expression_statement; 56, if_statement; 57, identifier:set; 58, argument_list; 59, string_content:head; 60, assignment; 61, expression_statement; 62, call; 63, assignment; 64, boolean_operator; 65, block; 66, call; 67, assignment; 68, boolean_operator; 69, block; 70, pattern_list; 71, tuple; 72, assignment; 73, attribute; 74, argument_list; 75, identifier:current; 76, call; 77, comparison_operator:current not in visited; 78, comparison_operator:current is not None; 79, expression_statement; 80, attribute; 81, argument_list; 82, identifier:current; 83, call; 84, comparison_operator:current not in visited; 85, comparison_operator:current is not None; 86, expression_statement; 87, identifier:fst_attr; 88, identifier:snd_attr; 89, string; 90, string; 91, pattern_list; 92, tuple; 93, identifier:visited; 94, identifier:add; 95, identifier:current; 96, identifier:getattr; 97, argument_list; 98, identifier:current; 99, identifier:visited; 100, identifier:current; 101, None; 102, call; 103, identifier:visited; 104, identifier:add; 105, identifier:current; 106, identifier:getattr; 107, argument_list; 108, identifier:current; 109, identifier:visited; 110, identifier:current; 111, None; 112, call; 113, string_content:head_node; 114, string_content:update_node; 115, identifier:fst_attr; 116, identifier:snd_attr; 117, string; 118, string; 119, subscript; 120, identifier:fst_attr; 121, attribute; 122, argument_list; 123, subscript; 124, identifier:snd_attr; 125, attribute; 126, argument_list; 127, string_content:update_node; 128, string_content:head_node; 129, identifier:graph; 130, identifier:current; 131, identifier:ordered; 132, identifier:append; 133, identifier:current; 134, identifier:graph; 135, identifier:current; 136, identifier:ordered; 137, identifier:append; 138, identifier:current
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; 6, 19; 6, 20; 7, 21; 8, 22; 9, 23; 13, 24; 13, 25; 13, 26; 14, 27; 15, 28; 15, 29; 16, 30; 17, 31; 17, 32; 18, 33; 20, 34; 22, 35; 22, 36; 23, 37; 23, 38; 24, 39; 24, 40; 25, 41; 26, 42; 27, 43; 27, 44; 28, 45; 28, 46; 29, 47; 29, 48; 29, 49; 30, 50; 30, 51; 31, 52; 31, 53; 32, 54; 32, 55; 32, 56; 38, 57; 38, 58; 40, 59; 41, 60; 42, 61; 47, 62; 48, 63; 49, 64; 49, 65; 54, 66; 55, 67; 56, 68; 56, 69; 60, 70; 60, 71; 61, 72; 62, 73; 62, 74; 63, 75; 63, 76; 64, 77; 64, 78; 65, 79; 66, 80; 66, 81; 67, 82; 67, 83; 68, 84; 68, 85; 69, 86; 70, 87; 70, 88; 71, 89; 71, 90; 72, 91; 72, 92; 73, 93; 73, 94; 74, 95; 76, 96; 76, 97; 77, 98; 77, 99; 78, 100; 78, 101; 79, 102; 80, 103; 80, 104; 81, 105; 83, 106; 83, 107; 84, 108; 84, 109; 85, 110; 85, 111; 86, 112; 89, 113; 90, 114; 91, 115; 91, 116; 92, 117; 92, 118; 97, 119; 97, 120; 102, 121; 102, 122; 107, 123; 107, 124; 112, 125; 112, 126; 117, 127; 118, 128; 119, 129; 119, 130; 121, 131; 121, 132; 122, 133; 123, 134; 123, 135; 125, 136; 125, 137; 126, 138
def sort_cyclic_graph_best_effort(graph, pick_first='head'): """Fallback for cases in which the graph has cycles.""" ordered = [] visited = set() # Go first on the pick_first chain then go back again on the others # that were not visited. Given the way the graph is built both chains # will always contain all the elements. if pick_first == 'head': fst_attr, snd_attr = ('head_node', 'update_node') else: fst_attr, snd_attr = ('update_node', 'head_node') current = FIRST while current is not None: visited.add(current) current = getattr(graph[current], fst_attr) if current not in visited and current is not None: ordered.append(current) current = FIRST while current is not None: visited.add(current) current = getattr(graph[current], snd_attr) if current not in visited and current is not None: ordered.append(current) return ordered
0, module; 1, function_definition; 2, function_name:dump; 3, parameters; 4, block; 5, identifier:props; 6, identifier:fp; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, expression_statement; 12, if_statement; 13, if_statement; 14, for_statement; 15, identifier:separator; 16, string; 17, identifier:comments; 18, None; 19, identifier:timestamp; 20, True; 21, identifier:sort_keys; 22, False; 23, comment:""" Write a series of key-value pairs to a file in simple line-oriented ``.properties`` format. :param props: A mapping or iterable of ``(key, value)`` pairs to write to ``fp``. All keys and values in ``props`` must be text strings. If ``sort_keys`` is `False`, the entries are output in iteration order. :param fp: A file-like object to write the values of ``props`` to. It must have been opened as a text file with a Latin-1-compatible encoding. :param separator: The string to use for separating keys & values. Only ``" "``, ``"="``, and ``":"`` (possibly with added whitespace) should ever be used as the separator. :type separator: text string :param comments: if non-`None`, ``comments`` will be written to ``fp`` as a comment before any other content :type comments: text string or `None` :param timestamp: If neither `None` nor `False`, a timestamp in the form of ``Mon Sep 02 14:00:54 EDT 2016`` is written as a comment to ``fp`` after ``comments`` (if any) and before the key-value pairs. If ``timestamp`` is `True`, the current date & time is used. If it is a number, it is converted from seconds since the epoch to local time. If it is a `datetime.datetime` object, its value is used directly, with naïve objects assumed to be in the local timezone. :type timestamp: `None`, `bool`, number, or `datetime.datetime` :param bool sort_keys: if true, the elements of ``props`` are sorted lexicographically by key in the output :return: `None` """; 24, comparison_operator:comments is not None; 25, block; 26, boolean_operator; 27, block; 28, pattern_list; 29, call; 30, block; 31, string_content:=; 32, identifier:comments; 33, None; 34, expression_statement; 35, comparison_operator:timestamp is not None; 36, comparison_operator:timestamp is not False; 37, expression_statement; 38, identifier:k; 39, identifier:v; 40, identifier:itemize; 41, argument_list; 42, expression_statement; 43, call; 44, identifier:timestamp; 45, None; 46, identifier:timestamp; 47, False; 48, call; 49, identifier:props; 50, keyword_argument; 51, call; 52, identifier:print; 53, argument_list; 54, identifier:print; 55, argument_list; 56, identifier:sort_keys; 57, identifier:sort_keys; 58, identifier:print; 59, argument_list; 60, call; 61, keyword_argument; 62, call; 63, keyword_argument; 64, call; 65, keyword_argument; 66, identifier:to_comment; 67, argument_list; 68, identifier:file; 69, identifier:fp; 70, identifier:to_comment; 71, argument_list; 72, identifier:file; 73, identifier:fp; 74, identifier:join_key_value; 75, argument_list; 76, identifier:file; 77, identifier:fp; 78, identifier:comments; 79, call; 80, identifier:k; 81, identifier:v; 82, identifier:separator; 83, identifier:java_timestamp; 84, argument_list; 85, identifier:timestamp
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; 7, 15; 7, 16; 8, 17; 8, 18; 9, 19; 9, 20; 10, 21; 10, 22; 11, 23; 12, 24; 12, 25; 13, 26; 13, 27; 14, 28; 14, 29; 14, 30; 16, 31; 24, 32; 24, 33; 25, 34; 26, 35; 26, 36; 27, 37; 28, 38; 28, 39; 29, 40; 29, 41; 30, 42; 34, 43; 35, 44; 35, 45; 36, 46; 36, 47; 37, 48; 41, 49; 41, 50; 42, 51; 43, 52; 43, 53; 48, 54; 48, 55; 50, 56; 50, 57; 51, 58; 51, 59; 53, 60; 53, 61; 55, 62; 55, 63; 59, 64; 59, 65; 60, 66; 60, 67; 61, 68; 61, 69; 62, 70; 62, 71; 63, 72; 63, 73; 64, 74; 64, 75; 65, 76; 65, 77; 67, 78; 71, 79; 75, 80; 75, 81; 75, 82; 79, 83; 79, 84; 84, 85
def dump(props, fp, separator='=', comments=None, timestamp=True, sort_keys=False): """ Write a series of key-value pairs to a file in simple line-oriented ``.properties`` format. :param props: A mapping or iterable of ``(key, value)`` pairs to write to ``fp``. All keys and values in ``props`` must be text strings. If ``sort_keys`` is `False`, the entries are output in iteration order. :param fp: A file-like object to write the values of ``props`` to. It must have been opened as a text file with a Latin-1-compatible encoding. :param separator: The string to use for separating keys & values. Only ``" "``, ``"="``, and ``":"`` (possibly with added whitespace) should ever be used as the separator. :type separator: text string :param comments: if non-`None`, ``comments`` will be written to ``fp`` as a comment before any other content :type comments: text string or `None` :param timestamp: If neither `None` nor `False`, a timestamp in the form of ``Mon Sep 02 14:00:54 EDT 2016`` is written as a comment to ``fp`` after ``comments`` (if any) and before the key-value pairs. If ``timestamp`` is `True`, the current date & time is used. If it is a number, it is converted from seconds since the epoch to local time. If it is a `datetime.datetime` object, its value is used directly, with naïve objects assumed to be in the local timezone. :type timestamp: `None`, `bool`, number, or `datetime.datetime` :param bool sort_keys: if true, the elements of ``props`` are sorted lexicographically by key in the output :return: `None` """ if comments is not None: print(to_comment(comments), file=fp) if timestamp is not None and timestamp is not False: print(to_comment(java_timestamp(timestamp)), file=fp) for k,v in itemize(props, sort_keys=sort_keys): print(join_key_value(k, v, separator), file=fp)
0, module; 1, function_definition; 2, function_name:dumps; 3, parameters; 4, block; 5, identifier:props; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, return_statement; 14, identifier:separator; 15, string; 16, identifier:comments; 17, None; 18, identifier:timestamp; 19, True; 20, identifier:sort_keys; 21, False; 22, comment:""" Convert a series of key-value pairs to a text string in simple line-oriented ``.properties`` format. :param props: A mapping or iterable of ``(key, value)`` pairs to serialize. All keys and values in ``props`` must be text strings. If ``sort_keys`` is `False`, the entries are output in iteration order. :param separator: The string to use for separating keys & values. Only ``" "``, ``"="``, and ``":"`` (possibly with added whitespace) should ever be used as the separator. :type separator: text string :param comments: if non-`None`, ``comments`` will be output as a comment before any other content :type comments: text string or `None` :param timestamp: If neither `None` nor `False`, a timestamp in the form of ``Mon Sep 02 14:00:54 EDT 2016`` is output as a comment after ``comments`` (if any) and before the key-value pairs. If ``timestamp`` is `True`, the current date & time is used. If it is a number, it is converted from seconds since the epoch to local time. If it is a `datetime.datetime` object, its value is used directly, with naïve objects assumed to be in the local timezone. :type timestamp: `None`, `bool`, number, or `datetime.datetime` :param bool sort_keys: if true, the elements of ``props`` are sorted lexicographically by key in the output :rtype: text string """; 23, assignment; 24, call; 25, call; 26, string_content:=; 27, identifier:s; 28, call; 29, identifier:dump; 30, argument_list; 31, attribute; 32, argument_list; 33, identifier:StringIO; 34, argument_list; 35, identifier:props; 36, identifier:s; 37, keyword_argument; 38, keyword_argument; 39, keyword_argument; 40, keyword_argument; 41, identifier:s; 42, identifier:getvalue; 43, identifier:separator; 44, identifier:separator; 45, identifier:comments; 46, identifier:comments; 47, identifier:timestamp; 48, identifier:timestamp; 49, identifier:sort_keys; 50, identifier:sort_keys
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; 6, 14; 6, 15; 7, 16; 7, 17; 8, 18; 8, 19; 9, 20; 9, 21; 10, 22; 11, 23; 12, 24; 13, 25; 15, 26; 23, 27; 23, 28; 24, 29; 24, 30; 25, 31; 25, 32; 28, 33; 28, 34; 30, 35; 30, 36; 30, 37; 30, 38; 30, 39; 30, 40; 31, 41; 31, 42; 37, 43; 37, 44; 38, 45; 38, 46; 39, 47; 39, 48; 40, 49; 40, 50
def dumps(props, separator='=', comments=None, timestamp=True, sort_keys=False): """ Convert a series of key-value pairs to a text string in simple line-oriented ``.properties`` format. :param props: A mapping or iterable of ``(key, value)`` pairs to serialize. All keys and values in ``props`` must be text strings. If ``sort_keys`` is `False`, the entries are output in iteration order. :param separator: The string to use for separating keys & values. Only ``" "``, ``"="``, and ``":"`` (possibly with added whitespace) should ever be used as the separator. :type separator: text string :param comments: if non-`None`, ``comments`` will be output as a comment before any other content :type comments: text string or `None` :param timestamp: If neither `None` nor `False`, a timestamp in the form of ``Mon Sep 02 14:00:54 EDT 2016`` is output as a comment after ``comments`` (if any) and before the key-value pairs. If ``timestamp`` is `True`, the current date & time is used. If it is a number, it is converted from seconds since the epoch to local time. If it is a `datetime.datetime` object, its value is used directly, with naïve objects assumed to be in the local timezone. :type timestamp: `None`, `bool`, number, or `datetime.datetime` :param bool sort_keys: if true, the elements of ``props`` are sorted lexicographically by key in the output :rtype: text string """ s = StringIO() dump(props, s, separator=separator, comments=comments, timestamp=timestamp, sort_keys=sort_keys) return s.getvalue()
0, module; 1, function_definition; 2, function_name:_zadd; 3, parameters; 4, block; 5, identifier:self; 6, identifier:key; 7, identifier:pk; 8, default_parameter; 9, default_parameter; 10, expression_statement; 11, return_statement; 12, identifier:ts; 13, None; 14, identifier:ttl; 15, None; 16, comment:"""Redis lua func to add an event to the corresponding sorted set. :param key: the key to be stored in redis server :param pk: the primary key of event :param ts: timestamp of the event, default to redis_server's current timestamp :param ttl: the expiration time of event since the last update """; 17, call; 18, attribute; 19, argument_list; 20, attribute; 21, identifier:eval; 22, attribute; 23, integer:1; 24, identifier:key; 25, boolean_operator; 26, identifier:pk; 27, identifier:self; 28, identifier:r; 29, identifier:self; 30, identifier:LUA_ZADD; 31, identifier:ts; 32, call; 33, attribute; 34, argument_list; 35, identifier:self; 36, identifier:_time
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 4, 10; 4, 11; 8, 12; 8, 13; 9, 14; 9, 15; 10, 16; 11, 17; 17, 18; 17, 19; 18, 20; 18, 21; 19, 22; 19, 23; 19, 24; 19, 25; 19, 26; 20, 27; 20, 28; 22, 29; 22, 30; 25, 31; 25, 32; 32, 33; 32, 34; 33, 35; 33, 36
def _zadd(self, key, pk, ts=None, ttl=None): """Redis lua func to add an event to the corresponding sorted set. :param key: the key to be stored in redis server :param pk: the primary key of event :param ts: timestamp of the event, default to redis_server's current timestamp :param ttl: the expiration time of event since the last update """ return self.r.eval(self.LUA_ZADD, 1, key, ts or self._time(), pk)
0, module; 1, function_definition; 2, function_name:add; 3, parameters; 4, block; 5, identifier:self; 6, identifier:event; 7, identifier:pk; 8, default_parameter; 9, default_parameter; 10, expression_statement; 11, expression_statement; 12, try_statement; 13, identifier:ts; 14, None; 15, identifier:ttl; 16, None; 17, comment:"""Add an event to event store. All events were stored in a sorted set in redis with timestamp as rank score. :param event: the event to be added, format should be ``table_action`` :param pk: the primary key of event :param ts: timestamp of the event, default to redis_server's current timestamp :param ttl: the expiration time of event since the last update :return: bool """; 18, assignment; 19, block; 20, except_clause; 21, identifier:key; 22, call; 23, expression_statement; 24, return_statement; 25, as_pattern; 26, comment:# connection error typically happens when redis server can't be; 27, comment:# reached or timed out, the error will be silent with an error; 28, comment:# log and return None.; 29, block; 30, attribute; 31, argument_list; 32, call; 33, True; 34, attribute; 35, as_pattern_target; 36, expression_statement; 37, return_statement; 38, identifier:self; 39, identifier:_keygen; 40, identifier:event; 41, identifier:ts; 42, attribute; 43, argument_list; 44, identifier:redis; 45, identifier:ConnectionError; 46, identifier:e; 47, call; 48, False; 49, identifier:self; 50, identifier:_zadd; 51, identifier:key; 52, identifier:pk; 53, identifier:ts; 54, identifier:ttl; 55, attribute; 56, argument_list; 57, attribute; 58, identifier:error; 59, binary_operator:"redis event store failed with connection error %r" % e; 60, identifier:self; 61, identifier:logger; 62, string:"redis event store failed with connection error %r"; 63, identifier:e
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 4, 10; 4, 11; 4, 12; 8, 13; 8, 14; 9, 15; 9, 16; 10, 17; 11, 18; 12, 19; 12, 20; 18, 21; 18, 22; 19, 23; 19, 24; 20, 25; 20, 26; 20, 27; 20, 28; 20, 29; 22, 30; 22, 31; 23, 32; 24, 33; 25, 34; 25, 35; 29, 36; 29, 37; 30, 38; 30, 39; 31, 40; 31, 41; 32, 42; 32, 43; 34, 44; 34, 45; 35, 46; 36, 47; 37, 48; 42, 49; 42, 50; 43, 51; 43, 52; 43, 53; 43, 54; 47, 55; 47, 56; 55, 57; 55, 58; 56, 59; 57, 60; 57, 61; 59, 62; 59, 63
def add(self, event, pk, ts=None, ttl=None): """Add an event to event store. All events were stored in a sorted set in redis with timestamp as rank score. :param event: the event to be added, format should be ``table_action`` :param pk: the primary key of event :param ts: timestamp of the event, default to redis_server's current timestamp :param ttl: the expiration time of event since the last update :return: bool """ key = self._keygen(event, ts) try: self._zadd(key, pk, ts, ttl) return True except redis.ConnectionError as e: # connection error typically happens when redis server can't be # reached or timed out, the error will be silent with an error # log and return None. self.logger.error( "redis event store failed with connection error %r" % e) return False
0, module; 1, function_definition; 2, function_name:group; 3, parameters; 4, block; 5, identifier:iterable; 6, identifier:key; 7, expression_statement; 8, for_statement; 9, comment:""" groupby which sorts the input, discards the key and returns the output as a sequence of lists. """; 10, pattern_list; 11, call; 12, block; 13, identifier:_; 14, identifier:grouped; 15, identifier:groupby; 16, argument_list; 17, expression_statement; 18, call; 19, keyword_argument; 20, yield; 21, identifier:sorted; 22, argument_list; 23, identifier:key; 24, identifier:key; 25, call; 26, identifier:iterable; 27, keyword_argument; 28, identifier:list; 29, argument_list; 30, identifier:key; 31, identifier:key; 32, identifier:grouped
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 7, 9; 8, 10; 8, 11; 8, 12; 10, 13; 10, 14; 11, 15; 11, 16; 12, 17; 16, 18; 16, 19; 17, 20; 18, 21; 18, 22; 19, 23; 19, 24; 20, 25; 22, 26; 22, 27; 25, 28; 25, 29; 27, 30; 27, 31; 29, 32
def group(iterable, key): """ groupby which sorts the input, discards the key and returns the output as a sequence of lists. """ for _, grouped in groupby(sorted(iterable, key=key), key=key): yield list(grouped)
0, module; 1, function_definition; 2, function_name:sort_strings; 3, parameters; 4, block; 5, identifier:strings; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, expression_statement; 11, if_statement; 12, expression_statement; 13, function_definition; 14, return_statement; 15, identifier:sort_order; 16, None; 17, identifier:reverse; 18, False; 19, identifier:case_sensitive; 20, False; 21, identifier:sort_order_first; 22, True; 23, comment:"""Sort a list of strings according to the provided sorted list of string prefixes TODO: - Provide an option to use `.startswith()` rather than a fixed prefix length (will be much slower) Arguments: sort_order_first (bool): Whether strings in sort_order should always preceed "unknown" strings sort_order (sequence of str): Desired ordering as a list of prefixes to the strings If sort_order strings have varying length, the max length will determine the prefix length compared reverse (bool): whether to reverse the sort orded. Passed through to `sorted(strings, reverse=reverse)` case_senstive (bool): Whether to sort in lexographic rather than alphabetic order and whether the prefixes in sort_order are checked in a case-sensitive way Examples: >>> sort_strings(['morn32', 'morning', 'unknown', 'date', 'dow', 'doy', 'moy'], ... ('dat', 'dow', 'moy', 'dom', 'doy', 'mor')) ['date', 'dow', 'moy', 'doy', 'morn32', 'morning', 'unknown'] >>> sort_strings(['morn32', 'morning', 'unknown', 'less unknown', 'lucy', 'date', 'dow', 'doy', 'moy'], ... ('dat', 'dow', 'moy', 'dom', 'doy', 'mor'), reverse=True) ['unknown', 'lucy', 'less unknown', 'morning', 'morn32', 'doy', 'moy', 'dow', 'date'] Strings whose prefixes don't exist in `sort_order` sequence can be interleaved into the sorted list in lexical order by setting `sort_order_first=False` >>> sort_strings(['morn32', 'morning', 'unknown', 'lucy', 'less unknown', 'date', 'dow', 'doy', 'moy'], ... ('dat', 'dow', 'moy', 'dom', 'moy', 'mor'), ... sort_order_first=False) # doctest: +NORMALIZE_WHITESPACE ['date', 'dow', 'doy', 'less unknown', 'lucy', 'moy', 'morn32', 'morning', 'unknown'] """; 24, not_operator; 25, block; 26, assignment; 27, function_name:compare; 28, parameters; 29, block; 30, call; 31, identifier:case_sensitive; 32, expression_statement; 33, expression_statement; 34, identifier:prefix_len; 35, call; 36, identifier:a; 37, identifier:b; 38, default_parameter; 39, if_statement; 40, return_statement; 41, identifier:sorted; 42, argument_list; 43, assignment; 44, assignment; 45, identifier:max; 46, generator_expression; 47, identifier:prefix_len; 48, identifier:prefix_len; 49, identifier:prefix_len; 50, block; 51, binary_operator:(-1 * (a < b) + 1 * (a > b)) * (-2 * reverse + 1); 52, identifier:strings; 53, keyword_argument; 54, identifier:sort_order; 55, call; 56, identifier:strings; 57, call; 58, call; 59, for_in_clause; 60, if_statement; 61, parenthesized_expression; 62, parenthesized_expression; 63, identifier:key; 64, call; 65, identifier:tuple; 66, generator_expression; 67, identifier:tuple; 68, generator_expression; 69, identifier:len; 70, argument_list; 71, identifier:s; 72, identifier:sort_order; 73, comparison_operator:a[:prefix_len] in sort_order; 74, block; 75, comment:# b may be in sort_order list, so it should be first; 76, elif_clause; 77, binary_operator:-1 * (a < b) + 1 * (a > b); 78, binary_operator:-2 * reverse + 1; 79, attribute; 80, argument_list; 81, call; 82, for_in_clause; 83, call; 84, for_in_clause; 85, identifier:s; 86, subscript; 87, identifier:sort_order; 88, if_statement; 89, boolean_operator; 90, block; 91, binary_operator:-1 * (a < b); 92, binary_operator:1 * (a > b); 93, binary_operator:-2 * reverse; 94, integer:1; 95, identifier:functools; 96, identifier:cmp_to_key; 97, identifier:compare; 98, attribute; 99, argument_list; 100, identifier:s; 101, identifier:sort_order; 102, attribute; 103, argument_list; 104, identifier:s; 105, identifier:strings; 106, identifier:a; 107, slice; 108, comparison_operator:b[:prefix_len] in sort_order; 109, block; 110, elif_clause; 111, identifier:sort_order_first; 112, comparison_operator:b[:prefix_len] in sort_order; 113, return_statement; 114, unary_operator; 115, parenthesized_expression; 116, integer:1; 117, parenthesized_expression; 118, unary_operator; 119, identifier:reverse; 120, identifier:s; 121, identifier:lower; 122, identifier:s; 123, identifier:lower; 124, identifier:prefix_len; 125, subscript; 126, identifier:sort_order; 127, expression_statement; 128, expression_statement; 129, if_statement; 130, identifier:sort_order_first; 131, block; 132, subscript; 133, identifier:sort_order; 134, binary_operator:-2 * reverse + 1; 135, integer:1; 136, comparison_operator:a < b; 137, comparison_operator:a > b; 138, integer:2; 139, identifier:b; 140, slice; 141, assignment; 142, assignment; 143, identifier:comparison; 144, block; 145, return_statement; 146, identifier:b; 147, slice; 148, binary_operator:-2 * reverse; 149, integer:1; 150, identifier:a; 151, identifier:b; 152, identifier:a; 153, identifier:b; 154, identifier:prefix_len; 155, identifier:comparison; 156, binary_operator:sort_order.index(a[:prefix_len]) - sort_order.index(b[:prefix_len]); 157, identifier:comparison; 158, call; 159, return_statement; 160, binary_operator:-1 * (-2 * reverse + 1); 161, identifier:prefix_len; 162, unary_operator; 163, identifier:reverse; 164, call; 165, call; 166, identifier:int; 167, argument_list; 168, binary_operator:comparison * (-2 * reverse + 1); 169, unary_operator; 170, parenthesized_expression; 171, integer:2; 172, attribute; 173, argument_list; 174, attribute; 175, argument_list; 176, binary_operator:comparison / abs(comparison or 1); 177, identifier:comparison; 178, parenthesized_expression; 179, integer:1; 180, binary_operator:-2 * reverse + 1; 181, identifier:sort_order; 182, identifier:index; 183, subscript; 184, identifier:sort_order; 185, identifier:index; 186, subscript; 187, identifier:comparison; 188, call; 189, binary_operator:-2 * reverse + 1; 190, binary_operator:-2 * reverse; 191, integer:1; 192, identifier:a; 193, slice; 194, identifier:b; 195, slice; 196, identifier:abs; 197, argument_list; 198, binary_operator:-2 * reverse; 199, integer:1; 200, unary_operator; 201, identifier:reverse; 202, identifier:prefix_len; 203, identifier:prefix_len; 204, boolean_operator; 205, unary_operator; 206, identifier:reverse; 207, integer:2; 208, identifier:comparison; 209, integer:1; 210, integer:2
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; 11, 25; 12, 26; 13, 27; 13, 28; 13, 29; 14, 30; 24, 31; 25, 32; 25, 33; 26, 34; 26, 35; 28, 36; 28, 37; 28, 38; 29, 39; 29, 40; 30, 41; 30, 42; 32, 43; 33, 44; 35, 45; 35, 46; 38, 47; 38, 48; 39, 49; 39, 50; 40, 51; 42, 52; 42, 53; 43, 54; 43, 55; 44, 56; 44, 57; 46, 58; 46, 59; 50, 60; 51, 61; 51, 62; 53, 63; 53, 64; 55, 65; 55, 66; 57, 67; 57, 68; 58, 69; 58, 70; 59, 71; 59, 72; 60, 73; 60, 74; 60, 75; 60, 76; 61, 77; 62, 78; 64, 79; 64, 80; 66, 81; 66, 82; 68, 83; 68, 84; 70, 85; 73, 86; 73, 87; 74, 88; 76, 89; 76, 90; 77, 91; 77, 92; 78, 93; 78, 94; 79, 95; 79, 96; 80, 97; 81, 98; 81, 99; 82, 100; 82, 101; 83, 102; 83, 103; 84, 104; 84, 105; 86, 106; 86, 107; 88, 108; 88, 109; 88, 110; 89, 111; 89, 112; 90, 113; 91, 114; 91, 115; 92, 116; 92, 117; 93, 118; 93, 119; 98, 120; 98, 121; 102, 122; 102, 123; 107, 124; 108, 125; 108, 126; 109, 127; 109, 128; 109, 129; 110, 130; 110, 131; 112, 132; 112, 133; 113, 134; 114, 135; 115, 136; 117, 137; 118, 138; 125, 139; 125, 140; 127, 141; 128, 142; 129, 143; 129, 144; 131, 145; 132, 146; 132, 147; 134, 148; 134, 149; 136, 150; 136, 151; 137, 152; 137, 153; 140, 154; 141, 155; 141, 156; 142, 157; 142, 158; 144, 159; 145, 160; 147, 161; 148, 162; 148, 163; 156, 164; 156, 165; 158, 166; 158, 167; 159, 168; 160, 169; 160, 170; 162, 171; 164, 172; 164, 173; 165, 174; 165, 175; 167, 176; 168, 177; 168, 178; 169, 179; 170, 180; 172, 181; 172, 182; 173, 183; 174, 184; 174, 185; 175, 186; 176, 187; 176, 188; 178, 189; 180, 190; 180, 191; 183, 192; 183, 193; 186, 194; 186, 195; 188, 196; 188, 197; 189, 198; 189, 199; 190, 200; 190, 201; 193, 202; 195, 203; 197, 204; 198, 205; 198, 206; 200, 207; 204, 208; 204, 209; 205, 210
def sort_strings(strings, sort_order=None, reverse=False, case_sensitive=False, sort_order_first=True): """Sort a list of strings according to the provided sorted list of string prefixes TODO: - Provide an option to use `.startswith()` rather than a fixed prefix length (will be much slower) Arguments: sort_order_first (bool): Whether strings in sort_order should always preceed "unknown" strings sort_order (sequence of str): Desired ordering as a list of prefixes to the strings If sort_order strings have varying length, the max length will determine the prefix length compared reverse (bool): whether to reverse the sort orded. Passed through to `sorted(strings, reverse=reverse)` case_senstive (bool): Whether to sort in lexographic rather than alphabetic order and whether the prefixes in sort_order are checked in a case-sensitive way Examples: >>> sort_strings(['morn32', 'morning', 'unknown', 'date', 'dow', 'doy', 'moy'], ... ('dat', 'dow', 'moy', 'dom', 'doy', 'mor')) ['date', 'dow', 'moy', 'doy', 'morn32', 'morning', 'unknown'] >>> sort_strings(['morn32', 'morning', 'unknown', 'less unknown', 'lucy', 'date', 'dow', 'doy', 'moy'], ... ('dat', 'dow', 'moy', 'dom', 'doy', 'mor'), reverse=True) ['unknown', 'lucy', 'less unknown', 'morning', 'morn32', 'doy', 'moy', 'dow', 'date'] Strings whose prefixes don't exist in `sort_order` sequence can be interleaved into the sorted list in lexical order by setting `sort_order_first=False` >>> sort_strings(['morn32', 'morning', 'unknown', 'lucy', 'less unknown', 'date', 'dow', 'doy', 'moy'], ... ('dat', 'dow', 'moy', 'dom', 'moy', 'mor'), ... sort_order_first=False) # doctest: +NORMALIZE_WHITESPACE ['date', 'dow', 'doy', 'less unknown', 'lucy', 'moy', 'morn32', 'morning', 'unknown'] """ if not case_sensitive: sort_order = tuple(s.lower() for s in sort_order) strings = tuple(s.lower() for s in strings) prefix_len = max(len(s) for s in sort_order) def compare(a, b, prefix_len=prefix_len): if prefix_len: if a[:prefix_len] in sort_order: if b[:prefix_len] in sort_order: comparison = sort_order.index(a[:prefix_len]) - sort_order.index(b[:prefix_len]) comparison = int(comparison / abs(comparison or 1)) if comparison: return comparison * (-2 * reverse + 1) elif sort_order_first: return -1 * (-2 * reverse + 1) # b may be in sort_order list, so it should be first elif sort_order_first and b[:prefix_len] in sort_order: return -2 * reverse + 1 return (-1 * (a < b) + 1 * (a > b)) * (-2 * reverse + 1) return sorted(strings, key=functools.cmp_to_key(compare))
0, module; 1, function_definition; 2, function_name:clean_field_dict; 3, parameters; 4, block; 5, identifier:field_dict; 6, default_parameter; 7, default_parameter; 8, expression_statement; 9, expression_statement; 10, if_statement; 11, for_statement; 12, return_statement; 13, identifier:cleaner; 14, attribute; 15, identifier:time_zone; 16, None; 17, comment:r"""Normalize field values by stripping whitespace from strings, localizing datetimes to a timezone, etc >>> (sorted(clean_field_dict({'_state': object(), 'x': 1, 'y': "\t Wash Me! \n" }).items()) == ... [('x', 1), ('y', 'Wash Me!')]) True """; 18, assignment; 19, comparison_operator:time_zone is None; 20, block; 21, pattern_list; 22, call; 23, block; 24, identifier:d; 25, identifier:str; 26, identifier:strip; 27, identifier:d; 28, dictionary; 29, identifier:time_zone; 30, None; 31, expression_statement; 32, identifier:k; 33, identifier:v; 34, identifier:viewitems; 35, argument_list; 36, if_statement; 37, if_statement; 38, assignment; 39, identifier:field_dict; 40, comparison_operator:k == '_state'; 41, block; 42, call; 43, block; 44, elif_clause; 45, else_clause; 46, identifier:tz; 47, identifier:DEFAULT_TZ; 48, identifier:k; 49, string; 50, continue_statement; 51, identifier:isinstance; 52, argument_list; 53, expression_statement; 54, call; 55, block; 56, block; 57, string_content:_state; 58, identifier:v; 59, identifier:basestring; 60, assignment; 61, identifier:isinstance; 62, argument_list; 63, expression_statement; 64, expression_statement; 65, subscript; 66, call; 67, identifier:v; 68, tuple; 69, assignment; 70, assignment; 71, identifier:d; 72, identifier:k; 73, identifier:cleaner; 74, argument_list; 75, attribute; 76, attribute; 77, subscript; 78, call; 79, subscript; 80, identifier:v; 81, call; 82, identifier:datetime; 83, identifier:datetime; 84, identifier:datetime; 85, identifier:date; 86, identifier:d; 87, identifier:k; 88, attribute; 89, argument_list; 90, identifier:d; 91, identifier:k; 92, identifier:str; 93, argument_list; 94, identifier:tz; 95, identifier:localize; 96, identifier:v; 97, 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; 6, 13; 6, 14; 7, 15; 7, 16; 8, 17; 9, 18; 10, 19; 10, 20; 11, 21; 11, 22; 11, 23; 12, 24; 14, 25; 14, 26; 18, 27; 18, 28; 19, 29; 19, 30; 20, 31; 21, 32; 21, 33; 22, 34; 22, 35; 23, 36; 23, 37; 31, 38; 35, 39; 36, 40; 36, 41; 37, 42; 37, 43; 37, 44; 37, 45; 38, 46; 38, 47; 40, 48; 40, 49; 41, 50; 42, 51; 42, 52; 43, 53; 44, 54; 44, 55; 45, 56; 49, 57; 52, 58; 52, 59; 53, 60; 54, 61; 54, 62; 55, 63; 56, 64; 60, 65; 60, 66; 62, 67; 62, 68; 63, 69; 64, 70; 65, 71; 65, 72; 66, 73; 66, 74; 68, 75; 68, 76; 69, 77; 69, 78; 70, 79; 70, 80; 74, 81; 75, 82; 75, 83; 76, 84; 76, 85; 77, 86; 77, 87; 78, 88; 78, 89; 79, 90; 79, 91; 81, 92; 81, 93; 88, 94; 88, 95; 89, 96; 93, 97
def clean_field_dict(field_dict, cleaner=str.strip, time_zone=None): r"""Normalize field values by stripping whitespace from strings, localizing datetimes to a timezone, etc >>> (sorted(clean_field_dict({'_state': object(), 'x': 1, 'y': "\t Wash Me! \n" }).items()) == ... [('x', 1), ('y', 'Wash Me!')]) True """ d = {} if time_zone is None: tz = DEFAULT_TZ for k, v in viewitems(field_dict): if k == '_state': continue if isinstance(v, basestring): d[k] = cleaner(str(v)) elif isinstance(v, (datetime.datetime, datetime.date)): d[k] = tz.localize(v) else: d[k] = v return d
0, module; 1, function_definition; 2, function_name:best_fit; 3, parameters; 4, block; 5, identifier:li; 6, identifier:value; 7, expression_statement; 8, expression_statement; 9, if_statement; 10, if_statement; 11, comment:"""For a sorted list li, returns the closest item to value"""; 12, assignment; 13, comparison_operator:index in (0, len(li)); 14, block; 15, comparison_operator:li[index] - value < value - li[index-1]; 16, block; 17, else_clause; 18, identifier:index; 19, call; 20, identifier:index; 21, tuple; 22, return_statement; 23, binary_operator:li[index] - value; 24, binary_operator:value - li[index-1]; 25, return_statement; 26, block; 27, identifier:min; 28, argument_list; 29, integer:0; 30, call; 31, identifier:index; 32, subscript; 33, identifier:value; 34, identifier:value; 35, subscript; 36, identifier:index; 37, return_statement; 38, call; 39, binary_operator:len(li) - 1; 40, identifier:len; 41, argument_list; 42, identifier:li; 43, identifier:index; 44, identifier:li; 45, binary_operator:index-1; 46, binary_operator:index-1; 47, identifier:bisect_left; 48, argument_list; 49, call; 50, integer:1; 51, identifier:li; 52, identifier:index; 53, integer:1; 54, identifier:index; 55, integer:1; 56, identifier:li; 57, identifier:value; 58, identifier:len; 59, argument_list; 60, identifier:li
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 7, 11; 8, 12; 9, 13; 9, 14; 10, 15; 10, 16; 10, 17; 12, 18; 12, 19; 13, 20; 13, 21; 14, 22; 15, 23; 15, 24; 16, 25; 17, 26; 19, 27; 19, 28; 21, 29; 21, 30; 22, 31; 23, 32; 23, 33; 24, 34; 24, 35; 25, 36; 26, 37; 28, 38; 28, 39; 30, 40; 30, 41; 32, 42; 32, 43; 35, 44; 35, 45; 37, 46; 38, 47; 38, 48; 39, 49; 39, 50; 41, 51; 45, 52; 45, 53; 46, 54; 46, 55; 48, 56; 48, 57; 49, 58; 49, 59; 59, 60
def best_fit(li, value): """For a sorted list li, returns the closest item to value""" index = min(bisect_left(li, value), len(li) - 1) if index in (0, len(li)): return index if li[index] - value < value - li[index-1]: return index else: return index-1
0, module; 1, function_definition; 2, function_name:index_pix_in_pixels; 3, parameters; 4, block; 5, identifier:pix; 6, identifier:pixels; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, comment:# ADW: Not really safe to set index = -1 (accesses last entry);; 11, comment:# -np.inf would be better, but breaks other code...; 12, comment:# ADW: Are the pixels always sorted? Is there a quick way to check?; 13, if_statement; 14, comment:# Assumes that 'pixels' is pre-sorted, otherwise...???; 15, expression_statement; 16, if_statement; 17, return_statement; 18, identifier:sort; 19, False; 20, identifier:outside; 21, unary_operator; 22, comment:""" Find the indices of a set of pixels into another set of pixels. !!! ASSUMES SORTED PIXELS !!! Parameters: ----------- pix : set of search pixels pixels : set of reference pixels Returns: -------- index : index into the reference pixels """; 23, identifier:sort; 24, block; 25, assignment; 26, call; 27, block; 28, else_clause; 29, identifier:index; 30, integer:1; 31, expression_statement; 32, identifier:index; 33, call; 34, attribute; 35, argument_list; 36, if_statement; 37, comment:# Find objects that are outside the pixels; 38, block; 39, assignment; 40, attribute; 41, argument_list; 42, identifier:np; 43, identifier:isscalar; 44, identifier:index; 45, not_operator; 46, block; 47, expression_statement; 48, identifier:pixels; 49, call; 50, identifier:np; 51, identifier:searchsorted; 52, identifier:pixels; 53, identifier:pix; 54, call; 55, expression_statement; 56, assignment; 57, attribute; 58, argument_list; 59, attribute; 60, argument_list; 61, assignment; 62, subscript; 63, identifier:outside; 64, identifier:np; 65, identifier:sort; 66, identifier:pixels; 67, call; 68, identifier:any; 69, identifier:index; 70, identifier:outside; 71, identifier:index; 72, unary_operator; 73, attribute; 74, argument_list; 75, call; 76, identifier:np; 77, identifier:in1d; 78, identifier:pix; 79, identifier:pixels; 80, attribute; 81, argument_list; 82, identifier:np; 83, identifier:in1d; 84, identifier:pix; 85, identifier:pixels
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; 7, 18; 7, 19; 8, 20; 8, 21; 9, 22; 13, 23; 13, 24; 15, 25; 16, 26; 16, 27; 16, 28; 17, 29; 21, 30; 24, 31; 25, 32; 25, 33; 26, 34; 26, 35; 27, 36; 28, 37; 28, 38; 31, 39; 33, 40; 33, 41; 34, 42; 34, 43; 35, 44; 36, 45; 36, 46; 38, 47; 39, 48; 39, 49; 40, 50; 40, 51; 41, 52; 41, 53; 45, 54; 46, 55; 47, 56; 49, 57; 49, 58; 54, 59; 54, 60; 55, 61; 56, 62; 56, 63; 57, 64; 57, 65; 58, 66; 59, 67; 59, 68; 61, 69; 61, 70; 62, 71; 62, 72; 67, 73; 67, 74; 72, 75; 73, 76; 73, 77; 74, 78; 74, 79; 75, 80; 75, 81; 80, 82; 80, 83; 81, 84; 81, 85
def index_pix_in_pixels(pix,pixels,sort=False,outside=-1): """ Find the indices of a set of pixels into another set of pixels. !!! ASSUMES SORTED PIXELS !!! Parameters: ----------- pix : set of search pixels pixels : set of reference pixels Returns: -------- index : index into the reference pixels """ # ADW: Not really safe to set index = -1 (accesses last entry); # -np.inf would be better, but breaks other code... # ADW: Are the pixels always sorted? Is there a quick way to check? if sort: pixels = np.sort(pixels) # Assumes that 'pixels' is pre-sorted, otherwise...??? index = np.searchsorted(pixels,pix) if np.isscalar(index): if not np.in1d(pix,pixels).any(): index = outside else: # Find objects that are outside the pixels index[~np.in1d(pix,pixels)] = outside return index
0, module; 1, function_definition; 2, function_name:search; 3, parameters; 4, block; 5, identifier:self; 6, identifier:text; 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, default_parameter; 16, expression_statement; 17, expression_statement; 18, if_statement; 19, if_statement; 20, if_statement; 21, if_statement; 22, if_statement; 23, expression_statement; 24, return_statement; 25, identifier:includes; 26, None; 27, identifier:doc_type; 28, None; 29, identifier:limit; 30, None; 31, identifier:autocomplete; 32, False; 33, identifier:promulgated_only; 34, False; 35, identifier:tags; 36, None; 37, identifier:sort; 38, None; 39, identifier:owner; 40, None; 41, identifier:series; 42, None; 43, string; 44, assignment; 45, call; 46, block; 47, comparison_operator:limit is not None; 48, block; 49, identifier:autocomplete; 50, block; 51, comparison_operator:tags is not None; 52, block; 53, call; 54, block; 55, else_clause; 56, assignment; 57, subscript; 58, string_content:Search for entities in the charmstore. @param text The text to search for. @param includes What metadata to return in results (e.g. charm-config). @param doc_type Filter to this type: bundle or charm. @param limit Maximum number of results to return. @param autocomplete Whether to prefix/suffix match search terms. @param promulgated_only Whether to filter to only promulgated charms. @param tags The tags to filter; can be a list of tags or a single tag. @param sort Sorting the result based on the sort string provided which can be name, author, series and - in front for descending. @param owner Optional owner. If provided, search results will only include entities that owner can view. @param series The series to filter; can be a list of series or a single series.; 59, identifier:queries; 60, call; 61, identifier:len; 62, argument_list; 63, expression_statement; 64, identifier:limit; 65, None; 66, expression_statement; 67, expression_statement; 68, identifier:tags; 69, None; 70, if_statement; 71, expression_statement; 72, identifier:len; 73, argument_list; 74, expression_statement; 75, block; 76, identifier:data; 77, call; 78, call; 79, string; 80, attribute; 81, argument_list; 82, identifier:text; 83, call; 84, call; 85, call; 86, comparison_operator:type(tags) is list; 87, block; 88, call; 89, identifier:queries; 90, assignment; 91, expression_statement; 92, attribute; 93, argument_list; 94, attribute; 95, argument_list; 96, string_content:Results; 97, identifier:self; 98, identifier:_common_query_parameters; 99, identifier:doc_type; 100, identifier:includes; 101, identifier:owner; 102, identifier:promulgated_only; 103, identifier:series; 104, identifier:sort; 105, attribute; 106, argument_list; 107, attribute; 108, argument_list; 109, attribute; 110, argument_list; 111, call; 112, identifier:list; 113, expression_statement; 114, attribute; 115, argument_list; 116, identifier:url; 117, call; 118, assignment; 119, identifier:self; 120, identifier:_get; 121, identifier:url; 122, identifier:data; 123, identifier:json; 124, identifier:queries; 125, identifier:append; 126, tuple; 127, identifier:queries; 128, identifier:append; 129, tuple; 130, identifier:queries; 131, identifier:append; 132, tuple; 133, identifier:type; 134, argument_list; 135, assignment; 136, identifier:queries; 137, identifier:append; 138, tuple; 139, attribute; 140, argument_list; 141, identifier:url; 142, call; 143, string; 144, identifier:text; 145, string; 146, identifier:limit; 147, string; 148, integer:1; 149, identifier:tags; 150, identifier:tags; 151, call; 152, string; 153, identifier:tags; 154, string; 155, identifier:format; 156, attribute; 157, call; 158, attribute; 159, argument_list; 160, string_content:text; 161, string_content:limit; 162, string_content:autocomplete; 163, attribute; 164, argument_list; 165, string_content:tags; 166, string_content:{}/search?{}; 167, identifier:self; 168, identifier:url; 169, identifier:urlencode; 170, argument_list; 171, string; 172, identifier:format; 173, attribute; 174, string; 175, identifier:join; 176, identifier:tags; 177, identifier:queries; 178, string_content:{}/search; 179, identifier:self; 180, identifier:url; 181, string_content:,
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; 3, 15; 4, 16; 4, 17; 4, 18; 4, 19; 4, 20; 4, 21; 4, 22; 4, 23; 4, 24; 7, 25; 7, 26; 8, 27; 8, 28; 9, 29; 9, 30; 10, 31; 10, 32; 11, 33; 11, 34; 12, 35; 12, 36; 13, 37; 13, 38; 14, 39; 14, 40; 15, 41; 15, 42; 16, 43; 17, 44; 18, 45; 18, 46; 19, 47; 19, 48; 20, 49; 20, 50; 21, 51; 21, 52; 22, 53; 22, 54; 22, 55; 23, 56; 24, 57; 43, 58; 44, 59; 44, 60; 45, 61; 45, 62; 46, 63; 47, 64; 47, 65; 48, 66; 50, 67; 51, 68; 51, 69; 52, 70; 52, 71; 53, 72; 53, 73; 54, 74; 55, 75; 56, 76; 56, 77; 57, 78; 57, 79; 60, 80; 60, 81; 62, 82; 63, 83; 66, 84; 67, 85; 70, 86; 70, 87; 71, 88; 73, 89; 74, 90; 75, 91; 77, 92; 77, 93; 78, 94; 78, 95; 79, 96; 80, 97; 80, 98; 81, 99; 81, 100; 81, 101; 81, 102; 81, 103; 81, 104; 83, 105; 83, 106; 84, 107; 84, 108; 85, 109; 85, 110; 86, 111; 86, 112; 87, 113; 88, 114; 88, 115; 90, 116; 90, 117; 91, 118; 92, 119; 92, 120; 93, 121; 94, 122; 94, 123; 105, 124; 105, 125; 106, 126; 107, 127; 107, 128; 108, 129; 109, 130; 109, 131; 110, 132; 111, 133; 111, 134; 113, 135; 114, 136; 114, 137; 115, 138; 117, 139; 117, 140; 118, 141; 118, 142; 126, 143; 126, 144; 129, 145; 129, 146; 132, 147; 132, 148; 134, 149; 135, 150; 135, 151; 138, 152; 138, 153; 139, 154; 139, 155; 140, 156; 140, 157; 142, 158; 142, 159; 143, 160; 145, 161; 147, 162; 151, 163; 151, 164; 152, 165; 154, 166; 156, 167; 156, 168; 157, 169; 157, 170; 158, 171; 158, 172; 159, 173; 163, 174; 163, 175; 164, 176; 170, 177; 171, 178; 173, 179; 173, 180; 174, 181
def search(self, text, includes=None, doc_type=None, limit=None, autocomplete=False, promulgated_only=False, tags=None, sort=None, owner=None, series=None): ''' Search for entities in the charmstore. @param text The text to search for. @param includes What metadata to return in results (e.g. charm-config). @param doc_type Filter to this type: bundle or charm. @param limit Maximum number of results to return. @param autocomplete Whether to prefix/suffix match search terms. @param promulgated_only Whether to filter to only promulgated charms. @param tags The tags to filter; can be a list of tags or a single tag. @param sort Sorting the result based on the sort string provided which can be name, author, series and - in front for descending. @param owner Optional owner. If provided, search results will only include entities that owner can view. @param series The series to filter; can be a list of series or a single series. ''' queries = self._common_query_parameters(doc_type, includes, owner, promulgated_only, series, sort) if len(text): queries.append(('text', text)) if limit is not None: queries.append(('limit', limit)) if autocomplete: queries.append(('autocomplete', 1)) if tags is not None: if type(tags) is list: tags = ','.join(tags) queries.append(('tags', tags)) if len(queries): url = '{}/search?{}'.format(self.url, urlencode(queries)) else: url = '{}/search'.format(self.url) data = self._get(url) return data.json()['Results']
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, default_parameter; 11, default_parameter; 12, expression_statement; 13, expression_statement; 14, if_statement; 15, expression_statement; 16, return_statement; 17, identifier:includes; 18, None; 19, identifier:doc_type; 20, None; 21, identifier:promulgated_only; 22, False; 23, identifier:sort; 24, None; 25, identifier:owner; 26, None; 27, identifier:series; 28, None; 29, string; 30, assignment; 31, call; 32, block; 33, else_clause; 34, assignment; 35, subscript; 36, string_content:List entities in the charmstore. @param includes What metadata to return in results (e.g. charm-config). @param doc_type Filter to this type: bundle or charm. @param promulgated_only Whether to filter to only promulgated charms. @param sort Sorting the result based on the sort string provided which can be name, author, series and - in front for descending. @param owner Optional owner. If provided, search results will only include entities that owner can view. @param series The series to filter; can be a list of series or a single series.; 37, identifier:queries; 38, call; 39, identifier:len; 40, argument_list; 41, expression_statement; 42, block; 43, identifier:data; 44, call; 45, call; 46, string; 47, attribute; 48, argument_list; 49, identifier:queries; 50, assignment; 51, expression_statement; 52, attribute; 53, argument_list; 54, attribute; 55, argument_list; 56, string_content:Results; 57, identifier:self; 58, identifier:_common_query_parameters; 59, identifier:doc_type; 60, identifier:includes; 61, identifier:owner; 62, identifier:promulgated_only; 63, identifier:series; 64, identifier:sort; 65, identifier:url; 66, call; 67, assignment; 68, identifier:self; 69, identifier:_get; 70, identifier:url; 71, identifier:data; 72, identifier:json; 73, attribute; 74, argument_list; 75, identifier:url; 76, call; 77, string; 78, identifier:format; 79, attribute; 80, call; 81, attribute; 82, argument_list; 83, string_content:{}/list?{}; 84, identifier:self; 85, identifier:url; 86, identifier:urlencode; 87, argument_list; 88, string; 89, identifier:format; 90, attribute; 91, identifier:queries; 92, string_content:{}/list; 93, identifier:self; 94, identifier:url
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; 6, 17; 6, 18; 7, 19; 7, 20; 8, 21; 8, 22; 9, 23; 9, 24; 10, 25; 10, 26; 11, 27; 11, 28; 12, 29; 13, 30; 14, 31; 14, 32; 14, 33; 15, 34; 16, 35; 29, 36; 30, 37; 30, 38; 31, 39; 31, 40; 32, 41; 33, 42; 34, 43; 34, 44; 35, 45; 35, 46; 38, 47; 38, 48; 40, 49; 41, 50; 42, 51; 44, 52; 44, 53; 45, 54; 45, 55; 46, 56; 47, 57; 47, 58; 48, 59; 48, 60; 48, 61; 48, 62; 48, 63; 48, 64; 50, 65; 50, 66; 51, 67; 52, 68; 52, 69; 53, 70; 54, 71; 54, 72; 66, 73; 66, 74; 67, 75; 67, 76; 73, 77; 73, 78; 74, 79; 74, 80; 76, 81; 76, 82; 77, 83; 79, 84; 79, 85; 80, 86; 80, 87; 81, 88; 81, 89; 82, 90; 87, 91; 88, 92; 90, 93; 90, 94
def list(self, includes=None, doc_type=None, promulgated_only=False, sort=None, owner=None, series=None): ''' List entities in the charmstore. @param includes What metadata to return in results (e.g. charm-config). @param doc_type Filter to this type: bundle or charm. @param promulgated_only Whether to filter to only promulgated charms. @param sort Sorting the result based on the sort string provided which can be name, author, series and - in front for descending. @param owner Optional owner. If provided, search results will only include entities that owner can view. @param series The series to filter; can be a list of series or a single series. ''' queries = self._common_query_parameters(doc_type, includes, owner, promulgated_only, series, sort) if len(queries): url = '{}/list?{}'.format(self.url, urlencode(queries)) else: url = '{}/list'.format(self.url) data = self._get(url) return data.json()['Results']
0, module; 1, function_definition; 2, function_name:_common_query_parameters; 3, parameters; 4, block; 5, identifier:self; 6, identifier:doc_type; 7, identifier:includes; 8, identifier:owner; 9, identifier:promulgated_only; 10, identifier:series; 11, identifier:sort; 12, expression_statement; 13, expression_statement; 14, if_statement; 15, if_statement; 16, if_statement; 17, if_statement; 18, if_statement; 19, if_statement; 20, return_statement; 21, string; 22, assignment; 23, comparison_operator:includes is not None; 24, block; 25, comparison_operator:doc_type is not None; 26, block; 27, identifier:promulgated_only; 28, block; 29, comparison_operator:owner is not None; 30, block; 31, comparison_operator:series is not None; 32, block; 33, comparison_operator:sort is not None; 34, block; 35, identifier:queries; 36, string_content:Extract common query parameters between search and list into slice. @param includes What metadata to return in results (e.g. charm-config). @param doc_type Filter to this type: bundle or charm. @param promulgated_only Whether to filter to only promulgated charms. @param sort Sorting the result based on the sort string provided which can be name, author, series and - in front for descending. @param owner Optional owner. If provided, search results will only include entities that owner can view. @param series The series to filter; can be a list of series or a single series.; 37, identifier:queries; 38, list; 39, identifier:includes; 40, None; 41, expression_statement; 42, identifier:doc_type; 43, None; 44, expression_statement; 45, expression_statement; 46, identifier:owner; 47, None; 48, expression_statement; 49, identifier:series; 50, None; 51, if_statement; 52, expression_statement; 53, identifier:sort; 54, None; 55, expression_statement; 56, call; 57, call; 58, call; 59, call; 60, comparison_operator:type(series) is list; 61, block; 62, call; 63, call; 64, attribute; 65, argument_list; 66, attribute; 67, argument_list; 68, attribute; 69, argument_list; 70, attribute; 71, argument_list; 72, call; 73, identifier:list; 74, expression_statement; 75, attribute; 76, argument_list; 77, attribute; 78, argument_list; 79, identifier:queries; 80, identifier:extend; 81, list_comprehension; 82, identifier:queries; 83, identifier:append; 84, tuple; 85, identifier:queries; 86, identifier:append; 87, tuple; 88, identifier:queries; 89, identifier:append; 90, tuple; 91, identifier:type; 92, argument_list; 93, assignment; 94, identifier:queries; 95, identifier:append; 96, tuple; 97, identifier:queries; 98, identifier:append; 99, tuple; 100, tuple; 101, for_in_clause; 102, string; 103, identifier:doc_type; 104, string; 105, integer:1; 106, string; 107, identifier:owner; 108, identifier:series; 109, identifier:series; 110, call; 111, string; 112, identifier:series; 113, string; 114, identifier:sort; 115, string; 116, identifier:include; 117, identifier:include; 118, identifier:includes; 119, string_content:type; 120, string_content:promulgated; 121, string_content:owner; 122, attribute; 123, argument_list; 124, string_content:series; 125, string_content:sort; 126, string_content:include; 127, string; 128, identifier:join; 129, identifier:series; 130, string_content:,
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; 12, 21; 13, 22; 14, 23; 14, 24; 15, 25; 15, 26; 16, 27; 16, 28; 17, 29; 17, 30; 18, 31; 18, 32; 19, 33; 19, 34; 20, 35; 21, 36; 22, 37; 22, 38; 23, 39; 23, 40; 24, 41; 25, 42; 25, 43; 26, 44; 28, 45; 29, 46; 29, 47; 30, 48; 31, 49; 31, 50; 32, 51; 32, 52; 33, 53; 33, 54; 34, 55; 41, 56; 44, 57; 45, 58; 48, 59; 51, 60; 51, 61; 52, 62; 55, 63; 56, 64; 56, 65; 57, 66; 57, 67; 58, 68; 58, 69; 59, 70; 59, 71; 60, 72; 60, 73; 61, 74; 62, 75; 62, 76; 63, 77; 63, 78; 64, 79; 64, 80; 65, 81; 66, 82; 66, 83; 67, 84; 68, 85; 68, 86; 69, 87; 70, 88; 70, 89; 71, 90; 72, 91; 72, 92; 74, 93; 75, 94; 75, 95; 76, 96; 77, 97; 77, 98; 78, 99; 81, 100; 81, 101; 84, 102; 84, 103; 87, 104; 87, 105; 90, 106; 90, 107; 92, 108; 93, 109; 93, 110; 96, 111; 96, 112; 99, 113; 99, 114; 100, 115; 100, 116; 101, 117; 101, 118; 102, 119; 104, 120; 106, 121; 110, 122; 110, 123; 111, 124; 113, 125; 115, 126; 122, 127; 122, 128; 123, 129; 127, 130
def _common_query_parameters(self, doc_type, includes, owner, promulgated_only, series, sort): ''' Extract common query parameters between search and list into slice. @param includes What metadata to return in results (e.g. charm-config). @param doc_type Filter to this type: bundle or charm. @param promulgated_only Whether to filter to only promulgated charms. @param sort Sorting the result based on the sort string provided which can be name, author, series and - in front for descending. @param owner Optional owner. If provided, search results will only include entities that owner can view. @param series The series to filter; can be a list of series or a single series. ''' queries = [] if includes is not None: queries.extend([('include', include) for include in includes]) if doc_type is not None: queries.append(('type', doc_type)) if promulgated_only: queries.append(('promulgated', 1)) if owner is not None: queries.append(('owner', owner)) if series is not None: if type(series) is list: series = ','.join(series) queries.append(('series', series)) if sort is not None: queries.append(('sort', sort)) return queries
0, module; 1, function_definition; 2, function_name:letter_scales; 3, parameters; 4, block; 5, identifier:counts; 6, expression_statement; 7, try_statement; 8, expression_statement; 9, expression_statement; 10, return_statement; 11, comment:"""Convert letter counts to frequencies, sorted increasing."""; 12, block; 13, except_clause; 14, assignment; 15, call; 16, identifier:freqs; 17, expression_statement; 18, identifier:ZeroDivisionError; 19, comment:# This logo is all gaps, nothing can be done; 20, block; 21, identifier:freqs; 22, list_comprehension; 23, attribute; 24, argument_list; 25, assignment; 26, return_statement; 27, tuple; 28, for_in_clause; 29, if_clause; 30, identifier:freqs; 31, identifier:sort; 32, keyword_argument; 33, identifier:scale; 34, binary_operator:1.0 / sum(counts.values()); 35, list; 36, identifier:aa; 37, binary_operator:cnt*scale; 38, pattern_list; 39, call; 40, identifier:cnt; 41, identifier:key; 42, lambda; 43, float:1.0; 44, call; 45, identifier:cnt; 46, identifier:scale; 47, identifier:aa; 48, identifier:cnt; 49, attribute; 50, argument_list; 51, lambda_parameters; 52, subscript; 53, identifier:sum; 54, argument_list; 55, identifier:counts; 56, identifier:iteritems; 57, identifier:pair; 58, identifier:pair; 59, integer:1; 60, call; 61, attribute; 62, argument_list; 63, identifier:counts; 64, identifier:values
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; 13, 19; 13, 20; 14, 21; 14, 22; 15, 23; 15, 24; 17, 25; 20, 26; 22, 27; 22, 28; 22, 29; 23, 30; 23, 31; 24, 32; 25, 33; 25, 34; 26, 35; 27, 36; 27, 37; 28, 38; 28, 39; 29, 40; 32, 41; 32, 42; 34, 43; 34, 44; 37, 45; 37, 46; 38, 47; 38, 48; 39, 49; 39, 50; 42, 51; 42, 52; 44, 53; 44, 54; 49, 55; 49, 56; 51, 57; 52, 58; 52, 59; 54, 60; 60, 61; 60, 62; 61, 63; 61, 64
def letter_scales(counts): """Convert letter counts to frequencies, sorted increasing.""" try: scale = 1.0 / sum(counts.values()) except ZeroDivisionError: # This logo is all gaps, nothing can be done return [] freqs = [(aa, cnt*scale) for aa, cnt in counts.iteritems() if cnt] freqs.sort(key=lambda pair: pair[1]) return freqs
0, module; 1, function_definition; 2, function_name:_push_subtree; 3, parameters; 4, block; 5, identifier:self; 6, typed_parameter; 7, expression_statement; 8, expression_statement; 9, if_statement; 10, comment:# in general we want the highest bit, but here it's also the lowest bit; 11, comment:# so just reuse that code instead of writing a new highest_bit_set(); 12, expression_statement; 13, if_statement; 14, expression_statement; 15, assert_statement; 16, if_statement; 17, expression_statement; 18, expression_statement; 19, if_statement; 20, identifier:leaves; 21, type; 22, comment:"""Extend with a full subtree <= the current minimum subtree. The leaves must form a full subtree, i.e. of size 2^k for some k. If there is a minimum subtree (i.e. __mintree_height > 0), then the input subtree must be smaller or of equal size to the minimum subtree. If the subtree is smaller (or no such minimum exists, in an empty tree), we can simply append its hash to self.hashes, since this maintains the invariant property of being sorted in descending size order. If the subtree is of equal size, we are in a similar situation to an addition carry. We handle it by combining the two subtrees into a larger subtree (of size 2^(k+1)), then recursively trying to add this new subtree back into the tree. Any collection of leaves larger than the minimum subtree must undergo additional partition to conform with the structure of a merkle tree, which is a more complex operation, performed by extend(). """; 23, assignment; 24, comparison_operator:count_bits_set(size) != 1; 25, block; 26, assignment; 27, boolean_operator; 28, block; 29, assignment; 30, comparison_operator:hashes == (root_hash,); 31, attribute; 32, block; 33, assignment; 34, assignment; 35, attribute; 36, block; 37, generic_type; 38, identifier:size; 39, call; 40, call; 41, integer:1; 42, raise_statement; 43, pattern_list; 44, expression_list; 45, comparison_operator:mintree_h > 0; 46, comparison_operator:subtree_h > mintree_h; 47, raise_statement; 48, pattern_list; 49, call; 50, identifier:hashes; 51, tuple; 52, identifier:self; 53, identifier:hashStore; 54, for_statement; 55, identifier:new_node_hashes; 56, call; 57, identifier:nodes; 58, list_comprehension; 59, identifier:self; 60, identifier:hashStore; 61, for_statement; 62, identifier:List; 63, type_parameter; 64, identifier:len; 65, argument_list; 66, identifier:count_bits_set; 67, argument_list; 68, call; 69, identifier:subtree_h; 70, identifier:mintree_h; 71, call; 72, attribute; 73, identifier:mintree_h; 74, integer:0; 75, identifier:subtree_h; 76, identifier:mintree_h; 77, call; 78, identifier:root_hash; 79, identifier:hashes; 80, attribute; 81, argument_list; 82, identifier:root_hash; 83, identifier:h; 84, identifier:hashes; 85, block; 86, attribute; 87, argument_list; 88, tuple; 89, for_in_clause; 90, identifier:node; 91, identifier:nodes; 92, block; 93, type; 94, identifier:leaves; 95, identifier:size; 96, identifier:ValueError; 97, argument_list; 98, identifier:lowest_bit_set; 99, argument_list; 100, identifier:self; 101, identifier:__mintree_height; 102, identifier:ValueError; 103, argument_list; 104, attribute; 105, identifier:_hash_full; 106, identifier:leaves; 107, integer:0; 108, identifier:size; 109, expression_statement; 110, identifier:self; 111, identifier:__push_subtree_hash; 112, identifier:subtree_h; 113, identifier:root_hash; 114, attribute; 115, identifier:height; 116, identifier:h; 117, pattern_list; 118, identifier:new_node_hashes; 119, expression_statement; 120, identifier:bytes; 121, binary_operator:"invalid subtree with size != 2^k: %s" % size; 122, identifier:size; 123, binary_operator:"subtree %s > current smallest subtree %s" % ( subtree_h, mintree_h); 124, identifier:self; 125, identifier:__hasher; 126, call; 127, identifier:self; 128, identifier:tree_size; 129, identifier:h; 130, identifier:height; 131, call; 132, string:"invalid subtree with size != 2^k: %s"; 133, identifier:size; 134, string:"subtree %s > current smallest subtree %s"; 135, tuple; 136, attribute; 137, argument_list; 138, attribute; 139, argument_list; 140, identifier:subtree_h; 141, identifier:mintree_h; 142, attribute; 143, identifier:writeLeaf; 144, identifier:h; 145, attribute; 146, identifier:writeNode; 147, identifier:node; 148, identifier:self; 149, identifier:hashStore; 150, identifier:self; 151, identifier:hashStore
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; 6, 20; 6, 21; 7, 22; 8, 23; 9, 24; 9, 25; 12, 26; 13, 27; 13, 28; 14, 29; 15, 30; 16, 31; 16, 32; 17, 33; 18, 34; 19, 35; 19, 36; 21, 37; 23, 38; 23, 39; 24, 40; 24, 41; 25, 42; 26, 43; 26, 44; 27, 45; 27, 46; 28, 47; 29, 48; 29, 49; 30, 50; 30, 51; 31, 52; 31, 53; 32, 54; 33, 55; 33, 56; 34, 57; 34, 58; 35, 59; 35, 60; 36, 61; 37, 62; 37, 63; 39, 64; 39, 65; 40, 66; 40, 67; 42, 68; 43, 69; 43, 70; 44, 71; 44, 72; 45, 73; 45, 74; 46, 75; 46, 76; 47, 77; 48, 78; 48, 79; 49, 80; 49, 81; 51, 82; 54, 83; 54, 84; 54, 85; 56, 86; 56, 87; 58, 88; 58, 89; 61, 90; 61, 91; 61, 92; 63, 93; 65, 94; 67, 95; 68, 96; 68, 97; 71, 98; 71, 99; 72, 100; 72, 101; 77, 102; 77, 103; 80, 104; 80, 105; 81, 106; 81, 107; 81, 108; 85, 109; 86, 110; 86, 111; 87, 112; 87, 113; 88, 114; 88, 115; 88, 116; 89, 117; 89, 118; 92, 119; 93, 120; 97, 121; 99, 122; 103, 123; 104, 124; 104, 125; 109, 126; 114, 127; 114, 128; 117, 129; 117, 130; 119, 131; 121, 132; 121, 133; 123, 134; 123, 135; 126, 136; 126, 137; 131, 138; 131, 139; 135, 140; 135, 141; 136, 142; 136, 143; 137, 144; 138, 145; 138, 146; 139, 147; 142, 148; 142, 149; 145, 150; 145, 151
def _push_subtree(self, leaves: List[bytes]): """Extend with a full subtree <= the current minimum subtree. The leaves must form a full subtree, i.e. of size 2^k for some k. If there is a minimum subtree (i.e. __mintree_height > 0), then the input subtree must be smaller or of equal size to the minimum subtree. If the subtree is smaller (or no such minimum exists, in an empty tree), we can simply append its hash to self.hashes, since this maintains the invariant property of being sorted in descending size order. If the subtree is of equal size, we are in a similar situation to an addition carry. We handle it by combining the two subtrees into a larger subtree (of size 2^(k+1)), then recursively trying to add this new subtree back into the tree. Any collection of leaves larger than the minimum subtree must undergo additional partition to conform with the structure of a merkle tree, which is a more complex operation, performed by extend(). """ size = len(leaves) if count_bits_set(size) != 1: raise ValueError("invalid subtree with size != 2^k: %s" % size) # in general we want the highest bit, but here it's also the lowest bit # so just reuse that code instead of writing a new highest_bit_set() subtree_h, mintree_h = lowest_bit_set(size), self.__mintree_height if mintree_h > 0 and subtree_h > mintree_h: raise ValueError("subtree %s > current smallest subtree %s" % ( subtree_h, mintree_h)) root_hash, hashes = self.__hasher._hash_full(leaves, 0, size) assert hashes == (root_hash,) if self.hashStore: for h in hashes: self.hashStore.writeLeaf(h) new_node_hashes = self.__push_subtree_hash(subtree_h, root_hash) nodes = [(self.tree_size, height, h) for h, height in new_node_hashes] if self.hashStore: for node in nodes: self.hashStore.writeNode(node)
0, module; 1, function_definition; 2, function_name:_sort_cards; 3, parameters; 4, type; 5, block; 6, identifier:self; 7, typed_parameter; 8, identifier:list; 9, expression_statement; 10, return_statement; 11, identifier:cards; 12, type; 13, string; 14, call; 15, identifier:Generator; 16, string_content:sort cards by blocknum and blockseq; 17, identifier:sorted; 18, argument_list; 19, list_comprehension; 20, keyword_argument; 21, attribute; 22, for_in_clause; 23, identifier:key; 24, call; 25, identifier:card; 26, identifier:__dict__; 27, identifier:card; 28, identifier:cards; 29, identifier:itemgetter; 30, argument_list; 31, string; 32, string; 33, string; 34, string_content:blocknum; 35, string_content:blockseq; 36, string_content:cardseq
0, 1; 1, 2; 1, 3; 1, 4; 1, 5; 3, 6; 3, 7; 4, 8; 5, 9; 5, 10; 7, 11; 7, 12; 9, 13; 10, 14; 12, 15; 13, 16; 14, 17; 14, 18; 18, 19; 18, 20; 19, 21; 19, 22; 20, 23; 20, 24; 21, 25; 21, 26; 22, 27; 22, 28; 24, 29; 24, 30; 30, 31; 30, 32; 30, 33; 31, 34; 32, 35; 33, 36
def _sort_cards(self, cards: Generator) -> list: '''sort cards by blocknum and blockseq''' return sorted([card.__dict__ for card in cards], key=itemgetter('blocknum', 'blockseq', 'cardseq'))
0, module; 1, function_definition; 2, function_name:sort_aliases; 3, parameters; 4, block; 5, identifier:self; 6, identifier:aliases; 7, expression_statement; 8, expression_statement; 9, if_statement; 10, expression_statement; 11, return_statement; 12, comment:"""Sorts the given aliases list, returns a sorted list. :param list aliases: :return: sorted aliases list """; 13, call; 14, not_operator; 15, block; 16, assignment; 17, list_comprehension; 18, attribute; 19, argument_list; 20, identifier:aliases; 21, return_statement; 22, identifier:parent_aliases; 23, call; 24, identifier:parent_alias; 25, for_in_clause; 26, if_clause; 27, identifier:self; 28, identifier:_cache_init; 29, identifier:aliases; 30, attribute; 31, argument_list; 32, identifier:parent_alias; 33, identifier:parent_aliases; 34, comparison_operator:parent_alias in aliases; 35, call; 36, identifier:keys; 37, identifier:parent_alias; 38, identifier:aliases; 39, attribute; 40, argument_list; 41, identifier:self; 42, identifier:_cache_get_entry; 43, attribute; 44, identifier:self; 45, identifier:CACHE_NAME_PARENTS
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; 15, 21; 16, 22; 16, 23; 17, 24; 17, 25; 17, 26; 18, 27; 18, 28; 21, 29; 23, 30; 23, 31; 25, 32; 25, 33; 26, 34; 30, 35; 30, 36; 34, 37; 34, 38; 35, 39; 35, 40; 39, 41; 39, 42; 40, 43; 43, 44; 43, 45
def sort_aliases(self, aliases): """Sorts the given aliases list, returns a sorted list. :param list aliases: :return: sorted aliases list """ self._cache_init() if not aliases: return aliases parent_aliases = self._cache_get_entry(self.CACHE_NAME_PARENTS).keys() return [parent_alias for parent_alias in parent_aliases if parent_alias in aliases]
0, module; 1, function_definition; 2, function_name:contigs_to_positions; 3, parameters; 4, block; 5, identifier:contigs; 6, default_parameter; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, for_statement; 11, return_statement; 12, identifier:binning; 13, integer:10000; 14, comment:"""Build positions from contig labels From a list of contig labels and a binning parameter, build a list of positions that's essentially a concatenation of linspaces with step equal to the binning. Parameters ---------- contigs : list or array_like The list of contig labels, must be sorted. binning : int, optional The step for the list of positions. Default is 10000. Returns ------- positions : numpy.ndarray The piece-wise sorted list of positions """; 15, assignment; 16, assignment; 17, pattern_list; 18, call; 19, block; 20, identifier:positions; 21, identifier:positions; 22, call; 23, identifier:index; 24, integer:0; 25, identifier:_; 26, identifier:chunk; 27, attribute; 28, argument_list; 29, expression_statement; 30, expression_statement; 31, expression_statement; 32, attribute; 33, argument_list; 34, identifier:itertools; 35, identifier:groubpy; 36, identifier:contigs; 37, assignment; 38, assignment; 39, augmented_assignment; 40, identifier:np; 41, identifier:zeros_like; 42, identifier:contigs; 43, identifier:l; 44, call; 45, subscript; 46, binary_operator:np.arange(list(chunk)) * binning; 47, identifier:index; 48, identifier:l; 49, identifier:len; 50, argument_list; 51, identifier:positions; 52, slice; 53, call; 54, identifier:binning; 55, identifier:chunk; 56, identifier:index; 57, binary_operator:index + l; 58, attribute; 59, argument_list; 60, identifier:index; 61, identifier:l; 62, identifier:np; 63, identifier:arange; 64, call; 65, identifier:list; 66, argument_list; 67, identifier:chunk
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 6, 12; 6, 13; 7, 14; 8, 15; 9, 16; 10, 17; 10, 18; 10, 19; 11, 20; 15, 21; 15, 22; 16, 23; 16, 24; 17, 25; 17, 26; 18, 27; 18, 28; 19, 29; 19, 30; 19, 31; 22, 32; 22, 33; 27, 34; 27, 35; 28, 36; 29, 37; 30, 38; 31, 39; 32, 40; 32, 41; 33, 42; 37, 43; 37, 44; 38, 45; 38, 46; 39, 47; 39, 48; 44, 49; 44, 50; 45, 51; 45, 52; 46, 53; 46, 54; 50, 55; 52, 56; 52, 57; 53, 58; 53, 59; 57, 60; 57, 61; 58, 62; 58, 63; 59, 64; 64, 65; 64, 66; 66, 67
def contigs_to_positions(contigs, binning=10000): """Build positions from contig labels From a list of contig labels and a binning parameter, build a list of positions that's essentially a concatenation of linspaces with step equal to the binning. Parameters ---------- contigs : list or array_like The list of contig labels, must be sorted. binning : int, optional The step for the list of positions. Default is 10000. Returns ------- positions : numpy.ndarray The piece-wise sorted list of positions """ positions = np.zeros_like(contigs) index = 0 for _, chunk in itertools.groubpy(contigs): l = len(chunk) positions[index : index + l] = np.arange(list(chunk)) * binning index += l return positions